Exemplo n.º 1
0
void CEffectsGame::CreateBullet( Vector3 pos, Vector3 dir )
{
	// find empty slot
	int i = 0;
	for (i=0; i<MAX_BULLETS; i++) 
		if (bullets[i] == NULL) break;

	if (i == MAX_BULLETS) return;

	static CTexture *fxTex = new CTexture("textures/fx.png");

	CSprite3D *bullet = new CSprite3D(fxTex, 0.2f, 2.0f, false);
	float margin = 0.1f;
	bullet->texcoord[0] = Vector2(1-margin,1);
	bullet->texcoord[1] = Vector2(0.75+margin,0.75);
	bullet->locked = true;
	bullet->lockedAxis = pCamera->forward;
	bullet->color = YELLOW;

	bullet->SetPosition(car->pBarrel->GetWorldPosition()/* + car->pBarrel->up * 1.0f*/);

	float s = cv_bulletScatter.GetFloat()/2;
	dir.x += frand(-s, s);
	dir.y += frand(-s, s);
	dir.z += frand(-s, s);

	bullet->velocity = dir.Normalize() * cv_bulletSpeed.GetFloat();
	
	pScene->Add(bullet);

	bullets[i] = bullet;
	bulletsNum++;
}
Exemplo n.º 2
0
void CStructure::Think()
{
	BaseClass::Think();

	if (GameData().GetCommandMenu())
	{
		if (IsUnderConstruction() && IsWorkingConstructionTurn())
		{
			CCommandMenu* pMenu = GameData().GetCommandMenu();
			pMenu->SetProgressBar(GameServer()->GetGameTime() - m_flConstructionTurnTime, build_time_construct.GetFloat());
		}

		if (GameData().GetCommandMenu()->WantsToClose())
			GameData().CloseCommandMenu();
		else
			GameData().GetCommandMenu()->Think();
	}

	if (GameServer()->GetGameTime() > m_flConstructionTurnTime + build_time_construct.GetFloat())
		ConstructionTurn();

	if (IsUnderConstruction())
	{
		if (CanAutoOpenMenu())
		{
			// If the player is nearby, looking at me, and not already looking at another command menu, open a temp command menu showing construction info.
			CCommandMenu* pMenu = GameData().CreateCommandMenu(GetOwner()->GetPlayerCharacter());
			SetupMenuButtons();
		}
		else if (CanAutoCloseMenu())
		{
			// If the player goes away or stops looking, close it.
			GameData().CloseCommandMenu();
		}

		if (GameData().GetCommandMenu())
			GameData().GetCommandMenu()->Think();
	}
	else if (TakesPower() && GetOwner() && GetOwner()->GetPlayerCharacter() && GetOwner()->GetPlayerCharacter()->IsHoldingPowerCord())
	{
		if (CanAutoOpenMenu())
		{
			// If the player is nearby, looking at me, and not already looking at another command menu, open a temp command menu showing construction info.
			CCommandMenu* pMenu = GameData().CreateCommandMenu(GetOwner()->GetPlayerCharacter());
			SetupMenuButtons();
		}
		else if (CanAutoCloseMenu())
		{
			// If the player goes away or stops looking, close it.
			GameData().CloseCommandMenu();
		}

		if (GameData().GetCommandMenu())
			GameData().GetCommandMenu()->Think();
	}
}
Exemplo n.º 3
0
bool RabidEngine::OnMouseMove(int dx, int dy)
{
  if(!g_console->Active())
  {
    {
      cl_camroty.SetFloat(cl_camroty.GetFloat() - dx);
      cl_camrotx.SetFloat(cl_camrotx.GetFloat() - dy);

      while(cl_camroty.GetFloat() > 360.0f)
        cl_camroty.SetFloat(cl_camroty.GetFloat() - 360.0f);
      while(cl_camroty.GetFloat() < 0.0f)
        cl_camroty.SetFloat(cl_camroty.GetFloat() + 360.0f);

      if(cl_camrotx.GetFloat() > 90)
        cl_camrotx.SetFloat(90.0);
      if(cl_camrotx.GetFloat() < -90)
        cl_camrotx.SetFloat(-90.0);
    }

    
    return true;
  }

  return false;
}
Exemplo n.º 4
0
void CLessonPanel::Paint(float x, float y, float w, float h)
{
    if (m_flStartTime < 0 || GameServer()->GetGameTime() > m_flStartTime + lesson_time.GetFloat())
        return;

    if (m_pLesson->m_flSlideAmount > 0)
    {
        if (m_pLesson->m_bSlideX)
            x += Bias(RemapValClamped((float)(GameServer()->GetGameTime() - m_flStartTime), 0, 1, 1.0f, 0.0f), 0.2f) * m_pLesson->m_flSlideAmount;
        else
            y += Bias(RemapValClamped((float)(GameServer()->GetGameTime() - m_flStartTime), 0, 1, 1.0f, 0.0f), 0.2f) * m_pLesson->m_flSlideAmount;
    }

    bool bScrolling = false;
    if (!m_bDoneScrolling)
    {
        int iPrintChars = (int)((GameServer()->GetGameTime() - m_flStartTime)*70);
        m_pText->SetPrintChars(iPrintChars);

        bScrolling = (iPrintChars < (int)m_pText->GetText().length());

        if (!bScrolling)
            m_bDoneScrolling = true;
    }
    else
        m_pText->SetPrintChars(-1);

    CRootPanel::PaintRect(x, y, w, h, Color(0, 0, 0, 50), 1);

    CPanel::Paint(x, y, w, h);
}
Exemplo n.º 5
0
void CPlayer::Instructor_LessonLearned(const tstring& sLesson)
{
    if (!GameWindow()->GetInstructor()->IsInitialized())
        GameWindow()->GetInstructor()->Initialize();

    auto it = m_apLessonProgress.find(sLesson);
    TAssert(it != m_apLessonProgress.end());
    if (it == m_apLessonProgress.end())
        return;

    CLessonProgress* pLessonProgress = &it->second;

    TAssert(pLessonProgress);
    if (!pLessonProgress)
        return;

    // Can only learn a lesson once in a while, to ensure that it is truly learned.
    // The idea is that the player spends a couple seconds toying around with the
    // new feature, but won't spend all of the lessons in that time.
    if (GameServer()->GetGameTime() < pLessonProgress->m_flLastTimeLearned + lesson_learntime.GetFloat())
        return;

    pLessonProgress->m_flLastTimeLearned = GameServer()->GetGameTime();
    pLessonProgress->m_iTimesLearned++;

    if (lesson_debug.GetBool())
    {
        CLesson* pLesson = GameWindow()->GetInstructor()->GetLesson(sLesson);

        if (pLessonProgress->m_iTimesLearned < pLesson->m_iTimesToLearn)
            TMsg(tsprintf("Instructor: Trained lesson " + sLesson + " - %d/%d\n", pLessonProgress->m_iTimesLearned, pLesson->m_iTimesToLearn));
        else if (pLessonProgress->m_iTimesLearned == pLesson->m_iTimesToLearn)
            TMsg("Instructor: Learned lesson " + sLesson + "\n");
    }
}
Exemplo n.º 6
0
float CVar::GetCVarFloat(tstring sName)
{
	CVar* pVar = FindCVar(sName);
	if (!pVar)
		return 0;

	return pVar->GetFloat();
}
Exemplo n.º 7
0
void ConstructBuilding::Update(const float t)
{
	if (m_buildprogress < 1.0f && m_build.BeginPass(m_chief.GetNumWorkers(EBW_Work)+v_autowork.GetFloat(), t))
	{
		m_build << m_stone;
		m_build << m_wood;
		m_build >> m_buildprogress;
		m_build.Commit();
	}
Exemplo n.º 8
0
void Sugar::Update(const float t)
{
	float work = m_cooker.Update(t, m_coal);
	if (m_cooker.WarmStart()) this->m_part.emitor->Start();
	if (m_cooker.WarmEnd()) this->m_part.emitor->Stop();
	if (!InBuildProcess() && work && 
            m_work.BeginPass(m_chief.GetNumWorkers(EBW_Work)+v_autowork.GetFloat(), 
									t * work))
	{
		m_work << m_cane;
		m_work >> m_sugar;
		m_work.Commit();
	}
Exemplo n.º 9
0
void CStructure::SetupMenuButtons()
{
	CCommandMenu* pMenu = GameData().GetCommandMenu();

	if (!pMenu)
		return;

	if (IsUnderConstruction())
	{
		pMenu->SetTitle(GetStructureName(m_eStructureType));
		pMenu->SetSubtitle(sprintf("UNDER CONSTRUCTION - %d/%d", m_iTotalTurnsToConstruct-m_iTurnsToConstruct, m_iTotalTurnsToConstruct));

		if (IsWorkingConstructionTurn())
			pMenu->SetProgressBar(GameServer()->GetGameTime() - m_flConstructionTurnTime, build_time_construct.GetFloat());
		else
			pMenu->DisableProgressBar();
	}
	else if (GetOwner() && GetOwner()->GetPlayerCharacter() && GetOwner()->GetPlayerCharacter()->IsHoldingPowerCord())
	{
		pMenu->SetTitle(GetStructureName(m_eStructureType));
		pMenu->SetSubtitle("Connect power?");
	}
}
Exemplo n.º 10
0
void CCharacterController::PlayerWalk(btCollisionWorld* pCollisionWorld, btScalar dt)
{
	Vector vecCurrentVelocity = m_hEntity->GetLocalVelocity();
	vecCurrentVelocity.z = 0;

	// Calculate friction first, so that the player's movement commands can overwhelm it.
	if (vecCurrentVelocity.Length2DSqr() > 0.00001f)
	{
		if (m_hEntity->GetGroundEntity())
		{
			float flSpeed2D = vecCurrentVelocity.Length2D();

			float flFriction = sv_friction.GetFloat() * flSpeed2D * dt;

			float flNewSpeed = flSpeed2D - flFriction;

			if (flNewSpeed < 0)
				flNewSpeed = 0;

			float flScale = flNewSpeed / flSpeed2D;

			vecCurrentVelocity *= flScale;

			m_hEntity->SetLocalVelocity(vecCurrentVelocity);
		}
	}

	// Calculate a new velocity using the player's desired direction of travel.
	btVector3 vecWishDirection = m_vecMoveVelocity;
	vecWishDirection.setZ(0);
	float flWishVelocity = m_vecMoveVelocity.length();
	if (flWishVelocity)
		vecWishDirection = vecWishDirection / flWishVelocity;
	else
		vecWishDirection = btVector3(0, 0, 0);

	if (flWishVelocity > m_hEntity->CharacterSpeed())
		flWishVelocity = m_hEntity->CharacterSpeed();

	float flVelocityInWishDirection = GetVelocity().dot(vecWishDirection);

	float flDirectionChange = flWishVelocity - flVelocityInWishDirection;

	if (flDirectionChange > 0)
	{
		float flAccelerationAmount = flWishVelocity * m_hEntity->CharacterAcceleration() * dt;
		if (flAccelerationAmount > flDirectionChange)
			flAccelerationAmount = flDirectionChange;
		vecCurrentVelocity = vecCurrentVelocity + ToTVector(vecWishDirection) * flAccelerationAmount;

		TAssert(vecCurrentVelocity.z == 0);
	}

	float flCurrentVelocity = vecCurrentVelocity.Length();

	if (flCurrentVelocity > m_hEntity->CharacterSpeed())
		vecCurrentVelocity *= m_hEntity->CharacterSpeed()/flCurrentVelocity;

	if (vecCurrentVelocity.LengthSqr() < 0.001f)
	{
		m_hEntity->SetLocalVelocity(Vector());
		return;
	}

	btTransform mWorld = m_pGhostObject->getWorldTransform();

	// Try moving the player directly, if it's possible.
	{
		btVector3 vecTargetPosition = mWorld.getOrigin() + ToBTVector(vecCurrentVelocity) * dt;

		CTraceResult tr;
		PlayerTrace(pCollisionWorld, mWorld.getOrigin(), vecTargetPosition, tr);

		if (tr.m_flFraction == 1)
		{
			mWorld.setOrigin(vecTargetPosition);
			m_pGhostObject->setWorldTransform(mWorld);
			m_hEntity->SetLocalVelocity(vecCurrentVelocity);
			return;
		}
	}

	// There was something blocking the way. Try walking up a step or along walls.

	btVector3 vecSavedStepUp(0, 0, 0);

	{
		// Move up a bit to try to clear a step.
		btVector3 vecStartPosition = m_pGhostObject->getWorldTransform().getOrigin();
		btVector3 vecTargetPosition = m_pGhostObject->getWorldTransform().getOrigin() + GetUpVector() * m_flStepHeight;

		CTraceResult tr;
		PlayerTrace(pCollisionWorld, vecStartPosition, vecTargetPosition, tr);

		if (tr.m_flFraction < 1)
		{
			// we moved up only a fraction of the step height
			btVector3 vecInterpolated;
			vecInterpolated.setInterpolate3(m_pGhostObject->getWorldTransform().getOrigin(), vecTargetPosition, tr.m_flFraction);
			m_pGhostObject->getWorldTransform().setOrigin(vecInterpolated);

			vecSavedStepUp = vecInterpolated - vecStartPosition;
		}
		else
		{
			vecSavedStepUp = vecTargetPosition - vecStartPosition;
			m_pGhostObject->getWorldTransform().setOrigin(vecTargetPosition);
		}
	}

	StepForwardAndStrafe(pCollisionWorld, ToBTVector(vecCurrentVelocity) * dt);

	if (vecSavedStepUp.length2() > 0)
	{
		// Move back down as much as we moved up.
		btVector3 vecStartPosition = m_pGhostObject->getWorldTransform().getOrigin();
		btVector3 vecTargetPosition = m_pGhostObject->getWorldTransform().getOrigin() - vecSavedStepUp;

		CTraceResult tr;
		PlayerTrace(pCollisionWorld, vecStartPosition, vecTargetPosition, tr);

		if (tr.m_flFraction < 1)
		{
			btVector3 vecInterpolated;
			vecInterpolated.setInterpolate3(m_pGhostObject->getWorldTransform().getOrigin(), vecTargetPosition, tr.m_flFraction);
			m_pGhostObject->getWorldTransform().setOrigin(vecInterpolated);
		}
		else
			m_pGhostObject->getWorldTransform().setOrigin(vecTargetPosition);
	}
}
Exemplo n.º 11
0
void CEffectsGame::UpdateBullets( float frametime )
{
	for (int i=0; i<MAX_BULLETS; i++) 
	{
		if (bullets[i] == NULL) continue;;

		CSprite3D *bullet = bullets[i];

		Vector3 move = bullet->velocity * frametime;
		Vector3 start = bullet->GetPosition();
		bullet->Move(move.x, move.y, move.z);
		bullet->velocity.y -= frametime * cv_bulletGravity.GetFloat();

		bullet->lockedAxis = bullet->velocity;
		bullet->lockedAxis.Normalize();

		Vector3 v = bullet->velocity;
		v.Normalize();
		gRenderer.AddLine(bullet->GetPosition(), bullet->GetPosition() + v, SRGBA(255,230,180,180));


		if (bullet->GetWorldPosition().y < 0) 
		{
			RemoveBullet(i);
		}

		SMapTile *tileHit;
		Vector3 tileHitPos;
		Vector3 pos;
		bool hit = false;
		if (hit = pLevel->CastRay(start, bullet->GetPosition(), OUT tileHitPos, OUT &tileHit, OUT &pos))
		{			
				EnterCriticalSection(&renderCS);
				tileHit->type = 0;
				LeaveCriticalSection(&renderCS);

				// remove tile from the level and mark for update
				SMapChunk *chunk = pLevel->GetChunk(
					floor(tileHitPos.x/SMapChunk::Size),
					floor(tileHitPos.y/SMapChunk::Size),
					floor(tileHitPos.z/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;
				
				// add a box to spawn list
				SSpawnTile s;
				s.pos = tileHitPos;
				s.vel = v * cv_bulletforce.GetFloat();
				boxesToSpawn.push(s);			
				
				// remove bullet
				RemoveBullet(i);

				float puffSpeed = 0.5;

				// add puff effect
				for (int i = 0; i<6; i++)
				{					
					static CTexture *puffTex = new CTexture("particles/explosion4.dds");
					CParticle *p = new CParticle(puffTex);
					p->size = Vector2(1.35, 1.35);
					p->position = pos;
					p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed) );
					p->lifetime = 1;
					//p->color = SRGBA(155,155,155,255);
					p->color = SRGB(clamp(pos.x*255.0f/32.0f,0,255)*0.9f, clamp(pos.y*255.0f/32.0f,0,255)*0.9f, clamp(pos.z*255.0f/32.0f,0,255)*0.9f);
					p->colorChange = p->color;// SRGBA(255,255,255,0);
					p->colorChange.a = 0;
					p->colorTime = 1;
					p->sizeVel = Vector2(0.85,0.85);
					particles->Add(p);
				}
		}		
	
	}

	//PrintText("Bullets: %d", bulletsNum);
}
Exemplo n.º 12
0
void CarBoxCallback(const NewtonBody* body, float timestep, int threadIndex)
{
	float mass, ix, iy, iz;

	NewtonBodyGetMassMatrix(body, &mass, &ix, &iy, &iz);
	Vector4 gravityForce = Vector4(0.0f, mass * GRAVITY, 0.0f, 1.0f);

	// set gravity as a force
	//NewtonBodySetForce(body, (float*)&gravityForce);

	CMesh *object = (CMesh*)NewtonBodyGetUserData(body);
	Vector3 force;

	if (Keydown('w')) force = object->forward;
	if (Keydown('s')) force = -object->forward;

	//if (Keydown('a')) force -= object->right;
	//if (Keydown('d')) force += object->right;

	force *= cv_speed.GetFloat();	// speed

	//force.y = GRAVITY;
	force *= mass;

	
	/*float f[3];
	NewtonBodyGetForce(body, &f[0]);
	Debug("BODY:     %f %f %f", f[0], f[1], f[2]);
	
	Debug("FORCE:    %f %f %f", force.x, force.y, force.z);
*/
	NewtonBodySetForce(body, &force[0]);	
	//NewtonBodyAddImpulse(body, &force[0], &object->GetWorldPosition()[0]);
	//NewtonBodySetVelocity(body, &force[0]);

	float torqueForce = cv_rspeed.GetFloat();
	Vector3 torque;
	if (Keydown('a')) torque.y -= torqueForce;
	if (Keydown('d')) torque.y += torqueForce;

	// Damping has no effect at all
/*	static float damp = 0.5f;
	if (KeyPressed('p')) damp += 0.1f;
	if (KeyPressed('o')) damp -= 0.1f;
	Vector3 damping = Vector3(damp,damp,damp);
	damping *= damp;
	NewtonBodySetAngularDamping(body, &damping[0]);
	*/

	
	
	NewtonBodySetOmega(body, &torque[0]);
	
	//torque *= mass;	
	//NewtonBodyAddTorque(body, &torque[0]);

	
	int sleep = NewtonBodyGetSleepState(body);
	object->color = sleep == 1 ? GREEN : RED;

	//Vector3 speed;
	//NewtonBodyGetVelocity(body, &speed[0]);
}
Exemplo n.º 13
0
void CSupplier::PostRender() const
{
	BaseClass::PostRender();

	if (!GameServer()->GetRenderer()->IsRenderingTransparent())
		return;

	float flGrowthTime = (float)(GameServer()->GetGameTime() - m_flTendrilGrowthStartTime);

	if (flGrowthTime < 0)
		return;

	if (m_flTendrilGrowthStartTime == 0)
	{
		DigitanksGame()->GetDigitanksRenderer()->AddTendrilBatch(this);
		return;
	}

	COverheadCamera* pCamera = DigitanksGame()->GetOverheadCamera();
	Vector vecCamera = pCamera->GetGlobalOrigin();
	float flDistanceSqr = GetGlobalOrigin().DistanceSqr(vecCamera);
	float flFadeDistance = tendril_fade_distance.GetFloat();

	float flFadeAlpha = RemapValClamped(flDistanceSqr, flFadeDistance*flFadeDistance, (flFadeDistance+20)*(flFadeDistance+20), 1.0f, 0.0f);

	if (flFadeAlpha <= 0)
		return;

	float flTreeAlpha = 1.0f;
	if (DigitanksGame()->GetTerrain()->GetBit(CTerrain::WorldToArraySpace(GetGlobalOrigin().x), CTerrain::WorldToArraySpace(GetGlobalOrigin().y), TB_TREE))
		flTreeAlpha = 0.3f;

	CRenderingContext r(GameServer()->GetRenderer(), true);
	if (DigitanksGame()->ShouldRenderFogOfWar())
		r.UseFrameBuffer(DigitanksGame()->GetDigitanksRenderer()->GetVisibilityMaskedBuffer());
	r.SetDepthMask(false);
	r.UseMaterial(s_hTendrilBeam);

	r.SetUniform("flTime", (float)GameServer()->GetGameTime());
	r.SetUniform("iTexture", 0);
	r.SetUniform("flAlpha", flFadeAlpha * flTreeAlpha);

	Color clrTeam = GetPlayerOwner()?GetPlayerOwner()->GetColor():Color(255,255,255,255);
	clrTeam = (Vector(clrTeam) + Vector(1,1,1))/2;

	if (m_flTendrilGrowthStartTime > 0)
	{
		float flTotalSize = (float)m_aTendrils.size() + GetBoundingRadius();

		for (size_t i = 0; i < m_aTendrils.size(); i++)
		{
			if (i < m_aTendrils.size() - 15)
				continue;

			const CTendril* pTendril = &m_aTendrils[i];

			float flGrowthLength = RemapVal(flGrowthTime, 0, GROWTH_TIME, pTendril->m_flLength-flTotalSize, pTendril->m_flLength);

			if (flGrowthLength < 0)
				continue;

			Vector vecDestination = GetGlobalOrigin() + (pTendril->m_vecEndPoint - GetGlobalOrigin()).Normalized() * flGrowthLength;

			Vector vecPath = vecDestination - GetGlobalOrigin();
			vecPath.y = 0;

			float flDistance = vecPath.Length2D();
			Vector vecDirection = vecPath.Normalized();
			size_t iSegments = (size_t)(flDistance/3);

			r.SetUniform("flSpeed", pTendril->m_flSpeed);

			clrTeam.SetAlpha(105);

			CRopeRenderer oRope(GameServer()->GetRenderer(), s_hTendrilBeam, DigitanksGame()->GetTerrain()->GetPointHeight(GetGlobalOrigin()) + Vector(0, 0, 1), 1.0f);
			oRope.SetColor(clrTeam);
			oRope.SetTextureScale(pTendril->m_flScale);
			oRope.SetTextureOffset(pTendril->m_flOffset);
			oRope.SetForward(Vector(0, 0, -1));

			for (size_t i = 1; i < iSegments; i++)
			{
				clrTeam.SetAlpha((int)RemapVal((float)i, 1, (float)iSegments, 100, 30));
				oRope.SetColor(clrTeam);

				float flCurrentDistance = ((float)i*flDistance)/iSegments;
				oRope.AddLink(DigitanksGame()->GetTerrain()->GetPointHeight(GetGlobalOrigin() + vecDirection*flCurrentDistance) + Vector(0, 0, 1));
			}

			oRope.Finish(DigitanksGame()->GetTerrain()->GetPointHeight(vecDestination) + Vector(0, 0, 1));
		}
	}
}
Exemplo n.º 14
0
void StoneMine::Update(const float dtime)
{
    m_line.Update(dtime * v_numzpr.GetFloat(), m_stone, v_numworks.GetInt());

}
Exemplo n.º 15
0
void RabidEngine::OnIdle()
{
  g_timer.Update();
  const float dt = g_timer.GetTimeChange();

  g_console->Update(dt);




  Transformation view;
  view.Rotate().FromEulerXYZ(cl_camrotx.GetFloat(),
                             cl_camroty.GetFloat(),
                             cl_camrotz.GetFloat());

  // move
  const Vector3f forward = -view.Rotate().GetColumn(2);
  const Vector3f right   =  view.Rotate().GetColumn(0);

  const float vel = 50.0 * dt;
  if(keyState[B_FORWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + forward.z * vel);
  }
  if(keyState[B_BACKWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -forward.z * vel);
  }
  if(keyState[B_RIGHT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + right.z * vel);
  }
  if(keyState[B_LEFT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -right.z * vel);
  }
  if(keyState[B_RENDER])
  {
    done.Set("0");
    keyState[B_RENDER] = 0;
  }
  if(keyState[B_LIGHT_MODE])
  {
    if(r_resid.GetBool())
      r_resid.Set("0");
    else
      r_resid.Set("1");
    keyState[B_LIGHT_MODE] = 0;
  }
  if(keyState[B_TOGGLE_BRIGHTEST])
  {
    if(r_showbrightest.GetBool())
      r_showbrightest.Set("0");
    else
      r_showbrightest.Set("1");
    keyState[B_TOGGLE_BRIGHTEST] = 0;
  }






  static int pass;
  static int surf = -1;
  static int brightest;
  static int patches;
  if(done.GetBool())
  {
  }
  else
  {
    if(pass == 0)
    {
      // clear accumulation buffers
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
//          if(surfaces[i]->GetType() != S_LIGHT)
//            surfaces[i]->ClearAccum();
      }
    }


    if(surf >= (int)surfaces.Size())
    {
      surf = -2;
      pass++;
      done.Set("1");
    }
    else if(surf == -1)
    {
      // Find Brightest Surface
      float maxPower = 0.0;
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
        float p = surfaces[i]->GetPower();
        if(p > maxPower)
        {
          brightest = i;
          maxPower = p;
        }
      }

      for(int i = 0; i < lights.Size(); i++)
        delete lights[i];
      lights.Resize(0);

      surfaces[brightest]->CreateLights(lights);
    }
    else
    {
      Surface* lsurf = surfaces[surf];

      bool skip = false;
      // lights can't receive light
      if(lsurf->GetType() == S_LIGHT)
        skip = true;

      // surface can light itself
      if(!skip && surf == brightest)
      {
        if(r_resid.GetBool())
          lsurf->CopyResidualToLightMap();
        skip = true;
      }



      if(!skip)
      {
        // Render each sub-light's contribution
        for(unsigned int l = 0; l < lights.Size(); l++)
        {
          Vector3f& p = lights[l]->p;
          Vector3f& d = lights[l]->d;
          float     I = lights[l]->I;

          // light is on wrong side of surface
          if(Dot(p - lsurf->c, lsurf->N) < 0.1)
            continue;

          g_renderer->SetLight(0, p.x, p.y, p.z);
          g_renderer->SetLightDir(0, d.x, d.y, d.z);
          g_renderer->SetLightIntensity(0, I);
          g_renderer->SetLightFraction(0, 1.0 / (float)lights.Size());

          lsurf->Frame(p);
          lsurf->CreateLightMap(p, d, surfaces);
          lsurf->AccumulateResidualLight();
          lsurf->AccumulateLight();
          g_renderer->SetViewMatrix(0);
          patches += lsurf->GetNumPatches();
        }

        r_resid.Set(r_resid.GetBool() ? "1" : "0");
      }
    }
    surf++;
  }


  if(r_resid.Changed())
  {
    for(int i = 0; i < surfaces.Size(); i++)
    {
      Surface* lsurf = surfaces[i];
      lsurf->Frame(lsurf->c + lsurf->N*10.0);

      if(r_resid.GetBool())
        lsurf->CopyResidualToLightMap();
      else
        lsurf->CopyAccumToLightMap();
    }
  }






  // Render normal view
  view.Translate() = Vector3f(cl_camx.GetFloat(),
                              cl_camy.GetFloat(),
                              cl_camz.GetFloat());

  view = view.Inverse();
  g_renderer->SetViewport(0,0, GetWidth(),GetHeight());
  g_renderer->SetViewMatrix(view);
  g_renderer->SetProjectionMatrix(0);
  g_renderer->SetClearColor(0.25f, 0.25f, 0.35f, 1.0f);
  g_renderer->BindMaterial(0);
  g_renderer->Clear(R_COLOR_BUFFER | R_DEPTH_BUFFER);
  g_renderer->SetColor(1,1,1);


  int bsurf = 0;
  float maxPower = 0.0;
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    float p = surfaces[i]->GetPower();
    if(p > maxPower)
    {
      bsurf = i;
      maxPower = p;
    }
  }


  // draw all surfaces normally
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    if(r_showbrightest.GetBool())
    {
      if(i == bsurf)
        g_renderDevice->SetColor(1.0, 1.0, 0.7);
      else
        g_renderDevice->SetColor(1,1,1);
    }
    surfaces[i]->Render();
  }

  g_console->Draw(g_renderer);

  g_renderer->DrawTextP(15, 50, 16, r_resid.GetBool() ? "Residual" : "Accumulation");
  g_renderer->DrawTextP(15, 30, 16, "Step: %d", pass);
  g_renderer->DrawTextP(15, 10, 16, "Patches: %d", patches);
  g_materialSystem->BindMaterial(logo);
  g_renderer->DrawRect(GetWidth()-200, 0, 200, 50, 0,0,1,1);

  g_renderer->Flip();
}
Exemplo n.º 16
0
// Can this lesson be displayed right now?
bool CPlayer::Instructor_IsLessonValid(const CLessonProgress* pLessonProgress)
{
    TAssert(pLessonProgress);
    if (!pLessonProgress)
        return true;

    CLesson* pLesson = GameWindow()->GetInstructor()->GetLesson(pLessonProgress->m_sLessonName);

    TAssert(pLesson);
    if (!pLesson)
        return true;

    if (Instructor_IsLessonLearned(pLessonProgress))
        return false;

    if (pLessonProgress->m_flLastTimeShowed != 0 && GameServer()->GetGameTime() < pLessonProgress->m_flLastTimeShowed + lesson_downtime.GetFloat())
        return false;

    for (size_t i = 0; i < pLesson->m_asPrerequisites.size(); i++)
    {
        if (!Instructor_IsLessonLearned(&m_apLessonProgress[pLesson->m_asPrerequisites[i]]))
            return false;
    }

    if (pLesson->m_pfnConditions)
        return pLesson->m_pfnConditions(this, pLesson);
    else
        return true;
}
Exemplo n.º 17
0
void CPlayer::Instructor_Think()
{
    if (!GameWindow()->GetInstructor()->IsInitialized())
        GameWindow()->GetInstructor()->Initialize();

    if (!m_apLessonProgress.size() && GameWindow()->GetInstructor()->GetLessons().size())
    {
        for (auto it = GameWindow()->GetInstructor()->GetLessons().begin(); it != GameWindow()->GetInstructor()->GetLessons().end(); it++)
        {
            CLessonProgress& oProgress = m_apLessonProgress[it->first];
            oProgress.m_sLessonName = it->first;
        }
    }

    if (m_flLastLesson < 0 || GameServer()->GetGameTime() > m_flLastLesson + lesson_nexttime.GetFloat())
    {
        m_apLessonPriorities.clear();

        for (auto it = m_apLessonProgress.begin(); it != m_apLessonProgress.end(); it++)
        {
            CLessonProgress* pLessonProgress = &it->second;
            CLesson* pLesson = GameWindow()->GetInstructor()->GetLesson(it->first);

            if (!pLesson->m_bRotation)
                continue;

            if (!pLesson)
            {
                TMsg("Couldn't find lesson '" + it->first + "'\n");
                continue;
            }

            if (pLesson->m_iLessonType == CLesson::LESSON_ENVIRONMENT)
                continue;

            if (!Instructor_IsLessonValid(pLessonProgress))
                continue;

            m_apLessonPriorities.push_back(pLessonProgress);
            push_heap(m_apLessonPriorities.begin(), m_apLessonPriorities.end(), LessonPriorityCompare);
        }

        if (lesson_debug.GetBool() && m_apLessonPriorities.size())
        {
            TMsg("Instructor: Lesson priorities:\n");
            for (size_t j = 0; j < m_apLessonPriorities.size(); j++)
            {
                CLesson* pLesson = GameWindow()->GetInstructor()->GetLesson(m_apLessonPriorities[j]->m_sLessonName);
                TMsg(tsprintf(" %d - " + m_apLessonPriorities[j]->m_sLessonName + " - %d\n", j + 1, pLesson->m_iPriority));
            }
        }

        CLessonProgress* pBestLesson = Instructor_GetBestLesson();

        if (pBestLesson)
        {
            if (lesson_debug.GetBool())
            {
                CLesson* pLesson = GameWindow()->GetInstructor()->GetLesson(pBestLesson->m_sLessonName);
                TMsg(tsprintf("Instructor: New lesson: " + pBestLesson->m_sLessonName + " Priority: %d\n", pLesson->m_iPriority));
            }

            m_flLastLesson = GameServer()->GetGameTime();
            pBestLesson->m_flLastTimeShowed = GameServer()->GetGameTime();

            GameWindow()->GetInstructor()->DisplayLesson(pBestLesson->m_sLessonName);
        }
    }
}