• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BuckarooBanzay / mapblock_lib / 8748698230

19 Apr 2024 05:08AM UTC coverage: 19.22% (-35.6%) from 54.827%
8748698230

Pull #3

github

BuckarooBanzay
mtt action
Pull Request #3: mtt action

202 of 1051 relevant lines covered (19.22%)

16.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.45
/create_catalog.lua
1
---------
2
-- Create catalog function
3
local global_env = ...
1✔
4

5
------
6
-- Serialize options
7
-- @number delay for async mode: delay between serialization-calls
8
-- @field callback function to call when the blocks are serialized
9
-- @field progress_callback function to call when the progress is update
10
-- @table serialize_options
11

12
--- create a new catalog and serialize the mapblocks from pos1 to pos2 in it
13
-- @see create_catalog.lua
14
-- @string filename the filename to save to
15
-- @param pos1 @{util.mapblock_pos} the first (lower) mapblock position
16
-- @param pos2 @{util.mapblock_pos} the second (upper) mapblock position
17
-- @param options[opt] @{serialize_options} serialization options
18
function mapblock_lib.create_catalog(filename, pos1, pos2, options)
2✔
19
        local f = global_env.io.open(filename, "wb")
×
20
        local z = mtzip.zip(f)
×
21

22
        local iterator, total_count = mapblock_lib.pos_iterator(pos1, pos2)
×
23
        local mapblock_pos
24
        local count = 0
×
25

26
        -- default to async serialization
27
        options = options or {}
×
28
        options.delay = options.delay or 0.2
×
29
        options.callback = options.callback or function() end
×
30
        options.progress_callback = options.progress_callback or function() end
×
31

32
        pos1, pos2 = mapblock_lib.sort_pos(pos1, pos2)
×
33
        local start = minetest.get_us_time()
×
34

35
        local worker
36
        worker = function()
37
                mapblock_pos = iterator()
×
38
                if mapblock_pos then
×
39
                        local rel_pos = vector.subtract(mapblock_pos, pos1)
×
40
                        local mapblock = mapblock_lib.serialize_mapblock(mapblock_pos)
×
41

42
                        -- only serialize non-air blocks
43
                        if not mapblock.air_only then
×
44
                                z:add("mapblock_" .. minetest.pos_to_string(rel_pos) .. ".bin",mapblock_lib.write_mapblock(mapblock))
×
45
                                z:add("mapblock_" .. minetest.pos_to_string(rel_pos) .. ".meta.json",mapblock_lib.write_mapblock_manifest(mapblock))
×
46
                        end
47

48
                        count = count + 1
×
49
                        options.progress_callback(count / total_count)
×
50
                        minetest.after(options.delay, worker)
×
51
                else
52
                        -- done, write global manifest
53
                        local manifest = {
×
54
                                range = vector.subtract(pos2, pos1),
55
                                version = mapblock_lib.version
×
56
                        }
57
                        z:add("manifest.json", minetest.write_json(manifest))
×
58
                        z:close()
×
59
                        f:close()
×
60
                        options.progress_callback(1)
×
61
                        local micros = minetest.get_us_time() - start
×
62
                        options.callback(count, micros)
×
63
                end
64
        end
65

66
        -- initial call
67
        worker()
×
68
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc