Skip to content

Commit

Permalink
Add AreaStore data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Jul 27, 2015
1 parent 454a290 commit c30a2d6
Show file tree
Hide file tree
Showing 15 changed files with 1,263 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.txt
Expand Up @@ -164,6 +164,7 @@ ENABLE_GETTEXT - Build with Gettext; Allows using translations
ENABLE_GLES - Search for Open GLES headers & libraries and use them
ENABLE_LEVELDB - Build with LevelDB; Enables use of LevelDB map backend (faster than SQLite3)
ENABLE_REDIS - Build with libhiredis; Enables use of Redis map backend
ENABLE_SPATIAL - Build with LibSpatial; Speeds up AreaStores
ENABLE_SOUND - Build with OpenAL, libogg & libvorbis; in-game Sounds
ENABLE_LUAJIT - Build with LuaJIT (much faster than non-JIT Lua)
ENABLE_SYSTEM_GMP - Use GMP from system (much faster than bundled mini-gmp)
Expand Down Expand Up @@ -197,6 +198,8 @@ LEVELDB_LIBRARY - Only when building with LevelDB; path to lible
LEVELDB_DLL - Only when building with LevelDB on Windows; path to libleveldb.dll
REDIS_INCLUDE_DIR - Only when building with Redis support; directory that contains hiredis.h
REDIS_LIBRARY - Only when building with Redis support; path to libhiredis.a/libhiredis.so
SPATIAL_INCLUDE_DIR - Only if you want to build with LibSpatial; directory that contains spatialindex/SpatialIndex.h
SPATIAL_LIBRARY - Only if you want to build with LibSpatial; path to libspatialindex_c.so
LUA_INCLUDE_DIR - Only if you want to use LuaJIT; directory where luajit.h is located
LUA_LIBRARY - Only if you want to use LuaJIT; path to libluajit.a/libluajit.so
MINGWM10_DLL - Only if compiling with MinGW; path to mingwm10.dll
Expand Down
2 changes: 2 additions & 0 deletions build/android/jni/Android.mk
Expand Up @@ -112,6 +112,7 @@ LOCAL_C_INCLUDES := \
deps/sqlite/

LOCAL_SRC_FILES := \
jni/src/areastore.cpp \
jni/src/ban.cpp \
jni/src/camera.cpp \
jni/src/cavegen.cpp \
Expand Down Expand Up @@ -283,6 +284,7 @@ LOCAL_SRC_FILES += \
jni/src/script/cpp_api/s_player.cpp \
jni/src/script/cpp_api/s_security.cpp \
jni/src/script/cpp_api/s_server.cpp \
jni/src/script/lua_api/l_areastore.cpp \
jni/src/script/lua_api/l_base.cpp \
jni/src/script/lua_api/l_craft.cpp \
jni/src/script/lua_api/l_env.cpp \
Expand Down
22 changes: 22 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -2602,6 +2602,28 @@ An `InvRef` is a reference to an inventory.
* `get_location()`: returns a location compatible to `minetest.get_inventory(location)`
* returns `{type="undefined"}` in case location is not known

### `AreaStore`
A fast access data structure to store areas, and find areas near a given position or area.
Every area has a `data` string attribute to store additional information.
You can create an empty `AreaStore` by calling `AreaStore()`, or `AreaStore(type_name)`.
If you chose the parameter-less constructor, a fast implementation will be automatically chosen for you.

#### Methods
* `get_area(id, include_borders, include_data)`: returns the area with the id `id`. (optional) Boolean values `include_borders` and `include_data` control what's copied.
* `get_areas_for_pos(pos, include_borders, include_data)`: returns all areas that contain the position `pos`. (optional) Boolean values `include_borders` and `include_data` control what's copied.
* `get_areas_in_area(edge1, edge2, accept_overlap, include_borders, include_data)`: returns all areas that contain all nodes inside the area specified by `edge1` and `edge2` (inclusive). If `accept_overlap` is true, also areas are returned that have nodes in common with the specified area. (optional) Boolean values `include_borders` and `include_data` control what's copied.
* `insert_area(edge1, edge2, data)`: inserts an area into the store. Returns the id if successful, nil otherwise. The (inclusive) positions `edge1` and `edge2` describe the area, `data`
is a string stored with the area.
* `reserve(count)`: reserves resources for at most `count` many contained areas. Only needed for efficiency, and only some implementations profit.
* `remove_area(id)`: removes the area with the given id from the store, returns success.
* `set_cache_params(params)`: sets params for the included prefiltering cache. Calling invalidates the cache, so that its elements have to be newly generated.
* `params`:
{
enabled = boolean, -- whether to enable, default true
block_radius = number, -- the radius (in nodes) of the areas the cache generates prefiltered lists for, minimum 16, default 64
limit = number, -- the cache's size, minimum 20, default 1000
}

### `ItemStack`
An `ItemStack` is a stack of items.

Expand Down
22 changes: 22 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -180,6 +180,21 @@ endif(ENABLE_REDIS)
find_package(SQLite3 REQUIRED)
find_package(Json REQUIRED)

OPTION(ENABLE_SPATIAL "Enable SpatialIndex AreaStore backend" TRUE)
set(USE_SPATIAL FALSE)

if(ENABLE_SPATIAL)
find_library(SPATIAL_LIBRARY spatialindex)
find_path(SPATIAL_INCLUDE_DIR spatialindex/SpatialIndex.h)
if(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
set(USE_SPATIAL TRUE)
message(STATUS "SpatialIndex AreaStore backend enabled.")
include_directories(${SPATIAL_INCLUDE_DIR})
else(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
message(STATUS "SpatialIndex not found!")
endif(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
endif(ENABLE_SPATIAL)


if(NOT MSVC)
set(USE_GPROF FALSE CACHE BOOL "Use -pg flag for g++")
Expand Down Expand Up @@ -289,6 +304,7 @@ add_subdirectory(unittest)
add_subdirectory(util)

set(common_SRCS
areastore.cpp
ban.cpp
cavegen.cpp
clientiface.cpp
Expand Down Expand Up @@ -532,6 +548,9 @@ if(BUILD_CLIENT)
if (USE_REDIS)
target_link_libraries(${PROJECT_NAME} ${REDIS_LIBRARY})
endif()
if (USE_SPATIAL)
target_link_libraries(${PROJECT_NAME} ${SPATIAL_LIBRARY})
endif()
endif(BUILD_CLIENT)


Expand All @@ -556,6 +575,9 @@ if(BUILD_SERVER)
if (USE_REDIS)
target_link_libraries(${PROJECT_NAME}server ${REDIS_LIBRARY})
endif()
if (USE_SPATIAL)
target_link_libraries(${PROJECT_NAME}server ${SPATIAL_LIBRARY})
endif()
if(USE_CURL)
target_link_libraries(
${PROJECT_NAME}server
Expand Down

8 comments on commit c30a2d6

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files should use lowercase underscore style (s/(l_|test_|)areastore.(h|cpp)/\1area_store.\2/).

@est31
Copy link
Contributor Author

@est31 est31 commented on c30a2d6 Jul 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we perhaps rename us to mine-test???
I agree to splitting up too long names, but avoiding an extra _ for a 4 char word, is that so bad?
I perhaps have a german language bias.

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minetest is an established word because it's a proper name. Areastore isn't. If you don't use underscores in some cases then where do you draw the line?

@est31
Copy link
Contributor Author

@est31 est31 commented on c30a2d6 Jul 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps you are right and such an underscore is better, everywhere. Perhaps we should allow exceptions for single syllables (no strict rule here, the creator decides whether to write it with _ or without, also not coupled to the CamelCase of the class name).

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you being sarcastic? I'm not sure what you're getting at. Established compound words like "filename" are O.K. either way, but words that aren't commonly used together in a compound word aren't.

@est31
Copy link
Contributor Author

@est31 est31 commented on c30a2d6 Jul 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just say that I'm perfectly comfortable with having areastore.cpp, nodedef.h, minimap.cpp, nodemetadata.cpp, httpfetch.cpp, hud.cpp, etc.

@est31
Copy link
Contributor Author

@est31 est31 commented on c30a2d6 Jul 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I ask where do you draw the line? map_gen or mapgen? You'd like to write file_cache.cpp, but keep filesys.h?

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mapgen is acceptable as a single word since it's commonly used. Filesys should be separated though.

It's really hard to come up with a good, well defined line. We don't want everything crammed together, but we don't want to require separators in common compound words either. It's kind of up to your best judgement. Area store just seems like something that should be separated to me since it isn't a common compound word.

Please sign in to comment.