Lumiera  0.pre.03
»edit your freedom«
dispatcher.hpp
Go to the documentation of this file.
1 /*
2  DISPATCHER.hpp - translating calculation streams into frame jobs
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
35 #ifndef STEAM_ENGINE_DISPATCHER_H
36 #define STEAM_ENGINE_DISPATCHER_H
37 
38 #include "steam/common.hpp"
42 #include "steam/play/timings.hpp"
44 #include "lib/iter-explorer.hpp"
45 #include "lib/time/timevalue.hpp"
46 #include "lib/nocopy.hpp"
47 
48 #include <functional>
49 #include <utility>
50 #include <tuple>
51 
52 
53 namespace steam {
54 namespace engine {
55 
56  using std::move;
57  using std::make_pair;
58  using mobject::ModelPort;
59  using play::Timings;
60  using play::DataSink;
62  using lib::time::TimeSpan;
63  using lib::time::FrameCnt;
64  using lib::time::FSecs;
65  using lib::time::Time;
66 
67 
90  class Dispatcher
92  {
93 
94  struct PipeFrameTick;
95 
96  template<class IT>
98 
99 
100  public:
101  virtual ~Dispatcher();
102 
103 
112 
123  template<class IT>
125 
137  virtual size_t resolveModelPort (ModelPort) =0;
138 
145  virtual JobTicket& getJobTicketFor (size_t portIDX, TimeValue nominalTime) =0;
146 
148  Job createJobFor (size_t portIDX, TimeValue nominalTime);
149  };
150 
151 
152 
153 
154  /* ======== Steps of the Job-planning Pipeline ======== */
155 
160  {
161  Dispatcher * const dispatcher;
162  const Timings timings;
163 
164  TimeVar currPoint{Time::NEVER};
165  TimeVar stopPoint{Time::NEVER};
166  FrameCnt frameNr{0};
167 
168 
169 
170  /* === state protocol API for IterStateWrapper === */
171  bool
172  checkPoint() const
173  {
174  return currPoint < stopPoint;
175  }
176 
177  TimeVar const&
178  yield() const
179  {
180  return currPoint;
181  }
182 
183  void
184  iterNext()
185  {
186  ++frameNr;
187  currPoint = timings.getFrameStartAt (frameNr);
188  }
189 
190  protected:
191  void
192  activate (Time start, Time after)
193  {
194  stopPoint = after;
195  frameNr = timings.getBreakPointAfter(start);
196  currPoint = timings.getFrameStartAt (frameNr);
197  }
198  };
199 
200 
201 
202 
212  template<class SRC>
214  : SRC
215  {
216 
220  auto
221  timeRange (Time start, Time after)
222  {
223  SRC::activate (start,after);
224  return buildPipeline (lib::explore (move(*this)));
225  } // expected next to invoke pullFrom(port,sink)
226 
227 
228 
233  auto
235  {
236  size_t portIDX = SRC::dispatcher->resolveModelPort(port);
237  return buildPipeline (
238  SRC::transform(
239  [portIDX](PipeFrameTick& core)
240  {
241  return JobPlanning{core.dispatcher->getJobTicketFor(portIDX, core.currPoint)
242  ,core.currPoint
243  ,core.frameNr};
244  }));
245  }
246 
247 
253  auto
255  {
256  return buildPipeline (
257  SRC::expandAll(
258  [](JobPlanning& currentLevel)
259  {
260  return currentLevel.buildDependencyPlanning();
261  }));
262  }
263 
275  auto
277  {
278  return terminatePipeline (
279  SRC::transform(
280  [sink](JobPlanning& currentLevel) -> JobPlanning&
281  {
283  return currentLevel;
284  })
285  .asIterator());
286  }
287 
288 
289  protected:
300  template<class PIP>
302  buildPipeline(PIP&& treeExplorer)
303  {
304  return PipelineBuilder<PIP> {move (treeExplorer)};
305  }
306 
307  template<class PIP>
309  terminatePipeline(PIP&& pipelineIterator)
310  {
311  return PlanningPipeline<PIP> {move (pipelineIterator)};
312  }
313  };
314 
315 
321  template<class PIP>
323  : PIP
324  {
325  FrameCnt
326  currFrameNr() const
327  {
328  return PIP::frameNr;
329  }
330 
331  bool
332  isBefore (Time breakPoint) const
333  {
334  return currFrameNr() < PIP::timings.getBreakPointAfter(breakPoint);
335  }
336 
337  Job
338  buildJob()
339  {
340  return PIP::operator->()->buildJob();
341  }
342 
343  Time
344  determineDeadline()
345  {
346  return PIP::operator->()->determineDeadline (PIP::timings);
347  }
348  };
349 
350 
351 
354  {
355  return PipelineBuilder<PipeFrameTick> {this, timings};
356  }
357 
358  inline Job
359  Dispatcher::createJobFor (size_t portIDX, TimeValue nominalTime)
360  {
361  return getJobTicketFor (portIDX, nominalTime)
362  .createJobFor (Time{nominalTime});
363  }
364 
365 
366 
367 }} // namespace steam::engine
368 #endif
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
auto pullFrom(mobject::ModelPort port)
Builder: connect to the JobTicket defining the actual processing for the nominal time of this frame a...
Definition: dispatcher.hpp:234
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:152
Organising the output data calculation possibilities.
An (abstract) capability to send media data to an external output.
Basic set of definitions and includes commonly used together.
Aggregation of planning data to generate actual frame calculation jobs.
Execution plan to generate render jobs within a specific render process.
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
Generic frame timing specification.
Definition: timings.hpp:95
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
auto timeRange(Time start, Time after)
Builder: start frame sequence.
Definition: dispatcher.hpp:221
virtual size_t resolveModelPort(ModelPort)=0
translate a generic ModelPort spec into the specific index number applicable at the Timeline referred...
auto feedTo(play::DataSink &sink)
Terminal builder: setup processing feed to the given DataSink.
Definition: dispatcher.hpp:276
virtual JobTicket & getJobTicketFor(size_t portIDX, TimeValue nominalTime)=0
Core Dispatcher operation: locate the appropriate Segment and retrieve/derive a »blueprint« for rende...
Internal abstraction: a service within the engine for translating a logical calculation stream (corre...
Definition: dispatcher.hpp:90
denotes an opened connection ready to receive media data for output.
PipelineBuilder< PIP > buildPipeline(PIP &&treeExplorer)
Definition: dispatcher.hpp:302
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
virtual ~Dispatcher()
this is an interface
Definition: dispatcher.cpp:37
PipelineBuilder< PipeFrameTick > forCalcStream(Timings timings)
Start a builder sequence to assemble a job-planning pipeline, backed by this Dispatcher.
Definition: dispatcher.hpp:353
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A complete job-planning pipeline: this »Lumiera Forward Iterator« drives the actual job-planning proc...
Definition: dispatcher.hpp:124
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
A Builder wrapper, allowing to build a Job-planning pipeline step by step, while supplying contextual...
Definition: dispatcher.hpp:97
Handle designating a point within the model, where actually output data can be pulled.
Definition: model-port.hpp:104
static const Time NEVER
border condition marker value. NEVER >= any time value
Definition: timevalue.hpp:323
Job-planning Step-1: establish a sequence of frame start times.
Definition: dispatcher.hpp:159
How to define a timing specification or constraint.
View on the execution planning for a single calculation step.
Job createJobFor(size_t portIDX, TimeValue nominalTime)
Convenience shortcut for tests: JobTicket ⟼ Job.
Definition: dispatcher.hpp:359
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
Building tree expanding and backtracking evaluations within hierarchical scopes.
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:321
Individual frame rendering task, forwarding to a closure.
Definition: job.h:277
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
auto buildDependencyPlanning()
Build a sequence of dependent JobPlanning scopes for all prerequisites of this current JobPlanning...
execution plan for pulling a specific exit node.
Definition: job-ticket.hpp:87
Job createJobFor(Time nominalTime)
Core operation: build a concrete render job based on this blueprint.
Definition: job-ticket.cpp:79
auto expandPrerequisites()
Builder: cause a exhaustive depth-first search to recursively discover all prerequisites of each top-...
Definition: dispatcher.hpp:254