Skip to content

Commit

Permalink
Unified the doxy-comment format.
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxoft committed Jul 31, 2015
1 parent 41d7119 commit 6e4122e
Show file tree
Hide file tree
Showing 114 changed files with 869 additions and 850 deletions.
129 changes: 71 additions & 58 deletions src/AllocationPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <memory>





template <class T>
class cAllocationPool
{
Expand All @@ -12,100 +16,109 @@ class cAllocationPool
public:
virtual ~cStarvationCallbacks() {}

/** Is called when the reserve buffer starts to be used **/
/** Is called when the reserve buffer starts to be used */
virtual void OnStartUsingReserve() = 0;

/** Is called once the reserve buffer has returned to normal size **/
/** Is called once the reserve buffer has returned to normal size */
virtual void OnEndUsingReserve() = 0;

/** Is called when the allocation pool is unable to allocate memory. Will be repeatedly
called if it does not free sufficient memory **/
called if it does not free sufficient memory */
virtual void OnOutOfReserve() = 0;
};

virtual ~cAllocationPool() {}

/** Allocates a pointer to T **/
/** Allocates a pointer to T */
virtual T * Allocate() = 0;

/** Frees the pointer passed in a_ptr, invalidating it **/
/** Frees the pointer passed in a_ptr, invalidating it */
virtual void Free(T * a_ptr) = 0;
};





/** Allocates memory storing unused elements in a linked list. Keeps at least NumElementsInReserve
elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/
elements in the list unless malloc fails so that the program has a reserve to handle OOM. */
template <class T, size_t NumElementsInReserve>
class cListAllocationPool : public cAllocationPool<T>
class cListAllocationPool:
public cAllocationPool<T>
{
public:
public:

cListAllocationPool(std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> a_Callbacks) :
m_Callbacks(std::move(a_Callbacks))
cListAllocationPool(std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> a_Callbacks):
m_Callbacks(std::move(a_Callbacks))
{
for (size_t i = 0; i < NumElementsInReserve; i++)
{
for (size_t i = 0; i < NumElementsInReserve; i++)
void * space = malloc(sizeof(T));
if (space == nullptr)
{
void * space = malloc(sizeof(T));
if (space == nullptr)
{
m_Callbacks->OnStartUsingReserve();
break;
}
m_FreeList.push_front(space);
m_Callbacks->OnStartUsingReserve();
break;
}
m_FreeList.push_front(space);
}
}

virtual ~cListAllocationPool()

virtual ~cListAllocationPool()
{
while (!m_FreeList.empty())
{
while (!m_FreeList.empty())
{
free (m_FreeList.front());
m_FreeList.pop_front();
}
free (m_FreeList.front());
m_FreeList.pop_front();
}
}

virtual T * Allocate() override

virtual T * Allocate() override
{
if (m_FreeList.size() <= NumElementsInReserve)
{
if (m_FreeList.size() <= NumElementsInReserve)
void * space = malloc(sizeof(T));
if (space != nullptr)
{
void * space = malloc(sizeof(T));
if (space != nullptr)
{
return new(space) T;
}
else if (m_FreeList.size() == NumElementsInReserve)
{
m_Callbacks->OnStartUsingReserve();
}
else if (m_FreeList.empty())
{
m_Callbacks->OnOutOfReserve();
// Try again until the memory is avalable
return Allocate();
}
return new(space) T;
}
// placement new, used to initalize the object
T * ret = new (m_FreeList.front()) T;
m_FreeList.pop_front();
return ret;
}
virtual void Free(T * a_ptr) override
{
if (a_ptr == nullptr)
else if (m_FreeList.size() == NumElementsInReserve)
{
return;
m_Callbacks->OnStartUsingReserve();
}
// placement destruct.
a_ptr->~T();
m_FreeList.push_front(a_ptr);
if (m_FreeList.size() == NumElementsInReserve)
else if (m_FreeList.empty())
{
m_Callbacks->OnEndUsingReserve();
m_Callbacks->OnOutOfReserve();
// Try again until the memory is avalable
return Allocate();
}
}
// placement new, used to initalize the object
T * ret = new (m_FreeList.front()) T;
m_FreeList.pop_front();
return ret;
}


virtual void Free(T * a_ptr) override
{
if (a_ptr == nullptr)
{
return;
}
// placement destruct.
a_ptr->~T();
m_FreeList.push_front(a_ptr);
if (m_FreeList.size() == NumElementsInReserve)
{
m_Callbacks->OnEndUsingReserve();
}
}

private:
std::list<void *> m_FreeList;
std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> m_Callbacks;
private:
std::list<void *> m_FreeList;
std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> m_Callbacks;
};


