/*
================
CmdSystemEx::ExecuteSingleCmd
================
*/
void CmdSystemEx::ExecuteSingleCmd( const char *cmd ) {
	CmdArgs args(cmd);
	if ( !args.Argc() )
		return;

	const char *arg0 = args.Argv(0);
	int index = cmdList.Find( arg0 );
	if ( index != -1 ) {
		ConsoleCmd &cCmd = cmdList[index];
		if( cCmd.flags & CMD_DEVELOPER && !com_developer.GetBool() ) {
			User::Warning( "Developer mode is not active!" );
			return;
		}
		if( cCmd.flags & CMD_CHEAT && !net_allowCheats.GetBool() ) {
			User::Warning( Format( "$* is cheat protected" ) << cmdList.GetKey(index) );
			return;
		}
		if ( cCmd.usage->minArguments > (args.Argc()-1) )
			cCmd.usage->ShowUsage();
		else
			cCmd.func(args);
		return;
	}
	if ( !cvarSystemEx->OnCommand(args) )
		User::Warning( Format( "Unknown command '$*'.\n" ) << arg0 );
}
Example #2
0
void CCamera::Think()
{
	bool bFreeMode = cam_free.GetBool();
	if (bFreeMode != m_bFreeMode)
	{
		m_vecFreeCamera = GetCameraPosition();
		m_angFreeCamera = VectorAngles((GetCameraTarget() - GetCameraPosition()).Normalized());
		m_bFreeMode = bFreeMode;
		CApplication::Get()->SetMouseCursorEnabled(!m_bFreeMode);
	}

	if (m_bFreeMode)
	{
		Vector vecForward, vecRight;
		AngleVectors(m_angFreeCamera, &vecForward, &vecRight, NULL);

		m_vecFreeCamera += vecForward * m_vecFreeVelocity.x * GameServer()->GetFrameTime() * 20;
		m_vecFreeCamera -= vecRight * m_vecFreeVelocity.z * GameServer()->GetFrameTime() * 20;
	}
	else
	{
		if (shrink_frustum.GetBool())
			GameServer()->GetRenderer()->FrustumOverride(GetCameraPosition(), GetCameraTarget(), GetCameraFOV()-1, GetCameraNear()+1, GetCameraFar()-1);
	}
}
Example #3
0
File: tree.cpp Project: BSVino/SMAK
void CTreeNode::CExpandButton::Paint(float x, float y, float w, float h)
{
	MakeQuad();

	::CRenderingContext r(nullptr, true);

	if ((w < 0) ^ (h < 0))
		r.SetBackCulling(false);

	r.UseMaterial(m_hMaterial);

	r.SetBlend(BLEND_ALPHA);
	r.SetUniform("iBorder", 0);
	r.SetUniform("bHighlight", false);
	r.SetUniform("vecColor", Color(255, 255, 255));
	r.SetUniform("bDiffuse", true);
	r.SetUniform("bTexCoords", false);

	r.SetUniform("vecDimensions", Vector4D(-w/2, -h/2, w, h));

	r.Translate(Vector((float)x+w/2, (float)y+h/2, 0));
	r.Rotate(m_flExpandedCurrent*90-90, Vector(0, 0, 1));

	// Hehe.
	if (glgui_spinnyarrows.GetBool())
		r.Rotate((float)RootPanel()->GetTime()*200, Vector(0, 0, 1));

	r.BeginRenderVertexArray(s_iQuad);
	r.SetPositionBuffer((size_t)0u, 24);
	r.SetTexCoordBuffer(12, 24);
	r.SetCustomIntBuffer("iVertex", 1, 20, 24);
	r.EndRenderVertexArray(6);
}
Example #4
0
void CCamera::KeyDown(int c)
{
	if (CVar::GetCVarBool("cheats") && c == 'Z')
	{
		cam_free.SetValue(m_bFreeMode?_T("off"):_T("on"));

		if (lock_freemode_frustum.GetBool())
		{
			if (m_bFreeMode)
				GameServer()->GetRenderer()->FrustumOverride(GetCameraPosition(), GetCameraTarget(), GetCameraFOV(), GetCameraNear(), GetCameraFar());
			else
				GameServer()->GetRenderer()->CancelFrustumOverride();
		}
	}

	if (m_bFreeMode)
	{
		if (c == 'W')
			m_vecFreeVelocity.x = 10.0f;
		if (c == 'S')
			m_vecFreeVelocity.x = -10.0f;
		if (c == 'D')
			m_vecFreeVelocity.z = 10.0f;
		if (c == 'A')
			m_vecFreeVelocity.z = -10.0f;
	}
}
Example #5
0
bool CConsole::IsVisible()
{
	if (developer.GetBool() && m_bBackground)
		return true;

	return BaseClass::IsVisible();
}
Example #6
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");
    }
}
Example #7
0
bool CConsole::IsCursorListener()
{
	// Don't interfere with mouse events, we're just showing an overlay.
	if (developer.GetBool() && !BaseClass::IsVisible())
		return false;

	return BaseClass::IsCursorListener();
}
Example #8
0
bool CVar::GetCVarBool(tstring sName)
{
	CVar* pVar = FindCVar(sName);
	if (!pVar)
		return false;

	return pVar->GetBool();
}
Example #9
0
CConsole* CApplication::GetConsole()
{
	if (m_pConsole == NULL)
	{
		m_pConsole = new CConsole();

		if (developer.GetBool())
			TMsg("Developer mode ON.\n");
	}

	return m_pConsole;
}
Example #10
0
void CALLBACK GLDebugCallback(GLenum iSource, GLenum iType, GLuint id, GLenum iSeverity, GLsizei iLength, const GLchar* pszMessage, GLvoid* pUserParam)
{
	if (iType != GL_DEBUG_TYPE_PERFORMANCE_ARB)
	{
		TAssert(iSeverity != GL_DEBUG_SEVERITY_HIGH_ARB);
		TAssert(iSeverity != GL_DEBUG_SEVERITY_MEDIUM_ARB);
	}

	if (gl_debug.GetBool())
	{
		tstring sMessage = "OpenGL Debug Message (";

		if (iSource == GL_DEBUG_SOURCE_API_ARB)
			sMessage += "Source: API ";
		else if (iSource == GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
			sMessage += "Source: Window System ";
		else if (iSource == GL_DEBUG_SOURCE_SHADER_COMPILER_ARB)
			sMessage += "Source: Shader Compiler ";
		else if (iSource == GL_DEBUG_SOURCE_THIRD_PARTY_ARB)
			sMessage += "Source: Third Party ";
		else if (iSource == GL_DEBUG_SOURCE_APPLICATION_ARB)
			sMessage += "Source: Application ";
		else if (iSource == GL_DEBUG_SOURCE_OTHER_ARB)
			sMessage += "Source: Other ";

		if (iType == GL_DEBUG_TYPE_ERROR_ARB)
			sMessage += "Type: Error ";
		else if (iType == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
			sMessage += "Type: Deprecated Behavior ";
		else if (iType == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
			sMessage += "Type: Undefined Behavior ";
		else if (iType == GL_DEBUG_TYPE_PORTABILITY_ARB)
			sMessage += "Type: Portability ";
		else if (iType == GL_DEBUG_TYPE_PERFORMANCE_ARB)
			sMessage += "Type: Performance ";
		else if (iType == GL_DEBUG_TYPE_OTHER_ARB)
			sMessage += "Type: Other ";

		if (iSeverity == GL_DEBUG_SEVERITY_HIGH_ARB)
			sMessage += "Severity: High) ";
		else if (iSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB)
			sMessage += "Severity: Medium) ";
		else if (iSeverity == GL_DEBUG_SEVERITY_LOW_ARB)
			sMessage += "Severity: Low) ";

		sMessage += convertstring<GLchar, tchar>(pszMessage) + "\n";

		TMsg(convertstring<GLchar, tchar>(sMessage).c_str());
	}
}
Example #11
0
void CParticleSystemLibrary::Render()
{
	TPROF("CParticleSystemLibrary::Render");

	if (!r_particles.GetBool())
		return;

	MakeQuad();

	CParticleSystemLibrary* pPSL = Get();

	if (!pPSL->m_apInstances.size())
		return;

	tmap<size_t, CSystemInstance*>::iterator it;

	if (true)
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);
		c.UseProgram("particle");
		c.SetUniform("bDiffuse", true);
		c.SetUniform("iDiffuse", 0);

		for (it = pPSL->m_apInstances.begin(); it != pPSL->m_apInstances.end(); it++)
		{
			CSystemInstance* pInstance = (*it).second;
			pInstance->Render(&c, false);
		}
	}

	if (true)
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);
		c.UseProgram("particle");
		c.SetUniform("bDiffuse", true);
		c.SetUniform("iDiffuse", 0);
		c.SetDepthMask(false);

		for (it = pPSL->m_apInstances.begin(); it != pPSL->m_apInstances.end(); it++)
		{
			CSystemInstance* pInstance = (*it).second;
			pInstance->Render(&c, true);
		}
	}

	CRenderingContext::DebugFinish();
}
Example #12
0
void CConsole::Paint(float x, float y, float w, float h)
{
	if (!CApplication::Get()->IsOpen())
		return;

	if (!BaseClass::IsVisible() && developer.GetBool())
	{
		int iAlpha = m_hOutput->GetAlpha();
		m_hOutput->SetAlpha(100);
		m_hOutput->Paint();
		m_hOutput->SetAlpha(iAlpha);
		return;
	}

	if (!BaseClass::IsVisible())
		return;

	glgui::CRootPanel::PaintRect(x, y, w, h, Color(0, 0, 0, 200), 1, true);

	BaseClass::Paint(x, y, w, h);
}
Example #13
0
void CInstructor::DisplayLesson(tstring sLesson)
{
    if (!lesson_enable.GetBool())
        return;

    if (!m_bActive)
        return;

    if (sLesson.length() == 0 || m_apLessons.find(sLesson) == m_apLessons.end())
    {
        if (m_apLessons[m_sCurrentLesson] && m_apLessons[m_sCurrentLesson]->m_bKillOnFinish)
            SetActive(false);

        if (m_pCurrentPanel)
            HideLesson();

        return;
    }

    if (m_pCurrentPanel)
        HideLesson();

    m_sCurrentLesson = sLesson;

    if (Game() && m_sLastLesson != m_sCurrentLesson)
        Game()->OnDisplayLesson(sLesson);

    m_sLastLesson = m_sCurrentLesson;

    CLesson* pLesson = m_apLessons[sLesson];

    CPlayer *pLocalPlayer = Game()->GetLocalPlayer();
    if (pLesson->m_iLearningMethod == CLesson::LEARN_DISPLAYING)
        pLocalPlayer->Instructor_LessonLearned(sLesson);

    m_pCurrentPanel = new CLessonPanel(pLesson);
    RootPanel()->AddControl(m_pCurrentPanel, true);

    CallOutput("OnDisplay");
}
void CRenderingContext::EndRenderVertexArrayIndexed(size_t iBuffer, size_t iVertices)
{
	CRenderContext& oContext = GetContext();

	if (!oContext.m_bProjectionUpdated)
		SetUniform("mProjection", oContext.m_mProjection);

	if (!oContext.m_bViewUpdated)
		SetUniform("mView", oContext.m_mView);

	if (!oContext.m_bTransformUpdated)
		SetUniform("mGlobal", oContext.m_mTransformations);

	oContext.m_bProjectionUpdated = oContext.m_bViewUpdated = oContext.m_bTransformUpdated = true;

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBuffer);
	glDrawElements(r_wireframe.GetBool()?GL_LINES:GL_TRIANGLES, iVertices, GL_UNSIGNED_INT, nullptr);

	glDisableVertexAttribArray(m_pShader->m_iPositionAttribute);
	for (size_t i = 0; i < MAX_TEXTURE_CHANNELS; i++)
	{
		if (m_pShader->m_aiTexCoordAttributes[i] != ~0)
			glDisableVertexAttribArray(m_pShader->m_aiTexCoordAttributes[i]);
	}
	if (m_pShader->m_iNormalAttribute != ~0)
		glDisableVertexAttribArray(m_pShader->m_iNormalAttribute);
	if (m_pShader->m_iTangentAttribute != ~0)
		glDisableVertexAttribArray(m_pShader->m_iTangentAttribute);
	if (m_pShader->m_iBitangentAttribute != ~0)
		glDisableVertexAttribArray(m_pShader->m_iBitangentAttribute);
	if (m_pShader->m_iColorAttribute != ~0)
		glDisableVertexAttribArray(m_pShader->m_iColorAttribute);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
