Hello! In this topic Im going to talk about
abstract data types and
generic classes in EAX.
I couldn't find any information about ADTs in EAX, so I decided to make my own script which allows creation of ADTs. I have succeed in creating of an queue of integers, but... as usual programmer does, I must make a generic class (template in C++)! I've found that script editor highlights the word
template as a keyword. But I have no idea how to make it here, although the creation of template class in C++ is not a big deal for me. Also, editor highlights such words as
class,
struct,
const, and many others, but they don't behave in the way they behave in C++. (Don't even try to use
const keyword! It causes some scary access violation messages :O !)
So my question is:
Is it possible to make a generic class in EAX?There is a step-by-step creation of very primitive queue of integers below:
1. Creation of the
Node class:
Code:
//-----------------------------------------------------------------------------
CIntNode : CObject;
//-----------------------------------------------------------------------------
CIntNode::CIntNode(CObject* Parent) {
super(Parent, GS);
Data = 0;
}
//-----------------------------------------------------------------------------
void CIntNode::NewNext(int data) {
Next = new CIntNode(this);
Next->Data = data;
Next->Next = NullObj;
Next->Prev = this;
}
//-----------------------------------------------------------------------------
void CIntNode::NewPrev(int data) {
Prev = new CIntNode(this);
Prev->Data = data;
Prev->Next = this;
Prev->Prev = NullObj;
}
//-----------------------------------------------------------------------------
2. Creation of Queue class:
Code:
//-----------------------------------------------------------------------------
CIntQueue : CObject;
//-----------------------------------------------------------------------------
CIntQueue::CIntQueue(CObject* Parent) {
super(Parent, GS);
// Make the first node:
Head = new CIntNode(Parent);
Tail = Head;
}
//-----------------------------------------------------------------------------
void CIntQueue::Push(int data) {
Tail->NewNext(data);
Tail = Tail->Next;
}
//-----------------------------------------------------------------------------
int CIntQueue::Pop() {
local retInt = Head->Data;
// local destroyingHead = Head;
Head = Head->Next;
//comment: Why does it crashes the game??? I do not need to free the memory??? O_O
//delete destroyingHead;
return retInt;
}
//-----------------------------------------------------------------------------
3. Testing:
I have already written the debug interface script based on
tuturial on PX Wiki with some enchantments: there is a global string array variable
debugStrs in wich I can place data wich is displayed on a screen in the game. So:
Code:
//-----------------------------------------------------------------------------
require d_debug_interface;
//-----------------------------------------------------------------------------
int debugStrsIndex;
//-----------------------------------------------------------------------------
void int_queue_test::FirstFrame() {
debugStrsIndex = 0;
CIntQueue* IntQueue = new CIntQueue(Root);
IntQueue->Push(123);
IntQueue->Push(4);
IntQueue->Push(5);
// "stupid" access of data
debugStrs[debugStrsIndex++] = "IntQueue->Head->Data:";
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Data);
debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Data:";
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Data);
debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Next->Data:";
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Next->Data);
debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Next->Next->Data:";
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Next->Next->Data);
// the data access as it supposed to be
debugStrs[debugStrsIndex++] = "Popping:";
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop());
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop());
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop());
debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop());
}
//-----------------------------------------------------------------------------
4. I load the game and see the output (image in the attachment).
If you, guys, know how to make the template class, you can show it on this example above or as you wish.
Thanks in advance.