bmh_admin/controller/entity.js

177 lines
5.6 KiB
JavaScript
Raw Normal View History

2025-03-20 06:16:14 +00:00
const { v1: uuidv1, v3: uuidv3, v4: uuidv4, v5: uuidv5 } = require('uuid');
const util = require("../util/common");
class Entity {
constructor(base) {
this.uid = uuidv4();
this.base = base;
this.animaPath = new Map();
this.userEvent = new Map();
this.eventFunc = new Map();
}
getUID() {
return this.uid;
}
getBase() {
return this.base;
}
init() {
}
insertAnimaPath(t, point) {
this.animaPath.set(t, point);
}
sortAnimaPath() {
const sortMap = new Map([...this.animaPath].sort((a, b) => a[0] - b[0]));
this.animaPath = sortMap;
}
clearAnimaPath() {
this.animaPath.clear();
}
updateAnimaPath(t) {
if (this.animaPath.size > 0) {
const keysArray = [...this.animaPath.keys()];
var indexKey = util.lower_bound(keysArray, t);
if (indexKey < keysArray.length) {
let point = {};
var second = keysArray[indexKey];
if (indexKey == 0) {
if (second <= t) {
point = this.animaPath.get(second);
}
}
else {
var first = keysArray[indexKey - 1];
var delta_time = second - first;
if (delta_time == 0.0) {
point = this.animaPath.get(first);
}
else {
var pointfirst = this.animaPath.get(first);
var pointsecond = this.animaPath.get(second);
point["空速"] = util.interpolate(
(t - first) / delta_time,
pointfirst["空速"],
pointsecond["空速"]);
point["升降率"] = util.interpolate(
(t - first) / delta_time,
pointfirst["升降率"],
pointsecond["升降率"]);
point["过载"] = util.interpolate(
(t - first) / delta_time,
pointfirst["过载"],
pointsecond["过载"]);
point["马赫数"] = util.interpolate(
(t - first) / delta_time,
pointfirst["马赫数"],
pointsecond["马赫数"]);
point["经度"] = util.interpolate(
(t - first) / delta_time,
pointfirst["经度"],
pointsecond["经度"]);
point["纬度"] = util.interpolate(
(t - first) / delta_time,
pointfirst["纬度"],
pointsecond["纬度"]);
point["海拔"] = util.interpolate(
(t - first) / delta_time,
pointfirst["海拔"],
pointsecond["海拔"]);
point["航向角"] = util.interpolate(
(t - first) / delta_time,
pointfirst["航向角"],
pointsecond["航向角"]);
point["俯仰角"] = util.interpolate(
(t - first) / delta_time,
pointfirst["俯仰角"],
pointsecond["俯仰角"]);
point["倾斜角"] = util.interpolate(
(t - first) / delta_time,
pointfirst["倾斜角"],
pointsecond["倾斜角"]);
}
}
return point;
}
}
}
insertUserEvent(t, event) {
event["执行"] = 0;
this.userEvent.set(t, event);
}
clearUserEvent() {
this.userEvent.clear();
}
removeUserEvent(t) {
this.userEvent.delete(t);
}
removeUserEvent(eventname, eventtype) {
for (const [key, value] of this.userEvent) {
let time = key;
let name = value["事件"];
let type = value["类型"];
if (name == eventname && type == eventtype) {
this.userEvent.delete(time);
}
}
}
bindUserEventFun(event, callback) {
let name = event["事件"];
let type = event["类型"];
let strKey = name + ";" + type;
this.eventFunc.set(strKey, callback);
}
updateUserEvent(t) {
if (this.userEvent.size > 0) {
const tArray = [...this.userEvent.keys()];
var indexT = util.lower_bound(tArray, t);
if (indexT < tArray.length) {
var second = tArray[indexT];
if (second <= t) {
let event = this.userEvent.get(second);
if (event["执行"] == 0) {
event["执行"] = 1;
//this.userEvent.set(second, event);
let name = event["事件"];
let type = event["类型"];
let para = event["参数"];
let callback = this.eventFunc.get(name + ";" + type);
if (callback) {
callback(para);
}
return event;
}
}
}
}
}
}
module.exports = Entity;