*I am not a C/C++ programmer. (Java was my primary language of interest.)
*This is my first plugin, and simultaneously, it is also essentially my hello word program for C/C++.
*I wrote this, for the same reason I write many things, for practice...to learn.
*I might have chosen to try to use the STL, but for certain reasons, I chose not to.
*Although there may be many bugs, this plugin may be proof that you don't really have to know C/C++.
---to write a simple plugin for 3D GameStudio (with memory leaks and bugs?).
---Rather, it may be proof, of what not to do.
*Although some features of C++ were used and abused and intermingled with C,
---the language of the source code is not really C++.
---Sadly, there is no real evidence of object-oriented programming in the source.
*I am well aware that an entity linked list can be easily implemented in C-Script,
---and, of course, I have traveled this route.
---Note that ptr_for_handle is an instruction rated medium in the manual.
---Note that entity1 and entity2 are depreciated, and the replacement is the ptr_for_handle instruction rated medium?
---Although, in some cases, if some functionality is sacrificed,
---this .dll can offer a faster alternative to scan_entity,
---I don't claim that this .dll provides and absolute replacement for scan_entity,
---or that such is necessary.
---This exercise did not necessarily require that the end result be something
---that could not be produced in C-Script.
*I'm not going to suggest some of the uses for entity linked lists,
---nor am I going to debate whether entity linked lists are necessary.
---It's obvious, if you've never needed or used an entity linked list,
---you don't require them (ha ha).
*Of course, I haven't purchased the SDK, so the plugin is open source and the source is included.
---You are free to improve or fix bugs in the code.
---Suggestions and bug fixes are always welcome,
---nitpicking about code conventions, coding styles, decisions made,...
---repetitive comments about the noobishness of the code, etc. I can do without.
---Compiled with Visual C++ 6. SDK 6.3 used.
*eLL is an acronym for entity linked list.
*The eLL.dll offers an array of simulated entity linked lists.
---Note: little more than self-referential struct wrapped around an entity pointer.
*The max number of entity linked lists is set with a call of eLLsNew(_eLLsMax),
---where _eLLsMax is the max number of linked lists desired.
---_eLLsMax -1 is the max accessible index.
---Although it should not crash if you invoke some other function first,
---eLLsNew(_eLLsMax), which might be placed in C-Script function main(),
---should be the first function called for the .dll.
*eLLsDelete() is invoked when everything in the lists and associated memory should be deleted.
---This might be invoked before a level change.
---After invoking eLLsDelete(), eLLsNew(_eLLsMax) might be invoked again.
---This function (eLLsDelete) should be invoked automatically,
---when the application closes and the acknex engine shuts down,
---via a destructor of an object that goes out of scope.
---Note this function (eLLsDelete()), differs from eLLDelete(_eLLIndex, _ent), and eLLDeleteAll(_eLLIndex).
---eLLDelete(_eLLIndex, _ent) deletes the element containing entity _ent from
---the entity linked list referenced by _eLLIndex (in the array).
---eLLDeleteAll(_eLLIndex) deletes every element (each containing an entity) from
---the entity linked list referenced by _eLLIndex (in the array).
Perhaps, I'm just wasting my time and no one else downloads or uses this, so I suppose
I'll just dump the link, then the .wdl, followed by the comments in the source.
If there are any actual questions, I'll address them.
WARNING: alpha. Slightly tested. Probably many bugs.
Beware of pop-ups at url. For a limited time only.
6.51KB
eLL.zip alpha 0.01Code:
//eLL.wdl
//(Included in download. If these aren't in alphabetical order, it's a bug.)
dllfunction eLLAppend(_eLLIndex, _ent);
dllfunction eLLContains(_eLLIndex, _ent);
dllfunction eLLDelete(_eLLIndex, _ent);
dllfunction eLLDeleteAll(_eLLIndex, _eLLClearInUse);
dllfunction eLLGetLength(_eLLIndex);
dllfunction eLLIsEmpty(_eLLIndex);
dllfunction eLLIsInUse(_eLLIndex);
dllfunction eLLNext(_eLLIndex);
dllfunction eLLNextReset(_eLLIndex);
dllfunction eLLPop(_eLLIndex);
dllfunction eLLPush(_eLLIndex, _ent);
dllfunction eLLsDelete();
dllfunction eLLsGet1stFree();
dllfunction eLLsGetIndexOf(_ent);
dllfunction eLLSetInUse(_eLLIndex, _inUse);
dllfunction eLLsGetMaxLimit();
dllfunction eLLsNew(_eLLsMax);
//comments from the source
//(Included in download twice...once in source and again separately as eLL-comments.txt)
/********************************
eLLAppend(var _eLLIndex, ENTITY* _ent)
Creates eLL with index _eLLIndex if it does not exist.
Appends entity _ent to end of entity linked list with index _eLLIndex.
Slower than eLLPush.
Warning: allocates memory on the heap (free store).
No duplicates allowed.
Returns 1 on success and 0 on failure.
example:
eLLAppend(my.teamId, me);
*********************************/
/********************************
eLLContains(var _eLLIndex, ENTITY* _ent)
Returns 1 if entity linked list referenced by _eLLIndex
contains entity _ent or 0 if it does not.
*********************************/
/********************************
eLLDelete(var _eLLIndex, ENTITY* _ent)
Deletes entity _ent from eLL with index _eLLIndex.
Returns memory of element to heap (free store).
Not ent_remove.
Returns 1 on success and 0 on failure.
example:
if (strState0_ == strStateDead) {
eLLDelete(my.teamId, me);
}
*********************************/
/********************************
eLLDeleteAll(var _eLLIndex, var _eLLClearInUse)
Deletes entire entity linked list with index _eLLIndex.
Optionally clear the flag for the list which indicates if it is in use (had additions).
Not ent_remove.
Returns memory of elements to heap (free store).
Returns 1 on success and 0 on failure.
*********************************/
/********************************
eLLGetLength(var _eLLIndex)
Returns length or count of elements for entity linked list with _eLLIndex.
example:
if (eLLGetLength(my.teamIdEnemy) > 0) {
//iterate through the list
}
*********************************/
/********************************
eLLIsEmpty(var _eLLIndex)
Returns 1 if eLL with index _eLLIndex is empty.
example:
if (!eLLIsEmpty(my.teamIdEnemy)) {
//iterate through the list
}
*********************************/
/********************************
eLLIsInUse(var _eLLIndex)
Returns 1 if any elements were added to
or the in use flag was set for eLL with _eLLIndex.
The in use flag is automatically set to TRUE
for eLLAppend and eLLPush,
but it is not automatically reset to FALSE when
there are no elements left in the list.
An empty list may be in use and a list containing elements
may be set to not in use.
Such is user defined.
More or less, in use is meant to indicate that,
even if the list is empty,
there were items added to the list,
or that items will be added to the list.
Indexes don't have to be contiguous.
*********************************/
/********************************
eLLNext(var _eLLIndex)
Iterates through eLL with index _eLLIndex.
Iterating through list A and then list B
should not void list A's iteration.
If the list is half-iterated,
an invocation of eLLNextReset will reset it.
example:
entity* ent0;
//...
eLLNextReset(my.teamIdEnemy);
ent0 = eLLNext(my.teamIdEnemy);
while(ent0 != null) {
// ...evaluate ent0
ent0 = eLLNext(my.teamIdEnemy);
}
*********************************/
/********************************
eLLNextReset(var _eLLIndex)
Resets the current iteration so that the next invocation
of eLLNext will return the first entity in the list.
*********************************/
/********************************
eLLPop(var _eLLIndex)
Deletes the top element from entity linked list with _eLLIndex.
Returns the entity of that top element.
Returns memory of element to heap (free store).
example:
entity* ent0;
ent0 = eLLPop(0);
while(ent0 != NULL) {
eLLPush(1, ent0);
ent0 = eLLPop(0);
}
*********************************/
/********************************
eLLPush(int _eLLIndex, ENTITY* _ent)
Push an entity onto the top of entity linked list with index _eLLIndex.
Quicker than eLLAppend.
For performance reasons, does not check for duplicate items.
Voids the current iteration for the list.
The iteration restarts from the beginning of the list.
*********************************/
/********************************
eLLsDelete()
Delete all eLLs and all eLLElements.
Warning: In order to return memory to the heap and avoid memory leaks,
this function (__eLLsDelete) should be invoked before the application exits.
(__eLLsDelete) invoked automatically when eLLAutomaticCleanup eLLAC goes out of scope.
There should be no need for the user to
invoke this function directly when the application exits.
This function may also be invoked on level change, I think.
Returns memory to the heap (free store).
Should delete/reset everything.
Does not ent_remove.
Note the s in eLLs.
example:
function exit0() {
eLLsDelete();
exit;
}
on_esc = exit0;
*********************************/
/********************************
eLLsGet1stFree()
Returns the index of the first entity linked list with flag in use off.
see: eLLIsInUse, eLLSetInUse, eLLDeleteAll
*********************************/
/********************************
eLLsGetIndexOf(ENTITY *_ent)
Returns an index of an entity linked list containing entity _ent
or -1 if entity _ent is not found in any entity linked list.
*********************************/
/********************************
eLLSetInUse(var _eLLIndex, var _inUse)
*********************************/
/********************************
eLLsGetMaxLimit()
Returns the max number of lists that were allocated.
No more than this number of eLLs can be used unless the array of lists is reset.
*********************************/
/********************************
eLLsNew
Allocates arrays of pointers on the heap.
Allows for count of _eLLsMax entity linked lists.
Initializes all pointers to NULL.
Invoke this prior to invoking any other eLL function.
This function might be called in main.
Returns 1 on success and 0 on failure.
Note the s in eLLs.
example:
function main() {
/...
eLLsNew(5); // allocate 5 entity linked lists
}
*********************************/