mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-14 10:17:20 +01:00
Removed the 2 queue implementations.
This commit is contained in:
parent
0202233a6f
commit
165ebb68bf
3
SCsub
3
SCsub
@ -11,9 +11,6 @@ sources = [
|
||||
|
||||
"register_types.cpp",
|
||||
|
||||
"containers/voxelman_queue.cpp",
|
||||
"containers/voxelman_unbounded_queue.cpp",
|
||||
|
||||
"library/voxelman_library.cpp",
|
||||
"library/voxelman_library_simple.cpp",
|
||||
"library/voxelman_library_merger.cpp",
|
||||
|
@ -15,8 +15,6 @@ def get_doc_classes():
|
||||
"GroundClutterFoliage",
|
||||
"GroundClutter",
|
||||
|
||||
"VoxelmanQueue",
|
||||
"VoxelmanUnboundedQueue",
|
||||
"VoxelLight",
|
||||
|
||||
"VoxelmanLevelGenerator",
|
||||
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "voxelman_queue.h"
|
||||
|
||||
/// VMQUeue
|
||||
|
||||
template <typename T>
|
||||
void VMQueue<T>::enqueue(T obj) {
|
||||
_lock->write_lock();
|
||||
|
||||
if (_size == _count) {
|
||||
_resize(_size + 10);
|
||||
}
|
||||
|
||||
_items[(_head + _count) % _size] = obj;
|
||||
++_count;
|
||||
|
||||
_lock->write_unlock();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VMQueue<T>::dequeue() {
|
||||
if (_size == 0)
|
||||
return T();
|
||||
|
||||
if (_count == 0)
|
||||
return T();
|
||||
|
||||
T obj;
|
||||
|
||||
_lock->write_lock();
|
||||
|
||||
obj = _items[_head];
|
||||
|
||||
_items[_head] = T();
|
||||
|
||||
++_head;
|
||||
--_count;
|
||||
|
||||
if (_head >= _size)
|
||||
_head -= _size;
|
||||
|
||||
_lock->write_unlock();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VMQueue<T>::peek() {
|
||||
T obj;
|
||||
|
||||
_lock->read_lock();
|
||||
obj = _items[_head];
|
||||
_lock->read_unlock();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void VMQueue<T>::resize(int new_size) {
|
||||
_lock->write_lock();
|
||||
|
||||
_resize(new_size);
|
||||
|
||||
_lock->write_unlock();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void VMQueue<T>::_resize(int new_size) {
|
||||
if (new_size == _size)
|
||||
return;
|
||||
|
||||
if (new_size > _size) {
|
||||
|
||||
T *narr = memnew_arr(T, new_size);
|
||||
//copymem(narr, _items, sizeof(T) * _size);
|
||||
|
||||
for (int i = 0; i < _size; ++i) {
|
||||
narr[i] = _items[i];
|
||||
}
|
||||
|
||||
memdelete_arr(_items);
|
||||
_items = narr;
|
||||
|
||||
_size = new_size;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VMQueue<T>::VMQueue(int initial_size) {
|
||||
_items = NULL;
|
||||
_head = 0;
|
||||
_count = 0;
|
||||
_size = initial_size;
|
||||
|
||||
if (unlikely(initial_size <= 0)) {
|
||||
_size = 10;
|
||||
|
||||
print_error("initial_size <= 0");
|
||||
}
|
||||
|
||||
_lock = RWLock::create();
|
||||
|
||||
_items = memnew_arr(T, _size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VMQueue<T>::VMQueue() {
|
||||
_items = NULL;
|
||||
_head = 0;
|
||||
_count = 0;
|
||||
_size = 10;
|
||||
|
||||
_lock = RWLock::create();
|
||||
|
||||
_items = memnew_arr(T, _size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VMQueue<T>::~VMQueue() {
|
||||
if (_items)
|
||||
memdelete_arr(_items);
|
||||
|
||||
memdelete(_lock);
|
||||
}
|
||||
|
||||
///VoxelmanQueue
|
||||
|
||||
void VoxelmanQueue::enqueue(Variant obj) {
|
||||
_queue.enqueue(obj);
|
||||
}
|
||||
Variant VoxelmanQueue::dequeue() {
|
||||
return _queue.dequeue();
|
||||
}
|
||||
Variant VoxelmanQueue::peek() {
|
||||
return _queue.peek();
|
||||
}
|
||||
|
||||
void VoxelmanQueue::resize(int new_size) {
|
||||
_queue.resize(new_size);
|
||||
}
|
||||
|
||||
VoxelmanQueue::VoxelmanQueue() {
|
||||
}
|
||||
|
||||
VoxelmanQueue::~VoxelmanQueue() {
|
||||
}
|
||||
|
||||
void VoxelmanQueue::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("enqueue", "obj"), &VoxelmanQueue::enqueue);
|
||||
ClassDB::bind_method(D_METHOD("dequeue"), &VoxelmanQueue::dequeue);
|
||||
ClassDB::bind_method(D_METHOD("peek"), &VoxelmanQueue::peek);
|
||||
ClassDB::bind_method(D_METHOD("resize", "new_size"), &VoxelmanQueue::resize);
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef VOXELMAN_QUEUE_H
|
||||
#define VOXELMAN_QUEUE_H
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/os/copymem.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "core/variant.h"
|
||||
|
||||
template <class T>
|
||||
class VMQueue {
|
||||
|
||||
public:
|
||||
void enqueue(T obj);
|
||||
T dequeue();
|
||||
T peek();
|
||||
|
||||
void resize(int new_size);
|
||||
|
||||
VMQueue(int initial_size);
|
||||
VMQueue();
|
||||
~VMQueue();
|
||||
|
||||
protected:
|
||||
void _resize(int new_size);
|
||||
|
||||
private:
|
||||
RWLock *_lock;
|
||||
|
||||
int _head;
|
||||
int _count;
|
||||
int _size;
|
||||
T *_items;
|
||||
};
|
||||
|
||||
class VoxelmanQueue : public Reference {
|
||||
GDCLASS(VoxelmanQueue, Reference);
|
||||
|
||||
public:
|
||||
void enqueue(Variant obj);
|
||||
Variant dequeue();
|
||||
Variant peek();
|
||||
|
||||
void resize(int new_size);
|
||||
|
||||
VoxelmanQueue();
|
||||
~VoxelmanQueue();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
VMQueue<Variant> _queue;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "voxelman_unbounded_queue.h"
|
||||
|
||||
/// VMQUeue
|
||||
|
||||
template <typename T>
|
||||
void VMUBQueue<T>::enqueue(T obj) {
|
||||
_enqueue_lock->write_lock();
|
||||
|
||||
UBQueueNode<T> *n = memnew(UBQueueNode<T>(obj));
|
||||
|
||||
_tail->next = n;
|
||||
_tail = n;
|
||||
|
||||
_enqueue_lock->write_unlock();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VMUBQueue<T>::dequeue() {
|
||||
T result;
|
||||
|
||||
_dequeue_lock->write_lock();
|
||||
|
||||
if (_head->next == NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = _head->next->data;
|
||||
|
||||
UBQueueNode<T> *h = _head;
|
||||
|
||||
_head = _head->next;
|
||||
|
||||
memdelete(h);
|
||||
|
||||
_dequeue_lock->write_unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VMUBQueue<T>::peek() {
|
||||
return _head->data;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VMUBQueue<T>::VMUBQueue() {
|
||||
_head = memnew(UBQueueNode<T>);
|
||||
_tail = _head;
|
||||
|
||||
_enqueue_lock = RWLock::create();
|
||||
_dequeue_lock = RWLock::create();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
VMUBQueue<T>::~VMUBQueue() {
|
||||
memdelete(_enqueue_lock);
|
||||
memdelete(_dequeue_lock);
|
||||
|
||||
UBQueueNode<T> *h = _head;
|
||||
|
||||
while (h) {
|
||||
UBQueueNode<T> *n = h->next;
|
||||
|
||||
memdelete(h);
|
||||
|
||||
h = n;
|
||||
}
|
||||
}
|
||||
|
||||
///VoxelmanUnboundedQueue
|
||||
|
||||
void VoxelmanUnboundedQueue::enqueue(Variant obj) {
|
||||
_queue.enqueue(obj);
|
||||
}
|
||||
Variant VoxelmanUnboundedQueue::dequeue() {
|
||||
return _queue.dequeue();
|
||||
}
|
||||
Variant VoxelmanUnboundedQueue::peek() {
|
||||
return _queue.peek();
|
||||
}
|
||||
|
||||
VoxelmanUnboundedQueue::VoxelmanUnboundedQueue() {
|
||||
}
|
||||
|
||||
VoxelmanUnboundedQueue::~VoxelmanUnboundedQueue() {
|
||||
}
|
||||
|
||||
void VoxelmanUnboundedQueue::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("enqueue", "obj"), &VoxelmanUnboundedQueue::enqueue);
|
||||
ClassDB::bind_method(D_METHOD("dequeue"), &VoxelmanUnboundedQueue::dequeue);
|
||||
ClassDB::bind_method(D_METHOD("peek"), &VoxelmanUnboundedQueue::peek);
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef VOXELMAN_UNBOUNDED_QUEUE_H
|
||||
#define VOXELMAN_UNBOUNDED_QUEUE_H
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/os/copymem.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "core/variant.h"
|
||||
|
||||
template <class T>
|
||||
struct UBQueueNode {
|
||||
T data;
|
||||
UBQueueNode *next;
|
||||
|
||||
UBQueueNode() {
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
UBQueueNode(T value) {
|
||||
data = value;
|
||||
next = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class VMUBQueue {
|
||||
|
||||
public:
|
||||
void enqueue(T obj);
|
||||
T dequeue();
|
||||
T peek();
|
||||
|
||||
VMUBQueue();
|
||||
~VMUBQueue();
|
||||
|
||||
private:
|
||||
RWLock *_enqueue_lock;
|
||||
RWLock *_dequeue_lock;
|
||||
|
||||
UBQueueNode<T> *_head;
|
||||
UBQueueNode<T> *_tail;
|
||||
};
|
||||
|
||||
class VoxelmanUnboundedQueue : public Reference {
|
||||
GDCLASS(VoxelmanUnboundedQueue, Reference);
|
||||
|
||||
public:
|
||||
void enqueue(Variant obj);
|
||||
Variant dequeue();
|
||||
Variant peek();
|
||||
|
||||
VoxelmanUnboundedQueue();
|
||||
~VoxelmanUnboundedQueue();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
VMUBQueue<Variant> _queue;
|
||||
};
|
||||
|
||||
#endif
|
@ -22,9 +22,6 @@ SOFTWARE.
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "containers/voxelman_queue.h"
|
||||
#include "containers/voxelman_unbounded_queue.h"
|
||||
|
||||
#include "library/voxel_surface.h"
|
||||
#include "library/voxel_surface_merger.h"
|
||||
#include "library/voxel_surface_simple.h"
|
||||
@ -78,9 +75,6 @@ SOFTWARE.
|
||||
#endif
|
||||
|
||||
void register_voxelman_types() {
|
||||
ClassDB::register_class<VoxelmanQueue>();
|
||||
ClassDB::register_class<VoxelmanUnboundedQueue>();
|
||||
|
||||
ClassDB::register_class<VoxelMesher>();
|
||||
ClassDB::register_class<VoxelMesherTransvoxel>();
|
||||
ClassDB::register_class<TransvoxelCellData>();
|
||||
|
Loading…
Reference in New Issue
Block a user