SoftLEASH game engine logo

WIKI

LUA / LÖVE

SOFTLEASH / DOCUMENTATION

Spatial Hash

Divide space into cells to make nearby-object queries easier to reason about.

A working outline. The snippets below use plain LÖVE and Lua, not the final SoftLEASH API.

Overview

A spatial hash groups objects into a grid of cells. Instead of checking every object against every other object, a system can first inspect the cells close to the query.


Use this outline for cell sizing, insertion, movement, and region queries. Add a diagram showing which cells are visited for a particular lookup.


LÖVE example

A small, plain LÖVE example for the draft. Replace this snippet with the documented SoftLEASH API and a focused use case later.


local g = love.graphics
local mouse = love.mouse
local size = 64

function love.draw()
    local x,y = mouse.getPosition()
    local cx = math.floor(x / size)
    local cy = math.floor(y / size)
    g.rectangle(
        "line", cx * size, cy * size,
        size, size
    )
    g.print("Move the mouse", 16, 16)
end
local g = love.graphics
local mouse = love.mouse
local size = 64

function love.draw()
    local x,y = mouse.getPosition()
    local cx = math.floor(x / size)
    local cy = math.floor(y / size)
    g.rectangle(
        "line", cx * size, cy * size,
        size, size
    )
    g.print("Move the mouse", 16, 16)
end
local g = love.graphics
local mouse = love.mouse
local size = 64

function love.draw()
    local x,y = mouse.getPosition()
    local cx = math.floor(x / size)
    local cy = math.floor(y / size)
    g.rectangle(
        "line", cx * size, cy * size,
        size, size
    )
    g.print("Move the mouse", 16, 16)
end


What to document next

  • Choosing a useful cell size.

  • Keeping moving objects in the correct cells.

  • Point, rectangle, and neighboring-cell queries.

SOFTLEASH / A GO DOG! TOOL

DOCUMENTATION IN PROGRESS

DOCUMENTATION IN PROGRESS