コード例 #1
0
ファイル: shiftRegDisplay.c プロジェクト: CodyShaw/Clock
void shiftOut(char output, char pin){
    outputDisable(pin);
    for(int i = 0; i <= 7; i++){
        int set = (output >> i) & 0x01;
        if(set == 1){
            data1();
        } else {
            data0();
        }
        pulseClock();
    }
    pulseClock();
    
    outputEnable(pin);

    __delay_us(100);
    outputDisable(pin);
    return;
}
コード例 #2
0
std::vector<std::string> *
HostnameModule::getDatas(void) {
	char	hname[128] = "";
	char	uname[128] = "";
	std::ostringstream s;

	if (gethostname(hname, 128))
		return this->_datas;
	if (getlogin_r(uname, 128))
		return this->_datas;

	this->_datas = new std::vector<std::string>;

	int		l = strlen("HOSTNAME");
	int		pos = static_cast<int>((34 - l) / 2);
	int i;
	s.str(std::string());
	s << '<';
	for (i = 0; i + 1 < pos - 1; i++) {
		s << '-';
	}
	s << " HOSTNAME ";
	for (i = pos + l + 2; i < 34; i++) {
		s << '-';
	}
	s << '>';
	std::string name(s.str());
	this->_datas->push_back(name);
	s.clear();
	s.str(std::string());

//	this->_datas->push_back("<------ Hostname ------>");
	s << "Hostname : " << hname;
	std::string data0(s.str());
	this->_datas->push_back(data0);
	s.clear();
	s.str(std::string());
	s << "Username : " << uname;
	std::string data1(s.str());
	this->_datas->push_back(data1);

	return this->_datas;
}
コード例 #3
0
ファイル: Writer32Test.cpp プロジェクト: 03050903/skia
DEF_TEST(Writer32_data, reporter) {
    const char* str = "0123456789";
    sk_sp<SkData> data0(SkData::MakeWithCString(str));
    sk_sp<SkData> data1(SkData::MakeEmpty());

    const size_t sizes[] = {
        SkWriter32::WriteDataSize(nullptr),
        SkWriter32::WriteDataSize(data0.get()),
        SkWriter32::WriteDataSize(data1.get()),
    };

    SkSWriter32<1000> writer;
    size_t sizeWritten = 0;

    writer.writeData(nullptr);
    sizeWritten += sizes[0];
    REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());

    writer.writeData(data0.get());
    sizeWritten += sizes[1];
    REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());

    writer.writeData(data1.get());
    sizeWritten += sizes[2];
    REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());

    auto result(writer.snapshotAsData());

    SkReader32 reader(result->data(), result->size());
    auto d0(reader.readData()),
         d1(reader.readData()),
         d2(reader.readData());

    REPORTER_ASSERT(reporter, 0 == d0->size());
    REPORTER_ASSERT(reporter, strlen(str)+1 == d1->size());
    REPORTER_ASSERT(reporter, !memcmp(str, d1->data(), strlen(str)+1));
    REPORTER_ASSERT(reporter, 0 == d2->size());

    REPORTER_ASSERT(reporter, reader.offset() == sizeWritten);
    REPORTER_ASSERT(reporter, reader.eof());
}
コード例 #4
0
ファイル: Vehicle.cpp プロジェクト: sc0rpio0o/diamondcore
void Vehicle::AddPassenger(Unit *unit, int8 seatId, bool force)
{
    SeatMap::iterator seat;
    seat = m_Seats.find(seatId);

    // this should never happen
    if(seat == m_Seats.end())
        return;

    unit->SetVehicleGUID(GetGUID());

    seat->second.passenger = unit;
    if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->isVehicle())
    {
        if(((Vehicle*)unit)->GetEmptySeatsCount(true) == 0)
            seat->second.flags = SEAT_VEHICLE_FULL;
        else
            seat->second.flags = SEAT_VEHICLE_FREE;
    }
    else
    {
        seat->second.flags = SEAT_FULL;
    }

    if(unit->GetTypeId() == TYPEID_PLAYER)
    {
        WorldPacket data0(SMSG_FORCE_MOVE_ROOT, 10);
        data0 << unit->GetPackGUID();
        data0 << (uint32)((seat->second.vs_flags & SF_CAN_CAST) ? 2 : 0);
        unit->SendMessageToSet(&data0,true);
    }

    if(seat->second.vs_flags & SF_MAIN_RIDER)
    {
        if(!(GetVehicleFlags() & VF_MOVEMENT))
        {
            GetMotionMaster()->Clear(false);
            GetMotionMaster()->MoveIdle();
            SetCharmerGUID(unit->GetGUID());
            unit->SetUInt64Value(UNIT_FIELD_CHARM, GetGUID());
            if(unit->GetTypeId() == TYPEID_PLAYER)
            {
				((Player*)unit)->SetMover(this);
                ((Player*)unit)->SetMoverInQueve(this);
                ((Player*)unit)->SetClientControl(this, 1);
            }
            if(canFly() || HasAuraType(SPELL_AURA_FLY) || HasAuraType(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED))
            {
                WorldPacket data3(SMSG_MOVE_SET_CAN_FLY, 12);
                data3<< GetPackGUID();
                data3 << (uint32)(0);
                SendMessageToSet(&data3,false);
            }
        }

        SpellClickInfoMapBounds clickPair = sObjectMgr.GetSpellClickInfoMapBounds(GetEntry());
        for(SpellClickInfoMap::const_iterator itr = clickPair.first; itr != clickPair.second; ++itr)
        {
            if (unit->GetTypeId() == TYPEID_UNIT || itr->second.IsFitToRequirements((Player*)unit))
            {
                Unit *caster = (itr->second.castFlags & 0x1) ? unit : this;
                Unit *target = (itr->second.castFlags & 0x2) ? unit : this;

                caster->CastSpell(target, itr->second.spellId, true);
            }
        }
        if(unit->GetTypeId() == TYPEID_PLAYER)
        {
            // it should be added only on rider enter?
            if(((Player*)unit)->GetGroup())
                ((Player*)unit)->SetGroupUpdateFlag(GROUP_UPDATE_VEHICLE);

            ((Player*)unit)->GetCamera().SetView(this);

            BuildVehicleActionBar((Player*)unit);
        }

        if(!(GetVehicleFlags() & VF_FACTION))
            setFaction(unit->getFaction());

        if(GetVehicleFlags() & VF_CANT_MOVE)
        {
            WorldPacket data2(SMSG_FORCE_MOVE_ROOT, 10);
            data2<< GetPackGUID();
            data2 << (uint32)(2);
            SendMessageToSet(&data2,false);
        }

        if(GetVehicleFlags() & VF_NON_SELECTABLE)
            SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
    }
    if(seat->second.vs_flags & SF_UNATTACKABLE)
        unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);

    EmptySeatsCountChanged();
}
コード例 #5
0
ファイル: Vehicle.cpp プロジェクト: X-Core/X-core-addons
void Vehicle::RemovePassenger(Unit *unit)
{
    SeatMap::iterator seat;
    for(seat = m_Seats.begin(); seat != m_Seats.end(); ++seat)
    {
        if((seat->second.flags & (SEAT_FULL | SEAT_VEHICLE_FREE | SEAT_VEHICLE_FULL)) && seat->second.passenger == unit)
        {
            unit->SetVehicleGUID(0);

            if(seat->second.vs_flags & SF_MAIN_RIDER)
            {
                RemoveSpellsCausingAura(SPELL_AURA_CONTROL_VEHICLE);
                if(unit->GetTypeId() == TYPEID_PLAYER)
                {
                    ((Player*)unit)->SetMover(unit);
                    ((Player*)unit)->SetClientControl(unit, 1);
                    ((Player*)unit)->SetMoverInQueve(NULL);
                    ((Player*)unit)->RemovePetActionBar();

                    if(((Player*)unit)->GetGroup())
                        ((Player*)unit)->SetGroupUpdateFlag(GROUP_UPDATE_VEHICLE);
                }
                unit->SetCharm(NULL);
                SetCharmerGUID(NULL);
                setFaction(GetCreatureInfo()->faction_A);
            }
            if(GetVehicleFlags() & VF_NON_SELECTABLE)
                RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
            if(GetVehicleFlags() & VF_CAST_AURA && m_VehicleData  && m_VehicleData->v_spells[0] != 0)
                unit->RemoveAurasDueToSpell(m_VehicleData->v_spells[0]);
            if(seat->second.vs_flags & SF_UNATTACKABLE)
                unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
            // restore player control
            if(unit->GetTypeId() == TYPEID_PLAYER)
            {
                ((Player*)unit)->SetFarSightGUID(NULL);

                if(seat->second.vs_flags & SF_CAN_CAST)
                {
                    WorldPacket data0(SMSG_FORCE_MOVE_UNROOT, 10);
                    data0 << unit->GetPackGUID();
                    data0 << (uint32)(2);                        // can rotate
                    unit->SendMessageToSet(&data0,true);
                }
                else
                {
                    WorldPacket data1(SMSG_FORCE_MOVE_UNROOT, 10);
                    data1 << unit->GetPackGUID();
                    data1 << (uint32)(0);                        // cannot rotate
                    unit->SendMessageToSet(&data1,true);
                }
            }
            unit->m_SeatData.OffsetX = 0.0f;
            unit->m_SeatData.OffsetY = 0.0f;
            unit->m_SeatData.OffsetZ = 0.0f;
            unit->m_SeatData.Orientation = 0.0f;
            unit->m_SeatData.c_time = 0;
            unit->m_SeatData.dbc_seat = 0;
            unit->m_SeatData.seat = 0;
            unit->m_SeatData.s_flags = 0;
            unit->m_SeatData.v_flags = 0;

            seat->second.passenger = NULL;
            seat->second.flags = SEAT_FREE;
            EmptySeatsCountChanged();
            break;
        }
    }
}
void ScreenBuilder::BuildScreen(std::vector<BaseSpriteData> * m_treeData)
{
	m_treeData->clear();

	float x = 0.0f;
	float y = 0.0f;

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 7; j++)
		{
			ScreenUtils::CalculateSquareCenter(
				m_fScreenWidth,
				m_fScreenHeight,
				j, i, &x, &y);

			TreeData data(j, i, x, y);
			m_treeData->push_back(data);
		}
	}

	for (int i = 0; i < 4; i++)
	{
		for (int j = 11; j < 17; j++)
		{
			ScreenUtils::CalculateSquareCenter(
				m_fScreenWidth,
				m_fScreenHeight,
				j, i, &x, &y);

			TreeData data(j, i, x, y);
			m_treeData->push_back(data);
		}
	}

	for (int i = 0; i < 5; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 4, &x, &y);
		TreeData data0(i, 4, x, y);
		m_treeData->push_back(data0);
	}

	for (int i = 0; i < 4; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 5, &x, &y);
		TreeData data0(i, 5, x, y);
		m_treeData->push_back(data0);
	}

	for (int i = 0; i < 3; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 6, &x, &y);
		TreeData data0(i, 6, x, y);
		m_treeData->push_back(data0);
	}


	for (int i = 12; i < 17; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 4, &x, &y);
		TreeData data0(i, 4, x, y);
		m_treeData->push_back(data0);
	}


	for (int i = 12; i < 17; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 9, &x, &y);
		TreeData data0(i, 9, x, y);
		m_treeData->push_back(data0);
	}

	
	for (int i = 0; i < 6; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 10, &x, &y);
		TreeData data(i, 10, x, y);
		m_treeData->push_back(data);
	}


	for (int i = 11; i < 17; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 10, &x, &y);
		TreeData data(i, 10, x, y);
		m_treeData->push_back(data);
	}


	for (int i = 11; i < 17; i++)
	{
		for (int j = 11; j < 15; j++)
		{
			ScreenUtils::CalculateSquareCenter(
				m_fScreenWidth,
				m_fScreenHeight,
				i, j, &x, &y);
			TreeData data(i, j, x, y);
			m_treeData->push_back(data);
		}
	}


	for (int i = 0; i < 7; i++)
	{
		ScreenUtils::CalculateSquareCenter(
			m_fScreenWidth,
			m_fScreenHeight, 
			i, 11, &x, &y);
		TreeData data(i, 11, x, y);
		m_treeData->push_back(data);
	}

	for (int i = 0; i < 8; i++)
	{
		for (int j = 12; j < 15; j++)
		{
			ScreenUtils::CalculateSquareCenter(
				m_fScreenWidth,
				m_fScreenHeight,
				i, j, &x, &y);
			TreeData data(i, j, x, y);
			m_treeData->push_back(data);
		}
	}
}
コード例 #7
0
void Vehicle::RemovePassenger(Unit *unit)
{
    SeatMap::iterator seat;
    for(seat = m_Seats.begin(); seat != m_Seats.end(); ++seat)
    {
        if((seat->second.flags & (SEAT_FULL | SEAT_VEHICLE_FREE | SEAT_VEHICLE_FULL)) && seat->second.passenger == unit)
        {
            unit->SetVehicleGUID(0);
            if(unit->GetTypeId() == TYPEID_PLAYER)
            {
                ((Player*)unit)->SetMover(unit);
                ((Player*)unit)->SetClientControl(unit, 1);
                ((Player*)unit)->GetCamera().SetView(unit);
            }

            if(seat->second.vs_flags & SF_MAIN_RIDER)
            {
                RemoveSpellsCausingAura(SPELL_AURA_CONTROL_VEHICLE);
                if(unit->GetTypeId() == TYPEID_PLAYER)
                {
                    ((Player*)unit)->RemovePetActionBar();

                    if(((Player*)unit)->GetGroup())
                        ((Player*)unit)->SetGroupUpdateFlag(GROUP_UPDATE_VEHICLE);
                }
                unit->SetCharm(NULL);
                SetCharmerGUID(NULL);
                setFaction(GetCreatureInfo()->faction_A);
            }
            if(GetVehicleFlags() & VF_NON_SELECTABLE)
                RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
            if(seat->second.vs_flags & SF_UNATTACKABLE)
                unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
            // restore player control
            if(unit->GetTypeId() == TYPEID_PLAYER)
            {
                if(seat->second.vs_flags & SF_CAN_CAST)
                {
                    WorldPacket data0(SMSG_FORCE_MOVE_UNROOT, 10);
                    data0 << unit->GetPackGUID();
                    data0 << (uint32)(2);                        // can rotate
                    unit->SendMessageToSet(&data0,true);
                }
                else
                {
                    WorldPacket data1(SMSG_FORCE_MOVE_UNROOT, 10);
                    data1 << unit->GetPackGUID();
                    data1 << (uint32)(0);                        // cannot rotate
                    unit->SendMessageToSet(&data1,true);
                }
            }
            unit->m_movementInfo.RemoveMovementFlag(MOVEFLAG_ONTRANSPORT);
            unit->m_movementInfo.RemoveMovementFlag(MOVEFLAG_ROOT);
            unit->m_movementInfo.ClearTransportData();

            seat->second.passenger = NULL;
            seat->second.flags = SEAT_FREE;
            EmptySeatsCountChanged();
            break;
        }
    }
}
コード例 #8
0
ファイル: kMeans.transformed.cpp プロジェクト: zayac/joule
variant _1_kMeans(std::vector<std::vector<double>> img, std::vector<std::vector<double>> old_centers_v, int K, double epsilon kMeans_DOWN__1_kMeans_decl) {
    cv::Mat centers(cv::Scalar(0)), old_centers(old_centers_v);
    cv::Mat data0(img);
    bool isrow = data0.rows == 1 && data0.channels() > 1;
    int N = !isrow ? data0.rows : data0.cols;
    int dims = (!isrow ? data0.cols : 1) * data0.channels();
    int type = data0.depth();

    if (!(data0.dims <= 2 && type == CV_32F && K > 0 && N >= K)) {
        error("Cannot perform K-means algorithm for this configuration" kMeans_DOWN__1_kMeans_error_use);
        return;
    }

    cv::Mat data(N, dims, CV_32F, data0.ptr(), isrow ? dims * sizeof(float) : static_cast<size_t>(data0.step));
    cv::Mat temp(1, dims, type);

    std::vector<int> counters(K, 0);
    const float* sample = data.ptr<float>(0);

    double max_center_shift = 0;

    for (int k = 0; k < K; ++k) {
        if (counters[k] != 0)
            continue;

        int max_k = 0;
        for (int k1 = 1; k1 < K; ++k1) {
            if (counters[max_k] < counters[k1])
                max_k = k1;
        }

        double max_dist = 0;
        int farthest_i = -1;
        float* new_center = centers.ptr<float>(k);
        float* old_center = centers.ptr<float>(max_k);
        float* _old_center = temp.ptr<float>();
        float scale = 1.f/counters[max_k];
        for (int j = 0; j < dims; ++j)
            _old_center[j] = old_center[j]*scale;

        for (int i = 0; i < N; ++i) {
            sample = data.ptr<float>(i);
            double dist = cv::normL2Sqr_(sample, _old_center, dims);

            if (max_dist <= dist) {
                max_dist = dist;
                farthest_i = i;
            }
        }

        counters[max_k]--;
        counters[k]++;
        sample = data.ptr<float>(farthest_i);

        for (int j = 0; j < dims; ++j) {
            old_center[j] -= sample[j];
            new_center[j] += sample[j];
        }
    }

    for (int k = 0; k < K; ++k) {
        float* center = centers.ptr<float>(k);
        if (counters[k] == 0) {
            error("For some reason one of the clusters is empty" kMeans_DOWN__1_kMeans_error_use);
            return;
        }
        float scale = 1.f/counters[k];
        for (int j = 0; j < dims; ++j)
            center[j] *= scale;

        double dist = 0;
        const float* old_center = old_centers.ptr<float>(k);
        for (int j = 0; j < dims; ++j) {
            double t = center[j] - old_center[j];
            dist += t * t;
        }
        max_center_shift = std::max(max_center_shift, dist);
    }

    std::vector<std::vector<double>> _centers;
    centers.copyTo(_centers);
    if (max_center_shift <= epsilon) {
        result(_centers kMeans_DOWN__1_kMeans_result_use);
    } else {
        _1_loop(img, _centers, K, epsilon kMeans_DOWN__1_kMeans_loop_use);
    }
}