THRESHOLDOBJ::THRESHOLDOBJ(int num) : BASE_CL() { outports = 1; inports = 1; width=65; strcpy(in_ports[0].in_name,"in"); strcpy(out_ports[0].out_name,"out"); play_interval=0;from_input=1; to_input=512; signal_gain=100; strcpy (wndcaption,"Meter"); last_value=0; for (accupos=0;accupos<ACCULEN;accupos++) accu[accupos]=0; accupos=0;redraw=1;firstadapt=1; interval_len=1; op=TRUE; usemedian=1;avgsum=0;baseline=0; showmeter=1;rising=0;falling=0; bigadapt=0;smalladapt=0;adapt_interval=200; input=0;gained_value=0; fontsize=10; barsize=30; left=510;right=550;top=20;bottom=400; color=RGB(0,0,100);bkcolor=RGB(255,255,255);fontcolor=0;fontbkcolor=RGB(255,255,255); empty_buckets(); if (!(font = CreateFont(-MulDiv(fontsize, GetDeviceCaps(GetDC(NULL), LOGPIXELSY), 72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"))) report_error("Font creation failed!"); if(!(displayWnd=CreateWindow("Meter_Class", wndcaption, WS_CLIPSIBLINGS| WS_CHILD | WS_CAPTION | WS_THICKFRAME ,left, top, right-left, bottom-top, ghWndMain, NULL, hInst, NULL))) report_error("can't create Meter Window"); else { SetForegroundWindow(displayWnd); ShowWindow( displayWnd, TRUE ); UpdateWindow( displayWnd ); } InvalidateRect(displayWnd, NULL, TRUE); }
void outlines_to_blobs( // find blobs BLOCK *block, // block to scan ICOORD bleft, ICOORD tright, C_OUTLINE_LIST *outlines) { // make buckets OL_BUCKETS buckets(bleft, tright); fill_buckets(outlines, &buckets); empty_buckets(block, &buckets); }
std::list<item> player::consume_items( const comp_selection<item_comp> &is, int batch ) { std::list<item> ret; if( has_trait( trait_DEBUG_HS ) ) { return ret; } item_comp selected_comp = is.comp; const tripoint &loc = pos(); const bool by_charges = ( item::count_by_charges( selected_comp.type ) && selected_comp.count > 0 ); // Count given to use_amount/use_charges, changed by those functions! long real_count = ( selected_comp.count > 0 ) ? selected_comp.count * batch : abs( selected_comp.count ); // First try to get everything from the map, than (remaining amount) from player if( is.use_from & use_from_map ) { if( by_charges ) { std::list<item> tmp = g->m.use_charges( loc, PICKUP_RANGE, selected_comp.type, real_count ); ret.splice( ret.end(), tmp ); } else { std::list<item> tmp = g->m.use_amount( loc, PICKUP_RANGE, selected_comp.type, real_count ); remove_ammo( tmp, *this ); ret.splice( ret.end(), tmp ); } } if( is.use_from & use_from_player ) { if( by_charges ) { std::list<item> tmp = use_charges( selected_comp.type, real_count ); ret.splice( ret.end(), tmp ); } else { std::list<item> tmp = use_amount( selected_comp.type, real_count ); remove_ammo( tmp, *this ); ret.splice( ret.end(), tmp ); } } // condense those items into one if( by_charges && ret.size() > 1 ) { std::list<item>::iterator b = ret.begin(); b++; while( ret.size() > 1 ) { ret.front().charges += b->charges; b = ret.erase( b ); } } lastconsumed = selected_comp.type; empty_buckets( *this ); return ret; }
void THRESHOLDOBJ::work(void) { float l,x,sum; int t,i; x=(float)((input)*signal_gain/100.0); l=accu[accupos]; avgsum+=x; // (float)input; if ((accupos>=999)||(accupos<0)) accupos=0; else accupos++; accu[accupos]=x; sum=0; for (t=0;t<interval_len;t++) { i=accupos-t; if (i<0) i+=1000; sum+=accu[i]; } gained_value=sum/interval_len; long interval=adapt_interval; if ((baseline) && (!usemedian)) { interval*=PACKETSPERSECOND; } if (adapt_num >= interval) { if (usemedian) { int numtrue, i, sum; if (bigadapt != 0) { numtrue = (int)(adapt_num * bigadapt / 100.0f); for (i = 1024, sum = 0; (i >= 0) && (sum < numtrue); i--) { sum += buckets[i]; } from_input = size_value(0.0f,1024.0f,(float)i,in_ports[0].in_min,in_ports[0].in_max,0); redraw=1; } if (smalladapt != 0) { numtrue = (int)(adapt_num * smalladapt / 100.0f); for (i = 0, sum = 0; (i <= 1024) && (sum < numtrue); i++) { sum += buckets[i]; } to_input = size_value(0.0f,1024.0f,(float)i,in_ports[0].in_min,in_ports[0].in_max,0); redraw=1; } empty_buckets(); } else { if ((!baseline) || (firstadapt)) { if (bigadapt != 0) { from_input = avgsum/interval*bigadapt/100.0f; redraw=1; } if (smalladapt != 0) { to_input = avgsum/interval*smalladapt/100.0f; redraw=1; } firstadapt=0; } } adapt_num=0; avgsum=0; } x=gained_value; if (rising&&(l>=accu[accupos])) x=INVALID_VALUE; if (falling&&(l<=accu[accupos])) x=INVALID_VALUE; if (op&&((gained_value<from_input)||(gained_value>to_input))) x=INVALID_VALUE; if ((!op)&&((gained_value<from_input)&&(gained_value>to_input))) x=INVALID_VALUE; if (baseline && firstadapt) x=INVALID_VALUE; pass_values(0,x); if ((hDlg==ghWndToolbox)&&(!TIMING.dialog_update)) { char temp[100]; sprintf(temp,"%.2f",from_input); SetDlgItemText(hDlg, IDC_AVGFROM, temp); sprintf(temp,"%.2f",to_input); SetDlgItemText(hDlg, IDC_AVGTO, temp); if (smalladapt) SetScrollPos(GetDlgItem(hDlg,IDC_AVGTOBAR), SB_CTL,(int) size_value(in_ports[0].in_min,in_ports[0].in_max, to_input,0.0f,1000.0f,0),TRUE); if (bigadapt) SetScrollPos(GetDlgItem(hDlg,IDC_AVGFROMBAR), SB_CTL,(int) size_value(in_ports[0].in_min,in_ports[0].in_max, from_input ,0.0f,1000.0f,0),TRUE); } if ((displayWnd)&&(!TIMING.draw_update)&&(!GLOBAL.fly)) InvalidateRect(displayWnd,NULL,FALSE); }
void THRESHOLDOBJ::session_pos(long pos) { accupos=0;avgsum=0; for (int t=0;t<1000;t++) accu[t]=0; empty_buckets(); }
void THRESHOLDOBJ::session_reset(void) { accupos=0;firstadapt=1;avgsum=0; for (int t=0;t<1000;t++) accu[t]=0; empty_buckets(); }
void THRESHOLDOBJ::session_start(void) { accupos=0; for (int t=0;t<interval_len;t++) accu[t]=0; empty_buckets(); }