Example #15
0
void CGameServerNetwork::UpdateNetworkVariables(int iClient, bool bForceAll)
{
	if (!GameNetwork()->IsConnected())
		return;

	double flTime = GameServer()->GetGameTime();

	size_t iMaxEnts = GameServer()->GetMaxEntities();
	for (size_t i = 0; i < iMaxEnts; i++)
	{
		CBaseEntity* pEntity = CBaseEntity::GetEntity(i);
		if (!pEntity)
			continue;

		const tchar* pszClassName = pEntity->GetClassName();

		CEntityRegistration* pRegistration = NULL;
		do
		{
			pRegistration = pEntity->GetRegisteredEntity(pszClassName);

			TAssert(pRegistration);
			if (!pRegistration)
				break;

			size_t iNetVarsSize = pRegistration->m_aNetworkVariables.size();
			for (size_t j = 0; j < iNetVarsSize; j++)
			{
				CNetworkedVariableData* pVarData = &pRegistration->m_aNetworkVariables[j];
				CNetworkedVariableBase* pVariable = pVarData->GetNetworkedVariableBase(pEntity);

				if (!bForceAll)
				{
					if (!pVariable->IsDirty())
						continue;

					if (flTime - pVariable->m_flLastUpdate < pVarData->m_flUpdateInterval)
						continue;
				}

				// For one, m_flLastUpdate needs to be a double
				pVariable->m_flLastUpdate = (float)flTime;
				// For two, it's shit.
				TUnimplemented();
				// Try some testing or something.

				CNetworkParameters p;
				p.ui1 = pEntity->GetHandle();

				size_t iDataSize;
				void* pValue = pVariable->Serialize(iDataSize);

				if (net_replication_debug.GetBool())
				{
					if (iDataSize >= 4)
						TMsg(tstring("Updating ") + pVarData->GetName() + sprintf(tstring(" (%x) (%f) (%d)\n"), *(unsigned int*)pValue, *(float*)pValue, *(int*)pValue));
					else
						TMsg(tstring("Updating ") + pVarData->GetName() + "\n");
				}

				p.CreateExtraData(iDataSize + strlen(pVarData->GetName())+1);
				strcpy((char*)p.m_pExtraData, pVarData->GetName());
				memcpy((unsigned char*)(p.m_pExtraData) + strlen(pVarData->GetName())+1, pValue, iDataSize);

				// UV stands for UpdateValue
				GameNetwork()->CallFunctionParameters(iClient, "UV", &p);

				// Only reset the dirty flag if all clients got the message.
				if (iClient == NETWORK_TOCLIENTS)
					pVariable->SetDirty(false);
			}

			pszClassName = pRegistration->m_pszParentClass;
		} while (pszClassName);
	}
}
Example #16
0
File: ao.cpp Project: ezhangle/SMAK
void CAOGenerator::Generate()
{
    double flTimeStarted = Application()->GetTime();

    if (!m_eAOMethod)
        return;

    m_pWorkListener->BeginProgress();
    m_pWorkListener->SetAction("Setting up", 0);

    m_bIsGenerating = true;
    m_bStopGenerating = false;
    m_bDoneGenerating = false;
    m_bIsBleeding = false;

    m_flLowestValue = -1;
    m_flHighestValue = 0;

    if (SMAKWindow())
        SMAKWindow()->ClearDebugLines();

    memset(&m_bPixelMask[0], 0, m_iWidth*m_iHeight*sizeof(bool));

    if (m_eAOMethod == AOMETHOD_SHADOWMAP)
    {
        ShadowMapSetupScene();
        GenerateShadowMaps();
    }
    else
    {
        if (m_eAOMethod == AOMETHOD_RENDER)
            RenderSetupScene();
        // In AO debug mode we need this to do the debug rendering, so do it anyways.
        else if (ao_debug.GetBool())
            RenderSetupScene();

        GenerateByTexel();
    }

    size_t i;

    m_pWorkListener->SetAction("Averaging reads", m_iWidth*m_iHeight);

    // Average out all of the reads.
    for (i = 0; i < m_iWidth*m_iHeight; i++)
    {
        // Don't immediately return, just skip this loop. We have cleanup work to do.
        if (m_bStopGenerating)
            break;

        if (m_eAOMethod == AOMETHOD_SHADOWMAP)
            m_avecShadowValues[i] = Vector(m_avecShadowValues[i].x, m_avecShadowValues[i].x, m_avecShadowValues[i].x);

        if (m_aiShadowReads[i])
            m_avecShadowValues[i] /= (float)m_aiShadowReads[i];
        else
            m_avecShadowValues[i] = Vector(0,0,0);

        m_pWorkListener->WorkProgress(i);
    }

    if (m_eAOMethod == AOMETHOD_RENDER || m_eAOMethod == AOMETHOD_SHADOWMAP)
    {
        if (m_eAOMethod == AOMETHOD_SHADOWMAP)
        {
            m_oAOFB.Destroy();
            CRenderer::UnloadVertexDataFromGL(m_iScene);
            CRenderer::UnloadVertexDataFromGL(m_iSceneDepth);
        }
        else
        {
            for (size_t i = 0; i < m_aiSceneMaterials.size(); i++)
                CRenderer::UnloadVertexDataFromGL(m_aiSceneMaterials[i]);

            m_oRenderFB.Destroy();
        }
    }

    // Somebody get this ao some clotters and morphine, STAT!
    m_bIsBleeding = true;
    if (!m_bStopGenerating)
        Bleed();
    m_bIsBleeding = false;

    if (!m_bStopGenerating)
        m_bDoneGenerating = true;
    m_bIsGenerating = false;

    // One last call to let them know we're done.
    m_pWorkListener->EndProgress();

    double flTimeEnded = Application()->GetTime();
    double flTimePassed = flTimeEnded - flTimeStarted;
    TMsg(sprintf("AO generation completed in %f seconds\n", flTimePassed));
}
Example #17
0
File: ao.cpp Project: ezhangle/SMAK
void CAOGenerator::GenerateShadowMaps()
{
    double flProcessSceneRead = 0;
    double flProgress = 0;

    size_t iShadowMapSize = 1024;

    // A frame buffer for holding the depth buffer shadow render
    CFrameBuffer oDepthFB = SMAKRenderer()->CreateFrameBuffer(iShadowMapSize, iShadowMapSize, (fb_options_e)(FB_DEPTH_TEXTURE|FB_RENDERBUFFER)); // RB unused

    // A frame buffer for holding the UV layout once it is rendered flat with the shadow
    CFrameBuffer oUVFB = SMAKRenderer()->CreateFrameBuffer(m_iWidth, m_iHeight, (fb_options_e)(FB_TEXTURE|FB_LINEAR|FB_DEPTH)); // Depth unused

    // A frame buffer for holding the completed AO map
    m_oAOFB = SMAKRenderer()->CreateFrameBuffer(m_iWidth, m_iHeight, (fb_options_e)(FB_TEXTURE|FB_TEXTURE_HALF_FLOAT|FB_LINEAR|FB_DEPTH)); // Depth unused

    CRenderingContext c(SMAKRenderer());

    c.UseFrameBuffer(&m_oAOFB);

    c.ClearColor(Color(0, 0, 0, 0));

    c.SetDepthFunction(DF_LEQUAL);
    c.SetDepthTest(true);
    c.SetBackCulling(false);

    Matrix4x4 mBias(
        0.5f, 0.0f, 0.0f, 0.0f,
        0.0f, 0.5f, 0.0f, 0.0f,
        0.0f, 0.0f, 0.5f, 0.0f,
        0.5f, 0.5f, 0.5f, 1.0f); // Bias from [-1, 1] to [0, 1]

    AABB oBox = m_pScene->m_oExtends;
    Vector vecCenter = oBox.Center();
    float flSize = oBox.Size().Length();	// Length of the box's diagonal

    Matrix4x4 mLightProjection = Matrix4x4::ProjectOrthographic(-flSize/2, flSize/2, -flSize/2, flSize/2, 1, flSize*2);

    size_t iSamples = (size_t)sqrt((float)m_iSamples);

    m_pWorkListener->SetAction("Taking exposures", m_iSamples);

    for (size_t x = 0; x <= iSamples; x++)
    {
        float flPitch = -asin(RemapVal((float)x, 0, (float)iSamples, -1, 1)) * 90 / (M_PI/2);

        for (size_t y = 0; y < iSamples; y++)
        {
            if (x == 0 || x == iSamples)
            {
                // Don't do a bunch of samples from the same spot on the poles.
                if (y != 0)
                    continue;
            }

            float flYaw = RemapVal((float)y, 0, (float)iSamples, -180, 180);

            // Randomize the direction a tad to help fight moire
            Vector vecDir = AngleVector(EAngle(flPitch+RandomFloat(-1, 1)/2, flYaw+RandomFloat(-1, 1)/2, 0));
            Vector vecLightPosition = vecDir*flSize + vecCenter;	// Puts us twice as far from the closest vertex

            if (ao_debug.GetInt() > 1)
                SMAKWindow()->AddDebugLine(vecLightPosition, vecLightPosition-vecDir);

            Matrix4x4 mLightView = Matrix4x4::ConstructCameraView(vecLightPosition, (vecCenter-vecLightPosition).Normalized(), Vector(0, 1, 0));

            c.SetProjection(mLightProjection);
            c.SetView(mLightView);

            // If we're looking from below and ground occlusion is on, don't bother with this render.
            if (!(flPitch < -10 && m_bGroundOcclusion))
            {
                c.UseProgram("model");
                c.UseFrameBuffer(&oDepthFB);
                c.SetViewport(Rect(0, 0, iShadowMapSize, iShadowMapSize));
                c.SetBackCulling(false);
                c.ClearDepth();

                c.BeginRenderVertexArray(m_iSceneDepth);
                c.SetPositionBuffer((size_t)0, 8*sizeof(float));
                c.SetNormalsBuffer((size_t)3*sizeof(float), 8*sizeof(float));
                c.SetTexCoordBuffer((size_t)6*sizeof(float), 8*sizeof(float));
                c.EndRenderVertexArray(m_iSceneDepthVerts);

                c.UseFrameBuffer(nullptr);

                if (ao_debug.GetBool())
                {
                    CRenderingContext c(SMAKRenderer());
                    c.SetViewport(Rect(0, 0, iShadowMapSize/2, iShadowMapSize/2));

                    DrawTexture(oDepthFB.m_iDepthTexture, 1, c);
                }
            }

            Matrix4x4 mTextureMatrix = mBias*mLightProjection*mLightView;

            {
                CRenderingContext c(SMAKRenderer(), true);

                c.UseFrameBuffer(&oUVFB);
                c.SetViewport(Rect(0, 0, m_iWidth, m_iHeight));
                c.ClearColor(Color(0, 0, 0, 0));
                c.ClearDepth();

                c.UseProgram("flat_shadow");
                c.SetUniform("mBiasedLightMatrix", mTextureMatrix);
                c.SetUniform("iShadowMap", 0);
                c.SetUniform("vecLightNormal", -vecDir);
                c.SetUniform("bOccludeAll", (flPitch < -10 && m_bGroundOcclusion));
                c.SetUniform("flTime", (float)Application()->GetTime());
                c.BindTexture(oDepthFB.m_iDepthTexture);

                c.BeginRenderVertexArray(m_iScene);
                c.SetPositionBuffer((size_t)0, 8*sizeof(float));
                c.SetNormalsBuffer((size_t)3*sizeof(float), 8*sizeof(float));
                c.SetTexCoordBuffer((size_t)6*sizeof(float), 8*sizeof(float));
                c.EndRenderVertexArray(m_iSceneVerts);
            }

            if (ao_debug.GetBool())
            {
                CRenderingContext c(SMAKRenderer());
                c.SetViewport(Rect(iShadowMapSize/2, 0, m_iWidth, m_iHeight));
                DrawTexture(oUVFB.m_iMap, 1, c);
            }

            double flTimeBefore = SMAKWindow()->GetTime();

            c.SetViewport(Rect(0, 0, m_iWidth, m_iHeight));
            c.UseFrameBuffer(&m_oAOFB);
            AccumulateTexture(oUVFB.m_iMap);
            c.UseFrameBuffer(nullptr);

            if (ao_debug.GetBool())
            {
                CRenderingContext c(SMAKRenderer());
                c.UseProgram("ao");
                c.SetViewport(Rect(iShadowMapSize/2+m_iWidth, 0, m_iWidth, m_iHeight));
                c.SetUniform("iAOMap", 0);
                c.SetBlend(BLEND_ALPHA);
                DrawTexture(m_oAOFB.m_iMap, 1, c);
            }

            flProcessSceneRead += (SMAKWindow()->GetTime() - flTimeBefore);
            flTimeBefore = SMAKWindow()->GetTime();

            m_pWorkListener->WorkProgress(x*iSamples + y);

            flProgress += (SMAKWindow()->GetTime() - flTimeBefore);

            if (m_bStopGenerating)
                break;
        }

        if (m_bStopGenerating)
            break;
    }

    c.UseFrameBuffer(&m_oAOFB);
    c.ReadPixels(0, 0, m_iWidth, m_iHeight, m_pvecPixels);
    c.UseFrameBuffer(nullptr);

    if (!m_bStopGenerating)
    {
        size_t iBufferSize = m_iWidth*m_iHeight;

        m_pWorkListener->SetAction("Reading pixels", iBufferSize);

        for (size_t p = 0; p < iBufferSize; p++)
        {
            Vector4D& vecPixel = m_pvecPixels[p];
            if (vecPixel.w == 0.0f)
                continue;

            m_avecShadowValues[p].x = vecPixel.x;
            m_aiShadowReads[p] = (size_t)vecPixel.w;
            m_bPixelMask[p] = true;

            m_pWorkListener->WorkProgress(p);
        }
    }

    oDepthFB.Destroy();
    oUVFB.Destroy();
    // Don't destroy m_oAOFB yet, we need it in a bit. It gets destroyed later.
}
Example #18
0
void Console::Draw(IRenderer* renderer)
{
  if(!text)
    text = renderer->GetMaterial("console_text");
  if(!bgShader)
    bgShader = renderer->GetMaterial("console_bg");

  int maxLines = (int)(conPos / 12);
  int pos = bufPos;
  int posEnd = bufPos;

  int trailPos = (int)(height * 0.11f);

  // Draw console trail
  if(!active && (conPos == 0) && contrail.GetBool())
  {
    renderer->SetOrthoProjection();
    renderer->SetViewMatrix(0);
    renderer->SetColor(1,1,1);
    renderer->BindMaterial(text);
    // draw bottom up
    for(int i = 0; i < 3; i++)
    {
      while(pos > 0 && pos < 8192 &&
            buffer[pos] != '\n')
      {
        pos--;
      }

      // draw line (pos to bufPos)
      renderer->DrawTextLen(5.0f, (height - (trailPos - ((i+1) * 14))+5.0f),
                            16.0f, &buffer[pos+1], (posEnd-pos-1));

      posEnd = pos;
      pos--;

      if(pos < 0)
      {
        break;
      }
    }
    return;
  }


  // Draw Active Console
  renderer->SetOrthoProjection();
  renderer->SetViewMatrix(0);
  renderer->BindMaterial(bgShader);
  renderer->SetColor(1,1,1);
  renderer->DrawRect(0.0, (height - conPos), (float)width, conPos, 0.0f,0.0f, 1.0f,(conPos / (height*0.5f)));

  renderer->BindMaterial(text);
  // draw bottom up
  for(int i = 0; i < maxLines; i++)
  {
    while(pos > 0 && pos < 8192 &&
          buffer[pos] != '\n')
    {
      pos--;
    }

    // draw line (pos to bufPos)
    renderer->DrawTextLen(5.0f, (height - (conPos - ((i+1) * 14))+5.0f),
                          16.0f, &buffer[pos+1], (int)(posEnd-pos-1));

    posEnd = pos;
    pos--;

    if(pos < 0)
    {
      break;
    }
  }

  renderer->DrawTextP(5.0f, (height - conPos+5.0f), 16.0f, cmd);
}
Example #19
0
void CSystemInstance::Render(CGameRenderingContext* c, bool bTransparent)
{
	for (size_t i = 0; i < m_apChildren.size(); i++)
		m_apChildren[i]->Render(c, bTransparent);

	if (m_pSystem->GetBlend() == BLEND_NONE && bTransparent)
		return;

	if (m_pSystem->GetBlend() != BLEND_NONE && !bTransparent)
		return;

	CGameRenderer* pRenderer = GameWindow()->GetGameRenderer();

	if (particles_debug.GetBool())
	{
		CRenderingContext c(pRenderer, true);
		c.UseProgram("debug");
		c.SetUniform("vecColor", Color(1.0, 1.0, 1.0, 1.0f));
		c.ResetTransformations();
		c.RenderWireBox(m_aabbBounds);
	}

	if (!pRenderer->IsSphereInFrustum(m_aabbBounds.Center(), m_aabbBounds.Size().Length() / 2))
		return;

	Vector vecForward, vecLeft, vecUp;
	pRenderer->GetCameraVectors(&vecForward, &vecLeft, &vecUp);

	if (m_pSystem->GetMaterial())
		c->UseMaterial(m_pSystem->GetMaterial());

	c->SetBlend(m_pSystem->GetBlend());

	Color clrParticle = m_pSystem->GetColor();
	if (m_bColorOverride)
		clrParticle = m_clrOverride;

	if (m_pSystem->GetModel())
	{
		int iRadius = c->GetUniform("flRadius");

		for (size_t i = 0; i < m_aParticles.size(); i++)
		{
			CParticle* pParticle = &m_aParticles[i];

			if (!pParticle->m_bActive)
				continue;

			c->SetUniform(iRadius, pParticle->m_flAlpha);
			c->SetColor(clrParticle);
			c->Translate(pParticle->m_vecOrigin);
			c->Rotate(-pParticle->m_angAngles.y, Vector(0, 0, 1));
			c->Rotate(pParticle->m_angAngles.p, Vector(0, 1, 0));
			c->Rotate(pParticle->m_angAngles.r, Vector(1, 0, 0));
			c->Scale(pParticle->m_flRadius, pParticle->m_flRadius, pParticle->m_flRadius);
			c->RenderModel(m_pSystem->GetModel());
			c->ResetTransformations();
		}
	}
	else
	{
		c->SetUniform("vecCameraPosition", GameServer()->GetRenderer()->GetCameraPosition());

		size_t iQuadVBO = CParticleSystemLibrary::Get()->GetQuadVBO();
		size_t iQuadVBOSize = CParticleSystemLibrary::Get()->GetQuadVBOSize();

		int iOrigin = c->GetUniform("vecOrigin");
		int iAlpha = c->GetUniform("flAlpha");
		int iRadius = c->GetUniform("flRadius");
		int iYaw = c->GetUniform("flYaw");
		int iColor = c->GetUniform("vecColor");

		for (size_t i = 0; i < m_aParticles.size(); i++)
		{
			CParticle* pParticle = &m_aParticles[i];

			if (!pParticle->m_bActive)
				continue;

			c->SetUniform(iOrigin, pParticle->m_vecOrigin);
			c->SetUniform(iAlpha, pParticle->m_flAlpha);
			c->SetUniform(iRadius, pParticle->m_flRadius);
			c->SetUniform(iYaw, (float)(pParticle->m_flBillboardYaw*M_PI/180));
			c->SetUniform(iColor, clrParticle);

			c->BeginRenderVertexArray(iQuadVBO);
			c->SetPositionBuffer(0u, 20);
			c->SetTexCoordBuffer(12, 20);
			c->EndRenderVertexArray(iQuadVBOSize);
		}
	}
}
Example #20
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();
}
Example #21
0
void CCharacter::PostRender(bool bTransparent) const
{
	if (!bTransparent && debug_showplayervectors.GetBool())
		ShowPlayerVectors();
}
Example #22
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);
        }
    }
}