Expand Down
26 changes: 12 additions & 14 deletions src/Bindings/LuaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ To overcome this, this object overloads the Destroy functions, which doesn't let
delete the window, but rather leaves it dangling, with only Lua having the reference to it.
Additionally, to forbid Lua from deleting this object while it is used by players, the manual bindings for
cPlayer:OpenWindow check if the window is of this class, and if so, make a global Lua reference for this object.
This reference needs to be unreferenced in the Destroy() function.
*/
This reference needs to be unreferenced in the Destroy() function. */
// tolua_begin
class cLuaWindow :
public cWindow
Expand All @@ -43,44 +42,43 @@ class cLuaWindow :
typedef cWindow super;

public:
/// Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size
/** Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size */
cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString & a_Title);

virtual ~cLuaWindow();

/// Returns the internal representation of the contents that are manipulated by Lua
/** Returns the internal representation of the contents that are manipulated by Lua */
cItemGrid & GetContents(void) { return m_Contents; }

// tolua_end

/** Sets the plugin reference and the internal Lua object reference index
used for preventing Lua's GC to collect this class while the window is open
*/
used for preventing Lua's GC to collect this class while the window is open. */
void SetLuaRef(cPluginLua * a_Plugin, int a_LuaRef);

/// Returns true if SetLuaRef() has been called
/** Returns true if SetLuaRef() has been called */
bool IsLuaReferenced(void) const;

/// Sets the callback function (Lua reference) to call when the window is about to close
/** Sets the callback function (Lua reference) to call when the window is about to close */
void SetOnClosing(cPluginLua * a_Plugin, int a_FnRef);

/// Sets the callback function (Lua reference) to call when a slot is changed
/** Sets the callback function (Lua reference) to call when a slot is changed */
void SetOnSlotChanged(cPluginLua * a_Plugin, int a_FnRef);

protected:
/// Contents of the non-inventory part
/** Contents of the non-inventory part */
cItemGrid m_Contents;

/// The plugin that has opened the window and owns the m_LuaRef
/** The plugin that has opened the window and owns the m_LuaRef */
cPluginLua * m_Plugin;

/// The Lua object reference, used for keeping the object alive as long as any player has the window open
/** The Lua object reference, used for keeping the object alive as long as any player has the window open */
int m_LuaRef;

/// The Lua reference for the callback to call when the window is closing for any player
/** The Lua reference for the callback to call when the window is closing for any player */
int m_OnClosingFnRef;

/// The Lua reference for the callback to call when a slot has changed
/** The Lua reference for the callback to call when a slot has changed */
int m_OnSlotChangedFnRef;

// cWindow overrides:
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/ManualBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L)



/// Provides interface between a Lua table of callbacks and the cBlockTracer::cCallbacks
/** Provides interface between a Lua table of callbacks and the cBlockTracer::cCallbacks */
class cLuaBlockTracerCallbacks :
public cBlockTracer::cCallbacks
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class cPlugin
// Called each tick
virtual void Tick(float a_Dt) = 0;

/** Calls the specified hook with the params given. Returns the bool that the hook callback returns.*/
/** Calls the specified hook with the params given. Returns the bool that the hook callback returns. */
virtual bool OnBlockSpread (cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) = 0;
virtual bool OnBlockToPickups (cWorld & a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0;
virtual bool OnChat (cPlayer & a_Player, AString & a_Message) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/BiomeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extern bool IsBiomeVeryCold(EMCSBiome a_Biome);
Doesn't report Very Cold biomes, use IsBiomeVeryCold() for those. */
extern bool IsBiomeCold(EMCSBiome a_Biome);

/** Returns the height when a biome when a biome starts snowing.*/
/** Returns the height when a biome when a biome starts snowing. */
extern int GetSnowStartHeight(EMCSBiome a_Biome);

// tolua_end
12 changes: 6 additions & 6 deletions src/BlockArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

typedef void (CombinatorFunc)(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta);

// This wild construct allows us to pass a function argument and still have it inlined by the compiler :)
/// Merges two blocktypes and blockmetas of the specified sizes and offsets using the specified combinator function
/** Merges two blocktypes and blockmetas of the specified sizes and offsets using the specified combinator function
This wild construct allows us to pass a function argument and still have it inlined by the compiler. */
template <bool MetasValid, CombinatorFunc Combinator>
void InternalMergeBlocks(
BLOCKTYPE * a_DstTypes, const BLOCKTYPE * a_SrcTypes,
Expand Down Expand Up @@ -73,7 +73,7 @@ void InternalMergeBlocks(



/// Combinator used for cBlockArea::msOverwrite merging
/** Combinator used for cBlockArea::msOverwrite merging */
template <bool MetaValid>
void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
{
Expand All @@ -88,7 +88,7 @@ void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLE



/// Combinator used for cBlockArea::msFillAir merging
/** Combinator used for cBlockArea::msFillAir merging */
template <bool MetaValid>
void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
{
Expand All @@ -107,7 +107,7 @@ void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETY



/// Combinator used for cBlockArea::msImprint merging
/** Combinator used for cBlockArea::msImprint merging */
template <bool MetaValid>
void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
{
Expand All @@ -126,7 +126,7 @@ void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETY



/// Combinator used for cBlockArea::msLake merging
/** Combinator used for cBlockArea::msLake merging */
template <bool MetaValid>
void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
{
Expand Down
17 changes: 8 additions & 9 deletions src/BlockEntities/BlockEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class cBlockEntity
m_World = a_World;
}

/// Creates a new block entity for the specified block type
/// If a_World is valid, then the entity is created bound to that world
/// Returns nullptr for unknown block types
/** Creates a new block entity for the specified block type
If a_World is valid, then the entity is created bound to that world
Returns nullptr for unknown block types. */
static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World = nullptr);

static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
Expand Down Expand Up @@ -102,26 +102,25 @@ class cBlockEntity

// tolua_end

/// Called when a player uses this entity; should open the UI window
/** Called when a player uses this entity; should open the UI window */
virtual void UsedBy( cPlayer * a_Player) = 0;

/** Sends the packet defining the block entity to the client specified.
To send to all eligible clients, use cWorld::BroadcastBlockEntity()
*/
To send to all eligible clients, use cWorld::BroadcastBlockEntity() */
virtual void SendTo(cClientHandle & a_Client) = 0;

/// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing.
/** Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. */
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
UNUSED(a_Dt);
return false;
}

protected:
/// Position in absolute block coordinates
/** Position in absolute block coordinates */
int m_PosX, m_PosY, m_PosZ;

/// Position relative to the chunk, used to speed up ticking
/** Position relative to the chunk, used to speed up ticking */
int m_RelX, m_RelZ;

BLOCKTYPE m_BlockType;
Expand Down
4 changes: 2 additions & 2 deletions src/BlockEntities/BlockEntityWithItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class cBlockEntityWithItems :
void SetSlot(int a_SlotNum, const cItem & a_Item) { m_Contents.SetSlot(a_SlotNum, a_Item); }
void SetSlot(int a_X, int a_Y, const cItem & a_Item) { m_Contents.SetSlot(a_X, a_Y, a_Item); }

/// Returns the ItemGrid used for storing the contents
/** Returns the ItemGrid used for storing the contents */
cItemGrid & GetContents(void) { return m_Contents; }

// tolua_end

/// Const version of the GetContents() function for C++ type-safety
/** Const version of the GetContents() function for C++ type-safety */
const cItemGrid & GetContents(void) const { return m_Contents; }

protected:
Expand Down
Loading

0 comments on commit 6e4122e

Please sign in to comment.