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)
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
26 #ifndef STEAM_ENGINE_DISPATCHER_H
27 #define STEAM_ENGINE_DISPATCHER_H
28 
29 #include "steam/common.hpp"
33 #include "steam/play/timings.hpp"
35 #include "lib/iter-explorer.hpp"
36 #include "lib/time/timevalue.hpp"
37 #include "lib/nocopy.hpp"
38 
39 #include <functional>
40 #include <utility>
41 #include <tuple>
42 
43 
44 namespace steam {
45 namespace engine {
46 
47  using std::move;
48  using std::make_pair;
49  using mobject::ModelPort;
50  using play::Timings;
51  using play::DataSink;
53  using lib::time::TimeSpan;
54  using lib::time::FrameCnt;
55  using lib::time::FSecs;
56  using lib::time::Time;
57 
58 
81  class Dispatcher
83  {
84 
85  struct PipeFrameTick;
86 
87  template<class IT>
89 
90 
91  public:
92  virtual ~Dispatcher();
93 
94 
103 
114  template<class IT>
116 
128  virtual size_t resolveModelPort (ModelPort) =0;
129 
136  virtual JobTicket& getJobTicketFor (size_t portIDX, TimeValue nominalTime) =0;
137 
139  Job createJobFor (size_t portIDX, TimeValue nominalTime);
140  };
141 
142 
143 
144 
145  /* ======== Steps of the Job-planning Pipeline ======== */
146 
151  {
152  Dispatcher * const dispatcher;
153  const Timings timings;
154 
155  TimeVar currPoint{Time::NEVER};
156  TimeVar stopPoint{Time::NEVER};
157  FrameCnt frameNr{0};
158 
159 
160 
161  /* === state protocol API for IterStateWrapper === */
162  bool
163  checkPoint() const
164  {
165  return currPoint < stopPoint;
166  }
167 
168  TimeVar const&
169  yield() const
170  {
171  return currPoint;
172  }
173 
174  void
175  iterNext()
176  {
177  ++frameNr;
178  currPoint = timings.getFrameStartAt (frameNr);
179  }
180 
181  protected:
182  void
183  activate (Time start, Time after)
184  {
185  stopPoint = after;
186  frameNr = timings.getBreakPointAfter(start);
187  currPoint = timings.getFrameStartAt (frameNr);
188  }
189  };
190 
191 
192 
193 
203  template<class SRC>
205  : SRC
206  {
207 
211  auto
212  timeRange (Time start, Time after)
213  {
214  SRC::activate (start,after);
215  return buildPipeline (lib::explore (move(*this)));
216  } // expected next to invoke pullFrom(port,sink)
217 
218 
219 
224  auto
226  {
227  size_t portIDX = SRC::dispatcher->resolveModelPort(port);
228  return buildPipeline (
229  SRC::transform(
230  [portIDX](PipeFrameTick& core)
231  {
232  return JobPlanning{core.dispatcher->getJobTicketFor(portIDX, core.currPoint)
233  ,core.currPoint
234  ,core.frameNr};
235  }));
236  }
237 
238 
244  auto
246  {
247  return buildPipeline (
248  SRC::expandAll(
249  [](JobPlanning& currentLevel)
250  {
251  return currentLevel.buildDependencyPlanning();
252  }));
253  }
254 
266  auto
268  {
269  return terminatePipeline (
270  SRC::transform(
271  [sink](JobPlanning& currentLevel) -> JobPlanning&
272  {
274  return currentLevel;
275  })
276  .asIterator());
277  }
278 
279 
280  protected:
291  template<class PIP>
293  buildPipeline(PIP&& treeExplorer)
294  {
295  return PipelineBuilder<PIP> {move (treeExplorer)};
296  }
297 
298  template<class PIP>
300  terminatePipeline(PIP&& pipelineIterator)
301  {
302  return PlanningPipeline<PIP> {move (pipelineIterator)};
303  }
304  };
305 
306 
312  template<class PIP>
314  : PIP
315  {
316  FrameCnt
317  currFrameNr() const
318  {
319  return PIP::frameNr;
320  }
321 
322  bool
323  isBefore (Time breakPoint) const
324  {
325  return currFrameNr() < PIP::timings.getBreakPointAfter(breakPoint);
326  }
327 
328  Job
329  buildJob()
330  {
331  return PIP::operator->()->buildJob();
332  }
333 
334  Time
335  determineDeadline()
336  {
337  return PIP::operator->()->determineDeadline (PIP::timings);
338  }
339  };
340 
341 
342 
345  {
346  return PipelineBuilder<PipeFrameTick> {this, timings};
347  }
348 
349  inline Job
350  Dispatcher::createJobFor (size_t portIDX, TimeValue nominalTime)
351  {
352  return getJobTicketFor (portIDX, nominalTime)
353  .createJobFor (Time{nominalTime});
354  }
355 
356 
357 
358 }} // namespace steam::engine
359 #endif
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
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:225
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:143
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:86
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
auto timeRange(Time start, Time after)
Builder: start frame sequence.
Definition: dispatcher.hpp:212
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:267
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:81
denotes an opened connection ready to receive media data for output.
PipelineBuilder< PIP > buildPipeline(PIP &&treeExplorer)
Definition: dispatcher.hpp:293
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
virtual ~Dispatcher()
this is an interface
Definition: dispatcher.cpp:28
PipelineBuilder< PipeFrameTick > forCalcStream(Timings timings)
Start a builder sequence to assemble a job-planning pipeline, backed by this Dispatcher.
Definition: dispatcher.hpp:344
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:115
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
A Builder wrapper, allowing to build a Job-planning pipeline step by step, while supplying contextual...
Definition: dispatcher.hpp:88
Handle designating a point within the model, where actually output data can be pulled.
Definition: model-port.hpp:95
static const Time NEVER
border condition marker value. NEVER >= any time value
Definition: timevalue.hpp:314
Job-planning Step-1: establish a sequence of frame start times.
Definition: dispatcher.hpp:150
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:350
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:573
Building tree expanding and backtracking evaluations within hierarchical scopes.
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:312
Individual frame rendering task, forwarding to a closure.
Definition: job.h:268
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
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:78
Job createJobFor(Time nominalTime)
Core operation: build a concrete render job based on this blueprint.
Definition: job-ticket.cpp:71
auto expandPrerequisites()
Builder: cause a exhaustive depth-first search to recursively discover all prerequisites of each top-...
Definition: dispatcher.hpp:245