Пример #1
0
Array<T>::Array(const Array<T>& parent, const dim4 &dims, const dim4 &offsets, const dim4 &strides) :
    ArrayInfo(parent.getDevId(), dims, offsets, strides, (af_dtype)dtype_traits<T>::af_type),
    data(parent.getData()), data_dims(parent.getDataDims()),
    node(), ready(true),
    offset(parent.getOffset() + calcOffset(parent.strides(), offsets)),
    owner(false)
{ }
Пример #2
0
 EPP_GLOBAL void calcOffsetAll(
   SliceIndex *minmax,
   unsigned int *current_top
 ) {
   unsigned int self = getLinearIndex();
   calcOffset( minmax, self, current_top );
 }
Пример #3
0
void meshStrokeBezier3(vg::geometry_t* geom, uint16_t prevIdx, uint16_t curIdx, const glm::vec2& cp0, const glm::vec2&  cp1, const glm::vec2& cp2, const glm::vec2& cp3)
{
    glm::vec3   klmT[4*2];
    int         count, countT;
    float       subdPts[2], subdPtsT[2];

    glm::vec2 cps[8] = {cp0, cp1, cp2, cp3};
    bezier3MakeImplicit(cps, klmT, countT, subdPtsT);
    bezier3SpecialPts(cps, count, subdPts);
    assert(count==countT);
    if (count>0) assert(ml::equalE(subdPts[0], subdPtsT[0]));
    if (count>1) assert(ml::equalE(subdPts[1], subdPtsT[1]));

    if (count>1)
    {
        orderAscend(subdPts[0], subdPts[1]);
    }

    for(int i=0; i<count; ++i)
    {
        float t = i==0?subdPts[i]:(subdPts[i]-subdPts[i-1])/(1-subdPts[i-1]);

        cubic::subdivide(cps, t, cps+4, cps);
        meshStrokeSubdivideBezier3(geom, prevIdx, curIdx, cps[4], cps[5], cps[6], cps[7]);
        glm::vec2 n = calcOffset(cps[4], cps[5]);
    }

    meshStrokeSubdivideBezier3(geom, prevIdx, curIdx, cps[0], cps[1], cps[2], cps[3]);
}
Пример #4
0
void CGarminStrTbl8::get(QFileExt& file, quint32 offset, type_e t, QStringList& info)
{
    info.clear();
    offset = calcOffset(file, offset, t);

    if(offset == 0xFFFFFFFF) return;

    if(offset > (quint32)sizeLBL1)
    {
        //qWarning() << "Index into string table to large" << hex << offset << dataLBL.size() << hdrLbl->addr_shift << hdrNet->net1_addr_shift;
        return;
    }

    QByteArray data;
    quint32 size = (sizeLBL1 - offset) < 200 ? (sizeLBL1 - offset) : 200;
    readFile(file, offsetLBL1 + offset, size, data);
    char * lbl = data.data();

    char * pBuffer = buffer; *pBuffer = 0;
    while(*lbl != 0)
    {
        if((unsigned)*lbl >= 0x1B && (unsigned)*lbl <= 0x1F)
        {
            *pBuffer = 0;
            if(strlen(buffer))
            {
                if (codepage != 0)
                {
                    info << codec->toUnicode(buffer);
                }
                else
                {
                    info << buffer;
                }
                pBuffer = buffer; *pBuffer = 0;
            }
            ++lbl;
            continue;
        }
        else if((unsigned)*lbl < 0x07)
        {
            ++lbl;
            continue;
        }
        else
        {
            *pBuffer++ = *lbl++;
        }
    }

    *pBuffer = 0;
    if(strlen(buffer))
    {
        if (codepage != 0)
            info << codec->toUnicode(buffer);
        else
            info << buffer;
    }
}
Пример #5
0
//TODOD: Move subdivision logic into main func, and stroke creation logic for single curve retain here 
void meshStrokeSubdivideBezier3(vg::geometry_t* geom, uint16_t prevIdx, uint16_t curIdx, const glm::vec2& cp0, const glm::vec2&  cp1, const glm::vec2& cp2, const glm::vec2& cp3)
{
    glm::vec2 cps[8] = {cp0, cp1, cp2, cp3};
    float l0 = glm::length(cp3-cp0), l1=glm::length(cp1-cp0), l2=glm::length(cp2-cp1), l3=glm::length(cp3-cp2), l=l1+l2+l3;
    int maxCount = 4;
    float k = glm::clamp(1.0f-l0/l, 0.0f, 1.0f);
    int count = (int)floor(4*k+0.5);//add dependency on half width!!!!
    for(int i=0; i<count-1; ++i)
    {
        float t = 1.0f/(count-(float)i);//add dependency on l1, l2, l3

        cubic::subdivide(cps, t, cps+4, cps);
        glm::vec2 n0 = calcOffset(cps[4], cps[5]);
        glm::vec2 n1 = calcOffset(cps[4], cps[5], cps[6]);
        glm::vec2 n2 = calcOffset(cps[5], cps[6], cps[7]);
        glm::vec2 n3 = calcOffset(cps[6], cps[7]);
        glm::vec2 p0pos = cps[4]+n0*hw;
        glm::vec2 p1pos = cps[5]+n1*hw;
        glm::vec2 p2pos = cps[6]+n2*hw;
        glm::vec2 p3pos = cps[7]+n3*hw;
        glm::vec2 p0neg = cps[4]-n0*hw;
        glm::vec2 p1neg = cps[5]-n1*hw;
        glm::vec2 p2neg = cps[6]-n2*hw;
        glm::vec2 p3neg = cps[7]-n3*hw;
        uint16_t i0 = vg::geomAddVertex(geom, *(ml::vec2*)&p0pos);
        uint16_t i1 = vg::geomAddVertex(geom, *(ml::vec2*)&p0neg);
        uint16_t i2 = vg::geomAddVertex(geom, *(ml::vec2*)&p3pos);
        uint16_t i3 = vg::geomAddVertex(geom, *(ml::vec2*)&p3neg);
        meshAddBezier3(geom, i0, i2, p0pos, p1pos, p2pos, p3pos);
        meshAddBezier3(geom, i3, i1, p3neg, p2neg, p1neg, p0neg);
        vg::geomAddTri(geom, i0, i2, i1);
        vg::geomAddTri(geom, i1, i2, i3);
    }
    glm::vec2 n0 = calcOffset(cps[0], cps[1]);
    glm::vec2 n1 = calcOffset(cps[0], cps[1], cps[2]);
    glm::vec2 n2 = calcOffset(cps[1], cps[2], cps[3]);
    glm::vec2 n3 = calcOffset(cps[2], cps[3]);
    glm::vec2 p0pos = cps[0]+n0*hw;
    glm::vec2 p1pos = cps[1]+n1*hw;
    glm::vec2 p2pos = cps[2]+n2*hw;
    glm::vec2 p3pos = cps[3]+n3*hw;
    glm::vec2 p0neg = cps[0]-n0*hw;
    glm::vec2 p1neg = cps[1]-n1*hw;
    glm::vec2 p2neg = cps[2]-n2*hw;
    glm::vec2 p3neg = cps[3]-n3*hw;
    uint16_t i0 = vg::geomAddVertex(geom, *(ml::vec2*)&p0pos);
    uint16_t i1 = vg::geomAddVertex(geom, *(ml::vec2*)&p0neg);
    uint16_t i2 = vg::geomAddVertex(geom, *(ml::vec2*)&p3pos);
    uint16_t i3 = vg::geomAddVertex(geom, *(ml::vec2*)&p3neg);
    meshAddBezier3(geom, i0, i2, p0pos, p1pos, p2pos, p3pos);
    meshAddBezier3(geom, i3, i1, p3neg, p2neg, p1neg, p0neg);
    vg::geomAddTri(geom, i0, i2, i1);
    vg::geomAddTri(geom, i1, i2, i3);
}
Пример #6
0
void CGarminStrTbl6::get(QFileExt& file, quint32 offset, type_e t, QStringList& labels)
{
    labels.clear();

    offset = calcOffset(file, offset,t);

    if(offset == 0xFFFFFFFF) return;

    if(offset > (quint32)sizeLBL1)
    {
        //         qWarning() << "Index into string table to large" << hex << offset << dataLBL.size() << hdrLbl->addr_shift << hdrNet->net1_addr_shift;
        return;
    }

    quint8  c1  = 0;
    quint8  c2  = 0;
    quint32 idx = 0;
    reg         = 0;
    bits        = 0;

    QByteArray data;
    quint32 size = (sizeLBL1 - offset) < 200 ? (sizeLBL1 - offset) : 200;

    readFile(file, offsetLBL1 + offset, size, data);

    p = (quint8*)data.data();

    fill();
    while(idx < sizeof(buffer))
    {
        c1 = reg >> 26;
        reg <<= 6;
        bits -= 6;
        fill();
        //terminator
        if(c1 > 0x2F) break;

        c2 = str6tbl1[c1];
        if(c2 == 0)
        {
            if(c1 == 0x1C)
            {
                c1 = reg >> 26;
                reg <<= 6;
                bits -= 6;
                fill();
                buffer[idx++] = str6tbl2[c1];
            }
            else if(c1 == 0x1B)
            {
                c1 = reg >> 26;
                reg <<= 6;
                bits -= 6;
                fill();
                buffer[idx++] = str6tbl3[c1];
            }
Пример #7
0
CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= Colors::WHITE*/)
: CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "")
{
	init();
	bg = BG;
	addChild(bg);
	pos = bg->pos;
	calcOffset();
    textLock = false;
}
Пример #8
0
void ClientEntity::renderOverlays(IFrontend *frontend, Layer layer, int scale, float zoom, int offsetX, int offsetY, int posX, int posY) const {
	int offsetPosX, offsetPosY;
	calcOffset(scale, zoom, posX, posY, offsetPosX, offsetPosY);
	for (EntityOverlaysConstIter i = _entityOverlays.begin(); i != _entityOverlays.end(); ++i) {
		const SpritePtr& overlay = *i;
		Log::info(LOG_CLIENT, "render %s, layer %i, x: %i, y: %i, zoom: %f, angle: %i, alpha: %f",
				overlay->getName().c_str(), layer, offsetX + offsetPosX, offsetY + offsetPosY, zoom, _angle, _alpha);
		overlay->render(frontend, layer, offsetX + offsetPosX, offsetY + offsetPosY, zoom, _angle, _alpha);
	}
}
Пример #9
0
uint32_t handleBranch(Assembler *assembler, char **tokens) {
    CondCodes cond = mnemToCondCode(&tokens[0][1]);
    uint32_t address = isalpha(tokens[1][0]) ?
                       //address starts with a char so is a label
                       getLabelAddress(assembler, tokens[1]) :
                       //else it's a numeric value
                       getValue(tokens[1]);
    uint32_t offset = calcOffset(assembler, address, true);

    return genBranch(cond, offset);
}
Пример #10
0
/*-----------------------------------------------------------------------------
 *  Function: initBenchmark
 *  Parameters: Benchmark*  - Benchmark to be initialized
 *
 *  Description:
 *    Initializes the benchmark to default values.
 *-----------------------------------------------------------------------------*/
void initBenchmark(Benchmark *pB, const char *name, const char *desc)
{
  pB->name = name;
  pB->descript = desc;
  pB->t_start.tv_sec = 0;
  pB->t_start.tv_nsec = 0;
  pB->t_stop.tv_sec = 0;
  pB->t_stop.tv_nsec = 0;

  calcOffset(pB);
}
	// ----------------------------------------------------------------------
	DIPostscriptWriter::
		DIPostscriptWriter(std::ostream& psfile, SimulationController& sc) : psfile_(psfile), pageNo_(1), eps_(false)
	{

//		eps ? eps_header() : ps_header();
		ps_header();
		calcOffset(sc.world());
		//newpage();
		setlinewidth2(0.1);


	}
Пример #12
0
CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int maxw/*=-1*/)
: CLabel(x, y, FONT_SMALL, CENTER)
{
	OBJ_CONSTRUCTION_CAPTURING_ALL;
	init();
	bg = new CPicture(name);
	pos = bg->pos;
	if((unsigned int)maxw < pos.w)
	{
		vstd::amin(pos.w, maxw);
		bg->srcRect = new Rect(0, 0, maxw, pos.h);
	}
	calcOffset();
    textLock = false;
}
Пример #13
0
uint32_t handleSDT(Assembler *assembler, char **tokens) {
    //set fields to default.
    bool load = equalStrings(tokens[0], "ldr");
    int Rd = getValue(tokens[1]);
    bool immediate = false;
    bool preIndexing = true;
    bool up = true;
    int Rn = 0xF;
    int offset = 0;

    if (tokens[2][0] == '=') {  //numeric constant
        immediate = false;
        uint32_t constant = getValue(tokens[2]);
        if (constant <= MAX_MOV_CONSTANT) {
            tokens[0] = "mov";
            tokens[2][0] = '#';
            return handleDataProcessing(assembler, tokens);
        } else {
            assembler->binaryProgram[(assembler->firstEmptyAddr) / INSTR_LENGTH]
                    = constant;
            offset = calcOffset(assembler,
                                (unsigned int) assembler->firstEmptyAddr, false);
            assembler->firstEmptyAddr += INSTR_LENGTH;
        }

    } else {
        preIndexing = (tokens[2][3] != ']' && tokens[2][4] != ']')
                        || tokens[3] == NULL;
        Rn = getValue(&tokens[2][1]);
        if (tokens[3] != NULL) {
            if (tokens[3][1] == '-') {
                up = false;

                //change negative at start of Rm to #
                tokens[3][1] = '#';

                //make token 3 start at last #
                tokens[3] = &tokens[3][1];
            }
            // offset is handled similarly to operand2, but with immediate
            // negated after
            offset = handleOperand2(&tokens[3], &immediate);
            immediate = !immediate;
        }
    }

    return genSDT(immediate, preIndexing, up, load, Rn, Rd, offset);
}
Пример #14
0
int putchar(int character) {
    switch (character) {
        case '\r': x = 0; break;
        case '\n': {
            x = 0;
            y++;
            if (y == LINE_PER_SCREEN) {
                lineWrap();
                y--;
            }
            break;
        }
        case '\t': {
            x = (x + 4) / 4 * 4;
            if (x == CHAR_PER_LINE) {
                x = 0;
                y++;
            }
            if (y == LINE_PER_SCREEN) {
                lineWrap();
                y--;
            }
            break;
        }
        case '\f': {
            memset((void *)VIDEO_ADDRESS, 0, CHAR_PER_LINE * LINE_PER_SCREEN * 2);
            x = y = 0;
            break;
        }
        default: {
            *(uint16_t *)(VIDEO_ADDRESS + calcOffset(x, y)) = character | (0xF << 8);
            x++;
            if (x == CHAR_PER_LINE) {
                x = 0;
                y++;
            }
            if (y == LINE_PER_SCREEN) {
                lineWrap();
                y--;
            }
            break;
        }
    }
    return character;
}
Пример #15
0
// Return the crc32 info for this rom. (ripped mostly from the old neshandler.cpp source)
QString crcinfo(QString romname, QString GameType, QString *key, RomDBMap *romDB)
{
    // Get CRC of file
    char block[32768] = "";
    uLong crc = crc32(0, Z_NULL, 0);
    QString crcRes;
    char filename_inzip[256];
    unz_file_info file_info;
    int offset;
    unzFile zf;
    int blocksize;

    blocksize = 8192;
#if 0
    LOG(VB_GENERAL, LOG_DEBUG,
        QString("crcinfo : %1 : %2 :").arg(romname).arg(GameType));
#endif

    if ((zf = unzOpen(qPrintable(romname))))
    {
        int FoundFile;
        for (FoundFile = unzGoToFirstFile(zf); FoundFile == UNZ_OK;
             FoundFile = unzGoToNextFile(zf))
        {
            if (unzOpenCurrentFile(zf) == UNZ_OK)
            {
                unzGetCurrentFileInfo(zf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);

                offset = calcOffset(GameType, file_info.uncompressed_size);

                if (offset > 0)
                    unzReadCurrentFile(zf, block, offset);

                // Get CRC of rom data
                int count;
                while ((count = unzReadCurrentFile(zf, block, blocksize)) > 0)
                {
                    crc = crc32(crc, (Bytef *)block, (uInt)count);
                }
                crcRes = crcStr(crc);
                *key = QString("%1:%2")
                             .arg(crcRes)
                             .arg(filename_inzip);

                if (romDB->contains(*key))
                {
                    unzCloseCurrentFile(zf);
                    break;
                }

                unzCloseCurrentFile(zf);
            }
        }
        unzClose(zf);
    }
    else
    {
        QFile f(romname);

        if (f.open(QIODevice::ReadOnly))
        {
            offset = calcOffset(GameType, f.size());

            if (offset > 0)
                f.read(block, offset);

            // Get CRC of rom data
            qint64 count;
            while ((count = f.read(block, blocksize)) > 0)
            {
                crc = crc32(crc, (Bytef *)block, (uInt)count);
            }

            crcRes = crcStr(crc);
            *key = QString("%1:").arg(crcRes);
            f.close();
        }
    }

    return crcRes;
}
Пример #16
0
    void printMetaObject(std::ostream &stream, const qi::MetaObject &mobj, bool color, bool showHidden, bool showDoc, bool raw, bool parseable) {
      qi::MetaObject::MethodMap   methods = mobj.methodMap();
      qi::MetaObject::SignalMap   events = mobj.signalMap();
      qi::MetaObject::PropertyMap props = mobj.propertyMap();

      filterHiddenInPlace(methods, showHidden);
      filterHiddenInPlace(events, showHidden);
      filterHiddenInPlace(props, showHidden);

      int offsetProps = std::min(calcOffset(props), 30);
      int offsetSigs  = std::min(calcOffset(events), 30);
      int offsetMeth  = std::min(calcOffset(methods), 30);

      //##### Methods
      if (parseable)
      {
        stream << ":";
      }
      else if (methods.size())
      {
        printCat(stream, color, "Methods");
      }
      std::string comma = "";
      for (const auto& method: methods) {
        if (parseable)
        {
          stream << comma << method.second.name();
          comma = ",";
          continue;
        }
        printIdName(stream, color, offsetMeth, method.second.uid(), method.second.name());
        if (raw)
          stream << " " << FC(StreamColor_Blue, color) << method.second.returnSignature().toString() << FC(StreamColor_Reset, color)
                 << " " << FC(StreamColor_Yellow, color) << method.second.parametersSignature().toString() << FC(StreamColor_Reset, color)
                 << std::endl;
        else
          stream << " " << FC(StreamColor_Blue, color) << method.second.returnSignature().toPrettySignature() << FC(StreamColor_Reset, color)
                 << " " << FC(StreamColor_Yellow, color) << method.second.parametersSignature().toPrettySignature() << FC(StreamColor_Reset, color)
                 << std::endl;
        if (!showDoc)
          continue;
        if (method.second.description() != "")
          stream << "       " << FC(StreamColor_DarkGreen, color) << method.second.description() << FC(StreamColor_Reset, color) << std::endl;

        for (const auto& mmp: method.second.parameters()) {
          stream << "       " << FC(StreamColor_Brown, color) << mmp.name() << ": "
                 << FC(StreamColor_DarkGreen, color) << mmp.description() << FC(StreamColor_Reset, color)
                 << std::endl;
        }

        if (method.second.returnDescription() != "")
          stream << FC(StreamColor_Brown, color) << "       return: " << FC(StreamColor_DarkGreen, color) << method.second.returnDescription() << FC(StreamColor_Reset, color)
                 << std::endl;
      }

      if (parseable)
      {
        stream << ":";
        comma = "";
      }
      else if (events.size())
      {
        printCat(stream, color, "Signals");
      }
      for (const auto& event: events)
      {
        if (parseable)
        {
          stream << comma << event.second.name();
          comma = ",";
          continue;
        }
        printIdName(stream, color, offsetSigs, event.second.uid(), event.second.name());
        if (raw)
          stream << " " << FC(StreamColor_Yellow, color) << event.second.parametersSignature().toString() << FC(StreamColor_Reset, color)
                 << std::endl;
        else
          stream << " " << FC(StreamColor_Yellow, color) << event.second.parametersSignature().toPrettySignature() << FC(StreamColor_Reset, color)
                 << std::endl;
      }

      if (parseable)
      {
        stream << ":";
        comma = "";
      }
      else if (props.size())
      {
        printCat(stream, color, "Properties");
      }
      for (const auto& property: props)
      {
        if (parseable)
        {
          stream << comma << property.second.name();
          comma = ",";
          continue;
        }
        printIdName(stream, color, offsetProps, property.second.uid(), property.second.name());
        if (raw)
          stream << " " << FC(StreamColor_Yellow, color) << property.second.signature().toString() << FC(StreamColor_Reset, color)
                 << std::endl;
        else
          stream << " " << FC(StreamColor_Yellow, color) << property.second.signature().toPrettySignature() << FC(StreamColor_Reset, color)
                 << std::endl;
      }
      if (parseable)
        stream << std::endl;
    }
Пример #17
0
void ClientEntity::render (IFrontend *frontend, Layer layer, int scale, float zoom, int offsetX, int offsetY) const
{
	if (!_currSprite)
		return;

	const ClientEntityPtr ropeEntity = _ropeEntity;
	const int basePosX = _pos.x * scale * zoom;
	const int basePosY = _pos.y * scale * zoom;
	int posX = basePosX;
	int posY = basePosY;

	switch (_align) {
	case ENTITY_ALIGN_UPPER_LEFT:
		break;
	case ENTITY_ALIGN_LOWER_LEFT:
		posX -= _currSprite->getWidth(layer) * zoom / 2.0f;
		posY += _size.y * scale * zoom / 2.0f;
		posY -= _currSprite->getHeight(layer) * zoom;
		break;
	case ENTITY_ALIGN_MIDDLE_CENTER: {
		posX -= _currSprite->getWidth(layer) * zoom / 2.0f;
		posY -= _currSprite->getHeight(layer) * zoom / 2.0f;
		break;
	}
	}

	setScreenPos(offsetX + posX, offsetY + posY);

	const int ropeX1 = basePosX;
	const int ropeY1 = (basePosY - _size.y * scale * zoom / 2.0f);
	int ropeX2 = 0;
	int ropeY2 = 0;
	if (ropeEntity && layer == LAYER_MIDDLE) {
		const vec2& pos = ropeEntity->getPos();
		const vec2& size = ropeEntity->getSize();
		ropeX2 = pos.x * scale * zoom;
		ropeY2 = pos.y * scale * zoom + size.y * scale * zoom / 2.0f;
		static const Color color = { 0.5f, 0.3f, 0.3f, 1.0f };
		frontend->renderLine(offsetX + ropeX1, offsetY + ropeY1, offsetX + ropeX2, offsetY + ropeY2, color);
	}

	const bool visible = _currSprite->render(frontend, layer, _screenPosX, _screenPosY, zoom, _angle, _alpha);
	_visChanged = visible != _visible;

	renderOverlays(frontend, layer, scale, zoom, offsetX, offsetY, posX, posY);

	if (layer != LAYER_FRONT)
		return;

	if (Config.isDebug())
		frontend->renderFilledRect(_screenPosX, _screenPosY, 4, 4, colorRed);

	const bool debug = Config.getConfigVar("debugentity")->getBoolValue();
	if (debug) {
		const BitmapFontPtr& font = UI::get().getFont();

		renderDot(frontend, offsetX + basePosX, offsetY + basePosY, colorGreen);
		renderDot(frontend, offsetX + posX, offsetY + posY, colorWhite);
		if (ropeEntity && layer == LAYER_MIDDLE) {
			renderDot(frontend, offsetX + ropeX1, offsetY + ropeY1, colorBlue);
			renderDot(frontend, offsetX + ropeX2, offsetY + ropeY2, colorBrightBlue);
		}
		int offsetPosX, offsetPosY;
		calcOffset(scale, zoom, posX, posY, offsetPosX, offsetPosY);
		renderDot(frontend, offsetX + offsetPosX, offsetY + offsetPosY, colorGray);

		int fontY = _screenPosY;
		if (!_animation->isNone()) {
			font->print(_animation->name, colorWhite, _screenPosX, fontY);
			fontY += font->getTextHeight(_animation->name);
		}
		font->print(string::toString(_angle), colorWhite, _screenPosX, fontY);
	}
}