示例#1
0
文件: Screen.cpp 项目: Noclip21/Test
void Screen::cam(Surface *wrapper,vector2 position)
{
	if(alive(wrapper))
	{
		if(alive(_cam)) _cam->kill();
		_cam = new Camera(width(),height(),wrapper);
		_cam->target(position);
	}
}
示例#2
0
	void gui_element::draw_tooltip_from_hover_or_world_highlight(vertex_triangle_buffer& output_buffer, const viewing_gui_context& context, const vec2i tooltip_pos) const {
		const auto& rect_world = context.get_rect_world();
		auto& step = context.get_step();
		const auto& cosmos = step.get_cosmos();

		const auto maybe_hovered_item = context._dynamic_cast<item_button_in_item>(rect_world.rect_hovered);
		const auto maybe_hovered_slot = context._dynamic_cast<slot_button_in_container>(rect_world.rect_hovered);
		const auto maybe_hovered_hotbar_button = context._dynamic_cast<hotbar_button_in_gui_element>(rect_world.rect_hovered);

		gui::text::fstr tooltip_text;

		const auto description_style = text::style(assets::font_id::GUI_FONT, vslightgray);

		if (maybe_hovered_item) {
			tooltip_text = text::simple_bbcode(describe_entity(cosmos[maybe_hovered_item.get_location().item_id]), description_style);
		}
		else if (maybe_hovered_slot) {
			tooltip_text = text::simple_bbcode(describe_slot(cosmos[maybe_hovered_slot.get_location().slot_id]), text::style());
		}
		else if (maybe_hovered_hotbar_button) {
			const auto assigned_entity = maybe_hovered_hotbar_button->get_assigned_entity(context.get_gui_element_entity());

			if (assigned_entity.alive()) {
				tooltip_text = text::simple_bbcode(describe_entity(assigned_entity), description_style);
			}
			else {
				tooltip_text = text::format(L"Empty slot", description_style);
			}
		}
		else {
			const auto hovered = cosmos[get_hovered_world_entity(cosmos, step.camera.transform.pos + rect_world.last_state.mouse.pos - step.camera.visible_world_area / 2)];

			if (hovered.alive()) {
				step.session.world_hover_highlighter.update(step.get_delta().in_milliseconds());
				step.session.world_hover_highlighter.draw(step, hovered);

				tooltip_text = text::simple_bbcode(describe_entity(hovered), text::style(assets::font_id::GUI_FONT, vslightgray));
			}
		}

		if (tooltip_text.size() > 0) {
			augs::gui::text_drawer description_drawer;
			description_drawer.set_text(tooltip_text);

			const auto tooltip_rect = ltrbi(tooltip_pos, description_drawer.get_bbox()).snap_to_bounds(ltrb(vec2(0, 0), get_screen_size()));

			augs::draw_rect_with_border(
				output_buffer,
				tooltip_rect,
				{ 0, 0, 0, 120 }, 
				slightly_visible_white
			);

			description_drawer.pos = tooltip_rect.get_position();
			description_drawer.draw(output_buffer);
		}
	}
示例#3
0
文件: Screen.cpp 项目: Noclip21/Test
void Screen::cam(Surface *wrapper,Surface *target)
{
	if(alive(wrapper) && alive(target))
	{
		if(alive(_cam)) _cam->kill();
		_cam = new Camera(width(),height(),wrapper);
		_cam->target(target);
	}
}
示例#4
0
_RTARCTOR::~_RTARCTOR           // DESTRUCTOR FOR R/T AR-CTOR
    ( void )
{
    if( alive() ) {
        dtor_the_array( this );
    }
}
示例#5
0
void Movable::collision( Map &map, vector<Movable *> &movables )
{
    if( !alive()) return;
    if( x() < 0  || y() < 0 || x() >= map.Width() || y() >= map.Height() ||
            map( x(), y() ).block & BLOCKED ||
            map( rx(), ry() ).block & block_dir[ direction() ] ||
            map( x(), y() ).block & block_rdir[ direction() ] ) {
        x( rx());
        y( ry());
        moving( false );
        return;
    }

    for( IDX i = 0; i < movables.size(); ++i ) {
        if( this != movables[i] && movables[i]->alive()) {
            if( x() == movables[i]->x() &&
                    y() == movables[i]->y() &&
                    movables[i]->alive()) {
                x( rx());
                y( ry());
                moving( false );
                hit( movables[i], map, movables );
            }
        }
    }
}
示例#6
0
 int count_alive_neighbours(int x, int y){
     int ans = 0;
     for (int i = -1; i < 2; i++)
         for (int j = -1; j < 2; j++)
             if (i || j) ans += alive(x + i, y + j);
     return ans;
 }
示例#7
0
 SharedObject WeakRef::shared() {
   SharedObject ret;
   if (alive()) {
     ret.assignNode((*this)->raw_);
   }
   return ret;
 }
void IpcClientInterface::dispatch(const QVariant &message)
{
    static const int aliveMessageType = QMetaType::type("ClangBackEnd::AliveMessage");
    static const int echoMessageType = QMetaType::type("ClangBackEnd::EchoMessage");
    static const int codeCompletedMessageType = QMetaType::type("ClangBackEnd::CodeCompletedMessage");
    static const int translationUnitDoesNotExistMessage = QMetaType::type("ClangBackEnd::TranslationUnitDoesNotExistMessage");
    static const int projectPartsDoNotExistMessage = QMetaType::type("ClangBackEnd::ProjectPartsDoNotExistMessage");
    static const int diagnosticsChangedMessage = QMetaType::type("ClangBackEnd::DiagnosticsChangedMessage");

    int type = message.userType();

    if (type == aliveMessageType)
        alive();
    else if (type == echoMessageType)
        echo(message.value<EchoMessage>());
    else if (type == codeCompletedMessageType)
        codeCompleted(message.value<CodeCompletedMessage>());
    else if (type == translationUnitDoesNotExistMessage)
        translationUnitDoesNotExist(message.value<TranslationUnitDoesNotExistMessage>());
    else if (type == projectPartsDoNotExistMessage)
        projectPartsDoNotExist(message.value<ProjectPartsDoNotExistMessage>());
    else if (type == diagnosticsChangedMessage)
        diagnosticsChanged(message.value<DiagnosticsChangedMessage>());
    else
        qWarning() << "Unknown IpcClientMessage";
}
示例#9
0
void Game::score() {
	assert(teams_.size() == 2);
/*	size_t collisions = (teams_[0].stats_.totalHits_

			+ teams_[0].stats_.totalFriendlyFire_
			+ teams_[1].stats_.totalHits_
			+ teams_[1].stats_.totalFriendlyFire_
	);

	size_t damage = (teams_[0].stats_.totalDamage_+ teams_[1].stats_.totalDamage_);

	assert(collisions == damage);*/
	vector<size_t> alive(2,0);

	for(size_t i = 0; i < teams_.size(); ++i) {
		Population& team = teams_[i];
		for(Ship& t : team) {
			if(!t.dead_)
				++alive[i];
		}
	}

	if(alive[0] != alive[1]) {
		if(alive[0] > alive[1]) {
			teams_[0].score_++;
			teams_[0].winner_=true;
		} else {
			teams_[1].score_++;
			teams_[1].winner_=true;
		}
	}

	newTeams_[0].score_ = teams_[0].score_;
	newTeams_[1].score_ = teams_[1].score_;
}
示例#10
0
void EnemyBase::draw(SDL_Renderer * renderer)
{
	if(showBar && alive())
	bar.draw(renderer);
	SDL_RenderCopy(renderer,texture,NULL,&area);

}
示例#11
0
task main ()
{
	nxtDisplayCenteredTextLine(3, "Roaming");
	nxtDisplayCenteredTextLine(5, "This is a test");
	while(nextEmptyCell<numLocalCells)
	{
		alive();
		char lastCellNum = nextEmptyCell;
	  nSyncedMotors = synchBC;
	  nSyncedTurnRatio = 101;
    nMotorEncoderTarget[motorB] = 200;
	  motor[motorB] =60;
    while(nMotorRunState[motorB] != runStateIdle) {}
    setTemp();
    checkLocalCell();
    doTurn();
    if(lastCellNum != nextEmptyCell)
    {
      AddToDatalog(1);
    }
    else
    {
    	AddToDatalog(0);
    }
 // wait1Msec(200);

  }
  SaveNxtDatalog();
  StarWars();
}
示例#12
0
void Movable::setanim()
{
    if( !alive()) return;
    if( moving()) {
        switch( direction()) {
            case North:
                anim.set( engine.data.animation[ _base->n_hash ], engine.images );
                break;
            case East:
                anim.set( engine.data.animation[ _base->e_hash ], engine.images );
                break;
            case South:
                anim.set( engine.data.animation[ _base->s_hash ], engine.images );
                break;
            case West:
                anim.set( engine.data.animation[ _base->w_hash ], engine.images );
                break;
        }
    } else {
        switch( direction()) {
            case North:
                anim.set( engine.data.animation[ _base->sn_hash ], engine.images );
                break;
            case East:
                anim.set( engine.data.animation[ _base->se_hash ], engine.images );
                break;
            case South:
                anim.set( engine.data.animation[ _base->ss_hash ], engine.images );
                break;
            case West:
                anim.set( engine.data.animation[ _base->sw_hash ], engine.images );
                break;
        }
    }
}
示例#13
0
void Movable::draw( F32 x1, F32 y1, F32 x, F32 y, F32 hw, F32 hh )
{
   F32 wx = 0.0f, wy = 0.0f;
   F32 ox = 0.0f, oy = 0.0f;
   if( !alive()) return;

   switch( direction()) {
       case North:
           oy = -offset();
           break;
       case East:
           ox = offset();
           break;
       case South:
           oy = offset();
           break;
       case West:
           ox = -offset();
           break;
   }

   wx = x1 + (( x + ox ) * hw ) + (( y + oy ) * hw );
   wy = y1 + (( y + oy ) * hh ) - (( x + ox ) * hh );
   anim.position( wx - (((((F32)anim.getw() / 2.0f ) -  hw ))/2.0f),
           (wy - (F32)anim.geth()) + hh + hh );
   anim.draw( engine.gfx );
}
示例#14
0
void spatial_properties_mixin<false, D>::set_logic_transform(const components::transform t) const {
	if (logic_transform() == t) {
		return;
	}
	
	const auto handle = *static_cast<const D*>(this);
	const auto owner = handle.get_owner_body();

	bool is_only_fixtural = owner.alive() && owner != handle;

	ensure(!is_only_fixtural);
	
	if (handle.has<components::physics>()) {
		ensure(!handle.has<components::transform>());
		const auto& phys = handle.get<components::physics>();
		phys.set_transform(t);
	}
	else {
		handle.get<components::transform>() = t;

		if (handle.has<components::dynamic_tree_node>()) {
			handle.get<components::dynamic_tree_node>().update_proxy();
		}
	}
}
示例#15
0
void Movable::trymove( Map &map, vector<Movable *> &movables, bool test )
{
   if( !alive() || moving()) {
       return;
   }
   rx( x());
   ry( y());
   switch( direction()) {
       case North:
           y()--;
           break;
       case East:
           x()++;
           break;
       case South:
           y()++;
           break;
       case West:
           x()--;
           break;
       default:
           enforce( false, "Bad Direction!" );
   }

   moving( 1 );
   if( test ) {
       collision( map, movables );
   }
}
void connection::connect() 
{
	boost::asio::ip::tcp::resolver resolver(m_io_service);
	boost::asio::ip::tcp::resolver::query query(m_addr, m_port);
	boost::system::error_code error = boost::asio::error::host_not_found;
	boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
	
	boost::asio::ip::tcp::resolver::iterator end;

	while (iter != end) {
		if (!error) {
			break;
		}
		
		m_socket.close();
		HS_INFO << "Trying to connect: " + m_addr + ":" + m_port << std::endl;
		
		m_socket.connect(*iter++, error);
		
		if (error) {
			HS_ERROR << error.message() << std::endl;
		}
	}
	
	if (alive()) {
		HS_INFO << "Connected!" << std::endl;
	} else {
		HS_WARNING << "Could not connect to " + m_addr + ":" + m_port << std::endl;
	}
}
示例#17
0
  void
  keypoint_container<P, F>::compact()
  {
    compact_has_run_ = true;

    matches_.resize(keypoint_vector_.size());
    std::fill(matches_.begin(), matches_.end(), -1);

    auto pts_it   = keypoint_vector_.begin();
    auto feat_it  = feature_vector_.begin();
    auto pts_res  = keypoint_vector_.begin();
    auto feat_res = feature_vector_.begin();

    for (;pts_it != keypoint_vector_.end();)
    {
      if (pts_it->alive())
      {
        *pts_res++ = *pts_it;
        *feat_res++ = *feat_it;
        int prev_index = pts_it - keypoint_vector_.begin();
        int new_index = pts_res - keypoint_vector_.begin() - 1;
        index2d_(cast<vint2>(pts_it->position)) = new_index;
        matches_[prev_index] = new_index;
        assert(keypoint_vector_[index2d_(pts_it->position.cast<int>())].position == pts_it->position);
      }

      pts_it++;
      feat_it++;
    }

    keypoint_vector_.resize(pts_res - keypoint_vector_.begin());
    feature_vector_.resize(feat_res - feature_vector_.begin());
  }
