|
| 1 | +//****************************************************************************** |
| 2 | +/// |
| 3 | +/// @file backend/control/parsertask.cpp |
| 4 | +/// |
| 5 | +/// This module implements the parser task in a multi-threaded architecture. |
| 6 | +/// |
| 7 | +/// @copyright |
| 8 | +/// @parblock |
| 9 | +/// |
| 10 | +/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8. |
| 11 | +/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd. |
| 12 | +/// |
| 13 | +/// POV-Ray is free software: you can redistribute it and/or modify |
| 14 | +/// it under the terms of the GNU Affero General Public License as |
| 15 | +/// published by the Free Software Foundation, either version 3 of the |
| 16 | +/// License, or (at your option) any later version. |
| 17 | +/// |
| 18 | +/// POV-Ray is distributed in the hope that it will be useful, |
| 19 | +/// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | +/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | +/// GNU Affero General Public License for more details. |
| 22 | +/// |
| 23 | +/// You should have received a copy of the GNU Affero General Public License |
| 24 | +/// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | +/// |
| 26 | +/// ---------------------------------------------------------------------------- |
| 27 | +/// |
| 28 | +/// POV-Ray is based on the popular DKB raytracer version 2.12. |
| 29 | +/// DKBTrace was originally written by David K. Buck. |
| 30 | +/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. |
| 31 | +/// |
| 32 | +/// @endparblock |
| 33 | +/// |
| 34 | +//****************************************************************************** |
| 35 | + |
| 36 | +// Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config) |
| 37 | +#include "backend/control/parsertask.h" |
| 38 | + |
| 39 | +// C++ variants of C standard header files |
| 40 | +// C++ standard header files |
| 41 | +// Boost header files |
| 42 | +// POV-Ray header files (base module) |
| 43 | +// (none at the moment) |
| 44 | + |
| 45 | +// POV-Ray header files (core module) |
| 46 | +#include "core/scene/tracethreaddata.h" |
| 47 | + |
| 48 | +// POV-Ray header files (parser module) |
| 49 | +#include "parser/parser.h" |
| 50 | + |
| 51 | +// POV-Ray header files (backend module) |
| 52 | +#include "backend/scene/backendscenedata.h" |
| 53 | + |
| 54 | +// this must be the last file included |
| 55 | +#include "base/povdebug.h" |
| 56 | + |
| 57 | +namespace pov |
| 58 | +{ |
| 59 | + |
| 60 | +using namespace pov_parser; |
| 61 | + |
| 62 | +ParserTask::ParserTask(std::shared_ptr<BackendSceneData> sd, const ParserOptions& opts) : |
| 63 | + SceneTask(new TraceThreadData(sd, opts.randomSeed), boost::bind(&ParserTask::SendFatalError, this, _1), "Parse", sd), |
| 64 | + mpParser(nullptr), |
| 65 | + mpBackendSceneData(sd), |
| 66 | + mOptions(opts), |
| 67 | + mLastProgressElapsedTime(0) |
| 68 | +{} |
| 69 | + |
| 70 | +void ParserTask::Run() |
| 71 | +{ |
| 72 | + mpParser.reset(new Parser(mpBackendSceneData, mOptions, messageFactory, *this, *this, *reinterpret_cast<TraceThreadData *>(GetDataPtr()))); |
| 73 | + mpParser->Run(); |
| 74 | +} |
| 75 | + |
| 76 | +void ParserTask::Stopped() |
| 77 | +{ |
| 78 | + mpParser.reset(); |
| 79 | + RenderBackend::SendSceneFailedResult(mpBackendSceneData->sceneId, kUserAbortErr, mpBackendSceneData->frontendAddress); |
| 80 | +} |
| 81 | + |
| 82 | +void ParserTask::Finish() |
| 83 | +{ |
| 84 | + if (mpParser != nullptr) |
| 85 | + { |
| 86 | + mpParser->GetParserDataPtr()->timeType = TraceThreadData::kParseTime; |
| 87 | + mpParser->GetParserDataPtr()->realTime = ConsumedRealTime(); |
| 88 | + mpParser->GetParserDataPtr()->cpuTime = ConsumedCPUTime(); |
| 89 | + mpParser->Finish(); |
| 90 | + mpParser.reset(); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +void ParserTask::SendFatalError(Exception& e) |
| 95 | +{ |
| 96 | + if (mpParser != nullptr) |
| 97 | + mpParser->SendFatalError(e); |
| 98 | +} |
| 99 | + |
| 100 | +UCS2String ParserTask::FindFile(UCS2String parsedFileName, unsigned int fileType) |
| 101 | +{ |
| 102 | + return mpBackendSceneData->FindFile(GetPOVMSContext(), parsedFileName, fileType); |
| 103 | +} |
| 104 | + |
| 105 | +IStream* ParserTask::ReadFile(const UCS2String& parsedFileName, const UCS2String& foundFileName, unsigned int fileType) |
| 106 | +{ |
| 107 | + return mpBackendSceneData->ReadFile(GetPOVMSContext(), parsedFileName, foundFileName, fileType); |
| 108 | +} |
| 109 | + |
| 110 | +OStream* ParserTask::CreateFile(const UCS2String& parsedFileName, unsigned int fileType, bool append) |
| 111 | +{ |
| 112 | + return mpBackendSceneData->CreateFile(GetPOVMSContext(), parsedFileName, fileType, append); |
| 113 | +} |
| 114 | + |
| 115 | +void ParserTask::ReportProgress(POV_LONG tokenCount) |
| 116 | +{ |
| 117 | + POV_LONG elapsedTime = ElapsedRealTime(); |
| 118 | + if ((elapsedTime - mLastProgressElapsedTime) > kMinProgressReportInterval) |
| 119 | + { |
| 120 | + POVMS_Object obj(kPOVObjectClass_ParserProgress); |
| 121 | + obj.SetLong(kPOVAttrib_RealTime, elapsedTime); |
| 122 | + obj.SetLong(kPOVAttrib_CurrentTokenCount, tokenCount); |
| 123 | + RenderBackend::SendSceneOutput(mpBackendSceneData->sceneId, mpBackendSceneData->frontendAddress, kPOVMsgIdent_Progress, obj); |
| 124 | + Cooperate(); |
| 125 | + mLastProgressElapsedTime = ElapsedRealTime(); |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +} // end of namespace pov |
0 commit comments