简体   繁体   中英

I am trying to understand these 2 blocks of code, could someone help please?

I am trying to understand some code and I was hoping someone could give me a basic overview of what this code means. The first bit of code I don't understand is this:

// loading file path
static string resourceRoot;
#define RESOURCE_PATH(p)  (char*)((resourceRoot+"/"+string(p)).c_str())

The second bit of code I am trying to fully understand is this:

void Draw::loadMeshFromFile(cMesh* mesh,string name)
{
    bool fileload;
    resourceRoot = m_Path.toStdString();
    string str1 = "Head/";
    string str2 = ".3ds";
    fileload = mesh->loadFromFile(str1+name+str2);
    if(!fileload)
    {
        printf("Error - 3D Model failed to load correctly.\n");
        return;
    }

Any help would be truly appreciated. I am trying to strengthen my programming, so I'd be glad for any response. Thanks

The first part is a macro which helps you to create a path for a specified resource, relative yo some root resource path, you can set in your code.

You basically would use it like this:

static string resourceRoot;
#define RESOURCE_PATH(p) (resourceRoot+"/"+string(p))

void load(cMesh* mesh)
{
    // Probably set somewhere else
    resourceRoot = "/opt/resources";

    mesh->loadFromFile(RESOURCE_PATH("relarespath/myresource").c_str());
}

or

void load(cMesh* mesh)
{
    // Probably set somewhere else
    resourceRoot = "/opt/resources";

    string myresourcename = RESOURCE_PATH("relarespath/myresource");
    mesh->loadFromFile(myresourcename.c_str());
}

Since accessing the pointer in the original code is potentially dangerous, I removed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM