Ejemplo n.º 1
0
/**
 * Top level function for parsing a City PML element
 * @param str Pointer to a string structure
 * @return Returns a pointer to a filled in city structure or NULL on failure
 **/
pCity cityTopLevel( pstring str )
{
	int lastGood = 0;
	pCity newCity = NULL;
	int startIndex = 0;
	int endIndex = 0;
	char *temp = NULL;
	int tempInt = 0;
	element el;

	if ( str == NULL ) {
		goto end;
	}

	/// Skip the opening "{"
	if ( skipOpen( str, 0 ) == 0 ) {
		goto end;
	}

	/// Get the start and end index of the element id
	getIndex( str, &startIndex);
	endIndex = skipAlpha(str);

	if ( endIndex == -1 ) {
		goto end;
	}

	if ( startIndex == endIndex ) {
		goto end;
	}

	temp = copyData( str, startIndex, endIndex );

	if ( temp == NULL ) {
		goto end;
	}

	if ( strcmp( temp, "City") != 0 ) {
		deallocate(temp, cgc_strlen(temp) + 1 );
		goto end;
	}

	deallocate(temp, cgc_strlen(temp) + 1 );

	skipWhiteSpace( str );
	if ( !atChar( str, '}') ) {
		goto end;
	}

	incChar( str );
	skipWhiteSpace(str);

	lastGood = str->index;

	if ( allocate( sizeof(City), 0, (void**)&newCity) != 0 ) {
		newCity = NULL;
		goto error;
	}

	initCity( newCity );

	temp = pullNextElementName( str );

	while ( temp != NULL ) {
		el = elementNameToEnum( temp );

		deallocate(temp, cgc_strlen(temp) + 1 );

		switch (el) {
			case name:
				temp = extractName( str );

				if ( temp == NULL ) {
					goto error;
				}

				/// Clear it out
				bzero( newCity->name, 20 );

				/// Copy the name data. It has already been filtered 
				///	for invalid characters.
				strncpy( newCity->name, temp, 19);

				/// Free the buffer
				deallocate( temp, cgc_strlen(temp) + 1 );
				temp = NULL;
				break;
			case mayor:
				temp = extractMayor( str );

				if ( temp == NULL ) {
					goto error;
				}
			
				bzero( newCity->mayor, 30 );
#ifdef PATCHED
				strncpy( newCity->mayor, temp, 29 );
#else
				strcpy( newCity->mayor, temp );
#endif
				freeCharPtr( &temp );

				break;
			case url:
				temp = extractUrl( str );

				if ( temp == NULL ) {
					goto error;
				}

				bzero( newCity->url, 30 );

				strncpy( newCity->url, temp, 29 );
				freeCharPtr( &temp );
				break;
			case border:
				if ( newCity->border_count >= CITYBORDERMAX) {
					goto error;
				}

				tempInt = newCity->border_count;

				newCity->borders[ tempInt ] = extractBorder(str);

				if ( newCity->borders[ tempInt] == NULL ) {
					goto error;
				}

				newCity->border_count++;
				break;
			case population:
				newCity->population = extractPopulation( str );

				if ( newCity->population < 0 ) {
					goto error;
				}

				break;
			default:
				printf("!!Invalid element ID for City\n");
				goto error;
				break;
		};

		lastGood = str->index;
		temp = pullNextElementName(str);
	}

	if ( skipOpen( str, 1) == 0 ) {
		goto error;
	}

	getIndex( str, &startIndex);
	endIndex = skipAlpha( str );

	if ( endIndex == -1 ) {
		goto error;
	} else if ( startIndex == endIndex ) {
		goto error;
	}

	temp = copyData( str, startIndex, endIndex );

	if ( temp == NULL ) {
		goto error;
	}

	if ( strcmp( temp, "City") != 0 ) {
		deallocate(temp, cgc_strlen(temp) + 1 );
		goto error;
	}

	deallocate( temp, cgc_strlen(temp) + 1 );
	skipWhiteSpace(str);
	if ( !atChar( str, '}') ) {
		goto error;
	}

	incChar(str);
	goto end;
error:
	if ( newCity ) {
		freeCity( newCity );
		newCity = NULL;
	}

	printf("!!Error at: @s\n", str->buffer + lastGood);
	str->index = lastGood;

end:
	return newCity;
}
Ejemplo n.º 2
0
TypedValue* SharedMap::nvGet(int64_t k) const {
  int index = getIndex(k);
  if (index == -1) return nullptr;
  return (TypedValue*)&getValueRef(index);
}
Ejemplo n.º 3
0
TypedValue* SharedMap::nvGetCell(int64_t k) const {
  int index = getIndex(k);
  return index != -1 ? getValueRef(index).getTypedAccessor() :
         nvGetNotFound(k);
}
Ejemplo n.º 4
0
void ListView::remedyLayoutParameter(Widget *item)
{
    if (!item)
    {
        return;
    }
    switch (_direction) {
        case Direction::VERTICAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case Gravity::LEFT:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::LEFT);
                        break;
                    case Gravity::RIGHT:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT);
                        break;
                    case Gravity::CENTER_HORIZONTAL:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(MarginZero);
                }
                else
                {
                    defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(MarginZero);
                }
                else
                {
                    llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f));
                }
                switch (_gravity) {
                    case Gravity::LEFT:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::LEFT);
                        break;
                    case Gravity::RIGHT:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT);
                        break;
                    case Gravity::CENTER_HORIZONTAL:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
                        break;
                    default:
                        break;
                }
            }
            break;
        }
        case Direction::HORIZONTAL:
        {
            LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
            if (!llp)
            {
                LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
                switch (_gravity) {
                    case Gravity::TOP:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::TOP);
                        break;
                    case Gravity::BOTTOM:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::BOTTOM);
                        break;
                    case Gravity::CENTER_VERTICAL:
                        defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
                        break;
                    default:
                        break;
                }
                if (getIndex(item) == 0)
                {
                    defaultLp->setMargin(MarginZero);
                }
                else
                {
                    defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
                }
                item->setLayoutParameter(defaultLp);
            }
            else
            {
                if (getIndex(item) == 0)
                {
                    llp->setMargin(MarginZero);
                }
                else
                {
                    llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f));
                }
                switch (_gravity) {
                    case Gravity::TOP:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::TOP);
                        break;
                    case Gravity::BOTTOM:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::BOTTOM);
                        break;
                    case Gravity::CENTER_VERTICAL:
                        llp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
                        break;
                    default:
                        break;
                }
            }
            break;
        }
        default:
            break;
    }
    
}
Ejemplo n.º 5
0
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base,
    std::map<ESM::RefNum, std::string>& cache, CSMDoc::Messages& messages)
{
    Record<Cell> cell = mCells.getRecord (cellIndex);

    Cell& cell2 = base ? cell.mBase : cell.mModified;

    CellRef ref;
    ref.mNew = false;
    ESM::MovedCellRef mref;
    bool isDeleted = false;

    // hack to initialise mindex
    while (!(mref.mRefNum.mIndex = 0) && ESM::Cell::getNextRef(reader, ref, isDeleted, true, &mref))
    {
        // Keep mOriginalCell empty when in modified (as an indicator that the
        // original cell will always be equal the current cell).
        ref.mOriginalCell = base ? cell2.mId : "";

        if (cell.get().isExterior())
        {
            // ignoring moved references sub-record; instead calculate cell from coordinates
            std::pair<int, int> index = ref.getCellIndex();

            std::ostringstream stream;
            stream << "#" << index.first << " " << index.second;

            ref.mCell = stream.str();

            if (!base &&                  // don't try to update base records
                mref.mRefNum.mIndex != 0) // MVRF tag found
            {
                // there is a requirement for a placeholder where the original object was
                //
                // see the forum discussions here for more details:
                // https://forum.openmw.org/viewtopic.php?f=6&t=577&start=30
                ref.mOriginalCell = cell2.mId;

                // It is not always possibe to ignore moved references sub-record and
                // calculate from coordinates. Some mods may place the ref in positions
                // outside normal bounds, resulting in non sensical cell id's.  This often
                // happens if the moved ref was deleted.
                //
                // Use the target cell from the MVRF tag but if different output an error
                // message
                if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1])
                {
                    std::cerr << "The Position of moved ref "
                        << ref.mRefID << " does not match the target cell" << std::endl;
                    std::cerr << "Position: #" << index.first << " " << index.second
                        <<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1] << std::endl;

                    std::ostringstream stream;
                    stream << "#" << mref.mTarget[0] << " " << mref.mTarget[1];
                    ref.mCell = stream.str(); // overwrite
                }
            }
        }
        else
            ref.mCell = cell2.mId;

        // ignore content file number
        std::map<ESM::RefNum, std::string>::iterator iter = cache.begin();
        for (; iter != cache.end(); ++iter)
        {
            if (ref.mRefNum.mIndex == iter->first.mIndex)
                break;
        }

        if (isDeleted)
        {
            if (iter==cache.end())
            {
                CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell,
                    mCells.getId (cellIndex));

                messages.add (id, "Attempt to delete a non-existing reference");
                continue;
            }

            int index = getIndex (iter->second);

            Record<CellRef> record = getRecord (index);

            if (base)
            {
                removeRows (index, 1);
                cache.erase (iter);
            }
            else
            {
                record.mState = RecordBase::State_Deleted;
                setRecord (index, record);
            }

            continue;
        }

        if (iter==cache.end())
        {
            // new reference
            ref.mId = getNewId();

            Record<CellRef> record;
            record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
            (base ? record.mBase : record.mModified) = ref;

            appendRecord (record);

            cache.insert (std::make_pair (ref.mRefNum, ref.mId));
        }
        else
        {
            // old reference -> merge
            ref.mId = iter->second;

            int index = getIndex (ref.mId);

            Record<CellRef> record = getRecord (index);
            record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
            (base ? record.mBase : record.mModified) = ref;

            setRecord (index, record);
        }
    }
}
Ejemplo n.º 6
0
Action::ResultE DistanceLOD::draw(Action *action)
{
	DrawActionBase *da = dynamic_cast<DrawActionBase *>(action);
	RenderAction   *ra = dynamic_cast<RenderAction *>  (action);
	
    action->useNodeList();

    UInt32 numLevels = action->getNNodes();
    Int32 index = -1;
    
    if (numLevels == 0)
    {
    	// update index field for being externally accessible
    	if (index != getIndex() && (!ra || !ra->getEffectsPass()))
    	{
			beginEditCP(getPtr(), IndexFieldMask);
				setIndex(index);
			endEditCP  (getPtr(), IndexFieldMask);
		}
		
        return Action::Continue;
    }

    const MFReal32 &range = (*getMFRange());
    UInt32 numRanges = range.size();
	
    if (numRanges == 0)
    {
        index = 0;
    }
    else
    {
        Real32 dist = 0;
		
        if (ra != NULL)
		{
			if (!ra->getEffectsPass())
				dist = calcDistance(da, ra->top_matrix());
			else
				dist = _lastDist;
		}
        else
            dist = calcDistance(da, da->getActNode()->getToWorld());

        if (numRanges >= numLevels)
            numRanges = numLevels - 1;

        if(numRanges == 0)
        {
            index = 0;
        }
        else if (dist >= range[numRanges - 1])
        {
            index = numRanges;
        }
        else
        {
            for (index = 0; index < numRanges; ++index)
            {
                if (dist < range[index])
                    break;
            }
        }
    }
    
    // update index field for being externally accessible
	if (index != getIndex() && (!ra || !ra->getEffectsPass()))
	{
		beginEditCP(getPtr(), IndexFieldMask);
			setIndex(index);
		endEditCP  (getPtr(), IndexFieldMask);
	}

    const NodePtr nodePtr = action->getNode(index);
    
    if(da->isVisible(getCPtr(nodePtr)))
    {
        da->addNode(nodePtr);
    }

    return Action::Continue;
}
Ejemplo n.º 7
0
int Lab::getLength(std::string filename) {
	int index = getIndex(filename);
	if (index == -1)
		return 0;
	return entries[i].size;
}
Ejemplo n.º 8
0
char saveStateLogic(FILE* fp)
{
    if (fp != NULL)
    {
        int i, counterX, counterY;
        int tempParticle;

        //First write the version code for this saveload version
        fprintf(fp, "%s\n\n", SAVELOAD_VERSION_CODE);

        //Save the max specials (for backward compatibility if needed)
        fprintf(fp, "%d\n\n", MAX_SPECIALS);

        //Save the dimensions
        fprintf(fp, "%d %d\n\n", workWidth, workHeight);

        //Save the particles
        /* Save format:
         * (x y xVel yVel heat element->index) ...
         *   .
         *   .
         *   .
         */
        for (counterY = 0; counterY < workHeight; counterY++)
        {
            for (counterX = 0; counterX < workWidth; counterX++)
            {
                tempParticle = allCoords[getIndex(counterX, counterY)];
                if(tempParticle != -1)
                {
                    // Normal element
                    if(a_element[tempParticle]->index < NUM_BASE_ELEMENTS)
                    {
                        fprintf(fp, "B(%f %f %d %d %c %d)",
                                a_x[tempParticle],
                                a_y[tempParticle],
                                a_xVel[tempParticle],
                                a_yVel[tempParticle],
                                a_heat[tempParticle],
                                a_element[tempParticle]->index);
                    }
                    // Custom element
                    else
                    {
                        fprintf(fp, "C(%f %f %d %d %c %lu)",
                                a_x[tempParticle],
                                a_y[tempParticle],
                                a_xVel[tempParticle],
                                a_yVel[tempParticle],
                                a_heat[tempParticle],
                                hashElement(a_element[tempParticle]));
                    }

                    fprintf(fp, "[");
                    for (i = 0; i < MAX_SPECIALS; i++)
                    {
                        fprintf(fp, "%d ", a_specialVals[tempParticle][i]);
                    }
                    fprintf(fp, "]");
                }
                else
                {
                    // E -- empty location
                    fprintf(fp, "E");
                }
            }
            fprintf(fp, "\n");
        }

        fclose(fp);
        return TRUE;
    }
    if(fp)
    {
        fclose(fp);
    }
    return FALSE;
}
Ejemplo n.º 9
0
char loadStateLogicV1(FILE* fp)
{
    //Clear the screen and set up some temp variables
    arraySetup();
    elementSetup();
    gameSetup();

    int i, j, elementIndex, elementHash,
        sizeX, sizeY, fileMaxSpecials, tempSpecialVal, charsRead, failed;
    struct Element* tempElement;
    int tempParticle;
    char buffer[64];
    char lookAhead;

    if(fp != NULL)
    {
        // Get the saveload version code
        if((charsRead = fscanf(fp, "%s\n\n", &buffer)) == EOF || charsRead < 1) { return FALSE; }
        if(strcmp(buffer, SAVELOAD_VERSION_CODE) != 0) { return FALSE; }

        // Get the max specials at the time of this file
        if((charsRead = fscanf(fp, "%d\n\n", &fileMaxSpecials)) == EOF || charsRead < 1) {return FALSE;}

        // Get the dimensions
        if((charsRead = fscanf(fp, "%d %d\n\n", &sizeX, &sizeY)) == EOF || charsRead < 2) {return FALSE;}


        //Make sure saves are portable from different dimensions
        if(sizeX > workWidth)
        {
            sizeX = workWidth;
        }
        if(sizeY > workHeight)
        {
            sizeY = workHeight;
        }


        while(!feof(fp))
        {
            failed = FALSE;

            // Check for all particles used
            if(loq <= 0) {return TRUE;}

            // Scan in the initial character
            // If there is nothing, we're done
            if((charsRead = fscanf(fp, "%c", &lookAhead)) == EOF || charsRead < 1) {return TRUE;}

            // Basic particle
            if(lookAhead == 'B')
            {
                // Try to read in a particle
                tempParticle = avail[loq-1];
                if((charsRead = fscanf(fp, "(%f %f %d %d %c %d)",
                                       &(a_x[tempParticle]),
                                       &(a_y[tempParticle]),
                                       &(a_xVel[tempParticle]),
                                       &(a_yVel[tempParticle]),
                                       &(a_heat[tempParticle]),
                                       &elementIndex)) == EOF
                   || charsRead < 6) {continue;}
                a_element[tempParticle] = elements[elementIndex];
            }
            // Custom particle
            else if(lookAhead == 'C')
            {
                // Try to read in a particle
                tempParticle = avail[loq-1];
                if((charsRead = fscanf(fp, "(%f %f %d %d %c %lu)",
                                       &(a_x[tempParticle]),
                                       &(a_y[tempParticle]),
                                       &(a_xVel[tempParticle]),
                                       &(a_yVel[tempParticle]),
                                       &(a_heat[tempParticle]),
                                       &elementHash)) == EOF
                   || charsRead < 6) {continue;}

                // Find custom with that hash, and set the index
                elementIndex = findElementFromHash(elementHash);
                if (elementIndex)
                {
                    a_element[tempParticle] = elements[elementIndex];
                }
                else
                {
                    // Don't fail now, we need to finish reading in all specials, etc. so that
                    // we don't corrupt the stream. Instead, finish reading in, then don't actually
                    // allocate the element.
                    failed = TRUE;
                }
            }
            // Empty location
            else if(lookAhead == 'E')
            {
                continue;
            }
            else
            {
                // Ignore whitespace and other characters
                continue;
            }

            // Save the integral coordinates for writing to allCoords
            i = (int)a_x[tempParticle];
            j = (int)a_y[tempParticle];
            if (i >= sizeX || j >= sizeY) { return FALSE; }

            // Check that our lookahead is correct
            if((charsRead = fscanf(fp, "%c", &lookAhead)) != EOF && charsRead == 1 && lookAhead == '[')
            {
                int k;
                for (k = 0; k < fileMaxSpecials; k++)
                {
                    if((charsRead = fscanf(fp, "%d ", &tempSpecialVal)) == EOF || charsRead < 1)
                    {
                        failed = TRUE;
                        break;
                    }

                    if (k < MAX_SPECIALS)
                    {
                        a_specialVals[tempParticle][k] = tempSpecialVal;
                    }
                }

                // Skip past the closing ']'
                fseek(fp, 1, SEEK_CUR);
            }
            else
            {
                // Put the lookAhead char back on the stream
                fseek(fp, -1, SEEK_CUR);
                failed = TRUE;
            }
            // If reading in failed, initialize to cleared
            if (failed)
            {
                clearSpecialValsToElementDefault(tempParticle);
            }

            // Only finish creating the particle if we succeed
            if (!failed)
            {
                // Remove the particle from avail
                loq--;

                // Make the particle set
                a_set[tempParticle] = TRUE;

                // Set the allCoords and bitmap color
                allCoords[getIndex(i, j)] = tempParticle;
                setBitmapColor(a_x[tempParticle], a_y[tempParticle], a_element[tempParticle]);
            }
        }

        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 10
0
Colour TabBarButton::getTabBackgroundColour() const     { return owner.getTabBackgroundColour (getIndex()); }
Ejemplo n.º 11
0
char loadStateLogicV0(FILE* fp)
{
    //Clear the screen and set up some temp variables
    arraySetup();
    elementSetup();
    gameSetup();

    int numElementsSaved, i, j, elementIndex, lowerElementIndex, higherElementIndex,
        sizeX, sizeY, fileMaxSpecials, tempSpecialVal, charsRead, failed;
    struct Element* tempElement;
    int tempParticle;
    char lookAhead;

    if(fp != NULL)
    {
        __android_log_write(ANDROID_LOG_INFO, "LOG", "Loading custom elements in the save");
        // Get the number of custom elements saved in the file
        if((charsRead = fscanf(fp, "%d\n\n", &numElementsSaved)) == EOF || charsRead < 1) { return FALSE; }

        // Get the max specials at the time of this file
        if((charsRead = fscanf(fp, "%d\n\n", &fileMaxSpecials)) == EOF || charsRead < 1) {return FALSE;}

        int* tempMap;
        int* tempElMap;
        tempElMap = (int*)malloc ( MAX_ELEMENTS * sizeof(int) );
        tempMap = (int*)malloc( numElementsSaved * 3 * sizeof(int) );
        elements = realloc( elements, (numElements + numElementsSaved) * sizeof( struct Element* ) );

        for(i = 0; i < numElementsSaved; i++)
        {
            if((charsRead = fscanf(fp, "%d", &elementIndex) == EOF || charsRead < 1)) {return FALSE;}

            tempElement = (struct Element*) malloc(sizeof(struct Element));
            if((charsRead = fscanf(fp, "%s", &tempElement->name)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->state)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->startingTemp)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->lowestTemp)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->highestTemp)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &lowerElementIndex)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &higherElementIndex)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->red)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->green)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->blue)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->density)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->fallVel)) == EOF || charsRead < 1) {return FALSE;}
            if((charsRead = fscanf(fp, "%d", &tempElement->inertia)) == EOF || charsRead < 1) {return FALSE;}

            int j;
            char collision;
            int special, specialVal;
            tempElement->collisions = malloc (NUM_BASE_ELEMENTS * sizeof(char));
            // Load collisions
            for (j = 0; j < NUM_BASE_ELEMENTS; j++)
            {
                __android_log_write(ANDROID_LOG_INFO, "LOG", "Loading collisions");
                charsRead = fscanf(fp, "%d", &collision);
                if (charsRead < 1 || charsRead == EOF)
                {
                    tempElement->collisions[j] = 0;
                }
                else
                {
                    tempElement->collisions[j] = collision;
                }
            }
            // Load specials
            for (j = 0; j < fileMaxSpecials; j++)
            {
                __android_log_write(ANDROID_LOG_INFO, "LOG", "Loading specials");
                charsRead = fscanf(fp, "%d %d", &special, &specialVal);
                if (j < MAX_SPECIALS)
                {
                    if (charsRead < 2 || charsRead == EOF)
                    {
                        tempElement->specials[j] = SPECIAL_NONE;
                        tempElement->specialVals[j] = 0;
                    }
                    else
                    {
                        tempElement->specials[j] = special;
                        tempElement->specialVals[j] = specialVal;
                    }
                }
            }
            tempMap[3*i] = elementIndex;
            tempMap[3*i + 1] = lowerElementIndex;
            tempMap[3*i + 2] = higherElementIndex;
            tempElMap[elementIndex] = i + numElements;
            elements[elementIndex] = tempElement;
        }
        for (i = 0; i < numElementsSaved; i++)
        {
            elements[ tempMap[3*i] ]->lowerElement = tempMap[3*i + 1] > NUM_BASE_ELEMENTS ?
                elements[ tempElMap[tempMap[3*i + 1]] ] : elements[tempMap[3*i + 1]];
            elements[ tempMap[3*i] ]->lowerElement = tempMap[3*i + 2] > NUM_BASE_ELEMENTS ?
                elements[tempElMap[tempMap[3*i + 2]] ]: elements[tempMap[3*i + 2]];
        }
        free(tempMap);
        free(tempElMap);

        numElements +=  numElementsSaved;
        __android_log_write(ANDROID_LOG_INFO, "LOG", "Done loading custom elements in the save");


        // Get the dimensions
        if((charsRead = fscanf(fp, "%d %d\n\n", &sizeX, &sizeY)) == EOF || charsRead < 2) {return FALSE;}


        //Make sure saves are portable from different dimensions
        if(sizeX > workWidth)
        {
            sizeX = workWidth;
        }
        if(sizeY > workHeight)
        {
            sizeY = workHeight;
        }


        while(!feof(fp))
        {
            // Check for all particles used
            if(loq <= 0) {return TRUE;}

            // Scan in the initial character
            if((charsRead = fscanf(fp, "%c", &lookAhead)) == EOF || charsRead < 1) {return FALSE;}

            // If it's not '(' then something is malformed, move on
            if(lookAhead != '(') {continue;}


            // Go back to before the open paren
            fseek(fp, -1, SEEK_CUR);
            // Try to read in a particle
            tempParticle = avail[loq-1];
            if((charsRead = fscanf(fp, "(%f %f %d %d %c %d)",
                                   &(a_x[tempParticle]),
                                   &(a_y[tempParticle]),
                                   &(a_xVel[tempParticle]),
                                   &(a_yVel[tempParticle]),
                                   &(a_heat[tempParticle]),
                                   &elementIndex)) == EOF
               || charsRead < 6) {continue;}

            // We succeeded, so decrement loq to remove the particle from being available
            loq--;

            // Save the integral coordinates for writing to allCoords
            i = (int)(a_x[tempParticle]);
            j = (int)(a_y[tempParticle]);
            if (i >= sizeX || j >= sizeY) { return FALSE; }

            // Keep the element handy
            if (elementIndex >= numElements) { return FALSE; }
            tempElement = elements[elementIndex];

            // Read in special vals
            failed = FALSE;
            // Check that our lookahead is correct
            if((charsRead = fscanf(fp, "%c", &lookAhead)) != EOF && charsRead == 1 && lookAhead == '[')
            {
                int k;
                for (k = 0; k < fileMaxSpecials; k++)
                {
                    if((charsRead = fscanf(fp, "%d ", &tempSpecialVal)) == EOF || charsRead < 1)
                    {
                        failed = TRUE;
                        break;
                    }

                    if (k < MAX_SPECIALS)
                    {
                        a_specialVals[tempParticle][k] = tempSpecialVal;
                    }
                }

                // Skip past the closing ']'
                fseek(fp, 1, SEEK_CUR);
            }
            else
            {
                // Put the lookAhead char back on the stream
                fseek(fp, -1, SEEK_CUR);
                failed = TRUE;
            }
            // If reading in failed, initialize to cleared
            if (failed)
            {
                clearSpecialValsToElementDefault(tempParticle);
            }

            // Set the element and make the particle set
            a_element[tempParticle] = tempElement;
            a_set[tempParticle] = TRUE;

            // Set the allCoords and bitmap color
            allCoords[getIndex(i, j)] = tempParticle;
            setBitmapColor(a_x[tempParticle], a_y[tempParticle], tempElement);
        }

        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 12
0
void StableSolver2D::projection()
{
	for(int i=1; i<=rowSize; i++) 
	{ 
		for(int j=1; j<=colSize; j++) 
		{
			div[getIndex(i, j)] = -0.5f*(vx[getIndex(i+1,j)]-vx[getIndex(i-1,j)]+vy[getIndex(i,j+1)]-vy[getIndex(i,j-1)]);
			p[getIndex(i,j)] = 0;
		}
	}
	setBoundary(div, 0); 
	setBoundary(p, 0);

	lin_solve(p, div, 1.0, 4.0, 0);

	for(int i=1; i<=rowSize; i++) 
	{ 
		for(int j=1; j<=colSize; j++) 
		{
			vx[getIndex(i,j)] -= 0.5f*(p[getIndex(i+1,j)]-p[getIndex(i-1,j)]);
			vy[getIndex(i,j)] -= 0.5f*(p[getIndex(i,j+1)]-p[getIndex(i,j-1)]);
		}
	}
	setBoundary(vx, 1); 
	setBoundary(vy, 2);
}
Ejemplo n.º 13
0
void StableSolver2D::setBoundary(float *value, int flag)
{
	int dim = rowSize;

	for(int i=1; i<=dim; i++) 
	{
		if(flag == 1)
		{
			value[getIndex(0, i)]		= -value[getIndex(1,i)];
			value[getIndex(dim+1,i)]	= -value[getIndex(dim,i)];
			value[getIndex(i,0  )]		= value[getIndex(i,1)];
			value[getIndex(i,dim+1)]	= value[getIndex(i,dim)];

		}

		if(flag == 2)
		{
			value[getIndex(0, i)]		= value[getIndex(1,i)];
			value[getIndex(dim+1,i)]	= value[getIndex(dim,i)];
			value[getIndex(i,0  )]		= -value[getIndex(i,1)];
			value[getIndex(i,dim+1)]	= -value[getIndex(i,dim)];
		}

		if(flag == 0)
		{
			value[getIndex(0, i)]		= value[getIndex(1,i)];
			value[getIndex(dim+1,i)]	= value[getIndex(dim,i)];
			value[getIndex(i,0  )]		= value[getIndex(i,1)];
			value[getIndex(i,dim+1)]	= value[getIndex(i,dim)];
		}
	}

	value[getIndex(0, 0)]			= 0.5f*(value[getIndex(1, 0)]+value[getIndex(0, 1)]);
	value[getIndex(0, dim+1)]		= 0.5f*(value[getIndex(1, dim+1)]+value[getIndex(0, dim)]);
	value[getIndex(dim+1, 0)]		= 0.5f*(value[getIndex(dim, 0)]+value[getIndex(dim+1, 1)]);
	value[getIndex(dim+1, dim+1)]	= 0.5f*(value[getIndex(dim, dim+1)]+value[getIndex(dim+1, dim)]);
}
Ejemplo n.º 14
0
/**
 * Extract the data from the Url element.
 * 	This can be something such as http://www.rome.com
 * @param str Pointer to a string structure
 * @return Returns the element data or NULL on failure
 *	The caller is responsible for freeing the pointer
 **/
char *extractUrl( pstring str ) 
{
	char *url = NULL;
	int startIndex = 0;
	char *temp = NULL;

	if ( str == NULL ) {
		goto end;
	}

	if ( skipOpen( str, 0 ) == 0 ) {
		goto end;
	}

	getIndex( str, &startIndex );

	skipAlpha(str);

	url = copyData( str, startIndex, str->index);

	if ( url == NULL ) {
		goto end;
	}

	if ( strcmp( url, "Url" ) ) {
		freeCharPtr( &url );
		goto end;
	}

	skipWhiteSpace( str );

	if (!atChar( str, '}') ) {
		goto end;
	}

	incChar(str);
	skipWhiteSpace(str);
	getIndex( str, &startIndex);

	skipUrl( str );

	url = copyData( str, startIndex, str->index );

	if ( url == NULL ) {
		goto end;
	}

	skipWhiteSpace(str);
	if ( skipOpen( str, 1 ) == 0 ) {
		goto error;
	}

	getIndex( str, &startIndex );
	skipAlpha(str);
	temp = copyData( str, startIndex, str->index);

	if ( temp == NULL ) {
		goto error;
	}

	if ( strcmp( temp, "Url") != 0 ) {
		freeCharPtr( &temp );
		goto error;
	}

	freeCharPtr( &temp );

	skipWhiteSpace(str);
	if ( !atChar( str, '}') ) {
		goto error;
	}

	incChar(str);

	goto end;
error:
	if ( url ) {
		freeCharPtr( &url );
	}

end:
	return url;
}
Ejemplo n.º 15
0
bool APCLocalArray::ExistsStr(const ArrayData* ad, const StringData* k) {
  auto a = asSharedArray(ad);
  return a->getIndex(k) != -1;
}
Ejemplo n.º 16
0
QRgba64 Lut3D::getColor(uint16_t red, uint16_t green, uint16_t blue)
{
    uint8_t redIndex, greenIndex, blueIndex;
    float redDif, greenDif, blueDif;
    float c8[2][2][2], c4[2][2], c2[2], c1;
    QRgba64 colorPoint;

    // Retrieve 3D LUT index
    redIndex   = getIndex(red);
    greenIndex = getIndex(green);
    blueIndex  = getIndex(blue);

    redDif   = (float)(red   - (redIndex   * INTERVAL)) / INTERVAL;
    greenDif = (float)(green - (greenIndex * INTERVAL)) / INTERVAL;
    blueDif  = (float)(blue  - (blueIndex  * INTERVAL)) / INTERVAL;

    // Interpolate red channel
    c8[0][0][0] = entry[blueIndex  ][greenIndex  ][redIndex  ].red();
    c8[0][0][1] = entry[blueIndex  ][greenIndex  ][redIndex+1].red();
    c8[0][1][0] = entry[blueIndex  ][greenIndex+1][redIndex  ].red();
    c8[0][1][1] = entry[blueIndex  ][greenIndex+1][redIndex+1].red();
    c8[1][0][0] = entry[blueIndex+1][greenIndex  ][redIndex  ].red();
    c8[1][0][1] = entry[blueIndex+1][greenIndex  ][redIndex+1].red();
    c8[1][1][0] = entry[blueIndex+1][greenIndex+1][redIndex  ].red();
    c8[1][1][1] = entry[blueIndex+1][greenIndex+1][redIndex+1].red();

    c4[0][0] = c8[0][0][0] * (1 - redDif) + c8[0][0][1] * redDif;
    c4[0][1] = c8[0][1][0] * (1 - redDif) + c8[0][1][1] * redDif;
    c4[1][0] = c8[1][0][0] * (1 - redDif) + c8[1][0][1] * redDif;
    c4[1][1] = c8[1][1][0] * (1 - redDif) + c8[1][1][1] * redDif;

    c2[0] = c4[0][0] * (1 - greenDif) + c4[0][1] * greenDif;
    c2[1] = c4[1][0] * (1 - greenDif) + c4[1][1] * greenDif;

    c1 = c2[0] * (1 - blueDif) + c2[1] * blueDif;
    colorPoint.setRed(c1);

    // Interpolate green channel
    c8[0][0][0] = entry[blueIndex  ][greenIndex  ][redIndex  ].green();
    c8[0][0][1] = entry[blueIndex  ][greenIndex  ][redIndex+1].green();
    c8[0][1][0] = entry[blueIndex  ][greenIndex+1][redIndex  ].green();
    c8[0][1][1] = entry[blueIndex  ][greenIndex+1][redIndex+1].green();
    c8[1][0][0] = entry[blueIndex+1][greenIndex  ][redIndex  ].green();
    c8[1][0][1] = entry[blueIndex+1][greenIndex  ][redIndex+1].green();
    c8[1][1][0] = entry[blueIndex+1][greenIndex+1][redIndex  ].green();
    c8[1][1][1] = entry[blueIndex+1][greenIndex+1][redIndex+1].green();

    c4[0][0] = c8[0][0][0] * (1 - redDif) + c8[0][0][1] * redDif;
    c4[0][1] = c8[0][1][0] * (1 - redDif) + c8[0][1][1] * redDif;
    c4[1][0] = c8[1][0][0] * (1 - redDif) + c8[1][0][1] * redDif;
    c4[1][1] = c8[1][1][0] * (1 - redDif) + c8[1][1][1] * redDif;

    c2[0] = c4[0][0] * (1 - greenDif) + c4[0][1] * greenDif;
    c2[1] = c4[1][0] * (1 - greenDif) + c4[1][1] * greenDif;

    c1 = c2[0] * (1 - blueDif) + c2[1] * blueDif;
    colorPoint.setGreen(c1);

    // Interpolate blue channel
    c8[0][0][0] = entry[blueIndex  ][greenIndex  ][redIndex  ].blue();
    c8[0][0][1] = entry[blueIndex  ][greenIndex  ][redIndex+1].blue();
    c8[0][1][0] = entry[blueIndex  ][greenIndex+1][redIndex  ].blue();
    c8[0][1][1] = entry[blueIndex  ][greenIndex+1][redIndex+1].blue();
    c8[1][0][0] = entry[blueIndex+1][greenIndex  ][redIndex  ].blue();
    c8[1][0][1] = entry[blueIndex+1][greenIndex  ][redIndex+1].blue();
    c8[1][1][0] = entry[blueIndex+1][greenIndex+1][redIndex  ].blue();
    c8[1][1][1] = entry[blueIndex+1][greenIndex+1][redIndex+1].blue();

    c4[0][0] = c8[0][0][0] * (1 - redDif) + c8[0][0][1] * redDif;
    c4[0][1] = c8[0][1][0] * (1 - redDif) + c8[0][1][1] * redDif;
    c4[1][0] = c8[1][0][0] * (1 - redDif) + c8[1][0][1] * redDif;
    c4[1][1] = c8[1][1][0] * (1 - redDif) + c8[1][1][1] * redDif;

    c2[0] = c4[0][0] * (1 - greenDif) + c4[0][1] * greenDif;
    c2[1] = c4[1][0] * (1 - greenDif) + c4[1][1] * greenDif;

    c1 = c2[0] * (1 - blueDif) + c2[1] * blueDif;
    colorPoint.setBlue(c1);
    return colorPoint;
}
Ejemplo n.º 17
0
void VoxelLayer::updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x,
                                       double* min_y, double* max_x, double* max_y)
{
  if (rolling_window_)
    updateOrigin(robot_x - getSizeInMetersX() / 2, robot_y - getSizeInMetersY() / 2);
  if (!enabled_)
    return;
  useExtraBounds(min_x, min_y, max_x, max_y);

  bool current = true;
  std::vector<ObservationSet> observations;
  std::vector<Observation> clearing_observations;

  if(clear_old_){
    resetOldCosts(min_x, min_y, max_x, max_y);
  }

  //get the marking observations
  current = current && getMarkingObservations(observations);

  //get the clearing observations
  current = current && getClearingObservations(clearing_observations);

  //update the global current status
  current_ = current;

  //raytrace freespace
  for (unsigned int i = 0; i < clearing_observations.size(); ++i)
  {
    raytraceFreespace(clearing_observations[i], min_x, min_y, max_x, max_y);
  }
   
  //place the new obstacles into a priority queue... each with a priority of zero to begin with
  for (std::vector<ObservationSet>::const_iterator it = observations.begin(); it != observations.end(); ++it)
  {
    const ObservationSet& obs_set = *it; 

    //check if this is in the max_timeout list 
    bool max_timeout = false; 
    
    if(observation_timeout.find(obs_set.topic)!= observation_timeout.end()){
      max_timeout = true;
      ROS_DEBUG("Observation set for topic %s - clearing\n", obs_set.topic.c_str());
    }

    for(std::vector<Observation>::const_iterator it_o = obs_set.marking_observations.begin(); 
        it_o != obs_set.marking_observations.end(); it_o++){
      const Observation& obs = *it_o;

      //we should throw out stale observations also 

      CostMapList cm_list; 
      cm_list.topic = obs_set.topic;
      cm_list.obs_timestamp = obs.cloud_->header.stamp; 
      
      double obs_ts = cm_list.obs_timestamp / 1.0e6; 

      const pcl::PointCloud<pcl::PointXYZ>& cloud = *(obs.cloud_);

      double sq_obstacle_range = obs.obstacle_range_ * obs.obstacle_range_;

      int count = 0; 

      for (unsigned int i = 0; i < cloud.points.size(); ++i)
      {
          //if the obstacle is too high or too far away from the robot we won't add it
          if (cloud.points[i].z > max_obstacle_height_)
            continue;          

          //compute the squared distance from the hitpoint to the pointcloud's origin
          double sq_dist = (cloud.points[i].x - obs.origin_.x) * (cloud.points[i].x - obs.origin_.x)
            + (cloud.points[i].y - obs.origin_.y) * (cloud.points[i].y - obs.origin_.y)
            + (cloud.points[i].z - obs.origin_.z) * (cloud.points[i].z - obs.origin_.z);

          //if the point is far enough away... we won't consider it
          if (sq_dist >= sq_obstacle_range)
            continue;

          //now we need to compute the map coordinates for the observation
          unsigned int mx, my, mz;
          if (cloud.points[i].z < origin_z_)
          {
              if (!worldToMap3D(cloud.points[i].x, cloud.points[i].y, origin_z_, mx, my, mz))
                continue;
          }
          else if (!worldToMap3D(cloud.points[i].x, cloud.points[i].y, cloud.points[i].z, mx, my, mz))
          {
              continue;
          }

          //mark the cell in the voxel grid and check if we should also mark it in the costmap
          if (voxel_grid_.markVoxelInMap(mx, my, mz, mark_threshold_))
          {
              unsigned int index = getIndex(mx, my);
              //these are the ones set as occupied 
              costmap_[index] = LETHAL_OBSTACLE;
              touch((double)cloud.points[i].x, (double)cloud.points[i].y, min_x, min_y, max_x, max_y);

              //keep track of which indices we updated 
              if(max_timeout){
                cm_list.indices.push_back(ObstaclePoint(index, (double)cloud.points[i].x, (double)cloud.points[i].y));
                count++;
              }
          }
      }
      if(max_timeout && count > 0){
        locations_utime.updateObstacleTime(cm_list);
        new_obs_list.push_back(cm_list);
      }
    }
  }

  if(clear_old_){
    //inflate the bounds - otherwise the inflation layer wont reset the inflated cost 
    *min_x -= inflation_radius_;
    *min_y -= inflation_radius_;
    *max_x += inflation_radius_;
    *max_y += inflation_radius_;
  }

  if (publish_voxel_)
  {
    costmap_2d::VoxelGrid grid_msg;
    unsigned int size = voxel_grid_.sizeX() * voxel_grid_.sizeY();
    grid_msg.size_x = voxel_grid_.sizeX();
    grid_msg.size_y = voxel_grid_.sizeY();
    grid_msg.size_z = voxel_grid_.sizeZ();
    grid_msg.data.resize(size);
    memcpy(&grid_msg.data[0], voxel_grid_.getData(), size * sizeof(unsigned int));

    grid_msg.origin.x = origin_x_;
    grid_msg.origin.y = origin_y_;
    grid_msg.origin.z = origin_z_;

    grid_msg.resolutions.x = resolution_;
    grid_msg.resolutions.y = resolution_;
    grid_msg.resolutions.z = z_resolution_;
    grid_msg.header.frame_id = global_frame_;
    grid_msg.header.stamp = ros::Time::now();
    voxel_pub_.publish(grid_msg);
  }

  footprint_layer_.updateBounds(robot_x, robot_y, robot_yaw, min_x, min_y, max_x, max_y);
}
Ejemplo n.º 18
0
bool SharedMap::exists(int64_t k) const {
  return getIndex(k) != -1;
}
ssize_t NameValueTableWrapper::getIndex(int64_t k) const {
  return getIndex(String(k));
}
Ejemplo n.º 20
0
TypedValue* SharedMap::NvGetStr(const ArrayData* ad, const StringData* key) {
  auto a = asSharedMap(ad);
  auto index = a->getIndex(key);
  if (index == -1) return nullptr;
  return (TypedValue*)&a->getValueRef(index);
}
Ejemplo n.º 21
0
        void run() {
            Client::WriteContext ctx(&_txn, ns());

            const int N = 5000;
            for (int i = 0; i < N; ++i) {
                insert(BSON("foo" << (i % 10)));
            }

            addIndex(BSON("foo" << 1));

            // Plan 0: IXScan over foo == 7
            // Every call to work() returns something so this should clearly win (by current scoring
            // at least).
            IndexScanParams ixparams;
            ixparams.descriptor = getIndex(&_txn, ctx.ctx().db(), BSON("foo" << 1));
            ixparams.bounds.isSimpleRange = true;
            ixparams.bounds.startKey = BSON("" << 7);
            ixparams.bounds.endKey = BSON("" << 7);
            ixparams.bounds.endKeyInclusive = true;
            ixparams.direction = 1;

            const Collection* coll = ctx.ctx().db()->getCollection(&_txn, ns());

            auto_ptr<WorkingSet> sharedWs(new WorkingSet());
            IndexScan* ix = new IndexScan(ixparams, sharedWs.get(), NULL);
            auto_ptr<PlanStage> firstRoot(new FetchStage(sharedWs.get(), ix, NULL, coll));

            // Plan 1: CollScan with matcher.
            CollectionScanParams csparams;
            csparams.collection = ctx.ctx().db()->getCollection( &_txn, ns() );
            csparams.direction = CollectionScanParams::FORWARD;

            // Make the filter.
            BSONObj filterObj = BSON("foo" << 7);
            StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
            verify(swme.isOK());
            auto_ptr<MatchExpression> filter(swme.getValue());
            // Make the stage.
            auto_ptr<PlanStage> secondRoot(new CollectionScan(csparams, sharedWs.get(),
                                                              filter.get()));

            // Hand the plans off to the runner.
            CanonicalQuery* cq = NULL;
            verify(CanonicalQuery::canonicalize(ns(), BSON("foo" << 7), &cq).isOK());
            verify(NULL != cq);

            MultiPlanStage* mps = new MultiPlanStage(ctx.ctx().db()->getCollection(&_txn, ns()),cq);
            mps->addPlan(createQuerySolution(), firstRoot.release(), sharedWs.get());
            mps->addPlan(createQuerySolution(), secondRoot.release(), sharedWs.get());

            // Plan 0 aka the first plan aka the index scan should be the best.
            mps->pickBestPlan();
            ASSERT(mps->bestPlanChosen());
            ASSERT_EQUALS(0, mps->bestPlanIdx());

            SingleSolutionRunner sr(
                ctx.ctx().db()->getCollection(&_txn, ns()),
                cq,
                mps->bestSolution(),
                mps,
                sharedWs.release()
            );

            // Get all our results out.
            int results = 0;
            BSONObj obj;
            while (Runner::RUNNER_ADVANCED == sr.getNext(&obj, NULL)) {
                ASSERT_EQUALS(obj["foo"].numberInt(), 7);
                ++results;
            }
            ctx.commit();

            ASSERT_EQUALS(results, N / 10);
        }
Ejemplo n.º 22
0
const TypedValue* APCLocalArray::NvGetInt(const ArrayData* ad, int64_t k) {
  auto a = asApcArray(ad);
  auto index = a->getIndex(k);
  if (index == -1) return nullptr;
  return GetValueRef(a, index).asTypedValue();
}
void CollageTexture::pasteImage(int x, int y, int w, int h, unsigned char * pxls, int glType)
{	
	int bpp;
	
	if(glType == GL_RGB)
		bpp=3;
	else if(glType == GL_RGBA)
		bpp=4;
	
	
	int collageIndex = getIndex(x,y);
	int sourceIndex = 0;
	int sourceRow = 0;
	
	int collageMax = c_width*c_height*c_bpp;
	int sourceMax = w*h*bpp;
	
	int startX = x;
		
	while(1)
	{
		
		if(x >= c_width || x-startX >= w) // if we're passed the edge of the collage or done with a row of the image, go to the next row
		{
			x = startX;
			y++;
			sourceRow++;
			sourceIndex = (sourceRow * w)*bpp;
			collageIndex = getIndex(x,y);
			
			if(collageIndex >= collageMax) //if we're passed the edge of the collage, break!
				break;
		}
		
		if(sourceIndex >= sourceMax) // have we managed to go past the end of any files?
			break;
		
		//if we're still good, copy in the pixels
		
		if(c_bpp == 4) // do we blend?
		{
			if( collage[collageIndex + 3] != 0) // something non transparent exists as this pixel, therefore: blend!
			{
				float dest_pct = (float)collage[collageIndex + 3]/255.0f;
				
				float source_pct  = 1;
				if(bpp==4)
					source_pct = (float)pxls[sourceIndex + 3]/255.0f;
				
				//additive blend
				collage[collageIndex    ] = (float)collage[collageIndex    ] * (1.0-source_pct) + (float)pxls[sourceIndex    ] * source_pct;
				collage[collageIndex + 1] = (float)collage[collageIndex + 1] * (1.0-source_pct) + (float)pxls[sourceIndex + 1] * source_pct;
				collage[collageIndex + 2] = (float)collage[collageIndex + 2] * (1.0-source_pct) + (float)pxls[sourceIndex + 2] * source_pct;
				
				collage[collageIndex + 3] = 255 * (dest_pct * (1.0-source_pct) + source_pct );
			}
			else // don't blend! (blending with nothing ends up diluting the color
			{
				collage[collageIndex    ] = pxls[sourceIndex    ];
				collage[collageIndex + 1] = pxls[sourceIndex + 1];
				collage[collageIndex + 2] = pxls[sourceIndex + 2];
				if(bpp==4)
					collage[collageIndex + 3] = pxls[sourceIndex + 3];
				else
					collage[collageIndex + 3] = 255;
			}
			
		}
		else // just copy straight, theres no blend data being stored
		{
			collage[collageIndex    ] = pxls[sourceIndex    ];
			collage[collageIndex + 1] = pxls[sourceIndex + 1];
			collage[collageIndex + 2] = pxls[sourceIndex + 2];
		}
		
		x++;
		collageIndex+=c_bpp;
		sourceIndex+=bpp;
	}
}
Ejemplo n.º 24
0
bool Set_List::contains(int item) const
{
	int ind = getIndex(item);
	return ind != -1;
}
int TabBarButton::getBestTabLength (const int depth)
{
    return jlimit (depth * 2,
                   depth * 7,
                   getLookAndFeel().getTabButtonBestWidth (getIndex(), getButtonText(), depth, *this));
}
Ejemplo n.º 26
0
	virtual void NodeTriangle(const GeometryVertex *v1,const GeometryVertex *v2,const GeometryVertex *v3)
	{
		mIndices.push_back( getIndex(v1->mPos) );
		mIndices.push_back( getIndex(v2->mPos) );
		mIndices.push_back( getIndex(v3->mPos) );
	}
Ejemplo n.º 27
0
TypedValue* SharedMap::nvGet(const StringData* key) const {
  int index = getIndex(key);
  if (index == -1) return nullptr;
  return (TypedValue*)&getValueRef(index);
}
Ejemplo n.º 28
0
TypedValue* APCLocalArray::NvGetInt(const ArrayData* ad, int64_t k) {
  auto a = asSharedArray(ad);
  auto index = a->getIndex(k);
  if (index == -1) return nullptr;
  return (TypedValue*)&a->getValueRef(index);
}
Ejemplo n.º 29
0
TypedValue* SharedMap::nvGetCell(const StringData* key) const {
  int index = getIndex(key);
  return index != -1 ? getValueRef(index).getTypedAccessor() :
         nvGetNotFound(key);
}
Ejemplo n.º 30
0
void TableViewWidget::updateDropSelection()
{
	setCurrentIndex(getIndex(qBound(0, m_dropRow, getRowCount()), 0));

	m_dropRow = -1;
}