mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
This patch removes a lot of old code. Context is now exclusively grabbed from the CSquirrelVM instance. This patch also comes with a few new types: SQArray and SQTable! The implementation also allows pushing Vector3D's on the stack, but these are handled slightly differently.. The largest field in tagSQObjectValue is 8 bytes, Vector3D is 12 bytes unaligned, but the tagSQObjectValue field in the tagSQObject struct is aligned to a 8 byte boundary while the field prior is only 4 bytes, Vector3D starts right after the type field in the tagSQObject (at the padding) to keep the whole structure the same size, therefore a new field has been added in between the padding (_pad) with a simple Vector3D accessor. Also added a hook to allow registering proper script enums.
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#ifndef SQTABLE_H
|
|
#define SQTABLE_H
|
|
#include "sqobject.h"
|
|
#include "sqstring.h"
|
|
|
|
#define hashptr(p) ((SQHash)(((SQInteger)((intp)p)) >> 3))
|
|
|
|
inline SQHash HashObj(const SQObjectPtr& key) // TODO: untested
|
|
{
|
|
switch (sq_type(key)) {
|
|
case OT_STRING: return _string(key)->_hash;
|
|
case OT_FLOAT: return (SQHash)((SQInteger)_float(key));
|
|
case OT_BOOL: case OT_INTEGER: return (SQHash)((SQInteger)_integer(key));
|
|
default: return hashptr(key._unVal.pRefCounted);
|
|
}
|
|
}
|
|
|
|
struct SQTable : public SQDelegable
|
|
{
|
|
public:
|
|
struct _HashNode
|
|
{
|
|
_HashNode() { hash = NULL; prev = NULL; next = NULL; }
|
|
|
|
SQObjectPtr val;
|
|
SQObjectPtr key;
|
|
SQInteger hash;
|
|
SQShort prev;
|
|
SQShort next;
|
|
};
|
|
|
|
void _ClearNodes();
|
|
inline _HashNode* _Get(const SQObjectPtr& key, SQHash hash) // TODO: untested
|
|
{
|
|
_HashNode* n = &_nodes[hash];
|
|
do {
|
|
if (_rawval(n->key) == _rawval(key) && sq_type(n->key) == sq_type(key)) {
|
|
return n;
|
|
}
|
|
} while (n->hash != -1);
|
|
return NULL;
|
|
}
|
|
bool Get(const SQObjectPtr& key, SQObjectPtr& val);
|
|
|
|
_HashNode* _nodes;
|
|
SQInteger _numofnodes;
|
|
SQInteger _usednodes;
|
|
SQInteger _prev;
|
|
SQInteger _next;
|
|
SQInteger _last;
|
|
};
|
|
|
|
#define SQ_FOR_EACH_TABLE(tableName, iteratorName) \
|
|
for (int iteratorName = 0; iteratorName < tableName->_numofnodes; iteratorName++)
|
|
|
|
#endif // SQTABLE_H
|