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
5d06bdf8
Commit
5d06bdf8
authored
10 years ago
by
sapier
Browse files
Options
Downloads
Patches
Plain Diff
Speedup getBlockNodeIdMapping by up to factor 4 by using a fixed size mapping array
parent
2625323f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mapblock.cpp
+10
-6
10 additions, 6 deletions
src/mapblock.cpp
with
10 additions
and
6 deletions
src/mapblock.cpp
+
10
−
6
View file @
5d06bdf8
...
...
@@ -452,10 +452,16 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
*/
// List relevant id-name pairs for ids in the block using nodedef
// Renumbers the content IDs (starting at 0 and incrementing
// use static memory requires about 65535 * sizeof(int) ram in order to be
// sure we can handle all content ids. But it's absolutely worth it as it's
// a speedup of 4 for one of the major time consuming functions on storing
// mapblocks.
static
content_t
getBlockNodeIdMapping_mapping
[
USHRT_MAX
];
static
void
getBlockNodeIdMapping
(
NameIdMapping
*
nimap
,
MapNode
*
nodes
,
INodeDefManager
*
nodedef
)
{
std
::
map
<
content_t
,
content_t
>
mapping
;
memset
(
getBlockNodeIdMapping_mapping
,
0xFF
,
USHRT_MAX
*
sizeof
(
content_t
));
std
::
set
<
content_t
>
unknown_contents
;
content_t
id_counter
=
0
;
for
(
u32
i
=
0
;
i
<
MAP_BLOCKSIZE
*
MAP_BLOCKSIZE
*
MAP_BLOCKSIZE
;
i
++
)
...
...
@@ -464,16 +470,14 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
content_t
id
=
CONTENT_IGNORE
;
// Try to find an existing mapping
std
::
map
<
content_t
,
content_t
>::
iterator
j
=
mapping
.
find
(
global_id
);
if
(
j
!=
mapping
.
end
())
{
id
=
j
->
second
;
if
(
getBlockNodeIdMapping_mapping
[
global_id
]
!=
0xFFFF
)
{
id
=
getBlockNodeIdMapping_mapping
[
global_id
];
}
else
{
// We have to assign a new mapping
id
=
id_counter
++
;
mapping
.
insert
(
std
::
make_pair
(
global_id
,
id
))
;
getBlockNodeIdMapping_mapping
[
global_id
]
=
id
;
const
ContentFeatures
&
f
=
nodedef
->
get
(
global_id
);
const
std
::
string
&
name
=
f
.
name
;
...
...
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