Need a better method.
#1

I'm trying to get into the habit of optimizing my code. Or at least more optimized than in the past.

I've created a little script that stores replacement object textures for later use.

pawn Код:
#define MAX_OBJECT_TEXTURE_TYPES                                              20
#define MAX_OBJECT_TEXTURE_INDEX                                               4

new texture_file[][] =
{
    {"lsmall_shops"},
    {"mattextures"}
};

new texture[][] =
{
    {"shop_floor1"},
    {"mp_diner_wood"},
    {"SAMPBlack"}
};

enum
{
    TXT_OBJ_RAMP1,
    TXT_OBJ_ROAD1,
}

enum OBJECT_TEXTURE_DATA
{
    Type,
    TextureModel,
    TXTFileIndex,
    TextureIndex,
    Color
};

new g_ObjectTextureData[MAX_OBJECT_TEXTURE_TYPES][OBJECT_TEXTURE_DATA][MAX_OBJECT_TEXTURE_INDEX + 1];

stock AddTexturedObject(type, index, texture_model, txt_file_index, texture_index, color)
{  
    if (type < 0 || type > MAX_OBJECT_TEXTURE_INDEX) return 0;
    g_ObjectTextureData[type][TextureModel][index] = texture_model;
    g_ObjectTextureData[type][TXTFileIndex][index] = txt_file_index;
    g_ObjectTextureData[type][TextureIndex][index] = texture_index;
    g_ObjectTextureData[type][Color][index] = color;
    return 1;
}

CrateTexturedObject(model, type, Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz, Float:viewdistance = 300.0)
{
    new objectid = CreateObject(model, x, y, z, rotx, roty, rotz, viewdistance);
    for (new i; i <= MAX_OBJECT_TEXTURE_INDEX; i ++)
    {
        if (g_ObjectTextureData[type][TextureModel][i] != 0)
        {
            SetObjectMaterial(  objectid,
                                i,
                                g_ObjectTextureData[type][TextureModel][i],
                                texture_file[ g_ObjectTextureData[type][TXTFileIndex][i] ],
                                texture[ g_ObjectTextureData[type][TextureIndex][i] ],
                                g_ObjectTextureData[type][Color][i]);          
        }
    }
}
As you can probably see, rather than store each texture name as a string, I've created two small arrays that hold the txt files names and the texture name and stored the array slot that will later point to the required texture name in the array. I don't mind doing it like this but after some time, adding new groups of textures becomes slow and defeats the point in doing it like this.

What I would like is a better way of storing and loading the data, which I'm sure there is.

I also need to find the fastest way of applying the stored textures to the object. I'm not sure if it can be any faster than the way I have it, without removing the loop.

0.3e has got me back into scripting but I seem to have forgot a lot of the basics. I know in the back of my head how to do it and probably would figure out a better way eventually but I need this rather quickly.

Also, If you could pick out any faults or let me know how you would do this, please do!

Any help is appreciated, Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)