Single block data storage
#13
Long story short: there can't be such a method, due to multithreading. I'll elaborate in a while (edit this post)
Imagine there was a GetBlockEntity() method (it used to be there Wink
Now, thread A calls the method, and it returns the block entity for given coords.
In the meantime, thread B receives a packet from a player that they have finished mining block at those exact same coords. Thread B calls cWorld::DigBlock() and the block entity is destroyed.
Now thread A has a pointer to a dead block entity, crashing the server when it tries to do anything with that pointer.

The same situation was with players and other entities.

The solution to this madness was to provide generic functions DoWithXYZ() that make your callback code execute while the respective object is locked and cannot be touched by any other thread (Java calls this Synchronized, I believe). If you need to address all objects of the kind in the chunk, there's also a cWorld::ForEachXYZInChunk() method that calls the callback for each object.

However, writing such callbacks is a major pain in the a**, so there are some utility functions that provide often-used functionality, such as GetSignLines() (and I expect more to come sooner or later)
Reply
Thanks given by: l0udPL


Messages In This Thread
Single block data storage - by l0udPL - 08-11-2012, 08:24 PM
RE: Single block data storage - by xoft - 08-11-2012, 08:57 PM
RE: Single block data storage - by l0udPL - 08-13-2012, 04:59 AM
RE: Single block data storage - by NiLSPACE - 08-13-2012, 05:00 AM
RE: Single block data storage - by l0udPL - 08-13-2012, 05:14 AM
RE: Single block data storage - by NiLSPACE - 08-14-2012, 12:36 AM
RE: Single block data storage - by l0udPL - 08-27-2012, 03:16 AM
RE: Single block data storage - by xoft - 08-27-2012, 03:53 AM
RE: Single block data storage - by Lapayo - 08-29-2012, 03:38 AM
RE: Single block data storage - by l0udPL - 08-29-2012, 04:04 AM
RE: Single block data storage - by xoft - 08-29-2012, 04:35 AM
RE: Single block data storage - by l0udPL - 08-29-2012, 04:48 AM
RE: Single block data storage - by xoft - 08-29-2012, 04:55 AM
RE: Single block data storage - by l0udPL - 08-29-2012, 07:20 AM
RE: Single block data storage - by xoft - 08-29-2012, 08:02 AM



Users browsing this thread: 3 Guest(s)