My fancy gE

You must understand the Game Editor concepts, before post here.

My fancy gE

Postby bat78 » Fri Aug 07, 2015 1:21 am

I know quite a lot bizarre tricks, but will occasionally list some of them.

1. Access actor's clone name through name
You can get the clone name of arbitrary actor through name just as if you were using clonename instead.
All simply by virtue of some inferior pointer arithmetic:
Code: Select all
sprintf(text, "My text actor's clone name is: %s", name + 33);

There is nothing much to explain. This is a matter of structure alignment / packing and since name is an offset address of statically allocated array of chars to represent the actor's name, 33 bytes forwards will aways reach the offset address of the clone name.

Could be useful:
If any of us have some time, we can create macros to represent pointer arithmetic to any of the Actor members.
With that, we can get rid of the nasty gE bug with being unable to access actor's property members unless with getclone.
(I already have a good idea of how to imply it)

2. Function to save/load actor state to/from file.
No more confusing and needless to say slow gE variable declaration using the gE built-in save system. Now you can automatically save or load unique data for all actors. With this, you can recover actor state from previous game just with one function call. Put this in global code:
Code: Select all
#define ACTOR_SAVE (0x1)
#define ACTOR_LOAD (0x2)
#define OFFSET_OF_CLONENAME name + 0x21
#define STRINGIFY(s) #s

void ActorState (const char cloneName [], const int action)
    Actor* aPtr;
    FILE*  fPtr;
    if(action != ACTOR_SAVE && action != ACTOR_LOAD) return();
    if(action == ACTOR_SAVE)
        aPtr  = getclone( cloneName );
        fPtr  = fopen   ( aPtr->OFFSET_OF_CLONENAME , STRINGIFY(wb) );
        if(fPtr) fwrite(aPtr, 1, sizeof(Actor), fPtr);
    fPtr = fopen   ( cloneName, STRINGIFY(rb) );
    aPtr = getclone( cloneName );
    if(fPtr) fread(aPtr, 1, sizeof(Actor), fPtr);

To save actor, just do this:
Code: Select all
ActorState(clonename, ACTOR_SAVE); // or actor.clonename where actor is the name of the actor you wish to save

To load the actor:
Code: Select all
ActorState(clonename, ACTOR_LOAD); // or actor.clonename where actor is the name of the actor you wish to load
Future of "Project Game-Editor Revival" here
User avatar
Posts: 790
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 83 Give a positive score

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest