About Store Forum Documentation Contact



Post Reply 
Delete / Create Objects in Editor Code
Author Message
Gian-Reto Offline
Member

Post: #1
Delete / Create Objects in Editor Code
I'm trying to modify my custom Editor mode so that I can place Terrain Objects automatically from code.

Is there any good tutorial about the proper way to delete / add objects like in the editor, but from code (with heightmap aligning, random angle and so on)?

Can I use the tutorials for the Ingame Objects deletion / creation?


Thanks in advance for any help


Gian-Reto
(This post was last modified: 02-14-2013 06:17 PM by Gian-Reto.)
02-14-2013 06:17 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Delete / Create Objects in Editor Code
Hi,

did you check at World Editor's methods:

void objDelete( ); // delete selected objects
void objCreate(C Vec &pos, Game::ObjParams *force_params=NULL); // create object at 'pos' world position, 'force_params'=if create object from custom parameters (if set to NULL, then it will be set according to current object selection)
02-27-2013 03:12 PM
Find all posts by this user Quote this message in a reply
Gian-Reto Offline
Member

Post: #3
RE: Delete / Create Objects in Editor Code
Hi Esenthel

No I didn't... somehow didn't found them. I'll try it out immediatly.

Thanks in advance


Gian-Reto
03-05-2013 10:56 PM
Find all posts by this user Quote this message in a reply
Gian-Reto Offline
Member

Post: #4
RE: Delete / Create Objects in Editor Code
Okay, it seems I still do something wrong.

What I try to at the moment is clearing my world from all embeded objects to automatically place them in a second step.

To achieve that I loop trough all areas, selecting all the embeded objects and deleting them:

Code:
void cleanTerrainObjects () {
    for (Int iteratorTX = -32; iteratorTX <= 32; iteratorTX++) {
        for (Int iteratorTY = -32; iteratorTY <= 32; iteratorTY++) {
            
            Edit::Area *area = Edit::World.grid.get(VecI2(iteratorTX,iteratorTY))->data();
            
            for (Int i = area->objs()-1; i >= 0; i--) {
                Edit::Obj obj = area->obj(i);
                if (obj.access() == Game::ACCESS_EMBED) {
                    area->setChanged();        
                    Edit::World.objSelSelect(&obj);
                    Edit::World.objDelete();
                    area->hmChanged();
                }
            }
        }
    }
}

I get an Exception in "EditStateUpdate" it seems. It happens after the code above has run and the Method it is in has ended (this Method gets called by the method bound to a button in the custom edit mode, but this Method is empty besides the Method call at the moment).

I assume some of the code written above must somehow cause this.... because the Exception happens at the end of the calling MEthod, and no other code is in it.


Anyway, one step further.

Gian-Reto

EDIT:

Got it working after some debugging. I'm not 100% why the first version didn't work, but being the C++ noob and Java-Code-Monkey that I am, I probably did something really stupid when I assigned the object. Pointers, oh the horror! wink

Code:
void cleanTerrainObjects () {
    for (Int iteratorTX = -32; iteratorTX <= 32; iteratorTX++) {
        for (Int iteratorTY = -32; iteratorTY <= 32; iteratorTY++) {
            
            Edit::Area *area = Edit::World.grid.get(VecI2(iteratorTX,iteratorTY))->data();
            
            for (Int i = area->objs()-1; i >= 0; i--) {
                //Edit::Obj foundObject = area->obj(i);
                if (area->obj(i).access() == Game::ACCESS_EMBED) {
                    area->setChanged();        
                    Edit::World.objSelSelect(&area->obj(i));
                    Edit::World.objDelete();
                    area->hmChanged();
                }
            }
        }
    }
}

Now onwards to creating the objects...
(This post was last modified: 03-22-2013 01:37 PM by Gian-Reto.)
03-06-2013 06:04 PM
Find all posts by this user Quote this message in a reply
Post Reply