void TimestampMergeFilter::filter(){
	Counter counter;
	counter.registerCallback([&](uint64_t countPerSec){
		string msg = to_string(countPerSec) + " line/s";
		if(m_inputQueue->empty()) msg += "\tstarving!";
		if(m_outputQueue->full()) msg += "\tblocked!";
		m_msgQueue->enqueue(Message(TIMESTAMP_MERGE_FILTER, msg));
	});
	counter.start();

	try{
		while(true){
			Observation obs = m_inputQueue->dequeue();
			if(m_buffer.empty()){
				m_buffer.push_front(obs);
			} else{
				if(*obs.date == *m_buffer.front().date && *obs.time == *m_buffer.front().time){
					m_buffer.push_front(obs);
				} else{
					m_outputQueue->enqueue(getMergedObs());
					m_buffer.clear();
					counter.tick();
					m_buffer.push_front(obs);
				}
			}
		}
	} catch(ObsQueue::QueueEndException&){
		if(!m_buffer.empty()){
			m_outputQueue->enqueue(getMergedObs());
			counter.stop();
			m_buffer.clear();
		}
		m_msgQueue->enqueue(Message(TIMESTAMP_MERGE_FILTER, "Finished !"));
		m_outputQueue->setQueueEnd();
	}
}
Esempio n. 2
0
      void
      updateBeacons(void)
      {
        m_beacons.clear();
        IMC::MessageList<IMC::LblBeacon>::const_iterator itr = m_lbl_cfg->beacons.begin();
        for (unsigned i = 0; itr != m_lbl_cfg->beacons.end(); ++itr, ++i)
          addBeacon(i, *itr);
        m_beacon = m_beacons.begin();
        m_ping_time.reset();

        if (isActive())
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE);
        else
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_IDLE);
      }
