Ejemplo n.º 1
0
bool Checker::canThrowCard(Seat* s, CardContainer& res)
{
    ManagerBase* m = s->manager();
    CardGreaterCmp gt(m);
    for (int i = 0; i < 4; ++i) {
        Seat* oth = m->seat(i);
        if (oth == s) {
            continue;
        }
        std::vector<Card> had;
        oth->getSuit(res.mask().hasOnlySuit(), had);
        CardContainer tmp;
        parse(m, had, tmp);
        for (auto& i : res.cards()) {
            for (auto& j : tmp.cards()) {
                if (i.mask.has(CardMask::Pair)) {
                    if (j.mask.has(CardMask::Pair)) {
                        if (i.cards.size() <= j.cards.size()) {
                            if (gt(i.cards[0], j.cards[0]) < 0) {
                                return false;
                            }
                        }
                    }
                } else if (gt(i.cards.back(), j.cards[0]) < 0) {
                    return false;
                }
            }
        }
    }
    return true;
}
Ejemplo n.º 2
0
void Manager::handlePutBottom(ValueEvent<PutBottomMsg>* e)
{
    auto v = e->value();
    Seat* s = seat(v.seat());
    std::vector<Card> bottom;
    for (auto c : v.card()) {
        bottom.push_back(c);
    }
    if (mStatus != PickBottom) {
        notifyPutBottomFail(s, bottom, ErrorCode::StatusError);
        return;
    }
    if (s->seat() != mDealer) {
        notifyPutBottomFail(s, bottom, ErrorCode::PerformerError);
        return;
    }
    try {
        mChecker->putBottom(s, bottom);
        mRes.putBottom(bottom);
        mStatus = BottomFinish;
        notifyFixBottom(s, bottom, FixBottomReason::Normal);
    } catch (Exception& e) {
        notifyPutBottomFail(s, bottom, e.code());
    }
}
Ejemplo n.º 3
0
void ServPlayer::handle(Message* m)
{
    if (m->type() == MsgType::Attach) {
        auto msg = m->get<AttachMsg>();
        Seat* s = manager()->seat(msg->seat());
        msg->set_self(s->player() == this);
    }
    mHdler->send(new Message(*m));
}
Ejemplo n.º 4
0
void ManagerBase::detach(Player* p)
{
    int id = p->seat();
    Seat* s = seat(id);
    if (s) {
        if (s->player() == p) {
            s->setPlayer(nullptr);
        }
        p->setSeat(NoneSeat);
        detach((ManagerObserver*)p);
        notifyDetach(p, id);
    }
}
Ejemplo n.º 5
0
    void SeatManager::removeSeat(const QString &name) {
        // check if seat exists
        if (!m_seats.contains(name))
            return;

        // remove from the list
        Seat *seat = m_seats.take(name);

        // delete seat
        seat->deleteLater();

        // emit signal
        emit seatRemoved(name);
    }
Ejemplo n.º 6
0
Pointer::Pointer(const Seat& seat)
	: seat_(seat)
	, focus_(NULL)
	, focusSerial_(0)
	, x_(-1)
	, y_(-1)
	, button_(0)
	, buttonState_(0)
	, axis_(0)
	, axisValue_(0.f)
	, wl_pointer_(NULL)
	, btnNotify_()
{
	ASSERT(seat.capabilities() & WL_SEAT_CAPABILITY_POINTER);

	wl_pointer_ = wl_seat_get_pointer(seat);

	ASSERT(wl_pointer_ != NULL);

	wl_pointer_set_user_data(*this, this);

	static const wl_pointer_listener listener = {
		enter, leave, motion, button, axis};

	wl_pointer_add_listener(*this, &listener, this);
}
Ejemplo n.º 7
0
void ManagerBase::attach(Player* p, int id)
{
    Seat* s = seat(id);
    if (!s) {
        throw Exception(ManagerBaseExcp, ErrorCode::InvalidSeat, "Invalid seat(%d)", id);
    }
    if (s->player()) {
        if (s->player() == p) {
            return;
        }
        throw Exception(ManagerBaseExcp, ErrorCode::SeatOccupied, "Current seat(%d) has been occupied", id);
    }
    detach(p);
    s->setPlayer(p);
    p->setSeat(id);
    attach((ManagerObserver*)p);
    notifyAttach(p, id);
}
Ejemplo n.º 8
0
void MyShellModule::init(Compositor& comp, Seat& seat)
{
	compositor_ = &comp;
	seat_ = &seat;

	shell_.reset(new Shell(comp));
	xdgShell_.reset(new XdgShell(comp));

	seat.keyboard()->onFocus(nytl::memberCallback(&MyShellModule::keyboardFocus, this));
}
Ejemplo n.º 9
0
void Manager::throwFailForceDiscard()
{
    const SingleRecord* r = mRes.getLastThrowFail();
    const CardContainer& c = r->cards;
    const CardUnit& u = c.cards().back();
    std::vector<Card> cards(1);
    cards[0] = u.cards.back();
    Seat* s = mPerformer;
    DiscardActionMsg m;
    m.set_seat(s->seat());
    m.set_reason(DiscardActionMsg::ThrowFailForce);
    m.set_order(mRes.resNumber());
    m.set_max(true);
    m.set_score(0);
    m << cards;
    mRes.put(s->seat(), c, true);
    mPerformer = mPerformer->next();
    notifyDiscardAction(m);
    mStatus = DiscardNotify;
}
Ejemplo n.º 10
0
void Manager::handleDiscardRequest(ValueEvent<DiscardRequestMsg>* e)
{
    Seat* s = seat(e->value().seat());
    std::vector<Card> cards;
    for (auto c : e->value().card()) {
        cards.push_back(c);
    }
    if (mStatus != DiscardWait) {
        notifyDiscardFail(s, cards, ErrorCode::StatusError);
        return;
    }
    if (mPerformer != s) {
        notifyDiscardFail(s, cards, ErrorCode::PerformerError);
        return;
    }
    CardContainer res;
    bool isMax = false;
    try {
        isMax = mChecker->discard(mRes, s, cards, res);
    } catch (Exception& excp) {
        if (excp.code() == ErrorCode::ThrowFail) {
            mStatus = ThrowFail;
            mRes.putThrowFail(s->id(), res);
        }
        notifyDiscardFail(s, cards, excp.code());
        return;
    }
    DiscardActionMsg m;
    m.set_seat(s->seat());
    m.set_max(isMax);
    m.set_reason(DiscardActionMsg::Normal);
    m.set_order(mRes.resNumber());
    m.set_score(0);
    mRes.put(s->seat(), res, isMax);
    if (mRes.resNumber() == 0) {
        mPerformer = seat(mRes.lastCircle().max()->seat);
        if ((mPerformer->id() & 1) != (mDealer & 1)) {
            int score = mRes.lastCircle().score();
            if (score > 0) {
                mRes.addScore(score);
                m.set_score(score);
            }
        }
    } else {
        mPerformer = mPerformer->next();
    }
    m << cards;
    notifyDiscardAction(m);
    if (mRes.resCnt() == 100) {
        mStatus = DiscardFinish;
        std::vector<Card> b;
        mGen.getBottom(b);
        Seat* s = seat(mRes.lastCircle().max()->seat);
        int score = 0;
        int factor = 0;
        if ((s->id() & 1) != (mDealer & 1)) {
            const CardContainer& cc = mRes.lastCircle().max()->cards;
            if (mOpt.slaveCanCatchBottom ||
                cc.mask().hasOnlySuit() == CardMask::Master) {
                for (auto& i : b) {
                    score += i.score();
                }
                factor = cc.factor();
                if (mOpt.doubleBottomScore) {
                    factor <<= 1;
                }
                mRes.addScore(score * factor);
            }
        }
        mPerformer = NULL;
        notifyDiscardFinish(mRes, score, factor);
    } else {
        mStatus = DiscardNotify;
    }
}
Ejemplo n.º 11
0
void MyShellModule::render(Output& outp, ny::DrawContext& dc)
{
	if(!myTexture.glTexture())
	{
		ny::Image myImage;
		ny::sendLog("loading wallpaper... ", myImage.load("wallpaper.png"));

		myTexture.create(myImage);
	}
	
	glViewport(0, 0, outp.size().x, outp.size().y);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	dc.clear(ny::Color::red);

	ny::TextureBrush texBrush;
	texBrush.extents.position = {0.f, 0.f};
	texBrush.extents.size = outp.size();
	texBrush.texture = &myTexture;

	ny::Rectangle bg = texBrush.extents;
	dc.mask(bg);
	dc.fill(texBrush);

	SurfaceRes* cursorSurface = nullptr;
	ny::sendLog("Shell: Drawing ", outp.mappedSurfaces().size(), " mapped surfaces");
	for(auto& surf : outp.mappedSurfaces())
	{
		if(surf->roleType() == surfaceRoleType::cursor)
			cursorSurface = surf;

		/*
		ny::Rectangle surfaceRect(surf->extents());
		surfaceRect.position(surfaceRect.position() - outp.extents().position);
		dc.mask(surfaceRect);

		ny::TextureBrush surfaceBrush;
		surfaceBrush.extents = surfaceRect;
		surfaceBrush.texture = surf->surfaceContext().content();

		dc.fill(surfaceBrush);
		*/

		surf->sendFrameDone();
	}

	//windows are sorted by z order
	for(auto& window : windows_)
	{
		auto* surf = window->surfaceRes();	
		if(!surf) continue;

		if(window == focus_)
		{
			ny::Rectangle surfaceRect(surf->extents());
			surfaceRect.position(surfaceRect.position() + nytl::Vec2ui{20,20});
			surfaceRect.size(surfaceRect.size() - nytl::Vec2ui{40,40});
			dc.mask(surfaceRect);
			dc.fill(ny::Color::green);
		}

		ny::Rectangle surfaceRect(surf->extents());
		surfaceRect.position(surfaceRect.position() - outp.extents().position);
		dc.mask(surfaceRect);

		ny::TextureBrush surfaceBrush;
		surfaceBrush.extents = surfaceRect;
		surfaceBrush.texture = surf->surfaceContext().content();

		dc.fill(surfaceBrush);
	}
	
	if(cursorSurface)
	{
		SurfaceRes* surf = cursorSurface;
		ny::Rectangle surfaceRect(surf->extents());
		surfaceRect.position(surfaceRect.position() - outp.extents().position);
		dc.mask(surfaceRect);

		ny::TextureBrush surfaceBrush;
		surfaceBrush.extents = surfaceRect;
		surfaceBrush.texture = surf->surfaceContext().content();

		dc.fill(surfaceBrush);

		surf->sendFrameDone();
	}
	
	else
	{
		if(!cursorTexture.glTexture())
		{
			ny::Image cursorImage;
			ny::sendLog("loading cursor image: ", cursorImage.load("cursor.png"));
			cursorTexture.create(cursorImage);
		}

		ny::TextureBrush cursorBrush;
		cursorBrush.extents.position = seat_->pointer()->position() - outp.extents().position;
		cursorBrush.extents.size = nytl::Vec2f(30, 30);
		cursorBrush.texture = &cursorTexture;

		dc.mask(ny::Rectangle(cursorBrush.extents.position, nytl::Vec2f(30, 30)));
		dc.fill(cursorBrush);
	}
}
Ejemplo n.º 12
0
void Screenshooter::shootSurface(wl_client *client, wl_resource *resource, uint32_t id)
{
    wl_resource *res = wl_resource_create(client, &orbital_surface_screenshot_interface, 1, id);
    class SurfaceScreenshot : public PointerGrab
    {
    public:
        SurfaceScreenshot(Compositor *c, wl_resource *res)
            : m_compositor(c)
            , m_resource(res)
            , m_surface(nullptr)
        {
            static const struct orbital_surface_screenshot_interface implementation = {
                wrapInterface(shoot),
            };
            wl_resource_set_implementation(m_resource, &implementation, this, nullptr);
        }

        void failed()
        {
            orbital_surface_screenshot_send_failed(m_resource);
            wl_resource_destroy(m_resource);
            delete this;
        }

        void shoot(wl_resource *resource)
        {
            if (!wl_shm_buffer_get(resource)) {
                failed();
                return;
            }

            wl_shm_buffer *shm = wl_shm_buffer_get(resource);
            int width = wl_shm_buffer_get_width(shm);
            int height = wl_shm_buffer_get_height(shm);
            int stride = wl_shm_buffer_get_stride(shm);
            QSize size = m_surface->contentSize();

            if (stride != size.width() * 4 || height != size.height()) {
                failed();
                return;
            }

            wl_shm_buffer_begin_access(shm);

            void *data = wl_shm_buffer_get_data(shm);
            m_surface->copyContent(data, stride * height, QRect(0, 0, width, height));

            wl_shm_buffer_end_access(shm);

            orbital_surface_screenshot_send_done(m_resource);
            wl_resource_destroy(m_resource);
            delete this;
        }

        void motion(uint32_t time, Pointer::MotionEvent evt) override
        {
            pointer()->move(evt);
        }
        void button(uint32_t time, PointerButton button, Pointer::ButtonState state) override
        {
            if (pointer()->buttonCount() == 0 && state == Pointer::ButtonState::Released) {
                View *view = m_compositor->pickView(pointer()->x(), pointer()->y());
                if (view) {
                    m_surface = view->surface();

                    QSize size = m_surface->contentSize();
                    orbital_surface_screenshot_send_setup(m_resource, size.width(), size.height(), size.width() * 4, 0);
                }

                end();
            }
        }

        Compositor *m_compositor;
        wl_resource *m_resource;
        Surface *m_surface;
    };

    auto *grab = new SurfaceScreenshot(m_compositor, res);
    Seat *seat = m_compositor->seats().front();
    seat->pointer()->setFocus(nullptr);
    grab->start(seat, PointerCursor::Kill);
}