void ClangCodeModelClientInterface::dispatch(const MessageEnvelop &messageEnvelop)
{
    switch (messageEnvelop.messageType()) {
        case MessageType::AliveMessage:
            alive();
            break;
        case MessageType::EchoMessage:
            echo(messageEnvelop.message<EchoMessage>());
            break;
        case MessageType::CodeCompletedMessage:
            codeCompleted(messageEnvelop.message<CodeCompletedMessage>());
            break;
        case MessageType::TranslationUnitDoesNotExistMessage:
            translationUnitDoesNotExist(messageEnvelop.message<TranslationUnitDoesNotExistMessage>());
            break;
        case MessageType::ProjectPartsDoNotExistMessage:
            projectPartsDoNotExist(messageEnvelop.message<ProjectPartsDoNotExistMessage>());
            break;
        case MessageType::DocumentAnnotationsChangedMessage:
            documentAnnotationsChanged(messageEnvelop.message<DocumentAnnotationsChangedMessage>());
            break;
        default:
            qWarning() << "Unknown ClangCodeModelClientMessage";
    }
}
示例#19
0
    void
    TPDynamic::policy() {
        useconds_t usecs = 1, 
                   range = 1;
#ifdef TRACE
        addRecord(getTime(), (void*) &TPDynamic::policy);
#endif
        while (alive()) {
            //Check if we have any work in our deque
            tpClosure * tempClosure;
            if (!(tempClosure = popTP()))
                tempClosure = steal();

            if (tempClosure) {
                usecs = range; // reset sleep time;
#ifdef TRACE
                addRecord(getTime(), (void*) tempClosure->factory);
#endif
                tempClosure->factory(tempClosure);
#ifdef TRACE
                addRecord(getTime(), (void*) &TPDynamic::policy);
#endif
                delete tempClosure;
                //Get the work ready!
            } else {
                usleep(usecs);
                if (usecs < 500)
                    usecs *= 2;
           }

            //Lets do the work!
            Codelet * tempCodelet = popCodelet();
            while (tempCodelet) {
                ThreadedProcedure * checkTP = tempCodelet->getTP();
                bool deleteTP = (checkTP) ? checkTP->checkParent() : false;
#ifdef TRACE
                addRecord(getTime(), tempCodelet->returnFunct());
#endif
#ifdef COUNT
		    if(getAffinity()) getAffinity()->startCounters(getID());
#endif
		    tempCodelet->fire();
#ifdef COUNT
		    if(getAffinity()) getAffinity()->incrementCounters(getID());
#endif
#ifdef TRACE
                addRecord(getTime(), (void*) &TPDynamic::policy);
#endif
                if (deleteTP) {
                    if (checkTP->decRef())
                        delete checkTP;
                }

                tempCodelet = popCodelet();
            }
        }
    }
