Exemplo n.º 1
0
void CLobbyPanel::CreateLobby(bool bOnline)
{
	m_bOnline = bOnline;

	CGameLobbyClient::SetLobbyUpdateCallback(&LobbyUpdateCallback);
	CGameLobbyClient::SetLobbyJoinCallback(&LobbyJoinCallback);
	CGameLobbyClient::SetLobbyLeaveCallback(&LobbyLeaveCallback);
	CGameLobbyClient::SetBeginGameCallback(&BeginGameCallback);

	const char* pszPort = DigitanksWindow()->GetCommandLineSwitchValue("--lobby-port");
	int iPort = pszPort?atoi(pszPort):0;

	m_iLobby = CGameLobbyServer::CreateLobby();
	CGameLobbyServer::SetListener(DigitanksLobbyListener());

	if (m_bOnline)
	{
		GameNetwork()->Disconnect();
		LobbyNetwork()->Disconnect();
		LobbyNetwork()->SetCallbacks(NULL, NULL, CGameLobbyServer::ClientEnterGame, CGameLobbyServer::ClientDisconnect);
		LobbyNetwork()->CreateHost(iPort);
	}

	CGameLobbyClient::S_JoinLobby(m_iLobby);
	CGameLobbyClient::S_UpdatePlayer(_T("host"), _T("1"));
	CGameLobbyClient::S_UpdateLobby(_T("gametype"), tsprintf(tstring("%d"), (gametype_t)lobby_gametype.GetInt()));

	if (!m_bOnline)
	{
		CGameLobbyClient::S_AddBot();
		CGameLobbyClient::S_AddBot();
		CGameLobbyClient::S_AddBot();
	}

	for (size_t i = 0; i < CGameLobbyClient::L_GetNumPlayers(); i++)
		CGameLobbyClient::S_UpdatePlayer(CGameLobbyClient::L_GetPlayer(i)->iID, _T("color"), tsprintf(tstring("%d"), i));

	if ((gametype_t)lobby_gametype.GetInt() == GAMETYPE_ARTILLERY)
		m_pDockPanel->SetDockedPanel(new CArtilleryGamePanel(true));
	else
		m_pDockPanel->SetDockedPanel(new CStrategyGamePanel(true));

	SetVisible(true);
	DigitanksWindow()->GetMainMenu()->SetVisible(false);

	m_bLayout = true;
}
Exemplo n.º 2
0
int CVar::GetCVarInt(tstring sName)
{
	CVar* pVar = FindCVar(sName);
	if (!pVar)
		return 0;

	return pVar->GetInt();
}
Exemplo n.º 3
0
void CCharacterController::PreStep(btCollisionWorld* pCollisionWorld)
{
	int i = 0;
	while (RecoverFromPenetration(pCollisionWorld))
	{
		i++;

		if (i > phys_maxpenetrationrecover.GetInt())
		{
			TMsg(tsprintf("%f Character controller couldn't recover from penetration.\n", GameServer()->GetGameTime()));
			break;
		}
	}
}
Exemplo n.º 4
0
void StoneMine::Update(const float dtime)
{
    m_line.Update(dtime * v_numzpr.GetFloat(), m_stone, v_numworks.GetInt());

}
Exemplo n.º 5
0
Arquivo: ao.cpp Projeto: ezhangle/SMAK
void CAOGenerator::GenerateTriangleByTexel(CConversionMeshInstance* pMeshInstance, CConversionFace* pFace, size_t v1, size_t v2, size_t v3, raytrace::CRaytracer* pTracer, size_t& iRendered)
{
    CConversionVertex* pV1 = pFace->GetVertex(v1);
    CConversionVertex* pV2 = pFace->GetVertex(v2);
    CConversionVertex* pV3 = pFace->GetVertex(v3);

    CConversionMesh* pMesh = pMeshInstance->GetMesh();

    Vector vu1 = pMesh->GetUV(pV1->vu);
    Vector vu2 = pMesh->GetUV(pV2->vu);
    Vector vu3 = pMesh->GetUV(pV3->vu);

    Vector vecLoUV = vu1;
    Vector vecHiUV = vu1;

    if (vu2.x < vecLoUV.x)
        vecLoUV.x = vu2.x;
    if (vu3.x < vecLoUV.x)
        vecLoUV.x = vu3.x;
    if (vu2.x > vecHiUV.x)
        vecHiUV.x = vu2.x;
    if (vu3.x > vecHiUV.x)
        vecHiUV.x = vu3.x;

    if (vu2.y < vecLoUV.y)
        vecLoUV.y = vu2.y;
    if (vu3.y < vecLoUV.y)
        vecLoUV.y = vu3.y;
    if (vu2.y > vecHiUV.y)
        vecHiUV.y = vu2.y;
    if (vu3.y > vecHiUV.y)
        vecHiUV.y = vu3.y;

    size_t iLoX = (size_t)(vecLoUV.x * m_iWidth);
    size_t iLoY = (size_t)(vecLoUV.y * m_iHeight);
    size_t iHiX = (size_t)(vecHiUV.x * m_iWidth);
    size_t iHiY = (size_t)(vecHiUV.y * m_iHeight);

    for (size_t i = iLoX; i <= iHiX; i++)
    {
        for (size_t j = iLoY; j <= iHiY; j++)
        {
            float flU = ((float)i + 0.5f)/(float)m_iWidth;
            float flV = ((float)j + 0.5f)/(float)m_iHeight;

            bool bInside = PointInTriangle(Vector(flU,flV,0), vu1, vu2, vu3);

            if (!bInside)
                continue;

            Vector v1 = pMeshInstance->GetVertex(pV1->v);
            Vector v2 = pMeshInstance->GetVertex(pV2->v);
            Vector v3 = pMeshInstance->GetVertex(pV3->v);

            Vector vn1 = pMeshInstance->GetNormal(pV1->vn);
            Vector vn2 = pMeshInstance->GetNormal(pV2->vn);
            Vector vn3 = pMeshInstance->GetNormal(pV3->vn);

            // Find where the UV is in world space.

            // First build 2x2 a "matrix" of the UV values.
            float mta = vu2.x - vu1.x;
            float mtb = vu3.x - vu1.x;
            float mtc = vu2.y - vu1.y;
            float mtd = vu3.y - vu1.y;

            // Invert it.
            float d = mta*mtd - mtb*mtc;
            float mtia =  mtd / d;
            float mtib = -mtb / d;
            float mtic = -mtc / d;
            float mtid =  mta / d;

            // Now build a 2x3 "matrix" of the vertices.
            float mva = v2.x - v1.x;
            float mvb = v3.x - v1.x;
            float mvc = v2.y - v1.y;
            float mvd = v3.y - v1.y;
            float mve = v2.z - v1.z;
            float mvf = v3.z - v1.z;

            // Multiply them together.
            // [a b]   [a b]   [a b]
            // [c d] * [c d] = [c d]
            // [e f]           [e f]
            // Really wish I had a matrix math library about now!
            float mra = mva*mtia + mvb*mtic;
            float mrb = mva*mtib + mvb*mtid;
            float mrc = mvc*mtia + mvd*mtic;
            float mrd = mvc*mtib + mvd*mtid;
            float mre = mve*mtia + mvf*mtic;
            float mrf = mve*mtib + mvf*mtid;

            // These vectors should be the U and V axis in world space.
            Vector vecUAxis(mra, mrc, mre);
            Vector vecVAxis(mrb, mrd, mrf);

            Vector vecUVOrigin = v1 - vecUAxis * vu1.x - vecVAxis * vu1.y;

            Vector vecUVPosition = vecUVOrigin + vecUAxis * flU + vecVAxis * flV;

            Vector vecNormal;

            if (m_bCreaseEdges)
                vecNormal = pFace->GetNormal();
            else
            {
                float wv1 = DistanceToLine(vecUVPosition, v2, v3) / DistanceToLine(v1, v2, v3);
                float wv2 = DistanceToLine(vecUVPosition, v1, v3) / DistanceToLine(v2, v1, v3);
                float wv3 = DistanceToLine(vecUVPosition, v1, v2) / DistanceToLine(v3, v1, v2);

                vecNormal = vn1 * wv1 + vn2 * wv2 + vn3 * wv3;
            }

            if (ao_debug.GetInt() > 1)
                SMAKWindow()->AddDebugLine(vecUVPosition, vecUVPosition + vecNormal/2);

            size_t iTexel;
            if (!Texel(i, j, iTexel, false))
                continue;

            if (m_eAOMethod == AOMETHOD_RENDER)
            {
                // Render the scene from this location
                m_avecShadowValues[iTexel] += RenderSceneFromPosition(vecUVPosition, vecNormal, pFace);
            }
            else if (m_eAOMethod == AOMETHOD_RAYTRACE)
            {
                RaytraceSceneMultithreaded(pTracer, vecUVPosition, vecNormal, pMeshInstance, pFace, iTexel);
            }

            m_aiShadowReads[iTexel]++;
            m_bPixelMask[iTexel] = true;

            m_pWorkListener->WorkProgress(++iRendered);

            if (m_bStopGenerating)
                break;
        }
        if (m_bStopGenerating)
            break;
    }
}
Exemplo n.º 6
0
Arquivo: ao.cpp Projeto: 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.
}