Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
bd0d7865
Commit
bd0d7865
authored
10 years ago
by
gregorycu
Committed by
Zeno-
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Change UniqueQueue to use a queue and a set.
parent
227e4807
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/map.cpp
+8
-4
8 additions, 4 deletions
src/map.cpp
src/util/container.h
+50
-49
50 additions, 49 deletions
src/util/container.h
with
58 additions
and
53 deletions
src/map.cpp
+
8
−
4
View file @
bd0d7865
...
@@ -1663,7 +1663,8 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
...
@@ -1663,7 +1663,8 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
/*
/*
Get a queued transforming liquid node
Get a queued transforming liquid node
*/
*/
v3s16
p0
=
m_transforming_liquid
.
pop_front
();
v3s16
p0
=
m_transforming_liquid
.
front
();
m_transforming_liquid
.
pop_front
();
MapNode
n0
=
getNodeNoEx
(
p0
);
MapNode
n0
=
getNodeNoEx
(
p0
);
...
@@ -1909,7 +1910,10 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
...
@@ -1909,7 +1910,10 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
}
}
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
while
(
must_reflow
.
size
()
>
0
)
while
(
must_reflow
.
size
()
>
0
)
m_transforming_liquid
.
push_back
(
must_reflow
.
pop_front
());
{
m_transforming_liquid
.
push_back
(
must_reflow
.
front
());
must_reflow
.
pop_front
();
}
updateLighting
(
lighting_modified_blocks
,
modified_blocks
);
updateLighting
(
lighting_modified_blocks
,
modified_blocks
);
...
@@ -2380,8 +2384,8 @@ void ServerMap::finishBlockMake(BlockMakeData *data,
...
@@ -2380,8 +2384,8 @@ void ServerMap::finishBlockMake(BlockMakeData *data,
*/
*/
while
(
data
->
transforming_liquid
.
size
()
>
0
)
while
(
data
->
transforming_liquid
.
size
()
>
0
)
{
{
v3s16
p
=
data
->
transforming_liquid
.
pop_
front
();
m_transforming_liquid
.
push_back
(
data
->
transforming_liquid
.
front
()
)
;
m_
transforming_liquid
.
p
ush_back
(
p
);
data
->
transforming_liquid
.
p
op_front
(
);
}
}
/*
/*
...
...
This diff is collapsed.
Click to expand it.
src/util/container.h
+
50
−
49
View file @
bd0d7865
...
@@ -28,52 +28,53 @@ with this program; if not, write to the Free Software Foundation, Inc.,
...
@@ -28,52 +28,53 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include
<list>
#include
<list>
#include
<vector>
#include
<vector>
#include
<map>
#include
<map>
#include
<set>
#include
<queue>
/*
/*
Queue with unique values with fast checking of value existence
Queue with unique values with fast checking of value existence
*/
*/
template
<
typename
Value
>
template
<
typename
Value
>
class
UniqueQueue
class
UniqueQueue
{
{
public:
public:
/*
/*
Does nothing if value is already queued.
Does nothing if value is already queued.
Return value:
Return value:
true: value added
true: value added
false: value already exists
false: value already exists
*/
*/
bool
push_back
(
Value
value
)
bool
push_back
(
const
Value
&
value
)
{
{
// Check if already exists
if
(
m_set
.
insert
(
value
).
second
)
if
(
m_map
.
find
(
value
)
!=
m_map
.
end
())
{
return
false
;
m_queue
.
push
(
value
);
return
true
;
}
return
false
;
}
// Add
void
pop_front
()
m_map
[
value
]
=
0
;
{
m_list
.
push_back
(
value
);
m_set
.
erase
(
m_queue
.
front
());
m_queue
.
pop
();
return
true
;
}
}
Value
pop_
front
()
const
Value
&
front
()
const
{
{
typename
std
::
list
<
Value
>::
iterator
i
=
m_list
.
begin
();
return
m_queue
.
front
();
Value
value
=
*
i
;
m_map
.
erase
(
value
);
m_list
.
erase
(
i
);
return
value
;
}
}
u32
size
()
u32
size
()
const
{
{
return
m_
map
.
size
();
return
m_
queue
.
size
();
}
}
private
:
private
:
std
::
map
<
Value
,
u8
>
m_
map
;
std
::
set
<
Value
>
m_
set
;
std
::
list
<
Value
>
m_
list
;
std
::
queue
<
Value
>
m_
queue
;
};
};
#if 1
#if 1
...
@@ -84,14 +85,14 @@ class MutexedMap
...
@@ -84,14 +85,14 @@ class MutexedMap
MutexedMap
()
MutexedMap
()
{
{
}
}
void
set
(
const
Key
&
name
,
const
Value
&
value
)
void
set
(
const
Key
&
name
,
const
Value
&
value
)
{
{
JMutexAutoLock
lock
(
m_mutex
);
JMutexAutoLock
lock
(
m_mutex
);
m_values
[
name
]
=
value
;
m_values
[
name
]
=
value
;
}
}
bool
get
(
const
Key
&
name
,
Value
*
result
)
bool
get
(
const
Key
&
name
,
Value
*
result
)
{
{
JMutexAutoLock
lock
(
m_mutex
);
JMutexAutoLock
lock
(
m_mutex
);
...
@@ -101,10 +102,10 @@ class MutexedMap
...
@@ -101,10 +102,10 @@ class MutexedMap
if
(
n
==
m_values
.
end
())
if
(
n
==
m_values
.
end
())
return
false
;
return
false
;
if
(
result
!=
NULL
)
if
(
result
!=
NULL
)
*
result
=
n
->
second
;
*
result
=
n
->
second
;
return
true
;
return
true
;
}
}
...
@@ -112,13 +113,13 @@ class MutexedMap
...
@@ -112,13 +113,13 @@ class MutexedMap
{
{
std
::
list
<
Value
>
result
;
std
::
list
<
Value
>
result
;
for
(
typename
std
::
map
<
Key
,
Value
>::
iterator
for
(
typename
std
::
map
<
Key
,
Value
>::
iterator
i
=
m_values
.
begin
();
i
=
m_values
.
begin
();
i
!=
m_values
.
end
();
++
i
){
i
!=
m_values
.
end
();
++
i
){
result
.
push_back
(
i
->
second
);
result
.
push_back
(
i
->
second
);
}
}
return
result
;
return
result
;
}
}
void
clear
()
void
clear
()
{
{
m_values
.
clear
();
m_values
.
clear
();
...
@@ -131,16 +132,16 @@ class MutexedMap
...
@@ -131,16 +132,16 @@ class MutexedMap
#endif
#endif
/*
/*
Generates ids for comparable values.
Generates ids for comparable values.
Id=0 is reserved for "no value".
Id=0 is reserved for "no value".
Is fast at:
Is fast at:
- Returning value by id (very fast)
- Returning value by id (very fast)
- Returning id by value
- Returning id by value
- Generating a new id for a value
- Generating a new id for a value
Is not able to:
Is not able to:
- Remove an id/value pair (is possible to implement but slow)
- Remove an id/value pair (is possible to implement but slow)
*/
*/
template
<
typename
T
>
template
<
typename
T
>
class
MutexedIdGenerator
class
MutexedIdGenerator
...
@@ -149,7 +150,7 @@ class MutexedIdGenerator
...
@@ -149,7 +150,7 @@ class MutexedIdGenerator
MutexedIdGenerator
()
MutexedIdGenerator
()
{
{
}
}
// Returns true if found
// Returns true if found
bool
getValue
(
u32
id
,
T
&
value
)
bool
getValue
(
u32
id
,
T
&
value
)
{
{
...
@@ -161,7 +162,7 @@ class MutexedIdGenerator
...
@@ -161,7 +162,7 @@ class MutexedIdGenerator
value
=
m_id_to_value
[
id
-
1
];
value
=
m_id_to_value
[
id
-
1
];
return
true
;
return
true
;
}
}
// If id exists for value, returns the id.
// If id exists for value, returns the id.
// Otherwise generates an id for the value.
// Otherwise generates an id for the value.
u32
getId
(
const
T
&
value
)
u32
getId
(
const
T
&
value
)
...
@@ -185,7 +186,7 @@ class MutexedIdGenerator
...
@@ -185,7 +186,7 @@ class MutexedIdGenerator
};
};
/*
/*
FIFO queue (well, actually a FILO also)
FIFO queue (well, actually a FILO also)
*/
*/
template
<
typename
T
>
template
<
typename
T
>
class
Queue
class
Queue
...
@@ -200,7 +201,7 @@ class Queue
...
@@ -200,7 +201,7 @@ class Queue
m_list
.
push_back
(
t
);
m_list
.
push_back
(
t
);
++
m_list_size
;
++
m_list_size
;
}
}
void
push_front
(
T
t
)
void
push_front
(
T
t
)
{
{
m_list
.
push_front
(
t
);
m_list
.
push_front
(
t
);
...
@@ -246,7 +247,7 @@ class Queue
...
@@ -246,7 +247,7 @@ class Queue
};
};
/*
/*
Thread-safe FIFO queue (well, actually a FILO also)
Thread-safe FIFO queue (well, actually a FILO also)
*/
*/
template
<
typename
T
>
template
<
typename
T
>
...
@@ -272,8 +273,8 @@ class MutexedQueue
...
@@ -272,8 +273,8 @@ class MutexedQueue
}
}
/* this version of pop_front returns a empty element of T on timeout.
/* this version of pop_front returns a empty element of T on timeout.
* Make sure default constructor of T creates a recognizable "empty" element
* Make sure default constructor of T creates a recognizable "empty" element
*/
*/
T
pop_frontNoEx
(
u32
wait_time_max_ms
)
T
pop_frontNoEx
(
u32
wait_time_max_ms
)
{
{
if
(
m_size
.
Wait
(
wait_time_max_ms
))
if
(
m_size
.
Wait
(
wait_time_max_ms
))
...
@@ -339,8 +340,8 @@ class MutexedQueue
...
@@ -339,8 +340,8 @@ class MutexedQueue
}
}
/* this version of pop_back returns a empty element of T on timeout.
/* this version of pop_back returns a empty element of T on timeout.
* Make sure default constructor of T creates a recognizable "empty" element
* Make sure default constructor of T creates a recognizable "empty" element
*/
*/
T
pop_backNoEx
(
u32
wait_time_max_ms
=
0
)
T
pop_backNoEx
(
u32
wait_time_max_ms
=
0
)
{
{
if
(
m_size
.
Wait
(
wait_time_max_ms
))
if
(
m_size
.
Wait
(
wait_time_max_ms
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment