void WorldLogic::restartGame(Logic &l)
{
  for (const std::shared_ptr<GameObject> &obj: l.game_model()->objects()) {
    if (typeid(obj) != typeid(model::Explosion)) {
      obj->alive() = false;
    }
  }

  add_box_interval_timer = 0.f;
  next_powerup_timer = NAN; // batman
  box_count = 0;

  _model->alive() = true;
  _model->playerPoints() = 0;
  _model->remainingLives() = 5;
  l.game_model()->gameSpeed() = 1.f;
  l.game_model()->stickyWallTimer() = 0.f;

  std::shared_ptr<Paddle> user_paddle(new Paddle("PlayerPaddle"));
  user_paddle->size() = vec3_type(10.f, 2.5f, 10.f);
  user_paddle->position() = vec3_type(0.f, -_model->getWorldHalfHeight() + user_paddle->size().y() * 2.f, 0.f);
  user_paddle->maxPosition() = vec3_type(_model->getWorldHalfWidth() - user_paddle->size().x() / 2.f, _model->getWorldHalfHeight(), HUGE_VALF);

  l.game_model()->addGameObject(user_paddle);

  _shallRestartTheGame = false;

  _model->gameRestarted() = true;
}
Exemple #2
0
Logic& Logic::getInstance()
{
    static Logic inst;
    if (!inst._initialized)
        inst.setInitialCoords();
    return inst;
}
Exemple #3
0
void Army::Move( Logic& l, float delta_time, int& i )
{
	if( to == final_to )
	{
		for( int j(0); j < l.GetArmies().size(); j++ )
		{
			Army& a( l.GetArmyByIndex(j) );
			if( a.used && i != j && x == a.x && y == a.y )
			{
				soldiers += a.soldiers;
				carts += a.carts;
				rectangles[ (int)Type::Army ].erase( a.rectangle );
				l.GetArmies().erase( j );
				break;
			}
		}
		from = to;
		state = Stationary;
	}
	else
	{
		from = to;
		to = l.CalculatePathTo( *this, final_to );
	}
}
Exemple #4
0
void Farm::Update( Logic& l, float delta_time )
{
	if( !used )
		return;

	float efficency = population / population_needed;
	if( efficency > 1.f )
		efficency = 1.f;

	food += food_production * delta_time * efficency;
	if( food > food_max )
		food = food_max;

	// Move extra population to city if possible
	if( population > population_needed )
	{
		int i = l.GetCityIndex( point );
		if( i != -1 )
		{
			City& c( l.GetCityByIndex( i ) );
			c.population += population - population_needed;
			population = population_needed;
		}
	}

	l.PopulationCalculations( food, population, hunger, delta_time );
}
Exemple #5
0
    void onWrite (beast::PropertyStream::Map& map)
    {
        Context::Scope scope (m_context);

        map ["trusted"] = m_logic.getChosenSize();
        {
            beast::PropertyStream::Set items ("sources", map);
            for (auto const& entry : m_logic.getSources())
            {
                items.add (entry.source->to_string());
            }
        }

        {
            beast::PropertyStream::Set items ("validators", map);
            for (auto const& entry : m_logic.getValidators())
            {
                RipplePublicKey const& publicKey (entry.first);
                Validator const& validator (entry.second);
                beast::PropertyStream::Map item (items);
                item["public_key"] = publicKey.to_string();
                validator.count().onWrite (item);
            }
        }
    }
/***********************************************************************
 Truth Table Generating function
 It takes the type of Family Type and number of inputs as input
 ***********************************************************************/