示例#20
0
    void Ping::processResult(int exitCode, QProcess::ExitStatus /* exitStatus */) {
		if (exitCode == 0) {
			emit alive();
		} else {
			emit dead();
		}

		emit done();
	}
示例#21
0
void VRPNTracker::update() {

  if(!alive()) { // insert hack here to fix VRPN's connection bug someday
    moveto(0,0,0);
    orient->identity();
    return;
  }
  tkr->mainloop(); // clear out old data
}
示例#22
0
void Controller::game()
{
	while(alive())
	{
		generate();
		move();
		update();
	}
}
//NXT power and safety checks
task backgroundWorker()
{
	nSchedulePriority	 = kLowPriority; //Set to low priority to avoid delaying other tasks

	for(;;)
	{
		alive(); //Keep the NXT from powering down
	}
}
示例#24
0
文件: loop.cpp 项目: skypjack/uvw
TEST(Loop, Functionalities) {
    auto loop = uvw::Loop::create();
    auto handle = loop->resource<uvw::PrepareHandle>();
    auto req = loop->resource<uvw::WorkReq>([]{});

    auto err = [](const auto &, auto &) { FAIL(); };

    loop->on<uvw::ErrorEvent>(err);
    req->on<uvw::ErrorEvent>(err);
    handle->on<uvw::ErrorEvent>(err);

    ASSERT_TRUE(static_cast<bool>(handle));
    ASSERT_TRUE(static_cast<bool>(req));

    ASSERT_TRUE(loop->descriptor());
    ASSERT_NO_THROW(loop->now());
    ASSERT_NO_THROW(loop->update());
    ASSERT_NO_THROW(loop->fork());

    ASSERT_FALSE(loop->alive());
    ASSERT_FALSE(loop->timeout().first);

    handle->start();
    handle->on<uvw::PrepareEvent>([](const auto &, auto &hndl) {
        hndl.loop().walk([](uvw::BaseHandle &) {
            static bool trigger = true;
            ASSERT_TRUE(trigger);
            trigger = false;
        });

        hndl.close();
    });

    ASSERT_TRUE(loop->alive());
    ASSERT_TRUE(loop->timeout().first);
    ASSERT_NO_THROW(loop->run());

    loop->walk([](uvw::BaseHandle &) { FAIL(); });

    ASSERT_NO_THROW(loop->run<uvw::Loop::Mode::ONCE>());
    ASSERT_NO_THROW(loop->run<uvw::Loop::Mode::NOWAIT>());

    ASSERT_FALSE(loop->alive());
}
示例#25
0
void trigger_detector_system::send_trigger_confirmations(const logic_step step) const {
	auto& confirmations = step.transient.messages.get_queue<messages::trigger_hit_confirmation_message>();
	confirmations.clear();

	auto& cosmos = step.cosm;
	const auto& collisions = step.transient.messages.get_queue<messages::collision_message>();

	for (const auto& c : collisions) {
		if (c.type != messages::collision_message::event_type::PRE_SOLVE)
			continue;

		const auto* const collision_detector = cosmos[c.subject].find<components::trigger_collision_detector>();
		const auto* const trigger = cosmos[c.collider].find<components::trigger>();

		if (collision_detector && trigger && trigger->react_to_collision_detectors && collision_detector->detection_intent_enabled
			) {
			messages::trigger_hit_confirmation_message confirmation;
			confirmation.detector_body = c.subject;
			confirmation.trigger = c.collider;
			step.transient.messages.post(confirmation);
		}
	}

	auto& requests = step.transient.messages.get_queue<messages::trigger_hit_request_message>();

	for (auto& e : requests) {
		auto& trigger_query_detector = cosmos[e.detector].get<components::trigger_query_detector>();
		const auto detector_body = cosmos[e.detector];
		
		std::vector<entity_id> found_triggers;

		ensure(detector_body.alive());

		const auto found_physical_triggers = cosmos.systems_temporary.get<physics_system>().query_body(detector_body, filters::trigger());

		for (const auto found_trigger_id : found_physical_triggers.entities) {
			const auto found_trigger = cosmos[found_trigger_id];
			const auto* const maybe_trigger = found_trigger.find<components::trigger>();
			
			if (maybe_trigger && maybe_trigger->react_to_query_detectors) {
				found_triggers.push_back(found_trigger);
			}
		}

		for (const auto t : found_triggers) {
			messages::trigger_hit_confirmation_message confirmation;
			confirmation.trigger = t;
			confirmation.detector_body = detector_body;
			trigger_query_detector.detection_intent_enabled = false;
			step.transient.messages.post(confirmation);
			break;
		}
	}

	requests.clear();
}
示例#26
0
void relations_mixin<false, D>::make_child(const entity_id ch_id, const sub_entity_name optional_name) const {
	auto& self = *static_cast<const D*>(this);
	auto& cosmos = self.get_cosmos();

	auto ch = cosmos[ch_id];

	if (ch.alive()) {
		ch.child_component().parent = self;
	}
}
示例#27
0
 ~Loop()
 {
   if (alive()) {
     // this is to call the close callbacks of the watchers
     // so that their handle memory can get freed
     run();
   }
   int rc = uv_loop_close(m_uvloop.get());
   assert(rc==0 || print_error(rc));
 }
task main() {
	init();
	waitForStart();
	while(true){
		udServos();
		drive();
		updateLight();
		alive();
	}
}
示例#29
0
  Thread* Thread::wakeup(STATE) {
    utilities::thread::SpinLock::LockGuard guard(init_lock_);

    if(!CBOOL(alive()) || !vm()) {
      return force_as<Thread>(Primitives::failure());
    }

    vm()->wakeup(state);

    return this;
  }
示例#30
0
文件: ship.cpp 项目: bzar/spacerocks
void Ship::shoot(bool const value)
{
  if(shooting != value)
  {
    shooting = value && alive();
    if(shooting)
      weapon->startShooting();
    else
      weapon->stopShooting();
  }
}