mapvision
简介
场景视野
一些说明:
- FMapVisionBase/MapVisionBase是基于ffi实现的;FMapVisionBaseNotffi/MapVisionBaseNotffi是不使用ffi实现的;
ffi版本实现时几个不利的地方:
-
由于使用者需要从脚本层向ffi登记回调函数,为了减少ffi调用脚本层所登记的回调函数的次数,遍历视野时需要构造视野里的实体数组;非ffi版本中则不需要这么处理;
-
由于脚本层只能将实体对象的引用记录在ffi层(比如handle_id),ffi层调用脚本层回调函数时,脚本层回调函数需要将实体对象的 引用还原为实体对象;非ffi版本中则不需要这么处理;
-
ffi版本中,相同情况下,获取实体列表后再遍历,比将回调函数扔给ffi进行遍历快但是相对浪费内存(ffi层调用脚本回调效率低,应该减少调用次数)
功能介绍
- 该包提供基于格子的场景视野功能,包括进程场景、移动的视野维护
- 使用该包的场景对象需要继承
components/FMapVisionBase.gs,在场景中拥有视野的的实体对象需要继承FMapEntityVisionBase.gs
基本使用
-
创建一个具有视野的场景
map1.gs
component pkg.mapvision.components.FMapVisionBase;
void create(map para = nil)
{
// init code
}
use.gs
import .map1;
map para = {
"col" : 100, // 宽100
"row" : 100, // 高100
"vision" : 10 // 视野范围10
};
object map_ob = new_object(map1, this_domain(), para); -
创建一个场景中的实体对象
entity1.gs
component pkg.mapvision.components.FMapEntityVisionBase;
void create(map para = nil)
{
// init code
}
use.gs
import .entity1;
object en_ob = new_object(entity1, this_domain()); -
实体在场景中的一系列动作
// 进入场景
int x = 20;
int y = 30;
map_ob.entity_enter(en_ob, x, y);
// 离开场景
map_ob.entity_leave(en_ob);
// 在场景中移动
int new_x = 30;
int new_y = 40;
map_ob.entity_move(en_ob, new_x, new_y);