[Plugin] RL_FILES - makes your life easy
#21

Quote:
Originally Posted by Gamer_Z
View Post
1) Please delete .SDF files from source code and .PCH files and (ipc,Debug,Release) directories, this will make redistribution smaller and faster.

2) This:

Here, I made some code for you while playing around in my plugin:
pawn Code:
namespace Natives
{
    //native TwoDArrayFunction(array[][],size_a = sizeof(array),size_b = sizeof(array[]));
    static cell AMX_NATIVE_CALL TwoDArrayFunction( AMX* amx, cell* params )
    {
        cell *dest = NULL;
        amx_GetAddr(amx,params[1],&dest);

        for(int a = params[2], b = a+(params[2]*params[3]); a < b; ++a)
        {
            std::cout << dest[a] << std::endl;
        }
        return 1;
    }
    //native ThreeDArrayFunction(array[][][],size_a = sizeof(array),size_b = sizeof(array[]),size_c = sizeof(array[][]));
    static cell AMX_NATIVE_CALL ThreeDArrayFunction( AMX* amx, cell* params )
    {
        cell *dest = NULL;
        amx_GetAddr(amx,params[1],&dest);

        for(int a = (params[2]*params[3])+params[2], b = a+(params[2]*params[3]*params[4]); a < b; ++a)
        {
            std::cout << dest[a] << std::endl;
            //dest[a] = 0;//modify array
        }
        return 1;
    }
    //native SomeStringfunc(array[][],size_a = sizeof(array),size_b = sizeof(array[]));
    static cell AMX_NATIVE_CALL SomeStringfunc( AMX* amx, cell* params )
    {
        cell *dest = NULL;
        amx_GetAddr(amx,params[1],&dest);

        for(int a = params[2], b = a+(params[2]*params[3]); a < b; a+=params[3])
        {
            //std::cout << dest[a] << std::endl;
            amx_SetString(&dest[a],"This is a test string\0",0,0,strlen("This is a test string\0")+1);
        }
        return 1;
    }
    AMX_NATIVE_INFO AMXNatives[ ] =
    {
        {"TwoDArrayFunction", TwoDArrayFunction},
        {"ThreeDArrayFunction", ThreeDArrayFunction},
        {"SomeStringfunc", SomeStringfunc},
        {0,                0}
    };
};//namespace Natives
usage:

pawn Code:
#include <a_samp>

native TwoDArrayFunction(array[][],size_a = sizeof(array),size_b = sizeof(array[]));
native ThreeDArrayFunction(array[][][],size_a = sizeof(array),size_b = sizeof(array[]),size_c = sizeof(array[][]));
native SomeStringfunc(array[][],size_a = sizeof(array),size_b = sizeof(array[]));
/*
enum ArrayStuff7
{
    SomeStuff7[7]
};

enum ArrayStuff5
{
    SomeStuff5[5]
};
*/

public OnFilterScriptInit()
{
    new array1[3][5];
    //new array2[3][ArrayStuff5];
    new array3[3][5][7];
    //new array4[3][5][ArrayStuff7];
    for(new a = 0,b,c,z=0,y=0; a < 3; ++a)
    {
        for(b = 0; b < 5; ++b)
        {
            array1[a][b] = z;
            //array2[a][SomeStuff5][b] = z;
            ++z;
            //printf("2)[%d][%d] = (%d)",a,b,array2[a][b]);
            for(c = 0; c < 7; ++c)
            {
                array3[a][b][c] = y;
                //array4[a][b][SomeStuff7][c] = y;
                //printf("3)[%d][%d] = (%d)",a,b,array3[a][b][c]);
                ++y;
            }
        }
    }
    printf("done");
    TwoDArrayFunction(array1);
    //TwoDArrayFunction(array2);
    ThreeDArrayFunction(array3);
    //ThreeDArrayFunction(array4);
    new strings[10][256];
    SomeStringfunc(strings);
    for(new i = 0; i < 10; ++i)
        print(strings[i]);
    return 1;
}