void LogicProcessor::ShowTruthTable(LogicType aLogicType, int aNumInputs){
    Logic* pLogic = CreateLogic(aLogicType, aNumInputs);
    bool** inputTable = GenerateInputTable(aNumInputs);
    int rowSize = int(pow(2, aNumInputs));

    int i=0;
    //For each combination of input
    for (;i<rowSize;i++) {
        //Display all input in this combination
        for (int j=0; j<aNumInputs; j++) {
            DisplayValue(inputTable[i][j]);
        }
        //Process these inputs for this Logic
        bool output = pLogic->Process(inputTable[i]);
        cout<<"--> ";
        //Display output
        DisplayValue(output);
        cout<<endl;
    }

    delete pLogic;

    //Destruct the Input Table
    for (i=0;i<rowSize;i++){
        delete []inputTable[i];
    }
}
Exemple #7
0
int main(int argument_count, char** argument_vars) {

	//runTest(argument_count, argument_vars) ; 
	Logic driver ;
	driver.logicMain() ;
	return 0 ;

}
Exemple #8
0
void TestLogicUserUpdate()
{
	static Logic logic;
	User user;
	user.name = "admin";
	user.password = "******";
	user.authority = 1;
	logic.userUpdate(user);
}
void LogicCollection::Load( std::istream& p_stream, entityid p_id )
{
    std::string temp;
    p_stream >> temp;       // chew up the "[LOGICS]"
    p_stream >> temp;       // load in the first logic name

    // loop while there are logic modules available
    while( temp != "[/LOGICS]" )
    {
        Add( temp, p_id );
        Logic* c = Get( temp );
        c->Load( p_stream );
        p_stream >> temp;       // try reading next logic name
    }
}
Exemple #10
0
 void
 on_endpoints (Slot::ptr const& slot,
     Endpoints const& endpoints)  override
 {
     SlotImp::ptr impl (std::dynamic_pointer_cast <SlotImp> (slot));
     m_logic.on_endpoints (impl, endpoints);
 }
Exemple #11
0
 Result
 activate (Slot::ptr const& slot,
     RipplePublicKey const& key, bool cluster) override
 {
     SlotImp::ptr impl (std::dynamic_pointer_cast <SlotImp> (slot));
     return m_logic.activate (impl, key, cluster);
 }
Exemple #12
0
 bool
 onConnected (Slot::ptr const& slot,
     beast::IP::Endpoint const& local_endpoint) override
 {
     SlotImp::ptr impl (std::dynamic_pointer_cast <SlotImp> (slot));
     return m_logic.onConnected (impl, local_endpoint);
 }
Exemple #13
0
    void onStop ()
    {
        m_logic.stop ();

        m_queue.dispatch (m_context.wrap (std::bind (
            &Thread::signalThreadShouldExit, this)));
    }
Exemple #14
0
 Slot::ptr
 new_inbound_slot (
     beast::IP::Endpoint const& local_endpoint,
         beast::IP::Endpoint const& remote_endpoint) override
 {
     return m_logic.new_inbound_slot (local_endpoint, remote_endpoint);
 }
Exemple #15
0
void TestLogicFactoryInsert(Logic& logic)
{
	Factory f;
	f.name = "饮料厂";
	f.addr = "饮料路饮料厂";
	f.email = "*****@*****.**";
	logic.factoryInsert(f);
}
Exemple #16
0
 void run ()
 {
     do
     {
         m_logic.periodicActivity();
         wait (1000);
     }
     while (! threadShouldExit ());
 }
Exemple #17
0
    void init ()
    {
        beast::Error error (m_store.open (m_databaseFile));

        if (! error)
        {
            m_logic.load ();
        }
    }
Exemple #18
0
    void onStop()
    {
        boost::system::error_code ec;
        timer_.cancel(ec);

        logic_.stop();

        exec_.async_wait([this]() { stopped(); });
    }
Exemple #19
0
 void
 close()
 {
     if (work_)
     {
         work_ = boost::none;
         checker_.stop();
         m_logic.stop();
     }
 }
Exemple #20
0
 void
 onPrepare ()
 {
     beast::Error error (m_store.open (m_databaseFile));
     if (error)
         m_journal.fatal <<
             "Failed to open '" << m_databaseFile.getFullPathName() << "'";
     if (! error)
         m_logic.load ();
 }
Exemple #21
0
 void run ()
 {
     beast::setCurrentThreadName ("Resource::Manager");
     for(;;)
     {
         logic_.periodicActivity();
         std::unique_lock<std::mutex> lock(mutex_);
         cond_.wait_for(lock, std::chrono::seconds(1));
         if (stop_)
             break;
     }
 }
 // with activate
 void
 test_backoff2()
 {
     auto const seconds = 10000;
     testcase("backoff 2");
     TestStore store;
     TestChecker checker;
     TestStopwatch clock;
     Logic<TestChecker> logic (clock, store, checker, beast::Journal{});
     logic.addFixedPeer ("test",
         beast::IP::Endpoint::from_string("65.0.0.1:5"));
     {
         Config c;
         c.autoConnect = false;
         c.listeningPort = 1024;
         logic.config(c);
     }
     std::size_t n = 0;
     std::array<std::uint8_t, 33> key;
     key.fill(0);
     for (std::size_t i = 0; i < seconds; ++i)
     {
         auto const list = logic.autoconnect();
         if (! list.empty())
         {
             expect (list.size() == 1);
             auto const slot = logic.new_outbound_slot(list.front());
             if (! expect (logic.onConnected(slot,
                     beast::IP::Endpoint::from_string("65.0.0.2:5"))))
                 return;
             std::string s = ".";
             RipplePublicKey pk (key.begin(), key.end());
             if (! expect (logic.activate(slot, pk, false) ==
                     PeerFinder::Result::success, "activate"))
                 return;
             logic.on_closed(slot);
             ++n;
         }
         clock.advance(std::chrono::seconds(1));
         logic.once_per_second();
     }
     // No more often than once per minute
     expect (n <= (seconds+59)/60, "backoff");
 }
Exemple #23
0
void Army::Transport( Logic& l, float delta_time )
{
	if( to == final_to )
	{
		int i = l.GetCityIndex( to );
		if( to == transporting_to )
		{
			if( i == -1 )
				throw std::string("Must transport to a city");
			City& c( l.GetCityByIndex(i) );

			c.food_contained += food_stored;
			food_stored = 0;
		}
		else if( to == transporting_from )
		{
			if( i != -1 )
			{
				City& c( l.GetCityByIndex(i) );
				if( hunger > 0 )
				{
					c.food_contained -= hunger;
					hunger = 0;
				}

				food_stored = storage_capacity;
				c.food_contained -= food_stored;
			}
			else
			{
				int j = l.GetFarmIndex( to );
				if( j == -1 )
					throw std::string("Must transport from a city or farm");
				Farm& f( l.GetFarmByIndex( j ) );
				if( hunger > 0 )
				{
					f.food -= hunger;
					hunger = 0;
				}

				food_stored = storage_capacity;
				f.food -= food_stored;
			}
		}
		final_to = from;
		from = to;
		to = l.CalculatePathTo( *this, final_to );
	}
	else
	{
		from = to;
		to = l.CalculatePathTo( *this, final_to );
	}
}
Exemple #24
0
int main() {
    
    // add. step <3/3>
    dynamic_add(MyLogic);
    
    
    DynamicBase *obj;
    
    // get, class. of course we can get from where didn't know Mylogic class except its base class.
    // @see line:18
    dynamic_get(std::string("Mylogic"), obj);
    
    if (obj) {
        // here is the point, we just know the base class. Logic.
        Logic *lc = (Logic*)obj;
        
        lc->do_something(); // here, -----> will call really_do_something() in Mylogic class, where we didn't know the class name. MyLogic.
    }
    
    // very simple, have fun.
    
    reutnr 0;
}
Exemple #25
0
void BuildTestData()
{
	static Logic logic;
	QFile file("buildTestData.txt");
	file.open(QFile::ReadOnly);
	QTextStream ts(&file);
	while( !ts.atEnd() )
	{
		QString name;
		int32 count;
		ts>>name>>count;
		printf("%s %d\n", name.toStdString().c_str(), count);
		if( name == "user" )
		{
			User user;
			for( int32 i = 0; i < count; ++i )
			{
				ts>>user.name>>user.password>>user.authority;
				//printf("user\n");
				logic.userInsert(user);
			}
		}
		else if( name == "factory" )
Exemple #26
0
void TestLogicProductInsert(Logic& logic)
{
	Product p;
	p.name = "手机";
	p.type = "重武器";
	p.count= 20;
	p.MF_id = 0;
	p.price_buy = 10000;
	p.price_nw = 100010;
	p.price_ww = 200000;
	p.date = "2011/5/29";
	p.fee_other = 0;
	logic.productInsert(p);
}
Exemple #27
0
void Quarry::Update( Logic& l, float delta_time )
{
	if( !used )
		return;

	float efficency = population / population_needed;
	if( efficency > 1.f )
		efficency = 1.f;

	l.PopulationCalculations( food_contained, population, hunger, delta_time );

	if( stone_contained >= stone_storage )
	{
		stone_contained = stone_storage;
		return;
	}

	// Reduce mountain maeby change to require more effort to extract more stone
	auto& v( height_map.square_contained );
	auto i = std::find( v.begin(), v.end(), Resource::Stone );
	auto closest = i;
	auto& r( rectangles[ (int)Type::Quarry ][rectangle] );
	auto size = 5; // TODO: Move value to a config file
	auto closest_length = size;
	while(true)
	{
		if( i == v.end() )
		{
			if( closest_length != size )
			{
				auto& resource( height_map.square_amount[ closest - v.begin() ] );
				stone_contained += stone_production * delta_time * efficency;
				resource -= stone_production * delta_time * efficency;
				if( resource <= 0 )
					height_map.Remove( closest - v.begin() );
			}
			break;
		}
		auto s = sqrt( pow( r.x - height_map.PosX( i - v.begin() ), 2 ) + pow( r.y - height_map.PosY( i - v.begin() ), 2 ) ); // TODO: Mabye remove v.begin()
		if( s < closest_length )
		{
			closest_length = s;
			closest = i;
		}
		i = std::find( ++i, v.end(), Resource::Stone );
	}
}
void WorldLogic::addBoxToGame(Logic &l)
{
  std::uniform_real_distribution<scalar_type> size_exp_dist(1.7f, 3.4f);
  scalar_type size = exp2(size_exp_dist(rng));

  vec3_type max_pos(_model->getWorldHalfWidth() - size / 2.f, _model->getWorldHalfHeight() - size / 2.f, HUGE_VALF);

  std::uniform_real_distribution<scalar_type> x_dist(-max_pos.x(), max_pos.x());
  scalar_type x = x_dist(rng);

  std::shared_ptr<Box> box(new Box("Box", !_model->remainingLives()));
  box->size() = size;
  box->position() = vec3_type(x, 0.f, 0.f);
  box->maxPosition() = max_pos;

  l.game_model()->addGameObject(box);
  box_count++;
}
Exemple #29
0
    void
    onTimer (boost::system::error_code ec)
    {
        if (ec)
        {
            if (ec != boost::asio::error::operation_aborted)
                journal_.error <<
                    "onTimer: " << ec.message();
            return;
        }

        logic_.onTimer();

        timer_.expires_from_now(std::chrono::seconds(1), ec);
        timer_.async_wait(strand_.wrap(exec_.wrap(
            std::bind(&ManagerImp::onTimer, this,
                beast::asio::placeholders::error))));
    }
Exemple #30
0
    void onStop ()
    {
#if RIPPLE_USE_VALIDATORS
        m_journal.info << "Validators stopping";
#endif

        m_logic.stop ();

        if (this->Thread::isThreadRunning())
        {
            m_journal.debug << "Signaling thread exit";
            m_queue.dispatch (m_context.wrap (bind (
                &Thread::signalThreadShouldExit, this)));
        }
        else
        {
            stopped();
        }
    }