Example #1
0
        public bool issueAOGenJob(AmbientOcclusion.eAOQuality quality, bool includeObjects, Controls.AOGenDialog primDlg)
        {
            networkAOInterface.ensureDirectories();

            deleteExistingInputFile();
            deleteExistingResults();
            deleteExistingJobs();

            if (doIHavePendingJobs())
            {
                MessageBox.Show("There are still jobs still being processed from this client. \n Please try again in a few moments.");
                return(false);
            }


            string mHostName = Dns.GetHostName();

            mCurrJobGUID    = System.Guid.NewGuid().ToString();
            mIncludeObjects = includeObjects;

            //Now, start up a thread to watch for file IO
            mControllingDialog = primDlg;
            if (mControllingDialog != null)
            {
                mControllingDialog.setNumWorkUnits(cNumSections);
            }

            mNumSectionsToComplete = cNumSections;


            mWorkerThread = new BackgroundWorker();
            mWorkerThread.WorkerReportsProgress      = true;
            mWorkerThread.WorkerSupportsCancellation = true;
            mWorkerThread.DoWork             += bw_DoWork;
            mWorkerThread.ProgressChanged    += bw_ProgressChanged;
            mWorkerThread.RunWorkerCompleted += bw_RunWorkerCompleted;

            mWorkerThread.RunWorkerAsync(quality);


            {
                //clear current AO Values to zero
                float[] AOVals = TerrainGlobals.getEditor().getAmbientOcclusionValues();
                for (int i = 0; i < AOVals.Length; i++)
                {
                    AOVals[i] = 0.0f;
                }

                if (TerrainGlobals.getTerrain().getQuadNodeRoot() != null)
                {
                    TerrainGlobals.getTerrain().getQuadNodeRoot().clearVisibleDatHandle();
                }
            }



            return(true);
        }