as for the "int a = (params[2]*params[3])+params[2])" , I don't understand why amx_GetAddr isn't pointing to the array start but some weird values, maybe array information? Dunno, but this is the right way to loop all possible multidimensional arrays. array[][][][] is not possible so don't worry.

Now you can make a function like PutAllDirectoryFilesInArray(directory[],contents[][]); and PutAllDirectoryDirectoriesInArray(directory[],contents[][]);

3)if you really want to make these functions, here is a detailed design/code info:

Each array has a limited size, so, if there are 50,000 files in a directory and the array size is only able to hold 100 strings, then we only assign the first 100 files, but suppose we want to assign file indexes 100 to 200, then we need to know an index, so our function definition will look like:

native RetrieveFileList(directory[],array[][],&returned_files=0,&index=0,size_a = sizeof(array),size_b = sizeof(array[]));

Our function in the plugin would look like this then (pseudocode):

pawn Code:
//native RetrieveFileList(directory[],array[][],&returned_files=0,&index=0,size_a = sizeof(array),size_b = sizeof(array[]));
    static cell AMX_NATIVE_CALL TwoDArrayFunction( AMX* amx, cell* params )
    {
        char* DirectoryToLoop;

        cell * index = NULL;
        amx_GetAddr(amx,params[4],&index);
        cell *returned_files = NULL;
        amx_GetAddr(amx,params[3],&returned_files);

        returned_files = 0;

        amx_StrParam(amx, params[1], DirectoryToLoop);
        if(!DirectoryToLoop)
            DirectoryToLoop = ".";
        if(index < 0)
            return false;

        cell *dest = NULL;
        amx_GetAddr(amx,params[1],&dest);

        int ArrayIdxStart = params[5];
        int ArrayStep = params[6];
        int ArrayMax = ArrayIdxStart+(ArrayIdxStart*ArrayStep);
       
        int LoopsDone = 0;

        int WriterPosition = 0;
        foreach(|file| in {DirectoryToLoop}, start looping files at {index})
        {
            WriterPosition = ArrayIdxStart+(ArrayStep*LoopsDone);
            if(WriterPosition < ArrayMax)
            {
                amx_SetString(&dest[ArrayIdxStart+(ArrayStep*LoopsDone)],file,0,0,strlen(file)+1);
            }
            else
            {
                index = index+(LoopsDone);
                returned_files = (LoopsDone+1);
                return (|files in directory| - index);//we still have files to loop
            }
            ++LoopsDone;
        }

        return 0;//no more files to loop
    }
Usage:

pawn Code:
#include <a_samp>
native RetrieveFileList(directory[],array[][],&returned_files=0,&index=0,size_a = sizeof(array),size_b = sizeof(array[]));

new MyArrayOfFiles[32][267];

public OnFilterScriptInit()
{
    //print all files in directory "./scriptfiles/"
    new index = 0;
    new FilesReturned = 0;
    while(RetrieveFileList("./scriptfiles/",MyArrayOfFiles,FilesReturned,index))
    {
        for(new i = 0; i < FilesReturned; ++i)
        {
            print(MyArrayOfFiles[i]);
        }
    }
    return 1;
}
Wow! Awesome, I will include it new version!
Reply
#22

Quote:
Originally Posted by Swimor
View Post
Wow! Awesome, I will include it new version!
btw, added 2 lines:

pawn Code:
}
        index = index+(LoopsDone-1);
        returned_files = (LoopsDone);
        return 0;//no more files to loop
    }
Reply
#23

Quote:
Originally Posted by Gamer_Z
View Post
btw, added 2 lines:

pawn Code:
}
        index = index+(LoopsDone-1);
        returned_files = (LoopsDone);
        return 0;//no more files to loop
    }
Seems like only one problem to fix and I will release new version with farray.

Btw, I will change this ti RL_DIRETORIES and I will build some directories function.
Reply
#24

Updated!
new version 1.3.1 now available!
* Some new options are added to the plugin.
Reply
#25

Great work man. How about some benchmarks?
Reply
#26

Quote:
Originally Posted by Ballu Miaa
View Post
Great work man. How about some benchmarks?
I will add some benchmarks on the next update.

Now I working on performance improvement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)