Esempio n. 3
0
Stat* ProcStats::replStat(Stat* s, const char* name, const char* desc) {
    if (!name) name = s->name();
    if (!desc) desc = s->desc();
    if (AggregateStat* as = dynamic_cast<AggregateStat*>(s)) {
        AggregateStat* res = new AggregateStat(as->isRegular());
        res->init(name, desc);
        for (uint32_t i = 0; i < as->size(); i++) {
            res->append(replStat(as->get(i)));
        }
        return res;
    } else if (dynamic_cast<ScalarStat*>(s)) {
        Counter* res = new ProcessCounter(this);
        res->init(name, desc);
        return res;
    } else if (VectorStat* vs = dynamic_cast<VectorStat*>(s)) {
        VectorCounter* res = new ProcessVectorCounter(this);
        assert(!vs->hasCounterNames());  // FIXME: Implement counter name copying
        res->init(name, desc, vs->size());
        return res;
    } else {
        panic("Unrecognized stat type");
        return nullptr;
    }
}
Esempio n. 4
0
bool MainLayer::init()
{
	/*-- 设置整体层属性 --*/
	this->setTouchMode(kCCTouchesOneByOne);
	this->setTouchEnabled(true);
	this->scheduleUpdate();
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	this->ignoreAnchorPointForPosition(true);
	setAnchorPoint(ccp(0.5f, 0.5f));
	this->setContentSize(s);
	setPosition(ccp(s.width / 2, s.height / 2));

	CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
	float width = vsize.width / 2;
	float height = vsize.height / 2;
	Counter *counter = Counter::sharedCounter();
	counter->clearScore();
	if (counter->isSound()
			&& !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
	{
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true);
	}
	/*-- door --*/
	CCAnimation *doorAnimation =
			CCAnimationCache::sharedAnimationCache()->animationByName("door");
	//左侧
	CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	leftDoor->setPosition(ccp(-200, -50));
	leftDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(leftDoor);
	leftDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	//右侧
	CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	rightDoor->setPosition(ccp(200, -50));
	rightDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(rightDoor);
	rightDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	/*-- 分数 --*/
	CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"),
			counter->getStringByKey("font"), 46);
	titletxt->setColor(ccc3(98, 104, 191));
	titletxt->setAnchorPoint(ccp(0.5, 0.5));
	titletxt->setPosition(ccp(0, height - 130));
	this->addChild(titletxt);
	CCNode *scoreLabel = counter->create_label();
	scoreLabel->setPosition(ccp(0, height - 200));
	scoreLabel->setAnchorPoint(ccp(0.5, 1));
	this->addChild(scoreLabel, 3, TAG_SCORE);
	/*-- role --*/
	return true;
}
Esempio n. 5
0
void KMod::setupCounter(Counter &counter) {
	char base[128];
	char text[128];
	snprintf(base, sizeof(base), "/dev/gator/events/%s", counter.getType());

	snprintf(text, sizeof(text), "%s/enabled", base);
	int enabled = true;
	if (DriverSource::writeReadDriver(text, &enabled) || !enabled) {
		counter.setEnabled(false);
		return;
	}

	int value = 0;
	snprintf(text, sizeof(text), "%s/key", base);
	DriverSource::readIntDriver(text, &value);
	counter.setKey(value);

	snprintf(text, sizeof(text), "%s/cores", base);
	if (DriverSource::readIntDriver(text, &value) == 0) {
		counter.setCores(value);
	}

	snprintf(text, sizeof(text), "%s/event", base);
	DriverSource::writeDriver(text, counter.getEvent());
	snprintf(text, sizeof(text), "%s/count", base);
	if (access(text, F_OK) == 0) {
		int count = counter.getCount();
		if (DriverSource::writeReadDriver(text, &count) && counter.getCount() > 0) {
			logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount());
			handleException();
		}
		counter.setCount(count);
	} else if (counter.getCount() > 0) {
		ConfigurationXML::remove();
		logg->logError(__FILE__, __LINE__, "Event Based Sampling is only supported with kernel versions 3.0.0 and higher with CONFIG_PERF_EVENTS=y, and CONFIG_HW_PERF_EVENTS=y. The invalid configuration.xml has been removed.\n");
		handleException();
	}
}
Esempio n. 6
0
      void
      setBrightness(LED* led, uint8_t value)
      {
        uint8_t id = led->id;
        uint16_t ticks = ((value * m_dif_dur) / 255) + m_min_dur;

        UCTK::Frame frame;
        frame.setId(PKT_ID_LED_PW);
        frame.setPayloadSize(3);
        frame.set(id, 0);
        frame.set(ticks, 1);

        if (m_ctl->sendFrame(frame))
        {
          led->brightness.value = value;
          m_wdog.reset();
        }
      }
Esempio n. 7
0
      void
      onResourceInitialization(void)
      {
        m_uart->writeString("\r");
        Delay::wait(1.0);
        m_uart->flush();

        if (!sendCommand("\r", "\r\n"))
          throw RestartNeeded(DTR("failed to enter command mode"), 5, false);

        if (!sendCommand("SET SAMPLE 1 s\r", ">SET SAMPLE 1 s\r\n"))
          throw RestartNeeded(DTR("failed to set sampling rate"), 5, false);

        if (!sendCommand("MONITOR\r", ">MONITOR\r\n"))
          throw RestartNeeded(DTR("failed to enter monitor mode"), 5, false);

        m_wdog.setTop(m_args.input_timeout);
      }
Esempio n. 8
0
      //! Update internal state with new parameter values.
      void
      onUpdateParameters(void)
      {
        clearLEDs();
        for (unsigned i = 0; i < m_args.led_names.size(); ++i)
        {
          LED* led = new LED;
          led->id = i;
          led->name = m_args.led_names[i];
          led->brightness.name = led->name;
          led->brightness.value = 0;
          m_led_by_name[led->name] = led;
          m_led_by_id[led->id] = led;
        }

        setConfig();

        m_wdog.setTop(m_args.wdog_tout);
      }
