def HandleDeleteObjectEvent(self, event): """Handle the delete object event. In this case, rather than delete the object from the scene completely, mothball it in a location well away from the simulation. """ vname = event.ObjectIdentity if vname not in self.Vehicles: self.__Logger.warn("attempt to delete unknown vehicle %s" % (vname)) return True vehicle = self.Vehicles[event.ObjectIdentity] self.VehicleReuseList[vehicle.VehicleType].append(vehicle) mothball = OpenSimVehicleDynamics() mothball.Position = ValueTypes.Vector3(10.0, 10.0, 500.0) mothball.UpdateTime = self.CurrentTime vehicle.TweenUpdate = mothball vehicle.LastUpdate = mothball vehicle.InUpdateQueue = True self.WorkQ.put(vehicle.VehicleName) # result = self.OpenSimConnector.DeleteObject(vehicleID) # print "Deleted vehicle " + vname + " with id " + str(vehicle) return True
def HandleDeleteObjectEvent(self): """Handle the delete object event. In this case, rather than delete the object from the scene completely, mothball it in a location well away from the simulation. """ deleted = self.frame.deleted(MovingVehicle) for car in deleted: vname = car.Name self.__Logger.info("deleting car %s from OpenSim", vname) if vname not in self.Vehicles2Sim: self.__Logger.warn("attempt to delete unknown vehicle %s" % (vname)) continue sim = self.Vehicles2Sim[vname] vehicle = sim["Vehicles"][car.Name] sim["VehicleReuseList"][vehicle.VehicleType].append(vehicle) mothball = OpenSimVehicleDynamics() mothball.Position = ValueTypes.Vector3(10.0, 10.0, 500.0) mothball.UpdateTime = self.CurrentTime vehicle.TweenUpdate = mothball vehicle.LastUpdate = mothball vehicle.InUpdateQueue = True self.WorkQ.put(vehicle.VehicleName) # result = self.OpenSimConnector.DeleteObject(vehicleID) # result = sim["RemoteControl"].DeleteObject(vehicleID) # print "Deleted vehicle " + vname + " with id " + str(vehicle) return True
def __init__(self, world, person): self.World = world self.Person = person self.LocationKeyMap = {} self.LocationKeyMap['home'] = ValueTypes.WeightedChoice( {self.Person: 1.0}) self.LocationKeyMap['work'] = ValueTypes.WeightedChoice( {self.Person.EmployedBy: 1.0}) self.AddLocationKey('coffee', SocialDecoration.BusinessType.Food, 'coffee') self.AddLocationKey('lunch', SocialDecoration.BusinessType.Food, 'fastfood') self.AddLocationKey('dinner', SocialDecoration.BusinessType.Food, 'small-restaurant') self.AddLocationKey('shopping', SocialDecoration.BusinessType.Service, None)
def __NormalizeVelocity(self, speed, heading): # i'm not at all sure why the coordinates for speed are off # by 270 degrees... but this works heading = (2.0 * (heading + 270.0) * math.pi) / 360.0 # the 0.9 multiplier just makes sure we dont overestimate # the velocity because of the time shifting, experience # is better if the car falls behind a bit rather than # having to be moved back because it got ahead x = self.VelocityFudgeFactor * self.TimeScale * speed * math.cos( heading) y = self.VelocityFudgeFactor * self.TimeScale * speed * math.sin( heading) return ValueTypes.Vector3(x / self.XSize, y / self.YSize, 0.0)
def _CreatePreferenceList(self, bizlist): """ Args: bizlist -- non-empty list of SocialNodes.Business objects """ if not bizlist: raise ValueError( "no businesses specified for preference list for %s" % self.Person.Name) plist = ValueTypes.WeightedChoice() for biz in bizlist: weight = self.Person.Preference.GetWeight(biz.Name) if weight: plist.AddChoice(biz, weight) # make sure there is at least one on the list if not plist.Choices(): plist.AddChoice(random.choice(bizlist), 1.0) return plist
def __NormalizeCoordinate(self, pos): return ValueTypes.Vector3((pos[0] - self.XBase) / self.XSize, (pos[1] - self.YBase) / self.YSize, 0.0)
def __init__(self, evrouter, settings, world, netsettings): """Initialize the OpenSimConnector by creating the opensim remote control handlers. Keyword arguments: evhandler -- the initialized event handler, EventRegistry type settings -- dictionary of settings from the configuration file """ EventHandler.EventHandler.__init__(self, evrouter) BaseConnector.BaseConnector.__init__(self, settings, world, netsettings) self.__Logger = logging.getLogger(__name__) # Get the world size wsize = settings["OpenSimConnector"]["WorldSize"] self.WorldSize = ValueTypes.Vector3(wsize[0], wsize[1], wsize[2]) woffs = settings["OpenSimConnector"]["WorldOffset"] self.WorldOffset = ValueTypes.Vector3(woffs[0], woffs[1], woffs[2]) # Initialize the vehicle and vehicle types self.Vehicles = {} self.VehicleReuseList = {} self.VehicleTypes = self.NetSettings.VehicleTypes for vname, vinfo in self.VehicleTypes.iteritems(): self.VehicleReuseList[vname] = deque([]) self.VehicleTypes[vname] = vinfo # Initialize some of the update control variables self.PositionDelta = settings["OpenSimConnector"].get( "PositionDelta", 0.1) self.VelocityDelta = settings["OpenSimConnector"].get( "VelocityDelta", 0.1) self.AccelerationDelta = settings["OpenSimConnector"].get( "AcclerationDelta", 0.1) self.Interpolated = 0 # Setup the remote control object if 'Capability' not in settings["OpenSimConnector"]: self.__Logger.error( "missing or expired opensim remote control capability") sys.exit(-1) self.Capability = uuid.UUID(settings["OpenSimConnector"]["Capability"]) self.EndPoint = settings["OpenSimConnector"]["EndPoint"] self.AsyncEndPoint = settings["OpenSimConnector"]["AsyncEndPoint"] self.Scene = settings["OpenSimConnector"]["Scene"] self.Binary = settings["OpenSimConnector"].get("Binary", False) self.UpdateThreadCount = settings["OpenSimConnector"].get( "UpdateThreadCount", 2) self.DumpCount = 50 self.CurrentStep = 0 self.CurrentTime = 0 self.AverageClockSkew = 0.0 self.Clock = time.time ## this is an ugly hack because the cygwin and linux ## versions of time.clock seem seriously broken if platform.system() == 'Windows': self.Clock = time.clock
def __init__(self): self.Position = ValueTypes.Vector3() self.Velocity = ValueTypes.Vector3() self.Acceleration = ValueTypes.Vector3() self.Rotation = ValueTypes.Quaternion() self.UpdateTime = 0
def __init__(self, settings, world, netsettings, cname, frame): """Initialize the OpenSimConnector by creating the opensim remote control handlers. Keyword arguments: evhandler -- the initialized event handler, EventRegistry type settings -- dictionary of settings from the configuration file """ self.Debug = True if self.Debug == True: self.debug_ct = 0 self.frame = frame if "Interval" in settings["OpenSimConnector"]: self.frame.interval = settings["OpenSimConnector"]["Interval"] BaseConnector.BaseConnector.__init__(self, settings, world, netsettings) self.__Logger = logging.getLogger(__name__) # Get the world size wsize = settings["OpenSimConnector"]["WorldSize"] self.WorldSize = ValueTypes.Vector3(wsize[0], wsize[1], wsize[2]) woffs = settings["OpenSimConnector"]["WorldOffset"] self.WorldOffset = ValueTypes.Vector3(woffs[0], woffs[1], woffs[2]) rsize = settings["OpenSimConnector"]["RegionSize"] self.RegionSizeX = rsize[0] self.RegionSizeY = rsize[1] AuthByUserName(settings) self.RegionMap = GenCoordinateMap(settings) self.Scenes = settings["OpenSimConnector"]["Scenes"] self.Vehicles2Sim = {} for name, sim in self.Scenes.items(): # Initialize the vehicle and vehicle types sim["Vehicles"] = {} sim["VehicleReuseList"] = {} sim["VehicleTypes"] = self.NetSettings.VehicleTypes for vname, vinfo in sim["VehicleTypes"].iteritems(): sim["VehicleReuseList"][vname] = deque([]) sim["VehicleTypes"][vname] = vinfo # Initialize some of the update control variables self.PositionDelta = settings["OpenSimConnector"].get( "PositionDelta", 0.1) self.VelocityDelta = settings["OpenSimConnector"].get( "VelocityDelta", 0.1) self.AccelerationDelta = settings["OpenSimConnector"].get( "AccelerationDelta", 0.1) self.Interpolated = 0 self.Binary = settings["OpenSimConnector"].get("Binary", False) self.UpdateThreadCount = settings["OpenSimConnector"].get( "UpdateThreadCount", 2) self.DumpCount = 50 self.CurrentStep = 0 self.CurrentTime = 0 self.AverageClockSkew = 0.0 self.Clock = time.time ## this is an ugly hack because the cygwin and linux ## versions of time.clock seem seriously broken if platform.system() == 'Windows': self.Clock = time.clock