2013-08-04 07:25:48 -04:00
|
|
|
|
|
|
|
// BlockTracer.h
|
|
|
|
|
|
|
|
// Declares the classes common for all blocktracers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-11 08:34:36 -04:00
|
|
|
#include "Defines.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
// fwd: World.h
|
|
|
|
class cWorld;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockTracer abstract
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** The callback class is used to notify the caller of individual events that are being traced.
|
|
|
|
*/
|
|
|
|
class cCallbacks abstract
|
|
|
|
{
|
|
|
|
public:
|
2014-04-02 10:39:42 -04:00
|
|
|
// Force a virtual destructor in descendants:
|
|
|
|
virtual ~cCallbacks() {}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called on each block encountered along the path, including the first block (path start)
|
|
|
|
When this callback returns true, the tracing is aborted.
|
|
|
|
*/
|
2017-05-11 08:34:36 -04:00
|
|
|
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) = 0;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called on each block encountered along the path, including the first block (path start), if chunk data is not loaded
|
|
|
|
When this callback returns true, the tracing is aborted.
|
|
|
|
*/
|
2014-07-17 10:33:09 -04:00
|
|
|
virtual bool OnNextBlockNoData(int a_BlockX, int a_BlockY, int a_BlockZ, char a_EntryFace)
|
|
|
|
{
|
2013-12-22 09:55:24 -05:00
|
|
|
UNUSED(a_BlockX);
|
|
|
|
UNUSED(a_BlockY);
|
|
|
|
UNUSED(a_BlockZ);
|
|
|
|
UNUSED(a_EntryFace);
|
2014-07-17 10:33:09 -04:00
|
|
|
return false;
|
2013-12-22 09:55:24 -05:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called when the path goes out of world, either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height)
|
|
|
|
The coords specify the exact point at which the path exited the world.
|
|
|
|
If this callback returns true, the tracing is aborted.
|
|
|
|
Note that some paths can go out of the world and come back again (parabola),
|
|
|
|
in such a case this callback is followed by OnIntoWorld() and further OnNextBlock() calls
|
|
|
|
*/
|
2014-07-17 10:33:09 -04:00
|
|
|
virtual bool OnOutOfWorld(double a_BlockX, double a_BlockY, double a_BlockZ)
|
|
|
|
{
|
2013-12-22 09:55:24 -05:00
|
|
|
UNUSED(a_BlockX);
|
|
|
|
UNUSED(a_BlockY);
|
|
|
|
UNUSED(a_BlockZ);
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called when the path goes into the world, from either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height)
|
|
|
|
The coords specify the exact point at which the path entered the world.
|
|
|
|
If this callback returns true, the tracing is aborted.
|
|
|
|
Note that some paths can go out of the world and come back again (parabola),
|
|
|
|
in such a case this callback is followed by further OnNextBlock() calls
|
|
|
|
*/
|
2014-07-17 10:33:09 -04:00
|
|
|
virtual bool OnIntoWorld(double a_BlockX, double a_BlockY, double a_BlockZ)
|
|
|
|
{
|
2013-12-22 09:55:24 -05:00
|
|
|
UNUSED(a_BlockX);
|
|
|
|
UNUSED(a_BlockY);
|
|
|
|
UNUSED(a_BlockZ);
|
2014-07-17 10:33:09 -04:00
|
|
|
return false;
|
2013-12-22 09:55:24 -05:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called when the path is sure not to hit any more blocks.
|
|
|
|
Note that for some shapes this might never happen (line with constant Y)
|
|
|
|
*/
|
|
|
|
virtual void OnNoMoreHits(void) {}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
/** Called when the block tracing walks into a chunk that is not allocated.
|
|
|
|
This usually means that the tracing is aborted.
|
|
|
|
*/
|
|
|
|
virtual void OnNoChunk(void) {}
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Creates the BlockTracer parent with the specified callbacks */
|
2013-08-04 07:25:48 -04:00
|
|
|
cBlockTracer(cWorld & a_World, cCallbacks & a_Callbacks) :
|
|
|
|
m_World(&a_World),
|
|
|
|
m_Callbacks(&a_Callbacks)
|
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Sets new world, returns the old one. Note that both need to be valid */
|
2013-08-04 07:25:48 -04:00
|
|
|
cWorld & SetWorld(cWorld & a_World)
|
|
|
|
{
|
|
|
|
cWorld & Old = *m_World;
|
|
|
|
m_World = &a_World;
|
|
|
|
return Old;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Sets new callbacks, returns the old ones. Note that both need to be valid */
|
2013-08-04 07:25:48 -04:00
|
|
|
cCallbacks & SetCallbacks(cCallbacks & a_NewCallbacks)
|
|
|
|
{
|
|
|
|
cCallbacks & Old = *m_Callbacks;
|
|
|
|
m_Callbacks = &a_NewCallbacks;
|
|
|
|
return Old;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
protected:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The world upon which to operate */
|
2013-08-04 07:25:48 -04:00
|
|
|
cWorld * m_World;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The callback to use for reporting */
|
2013-08-04 07:25:48 -04:00
|
|
|
cCallbacks * m_Callbacks;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|