Esempio n. 9
0
      void
      onResourceInitialization(void)
      {
        m_uart->writeString("\r");
        Delay::wait(1.0);
        m_uart->flush();

        if (!sendCommand("\r", "\r\n"))
          throw RestartNeeded(DTR("failed to enter command mode"), 5);

        if (!sendCommand("SET SAMPLE 1 s\r", ">SET SAMPLE 1 s\r\n"))
          throw RestartNeeded(DTR("failed to set sampling rate"), 5);

        if (!sendCommand("MONITOR\r", ">MONITOR\r\n"))
          throw RestartNeeded(DTR("failed to enter monitor mode"), 5);

        setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE);
        m_wdog.setTop(m_args.input_timeout);
      }
Esempio n. 10
0
int main()
{
	Counter counter;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(2);
	for(int i=0; i<5; i++)
		counter.hit();
	sleep(3);
	cout<<counter.getCount()<<endl;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(6);
	cout<<counter.getCount()<<endl;
	sleep(3);
	cout<<counter.getCount()<<endl;
	
	return 0;
}
Esempio n. 11
0
void playWithCounter(Counter& ctr)
{
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);

	ctr--;
	print (ctr);
	ctr--;
	print (ctr);
	ctr--;
	print (ctr);

	ctr.reset();
	print (ctr);
	ctr--;
	print (ctr);
}
Esempio n. 12
0
        Task(const std::string& name, Tasks::Context& ctx):
          DUNE::Tasks::Task(name, ctx)
        {
          // Define configuration parameters.
          param("Entity Label - GPS", m_args.elabel_gps)
          .description("Entity label of 'GpsFix' and 'GroundVelocity' messages");

          param("Entity Label - IMU", m_args.elabel_imu)
          .description("Entity label of 'EulerAngles' and 'AngularVelocity' messages");

          param("Entity Label - Yaw", m_args.elabel_yaw)
          .description("Entity label of 'EulerAngles' messages (field 'psi')");

          m_estate.clear();

          // Navigation enters error mode without valid GPS data.
          m_time_without_gps.setTop(5.0);

          // Register callbacks
          bind<IMC::AngularVelocity>(this);
          bind<IMC::EulerAngles>(this);
          bind<IMC::GpsFix>(this);
          bind<IMC::GroundVelocity>(this);
        }
Esempio n. 13
0
JSValue* JSCounter::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case IdentifierAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->identifier());
    }
    case ListStyleAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->listStyle());
    }
    case SeparatorAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->separator());
    }
    case ConstructorAttrNum:
        return getConstructor(exec);
    }
    return 0;
}
Esempio n. 14
0
void print(const Counter& ctr)
{
	cout << ctr.getCounterValue() << endl;
}
void TestEventCounter::testIncreaseWeightedCounter() {
	Counter counter = Counter(dimension1, dimension2, dimension3);
	counter.increase(0, 0, 0, 2.4);
	ASSERT_EQUAL_DELTA(2.4, counter.getWeightedEntries(0, 0, 0), 0.1);
}
void TestEventCounter::testIncereaseCoutner() {
	Counter counter = Counter(dimension1, dimension2, dimension3);
	counter.increase(0, 0, 0, 2.4);
	ASSERT_EQUAL(1, counter.getEntries(0, 0, 0));
}
void TestEventCounter::testCounterConstructor() {
	Counter counter = Counter(dimension1, dimension2, dimension3);
	ASSERT_EQUAL(dimension1, counter.getSizeOfFirstDimension());
	ASSERT_EQUAL(dimension2, counter.getSizeOfSecondDimension());
	ASSERT_EQUAL(dimension3, counter.getSizeOfThirdDimension());
}
void TestEventCounter::testStandardCounterConstructor() {
	Counter standardCounter = Counter();
	ASSERT_EQUAL(0, standardCounter.getSizeOfFirstDimension());
	ASSERT_EQUAL(0, standardCounter.getSizeOfSecondDimension());
	ASSERT_EQUAL(0, standardCounter.getSizeOfThirdDimension());
}
Esempio n. 19
0
 ~Test() { Instance.dump("~~TERD", this); }
