mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
send handle from JS (#2795)
This commit is contained in:
@@ -21,13 +21,13 @@ ArrayPool::~ArrayPool() {
|
||||
Object *ArrayPool::alloc(uint index) {
|
||||
uint bytes = _size * BYTES_PER_ELEMENT;
|
||||
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, nullptr, bytes);
|
||||
obj->incRef();
|
||||
_objects[index] = obj;
|
||||
_indexes[obj] = index;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object *ArrayPool::resize(Object *origin, uint size) {
|
||||
Object *ArrayPool::resize(Object *origin, uint size, uint index) {
|
||||
uint bytes = size * BYTES_PER_ELEMENT;
|
||||
uint8_t *buffer = static_cast<uint8_t *>(CC_MALLOC(bytes));
|
||||
if (!buffer) {
|
||||
@@ -44,10 +44,8 @@ Object *ArrayPool::resize(Object *origin, uint size) {
|
||||
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, buffer, bytes);
|
||||
CC_FREE(buffer);
|
||||
|
||||
uint originIndex = _indexes[origin];
|
||||
_objects[originIndex] = obj;
|
||||
_indexes[obj] = originIndex;
|
||||
_indexes.erase(origin);
|
||||
CC_ASSERT(_objects.count(index) != 0);
|
||||
_objects[index] = obj;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@ public:
|
||||
~ArrayPool();
|
||||
|
||||
Object *alloc(uint index);
|
||||
Object *resize(Object *origin, uint size);
|
||||
Object *resize(Object *origin, uint size, uint index);
|
||||
|
||||
private:
|
||||
static cc::map<PoolType, ArrayPool *> _pools;
|
||||
|
||||
cc::map<uint, Object *> _objects;
|
||||
cc::map<Object *, uint> _indexes;
|
||||
PoolType _type;
|
||||
uint _size = 0;
|
||||
};
|
||||
|
||||
@@ -196,15 +196,22 @@ static bool jsb_ArrayPool_resize(se::State &s) {
|
||||
|
||||
const auto &args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 2) {
|
||||
if (argc == 3) {
|
||||
uint size = 0;
|
||||
if (seval_to_uint(args[1], &size)) {
|
||||
s.rval().setObject(arrayPool->resize(args[0].toObject(), size));
|
||||
return true;
|
||||
if (!seval_to_uint(args[1], &size)) {
|
||||
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get size.");
|
||||
return false;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to resize array");
|
||||
return false;
|
||||
|
||||
uint index = 0;
|
||||
if (!seval_to_uint(args[2], &index)) {
|
||||
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get index.");
|
||||
return false;
|
||||
} else {
|
||||
s.rval().setObject(arrayPool->resize(args[0].toObject(), size, index));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
|
||||
Reference in New Issue
Block a user