Raised This Month: $51 Target: $400
 12% 

Array Copy Stock


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-09-2011 , 11:08   Array Copy Stock
Reply With Quote #1

I made this the other day because I could not find one. Maybe someone else will need it. It will copy data from one array to another for a max length of cells and you're able to set starting positions. If someone sees optimization errors or has any other, better, ideas feel free to edit/comment.

Code:
/**
 * Copies information from one array into another.
 * 
 * @param into        The array to place the data into
 * @param from        The array to get the data from
 * @param len         The number of cells to copy
 * @param ignoretags  True to enable tag comparison, false to
 *                    ignore them.
 * @param intotag     The tagof constant for the into array
 * @param intosize    The max size of data to place into
 *                    the array
 * @param intopos     The starting position to place data
 *                    into
 * @param fromtag     The tagof constant for the from array
 * @param fromsize    The max size of data to place from
 *                    the array
 * @param frompos     The starting position to begin copying
 *                    data from
 */
stock arraycopy( any:into[], any:from[], len = sizeof into, bool:ignoretags = false, intotag = tagof into, intosize = sizeof into, intopos = 0, fromtag = tagof from, fromsize = sizeof from, frompos = 0) {
    if (!ignoretags && intotag != fromtag) {
        //So we know no elements were copied (we did not remove an element ie. returning -1)
        return 0;
    }
    
    new i
    while (i < len) {
        if (intopos >= intosize || frompos >= fromsize) {
            break;
        }
        
        into[intopos++] = from[frompos++];
        i++;
    }
    
    return i;
}
Attached Files
File Type: inc arraycopy.inc (1.5 KB, 471 views)
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-10-2011 at 15:28.
Tirant is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode