void CGlobalAITestScript::GameStart(void) { globalAI->CreateGlobalAI(1, dllName.c_str()); gs->Team(0)->energy = 1000; gs->Team(0)->energyStorage = 1000; gs->Team(0)->metal = 1000; gs->Team(0)->metalStorage = 1000; gs->Team(1)->energy = 1000; gs->Team(1)->energyStorage = 1000; gs->Team(1)->metal = 1000; gs->Team(1)->metalStorage = 1000; const std::string startUnit0 = sideParser.GetStartUnit(0, ""); const std::string startUnit1 = sideParser.GetStartUnit(1, startUnit0); // default to side 1, in case mod has only 1 side if (startUnit0.length() == 0) { throw content_error ("Unable to load a commander for the first side"); } MapParser mapParser(stupidGlobalMapname); if (!mapParser.IsValid()) { throw content_error("MapParser: " + mapParser.GetErrorLog()); } float3 startPos0(1000.0f, 80.0f, 1000.0f); float3 startPos1(1200.0f, 80.0f, 1200.0f); mapParser.GetStartPos(0, startPos0); mapParser.GetStartPos(1, startPos1); unitLoader.LoadUnit(startUnit0, startPos0, 0, false, 0, NULL); unitLoader.LoadUnit(startUnit1, startPos1, 1, false, 0, NULL); }
void CSkirmishAITestScript::GameStart(void) { // make sure CSelectedUnits::AiOrder() // still works without a setup script teamHandler->Team(skirmishAI_teamId)->isAI = true; teamHandler->Team(skirmishAI_teamId)->skirmishAIKey = key; teamHandler->Team(skirmishAI_teamId)->skirmishAIOptions = options; teamHandler->Team(skirmishAI_teamId)->leader = player_teamId; playerHandler->Player(player_teamId)->SetControlledTeams(); teamHandler->Team(player_teamId)->energy = 1000; teamHandler->Team(player_teamId)->energyStorage = 1000; teamHandler->Team(player_teamId)->metal = 1000; teamHandler->Team(player_teamId)->metalStorage = 1000; teamHandler->Team(skirmishAI_teamId)->energy = 1000; teamHandler->Team(skirmishAI_teamId)->energyStorage = 1000; teamHandler->Team(skirmishAI_teamId)->metal = 1000; teamHandler->Team(skirmishAI_teamId)->metalStorage = 1000; eoh->CreateSkirmishAI(skirmishAI_teamId, key); const std::string startUnit0 = sideParser.GetStartUnit(0, ""); const std::string startUnit1 = sideParser.GetStartUnit(1, startUnit0); // default to side 1, in case mod has only 1 side if (startUnit0.length() == 0) { throw content_error ("Unable to load a commander for the first side"); } MapParser mapParser(stupidGlobalMapname); if (!mapParser.IsValid()) { throw content_error("MapParser: " + mapParser.GetErrorLog()); } float3 startPos0(1000.0f, 80.0f, 1000.0f); float3 startPos1(1200.0f, 80.0f, 1200.0f); mapParser.GetStartPos(0, startPos0); mapParser.GetStartPos(1, startPos1); unitLoader.LoadUnit(startUnit0, startPos0, 0, false, 0, NULL); unitLoader.LoadUnit(startUnit1, startPos1, 1, false, 0, NULL); }
RenderManager::RenderManager(ID3D11DeviceContext *devcon, ID3D11Device *dev, IDXGISwapChain *swapchain, Apex *apex, Camera *cam, D3D11_VIEWPORT *viewport) : mDevcon(devcon), mDev(dev), mSwapchain(swapchain), mCam(cam), mApex(apex), mViewport(viewport) { sceneBuff.normalMap = 1; sceneBuff.phong = 1; sceneBuff.textures = 1; sceneBuff.ambientOn = 1; sceneBuff.diffuseOn = 1; sceneBuff.specularOn = 1; sceneBuff.dirLightOn = 1; sceneBuff.pLightOn = 1; sceneBuff.shadowsOn = 1; sceneBuff.cascadeOn = 0; PartyMode = 0; emitterOn = true; fps = 0; SCREEN_WIDTH = 1280; SCREEN_HEIGHT = 720; ID3D11Texture2D *pBackBuffer; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // use the back buffer address to create the render target dev->CreateRenderTargetView(pBackBuffer, NULL, &mBackbuffer); pBackBuffer->Release(); mAssetManager = new AssetManager(mDev, mDevcon); GeometryGenerator *geoGen = new GeometryGenerator(); //Special "renderable" case, do not add to the vector mScreen = new ScreenQuad(mDevcon, mDev, geoGen); //Special camera, doesn't move mSkyBox = new SkyBox(mDevcon, mDev, geoGen); //mCloth = apex->CreateCloth(gRenderer, "curtainew");//"ctdm_Cape_400");//"bannercloth");// //renderables.push_back(mCloth); //emitter = apex->CreateEmitter(gRenderer, "SmokeEmitter"); //emitter->SetPosition(-18.0f, -65.0f, -243.0f); ////emitter->SetEmit(true); // //torch1 = apex->CreateEmitter(gRenderer, "TorchEmitter"); //torch1->SetPosition(-13.5f, -2.0f, -42.0f); // torch2 = apex->CreateEmitter(gRenderer, "TorchEmitter"); // torch2->SetPosition(-67.6f, -2.0f, -42.0f); //particles = apex->CreateEmitter(gRenderer, "testSpriteEmitter4ParticleFluidIos"); // particles->SetPosition(-19.0f, 45.0f, 206.0f); /*projectile = new Projectile(dev, devcon, apex); renderables.push_back(projectile);*/ //mGrid = new GroundPlane(mDevcon, mDev, geoGen, 4000, 10); //renderables.push_back(mGrid); //renderables.push_back(emitter); //renderables.push_back(particles); //renderables.push_back(torch1); //renderables.push_back(torch2); HRESULT hr; hr = mFont.Initialize(mDev, L"Times New Roman", 30.0f, FontSheet::FontStyleRegular, true); hr = mText.Initialize(mDev); mScreenCam = new Camera(); mScreenCam->SetLensOrtho(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1000.0f); mScreenCam->UpdateViewMatrix(); D3D11_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(SceneBuff); bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mDev->CreateBuffer(&bd, NULL, &sceneCBuffer); // create the depth buffer texture //ID3D11RasterizerState* pState; //D3D11_RASTERIZER_DESC raster; ZeroMemory( &raster, sizeof(D3D11_RASTERIZER_DESC)); raster.FillMode = D3D11_FILL_SOLID; raster.CullMode = D3D11_CULL_NONE; raster.FrontCounterClockwise = FALSE; raster.DepthBias = 0; raster.DepthBiasClamp = 0.0f; raster.SlopeScaledDepthBias = 0.0f; raster.DepthClipEnable = TRUE; //set for testing otherwise true raster.ScissorEnable = FALSE; raster.MultisampleEnable = FALSE; raster.AntialiasedLineEnable = FALSE; hr = dev->CreateRasterizerState (&raster, &pState); devcon->RSSetState( pState ); D3D11_SAMPLER_DESC sd; sd.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sd.MaxAnisotropy = 16; sd.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sd.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sd.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sd.BorderColor[0] = 0.0f; sd.BorderColor[1] = 0.0f; sd.BorderColor[2] = 0.0f; sd.BorderColor[3] = 0.0f; sd.MinLOD = 0.0f; sd.MaxLOD = FLT_MAX; sd.MipLODBias = 0.0f; dev->CreateSamplerState(&sd, &mSampState); devcon->PSSetSamplers(0, 1, &mSampState); D3D11_TEXTURE2D_DESC texd; ZeroMemory(&texd, sizeof(texd)); texd.Width = SCREEN_WIDTH; texd.Height = SCREEN_HEIGHT; texd.ArraySize = 1; texd.MipLevels = 1; texd.SampleDesc.Count = 1; texd.Format = DXGI_FORMAT_R32_TYPELESS; texd.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; dev->CreateTexture2D(&texd, NULL, &mDepthTargetTexture); D3D11_DEPTH_STENCIL_VIEW_DESC dsvd; ZeroMemory(&dsvd, sizeof(dsvd)); dsvd.Format = DXGI_FORMAT_D32_FLOAT; dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; dsvd.Texture2D.MipSlice = 0; dev->CreateDepthStencilView(mDepthTargetTexture, &dsvd, &mZbuffer); texd.BindFlags = D3D11_BIND_DEPTH_STENCIL; dev->CreateDepthStencilView(mDepthTargetTexture, &dsvd, &mZbuffer2); D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; // Setup the description of the shader resource view. shaderResourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT; shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; shaderResourceViewDesc.Texture2D.MipLevels = 1; dev->CreateShaderResourceView(mDepthTargetTexture, &shaderResourceViewDesc, &mDepthShaderResourceView); // Init blending D3D11_BLEND_DESC blendDesc; blendDesc.AlphaToCoverageEnable = TRUE; blendDesc.IndependentBlendEnable = FALSE; blendDesc.RenderTarget[0].BlendEnable = TRUE; blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; hr = dev->CreateBlendState(&blendDesc, &mBlendState); if( FAILED(hr) ) return; float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f}; devcon->OMSetBlendState(mBlendState, blendFactor, 0xffffffff); // restore default //Set the directional light ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(DirectionalLight)*10; bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mDev->CreateBuffer(&bd, NULL, &dirLightCBuffer); mDirLight[0].Ambient = XMFLOAT4(.4f, .4f, .4f, 1); mDirLight[0].Diffuse = XMFLOAT4(.6f, .6f, .6f, 1); mDirLight[0].Direction = XMFLOAT3(0.57735f, -0.68f, -0.866f); mDirLight[0].Specular = XMFLOAT4(0.7f, 0.67f, 0.62f, 1); mDirLight[1].Ambient = XMFLOAT4(.3f, .3f, .3f, 1); mDirLight[1].Diffuse = XMFLOAT4(.6f, .6f, .6f, 1); mDirLight[1].Direction = XMFLOAT3(10, 0, 0); mDirLight[1].Specular = XMFLOAT4(1, 1, 1, 1); //Set the point light ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(PointLight) * MAX_NUM_POINT_LIGHTS; bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mDev->CreateBuffer(&bd, NULL, &pointLightCBuffer); ID3D11SamplerState* pSS; // D3D11_SAMPLER_DESC sd; ZeroMemory(&sd, sizeof(sd)); //sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; sd.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; sd.MaxAnisotropy = 1; sd.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR; sd.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR; sd.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR; sd.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL; mDev->CreateSamplerState(&sd, &pSS); mDevcon->PSSetSamplers(5, 1, &pSS); vector<String> sceneNames; sceneNames.push_back("scene/hub_scene.txt"); sceneNames.push_back("scene/bowling_scene.txt"); sceneNames.push_back("scene/dark_scene.txt"); sceneNames.push_back("scene/jenga_scene.txt"); sceneNames.push_back("scene/openworld_scene.txt"); Scene *tempScene; newTimer.Reset(); for(int i = 0; i < (int)sceneNames.size(); i++) { apex->setScene(i); tempScene = new Scene( dev, devcon, apex, geoGen, mSkyBox, mScreen, mZbuffer, mViewport, sceneNames[i], mAssetManager); scene.push_back(tempScene); newTimer.Tick(); sceneLoadTimes.push_back(newTimer.DeltaTime()); } // Setting up Cascade Light Shadow Maps for( int i = 0; i < scene.size(); i++ ) { if( i == 0) shad = new ShadowManager(mDev, mDevcon, 2048, 2048, 0, 120.0, 120.0); else if( i == 1) shad = new ShadowManager(mDev, mDevcon, 2048, 2048, 0, 120.0, 120.0); else if( i == 2) shad = new ShadowManager(mDev, mDevcon, 2048, 2048, 0, 120.0, 120.0); else if( i == 3) shad = new ShadowManager(mDev, mDevcon, 2048, 2048, 0, 120.0, 120.0); else shad = new ShadowManager(mDev, mDevcon, 2048, 2048, 0, 60.0, 60.0); shad->lightPos = mDirLight[0].Direction; shadows[i].push_back( shad ); } for( int i = 0; i < scene.size(); i++ ) { shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 120.0, 120.0); if( i == 0) shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 50.0, 50.0); else if( i == 1) shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 100.0, 100.0); else if( i == 2) shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 120.0, 120.0); else if( i == 3) shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 250.0, 250.0); else shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 120.0, 120.0); shad->lightPos = mDirLight[0].Direction; shadows[i].push_back( shad ); } for( int i = 0; i < scene.size(); i++ ) { shad = new ShadowManager(mDev, mDevcon, 1024, 1024, 0, 120.0, 120.0); if( i == 0) shad = new ShadowManager(mDev, mDevcon, 512, 512, 0, 300.0, 300.0); else if( i == 1) shad = new ShadowManager(mDev, mDevcon, 512, 512, 0, 300.0, 300.0); else if( i == 2) shad = new ShadowManager(mDev, mDevcon, 512, 512, 0, 300.0, 300.0); else if( i == 3) shad = new ShadowManager(mDev, mDevcon, 512, 512, 0, 500.0, 500.0); else shad = new ShadowManager(mDev, mDevcon, 512, 512, 0, 300.0, 300.0); shad->lightPos = mDirLight[0].Direction; shadows[i].push_back( shad ); } //// Setting up Point Light Shadow Maps //for( int i = 1; i <= 6; i++ ) //{ // shad = new ShadowManager(mDev, mDevcon, 512, 512, i); // shad->lightPos = mPointLight[0].Position; // shadows.push_back( shad ); //} //for( int i = 1; i <= 6; i++ ) //{ // shad = new ShadowManager(mDev, mDevcon, 512, 512, i); // shad->lightPos = mPointLight[1].Position; // shadows.push_back( shad ); //} PointLight tempPointLight; //SCENE0 - HUB tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = XMFLOAT4(1.7f, 0.6f, 0.0f, 1); tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 15.0f; tempPointLight.Position = XMFLOAT3(-22.7255f, -11.34f, -15.337f); scene[0]->mPointLights[0] = tempPointLight; scene[0]->mPointLights[0].Pad = 2; tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = XMFLOAT4(1.7f, 0.6f, 0.0f, 1); tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 15.0f; tempPointLight.Position = XMFLOAT3(-11.8275f, -11.34f, -26.35f); scene[0]->mPointLights[1] = tempPointLight; //SCENE1 - BOWLING XMFLOAT3 startPos1(-25.0f, 10.0f, -160); XMFLOAT3 startPos2( 25.0f, 10.0f, -160); for(int i = 0; i < 10; i++) { tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::Green; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 30.0f; tempPointLight.Position = startPos1; startPos1.z += 20.0f; scene[1]->mPointLights[i] = tempPointLight; } for(int i = 10; i < 20; i++) { tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::Green; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 30.0f; tempPointLight.Position = startPos2; startPos2.z += 20.0f; scene[1]->mPointLights[i] = tempPointLight; } tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::Green; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 25.0f; tempPointLight.Position = XMFLOAT3(0.0f, 16.0f, 27.5f); scene[1]->mPointLights[20] = tempPointLight; scene[1]->mPointLights[0].Pad = 21; for( int i = 0; i < 1; i++ ) { for( int j = 1; j <= 6; j++ ) { shad = new ShadowManager(mDev, mDevcon, 512, 512, j); shad->lightPos = scene[1]->mPointLights[i].Position; shadows[1].push_back( shad ); } } ////SCENE2 - DARKNESS //tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); //tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); //tempPointLight.Diffuse = Colors::Magenta; //tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); //tempPointLight.Range = 15.0f; //tempPointLight.Position = XMFLOAT3(-0.5f, 2.5f, 73.0f); //scene[2]->mPointLights[0] = tempPointLight; //scene[2]->mPointLights[0].Pad = 1; //SCENE2 - DARKNESS tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::TorchOrange; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 15.0f; tempPointLight.Position = XMFLOAT3(-0.5f, 2.5f, 73.0f); scene[2]->mPointLights[0] = tempPointLight; scene[2]->mPointLights[0].Pad = 1; /*tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::Magenta; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 15.0f; tempPointLight.Position = XMFLOAT3(0.0f, 14.0f, 180.0f); scene[2]->mPointLights[1] = tempPointLight;*/ for( int i = 0; i < 2; i++ ) { for( int j = 1; j <= 6; j++ ) { shad = new ShadowManager(mDev, mDevcon, 1024, 1024, j); shad->lightPos = scene[2]->mPointLights[i].Position; shadows[2].push_back( shad ); } } //SCENE3 - tempPointLight.Ambient = XMFLOAT4(0.0f, 0.0f, 0.0f, 1); tempPointLight.Att = XMFLOAT3(1.0f, 0.05f, .0075f); tempPointLight.Diffuse = Colors::Blue; tempPointLight.Specular = XMFLOAT4(1, 1, 1, 1); tempPointLight.Range = 15.0f; tempPointLight.Position = XMFLOAT3(0.0f, 4.5f, 17.0f); scene[3]->mPointLights[0] = tempPointLight; scene[3]->mPointLights[0].Pad = 1; //SCENE4 - OPEN WORLD scene[4]->mPointLights[0].Pad = 0; apex->setScene(0); // Shadow Constant Buffer for( int j = 0; j < scene.size(); j++ ) { ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(ShadowBuff) * shadows[j].size(); bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mDev->CreateBuffer(&bd, NULL, &shadowCBuffer[j]); for( int i = 0; i < shadows[i].size(); i++ ) { ShadowBuff temp; temp.lightPos = shadows[j][i]->lightPos; XMStoreFloat4x4( &temp.lightViewProj, shadows[j][i]->mShadowCam->ViewProj() ); shadowBuff[j].push_back( temp ); } } }