mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Explicitly make sure that collectors in entity search algorithms are sent by reference instead of by copy. Should close #16
Invert the negate parameter to comply with how the algorithms work and what the negare argument is supposed to do. Few other minor additions or adjustments.
This commit is contained in:
parent
cd6e185d65
commit
26f5c495f5
@ -20,10 +20,8 @@ namespace Algo {
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Used to fake a string so a raw buffer can be used with search algorithms.
|
||||
*/
|
||||
class FakeString
|
||||
struct FakeString
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SQChar mBuffer[SQMOD_PLAYER_TMP_BUFFER]; // Buffer to hold the data.
|
||||
std::size_t mSize; // The size of the data in the buffer.
|
||||
@ -60,13 +58,21 @@ public:
|
||||
return mSize;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the string buffer.
|
||||
*/
|
||||
CSStr c_str() const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Find in buffer contents of another string.
|
||||
*/
|
||||
std::size_t find(CSStr s) const
|
||||
{
|
||||
CCStr r = std::strstr(mBuffer, s);
|
||||
return r == nullptr ? String::npos : (r - mBuffer);
|
||||
return (r == nullptr) ? String::npos : (r - mBuffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -141,7 +147,7 @@ static inline Array Player_AllWhereNameEquals(bool neg, CSStr name)
|
||||
// Process each entity in the pool
|
||||
EachEquals(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
AppendElemFunc< CPlayer >(), name, neg);
|
||||
AppendElemFunc< CPlayer >(), name, !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -159,7 +165,7 @@ static inline Array Player_AllWhereNameBegins(bool neg, CSStr name)
|
||||
// Process each entity in the pool
|
||||
EachBegins(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
AppendElemFunc< CPlayer >(), name, strlen(name), neg);
|
||||
AppendElemFunc< CPlayer >(), name, strlen(name), !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -177,7 +183,7 @@ static inline Array Player_AllWhereNameEnds(bool neg, CSStr name)
|
||||
// Process each entity in the pool
|
||||
EachEnds(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
AppendElemFunc< CPlayer >(), name, strlen(name), neg);
|
||||
AppendElemFunc< CPlayer >(), name, strlen(name), !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -195,7 +201,7 @@ static inline Array Player_AllWhereNameContains(bool neg, CSStr name)
|
||||
// Process each entity in the pool
|
||||
EachContains(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
AppendElemFunc< CPlayer >(), name, neg);
|
||||
AppendElemFunc< CPlayer >(), name, !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -210,7 +216,8 @@ static inline Object Player_FirstWhereNameEquals(bool neg, CSStr name)
|
||||
RecvElemFunc< CPlayer > recv;
|
||||
// Process each entity in the pool
|
||||
FirstEquals(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), recv, name, neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< RecvElemFunc< CPlayer > >(recv), name, !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -225,7 +232,8 @@ static inline Object Player_FirstWhereNameBegins(bool neg, CSStr name)
|
||||
RecvElemFunc< CPlayer > recv;
|
||||
// Process each entity in the pool
|
||||
FirstBegins(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), recv, name, strlen(name), neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< RecvElemFunc< CPlayer > >(recv), name, strlen(name), !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -240,7 +248,8 @@ static inline Object Player_FirstWhereNameEnds(bool neg, CSStr name)
|
||||
RecvElemFunc< CPlayer > recv;
|
||||
// Process each entity in the pool
|
||||
FirstEnds(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), recv, name, strlen(name), neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< RecvElemFunc< CPlayer > >(recv), name, strlen(name), !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -255,7 +264,8 @@ static inline Object Player_FirstWhereNameContains(bool neg, CSStr name)
|
||||
RecvElemFunc< CPlayer > recv;
|
||||
// Process each entity in the pool
|
||||
FirstContains(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), recv, name, neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< RecvElemFunc< CPlayer > >(recv), name, !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -270,7 +280,8 @@ static inline Uint32 Player_EachWhereNameEquals(bool neg, CSStr name, Object & e
|
||||
ForwardElemFunc< CPlayer > fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachEquals(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), fwd, name, neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemFunc< CPlayer > >(fwd), name, !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -285,7 +296,8 @@ static inline Uint32 Player_EachWhereNameBegins(bool neg, CSStr name, Object & e
|
||||
ForwardElemFunc< CPlayer > fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachBegins(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), fwd, name, strlen(name), neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemFunc< CPlayer > >(fwd), name, strlen(name), !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -300,7 +312,8 @@ static inline Uint32 Player_EachWhereNameEnds(bool neg, CSStr name, Object & env
|
||||
ForwardElemFunc< CPlayer > fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachEnds(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), fwd, name, strlen(name), neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemFunc< CPlayer > >(fwd), name, strlen(name), !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -315,7 +328,8 @@ static inline Uint32 Player_EachWhereNameContains(bool neg, CSStr name, Object &
|
||||
ForwardElemFunc< CPlayer > fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachContains(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(), fwd, name, neg);
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemFunc< CPlayer > >(fwd), name, !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#define SQMOD_VALID_TAG_STR(t) if (!t) { STHROWF("The specified tag is invalid"); }
|
||||
@ -563,6 +564,22 @@ template < typename T > struct RecvElemFunc
|
||||
{
|
||||
return mObj;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed object.
|
||||
*/
|
||||
operator Object & ()
|
||||
{
|
||||
return mObj;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed object.
|
||||
*/
|
||||
operator const Object & () const
|
||||
{
|
||||
return mObj;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -699,7 +716,7 @@ public:
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, neg);
|
||||
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -715,7 +732,7 @@ public:
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), neg);
|
||||
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -731,7 +748,7 @@ public:
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), neg);
|
||||
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -747,7 +764,7 @@ public:
|
||||
// Allocate an empty array on the stack
|
||||
sq_newarray(DefaultVM::Get(), 0);
|
||||
// Process each entity in the pool
|
||||
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, neg);
|
||||
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, !neg);
|
||||
// Return the array at the top of the stack
|
||||
return Var< Array >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
@ -761,7 +778,8 @@ public:
|
||||
// Create a new element receiver
|
||||
RecvElem recv;
|
||||
// Process each entity in the pool
|
||||
FirstEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), recv, tag, neg);
|
||||
FirstEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< RecvElem >(recv), tag, !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -775,7 +793,8 @@ public:
|
||||
// Create a new element receiver
|
||||
RecvElem recv;
|
||||
// Process each entity in the pool
|
||||
FirstBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), recv, tag, strlen(tag), neg);
|
||||
FirstBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< RecvElem >(recv), tag, strlen(tag), !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -789,7 +808,8 @@ public:
|
||||
// Create a new element receiver
|
||||
RecvElem recv;
|
||||
// Process each entity in the pool
|
||||
FirstEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), recv, tag, strlen(tag), neg);
|
||||
FirstEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< RecvElem >(recv), tag, strlen(tag), !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -803,7 +823,8 @@ public:
|
||||
// Create a new element receiver
|
||||
RecvElem recv;
|
||||
// Process each entity in the pool
|
||||
FirstContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), recv, tag, neg);
|
||||
FirstContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< RecvElem >(recv), tag, !neg);
|
||||
// Return the received element, if any
|
||||
return recv.mObj;
|
||||
}
|
||||
@ -816,7 +837,8 @@ public:
|
||||
// Create a new element forwarder
|
||||
ForwardElem fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
Collect(Inst::CBegin(), Inst::CEnd(), ValidInst(), fwd);
|
||||
Collect(Inst::CBegin(), Inst::CEnd(), ValidInst(),
|
||||
std::reference_wrapper< ForwardElem >(fwd));
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -830,7 +852,8 @@ public:
|
||||
// Create a new element forwarder
|
||||
ForwardElem fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), fwd, tag, neg);
|
||||
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElem >(fwd), tag, !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -844,7 +867,8 @@ public:
|
||||
// Create a new element forwarder
|
||||
ForwardElem fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), fwd, tag, strlen(tag), neg);
|
||||
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElem >(fwd), tag, strlen(tag), !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -858,7 +882,8 @@ public:
|
||||
// Create a new element forwarder
|
||||
ForwardElem fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), fwd, tag, strlen(tag), neg);
|
||||
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElem >(fwd), tag, strlen(tag), !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
@ -872,7 +897,8 @@ public:
|
||||
// Create a new element forwarder
|
||||
ForwardElem fwd(env, func);
|
||||
// Process each entity in the pool
|
||||
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), fwd, tag, neg);
|
||||
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElem >(fwd), tag, !neg);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user