85 #include "controller.h"
87 #include "../submodules/CoreLibrary/CoreLibrary/utils.h"
93 using namespace r_code;
95 const float32 PLUS_INFINITY = std::numeric_limits<float>::infinity();
102 uint32 View::lastOID_ = 0;
107 controller_->invalidate();
110 uint32 View::GetOID() {
113 uint32 oid = lastOID_++;
118 uint16 View::ViewOpcode_;
120 float32 View::MorphValue(float32 value, float32 source_thr, float32 destination_thr) {
123 return destination_thr;
125 if (source_thr > 0) {
127 if (destination_thr > 0) {
129 float32 r = value * destination_thr / source_thr;
136 return destination_thr + value;
139 float32 View::MorphChange(float32 change, float32 source_thr, float32 destination_thr) {
141 if (source_thr > 0) {
143 if (destination_thr > 0)
144 return change * destination_thr / source_thr;
148 return destination_thr + change;
151 View::View(View *view, Group *group) : r_code::
_View(), controller_(NULL) {
153 Group *source = view->get_host();
154 object_ = view->object_;
155 memcpy(code_, view->code_, VIEW_CODE_MAX_SIZE *
sizeof(
Atom));
156 code_[VIEW_OID].atom_ = GetOID();
157 references_[0] = group;
158 references_[1] = source;
161 code(VIEW_SLN) = Atom::Float(MorphValue(view->code(VIEW_SLN).asFloat(), source->get_sln_thr(), group->get_sln_thr()));
162 switch (object_->code(0).getDescriptor()) {
164 code(GRP_VIEW_VIS) = Atom::Float(MorphValue(view->code(GRP_VIEW_VIS).asFloat(), source->get_vis_thr(), group->get_vis_thr()));
166 case Atom::NULL_PROGRAM:
167 case Atom::INSTANTIATED_PROGRAM:
168 case Atom::INSTANTIATED_CPP_PROGRAM:
169 case Atom::INSTANTIATED_INPUT_LESS_PROGRAM:
170 case Atom::INSTANTIATED_ANTI_PROGRAM:
171 case Atom::COMPOSITE_STATE:
173 code(VIEW_ACT) = Atom::Float(MorphValue(view->code(VIEW_ACT).asFloat(), source->get_act_thr(), group->get_act_thr()));
186 void View::reset_ctrl_values() {
197 periods_at_low_sln_ = 0;
198 periods_at_high_sln_ = 0;
199 periods_at_low_act_ = 0;
200 periods_at_high_act_ = 0;
203 void View::reset_init_sln() {
205 initial_sln_ = get_sln();
208 void View::reset_init_act() {
211 initial_act_ = get_act();
216 float32 View::update_res() {
218 float32 new_res = get_res();
219 if (new_res == PLUS_INFINITY)
221 if (res_changes_ > 0 && acc_res_ != 0)
222 new_res = get_res() + (float32)acc_res_ / (float32)res_changes_;
225 code(VIEW_RES) = r_code::Atom::Float(new_res);
231 float32 View::update_sln(float32 low, float32 high) {
233 if (sln_changes_ > 0 && acc_sln_ != 0) {
235 float32 new_sln = get_sln() + acc_sln_ / sln_changes_;
238 else if (new_sln > 1)
240 code(VIEW_SLN) = r_code::Atom::Float(new_sln);
245 float32 sln = get_sln();
247 ++periods_at_low_sln_;
250 periods_at_low_sln_ = 0;
252 ++periods_at_high_sln_;
254 periods_at_high_sln_ = 0;
259 float32 View::update_act(float32 low, float32 high) {
261 if (act_changes_ > 0 && acc_act_ != 0) {
263 float32 new_act = get_act() + acc_act_ / act_changes_;
266 else if (new_act > 1)
268 code(VIEW_ACT) = r_code::Atom::Float(new_act);
273 float32 act = get_act();
275 ++periods_at_low_act_;
278 periods_at_low_act_ = 0;
280 ++periods_at_high_act_;
282 periods_at_high_act_ = 0;
287 float32 View::update_vis() {
289 if (vis_changes_ > 0 && acc_vis_ != 0) {
291 float32 new_vis = get_vis() + acc_vis_ / vis_changes_;
294 else if (new_vis > 1)
296 code(GRP_VIEW_VIS) = r_code::Atom::Float(new_vis);
303 void View::delete_from_object() {
305 object_->acq_views();
306 object_->views_.erase(
this);
307 if (object_->views_.size() == 0)
308 object_->invalidate();
309 object_->rel_views();
312 void View::delete_from_group() {
314 Group *g = get_host();
316 g->delete_view(
this);
322 NotificationView::NotificationView(
Code *origin,
Code *destination,
Code *marker) : View() {
324 code(VIEW_OPCODE) = r_code::Atom::SSet(ViewOpcode_, VIEW_ARITY);
325 code(VIEW_SYNC) = r_code::Atom::Float(View::SYNC_ONCE);
326 code(VIEW_IJT) = r_code::Atom::IPointer(VIEW_ARITY + 1);
327 code(VIEW_SLN) = r_code::Atom::Float(1);
328 code(VIEW_RES) = r_code::Atom::Float(_Mem::Get()->get_ntf_mk_res());
329 code(VIEW_HOST) = r_code::Atom::RPointer(0);
330 code(VIEW_ORG) = r_code::Atom::RPointer(1);
331 code(VIEW_ARITY + 1) = r_code::Atom::Timestamp();
332 code(VIEW_ARITY + 2) = 0;
333 code(VIEW_ARITY + 3) = 0;
334 references_[0] = destination;
335 references_[1] = origin;