#include "dmm.hh"
#ifdef DMM_ONLINE
class Menu_Button;
const int ARRAY_SIZE_PRIME_NUMBER = 1000003;
class Node
{
public:
Node* next;
void* data;
};
Node* dmm_array[ARRAY_SIZE_PRIME_NUMBER];
void debug_dmm_print()
{
dmp::cout << "(\n";
for (int i=0; i<ARRAY_SIZE_PRIME_NUMBER; i++)
{
for (Node* n = dmm_array[i]; n != null; n = n->next)
{
dmp::Root* r = reinterpret_cast<dmp::Root*>(n->data);
dmp::cout << " " << dmm_decode(r->debug_code) << '\n';
}
}
dmp::cout << ")\n";
}
void* operator new (size_t size)
{
WARNING: careful with the ordering of linking... the last file in the list is executed first...
void* address = ::calloc(size,1);
if (address == null)
{
#ifdef ALLEGRO_MESSAGE_AND_EXIT
ALLEGRO_MESSAGE_AND_EXIT(("Memory exhausted"));
#else
printf("*** Memory exhausted");
exit(EXIT_FAILURE);
#endif
}
unsigned int address_int = reinterpret_cast<unsigned int>(address);
unsigned int i = address_int % ARRAY_SIZE_PRIME_NUMBER;
Node* n = reinterpret_cast<Node*>(::malloc(sizeof(Node)));
ASSERT(n != null);
n->data = address;
n->next = dmm_array[i];
dmm_array[i] = n;
return address;
}
void operator delete (void* p)
{
if (p == null)
{
return;
}
unsigned int address_int = reinterpret_cast<unsigned int>(p);
unsigned int i = address_int % ARRAY_SIZE_PRIME_NUMBER;
Node* n_old = null;
for (Node* n = dmm_array[i]; n != null; n = n->next)
{
void* q = n->data;
if (q == p)
{
if (n_old == null)
{
dmm_array[i] = null;
}
else
{
n_old->next = n->next;
}
ASSERT(n != null);
::free(n);
break;
}
n_old = n;
}
::free(p);
}
#undef DCODE_CASE
#define DCODE_CASE(var) case dmp::var: return #var;
const char* dmm_decode(dmp::enum_debug_code code)
{
switch (code)
{
DCODE_CASE(DCODE_GENERIC);
DCODE_CASE(DCODE_BOOLEAN);
DCODE_CASE(DCODE_INTEGER);
DCODE_CASE(DCODE_QUICK);
DCODE_CASE(DCODE_FLOAT);
DCODE_CASE(DCODE_DOUBLE);
DCODE_CASE(DCODE_STRING);
DCODE_CASE(DCODE_XYI);
DCODE_CASE(DCODE_XYQ);
DCODE_CASE(DCODE_XYD);
DCODE_CASE(DCODE_V3I);
DCODE_CASE(DCODE_V3Q);
DCODE_CASE(DCODE_V3D);
DCODE_CASE(DCODE_BITMAP);
DCODE_CASE(DCODE_SAMPLE);
DCODE_CASE(DCODE_GULPER);
DCODE_CASE(DCODE_LIST);
DCODE_CASE(DCODE_LIST_NODE);
DCODE_CASE(DCODE_LIST_ITERATOR);
DCODE_CASE(DCODE_ARRAY);
DCODE_CASE(DCODE_MENU_BUTTON);
DCODE_CASE(DCODE_MENU_LIST);
DCODE_CASE(DCODE_SPRITE);
DCODE_CASE(DCODE_SPRITE_2);
DCODE_CASE(DCODE_SPRITE_GRABBER_ACTION);
DCODE_CASE(DCODE_SPRITE_EDITOR_RECT);
DCODE_CASE(DCODE_WIDGET);
DCODE_CASE(DCODE_FILE);
DCODE_CASE(DCODE_TRI_RANDOM_OUTER);
DCODE_CASE(DCODE_TRI_INPUT_DEVICE);
DCODE_CASE(DCODE_TRI_PLAYER);
DCODE_CASE(DCODE_TRI_PONG_FADER);
DCODE_CASE(DCODE_TRI_PONG_BALL);
DCODE_CASE(DCODE_TRI_SLIMER);
DCODE_CASE(DCODE_TRI_STRATEGY);
DCODE_CASE(DCODE_TRI_TRICKS_NODE);
DCODE_CASE(DCODE_TRI_TRICKS);
DCODE_CASE(DCODE_TRI_PAIR);
DCODE_CASE(DCODE_R4_SAVE);
DCODE_CASE(DCODE_X1);
DCODE_CASE(DCODE_X2);
DCODE_CASE(DCODE_Y1);
DCODE_CASE(DCODE_Y2);
DCODE_CASE(DCODE_BOARD);
}
return "<Unknown>";
}
#endif