Fixed events on V8

This commit is contained in:
ksuprynowicz 2023-03-10 22:15:13 +01:00
parent de75aa1794
commit 819ebc9e49
4 changed files with 29 additions and 24 deletions

View file

@ -23,13 +23,15 @@
#include "TouchEvent.h" #include "TouchEvent.h"
#include "WheelEvent.h" #include "WheelEvent.h"
STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ //STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){
auto scriptEngine = manager->engine().get(); // auto scriptEngine = manager->engine().get();
void registerEventTypes(ScriptEngine* scriptEngine){
scriptRegisterMetaType<KeyEvent, KeyEvent::toScriptValue, KeyEvent::fromScriptValue>(scriptEngine, "KeyEvent"); scriptRegisterMetaType<KeyEvent, KeyEvent::toScriptValue, KeyEvent::fromScriptValue>(scriptEngine, "KeyEvent");
scriptRegisterMetaType<MouseEvent, MouseEvent::toScriptValue, MouseEvent::fromScriptValue>(scriptEngine, "MouseEvent"); scriptRegisterMetaType<MouseEvent, MouseEvent::toScriptValue, MouseEvent::fromScriptValue>(scriptEngine, "MouseEvent");
scriptRegisterMetaType<PointerEvent, PointerEvent::toScriptValue, PointerEvent::fromScriptValue>(scriptEngine, "PointerEvent"); scriptRegisterMetaType<PointerEvent, PointerEvent::toScriptValue, PointerEvent::fromScriptValue>(scriptEngine, "PointerEvent");
scriptRegisterMetaType<TouchEvent, TouchEvent::toScriptValue, TouchEvent::fromScriptValue>(scriptEngine, "TouchEvent"); scriptRegisterMetaType<TouchEvent, TouchEvent::toScriptValue, TouchEvent::fromScriptValue>(scriptEngine, "TouchEvent");
scriptRegisterMetaType<WheelEvent, WheelEvent::toScriptValue, WheelEvent::fromScriptValue>(scriptEngine, "WheelEvent"); scriptRegisterMetaType<WheelEvent, WheelEvent::toScriptValue, WheelEvent::fromScriptValue>(scriptEngine, "WheelEvent");
scriptRegisterMetaType<SpatialEvent, SpatialEvent::toScriptValue, SpatialEvent::fromScriptValue>(scriptEngine, "SpatialEvent"); scriptRegisterMetaType<SpatialEvent, SpatialEvent::toScriptValue, SpatialEvent::fromScriptValue>(scriptEngine, "SpatialEvent");
})); }
//}));

View file

@ -104,6 +104,7 @@ static bool scriptableResourceFromScriptValue(const ScriptValue& value, Scriptab
STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){
auto scriptEngine = manager->engine().get(); auto scriptEngine = manager->engine().get();
registerEventTypes(scriptEngine);
scriptRegisterMetaType<ExternalResource::Bucket, externalResourceBucketToScriptValue, externalResourceBucketFromScriptValue>(scriptEngine); scriptRegisterMetaType<ExternalResource::Bucket, externalResourceBucketToScriptValue, externalResourceBucketFromScriptValue>(scriptEngine);
scriptRegisterMetaType<ScriptableResourceRawPtr, scriptableResourceToScriptValue, scriptableResourceFromScriptValue>(scriptEngine); scriptRegisterMetaType<ScriptableResourceRawPtr, scriptableResourceToScriptValue, scriptableResourceFromScriptValue>(scriptEngine);

View file

@ -1384,7 +1384,7 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
} }
_callCounter++; _callCounter++;
if (_callCounter % 10 == 0) { if (_callCounter % 1000 == 0) {
qCDebug(scriptengine_v8) << "Script engine: " << _engine->manager()->getFilename() << " Signal proxy " << fullName() qCDebug(scriptengine_v8) << "Script engine: " << _engine->manager()->getFilename() << " Signal proxy " << fullName()
<< " call count: " << _callCounter << " total time: " << _totalCallTime_s; << " call count: " << _callCounter << " total time: " << _totalCallTime_s;
} }

View file

@ -369,28 +369,30 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
for (h = LEFT_HAND; h <= RIGHT_HAND; h++) { for (h = LEFT_HAND; h <= RIGHT_HAND; h++) {
// XXX find a way to extract searchRay from samuel's stuff // XXX find a way to extract searchRay from samuel's stuff
rayPicks[h].searchRay = { if (controllerLocations[h].valid) {
origin: controllerLocations[h].position, rayPicks[h].searchRay = {
direction: Quat.getUp(controllerLocations[h].orientation), origin: controllerLocations[h].position,
length: 1000 direction: Quat.getUp(controllerLocations[h].orientation),
}; length: 1000
};
if (rayPicks[h].type === Picks.INTERSECTED_ENTITY) { if (rayPicks[h].type === Picks.INTERSECTED_ENTITY) {
// XXX check to make sure this one isn't already in nearbyEntityProperties? // XXX check to make sure this one isn't already in nearbyEntityProperties?
if (rayPicks[h].distance < NEAR_GRAB_PICK_RADIUS * sensorScaleFactor) { if (rayPicks[h].distance < NEAR_GRAB_PICK_RADIUS * sensorScaleFactor) {
var nearEntityID = rayPicks[h].objectID; var nearEntityID = rayPicks[h].objectID;
var nearbyProps = Entities.getEntityProperties(nearEntityID, DISPATCHER_PROPERTIES); var nearbyProps = Entities.getEntityProperties(nearEntityID, DISPATCHER_PROPERTIES);
nearbyProps.id = nearEntityID; nearbyProps.id = nearEntityID;
nearbyProps.distance = rayPicks[h].distance; nearbyProps.distance = rayPicks[h].distance;
nearbyEntityPropertiesByID[nearEntityID] = nearbyProps; nearbyEntityPropertiesByID[nearEntityID] = nearbyProps;
nearbyEntityProperties[h].push(nearbyProps); nearbyEntityProperties[h].push(nearbyProps);
}
} }
}
// sort by distance from each hand // sort by distance from each hand
nearbyEntityProperties[h].sort(function (a, b) { nearbyEntityProperties[h].sort(function (a, b) {
return a.distance - b.distance; return a.distance - b.distance;
}); });
}
} }
// sometimes, during a HMD snap-turn, an equipped or held item wont be near // sometimes, during a HMD snap-turn, an equipped or held item wont be near