int main(int argc, char* argv[]) { MPI_Init(&argc, &argv); Grid grid = (Grid) { .NumberOfPoints = 0, .Points = 0, .NumberOfCells = 0, .Cells = 0}; unsigned int numPoints[3] = {70, 60, 44}; double spacing[3] = {1, 1.1, 1.3}; InitializeGrid(&grid, numPoints, spacing); Attributes attributes; InitializeAttributes(&attributes, &grid); #ifdef USE_CATALYST int fileNameLength = 0; fileNameLength = strlen(argv[1]); coprocessorinitializewithpython(argv[1], &fileNameLength); int i; for(i=2;i<argc;i++) { // Add in any other Python script pipelines that are passed in. fileNameLength = strlen(argv[i]); coprocessoraddpythonscript(argv[i], &fileNameLength); } #endif unsigned int numberOfTimeSteps = 100; unsigned int timeStep; for(timeStep=0;timeStep<numberOfTimeSteps;timeStep++) { // use a time step length of 0.1 double time = timeStep * 0.1; UpdateFields(&attributes, time); #ifdef USE_CATALYST int lastTimeStep = 0; if(timeStep == numberOfTimeSteps-1) { lastTimeStep = 1; } CatalystCoProcess(grid.NumberOfPoints, grid.Points, grid.NumberOfCells, grid.Cells, attributes.Velocity, attributes.Pressure, time, timeStep, lastTimeStep); #endif } #ifdef USE_CATALYST coprocessorfinalize(); #endif MPI_Finalize(); return 0; }
void Level00::VInitialize() { mState = BASE_SCENE_STATE_INITIALIZING; VOnResize(); InitializeLevel(); InitializeGrid(); InitializeRobots(); InitializeGeometry(); InitializeWallShaders(); InitializeLightShaders(); InitializePlayerShaders(); InitializeCamera(); mState = BASE_SCENE_STATE_RUNNING; }
VOID ViewUnitEditor::DrawBall() { if (_pUnitdesigninfo == NULL) { return; } // Declare & Define a necessary variables POINTFLOAT unitSize = _pStripinfo->GetUnitSize(); POINTFLOAT unitPadding = _pUnitdesigninfo->GetUnitPadding(); POINTFLOAT ballPitch = _pUnitdesigninfo->GetBallPitch(); POINT ballCount = _pUnitdesigninfo->GetBallCountXY(); BallData* pBallData = NULL; FLOAT fRadius, fEachRadius; bool bIsChecked; // Initialize a Balls' Layer POINTFLOAT point = {0, 0}; Layer *_pLayer = LayerFactory::create(_TEXT("Unit Layer")); _layers.clearLayers(); // Initialize a Ball Colors RGBA clDefaultSheetColor = _pStripinfo->GetBallDesignDefaultSheet(); RGBA clDefaultOutlineColor = _pStripinfo->GetBallDesignOutline(); RGBA clCheckedSheetColor = _pStripinfo->GetBallDesignCheckedSheet() ; RGBA clCheckedOutlineColor = _pStripinfo->GetBallDesignOutline(); _pViewUnitPainter->setFillColor(clDefaultSheetColor); _pViewUnitPainter->setLineColor(clDefaultOutlineColor); _pViewUnitPainter->setSelectFillColr(_pStripinfo->GetSelectBallSheetColor()); _pViewUnitPainter->setSelectLineColr(_pStripinfo->GetSelectBallOutlineColor()); // Create a Balls' Layer _pLayer = LayerFactory::create(_TEXT("Ball Layer")); // Make a Ball Size & Margin's Information if (ballPitch.x < MINIMUM_PITCH) { ballPitch.x = MINIMUM_PITCH; } if (ballPitch.y < MINIMUM_PITCH) { ballPitch.y = MINIMUM_PITCH; } POINTFLOAT ballStartPoint = { -(unitSize.x / 2) + unitPadding.x, -(unitSize.y / 2) + unitPadding.y }; POINTFLOAT remainsBallPitch = {0.0f, 0.0f}; POINTFLOAT ballSize = { (unitSize.x - (unitPadding.x * 2.0f) - (ballPitch.x * (ballCount.x - 1.0f))) / (float)ballCount.x, (unitSize.y - (unitPadding.y * 2.0f) - (ballPitch.y * (ballCount.y - 1.0f))) / (float)ballCount.y }; if (ballSize.x > ballSize.y) { if (ballCount.x < 3) { remainsBallPitch.x = (ballSize.x - ballSize.y) * 2; } else { remainsBallPitch.x = (ballSize.x - ballSize.y) * (float)ballCount.x / ((float)ballCount.x - 1.0f); } fRadius = ballSize.y / 2; } else { if (ballCount.y < 3) { remainsBallPitch.y = (ballSize.y - ballSize.x) * 2; } else { remainsBallPitch.y = (ballSize.y - ballSize.x) * (float)ballCount.y / ((float)ballCount.y - 1.0f); } fRadius = ballSize.x / 2; } // Initialize a Ball Information's Grid int idx = 1; InitializeGrid(); // Loop (draw balls) for(INT32 nRow = 0 ; nRow < ballCount.y ; nRow++) { for(INT32 nCol = 0 ; nCol < ballCount.x ; nCol++) { // Get Radius if (_pUnitdesigninfo->IsSizeManually(nCol, nRow)) { if (!_pUnitdesigninfo->GetBallRadius(nCol, nRow, fEachRadius)) { fEachRadius = fRadius; } } else { fEachRadius = fRadius; } _pUnitdesigninfo->SetBallRadius(nCol, nRow, fEachRadius); // Get Position if (_pUnitdesigninfo->IsBallPosManually(nCol, nRow)) { if (!_pUnitdesigninfo->GetBallPoint(nCol, nRow, point)) { point.x = ballStartPoint.x + ((fRadius * 2 + ballPitch.x + remainsBallPitch.x) * nCol) + fRadius; point.y = ballStartPoint.y + ((fRadius * 2 + ballPitch.y + remainsBallPitch.y) * nRow) + fRadius; } } else { point.x = ballStartPoint.x + ((fRadius * 2 + ballPitch.x + remainsBallPitch.x) * nCol) + fRadius; point.y = ballStartPoint.y + ((fRadius * 2 + ballPitch.y + remainsBallPitch.y) * nRow) + fRadius; } _pUnitdesigninfo->SetBallPoint(nCol, nRow, point); // Draw a Ball Shape if ((bIsChecked = _pUnitdesigninfo->IsChecked(nCol, nRow)) == false) { _pShape = CreateCircle(_pViewUnitPainter, clDefaultOutlineColor, clDefaultSheetColor, point.x, point.y, fEachRadius); } else { _pShape = CreateCircle(_pViewUnitPainter, clCheckedOutlineColor, clCheckedSheetColor, point.x, point.y, fEachRadius); } // Insert a Ball Shape in Layer _pLayer->insert(_pShape); // Insert a Ball Info in StringGrid InsertGridInfo(idx, nCol, nRow, point, fEachRadius, _pUnitdesigninfo->IsChecked(nCol, nRow)); idx++; } // for(INT32 col = 0 ; col < nCol ; col++) } // for(INT32 row = 0 ; row < nRow ; row++) // Set a Status of Ball Information's Grid SetGridEditingStatus(); // Insert a Layer in Layers Object _layers.insert(_pLayer); }
void Level00::RenderLightCircles() { const UINT stride = sizeof(mat4f); const UINT offset = 0; const UINT Colorstride = sizeof(float); mDeviceContext->IASetInputLayout(mCircleInputLayout); mDeviceContext->VSSetShader(mCircleVertexShader, NULL, 0); mDeviceContext->PSSetShader(mQuadPixelShader, NULL, 0); mQuadShaderData.Color = gCircleColor; mDeviceContext->UpdateSubresource(mQuadShaderBuffer, 0, NULL, &mQuadShaderData, 0, 0); mDeviceContext->VSSetConstantBuffers(0, 1, &mQuadShaderBuffer); mRenderer->VBindMesh(mCircleMesh); mDeviceContext->IASetVertexBuffers(1, 1, &mCircleInstanceBuffer, &stride, &offset); mDeviceContext->IASetVertexBuffers(2, 1, &mColorWeightInstanceBuffer, &Colorstride, &offset); mDeviceContext->DrawIndexedInstanced(mCircleMesh->GetIndexCount(), mCircleCount, 0, 0, 0); //Light shadows mDeviceContext->ClearRenderTargetView(mShadowsFinalRTV, black); for (int i = 0; i < mCircleCount; i++) { if (mCircleColorWeights[i] == 0) continue; mat4f clip = (mCircleTransforms[i].transpose() * mQuadShaderData.View.transpose()) * mQuadShaderData.Projection.transpose(); vec4f zero = { 0.0f, 0.0f, 14.0f, 1.0f }; mPointShaderData.Point = zero * clip; mDeviceContext->ClearRenderTargetView(mShadowsARTV, white); mDeviceContext->ClearRenderTargetView(mShadowsBRTV, white); mDeviceContext->IASetInputLayout(mQuadInputLayout); mDeviceContext->PSSetSamplers(0, 1, &mSamplerState); mDeviceContext->VSSetShader(mBillboardVertexShader, nullptr, 0); mDeviceContext->PSSetShader(mShadowPixelShader, nullptr, 0); mDeviceContext->UpdateSubresource(mPointShaderBuffer, 0, NULL, &mPointShaderData, 0, 0); mDeviceContext->PSSetConstantBuffers(0, 1, &mPointShaderBuffer); //mDeviceContext->ClearRenderTargetView(mShadowCastersBRTV, transp); mDeviceContext->OMSetRenderTargets(1, &mShadowsBRTV, nullptr); mDeviceContext->PSSetShaderResources(0, 1, &mShadowCastersSRV); int p; for (p = 0; p <= 1; p++) { if (p != 0) mDeviceContext->OMSetRenderTargets(1, p % 2 == 0 ? &mShadowsBRTV : &mShadowsARTV, nullptr); if (p != 0) mDeviceContext->PSSetShaderResources(0, 1, p % 2 == 0 ? &mShadowsASRV : &mShadowsBSRV); mDeviceContext->Draw(3, 0); mDeviceContext->PSSetShaderResources(0, 1, nullSRV); } mDeviceContext->OMSetBlendState(mBlendStateShadowCalc, nullptr, ~0); mDeviceContext->VSSetShader(mBillboardVertexShader, nullptr, 0); mDeviceContext->PSSetShader(mBillboardPixelShader, nullptr, 0); mDeviceContext->OMSetRenderTargets(1, &mShadowsFinalRTV, nullptr); mDeviceContext->PSSetShaderResources(0, 1, p % 2 == 0 ? &mShadowsASRV : &mShadowsBSRV); mDeviceContext->Draw(3, 0); mDeviceContext->PSSetShaderResources(0, 1, nullSRV); mDeviceContext->OMSetBlendState(nullptr, nullptr, ~0); mDeviceContext->OMSetRenderTargets(1, mRenderer->GetRenderTargetView(), nullptr); } //FIXME player stuff //Node* newPlayerNode = mGrid.GetNodeAt(mExplorers.mTransform->GetPosition()); if (true/* || mPlayerNode != newPlayerNode*/) { //mPlayerNode = newPlayerNode; InitializeGrid(); //Compute mDeviceContext->CSSetShader(mShadowGridComputeShader, NULL, 0); mDeviceContext->UpdateSubresource(mSrcDataGPUBuffer, 0, NULL, &mGridNodeData, 0, 0); mDeviceContext->CSSetShaderResources(0, 1, &mSrcDataGPUBufferView); mDeviceContext->CSSetShaderResources(1, 1, &mShadowsFinalSRV); mDeviceContext->CSSetShaderResources(2, 1, &mShadowCastersSRV); mDeviceContext->CSSetUnorderedAccessViews(0, 1, &mDestDataGPUBufferView, NULL); mDeviceContext->CSSetConstantBuffers(0, 1, &mQuadShaderBuffer); for (int i = 0; i < 100; i++) { mDeviceContext->Dispatch(34, 1, 1); mDeviceContext->CopyResource(mSrcDataGPUBuffer, mDestDataGPUBuffer); } mDeviceContext->CSSetShader(NULL, NULL, 0); mDeviceContext->CSSetShaderResources(0, 3, nullSRV); //Copy results to a CPU friendly buffer mDeviceContext->CopyResource(mDestDataGPUBufferCPURead, mDestDataGPUBuffer); //Map and update D3D11_MAPPED_SUBRESOURCE mappedResource; mDeviceContext->Map(mDestDataGPUBufferCPURead, 0, D3D11_MAP_READ, 0, &mappedResource); GridNode* ints = reinterpret_cast<GridNode*>(mappedResource.pData); auto g = mGrid.pathFinder.graph.grid; for (int i = 0; i < numSpheresX; i++) { for (int j = 0; j < numSpheresY; j++) { g[i][j].hasLight = ints[i + j*numSpheresX].hasLight; g[i][j].weight = ints[i + j*numSpheresX].weight; } } mDeviceContext->Unmap(mDestDataGPUBufferCPURead, 0); } }