Example #2
0
        public void issueAOGenLocal(AmbientOcclusion.eAOQuality quality, bool includeObjects, Controls.AOGenDialog primDlg)
        {
            mControllingDialog = primDlg;
            if (mControllingDialog != null)
            {
                mControllingDialog.setNumWorkUnits(1);
            }

            TerrainGlobals.getEditor().computeAmbientOcclusion(quality, includeObjects);
            if (mControllingDialog != null)
            {
                mControllingDialog.increaseWorkUnitCount();
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool doNetworkGen = radioButton1.Checked;

            if (doNetworkGen)
            {
                if (DistributedAOGen.networkAOInterface.doesWorkExist())
                {
                    DialogResult res = MessageBox.Show("There is prior work being done on the network. Would you like to wait in line? \n\n Click YES to wait in line for the network. \n\n Click NO to locally generate AO. \n\n Click CANCEL to.. ", "Think about it..", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                    if (res == DialogResult.Yes)
                    {
                        doNetworkGen = true;
                    }
                    else if (res == DialogResult.No)
                    {
                        doNetworkGen = false;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            AmbientOcclusion.eAOQuality quality = AmbientOcclusion.eAOQuality.cAO_Off;
            if (comboBox1.SelectedIndex == 0)
            {
                quality = AmbientOcclusion.eAOQuality.cAO_Worst;
            }
            if (comboBox1.SelectedIndex == 1)
            {
                quality = AmbientOcclusion.eAOQuality.cAO_Medium;
            }
            if (comboBox1.SelectedIndex == 2)
            {
                quality = AmbientOcclusion.eAOQuality.cAO_Best;
            }
            if (comboBox1.SelectedIndex == 3)
            {
                quality = AmbientOcclusion.eAOQuality.cAO_Final;
            }

            bool includeObjects = checkBox1.Checked;

            if (doNetworkGen && Directory.Exists(@"\\esfile\phoenix\Tools\DistributedLighting\"))
            {
                daog = new DistributedAOGen();
                if (!daog.issueAOGenJob(quality, includeObjects, this))
                {
                    //something canceled internally.
                    cancel();
                }
            }
            else
            {
                daog = new DistributedAOGen();
                daog.issueAOGenLocal(quality, includeObjects, this);
            }

            comboBox1.Enabled    = false;
            checkBox1.Enabled    = false;
            button1.Enabled      = false;
            button2.Enabled      = true;
            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
            progressBar1.Value   = 0;
        }
Example #4
0
        public eReturnCodes generateLighting(string targetFile, string destDir, string issuingName, AmbientOcclusion.eAOQuality quality, int totalNumberOfSections, int targetSectionIndex)
        {
            mAoNumSections  = totalNumberOfSections;
            mAoSectionIndex = targetSectionIndex;
            outputDir       = destDir;

            //load our TLD file
            if (targetFile != "" && File.Exists(targetFile))
            {
                if (!loadTempDataFile(targetFile))
                {
                    return(eReturnCodes.cRC_TDL_LOAD_ERROR);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("TDL File not specified, or not available.");
                Console.ForegroundColor = ConsoleColor.White;
                return(eReturnCodes.cRC_TDL_NOT_FOUND);
            }



            ////////////////////////////////////////////////////////////////////////////////

            TerrainGlobals.getTerrainExportRender().init();
            ModelManager.init();

            // AmbientOcclusion.eAOQuality quality = AmbientOcclusion.eAOQuality.cAO_Worst;
            int numSamples        = (int)quality;
            int samplesPerSection = (int)(numSamples / mAoNumSections);
            int startSampleCount  = samplesPerSection * mAoSectionIndex;
            int endSampleCount    = startSampleCount + samplesPerSection;

            AmbientOcclusion ao         = new AmbientOcclusion();
            float            totalTime  = 0;
            float            peelTime   = 0;
            float            gatherTime = 0;

            ao.calcualteAO(quality, true, ref totalTime, ref peelTime, ref gatherTime, startSampleCount, endSampleCount);
            ao.destroy();
            ao = null;



            TerrainGlobals.getTerrainExportRender().destroy();
            ModelManager.destroy();


            //////////////////////////////////////////////////////////////////////////
            bool writingOK = true;

            {
                const int cMajik = 0xA001;

                string ouputDumpFilename = outputDir + @"\" + issuingName + ".AO" + targetSectionIndex;

                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }
                FileStream s = null;
                try
                {
                    s = File.Open(ouputDumpFilename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error writing result to" + ouputDumpFilename);
                    Console.ForegroundColor = ConsoleColor.White;
                    writingOK = false;
                }

                if (writingOK)
                {
                    BinaryWriter f      = new BinaryWriter(s);
                    int          width  = (int)TerrainGlobals.getTerrain().mNumXVerts;
                    int          height = (int)TerrainGlobals.getTerrain().mNumZVerts;

                    //write our header.
                    f.Write(cMajik);
                    f.Write(mAoNumSections);
                    f.Write(mAoSectionIndex);
                    f.Write(numSamples);
                    f.Write(startSampleCount);
                    f.Write(endSampleCount);

                    f.Write(width);
                    f.Write(height);
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            float AOVal = TerrainGlobals.getTerrain().getAmbientOcclusion(x, y);
                            f.Write(AOVal);
                        }
                    }

                    f.Close();
                    s.Close();
                }
            }
            if (!writingOK)
            {
                return(eReturnCodes.cRC_OUTPUT_WRITE_ERROR);
            }


            return(eReturnCodes.cRC_OK);
        }
Example #5
0
 public bool issueAOGenJob(AmbientOcclusion.eAOQuality quality, bool includeObjects)
 {
     return(issueAOGenJob(quality, includeObjects, null));
 }
Example #6
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            string mHostName = Dns.GetHostName();

            AmbientOcclusion.eAOQuality quality = (AmbientOcclusion.eAOQuality)e.Argument;
            //Copy our data & jobs on a worker thread
            //write our temporary data
            Directory.CreateDirectory(networkAOInterface.SourceDir + "\\" + mHostName);
            string sourceInputFile = networkAOInterface.SourceDir + "\\" + mHostName + "\\data.ZIP";

            writeTempData(sourceInputFile);

            if (mWorkerThread.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            //Issue our job files to the network
            XmlSerializer s = new XmlSerializer(typeof(pendingJobXML), new Type[] { });

            for (int i = 0; i < cNumSections; i++)
            {
                pendingJobXML pending = new pendingJobXML();
                pending.workingJobGUID        = mCurrJobGUID;
                pending.issuingSystemName     = mHostName;
                pending.quality               = quality;
                pending.targetSectionIndex    = i;
                pending.totalNumberOfSections = cNumSections;
                pending.issuingSourceFile     = sourceInputFile;
                pending.lastModified          = DateTime.Now;

                string jobFilename = networkAOInterface.JobsDir + mHostName + "_" + i + "_" + mCurrJobGUID + ".aojob";
                Stream st          = File.Open(jobFilename, FileMode.CreateNew, FileAccess.Write, FileShare.None);
                s.Serialize(st, pending);
                st.Close();
            }


            string        targetDir    = networkAOInterface.ResultDir + Dns.GetHostName();
            List <string> filesToCheck = new List <string>();

            for (int i = 0; i < mNumSectionsToComplete; i++)
            {
                filesToCheck.Add(targetDir + "\\" + Dns.GetHostName() + ".AO" + i);
            }

            int notProcessedTimer = 10;//in seconds (due to the sleep @ the bottom of this thread

            while (filesToCheck.Count != 0)
            {
                //did we cancel?
                if (mWorkerThread.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                //if NONE of our work has been picked up then either the clients are all down, or they are all busy
                //ask the user if they want to keep waiting.
                if (!areJobsBeingProcessed())
                {
                    if (notProcessedTimer <= 0)
                    {
                        DialogResult res = MessageBox.Show(
                            "The issued jobs have not been acquired by the working clients yet. \n " +
                            "This may mean that the clients are down, or otherwise busy with other work. \n" +
                            "Would you like to continue to wait? \n\n " +
                            "Click YES to wait in line for the network. \n\n Click NO to cancel. ",
                            "Think about it..",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Exclamation);
                        if (res == DialogResult.Yes)
                        {
                            notProcessedTimer = 10;//in seconds (due to the sleep @ the bottom of this thread
                        }
                        else if (res == DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                    else
                    {
                        notProcessedTimer--;
                    }
                }
                else
                {
                    notProcessedTimer = 60; //reset the timer
                }
                for (int i = 0; i < filesToCheck.Count; i++)
                {
                    if (File.Exists(filesToCheck[i]))
                    {
                        mWorkerThread.ReportProgress(mNumSectionsToComplete - 1 - filesToCheck[i].Length, filesToCheck[i]);
                        filesToCheck.RemoveAt(i);
                        i--;
                    }
                }


                Thread.Sleep(1000);
            }

            e.Result = mNumSectionsToComplete;// This gets passed to RunWorkerCopmleted
        }