Giter Site home page Giter Site logo

aoi's Introduction

aoi

Area of Interest

API

local aoi = require "aoi"

-- create aoi object
local aoi_obj = aoi.aoi_new(map_row, map_col, grid_row, grid_col)

-- add  watcher and maker object
local marked = aoi.WATCHER_MARK | aoi.MAKER_MARK
aoi_obj:aoi_add(obj_id, marked, pos_x, pos_y)

-- remove object
aoi_obj:aoi_remove(obj_id)

-- set object, pos_x in range [0, map_col), pos_y in range [0, map_row)
aoi_obj:aoi_set(obj_id, pos_x, pos_y)

-- update aoi
local ret = aoi_obj:aoi_update()

-- ret table detail:
ret = {
    [watcher_id1] = {
        { 
            [maker_id1] = { id=1, pos_x = 11, pos_y = 22, status = "A" },   -- add 1 object
            [maker_id2] = { id=2, pos_x = 11, pos_y = 22, status = "U" },   -- update 2 object
            ...
        },
        {
          [maker_id3] = { id=3, status = "D" },   -- remove 3 object  
          ...
        }
        ...
    },
    ...
}

-- get maker objects of 9 grids by obj_id.
local ret = aoi_obj:aoi_get_objs_by_obj(obj_id)

-- ret table detail:
ret = {
    [maker_id1] = { id=1, pos_x = 11, pos_y = 22},
    [maker_id2] = { id=2, pos_x = 11, pos_y = 22},
    ...
}

benchmark

test 10K object add in same grid, cost 0.028496s. in my Intel(R) Core(TM) i7-4578U CPU @ 3.00GHz.

read aoi_test.lua for more detail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.