PnP TerrainCreator - Forum

The PnP TerrainCreator Forum
It is currently Sun Sep 24, 2017 5:45 pm

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Raw input plugin
PostPosted: Sun Oct 22, 2006 11:53 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
Experimenting, I tried this in the raw input plugin:
bool xx_b = true;
xx_b = Terrain.SetDefMapHeight(nX,nY,fHeight);

fHeight = Terrain.GetDefMapHeight(nX, nY);

The SetDef.. returns false, while the GetDef.. returns a value (>0). So why can I not set the height? Also, the .h file say nX & nY are in the range 0 to the number of x/y sectors, not #elements*#sectors x/y??? I am assuming nX/nY are elements in the complete terrain definition and not in a specific sector??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:26 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Well currently the importer only allows you to change the heightmap of the sector's detail on which you invoked the import plugin. The definition map in the range of this sector will be updated automatically, as soon as the import plugin finishes.

Changes to the definition map can only be made as long as no sector detail is opened. So from the current importer implementation there is no way to achieve this. Until we implemented import for the whole terrain, there is a workaround: You could use the height map generator interface, with which you can access/change the heightmap of all terrain sectors.

The docs say nX/Ny is in the range "0 to (GetNumSectorsX/Y() * GetSectorDefinitionBorderSize() - 1)". So it is, as you expected, the complete terrain.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 4:47 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
I stuck this in the raw input pluging:

bool CPnPTCRAWHMapImportPlugIn::ReadSector(CIPnPTCApplication01& App,CIPnPTCSector01& Sector,CIPnPTCTerrain01& Terrain,std::string Filename,int iFormat,float fOffset,float fFactor)
{
// open the file to be read
FILE* f=fopen(Filename.c_str(),"rb");
if (!f)
{
static char cMessage[1000];
sprintf(cMessage,"The file '%s'\ncould not be opened for reading.",Filename.c_str());
MessageBox(NULL,cMessage,"Error importing sector heightmap",MB_ICONSTOP|MB_TASKMODAL|MB_OK);
return false;
}

// get file size
fseek(f,0,SEEK_END);
long lFileSize=ftell(f);
fseek(f,0,SEEK_SET);

// get sector border size
unsigned int nBorderSize=Sector.GetBorderSize();

// get data element size
DWORD dwElementSize=GetRAWDataSize(iFormat);

//gw

//unsigned int size = Terrain.GetSectorDefinitionBorderSize();

unsigned int num_x_sectors_ui = 0;
num_x_sectors_ui = Terrain.GetNumSectorsX();

unsigned int num_y_sectors_ui = 0;
num_y_sectors_ui = Terrain.GetNumSectorsY();

unsigned int num_sectors_ui = num_x_sectors_ui*num_x_sectors_ui;

unsigned int num_sector_elements_ui = Sector.GetBorderSize();

unsigned long total_num_elements_ui = num_sector_elements_ui*num_sectors_ui;

unsigned long total_num_hmap_bytes = total_num_elements_ui*dwElementSize;


unsigned int sec_x_ui = 0;
unsigned int sec_y_ui = 0;

for(sec_x_ui=0; sec_x_ui<num_x_sectors_ui; sec_x_ui++)
{
for(sec_y_ui=0; sec_y_ui<num_y_sectors_ui; sec_y_ui++)
{
CIPnPTCSectorDefinition01* sector_def = Terrain.GetSectorDefinition(sec_x_ui,sec_y_ui);

CIPnPTCSector01* sector_det = sector_def->GetSectorDetail();


int maxi = sector_det->GetMaxXIndex();
unsigned int xs = 1023;
unsigned int ys = 1023;
float ht = sector_det->GetHeight(xs, ys);
bool ret = sector_det->SetHeight(xs,ys,45.0);
ht = sector_det->GetHeight(xs,ys);

}
}

//gw restore the original sector detail.

CIPnPTCSectorDefinition01* sector_def = Terrain.GetSectorDefinition(0,0);

CIPnPTCSector01* sector_det = sector_def->GetSectorDetail();

return true;

The loop seems to work to set the height. I had to add the restore so that the return from the dll does not generate an access violation. It works on a 3x3 sector terrain. However, on a larger terrain, when it gets to the 5,8 sector, windows stops it, complaining of possible heap problems.

I know I am "hacking" in this stuff, but it seems as if getting a new sector detail and/or sector definition leaves memory not freed. I am not surprised as you may not have intended for the sequential opening of sector data. Anyway, just to ask you if there might be a bug? Or, if there is unfreed memory, and you could add to free it?? Or, is this a dead end??
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 6:39 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Difficult to say, if this could possibly work. I'd again suggest to use the generator interface at the moment. But I'll take a look why it isn't working.

But I found a bug in your code. You wrote:

Code:
unsigned int num_sectors_ui = num_x_sectors_ui*num_x_sectors_ui;


And it should be:

Code:
unsigned int num_sectors_ui = num_x_sectors_ui*num_y_sectors_ui;


x*y not x*x

Don't know what for you need that value. But it might be a reason why it doesn't work on a not squared (5x8) terrain.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 11:31 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
I'm sure I posted a reply, but its not there so I'll do it over.

The line in error is an old test and not used, but thanks for pointing out the error.

The SetHeight returns true and the following GetHeight returns the new value, so I believe the detail map is being changed. However, the heap problem occurs after some number of calls to get the next sector def and sector detail. So, I am assuming that once a sector is "opened", it is not "closed" until the dll exits, or some such. If there is no "bug", perhaps there could be optional arguments for the functions to specify to close the current/all sectors before returning the requested sector def / detail???

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 8:35 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Actually, the program should automatically close the currently opened sector, when a new sector is opened. That's why you have to reopen the first sector again, when you are done reading the whole terrain (I'm not sure if this has any chance to work correctly, as the pointer value will be changed most likely. So there would surely be a crash, but I could work around that by rereading the pointer value)

However, it should be possible to open all sectors consecutively. So I'll take a look at that, as it might affect other plugins as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:08 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
I added a detail.Save() before entering my loop over sectors, and a save() after setting the heightmap in each sector. I also removed the re-opening of the original sector before exiting, and so far, it has not crashed on exit. The issue of how many sectors I can do at one time without a heap problem, still exists.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 28, 2006 9:52 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
I tried saving the neighbor sectors after saving each changed sector and, at least once I was able to map 65 sectors before a heap error. This, of course may be coincidental. The error I get is:
HEAP[PnPTerrainCreator.exe]: HEAP: Free Heap block b0390e0 modified at b03c0c0 after it was freed.

I seem to be able to map at least 36 sectors before an error, so running it 4 times will allow me to map my 11x11 sector terrain. However, it would be good to be able to map nxn sectors without error. So, if you would look into it sometime...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 2:30 am 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
So, I tried a stripped down version of the diamond creation routine to just go through the sectors and and set the values to 0 without the diamond etc. calculations. After few sectors, I got the heap error.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 12:13 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
I can confirm this beeing a bug in the main program's sector management. Should be no problem to fix it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 4:39 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
Good. I have a 11x11 sector (1024x1024 bits per sector) photoshop greyscale image to give me a base terrain layout as a starting point. I will wait for you to fix up the sector code before continuing with my code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 5:24 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
Another thing. It would be good to have an overloaded GetSectorDetail() function (or opptional bool arg) to open a sector and not the neighbor sectors.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 1:27 am 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
Ralf wrote:
I can confirm this beeing a bug in the main program's sector management. Should be no problem to fix it.

Any progress???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 9:07 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Well, yes.

That problem is solved. But I cannot release a new version yet, because before I fixed that bug, I changed the complete 2D heightmap display in order to make water visible in 2D. And there are a few instabilities, which I have to solve before releasing a new version.

But I think, I could manage that on the week end.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 11:51 pm 
Offline

Joined: Tue Sep 26, 2006 10:18 pm
Posts: 142
Location: Northern California
No hurry, I was just wondering how it was going.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron