process.h
Engine/source/core/util/journal/process.h
Classes:
class
Event generation signal.
class
Register a command line handling function.
class
Register a processing function.
Public Defines
define
PROCESS_DEFAULT_ORDER() 0.5f
define
PROCESS_FIRST_ORDER() 0.0f
define
PROCESS_INPUT_ORDER() 0.4f
define
PROCESS_LAST_ORDER() 1.0f
define
PROCESS_NET_ORDER() 0.35f
define
PROCESS_RENDER_ORDER() 0.8f
define
PROCESS_TIME_ORDER() 0.75f
Detailed Description
Public Defines
PROCESS_DEFAULT_ORDER() 0.5f
PROCESS_FIRST_ORDER() 0.0f
PROCESS_INPUT_ORDER() 0.4f
PROCESS_LAST_ORDER() 1.0f
PROCESS_NET_ORDER() 0.35f
PROCESS_RENDER_ORDER() 0.8f
PROCESS_TIME_ORDER() 0.75f
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _UTIL_JOURNAL_PROCESS_H_ 25#define _UTIL_JOURNAL_PROCESS_H_ 26 27#include "platform/platform.h" 28#include "core/util/tVector.h" 29#include "core/util/delegate.h" 30#include "core/util/tSignal.h" 31 32 33#define PROCESS_FIRST_ORDER 0.0f 34#define PROCESS_NET_ORDER 0.35f 35#define PROCESS_INPUT_ORDER 0.4f 36#define PROCESS_DEFAULT_ORDER 0.5f 37#define PROCESS_TIME_ORDER 0.75f 38#define PROCESS_RENDER_ORDER 0.8f 39#define PROCESS_LAST_ORDER 1.0f 40 41class StandardMainLoop; 42 43 44/// Event generation signal. 45/// 46/// Objects that generate events need to register a callback with 47/// this signal and should only generate events from within the callback. 48/// 49/// This signal is triggered from the ProcessEvents() method. 50class Process 51{ 52public: 53 /// Trigger the ProcessSignal and replay journal events. 54 /// 55 /// The ProcessSignal is triggered during which all events are generated, 56 /// journaled, and delivered using the EventSignal classes. Event producers should 57 /// only generate events from within the function they register with ProcessSignal. 58 /// ProcessSignal is also triggered during event playback, though all new events are 59 /// thrown away so as not to interfere with journal playback. 60 /// This function returns false if Process::requestShutdown() has been called, otherwise it 61 /// returns true. 62 /// 63 /// NOTE: This should only be called from main loops - it should really be private, 64 /// but we need to sort out how to handle the unit test cases 65 static bool processEvents(); 66 67 /// Ask the processEvents() function to shutdown. 68 static void requestShutdown(S32 status = 0); 69 70 71 static void notifyInit(Delegate<bool()> del, F32 order = PROCESS_DEFAULT_ORDER) 72 { 73 get()._signalInit.notify(del,order); 74 } 75 76 template <class T> 77 static void notifyInit(T func, F32 order = PROCESS_DEFAULT_ORDER) 78 { 79 get()._signalInit.notify(func,order); 80 } 81 82 83 static void notifyCommandLine(Delegate<void(S32, const char **)> del, F32 order = PROCESS_DEFAULT_ORDER) 84 { 85 get()._signalCommandLine.notify(del,order); 86 } 87 88 template <class T> 89 static void notifyCommandLine(T func, F32 order = PROCESS_DEFAULT_ORDER) 90 { 91 get()._signalCommandLine.notify(func,order); 92 } 93 94 95 static void notify(Delegate<void()> del, F32 order = PROCESS_DEFAULT_ORDER) 96 { 97 get()._signalProcess.notify(del,order); 98 } 99 100 static void notify(SignalSlot<void()> &slot, F32 order = PROCESS_DEFAULT_ORDER) 101 { 102 get()._signalProcess.notify(slot,order); 103 } 104 105 template <class T> 106 static void notify(T func, F32 order = PROCESS_DEFAULT_ORDER) 107 { 108 get()._signalProcess.notify(func,order); 109 } 110 111 template <class T,class U> 112 static void notify(T obj,U func, F32 order = PROCESS_DEFAULT_ORDER) 113 { 114 get()._signalProcess.notify(obj,func,order); 115 } 116 117 118 static void remove(Delegate<void()> del) 119 { 120 get()._signalProcess.remove(del); 121 } 122 123 template <class T> 124 static void remove(T func) 125 { 126 get()._signalProcess.remove(func); 127 } 128 129 template <class T,class U> 130 static void remove(T obj,U func) 131 { 132 get()._signalProcess.remove(obj,func); 133 } 134 135 136 static void notifyShutdown(Delegate<bool(void)> del, F32 order = PROCESS_DEFAULT_ORDER) 137 { 138 get()._signalShutdown.notify(del,order); 139 } 140 141 template <class T> 142 static void notifyShutdown(T func, F32 order = PROCESS_DEFAULT_ORDER) 143 { 144 get()._signalShutdown.notify(func,order); 145 } 146 147 /// Trigger the registered init functions 148 static bool init(); 149 150 /// Trigger the registered shutdown functions 151 static bool shutdown(); 152 153 /// get the current return status code we've been asked to end with. 154 static S32 getReturnStatus(); 155 156private: 157 friend class StandardMainLoop; 158 159 /// Trigger the registered command line handling functions 160 static void handleCommandLine(S32 argc, const char **argv); 161 162 /// Private constructor 163 Process(); 164 165 /// Access method will construct the singleton as necessary 166 static Process &get(); 167 168 Signal<bool()> _signalInit; 169 Signal<void(S32, const char **)> _signalCommandLine; 170 Signal<void()> _signalProcess; 171 Signal<bool()> _signalShutdown; 172 173 bool _RequestShutdown; 174 S32 _ReturnStatus; 175}; 176 177/// Register a command line handling function. 178/// 179/// To use this, put it as a member variable into your module definition. 180class ProcessRegisterCommandLine 181{ 182public: 183 template <class T> 184 ProcessRegisterCommandLine( T func, F32 order = PROCESS_DEFAULT_ORDER ) 185 { 186 Process::notifyCommandLine( func, order ); 187 } 188}; 189 190/// Register a processing function 191/// 192/// To use this, put it as a member variable into your module definition. 193class ProcessRegisterProcessing 194{ 195public: 196 template <class T> 197 ProcessRegisterProcessing( T func, F32 order = PROCESS_DEFAULT_ORDER ) 198 { 199 Process::notify( func, order ); 200 } 201}; 202 203#endif 204