void SkPathOpsDebug::ShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp,
        const char* testName) {
    ShowFunctionHeader(testName);
    showPath(a, "path", true);
    showPath(b, "pathB", true);
    ShowOp(shapeOp, "path", "pathB");
}
Ejemplo n.º 2
0
static int comparePaths(const SkPath& one, const SkPath& two, SkBitmap& bitmap,
        SkCanvas* canvas) {
    int errors = pathsDrawTheSame(one, two, bitmap, canvas);
    if (errors == 0) {
        return 0;
    }
    drawAsciiPaths(one, two, gDrawAllAsciiPaths);
    for (int x = 9; x <= 33; ++x) {
        errors = scaledDrawTheSame(one, two, x, x - (x >> 2), gDrawAllAsciiPaths,
            bitmap, canvas);
        if (errors == 0) {
            return 0;
        }
    }
    if (!gDrawAllAsciiPaths) {
        errors = scaledDrawTheSame(one, two, 9, 7, false, bitmap, canvas);
        if (errors > 4) {
            scaledDrawTheSame(one, two, 9, 7, true, bitmap, canvas);
        }
    }
    if (errors > 0) SkDebugf("\n%s errors=%d\n", __FUNCTION__, errors); 
    if (errors > 4 && gComparePathsAssert) {
        showPath(one);
        showPath(two, "simplified:");
        SkASSERT(0);
    }
    return errors;
}
Ejemplo n.º 3
0
static void showShapeOpPath(const SkPath& one, const SkPath& two, const SkPath& a, const SkPath& b,
        const SkPath& scaledOne, const SkPath& scaledTwo, const ShapeOp shapeOp) {
    SkASSERT((unsigned) shapeOp < sizeof(opStrs) / sizeof(opStrs[0]));
    showPath(a, "minuend:");
    SkDebugf("op: %s\n", opStrs[shapeOp]);
    showPath(b, "subtrahend:");
    showPath(one, "region:");
    showPath(two, "op result:");
    drawAsciiPaths(scaledOne, scaledTwo, true);
}
Ejemplo n.º 4
0
 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
     showPath(canvas,   0,   0, SkPath::kWinding_FillType,
              scale, paint);
     showPath(canvas, 200,   0, SkPath::kEvenOdd_FillType,
              scale, paint);
     showPath(canvas,  00, 200, SkPath::kInverseWinding_FillType,
              scale, paint);
     showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
              scale, paint);
 }
Ejemplo n.º 5
0
// Three circles bounce inside a rectangle. The circles describe three, four
// or five points which in turn describe a polygon. The polygon points
// bounce inside the circles. The circles rotate and scale over time. The
// polygons are combined into a single path, simplified, and stroked.
static bool drawCircles(SkCanvas* canvas, int step)
{
    const int circles = 3;
    int scales[circles];
    int angles[circles];
    int locs[circles * 2];
    int pts[circles * 2 * 4];
    int c, p;
    for (c = 0; c < circles; ++c) {
        scales[c] = abs(10 - (step + c * 4) % 21);
        angles[c] = (step + c * 6) % 600;
        locs[c * 2] = abs(130 - (step + c * 9) % 261);
        locs[c * 2 + 1] = abs(170 - (step + c * 11) % 341);
        for (p = 0; p < 4; ++p) {
            pts[c * 8 + p * 2] = abs(90 - ((step + c * 121 + p * 13) % 190));
            pts[c * 8 + p * 2 + 1] = abs(110 - ((step + c * 223 + p * 17) % 230));
        }
    }
    SkPath path, out;
    for (c = 0; c < circles; ++c) {
        for (p = 0; p < 4; ++p) {
            SkScalar x = pts[c * 8 + p * 2];
            SkScalar y = pts[c * 8 + p * 2 + 1];
            x *= 3 + scales[c] / 10.0f;
            y *= 3 + scales[c] / 10.0f;
            SkScalar angle = angles[c] * 3.1415f * 2 / 600;
            SkScalar temp = x * cos(angle) - y * sin(angle);
            y = x * sin(angle) + y * cos(angle);
            x = temp;
            x += locs[c * 2] * 200 / 130.0f;
            y += locs[c * 2 + 1] * 200 / 170.0f;
            x += 50;
    //        y += 200;
            if (p == 0) {
                path.moveTo(x, y);
            } else {
                path.lineTo(x, y);
            }
        }
        path.close();
    }
    showPath(path, "original:");
    simplify(path, true, out);
    showPath(out, "simplified:");
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(3);
    paint.setColor(0x3F007fbF);
    canvas->drawPath(path, paint);
    paint.setColor(0xFF60FF00);
    paint.setStrokeWidth(1);
    canvas->drawPath(out, paint);
    return true;
}
static void showPathOpPath(const SkPath& one, const SkPath& two, const SkPath& a, const SkPath& b,
        const SkPath& scaledOne, const SkPath& scaledTwo, const SkPathOp shapeOp,
        const SkMatrix& scale) {
    SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs));
    SkDebugf("static void xOp#%s(skiatest::Reporter* reporter) {\n", opSuffixes[shapeOp]);
    SkDebugf("    SkPath path, pathB;\n");
    showPath(a, "path", false);
    showPath(b, "pathB", false);
    SkDebugf("    testPathOp(reporter, path, pathB, %s);\n", opStrs[shapeOp]);
    SkDebugf("}\n");
    drawAsciiPaths(scaledOne, scaledTwo, true);
}
Ejemplo n.º 7
0
bool drawAsciiPaths(const SkPath& one, const SkPath& two,
        bool drawPaths) {
    if (!drawPaths) {
        return true;
    }
    if (gShowAsciiPaths) {
        showPath(one, "one:");
        showPath(two, "two:");
    }
    const SkRect& bounds1 = one.getBounds();
    const SkRect& bounds2 = two.getBounds();
    SkRect larger = bounds1;
    larger.join(bounds2);
    SkBitmap bits;
    char out[256];
    int bitWidth = SkScalarCeil(larger.width()) + 2;
    if (bitWidth * 2 + 1 >= (int) sizeof(out)) {
        return false;
    }
    int bitHeight = SkScalarCeil(larger.height()) + 2;
    if (bitHeight >= (int) sizeof(out)) {
        return false;
    }
    bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight);
    bits.allocPixels();
    SkCanvas canvas(bits);
    canvas.drawColor(SK_ColorWHITE);
    SkPaint paint;
    canvas.save();
    canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
    canvas.drawPath(one, paint);
    canvas.restore();
    canvas.save();
    canvas.translate(-bounds2.fLeft + 1 + bitWidth, -bounds2.fTop + 1);
    canvas.drawPath(two, paint);
    canvas.restore();
    for (int y = 0; y < bitHeight; ++y) {
        uint32_t* addr1 = bits.getAddr32(0, y);
        int x;
        char* outPtr = out;
        for (x = 0; x < bitWidth; ++x) {
            *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
        }
        *outPtr++ = '|';
        for (x = bitWidth; x < bitWidth * 2; ++x) {
            *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
        }
        *outPtr++ = '\0';
        SkDebugf("%s\n", out);
    }
    return true;
}
Ejemplo n.º 8
0
void MMapperPluginParser::submit() {
  m_descriptionReady = false;
  
  // non standard end of description parsed (fog, dark or so ...)
  if (Patterns::matchNoDescriptionPatterns(m_roomName)) {
    qDebug() << "* fog, dark or so ..., nulling strings";
    m_roomName = nullString;
    m_dynamicRoomDesc = nullString;
    m_staticRoomDesc = nullString;
  }
  
  if (!queue.isEmpty()) {
    CommandIdType c = queue.dequeue();
    if ( c != CID_SCOUT ) {
      emit showPath(queue, false);
      characterMoved(_move, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
      if (c != _move)
        queue.clear();
      _move = CID_LOOK;
    }

  } else {
    //emit showPath(queue, false);
    characterMoved(_move, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
    _move = CID_LOOK;
  }

  m_exitsFlags = 0;
  m_promptFlags = 0;
  m_roomName = nullString;
  m_dynamicRoomDesc = nullString;
  m_staticRoomDesc = nullString;
}
Ejemplo n.º 9
0
bool testSimplifyx(SkPath& path, bool useXor, SkPath& out, State4& state,
        const char* pathStr) {
    SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
    path.setFillType(fillType);
    if (gShowPath) {
        showPath(path);
    }
    simplifyx(path, out);
    if (!gComparePaths) {
        return true;
    }
    int result = comparePaths(path, out, state.bitmap);
    if (result && gPathStrAssert) {
        SkDebugf("addTest %s\n", state.filename);
        char temp[8192];
        bzero(temp, sizeof(temp));
        SkMemoryWStream stream(temp, sizeof(temp));
        const char* pathPrefix = NULL;
        const char* nameSuffix = NULL;
        if (fillType == SkPath::kEvenOdd_FillType) {
            pathPrefix = "    path.setFillType(SkPath::kEvenOdd_FillType);\n";
            nameSuffix = "x";
        }
        const char testFunction[] = "testSimplifyx(path);";
        outputToStream(state, pathStr, pathPrefix, nameSuffix, testFunction, stream);
        SkDebugf(temp);
        SkASSERT(0);
    }
    return result == 0;
}
bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& state,
                  const char* pathStr) {
    SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
    path.setFillType(fillType);
    if (gShowPath) {
        showPath(path, "path", false);
    }
    if (!Simplify(path, &out)) {
        SkDebugf("%s did not expect failure\n", __FUNCTION__);
        REPORTER_ASSERT(state.fReporter, 0);
        return false;
    }
    if (!state.fReporter->verbose()) {
        return true;
    }
    int result = comparePaths(state.fReporter, path, out, *state.fBitmap);
    if (result && gPathStrAssert) {
        char temp[8192];
        sk_bzero(temp, sizeof(temp));
        SkMemoryWStream stream(temp, sizeof(temp));
        const char* pathPrefix = NULL;
        const char* nameSuffix = NULL;
        if (fillType == SkPath::kEvenOdd_FillType) {
            pathPrefix = "    path.setFillType(SkPath::kEvenOdd_FillType);\n";
            nameSuffix = "x";
        }
        const char testFunction[] = "testSimplifyx(path);";
        outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, stream);
        SkDebugf(temp);
        REPORTER_ASSERT(state.fReporter, 0);
    }
    state.fReporter->bumpTestCount();
    return result == 0;
}
Ejemplo n.º 11
0
bool testSimplify(const SkPath& path, bool fill, SkPath& out, SkBitmap& bitmap) {
    if (gShowPath) {
        showPath(path);
    }
    simplify(path, fill, out);
    if (!gComparePaths) {
        return true;
    }
    return comparePaths(path, out, bitmap) == 0;
}
Ejemplo n.º 12
0
static void showPathOpPath(const char* testName, const SkPath& one, const SkPath& two,
        const SkPath& a, const SkPath& b, const SkPath& scaledOne, const SkPath& scaledTwo,
        const SkPathOp shapeOp, const SkMatrix& scale) {
    SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs));
    SkString defaultTestName;
    if (!testName) {
        defaultTestName.printf("xOp%d%s", gTestNo, opSuffixes[shapeOp]);
        testName = defaultTestName.c_str();
    }
    SkDebugf("static void %s(skiatest::Reporter* reporter, const char* filename) {\n", testName);
    *gTestOp.append() = shapeOp;
    ++gTestNo;
    SkDebugf("\n*** this test fails ***\n");
    SkDebugf("    SkPath path, pathB;\n");
    showPath(a, "path", false);
    showPath(b, "pathB", false);
    SkDebugf("    testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[shapeOp]);
    SkDebugf("}\n");
    drawAsciiPaths(scaledOne, scaledTwo, true);
}
Ejemplo n.º 13
0
void MMapperPluginParser::mudOutput(const QString &text) {
  if (text.isEmpty()) return;

  if (text.startsWith('Y')) {
    qDebug() << "* MMapperPluginParser detected some text" << text;

    if (text.startsWith("You are dead!")) {
      queue.clear();
      emit showPath(queue, true);
      emit releaseAllPaths();
      return;
    }
    else if (text.startsWith("You failed to climb")) {
      if (!queue.isEmpty()) queue.dequeue();
      queue.prepend(CID_NONE);
      emit showPath(queue, true);
      return;
    }
    else if (text.startsWith("You are too exhausted.")) {
      if (!queue.isEmpty()) queue.dequeue();
      //queue.prepend(CID_NONE);
      emit showPath(queue, true);
      return;
    }
    /*
    else if (text.startsWith("You flee head")) {
      queue.enqueue(_move);
    }
    else if (text.startsWith("You follow")) {
      queue.enqueue(_move);
      return;
    }
    */
    else if (text.startsWith("You quietly scout")) {
      queue.prepend(CID_SCOUT);
      return;
    }
  }
}
Ejemplo n.º 14
0
    void showFour(SkCanvas* canvas, SkScalar scale, bool aa) {

        SkPaint paint;
        SkPoint center = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(100));
        SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
        SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
        SkShader* s = SkGradientShader::CreateRadial(center,
                                                     SkIntToScalar(100),
                                                     colors,
                                                     pos,
                                                     SK_ARRAY_COUNT(colors),
                                                     SkShader::kClamp_TileMode);
        paint.setShader(s)->unref();
        paint.setAntiAlias(aa);

        showPath(canvas,   0,   0, SkPath::kWinding_FillType,
                 scale, paint);
        showPath(canvas, 200,   0, SkPath::kEvenOdd_FillType,
                 scale, paint);
        showPath(canvas,  00, 200, SkPath::kInverseWinding_FillType,
                 scale, paint);
        showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
                 scale, paint);
    }
Ejemplo n.º 15
0
void showPath(Directory *currentDirectory)
{
  char* name2 = (char *)malloc(sizeof(char) * MAX_SUBDIRECTORIES);
  strcpy(name2, "/");

  if (strcmp(currentDirectory -> name, name2) == 0)//checks root
  {
    ;
  }// if(strcmp(currentDirectory -> name, name2) == 0)

  else //recurses
  {
    showPath(currentDirectory -> parentPointer); // path
    printf("/%s", currentDirectory -> name);
  }// else
}// void showPath(Directory *currentDirectory)
Ejemplo n.º 16
0
void showPath(Directory* directory_to_print)
{
  if (directory_to_print->parent_directory != NULL)
  {
    showPath(directory_to_print->parent_directory);
  }//end if

  if (directory_to_print->parent_directory == NULL)
  {
  	printf("%s", directory_to_print->pointer_to_name);
  	return;
  }//end if

  printf("%s/", directory_to_print->pointer_to_name);

  return;
}// end showPath
Ejemplo n.º 17
0
int main(){
	node nodes[5];
	path aPath;
	int counter1=0;
		for(; counter1<NO_OF_GRID_COLUMNS; counter1++)
			nodes[counter1] = createNode(counter1+15, counter1+15);

		aPath.nodes = nodes;
		aPath.length = 5;

	path newPath;
	node newnodes[100];
	newPath.nodes = newnodes;
	getDryRunPath(&newPath);
	
	showPath(newPath);
}
  // Creates a simple extrusion
  void showSimplePipe()
  {
    // Generates the actual extrusion
    vl::Extrusion extrusion;

    // Define the silhouette to be extruded: 24 sided circle
    const int sides = 24;
    const float radius = 1.0f;
    for(int i=0; i<sides; ++i)
    {
      float t = (float)i/sides*vl::fPi*2.0f;
      extrusion.silhouette().push_back(vl::fvec2(::cos(t)*radius, ::sin(t)*radius));
    }

    // Define the path along which the silhouette is extruded.
    // Note: the first and last control points are not part of the actual extrusion 
    // but are used to define the orientation of the first and start segment.
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0) + vl::fvec3(-1,0,0));
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0));
    extrusion.positionPath().push_back(vl::fvec3(-5, 5, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 5, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0) + vl::fvec3(+1,0,0));

    // Setup the extrusion options.
    extrusion.setSilhouetteMode(vl::SilhouetteClosed);
    extrusion.setSmooth(false);
    extrusion.setFillBottom(true); // start of the extrusion is closed
    extrusion.setFillTop(true);    // end of the extrusion is closed

    // Setup a simple white effect.
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_LIGHTING);
    effect->shader()->enable(vl::EN_DEPTH_TEST);

    // Generates the extrusion.
    vl::ref<vl::Geometry> geom = extrusion.extrude();
    sceneManager()->tree()->addActor( geom.get(), effect.get(), NULL );

    // Utility function that visualizes the extrusion path.
    showPath(extrusion.positionPath(),vl::red);
  }
Ejemplo n.º 19
0
void MumeXmlParser::move()
{
    m_descriptionReady = false;

    if (m_roomName == emptyString || // blindness
        Patterns::matchNoDescriptionPatterns(
            m_roomName)) { // non standard end of description parsed (fog, dark or so ...)
        m_roomName = nullString;
        m_dynamicRoomDesc = nullString;
        m_staticRoomDesc = nullString;
    }

    const auto emitEvent = [this]() {
        auto ev = ParseEvent::createEvent(m_move,
                                          m_roomName,
                                          m_dynamicRoomDesc,
                                          m_staticRoomDesc,
                                          m_exitsFlags,
                                          m_promptFlags,
                                          m_connectedRoomFlags);
        emit event(SigParseEvent{ev});
    };

    if (queue.isEmpty()) {
        emitEvent();
    } else {
        const CommandIdType c = queue.dequeue();
        // Ignore scouting unless it forced movement via a one-way
        if (c != CommandIdType::SCOUT
            || (c == CommandIdType::SCOUT && m_move != CommandIdType::LOOK)) {
            emit showPath(queue, false);
            emitEvent();
            if (c != m_move) {
                queue.clear();
            }
        }
    }
    m_move = CommandIdType::LOOK;
}
Ejemplo n.º 20
0
static void showSimplifiedPath(const SkPath& one, const SkPath& two,
        const SkPath& scaledOne, const SkPath& scaledTwo) {
    showPath(one, "original:");
    showPath(two, "simplified:");
    drawAsciiPaths(scaledOne, scaledTwo, true);
}
Ejemplo n.º 21
0
QByteArray MumeXmlParser::characters(QByteArray &ch)
{
    QByteArray toUser;

    if (ch.isEmpty()) {
        return toUser;
    }

    // replace > and < chars
    stripXmlEntities(ch);

    const auto &config = getConfig();
    m_stringBuffer = QString::fromLatin1(ch);

    if (m_readSnoopTag && m_stringBuffer.length() > 3 && m_stringBuffer.at(0) == '&'
        && m_stringBuffer.at(2) == ' ') {
        // Remove snoop prefix (i.e. "&J Exits: north.")
        m_stringBuffer = m_stringBuffer.mid(3);
    }

    switch (m_xmlMode) {
    case XmlMode::NONE: // non room info
        m_stringBuffer = normalizeStringCopy(m_stringBuffer.trimmed());
        if (m_stringBuffer.isEmpty()) { // standard end of description parsed
            if (m_readingRoomDesc) {
                m_readingRoomDesc = false; // we finished read desc mode
                m_descriptionReady = true;
                if (config.mumeNative.emulatedExits) {
                    emulateExits();
                }
            }
        } else {
            parseMudCommands(m_stringBuffer);
        }
        if (m_readSnoopTag) {
            if (m_descriptionReady) {
                m_promptFlags.reset(); // Don't trust god prompts
                queue.enqueue(m_move);
                emit showPath(queue, true);
                move();
                m_readSnoopTag = false;
            }
        }
        toUser.append(ch);
        break;

    case XmlMode::ROOM: // dynamic line
        m_dynamicRoomDesc += normalizeStringCopy(m_stringBuffer.simplified().append("\n"));
        toUser.append(ch);
        break;

    case XmlMode::NAME:
        if (m_descriptionReady) {
            move();
        }
        m_readingRoomDesc = true; // start of read desc mode
        m_roomName = normalizeStringCopy(m_stringBuffer);
        toUser.append(ch);
        break;

    case XmlMode::DESCRIPTION: // static line
        m_staticRoomDesc += normalizeStringCopy(m_stringBuffer.simplified().append("\n"));
        if (!m_gratuitous) {
            toUser.append(ch);
        }
        break;

    case XmlMode::EXITS:
        m_exits += m_stringBuffer;
        if (m_readingRoomDesc) {
            m_readingRoomDesc = false;
            m_descriptionReady = true;
        }
        break;

    case XmlMode::PROMPT:
        emit sendPromptLineEvent(normalizeStringCopy(m_stringBuffer).toLatin1());
        if (m_readingRoomDesc) {       // fixes compact mode
            m_readingRoomDesc = false; // we finished read desc mode
            m_descriptionReady = true;
            if (config.mumeNative.emulatedExits) {
                emulateExits();
            }
        }
        if (m_descriptionReady) {
            parsePrompt(normalizeStringCopy(m_stringBuffer));
            move();
        }

        toUser.append(ch);
        break;

    case XmlMode::TERRAIN:
    default:
        toUser.append(ch);
        break;
    }

    if (!getConfig().parser.removeXmlTags) {
        toUser.replace(ampersand, ampersandTemplate);
        toUser.replace(greaterThanChar, greaterThanTemplate);
        toUser.replace(lessThanChar, lessThanTemplate);
    }
    return toUser;
}
Ejemplo n.º 22
0
static bool drawStars(SkCanvas* canvas, int step)
{
    SkPath path, out;
    const int stars = 25;
    int pts[stars];
    static bool initialize = true;
    int s;
    for (s = 0; s < stars; ++s) {
        pts[s] = 4 + (s % 7);
    }
    SkPoint locs[stars];
    SkScalar angles[stars];
    SkScalar innerRadius[stars];
    SkScalar outerRadius[stars];
    const int width = 640;
    const int height = 480;
    const int margin = 30;
    const int minRadius = 120;
    const int maxInner = 800;
    const int maxOuter = 1153;
    for (s = 0; s < stars; ++s) {
        int starW = width - margin * 2 + (SkScalar) s * (stars - s) / stars;
        locs[s].fX = (int) (step * (1.3f * (s + 1) / stars) + s * 121) % (starW * 2);
        if (locs[s].fX > starW) {
            locs[s].fX = starW * 2 - locs[s].fX;
        }
        locs[s].fX += margin;
        int starH = height - margin * 2 + (SkScalar) s * s / stars;
        locs[s].fY = (int) (step * (1.7f * (s + 1) / stars) + s * 183) % (starH * 2);
        if (locs[s].fY > starH) {
            locs[s].fY = starH * 2 - locs[s].fY;
        }
        locs[s].fY += margin;
        angles[s] = ((step + s * 47) % (360 * 4)) * 3.1415f / 180 / 4;
        innerRadius[s] = (step + s * 30) % (maxInner * 2);
        if (innerRadius[s] > maxInner) {
            innerRadius[s] = (maxInner * 2) - innerRadius[s];
        }
        innerRadius[s] = innerRadius[s] / 4 + minRadius;
        outerRadius[s] = (step + s * 70) % (maxOuter * 2);
        if (outerRadius[s] > maxOuter) {
            outerRadius[s] = (maxOuter * 2) - outerRadius[s];
        }
        outerRadius[s] = outerRadius[s] / 4 + minRadius;
        createStar(path, innerRadius[s] / 4.0f, outerRadius[s] / 4.0f,
                angles[s], pts[s], locs[s]);
    }
#define SHOW_PATH 0
#if SHOW_PATH
    showPath(path, "original:");
#endif
#define TEST_SIMPLIFY 01
#if TEST_SIMPLIFY
    simplify(path, true, out);
#if SHOW_PATH
    showPath(out, "simplified:");
#endif
#endif
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(6);
    paint.setColor(0x1F003f7f);
    canvas->drawPath(path, paint);
    paint.setColor(0xFF305F00);
    paint.setStrokeWidth(1);
#if TEST_SIMPLIFY
    canvas->drawPath(out, paint);
#endif
    return true;
}
Ejemplo n.º 23
0
void MumeXmlParser::parseMudCommands(const QString &str)
{
    if (str.at(0) == ('Y')) {
        if (str.startsWith("You are dead!")) {
            queue.clear();
            emit showPath(queue, true);
            emit releaseAllPaths();
            markCurrentCommand();
            return;
        } else if (str.startsWith("You failed to climb")) {
            if (!queue.isEmpty())
                queue.dequeue();
            queue.prepend(CommandIdType::NONE); // REVISIT: Do we need this?
            emit showPath(queue, true);
            return;
        } else if (str.startsWith("You flee head")) {
            queue.enqueue(CommandIdType::LOOK);
            return;
        } else if (str.startsWith("You follow")) {
            queue.enqueue(CommandIdType::LOOK);
            return;
        } else if (str.startsWith("You need to swim to go there.")
                   || str.startsWith("You cannot ride there.")
                   || str.startsWith("You are too exhausted.")
                   || str.startsWith("You are too exhausted to ride.")
                   || str.startsWith("Your mount refuses to follow your orders!")
                   || str.startsWith("You failed swimming there.")
                   || str.startsWith("You can't go into deep water!")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
            return;
        } else if (str.startsWith("You quietly scout")) {
            queue.prepend(CommandIdType::SCOUT);
            return;
        }
    } else if (str.at(0) == 'T') {
        if (str.startsWith("The current time is")) {
            m_mumeClock->parseClockTime(str);
            // The door
        } else if (str.endsWith("seems to be closed.")
                   // The (a|de)scent
                   || str.endsWith("is too steep, you need to climb to go there.")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    } else if (str.at(0) == 'A') {
        if (str.startsWith("Alas, you cannot go that way...")
            // A pack horse
            || str.endsWith("is too exhausted.")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    } else if (str.at(0) == 'N') {
        if (str.startsWith("No way! You are fighting for your life!")
            || str.startsWith("Nah... You feel too relaxed to do that.")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    } else if (str.at(0) == 'M') {
        if (str.startsWith("Maybe you should get on your feet first?")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    } else if (str.at(0) == 'I') {
        if (str.startsWith("In your dreams, or what?")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    } else if (str.at(0) == 'Z') {
        // pack horse
        if (str.endsWith("doesn't want you riding him anymore.")
            // donkey
            || str.endsWith("doesn't want you riding her anymore.")
            // hungry warg
            || str.endsWith("doesn't want you riding it anymore.")) {
            if (!queue.isEmpty())
                queue.dequeue();
            emit showPath(queue, true);
        }
    }
    if (str.endsWith("of the Third Age.")) {
        m_mumeClock->parseMumeTime(str);
    }

    // Certain weather events happen on ticks
    if (m_readWeatherTag) {
        m_readWeatherTag = false;
        m_mumeClock->parseWeather(str);
    }
}
Ejemplo n.º 24
0
void PowerBar::initTouchThings()
{
    auto listener = EventListenerTouchOneByOne::create();
    static bool moved = false;
    static Vec2 startPos;
    static float angle, strenth;
    listener->onTouchBegan = [this](Touch* touch, Event* event){
        moved = false;
        startPos = touch->getLocation();
        if (_enable && !_huntingHerosManageProtocal->op_fetchIsHeadsBusy()) {
            auto size = Director::getInstance()->getWinSize();
            float yr = touch->getLocation().y / size.height;
            float xr = touch->getLocation().x / size.width;
            CCLOG("power touch radio %f %f", xr, yr);
            // ban 掉一些区域
            if (xr > 0.9 && yr >0.85) { //暂停
            } else if (yr < 0.19) { //机能区域
            } else if (yr > 0.85 && xr > 0.17 && xr < 0.65) { //头像区域
            } else {
                // TODO 告诉 heros 开始 aiming
                _huntingHerosManageProtocal->op_aimingStart();
//                op_show();
                auto p = touch->getLocation();
                auto r = _mainCamera->unproject(Vec3{p.x,p.y,0});
                r.x = 40;
                r.y = 10*r.y;
                r.z = 10*r.z;
                Vec3 rr;
                _mainCamera->getWorldToNodeTransform().transformVector(r, &rr);
                CCLOG("r %f %f %f", r.x, r.y, r.z);
                //这里获得的是一个在镜头截面上的值,根据镜头的近切面和我们需要坐标所在平面来换算。
                rr.z = -10;
                rr.y = 100-rr.y;
                

                CCLOG("rr %f %f %f", rr.x, rr.y, rr.z);
                _pxArrow->stopAllActions();
                _pxArrow->setPosition3D(rr);
//                _pxArrow->setVisible(true);
                _pxArrow->setScale(0);
                return true;
            }
        }
        return false;
    };

    listener->onTouchMoved = [this](Touch* touch, Event* event){
        moved = true;
        auto diff = (touch->getStartLocation() - touch->getLocation());
        angle = vector2angel(diff);
        if (angle>180) {
            angle = angle-360;
        }
        auto size = Director::getInstance()->getWinSize();
        strenth =  diff.length() / (size.height*0.35);
        _pxArrow->setScale(strenth*0.1);
        _pxArrow->setRotation3D({0,0,-(angle-45)});
        //TODO 告诉 heros
        strenth = std::min(1.f, strenth);
        _huntingHerosManageProtocal->op_configAiming(angle, strenth);
//        this->op_configPower(strenth, angle);
        showPath(angle, strenth);
    };

    listener->onTouchEnded = [this](Touch* touch, Event* event){
        op_dismiss();
        _pxArrow->runAction(Sequence::create(ScaleTo::create(0.2, 0), Hide::create(), NULL));
        _huntingHerosManageProtocal->op_toastBow(angle, strenth);
        this->hidePath();
    };

    listener->onTouchCancelled = [this](Touch* touch, Event* event){
    };

    _mainLayer->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, _mainLayer);

}
Ejemplo n.º 25
0
void Parser::parseNewMudInput(IncomingData& data /*TelnetIncomingDataQueue& que*/)
{
	bool staticLine = false;
	bool dontSendToUser = false;
	/*IncomingData data; 	
	bool staticLine;
	
	while ( !que.isEmpty() )
	{
		data = que.dequeue();
*/
		
		//dline = (quint8 *)data.line.data();
		switch (data.type)
		{
			case TDT_DELAY:
			case TDT_MENU_PROMPT: 
			case TDT_LOGIN: 
			case TDT_LOGIN_PASSWORD: 
			case TDT_TELNET:
			case TDT_SPLIT:
			case TDT_UNKNOWN:			
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***STYPE***";
		(*debugStream) << "Other";
		(*debugStream) << "***ETYPE***";
#endif
				emit sendToUser(data.line);
				break;			

			case TDT_PROMPT:
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***STYPE***";
		(*debugStream) << "Prompt";
		(*debugStream) << "***ETYPE***";
#endif
				m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size());
				m_stringBuffer = m_stringBuffer.simplified();
				latinToAscii(m_stringBuffer);
				
				if (m_readingRoomDesc)
				{
					m_readingRoomDesc = false; // we finished read desc mode
					m_descriptionReady = true;
					if (m_examine) m_examine = false; // stop showing bypassing brief-mode
				}
				
				if	(m_descriptionReady)
				{			
					m_descriptionReady = false;

					parsePrompt(m_stringBuffer);

					if (!queue.isEmpty())
					{
						CommandIdType c = queue.dequeue();
						if ( c != CID_SCOUT ){
							//qDebug("%s",m_roomName.toAscii().data());
							//qDebug("%s",m_dynamicRoomDesc.toAscii().data());
							emit showPath(queue, false);
							characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
						}
						//additional scout move needs to be removed when scout was successful
						else queue.dequeue();
					}
					else
					{	
						//qDebug("%s",m_roomName.toAscii().data());
						//qDebug("%s",m_dynamicRoomDesc.toAscii().data());
						emit showPath(queue, false);
						characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
					}    
				}
				
				emit sendToUser(data.line);				
				break;

			case TDT_CRLF:
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***STYPE***";
		(*debugStream) << "CRLF";
		(*debugStream) << "***ETYPE***";
#endif			
				if (data.line.contains("null)>")) break;								

				m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size());
				m_stringBuffer = m_stringBuffer.simplified();
				latinToAscii(m_stringBuffer);
								
				if (m_readingRoomDesc) 
				{					
					if (isEndOfRoomDescription(m_stringBuffer)) // standard end of description parsed
					{  
						m_readingRoomDesc = false; // we finished read desc mode
						m_descriptionReady = true;
						dontSendToUser = true;
					}
					else 
					if (m_stringBuffer.isEmpty())  // standard end of description parsed
					{  
						m_readingRoomDesc = false; // we finished read desc mode
						m_descriptionReady = true;
						if (Config().m_emulatedExits)
							emulateExits();
					} 
					else // reading room description line 
					{ 
						
						switch(Config().m_roomDescriptionsParserType)
						{
						case Configuration::RDPT_COLOR:
							if ((m_readingStaticDescLines == true) && isStaticRoomDescriptionLine(m_stringBuffer))
							{	
								staticLine = true;
								m_staticRoomDesc += m_stringBuffer+"\n";
							}
							else
							{							
								m_readingStaticDescLines = false;
								m_dynamicRoomDesc += m_stringBuffer+"\n";
							}								
							m_roomDescLines++;														
							break;	
							
						case Configuration::RDPT_PARSER:
							if ((m_roomDescLines >= Config().m_minimumStaticLines) && 
								((m_readingStaticDescLines == false) || 
								Patterns::matchDynamicDescriptionPatterns(m_stringBuffer)))
							{
								m_readingStaticDescLines = false;						
								m_dynamicRoomDesc += m_stringBuffer+"\n";
							}
							else
							{
								staticLine = true;
								m_staticRoomDesc += m_stringBuffer+"\n";								
							}
							m_roomDescLines++;							
							break;	
							
						case Configuration::RDPT_LINEBREAK:
							m_dynamicRoomDesc += m_stringBuffer+"\n";
							m_roomDescLines++;														
							break;								
						}						
						
						
					}
				} 
				else 
				if (!m_readingRoomDesc && m_descriptionReady) //read betwen Exits and Prompt (track for example)
				{
					if ( isRoomName(m_stringBuffer) ) //Room name arrived
					{ 
						
						
						if	(m_descriptionReady)
						{			
							m_descriptionReady = false;
		
							if (!queue.isEmpty())
							{
								CommandIdType c = queue.dequeue();
								if ( c != CID_SCOUT ){
									emit showPath(queue, false);
									characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
								}
								//additional scout move needs to be removed when scout was successful
								else queue.dequeue();
							}
							else
							{	
								emit showPath(queue, false);
								characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
							}    
						}					
						
						
						m_readingRoomDesc = true; //start of read desc mode
						m_descriptionReady = false;										
						m_roomName=m_stringBuffer;
						m_dynamicRoomDesc=nullString;
						m_staticRoomDesc=nullString;
						m_roomDescLines = 0;
						m_readingStaticDescLines = true;
						m_exitsFlags = 0;
					} 
					else
					if (!m_stringBuffer.isEmpty()) parseMudCommands(m_stringBuffer);					
						  
				} 
				else 
				if ( isRoomName(m_stringBuffer) ) //Room name arrived
				{ 
					
					
					if	(m_descriptionReady)
					{			
						m_descriptionReady = false;
	
						if (!queue.isEmpty())
						{
							CommandIdType c = queue.dequeue();
							if ( c != CID_SCOUT ){
								emit showPath(queue, false);
								characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
							}
							//additional scout move needs to be removed when scout was successful
							else queue.dequeue();
						}
						else
						{	
							emit showPath(queue, false);
							characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags);
						}    
					}					
					
					
					m_readingRoomDesc = true; //start of read desc mode
					m_descriptionReady = false;										
					m_roomName=m_stringBuffer;
					m_dynamicRoomDesc=nullString;
					m_staticRoomDesc=nullString;
					m_roomDescLines = 0;
					m_readingStaticDescLines = true;
					m_exitsFlags = 0;
				} 
				else 
				if (!m_stringBuffer.isEmpty() && Patterns::matchNoDescriptionPatterns(m_stringBuffer)) // non standard end of description parsed (fog, dark or so ...)
				{ 
					m_readingRoomDesc = false; // we finished read desc mode
					m_descriptionReady = true;
					m_roomName=nullString;
					m_dynamicRoomDesc=nullString;
					m_staticRoomDesc=nullString;
					m_roomDescLines = 0;
					m_readingStaticDescLines = false;
					m_exitsFlags = 0;
					m_promptFlags = 0;
				} 
				else // parse standard input (answers) from server
				{ 
					//str=removeAnsiMarks(m_stringBuffer);
					if (!m_stringBuffer.isEmpty()) parseMudCommands(m_stringBuffer);
				}
										
				if (!dontSendToUser && !(staticLine && (m_examine || Config().m_brief))) emit sendToUser(data.line);
				break;

			case TDT_LFCR: 
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***STYPE***";
		(*debugStream) << "LFCR";
		(*debugStream) << "***ETYPE***";
#endif			
				m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size());
				m_stringBuffer = m_stringBuffer.simplified();
				latinToAscii(m_stringBuffer);


				if (m_readingRoomDesc && (Config().m_roomDescriptionsParserType == Configuration::RDPT_LINEBREAK) )
				{
					staticLine = true;
					m_staticRoomDesc += m_stringBuffer+"\n";
					m_roomDescLines++;
				}
				if (!(staticLine && (m_examine || Config().m_brief))) emit sendToUser(data.line);
				break;

			case TDT_LF:
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***STYPE***";
		(*debugStream) << "LF";
		(*debugStream) << "***ETYPE***";
#endif			
				m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size());
				emit sendToUser(data.line);
				break;			
		}
		
#ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE
		(*debugStream) << "***S***";
		(*debugStream) << data.line;
		(*debugStream) << "***E***";
#endif
		
	//}
		
}
Ejemplo n.º 26
0
void Parser::parseMudCommands(QString& str) {

	/*if (str.startsWith('B') && str.startsWith("Brief mode on")){
		emit sendToMud((QByteArray)"brief\n");
	}*/
	
	if (str.startsWith('<') && str.startsWith("<xml>")) //we are in xml mode
	{	emit setXmlMode();
		emit sendToUser((QByteArray)"[MMapper] Mode ---> XML\n");
		emptyQueue();
	}

	if (str.startsWith('Y'))
	{
		if (str.startsWith("You are dead!"))
		{
			queue.clear();
			emit showPath(queue, true);			
			emit releaseAllPaths();
			return;
		}
	
		if (str.startsWith("You flee"))
		{
			if (str.contains("north")) queue.enqueue(CID_NORTH);
			else
			if (str.contains("south")) queue.enqueue(CID_SOUTH);
			else
			if (str.contains("east"))  queue.enqueue(CID_EAST);
			else
			if (str.contains("west"))  queue.enqueue(CID_WEST);
			else
			if (str.contains("up"))    queue.enqueue(CID_UP);  
			else
			if (str.contains("down"))  queue.enqueue(CID_DOWN);
			return;
		}

		if (str.startsWith("You now follow")){
			m_following = true;   
			emit sendToUser((QByteArray)"----> follow mode on.\n");
			return;
		}
		else if (str.startsWith("You quietly scout"))
    		{
      			queue.prepend(CID_SCOUT);
      			return;
    		}
		if (m_following) {
			if (str=="You will not follow anyone else now.")
			{
				m_following = false;   
				emit sendToUser((QByteArray)"----> follow mode off.\n");
				return;
			}
			if (str.startsWith("You follow"))
			{
				switch (m_followDir) {
				  case NORTH:   queue.enqueue(CID_NORTH);break;     
				  case SOUTH:   queue.enqueue(CID_SOUTH);break;     
				  case EAST:    queue.enqueue(CID_EAST);break;     
				  case WEST:    queue.enqueue(CID_WEST);break;     
				  case UP:      queue.enqueue(CID_UP);break;     
				  case DOWN:    queue.enqueue(CID_DOWN);break;     				  
				  case UNKNOWN: queue.enqueue(CID_NONE);break;     
				}
				return;
			}
		}			
	}

	if (m_following) {
		if(str.contains("leave"))
		{		
			if ((str.contains("leaves north")) || (str.contains("leave north"))) m_followDir = NORTH;
			else
			if ((str.contains("leaves south")) || (str.contains("leave south"))) m_followDir = SOUTH;
			else
			if ((str.contains("leaves east"))  || (str.contains("leave east")))  m_followDir = EAST;
			else
			if ((str.contains("leaves west"))  || (str.contains("leave west")))  m_followDir = WEST;
			else
			if ((str.contains("leaves up"))    || (str.contains("leave up")))    m_followDir = UP;  
			else
			if ((str.contains("leaves down"))  || (str.contains("leave down")))  m_followDir = DOWN;
		}
	}

	// parse regexps which cancel last char move
	if (Patterns::matchMoveCancelPatterns(str))
	{
		if(!queue.isEmpty()) queue.dequeue(); 
		emit showPath(queue, true);
		return;   
	}

	// parse regexps which force new char move
	if (Patterns::matchMoveForcePatterns(str))
	{
		queue.enqueue(CID_NONE);
		emit showPath(queue, true);
		return;   
	}	
}
  // Creates a fancy arch applying rotation and scaling to the extrusion
  void showFancyArch()
  {
    // Generates the actual extrusion
    vl::Extrusion extrusion;

    // Define the silhouette to be extruded (a quad).
    const int sides = 4;
    const float radius = 1.0f;
    for(int i=0; i<sides; ++i)
    {
      float t = (float)i/sides*vl::fPi*2.0f;
      extrusion.silhouette().push_back(vl::fvec2(::cos(t)*radius, ::sin(t)*radius));
    }

    // Define the path along which the silhouette is extruded.
    // Note: the first and last control points are not part of the actual extrusion 
    // but are used to define the orientation of the first and start segment.
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0) + vl::fvec3(0,-1,0));
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0));
    for(int j=0; j<640; ++j)
    {
      float t = (float)j/(640-1)*vl::fPi;
      extrusion.positionPath().push_back(vl::fvec3(-cos(t)*5, sin(t)*5, 0) + vl::fvec3(0,5,0));
    }
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0) + vl::fvec3(0,-1,0));

    // Defines a rotation key (in degrees) for each segment generated in order
    // to rotate the silhouette along the extrusion path.
    // Note that the segments generated are extrusion.positionPath().size()-2 as
    // the first and last control points are not part of the actual extrusion 
    // but are used to define the orientation of the first and start segment.
    for(unsigned i=0; i<extrusion.positionPath().size()-2; ++i)
    {
      float t = (float)i/(extrusion.positionPath().size()-2-1);
      // rotate of 360*2 degrees (turns around twice)
      extrusion.rotationPath().push_back(t*360.0f*2.0f);
    }

    // Defines a scaling key (in degrees) for each segment generated in order
    // to rotate the silhouette along the extrusion path.
    // Note that the segments generated are extrusion.positionPath().size()-2 as
    // the first and last control points are not part of the actual extrusion 
    // but are used to define the orientation of the first and start segment.
    for(unsigned i=0; i<extrusion.positionPath().size()-2; ++i)
    {
      float t = (float)i/(extrusion.positionPath().size()-2-1);
      // make it smaller in the middle
      float s = 1.0f - ::sin( t*vl::fPi )*0.8f;
      extrusion.scalingPath().push_back(s);
    }

    // Setup the extrusion options.
    extrusion.setSilhouetteMode(vl::SilhouetteClosed);
    extrusion.setSmooth(false);
    extrusion.setFillBottom(false); // start of the extrusion is closed
    extrusion.setFillTop(false);    // end of the extrusion is closed

    // Setup a simple white effect.
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_LIGHTING);
    effect->shader()->enable(vl::EN_DEPTH_TEST);

    // Generates the extrusion.
    vl::ref<vl::Geometry> geom = extrusion.extrude();
    sceneManager()->tree()->addActor( geom.get(), effect.get(), NULL );

    // Utility function that visualizes the extrusion path.
    showPath(extrusion.positionPath(),vl::red);
  }
static void showSimplifiedPath(const SkPath& one, const SkPath& two,
        const SkPath& scaledOne, const SkPath& scaledTwo) {
    showPath(one, "path", false);
    drawAsciiPaths(scaledOne, scaledTwo, true);
}