Lumiverse  2.5
A framework for creating lighting control applications
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Lumiverse::SimulationAnimationPatch Class Referenceabstract

A subclass of ArnoldPatch. Instead of interrupting the worker thread every time a new rendering task is received, this class keeps all requests in a queue. A worker thread grasps tasks and dumps frame buffer to a ArnoldFrameManager. More...

#include <SimulationAnimationPatch.h>

Inheritance diagram for Lumiverse::SimulationAnimationPatch:
Inheritance graph
[legend]

Public Types

typedef function< void()> FinishedCallbackFunction
 
typedef function< bool(set< Device * >)> IsUpdateRequiredFunction
 
typedef function< void(FrameDeviceInfo &)> CreateFrameInfoBodyFunction
 
typedef function< void()> InterruptFunction
 
typedef function< void()> ClearUpdateFlagsFunction
 

Public Member Functions

 SimulationAnimationPatch ()
 Constructs a SimulationAnimationPatch object.
 
 SimulationAnimationPatch (const JSONNode data)
 Constructs ArnoldPatch from JSON data. More...
 
virtual ~SimulationAnimationPatch ()
 Destroys the object.
 
void init ()
 Initializes Arnold with function of its parent class and starts a worker thread.
 
virtual void startRecording ()
 Starts recording. Main thread starts to send frame labeled as RECORDING info to worker.
 
virtual void endRecording ()
 Ends recording. Main thread stops to send frame labeled as RECORDING info to worker. It starts to send INTERACTIVE frame instead.
 
virtual void startInteractive ()
 Starts interactive mode. Worker thread can get interrupted. It always takes the most fresh info.
 
virtual SimulationAnimationMode getMode ()
 Returns the mode/state in which the patch is. More...
 
virtual string getType ()
 Gets the type of this object. More...
 
void update (set< Device * > devices, IsUpdateRequiredFunction isUpdateRequired, InterruptFunction interruptRender, ClearUpdateFlagsFunction clearUpdateFlags)
 Updates the rendering queue given the list of devices in the rig. More...
 
void close ()
 Waits for the worker thread and closes the Arnold session. More...
 
virtual void reset (InterruptFunction interruptRender)
 Resets the object to its initial state. More...
 
virtual void reset ()=0
 
virtual void stop ()
 Stops the patch. More...
 
virtual int addFinishedCallback (FinishedCallbackFunction func)
 Registers a callback function for parameter changed event. More...
 
virtual void deleteFinishedCallback (int id)
 Deletes a registered callback for parameter change. More...
 

Protected Member Functions

void loadJSON (const JSONNode data)
 Loads data from a parsed JSON object. More...
 
virtual void workerLoop ()
 Worker loop. More...
 
virtual void onWorkerFinished ()
 Helper to call all the registered callbacks for rendering finished event.
 
virtual void onRecording ()
 
virtual void onRendering ()
 
virtual void workerRender (FrameDeviceInfo frame)=0
 
virtual void createFrameInfoHeader (FrameDeviceInfo &frame)
 
virtual void createFrameInfoBody (set< Device * > devices, FrameDeviceInfo &frame, bool forceUpdate=false)=0
 
virtual void enqueueFrameInfo (const FrameDeviceInfo &frame)
 

Protected Attributes

std::thread * m_worker
 
std::mutex m_queue
 
std::vector< FrameDeviceInfom_queuedFrameDeviceInfo
 
std::chrono::time_point< std::chrono::system_clock > m_startPoint
 
SimulationAnimationMode m_mode
 Indicates the mode of SimulationAnimationPatch.
 
map< int, FinishedCallbackFunction > m_onFinishedFunctions
 The list for callback functions.
 

Detailed Description

A subclass of ArnoldPatch. Instead of interrupting the worker thread every time a new rendering task is received, this class keeps all requests in a queue. A worker thread grasps tasks and dumps frame buffer to a ArnoldFrameManager.

See also
ArnoldPatch, ArnoldFrameManager

Constructor & Destructor Documentation

Lumiverse::SimulationAnimationPatch::SimulationAnimationPatch ( const JSONNode  data)

Constructs ArnoldPatch from JSON data.

Parameters
dataJSONNode containing the SimulationAnimationPatch object data.

Member Function Documentation

int Lumiverse::SimulationAnimationPatch::addFinishedCallback ( FinishedCallbackFunction  func)
virtual

Registers a callback function for parameter changed event.

All registered functinos would be called when a parameter is changed by Device::setParam and Device::reset function.

Parameters
funcThe callback function.
Returns
The int id for the registered function.
See also
addMetadataChangedCallback(DeviceCallbackFunction func)
void Lumiverse::SimulationAnimationPatch::close ( )

Waits for the worker thread and closes the Arnold session.

The main thread sends a special frame info at the beginning of this function. (a info with devices list only containning a NULL) Then the thread would wait to join the worker thread. After all there are done, closes the arnold session as the parent class.

void Lumiverse::SimulationAnimationPatch::deleteFinishedCallback ( int  id)
virtual

Deletes a registered callback for parameter change.

Parameters
idThe id returned when the callback is registered
See also
addParameterChangedCallback(DeviceCallbackFunction func)
virtual SimulationAnimationMode Lumiverse::SimulationAnimationPatch::getMode ( )
inlinevirtual

Returns the mode/state in which the patch is.

Returns
The mode/state.
virtual string Lumiverse::SimulationAnimationPatch::getType ( )
inlinevirtual

Gets the type of this object.

Returns
String containing "SimulationAnimationPatch"

Reimplemented in Lumiverse::ArnoldAnimationPatch.

void Lumiverse::SimulationAnimationPatch::loadJSON ( const JSONNode  data)
protected

Loads data from a parsed JSON object.

Parameters
dataJSON data to load
void Lumiverse::SimulationAnimationPatch::reset ( InterruptFunction  interruptRender)
virtual

Resets the object to its initial state.

Including resetting start point, clearing frame manager, interrupting worker and clearing worker's queue.

void Lumiverse::SimulationAnimationPatch::stop ( )
virtual

Stops the patch.

The main thread would stop responding to new requests and the worker thread would be joined.

void Lumiverse::SimulationAnimationPatch::update ( set< Device * >  devices,
IsUpdateRequiredFunction  isUpdateRequired,
InterruptFunction  interruptRender,
ClearUpdateFlagsFunction  clearUpdateFlags 
)

Updates the rendering queue given the list of devices in the rig.

Before enqueuing the rendering info, main thread checks if there is any parameter or metadata changed during last update interval. It only adds a new request when it's truly necessary.

void Lumiverse::SimulationAnimationPatch::workerLoop ( )
protectedvirtual

Worker loop.

Dequeues a new task. Sets the light parameters and renders. Dumps the frame buffer. The loop ends when an end info is received.


The documentation for this class was generated from the following files: