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

Array Copy Stock


Post New Thread Reply   
 
Thread Tools Display Modes
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-10-2011 , 14:05   Re: Array Copy Stock
Reply With Quote #11

Quote:
Originally Posted by fysiks View Post
Does it work here?
Yes.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-10-2011 , 14:07   Re: Array Copy Stock
Reply With Quote #12

Ya, why not do

Code:
if (tagof into != tagof from)
    break
so

PHP Code:
stock arraycopy(into[], size1pos1from[], size2pos2len) {
    if (
tagof into != tagof from) {
        
log_error(AMX_ERR_PARAMS"Tag of ^"into^" does not match tag of ^"from^"");
        return;
    }
    
    for (new 
ileni++) {
        if (
pos1 >= size1 || pos2 >= size2) {
            break;
        }
        
        
into[pos1++] = from[pos2++];
    }

Yea! so there is basically an instanceof operator!
__________________

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 14:11.
Tirant is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-10-2011 , 14:11   Re: Array Copy Stock
Reply With Quote #13

Quote:
Originally Posted by Tirant View Post
Ya, why not do

Code:
if (tagof into != tagof from)
    break
That would just be
Code:
if (0 != 0)
    break
You need to store the tags into an argument like it is done in the link provided earlier.

Something you should also do is return the amount of values copied.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-10-2011 , 14:31   Re: Array Copy Stock
Reply With Quote #14

So something like this

PHP Code:
stock arraycopy(into[], tag1 tagof intosize1pos1from[], tag2 tagof fromsize2pos2len) {
    if (
tag1 != tag2) {
        
log_error(AMX_ERR_PARAMS"Tag of ^"into^" (%d) does not match tag of ^"from^" (%d)"tag1tag2);
        return -
1;
    }
    
    new 
i
    
while (len) {
        if (
pos1 >= size1 || pos2 >= size2) {
            break;
        }
        
        
into[pos1++] = from[pos2++];
        
i++;
    }
    
    return 
i;

__________________

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]
Tirant is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-10-2011 , 14:44   Re: Array Copy Stock
Reply With Quote #15

Yes; however, you still need to tag both into and from as any so that any tag can be used. Currently it will give you a tag mismatch.

I suggest you move the tags to the end of the parameter list, so people don't have to use an underscore to skip the argument.

I would also suggest a parameter for ignoring tags.

Personally, how I would make it:
Code:
stock arraycopy( any:into[], any:from[], len, 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;
}

Last edited by Emp`; 09-10-2011 at 14:47.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-10-2011 , 15:01   Re: Array Copy Stock
Reply With Quote #16

Quote:
Originally Posted by Emp` View Post
Yes; however, you still need to tag both into and from as any so that any tag can be used. Currently it will give you a tag mismatch.

I suggest you move the tags to the end of the parameter list, so people don't have to use an underscore to skip the argument.

I would also suggest a parameter for ignoring tags.

Personally, how I would make it:
Code:
stock arraycopy( any:into[], any:from[], len, 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;
}
Okay, I like that. Maybe we should have "len = sizeof into" within the parameter list also.

Also, why remove the error reporting? IMO, if the tags are not right when they should be, I think the client should be notified.
__________________

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]
Tirant is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-10-2011 , 15:05   Re: Array Copy Stock
Reply With Quote #17

Quote:
Originally Posted by Tirant View Post
Okay, I like that. Maybe we should have "len = sizeof into" within the parameter list also.

Also, why remove the error reporting? IMO, if the tags are not right when they should be, I think the client should be notified.
That's up to you, I was just showing how I would make it.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-10-2011 , 15:10   Re: Array Copy Stock
Reply With Quote #18

Did you test your stock ? Because I'm doing some tests just by curiosity, and by using tagof in the header will result 0 always or using multi-tag (any, or {Float, bool, etc..} ) and the value will be always the same (more the first tag). In others words, and if I don't say bullshits, it works only with mono-tag, and tagof has to used inside the function.
__________________

Last edited by Arkshine; 09-10-2011 at 15:22.
Arkshine is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-10-2011 , 15:13   Re: Array Copy Stock
Reply With Quote #19

Quote:
Originally Posted by Emp` View Post
That's up to you, I was just showing how I would make it.
I think I'm going to agree with you and keep it out. It will return 0, so there will be a way to know if your loop did not work.
__________________

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]
Tirant is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-10-2011 , 15:21   Re: Array Copy Stock
Reply With Quote #20

Quote:
Originally Posted by Arkshine View Post
Did you test your stock ? Because I'm doing some tests just by curiosity, and by using tagof in the header will result 0 always or using multi-tag (any, or {Float, bool, etc..} ) and the value will be always the same. In others words, and if I don't say bullshits, it works only with mono-tag, and tagof has to used inside the function.
Ah, it does seem to bugger up when used as a default value for a parameter. I thought it might work like sizeof/charsmax.

However, this works fine:
Code:
arraycopy( copyarray, initarray, sizeof copyarray, .intotag = tagof copyarray, .fromtag = tagof initarray );
The only way I see it working well is by using a macro to auto fill the required info.

Something like:
Code:
#define array_copy(%1, %2, %3) arraycopy( %1, %2, %3, .intotag = tagof %1, .fromtag = tagof %2 )
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Reply



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 18:12.


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