void CWeaponBuildTool::PrimaryAttack()
{
	// Place a block
#ifndef CLIENT_DLL

	if ( ( gpGlobals->curtime - lastTime ) > 1.0f )
	{
		CBasePlayer *player = (CBasePlayer *) GetOwner();

		trace_t tr;
		GetPlayerTraceLine( tr, player, lfm_build_tool_distance.GetInt() );

		const Vector& end = tr.endpos;
		Vector pos = Vector( end );
		SnapVector( pos );

		//QAngle angles = player->EyeAngles();
		QAngle angles;
		VectorAngles( tr.plane.normal, angles );
		SnapAngle( angles, SNAP_ANGLE_NONE );

		CBaseEntity *ent = SpawnBlock( 0, player->GetTeamNumber(), pos, angles, this );
		if ( ent->IsBlock() )
		{
			CBlockBase *block = dynamic_cast< CBlockBase * > ( ent );
			block->Freeze( player, FROZEN_BY_PLAYER );
		}

		lastTime = gpGlobals->curtime;
	}

#endif // SERVER
}
Exemplo n.º 2
0
void SSParticles::UpdateUserLayer( const float deltaTime ) {
	int ParticleCount = 0;
	for (int i = 0; i < MAX_PARTICLE_BLOCKS; i++) {
		if (m_ParticleBlocks[i].IsActive) {
			for (int k = 0; k < PARTICLE_BLOCK_COUNT; k++) {
				glm::vec4 temp = m_ParticleBlocks[i].Particles[k].VelocityTTL;
				m_ParticleBlocks[i].Particles[k].Pos += glm::vec4(temp.x, temp.y, temp.z, 0) * 0.05f * deltaTime;

				ApplyGravity(m_ParticleBlocks[i].Particles[k]);
				if (glm::any(glm::greaterThan(glm::abs(m_ParticleBlocks[i].Particles[k].Pos), glm::vec4(1, 1, 1, 10)))) {
					m_ParticleBlocks[i].Particles[k].VelocityTTL *= -1;
				}
			}
			//kill particle blocks
			m_ParticleBlocks[i].TTL -= deltaTime;
			if (m_ParticleBlocks[i].TTL <= 0) {
				m_ParticleBlocks[i].IsActive = false;
				DeallocateParticles(m_ParticleBlocks[i].Particles);
				m_ParticleBlocks[i].Particles = nullptr;
				//printf("Killed a block of particles\n");
			}
		}
	}
	//spawn more particles
	m_SpawnTimer += deltaTime;
	float test = BLOCK_SPAWN_TIME;
	if (m_SpawnTimer > BLOCK_SPAWN_TIME) {
		for (int i = 0; i < BLOCK_SPAWN_AMOUNT; i++)
			SpawnBlock();
		m_SpawnTimer = 0;
	}
	//update vertex buffer
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
	for (int i = 0; i < MAX_PARTICLE_BLOCKS; i++) {
		if (m_ParticleBlocks[i].IsActive) {
			glBufferSubData(GL_ARRAY_BUFFER, i * PARTICLE_BLOCK_SIZE, PARTICLE_BLOCK_SIZE, m_ParticleBlocks[i].Particles);
			ParticleCount += PARTICLE_BLOCK_COUNT;
		}
	}
	glBindVertexArray(m_VAO);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	m_RenderProgram.Apply();
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
	glBindVertexArray(m_VAO);
	glPointSize(1.0f);
	glDrawArrays(GL_POINTS, 0, ParticleCount);

	//profiling
	m_ProfileTimer += deltaTime;
	if (m_ProfileTimer > 5) {
		Profiler::ProfilerManager::GetInstance().PrintAveragesMilliSeconds();
		m_ProfileTimer = 0;
	}
	Profiler::ProfilerManager::GetInstance().ResetFrame();
}