void Enemy::move() {
	if (this->isDead && (sKind != 5 || sNum != 0))
		return;

	switch (status) {
	case EnemyNS::DIRECTION::ENTER: 
		enterEnemy();
		break;
	case EnemyNS::DIRECTION::BEGINPOS: 
		beginPos();
		break;
	case EnemyNS::DIRECTION::POSITION: 
		position();
		break;
	case EnemyNS::DIRECTION::SYNC:
		makeSync();
		break;
	case EnemyNS::DIRECTION::ATTACK: 
		attack();
		break;
	case EnemyNS::DIRECTION::BEGINBACK:
		beginBackPos();
		break;
	case EnemyNS::DIRECTION::BACKPOS:
		backPosition();
	}
}
Example #2
0
void BoxTool::endCreating(const QPointF &pos_) {
    Body* b = scene()->activeBody();
    QPointF pos = pos_;
    if (b) {
        pos = b->toLocal(pos_);
    }
    Tool::endCreating(pos);
    QPointF size = pos-beginPos();
    if (size.x()>0)
        m_primitive->setRight(pos.x());
    else if (size.x()<0)
        m_primitive->setLeft(pos.x());
    else {
        delete m_primitive;
        m_primitive = 0;
        return;
    }
    if (size.y()>0)
        m_primitive->setBottom(pos.y());
    else if (size.y()<0)
        m_primitive->setTop(pos.y());
    else {
        delete m_primitive;
        m_primitive = 0;
        return;
    }

    CreatePrimitiveCommand* cmd = new CreatePrimitiveCommand(scene()->activeBody(), m_primitive);
    m_primitive = 0;
    scene()->execCommand(cmd);
}
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    void SliderControl::RebuildSliderLine()
    {
        const F32 halfHeight = VGetHeight() / 2.0f;
        Point3 beginPos(VGetPosition()), endPos(VGetPosition());
        beginPos.SetY(beginPos.GetY() - halfHeight);
        endPos.SetX(endPos.GetX() + VGetWidth());
        endPos.SetY(endPos.GetY() - halfHeight);

        m_sliderLineBatch.reset(GCC_NEW GLBatch());
        m_sliderLineBatch->Begin(GL_LINES, 2);
        m_sliderLineBatch->Vertex3f(beginPos.GetX(), beginPos.GetY(), beginPos.GetZ());
        m_sliderLineBatch->Vertex3f(endPos.GetX(), endPos.GetY(), endPos.GetZ());
        m_sliderLineBatch->End();
    }
Example #4
0
bool TextFieldTTFActionTest::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)
{
    // if insert enter, treat as default to detach with ime
    if ('\n' == *text)
    {
        return false;
    }
    
    // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
    if (pSender->getCharCount() >= m_nCharLimit)
    {
        return true;
    }

    // create a insert text sprite aScut do some action
    CCLabelTTF * label = CCLabelTTF::create(text, FONT_NAME, FONT_SIZE);
    this->addChild(label);
    ccColor3B color = { 226, 121, 7};
    label->setColor(color);

    // move the sprite from top to position
    CCPoint endPos = pSender->getPosition();
    if (pSender->getCharCount())
    {
        endPos.x += pSender->getContentSize().width / 2;
    }
    CCSize  inputTextSize = label->getContentSize();
    CCPoint beginPos(endPos.x, CCDirector::sharedDirector()->getWinSize().height - inputTextSize.height * 2); 

    float duration = 0.5;
    label->setPosition(beginPos);
    label->setScale(8);

    CCAction * seq = CCSequence::create(
        CCSpawn::create(
            CCMoveTo::create(duration, endPos),
            CCScaleTo::create(duration, 1),
            CCFadeOut::create(duration),
        0),
        CCCallFuncN::create(this, callfuncN_selector(TextFieldTTFActionTest::callbackRemoveNodeWhendidAction)),
        0);
    label->runAction(seq);
    return false;
}
bool TextFieldTTFActionTest::onTextFieldInsertText(TextFieldTTF * sender, const char * text, int nLen)
{
    // if insert enter, treat as default to detach with ime
    if ('\n' == *text)
    {
        return false;
    }
    
    // if the textfield's char count more than _charLimit, doesn't insert text anymore.
    if (sender->getCharCount() >= _charLimit)
    {
        return true;
    }

    // create a insert text sprite and do some action
    auto label = LabelTTF::create(text, FONT_NAME, FONT_SIZE);
    this->addChild(label);
    Color3B color(226, 121, 7);
    label->setColor(color);

    // move the sprite from top to position
    auto endPos = sender->getPosition();
    if (sender->getCharCount())
    {
        endPos.x += sender->getContentSize().width / 2;
    }
    auto inputTextSize = label->getContentSize();
    Point beginPos(endPos.x, Director::getInstance()->getWinSize().height - inputTextSize.height * 2); 

    float duration = 0.5;
    label->setPosition(beginPos);
    label->setScale(8);

    auto seq = Sequence::create(
        Spawn::create(
            MoveTo::create(duration, endPos),
            ScaleTo::create(duration, 1),
            FadeOut::create(duration),
            NULL),
        CallFuncN::create(CC_CALLBACK_1(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction, this)),
        NULL);
    label->runAction(seq);
    return false;
}
Example #6
0
bool BoxTool::onMouseMove(const QPointF &pos_) {
    Body* b = scene()->activeBody();
    QPointF pos = pos_;
    if (b) {
        pos = b->toLocal(pos_);
    }
    if (Tool::onMouseMove(pos)) {
        QPointF size = pos-beginPos();
        if (size.x()>0)
            m_primitive->setRight(pos.x());
        else
            m_primitive->setLeft(pos.x());
        if (size.y()>0)
            m_primitive->setBottom(pos.y());
        else
            m_primitive->setTop(pos.y());
        scene()->setText(m_primitive->text());
        return true;
    }
    return false;
}
Example #7
0
static
void
runESL(const ESLOptions& opt)
{
    TimeTracker timer;
    timer.resume();
    {
        // early test that we have permission to write to output file
        OutStream outs(opt.outputFilename);
    }

    typedef std::shared_ptr<bam_streamer> stream_ptr;
    std::vector<stream_ptr> bamStreams;

    // setup all data for main alignment loop:
    for (const std::string& afile : opt.alignFileOpt.alignmentFilename)
    {
        stream_ptr tmp(new bam_streamer(afile.c_str(),
                                        (opt.region.empty()
                                         ? NULL
                                         : opt.region.c_str())));
        bamStreams.push_back(tmp);
    }

    const unsigned bamCount(bamStreams.size());

    assert(0 != bamCount);

    // check bam header compatibility:
    if (bamCount > 1)
    {
        /// TODO: provide a better error exception for failed bam header check:
        const bam_header_t* compareHeader(bamStreams[0]->get_header());
        for (unsigned bamIndex(1); bamIndex<bamCount; ++bamIndex)
        {
            const bam_header_t* indexHeader(bamStreams[bamIndex]->get_header());
            if (! check_header_compatibility(compareHeader,indexHeader))
            {
                log_os << "ERROR: incompatible bam headers between files:\n"
                       << "\t" << opt.alignFileOpt.alignmentFilename[0] << "\n"
                       << "\t" << opt.alignFileOpt.alignmentFilename[bamIndex] << "\n";
                exit(EXIT_FAILURE);
            }
        }
    }

    // assume headers compatible after this point....

    const bam_header_t& header(*(bamStreams[0]->get_header()));
    const bam_header_info bamHeader(header);

    int32_t tid(0), beginPos(0), endPos(0);
    parse_bam_region(bamHeader,opt.region,tid,beginPos,endPos);

    const GenomeInterval scanRegion(tid,beginPos,endPos);
#ifdef DEBUG_ESL
    static const std::string log_tag("EstimateSVLoci");
    log_os << log_tag << " scanRegion= " << scanRegion << "\n";
#endif

    // grab the reference for segment we're estimating plus a buffer around the segment edges:
    static const unsigned refEdgeBufferSize(500);

    reference_contig_segment refSegment;
    getIntervalReferenceSegment(opt.referenceFilename, bamHeader, refEdgeBufferSize, scanRegion, refSegment);

    SVLocusSetFinder locusFinder(opt, scanRegion, bamHeader, refSegment);

    input_stream_data sdata;
    for (unsigned bamIndex(0); bamIndex<bamCount; ++bamIndex)
    {
        sdata.register_reads(*bamStreams[bamIndex],bamIndex);
    }

    // loop through alignments:
    input_stream_handler sinput(sdata);
    while (sinput.next())
    {
        const input_record_info current(sinput.get_current());

        if (current.itype != INPUT_TYPE::READ)
        {
            log_os << "ERROR: invalid input condition.\n";
            exit(EXIT_FAILURE);
        }

        const bam_streamer& readStream(*bamStreams[current.sample_no]);
        const bam_record& read(*(readStream.get_record_ptr()));

        locusFinder.update(read, current.sample_no);
    }

    // finished updating:
    locusFinder.flush();
    timer.stop();
    const CpuTimes totalTimes(timer.getTimes());
#ifdef DEBUG_ESL
    log_os << log_tag << " found " << locusFinder.getLocusSet().size() << " loci. \n";
    log_os << log_tag << " totalTime: ";
    totalTimes.reportHr(log_os);
    log_os << "\n";
#endif
    locusFinder.setBuildTime(totalTimes);
    locusFinder.getLocusSet().save(opt.outputFilename.c_str());
}
Example #8
0
static
void
runESL(const ESLOptions& opt)
{
    {
        // early test that we have permission to write to output file
        OutStream outs(opt.outputFilename);
    }

    typedef boost::shared_ptr<bam_streamer> stream_ptr;
    std::vector<stream_ptr> bam_streams;

    // setup all data for main alignment loop:
    BOOST_FOREACH(const std::string& afile, opt.alignmentFilename)
    {
        stream_ptr tmp(new bam_streamer(afile.c_str(),opt.region.c_str()));
        bam_streams.push_back(tmp);
    }

    // TODO check header compatibility between all open bam streams
    const unsigned n_inputs(bam_streams.size());

    // assume headers compatible after this point....

    assert(0 != n_inputs);

    const bam_header_t& header(*(bam_streams[0]->get_header()));
    const bam_header_info bamHeader(header);
    int32_t tid(0), beginPos(0), endPos(0);
    parse_bam_region(bamHeader,opt.region,tid,beginPos,endPos);

    const GenomeInterval scanRegion(tid,beginPos,endPos);

    SVLocusSetFinder locusFinder(opt,scanRegion);
    locusFinder.setBamHeader(header);

    input_stream_data sdata;
    for (unsigned i(0); i<n_inputs; ++i)
    {
        sdata.register_reads(*bam_streams[i],i);
    }

    // loop through alignments:
    input_stream_handler sinput(sdata);
    while (sinput.next())
    {
        const input_record_info current(sinput.get_current());

        if       (current.itype != INPUT_TYPE::READ)
        {
            log_os << "ERROR: invalid input condition.\n";
            exit(EXIT_FAILURE);
        }

        const bam_streamer& read_stream(*bam_streams[current.sample_no]);
        const bam_record& read(*(read_stream.get_record_ptr()));

        locusFinder.update(read,current.sample_no);
    }

    // finished updating:
    locusFinder.flush();

    locusFinder.getLocusSet().save(opt.outputFilename.c_str());
}
Example #9
0
bool MobiBookReader::UpdateReadingData(
        const char*,
        const std::vector<ICT_ReadingDataItem *> *_pvOld,
        const char*,
        std::vector<ICT_ReadingDataItem *> *_pvNew)
{
    if (NULL == _pvOld || NULL == _pvNew || 0 == _pvOld->size() || 0 != _pvNew->size())
    {
        return false;
    }

    DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() DKM_OpenDocument %s", __FUNCTION__, m_strBookPath.c_str());
    DK_WCHAR *wsFilePath = EncodingUtil::CharToWChar(m_strBookPath.c_str());
    if (NULL == wsFilePath)
    {
        DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() CharToWChar Error", __FUNCTION__);
        return false;
    }

    IDKEBook *pBook = (IDKEBook *)DKM_OpenDocument(wsFilePath, NULL);
    DK_FREE(wsFilePath);
    if (NULL == pBook)
    {
        DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() DKE_OpenMOBIDocument fail", __FUNCTION__);
        return false;
    }

    DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() PrepareParseContent", __FUNCTION__);
    if (DK_FAILED(pBook->PrepareParseContent(DK_NULL)))
    {
        DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() PrepareParseContent fail", __FUNCTION__);
        DKM_CloseDocument(pBook);
        return false;
    }

    DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() Begin to update", __FUNCTION__);
    for (unsigned int i = 0; i < _pvOld->size(); ++i)
    {
        CT_RefPos begin = (*_pvOld)[i]->GetBeginPos();
        DK_FLOWPOSITION beginPos((unsigned int)(begin.GetChapterIndex()), 
                                 (unsigned int)(begin.GetParaIndex()), 
                                 (unsigned int)(begin.GetAtomIndex()));

        CT_RefPos end = (*_pvOld)[i]->GetEndPos();
        DK_FLOWPOSITION endPos((unsigned int)(end.GetChapterIndex()), 
                               (unsigned int)(end.GetParaIndex()), 
                               (unsigned int)(end.GetAtomIndex()));

        if (ICT_ReadingDataItem::PROGRESS == (*_pvOld)[i]->GetUserDataType())
        {
            --(endPos.nChapterIndex);
        }

        DK_UINT beginChapter = 0;
        DK_OFFSET beginOffset = 0;
        DK_UINT endChapter = 0;
        DK_OFFSET endOffset = 0;
        if (DKR_OK == pBook->DKFlowPositionRange2OffsetRange(beginPos, endPos, &beginChapter, &beginOffset, &endChapter, &endOffset))
        {
            DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() beginChapter %d, beginOffset %d", __FUNCTION__, beginChapter, beginOffset);
            DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() endChapter %d, endOffset %d", __FUNCTION__, endChapter, endOffset);

            ICT_ReadingDataItem *pclsReadingDate = DKXReadingDataItemFactory::CreateReadingDataItem();
            if (pclsReadingDate)
            {
                pclsReadingDate->SetCreateTime((*_pvOld)[i]->GetCreateTime());
                pclsReadingDate->SetCreator("DuoKan");

                begin.SetChapterIndex(0);
                begin.SetParaIndex(0);
                begin.SetAtomIndex(beginOffset);
                pclsReadingDate->SetBeginPos(begin);

                end.SetChapterIndex(0);
                end.SetParaIndex(0);
                end.SetAtomIndex(endOffset);
                pclsReadingDate->SetEndPos(end);

                pclsReadingDate->SetLastModifyTime((*_pvOld)[i]->GetLastModifyTime());
                pclsReadingDate->SetBookContent((*_pvOld)[i]->GetBookContent());
                pclsReadingDate->SetUserContent((*_pvOld)[i]->GetUserContent());
                pclsReadingDate->SetUserDataType((*_pvOld)[i]->GetUserDataType());
                pclsReadingDate->SetUploaded((*_pvOld)[i]->IsUploaded());

                _pvNew->push_back(pclsReadingDate);
            }
        }
    }

    DKM_CloseDocument(pBook);
    DebugPrintf(DLC_ZHAIGH, "MobiBookReader::%s() Finish", __FUNCTION__);
    return true;
}