It is currently Sat Aug 22, 2020 2:02 pm


All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Voxels inserted only when they differ from the existing ones
PostPosted: Sat Apr 09, 2011 3:49 pm 

Joined: Thu Mar 10, 2011 10:34 am
Posts: 19
Every time you try to save a voxel by setVoxelAt function, polyvox checks if the voxel was actually modified before effectively saving it.
Don't you think it's a bit wasteful doing this kind of check instead of just writing the data back to the volume?

I mean, I know that probably some work must be done and it could be avoided if the voxel wasn't changed, but I guess most of the time the voxel is just gonna be saved because if the programmer called that function, he meant to _do_ some modifications. Doing all of those checks might waste some CPU time and HELL, I SPENT HALF AN HOUR LOOKING FOR A BUG JUST BECAUSE MY OPERATOR == WAS NOT KEEPING INTO ACCOUNT ONE VARIABLE OF THE STRUCT :P (sorry for the little rant :D)

My voxels store one quantity (let's say, "how much stuff is in there") and the kind of voxel (for example, air, oil, water). What happened is that the volume wasn't updating because the operator == was not checking for the "how much stuff" variable, but just for the "what is in there" one.

Apart from me being a bit "stupid", I think that just straight copying might work just better and faster. Any thoughts?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxels inserted only when they differ from the existing
PostPosted: Sun Apr 10, 2011 6:20 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
The behaviour you describe was only in the old version of the Volume class - it has already been removed from the new version supporting RLE/paging. That said, there was some good logic behind the mechanism, as described by a comment in the code:

Code:
//It's quite possible that the user might attempt to set a voxel to it's current
//value. We test for this case firstly because it could help performance, but more
//importantly because it lets us avoid unsharing blocks unnecessarily.


The point is that the old system would allow several different blocks to point at the same area of memory if their contents were identical (usually for homogenous and/or empty blocks). Hence setting a voxel could have some cost as the blocks would no longer be identical and so would have to be unshared/duplicated.

But overall it wasn't a great system , which is why it was replaced by the RLE stuff.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


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
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net