Esempio n. 20
0
 Test(const Test&) : Instance(sInstance) { Instance.dump("(*COPIED*)", this); }
Esempio n. 21
0
int main()
{
    Counter MomCounter;
    char choice;

    cout<<setw(4)<<setfill('0') << endl <<MomCounter.GetCount() << endl << endl;

    cin>>choice;

    choice=toupper(choice);


    while(choice!='X')
    {
        switch(choice)
        {

            case 'F':
                if(MomCounter.GetCount()+1<=MomCounter.GetMax())
                {
                MomCounter.Incr1();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }

                break;

            case 'D':
                if(MomCounter.GetCount()+10<=MomCounter.GetMax())
                {
                    MomCounter.Incr10();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;

            case 'S':
                if(MomCounter.GetCount()+100<=MomCounter.GetMax())
                {
                    MomCounter.Incr100();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;

            case 'A':
                if(MomCounter.GetCount()+1000<=MomCounter.GetMax())
                {
                    MomCounter.Incr1000();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;


            case 'R':
                MomCounter.Reset();
                break;


        }
        cout<<setw(4)<<setfill('0') << endl <<MomCounter.GetCount() << endl;
        cout<<"\n:" ;
        cin>>choice;


        choice = toupper(choice);
    }

    
    return 0;
}
Esempio n. 22
0
int main() {
    Counter i;
    std::cout << "The value of i is " << i.GetItsVal() << std::endl;
    return 0;
}
Esempio n. 23
0
void generateIOComponentModules()
{
	std::list<Output *> output_list;
	{
		boost::mutex::scoped_lock lock(thread_protection_mutex);

		int remaining = machines.size();
		std::cout << remaining << " Machines\n";
		std::cout << "Linking clockwork machines to hardware\n";
		std::map<std::string, MachineInstance*>::const_iterator iter = machines.begin();
		while (iter != machines.end())
		{
			const int error_buf_size = 100;
			char error_buf[error_buf_size];
			MachineInstance *m = (*iter).second;
			iter++;
			--remaining;
			if ( (m->_type == "POINT" || m->_type == "ANALOGINPUT"  || m->_type == "COUNTERRATE"
						|| m->_type == "COUNTER" 
						|| m->_type == "STATUS_FLAG" || m->_type == "ANALOGOUTPUT" ) && m->parameters.size() > 1)
			{
				output_points.push_back(m);
				// points should have two parameters, the name of the io module and the bit offset
				//Parameter module = m->parameters[0];
				//Parameter offset = m->parameters[1];
				//Value params = p.val;
				//if (params.kind == Value::t_list && params.listValue.size() > 1) {
				std::string name;
				unsigned int entry_position = 0;
				if (m->_type == "COUNTERRATE")
				{
					name = m->parameters[1].real_name;
					entry_position = m->parameters[2].val.iValue;
				}
				else
				{
					name = m->parameters[0].real_name;
					entry_position = m->parameters[1].val.iValue;
				}

#if 0
				std::cerr << "Setting up point " << m->getName() 
					<< " " << entry_position << " on module " << name << "\n";
#endif
				MachineInstance *module_mi = MachineInstance::find(name.c_str());
				if (!module_mi)
				{
					snprintf(error_buf, error_buf_size, "No machine called %s", name.c_str());
					MessageLog::instance()->add(error_buf);
					std::cerr << error_buf << "\n";
					error_messages.push_back(error_buf);
					++num_errors;
					continue;
				}
				if (!module_mi->properties.exists("position"))   // module position not given
				{
					snprintf(error_buf, error_buf_size, "Machine %s does not specify a position", 
						module_mi->getName().c_str());
					MessageLog::instance()->add(error_buf);
					std::cerr << error_buf << "\n";
					error_messages.push_back(error_buf);
					++num_errors;
					continue;
				}
				if (m->_type == "ANALOGOUTPUT") {
					const Value &default_value = m->properties.lookup("default");
					if (default_value == SymbolTable::Null) {
						snprintf(error_buf, error_buf_size, 
							"Machine %s must specify a default value", m->getName().c_str());
						MessageLog::instance()->add(error_buf);
						std::cerr << error_buf << "\n";
						error_messages.push_back(error_buf);
						++num_errors;
					}
				}
				int module_position = module_mi->properties.lookup("position").iValue;
				if (module_position == -1)    // module position unmapped
				{
					snprintf(error_buf, error_buf_size, "Machine %s position not mapped", name.c_str());
					MessageLog::instance()->add(error_buf);
					std::cerr << error_buf << "\n";
					continue;
				}

#ifndef EC_SIMULATOR
				// some modules have multiple io types (eg the EK1814) and therefore
				// multiple syncmasters, we number
				// the points from 1..n but the device numbers them 1.n,1.m,..., resetting
				// the index for each sync master.
				ECModule *module = ECInterface::findModule(module_position);
				if (!module)
				{
					snprintf(error_buf, error_buf_size, "No module found at position %d for %s", 
						module_position, m->getName().c_str());
					MessageLog::instance()->add(error_buf);
					std::cerr << error_buf << "\n";
					error_messages.push_back(error_buf);
					++num_errors;
					continue;
				}

				if (entry_position >= module->num_entries)
				{
					snprintf(error_buf, error_buf_size, "No entry %d on module %d (%s)", 
							entry_position, module_position, name.c_str());
					MessageLog::instance()->add(error_buf);
					std::cerr << error_buf << "\n";
					error_messages.push_back(error_buf);
					++num_errors;
					continue; // could not find this device
				}
				EntryDetails *ed = &module->entry_details[entry_position];
				unsigned int direction = module->syncs[ed->sm_index].dir;
				unsigned int offset_idx = entry_position;
				unsigned int bitlen = module->pdo_entries[entry_position].bit_length;

				if (direction == EC_DIR_OUTPUT)
				{
#if 0
					std::cerr << "Adding new output device " << m->getName()
						<< " position: " << entry_position
						<< " name: " << module->entry_details[offset_idx].name
						<< " bit_pos: " << module->bit_positions[offset_idx]
						<< " offset: " << module->offsets[offset_idx]
						<< " bitlen: " << bitlen <<  "\n";
#endif
					IOAddress addr (
							IOComponent::add_io_entry(ed->name.c_str(),
								module_position,
								module->offsets[offset_idx],
								module->bit_positions[offset_idx], offset_idx, bitlen));

					if (bitlen == 1)
					{
						Output *o = new Output(addr);
						output_list.push_back(o);
						IOComponent::devices[m->getName().c_str()] = o;
						o->setName(m->getName().c_str());
						m->io_interface = o;
						o->addDependent(m);
						o->addOwner(m);
					}
					else
					{
						AnalogueOutput *o = new AnalogueOutput(addr);
						output_list.push_back(o);
						IOComponent::devices[m->getName().c_str()] = o;
						o->setName(m->getName().c_str());
						m->io_interface = o;
						o->addDependent(m);
						o->addOwner(m);
						o->setupProperties(m);
					}
				}
				else
				{
					//sstr << m->getName() << "_IN_" << entry_position << std::flush;
					//const char *name_str = sstr.str().c_str();
#if 1
					std::cerr << "Adding new input device " << m->getName()
						<< " position: " << entry_position
						<< " name: " << module->entry_details[offset_idx].name
						<< " sm_idx: " << std::hex << ed->sm_index << std::dec
						<< " bit_pos: " << module->bit_positions[offset_idx]
						<< " offset: " << module->offsets[offset_idx]
						<<  " bitlen: " << bitlen << "\n";
#endif
					IOAddress addr( IOComponent::add_io_entry(ed->name.c_str(),
								module_position,
								module->offsets[offset_idx],
								module->bit_positions[offset_idx], offset_idx, bitlen));

					if (bitlen == 1)
					{
						Input *in = new Input(addr);
						IOComponent::devices[m->getName().c_str()] = in;
						in->setName(m->getName().c_str());
						m->io_interface = in;
						in->addDependent(m);
						in->addOwner(m);
					}
					else
					{
						if (m->_type == "COUNTERRATE")
						{
							CounterRate *in = new CounterRate(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							m->setNeedsThrottle(true);
							in->setupProperties(m);
						}
						else if (m->_type == "COUNTER")
						{
							Counter *in = new Counter(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							in->setupProperties(m);
							m->setNeedsThrottle(true);
						}
						else
						{
							AnalogueInput *in = new AnalogueInput(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							in->setupProperties(m);
							m->setNeedsThrottle(true);
						}
					}
				}
#endif
			}
			else
			{
#if 0
				if (m->_type != "POINT" && m->_type != "STATUS_FLAG" && m->_type != "COUNTERRATE"
						&& m->_type != "COUNTER"
						&& m->_type != "ANALOGINPUT" && m->_type != "ANALOGOUTPUT" )
					DBG_MSG << "Skipping " << m->_type << " " << m->getName() << " (not a POINT)\n";
				else
					DBG_MSG << "Skipping " << m->_type << " " << m->getName() << " (no parameters)\n";
#endif
			}
		}
		assert(remaining==0);
	}
}
Esempio n. 24
0
int main(int argc, const char * argv[]) 
{
    int posX=100, posY=100, microseconds = 2500, last = SDL_GetTicks(), accelerant = (WindowWidth/0.9);
    vector<Sprite *> sprites;
    SDL_Window *window=NULL;
    SDL_Renderer *renderer=NULL;
    
    /*Creates Window*/
    SDL_Init(SDL_INIT_VIDEO);
    window= SDL_CreateWindow("Bike", posX, posY, WindowWidth, WindowHeight, 0);
    renderer= SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    
    /*Creates Background's 1st Half [0]*/
    BG *bg1 = new BG(renderer, WindowWidth, WindowHeight);
    bg1->read("./txt/otherbackground.txt", 0);
    sprites.push_back(bg1);
    
    /*Creates Background's 2nd Half [1]*/
    BG *bg2 = new BG(renderer, WindowWidth, WindowHeight);
    bg2->read("./txt/otherbackground.txt", WindowWidth);
    sprites.push_back(bg2);
    
    /*Creates Cat [2]*/
    Cat *cat=new Cat(renderer, WindowWidth, WindowHeight);
    cat->read("./txt/cat.txt", 0);
    sprites.push_back(cat);

    /*Creates Bird1 [3]*/
    Bird *bird1 = new Bird (renderer, WindowWidth, WindowHeight);
    bird1->seed(SDL_GetTicks());
    bird1->read("./txt/bird.txt", 0);
    sprites.push_back(bird1);

    /*Creates Bird2 [4]*/
    Bird *bird2 = new Bird (renderer, WindowWidth, WindowHeight);
    bird2->seed(SDL_GetTicks());
    bird2->read("./txt/bird.txt", 0);
    sprites.push_back(bird2);
    
    /*Creates Bird3 [5]*/
    Bird *bird3 = new Bird (renderer, WindowWidth, WindowHeight);
    bird3->seed(SDL_GetTicks());
    bird3->read("./txt/bird.txt", 0);
    sprites.push_back(bird3);

    /*Creates boulder1 [6]*/
    Boulder *boulder1 = new Boulder (renderer, WindowWidth, WindowHeight);
    boulder1->read("./txt/boulder.txt", 0);
    sprites.push_back(boulder1);

    for (int i = 0; i<6; i++){
    	Counter *counter = new Counter (renderer, WindowWidth, WindowHeight);
    	counter->read("./txt/counter.txt", i);
    	sprites.push_back(counter);
    }
    
    /*Creates Rain [7-N]*/
    for(int i=0;i<300;i++)
    {
        Sprite *s = new Sprite(renderer, WindowWidth, WindowHeight);
        s->read("./txt/rain.txt", 0);
        sprites.push_back(s);
    }
   
    while(!exitFlag)
    {
        /*gives the processor a break*/
        usleep(microseconds);

        float dt = float(SDL_GetTicks()-last)/1000.0;
    
        SDL_Event e;
        if(SDL_PollEvent(&e))
        {
            if(e.type==SDL_QUIT)
                break;
            cat->move(e);
            bird1->move(e, accelerant); 
            bird2->move(e, accelerant);
            bird3->move(e, accelerant);
            boulder1->move(e, accelerant);
            bg2->scroll(e, accelerant);
    		bg1->scroll(e, accelerant);
        }
        
        for(unsigned i=0;i<sprites.size();i++){
        	if(i == 2) sprites[i]->update(dt,sprites[1]->getVelocity(),0);
        	else if(i>7 && i<14) sprites[i]->update(dt,i-7,score);
        	else sprites[i]->update(dt,i-7,0);
        }
        
        last=SDL_GetTicks();
        
        SDL_RenderClear(renderer);
        
        bg1->display();
        bg2->display();

        
        for(unsigned i=2;i<sprites.size();i++)
            sprites[i]->draw();
            
        //==============COLLISION CODE==========================================
        if(sprites[2]->collidesWith(sprites[6]))
        {
			cout << "CRASH!" << endl;
            cout << "SCORE: " << score << endl;
            //exitFlag = true;
            //maybe we should trip a flag to stop the main game loop???????? 
            //=====psuedo==============
            //kill movements
            //question, "continue? y/n"
            //cin >> userInput >> endl;
            // if yes
            //        
            //if no 
            //      exitFlag = true;
            //=========================
		}

        if(sprites[2]->collidesWith(sprites[5]))
        {
           // cout << "bird3 impact" << endl;
            score++;
        }
        if(sprites[2]->collidesWith(sprites[4]))
        {
           // cout << "bird2 impact" << enmdl;
            score++;
        }
        if(sprites[2]->collidesWith(sprites[3]))
        {
           // cout << "bird1 impact" << endl;
            score++;
        }
       
        /*
        for(unsigned i=3;i<sprites.size();i++){
            for(unsigned j=i+1;j<sprites.size();j++){
                if(!sprites[i]->isDead() && !sprites[j]->isDead() &&
                   sprites[j]->collidesWith(sprites[i])){
                       if(sprites[i]->getVelocity()>sprites[j]->getVelocity())
                           sprites[j]->kill();
                       else
                           sprites[i]->kill();
                }
            }
        }
        */
        //======================================================================
       
        SDL_RenderPresent(renderer);
    }
    
    for(unsigned i=0;i<sprites.size();i++)
        delete sprites[i];
    
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}
CounterObserver::CounterObserver(Counter& obj)
{
	obj.AddObserver(this);
}
Esempio n. 26
0
/**
 * Start the Counter counting.
 * This enables the counter and it starts accumulating counts from the associated
 * input channel. The counter value is not reset on starting, and still has the previous value.
 *
 * @param channel The channel of the digital input used with this counter
 */
void StartCounter(UINT32 channel)
{
    Counter *counter = AllocateCounter(channel);
    if (counter != NULL)
        counter->Start();
}
Esempio n. 27
0
Counter::Counter(const Counter& thecounter):
itsVal(thecounter.GetItsVal())
{cout<<"Copy Constructor\n";};
Esempio n. 28
0
 Test(char C) : Instance(sInstance, C) { Instance.dump("++TERD", this); }
Esempio n. 29
0
 ~Mqtt ()
 {
     messages.disableRate();
 }
Esempio n. 30
0
 Test() : Instance(sInstance) { Instance.dump("++TERD", this); }