Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Difference between objptr and objgetid? #324

@Fighter19

Description

@Fighter19

In the example code, objptr is used like this:

    // prepare new object
    if (objNew(type, xp, yp) == 0)
        // no more space, get out
        return;

    // Init some vars for snes sprite (objgetid is the current object id)
    objGetPointer(objgetid);
    newobject = &objbuffers[objptr - 1];

The documentation for objNew states, that objgetid will have the ID, after the call.
objGetPointer states the handle needs to be offset by "-1", after which objptr will have the pointer.

Now I'm a bit confused, why it's necessary to use the objptr to obtain a pointer.
Shouldn't it be the pointer already according to documentation?

And if no, what's the difference between objptr and objgetid?

The assembly code also shifts the id to obtain id * sizeof(t_obj), so it's one more reason why I'd expect objptr to be t_obj* already.

EDIT:
To be clear what I wanted to ask:
Shouldn't the example read:

    // prepare new object
    if (objNew(type, xp, yp) == 0)
        // no more space, get out
        return;

    // Init some vars for snes sprite (objgetid is the current object id)
    objGetPointer(objgetid);
    newobject = objptr;

to make any sense?

Otherwise I don't see how objgetid and objptr are in any way different.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions