aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 14:54:35 +0100
committerUbitUmarov2015-09-01 14:54:35 +0100
commit371c9dd2af01a2e7422ec901ee1f80757284a78c (patch)
tree058d2a513cacb12efcce0c0df0ae14ad135dbfe2
parentremove lixo (diff)
parentdont change camera on crossings (diff)
downloadopensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz
bad merge?
Diffstat (limited to '')
-rw-r--r--.gitignore3
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs288
-rw-r--r--OpenSim/Capabilities/Caps.cs14
-rw-r--r--OpenSim/Capabilities/CapsHandlers.cs1
-rw-r--r--OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs2
-rw-r--r--OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs194
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs224
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs4
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs4
-rw-r--r--OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs15
-rw-r--r--OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs438
-rw-r--r--OpenSim/Capabilities/LLSDAssetUploadComplete.cs3
-rw-r--r--OpenSim/Capabilities/LLSDAssetUploadRequest.cs15
-rw-r--r--OpenSim/Capabilities/LLSDAssetUploadResponse.cs33
-rw-r--r--OpenSim/Data/AssetDataBase.cs2
-rw-r--r--OpenSim/Data/IAssetData.cs2
-rw-r--r--OpenSim/Data/IProfilesData.cs2
-rw-r--r--OpenSim/Data/IUserAccountData.cs1
-rw-r--r--OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs2
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs41
-rw-r--r--OpenSim/Data/MySQL/MySQLFramework.cs21
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs7
-rw-r--r--OpenSim/Data/MySQL/MySQLRegionData.cs73
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs306
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs46
-rw-r--r--OpenSim/Data/MySQL/MySQLUserProfilesData.cs33
-rw-r--r--OpenSim/Data/MySQL/MySQLXAssetData.cs2
-rw-r--r--OpenSim/Data/MySQL/Resources/RegionStore.migrations5
-rw-r--r--OpenSim/Data/MySQL/Resources/UserProfiles.migrations3
-rw-r--r--OpenSim/Data/Null/NullRegionData.cs8
-rw-r--r--OpenSim/Data/Null/NullSimulationData.cs5
-rw-r--r--OpenSim/Data/Null/NullUserAccountData.cs5
-rw-r--r--OpenSim/Data/PGSQL/PGSQLAssetData.cs3
-rw-r--r--OpenSim/Data/PGSQL/PGSQLUserAccountData.cs5
-rw-r--r--OpenSim/Data/PGSQL/Resources/UserProfiles.migrations5
-rw-r--r--OpenSim/Data/SQLite/Resources/UserProfiles.migrations12
-rw-r--r--OpenSim/Data/SQLite/SQLiteAssetData.cs4
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs6
-rw-r--r--OpenSim/Data/SQLite/SQLiteUserAccountData.cs5
-rw-r--r--OpenSim/Data/SQLite/SQLiteUserProfilesData.cs2
-rw-r--r--OpenSim/Framework/AnimationSet.cs168
-rw-r--r--OpenSim/Framework/AssetBase.cs13
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs49
-rw-r--r--OpenSim/Framework/AvatarWearable.cs21
-rw-r--r--OpenSim/Framework/BlockingQueue.cs5
-rw-r--r--OpenSim/Framework/ChildAgentDataUpdate.cs202
-rw-r--r--OpenSim/Framework/ColliderData.cs1
-rw-r--r--OpenSim/Framework/Communications/RestClient.cs48
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs19
-rw-r--r--OpenSim/Framework/CustomTypes.cs43
-rw-r--r--OpenSim/Framework/EstateSettings.cs23
-rw-r--r--OpenSim/Framework/IClientAPI.cs41
-rw-r--r--OpenSim/Framework/ILandChannel.cs2
-rw-r--r--OpenSim/Framework/ILandObject.cs2
-rw-r--r--OpenSim/Framework/IMoneyModule.cs3
-rw-r--r--OpenSim/Framework/LandData.cs34
-rw-r--r--OpenSim/Framework/LandUpdateArgs.cs3
-rw-r--r--OpenSim/Framework/LocklessQueue.cs8
-rw-r--r--OpenSim/Framework/Monitoring/BaseStatsCollector.cs21
-rw-r--r--OpenSim/Framework/Monitoring/ServerStatsCollector.cs43
-rw-r--r--OpenSim/Framework/Monitoring/Stats/Stat.cs13
-rw-r--r--OpenSim/Framework/Monitoring/StatsManager.cs15
-rw-r--r--OpenSim/Framework/Monitoring/Watchdog.cs2
-rw-r--r--OpenSim/Framework/NetworkServersInfo.cs2
-rw-r--r--OpenSim/Framework/OSChatMessage.cs21
-rw-r--r--OpenSim/Framework/ObjectChangeData.cs80
-rw-r--r--OpenSim/Framework/ParcelMediaCommandEnum.cs2
-rw-r--r--OpenSim/Framework/PermissionsUtil.cs4
-rw-r--r--OpenSim/Framework/PluginLoader.cs18
-rw-r--r--OpenSim/Framework/PrimitiveBaseShape.cs38
-rw-r--r--OpenSim/Framework/PriorityQueue.cs37
-rw-r--r--OpenSim/Framework/RegionInfo.cs270
-rw-r--r--OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs110
-rw-r--r--OpenSim/Framework/RegionSettings.cs24
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs29
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs107
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs4
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs60
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs215
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs4
-rw-r--r--OpenSim/Framework/Servers/Tests/OSHttpTests.cs326
-rw-r--r--OpenSim/Framework/TaskInventoryDictionary.cs189
-rw-r--r--OpenSim/Framework/TaskInventoryItem.cs2
-rw-r--r--OpenSim/Framework/TerrainData.cs320
-rw-r--r--OpenSim/Framework/Tests/MundaneFrameworkTests.cs6
-rw-r--r--OpenSim/Framework/ThrottleOutPacketType.cs2
-rw-r--r--OpenSim/Framework/UserProfileData.cs4
-rw-r--r--OpenSim/Framework/UserProfiles.cs8
-rw-r--r--OpenSim/Framework/Util.cs253
-rw-r--r--OpenSim/Framework/VersionInfo.cs8
-rw-r--r--OpenSim/Framework/WearableCacheItem.cs70
-rw-r--r--OpenSim/Framework/WebUtil.cs151
-rw-r--r--OpenSim/Region/Application/Application.cs1
-rw-r--r--OpenSim/Region/Application/OpenSim.cs38
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs92
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs978
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs703
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs490
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs22
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs410
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs427
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs18
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs297
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs9
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs20
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs184
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs12
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs3
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs1694
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs303
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs423
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs10
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs12
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs219
-rw-r--r--OpenSim/Region/ClientStack/RegionApplicationBase.cs30
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs28
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs206
-rw-r--r--OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs11
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs5
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs178
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs14
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs389
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs11
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs216
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs5
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs6
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Groups/GroupsModule.cs260
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs67
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs113
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs112
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs3
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs175
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs30
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs187
-rw-r--r--OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs104
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs1027
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs4
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs20
-rw-r--r--OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs263
-rw-r--r--OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs98
-rw-r--r--OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs233
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs454
-rw-r--r--OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs2
-rw-r--r--OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs2
-rw-r--r--OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs76
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsIn/UserProfiles/LocalUserProfilesServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs7
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs69
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs27
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs15
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs8
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs12
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs15
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs92
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs33
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs75
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandChannel.cs32
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs687
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs233
-rw-r--r--OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs18
-rw-r--r--OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Region/RestartModule.cs127
-rw-r--r--OpenSim/Region/CoreModules/World/Sound/SoundModule.cs176
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs15
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs3
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs3
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs29
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs28
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs13
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs30
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs16
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs480
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs122
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs64
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs99
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs607
-rw-r--r--OpenSim/Region/DataSnapshot/DataSnapshotManager.cs23
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAgentAssetTransactions.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IBakedTextureModule.cs3
-rw-r--r--OpenSim/Region/Framework/Interfaces/ICapabilitiesModule.cs8
-rw-r--r--OpenSim/Region/Framework/Interfaces/IDynamicMenuModule.cs1
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityInventory.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs8
-rw-r--r--OpenSim/Region/Framework/Interfaces/IHttpRequests.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs18
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs5
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionConsole.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRestartModule.cs1
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISearchModule.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs1
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISnmpModule.cs27
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISoundModule.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/ITerrainModule.cs15
-rw-r--r--OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs13
-rw-r--r--OpenSim/Region/Framework/Interfaces/IWorldComm.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/IWorldMapModule.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/MovementAnimationOverrides.cs101
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs373
-rw-r--r--OpenSim/Region/Framework/Scenes/CollisionSounds.cs304
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs71
-rw-r--r--OpenSim/Region/Framework/Scenes/KeyframeMotion.cs222
-rw-r--r--OpenSim/Region/Framework/Scenes/Prioritizer.cs72
-rw-r--r--OpenSim/Region/Framework/Scenes/SOPMaterial.cs95
-rw-r--r--OpenSim/Region/Framework/Scenes/SOPVehicle.cs791
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs514
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs160
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs6
-rwxr-xr-xOpenSim/Region/Framework/Scenes/Scene.cs888
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs601
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs11
-rwxr-xr-xOpenSim/Region/Framework/Scenes/SceneGraph.cs496
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs246
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs19
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs1703
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs1632
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs812
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs2325
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs141
-rwxr-xr-xOpenSim/Region/Framework/Scenes/SimStatsReporter.cs142
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainChannel.cs44
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs25
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs7
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/UndoState.cs367
-rw-r--r--OpenSim/Region/Framework/Scenes/UuidGatherer.cs40
-rw-r--r--OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs47
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs3
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs4
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs4
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs82
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs33
-rw-r--r--OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs39
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs5
-rw-r--r--OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs38
-rw-r--r--OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs7
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs53
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs62
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs4
-rw-r--r--OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs6
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/AssemblyInfo.cs58
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/ODECharacter.cs1467
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs4124
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/ODERayCastRequestManager.cs384
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/OdePhysicsJoint.cs48
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs3887
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs353
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/Tests/ODETestClass.cs122
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/drawstuff.cs98
-rw-r--r--OpenSim/Region/Physics/Manager/IMesher.cs29
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsActor.cs227
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs8
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs62
-rw-r--r--OpenSim/Region/Physics/Manager/VehicleConstants.cs45
-rw-r--r--OpenSim/Region/Physics/Manager/ZeroMesher.cs22
-rw-r--r--OpenSim/Region/Physics/Meshing/Mesh.cs79
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs18
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMap.cs62
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs5
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs14
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs14
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs309
-rw-r--r--OpenSim/Region/Physics/POSPlugin/POSPrim.cs2
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/HelperTypes.cs340
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/Mesh.cs601
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs1424
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/PrimMesher.cs1708
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/SculptMap.cs244
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs220
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs58
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs1847
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs1096
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs933
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs3897
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs683
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs356
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs2025
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs90
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs2869
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerLargeLandChannel.cs1
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerPermissionModule.cs4
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionConnections.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs30
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs117
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs3786
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs168
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs46
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs71
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs17
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs95
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs45
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs210
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs52
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/EventManager.cs3
-rwxr-xr-xOpenSim/Region/ScriptEngine/XEngine/XEngine.cs381
-rw-r--r--OpenSim/Server/Base/HttpServerBase.cs30
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs9
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs3
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginHandlers.cs11
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs18
-rw-r--r--OpenSim/Server/Handlers/Map/MapGetServerConnector.cs28
-rw-r--r--OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs253
-rw-r--r--OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs2
-rw-r--r--OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs3
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs39
-rw-r--r--OpenSim/Server/ServerMain.cs5
-rw-r--r--OpenSim/Services/AssetService/AssetService.cs5
-rw-r--r--OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs9
-rw-r--r--OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs90
-rw-r--r--OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs11
-rw-r--r--OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs19
-rw-r--r--OpenSim/Services/Base/ServiceBase.cs7
-rw-r--r--OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs347
-rw-r--r--OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs7
-rw-r--r--OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs68
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServicesConnector.cs10
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs6
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs4
-rw-r--r--OpenSim/Services/Connectors/Land/LandServicesConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs66
-rw-r--r--OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs6
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs11
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs6
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs90
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs6
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs21
-rw-r--r--OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs6
-rw-r--r--OpenSim/Services/GridService/GridService.cs38
-rw-r--r--OpenSim/Services/GridService/HypergridLinker.cs31
-rw-r--r--OpenSim/Services/HypergridService/UserAccountCache.cs5
-rw-r--r--OpenSim/Services/Interfaces/IAttachmentsService.cs17
-rw-r--r--OpenSim/Services/Interfaces/IAuthenticationService.cs1
-rw-r--r--OpenSim/Services/Interfaces/IAvatarService.cs29
-rw-r--r--OpenSim/Services/Interfaces/IBakedTextureService.cs9
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs125
-rw-r--r--OpenSim/Services/Interfaces/ILoginService.cs4
-rw-r--r--OpenSim/Services/Interfaces/IMapImageService.cs6
-rw-r--r--OpenSim/Services/Interfaces/ISimulationService.cs8
-rw-r--r--OpenSim/Services/Interfaces/IUserAccountService.cs5
-rw-r--r--OpenSim/Services/Interfaces/IUserProfilesService.cs5
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginResponse.cs22
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs32
-rw-r--r--OpenSim/Services/MapImageService/MapImageService.cs155
-rw-r--r--OpenSim/Services/SimulationService/SimulationDataService.cs5
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountService.cs21
-rw-r--r--OpenSim/Services/UserProfilesService/UserProfilesService.cs2
-rw-r--r--OpenSim/Tests/Clients/Grid/GridClient.cs205
-rw-r--r--OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs2
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs13
-rw-r--r--OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs3
-rw-r--r--OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs10
-rw-r--r--OpenSim/Tests/Common/Mock/TestClient.cs46
-rw-r--r--OpenSim/Tests/Common/Mock/TestLandChannel.cs1
-rw-r--r--OpenSim/Tests/Common/Mock/TestScene.cs3
-rw-r--r--OpenSim/Tests/Performance/NPCPerformanceTests.cs4
-rwxr-xr-xbin/MsgPack.dllbin0 -> 37376 bytes
-rw-r--r--bin/OpenSim.ini.example4
-rw-r--r--bin/OpenSimDefaults.ini4
-rw-r--r--bin/OpenSimDefaults.ini.example1325
-rw-r--r--bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config7
-rw-r--r--bin/assets/TexturesAssetSet/defaultalpha.jp2bin0 -> 319 bytes
-rw-r--r--bin/enter_uuid.xml7
-rwxr-xr-x[-rw-r--r--]bin/lib32/libode.sobin3051566 -> 3134141 bytes
-rwxr-xr-xbin/lib32/ode.dllbin496640 -> 547840 bytes
-rwxr-xr-xbin/lib64/ode.dllbin656384 -> 651776 bytes
-rw-r--r--bin/set_object_owner.xml8
-rw-r--r--prebuild.xml132
406 files changed, 62371 insertions, 7876 deletions
diff --git a/.gitignore b/.gitignore
index 94f896d..d1f7710 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
1.project 1.project
2.settings 2.settings
3.gitignore
3*.csproj 4*.csproj
4*.csproj.user 5*.csproj.user
5*.build 6*.build
@@ -10,6 +11,7 @@
10*.pidb 11*.pidb
11*.dll.build 12*.dll.build
12*.dll 13*.dll
14*.log
13 15
14# Ignore .user and .suo files as these are user preference specific 16# Ignore .user and .suo files as these are user preference specific
15# http://stackoverflow.com/questions/72298/should-i-add-the-visual-studio-suo-and-user-files-to-source-control 17# http://stackoverflow.com/questions/72298/should-i-add-the-visual-studio-suo-and-user-files-to-source-control
@@ -29,6 +31,7 @@
29*/*/*/*/*/bin 31*/*/*/*/*/bin
30*/*/*/*/*/*/bin 32*/*/*/*/*/*/bin
31*/*/*/*/*/*/*/bin 33*/*/*/*/*/*/*/bin
34addon-modules/
32bin/Debug/*.dll 35bin/Debug/*.dll
33bin/*.dll.mdb 36bin/*.dll.mdb
34bin/*.db 37bin/*.db
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 0228c3c..0c582e1 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -75,6 +75,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
75 75
76 private string m_name = "RemoteAdminPlugin"; 76 private string m_name = "RemoteAdminPlugin";
77 private string m_version = "0.0"; 77 private string m_version = "0.0";
78 private string m_openSimVersion;
78 79
79 public string Version 80 public string Version
80 { 81 {
@@ -94,6 +95,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController
94 95
95 public void Initialise(OpenSimBase openSim) 96 public void Initialise(OpenSimBase openSim)
96 { 97 {
98 m_openSimVersion = openSim.GetVersionText();
99
97 m_configSource = openSim.ConfigSource.Source; 100 m_configSource = openSim.ConfigSource.Source;
98 try 101 try
99 { 102 {
@@ -136,6 +139,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
136 availableMethods["admin_region_query"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRegionQueryMethod); 139 availableMethods["admin_region_query"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRegionQueryMethod);
137 availableMethods["admin_shutdown"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcShutdownMethod); 140 availableMethods["admin_shutdown"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcShutdownMethod);
138 availableMethods["admin_broadcast"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAlertMethod); 141 availableMethods["admin_broadcast"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAlertMethod);
142 availableMethods["admin_dialog"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcDialogMethod);
139 availableMethods["admin_restart"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRestartMethod); 143 availableMethods["admin_restart"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRestartMethod);
140 availableMethods["admin_load_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadHeightmapMethod); 144 availableMethods["admin_load_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadHeightmapMethod);
141 availableMethods["admin_save_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveHeightmapMethod); 145 availableMethods["admin_save_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveHeightmapMethod);
@@ -164,8 +168,11 @@ namespace OpenSim.ApplicationPlugins.RemoteController
164 availableMethods["admin_acl_list"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListList); 168 availableMethods["admin_acl_list"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListList);
165 availableMethods["admin_estate_reload"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcEstateReload); 169 availableMethods["admin_estate_reload"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcEstateReload);
166 170
167 // Land management 171 // Misc
168 availableMethods["admin_reset_land"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcResetLand); 172 availableMethods["admin_refresh_search"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRefreshSearch);
173 availableMethods["admin_refresh_map"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRefreshMap);
174 availableMethods["admin_get_opensim_version"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcGetOpenSimVersion);
175 availableMethods["admin_get_agent_count"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcGetAgentCount);
169 176
170 // Either enable full remote functionality or just selected features 177 // Either enable full remote functionality or just selected features
171 string enabledMethods = m_config.GetString("enabled_methods", "all"); 178 string enabledMethods = m_config.GetString("enabled_methods", "all");
@@ -266,25 +273,105 @@ namespace OpenSim.ApplicationPlugins.RemoteController
266 273
267 try 274 try
268 { 275 {
269 m_log.Info("[RADMIN]: Request to restart Region."); 276 Scene rebootedScene = null;
277 bool restartAll = false;
270 278
271 CheckRegionParams(requestData, responseData); 279 IConfig startupConfig = m_configSource.Configs["Startup"];
280 if (startupConfig != null)
281 {
282 if (startupConfig.GetBoolean("InworldRestartShutsDown", false))
283 {
284 rebootedScene = m_application.SceneManager.CurrentOrFirstScene;
285 restartAll = true;
286 }
287 }
272 288
273 Scene rebootedScene = null; 289 if (rebootedScene == null)
274 GetSceneFromRegionParams(requestData, responseData, out rebootedScene); 290 {
291 CheckRegionParams(requestData, responseData);
292
293 GetSceneFromRegionParams(requestData, responseData, out rebootedScene);
294 }
295
296 IRestartModule restartModule = rebootedScene.RequestModuleInterface<IRestartModule>();
275 297
276 responseData["success"] = false; 298 responseData["success"] = false;
277 responseData["accepted"] = true; 299 responseData["accepted"] = true;
278 responseData["rebooting"] = true; 300 responseData["rebooting"] = true;
279 301
280 IRestartModule restartModule = rebootedScene.RequestModuleInterface<IRestartModule>(); 302 string message;
281 if (restartModule != null) 303 List<int> times = new List<int>();
304
305 if (requestData.ContainsKey("alerts"))
282 { 306 {
283 List<int> times = new List<int> { 30, 15 }; 307 string[] alertTimes = requestData["alerts"].ToString().Split( new char[] {','});
308 if (alertTimes.Length == 1 && Convert.ToInt32(alertTimes[0]) == -1)
309 {
310 m_log.Info("[RADMIN]: Request to cancel restart.");
284 311
285 restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); 312 if (restartModule != null)
286 responseData["success"] = true; 313 {
314 message = "Restart has been cancelled";
315
316 if (requestData.ContainsKey("message"))
317 message = requestData["message"].ToString();
318
319 restartModule.AbortRestart(message);
320
321 responseData["success"] = true;
322 responseData["rebooting"] = false;
323
324 return;
325 }
326 }
327 foreach (string a in alertTimes)
328 times.Add(Convert.ToInt32(a));
329 }
330 else
331 {
332 int timeout = 30;
333 if (requestData.ContainsKey("milliseconds"))
334 timeout = Int32.Parse(requestData["milliseconds"].ToString()) / 1000;
335 while (timeout > 0)
336 {
337 times.Add(timeout);
338 if (timeout > 300)
339 timeout -= 120;
340 else if (timeout > 30)
341 timeout -= 30;
342 else
343 timeout -= 15;
344 }
287 } 345 }
346
347 m_log.Info("[RADMIN]: Request to restart Region.");
348
349 message = "Region is restarting in {0}. Please save what you are doing and log out.";
350
351 if (requestData.ContainsKey("message"))
352 message = requestData["message"].ToString();
353
354 bool notice = true;
355 if (requestData.ContainsKey("noticetype")
356 && ((string)requestData["noticetype"] == "dialog"))
357 {
358 notice = false;
359 }
360
361 List<Scene> restartList;
362
363 if (restartAll)
364 restartList = m_application.SceneManager.Scenes;
365 else
366 restartList = new List<Scene>() { rebootedScene };
367
368 foreach (Scene s in m_application.SceneManager.Scenes)
369 {
370 restartModule = s.RequestModuleInterface<IRestartModule>();
371 if (restartModule != null)
372 restartModule.ScheduleRestart(UUID.Zero, message, times.ToArray(), notice);
373 }
374 responseData["success"] = true;
288 } 375 }
289 catch (Exception e) 376 catch (Exception e)
290 { 377 {
@@ -321,6 +408,32 @@ namespace OpenSim.ApplicationPlugins.RemoteController
321 m_log.Info("[RADMIN]: Alert request complete"); 408 m_log.Info("[RADMIN]: Alert request complete");
322 } 409 }
323 410
411 public void XmlRpcDialogMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
412 {
413 Hashtable responseData = (Hashtable)response.Value;
414
415 m_log.Info("[RADMIN]: Dialog request started");
416
417 Hashtable requestData = (Hashtable)request.Params[0];
418
419 string message = (string)requestData["message"];
420 string fromuuid = (string)requestData["from"];
421 m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
422
423 responseData["accepted"] = true;
424 responseData["success"] = true;
425
426 m_application.SceneManager.ForEachScene(
427 delegate(Scene scene)
428 {
429 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
430 if (dialogModule != null)
431 dialogModule.SendNotificationToUsersInRegion(UUID.Zero, fromuuid, message);
432 });
433
434 m_log.Info("[RADMIN]: Dialog request complete");
435 }
436
324 private void XmlRpcLoadHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) 437 private void XmlRpcLoadHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
325 { 438 {
326 m_log.Info("[RADMIN]: Load height maps request started"); 439 m_log.Info("[RADMIN]: Load height maps request started");
@@ -424,13 +537,32 @@ namespace OpenSim.ApplicationPlugins.RemoteController
424 message = "Region is going down now."; 537 message = "Region is going down now.";
425 } 538 }
426 539
427 m_application.SceneManager.ForEachScene( 540 if (requestData.ContainsKey("noticetype")
541 && ((string) requestData["noticetype"] == "dialog"))
542 {
543 m_application.SceneManager.ForEachScene(
544
428 delegate(Scene scene) 545 delegate(Scene scene)
546 {
547 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
548 if (dialogModule != null)
549 dialogModule.SendNotificationToUsersInRegion(UUID.Zero, "System", message);
550 });
551 }
552 else
553 {
554 if (!requestData.ContainsKey("noticetype")
555 || ((string)requestData["noticetype"] != "none"))
556 {
557 m_application.SceneManager.ForEachScene(
558 delegate(Scene scene)
429 { 559 {
430 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>(); 560 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
431 if (dialogModule != null) 561 if (dialogModule != null)
432 dialogModule.SendGeneralAlert(message); 562 dialogModule.SendGeneralAlert(message);
433 }); 563 });
564 }
565 }
434 566
435 // Perform shutdown 567 // Perform shutdown
436 System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing 568 System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing
@@ -1489,7 +1621,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1489 } 1621 }
1490 1622
1491 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>(); 1623 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
1492 Dictionary<string, object> archiveOptions = new Dictionary<string,object>(); 1624 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
1493 if (mergeOar) archiveOptions.Add("merge", null); 1625 if (mergeOar) archiveOptions.Add("merge", null);
1494 if (skipAssets) archiveOptions.Add("skipAssets", null); 1626 if (skipAssets) archiveOptions.Add("skipAssets", null);
1495 if (archiver != null) 1627 if (archiver != null)
@@ -1749,21 +1881,31 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1749 1881
1750 private void XmlRpcRegionQueryMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) 1882 private void XmlRpcRegionQueryMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1751 { 1883 {
1752 m_log.Info("[RADMIN]: Received Query XML Administrator Request");
1753
1754 Hashtable responseData = (Hashtable)response.Value; 1884 Hashtable responseData = (Hashtable)response.Value;
1755 Hashtable requestData = (Hashtable)request.Params[0]; 1885 Hashtable requestData = (Hashtable)request.Params[0];
1756 1886
1887 int flags = 0;
1888 string text = String.Empty;
1889 int health = 0;
1890 responseData["success"] = true;
1891
1757 CheckRegionParams(requestData, responseData); 1892 CheckRegionParams(requestData, responseData);
1758 1893
1759 Scene scene = null; 1894 Scene scene = null;
1760 GetSceneFromRegionParams(requestData, responseData, out scene); 1895 try
1761 1896 {
1762 int health = scene.GetHealth(); 1897 GetSceneFromRegionParams(requestData, responseData, out scene);
1763 responseData["health"] = health; 1898 health = scene.GetHealth(out flags, out text);
1899 }
1900 catch (Exception e)
1901 {
1902 responseData["error"] = null;
1903 }
1764 1904
1765 responseData["success"] = true; 1905 responseData["success"] = true;
1766 m_log.Info("[RADMIN]: Query XML Administrator Request complete"); 1906 responseData["health"] = health;
1907 responseData["flags"] = flags;
1908 responseData["message"] = text;
1767 } 1909 }
1768 1910
1769 private void XmlRpcConsoleCommandMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) 1911 private void XmlRpcConsoleCommandMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
@@ -2068,55 +2210,97 @@ namespace OpenSim.ApplicationPlugins.RemoteController
2068 responseData["success"] = true; 2210 responseData["success"] = true;
2069 } 2211 }
2070 2212
2071 private void XmlRpcResetLand(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) 2213 private void XmlRpcRefreshSearch(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
2072 { 2214 {
2073 Hashtable requestData = (Hashtable)request.Params[0]; 2215 m_log.Info("[RADMIN]: Received Refresh Search Request");
2216
2074 Hashtable responseData = (Hashtable)response.Value; 2217 Hashtable responseData = (Hashtable)response.Value;
2218 Hashtable requestData = (Hashtable)request.Params[0];
2219
2220 CheckRegionParams(requestData, responseData);
2075 2221
2076 string musicURL = string.Empty; 2222 Scene scene = null;
2077 UUID groupID = UUID.Zero; 2223 GetSceneFromRegionParams(requestData, responseData, out scene);
2078 uint flags = 0;
2079 bool set_group = false, set_music = false, set_flags = false;
2080 2224
2081 if (requestData.Contains("group") && requestData["group"] != null) 2225 ISearchModule searchModule = scene.RequestModuleInterface<ISearchModule>();
2082 set_group = UUID.TryParse(requestData["group"].ToString(), out groupID); 2226 if (searchModule != null)
2083 if (requestData.Contains("music") && requestData["music"] != null)
2084 { 2227 {
2085 musicURL = requestData["music"].ToString(); 2228 searchModule.Refresh();
2086 set_music = true; 2229 responseData["success"] = true;
2087 } 2230 }
2088 if (requestData.Contains("flags") && requestData["flags"] != null) 2231 else
2089 set_flags = UInt32.TryParse(requestData["flags"].ToString(), out flags); 2232 {
2233 responseData["success"] = false;
2234 }
2235
2236 m_log.Info("[RADMIN]: Refresh Search Request complete");
2237 }
2238
2239 private void XmlRpcRefreshMap(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
2240 {
2241 m_log.Info("[RADMIN]: Received Refresh Map Request");
2242
2243 Hashtable responseData = (Hashtable)response.Value;
2244 Hashtable requestData = (Hashtable)request.Params[0];
2090 2245
2091 m_log.InfoFormat("[RADMIN]: Received Reset Land Request group={0} musicURL={1} flags={2}", 2246 CheckRegionParams(requestData, responseData);
2092 (set_group ? groupID.ToString() : "unchanged"),
2093 (set_music ? musicURL : "unchanged"),
2094 (set_flags ? flags.ToString() : "unchanged"));
2095 2247
2096 m_application.SceneManager.ForEachScene(delegate(Scene s) 2248 Scene scene = null;
2249 GetSceneFromRegionParams(requestData, responseData, out scene);
2250
2251 IMapImageUploadModule mapTileModule = scene.RequestModuleInterface<IMapImageUploadModule>();
2252 if (mapTileModule != null)
2097 { 2253 {
2098 List<ILandObject> parcels = s.LandChannel.AllParcels(); 2254 Util.FireAndForget((x) =>
2099 foreach (ILandObject p in parcels)
2100 { 2255 {
2101 if (set_music) 2256 mapTileModule.UploadMapTile(scene);
2102 p.LandData.MusicURL = musicURL; 2257 });
2258 responseData["success"] = true;
2259 }
2260 else
2261 {
2262 responseData["success"] = false;
2263 }
2103 2264
2104 if (set_group) 2265 m_log.Info("[RADMIN]: Refresh Map Request complete");
2105 p.LandData.GroupID = groupID; 2266 }
2106 2267
2107 if (set_flags) 2268 private void XmlRpcGetOpenSimVersion(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
2108 p.LandData.Flags = flags; 2269 {
2270 m_log.Info("[RADMIN]: Received Get OpenSim Version Request");
2109 2271
2110 s.LandChannel.UpdateLandObject(p.LandData.LocalID, p.LandData); 2272 Hashtable responseData = (Hashtable)response.Value;
2111 }
2112 }
2113 );
2114 2273
2274 responseData["version"] = m_openSimVersion;
2115 responseData["success"] = true; 2275 responseData["success"] = true;
2116 2276
2117 m_log.Info("[RADMIN]: Reset Land Request complete"); 2277 m_log.Info("[RADMIN]: Get OpenSim Version Request complete");
2118 } 2278 }
2119 2279
2280 private void XmlRpcGetAgentCount(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
2281 {
2282 m_log.Info("[RADMIN]: Received Get Agent Count Request");
2283
2284 Hashtable responseData = (Hashtable)response.Value;
2285 Hashtable requestData = (Hashtable)request.Params[0];
2286
2287 CheckRegionParams(requestData, responseData);
2288
2289 Scene scene = null;
2290 GetSceneFromRegionParams(requestData, responseData, out scene);
2291
2292 if (scene == null)
2293 {
2294 responseData["success"] = false;
2295 }
2296 else
2297 {
2298 responseData["count"] = scene.GetRootAgentCount();
2299 responseData["success"] = true;
2300 }
2301
2302 m_log.Info("[RADMIN]: Get Agent Count Request complete");
2303 }
2120 2304
2121 /// <summary> 2305 /// <summary>
2122 /// Parse a float with the given parameter name from a request data hash table. 2306 /// Parse a float with the given parameter name from a request data hash table.
@@ -2823,7 +3007,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
2823 /// </summary> 3007 /// </summary>
2824 private void ApplyNextOwnerPermissions(InventoryItemBase item) 3008 private void ApplyNextOwnerPermissions(InventoryItemBase item)
2825 { 3009 {
2826 if (item.InvType == (int)InventoryType.Object) 3010 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
2827 { 3011 {
2828 uint perms = item.CurrentPermissions; 3012 uint perms = item.CurrentPermissions;
2829 PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms); 3013 PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms);
diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs
index 049afab..3efab8e 100644
--- a/OpenSim/Capabilities/Caps.cs
+++ b/OpenSim/Capabilities/Caps.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO; 31using System.IO;
32using System.Reflection; 32using System.Reflection;
33using System.Threading;
33using log4net; 34using log4net;
34using Nini.Config; 35using Nini.Config;
35using OpenMetaverse; 36using OpenMetaverse;
@@ -71,6 +72,7 @@ namespace OpenSim.Framework.Capabilities
71 private IHttpServer m_httpListener; 72 private IHttpServer m_httpListener;
72 private UUID m_agentID; 73 private UUID m_agentID;
73 private string m_regionName; 74 private string m_regionName;
75 private ManualResetEvent m_capsActive = new ManualResetEvent(false);
74 76
75 public UUID AgentID 77 public UUID AgentID
76 { 78 {
@@ -136,6 +138,7 @@ namespace OpenSim.Framework.Capabilities
136 m_agentID = agent; 138 m_agentID = agent;
137 m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL); 139 m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL);
138 m_regionName = regionName; 140 m_regionName = regionName;
141 m_capsActive.Reset();
139 } 142 }
140 143
141 /// <summary> 144 /// <summary>
@@ -255,5 +258,16 @@ namespace OpenSim.Framework.Capabilities
255 258
256 return caps; 259 return caps;
257 } 260 }
261
262 public void Activate()
263 {
264 m_capsActive.Set();
265 }
266
267 public bool WaitForActivation()
268 {
269 // Wait for 30s. If that elapses, return false and run without caps
270 return m_capsActive.WaitOne(120000);
271 }
258 } 272 }
259} \ No newline at end of file 273} \ No newline at end of file
diff --git a/OpenSim/Capabilities/CapsHandlers.cs b/OpenSim/Capabilities/CapsHandlers.cs
index 890df90..04cede1 100644
--- a/OpenSim/Capabilities/CapsHandlers.cs
+++ b/OpenSim/Capabilities/CapsHandlers.cs
@@ -90,6 +90,7 @@ namespace OpenSim.Framework.Capabilities
90 lock (m_capsHandlers) 90 lock (m_capsHandlers)
91 { 91 {
92 m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); 92 m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path);
93 m_httpListener.RemoveStreamHandler("PUT", m_capsHandlers[capsName].Path);
93 m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); 94 m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path);
94 m_capsHandlers.Remove(capsName); 95 m_capsHandlers.Remove(capsName);
95 } 96 }
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
index c904392..638e8bc 100644
--- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
+++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
@@ -114,7 +114,7 @@ namespace OpenSim.Capabilities.Handlers
114 llsdItem.asset_id = invItem.AssetID; 114 llsdItem.asset_id = invItem.AssetID;
115 llsdItem.created_at = invItem.CreationDate; 115 llsdItem.created_at = invItem.CreationDate;
116 llsdItem.desc = invItem.Description; 116 llsdItem.desc = invItem.Description;
117 llsdItem.flags = (int)invItem.Flags; 117 llsdItem.flags = ((int)invItem.Flags) & 0xff;
118 llsdItem.item_id = invItem.ID; 118 llsdItem.item_id = invItem.ID;
119 llsdItem.name = invItem.Name; 119 llsdItem.name = invItem.Name;
120 llsdItem.parent_id = invItem.Folder; 120 llsdItem.parent_id = invItem.Folder;
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
index 6b67da1..7fcc798 100644
--- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
@@ -44,26 +44,64 @@ namespace OpenSim.Capabilities.Handlers
44 public class GetMeshHandler : BaseStreamHandler 44 public class GetMeshHandler : BaseStreamHandler
45 { 45 {
46 private static readonly ILog m_log = 46 private static readonly ILog m_log =
47 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
48 private IAssetService m_assetService; 49 private IAssetService m_assetService;
49 50
50 // TODO: Change this to a config option 51 public const string DefaultFormat = "vnd.ll.mesh";
51 private string m_RedirectURL = null; 52
52 53 public GetMeshHandler(IAssetService assService)
53 public GetMeshHandler(string path, IAssetService assService, string name, string description, string redirectURL)
54 : base("GET", path, name, description)
55 { 54 {
56 m_assetService = assService; 55 m_assetService = assService;
57 m_RedirectURL = redirectURL; 56 m_RedirectURL = redirectURL;
58 if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) 57 if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/"))
59 m_RedirectURL += "/"; 58 m_RedirectURL += "/";
60 } 59 }
60 public Hashtable Handle(Hashtable request)
61 {
62 Hashtable ret = new Hashtable();
63 ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
64 ret["content_type"] = "text/plain";
65 ret["keepalive"] = false;
66 ret["reusecontext"] = false;
67 ret["int_bytes"] = 0;
68 ret["int_lod"] = 0;
69 string MeshStr = (string)request["mesh_id"];
70
71
72 //m_log.DebugFormat("[GETMESH]: called {0}", MeshStr);
73
74 if (m_assetService == null)
75 {
76 m_log.Error("[GETMESH]: Cannot fetch mesh " + MeshStr + " without an asset service");
77 }
78
79 UUID meshID;
80 if (!String.IsNullOrEmpty(MeshStr) && UUID.TryParse(MeshStr, out meshID))
81 {
82 // m_log.DebugFormat("[GETMESH]: Received request for mesh id {0}", meshID);
83
84
85 ret = ProcessGetMesh(request, UUID.Zero, null);
86
87
88 }
89 else
90 {
91 m_log.Warn("[GETMESH]: Failed to parse a mesh_id from GetMesh request: " + (string)request["uri"]);
92 }
61 93
62 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 94
95 return ret;
96 }
97 public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap)
63 { 98 {
64 // Try to parse the texture ID from the request URL 99 // Try to parse the texture ID from the request URL
65 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); 100 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
66 string textureStr = query.GetOne("mesh_id"); 101 string textureStr = query.GetOne("mesh_id");
102 responsedata["reusecontext"] = false;
103 responsedata["int_lod"] = 0;
104 responsedata["int_bytes"] = 0;
67 105
68 if (m_assetService == null) 106 if (m_assetService == null)
69 { 107 {
@@ -160,40 +198,121 @@ namespace OpenSim.Capabilities.Handlers
160 // sending back the last byte instead of an error status 198 // sending back the last byte instead of an error status
161 if (start >= texture.Data.Length) 199 if (start >= texture.Data.Length)
162 { 200 {
163 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
164 response.ContentType = texture.Metadata.ContentType;
165 }
166 else
167 {
168 // Handle the case where no second range value was given. This is equivalent to requesting
169 // the rest of the entity.
170 if (end == -1)
171 end = int.MaxValue;
172 201
173 end = Utils.Clamp(end, 0, texture.Data.Length - 1); 202 Hashtable headers = new Hashtable();
174 start = Utils.Clamp(start, 0, end); 203 responsedata["headers"] = headers;
175 int len = end - start + 1; 204
205 string range = String.Empty;
206
207 if (((Hashtable)request["headers"])["range"] != null)
208 range = (string)((Hashtable)request["headers"])["range"];
176 209
177 if (0 == start && len == texture.Data.Length) 210 else if (((Hashtable)request["headers"])["Range"] != null)
211 range = (string)((Hashtable)request["headers"])["Range"];
212
213 if (!String.IsNullOrEmpty(range)) // Mesh Asset LOD // Physics
178 { 214 {
179 response.StatusCode = (int)System.Net.HttpStatusCode.OK; 215 // Range request
216 int start, end;
217 if (TryParseRange(range, out start, out end))
218 {
219 // Before clamping start make sure we can satisfy it in order to avoid
220 // sending back the last byte instead of an error status
221 if (start >= mesh.Data.Length)
222 {
223 responsedata["int_response_code"] = 404; //501; //410; //404;
224 responsedata["content_type"] = "text/plain";
225 responsedata["keepalive"] = false;
226 responsedata["str_response_string"] = "This range doesnt exist.";
227 responsedata["reusecontext"] = false;
228 responsedata["int_lod"] = 3;
229 return responsedata;
230 }
231 else
232 {
233 end = Utils.Clamp(end, 0, mesh.Data.Length - 1);
234 start = Utils.Clamp(start, 0, end);
235 int len = end - start + 1;
236
237 //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
238
239 if (start > 20000)
240 {
241 responsedata["int_lod"] = 3;
242 }
243 else if (start < 4097)
244 {
245 responsedata["int_lod"] = 1;
246 }
247 else
248 {
249 responsedata["int_lod"] = 2;
250 }
251
252
253 if (start == 0 && len == mesh.Data.Length) // well redudante maybe
254 {
255 responsedata["int_response_code"] = (int) System.Net.HttpStatusCode.OK;
256 responsedata["bin_response_data"] = mesh.Data;
257 responsedata["int_bytes"] = mesh.Data.Length;
258 responsedata["reusecontext"] = false;
259 responsedata["int_lod"] = 3;
260
261 }
262 else
263 {
264 responsedata["int_response_code"] =
265 (int) System.Net.HttpStatusCode.PartialContent;
266 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end,
267 mesh.Data.Length);
268
269 byte[] d = new byte[len];
270 Array.Copy(mesh.Data, start, d, 0, len);
271 responsedata["bin_response_data"] = d;
272 responsedata["int_bytes"] = len;
273 responsedata["reusecontext"] = false;
274 }
275 }
276 }
277 else
278 {
279 m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]);
280 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
281 responsedata["content_type"] = "application/vnd.ll.mesh";
282 responsedata["int_response_code"] = 200;
283 responsedata["reusecontext"] = false;
284 responsedata["int_lod"] = 3;
285 }
180 } 286 }
181 else 287 else
182 { 288 {
183 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; 289 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
184 response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); 290 responsedata["content_type"] = "application/vnd.ll.mesh";
291 responsedata["int_response_code"] = 200;
292 responsedata["reusecontext"] = false;
293 responsedata["int_lod"] = 3;
185 } 294 }
186 295 }
187 response.ContentLength = len; 296 else
188 response.ContentType = "application/vnd.ll.mesh"; 297 {
189 298 responsedata["int_response_code"] = 404; //501; //410; //404;
190 response.Body.Write(texture.Data, start, len); 299 responsedata["content_type"] = "text/plain";
300 responsedata["keepalive"] = false;
301 responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh.";
302 responsedata["reusecontext"] = false;
303 responsedata["int_lod"] = 1;
304 return responsedata;
191 } 305 }
192 } 306 }
193 else 307 else
194 { 308 {
195 m_log.Warn("[GETMESH]: Malformed Range header: " + range); 309 responsedata["int_response_code"] = 404; //501; //410; //404;
196 response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; 310 responsedata["content_type"] = "text/plain";
311 responsedata["keepalive"] = false;
312 responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!";
313 responsedata["reusecontext"] = false;
314 responsedata["int_lod"] = 0;
315 return responsedata;
197 } 316 }
198 } 317 }
199 else 318 else
@@ -249,5 +368,20 @@ namespace OpenSim.Capabilities.Handlers
249 start = end = 0; 368 start = end = 0;
250 return false; 369 return false;
251 } 370 }
371 private bool TryParseRange(string header, out int start, out int end)
372 {
373 if (header.StartsWith("bytes="))
374 {
375 string[] rangeValues = header.Substring(6).Split('-');
376 if (rangeValues.Length == 2)
377 {
378 if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end))
379 return true;
380 }
381 }
382
383 start = end = 0;
384 return false;
385 }
252 } 386 }
253} \ No newline at end of file 387} \ No newline at end of file
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
index 828e943..a8e0fb5 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
@@ -47,10 +47,11 @@ using Caps = OpenSim.Framework.Capabilities.Caps;
47 47
48namespace OpenSim.Capabilities.Handlers 48namespace OpenSim.Capabilities.Handlers
49{ 49{
50 public class GetTextureHandler : BaseStreamHandler 50 public class GetTextureHandler
51 { 51 {
52 private static readonly ILog m_log = 52 private static readonly ILog m_log =
53 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 53 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
54 private IAssetService m_assetService; 55 private IAssetService m_assetService;
55 56
56 public const string DefaultFormat = "x-j2c"; 57 public const string DefaultFormat = "x-j2c";
@@ -58,8 +59,8 @@ namespace OpenSim.Capabilities.Handlers
58 // TODO: Change this to a config option 59 // TODO: Change this to a config option
59 private string m_RedirectURL = null; 60 private string m_RedirectURL = null;
60 61
61 public GetTextureHandler(string path, IAssetService assService, string name, string description, string redirectURL) 62
62 : base("GET", path, name, description) 63 public GetTextureHandler(IAssetService assService)
63 { 64 {
64 m_assetService = assService; 65 m_assetService = assService;
65 m_RedirectURL = redirectURL; 66 m_RedirectURL = redirectURL;
@@ -67,19 +68,22 @@ namespace OpenSim.Capabilities.Handlers
67 m_RedirectURL += "/"; 68 m_RedirectURL += "/";
68 } 69 }
69 70
70 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 71 public Hashtable Handle(Hashtable request)
71 { 72 {
72 // Try to parse the texture ID from the request URL 73 Hashtable ret = new Hashtable();
73 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); 74 ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
74 string textureStr = query.GetOne("texture_id"); 75 ret["content_type"] = "text/plain";
75 string format = query.GetOne("format"); 76 ret["keepalive"] = false;
77 ret["reusecontext"] = false;
78 ret["int_bytes"] = 0;
79 string textureStr = (string)request["texture_id"];
80 string format = (string)request["format"];
76 81
77 //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); 82 //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr);
78 83
79 if (m_assetService == null) 84 if (m_assetService == null)
80 { 85 {
81 m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); 86 m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service");
82 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
83 } 87 }
84 88
85 UUID textureID; 89 UUID textureID;
@@ -94,30 +98,41 @@ namespace OpenSim.Capabilities.Handlers
94 } 98 }
95 else 99 else
96 { 100 {
97 formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); 101 formats = new string[1] { DefaultFormat }; // default
102 if (((Hashtable)request["headers"])["Accept"] != null)
103 formats = WebUtil.GetPreferredImageTypes((string)((Hashtable)request["headers"])["Accept"]);
98 if (formats.Length == 0) 104 if (formats.Length == 0)
99 formats = new string[1] { DefaultFormat }; // default 105 formats = new string[1] { DefaultFormat }; // default
100 106
101 } 107 }
102 // OK, we have an array with preferred formats, possibly with only one entry 108 // OK, we have an array with preferred formats, possibly with only one entry
103 109 bool foundtexture = false;
104 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
105 foreach (string f in formats) 110 foreach (string f in formats)
106 { 111 {
107 if (FetchTexture(httpRequest, httpResponse, textureID, f)) 112 foundtexture = FetchTexture(request, ret, textureID, f);
113 if (foundtexture)
108 break; 114 break;
109 } 115 }
116 if (!foundtexture)
117 {
118 ret["int_response_code"] = 404;
119 ret["error_status_text"] = "not found";
120 ret["str_response_string"] = "not found";
121 ret["content_type"] = "text/plain";
122 ret["keepalive"] = false;
123 ret["reusecontext"] = false;
124 ret["int_bytes"] = 0;
125 }
110 } 126 }
111 else 127 else
112 { 128 {
113 m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); 129 m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + (string)request["uri"]);
114 } 130 }
115 131
116// m_log.DebugFormat( 132// m_log.DebugFormat(
117// "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", 133// "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}",
118// textureID, httpResponse.StatusCode, httpResponse.ContentLength); 134// textureID, httpResponse.StatusCode, httpResponse.ContentLength);
119 135 return ret;
120 return null;
121 } 136 }
122 137
123 /// <summary> 138 /// <summary>
@@ -128,7 +143,7 @@ namespace OpenSim.Capabilities.Handlers
128 /// <param name="textureID"></param> 143 /// <param name="textureID"></param>
129 /// <param name="format"></param> 144 /// <param name="format"></param>
130 /// <returns>False for "caller try another codec"; true otherwise</returns> 145 /// <returns>False for "caller try another codec"; true otherwise</returns>
131 private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) 146 private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID, string format)
132 { 147 {
133// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); 148// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
134 AssetBase texture; 149 AssetBase texture;
@@ -137,86 +152,70 @@ namespace OpenSim.Capabilities.Handlers
137 if (format != DefaultFormat) 152 if (format != DefaultFormat)
138 fullID = fullID + "-" + format; 153 fullID = fullID + "-" + format;
139 154
140 if (!String.IsNullOrEmpty(m_RedirectURL)) 155 // try the cache
156 texture = m_assetService.GetCached(fullID);
157
158 if (texture == null)
141 { 159 {
142 // Only try to fetch locally cached textures. Misses are redirected 160 //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
143 texture = m_assetService.GetCached(fullID); 161
162 // Fetch locally or remotely. Misses return a 404
163 texture = m_assetService.Get(textureID.ToString());
144 164
145 if (texture != null) 165 if (texture != null)
146 { 166 {
147 if (texture.Type != (sbyte)AssetType.Texture) 167 if (texture.Type != (sbyte)AssetType.Texture)
168 return true;
169
170 if (format == DefaultFormat)
148 { 171 {
149 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 172 WriteTextureData(request, response, texture, format);
150 return true; 173 return true;
151 } 174 }
152 WriteTextureData(httpRequest, httpResponse, texture, format); 175 else
153 }
154 else
155 {
156 string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString();
157 m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
158 httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
159 httpResponse.RedirectLocation = textureUrl;
160 return true;
161 }
162 }
163 else // no redirect
164 {
165 // try the cache
166 texture = m_assetService.GetCached(fullID);
167
168 if (texture == null)
169 {
170// m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
171
172 // Fetch locally or remotely. Misses return a 404
173 texture = m_assetService.Get(textureID.ToString());
174
175 if (texture != null)
176 { 176 {
177 if (texture.Type != (sbyte)AssetType.Texture) 177 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
178 { 178 newTexture.Data = ConvertTextureData(texture, format);
179 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 179 if (newTexture.Data.Length == 0)
180 return true; 180 return false; // !!! Caller try another codec, please!
181 } 181
182 if (format == DefaultFormat) 182 newTexture.Flags = AssetFlags.Collectable;
183 { 183 newTexture.Temporary = true;
184 WriteTextureData(httpRequest, httpResponse, texture, format); 184 newTexture.Local = true;
185 return true; 185 m_assetService.Store(newTexture);
186 } 186 WriteTextureData(request, response, newTexture, format);
187 else 187 return true;
188 {
189 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
190 newTexture.Data = ConvertTextureData(texture, format);
191 if (newTexture.Data.Length == 0)
192 return false; // !!! Caller try another codec, please!
193
194 newTexture.Flags = AssetFlags.Collectable;
195 newTexture.Temporary = true;
196 newTexture.Local = true;
197 m_assetService.Store(newTexture);
198 WriteTextureData(httpRequest, httpResponse, newTexture, format);
199 return true;
200 }
201 } 188 }
202 } 189 }
203 else // it was on the cache 190 }
204 { 191 else // it was on the cache
205// m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); 192 {
206 WriteTextureData(httpRequest, httpResponse, texture, format); 193 //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
207 return true; 194 WriteTextureData(request, response, texture, format);
208 } 195 return true;
209 } 196 }
210 197
198 //response = new Hashtable();
199
200
201 //WriteTextureData(request,response,null,format);
211 // not found 202 // not found
212// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); 203 //m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
213 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 204 return false;
214 return true;
215 } 205 }
216 206
217 private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) 207 private void WriteTextureData(Hashtable request, Hashtable response, AssetBase texture, string format)
218 { 208 {
219 string range = request.Headers.GetOne("Range"); 209 Hashtable headers = new Hashtable();
210 response["headers"] = headers;
211
212 string range = String.Empty;
213
214 if (((Hashtable)request["headers"])["range"] != null)
215 range = (string)((Hashtable)request["headers"])["range"];
216
217 else if (((Hashtable)request["headers"])["Range"] != null)
218 range = (string)((Hashtable)request["headers"])["Range"];
220 219
221 if (!String.IsNullOrEmpty(range)) // JP2's only 220 if (!String.IsNullOrEmpty(range)) // JP2's only
222 { 221 {
@@ -244,10 +243,8 @@ namespace OpenSim.Capabilities.Handlers
244 // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. 243 // However, if we return PartialContent (or OK) instead, the viewer will display that resolution.
245 244
246// response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; 245// response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
247// response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); 246 // viewers don't seem to handle RequestedRangeNotSatisfiable and keep retrying with same parameters
248// response.StatusCode = (int)System.Net.HttpStatusCode.OK; 247 response["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
249 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
250 response.ContentType = texture.Metadata.ContentType;
251 } 248 }
252 else 249 else
253 { 250 {
@@ -262,41 +259,46 @@ namespace OpenSim.Capabilities.Handlers
262 259
263// m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); 260// m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
264 261
265 // Always return PartialContent, even if the range covered the entire data length 262 response["content-type"] = texture.Metadata.ContentType;
266 // We were accidentally sending back 404 before in this situation 263
267 // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the 264 if (start == 0 && len == texture.Data.Length) // well redudante maybe
268 // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. 265 {
269 // 266 response["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
270 // We also do not want to send back OK even if the whole range was satisfiable since this causes 267 response["bin_response_data"] = texture.Data;
271 // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. 268 response["int_bytes"] = texture.Data.Length;
272// if (end > maxEnd) 269 }
273// response.StatusCode = (int)System.Net.HttpStatusCode.OK; 270 else
274// else 271 {
275 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; 272 response["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent;
276 273 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length);
277 response.ContentLength = len; 274
278 response.ContentType = texture.Metadata.ContentType; 275 byte[] d = new byte[len];
279 response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); 276 Array.Copy(texture.Data, start, d, 0, len);
280 277 response["bin_response_data"] = d;
281 response.Body.Write(texture.Data, start, len); 278 response["int_bytes"] = len;
279 }
280// response.Body.Write(texture.Data, start, len);
282 } 281 }
283 } 282 }
284 else 283 else
285 { 284 {
286 m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); 285 m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range);
287 response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; 286 response["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest;
288 } 287 }
289 } 288 }
290 else // JP2's or other formats 289 else // JP2's or other formats
291 { 290 {
292 // Full content request 291 // Full content request
293 response.StatusCode = (int)System.Net.HttpStatusCode.OK; 292 response["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
294 response.ContentLength = texture.Data.Length;
295 if (format == DefaultFormat) 293 if (format == DefaultFormat)
296 response.ContentType = texture.Metadata.ContentType; 294 response["content_type"] = texture.Metadata.ContentType;
297 else 295 else
298 response.ContentType = "image/" + format; 296 response["content_type"] = "image/" + format;
299 response.Body.Write(texture.Data, 0, texture.Data.Length); 297
298 response["bin_response_data"] = texture.Data;
299 response["int_bytes"] = texture.Data.Length;
300
301// response.Body.Write(texture.Data, 0, texture.Data.Length);
300 } 302 }
301 303
302// if (response.StatusCode < 200 || response.StatusCode > 299) 304// if (response.StatusCode < 200 || response.StatusCode > 299)
@@ -428,4 +430,4 @@ namespace OpenSim.Capabilities.Handlers
428 return null; 430 return null;
429 } 431 }
430 } 432 }
431} \ No newline at end of file 433}
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
index fa0b228..d55e0ff 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
@@ -33,6 +33,7 @@ using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 33using OpenSim.Server.Handlers.Base;
34using OpenMetaverse; 34using OpenMetaverse;
35 35
36/*
36namespace OpenSim.Capabilities.Handlers 37namespace OpenSim.Capabilities.Handlers
37{ 38{
38 public class GetTextureServerConnector : ServiceConnector 39 public class GetTextureServerConnector : ServiceConnector
@@ -68,4 +69,5 @@ namespace OpenSim.Capabilities.Handlers
68 new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl)); 69 new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl));
69 } 70 }
70 } 71 }
71} \ No newline at end of file 72}
73*/
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs
index e5d9618..61aa689 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs
@@ -38,6 +38,7 @@ using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Tests.Common; 39using OpenSim.Tests.Common;
40 40
41/*
41namespace OpenSim.Capabilities.Handlers.GetTexture.Tests 42namespace OpenSim.Capabilities.Handlers.GetTexture.Tests
42{ 43{
43 [TestFixture] 44 [TestFixture]
@@ -59,4 +60,5 @@ namespace OpenSim.Capabilities.Handlers.GetTexture.Tests
59 Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); 60 Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound));
60 } 61 }
61 } 62 }
62} \ No newline at end of file 63}
64*/
diff --git a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs
index 8849a59..5536564 100644
--- a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs
+++ b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Collections.Specialized; 31using System.Collections.Specialized;
31using System.Drawing; 32using System.Drawing;
32using System.Drawing.Imaging; 33using System.Drawing.Imaging;
@@ -50,6 +51,7 @@ namespace OpenSim.Capabilities.Handlers
50{ 51{
51 public class UploadBakedTextureHandler 52 public class UploadBakedTextureHandler
52 { 53 {
54
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 56
55 private Caps m_HostCapsObj; 57 private Caps m_HostCapsObj;
@@ -79,9 +81,9 @@ namespace OpenSim.Capabilities.Handlers
79 { 81 {
80 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; 82 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
81 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 83 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
82 84
83 BakedTextureUploader uploader = 85 BakedTextureUploader uploader =
84 new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener); 86 new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_HostCapsObj.AgentID);
85 uploader.OnUpLoad += BakedTextureUploaded; 87 uploader.OnUpLoad += BakedTextureUploaded;
86 88
87 m_HostCapsObj.HttpListener.AddStreamHandler( 89 m_HostCapsObj.HttpListener.AddStreamHandler(
@@ -117,7 +119,7 @@ namespace OpenSim.Capabilities.Handlers
117 /// <param name="data"></param> 119 /// <param name="data"></param>
118 private void BakedTextureUploaded(UUID assetID, byte[] data) 120 private void BakedTextureUploaded(UUID assetID, byte[] data)
119 { 121 {
120// m_log.DebugFormat("[UPLOAD BAKED TEXTURE HANDLER]: Received baked texture {0}", assetID.ToString()); 122 m_log.DebugFormat("[UPLOAD BAKED TEXTURE HANDLER]: Received baked texture {0}", assetID.ToString());
121 123
122 AssetBase asset; 124 AssetBase asset;
123 asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString()); 125 asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString());
@@ -125,6 +127,7 @@ namespace OpenSim.Capabilities.Handlers
125 asset.Temporary = true; 127 asset.Temporary = true;
126 asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are 128 asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are
127 m_assetService.Store(asset); 129 m_assetService.Store(asset);
130
128 } 131 }
129 } 132 }
130 133
@@ -137,15 +140,19 @@ namespace OpenSim.Capabilities.Handlers
137 private string uploaderPath = String.Empty; 140 private string uploaderPath = String.Empty;
138 private UUID newAssetID; 141 private UUID newAssetID;
139 private IHttpServer httpListener; 142 private IHttpServer httpListener;
143 private UUID AgentId = UUID.Zero;
140 144
141 public BakedTextureUploader(string path, IHttpServer httpServer) 145 public BakedTextureUploader(string path, IHttpServer httpServer, UUID uUID)
142 { 146 {
143 newAssetID = UUID.Random(); 147 newAssetID = UUID.Random();
144 uploaderPath = path; 148 uploaderPath = path;
145 httpListener = httpServer; 149 httpListener = httpServer;
150 AgentId = uUID;
146 // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID); 151 // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID);
147 } 152 }
148 153
154
155
149 /// <summary> 156 /// <summary>
150 /// Handle raw uploaded baked texture data. 157 /// Handle raw uploaded baked texture data.
151 /// </summary> 158 /// </summary>
diff --git a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
new file mode 100644
index 0000000..16e2f2d
--- /dev/null
+++ b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
@@ -0,0 +1,438 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using OpenMetaverse;
35using OpenMetaverse.StructuredData;
36using OpenSim.Framework;
37using OpenSim.Framework.Capabilities;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Services.Interfaces;
41using Caps = OpenSim.Framework.Capabilities.Caps;
42
43namespace OpenSim.Capabilities.Handlers
44{
45 public class WebFetchInvDescHandler
46 {
47 private static readonly ILog m_log =
48 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IInventoryService m_InventoryService;
51 private ILibraryService m_LibraryService;
52// private object m_fetchLock = new Object();
53
54 public WebFetchInvDescHandler(IInventoryService invService, ILibraryService libService)
55 {
56 m_InventoryService = invService;
57 m_LibraryService = libService;
58 }
59
60 public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 {
62// lock (m_fetchLock)
63// {
64// m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Received request {0}", request);
65
66 // nasty temporary hack here, the linden client falsely
67 // identifies the uuid 00000000-0000-0000-0000-000000000000
68 // as a string which breaks us
69 //
70 // correctly mark it as a uuid
71 //
72 request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");
73
74 // another hack <integer>1</integer> results in a
75 // System.ArgumentException: Object type System.Int32 cannot
76 // be converted to target type: System.Boolean
77 //
78 request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>");
79 request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>");
80
81 Hashtable hash = new Hashtable();
82 try
83 {
84 hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
85 }
86 catch (LLSD.LLSDParseException e)
87 {
88 m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
89 m_log.Error("Request: " + request);
90 }
91
92 ArrayList foldersrequested = (ArrayList)hash["folders"];
93
94 string response = "";
95
96 for (int i = 0; i < foldersrequested.Count; i++)
97 {
98 string inventoryitemstr = "";
99 Hashtable inventoryhash = (Hashtable)foldersrequested[i];
100
101 LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();
102
103 try
104 {
105 LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
106 }
107 catch (Exception e)
108 {
109 m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
110 }
111 LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest);
112
113 inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply);
114 inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", "");
115 inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", "");
116
117 response += inventoryitemstr;
118 }
119
120 if (response.Length == 0)
121 {
122 // Ter-guess: If requests fail a lot, the client seems to stop requesting descendants.
123 // Therefore, I'm concluding that the client only has so many threads available to do requests
124 // and when a thread stalls.. is stays stalled.
125 // Therefore we need to return something valid
126 response = "<llsd><map><key>folders</key><array /></map></llsd>";
127 }
128 else
129 {
130 response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>";
131 }
132
133// m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request");
134 //m_log.Debug("[WEB FETCH INV DESC HANDLER] "+response);
135
136 return response;
137
138// }
139 }
140
141 /// <summary>
142 /// Construct an LLSD reply packet to a CAPS inventory request
143 /// </summary>
144 /// <param name="invFetch"></param>
145 /// <returns></returns>
146 private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch)
147 {
148 LLSDInventoryDescendents reply = new LLSDInventoryDescendents();
149 LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents();
150 contents.agent_id = invFetch.owner_id;
151 contents.owner_id = invFetch.owner_id;
152 contents.folder_id = invFetch.folder_id;
153
154 reply.folders.Array.Add(contents);
155 InventoryCollection inv = new InventoryCollection();
156 inv.Folders = new List<InventoryFolderBase>();
157 inv.Items = new List<InventoryItemBase>();
158 int version = 0;
159 int descendents = 0;
160
161 inv
162 = Fetch(
163 invFetch.owner_id, invFetch.folder_id, invFetch.owner_id,
164 invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version, out descendents);
165
166 if (inv != null && inv.Folders != null)
167 {
168 foreach (InventoryFolderBase invFolder in inv.Folders)
169 {
170 contents.categories.Array.Add(ConvertInventoryFolder(invFolder));
171 }
172
173 descendents += inv.Folders.Count;
174 }
175
176 if (inv != null && inv.Items != null)
177 {
178 foreach (InventoryItemBase invItem in inv.Items)
179 {
180 contents.items.Array.Add(ConvertInventoryItem(invItem));
181 }
182 }
183
184 contents.descendents = descendents;
185 contents.version = version;
186
187// m_log.DebugFormat(
188// "[WEB FETCH INV DESC HANDLER]: Replying to request for folder {0} (fetch items {1}, fetch folders {2}) with {3} items and {4} folders for agent {5}",
189// invFetch.folder_id,
190// invFetch.fetch_items,
191// invFetch.fetch_folders,
192// contents.items.Array.Count,
193// contents.categories.Array.Count,
194// invFetch.owner_id);
195
196 return reply;
197 }
198
199 /// <summary>
200 /// Handle the caps inventory descendents fetch.
201 /// </summary>
202 /// <param name="agentID"></param>
203 /// <param name="folderID"></param>
204 /// <param name="ownerID"></param>
205 /// <param name="fetchFolders"></param>
206 /// <param name="fetchItems"></param>
207 /// <param name="sortOrder"></param>
208 /// <param name="version"></param>
209 /// <returns>An empty InventoryCollection if the inventory look up failed</returns>
210 private InventoryCollection Fetch(
211 UUID agentID, UUID folderID, UUID ownerID,
212 bool fetchFolders, bool fetchItems, int sortOrder, out int version, out int descendents)
213 {
214// m_log.DebugFormat(
215// "[WEB FETCH INV DESC HANDLER]: Fetching folders ({0}), items ({1}) from {2} for agent {3}",
216// fetchFolders, fetchItems, folderID, agentID);
217
218 // FIXME MAYBE: We're not handling sortOrder!
219
220 version = 0;
221 descendents = 0;
222
223 InventoryFolderImpl fold;
224 if (m_LibraryService != null && m_LibraryService.LibraryRootFolder != null && agentID == m_LibraryService.LibraryRootFolder.Owner)
225 {
226 if ((fold = m_LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
227 {
228 InventoryCollection ret = new InventoryCollection();
229 ret.Folders = new List<InventoryFolderBase>();
230 ret.Items = fold.RequestListOfItems();
231 descendents = ret.Folders.Count + ret.Items.Count;
232
233 return ret;
234 }
235 }
236
237 InventoryCollection contents = new InventoryCollection();
238
239 if (folderID != UUID.Zero)
240 {
241 contents = m_InventoryService.GetFolderContent(agentID, folderID);
242 InventoryFolderBase containingFolder = new InventoryFolderBase();
243 containingFolder.ID = folderID;
244 containingFolder.Owner = agentID;
245 containingFolder = m_InventoryService.GetFolder(containingFolder);
246
247 if (containingFolder != null)
248 {
249// m_log.DebugFormat(
250// "[WEB FETCH INV DESC HANDLER]: Retrieved folder {0} {1} for agent id {2}",
251// containingFolder.Name, containingFolder.ID, agentID);
252
253 version = containingFolder.Version;
254
255 if (fetchItems)
256 {
257 List<InventoryItemBase> itemsToReturn = contents.Items;
258 List<InventoryItemBase> originalItems = new List<InventoryItemBase>(itemsToReturn);
259
260 // descendents must only include the links, not the linked items we add
261 descendents = originalItems.Count;
262
263 // Add target items for links in this folder before the links themselves.
264 foreach (InventoryItemBase item in originalItems)
265 {
266 if (item.AssetType == (int)AssetType.Link)
267 {
268 InventoryItemBase linkedItem = m_InventoryService.GetItem(new InventoryItemBase(item.AssetID));
269
270 // Take care of genuinely broken links where the target doesn't exist
271 // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate,
272 // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles
273 // rather than having to keep track of every folder requested in the recursion.
274 if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link)
275 itemsToReturn.Insert(0, linkedItem);
276 }
277 }
278
279 // Now scan for folder links and insert the items they target and those links at the head of the return data
280 foreach (InventoryItemBase item in originalItems)
281 {
282 if (item.AssetType == (int)AssetType.LinkFolder)
283 {
284 InventoryCollection linkedFolderContents = m_InventoryService.GetFolderContent(ownerID, item.AssetID);
285 List<InventoryItemBase> links = linkedFolderContents.Items;
286
287 itemsToReturn.InsertRange(0, links);
288
289 foreach (InventoryItemBase link in linkedFolderContents.Items)
290 {
291 // Take care of genuinely broken links where the target doesn't exist
292 // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate,
293 // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles
294 // rather than having to keep track of every folder requested in the recursion.
295 if (link != null)
296 {
297// m_log.DebugFormat(
298// "[WEB FETCH INV DESC HANDLER]: Adding item {0} {1} from folder {2} linked from {3}",
299// link.Name, (AssetType)link.AssetType, item.AssetID, containingFolder.Name);
300
301 InventoryItemBase linkedItem
302 = m_InventoryService.GetItem(new InventoryItemBase(link.AssetID));
303
304 if (linkedItem != null)
305 itemsToReturn.Insert(0, linkedItem);
306 }
307 }
308 }
309 }
310 }
311
312// foreach (InventoryItemBase item in contents.Items)
313// {
314// m_log.DebugFormat(
315// "[WEB FETCH INV DESC HANDLER]: Returning item {0}, type {1}, parent {2} in {3} {4}",
316// item.Name, (AssetType)item.AssetType, item.Folder, containingFolder.Name, containingFolder.ID);
317// }
318
319 // =====
320
321//
322// foreach (InventoryItemBase linkedItem in linkedItemsToAdd)
323// {
324// m_log.DebugFormat(
325// "[WEB FETCH INV DESC HANDLER]: Inserted linked item {0} for link in folder {1} for agent {2}",
326// linkedItem.Name, folderID, agentID);
327//
328// contents.Items.Add(linkedItem);
329// }
330//
331// // If the folder requested contains links, then we need to send those folders first, otherwise the links
332// // will be broken in the viewer.
333// HashSet<UUID> linkedItemFolderIdsToSend = new HashSet<UUID>();
334// foreach (InventoryItemBase item in contents.Items)
335// {
336// if (item.AssetType == (int)AssetType.Link)
337// {
338// InventoryItemBase linkedItem = m_InventoryService.GetItem(new InventoryItemBase(item.AssetID));
339//
340// // Take care of genuinely broken links where the target doesn't exist
341// // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate,
342// // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles
343// // rather than having to keep track of every folder requested in the recursion.
344// if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link)
345// {
346// // We don't need to send the folder if source and destination of the link are in the same
347// // folder.
348// if (linkedItem.Folder != containingFolder.ID)
349// linkedItemFolderIdsToSend.Add(linkedItem.Folder);
350// }
351// }
352// }
353//
354// foreach (UUID linkedItemFolderId in linkedItemFolderIdsToSend)
355// {
356// m_log.DebugFormat(
357// "[WEB FETCH INV DESC HANDLER]: Recursively fetching folder {0} linked by item in folder {1} for agent {2}",
358// linkedItemFolderId, folderID, agentID);
359//
360// int dummyVersion;
361// InventoryCollection linkedCollection
362// = Fetch(
363// agentID, linkedItemFolderId, ownerID, fetchFolders, fetchItems, sortOrder, out dummyVersion);
364//
365// InventoryFolderBase linkedFolder = new InventoryFolderBase(linkedItemFolderId);
366// linkedFolder.Owner = agentID;
367// linkedFolder = m_InventoryService.GetFolder(linkedFolder);
368//
369//// contents.Folders.AddRange(linkedCollection.Folders);
370//
371// contents.Folders.Add(linkedFolder);
372// contents.Items.AddRange(linkedCollection.Items);
373// }
374// }
375 }
376 }
377 else
378 {
379 // Lost items don't really need a version
380 version = 1;
381 }
382
383 return contents;
384
385 }
386 /// <summary>
387 /// Convert an internal inventory folder object into an LLSD object.
388 /// </summary>
389 /// <param name="invFolder"></param>
390 /// <returns></returns>
391 private LLSDInventoryFolder ConvertInventoryFolder(InventoryFolderBase invFolder)
392 {
393 LLSDInventoryFolder llsdFolder = new LLSDInventoryFolder();
394 llsdFolder.folder_id = invFolder.ID;
395 llsdFolder.parent_id = invFolder.ParentID;
396 llsdFolder.name = invFolder.Name;
397 llsdFolder.type = invFolder.Type;
398 llsdFolder.preferred_type = -1;
399
400 return llsdFolder;
401 }
402
403 /// <summary>
404 /// Convert an internal inventory item object into an LLSD object.
405 /// </summary>
406 /// <param name="invItem"></param>
407 /// <returns></returns>
408 private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem)
409 {
410 LLSDInventoryItem llsdItem = new LLSDInventoryItem();
411 llsdItem.asset_id = invItem.AssetID;
412 llsdItem.created_at = invItem.CreationDate;
413 llsdItem.desc = invItem.Description;
414 llsdItem.flags = ((int)invItem.Flags) & 0xff;
415 llsdItem.item_id = invItem.ID;
416 llsdItem.name = invItem.Name;
417 llsdItem.parent_id = invItem.Folder;
418 llsdItem.type = invItem.AssetType;
419 llsdItem.inv_type = invItem.InvType;
420
421 llsdItem.permissions = new LLSDPermissions();
422 llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid;
423 llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions;
424 llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions;
425 llsdItem.permissions.group_id = invItem.GroupID;
426 llsdItem.permissions.group_mask = (int)invItem.GroupPermissions;
427 llsdItem.permissions.is_owner_group = invItem.GroupOwned;
428 llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions;
429 llsdItem.permissions.owner_id = invItem.Owner;
430 llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions;
431 llsdItem.sale_info = new LLSDSaleInfo();
432 llsdItem.sale_info.sale_price = invItem.SalePrice;
433 llsdItem.sale_info.sale_type = invItem.SaleType;
434
435 return llsdItem;
436 }
437 }
438}
diff --git a/OpenSim/Capabilities/LLSDAssetUploadComplete.cs b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs
index ab6cee5..ae8eb09 100644
--- a/OpenSim/Capabilities/LLSDAssetUploadComplete.cs
+++ b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs
@@ -30,12 +30,15 @@ using OpenMetaverse;
30 30
31namespace OpenSim.Framework.Capabilities 31namespace OpenSim.Framework.Capabilities
32{ 32{
33
33 [LLSDType("MAP")] 34 [LLSDType("MAP")]
34 public class LLSDAssetUploadComplete 35 public class LLSDAssetUploadComplete
35 { 36 {
36 public string new_asset = String.Empty; 37 public string new_asset = String.Empty;
37 public UUID new_inventory_item = UUID.Zero; 38 public UUID new_inventory_item = UUID.Zero;
39// public UUID new_texture_folder_id = UUID.Zero;
38 public string state = String.Empty; 40 public string state = String.Empty;
41 public LLSDAssetUploadError error = null;
39 //public bool success = false; 42 //public bool success = false;
40 43
41 public LLSDAssetUploadComplete() 44 public LLSDAssetUploadComplete()
diff --git a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs
index 6e66f0a..6779cc1 100644
--- a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs
+++ b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs
@@ -31,14 +31,27 @@ using OpenMetaverse;
31namespace OpenSim.Framework.Capabilities 31namespace OpenSim.Framework.Capabilities
32{ 32{
33 [OSDMap] 33 [OSDMap]
34 public class LLSDAssetResource
35 {
36 public OSDArray instance_list = new OSDArray();
37 public OSDArray texture_list = new OSDArray();
38 public OSDArray mesh_list = new OSDArray();
39 public string metric = String.Empty;
40 }
41
42 [OSDMap]
34 public class LLSDAssetUploadRequest 43 public class LLSDAssetUploadRequest
35 { 44 {
36 public string asset_type = String.Empty; 45 public string asset_type = String.Empty;
37 public string description = String.Empty; 46 public string description = String.Empty;
38 public UUID folder_id = UUID.Zero; 47 public UUID folder_id = UUID.Zero;
48 public UUID texture_folder_id = UUID.Zero;
49 public int next_owner_mask = 0;
50 public int group_mask = 0;
51 public int everyone_mask = 0;
39 public string inventory_type = String.Empty; 52 public string inventory_type = String.Empty;
40 public string name = String.Empty; 53 public string name = String.Empty;
41 54 public LLSDAssetResource asset_resources = new LLSDAssetResource();
42 public LLSDAssetUploadRequest() 55 public LLSDAssetUploadRequest()
43 { 56 {
44 } 57 }
diff --git a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs
index 0d6f7f9..7c4bc97 100644
--- a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs
+++ b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs
@@ -26,20 +26,51 @@
26 */ 26 */
27 27
28using System; 28using System;
29using OpenMetaverse;
29 30
30namespace OpenSim.Framework.Capabilities 31namespace OpenSim.Framework.Capabilities
31{ 32{
32 [OSDMap] 33 [OSDMap]
34 public class LLSDAssetUploadError
35 {
36 public string message = String.Empty;
37 public UUID identifier = UUID.Zero;
38 }
39
40 [OSDMap]
41 public class LLSDAssetUploadResponsePricebrkDown
42 {
43 public int mesh_streaming;
44 public int mesh_physics;
45 public int mesh_instance;
46 public int texture;
47 public int model;
48 }
49
50 [OSDMap]
51 public class LLSDAssetUploadResponseData
52 {
53 public double resource_cost;
54 public double model_streaming_cost;
55 public double simulation_cost;
56 public double physics_cost;
57 public LLSDAssetUploadResponsePricebrkDown upload_price_breakdown = new LLSDAssetUploadResponsePricebrkDown();
58 }
59
60 [OSDMap]
33 public class LLSDAssetUploadResponse 61 public class LLSDAssetUploadResponse
34 { 62 {
35 public string uploader = String.Empty; 63 public string uploader = String.Empty;
36 public string state = String.Empty; 64 public string state = String.Empty;
37 65 public int upload_price = 0;
66 public LLSDAssetUploadResponseData data = null;
67 public LLSDAssetUploadError error = null;
38 public LLSDAssetUploadResponse() 68 public LLSDAssetUploadResponse()
39 { 69 {
40 } 70 }
41 } 71 }
42 72
73
43 [OSDMap] 74 [OSDMap]
44 public class LLSDNewFileAngentInventoryVariablePriceReplyResponse 75 public class LLSDNewFileAngentInventoryVariablePriceReplyResponse
45 { 76 {
diff --git a/OpenSim/Data/AssetDataBase.cs b/OpenSim/Data/AssetDataBase.cs
index 1bb432c..9593a25 100644
--- a/OpenSim/Data/AssetDataBase.cs
+++ b/OpenSim/Data/AssetDataBase.cs
@@ -37,7 +37,7 @@ namespace OpenSim.Data
37 public abstract class AssetDataBase : IAssetDataPlugin 37 public abstract class AssetDataBase : IAssetDataPlugin
38 { 38 {
39 public abstract AssetBase GetAsset(UUID uuid); 39 public abstract AssetBase GetAsset(UUID uuid);
40 public abstract void StoreAsset(AssetBase asset); 40 public abstract bool StoreAsset(AssetBase asset);
41 public abstract bool[] AssetsExist(UUID[] uuids); 41 public abstract bool[] AssetsExist(UUID[] uuids);
42 42
43 public abstract List<AssetMetadata> FetchAssetMetadataSet(int start, int count); 43 public abstract List<AssetMetadata> FetchAssetMetadataSet(int start, int count);
diff --git a/OpenSim/Data/IAssetData.cs b/OpenSim/Data/IAssetData.cs
index a41e310..febab5d 100644
--- a/OpenSim/Data/IAssetData.cs
+++ b/OpenSim/Data/IAssetData.cs
@@ -34,7 +34,7 @@ namespace OpenSim.Data
34 public interface IAssetDataPlugin : IPlugin 34 public interface IAssetDataPlugin : IPlugin
35 { 35 {
36 AssetBase GetAsset(UUID uuid); 36 AssetBase GetAsset(UUID uuid);
37 void StoreAsset(AssetBase asset); 37 bool StoreAsset(AssetBase asset);
38 bool[] AssetsExist(UUID[] uuids); 38 bool[] AssetsExist(UUID[] uuids);
39 List<AssetMetadata> FetchAssetMetadataSet(int start, int count); 39 List<AssetMetadata> FetchAssetMetadataSet(int start, int count);
40 void Initialise(string connect); 40 void Initialise(string connect);
diff --git a/OpenSim/Data/IProfilesData.cs b/OpenSim/Data/IProfilesData.cs
index 7fb075d..0de7f68 100644
--- a/OpenSim/Data/IProfilesData.cs
+++ b/OpenSim/Data/IProfilesData.cs
@@ -48,8 +48,6 @@ namespace OpenSim.Data
48 bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result); 48 bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result);
49 bool UpdateAvatarInterests(UserProfileProperties up, ref string result); 49 bool UpdateAvatarInterests(UserProfileProperties up, ref string result);
50 bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result); 50 bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result);
51 bool UpdateUserPreferences(ref UserPreferences pref, ref string result);
52 bool GetUserPreferences(ref UserPreferences pref, ref string result);
53 bool GetUserAppData(ref UserAppData props, ref string result); 51 bool GetUserAppData(ref UserAppData props, ref string result);
54 bool SetUserAppData(UserAppData props, ref string result); 52 bool SetUserAppData(UserAppData props, ref string result);
55 OSDArray GetUserImageAssets(UUID avatarId); 53 OSDArray GetUserImageAssets(UUID avatarId);
diff --git a/OpenSim/Data/IUserAccountData.cs b/OpenSim/Data/IUserAccountData.cs
index 906ba6c..bc7eda7 100644
--- a/OpenSim/Data/IUserAccountData.cs
+++ b/OpenSim/Data/IUserAccountData.cs
@@ -50,5 +50,6 @@ namespace OpenSim.Data
50 bool Store(UserAccountData data); 50 bool Store(UserAccountData data);
51 bool Delete(string field, string val); 51 bool Delete(string field, string val);
52 UserAccountData[] GetUsers(UUID scopeID, string query); 52 UserAccountData[] GetUsers(UUID scopeID, string query);
53 UserAccountData[] GetUsersWhere(UUID scopeID, string where);
53 } 54 }
54} 55}
diff --git a/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
index ed0ab98..17f1374 100644
--- a/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
+++ b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs
index 5d8da17..cb5a38e 100644
--- a/OpenSim/Data/MySQL/MySQLAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLAssetData.cs
@@ -154,7 +154,7 @@ namespace OpenSim.Data.MySQL
154 /// </summary> 154 /// </summary>
155 /// <param name="asset">Asset UUID to create</param> 155 /// <param name="asset">Asset UUID to create</param>
156 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> 156 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
157 override public void StoreAsset(AssetBase asset) 157 override public bool StoreAsset(AssetBase asset)
158 { 158 {
159 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 159 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
160 { 160 {
@@ -203,6 +203,43 @@ namespace OpenSim.Data.MySQL
203 cmd.Parameters.AddWithValue("?data", asset.Data); 203 cmd.Parameters.AddWithValue("?data", asset.Data);
204 cmd.ExecuteNonQuery(); 204 cmd.ExecuteNonQuery();
205 } 205 }
206
207 string assetDescription = asset.Description;
208 if (asset.Description.Length > 64)
209 {
210 assetDescription = asset.Description.Substring(0, 64);
211 m_log.WarnFormat(
212 "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add",
213 asset.Description, asset.ID, asset.Description.Length, assetDescription.Length);
214 }
215
216 try
217 {
218 using (cmd)
219 {
220 // create unix epoch time
221 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
222 cmd.Parameters.AddWithValue("?id", asset.ID);
223 cmd.Parameters.AddWithValue("?name", assetName);
224 cmd.Parameters.AddWithValue("?description", assetDescription);
225 cmd.Parameters.AddWithValue("?assetType", asset.Type);
226 cmd.Parameters.AddWithValue("?local", asset.Local);
227 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
228 cmd.Parameters.AddWithValue("?create_time", now);
229 cmd.Parameters.AddWithValue("?access_time", now);
230 cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID);
231 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
232 cmd.Parameters.AddWithValue("?data", asset.Data);
233 cmd.ExecuteNonQuery();
234 return true;
235 }
236 }
237 catch (Exception e)
238 {
239 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
240 asset.FullID, asset.Name, e.Message);
241 return false;
242 }
206 } 243 }
207 catch (Exception e) 244 catch (Exception e)
208 { 245 {
@@ -364,4 +401,4 @@ namespace OpenSim.Data.MySQL
364 401
365 #endregion 402 #endregion
366 } 403 }
367} \ No newline at end of file 404}
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index 5820a90..a522912 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -45,14 +45,21 @@ namespace OpenSim.Data.MySQL
45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected string m_connectionString; 47 protected string m_connectionString;
48 protected object m_dbLock = new object();
48 49
49 protected MySqlFramework(string connectionString) 50 protected MySqlFramework(string connectionString)
50 { 51 {
51 m_connectionString = connectionString; 52 m_connectionString = connectionString;
52 } 53 }
53 54
55 //////////////////////////////////////////////////////////////
56 //
57 // All non queries are funneled through one connection
58 // to increase performance a little
59 //
54 protected int ExecuteNonQuery(MySqlCommand cmd) 60 protected int ExecuteNonQuery(MySqlCommand cmd)
55 { 61 {
62 lock (m_dbLock)
56 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 63 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
57 { 64 {
58 dbcon.Open(); 65 dbcon.Open();
@@ -60,7 +67,19 @@ namespace OpenSim.Data.MySQL
60 67
61 try 68 try
62 { 69 {
63 return cmd.ExecuteNonQuery(); 70 dbcon.Open();
71 cmd.Connection = dbcon;
72
73 try
74 {
75 return cmd.ExecuteNonQuery();
76 }
77 catch (Exception e)
78 {
79 m_log.Error(e.Message, e);
80 m_log.Error(Environment.StackTrace.ToString());
81 return 0;
82 }
64 } 83 }
65 catch (Exception e) 84 catch (Exception e)
66 { 85 {
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index 35fa89f..dc657c8 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -175,6 +175,11 @@ namespace OpenSim.Data.MySQL
175 int v = Convert.ToInt32(reader[name]); 175 int v = Convert.ToInt32(reader[name]);
176 m_Fields[name].SetValue(row, v); 176 m_Fields[name].SetValue(row, v);
177 } 177 }
178 else if (m_Fields[name].FieldType == typeof(uint))
179 {
180 uint v = Convert.ToUInt32(reader[name]);
181 m_Fields[name].SetValue(row, v);
182 }
178 else 183 else
179 { 184 {
180 m_Fields[name].SetValue(row, reader[name]); 185 m_Fields[name].SetValue(row, reader[name]);
@@ -362,4 +367,4 @@ namespace OpenSim.Data.MySQL
362 } 367 }
363 368
364 } 369 }
365} \ No newline at end of file 370}
diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs
index 2ad7590..3dc049b 100644
--- a/OpenSim/Data/MySQL/MySQLRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLRegionData.cs
@@ -82,6 +82,7 @@ namespace OpenSim.Data.MySQL
82 82
83 public RegionData Get(int posX, int posY, UUID scopeID) 83 public RegionData Get(int posX, int posY, UUID scopeID)
84 { 84 {
85/* fixed size regions
85 string command = "select * from `"+m_Realm+"` where locX = ?posX and locY = ?posY"; 86 string command = "select * from `"+m_Realm+"` where locX = ?posX and locY = ?posY";
86 if (scopeID != UUID.Zero) 87 if (scopeID != UUID.Zero)
87 command += " and ScopeID = ?scopeID"; 88 command += " and ScopeID = ?scopeID";
@@ -98,6 +99,45 @@ namespace OpenSim.Data.MySQL
98 99
99 return ret[0]; 100 return ret[0];
100 } 101 }
102*/
103 // extend database search for maximum region size area
104 string command = "select * from `" + m_Realm + "` where locX between ?startX and ?endX and locY between ?startY and ?endY";
105 if (scopeID != UUID.Zero)
106 command += " and ScopeID = ?scopeID";
107
108 int startX = posX - (int)Constants.MaximumRegionSize;
109 int startY = posY - (int)Constants.MaximumRegionSize;
110 int endX = posX;
111 int endY = posY;
112
113 List<RegionData> ret;
114 using (MySqlCommand cmd = new MySqlCommand(command))
115 {
116 cmd.Parameters.AddWithValue("?startX", startX.ToString());
117 cmd.Parameters.AddWithValue("?startY", startY.ToString());
118 cmd.Parameters.AddWithValue("?endX", endX.ToString());
119 cmd.Parameters.AddWithValue("?endY", endY.ToString());
120 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
121
122 ret = RunCommand(cmd);
123 }
124
125 if (ret.Count == 0)
126 return null;
127
128 // find the first that contains pos
129 RegionData rg = null;
130 foreach (RegionData r in ret)
131 {
132 if (posX >= r.posX && posX < r.posX + r.sizeX
133 && posY >= r.posY && posY < r.posY + r.sizeY)
134 {
135 rg = r;
136 break;
137 }
138 }
139
140 return rg;
101 } 141 }
102 142
103 public RegionData Get(UUID regionID, UUID scopeID) 143 public RegionData Get(UUID regionID, UUID scopeID)
@@ -121,6 +161,7 @@ namespace OpenSim.Data.MySQL
121 161
122 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) 162 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
123 { 163 {
164/* fix size regions
124 string command = "select * from `"+m_Realm+"` where locX between ?startX and ?endX and locY between ?startY and ?endY"; 165 string command = "select * from `"+m_Realm+"` where locX between ?startX and ?endX and locY between ?startY and ?endY";
125 if (scopeID != UUID.Zero) 166 if (scopeID != UUID.Zero)
126 command += " and ScopeID = ?scopeID"; 167 command += " and ScopeID = ?scopeID";
@@ -135,6 +176,38 @@ namespace OpenSim.Data.MySQL
135 176
136 return RunCommand(cmd); 177 return RunCommand(cmd);
137 } 178 }
179 */
180 string command = "select * from `" + m_Realm + "` where locX between ?startX and ?endX and locY between ?startY and ?endY";
181 if (scopeID != UUID.Zero)
182 command += " and ScopeID = ?scopeID";
183
184 int qstartX = startX - (int)Constants.MaximumRegionSize;
185 int qstartY = startY - (int)Constants.MaximumRegionSize;
186
187 List<RegionData> dbret;
188 using (MySqlCommand cmd = new MySqlCommand(command))
189 {
190 cmd.Parameters.AddWithValue("?startX", qstartX.ToString());
191 cmd.Parameters.AddWithValue("?startY", qstartY.ToString());
192 cmd.Parameters.AddWithValue("?endX", endX.ToString());
193 cmd.Parameters.AddWithValue("?endY", endY.ToString());
194 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
195
196 dbret = RunCommand(cmd);
197 }
198
199 List<RegionData> ret = new List<RegionData>();
200
201 if (dbret.Count == 0)
202 return ret;
203
204 foreach (RegionData r in dbret)
205 {
206 if (r.posX + r.sizeX > startX && r.posX <= endX
207 && r.posY + r.sizeX > startY && r.posY <= endY)
208 ret.Add(r);
209 }
210 return ret;
138 } 211 }
139 212
140 public List<RegionData> RunCommand(MySqlCommand cmd) 213 public List<RegionData> RunCommand(MySqlCommand cmd)
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index bb0ab75..81b5ec4 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -76,7 +76,7 @@ namespace OpenSim.Data.MySQL
76 Initialise(connectionString); 76 Initialise(connectionString);
77 } 77 }
78 78
79 public void Initialise(string connectionString) 79 public virtual void Initialise(string connectionString)
80 { 80 {
81 m_connectionString = connectionString; 81 m_connectionString = connectionString;
82 82
@@ -123,7 +123,7 @@ namespace OpenSim.Data.MySQL
123 123
124 public void Dispose() {} 124 public void Dispose() {}
125 125
126 public void StoreObject(SceneObjectGroup obj, UUID regionUUID) 126 public virtual void StoreObject(SceneObjectGroup obj, UUID regionUUID)
127 { 127 {
128 uint flags = obj.RootPart.GetEffectiveObjectFlags(); 128 uint flags = obj.RootPart.GetEffectiveObjectFlags();
129 129
@@ -183,10 +183,11 @@ namespace OpenSim.Data.MySQL
183 "ParticleSystem, ClickAction, Material, " + 183 "ParticleSystem, ClickAction, Material, " +
184 "CollisionSound, CollisionSoundVolume, " + 184 "CollisionSound, CollisionSoundVolume, " +
185 "PassTouches, " + 185 "PassTouches, " +
186 "LinkNumber, MediaURL, AttachedPosX, " + 186 "PassCollisions, " +
187 "AttachedPosY, AttachedPosZ, KeyframeMotion, " + 187 "LinkNumber, MediaURL, KeyframeMotion, AttachedPosX, " +
188 "AttachedPosY, AttachedPosZ, " +
188 "PhysicsShapeType, Density, GravityModifier, " + 189 "PhysicsShapeType, Density, GravityModifier, " +
189 "Friction, Restitution, DynAttrs " + 190 "Friction, Restitution, Vehicle, DynAttrs " +
190 ") values (" + "?UUID, " + 191 ") values (" + "?UUID, " +
191 "?CreationDate, ?Name, ?Text, " + 192 "?CreationDate, ?Name, ?Text, " +
192 "?Description, ?SitName, ?TouchName, " + 193 "?Description, ?SitName, ?TouchName, " +
@@ -218,11 +219,11 @@ namespace OpenSim.Data.MySQL
218 "?SaleType, ?ColorR, ?ColorG, " + 219 "?SaleType, ?ColorR, ?ColorG, " +
219 "?ColorB, ?ColorA, ?ParticleSystem, " + 220 "?ColorB, ?ColorA, ?ParticleSystem, " +
220 "?ClickAction, ?Material, ?CollisionSound, " + 221 "?ClickAction, ?Material, ?CollisionSound, " +
221 "?CollisionSoundVolume, ?PassTouches, " + 222 "?CollisionSoundVolume, ?PassTouches, ?PassCollisions, " +
222 "?LinkNumber, ?MediaURL, ?AttachedPosX, " + 223 "?LinkNumber, ?MediaURL, ?KeyframeMotion, ?AttachedPosX, " +
223 "?AttachedPosY, ?AttachedPosZ, ?KeyframeMotion, " + 224 "?AttachedPosY, ?AttachedPosZ, " +
224 "?PhysicsShapeType, ?Density, ?GravityModifier, " + 225 "?PhysicsShapeType, ?Density, ?GravityModifier, " +
225 "?Friction, ?Restitution, ?DynAttrs)"; 226 "?Friction, ?Restitution, ?Vehicle, ?DynAttrs)";
226 227
227 FillPrimCommand(cmd, prim, obj.UUID, regionUUID); 228 FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
228 229
@@ -262,7 +263,7 @@ namespace OpenSim.Data.MySQL
262 } 263 }
263 } 264 }
264 265
265 public void RemoveObject(UUID obj, UUID regionUUID) 266 public virtual void RemoveObject(UUID obj, UUID regionUUID)
266 { 267 {
267// m_log.DebugFormat("[REGION DB]: Deleting scene object {0} from {1} in database", obj, regionUUID); 268// m_log.DebugFormat("[REGION DB]: Deleting scene object {0} from {1} in database", obj, regionUUID);
268 269
@@ -317,7 +318,8 @@ namespace OpenSim.Data.MySQL
317 /// <param name="uuid">the Item UUID</param> 318 /// <param name="uuid">the Item UUID</param>
318 private void RemoveItems(UUID uuid) 319 private void RemoveItems(UUID uuid)
319 { 320 {
320 lock (m_dbLock) 321 // locked by caller
322// lock (m_dbLock)
321 { 323 {
322 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 324 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
323 { 325 {
@@ -411,7 +413,7 @@ namespace OpenSim.Data.MySQL
411 } 413 }
412 } 414 }
413 415
414 public List<SceneObjectGroup> LoadObjects(UUID regionID) 416 public virtual List<SceneObjectGroup> LoadObjects(UUID regionID)
415 { 417 {
416 const int ROWS_PER_QUERY = 5000; 418 const int ROWS_PER_QUERY = 5000;
417 419
@@ -590,40 +592,53 @@ namespace OpenSim.Data.MySQL
590 592
591 public void StoreTerrain(TerrainData terrData, UUID regionID) 593 public void StoreTerrain(TerrainData terrData, UUID regionID)
592 { 594 {
593 lock (m_dbLock) 595 Util.FireAndForget(delegate(object x)
594 { 596 {
595 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 597 m_log.Info("[REGION DB]: Storing terrain");
596 {
597 dbcon.Open();
598 598
599 using (MySqlCommand cmd = dbcon.CreateCommand()) 599 lock (m_dbLock)
600 {
601 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
600 { 602 {
601 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID"; 603 dbcon.Open();
602 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
603
604 ExecuteNonQuery(cmd);
605 604
606 int terrainDBRevision; 605 using (MySqlCommand cmd = dbcon.CreateCommand())
607 Array terrainDBblob; 606 {
608 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); 607 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
608 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
609 609
610 m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}", 610 using (MySqlCommand cmd2 = dbcon.CreateCommand())
611 LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision); 611 {
612 try
613 {
614 cmd2.CommandText = "insert into terrain (RegionUUID, " +
615 "Revision, Heightfield) values (?RegionUUID, " +
616 "?Revision, ?Heightfield)";
612 617
613 cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)" 618 int terrainDBRevision;
614 + "values (?RegionUUID, ?Revision, ?Heightfield)"; 619 Array terrainDBblob;
620 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
615 621
616 cmd.Parameters.AddWithValue("Revision", terrainDBRevision); 622 cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString());
617 cmd.Parameters.AddWithValue("Heightfield", terrainDBblob); 623 cmd2.Parameters.AddWithValue("Revision", terrainDBRevision);
624 cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob);
618 625
619 ExecuteNonQuery(cmd); 626 ExecuteNonQuery(cmd);
627 ExecuteNonQuery(cmd2);
628 }
629 catch (Exception e)
630 {
631 m_log.ErrorFormat(e.ToString());
632 }
633 }
634 }
620 } 635 }
621 } 636 }
622 } 637 });
623 } 638 }
624 639
625 // Legacy region loading 640 // Legacy region loading
626 public double[,] LoadTerrain(UUID regionID) 641 public virtual double[,] LoadTerrain(UUID regionID)
627 { 642 {
628 double[,] ret = null; 643 double[,] ret = null;
629 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); 644 TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
@@ -655,8 +670,11 @@ namespace OpenSim.Data.MySQL
655 while (reader.Read()) 670 while (reader.Read())
656 { 671 {
657 int rev = Convert.ToInt32(reader["Revision"]); 672 int rev = Convert.ToInt32(reader["Revision"]);
658 byte[] blob = (byte[])reader["Heightfield"]; 673 if ((reader["Heightfield"] != DBNull.Value))
659 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); 674 {
675 byte[] blob = (byte[])reader["Heightfield"];
676 terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
677 }
660 } 678 }
661 } 679 }
662 } 680 }
@@ -666,7 +684,7 @@ namespace OpenSim.Data.MySQL
666 return terrData; 684 return terrData;
667 } 685 }
668 686
669 public void RemoveLandObject(UUID globalID) 687 public virtual void RemoveLandObject(UUID globalID)
670 { 688 {
671 lock (m_dbLock) 689 lock (m_dbLock)
672 { 690 {
@@ -685,7 +703,7 @@ namespace OpenSim.Data.MySQL
685 } 703 }
686 } 704 }
687 705
688 public void StoreLandObject(ILandObject parcel) 706 public virtual void StoreLandObject(ILandObject parcel)
689 { 707 {
690 lock (m_dbLock) 708 lock (m_dbLock)
691 { 709 {
@@ -705,7 +723,8 @@ namespace OpenSim.Data.MySQL
705 "UserLocationX, UserLocationY, UserLocationZ, " + 723 "UserLocationX, UserLocationY, UserLocationZ, " +
706 "UserLookAtX, UserLookAtY, UserLookAtZ, " + 724 "UserLookAtX, UserLookAtY, UserLookAtZ, " +
707 "AuthbuyerID, OtherCleanTime, Dwell, MediaType, MediaDescription, " + 725 "AuthbuyerID, OtherCleanTime, Dwell, MediaType, MediaDescription, " +
708 "MediaSize, MediaLoop, ObscureMusic, ObscureMedia) values (" + 726 "MediaSize, MediaLoop, ObscureMusic, ObscureMedia, " +
727 "SeeAVs, AnyAVSounds, GroupAVSounds) values (" +
709 "?UUID, ?RegionUUID, " + 728 "?UUID, ?RegionUUID, " +
710 "?LocalLandID, ?Bitmap, ?Name, ?Description, " + 729 "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
711 "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " + 730 "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
@@ -716,7 +735,8 @@ namespace OpenSim.Data.MySQL
716 "?UserLocationX, ?UserLocationY, ?UserLocationZ, " + 735 "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
717 "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " + 736 "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
718 "?AuthbuyerID, ?OtherCleanTime, ?Dwell, ?MediaType, ?MediaDescription, "+ 737 "?AuthbuyerID, ?OtherCleanTime, ?Dwell, ?MediaType, ?MediaDescription, "+
719 "CONCAT(?MediaWidth, ',', ?MediaHeight), ?MediaLoop, ?ObscureMusic, ?ObscureMedia)"; 738 "CONCAT(?MediaWidth, ',', ?MediaHeight), ?MediaLoop, ?ObscureMusic, ?ObscureMedia, " +
739 "?SeeAVs, ?AnyAVSounds, ?GroupAVSounds)";
720 740
721 FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID); 741 FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
722 742
@@ -742,7 +762,7 @@ namespace OpenSim.Data.MySQL
742 } 762 }
743 } 763 }
744 764
745 public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID) 765 public virtual RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
746 { 766 {
747 RegionLightShareData nWP = new RegionLightShareData(); 767 RegionLightShareData nWP = new RegionLightShareData();
748 nWP.OnSave += StoreRegionWindlightSettings; 768 nWP.OnSave += StoreRegionWindlightSettings;
@@ -840,7 +860,7 @@ namespace OpenSim.Data.MySQL
840 return nWP; 860 return nWP;
841 } 861 }
842 862
843 public RegionSettings LoadRegionSettings(UUID regionUUID) 863 public virtual RegionSettings LoadRegionSettings(UUID regionUUID)
844 { 864 {
845 RegionSettings rs = null; 865 RegionSettings rs = null;
846 866
@@ -880,7 +900,7 @@ namespace OpenSim.Data.MySQL
880 return rs; 900 return rs;
881 } 901 }
882 902
883 public void StoreRegionWindlightSettings(RegionLightShareData wl) 903 public virtual void StoreRegionWindlightSettings(RegionLightShareData wl)
884 { 904 {
885 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 905 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
886 { 906 {
@@ -983,7 +1003,7 @@ namespace OpenSim.Data.MySQL
983 } 1003 }
984 } 1004 }
985 1005
986 public void RemoveRegionWindlightSettings(UUID regionID) 1006 public virtual void RemoveRegionWindlightSettings(UUID regionID)
987 { 1007 {
988 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 1008 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
989 { 1009 {
@@ -1060,7 +1080,7 @@ namespace OpenSim.Data.MySQL
1060 } 1080 }
1061 #endregion 1081 #endregion
1062 1082
1063 public void StoreRegionSettings(RegionSettings rs) 1083 public virtual void StoreRegionSettings(RegionSettings rs)
1064 { 1084 {
1065 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 1085 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
1066 { 1086 {
@@ -1105,7 +1125,44 @@ namespace OpenSim.Data.MySQL
1105 "?TerrainImageID, " + 1125 "?TerrainImageID, " +
1106 "?TelehubObject, ?ParcelImageID)"; 1126 "?TelehubObject, ?ParcelImageID)";
1107 1127
1108 FillRegionSettingsCommand(cmd, rs); 1128 using (MySqlCommand cmd = dbcon.CreateCommand())
1129 {
1130 cmd.CommandText = "replace into regionsettings (regionUUID, " +
1131 "block_terraform, block_fly, allow_damage, " +
1132 "restrict_pushing, allow_land_resell, " +
1133 "allow_land_join_divide, block_show_in_search, " +
1134 "agent_limit, object_bonus, maturity, " +
1135 "disable_scripts, disable_collisions, " +
1136 "disable_physics, terrain_texture_1, " +
1137 "terrain_texture_2, terrain_texture_3, " +
1138 "terrain_texture_4, elevation_1_nw, " +
1139 "elevation_2_nw, elevation_1_ne, " +
1140 "elevation_2_ne, elevation_1_se, " +
1141 "elevation_2_se, elevation_1_sw, " +
1142 "elevation_2_sw, water_height, " +
1143 "terrain_raise_limit, terrain_lower_limit, " +
1144 "use_estate_sun, fixed_sun, sun_position, " +
1145 "covenant, covenant_datetime, Sandbox, sunvectorx, sunvectory, " +
1146 "sunvectorz, loaded_creation_datetime, " +
1147 "loaded_creation_id, map_tile_ID, block_search, casino, " +
1148 "TelehubObject, parcel_tile_ID) " +
1149 "values (?RegionUUID, ?BlockTerraform, " +
1150 "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
1151 "?AllowLandResell, ?AllowLandJoinDivide, " +
1152 "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
1153 "?Maturity, ?DisableScripts, ?DisableCollisions, " +
1154 "?DisablePhysics, ?TerrainTexture1, " +
1155 "?TerrainTexture2, ?TerrainTexture3, " +
1156 "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
1157 "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
1158 "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
1159 "?WaterHeight, ?TerrainRaiseLimit, " +
1160 "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
1161 "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
1162 "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
1163 "?LoadedCreationDateTime, ?LoadedCreationID, " +
1164 "?TerrainImageID, ?block_search, ?casino, " +
1165 "?TelehubObject, ?ParcelImageID)";
1109 1166
1110 ExecuteNonQuery(cmd); 1167 ExecuteNonQuery(cmd);
1111 } 1168 }
@@ -1114,7 +1171,7 @@ namespace OpenSim.Data.MySQL
1114 SaveSpawnPoints(rs); 1171 SaveSpawnPoints(rs);
1115 } 1172 }
1116 1173
1117 public List<LandData> LoadLandObjects(UUID regionUUID) 1174 public virtual List<LandData> LoadLandObjects(UUID regionUUID)
1118 { 1175 {
1119 List<LandData> landData = new List<LandData>(); 1176 List<LandData> landData = new List<LandData>();
1120 1177
@@ -1296,6 +1353,7 @@ namespace OpenSim.Data.MySQL
1296 prim.CollisionSoundVolume = (float)(double)row["CollisionSoundVolume"]; 1353 prim.CollisionSoundVolume = (float)(double)row["CollisionSoundVolume"];
1297 1354
1298 prim.PassTouches = ((sbyte)row["PassTouches"] != 0); 1355 prim.PassTouches = ((sbyte)row["PassTouches"] != 0);
1356 prim.PassCollisions = ((sbyte)row["PassCollisions"] != 0);
1299 prim.LinkNum = (int)row["LinkNumber"]; 1357 prim.LinkNum = (int)row["LinkNumber"];
1300 1358
1301 if (!(row["MediaURL"] is System.DBNull)) 1359 if (!(row["MediaURL"] is System.DBNull))
@@ -1334,6 +1392,15 @@ namespace OpenSim.Data.MySQL
1334 prim.Friction = (float)(double)row["Friction"]; 1392 prim.Friction = (float)(double)row["Friction"];
1335 prim.Restitution = (float)(double)row["Restitution"]; 1393 prim.Restitution = (float)(double)row["Restitution"];
1336 1394
1395 SOPVehicle vehicle = null;
1396
1397 if (row["Vehicle"].ToString() != String.Empty)
1398 {
1399 vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
1400 if (vehicle != null)
1401 prim.VehicleParams = vehicle;
1402 }
1403
1337 return prim; 1404 return prim;
1338 } 1405 }
1339 1406
@@ -1344,32 +1411,40 @@ namespace OpenSim.Data.MySQL
1344 /// <returns></returns> 1411 /// <returns></returns>
1345 private static TaskInventoryItem BuildItem(IDataReader row) 1412 private static TaskInventoryItem BuildItem(IDataReader row)
1346 { 1413 {
1347 TaskInventoryItem taskItem = new TaskInventoryItem(); 1414 try
1348 1415 {
1349 taskItem.ItemID = DBGuid.FromDB(row["itemID"]); 1416 TaskInventoryItem taskItem = new TaskInventoryItem();
1350 taskItem.ParentPartID = DBGuid.FromDB(row["primID"]); 1417
1351 taskItem.AssetID = DBGuid.FromDB(row["assetID"]); 1418 taskItem.ItemID = DBGuid.FromDB(row["itemID"]);
1352 taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]); 1419 taskItem.ParentPartID = DBGuid.FromDB(row["primID"]);
1353 1420 taskItem.AssetID = DBGuid.FromDB(row["assetID"]);
1354 taskItem.InvType = Convert.ToInt32(row["invType"]); 1421 taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]);
1355 taskItem.Type = Convert.ToInt32(row["assetType"]); 1422
1356 1423 taskItem.InvType = Convert.ToInt32(row["invType"]);
1357 taskItem.Name = (String)row["name"]; 1424 taskItem.Type = Convert.ToInt32(row["assetType"]);
1358 taskItem.Description = (String)row["description"]; 1425
1359 taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]); 1426 taskItem.Name = (String)row["name"];
1360 taskItem.CreatorIdentification = (String)row["creatorID"]; 1427 taskItem.Description = (String)row["description"];
1361 taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]); 1428 taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
1362 taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]); 1429 taskItem.CreatorIdentification = (String)row["creatorID"];
1363 taskItem.GroupID = DBGuid.FromDB(row["groupID"]); 1430 taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]);
1364 1431 taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]);
1365 taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]); 1432 taskItem.GroupID = DBGuid.FromDB(row["groupID"]);
1366 taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]); 1433
1367 taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]); 1434 taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
1368 taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]); 1435 taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
1369 taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]); 1436 taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
1370 taskItem.Flags = Convert.ToUInt32(row["flags"]); 1437 taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
1371 1438 taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
1372 return taskItem; 1439 taskItem.Flags = Convert.ToUInt32(row["flags"]);
1440
1441 return taskItem;
1442 }
1443 catch
1444 {
1445 m_log.ErrorFormat("[MYSQL DB]: Error reading task inventory: itemID was {0}, primID was {1}", row["itemID"].ToString(), row["primID"].ToString());
1446 throw;
1447 }
1373 } 1448 }
1374 1449
1375 private static RegionSettings BuildRegionSettings(IDataReader row) 1450 private static RegionSettings BuildRegionSettings(IDataReader row)
@@ -1427,6 +1502,9 @@ namespace OpenSim.Data.MySQL
1427 newSettings.ParcelImageID = DBGuid.FromDB(row["parcel_tile_ID"]); 1502 newSettings.ParcelImageID = DBGuid.FromDB(row["parcel_tile_ID"]);
1428 newSettings.TelehubObject = DBGuid.FromDB(row["TelehubObject"]); 1503 newSettings.TelehubObject = DBGuid.FromDB(row["TelehubObject"]);
1429 1504
1505 newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
1506 newSettings.Casino = Convert.ToBoolean(row["casino"]);
1507
1430 return newSettings; 1508 return newSettings;
1431 } 1509 }
1432 1510
@@ -1503,6 +1581,13 @@ namespace OpenSim.Data.MySQL
1503 1581
1504 newData.ParcelAccessList = new List<LandAccessEntry>(); 1582 newData.ParcelAccessList = new List<LandAccessEntry>();
1505 1583
1584 if (!(row["SeeAVs"] is System.DBNull))
1585 newData.SeeAVs = Convert.ToInt32(row["SeeAVs"]) != 0 ? true : false;
1586 if (!(row["AnyAVSounds"] is System.DBNull))
1587 newData.AnyAVSounds = Convert.ToInt32(row["AnyAVSounds"]) != 0 ? true : false;
1588 if (!(row["GroupAVSounds"] is System.DBNull))
1589 newData.GroupAVSounds = Convert.ToInt32(row["GroupAVSounds"]) != 0 ? true : false;
1590
1506 return newData; 1591 return newData;
1507 } 1592 }
1508 1593
@@ -1521,6 +1606,34 @@ namespace OpenSim.Data.MySQL
1521 } 1606 }
1522 1607
1523 /// <summary> 1608 /// <summary>
1609 ///
1610 /// </summary>
1611 /// <param name="val"></param>
1612 /// <returns></returns>
1613 private static Array SerializeTerrain(double[,] val, double[,] oldTerrain)
1614 {
1615 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1616 BinaryWriter bw = new BinaryWriter(str);
1617
1618 // TODO: COMPATIBILITY - Add byte-order conversions
1619 for (int x = 0; x < (int)Constants.RegionSize; x++)
1620 for (int y = 0; y < (int)Constants.RegionSize; y++)
1621 {
1622 double height = 20.0;
1623 if (oldTerrain != null)
1624 height = oldTerrain[x, y];
1625 if (!double.IsNaN(val[x, y]))
1626 height = val[x, y];
1627 if (height == 0.0)
1628 height = double.Epsilon;
1629
1630 bw.Write(height);
1631 }
1632
1633 return str.ToArray();
1634 }
1635
1636 /// <summary>
1524 /// Fill the prim command with prim values 1637 /// Fill the prim command with prim values
1525 /// </summary> 1638 /// </summary>
1526 /// <param name="row"></param> 1639 /// <param name="row"></param>
@@ -1654,6 +1767,11 @@ namespace OpenSim.Data.MySQL
1654 else 1767 else
1655 cmd.Parameters.AddWithValue("PassTouches", 0); 1768 cmd.Parameters.AddWithValue("PassTouches", 0);
1656 1769
1770 if (prim.PassCollisions)
1771 cmd.Parameters.AddWithValue("PassCollisions", 1);
1772 else
1773 cmd.Parameters.AddWithValue("PassCollisions", 0);
1774
1657 cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum); 1775 cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
1658 cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl); 1776 cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
1659 if (prim.AttachedPos != null) 1777 if (prim.AttachedPos != null)
@@ -1668,6 +1786,11 @@ namespace OpenSim.Data.MySQL
1668 else 1786 else
1669 cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]); 1787 cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]);
1670 1788
1789 if (prim.VehicleParams != null)
1790 cmd.Parameters.AddWithValue("Vehicle", prim.VehicleParams.ToXml2());
1791 else
1792 cmd.Parameters.AddWithValue("Vehicle", String.Empty);
1793
1671 if (prim.DynAttrs.CountNamespaces > 0) 1794 if (prim.DynAttrs.CountNamespaces > 0)
1672 cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml()); 1795 cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
1673 else 1796 else
@@ -1756,6 +1879,8 @@ namespace OpenSim.Data.MySQL
1756 cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime); 1879 cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
1757 cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID); 1880 cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
1758 cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID); 1881 cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
1882 cmd.Parameters.AddWithValue("block_search", settings.GodBlockSearch);
1883 cmd.Parameters.AddWithValue("casino", settings.Casino);
1759 1884
1760 cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID); 1885 cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID);
1761 cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject); 1886 cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
@@ -1813,6 +1938,10 @@ namespace OpenSim.Data.MySQL
1813 cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop); 1938 cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop);
1814 cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic); 1939 cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic);
1815 cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia); 1940 cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia);
1941 cmd.Parameters.AddWithValue("SeeAVs", land.SeeAVs ? 1 : 0);
1942 cmd.Parameters.AddWithValue("AnyAVSounds", land.AnyAVSounds ? 1 : 0);
1943 cmd.Parameters.AddWithValue("GroupAVSounds", land.GroupAVSounds ? 1 : 0);
1944
1816 } 1945 }
1817 1946
1818 /// <summary> 1947 /// <summary>
@@ -1919,7 +2048,7 @@ namespace OpenSim.Data.MySQL
1919 cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml()); 2048 cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
1920 } 2049 }
1921 2050
1922 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) 2051 public virtual void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1923 { 2052 {
1924 lock (m_dbLock) 2053 lock (m_dbLock)
1925 { 2054 {
@@ -1963,6 +2092,37 @@ namespace OpenSim.Data.MySQL
1963 } 2092 }
1964 } 2093 }
1965 2094
2095 public UUID[] GetObjectIDs(UUID regionID)
2096 {
2097 List<UUID> uuids = new List<UUID>();
2098
2099 lock (m_dbLock)
2100 {
2101 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
2102 {
2103 dbcon.Open();
2104
2105 using (MySqlCommand cmd = dbcon.CreateCommand())
2106 {
2107 cmd.CommandText = "select UUID from prims where RegionUUID = ?RegionUUID and SceneGroupID = UUID";
2108 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
2109
2110 using (IDataReader reader = ExecuteReader(cmd))
2111 {
2112 while (reader.Read())
2113 {
2114 UUID id = new UUID(reader["UUID"].ToString());
2115
2116 uuids.Add(id);
2117 }
2118 }
2119 }
2120 }
2121 }
2122
2123 return uuids.ToArray();
2124 }
2125
1966 private void LoadSpawnPoints(RegionSettings rs) 2126 private void LoadSpawnPoints(RegionSettings rs)
1967 { 2127 {
1968 rs.ClearSpawnPoints(); 2128 rs.ClearSpawnPoints();
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
index e964295..4ff3175 100644
--- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -46,17 +46,21 @@ namespace OpenSim.Data.MySQL
46 { 46 {
47 string[] words = query.Split(new char[] {' '}); 47 string[] words = query.Split(new char[] {' '});
48 48
49 bool valid = false;
50
49 for (int i = 0 ; i < words.Length ; i++) 51 for (int i = 0 ; i < words.Length ; i++)
50 { 52 {
51 if (words[i].Length < 3) 53 if (words[i].Length > 2)
52 { 54 valid = true;
53 if (i != words.Length - 1) 55// if (words[i].Length < 3)
54 Array.Copy(words, i + 1, words, i, words.Length - i - 1); 56// {
55 Array.Resize(ref words, words.Length - 1); 57// if (i != words.Length - 1)
56 } 58// Array.Copy(words, i + 1, words, i, words.Length - i - 1);
59// Array.Resize(ref words, words.Length - 1);
60// }
57 } 61 }
58 62
59 if (words.Length == 0) 63 if ((!valid) || words.Length == 0)
60 return new UserAccountData[0]; 64 return new UserAccountData[0];
61 65
62 if (words.Length > 2) 66 if (words.Length > 2)
@@ -66,20 +70,36 @@ namespace OpenSim.Data.MySQL
66 { 70 {
67 if (words.Length == 1) 71 if (words.Length == 1)
68 { 72 {
69 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?search or LastName like ?search)", m_Realm); 73 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?search or LastName like ?search) and active=1", m_Realm);
70 cmd.Parameters.AddWithValue("?search", "%" + words[0] + "%"); 74 cmd.Parameters.AddWithValue("?search", words[0] + "%");
71 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); 75 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
72 } 76 }
73 else 77 else
74 { 78 {
75 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst or LastName like ?searchLast)", m_Realm); 79 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst and LastName like ?searchLast) and active=1", m_Realm);
76 cmd.Parameters.AddWithValue("?searchFirst", "%" + words[0] + "%"); 80 cmd.Parameters.AddWithValue("?searchFirst", words[0] + "%");
77 cmd.Parameters.AddWithValue("?searchLast", "%" + words[1] + "%"); 81 cmd.Parameters.AddWithValue("?searchLast", words[1] + "%");
78 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); 82 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
79 } 83 }
80 84
81 return DoQuery(cmd); 85 return DoQuery(cmd);
82 } 86 }
83 } 87 }
88
89 public UserAccountData[] GetUsersWhere(UUID scopeID, string where)
90 {
91 using (MySqlCommand cmd = new MySqlCommand())
92 {
93 if (scopeID != UUID.Zero)
94 {
95 where = "(ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (" + where + ")";
96 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
97 }
98
99 cmd.CommandText = String.Format("select * from {0} where " + where, m_Realm);
100
101 return DoQuery(cmd);
102 }
103 }
84 } 104 }
85} \ No newline at end of file 105}
diff --git a/OpenSim/Data/MySQL/MySQLUserProfilesData.cs b/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
index b35595d..c213dd1 100644
--- a/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserProfilesData.cs
@@ -631,6 +631,8 @@ namespace OpenSim.Data.MySQL
631 { 631 {
632 if(reader.HasRows) 632 if(reader.HasRows)
633 { 633 {
634 m_log.DebugFormat("[PROFILES_DATA]" +
635 ": Getting data for {0}.", props.UserId);
634 reader.Read(); 636 reader.Read();
635 props.WebUrl = (string)reader["profileURL"]; 637 props.WebUrl = (string)reader["profileURL"];
636 UUID.TryParse((string)reader["profileImage"], out props.ImageId); 638 UUID.TryParse((string)reader["profileImage"], out props.ImageId);
@@ -646,6 +648,9 @@ namespace OpenSim.Data.MySQL
646 } 648 }
647 else 649 else
648 { 650 {
651 m_log.DebugFormat("[PROFILES_DATA]" +
652 ": No data for {0}", props.UserId);
653
649 props.WebUrl = string.Empty; 654 props.WebUrl = string.Empty;
650 props.ImageId = UUID.Zero; 655 props.ImageId = UUID.Zero;
651 props.AboutText = string.Empty; 656 props.AboutText = string.Empty;
@@ -891,7 +896,7 @@ namespace OpenSim.Data.MySQL
891 } 896 }
892 897
893 #region User Preferences 898 #region User Preferences
894 public bool GetUserPreferences(ref UserPreferences pref, ref string result) 899 public OSDArray GetUserPreferences(UUID avatarId)
895 { 900 {
896 string query = string.Empty; 901 string query = string.Empty;
897 902
@@ -908,16 +913,19 @@ namespace OpenSim.Data.MySQL
908 dbcon.Open(); 913 dbcon.Open();
909 using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) 914 using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
910 { 915 {
911 cmd.Parameters.AddWithValue("?Id", pref.UserId.ToString()); 916 cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
912 917
913 using (MySqlDataReader reader = cmd.ExecuteReader()) 918 using (MySqlDataReader reader = cmd.ExecuteReader())
914 { 919 {
915 if(reader.HasRows) 920 if(reader.HasRows)
916 { 921 {
917 reader.Read(); 922 reader.Read();
918 bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail); 923 OSDMap record = new OSDMap();
919 bool.TryParse((string)reader["visible"], out pref.Visible); 924
920 pref.EMail = (string)reader["email"]; 925 record.Add("imviaemail",OSD.FromString((string)reader["imviaemail"]));
926 record.Add("visible",OSD.FromString((string)reader["visible"]));
927 record.Add("email",OSD.FromString((string)reader["email"]));
928 data.Add(record);
921 } 929 }
922 else 930 else
923 { 931 {
@@ -930,8 +938,8 @@ namespace OpenSim.Data.MySQL
930 using (MySqlCommand put = new MySqlCommand(query, dbcon)) 938 using (MySqlCommand put = new MySqlCommand(query, dbcon))
931 { 939 {
932 940
933 put.Parameters.AddWithValue("?Email", pref.EMail); 941// put.Parameters.AddWithValue("?Email", pref.EMail);
934 put.Parameters.AddWithValue("?uuid", pref.UserId.ToString()); 942// put.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
935 943
936 put.ExecuteNonQuery(); 944 put.ExecuteNonQuery();
937 } 945 }
@@ -944,17 +952,15 @@ namespace OpenSim.Data.MySQL
944 { 952 {
945 m_log.ErrorFormat("[PROFILES_DATA]" + 953 m_log.ErrorFormat("[PROFILES_DATA]" +
946 ": Get preferences exception {0}", e.Message); 954 ": Get preferences exception {0}", e.Message);
947 result = e.Message;
948 return false;
949 } 955 }
950 return true; 956 return data;
951 } 957 }
952 958
953 public bool UpdateUserPreferences(ref UserPreferences pref, ref string result) 959 public bool UpdateUserPreferences(bool emailIm, bool visible, UUID avatarId )
954 { 960 {
955 string query = string.Empty; 961 string query = string.Empty;
956 962
957 query += "UPDATE usersettings SET "; 963 query += "UPDATE userpsettings SET ";
958 query += "imviaemail=?ImViaEmail, "; 964 query += "imviaemail=?ImViaEmail, ";
959 query += "visible=?Visible, "; 965 query += "visible=?Visible, ";
960 query += "email=?EMail "; 966 query += "email=?EMail ";
@@ -980,7 +986,6 @@ namespace OpenSim.Data.MySQL
980 { 986 {
981 m_log.ErrorFormat("[PROFILES_DATA]" + 987 m_log.ErrorFormat("[PROFILES_DATA]" +
982 ": UserPreferencesUpdate exception {0} {1}", e.Message, e.InnerException); 988 ": UserPreferencesUpdate exception {0} {1}", e.Message, e.InnerException);
983 result = e.Message;
984 return false; 989 return false;
985 } 990 }
986 return true; 991 return true;
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs
index af7e876..68e1a5a 100644
--- a/OpenSim/Data/MySQL/MySQLXAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs
@@ -500,4 +500,4 @@ namespace OpenSim.Data.MySQL
500 500
501 #endregion 501 #endregion
502 } 502 }
503} \ No newline at end of file 503}
diff --git a/OpenSim/Data/MySQL/Resources/RegionStore.migrations b/OpenSim/Data/MySQL/Resources/RegionStore.migrations
index ac31380..738f5c2 100644
--- a/OpenSim/Data/MySQL/Resources/RegionStore.migrations
+++ b/OpenSim/Data/MySQL/Resources/RegionStore.migrations
@@ -717,7 +717,7 @@ ALTER TABLE regionsettings ADD COLUMN loaded_creation_datetime int unsigned NOT
717 717
718COMMIT; 718COMMIT;
719 719
720:VERSION 32 720:VERSION 32 #---------------------
721 721
722BEGIN; 722BEGIN;
723CREATE TABLE `regionwindlight` ( 723CREATE TABLE `regionwindlight` (
@@ -939,6 +939,7 @@ ALTER TABLE prims ADD COLUMN AttachedPosY double default 0;
939ALTER TABLE prims ADD COLUMN AttachedPosZ double default 0; 939ALTER TABLE prims ADD COLUMN AttachedPosZ double default 0;
940ALTER TABLE primshapes ADD COLUMN LastAttachPoint int(4) not null default '0'; 940ALTER TABLE primshapes ADD COLUMN LastAttachPoint int(4) not null default '0';
941COMMIT; 941COMMIT;
942<<<<<<< HEAD
942 943
943:VERSION 50 #---- Change LandFlags to unsigned 944:VERSION 50 #---- Change LandFlags to unsigned
944 945
@@ -948,3 +949,5 @@ ALTER TABLE land CHANGE COLUMN LandFlags LandFlags int unsigned default null;
948 949
949COMMIT; 950COMMIT;
950 951
952=======
953>>>>>>> avn/ubitvar
diff --git a/OpenSim/Data/MySQL/Resources/UserProfiles.migrations b/OpenSim/Data/MySQL/Resources/UserProfiles.migrations
index 87e99fa..3df9b9b 100644
--- a/OpenSim/Data/MySQL/Resources/UserProfiles.migrations
+++ b/OpenSim/Data/MySQL/Resources/UserProfiles.migrations
@@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `userdata` (
81 81
82commit; 82commit;
83 83
84<<<<<<< HEAD
84:VERSION 3 # ------------------------------- 85:VERSION 3 # -------------------------------
85begin; 86begin;
86CREATE TABLE IF NOT EXISTS `usersettings` ( 87CREATE TABLE IF NOT EXISTS `usersettings` (
@@ -96,3 +97,5 @@ commit;
96begin; 97begin;
97ALTER TABLE userpicks ADD COLUMN gatekeeper varchar(255); 98ALTER TABLE userpicks ADD COLUMN gatekeeper varchar(255);
98commit; 99commit;
100=======
101>>>>>>> avn/ubitvar
diff --git a/OpenSim/Data/Null/NullRegionData.cs b/OpenSim/Data/Null/NullRegionData.cs
index d28cd99..3e69394 100644
--- a/OpenSim/Data/Null/NullRegionData.cs
+++ b/OpenSim/Data/Null/NullRegionData.cs
@@ -140,7 +140,8 @@ namespace OpenSim.Data.Null
140 { 140 {
141 foreach (RegionData r in m_regionData.Values) 141 foreach (RegionData r in m_regionData.Values)
142 { 142 {
143 if (r.posX == posX && r.posY == posY) 143 if (posX >= r.posX && posX < r.posX + r.sizeX
144 && posY >= r.posY && posY < r.posY + r.sizeY)
144 ret.Add(r); 145 ret.Add(r);
145 } 146 }
146 } 147 }
@@ -176,8 +177,9 @@ namespace OpenSim.Data.Null
176 { 177 {
177 foreach (RegionData r in m_regionData.Values) 178 foreach (RegionData r in m_regionData.Values)
178 { 179 {
179 if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY) 180 if (r.posX + r.sizeX > startX && r.posX <= endX
180 ret.Add(r); 181 && r.posY + r.sizeX > startY && r.posY <= endY)
182 ret.Add(r);
181 } 183 }
182 } 184 }
183 185
diff --git a/OpenSim/Data/Null/NullSimulationData.cs b/OpenSim/Data/Null/NullSimulationData.cs
index deeaced..339e7f4 100644
--- a/OpenSim/Data/Null/NullSimulationData.cs
+++ b/OpenSim/Data/Null/NullSimulationData.cs
@@ -184,6 +184,11 @@ namespace OpenSim.Data.Null
184 { 184 {
185 } 185 }
186 186
187 public UUID[] GetObjectIDs(UUID regionID)
188 {
189 return new UUID[0];
190 }
191
187 public void SaveExtra(UUID regionID, string name, string value) 192 public void SaveExtra(UUID regionID, string name, string value)
188 { 193 {
189 } 194 }
diff --git a/OpenSim/Data/Null/NullUserAccountData.cs b/OpenSim/Data/Null/NullUserAccountData.cs
index ec54dba..241616b 100644
--- a/OpenSim/Data/Null/NullUserAccountData.cs
+++ b/OpenSim/Data/Null/NullUserAccountData.cs
@@ -193,5 +193,10 @@ namespace OpenSim.Data.Null
193 193
194 return false; 194 return false;
195 } 195 }
196
197 public UserAccountData[] GetUsersWhere(UUID scopeID, string where)
198 {
199 return null;
200 }
196 } 201 }
197} 202}
diff --git a/OpenSim/Data/PGSQL/PGSQLAssetData.cs b/OpenSim/Data/PGSQL/PGSQLAssetData.cs
index 5d8b0a2..81adb03 100644
--- a/OpenSim/Data/PGSQL/PGSQLAssetData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLAssetData.cs
@@ -149,7 +149,7 @@ namespace OpenSim.Data.PGSQL
149 /// Create asset in m_database 149 /// Create asset in m_database
150 /// </summary> 150 /// </summary>
151 /// <param name="asset">the asset</param> 151 /// <param name="asset">the asset</param>
152 override public void StoreAsset(AssetBase asset) 152 override public bool StoreAsset(AssetBase asset)
153 { 153 {
154 154
155 string sql = 155 string sql =
@@ -208,6 +208,7 @@ namespace OpenSim.Data.PGSQL
208 m_log.Error("[ASSET DB]: Error storing item :" + e.Message + " sql "+sql); 208 m_log.Error("[ASSET DB]: Error storing item :" + e.Message + " sql "+sql);
209 } 209 }
210 } 210 }
211 return true;
211 } 212 }
212 213
213 214
diff --git a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs
index 0a68b23..a2b5a2a 100644
--- a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs
@@ -325,5 +325,10 @@ namespace OpenSim.Data.PGSQL
325 return DoQuery(cmd); 325 return DoQuery(cmd);
326 } 326 }
327 } 327 }
328
329 public UserAccountData[] GetUsersWhere(UUID scopeID, string where)
330 {
331 return null;
332 }
328 } 333 }
329} 334}
diff --git a/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations b/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations
index a6bd8ca..a67107a 100644
--- a/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations
+++ b/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations
@@ -81,6 +81,7 @@ CREATE TABLE userdata (
81 81
82commit; 82commit;
83 83
84<<<<<<< HEAD
84:VERSION 3 # ------------------------------- 85:VERSION 3 # -------------------------------
85begin; 86begin;
86CREATE TABLE usersettings ( 87CREATE TABLE usersettings (
@@ -152,4 +153,6 @@ BEGIN;
152 153
153ALTER TABLE usersettings ALTER COLUMN imviaemail SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END; 154ALTER TABLE usersettings ALTER COLUMN imviaemail SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END;
154 155
155COMMIT; \ No newline at end of file 156COMMIT;
157=======
158>>>>>>> avn/ubitvar
diff --git a/OpenSim/Data/SQLite/Resources/UserProfiles.migrations b/OpenSim/Data/SQLite/Resources/UserProfiles.migrations
index 86434e8..16581f6 100644
--- a/OpenSim/Data/SQLite/Resources/UserProfiles.migrations
+++ b/OpenSim/Data/SQLite/Resources/UserProfiles.migrations
@@ -88,15 +88,3 @@ CREATE TABLE IF NOT EXISTS userdata (
88 88
89commit; 89commit;
90 90
91
92:VERSION 3 # -------------------------------
93
94begin;
95CREATE TABLE IF NOT EXISTS usersettings (
96 useruuid char(36) NOT NULL,
97 imviaemail binary(1) NOT NULL,
98 visible binary(1) NOT NULL,
99 email varchar(254) NOT NULL,
100 PRIMARY KEY (useruuid)
101)
102commit; \ No newline at end of file
diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs
index f0dda64..9c2bd2e 100644
--- a/OpenSim/Data/SQLite/SQLiteAssetData.cs
+++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs
@@ -131,7 +131,7 @@ namespace OpenSim.Data.SQLite
131 /// Create an asset 131 /// Create an asset
132 /// </summary> 132 /// </summary>
133 /// <param name="asset">Asset Base</param> 133 /// <param name="asset">Asset Base</param>
134 override public void StoreAsset(AssetBase asset) 134 override public bool StoreAsset(AssetBase asset)
135 { 135 {
136 string assetName = asset.Name; 136 string assetName = asset.Name;
137 if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) 137 if (asset.Name.Length > AssetBase.MAX_ASSET_NAME)
@@ -171,6 +171,7 @@ namespace OpenSim.Data.SQLite
171 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); 171 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
172 172
173 cmd.ExecuteNonQuery(); 173 cmd.ExecuteNonQuery();
174 return true;
174 } 175 }
175 } 176 }
176 } 177 }
@@ -191,6 +192,7 @@ namespace OpenSim.Data.SQLite
191 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); 192 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
192 193
193 cmd.ExecuteNonQuery(); 194 cmd.ExecuteNonQuery();
195 return true;
194 } 196 }
195 } 197 }
196 } 198 }
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index 6ed3d40..9a47e37 100644
--- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
@@ -2013,6 +2013,7 @@ namespace OpenSim.Data.SQLite
2013 return entry; 2013 return entry;
2014 } 2014 }
2015 2015
2016 /*
2016 /// <summary> 2017 /// <summary>
2017 /// 2018 ///
2018 /// </summary> 2019 /// </summary>
@@ -2944,6 +2945,11 @@ namespace OpenSim.Data.SQLite
2944 } 2945 }
2945 } 2946 }
2946 2947
2948 public UUID[] GetObjectIDs(UUID regionID)
2949 {
2950 return new UUID[0];
2951 }
2952
2947 public void SaveExtra(UUID regionID, string name, string value) 2953 public void SaveExtra(UUID regionID, string name, string value)
2948 { 2954 {
2949 } 2955 }
diff --git a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
index f98d376..91d62ce 100644
--- a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
@@ -82,5 +82,10 @@ namespace OpenSim.Data.SQLite
82 return DoQuery(cmd); 82 return DoQuery(cmd);
83 } 83 }
84 } 84 }
85
86 public UserAccountData[] GetUsersWhere(UUID scopeID, string where)
87 {
88 return null;
89 }
85 } 90 }
86} 91}
diff --git a/OpenSim/Data/SQLite/SQLiteUserProfilesData.cs b/OpenSim/Data/SQLite/SQLiteUserProfilesData.cs
index cd3e8b6..70579af 100644
--- a/OpenSim/Data/SQLite/SQLiteUserProfilesData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserProfilesData.cs
@@ -741,6 +741,7 @@ namespace OpenSim.Data.SQLite
741 return true; 741 return true;
742 } 742 }
743 743
744 /*
744 public bool UpdateUserPreferences(ref UserPreferences pref, ref string result) 745 public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
745 { 746 {
746 string query = string.Empty; 747 string query = string.Empty;
@@ -825,6 +826,7 @@ namespace OpenSim.Data.SQLite
825 } 826 }
826 return true; 827 return true;
827 } 828 }
829 */
828 830
829 public bool GetUserAppData(ref UserAppData props, ref string result) 831 public bool GetUserAppData(ref UserAppData props, ref string result)
830 { 832 {
diff --git a/OpenSim/Framework/AnimationSet.cs b/OpenSim/Framework/AnimationSet.cs
new file mode 100644
index 0000000..6c5b15c
--- /dev/null
+++ b/OpenSim/Framework/AnimationSet.cs
@@ -0,0 +1,168 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31
32namespace OpenSim.Framework
33{
34 public delegate bool AnimationSetValidator(UUID animID);
35
36 public class AnimationSet
37 {
38 private bool m_parseError = false;
39
40 public const uint createBasePermitions = (uint)(PermissionMask.All); // no export ?
41 public const uint createNextPermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
42
43 public const uint allowedBasePermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
44 public const uint allowedNextPermitions = 0;
45
46 public static void setCreateItemPermitions(InventoryItemBase it)
47 {
48 if (it == null)
49 return;
50
51 it.BasePermissions = createBasePermitions;
52 it.CurrentPermissions = createBasePermitions;
53 // it.GroupPermissions &= allowedPermitions;
54 it.NextPermissions = createNextPermitions;
55 // it.EveryOnePermissions &= allowedPermitions;
56 it.GroupPermissions = 0;
57 it.EveryOnePermissions = 0;
58 }
59
60 public static void enforceItemPermitions(InventoryItemBase it, bool IsCreator)
61 {
62 if (it == null)
63 return;
64
65 uint bp;
66 uint np;
67
68 if (IsCreator)
69 {
70 bp = createBasePermitions;
71 np = createNextPermitions;
72 }
73 else
74 {
75 bp = allowedBasePermitions;
76 np = allowedNextPermitions;
77 }
78
79 it.BasePermissions &= bp;
80 it.CurrentPermissions &= bp;
81 // it.GroupPermissions &= allowedPermitions;
82 it.NextPermissions &= np;
83 // it.EveryOnePermissions &= allowedPermitions;
84 it.GroupPermissions = 0;
85 it.EveryOnePermissions = 0;
86 }
87
88 public int AnimationCount { get; private set; }
89 private Dictionary<string, KeyValuePair<string, UUID>> m_animations = new Dictionary<string, KeyValuePair<string, UUID>>();
90
91 public UUID GetAnimation(string index)
92 {
93 KeyValuePair<string, UUID> val;
94 if (m_animations.TryGetValue(index, out val))
95 return val.Value;
96
97 return UUID.Zero;
98 }
99
100 public string GetAnimationName(string index)
101 {
102 KeyValuePair<string, UUID> val;
103 if (m_animations.TryGetValue(index, out val))
104 return val.Key;
105
106 return String.Empty;
107 }
108
109 public void SetAnimation(string index, string name, UUID anim)
110 {
111 if (anim == UUID.Zero)
112 {
113 m_animations.Remove(index);
114 return;
115 }
116
117 m_animations[index] = new KeyValuePair<string, UUID>(name, anim);
118 }
119
120 public AnimationSet(Byte[] data)
121 {
122 string assetData = System.Text.Encoding.ASCII.GetString(data);
123 Console.WriteLine("--------------------");
124 Console.WriteLine("AnimationSet length {0} bytes", assetData.Length);
125 Console.WriteLine(assetData);
126 Console.WriteLine("--------------------");
127 }
128
129 public Byte[] ToBytes()
130 {
131 // If there was an error parsing the input, we give back an
132 // empty set rather than the original data.
133 if (m_parseError)
134 {
135 string dummy = "version 1\ncount 0\n";
136 return System.Text.Encoding.ASCII.GetBytes(dummy);
137 }
138
139 string assetData = String.Format("version 1\ncount {0}\n", m_animations.Count);
140 foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
141 assetData += String.Format("{0} {1} {2}\n", kvp.Key, kvp.Value.Value.ToString(), kvp.Value.Key);
142 return System.Text.Encoding.ASCII.GetBytes(assetData);
143 }
144
145 public bool Validate(AnimationSetValidator val)
146 {
147 if (m_parseError)
148 return false;
149
150 List<string> badAnims = new List<string>();
151
152 bool allOk = true;
153 foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
154 {
155 if (!val(kvp.Value.Value))
156 {
157 allOk = false;
158 badAnims.Add(kvp.Key);
159 }
160 }
161
162 foreach (string idx in badAnims)
163 m_animations.Remove(idx);
164
165 return allOk;
166 }
167 }
168}
diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs
index 2f04d2e..3937d9c 100644
--- a/OpenSim/Framework/AssetBase.cs
+++ b/OpenSim/Framework/AssetBase.cs
@@ -63,6 +63,8 @@ namespace OpenSim.Framework
63 /// </summary> 63 /// </summary>
64 private AssetMetadata m_metadata; 64 private AssetMetadata m_metadata;
65 65
66 private int m_uploadAttempts;
67
66 // This is needed for .NET serialization!!! 68 // This is needed for .NET serialization!!!
67 // Do NOT "Optimize" away! 69 // Do NOT "Optimize" away!
68 public AssetBase() 70 public AssetBase()
@@ -148,7 +150,12 @@ namespace OpenSim.Framework
148 Type == (sbyte)AssetType.Folder || 150 Type == (sbyte)AssetType.Folder ||
149 Type == (sbyte)AssetType.ImageJPEG || 151 Type == (sbyte)AssetType.ImageJPEG ||
150 Type == (sbyte)AssetType.ImageTGA || 152 Type == (sbyte)AssetType.ImageTGA ||
153<<<<<<< HEAD
151 Type == (sbyte)AssetType.LSLBytecode); 154 Type == (sbyte)AssetType.LSLBytecode);
155=======
156 Type == (sbyte)AssetType.Mesh ||
157 Type == (sbyte) AssetType.LSLBytecode);
158>>>>>>> avn/ubitvar
152 } 159 }
153 } 160 }
154 161
@@ -197,6 +204,12 @@ namespace OpenSim.Framework
197 set { m_metadata.Type = value; } 204 set { m_metadata.Type = value; }
198 } 205 }
199 206
207 public int UploadAttempts
208 {
209 get { return m_uploadAttempts; }
210 set { m_uploadAttempts = value; }
211 }
212
200 /// <summary> 213 /// <summary>
201 /// Is this a region only asset, or does this exist on the asset server also 214 /// Is this a region only asset, or does this exist on the asset server also
202 /// </summary> 215 /// </summary>
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 69113b1..72c6bfc 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -53,7 +53,11 @@ namespace OpenSim.Framework
53 // should be only used as initial default value ( V1 viewers ) 53 // should be only used as initial default value ( V1 viewers )
54 public readonly static int VISUALPARAM_COUNT = 218; 54 public readonly static int VISUALPARAM_COUNT = 218;
55 55
56 public readonly static int TEXTURE_COUNT = 21; 56// public readonly static int TEXTURE_COUNT = 21
57 // 21 bad, make it be updated as libovm gets update
58 // also keeping in sync with it
59 public readonly static int TEXTURE_COUNT = Primitive.TextureEntry.MAX_FACES;
60
57 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 61 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
58 62
59 protected int m_serial = 0; 63 protected int m_serial = 0;
@@ -179,11 +183,16 @@ namespace OpenSim.Framework
179 m_attachments = new Dictionary<int, List<AvatarAttachment>>(); 183 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
180 } 184 }
181 185
182 public AvatarAppearance(AvatarAppearance appearance) : this(appearance, true) 186 public AvatarAppearance(AvatarAppearance appearance): this(appearance, true,true)
183 { 187 {
184 } 188 }
185 189
186 public AvatarAppearance(AvatarAppearance appearance, bool copyWearables) 190 public AvatarAppearance(AvatarAppearance appearance, bool copyWearables)
191 : this(appearance, copyWearables, true)
192 {
193 }
194
195 public AvatarAppearance(AvatarAppearance appearance, bool copyWearables, bool copyBaked)
187 { 196 {
188// m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance"); 197// m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance");
189 198
@@ -217,6 +226,10 @@ namespace OpenSim.Framework
217 { 226 {
218 byte[] tbytes = appearance.Texture.GetBytes(); 227 byte[] tbytes = appearance.Texture.GetBytes();
219 m_texture = new Primitive.TextureEntry(tbytes,0,tbytes.Length); 228 m_texture = new Primitive.TextureEntry(tbytes,0,tbytes.Length);
229 if (copyBaked && appearance.m_cacheitems != null)
230 m_cacheitems = (WearableCacheItem[])appearance.m_cacheitems.Clone();
231 else
232 m_cacheitems = null;
220 } 233 }
221 234
222 m_visualparams = null; 235 m_visualparams = null;
@@ -458,7 +471,10 @@ namespace OpenSim.Framework
458// m_log.WarnFormat("[AVATARAPPEARANCE] set wearable {0} --> {1}:{2}",wearableId,wearable.ItemID,wearable.AssetID); 471// m_log.WarnFormat("[AVATARAPPEARANCE] set wearable {0} --> {1}:{2}",wearableId,wearable.ItemID,wearable.AssetID);
459// DEBUG OFF 472// DEBUG OFF
460 m_wearables[wearableId].Clear(); 473 m_wearables[wearableId].Clear();
461 for (int i = 0; i < wearable.Count; i++) 474 int count = wearable.Count;
475 if (count > AvatarWearable.MAX_WEARABLES)
476 count = AvatarWearable.MAX_WEARABLES;
477 for (int i = 0; i < count; i++)
462 m_wearables[wearableId].Add(wearable[i].ItemID, wearable[i].AssetID); 478 m_wearables[wearableId].Add(wearable[i].ItemID, wearable[i].AssetID);
463 } 479 }
464 480
@@ -722,6 +738,13 @@ namespace OpenSim.Framework
722 } 738 }
723 data["textures"] = textures; 739 data["textures"] = textures;
724 740
741 if (m_cacheitems != null)
742 {
743 OSDArray baked = WearableCacheItem.BakedToOSD(m_cacheitems);
744 if (baked != null)
745 data["bakedcache"] = baked;
746 }
747
725 // Visual Parameters 748 // Visual Parameters
726 OSDBinary visualparams = new OSDBinary(m_visualparams); 749 OSDBinary visualparams = new OSDBinary(m_visualparams);
727 data["visualparams"] = visualparams; 750 data["visualparams"] = visualparams;
@@ -757,7 +780,12 @@ namespace OpenSim.Framework
757 if ((data != null) && (data["wearables"] != null) && (data["wearables"]).Type == OSDType.Array) 780 if ((data != null) && (data["wearables"] != null) && (data["wearables"]).Type == OSDType.Array)
758 { 781 {
759 OSDArray wears = (OSDArray)(data["wearables"]); 782 OSDArray wears = (OSDArray)(data["wearables"]);
760 for (int i = 0; i < wears.Count; i++) 783
784 int count = wears.Count;
785 if (count > AvatarWearable.MAX_WEARABLES)
786 count = AvatarWearable.MAX_WEARABLES;
787
788 for (int i = 0; i < count; i++)
761 m_wearables[i] = new AvatarWearable((OSDArray)wears[i]); 789 m_wearables[i] = new AvatarWearable((OSDArray)wears[i]);
762 } 790 }
763 else 791 else
@@ -783,6 +811,12 @@ namespace OpenSim.Framework
783 m_log.Warn("[AVATAR APPEARANCE]: failed to unpack textures"); 811 m_log.Warn("[AVATAR APPEARANCE]: failed to unpack textures");
784 } 812 }
785 813
814 if ((data != null) && (data["bakedcache"] != null) && (data["bakedcache"]).Type == OSDType.Array)
815 {
816 OSDArray bakedOSDArray = (OSDArray)(data["bakedcache"]);
817 m_cacheitems = WearableCacheItem.BakedFromOSD(bakedOSDArray);
818 }
819
786 // Visual Parameters 820 // Visual Parameters
787 SetDefaultParams(); 821 SetDefaultParams();
788 if ((data != null) && (data["visualparams"] != null)) 822 if ((data != null) && (data["visualparams"] != null))
@@ -1632,7 +1666,12 @@ namespace OpenSim.Framework
1632 BREAST_PHYSICS_LEFTRIGHT_MAX_EFFECT = 247, 1666 BREAST_PHYSICS_LEFTRIGHT_MAX_EFFECT = 247,
1633 BREAST_PHYSICS_LEFTRIGHT_SPRING= 248, 1667 BREAST_PHYSICS_LEFTRIGHT_SPRING= 248,
1634 BREAST_PHYSICS_LEFTRIGHT_GAIN = 249, 1668 BREAST_PHYSICS_LEFTRIGHT_GAIN = 249,
1635 BREAST_PHYSICS_LEFTRIGHT_DAMPING = 250 1669 BREAST_PHYSICS_LEFTRIGHT_DAMPING = 250,
1670
1671 // Ubit: 07/96/2013 new parameters
1672 _APPEARANCEMESSAGE_VERSION = 251, //ID 11000
1673
1674 SHAPE_HOVER = 252, //ID 11001
1636 } 1675 }
1637 #endregion 1676 #endregion
1638 } 1677 }
diff --git a/OpenSim/Framework/AvatarWearable.cs b/OpenSim/Framework/AvatarWearable.cs
index 8e27596..0ba4e65 100644
--- a/OpenSim/Framework/AvatarWearable.cs
+++ b/OpenSim/Framework/AvatarWearable.cs
@@ -62,10 +62,16 @@ namespace OpenSim.Framework
62 public static readonly int UNDERSHIRT = 10; 62 public static readonly int UNDERSHIRT = 10;
63 public static readonly int UNDERPANTS = 11; 63 public static readonly int UNDERPANTS = 11;
64 public static readonly int SKIRT = 12; 64 public static readonly int SKIRT = 12;
65
66 public static readonly int MAX_BASICWEARABLES = 13;
67
65 public static readonly int ALPHA = 13; 68 public static readonly int ALPHA = 13;
66 public static readonly int TATTOO = 14; 69 public static readonly int TATTOO = 14;
67 70
68 public static readonly int MAX_WEARABLES = 15; 71// public static readonly int MAX_WEARABLES = 15;
72 public static readonly int PHYSICS = 15;
73 public static int MAX_WEARABLES = 16;
74
69 75
70 public static readonly UUID DEFAULT_BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9"); 76 public static readonly UUID DEFAULT_BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9");
71 public static readonly UUID DEFAULT_BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73"); 77 public static readonly UUID DEFAULT_BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73");
@@ -219,7 +225,7 @@ namespace OpenSim.Framework
219 { 225 {
220 get 226 get
221 { 227 {
222 AvatarWearable[] defaultWearables = new AvatarWearable[MAX_WEARABLES]; //should be 15 of these 228 AvatarWearable[] defaultWearables = new AvatarWearable[MAX_WEARABLES];
223 for (int i = 0; i < MAX_WEARABLES; i++) 229 for (int i = 0; i < MAX_WEARABLES; i++)
224 { 230 {
225 defaultWearables[i] = new AvatarWearable(); 231 defaultWearables[i] = new AvatarWearable();
@@ -242,10 +248,13 @@ namespace OpenSim.Framework
242 248
243// // Alpha 249// // Alpha
244// defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET); 250// defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET);
245 251
246// // Tattoo 252 // // Tattoo
247// defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET); 253 // defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET);
248 254
255 // // Physics
256 // defaultWearables[PHYSICS].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET);
257
249 return defaultWearables; 258 return defaultWearables;
250 } 259 }
251 } 260 }
diff --git a/OpenSim/Framework/BlockingQueue.cs b/OpenSim/Framework/BlockingQueue.cs
index d11ad11..daf99a8 100644
--- a/OpenSim/Framework/BlockingQueue.cs
+++ b/OpenSim/Framework/BlockingQueue.cs
@@ -76,10 +76,9 @@ namespace OpenSim.Framework
76 { 76 {
77 lock (m_queueSync) 77 lock (m_queueSync)
78 { 78 {
79 bool success = true; 79 if (m_queue.Count < 1 && m_pqueue.Count < 1)
80 while (m_queue.Count < 1 && m_pqueue.Count < 1 && success)
81 { 80 {
82 success = Monitor.Wait(m_queueSync, msTimeout); 81 Monitor.Wait(m_queueSync, msTimeout);
83 } 82 }
84 83
85 if (m_pqueue.Count > 0) 84 if (m_pqueue.Count > 0)
diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs
index 2a8e67d..a714d86 100644
--- a/OpenSim/Framework/ChildAgentDataUpdate.cs
+++ b/OpenSim/Framework/ChildAgentDataUpdate.cs
@@ -94,6 +94,7 @@ namespace OpenSim.Framework
94 // This probably shouldn't be here 94 // This probably shouldn't be here
95 public byte[] Throttles; 95 public byte[] Throttles;
96 96
97 public Dictionary<ulong, string> ChildrenCapSeeds = null;
97 98
98 public OSDMap Pack() 99 public OSDMap Pack()
99 { 100 {
@@ -119,6 +120,19 @@ namespace OpenSim.Framework
119 if ((Throttles != null) && (Throttles.Length > 0)) 120 if ((Throttles != null) && (Throttles.Length > 0))
120 args["throttles"] = OSD.FromBinary(Throttles); 121 args["throttles"] = OSD.FromBinary(Throttles);
121 122
123 if (ChildrenCapSeeds != null && ChildrenCapSeeds.Count > 0)
124 {
125 OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
126 foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
127 {
128 OSDMap pair = new OSDMap();
129 pair["handle"] = OSD.FromString(kvp.Key.ToString());
130 pair["seed"] = OSD.FromString(kvp.Value);
131 childrenSeeds.Add(pair);
132 }
133 args["children_seeds"] = childrenSeeds;
134 }
135
122 return args; 136 return args;
123 } 137 }
124 138
@@ -165,6 +179,30 @@ namespace OpenSim.Framework
165 179
166 if (args["throttles"] != null) 180 if (args["throttles"] != null)
167 Throttles = args["throttles"].AsBinary(); 181 Throttles = args["throttles"].AsBinary();
182
183 if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
184 (args["children_seeds"].Type == OSDType.Array))
185 {
186 OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
187 ChildrenCapSeeds = new Dictionary<ulong, string>();
188 foreach (OSD o in childrenSeeds)
189 {
190 if (o.Type == OSDType.Map)
191 {
192 ulong handle = 0;
193 string seed = "";
194 OSDMap pair = (OSDMap)o;
195 if (pair["handle"] != null)
196 if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
197 continue;
198 if (pair["seed"] != null)
199 seed = pair["seed"].AsString();
200 if (!ChildrenCapSeeds.ContainsKey(handle))
201 ChildrenCapSeeds.Add(handle, seed);
202 }
203 }
204 }
205
168 } 206 }
169 207
170 /// <summary> 208 /// <summary>
@@ -317,9 +355,11 @@ namespace OpenSim.Framework
317 public UUID ActiveGroupID; 355 public UUID ActiveGroupID;
318 356
319 public AgentGroupData[] Groups; 357 public AgentGroupData[] Groups;
358 public Dictionary<ulong, string> ChildrenCapSeeds = null;
320 public Animation[] Anims; 359 public Animation[] Anims;
321 public Animation DefaultAnim = null; 360 public Animation DefaultAnim = null;
322 public Animation AnimState = null; 361 public Animation AnimState = null;
362 public Byte MotionState = 0;
323 363
324 public UUID GranterID; 364 public UUID GranterID;
325 public UUID ParentPart; 365 public UUID ParentPart;
@@ -349,6 +389,8 @@ namespace OpenSim.Framework
349 public List<ISceneObject> AttachmentObjects; 389 public List<ISceneObject> AttachmentObjects;
350 public List<string> AttachmentObjectStates; 390 public List<string> AttachmentObjectStates;
351 391
392 public Dictionary<string, UUID> MovementAnimationOverRides = new Dictionary<string, UUID>();
393
352 public virtual OSDMap Pack() 394 public virtual OSDMap Pack()
353 { 395 {
354// m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data"); 396// m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
@@ -399,6 +441,19 @@ namespace OpenSim.Framework
399 args["groups"] = groups; 441 args["groups"] = groups;
400 } 442 }
401 443
444 if (ChildrenCapSeeds != null && ChildrenCapSeeds.Count > 0)
445 {
446 OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
447 foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
448 {
449 OSDMap pair = new OSDMap();
450 pair["handle"] = OSD.FromString(kvp.Key.ToString());
451 pair["seed"] = OSD.FromString(kvp.Value);
452 childrenSeeds.Add(pair);
453 }
454 args["children_seeds"] = childrenSeeds;
455 }
456
402 if ((Anims != null) && (Anims.Length > 0)) 457 if ((Anims != null) && (Anims.Length > 0))
403 { 458 {
404 OSDArray anims = new OSDArray(Anims.Length); 459 OSDArray anims = new OSDArray(Anims.Length);
@@ -417,6 +472,26 @@ namespace OpenSim.Framework
417 args["animation_state"] = AnimState.PackUpdateMessage(); 472 args["animation_state"] = AnimState.PackUpdateMessage();
418 } 473 }
419 474
475 if (MovementAnimationOverRides.Count > 0)
476 {
477 OSDArray AOs = new OSDArray(MovementAnimationOverRides.Count);
478 {
479 foreach (KeyValuePair<string, UUID> kvp in MovementAnimationOverRides)
480 {
481 OSDMap ao = new OSDMap(2);
482 ao["state"] = OSD.FromString(kvp.Key);
483 ao["uuid"] = OSD.FromUUID(kvp.Value);
484 AOs.Add(ao);
485 }
486 }
487 args["movementAO"] = AOs;
488 }
489
490 if (MotionState != 0)
491 {
492 args["motion_state"] = OSD.FromInteger(MotionState);
493 }
494
420 if (Appearance != null) 495 if (Appearance != null)
421 args["packed_appearance"] = Appearance.Pack(); 496 args["packed_appearance"] = Appearance.Pack();
422 497
@@ -431,6 +506,8 @@ namespace OpenSim.Framework
431 // The code to pack textures, visuals, wearables and attachments 506 // The code to pack textures, visuals, wearables and attachments
432 // should be removed; packed appearance contains the full appearance 507 // should be removed; packed appearance contains the full appearance
433 // This is retained for backward compatibility only 508 // This is retained for backward compatibility only
509
510/* then lets remove
434 if (Appearance.Texture != null) 511 if (Appearance.Texture != null)
435 { 512 {
436 byte[] rawtextures = Appearance.Texture.GetBytes(); 513 byte[] rawtextures = Appearance.Texture.GetBytes();
@@ -459,7 +536,7 @@ namespace OpenSim.Framework
459 args["attachments"] = attachs; 536 args["attachments"] = attachs;
460 } 537 }
461 // End of code to remove 538 // End of code to remove
462 539*/
463 if ((Controllers != null) && (Controllers.Length > 0)) 540 if ((Controllers != null) && (Controllers.Length > 0))
464 { 541 {
465 OSDArray controls = new OSDArray(Controllers.Length); 542 OSDArray controls = new OSDArray(Controllers.Length);
@@ -600,6 +677,29 @@ namespace OpenSim.Framework
600 } 677 }
601 } 678 }
602 679
680 if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
681 (args["children_seeds"].Type == OSDType.Array))
682 {
683 OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
684 ChildrenCapSeeds = new Dictionary<ulong, string>();
685 foreach (OSD o in childrenSeeds)
686 {
687 if (o.Type == OSDType.Map)
688 {
689 ulong handle = 0;
690 string seed = "";
691 OSDMap pair = (OSDMap)o;
692 if (pair["handle"] != null)
693 if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
694 continue;
695 if (pair["seed"] != null)
696 seed = pair["seed"].AsString();
697 if (!ChildrenCapSeeds.ContainsKey(handle))
698 ChildrenCapSeeds.Add(handle, seed);
699 }
700 }
701 }
702
603 if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array) 703 if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
604 { 704 {
605 OSDArray anims = (OSDArray)(args["animations"]); 705 OSDArray anims = (OSDArray)(args["animations"]);
@@ -638,6 +738,28 @@ namespace OpenSim.Framework
638 } 738 }
639 } 739 }
640 740
741 MovementAnimationOverRides.Clear();
742
743 if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
744 {
745 OSDArray AOs = (OSDArray)(args["movementAO"]);
746 int count = AOs.Count;
747
748 for (int i = 0; i < count; i++)
749 {
750 OSDMap ao = (OSDMap)AOs[i];
751 if (ao["state"] != null && ao["uuid"] != null)
752 {
753 string state = ao["state"].AsString();
754 UUID id = ao["uuid"].AsUUID();
755 MovementAnimationOverRides[state] = id;
756 }
757 }
758 }
759
760 if (args.ContainsKey("motion_state"))
761 MotionState = (byte)args["motion_state"].AsInteger();
762
641 //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array) 763 //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
642 //{ 764 //{
643 // OSDArray textures = (OSDArray)(args["agent_textures"]); 765 // OSDArray textures = (OSDArray)(args["agent_textures"]);
@@ -647,53 +769,71 @@ namespace OpenSim.Framework
647 // AgentTextures[i++] = o.AsUUID(); 769 // AgentTextures[i++] = o.AsUUID();
648 //} 770 //}
649 771
650 Appearance = new AvatarAppearance();
651 772
652 // The code to unpack textures, visuals, wearables and attachments 773 // packed_appearence should contain all appearance information
653 // should be removed; packed appearance contains the full appearance 774 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
654 // This is retained for backward compatibility only
655 if (args["texture_entry"] != null)
656 { 775 {
657 byte[] rawtextures = args["texture_entry"].AsBinary(); 776 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
658 Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures,0,rawtextures.Length); 777 Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
659 Appearance.SetTextureEntries(textures);
660 } 778 }
779 else
780 {
781 // if missing try the old pack method
782 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");
661 783
662 if (args["visual_params"] != null) 784 Appearance = new AvatarAppearance();
663 Appearance.SetVisualParams(args["visual_params"].AsBinary());
664 785
665 if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array) 786 // The code to unpack textures, visuals, wearables and attachments
666 { 787 // should be removed; packed appearance contains the full appearance
667 OSDArray wears = (OSDArray)(args["wearables"]); 788 // This is retained for backward compatibility only
668 for (int i = 0; i < wears.Count / 2; i++) 789 if (args["texture_entry"] != null)
669 { 790 {
670 AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]); 791 byte[] rawtextures = args["texture_entry"].AsBinary();
671 Appearance.SetWearable(i,awear); 792 Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
793 Appearance.SetTextureEntries(textures);
672 } 794 }
673 }
674 795
675 if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) 796 if (args["visual_params"] != null)
676 { 797 Appearance.SetVisualParams(args["visual_params"].AsBinary());
677 OSDArray attachs = (OSDArray)(args["attachments"]); 798
678 foreach (OSD o in attachs) 799 if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
679 { 800 {
680 if (o.Type == OSDType.Map) 801 OSDArray wears = (OSDArray)(args["wearables"]);
802
803 int count = wears.Count;
804 if (count > AvatarWearable.MAX_WEARABLES)
805 count = AvatarWearable.MAX_WEARABLES;
806
807 for (int i = 0; i < count / 2; i++)
681 { 808 {
682 // We know all of these must end up as attachments so we 809 AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
683 // append rather than replace to ensure multiple attachments 810 Appearance.SetWearable(i, awear);
684 // per point continues to work
685// m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
686 Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
687 } 811 }
688 } 812 }
689 }
690 // end of code to remove
691 813
814 if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
815 {
816 OSDArray attachs = (OSDArray)(args["attachments"]);
817 foreach (OSD o in attachs)
818 {
819 if (o.Type == OSDType.Map)
820 {
821 // We know all of these must end up as attachments so we
822 // append rather than replace to ensure multiple attachments
823 // per point continues to work
824 // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
825 Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
826 }
827 }
828 }
829 // end of code to remove
830 }
831/* moved above
692 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map) 832 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
693 Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]); 833 Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
694 else 834 else
695 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance"); 835 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
696 836*/
697 if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) 837 if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
698 { 838 {
699 OSDArray controls = (OSDArray)(args["controllers"]); 839 OSDArray controls = (OSDArray)(args["controllers"]);
diff --git a/OpenSim/Framework/ColliderData.cs b/OpenSim/Framework/ColliderData.cs
index 1b7b682..00013e1 100644
--- a/OpenSim/Framework/ColliderData.cs
+++ b/OpenSim/Framework/ColliderData.cs
@@ -42,6 +42,7 @@ namespace OpenSim.Framework
42 public Vector3 velVector = Vector3.Zero; 42 public Vector3 velVector = Vector3.Zero;
43 public string nameStr = String.Empty; 43 public string nameStr = String.Empty;
44 public int colliderType = 0; 44 public int colliderType = 0;
45 public int linkNumber;
45 } 46 }
46 47
47 public class ColliderArgs : EventArgs 48 public class ColliderArgs : EventArgs
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs
index 6f517b6..4403f40 100644
--- a/OpenSim/Framework/Communications/RestClient.cs
+++ b/OpenSim/Framework/Communications/RestClient.cs
@@ -389,9 +389,32 @@ namespace OpenSim.Framework.Communications
389 } 389 }
390 } 390 }
391 391
392 if (_response != null)
393 _response.Close();
394
392 return null; 395 return null;
393 } 396 }
394 397
398<<<<<<< HEAD
399=======
400 using (Stream src = _response.GetResponseStream())
401 {
402 int length = src.Read(_readbuf, 0, BufferSize);
403 while (length > 0)
404 {
405 _resource.Write(_readbuf, 0, length);
406 length = src.Read(_readbuf, 0, BufferSize);
407 }
408 }
409
410 // TODO! Implement timeout, without killing the server
411 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
412 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
413
414// _allDone.WaitOne();
415 if (_response != null)
416 _response.Close();
417>>>>>>> avn/ubitvar
395 if (_asyncException != null) 418 if (_asyncException != null)
396 throw _asyncException; 419 throw _asyncException;
397 420
@@ -413,7 +436,7 @@ namespace OpenSim.Framework.Communications
413 _request = (HttpWebRequest) WebRequest.Create(buildUri()); 436 _request = (HttpWebRequest) WebRequest.Create(buildUri());
414 _request.KeepAlive = false; 437 _request.KeepAlive = false;
415 _request.ContentType = "application/xml"; 438 _request.ContentType = "application/xml";
416 _request.Timeout = 900000; 439 _request.Timeout = 30000;
417 _request.Method = RequestMethod; 440 _request.Method = RequestMethod;
418 _asyncException = null; 441 _asyncException = null;
419 _request.ContentLength = src.Length; 442 _request.ContentLength = src.Length;
@@ -421,6 +444,7 @@ namespace OpenSim.Framework.Communications
421 auth.AddAuthorization(_request.Headers); 444 auth.AddAuthorization(_request.Headers);
422 445
423 src.Seek(0, SeekOrigin.Begin); 446 src.Seek(0, SeekOrigin.Begin);
447<<<<<<< HEAD
424 448
425 int reqnum = WebUtil.RequestNumber++; 449 int reqnum = WebUtil.RequestNumber++;
426 if (WebUtil.DebugLevel >= 3) 450 if (WebUtil.DebugLevel >= 3)
@@ -433,9 +457,22 @@ namespace OpenSim.Framework.Communications
433 byte[] buf = new byte[1024]; 457 byte[] buf = new byte[1024];
434 int length = src.Read(buf, 0, 1024); 458 int length = src.Read(buf, 0, 1024);
435 while (length > 0) 459 while (length > 0)
460=======
461 m_log.Info("[REST]: Seek is ok");
462
463 using (Stream dst = _request.GetRequestStream())
464>>>>>>> avn/ubitvar
436 { 465 {
437 dst.Write(buf, 0, length); 466 m_log.Info("[REST]: GetRequestStream is ok");
438 length = src.Read(buf, 0, 1024); 467
468 byte[] buf = new byte[1024];
469 int length = src.Read(buf, 0, 1024);
470 m_log.Info("[REST]: First Read is ok");
471 while (length > 0)
472 {
473 dst.Write(buf, 0, length);
474 length = src.Read(buf, 0, 1024);
475 }
439 } 476 }
440 477
441 try 478 try
@@ -470,6 +507,9 @@ namespace OpenSim.Framework.Communications
470 507
471 _response.Close(); 508 _response.Close();
472 509
510 if (_response != null)
511 _response.Close();
512
473// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); 513// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
474 514
475 // TODO! Implement timeout, without killing the server 515 // TODO! Implement timeout, without killing the server
@@ -519,4 +559,4 @@ namespace OpenSim.Framework.Communications
519 559
520 #endregion Async Invocation 560 #endregion Async Invocation
521 } 561 }
522} \ No newline at end of file 562}
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index 0f68afe..851fbed 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -83,7 +83,7 @@ namespace OpenSim.Framework.Console
83 = "To enter an argument that contains spaces, surround the argument with double quotes.\nFor example, show object name \"My long object name\"\n"; 83 = "To enter an argument that contains spaces, surround the argument with double quotes.\nFor example, show object name \"My long object name\"\n";
84 84
85 public const string ItemHelpText 85 public const string ItemHelpText
86= @"For more information, type 'help all' to get a list of all commands, 86= @"For more information, type 'help' to get a list of all commands,
87 or type help <item>' where <item> is one of the following:"; 87 or type help <item>' where <item> is one of the following:";
88 88
89 /// <value> 89 /// <value>
@@ -116,12 +116,14 @@ namespace OpenSim.Framework.Console
116 if (helpParts.Count == 0) 116 if (helpParts.Count == 0)
117 { 117 {
118 help.Add(GeneralHelpText); 118 help.Add(GeneralHelpText);
119 help.Add(ItemHelpText); 119 help.AddRange(CollectAllCommandsHelp());
120 help.AddRange(CollectModulesHelp(tree));
121 } 120 }
122 else if (helpParts.Count == 1 && helpParts[0] == "all") 121 else if (helpParts.Count == 1 && helpParts[0] == "categories")
123 { 122 {
124 help.AddRange(CollectAllCommandsHelp()); 123 help.Add(""); // Will become a newline.
124 help.Add(GeneralHelpText);
125 help.Add(ItemHelpText);
126 help.AddRange(CollectModulesHelp(tree));
125 } 127 }
126 else 128 else
127 { 129 {
@@ -145,8 +147,11 @@ namespace OpenSim.Framework.Console
145 { 147 {
146 foreach (List<CommandInfo> commands in m_modulesCommands.Values) 148 foreach (List<CommandInfo> commands in m_modulesCommands.Values)
147 { 149 {
148 var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help)); 150 foreach (CommandInfo c in commands)
149 help.AddRange(ourHelpText); 151 {
152 if (c.long_help != String.Empty)
153 help.Add(string.Format("{0} - {1}", c.help_text, c.long_help));
154 }
150 } 155 }
151 } 156 }
152 157
diff --git a/OpenSim/Framework/CustomTypes.cs b/OpenSim/Framework/CustomTypes.cs
new file mode 100644
index 0000000..d109c26
--- /dev/null
+++ b/OpenSim/Framework/CustomTypes.cs
@@ -0,0 +1,43 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace OpenSim.Framework
31{
32 public enum CustomAssetType : sbyte
33 {
34 CustomTypeBase = 0x60,
35 AnimationSet = 0x60,
36 }
37
38 public enum CustomInventoryType : sbyte
39 {
40 CustomTypeBase = 0x60,
41 AnimationSet = 0x60,
42 }
43}
diff --git a/OpenSim/Framework/EstateSettings.cs b/OpenSim/Framework/EstateSettings.cs
index 4df7860..3aec437 100644
--- a/OpenSim/Framework/EstateSettings.cs
+++ b/OpenSim/Framework/EstateSettings.cs
@@ -363,11 +363,30 @@ namespace OpenSim.Framework
363 return false; 363 return false;
364 } 364 }
365 365
366 public bool IsBanned(UUID avatarID) 366 public bool IsBanned(UUID avatarID, int userFlags)
367 { 367 {
368 foreach (EstateBan ban in l_EstateBans) 368 foreach (EstateBan ban in l_EstateBans)
369 if (ban.BannedUserID == avatarID) 369 if (ban.BannedUserID == avatarID)
370 return true; 370 return true;
371
372 if (!IsEstateManagerOrOwner(avatarID) && !HasAccess(avatarID))
373 {
374 if (DenyMinors)
375 {
376 if ((userFlags & 32) == 0)
377 {
378 return true;
379 }
380 }
381 if (DenyAnonymous)
382 {
383 if ((userFlags & 4) == 0)
384 {
385 return true;
386 }
387 }
388 }
389
371 return false; 390 return false;
372 } 391 }
373 392
@@ -375,7 +394,7 @@ namespace OpenSim.Framework
375 { 394 {
376 if (ban == null) 395 if (ban == null)
377 return; 396 return;
378 if (!IsBanned(ban.BannedUserID)) 397 if (!IsBanned(ban.BannedUserID, 32)) //Ignore age-based bans
379 l_EstateBans.Add(ban); 398 l_EstateBans.Add(ban);
380 } 399 }
381 400
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index e36edb2..f5fd5f5 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -64,14 +64,15 @@ namespace OpenSim.Framework
64 64
65 public delegate void NetworkStats(int inPackets, int outPackets, int unAckedBytes); 65 public delegate void NetworkStats(int inPackets, int outPackets, int unAckedBytes);
66 66
67 public delegate void CachedTextureRequest(IClientAPI remoteClient, int serial, List<CachedTextureRequestArg> cachedTextureRequest);
68
69 public delegate void SetAppearance(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 AvSize, WearableCacheItem[] CacheItems); 67 public delegate void SetAppearance(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 AvSize, WearableCacheItem[] CacheItems);
68 public delegate void CachedTextureRequest(IClientAPI remoteClient, int serial, List<CachedTextureRequestArg> cachedTextureRequest);
70 69
71 public delegate void StartAnim(IClientAPI remoteClient, UUID animID); 70 public delegate void StartAnim(IClientAPI remoteClient, UUID animID);
72 71
73 public delegate void StopAnim(IClientAPI remoteClient, UUID animID); 72 public delegate void StopAnim(IClientAPI remoteClient, UUID animID);
74 73
74 public delegate void ChangeAnim(UUID animID, bool addOrRemove, bool sendPack);
75
75 public delegate void LinkObjects(IClientAPI remoteClient, uint parent, List<uint> children); 76 public delegate void LinkObjects(IClientAPI remoteClient, uint parent, List<uint> children);
76 77
77 public delegate void DelinkObjects(List<uint> primIds, IClientAPI client); 78 public delegate void DelinkObjects(List<uint> primIds, IClientAPI client);
@@ -132,6 +133,8 @@ namespace OpenSim.Framework
132 133
133 public delegate void UpdateVector(uint localID, Vector3 pos, IClientAPI remoteClient); 134 public delegate void UpdateVector(uint localID, Vector3 pos, IClientAPI remoteClient);
134 135
136 public delegate void ClientChangeObject(uint localID, object data ,IClientAPI remoteClient);
137
135 public delegate void UpdatePrimRotation(uint localID, Quaternion rot, IClientAPI remoteClient); 138 public delegate void UpdatePrimRotation(uint localID, Quaternion rot, IClientAPI remoteClient);
136 139
137 public delegate void UpdatePrimSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient); 140 public delegate void UpdatePrimSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient);
@@ -268,6 +271,9 @@ namespace OpenSim.Framework
268 public delegate void MoveInventoryItem( 271 public delegate void MoveInventoryItem(
269 IClientAPI remoteClient, List<InventoryItemBase> items); 272 IClientAPI remoteClient, List<InventoryItemBase> items);
270 273
274 public delegate void MoveItemsAndLeaveCopy(
275 IClientAPI remoteClient, List<InventoryItemBase> items, UUID destFolder);
276
271 public delegate void RemoveInventoryItem( 277 public delegate void RemoveInventoryItem(
272 IClientAPI remoteClient, List<UUID> itemIDs); 278 IClientAPI remoteClient, List<UUID> itemIDs);
273 279
@@ -443,6 +449,7 @@ namespace OpenSim.Framework
443 public delegate void ClassifiedInfoRequest(UUID classifiedID, IClientAPI client); 449 public delegate void ClassifiedInfoRequest(UUID classifiedID, IClientAPI client);
444 public delegate void ClassifiedInfoUpdate(UUID classifiedID, uint category, string name, string description, UUID parcelID, uint parentEstate, UUID snapshotID, Vector3 globalPos, byte classifiedFlags, int price, IClientAPI client); 450 public delegate void ClassifiedInfoUpdate(UUID classifiedID, uint category, string name, string description, UUID parcelID, uint parentEstate, UUID snapshotID, Vector3 globalPos, byte classifiedFlags, int price, IClientAPI client);
445 public delegate void ClassifiedDelete(UUID classifiedID, IClientAPI client); 451 public delegate void ClassifiedDelete(UUID classifiedID, IClientAPI client);
452 public delegate void ClassifiedGodDelete(UUID classifiedID, UUID queryID, IClientAPI client);
446 453
447 public delegate void EventNotificationAddRequest(uint EventID, IClientAPI client); 454 public delegate void EventNotificationAddRequest(uint EventID, IClientAPI client);
448 public delegate void EventNotificationRemoveRequest(uint EventID, IClientAPI client); 455 public delegate void EventNotificationRemoveRequest(uint EventID, IClientAPI client);
@@ -465,9 +472,9 @@ namespace OpenSim.Framework
465 472
466 public delegate void AgentFOV(IClientAPI client, float verticalAngle); 473 public delegate void AgentFOV(IClientAPI client, float verticalAngle);
467 474
468 public delegate void MuteListEntryUpdate(IClientAPI client, UUID MuteID, string Name, int Flags,UUID AgentID); 475 public delegate void MuteListEntryUpdate(IClientAPI client, UUID MuteID, string Name, int type, uint flags);
469 476
470 public delegate void MuteListEntryRemove(IClientAPI client, UUID MuteID, string Name, UUID AgentID); 477 public delegate void MuteListEntryRemove(IClientAPI client, UUID MuteID, string Name);
471 478
472 public delegate void AvatarInterestReply(IClientAPI client,UUID target, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages); 479 public delegate void AvatarInterestReply(IClientAPI client,UUID target, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages);
473 480
@@ -505,6 +512,7 @@ namespace OpenSim.Framework
505 public delegate void SimWideDeletesDelegate(IClientAPI client,UUID agentID, int flags, UUID targetID); 512 public delegate void SimWideDeletesDelegate(IClientAPI client,UUID agentID, int flags, UUID targetID);
506 513
507 public delegate void SendPostcard(IClientAPI client); 514 public delegate void SendPostcard(IClientAPI client);
515 public delegate void ChangeInventoryItemFlags(IClientAPI client, UUID itemID, uint flags);
508 516
509 #endregion 517 #endregion
510 518
@@ -734,6 +742,8 @@ namespace OpenSim.Framework
734 742
735 IScene Scene { get; } 743 IScene Scene { get; }
736 744
745 List<uint> SelectedObjects { get; }
746
737 // [Obsolete("LLClientView Specific - Replace with ???")] 747 // [Obsolete("LLClientView Specific - Replace with ???")]
738 int NextAnimationSequenceNumber { get; } 748 int NextAnimationSequenceNumber { get; }
739 749
@@ -747,6 +757,8 @@ namespace OpenSim.Framework
747 /// </summary> 757 /// </summary>
748 bool IsActive { get; set; } 758 bool IsActive { get; set; }
749 759
760 int PingTimeMS { get; }
761
750 /// <summary> 762 /// <summary>
751 /// Set if the client is closing due to a logout request 763 /// Set if the client is closing due to a logout request
752 /// </summary> 764 /// </summary>
@@ -794,6 +806,7 @@ namespace OpenSim.Framework
794 event ObjectDrop OnObjectDrop; 806 event ObjectDrop OnObjectDrop;
795 event StartAnim OnStartAnim; 807 event StartAnim OnStartAnim;
796 event StopAnim OnStopAnim; 808 event StopAnim OnStopAnim;
809 event ChangeAnim OnChangeAnim;
797 event LinkObjects OnLinkObjects; 810 event LinkObjects OnLinkObjects;
798 event DelinkObjects OnDelinkObjects; 811 event DelinkObjects OnDelinkObjects;
799 event RequestMapBlocks OnRequestMapBlocks; 812 event RequestMapBlocks OnRequestMapBlocks;
@@ -860,6 +873,7 @@ namespace OpenSim.Framework
860 event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily; 873 event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
861 event UpdatePrimFlags OnUpdatePrimFlags; 874 event UpdatePrimFlags OnUpdatePrimFlags;
862 event UpdatePrimTexture OnUpdatePrimTexture; 875 event UpdatePrimTexture OnUpdatePrimTexture;
876 event ClientChangeObject onClientChangeObject;
863 event UpdateVector OnUpdatePrimGroupPosition; 877 event UpdateVector OnUpdatePrimGroupPosition;
864 event UpdateVector OnUpdatePrimSinglePosition; 878 event UpdateVector OnUpdatePrimSinglePosition;
865 event UpdatePrimRotation OnUpdatePrimGroupRotation; 879 event UpdatePrimRotation OnUpdatePrimGroupRotation;
@@ -884,6 +898,7 @@ namespace OpenSim.Framework
884 event RequestTaskInventory OnRequestTaskInventory; 898 event RequestTaskInventory OnRequestTaskInventory;
885 event UpdateInventoryItem OnUpdateInventoryItem; 899 event UpdateInventoryItem OnUpdateInventoryItem;
886 event CopyInventoryItem OnCopyInventoryItem; 900 event CopyInventoryItem OnCopyInventoryItem;
901 event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
887 event MoveInventoryItem OnMoveInventoryItem; 902 event MoveInventoryItem OnMoveInventoryItem;
888 event RemoveInventoryFolder OnRemoveInventoryFolder; 903 event RemoveInventoryFolder OnRemoveInventoryFolder;
889 event RemoveInventoryItem OnRemoveInventoryItem; 904 event RemoveInventoryItem OnRemoveInventoryItem;
@@ -1002,7 +1017,7 @@ namespace OpenSim.Framework
1002 event ClassifiedInfoRequest OnClassifiedInfoRequest; 1017 event ClassifiedInfoRequest OnClassifiedInfoRequest;
1003 event ClassifiedInfoUpdate OnClassifiedInfoUpdate; 1018 event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
1004 event ClassifiedDelete OnClassifiedDelete; 1019 event ClassifiedDelete OnClassifiedDelete;
1005 event ClassifiedDelete OnClassifiedGodDelete; 1020 event ClassifiedGodDelete OnClassifiedGodDelete;
1006 1021
1007 event EventNotificationAddRequest OnEventNotificationAddRequest; 1022 event EventNotificationAddRequest OnEventNotificationAddRequest;
1008 event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; 1023 event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
@@ -1041,11 +1056,12 @@ namespace OpenSim.Framework
1041 event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; 1056 event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
1042 event SimWideDeletesDelegate OnSimWideDeletes; 1057 event SimWideDeletesDelegate OnSimWideDeletes;
1043 event SendPostcard OnSendPostcard; 1058 event SendPostcard OnSendPostcard;
1059 event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
1044 event MuteListEntryUpdate OnUpdateMuteListEntry; 1060 event MuteListEntryUpdate OnUpdateMuteListEntry;
1045 event MuteListEntryRemove OnRemoveMuteListEntry; 1061 event MuteListEntryRemove OnRemoveMuteListEntry;
1046 event GodlikeMessage onGodlikeMessage; 1062 event GodlikeMessage onGodlikeMessage;
1047 event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 1063 event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
1048 1064 event GenericCall2 OnUpdateThrottles;
1049 /// <summary> 1065 /// <summary>
1050 /// Set the debug level at which packet output should be printed to console. 1066 /// Set the debug level at which packet output should be printed to console.
1051 /// </summary> 1067 /// </summary>
@@ -1066,7 +1082,7 @@ namespace OpenSim.Framework
1066 /// If true, attempts the close without checking active status. You do not want to try this except as a last 1082 /// If true, attempts the close without checking active status. You do not want to try this except as a last
1067 /// ditch attempt where Active == false but the ScenePresence still exists. 1083 /// ditch attempt where Active == false but the ScenePresence still exists.
1068 /// </param> 1084 /// </param>
1069 void Close(bool force); 1085 void Close(bool sendStop, bool force);
1070 1086
1071 void Kick(string message); 1087 void Kick(string message);
1072 1088
@@ -1102,6 +1118,8 @@ namespace OpenSim.Framework
1102 /// <param name="localID"></param> 1118 /// <param name="localID"></param>
1103 void SendKillObject(List<uint> localID); 1119 void SendKillObject(List<uint> localID);
1104 1120
1121 void SendPartFullUpdate(ISceneEntity ent, uint? parentID);
1122
1105 void SendAnimations(UUID[] animID, int[] seqs, UUID sourceAgentId, UUID[] objectIDs); 1123 void SendAnimations(UUID[] animID, int[] seqs, UUID sourceAgentId, UUID[] objectIDs);
1106 void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args); 1124 void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args);
1107 1125
@@ -1125,6 +1143,8 @@ namespace OpenSim.Framework
1125 void SendGenericMessage(string method, UUID invoice, List<string> message); 1143 void SendGenericMessage(string method, UUID invoice, List<string> message);
1126 void SendGenericMessage(string method, UUID invoice, List<byte[]> message); 1144 void SendGenericMessage(string method, UUID invoice, List<byte[]> message);
1127 1145
1146 bool CanSendLayerData();
1147
1128 void SendLayerData(float[] map); 1148 void SendLayerData(float[] map);
1129 void SendLayerData(int px, int py, float[] map); 1149 void SendLayerData(int px, int py, float[] map);
1130 1150
@@ -1168,6 +1188,10 @@ namespace OpenSim.Framework
1168 void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations); 1188 void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations);
1169 1189
1170 void SetChildAgentThrottle(byte[] throttle); 1190 void SetChildAgentThrottle(byte[] throttle);
1191 void SetChildAgentThrottle(byte[] throttle,float factor);
1192
1193 void SetAgentThrottleSilent(int throttle, int setting);
1194 int GetAgentThrottleSilent(int throttle);
1171 1195
1172 void SendAvatarDataImmediate(ISceneEntity avatar); 1196 void SendAvatarDataImmediate(ISceneEntity avatar);
1173 1197
@@ -1192,6 +1216,7 @@ namespace OpenSim.Framework
1192 /// </summary> 1216 /// </summary>
1193 /// <param name="Item"></param> 1217 /// <param name="Item"></param>
1194 void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId); 1218 void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId);
1219 void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId);
1195 1220
1196 void SendRemoveInventoryItem(UUID itemID); 1221 void SendRemoveInventoryItem(UUID itemID);
1197 1222
@@ -1211,7 +1236,7 @@ namespace OpenSim.Framework
1211 /// <param name="node"></param> 1236 /// <param name="node"></param>
1212 void SendBulkUpdateInventory(InventoryNodeBase node); 1237 void SendBulkUpdateInventory(InventoryNodeBase node);
1213 1238
1214 void SendXferPacket(ulong xferID, uint packet, byte[] data); 1239 void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory);
1215 1240
1216 void SendAbortXferPacket(ulong xferID); 1241 void SendAbortXferPacket(ulong xferID);
1217 1242
diff --git a/OpenSim/Framework/ILandChannel.cs b/OpenSim/Framework/ILandChannel.cs
index c46c03c..63cc7eb 100644
--- a/OpenSim/Framework/ILandChannel.cs
+++ b/OpenSim/Framework/ILandChannel.cs
@@ -93,5 +93,7 @@ namespace OpenSim.Region.Framework.Interfaces
93 93
94 void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id); 94 void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id);
95 void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id); 95 void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id);
96 void sendClientInitialLandInfo(IClientAPI remoteClient);
97
96 } 98 }
97} 99}
diff --git a/OpenSim/Framework/ILandObject.cs b/OpenSim/Framework/ILandObject.cs
index 8465c86..db1496c 100644
--- a/OpenSim/Framework/ILandObject.cs
+++ b/OpenSim/Framework/ILandObject.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Framework
68 void SendLandUpdateToAvatarsOverMe(); 68 void SendLandUpdateToAvatarsOverMe();
69 69
70 void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client); 70 void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client);
71 void UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client); 71 bool UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client, out bool snap_selection, out bool needOverlay);
72 bool IsEitherBannedOrRestricted(UUID avatar); 72 bool IsEitherBannedOrRestricted(UUID avatar);
73 bool IsBannedFromLand(UUID avatar); 73 bool IsBannedFromLand(UUID avatar);
74 bool CanBeOnThisLand(UUID avatar, float posHeight); 74 bool CanBeOnThisLand(UUID avatar, float posHeight);
diff --git a/OpenSim/Framework/IMoneyModule.cs b/OpenSim/Framework/IMoneyModule.cs
index 52f3e83..55c9613 100644
--- a/OpenSim/Framework/IMoneyModule.cs
+++ b/OpenSim/Framework/IMoneyModule.cs
@@ -33,7 +33,7 @@ namespace OpenSim.Framework
33 public interface IMoneyModule 33 public interface IMoneyModule
34 { 34 {
35 bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, 35 bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID,
36 int amount); 36 int amount, UUID txn, out string reason);
37 37
38 int GetBalance(UUID agentID); 38 int GetBalance(UUID agentID);
39 bool UploadCovered(UUID agentID, int amount); 39 bool UploadCovered(UUID agentID, int amount);
@@ -41,6 +41,7 @@ namespace OpenSim.Framework
41 void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type); 41 void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type);
42 void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type, string extraData); 42 void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type, string extraData);
43 void ApplyUploadCharge(UUID agentID, int amount, string text); 43 void ApplyUploadCharge(UUID agentID, int amount, string text);
44 void MoveMoney(UUID fromUser, UUID toUser, int amount, string text);
44 45
45 int UploadCharge { get; } 46 int UploadCharge { get; }
46 int GroupCreationCharge { get; } 47 int GroupCreationCharge { get; }
diff --git a/OpenSim/Framework/LandData.cs b/OpenSim/Framework/LandData.cs
index fc02f33..4fbbbc1 100644
--- a/OpenSim/Framework/LandData.cs
+++ b/OpenSim/Framework/LandData.cs
@@ -67,9 +67,9 @@ namespace OpenSim.Framework
67 67
68 private uint _flags = (uint)ParcelFlags.AllowFly | (uint)ParcelFlags.AllowLandmark | 68 private uint _flags = (uint)ParcelFlags.AllowFly | (uint)ParcelFlags.AllowLandmark |
69 (uint)ParcelFlags.AllowAPrimitiveEntry | 69 (uint)ParcelFlags.AllowAPrimitiveEntry |
70 (uint)ParcelFlags.AllowDeedToGroup | (uint)ParcelFlags.AllowTerraform | 70 (uint)ParcelFlags.AllowDeedToGroup |
71 (uint)ParcelFlags.CreateObjects | (uint)ParcelFlags.AllowOtherScripts | 71 (uint)ParcelFlags.CreateObjects | (uint)ParcelFlags.AllowOtherScripts |
72 (uint)ParcelFlags.SoundLocal | (uint)ParcelFlags.AllowVoiceChat; 72 (uint)ParcelFlags.AllowVoiceChat;
73 73
74 private byte _landingType = 0; 74 private byte _landingType = 0;
75 private string _name = "Your Parcel"; 75 private string _name = "Your Parcel";
@@ -99,6 +99,10 @@ namespace OpenSim.Framework
99 private bool _obscureMedia = false; 99 private bool _obscureMedia = false;
100 private float _dwell = 0; 100 private float _dwell = 0;
101 101
102 public bool SeeAVs { get; set; }
103 public bool AnyAVSounds { get; set; }
104 public bool GroupAVSounds { get; set; }
105
102 /// <summary> 106 /// <summary>
103 /// Traffic count of parcel 107 /// Traffic count of parcel
104 /// </summary> 108 /// </summary>
@@ -728,6 +732,9 @@ namespace OpenSim.Framework
728 public LandData() 732 public LandData()
729 { 733 {
730 _globalID = UUID.Random(); 734 _globalID = UUID.Random();
735 SeeAVs = true;
736 AnyAVSounds = true;
737 GroupAVSounds = true;
731 } 738 }
732 739
733 /// <summary> 740 /// <summary>
@@ -778,6 +785,9 @@ namespace OpenSim.Framework
778 landData._simwideArea = _simwideArea; 785 landData._simwideArea = _simwideArea;
779 landData._simwidePrims = _simwidePrims; 786 landData._simwidePrims = _simwidePrims;
780 landData._dwell = _dwell; 787 landData._dwell = _dwell;
788 landData.SeeAVs = SeeAVs;
789 landData.AnyAVSounds = AnyAVSounds;
790 landData.GroupAVSounds = GroupAVSounds;
781 791
782 landData._parcelAccessList.Clear(); 792 landData._parcelAccessList.Clear();
783 foreach (LandAccessEntry entry in _parcelAccessList) 793 foreach (LandAccessEntry entry in _parcelAccessList)
@@ -793,21 +803,21 @@ namespace OpenSim.Framework
793 return landData; 803 return landData;
794 } 804 }
795 805
796 public void ToXml(XmlWriter xmlWriter) 806// public void ToXml(XmlWriter xmlWriter)
797 { 807// {
798 serializer.Serialize(xmlWriter, this); 808// serializer.Serialize(xmlWriter, this);
799 } 809// }
800 810
801 /// <summary> 811 /// <summary>
802 /// Restore a LandData object from the serialized xml representation. 812 /// Restore a LandData object from the serialized xml representation.
803 /// </summary> 813 /// </summary>
804 /// <param name="xmlReader"></param> 814 /// <param name="xmlReader"></param>
805 /// <returns></returns> 815 /// <returns></returns>
806 public static LandData FromXml(XmlReader xmlReader) 816// public static LandData FromXml(XmlReader xmlReader)
807 { 817// {
808 LandData land = (LandData)serializer.Deserialize(xmlReader); 818// LandData land = (LandData)serializer.Deserialize(xmlReader);
809 819//
810 return land; 820// return land;
811 } 821// }
812 } 822 }
813} 823}
diff --git a/OpenSim/Framework/LandUpdateArgs.cs b/OpenSim/Framework/LandUpdateArgs.cs
index 7d6c4f2..a48b8bf 100644
--- a/OpenSim/Framework/LandUpdateArgs.cs
+++ b/OpenSim/Framework/LandUpdateArgs.cs
@@ -56,5 +56,8 @@ namespace OpenSim.Framework
56 public bool MediaLoop; 56 public bool MediaLoop;
57 public bool ObscureMusic; 57 public bool ObscureMusic;
58 public bool ObscureMedia; 58 public bool ObscureMedia;
59 public bool SeeAVs;
60 public bool AnyAVSounds;
61 public bool GroupAVSounds;
59 } 62 }
60} 63}
diff --git a/OpenSim/Framework/LocklessQueue.cs b/OpenSim/Framework/LocklessQueue.cs
index 84f887c..9bd9baf 100644
--- a/OpenSim/Framework/LocklessQueue.cs
+++ b/OpenSim/Framework/LocklessQueue.cs
@@ -29,7 +29,7 @@ using System.Threading;
29 29
30namespace OpenSim.Framework 30namespace OpenSim.Framework
31{ 31{
32 public sealed class LocklessQueue<T> 32 public class LocklessQueue<T>
33 { 33 {
34 private sealed class SingleLinkNode 34 private sealed class SingleLinkNode
35 { 35 {
@@ -41,7 +41,7 @@ namespace OpenSim.Framework
41 SingleLinkNode tail; 41 SingleLinkNode tail;
42 int count; 42 int count;
43 43
44 public int Count { get { return count; } } 44 public virtual int Count { get { return count; } }
45 45
46 public LocklessQueue() 46 public LocklessQueue()
47 { 47 {
@@ -76,7 +76,7 @@ namespace OpenSim.Framework
76 Interlocked.Increment(ref count); 76 Interlocked.Increment(ref count);
77 } 77 }
78 78
79 public bool Dequeue(out T item) 79 public virtual bool Dequeue(out T item)
80 { 80 {
81 item = default(T); 81 item = default(T);
82 SingleLinkNode oldHead = null; 82 SingleLinkNode oldHead = null;
@@ -136,4 +136,4 @@ namespace OpenSim.Framework
136 (object)Interlocked.CompareExchange<SingleLinkNode>(ref location, newValue, comparand); 136 (object)Interlocked.CompareExchange<SingleLinkNode>(ref location, newValue, comparand);
137 } 137 }
138 } 138 }
139} \ No newline at end of file 139}
diff --git a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs
index 20495f6..96536e8 100644
--- a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs
+++ b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs
@@ -43,7 +43,6 @@ namespace OpenSim.Framework.Monitoring
43 StringBuilder sb = new StringBuilder(Environment.NewLine); 43 StringBuilder sb = new StringBuilder(Environment.NewLine);
44 sb.Append("MEMORY STATISTICS"); 44 sb.Append("MEMORY STATISTICS");
45 sb.Append(Environment.NewLine); 45 sb.Append(Environment.NewLine);
46
47 sb.AppendFormat( 46 sb.AppendFormat(
48 "Heap allocated to OpenSim : {0} MB\n", 47 "Heap allocated to OpenSim : {0} MB\n",
49 Math.Round(GC.GetTotalMemory(false) / 1024.0 / 1024.0)); 48 Math.Round(GC.GetTotalMemory(false) / 1024.0 / 1024.0));
@@ -56,9 +55,23 @@ namespace OpenSim.Framework.Monitoring
56 "Average heap allocation rate: {0} MB/s\n", 55 "Average heap allocation rate: {0} MB/s\n",
57 Math.Round((MemoryWatchdog.AverageHeapAllocationRate * 1000) / 1024.0 / 1024, 3)); 56 Math.Round((MemoryWatchdog.AverageHeapAllocationRate * 1000) / 1024.0 / 1024, 3));
58 57
59 sb.AppendFormat( 58 Process myprocess = Process.GetCurrentProcess();
60 "Process memory : {0} MB\n", 59 if (!myprocess.HasExited)
61 Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024.0 / 1024.0)); 60 {
61 myprocess.Refresh();
62 sb.AppendFormat(
63 "Process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n",
64 Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024.0 / 1024.0),
65 Math.Round(Process.GetCurrentProcess().PagedMemorySize64 / 1024.0 / 1024.0),
66 Math.Round(Process.GetCurrentProcess().VirtualMemorySize64 / 1024.0 / 1024.0));
67 sb.AppendFormat(
68 "Peak process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n",
69 Math.Round(Process.GetCurrentProcess().PeakWorkingSet64 / 1024.0 / 1024.0),
70 Math.Round(Process.GetCurrentProcess().PeakPagedMemorySize64 / 1024.0 / 1024.0),
71 Math.Round(Process.GetCurrentProcess().PeakVirtualMemorySize64 / 1024.0 / 1024.0));
72 }
73 else
74 sb.Append("Process reported as Exited \n");
62 75
63 return sb.ToString(); 76 return sb.ToString();
64 } 77 }
diff --git a/OpenSim/Framework/Monitoring/ServerStatsCollector.cs b/OpenSim/Framework/Monitoring/ServerStatsCollector.cs
index 77315bb..be4a8b4 100644
--- a/OpenSim/Framework/Monitoring/ServerStatsCollector.cs
+++ b/OpenSim/Framework/Monitoring/ServerStatsCollector.cs
@@ -249,6 +249,49 @@ namespace OpenSim.Framework.Monitoring
249 (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); }); 249 (s) => { s.Value = Math.Round(MemoryWatchdog.LastHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
250 MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory, 250 MakeStat("AverageHeapAllocationRate", null, "MB/sec", ContainerMemory,
251 (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); }); 251 (s) => { s.Value = Math.Round(MemoryWatchdog.AverageHeapAllocationRate * 1000d / 1024d / 1024d, 3); });
252
253 MakeStat("ProcessResident", null, "MB", ContainerProcess,
254 (s) =>
255 {
256 Process myprocess = Process.GetCurrentProcess();
257 myprocess.Refresh();
258 s.Value = Math.Round(Process.GetCurrentProcess().WorkingSet64 / 1024.0 / 1024.0);
259 });
260 MakeStat("ProcessPaged", null, "MB", ContainerProcess,
261 (s) =>
262 {
263 Process myprocess = Process.GetCurrentProcess();
264 myprocess.Refresh();
265 s.Value = Math.Round(Process.GetCurrentProcess().PagedMemorySize64 / 1024.0 / 1024.0);
266 });
267 MakeStat("ProcessVirtual", null, "MB", ContainerProcess,
268 (s) =>
269 {
270 Process myprocess = Process.GetCurrentProcess();
271 myprocess.Refresh();
272 s.Value = Math.Round(Process.GetCurrentProcess().VirtualMemorySize64 / 1024.0 / 1024.0);
273 });
274 MakeStat("PeakProcessResident", null, "MB", ContainerProcess,
275 (s) =>
276 {
277 Process myprocess = Process.GetCurrentProcess();
278 myprocess.Refresh();
279 s.Value = Math.Round(Process.GetCurrentProcess().PeakWorkingSet64 / 1024.0 / 1024.0);
280 });
281 MakeStat("PeakProcessPaged", null, "MB", ContainerProcess,
282 (s) =>
283 {
284 Process myprocess = Process.GetCurrentProcess();
285 myprocess.Refresh();
286 s.Value = Math.Round(Process.GetCurrentProcess().PeakPagedMemorySize64 / 1024.0 / 1024.0);
287 });
288 MakeStat("PeakProcessVirtual", null, "MB", ContainerProcess,
289 (s) =>
290 {
291 Process myprocess = Process.GetCurrentProcess();
292 myprocess.Refresh();
293 s.Value = Math.Round(Process.GetCurrentProcess().PeakVirtualMemorySize64 / 1024.0 / 1024.0);
294 });
252 } 295 }
253 296
254 // Notes on performance counters: 297 // Notes on performance counters:
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index a7cb2a6..916fa53 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -239,6 +239,17 @@ namespace OpenSim.Framework.Monitoring
239 return sb.ToString(); 239 return sb.ToString();
240 } 240 }
241 241
242 public virtual OSDMap ToBriefOSDMap()
243 {
244 OSDMap ret = new OSDMap();
245
246 ret.Add("Value", OSD.FromReal(Value));
247
248 double lastChangeOverTime, averageChangeOverTime;
249
250 return ret;
251 }
252
242 public virtual OSDMap ToOSDMap() 253 public virtual OSDMap ToOSDMap()
243 { 254 {
244 OSDMap ret = new OSDMap(); 255 OSDMap ret = new OSDMap();
@@ -323,4 +334,4 @@ namespace OpenSim.Framework.Monitoring
323 } 334 }
324 } 335 }
325 } 336 }
326} \ No newline at end of file 337}
diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs
index 3136ee8..a167b55 100644
--- a/OpenSim/Framework/Monitoring/StatsManager.cs
+++ b/OpenSim/Framework/Monitoring/StatsManager.cs
@@ -283,7 +283,7 @@ namespace OpenSim.Framework.Monitoring
283 if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName)) 283 if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName))
284 continue; 284 continue;
285 285
286 statMap.Add(statName, theStats[statName].ToOSDMap()); 286 statMap.Add(statName, theStats[statName].ToBriefOSDMap());
287 } 287 }
288 288
289 contMap.Add(contName, statMap); 289 contMap.Add(contName, statMap);
@@ -305,6 +305,17 @@ namespace OpenSim.Framework.Monitoring
305 string pContainerName = StatsManager.AllSubCommand; 305 string pContainerName = StatsManager.AllSubCommand;
306 string pStatName = StatsManager.AllSubCommand; 306 string pStatName = StatsManager.AllSubCommand;
307 307
308 if (!request.ContainsKey("pass") || request["pass"].ToString() != "l0st4nge1s")
309 {
310 responsedata["int_response_code"] = response_code;
311 responsedata["content_type"] = "text/plain";
312 responsedata["keepalive"] = false;
313 responsedata["str_response_string"] = "Access denied";
314 responsedata["access_control_allow_origin"] = "*";
315
316 return responsedata;
317 }
318
308 if (request.ContainsKey("cat")) pCategoryName = request["cat"].ToString(); 319 if (request.ContainsKey("cat")) pCategoryName = request["cat"].ToString();
309 if (request.ContainsKey("cont")) pContainerName = request["cat"].ToString(); 320 if (request.ContainsKey("cont")) pContainerName = request["cat"].ToString();
310 if (request.ContainsKey("stat")) pStatName = request["stat"].ToString(); 321 if (request.ContainsKey("stat")) pStatName = request["stat"].ToString();
@@ -554,4 +565,4 @@ namespace OpenSim.Framework.Monitoring
554 Debug, 565 Debug,
555 Info 566 Info
556 } 567 }
557} \ No newline at end of file 568}
diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs
index a644fa5..0cab427 100644
--- a/OpenSim/Framework/Monitoring/Watchdog.cs
+++ b/OpenSim/Framework/Monitoring/Watchdog.cs
@@ -377,4 +377,4 @@ namespace OpenSim.Framework.Monitoring
377 m_watchdogTimer.Start(); 377 m_watchdogTimer.Start();
378 } 378 }
379 } 379 }
380} \ No newline at end of file 380}
diff --git a/OpenSim/Framework/NetworkServersInfo.cs b/OpenSim/Framework/NetworkServersInfo.cs
index 4b7d4c7..dfe9695 100644
--- a/OpenSim/Framework/NetworkServersInfo.cs
+++ b/OpenSim/Framework/NetworkServersInfo.cs
@@ -41,6 +41,7 @@ namespace OpenSim.Framework
41 41
42 // "Out of band" managemnt https 42 // "Out of band" managemnt https
43 public bool ssl_listener = false; 43 public bool ssl_listener = false;
44 public bool ssl_external = false;
44 public uint https_port = 0; 45 public uint https_port = 0;
45 public string cert_path = String.Empty; 46 public string cert_path = String.Empty;
46 public string cert_pass = String.Empty; 47 public string cert_pass = String.Empty;
@@ -64,6 +65,7 @@ namespace OpenSim.Framework
64 65
65 // "Out of band management https" 66 // "Out of band management https"
66 ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false); 67 ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false);
68 ssl_external = config.Configs["Network"].GetBoolean("https_external",false);
67 if( ssl_listener) 69 if( ssl_listener)
68 { 70 {
69 cert_path = config.Configs["Network"].GetString("cert_path",String.Empty); 71 cert_path = config.Configs["Network"].GetString("cert_path",String.Empty);
diff --git a/OpenSim/Framework/OSChatMessage.cs b/OpenSim/Framework/OSChatMessage.cs
index 455756d..7450be2 100644
--- a/OpenSim/Framework/OSChatMessage.cs
+++ b/OpenSim/Framework/OSChatMessage.cs
@@ -51,12 +51,11 @@ namespace OpenSim.Framework
51 protected object m_senderObject; 51 protected object m_senderObject;
52 protected ChatTypeEnum m_type; 52 protected ChatTypeEnum m_type;
53 protected UUID m_fromID; 53 protected UUID m_fromID;
54 protected UUID m_toID; 54 protected UUID m_destination = UUID.Zero;
55 55
56 public OSChatMessage() 56 public OSChatMessage()
57 { 57 {
58 m_position = new Vector3(); 58 m_position = new Vector3();
59 m_toID = UUID.Zero;
60 } 59 }
61 60
62 /// <summary> 61 /// <summary>
@@ -104,15 +103,6 @@ namespace OpenSim.Framework
104 set { m_from = value; } 103 set { m_from = value; }
105 } 104 }
106 105
107 /// <summary>
108 /// The name of the sender (needed for scripts)
109 /// </summary>
110 public string To
111 {
112 get { return m_from; }
113 set { m_from = value; }
114 }
115
116 #region IEventArgs Members 106 #region IEventArgs Members
117 107
118 /// TODO: Sender and SenderObject should just be Sender and of 108 /// TODO: Sender and SenderObject should just be Sender and of
@@ -142,13 +132,10 @@ namespace OpenSim.Framework
142 set { m_fromID = value; } 132 set { m_fromID = value; }
143 } 133 }
144 134
145 /// <summary> 135 public UUID Destination
146 /// The single recipient or all if not set.
147 /// </summary>
148 public UUID TargetUUID
149 { 136 {
150 get { return m_toID; } 137 get { return m_destination; }
151 set { m_toID = value; } 138 set { m_destination = value; }
152 } 139 }
153 140
154 /// <summary> 141 /// <summary>
diff --git a/OpenSim/Framework/ObjectChangeData.cs b/OpenSim/Framework/ObjectChangeData.cs
new file mode 100644
index 0000000..8d56291
--- /dev/null
+++ b/OpenSim/Framework/ObjectChangeData.cs
@@ -0,0 +1,80 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29
30namespace OpenSim.Framework
31{
32 public enum ObjectChangeType : uint
33 {
34 // bits definitions
35 Position = 0x01,
36 Rotation = 0x02,
37 Scale = 0x04,
38 Group = 0x08,
39 UniformScale = 0x10,
40
41 // macros from above
42 // single prim
43 primP = 0x01,
44 primR = 0x02,
45 primPR = 0x03,
46 primS = 0x04,
47 primPS = 0x05,
48 primRS = 0x06,
49 primPSR = 0x07,
50
51 primUS = 0x14,
52 primPUS = 0x15,
53 primRUS = 0x16,
54 primPUSR = 0x17,
55
56 // group
57 groupP = 0x09,
58 groupR = 0x0A,
59 groupPR = 0x0B,
60 groupS = 0x0C,
61 groupPS = 0x0D,
62 groupRS = 0x0E,
63 groupPSR = 0x0F,
64
65 groupUS = 0x1C,
66 groupPUS = 0x1D,
67 groupRUS = 0x1E,
68 groupPUSR = 0x1F,
69
70 PRSmask = 0x07
71 }
72
73 public struct ObjectChangeData
74 {
75 public Quaternion rotation;
76 public Vector3 position;
77 public Vector3 scale;
78 public ObjectChangeType change;
79 }
80}
diff --git a/OpenSim/Framework/ParcelMediaCommandEnum.cs b/OpenSim/Framework/ParcelMediaCommandEnum.cs
index 93c41ec..e714382 100644
--- a/OpenSim/Framework/ParcelMediaCommandEnum.cs
+++ b/OpenSim/Framework/ParcelMediaCommandEnum.cs
@@ -27,7 +27,7 @@
27 27
28namespace OpenSim.Framework 28namespace OpenSim.Framework
29{ 29{
30 public enum ParcelMediaCommandEnum 30 public enum ParcelMediaCommandEnum : int
31 { 31 {
32 Stop = 0, 32 Stop = 0,
33 Pause = 1, 33 Pause = 1,
diff --git a/OpenSim/Framework/PermissionsUtil.cs b/OpenSim/Framework/PermissionsUtil.cs
index d785a78..5d3186d 100644
--- a/OpenSim/Framework/PermissionsUtil.cs
+++ b/OpenSim/Framework/PermissionsUtil.cs
@@ -72,8 +72,8 @@ namespace OpenSim.Framework
72 /// <param name="mainPerms">The permissions variable to modify.</param> 72 /// <param name="mainPerms">The permissions variable to modify.</param>
73 public static void ApplyFoldedPermissions(uint foldedPerms, ref uint mainPerms) 73 public static void ApplyFoldedPermissions(uint foldedPerms, ref uint mainPerms)
74 { 74 {
75 if ((foldedPerms & 7) == 0) 75// if ((foldedPerms & 7) == 0)
76 return; // assume that if the folded permissions are 0 then this means that they weren't actually recorded 76// return; // assume that if the folded permissions are 0 then this means that they weren't actually recorded
77 77
78 if ((foldedPerms & ((uint)PermissionMask.Copy >> 13)) == 0) 78 if ((foldedPerms & ((uint)PermissionMask.Copy >> 13)) == 0)
79 mainPerms &= ~(uint)PermissionMask.Copy; 79 mainPerms &= ~(uint)PermissionMask.Copy;
diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs
index d12aa61..5fa27d6 100644
--- a/OpenSim/Framework/PluginLoader.cs
+++ b/OpenSim/Framework/PluginLoader.cs
@@ -245,6 +245,7 @@ namespace OpenSim.Framework
245 // occasionally seems to corrupt its addin cache 245 // occasionally seems to corrupt its addin cache
246 // Hence, as a temporary solution we'll remove it before each startup 246 // Hence, as a temporary solution we'll remove it before each startup
247 247
248<<<<<<< HEAD
248 try 249 try
249 { 250 {
250 if (Directory.Exists(dir + "/addin-db-000")) 251 if (Directory.Exists(dir + "/addin-db-000"))
@@ -252,6 +253,23 @@ namespace OpenSim.Framework
252 253
253 if (Directory.Exists(dir + "/addin-db-001")) 254 if (Directory.Exists(dir + "/addin-db-001"))
254 Directory.Delete(dir + "/addin-db-001", true); 255 Directory.Delete(dir + "/addin-db-001", true);
256=======
257 string customDir = Environment.GetEnvironmentVariable ("MONO_ADDINS_REGISTRY");
258 string v0 = "addin-db-000";
259 string v1 = "addin-db-001";
260 if (customDir != null && customDir != String.Empty)
261 {
262 v0 = Path.Combine(customDir, v0);
263 v1 = Path.Combine(customDir, v1);
264 }
265 try
266 {
267 if (Directory.Exists(v0))
268 Directory.Delete(v0, true);
269
270 if (Directory.Exists(v1))
271 Directory.Delete(v1, true);
272>>>>>>> avn/ubitvar
255 } 273 }
256 catch (IOException) 274 catch (IOException)
257 { 275 {
diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs
index c8a5376..6a12a45 100644
--- a/OpenSim/Framework/PrimitiveBaseShape.cs
+++ b/OpenSim/Framework/PrimitiveBaseShape.cs
@@ -728,7 +728,12 @@ namespace OpenSim.Framework
728 return _lightColorR; 728 return _lightColorR;
729 } 729 }
730 set { 730 set {
731 _lightColorR = value; 731 if (value < 0)
732 _lightColorR = 0;
733 else if (value > 1.0f)
734 _lightColorR = 1.0f;
735 else
736 _lightColorR = value;
732 } 737 }
733 } 738 }
734 739
@@ -737,7 +742,12 @@ namespace OpenSim.Framework
737 return _lightColorG; 742 return _lightColorG;
738 } 743 }
739 set { 744 set {
740 _lightColorG = value; 745 if (value < 0)
746 _lightColorG = 0;
747 else if (value > 1.0f)
748 _lightColorG = 1.0f;
749 else
750 _lightColorG = value;
741 } 751 }
742 } 752 }
743 753
@@ -746,7 +756,12 @@ namespace OpenSim.Framework
746 return _lightColorB; 756 return _lightColorB;
747 } 757 }
748 set { 758 set {
749 _lightColorB = value; 759 if (value < 0)
760 _lightColorB = 0;
761 else if (value > 1.0f)
762 _lightColorB = 1.0f;
763 else
764 _lightColorB = value;
750 } 765 }
751 } 766 }
752 767
@@ -755,7 +770,12 @@ namespace OpenSim.Framework
755 return _lightColorA; 770 return _lightColorA;
756 } 771 }
757 set { 772 set {
758 _lightColorA = value; 773 if (value < 0)
774 _lightColorA = 0;
775 else if (value > 1.0f)
776 _lightColorA = 1.0f;
777 else
778 _lightColorA = value;
759 } 779 }
760 } 780 }
761 781
@@ -869,6 +889,11 @@ namespace OpenSim.Framework
869 889
870 public ulong GetMeshKey(Vector3 size, float lod) 890 public ulong GetMeshKey(Vector3 size, float lod)
871 { 891 {
892 return GetMeshKey(size, lod, false);
893 }
894
895 public ulong GetMeshKey(Vector3 size, float lod, bool convex)
896 {
872 ulong hash = 5381; 897 ulong hash = 5381;
873 898
874 hash = djb2(hash, this.PathCurve); 899 hash = djb2(hash, this.PathCurve);
@@ -914,6 +939,9 @@ namespace OpenSim.Framework
914 hash = djb2(hash, scaleBytes[i]); 939 hash = djb2(hash, scaleBytes[i]);
915 } 940 }
916 941
942 if(convex)
943 hash = djb2(hash, 0xa5);
944
917 return hash; 945 return hash;
918 } 946 }
919 947
@@ -1417,7 +1445,7 @@ namespace OpenSim.Framework
1417 prim.Textures = this.Textures; 1445 prim.Textures = this.Textures;
1418 1446
1419 prim.Properties = new Primitive.ObjectProperties(); 1447 prim.Properties = new Primitive.ObjectProperties();
1420 prim.Properties.Name = "Primitive"; 1448 prim.Properties.Name = "Object";
1421 prim.Properties.Description = ""; 1449 prim.Properties.Description = "";
1422 prim.Properties.CreatorID = UUID.Zero; 1450 prim.Properties.CreatorID = UUID.Zero;
1423 prim.Properties.GroupID = UUID.Zero; 1451 prim.Properties.GroupID = UUID.Zero;
diff --git a/OpenSim/Framework/PriorityQueue.cs b/OpenSim/Framework/PriorityQueue.cs
index e7a7f7f..4f05f65 100644
--- a/OpenSim/Framework/PriorityQueue.cs
+++ b/OpenSim/Framework/PriorityQueue.cs
@@ -45,7 +45,8 @@ namespace OpenSim.Framework
45 /// <summary> 45 /// <summary>
46 /// Total number of queues (priorities) available 46 /// Total number of queues (priorities) available
47 /// </summary> 47 /// </summary>
48 public const uint NumberOfQueues = 12; 48
49 public const uint NumberOfQueues = 12; // includes immediate queues, m_queueCounts need to be set acording
49 50
50 /// <summary> 51 /// <summary>
51 /// Number of queuest (priorities) that are processed immediately 52 /// Number of queuest (priorities) that are processed immediately
@@ -60,7 +61,10 @@ namespace OpenSim.Framework
60 // each pass. weighted towards the higher priority queues 61 // each pass. weighted towards the higher priority queues
61 private uint m_nextQueue = 0; 62 private uint m_nextQueue = 0;
62 private uint m_countFromQueue = 0; 63 private uint m_countFromQueue = 0;
63 private uint[] m_queueCounts = { 8, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1 }; 64 // first queues are imediate, so no counts
65// private uint[] m_queueCounts = { 0, 0, 8, 4, 4, 2, 2, 2, 2, 1, 1, 1 };
66 private uint[] m_queueCounts = {0, 0, 8, 8, 5, 4, 3, 2, 1, 1, 1, 1};
67 // this is ava, ava, attach, <10m, 20,40,80,160m,320,640,1280, +
64 68
65 // next request is a counter of the number of updates queued, it provides 69 // next request is a counter of the number of updates queued, it provides
66 // a total ordering on the updates coming through the queue and is more 70 // a total ordering on the updates coming through the queue and is more
@@ -130,6 +134,21 @@ namespace OpenSim.Framework
130 return true; 134 return true;
131 } 135 }
132 136
137
138 public void Remove(List<uint> ids)
139 {
140 LookupItem lookup;
141
142 foreach (uint localid in ids)
143 {
144 if (m_lookupTable.TryGetValue(localid, out lookup))
145 {
146 lookup.Heap.Remove(lookup.Handle);
147 m_lookupTable.Remove(localid);
148 }
149 }
150 }
151
133 /// <summary> 152 /// <summary>
134 /// Remove an item from one of the queues. Specifically, it removes the 153 /// Remove an item from one of the queues. Specifically, it removes the
135 /// oldest item from the next queue in order to provide fair access to 154 /// oldest item from the next queue in order to provide fair access to
@@ -137,7 +156,7 @@ namespace OpenSim.Framework
137 /// </summary> 156 /// </summary>
138 public bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue) 157 public bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue)
139 { 158 {
140 // If there is anything in priority queue 0, return it first no 159 // If there is anything in imediate queues, return it first no
141 // matter what else. Breaks fairness. But very useful. 160 // matter what else. Breaks fairness. But very useful.
142 for (int iq = 0; iq < NumberOfImmediateQueues; iq++) 161 for (int iq = 0; iq < NumberOfImmediateQueues; iq++)
143 { 162 {
@@ -172,14 +191,13 @@ namespace OpenSim.Framework
172 } 191 }
173 192
174 // Find the next non-immediate queue with updates in it 193 // Find the next non-immediate queue with updates in it
175 for (int i = 0; i < NumberOfQueues; ++i) 194 for (uint i = NumberOfImmediateQueues; i < NumberOfQueues; ++i)
176 { 195 {
177 m_nextQueue = (uint)((m_nextQueue + 1) % NumberOfQueues); 196 m_nextQueue++;
178 m_countFromQueue = m_queueCounts[m_nextQueue]; 197 if(m_nextQueue >= NumberOfQueues)
198 m_nextQueue = NumberOfImmediateQueues;
179 199
180 // if this is one of the immediate queues, just skip it 200 m_countFromQueue = m_queueCounts[m_nextQueue];
181 if (m_nextQueue < NumberOfImmediateQueues)
182 continue;
183 201
184 if (m_heaps[m_nextQueue].Count > 0) 202 if (m_heaps[m_nextQueue].Count > 0)
185 { 203 {
@@ -189,7 +207,6 @@ namespace OpenSim.Framework
189 m_lookupTable.Remove(item.Value.Entity.LocalId); 207 m_lookupTable.Remove(item.Value.Entity.LocalId);
190 timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime); 208 timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
191 value = item.Value; 209 value = item.Value;
192
193 return true; 210 return true;
194 } 211 }
195 } 212 }
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs
index 79fbd96..d75a6cf 100644
--- a/OpenSim/Framework/RegionInfo.cs
+++ b/OpenSim/Framework/RegionInfo.cs
@@ -40,6 +40,7 @@ using OpenMetaverse.StructuredData;
40 40
41namespace OpenSim.Framework 41namespace OpenSim.Framework
42{ 42{
43 [Serializable]
43 public class RegionLightShareData : ICloneable 44 public class RegionLightShareData : ICloneable
44 { 45 {
45 public bool valid = false; 46 public bool valid = false;
@@ -101,6 +102,12 @@ namespace OpenSim.Framework
101 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 102 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
102 private static readonly string LogHeader = "[REGION INFO]"; 103 private static readonly string LogHeader = "[REGION INFO]";
103 104
105<<<<<<< HEAD
106=======
107 public bool commFailTF = false;
108 public ConfigurationMember configMember;
109 public string DataStore = String.Empty;
110>>>>>>> avn/ubitvar
104 public string RegionFile = String.Empty; 111 public string RegionFile = String.Empty;
105 public bool isSandbox = false; 112 public bool isSandbox = false;
106 public bool Persistent = true; 113 public bool Persistent = true;
@@ -527,7 +534,11 @@ namespace OpenSim.Framework
527 return null; 534 return null;
528 } 535 }
529 536
537<<<<<<< HEAD
530 private void SetExtraSetting(string key, string value) 538 private void SetExtraSetting(string key, string value)
539=======
540 public void SetExtraSetting(string key, string value)
541>>>>>>> avn/ubitvar
531 { 542 {
532 string keylower = key.ToLower(); 543 string keylower = key.ToLower();
533 m_extraSettings[keylower] = value; 544 m_extraSettings[keylower] = value;
@@ -823,7 +834,15 @@ namespace OpenSim.Framework
823 string location = String.Format("{0},{1}", RegionLocX, RegionLocY); 834 string location = String.Format("{0},{1}", RegionLocX, RegionLocY);
824 config.Set("Location", location); 835 config.Set("Location", location);
825 836
837<<<<<<< HEAD
826 if (RegionSizeX > 0) 838 if (RegionSizeX > 0)
839=======
840 if (DataStore != String.Empty)
841 config.Set("Datastore", DataStore);
842
843 if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
844 {
845>>>>>>> avn/ubitvar
827 config.Set("SizeX", RegionSizeX); 846 config.Set("SizeX", RegionSizeX);
828 847
829 if (RegionSizeY > 0) 848 if (RegionSizeY > 0)
@@ -901,6 +920,234 @@ namespace OpenSim.Framework
901 throw new Exception("Invalid file type for region persistence."); 920 throw new Exception("Invalid file type for region persistence.");
902 } 921 }
903 922
923<<<<<<< HEAD
924=======
925 public void loadConfigurationOptionsFromMe()
926 {
927 configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
928 "UUID of Region (Default is recommended, random UUID)",
929 RegionID.ToString(), true);
930 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
931 "Region Name", RegionName, true);
932
933 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
934 "Grid Location (X Axis)", RegionLocX.ToString(), true);
935 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
936 "Grid Location (Y Axis)", RegionLocY.ToString(), true);
937 configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
938 "Size of region in X dimension", RegionSizeX.ToString(), true);
939 configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
940 "Size of region in Y dimension", RegionSizeY.ToString(), true);
941 configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
942 "Size of region in Z dimension", RegionSizeZ.ToString(), true);
943
944 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
945 configMember.addConfigurationOption("internal_ip_address",
946 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
947 "Internal IP Address for incoming UDP client connections",
948 m_internalEndPoint.Address.ToString(),
949 true);
950 configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
951 "Internal IP Port for incoming UDP client connections",
952 m_internalEndPoint.Port.ToString(), true);
953 configMember.addConfigurationOption("allow_alternate_ports",
954 ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
955 "Allow sim to find alternate UDP ports when ports are in use?",
956 m_allow_alternate_ports.ToString(), true);
957 configMember.addConfigurationOption("external_host_name",
958 ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
959 "External Host Name", m_externalHostName, true);
960 configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
961 "Last Map UUID", lastMapUUID.ToString(), true);
962 configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
963 "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
964
965 configMember.addConfigurationOption("nonphysical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
966 "Minimum size for nonphysical prims", m_nonphysPrimMin.ToString(), true);
967
968 configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
969 "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
970
971 configMember.addConfigurationOption("physical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
972 "Minimum size for nonphysical prims", m_physPrimMin.ToString(), true);
973
974 configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
975 "Maximum size for physical prims", m_physPrimMax.ToString(), true);
976
977 configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
978 "Clamp prims to max size", m_clampPrimSize.ToString(), true);
979
980 configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
981 "Max objects this sim will hold", m_objectCapacity.ToString(), true);
982
983 configMember.addConfigurationOption("linkset_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
984 "Max prims an object will hold", m_linksetCapacity.ToString(), true);
985
986 configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
987 "Max avatars this sim will hold", m_agentCapacity.ToString(), true);
988
989 configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
990 "Scope ID for this region", ScopeID.ToString(), true);
991
992 configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
993 "Free form string describing the type of region", String.Empty, true);
994
995 configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
996 "UUID of a texture to use as the map for this region", m_maptileStaticUUID.ToString(), true);
997 }
998
999 public void loadConfigurationOptions()
1000 {
1001 configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
1002 "UUID of Region (Default is recommended, random UUID)",
1003 UUID.Random().ToString(), true);
1004 configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
1005 "Region Name", "OpenSim Test", false);
1006
1007 configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
1008 "Grid Location (X Axis)", "1000", false);
1009 configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
1010 "Grid Location (Y Axis)", "1000", false);
1011 configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
1012 "Size of region in X dimension", Constants.RegionSize.ToString(), false);
1013 configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
1014 "Size of region in Y dimension", Constants.RegionSize.ToString(), false);
1015 configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
1016 "Size of region in Z dimension", Constants.RegionHeight.ToString(), false);
1017
1018 //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
1019 configMember.addConfigurationOption("internal_ip_address",
1020 ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
1021 "Internal IP Address for incoming UDP client connections", "0.0.0.0",
1022 false);
1023 configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
1024 "Internal IP Port for incoming UDP client connections",
1025 ConfigSettings.DefaultRegionHttpPort.ToString(), false);
1026 configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
1027 "Allow sim to find alternate UDP ports when ports are in use?",
1028 "false", true);
1029 configMember.addConfigurationOption("external_host_name",
1030 ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
1031 "External Host Name", "127.0.0.1", false);
1032 configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
1033 "Last Map UUID", lastMapUUID.ToString(), true);
1034
1035 configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
1036 "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
1037
1038 configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
1039 "Maximum size for nonphysical prims", "0", true);
1040
1041 configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
1042 "Maximum size for physical prims", "0", true);
1043
1044 configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
1045 "Clamp prims to max size", "false", true);
1046
1047 configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
1048 "Max objects this sim will hold", "15000", true);
1049
1050 configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
1051 "Max avatars this sim will hold", "100", true);
1052
1053 configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
1054 "Scope ID for this region", UUID.Zero.ToString(), true);
1055
1056 configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
1057 "Region Type", String.Empty, true);
1058
1059 configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
1060 "UUID of a texture to use as the map for this region", String.Empty, true);
1061 }
1062
1063 public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
1064 {
1065 switch (configuration_key)
1066 {
1067 case "sim_UUID":
1068 RegionID = (UUID) configuration_result;
1069 originRegionID = (UUID) configuration_result;
1070 break;
1071 case "sim_name":
1072 RegionName = (string) configuration_result;
1073 break;
1074 case "sim_location_x":
1075 RegionLocX = (uint) configuration_result;
1076 break;
1077 case "sim_location_y":
1078 RegionLocY = (uint) configuration_result;
1079 break;
1080 case "sim_size_x":
1081 RegionSizeX = (uint) configuration_result;
1082 break;
1083 case "sim_size_y":
1084 RegionSizeY = (uint) configuration_result;
1085 break;
1086 case "sim_size_z":
1087 RegionSizeZ = (uint) configuration_result;
1088 break;
1089 case "datastore":
1090 DataStore = (string) configuration_result;
1091 break;
1092 case "internal_ip_address":
1093 IPAddress address = (IPAddress) configuration_result;
1094 m_internalEndPoint = new IPEndPoint(address, 0);
1095 break;
1096 case "internal_ip_port":
1097 m_internalEndPoint.Port = (int) configuration_result;
1098 break;
1099 case "allow_alternate_ports":
1100 m_allow_alternate_ports = (bool) configuration_result;
1101 break;
1102 case "external_host_name":
1103 if ((string) configuration_result != "SYSTEMIP")
1104 {
1105 m_externalHostName = (string) configuration_result;
1106 }
1107 else
1108 {
1109 m_externalHostName = Util.GetLocalHost().ToString();
1110 }
1111 break;
1112 case "lastmap_uuid":
1113 lastMapUUID = (UUID)configuration_result;
1114 break;
1115 case "lastmap_refresh":
1116 lastMapRefresh = (string)configuration_result;
1117 break;
1118 case "nonphysical_prim_max":
1119 m_nonphysPrimMax = (int)configuration_result;
1120 break;
1121 case "physical_prim_max":
1122 m_physPrimMax = (int)configuration_result;
1123 break;
1124 case "clamp_prim_size":
1125 m_clampPrimSize = (bool)configuration_result;
1126 break;
1127 case "object_capacity":
1128 m_objectCapacity = (int)configuration_result;
1129 break;
1130 case "linkset_capacity":
1131 m_linksetCapacity = (int)configuration_result;
1132 break;
1133 case "agent_capacity":
1134 m_agentCapacity = (int)configuration_result;
1135 break;
1136 case "scope_id":
1137 ScopeID = (UUID)configuration_result;
1138 break;
1139 case "region_type":
1140 m_regionType = (string)configuration_result;
1141 break;
1142 case "region_static_maptile":
1143 m_maptileStaticUUID = (UUID)configuration_result;
1144 break;
1145 }
1146
1147 return true;
1148 }
1149
1150>>>>>>> avn/ubitvar
904 public void SaveLastMapUUID(UUID mapUUID) 1151 public void SaveLastMapUUID(UUID mapUUID)
905 { 1152 {
906 lastMapUUID = mapUUID; 1153 lastMapUUID = mapUUID;
@@ -1004,5 +1251,28 @@ namespace OpenSim.Framework
1004 regionInfo.ServerURI = serverURI; 1251 regionInfo.ServerURI = serverURI;
1005 return regionInfo; 1252 return regionInfo;
1006 } 1253 }
1254
1255 public int getInternalEndPointPort()
1256 {
1257 return m_internalEndPoint.Port;
1258 }
1259
1260 public Dictionary<string, object> ToKeyValuePairs()
1261 {
1262 Dictionary<string, object> kvp = new Dictionary<string, object>();
1263 kvp["uuid"] = RegionID.ToString();
1264 kvp["locX"] = RegionLocX.ToString();
1265 kvp["locY"] = RegionLocY.ToString();
1266 kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
1267 kvp["external_port"] = ExternalEndPoint.Port.ToString();
1268 kvp["external_host_name"] = ExternalHostName;
1269 kvp["http_port"] = HttpPort.ToString();
1270 kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
1271 kvp["internal_port"] = InternalEndPoint.Port.ToString();
1272 kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
1273 kvp["server_uri"] = ServerURI;
1274
1275 return kvp;
1276 }
1007 } 1277 }
1008} 1278}
diff --git a/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
index f60bb12..487c087 100644
--- a/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
+++ b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
@@ -48,6 +48,9 @@ namespace OpenSim.Framework.RegionLoader.Web
48 48
49 public RegionInfo[] LoadRegions() 49 public RegionInfo[] LoadRegions()
50 { 50 {
51 int tries = 3;
52 int wait = 2000;
53
51 if (m_configSource == null) 54 if (m_configSource == null)
52 { 55 {
53 m_log.Error("[WEBLOADER]: Unable to load configuration source!"); 56 m_log.Error("[WEBLOADER]: Unable to load configuration source!");
@@ -66,34 +69,59 @@ namespace OpenSim.Framework.RegionLoader.Web
66 } 69 }
67 else 70 else
68 { 71 {
69 RegionInfo[] regionInfos = new RegionInfo[] {}; 72 while(tries > 0)
70 int regionCount = 0; 73 {
71 HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url); 74 RegionInfo[] regionInfos = new RegionInfo[] {};
72 webRequest.Timeout = 30000; //30 Second Timeout 75 int regionCount = 0;
73 m_log.DebugFormat("[WEBLOADER]: Sending download request to {0}", url); 76 HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url);
74 77 webRequest.Timeout = 30000; //30 Second Timeout
75 try 78 m_log.DebugFormat("[WEBLOADER]: Sending download request to {0}", url);
76 {
77 string xmlSource = String.Empty;
78
79 using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
80 {
81 m_log.Debug("[WEBLOADER]: Downloading region information...");
82 79
83 using (Stream s = webResponse.GetResponseStream()) 80 try
81 {
82 HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
83 m_log.Debug("[WEBLOADER]: Downloading region information...");
84 StreamReader reader = new StreamReader(webResponse.GetResponseStream());
85 string xmlSource = String.Empty;
86 string tempStr = reader.ReadLine();
87 while (tempStr != null)
88 {
89 xmlSource = xmlSource + tempStr;
90 tempStr = reader.ReadLine();
91 }
92 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
93 xmlSource.Length);
94 XmlDocument xmlDoc = new XmlDocument();
95 xmlDoc.LoadXml(xmlSource);
96 if (xmlDoc.FirstChild.Name == "Nini")
84 { 97 {
85 using (StreamReader reader = new StreamReader(s)) 98 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
86 { 99
87 string tempStr = reader.ReadLine(); 100 if (regionCount > 0)
88 while (tempStr != null) 101 {
89 { 102 regionInfos = new RegionInfo[regionCount];
90 xmlSource = xmlSource + tempStr; 103 int i;
91 tempStr = reader.ReadLine(); 104 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
92 } 105 {
93 } 106 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
94 } 107 regionInfos[i] =
95 } 108 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],false,m_configSource);
109 }
110 }
111 }
112 }
113 catch (WebException ex)
114 {
115 if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
116 {
117 if (!allowRegionless)
118 throw ex;
119 }
120 else
121 throw ex;
122 }
96 123
124<<<<<<< HEAD
97 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " + 125 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
98 xmlSource.Length); 126 xmlSource.Length);
99 XmlDocument xmlDoc = new XmlDocument(); 127 XmlDocument xmlDoc = new XmlDocument();
@@ -118,28 +146,22 @@ namespace OpenSim.Framework.RegionLoader.Web
118 catch (WebException ex) 146 catch (WebException ex)
119 { 147 {
120 using (HttpWebResponse response = (HttpWebResponse)ex.Response) 148 using (HttpWebResponse response = (HttpWebResponse)ex.Response)
149=======
150 if (regionCount > 0 | allowRegionless)
151 return regionInfos;
152
153 m_log.Debug("[WEBLOADER]: Request yielded no regions.");
154 tries--;
155 if (tries > 0)
156>>>>>>> avn/ubitvar
121 { 157 {
122 if (response.StatusCode == HttpStatusCode.NotFound) 158 m_log.Debug("[WEBLOADER]: Retrying");
123 { 159 System.Threading.Thread.Sleep(wait);
124 if (!allowRegionless)
125 throw ex;
126 }
127 else
128 {
129 throw ex;
130 }
131 } 160 }
132 } 161 }
133 162
134 if (regionCount > 0 | allowRegionless) 163 m_log.Error("[WEBLOADER]: No region configs were available.");
135 { 164 return null;
136 return regionInfos;
137 }
138 else
139 {
140 m_log.Error("[WEBLOADER]: No region configs were available.");
141 return null;
142 }
143 } 165 }
144 } 166 }
145 } 167 }
diff --git a/OpenSim/Framework/RegionSettings.cs b/OpenSim/Framework/RegionSettings.cs
index a895c40..dec01ea 100644
--- a/OpenSim/Framework/RegionSettings.cs
+++ b/OpenSim/Framework/RegionSettings.cs
@@ -482,6 +482,28 @@ namespace OpenSim.Framework
482 set { m_LoadedCreationID = value; } 482 set { m_LoadedCreationID = value; }
483 } 483 }
484 484
485 private bool m_GodBlockSearch = false;
486 public bool GodBlockSearch
487 {
488 get { return m_GodBlockSearch; }
489 set { m_GodBlockSearch = value; }
490 }
491
492 private bool m_Casino = false;
493 public bool Casino
494 {
495 get { return m_Casino; }
496 set { m_Casino = value; }
497 }
498
499 // Telehub support
500 private bool m_TelehubEnabled = false;
501 public bool HasTelehub
502 {
503 get { return m_TelehubEnabled; }
504 set { m_TelehubEnabled = value; }
505 }
506
485 /// <summary> 507 /// <summary>
486 /// Connected Telehub object 508 /// Connected Telehub object
487 /// </summary> 509 /// </summary>
@@ -520,4 +542,4 @@ namespace OpenSim.Framework
520 l_SpawnPoints.Clear(); 542 l_SpawnPoints.Clear();
521 } 543 }
522 } 544 }
523} \ No newline at end of file 545}
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 828a852..60702d4 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -65,8 +65,12 @@ namespace OpenSim.Framework.Servers
65 /// This will control a periodic log printout of the current 'show stats' (if they are active) for this 65 /// This will control a periodic log printout of the current 'show stats' (if they are active) for this
66 /// server. 66 /// server.
67 /// </summary> 67 /// </summary>
68<<<<<<< HEAD
68 private int m_periodDiagnosticTimerMS = 60 * 60 * 1000; 69 private int m_periodDiagnosticTimerMS = 60 * 60 * 1000;
69 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); 70 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
71=======
72// private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
73>>>>>>> avn/ubitvar
70 74
71 /// <summary> 75 /// <summary>
72 /// Random uuid for private data 76 /// Random uuid for private data
@@ -84,6 +88,11 @@ namespace OpenSim.Framework.Servers
84 // Random uuid for private data 88 // Random uuid for private data
85 m_osSecret = UUID.Random().ToString(); 89 m_osSecret = UUID.Random().ToString();
86 90
91<<<<<<< HEAD
92=======
93// m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
94// m_periodicDiagnosticsTimer.Enabled = true;
95>>>>>>> avn/ubitvar
87 } 96 }
88 97
89 /// <summary> 98 /// <summary>
@@ -146,14 +155,24 @@ namespace OpenSim.Framework.Servers
146 /// Performs initialisation of the scene, such as loading configuration from disk. 155 /// Performs initialisation of the scene, such as loading configuration from disk.
147 /// </summary> 156 /// </summary>
148 public virtual void Startup() 157 public virtual void Startup()
149 { 158 {
159 m_log.Info("[STARTUP]: Beginning startup processing");
160
161 m_log.Info("[STARTUP]: Careminster version: " + m_version + Environment.NewLine);
162 // clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and
163 // the clr version number doesn't match the project version number under Mono.
164 //m_log.Info("[STARTUP]: Virtual machine runtime version: " + Environment.Version + Environment.NewLine);
165 m_log.InfoFormat(
166 "[STARTUP]: Operating system version: {0}, .NET platform {1}, {2}-bit\n",
167 Environment.OSVersion, Environment.OSVersion.Platform, Util.Is64BitProcess() ? "64" : "32");
168
150 StartupSpecific(); 169 StartupSpecific();
151 170
152 TimeSpan timeTaken = DateTime.Now - m_startuptime; 171 TimeSpan timeTaken = DateTime.Now - m_startuptime;
153 172
154 MainConsole.Instance.OutputFormat( 173// MainConsole.Instance.OutputFormat(
155 "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.", 174// "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.",
156 timeTaken.Minutes, timeTaken.Seconds); 175// timeTaken.Minutes, timeTaken.Seconds);
157 } 176 }
158 177
159 public string osSecret 178 public string osSecret
@@ -175,4 +194,4 @@ namespace OpenSim.Framework.Servers
175 } 194 }
176 } 195 }
177 } 196 }
178} \ No newline at end of file 197}
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index f252bd5..616c673 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -403,6 +403,7 @@ namespace OpenSim.Framework.Servers.HttpServer
403 StreamReader reader = new StreamReader(requestStream, encoding); 403 StreamReader reader = new StreamReader(requestStream, encoding);
404 404
405 string requestBody = reader.ReadToEnd(); 405 string requestBody = reader.ReadToEnd();
406 reader.Close();
406 407
407 Hashtable keysvals = new Hashtable(); 408 Hashtable keysvals = new Hashtable();
408 Hashtable headervals = new Hashtable(); 409 Hashtable headervals = new Hashtable();
@@ -460,7 +461,7 @@ namespace OpenSim.Framework.Servers.HttpServer
460 } 461 }
461 462
462 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); 463 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
463 resp.ReuseContext = true; 464 resp.ReuseContext = false;
464 HandleRequest(req, resp); 465 HandleRequest(req, resp);
465 466
466 // !!!HACK ALERT!!! 467 // !!!HACK ALERT!!!
@@ -759,7 +760,7 @@ namespace OpenSim.Framework.Servers.HttpServer
759 // Every month or so this will wrap and give bad numbers, not really a problem 760 // Every month or so this will wrap and give bad numbers, not really a problem
760 // since its just for reporting 761 // since its just for reporting
761 int tickdiff = requestEndTick - requestStartTick; 762 int tickdiff = requestEndTick - requestStartTick;
762 if (tickdiff > 3000 && requestHandler != null && requestHandler.Name != "GetTexture") 763 if (tickdiff > 3000 && (requestHandler == null || requestHandler.Name == null || requestHandler.Name != "GetTexture"))
763 { 764 {
764 m_log.InfoFormat( 765 m_log.InfoFormat(
765 "[LOGHTTP] Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms", 766 "[LOGHTTP] Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms",
@@ -1024,6 +1025,19 @@ namespace OpenSim.Framework.Servers.HttpServer
1024 string responseString = String.Empty; 1025 string responseString = String.Empty;
1025 XmlRpcRequest xmlRprcRequest = null; 1026 XmlRpcRequest xmlRprcRequest = null;
1026 1027
1028 bool gridproxy = false;
1029 if (requestBody.Contains("encoding=\"utf-8"))
1030 {
1031 int channelindx = -1;
1032 int optionsindx = requestBody.IndexOf(">options<");
1033 if(optionsindx >0)
1034 {
1035 channelindx = requestBody.IndexOf(">channel<");
1036 if (optionsindx < channelindx)
1037 gridproxy = true;
1038 }
1039 }
1040
1027 try 1041 try
1028 { 1042 {
1029 xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody); 1043 xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
@@ -1081,6 +1095,8 @@ namespace OpenSim.Framework.Servers.HttpServer
1081 } 1095 }
1082 xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] 1096 xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
1083 1097
1098 if (gridproxy)
1099 xmlRprcRequest.Params.Add("gridproxy"); // Param[4]
1084 try 1100 try
1085 { 1101 {
1086 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); 1102 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
@@ -1732,10 +1748,40 @@ namespace OpenSim.Framework.Servers.HttpServer
1732 1748
1733 internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) 1749 internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response)
1734 { 1750 {
1735 //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); 1751 int responsecode;
1736 int responsecode = (int)responsedata["int_response_code"]; 1752 string responseString = String.Empty;
1737 string responseString = (string)responsedata["str_response_string"]; 1753 byte[] responseData = null;
1738 string contentType = (string)responsedata["content_type"]; 1754 string contentType;
1755
1756 if (responsedata == null)
1757 {
1758 responsecode = 500;
1759 responseString = "No response could be obtained";
1760 contentType = "text/plain";
1761 responsedata = new Hashtable();
1762 }
1763 else
1764 {
1765 try
1766 {
1767 //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
1768 responsecode = (int)responsedata["int_response_code"];
1769 if (responsedata["bin_response_data"] != null)
1770 responseData = (byte[])responsedata["bin_response_data"];
1771 else
1772 responseString = (string)responsedata["str_response_string"];
1773 contentType = (string)responsedata["content_type"];
1774 if (responseString == null)
1775 responseString = String.Empty;
1776 }
1777 catch
1778 {
1779 responsecode = 500;
1780 responseString = "No response could be obtained";
1781 contentType = "text/plain";
1782 responsedata = new Hashtable();
1783 }
1784 }
1739 1785
1740 if (responsedata.ContainsKey("error_status_text")) 1786 if (responsedata.ContainsKey("error_status_text"))
1741 { 1787 {
@@ -1780,25 +1826,40 @@ namespace OpenSim.Framework.Servers.HttpServer
1780 1826
1781 response.AddHeader("Content-Type", contentType); 1827 response.AddHeader("Content-Type", contentType);
1782 1828
1829 if (responsedata.ContainsKey("headers"))
1830 {
1831 Hashtable headerdata = (Hashtable)responsedata["headers"];
1832
1833 foreach (string header in headerdata.Keys)
1834 response.AddHeader(header, (string)headerdata[header]);
1835 }
1836
1783 byte[] buffer; 1837 byte[] buffer;
1784 1838
1785 if (!(contentType.Contains("image") 1839 if (responseData != null)
1786 || contentType.Contains("x-shockwave-flash")
1787 || contentType.Contains("application/x-oar")
1788 || contentType.Contains("application/vnd.ll.mesh")))
1789 { 1840 {
1790 // Text 1841 buffer = responseData;
1791 buffer = Encoding.UTF8.GetBytes(responseString);
1792 } 1842 }
1793 else 1843 else
1794 { 1844 {
1795 // Binary! 1845 if (!(contentType.Contains("image")
1796 buffer = Convert.FromBase64String(responseString); 1846 || contentType.Contains("x-shockwave-flash")
1797 } 1847 || contentType.Contains("application/x-oar")
1848 || contentType.Contains("application/vnd.ll.mesh")))
1849 {
1850 // Text
1851 buffer = Encoding.UTF8.GetBytes(responseString);
1852 }
1853 else
1854 {
1855 // Binary!
1856 buffer = Convert.FromBase64String(responseString);
1857 }
1798 1858
1799 response.SendChunked = false; 1859 response.SendChunked = false;
1800 response.ContentLength64 = buffer.Length; 1860 response.ContentLength64 = buffer.Length;
1801 response.ContentEncoding = Encoding.UTF8; 1861 response.ContentEncoding = Encoding.UTF8;
1862 }
1802 1863
1803 return buffer; 1864 return buffer;
1804 } 1865 }
@@ -1886,9 +1947,14 @@ namespace OpenSim.Framework.Servers.HttpServer
1886 m_httpListener2.Start(64); 1947 m_httpListener2.Start(64);
1887 1948
1888 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events 1949 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events
1950<<<<<<< HEAD
1889 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 3, 25000); 1951 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 3, 25000);
1890 PollServiceRequestManager.Start(); 1952 PollServiceRequestManager.Start();
1891 1953
1954=======
1955 m_PollServiceManager = new PollServiceRequestManager(this, 4, 25000);
1956 m_PollServiceManager.Start();
1957>>>>>>> avn/ubitvar
1892 HTTPDRunning = true; 1958 HTTPDRunning = true;
1893 1959
1894 //HttpListenerContext context; 1960 //HttpListenerContext context;
@@ -1937,7 +2003,9 @@ namespace OpenSim.Framework.Servers.HttpServer
1937 2003
1938 public void httpServerException(object source, Exception exception) 2004 public void httpServerException(object source, Exception exception)
1939 { 2005 {
1940 m_log.Error(String.Format("[BASE HTTP SERVER]: {0} had an exception: {1} ", source.ToString(), exception.Message), exception); 2006 if (source.ToString() == "HttpServer.HttpListener" && exception.ToString().StartsWith("Mono.Security.Protocol.Tls.TlsException"))
2007 return;
2008 m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString());
1941 /* 2009 /*
1942 if (HTTPDRunning)// && NotSocketErrors > 5) 2010 if (HTTPDRunning)// && NotSocketErrors > 5)
1943 { 2011 {
@@ -1984,6 +2052,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1984 2052
1985 public void RemoveHTTPHandler(string httpMethod, string path) 2053 public void RemoveHTTPHandler(string httpMethod, string path)
1986 { 2054 {
2055 if (path == null) return; // Caps module isn't loaded, tries to remove handler where path = null
1987 lock (m_HTTPHandlers) 2056 lock (m_HTTPHandlers)
1988 { 2057 {
1989 if (httpMethod != null && httpMethod.Length == 0) 2058 if (httpMethod != null && httpMethod.Length == 0)
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
index 9477100..3fd3bf7 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
@@ -52,7 +52,9 @@ namespace OpenSim.Framework.Servers.HttpServer
52 { 52 {
53 LongPoll = 0, 53 LongPoll = 0,
54 LslHttp = 1, 54 LslHttp = 1,
55 Inventory = 2 55 Inventory = 2,
56 Texture = 3,
57 Mesh = 4
56 } 58 }
57 59
58 public string Url { get; set; } 60 public string Url { get; set; }
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
index caf0e98..49cd110 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Text; 32using System.Text;
32using HttpServer; 33using HttpServer;
@@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer
44 public readonly IHttpRequest Request; 45 public readonly IHttpRequest Request;
45 public readonly int RequestTime; 46 public readonly int RequestTime;
46 public readonly UUID RequestID; 47 public readonly UUID RequestID;
48 public int contextHash;
49
50 private void GenContextHash()
51 {
52 Random rnd = new Random();
53 contextHash = 0;
54 if (Request.Headers["remote_addr"] != null)
55 contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16;
56 else
57 contextHash = rnd.Next() << 16;
58 if (Request.Headers["remote_port"] != null)
59 {
60 string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' });
61 contextHash += Int32.Parse(strPorts[0]);
62 }
63 else
64 contextHash += rnd.Next() & 0xffff;
65 }
47 66
48 public PollServiceHttpRequest( 67 public PollServiceHttpRequest(
49 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) 68 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
@@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer
53 Request = pRequest; 72 Request = pRequest;
54 RequestTime = System.Environment.TickCount; 73 RequestTime = System.Environment.TickCount;
55 RequestID = UUID.Random(); 74 RequestID = UUID.Random();
75 GenContextHash();
56 } 76 }
57 77
58 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) 78 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
@@ -65,6 +85,7 @@ namespace OpenSim.Framework.Servers.HttpServer
65 response.SendChunked = false; 85 response.SendChunked = false;
66 response.ContentLength64 = buffer.Length; 86 response.ContentLength64 = buffer.Length;
67 response.ContentEncoding = Encoding.UTF8; 87 response.ContentEncoding = Encoding.UTF8;
88 response.ReuseContext = false;
68 89
69 try 90 try
70 { 91 {
@@ -93,5 +114,44 @@ namespace OpenSim.Framework.Servers.HttpServer
93 PollServiceArgs.RequestsHandled++; 114 PollServiceArgs.RequestsHandled++;
94 } 115 }
95 } 116 }
117
118 internal void DoHTTPstop(BaseHttpServer server)
119 {
120 OSHttpResponse response
121 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);
122
123 response.SendChunked = false;
124 response.ContentLength64 = 0;
125 response.ContentEncoding = Encoding.UTF8;
126 response.ReuseContext = false;
127 response.KeepAlive = false;
128 response.SendChunked = false;
129 response.StatusCode = 503;
130
131 try
132 {
133 response.OutputStream.Flush();
134 response.Send();
135 }
136 catch (Exception e)
137 {
138 }
139 }
140 }
141
142 class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest>
143 {
144 public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2)
145 {
146 if (b1.contextHash != b2.contextHash)
147 return false;
148 bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext);
149 return b;
150 }
151
152 public int GetHashCode(PollServiceHttpRequest b2)
153 {
154 return (int)b2.contextHash;
155 }
96 } 156 }
97} \ No newline at end of file 157} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 28bba70..4ffe6e5 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -65,15 +65,25 @@ namespace OpenSim.Framework.Servers.HttpServer
65 65
66 private readonly BaseHttpServer m_server; 66 private readonly BaseHttpServer m_server;
67 67
68 private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext;
68 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); 69 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
69 private static List<PollServiceHttpRequest> m_longPollRequests = new List<PollServiceHttpRequest>(); 70 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
71 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
70 72
71 private uint m_WorkerThreadCount = 0; 73 private uint m_WorkerThreadCount = 0;
72 private Thread[] m_workerThreads; 74 private Thread[] m_workerThreads;
75 private Thread m_retrysThread;
73 76
77<<<<<<< HEAD
74 private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); 78 private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2);
75 79
76// private int m_timeout = 1000; // increase timeout 250; now use the event one 80// private int m_timeout = 1000; // increase timeout 250; now use the event one
81=======
82 private bool m_running = true;
83 private int slowCount = 0;
84
85 private SmartThreadPool m_threadPool;
86>>>>>>> avn/ubitvar
77 87
78 public PollServiceRequestManager( 88 public PollServiceRequestManager(
79 BaseHttpServer pSrv, bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout) 89 BaseHttpServer pSrv, bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout)
@@ -83,6 +93,7 @@ namespace OpenSim.Framework.Servers.HttpServer
83 m_WorkerThreadCount = pWorkerThreadCount; 93 m_WorkerThreadCount = pWorkerThreadCount;
84 m_workerThreads = new Thread[m_WorkerThreadCount]; 94 m_workerThreads = new Thread[m_WorkerThreadCount];
85 95
96<<<<<<< HEAD
86 StatsManager.RegisterStat( 97 StatsManager.RegisterStat(
87 new Stat( 98 new Stat(
88 "QueuedPollResponses", 99 "QueuedPollResponses",
@@ -108,10 +119,25 @@ namespace OpenSim.Framework.Servers.HttpServer
108 MeasuresOfInterest.AverageChangeOverTime, 119 MeasuresOfInterest.AverageChangeOverTime,
109 stat => stat.Value = ResponsesProcessed, 120 stat => stat.Value = ResponsesProcessed,
110 StatVerbosity.Debug)); 121 StatVerbosity.Debug));
122=======
123 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
124 m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
125
126 STPStartInfo startInfo = new STPStartInfo();
127 startInfo.IdleTimeout = 30000;
128 startInfo.MaxWorkerThreads = 15;
129 startInfo.MinWorkerThreads = 1;
130 startInfo.ThreadPriority = ThreadPriority.Normal;
131 startInfo.StartSuspended = true;
132 startInfo.ThreadPoolName = "PoolService";
133
134 m_threadPool = new SmartThreadPool(startInfo);
135>>>>>>> avn/ubitvar
111 } 136 }
112 137
113 public void Start() 138 public void Start()
114 { 139 {
140<<<<<<< HEAD
115 IsRunning = true; 141 IsRunning = true;
116 142
117 if (PerformResponsesAsync) 143 if (PerformResponsesAsync)
@@ -139,40 +165,100 @@ namespace OpenSim.Framework.Servers.HttpServer
139 null, 165 null,
140 1000 * 60 * 10); 166 1000 * 60 * 10);
141 } 167 }
168=======
169 m_threadPool.Start();
170 //startup worker threads
171 for (uint i = 0; i < m_WorkerThreadCount; i++)
172 {
173 m_workerThreads[i]
174 = Watchdog.StartThread(
175 PoolWorkerJob,
176 string.Format("PollServiceWorkerThread {0}:{1}", i, m_server.Port),
177 ThreadPriority.Normal,
178 false,
179 false,
180 null,
181 int.MaxValue);
182 }
183
184 m_retrysThread = Watchdog.StartThread(
185 this.CheckRetries,
186 string.Format("PollServiceWatcherThread:{0}", m_server.Port),
187 ThreadPriority.Normal,
188 false,
189 true,
190 null,
191 1000 * 60 * 10);
192>>>>>>> avn/ubitvar
142 } 193 }
143 194
144 private void ReQueueEvent(PollServiceHttpRequest req) 195 private void ReQueueEvent(PollServiceHttpRequest req)
145 { 196 {
146 if (IsRunning) 197 if (IsRunning)
147 { 198 {
148 // delay the enqueueing for 100ms. There's no need to have the event 199 lock (m_retryRequests)
149 // actively on the queue 200 m_retryRequests.Enqueue(req);
150 Timer t = new Timer(self => { 201 }
151 ((Timer)self).Dispose(); 202 }
152 m_requests.Enqueue(req);
153 });
154 203
155 t.Change(100, Timeout.Infinite); 204 public void Enqueue(PollServiceHttpRequest req)
205 {
206 lock (m_bycontext)
207 {
208 Queue<PollServiceHttpRequest> ctxQeueue;
209 if (m_bycontext.TryGetValue(req, out ctxQeueue))
210 {
211 ctxQeueue.Enqueue(req);
212 }
213 else
214 {
215 ctxQeueue = new Queue<PollServiceHttpRequest>();
216 m_bycontext[req] = ctxQeueue;
217 EnqueueInt(req);
218 }
219 }
220 }
156 221
222 public void byContextDequeue(PollServiceHttpRequest req)
223 {
224 Queue<PollServiceHttpRequest> ctxQeueue;
225 lock (m_bycontext)
226 {
227 if (m_bycontext.TryGetValue(req, out ctxQeueue))
228 {
229 if (ctxQeueue.Count > 0)
230 {
231 PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
232 EnqueueInt(newreq);
233 }
234 else
235 {
236 m_bycontext.Remove(req);
237 }
238 }
157 } 239 }
158 } 240 }
159 241
160 public void Enqueue(PollServiceHttpRequest req) 242
243 public void EnqueueInt(PollServiceHttpRequest req)
161 { 244 {
162 if (IsRunning) 245 if (IsRunning)
163 { 246 {
164 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) 247 if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll)
165 { 248 {
166 lock (m_longPollRequests) 249 m_requests.Enqueue(req);
167 m_longPollRequests.Add(req);
168 } 250 }
169 else 251 else
170 m_requests.Enqueue(req); 252 {
253 lock (m_slowRequests)
254 m_slowRequests.Enqueue(req);
255 }
171 } 256 }
172 } 257 }
173 258
174 private void CheckLongPollThreads() 259 private void CheckRetries()
175 { 260 {
261<<<<<<< HEAD
176 // The only purpose of this thread is to check the EQs for events. 262 // The only purpose of this thread is to check the EQs for events.
177 // If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests. 263 // If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests.
178 // If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests. 264 // If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests.
@@ -180,13 +266,15 @@ namespace OpenSim.Framework.Servers.HttpServer
180 // so if they aren't ready to be served by a worker thread (no events), they are placed 266 // so if they aren't ready to be served by a worker thread (no events), they are placed
181 // directly back in the "ready-to-serve" queue by the worker thread. 267 // directly back in the "ready-to-serve" queue by the worker thread.
182 while (IsRunning) 268 while (IsRunning)
269=======
270 while (m_running)
271>>>>>>> avn/ubitvar
183 { 272 {
184 Thread.Sleep(500); 273 Thread.Sleep(100); // let the world move .. back to faster rate
185 Watchdog.UpdateThread(); 274 Watchdog.UpdateThread();
186 275 lock (m_retryRequests)
187// List<PollServiceHttpRequest> not_ready = new List<PollServiceHttpRequest>();
188 lock (m_longPollRequests)
189 { 276 {
277<<<<<<< HEAD
190 if (m_longPollRequests.Count > 0 && IsRunning) 278 if (m_longPollRequests.Count > 0 && IsRunning)
191 { 279 {
192 List<PollServiceHttpRequest> ready = m_longPollRequests.FindAll(req => 280 List<PollServiceHttpRequest> ready = m_longPollRequests.FindAll(req =>
@@ -199,28 +287,67 @@ namespace OpenSim.Framework.Servers.HttpServer
199 m_requests.Enqueue(req); 287 m_requests.Enqueue(req);
200 m_longPollRequests.Remove(req); 288 m_longPollRequests.Remove(req);
201 }); 289 });
290=======
291 while (m_retryRequests.Count > 0 && m_running)
292 m_requests.Enqueue(m_retryRequests.Dequeue());
293 }
294 slowCount++;
295 if (slowCount >= 10)
296 {
297 slowCount = 0;
298>>>>>>> avn/ubitvar
202 299
300 lock (m_slowRequests)
301 {
302 while (m_slowRequests.Count > 0 && m_running)
303 m_requests.Enqueue(m_slowRequests.Dequeue());
203 } 304 }
204
205 } 305 }
206 } 306 }
207 } 307 }
208 308
209 public void Stop() 309 public void Stop()
210 { 310 {
311<<<<<<< HEAD
211 IsRunning = false; 312 IsRunning = false;
212// m_timeout = -10000; // cause all to expire 313// m_timeout = -10000; // cause all to expire
314=======
315 m_running = false;
316>>>>>>> avn/ubitvar
213 Thread.Sleep(1000); // let the world move 317 Thread.Sleep(1000); // let the world move
214 318
215 foreach (Thread t in m_workerThreads) 319 foreach (Thread t in m_workerThreads)
216 Watchdog.AbortThread(t.ManagedThreadId); 320 Watchdog.AbortThread(t.ManagedThreadId);
217 321
322 // any entry in m_bycontext should have a active request on the other queues
323 // so just delete contents to easy GC
324 foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values)
325 qu.Clear();
326 m_bycontext.Clear();
327
328 try
329 {
330 foreach (PollServiceHttpRequest req in m_retryRequests)
331 {
332 req.DoHTTPstop(m_server);
333 }
334 }
335 catch
336 {
337 }
338
218 PollServiceHttpRequest wreq; 339 PollServiceHttpRequest wreq;
340 m_retryRequests.Clear();
219 341
220 lock (m_longPollRequests) 342 lock (m_slowRequests)
221 { 343 {
344<<<<<<< HEAD
222 if (m_longPollRequests.Count > 0 && IsRunning) 345 if (m_longPollRequests.Count > 0 && IsRunning)
223 m_longPollRequests.ForEach(req => m_requests.Enqueue(req)); 346 m_longPollRequests.ForEach(req => m_requests.Enqueue(req));
347=======
348 while (m_slowRequests.Count > 0)
349 m_requests.Enqueue(m_slowRequests.Dequeue());
350>>>>>>> avn/ubitvar
224 } 351 }
225 352
226 while (m_requests.Count() > 0) 353 while (m_requests.Count() > 0)
@@ -228,16 +355,19 @@ namespace OpenSim.Framework.Servers.HttpServer
228 try 355 try
229 { 356 {
230 wreq = m_requests.Dequeue(0); 357 wreq = m_requests.Dequeue(0);
358<<<<<<< HEAD
231 ResponsesProcessed++; 359 ResponsesProcessed++;
232 wreq.DoHTTPGruntWork( 360 wreq.DoHTTPGruntWork(
233 m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id)); 361 m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id));
362=======
363 wreq.DoHTTPstop(m_server);
364>>>>>>> avn/ubitvar
234 } 365 }
235 catch 366 catch
236 { 367 {
237 } 368 }
238 } 369 }
239 370
240 m_longPollRequests.Clear();
241 m_requests.Clear(); 371 m_requests.Clear();
242 } 372 }
243 373
@@ -247,6 +377,11 @@ namespace OpenSim.Framework.Servers.HttpServer
247 { 377 {
248 while (IsRunning) 378 while (IsRunning)
249 { 379 {
380<<<<<<< HEAD
381=======
382 PollServiceHttpRequest req = m_requests.Dequeue(5000);
383
384>>>>>>> avn/ubitvar
250 Watchdog.UpdateThread(); 385 Watchdog.UpdateThread();
251 WaitPerformResponse(); 386 WaitPerformResponse();
252 } 387 }
@@ -265,6 +400,7 @@ namespace OpenSim.Framework.Servers.HttpServer
265 { 400 {
266 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); 401 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
267 402
403<<<<<<< HEAD
268 if (responsedata == null) 404 if (responsedata == null)
269 return; 405 return;
270 406
@@ -287,11 +423,15 @@ namespace OpenSim.Framework.Servers.HttpServer
287 else 423 else
288 { 424 {
289 m_threadPool.QueueWorkItem(x => 425 m_threadPool.QueueWorkItem(x =>
426=======
427 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue
428>>>>>>> avn/ubitvar
290 { 429 {
291 try 430 try
292 { 431 {
293 ResponsesProcessed++; 432 ResponsesProcessed++;
294 req.DoHTTPGruntWork(m_server, responsedata); 433 req.DoHTTPGruntWork(m_server, responsedata);
434 byContextDequeue(req);
295 } 435 }
296 catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream 436 catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
297 { 437 {
@@ -300,6 +440,7 @@ namespace OpenSim.Framework.Servers.HttpServer
300 } 440 }
301 catch (Exception e) 441 catch (Exception e)
302 { 442 {
443<<<<<<< HEAD
303 m_log.Error(e); 444 m_log.Error(e);
304 } 445 }
305 446
@@ -318,6 +459,34 @@ namespace OpenSim.Framework.Servers.HttpServer
318 else 459 else
319 { 460 {
320 ReQueueEvent(req); 461 ReQueueEvent(req);
462=======
463 try
464 {
465 req.DoHTTPGruntWork(m_server, responsedata);
466 byContextDequeue(req);
467 }
468 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
469 {
470 // Ignore it, no need to reply
471 }
472
473 return null;
474 }, null);
475 }
476 }
477 else
478 {
479 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
480 {
481 req.DoHTTPGruntWork(m_server,
482 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
483 byContextDequeue(req);
484 }
485 else
486 {
487 ReQueueEvent(req);
488 }
489>>>>>>> avn/ubitvar
321 } 490 }
322 } 491 }
323 } 492 }
@@ -327,5 +496,7 @@ namespace OpenSim.Framework.Servers.HttpServer
327 } 496 }
328 } 497 }
329 } 498 }
499
330 } 500 }
331} \ No newline at end of file 501}
502
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index e403ba0..35177f4 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -871,7 +871,7 @@ namespace OpenSim.Framework.Servers
871 } 871 }
872 } 872 }
873 873
874 protected string GetVersionText() 874 public string GetVersionText()
875 { 875 {
876 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion); 876 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
877 } 877 }
@@ -1044,4 +1044,4 @@ namespace OpenSim.Framework.Servers
1044 /// </summary> 1044 /// </summary>
1045 protected virtual void ShutdownSpecific() {} 1045 protected virtual void ShutdownSpecific() {}
1046 } 1046 }
1047} \ No newline at end of file 1047}
diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
index 5c0e0df..e13551c 100644
--- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
+++ b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
@@ -41,7 +41,331 @@ namespace OpenSim.Framework.Servers.Tests
41{ 41{
42 [TestFixture] 42 [TestFixture]
43 public class OSHttpTests : OpenSimTestCase 43 public class OSHttpTests : OpenSimTestCase
44<<<<<<< HEAD
44 { 45 {
46=======
47 {
48 // we need an IHttpClientContext for our tests
49 public class TestHttpClientContext: IHttpClientContext
50 {
51 private bool _secured;
52 public bool IsSecured
53 {
54 get { return _secured; }
55 }
56 public bool Secured
57 {
58 get { return _secured; }
59 }
60
61 public TestHttpClientContext(bool secured)
62 {
63 _secured = secured;
64 }
65
66 public void Disconnect(SocketError error) {}
67 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body) {}
68 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason) {}
69 public void Respond(string body) {}
70 public void Send(byte[] buffer) {}
71 public void Send(byte[] buffer, int offset, int size) {}
72 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType) {}
73 public void Close() { }
74 public bool EndWhenDone { get { return false;} set { return;}}
75
76 public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
77 {
78 return new HTTPNetworkContext();
79 }
80
81 public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
82 /// <summary>
83 /// A request have been received in the context.
84 /// </summary>
85 public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
86
87 public bool CanSend { get { return true; } }
88 public string RemoteEndPoint { get { return ""; } }
89 public string RemoteEndPointAddress { get { return ""; } }
90 public string RemoteEndPointPort { get { return ""; } }
91 }
92
93 public class TestHttpRequest: IHttpRequest
94 {
95 private string _uriPath;
96 public bool BodyIsComplete
97 {
98 get { return true; }
99 }
100 public string[] AcceptTypes
101 {
102 get {return _acceptTypes; }
103 }
104 private string[] _acceptTypes;
105 public Stream Body
106 {
107 get { return _body; }
108 set { _body = value;}
109 }
110 private Stream _body;
111 public ConnectionType Connection
112 {
113 get { return _connection; }
114 set { _connection = value; }
115 }
116 private ConnectionType _connection;
117 public int ContentLength
118 {
119 get { return _contentLength; }
120 set { _contentLength = value; }
121 }
122 private int _contentLength;
123 public NameValueCollection Headers
124 {
125 get { return _headers; }
126 }
127 private NameValueCollection _headers = new NameValueCollection();
128 public string HttpVersion
129 {
130 get { return _httpVersion; }
131 set { _httpVersion = value; }
132 }
133 private string _httpVersion = null;
134 public string Method
135 {
136 get { return _method; }
137 set { _method = value; }
138 }
139 private string _method = null;
140 public HttpInput QueryString
141 {
142 get { return _queryString; }
143 }
144 private HttpInput _queryString = null;
145 public Uri Uri
146 {
147 get { return _uri; }
148 set { _uri = value; }
149 }
150 private Uri _uri = null;
151 public string[] UriParts
152 {
153 get { return _uri.Segments; }
154 }
155 public HttpParam Param
156 {
157 get { return null; }
158 }
159 public HttpForm Form
160 {
161 get { return null; }
162 }
163 public bool IsAjax
164 {
165 get { return false; }
166 }
167 public RequestCookies Cookies
168 {
169 get { return null; }
170 }
171
172 public TestHttpRequest() {}
173
174 public TestHttpRequest(string contentEncoding, string contentType, string userAgent,
175 string remoteAddr, string remotePort, string[] acceptTypes,
176 ConnectionType connectionType, int contentLength, Uri uri)
177 {
178 _headers["content-encoding"] = contentEncoding;
179 _headers["content-type"] = contentType;
180 _headers["user-agent"] = userAgent;
181 _headers["remote_addr"] = remoteAddr;
182 _headers["remote_port"] = remotePort;
183
184 _acceptTypes = acceptTypes;
185 _connection = connectionType;
186 _contentLength = contentLength;
187 _uri = uri;
188 }
189
190 public void DecodeBody(FormDecoderProvider providers) {}
191 public void SetCookies(RequestCookies cookies) {}
192 public void AddHeader(string name, string value)
193 {
194 _headers.Add(name, value);
195 }
196 public int AddToBody(byte[] bytes, int offset, int length)
197 {
198 return 0;
199 }
200 public void Clear() {}
201
202 public object Clone()
203 {
204 TestHttpRequest clone = new TestHttpRequest();
205 clone._acceptTypes = _acceptTypes;
206 clone._connection = _connection;
207 clone._contentLength = _contentLength;
208 clone._uri = _uri;
209 clone._headers = new NameValueCollection(_headers);
210
211 return clone;
212 }
213 public IHttpResponse CreateResponse(IHttpClientContext context)
214 {
215 return new HttpResponse(context, this);
216 }
217 /// <summary>
218 /// Path and query (will be merged with the host header) and put in Uri
219 /// </summary>
220 /// <see cref="Uri"/>
221 public string UriPath
222 {
223 get { return _uriPath; }
224 set
225 {
226 _uriPath = value;
227
228 }
229 }
230
231 }
232
233 public class TestHttpResponse: IHttpResponse
234 {
235 public Stream Body
236 {
237 get { return _body; }
238
239 set { _body = value; }
240 }
241 private Stream _body;
242
243 public string ProtocolVersion
244 {
245 get { return _protocolVersion; }
246 set { _protocolVersion = value; }
247 }
248 private string _protocolVersion;
249
250 public bool Chunked
251 {
252 get { return _chunked; }
253
254 set { _chunked = value; }
255 }
256 private bool _chunked;
257
258 public ConnectionType Connection
259 {
260 get { return _connection; }
261
262 set { _connection = value; }
263 }
264 private ConnectionType _connection;
265
266 public Encoding Encoding
267 {
268 get { return _encoding; }
269
270 set { _encoding = value; }
271 }
272 private Encoding _encoding;
273
274 public int KeepAlive
275 {
276 get { return _keepAlive; }
277
278 set { _keepAlive = value; }
279 }
280 private int _keepAlive;
281
282 public HttpStatusCode Status
283 {
284 get { return _status; }
285
286 set { _status = value; }
287 }
288 private HttpStatusCode _status;
289
290 public string Reason
291 {
292 get { return _reason; }
293
294 set { _reason = value; }
295 }
296 private string _reason;
297
298 public long ContentLength
299 {
300 get { return _contentLength; }
301
302 set { _contentLength = value; }
303 }
304 private long _contentLength;
305
306 public string ContentType
307 {
308 get { return _contentType; }
309
310 set { _contentType = value; }
311 }
312 private string _contentType;
313
314 public bool HeadersSent
315 {
316 get { return _headersSent; }
317 }
318 private bool _headersSent;
319
320 public bool Sent
321 {
322 get { return _sent; }
323 }
324 private bool _sent;
325
326 public ResponseCookies Cookies
327 {
328 get { return _cookies; }
329 }
330 private ResponseCookies _cookies = null;
331
332 public TestHttpResponse()
333 {
334 _headersSent = false;
335 _sent = false;
336 }
337
338 public void AddHeader(string name, string value) {}
339 public void Send()
340 {
341 if (!_headersSent) SendHeaders();
342 if (_sent) throw new InvalidOperationException("stuff already sent");
343 _sent = true;
344 }
345
346 public void SendBody(byte[] buffer, int offset, int count)
347 {
348 if (!_headersSent) SendHeaders();
349 _sent = true;
350 }
351 public void SendBody(byte[] buffer)
352 {
353 if (!_headersSent) SendHeaders();
354 _sent = true;
355 }
356
357 public void SendHeaders()
358 {
359 if (_headersSent) throw new InvalidOperationException("headers already sent");
360 _headersSent = true;
361 }
362
363 public void Redirect(Uri uri) {}
364 public void Redirect(string url) {}
365 }
366
367
368>>>>>>> avn/ubitvar
45 public OSHttpRequest req0; 369 public OSHttpRequest req0;
46 public OSHttpRequest req1; 370 public OSHttpRequest req1;
47 371
@@ -113,4 +437,4 @@ namespace OpenSim.Framework.Servers.Tests
113 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml")); 437 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml"));
114 } 438 }
115 } 439 }
116} \ No newline at end of file 440}
diff --git a/OpenSim/Framework/TaskInventoryDictionary.cs b/OpenSim/Framework/TaskInventoryDictionary.cs
index 8af2c41..2c20ef7 100644
--- a/OpenSim/Framework/TaskInventoryDictionary.cs
+++ b/OpenSim/Framework/TaskInventoryDictionary.cs
@@ -27,9 +27,13 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading;
31using System.Reflection;
30using System.Xml; 32using System.Xml;
33using System.Diagnostics;
31using System.Xml.Schema; 34using System.Xml.Schema;
32using System.Xml.Serialization; 35using System.Xml.Serialization;
36using log4net;
33using OpenMetaverse; 37using OpenMetaverse;
34 38
35namespace OpenSim.Framework 39namespace OpenSim.Framework
@@ -47,6 +51,180 @@ namespace OpenSim.Framework
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 52
49 private static XmlSerializer tiiSerializer = new XmlSerializer(typeof (TaskInventoryItem)); 53 private static XmlSerializer tiiSerializer = new XmlSerializer(typeof (TaskInventoryItem));
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
56 private Thread LockedByThread;
57// private string WriterStack;
58
59// private Dictionary<Thread, string> ReadLockers =
60// new Dictionary<Thread, string>();
61
62 /// <value>
63 /// An advanced lock for inventory data
64 /// </value>
65 private volatile System.Threading.ReaderWriterLockSlim m_itemLock = new System.Threading.ReaderWriterLockSlim();
66
67 /// <summary>
68 /// Are we readlocked by the calling thread?
69 /// </summary>
70 public bool IsReadLockedByMe()
71 {
72 if (m_itemLock.RecursiveReadCount > 0)
73 {
74 return true;
75 }
76 else
77 {
78 return false;
79 }
80 }
81
82 /// <summary>
83 /// Lock our inventory list for reading (many can read, one can write)
84 /// </summary>
85 public void LockItemsForRead(bool locked)
86 {
87 if (locked)
88 {
89 if (m_itemLock.IsWriteLockHeld && LockedByThread != null)
90 {
91 if (!LockedByThread.IsAlive)
92 {
93 //Locked by dead thread, reset.
94 m_itemLock = new System.Threading.ReaderWriterLockSlim();
95 }
96 }
97
98 if (m_itemLock.RecursiveReadCount > 0)
99 {
100 m_log.Error("[TaskInventoryDictionary] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
101 try
102 {
103 // That call stack is useful for end users only. RealProgrammers need a full dump. Commented.
104 // StackTrace stackTrace = new StackTrace(); // get call stack
105 // StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
106 //
107 // // write call stack method names
108 // foreach (StackFrame stackFrame in stackFrames)
109 // {
110 // m_log.Error("[SceneObjectGroup.m_parts] "+(stackFrame.GetMethod().Name)); // write method name
111 // }
112
113 // The below is far more useful
114// System.Console.WriteLine("------------------------------------------");
115// System.Console.WriteLine("My call stack:\n" + Environment.StackTrace);
116// System.Console.WriteLine("------------------------------------------");
117// foreach (KeyValuePair<Thread, string> kvp in ReadLockers)
118// {
119// System.Console.WriteLine("Locker name {0} call stack:\n" + kvp.Value, kvp.Key.Name);
120// System.Console.WriteLine("------------------------------------------");
121// }
122 }
123 catch
124 {}
125 m_itemLock.ExitReadLock();
126 }
127 if (m_itemLock.RecursiveWriteCount > 0)
128 {
129 m_log.Error("[TaskInventoryDictionary] Recursive write lock requested. This should not happen and means something needs to be fixed.");
130// try
131// {
132// System.Console.WriteLine("------------------------------------------");
133// System.Console.WriteLine("My call stack:\n" + Environment.StackTrace);
134// System.Console.WriteLine("------------------------------------------");
135// System.Console.WriteLine("Locker's call stack:\n" + WriterStack);
136// System.Console.WriteLine("------------------------------------------");
137// }
138// catch
139// {}
140 m_itemLock.ExitWriteLock();
141 }
142
143 while (!m_itemLock.TryEnterReadLock(60000))
144 {
145 m_log.Error("Thread lock detected while trying to aquire READ lock in TaskInventoryDictionary. Locked by thread " + LockedByThread.Name + ". I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
146 //if (m_itemLock.IsWriteLockHeld)
147 //{
148 m_itemLock = new System.Threading.ReaderWriterLockSlim();
149// System.Console.WriteLine("------------------------------------------");
150// System.Console.WriteLine("My call stack:\n" + Environment.StackTrace);
151// System.Console.WriteLine("------------------------------------------");
152// System.Console.WriteLine("Locker's call stack:\n" + WriterStack);
153// System.Console.WriteLine("------------------------------------------");
154// LockedByThread = null;
155// ReadLockers.Clear();
156 //}
157 }
158// ReadLockers[Thread.CurrentThread] = Environment.StackTrace;
159 }
160 else
161 {
162 if (m_itemLock.RecursiveReadCount>0)
163 {
164 m_itemLock.ExitReadLock();
165 }
166// if (m_itemLock.RecursiveReadCount == 0)
167// ReadLockers.Remove(Thread.CurrentThread);
168 }
169 }
170
171 /// <summary>
172 /// Lock our inventory list for writing (many can read, one can write)
173 /// </summary>
174 public void LockItemsForWrite(bool locked)
175 {
176 if (locked)
177 {
178 //Enter a write lock, wait indefinately for one to open.
179 if (m_itemLock.RecursiveReadCount > 0)
180 {
181 m_log.Error("[TaskInventoryDictionary] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
182 m_itemLock.ExitReadLock();
183 }
184 if (m_itemLock.RecursiveWriteCount > 0)
185 {
186 m_log.Error("[TaskInventoryDictionary] Recursive write lock requested. This should not happen and means something needs to be fixed.");
187
188 m_itemLock.ExitWriteLock();
189 }
190 while (!m_itemLock.TryEnterWriteLock(60000))
191 {
192 if (m_itemLock.IsWriteLockHeld)
193 {
194 m_log.Error("Thread lock detected while trying to aquire WRITE lock in TaskInventoryDictionary. Locked by thread " + LockedByThread.Name + ". I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
195// System.Console.WriteLine("------------------------------------------");
196// System.Console.WriteLine("My call stack:\n" + Environment.StackTrace);
197// System.Console.WriteLine("------------------------------------------");
198// System.Console.WriteLine("Locker's call stack:\n" + WriterStack);
199// System.Console.WriteLine("------------------------------------------");
200 }
201 else
202 {
203 m_log.Error("Thread lock detected while trying to aquire WRITE lock in TaskInventoryDictionary. Locked by a reader. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
204// System.Console.WriteLine("------------------------------------------");
205// System.Console.WriteLine("My call stack:\n" + Environment.StackTrace);
206// System.Console.WriteLine("------------------------------------------");
207// foreach (KeyValuePair<Thread, string> kvp in ReadLockers)
208// {
209// System.Console.WriteLine("Locker name {0} call stack:\n" + kvp.Value, kvp.Key.Name);
210// System.Console.WriteLine("------------------------------------------");
211// }
212 }
213 m_itemLock = new System.Threading.ReaderWriterLockSlim();
214// ReadLockers.Clear();
215 }
216
217 LockedByThread = Thread.CurrentThread;
218// WriterStack = Environment.StackTrace;
219 }
220 else
221 {
222 if (m_itemLock.RecursiveWriteCount > 0)
223 {
224 m_itemLock.ExitWriteLock();
225 }
226 }
227 }
50 228
51 #region ICloneable Members 229 #region ICloneable Members
52 230
@@ -54,14 +232,13 @@ namespace OpenSim.Framework
54 { 232 {
55 TaskInventoryDictionary clone = new TaskInventoryDictionary(); 233 TaskInventoryDictionary clone = new TaskInventoryDictionary();
56 234
57 lock (this) 235 m_itemLock.EnterReadLock();
236 foreach (UUID uuid in Keys)
58 { 237 {
59 foreach (UUID uuid in Keys) 238 clone.Add(uuid, (TaskInventoryItem) this[uuid].Clone());
60 {
61 clone.Add(uuid, (TaskInventoryItem) this[uuid].Clone());
62 }
63 } 239 }
64 240 m_itemLock.ExitReadLock();
241
65 return clone; 242 return clone;
66 } 243 }
67 244
diff --git a/OpenSim/Framework/TaskInventoryItem.cs b/OpenSim/Framework/TaskInventoryItem.cs
index 307cb75..2ec4bd1 100644
--- a/OpenSim/Framework/TaskInventoryItem.cs
+++ b/OpenSim/Framework/TaskInventoryItem.cs
@@ -72,7 +72,7 @@ namespace OpenSim.Framework
72 private UUID _loadedID = UUID.Zero; 72 private UUID _loadedID = UUID.Zero;
73 73
74 private bool _ownerChanged = false; 74 private bool _ownerChanged = false;
75 75
76 public UUID AssetID { 76 public UUID AssetID {
77 get { 77 get {
78 return _assetID; 78 return _assetID;
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs
index 6b1be4e..d2e1c6a 100644
--- a/OpenSim/Framework/TerrainData.cs
+++ b/OpenSim/Framework/TerrainData.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.IO.Compression;
31using System.Reflection; 32using System.Reflection;
32 33
33using OpenMetaverse; 34using OpenMetaverse;
@@ -48,6 +49,7 @@ namespace OpenSim.Framework
48 49
49 public abstract float this[int x, int y] { get; set; } 50 public abstract float this[int x, int y] { get; set; }
50 // Someday terrain will have caves 51 // Someday terrain will have caves
52 // at most holes :p
51 public abstract float this[int x, int y, int z] { get; set; } 53 public abstract float this[int x, int y, int z] { get; set; }
52 54
53 public abstract bool IsTaintedAt(int xx, int yy); 55 public abstract bool IsTaintedAt(int xx, int yy);
@@ -72,8 +74,8 @@ namespace OpenSim.Framework
72 return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); 74 return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
73 } 75 }
74 76
75 // return a special compressed representation of the heightmap in ints 77 // return a special compressed representation of the heightmap in ushort
76 public abstract int[] GetCompressedMap(); 78 public abstract float[] GetCompressedMap();
77 public abstract float CompressionFactor { get; } 79 public abstract float CompressionFactor { get; }
78 80
79 public abstract float[] GetFloatsSerialized(); 81 public abstract float[] GetFloatsSerialized();
@@ -94,14 +96,18 @@ namespace OpenSim.Framework
94 { 96 {
95 // Terrain is 'double[256,256]' 97 // Terrain is 'double[256,256]'
96 Legacy256 = 11, 98 Legacy256 = 11,
99
97 // Terrain is 'int32, int32, float[,]' where the ints are X and Y dimensions 100 // Terrain is 'int32, int32, float[,]' where the ints are X and Y dimensions
98 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. 101 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
99 Variable2D = 22, 102 Variable2D = 22,
103 Variable2DGzip = 23,
104
100 // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions 105 // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions
101 // and third int is the 'compression factor'. The heights are compressed as 106 // and third int is the 'compression factor'. The heights are compressed as
102 // "int compressedHeight = (int)(height * compressionFactor);" 107 // "ushort compressedHeight = (ushort)(height * compressionFactor);"
103 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. 108 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
104 Compressed2D = 27, 109 Compressed2D = 27,
110
105 // A revision that is not listed above or any revision greater than this value is 'Legacy256'. 111 // A revision that is not listed above or any revision greater than this value is 'Legacy256'.
106 RevisionHigh = 1234 112 RevisionHigh = 1234
107 } 113 }
@@ -109,7 +115,7 @@ namespace OpenSim.Framework
109 // Version of terrain that is a heightmap. 115 // Version of terrain that is a heightmap.
110 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge 116 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
111 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. 117 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
112 // The heighmap is kept as an array of integers. The integer values are converted to 118 // The heighmap is kept as an array of ushorts. The ushort values are converted to
113 // and from floats by TerrainCompressionFactor. 119 // and from floats by TerrainCompressionFactor.
114 public class HeightmapTerrainData : TerrainData 120 public class HeightmapTerrainData : TerrainData
115 { 121 {
@@ -119,12 +125,12 @@ namespace OpenSim.Framework
119 // TerrainData.this[x, y] 125 // TerrainData.this[x, y]
120 public override float this[int x, int y] 126 public override float this[int x, int y]
121 { 127 {
122 get { return FromCompressedHeight(m_heightmap[x, y]); } 128 get { return m_heightmap[x, y]; }
123 set { 129 set
124 int newVal = ToCompressedHeight(value); 130 {
125 if (m_heightmap[x, y] != newVal) 131 if (m_heightmap[x, y] != value)
126 { 132 {
127 m_heightmap[x, y] = newVal; 133 m_heightmap[x, y] = value;
128 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true; 134 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true;
129 } 135 }
130 } 136 }
@@ -164,10 +170,9 @@ namespace OpenSim.Framework
164 // TerrainData.ClearLand(float) 170 // TerrainData.ClearLand(float)
165 public override void ClearLand(float pHeight) 171 public override void ClearLand(float pHeight)
166 { 172 {
167 int flatHeight = ToCompressedHeight(pHeight);
168 for (int xx = 0; xx < SizeX; xx++) 173 for (int xx = 0; xx < SizeX; xx++)
169 for (int yy = 0; yy < SizeY; yy++) 174 for (int yy = 0; yy < SizeY; yy++)
170 m_heightmap[xx, yy] = flatHeight; 175 m_heightmap[xx, yy] = pHeight;
171 } 176 }
172 177
173 // Return 'true' of the patch that contains these region coordinates has been modified. 178 // Return 'true' of the patch that contains these region coordinates has been modified.
@@ -177,13 +182,15 @@ namespace OpenSim.Framework
177 { 182 {
178 int tx = xx / Constants.TerrainPatchSize; 183 int tx = xx / Constants.TerrainPatchSize;
179 int ty = yy / Constants.TerrainPatchSize; 184 int ty = yy / Constants.TerrainPatchSize;
180 bool ret = m_taint[tx, ty]; 185 bool ret = m_taint[tx, ty];
181 if (ret && clearOnTest) 186 if (ret && clearOnTest)
182 m_taint[tx, ty] = false; 187 m_taint[tx, ty] = false;
183 return ret; 188 return ret;
184 } 189 }
185 190
186 // Old form that clears the taint flag when we check it. 191 // Old form that clears the taint flag when we check it.
192 // ubit: this dangerus naming should be only check without clear
193 // keeping for old modules outthere
187 public override bool IsTaintedAt(int xx, int yy) 194 public override bool IsTaintedAt(int xx, int yy)
188 { 195 {
189 return IsTaintedAt(xx, yy, true /* clearOnTest */); 196 return IsTaintedAt(xx, yy, true /* clearOnTest */);
@@ -202,8 +209,10 @@ namespace OpenSim.Framework
202 } 209 }
203 else 210 else
204 { 211 {
205 DBRevisionCode = (int)DBTerrainRevision.Compressed2D; 212 DBRevisionCode = (int)DBTerrainRevision.Variable2DGzip;
206 blob = ToCompressedTerrainSerialization(); 213// DBRevisionCode = (int)DBTerrainRevision.Variable2D;
214 blob = ToCompressedTerrainSerializationV2DGzip();
215// blob = ToCompressedTerrainSerializationV2D();
207 ret = true; 216 ret = true;
208 } 217 }
209 return ret; 218 return ret;
@@ -214,9 +223,9 @@ namespace OpenSim.Framework
214 public override float CompressionFactor { get { return m_compressionFactor; } } 223 public override float CompressionFactor { get { return m_compressionFactor; } }
215 224
216 // TerrainData.GetCompressedMap 225 // TerrainData.GetCompressedMap
217 public override int[] GetCompressedMap() 226 public override float[] GetCompressedMap()
218 { 227 {
219 int[] newMap = new int[SizeX * SizeY]; 228 float[] newMap = new float[SizeX * SizeY];
220 229
221 int ind = 0; 230 int ind = 0;
222 for (int xx = 0; xx < SizeX; xx++) 231 for (int xx = 0; xx < SizeX; xx++)
@@ -230,7 +239,7 @@ namespace OpenSim.Framework
230 public override TerrainData Clone() 239 public override TerrainData Clone()
231 { 240 {
232 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ); 241 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
233 ret.m_heightmap = (int[,])this.m_heightmap.Clone(); 242 ret.m_heightmap = (float[,])this.m_heightmap.Clone();
234 return ret; 243 return ret;
235 } 244 }
236 245
@@ -247,7 +256,7 @@ namespace OpenSim.Framework
247 for (int jj = 0; jj < SizeY; jj++) 256 for (int jj = 0; jj < SizeY; jj++)
248 for (int ii = 0; ii < SizeX; ii++) 257 for (int ii = 0; ii < SizeX; ii++)
249 { 258 {
250 heights[idx++] = FromCompressedHeight(m_heightmap[ii, jj]); 259 heights[idx++] = m_heightmap[ii, jj];
251 } 260 }
252 261
253 return heights; 262 return heights;
@@ -259,7 +268,7 @@ namespace OpenSim.Framework
259 double[,] ret = new double[SizeX, SizeY]; 268 double[,] ret = new double[SizeX, SizeY];
260 for (int xx = 0; xx < SizeX; xx++) 269 for (int xx = 0; xx < SizeX; xx++)
261 for (int yy = 0; yy < SizeY; yy++) 270 for (int yy = 0; yy < SizeY; yy++)
262 ret[xx, yy] = FromCompressedHeight(m_heightmap[xx, yy]); 271 ret[xx, yy] = (double)m_heightmap[xx, yy];
263 272
264 return ret; 273 return ret;
265 } 274 }
@@ -267,19 +276,40 @@ namespace OpenSim.Framework
267 276
268 // ============================================================= 277 // =============================================================
269 278
270 private int[,] m_heightmap; 279 private float[,] m_heightmap;
271 // Remember subregions of the heightmap that has changed. 280 // Remember subregions of the heightmap that has changed.
272 private bool[,] m_taint; 281 private bool[,] m_taint;
273 282
274 // To save space (especially for large regions), keep the height as a short integer
275 // that is coded as the float height times the compression factor (usually '100' 283 // that is coded as the float height times the compression factor (usually '100'
276 // to make for two decimal points). 284 // to make for two decimal points).
277 public int ToCompressedHeight(double pHeight) 285 public short ToCompressedHeightshort(float pHeight)
286 {
287 // clamp into valid range
288 pHeight *= CompressionFactor;
289 if (pHeight < short.MinValue)
290 return short.MinValue;
291 else if (pHeight > short.MaxValue)
292 return short.MaxValue;
293 return (short)pHeight;
294 }
295
296 public ushort ToCompressedHeightushort(float pHeight)
278 { 297 {
279 return (int)(pHeight * CompressionFactor); 298 // clamp into valid range
299 pHeight *= CompressionFactor;
300 if (pHeight < ushort.MinValue)
301 return ushort.MinValue;
302 else if (pHeight > ushort.MaxValue)
303 return ushort.MaxValue;
304 return (ushort)pHeight;
280 } 305 }
281 306
282 public float FromCompressedHeight(int pHeight) 307 public float FromCompressedHeight(short pHeight)
308 {
309 return ((float)pHeight) / CompressionFactor;
310 }
311
312 public float FromCompressedHeight(ushort pHeight)
283 { 313 {
284 return ((float)pHeight) / CompressionFactor; 314 return ((float)pHeight) / CompressionFactor;
285 } 315 }
@@ -293,12 +323,12 @@ namespace OpenSim.Framework
293 SizeZ = (int)Constants.RegionHeight; 323 SizeZ = (int)Constants.RegionHeight;
294 m_compressionFactor = 100.0f; 324 m_compressionFactor = 100.0f;
295 325
296 m_heightmap = new int[SizeX, SizeY]; 326 m_heightmap = new float[SizeX, SizeY];
297 for (int ii = 0; ii < SizeX; ii++) 327 for (int ii = 0; ii < SizeX; ii++)
298 { 328 {
299 for (int jj = 0; jj < SizeY; jj++) 329 for (int jj = 0; jj < SizeY; jj++)
300 { 330 {
301 m_heightmap[ii, jj] = ToCompressedHeight(pTerrain[ii, jj]); 331 m_heightmap[ii, jj] = (float)pTerrain[ii, jj];
302 332
303 } 333 }
304 } 334 }
@@ -315,14 +345,15 @@ namespace OpenSim.Framework
315 SizeY = pY; 345 SizeY = pY;
316 SizeZ = pZ; 346 SizeZ = pZ;
317 m_compressionFactor = 100.0f; 347 m_compressionFactor = 100.0f;
318 m_heightmap = new int[SizeX, SizeY]; 348 m_heightmap = new float[SizeX, SizeY];
319 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; 349 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
320 // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); 350 // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
321 ClearTaint(); 351 ClearTaint();
322 ClearLand(0f); 352 ClearLand(0f);
323 } 353 }
324 354
325 public HeightmapTerrainData(int[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) 355 public HeightmapTerrainData(float[] cmap, float pCompressionFactor, int pX, int pY, int pZ)
356 : this(pX, pY, pZ)
326 { 357 {
327 m_compressionFactor = pCompressionFactor; 358 m_compressionFactor = pCompressionFactor;
328 int ind = 0; 359 int ind = 0;
@@ -333,12 +364,22 @@ namespace OpenSim.Framework
333 } 364 }
334 365
335 // Create a heighmap from a database blob 366 // Create a heighmap from a database blob
336 public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) : this(pSizeX, pSizeY, pSizeZ) 367 public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
368 : this(pSizeX, pSizeY, pSizeZ)
337 { 369 {
338 switch ((DBTerrainRevision)pFormatCode) 370 switch ((DBTerrainRevision)pFormatCode)
339 { 371 {
372 case DBTerrainRevision.Variable2DGzip:
373 FromCompressedTerrainSerializationV2DGZip(pBlob);
374 m_log.DebugFormat("{0} HeightmapTerrainData create from Variable2DGzip serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY);
375 break;
376
377 case DBTerrainRevision.Variable2D:
378 FromCompressedTerrainSerializationV2D(pBlob);
379 m_log.DebugFormat("{0} HeightmapTerrainData create from Variable2D serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY);
380 break;
340 case DBTerrainRevision.Compressed2D: 381 case DBTerrainRevision.Compressed2D:
341 FromCompressedTerrainSerialization(pBlob); 382 FromCompressedTerrainSerialization2D(pBlob);
342 m_log.DebugFormat("{0} HeightmapTerrainData create from Compressed2D serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY); 383 m_log.DebugFormat("{0} HeightmapTerrainData create from Compressed2D serialization. Size=<{1},{2}>", LogHeader, SizeX, SizeY);
343 break; 384 break;
344 default: 385 default:
@@ -373,50 +414,116 @@ namespace OpenSim.Framework
373 return ret; 414 return ret;
374 } 415 }
375 416
376 // Just create an array of doubles. Presumes the caller implicitly knows the size. 417 // Presumes the caller implicitly knows the size.
377 public void FromLegacyTerrainSerialization(byte[] pBlob) 418 public void FromLegacyTerrainSerialization(byte[] pBlob)
378 { 419 {
379 // In case database info doesn't match real terrain size, initialize the whole terrain. 420 // In case database info doesn't match real terrain size, initialize the whole terrain.
380 ClearLand(); 421 ClearLand();
381 422
382 using (MemoryStream mstr = new MemoryStream(pBlob)) 423 try
383 { 424 {
384 using (BinaryReader br = new BinaryReader(mstr)) 425 using (MemoryStream mstr = new MemoryStream(pBlob))
385 { 426 {
386 for (int xx = 0; xx < (int)Constants.RegionSize; xx++) 427 using (BinaryReader br = new BinaryReader(mstr))
387 { 428 {
388 for (int yy = 0; yy < (int)Constants.RegionSize; yy++) 429 for (int xx = 0; xx < (int)Constants.RegionSize; xx++)
389 { 430 {
390 float val = (float)br.ReadDouble(); 431 for (int yy = 0; yy < (int)Constants.RegionSize; yy++)
391 if (xx < SizeX && yy < SizeY) 432 {
392 m_heightmap[xx, yy] = ToCompressedHeight(val); 433 float val = (float)br.ReadDouble();
434
435 if (xx < SizeX && yy < SizeY)
436 m_heightmap[xx, yy] = val;
437 }
393 } 438 }
394 } 439 }
395 } 440 }
396 ClearTaint();
397 } 441 }
442 catch
443 {
444 ClearLand();
445 }
446 ClearTaint();
398 } 447 }
399 448
400 // See the reader below. 449
401 public Array ToCompressedTerrainSerialization() 450 // stores as variable2D
451 // int32 sizeX
452 // int32 sizeY
453 // float[,] array
454
455 public Array ToCompressedTerrainSerializationV2D()
402 { 456 {
403 Array ret = null; 457 Array ret = null;
404 using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(Int16)))) 458 try
405 { 459 {
406 using (BinaryWriter bw = new BinaryWriter(str)) 460 using (MemoryStream str = new MemoryStream((2 * sizeof(Int32)) + (SizeX * SizeY * sizeof(float))))
461 {
462 using (BinaryWriter bw = new BinaryWriter(str))
463 {
464 bw.Write((Int32)SizeX);
465 bw.Write((Int32)SizeY);
466 for (int yy = 0; yy < SizeY; yy++)
467 for (int xx = 0; xx < SizeX; xx++)
468 {
469 // reduce to 1cm resolution
470 float val = (float)Math.Round(m_heightmap[xx, yy],2,MidpointRounding.ToEven);
471 bw.Write(val);
472 }
473 }
474 ret = str.ToArray();
475 }
476 }
477 catch
478 {
479
480 }
481
482 m_log.DebugFormat("{0} V2D {1} bytes",
483 LogHeader, ret.Length);
484
485 return ret;
486 }
487
488 // as above with Gzip compression
489 public Array ToCompressedTerrainSerializationV2DGzip()
490 {
491 Array ret = null;
492 try
493 {
494 using (MemoryStream inp = new MemoryStream((2 * sizeof(Int32)) + (SizeX * SizeY * sizeof(float))))
407 { 495 {
408 bw.Write((Int32)DBTerrainRevision.Compressed2D); 496 using (BinaryWriter bw = new BinaryWriter(inp))
409 bw.Write((Int32)SizeX); 497 {
410 bw.Write((Int32)SizeY); 498 bw.Write((Int32)SizeX);
411 bw.Write((Int32)CompressionFactor); 499 bw.Write((Int32)SizeY);
412 for (int yy = 0; yy < SizeY; yy++) 500 for (int yy = 0; yy < SizeY; yy++)
413 for (int xx = 0; xx < SizeX; xx++) 501 for (int xx = 0; xx < SizeX; xx++)
502 {
503 bw.Write((float)m_heightmap[xx, yy]);
504 }
505
506 bw.Flush();
507 inp.Seek(0, SeekOrigin.Begin);
508
509 using (MemoryStream outputStream = new MemoryStream())
414 { 510 {
415 bw.Write((Int16)m_heightmap[xx, yy]); 511 using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress))
512 {
513 inp.CopyStream(compressionStream, int.MaxValue);
514 compressionStream.Close();
515 ret = outputStream.ToArray();
516 }
416 } 517 }
518 }
417 } 519 }
418 ret = str.ToArray();
419 } 520 }
521 catch
522 {
523
524 }
525 m_log.DebugFormat("{0} V2DGzip {1} bytes",
526 LogHeader, ret.Length);
420 return ret; 527 return ret;
421 } 528 }
422 529
@@ -426,7 +533,7 @@ namespace OpenSim.Framework
426 // the forth int is the compression factor for the following int16s 533 // the forth int is the compression factor for the following int16s
427 // This is just sets heightmap info. The actual size of the region was set on this instance's 534 // This is just sets heightmap info. The actual size of the region was set on this instance's
428 // creation and any heights not initialized by theis blob are set to the default height. 535 // creation and any heights not initialized by theis blob are set to the default height.
429 public void FromCompressedTerrainSerialization(byte[] pBlob) 536 public void FromCompressedTerrainSerialization2D(byte[] pBlob)
430 { 537 {
431 Int32 hmFormatCode, hmSizeX, hmSizeY, hmCompressionFactor; 538 Int32 hmFormatCode, hmSizeX, hmSizeY, hmCompressionFactor;
432 539
@@ -448,7 +555,7 @@ namespace OpenSim.Framework
448 { 555 {
449 for (int xx = 0; xx < hmSizeX; xx++) 556 for (int xx = 0; xx < hmSizeX; xx++)
450 { 557 {
451 Int16 val = br.ReadInt16(); 558 float val = FromCompressedHeight(br.ReadInt16());
452 if (xx < SizeX && yy < SizeY) 559 if (xx < SizeX && yy < SizeY)
453 m_heightmap[xx, yy] = val; 560 m_heightmap[xx, yy] = val;
454 } 561 }
@@ -456,9 +563,112 @@ namespace OpenSim.Framework
456 } 563 }
457 ClearTaint(); 564 ClearTaint();
458 565
459 m_log.InfoFormat("{0} Read compressed 2d heightmap. Heightmap size=<{1},{2}>. Region size=<{3},{4}>. CompFact={5}", 566 m_log.DebugFormat("{0} Read (compressed2D) heightmap. Heightmap size=<{1},{2}>. Region size=<{3},{4}>. CompFact={5}",
460 LogHeader, hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor); 567 LogHeader, hmSizeX, hmSizeY, SizeX, SizeY, hmCompressionFactor);
461 } 568 }
462 } 569 }
570
571 // Initialize heightmap from blob consisting of:
572 // int32, int32, int32, float[]
573 // where the first int32 is format code, next two int32s are the X and y of heightmap data
574 // This is just sets heightmap info. The actual size of the region was set on this instance's
575 // creation and any heights not initialized by theis blob are set to the default height.
576 public void FromCompressedTerrainSerializationV2D(byte[] pBlob)
577 {
578 Int32 hmSizeX, hmSizeY;
579 try
580 {
581 using (MemoryStream mstr = new MemoryStream(pBlob))
582 {
583 using (BinaryReader br = new BinaryReader(mstr))
584 {
585 hmSizeX = br.ReadInt32();
586 hmSizeY = br.ReadInt32();
587
588 // In case database info doesn't match real terrain size, initialize the whole terrain.
589 ClearLand();
590
591 for (int yy = 0; yy < hmSizeY; yy++)
592 {
593 for (int xx = 0; xx < hmSizeX; xx++)
594 {
595 float val = br.ReadSingle();
596 if (xx < SizeX && yy < SizeY)
597 m_heightmap[xx, yy] = val;
598 }
599 }
600 }
601 }
602 }
603 catch (Exception e)
604 {
605 ClearTaint();
606 m_log.ErrorFormat("{0} 2D error: {1} - terrain may be damaged",
607 LogHeader, e.Message);
608 return;
609 }
610 ClearTaint();
611
612 m_log.DebugFormat("{0} V2D Heightmap size=<{1},{2}>. Region size=<{3},{4}>",
613 LogHeader, hmSizeX, hmSizeY, SizeX, SizeY);
614
615 }
616
617 // as above but Gzip compressed
618 public void FromCompressedTerrainSerializationV2DGZip(byte[] pBlob)
619 {
620 m_log.InfoFormat("{0} VD2Gzip {1} bytes input",
621 LogHeader, pBlob.Length);
622
623 Int32 hmSizeX, hmSizeY;
624
625 try
626 {
627 using (MemoryStream outputStream = new MemoryStream())
628 {
629 using (MemoryStream inputStream = new MemoryStream(pBlob))
630 {
631 using (GZipStream decompressionStream = new GZipStream(inputStream, CompressionMode.Decompress))
632 {
633 decompressionStream.Flush();
634 decompressionStream.CopyTo(outputStream);
635 }
636 }
637
638 outputStream.Seek(0, SeekOrigin.Begin);
639
640 using (BinaryReader br = new BinaryReader(outputStream))
641 {
642 hmSizeX = br.ReadInt32();
643 hmSizeY = br.ReadInt32();
644
645 // In case database info doesn't match real terrain size, initialize the whole terrain.
646 ClearLand();
647
648 for (int yy = 0; yy < hmSizeY; yy++)
649 {
650 for (int xx = 0; xx < hmSizeX; xx++)
651 {
652 float val = br.ReadSingle();
653 if (xx < SizeX && yy < SizeY)
654 m_heightmap[xx, yy] = val;
655 }
656 }
657 }
658 }
659 }
660 catch( Exception e)
661 {
662 ClearTaint();
663 m_log.ErrorFormat("{0} V2DGzip error: {1} - terrain may be damaged",
664 LogHeader, e.Message);
665 return;
666 }
667
668 ClearTaint();
669 m_log.DebugFormat("{0} V2DGzip. Heightmap size=<{1},{2}>. Region size=<{3},{4}>",
670 LogHeader, hmSizeX, hmSizeY, SizeX, SizeY);
671
672 }
463 } 673 }
464} 674}
diff --git a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
index 3f0a031..08f2af5 100644
--- a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
+++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
@@ -218,12 +218,12 @@ namespace OpenSim.Framework.Tests
218 BannedHostNameMask = string.Empty, 218 BannedHostNameMask = string.Empty,
219 BannedUserID = bannedUserId} 219 BannedUserID = bannedUserId}
220 ); 220 );
221 Assert.IsTrue(es.IsBanned(bannedUserId), "User Should be banned but is not."); 221 Assert.IsTrue(es.IsBanned(bannedUserId, 32), "User Should be banned but is not.");
222 Assert.IsFalse(es.IsBanned(UUID.Zero), "User Should not be banned but is."); 222 Assert.IsFalse(es.IsBanned(UUID.Zero, 32), "User Should not be banned but is.");
223 223
224 es.RemoveBan(bannedUserId); 224 es.RemoveBan(bannedUserId);
225 225
226 Assert.IsFalse(es.IsBanned(bannedUserId), "User Should not be banned but is."); 226 Assert.IsFalse(es.IsBanned(bannedUserId, 32), "User Should not be banned but is.");
227 227
228 es.AddEstateManager(UUID.Zero); 228 es.AddEstateManager(UUID.Zero);
229 229
diff --git a/OpenSim/Framework/ThrottleOutPacketType.cs b/OpenSim/Framework/ThrottleOutPacketType.cs
index ca4b126..87899f0 100644
--- a/OpenSim/Framework/ThrottleOutPacketType.cs
+++ b/OpenSim/Framework/ThrottleOutPacketType.cs
@@ -47,6 +47,8 @@ namespace OpenSim.Framework
47 Texture = 5, 47 Texture = 5,
48 /// <summary>Non-texture assets</summary> 48 /// <summary>Non-texture assets</summary>
49 Asset = 6, 49 Asset = 6,
50
51 HighPriority = 128,
50 } 52 }
51 53
52 [Flags] 54 [Flags]
diff --git a/OpenSim/Framework/UserProfileData.cs b/OpenSim/Framework/UserProfileData.cs
index 266ccf0..61d8fe5 100644
--- a/OpenSim/Framework/UserProfileData.cs
+++ b/OpenSim/Framework/UserProfileData.cs
@@ -160,7 +160,11 @@ namespace OpenSim.Framework
160 public virtual ulong HomeRegion 160 public virtual ulong HomeRegion
161 { 161 {
162 get 162 get
163<<<<<<< HEAD
163 { 164 {
165=======
166 {
167>>>>>>> avn/ubitvar
164 return Util.RegionWorldLocToHandle(Util.RegionToWorldLoc(m_homeRegionX), Util.RegionToWorldLoc(m_homeRegionY)); 168 return Util.RegionWorldLocToHandle(Util.RegionToWorldLoc(m_homeRegionX), Util.RegionToWorldLoc(m_homeRegionY));
165 // return Utils.UIntsToLong( m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize); 169 // return Utils.UIntsToLong( m_homeRegionX * (uint)Constants.RegionSize, m_homeRegionY * (uint)Constants.RegionSize);
166 } 170 }
diff --git a/OpenSim/Framework/UserProfiles.cs b/OpenSim/Framework/UserProfiles.cs
index 98ab651..944a492 100644
--- a/OpenSim/Framework/UserProfiles.cs
+++ b/OpenSim/Framework/UserProfiles.cs
@@ -91,14 +91,6 @@ namespace OpenSim.Framework
91 public UUID TargetId; 91 public UUID TargetId;
92 public string Notes; 92 public string Notes;
93 } 93 }
94
95 public class UserPreferences
96 {
97 public UUID UserId;
98 public bool IMViaEmail = false;
99 public bool Visible = false;
100 public string EMail = string.Empty;
101 }
102 94
103 public class UserAccountProperties 95 public class UserAccountProperties
104 { 96 {
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index a5f798d..eb3526a 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -61,6 +61,15 @@ namespace OpenSim.Framework
61 public enum PermissionMask : uint 61 public enum PermissionMask : uint
62 { 62 {
63 None = 0, 63 None = 0,
64
65 // folded perms
66 foldedTransfer = 1,
67 foldedModify = 1 << 1,
68 foldedCopy = 1 << 2,
69
70 foldedMask = 0x07,
71
72 //
64 Transfer = 1 << 13, 73 Transfer = 1 << 13,
65 Modify = 1 << 14, 74 Modify = 1 << 14,
66 Copy = 1 << 15, 75 Copy = 1 << 15,
@@ -267,14 +276,12 @@ namespace OpenSim.Framework
267 /// </summary> 276 /// </summary>
268 /// <param name="a">A 3d vector</param> 277 /// <param name="a">A 3d vector</param>
269 /// <returns>A new vector which is normalized form of the vector</returns> 278 /// <returns>A new vector which is normalized form of the vector</returns>
270 /// <remarks>The vector paramater cannot be <0,0,0></remarks> 279
271 public static Vector3 GetNormalizedVector(Vector3 a) 280 public static Vector3 GetNormalizedVector(Vector3 a)
272 { 281 {
273 if (IsZeroVector(a)) 282 Vector3 v = new Vector3(a.X, a.Y, a.Z);
274 throw new ArgumentException("Vector paramater cannot be a zero vector."); 283 v.Normalize();
275 284 return v;
276 float Mag = (float) GetMagnitude(a);
277 return new Vector3(a.X / Mag, a.Y / Mag, a.Z / Mag);
278 } 285 }
279 286
280 /// <summary> 287 /// <summary>
@@ -641,19 +648,25 @@ namespace OpenSim.Framework
641 /// </summary> 648 /// </summary>
642 /// <param name="data"></param> 649 /// <param name="data"></param>
643 /// <returns></returns> 650 /// <returns></returns>
651
644 public static string Md5Hash(string data) 652 public static string Md5Hash(string data)
645 { 653 {
646 byte[] dataMd5 = ComputeMD5Hash(data); 654 return Md5Hash(data, Encoding.Default);
655 }
656
657 public static string Md5Hash(string data, Encoding encoding)
658 {
659 byte[] dataMd5 = ComputeMD5Hash(data, encoding);
647 StringBuilder sb = new StringBuilder(); 660 StringBuilder sb = new StringBuilder();
648 for (int i = 0; i < dataMd5.Length; i++) 661 for (int i = 0; i < dataMd5.Length; i++)
649 sb.AppendFormat("{0:x2}", dataMd5[i]); 662 sb.AppendFormat("{0:x2}", dataMd5[i]);
650 return sb.ToString(); 663 return sb.ToString();
651 } 664 }
652 665
653 private static byte[] ComputeMD5Hash(string data) 666 private static byte[] ComputeMD5Hash(string data, Encoding encoding)
654 { 667 {
655 MD5 md5 = MD5.Create(); 668 MD5 md5 = MD5.Create();
656 return md5.ComputeHash(Encoding.Default.GetBytes(data)); 669 return md5.ComputeHash(encoding.GetBytes(data));
657 } 670 }
658 671
659 /// <summary> 672 /// <summary>
@@ -661,6 +674,12 @@ namespace OpenSim.Framework
661 /// </summary> 674 /// </summary>
662 /// <param name="data"></param> 675 /// <param name="data"></param>
663 /// <returns></returns> 676 /// <returns></returns>
677
678 public static string SHA1Hash(string data, Encoding enc)
679 {
680 return SHA1Hash(enc.GetBytes(data));
681 }
682
664 public static string SHA1Hash(string data) 683 public static string SHA1Hash(string data)
665 { 684 {
666 return SHA1Hash(Encoding.Default.GetBytes(data)); 685 return SHA1Hash(Encoding.Default.GetBytes(data));
@@ -714,17 +733,26 @@ namespace OpenSim.Framework
714 /// <param name="oldy">Old region y-coord</param> 733 /// <param name="oldy">Old region y-coord</param>
715 /// <param name="newy">New region y-coord</param> 734 /// <param name="newy">New region y-coord</param>
716 /// <returns></returns> 735 /// <returns></returns>
717 public static bool IsOutsideView(float drawdist, uint oldx, uint newx, uint oldy, uint newy) 736 public static bool IsOutsideView(float drawdist, uint oldx, uint newx, uint oldy, uint newy,
737 int oldsizex, int oldsizey, int newsizex, int newsizey)
718 { 738 {
719 int dd = (int)((drawdist + Constants.RegionSize - 1) / Constants.RegionSize); 739 // we still need to make sure we see new region 1stNeighbors
720 740
721 int startX = (int)oldx - dd; 741 oldx *= Constants.RegionSize;
722 int startY = (int)oldy - dd; 742 newx *= Constants.RegionSize;
743 if (oldx + oldsizex + drawdist < newx)
744 return true;
745 if (newx + newsizex + drawdist < oldx)
746 return true;
723 747
724 int endX = (int)oldx + dd; 748 oldy *= Constants.RegionSize;
725 int endY = (int)oldy + dd; 749 newy *= Constants.RegionSize;
750 if (oldy + oldsizey + drawdist < newy)
751 return true;
752 if (newy + newsizey + drawdist< oldy)
753 return true;
726 754
727 return (newx < startX || endX < newx || newy < startY || endY < newy); 755 return false;
728 } 756 }
729 757
730 public static string FieldToString(byte[] bytes) 758 public static string FieldToString(byte[] bytes)
@@ -805,6 +833,16 @@ namespace OpenSim.Framework
805 } 833 }
806 834
807 /// <summary> 835 /// <summary>
836 /// Converts a URL to a IPAddress
837 /// </summary>
838 /// <param name="url">URL Standard Format</param>
839 /// <returns>A resolved IP Address</returns>
840 public static IPAddress GetHostFromURL(string url)
841 {
842 return GetHostFromDNS(url.Split(new char[] {'/', ':'})[3]);
843 }
844
845 /// <summary>
808 /// Returns a IP address from a specified DNS, favouring IPv4 addresses. 846 /// Returns a IP address from a specified DNS, favouring IPv4 addresses.
809 /// </summary> 847 /// </summary>
810 /// <param name="dnsAddress">DNS Hostname</param> 848 /// <param name="dnsAddress">DNS Hostname</param>
@@ -1065,6 +1103,25 @@ namespace OpenSim.Framework
1065 } 1103 }
1066 } 1104 }
1067 1105
1106 public static string GetConfigVarWithDefaultSection(IConfigSource config, string varname, string section)
1107 {
1108 // First, check the Startup section, the default section
1109 IConfig cnf = config.Configs["Startup"];
1110 if (cnf == null)
1111 return string.Empty;
1112 string val = cnf.GetString(varname, string.Empty);
1113
1114 // Then check for an overwrite of the default in the given section
1115 if (!string.IsNullOrEmpty(section))
1116 {
1117 cnf = config.Configs[section];
1118 if (cnf != null)
1119 val = cnf.GetString(varname, val);
1120 }
1121
1122 return val;
1123 }
1124
1068 /// <summary> 1125 /// <summary>
1069 /// Gets the value of a configuration variable by looking into 1126 /// Gets the value of a configuration variable by looking into
1070 /// multiple sections in order. The latter sections overwrite 1127 /// multiple sections in order. The latter sections overwrite
@@ -1388,6 +1445,46 @@ namespace OpenSim.Framework
1388 return ret; 1445 return ret;
1389 } 1446 }
1390 1447
1448 public static string Compress(string text)
1449 {
1450 byte[] buffer = Util.UTF8.GetBytes(text);
1451 MemoryStream memory = new MemoryStream();
1452 using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
1453 {
1454 compressor.Write(buffer, 0, buffer.Length);
1455 }
1456
1457 memory.Position = 0;
1458
1459 byte[] compressed = new byte[memory.Length];
1460 memory.Read(compressed, 0, compressed.Length);
1461
1462 byte[] compressedBuffer = new byte[compressed.Length + 4];
1463 Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
1464 Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
1465 return Convert.ToBase64String(compressedBuffer);
1466 }
1467
1468 public static string Decompress(string compressedText)
1469 {
1470 byte[] compressedBuffer = Convert.FromBase64String(compressedText);
1471 using (MemoryStream memory = new MemoryStream())
1472 {
1473 int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
1474 memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
1475
1476 byte[] buffer = new byte[msgLength];
1477
1478 memory.Position = 0;
1479 using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
1480 {
1481 decompressor.Read(buffer, 0, buffer.Length);
1482 }
1483
1484 return Util.UTF8.GetString(buffer);
1485 }
1486 }
1487
1391 /// <summary> 1488 /// <summary>
1392 /// Copy data from one stream to another, leaving the read position of both streams at the beginning. 1489 /// Copy data from one stream to another, leaving the read position of both streams at the beginning.
1393 /// </summary> 1490 /// </summary>
@@ -1524,19 +1621,19 @@ namespace OpenSim.Framework
1524 { 1621 {
1525 string os = String.Empty; 1622 string os = String.Empty;
1526 1623
1527 if (Environment.OSVersion.Platform != PlatformID.Unix) 1624// if (Environment.OSVersion.Platform != PlatformID.Unix)
1528 { 1625// {
1529 os = Environment.OSVersion.ToString(); 1626// os = Environment.OSVersion.ToString();
1530 } 1627// }
1531 else 1628// else
1532 { 1629// {
1533 os = ReadEtcIssue(); 1630// os = ReadEtcIssue();
1534 } 1631// }
1535 1632//
1536 if (os.Length > 45) 1633// if (os.Length > 45)
1537 { 1634// {
1538 os = os.Substring(0, 45); 1635// os = os.Substring(0, 45);
1539 } 1636// }
1540 1637
1541 return os; 1638 return os;
1542 } 1639 }
@@ -1591,6 +1688,69 @@ namespace OpenSim.Framework
1591 return displayConnectionString; 1688 return displayConnectionString;
1592 } 1689 }
1593 1690
1691 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
1692 {
1693 Type settingsType = settingsClass.GetType();
1694
1695 FieldInfo[] fieldInfos = settingsType.GetFields();
1696 foreach (FieldInfo fieldInfo in fieldInfos)
1697 {
1698 if (!fieldInfo.IsStatic)
1699 {
1700 if (fieldInfo.FieldType == typeof(System.String))
1701 {
1702 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
1703 }
1704 else if (fieldInfo.FieldType == typeof(System.Boolean))
1705 {
1706 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
1707 }
1708 else if (fieldInfo.FieldType == typeof(System.Int32))
1709 {
1710 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
1711 }
1712 else if (fieldInfo.FieldType == typeof(System.Single))
1713 {
1714 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
1715 }
1716 else if (fieldInfo.FieldType == typeof(System.UInt32))
1717 {
1718 fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
1719 }
1720 }
1721 }
1722
1723 PropertyInfo[] propertyInfos = settingsType.GetProperties();
1724 foreach (PropertyInfo propInfo in propertyInfos)
1725 {
1726 if ((propInfo.CanRead) && (propInfo.CanWrite))
1727 {
1728 if (propInfo.PropertyType == typeof(System.String))
1729 {
1730 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
1731 }
1732 else if (propInfo.PropertyType == typeof(System.Boolean))
1733 {
1734 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
1735 }
1736 else if (propInfo.PropertyType == typeof(System.Int32))
1737 {
1738 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
1739 }
1740 else if (propInfo.PropertyType == typeof(System.Single))
1741 {
1742 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
1743 }
1744 if (propInfo.PropertyType == typeof(System.UInt32))
1745 {
1746 propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
1747 }
1748 }
1749 }
1750
1751 return settingsClass;
1752 }
1753
1594 public static string Base64ToString(string str) 1754 public static string Base64ToString(string str)
1595 { 1755 {
1596 Decoder utf8Decode = Encoding.UTF8.GetDecoder(); 1756 Decoder utf8Decode = Encoding.UTF8.GetDecoder();
@@ -1645,7 +1805,7 @@ namespace OpenSim.Framework
1645 1805
1646 public static Guid GetHashGuid(string data, string salt) 1806 public static Guid GetHashGuid(string data, string salt)
1647 { 1807 {
1648 byte[] hash = ComputeMD5Hash(data + salt); 1808 byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default);
1649 1809
1650 //string s = BitConverter.ToString(hash); 1810 //string s = BitConverter.ToString(hash);
1651 1811
@@ -1792,6 +1952,32 @@ namespace OpenSim.Framework
1792 return found.ToArray(); 1952 return found.ToArray();
1793 } 1953 }
1794 1954
1955 public static string ServerURI(string uri)
1956 {
1957 if (uri == string.Empty)
1958 return string.Empty;
1959
1960 // Get rid of eventual slashes at the end
1961 uri = uri.TrimEnd('/');
1962
1963 IPAddress ipaddr1 = null;
1964 string port1 = "";
1965 try
1966 {
1967 ipaddr1 = Util.GetHostFromURL(uri);
1968 }
1969 catch { }
1970
1971 try
1972 {
1973 port1 = uri.Split(new char[] { ':' })[2];
1974 }
1975 catch { }
1976
1977 // We tried our best to convert the domain names to IP addresses
1978 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri;
1979 }
1980
1795 /// <summary> 1981 /// <summary>
1796 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 256 bytes if necessary. 1982 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 256 bytes if necessary.
1797 /// </summary> 1983 /// </summary>
@@ -1970,6 +2156,11 @@ namespace OpenSim.Framework
1970 } 2156 }
1971 } 2157 }
1972 2158
2159 public static void FireAndForget(System.Threading.WaitCallback callback)
2160 {
2161 FireAndForget(callback, null);
2162 }
2163
1973 public static void InitThreadPool(int minThreads, int maxThreads) 2164 public static void InitThreadPool(int minThreads, int maxThreads)
1974 { 2165 {
1975 if (maxThreads < 2) 2166 if (maxThreads < 2)
@@ -1986,7 +2177,7 @@ namespace OpenSim.Framework
1986 2177
1987 STPStartInfo startInfo = new STPStartInfo(); 2178 STPStartInfo startInfo = new STPStartInfo();
1988 startInfo.ThreadPoolName = "Util"; 2179 startInfo.ThreadPoolName = "Util";
1989 startInfo.IdleTimeout = 2000; 2180 startInfo.IdleTimeout = 20000;
1990 startInfo.MaxWorkerThreads = maxThreads; 2181 startInfo.MaxWorkerThreads = maxThreads;
1991 startInfo.MinWorkerThreads = minThreads; 2182 startInfo.MinWorkerThreads = minThreads;
1992 2183
diff --git a/OpenSim/Framework/VersionInfo.cs b/OpenSim/Framework/VersionInfo.cs
index d2979a7..ea99444 100644
--- a/OpenSim/Framework/VersionInfo.cs
+++ b/OpenSim/Framework/VersionInfo.cs
@@ -29,11 +29,15 @@ namespace OpenSim
29{ 29{
30 public class VersionInfo 30 public class VersionInfo
31 { 31 {
32<<<<<<< HEAD:OpenSim/Framework/VersionInfo.cs
32 public const string VersionNumber = "0.8.2.0"; 33 public const string VersionNumber = "0.8.2.0";
34=======
35 private const string VERSION_NUMBER = "0.8.0CM";
36>>>>>>> avn/ubitvar:OpenSim/Framework/Servers/VersionInfo.cs
33 private const Flavour VERSION_FLAVOUR = Flavour.Dev; 37 private const Flavour VERSION_FLAVOUR = Flavour.Dev;
34 38
35 public enum Flavour 39 public enum Flavour
36 { 40 {
37 Unknown, 41 Unknown,
38 Dev, 42 Dev,
39 RC1, 43 RC1,
@@ -51,7 +55,7 @@ namespace OpenSim
51 55
52 public static string GetVersionString(string versionNumber, Flavour flavour) 56 public static string GetVersionString(string versionNumber, Flavour flavour)
53 { 57 {
54 string versionString = "OpenSim " + versionNumber + " " + flavour; 58 string versionString = "Careminster " + versionNumber + " " + flavour;
55 return versionString.PadRight(VERSIONINFO_VERSION_LENGTH); 59 return versionString.PadRight(VERSIONINFO_VERSION_LENGTH);
56 } 60 }
57 61
diff --git a/OpenSim/Framework/WearableCacheItem.cs b/OpenSim/Framework/WearableCacheItem.cs
index 1aecf79..af28abc 100644
--- a/OpenSim/Framework/WearableCacheItem.cs
+++ b/OpenSim/Framework/WearableCacheItem.cs
@@ -43,12 +43,13 @@ namespace OpenSim.Framework
43 43
44 public static WearableCacheItem[] GetDefaultCacheItem() 44 public static WearableCacheItem[] GetDefaultCacheItem()
45 { 45 {
46 int itemmax = 21; 46 int itemmax = AvatarAppearance.TEXTURE_COUNT;
47 WearableCacheItem[] retitems = new WearableCacheItem[itemmax]; 47 WearableCacheItem[] retitems = new WearableCacheItem[itemmax];
48 for (uint i=0;i<itemmax;i++) 48 for (uint i=0;i<itemmax;i++)
49 retitems[i] = new WearableCacheItem() {CacheId = UUID.Zero, TextureID = UUID.Zero, TextureIndex = i + 1}; 49 retitems[i] = new WearableCacheItem() {CacheId = UUID.Zero, TextureID = UUID.Zero, TextureIndex = i};
50 return retitems; 50 return retitems;
51 } 51 }
52
52 public static WearableCacheItem[] FromOSD(OSD pInput, IImprovedAssetCache dataCache) 53 public static WearableCacheItem[] FromOSD(OSD pInput, IImprovedAssetCache dataCache)
53 { 54 {
54 List<WearableCacheItem> ret = new List<WearableCacheItem>(); 55 List<WearableCacheItem> ret = new List<WearableCacheItem>();
@@ -98,6 +99,7 @@ namespace OpenSim.Framework
98 return ret.ToArray(); 99 return ret.ToArray();
99 100
100 } 101 }
102
101 public static OSD ToOSD(WearableCacheItem[] pcacheItems, IImprovedAssetCache dataCache) 103 public static OSD ToOSD(WearableCacheItem[] pcacheItems, IImprovedAssetCache dataCache)
102 { 104 {
103 OSDArray arr = new OSDArray(); 105 OSDArray arr = new OSDArray();
@@ -124,6 +126,68 @@ namespace OpenSim.Framework
124 } 126 }
125 return arr; 127 return arr;
126 } 128 }
129
130 public static OSDArray BakedToOSD(WearableCacheItem[] pcacheItems)
131 {
132 if (pcacheItems.Length < AvatarAppearance.BAKE_INDICES[AvatarAppearance.BAKE_INDICES.Length - 1])
133 return null;
134
135 OSDArray arr = new OSDArray();
136
137 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++)
138 {
139 int idx = AvatarAppearance.BAKE_INDICES[i];
140
141 WearableCacheItem item = pcacheItems[idx];
142
143 OSDMap itemmap = new OSDMap();
144 itemmap.Add("textureindex", OSD.FromUInteger(item.TextureIndex));
145 itemmap.Add("cacheid", OSD.FromUUID(item.CacheId));
146 itemmap.Add("textureid", OSD.FromUUID(item.TextureID));
147/*
148 if (item.TextureAsset != null)
149 {
150 itemmap.Add("assetdata", OSD.FromBinary(item.TextureAsset.Data));
151 itemmap.Add("assetcreator", OSD.FromString(item.TextureAsset.CreatorID));
152 itemmap.Add("assetname", OSD.FromString(item.TextureAsset.Name));
153 }
154 */
155 arr.Add(itemmap);
156 }
157 return arr;
158 }
159
160 public static WearableCacheItem[] BakedFromOSD(OSD pInput)
161 {
162 WearableCacheItem[] pcache = WearableCacheItem.GetDefaultCacheItem();
163
164 if (pInput.Type == OSDType.Array)
165 {
166 OSDArray itemarray = (OSDArray)pInput;
167 foreach (OSDMap item in itemarray)
168 {
169 int idx = (int)item["textureindex"].AsUInteger();
170 if (idx < 0 || idx > pcache.Length)
171 continue;
172 pcache[idx].CacheId = item["cacheid"].AsUUID();
173 pcache[idx].TextureID = item["textureid"].AsUUID();
174/*
175 if (item.ContainsKey("assetdata"))
176 {
177 AssetBase asset = new AssetBase(item["textureid"].AsUUID(), "BakedTexture", (sbyte)AssetType.Texture, UUID.Zero.ToString());
178 asset.Temporary = true;
179 asset.Local = true;
180 asset.Data = item["assetdata"].AsBinary();
181 pcache[idx].TextureAsset = asset;
182 }
183 else
184 */
185 pcache[idx].TextureAsset = null;
186 }
187 }
188 return pcache;
189 }
190
127 public static WearableCacheItem SearchTextureIndex(uint pTextureIndex,WearableCacheItem[] pcacheItems) 191 public static WearableCacheItem SearchTextureIndex(uint pTextureIndex,WearableCacheItem[] pcacheItems)
128 { 192 {
129 for (int i = 0; i < pcacheItems.Length; i++) 193 for (int i = 0; i < pcacheItems.Length; i++)
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index b180c8a..94b5230 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -86,7 +86,7 @@ namespace OpenSim.Framework
86 /// Number of milliseconds a call can take before it is considered 86 /// Number of milliseconds a call can take before it is considered
87 /// a "long" call for warning & debugging purposes 87 /// a "long" call for warning & debugging purposes
88 /// </summary> 88 /// </summary>
89 public const int LongCallTime = 3000; 89 public const int LongCallTime = 500;
90 90
91 /// <summary> 91 /// <summary>
92 /// The maximum length of any data logged because of a long request time. 92 /// The maximum length of any data logged because of a long request time.
@@ -205,8 +205,16 @@ namespace OpenSim.Framework
205 { 205 {
206 if (DebugLevel == 5) 206 if (DebugLevel == 5)
207 { 207 {
208<<<<<<< HEAD
208 if (output.Length > MaxRequestDiagLength) 209 if (output.Length > MaxRequestDiagLength)
209 output = output.Substring(0, MaxRequestDiagLength) + "..."; 210 output = output.Substring(0, MaxRequestDiagLength) + "...";
211=======
212 int len = output.Length;
213 if(len > 80)
214 len = 80;
215 output = output.Substring(0, len);
216 output = output + "...";
217>>>>>>> avn/ubitvar
210 } 218 }
211 219
212 m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output)); 220 m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output));
@@ -233,6 +241,9 @@ namespace OpenSim.Framework
233 string errorMessage = "unknown error"; 241 string errorMessage = "unknown error";
234 int tickstart = Util.EnvironmentTickCount(); 242 int tickstart = Util.EnvironmentTickCount();
235 int tickdata = 0; 243 int tickdata = 0;
244 int tickcompressdata = 0;
245 int tickJsondata = 0;
246 int compsize = 0;
236 string strBuffer = null; 247 string strBuffer = null;
237 248
238 try 249 try
@@ -250,6 +261,8 @@ namespace OpenSim.Framework
250 { 261 {
251 strBuffer = OSDParser.SerializeJsonString(data); 262 strBuffer = OSDParser.SerializeJsonString(data);
252 263
264 tickJsondata = Util.EnvironmentTickCountSubtract(tickstart);
265
253 if (DebugLevel >= 5) 266 if (DebugLevel >= 5)
254 LogOutgoingDetail("SEND", reqnum, strBuffer); 267 LogOutgoingDetail("SEND", reqnum, strBuffer);
255 268
@@ -271,13 +284,23 @@ namespace OpenSim.Framework
271 // gets written on the stream upon Dispose() 284 // gets written on the stream upon Dispose()
272 } 285 }
273 byte[] buf = ms.ToArray(); 286 byte[] buf = ms.ToArray();
287
288 tickcompressdata = Util.EnvironmentTickCountSubtract(tickstart);
289
274 request.ContentLength = buf.Length; //Count bytes to send 290 request.ContentLength = buf.Length; //Count bytes to send
291 compsize = buf.Length;
275 using (Stream requestStream = request.GetRequestStream()) 292 using (Stream requestStream = request.GetRequestStream())
276 requestStream.Write(buf, 0, (int)buf.Length); 293 requestStream.Write(buf, 0, (int)buf.Length);
277 } 294 }
278 } 295 }
279 else 296 else
280 { 297 {
298<<<<<<< HEAD
299=======
300 tickcompressdata = tickJsondata;
301 compsize = buffer.Length;
302 request.ContentType = "application/json";
303>>>>>>> avn/ubitvar
281 request.ContentLength = buffer.Length; //Count bytes to send 304 request.ContentLength = buffer.Length; //Count bytes to send
282 using (Stream requestStream = request.GetRequestStream()) 305 using (Stream requestStream = request.GetRequestStream())
283 requestStream.Write(buffer, 0, buffer.Length); //Send it 306 requestStream.Write(buffer, 0, buffer.Length); //Send it
@@ -292,6 +315,7 @@ namespace OpenSim.Framework
292 { 315 {
293 using (Stream responseStream = response.GetResponseStream()) 316 using (Stream responseStream = response.GetResponseStream())
294 { 317 {
318<<<<<<< HEAD
295 using (StreamReader reader = new StreamReader(responseStream)) 319 using (StreamReader reader = new StreamReader(responseStream))
296 { 320 {
297 string responseStr = reader.ReadToEnd(); 321 string responseStr = reader.ReadToEnd();
@@ -299,6 +323,12 @@ namespace OpenSim.Framework
299 WebUtil.LogResponseDetail(reqnum, responseStr); 323 WebUtil.LogResponseDetail(reqnum, responseStr);
300 return CanonicalizeResults(responseStr); 324 return CanonicalizeResults(responseStr);
301 } 325 }
326=======
327 string responseStr = null;
328 responseStr = responseStream.GetStreamString();
329 //m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
330 return CanonicalizeResults(responseStr);
331>>>>>>> avn/ubitvar
302 } 332 }
303 } 333 }
304 } 334 }
@@ -314,6 +344,7 @@ namespace OpenSim.Framework
314 catch (Exception ex) 344 catch (Exception ex)
315 { 345 {
316 errorMessage = ex.Message; 346 errorMessage = ex.Message;
347 m_log.Debug("[WEB UTIL]: Exception making request: " + ex.ToString());
317 } 348 }
318 finally 349 finally
319 { 350 {
@@ -321,8 +352,21 @@ namespace OpenSim.Framework
321 if (tickdiff > LongCallTime) 352 if (tickdiff > LongCallTime)
322 { 353 {
323 m_log.InfoFormat( 354 m_log.InfoFormat(
355<<<<<<< HEAD
324 "[LOGHTTP]: Slow JSON-RPC request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 356 "[LOGHTTP]: Slow JSON-RPC request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
325 reqnum, method, url, tickdiff, tickdata, 357 reqnum, method, url, tickdiff, tickdata,
358=======
359 "[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4}ms writing({5} at Json; {6} at comp), {7} bytes ({8} uncomp): {9}",
360 reqnum,
361 method,
362 url,
363 tickdiff,
364 tickdata,
365 tickJsondata,
366 tickcompressdata,
367 compsize,
368 strBuffer != null ? strBuffer.Length : 0,
369>>>>>>> avn/ubitvar
326 strBuffer != null 370 strBuffer != null
327 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) 371 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
328 : ""); 372 : "");
@@ -396,7 +440,7 @@ namespace OpenSim.Framework
396 /// </summary> 440 /// </summary>
397 public static OSDMap PostToService(string url, NameValueCollection data) 441 public static OSDMap PostToService(string url, NameValueCollection data)
398 { 442 {
399 return ServiceFormRequest(url,data,10000); 443 return ServiceFormRequest(url,data, 20000);
400 } 444 }
401 445
402 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) 446 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout)
@@ -790,7 +834,8 @@ namespace OpenSim.Framework
790 reqnum, verb, requestUrl); 834 reqnum, verb, requestUrl);
791 835
792 int tickstart = Util.EnvironmentTickCount(); 836 int tickstart = Util.EnvironmentTickCount();
793 int tickdata = 0; 837// int tickdata = 0;
838 int tickdiff = 0;
794 839
795 Type type = typeof(TRequest); 840 Type type = typeof(TRequest);
796 841
@@ -831,10 +876,17 @@ namespace OpenSim.Framework
831 request.ContentLength = length; 876 request.ContentLength = length;
832 byte[] data = buffer.ToArray(); 877 byte[] data = buffer.ToArray();
833 878
879<<<<<<< HEAD
834 if (WebUtil.DebugLevel >= 5) 880 if (WebUtil.DebugLevel >= 5)
835 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 881 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
836 882
837 request.BeginGetRequestStream(delegate(IAsyncResult res) 883 request.BeginGetRequestStream(delegate(IAsyncResult res)
884=======
885 // capture how much time was spent writing
886 // useless in this async
887// tickdata = Util.EnvironmentTickCountSubtract(tickstart);
888 request.BeginGetResponse(delegate(IAsyncResult ar)
889>>>>>>> avn/ubitvar
838 { 890 {
839 using (Stream requestStream = request.EndGetRequestStream(res)) 891 using (Stream requestStream = request.EndGetRequestStream(res))
840 requestStream.Write(data, 0, length); 892 requestStream.Write(data, 0, length);
@@ -844,6 +896,7 @@ namespace OpenSim.Framework
844 896
845 request.BeginGetResponse(delegate(IAsyncResult ar) 897 request.BeginGetResponse(delegate(IAsyncResult ar)
846 { 898 {
899<<<<<<< HEAD
847 using (WebResponse response = request.EndGetResponse(ar)) 900 using (WebResponse response = request.EndGetResponse(ar))
848 { 901 {
849 try 902 try
@@ -858,6 +911,14 @@ namespace OpenSim.Framework
858 { 911 {
859 } 912 }
860 } 913 }
914=======
915 // Let's not close this
916 // yes do close it
917 buffer.Close();
918 respStream.Close();
919 response.Close();
920 }
921>>>>>>> avn/ubitvar
861 922
862 action(deserial); 923 action(deserial);
863 924
@@ -919,6 +980,7 @@ namespace OpenSim.Framework
919 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}", 980 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}",
920 verb, requestUrl, e.Message, e.StackTrace); 981 verb, requestUrl, e.Message, e.StackTrace);
921 } 982 }
983<<<<<<< HEAD
922 984
923 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString()); 985 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
924 986
@@ -942,12 +1004,36 @@ namespace OpenSim.Framework
942 string originalRequest = null; 1004 string originalRequest = null;
943 1005
944 if (buffer != null) 1006 if (buffer != null)
1007=======
1008 }
1009 catch (Exception e)
1010 {
1011 m_log.ErrorFormat(
1012 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}",
1013 verb, requestUrl, e.Message, e.StackTrace);
1014 }
1015
1016 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
1017 try
1018 {
1019 action(deserial);
1020 }
1021 catch (Exception e)
1022>>>>>>> avn/ubitvar
945 { 1023 {
946 originalRequest = Encoding.UTF8.GetString(buffer.ToArray()); 1024 originalRequest = Encoding.UTF8.GetString(buffer.ToArray());
947 1025
1026<<<<<<< HEAD
948 if (originalRequest.Length > WebUtil.MaxRequestDiagLength) 1027 if (originalRequest.Length > WebUtil.MaxRequestDiagLength)
949 originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength); 1028 originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength);
950 } 1029 }
1030=======
1031 tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
1032 if (tickdiff > WebUtil.LongCallTime)
1033 {
1034/*
1035 string originalRequest = null;
1036>>>>>>> avn/ubitvar
951 1037
952 m_log.InfoFormat( 1038 m_log.InfoFormat(
953 "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 1039 "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
@@ -959,11 +1045,36 @@ namespace OpenSim.Framework
959 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing", 1045 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
960 reqnum, tickdiff, tickdata); 1046 reqnum, tickdiff, tickdata);
961 } 1047 }
1048<<<<<<< HEAD
962 } 1049 }
963 finally 1050 finally
964 { 1051 {
965 if (buffer != null) 1052 if (buffer != null)
966 buffer.Dispose(); 1053 buffer.Dispose();
1054=======
1055
1056 m_log.InfoFormat(
1057 "[ASYNC REQUEST]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
1058 reqnum,
1059 verb,
1060 requestUrl,
1061 tickdiff,
1062 tickdata,
1063 originalRequest);
1064*/
1065 m_log.InfoFormat(
1066 "[ASYNC REQUEST]: Slow WebRequest SETUP <{0}> {1} {2} took {3}ms",
1067 reqnum,
1068 verb,
1069 requestUrl,
1070 tickdiff);
1071 }
1072 else if (WebUtil.DebugLevel >= 4)
1073 {
1074 m_log.DebugFormat(
1075 "[WEB UTIL]: HTTP OUT {0} took {1}ms",
1076 reqnum, tickdiff);
1077>>>>>>> avn/ubitvar
967 } 1078 }
968 } 1079 }
969 } 1080 }
@@ -1004,6 +1115,8 @@ namespace OpenSim.Framework
1004 1115
1005 string respstring = String.Empty; 1116 string respstring = String.Empty;
1006 1117
1118 int tickset = Util.EnvironmentTickCountSubtract(tickstart);
1119
1007 using (MemoryStream buffer = new MemoryStream()) 1120 using (MemoryStream buffer = new MemoryStream())
1008 { 1121 {
1009 if ((verb == "POST") || (verb == "PUT")) 1122 if ((verb == "POST") || (verb == "PUT"))
@@ -1015,14 +1128,19 @@ namespace OpenSim.Framework
1015 { 1128 {
1016 writer.Write(obj); 1129 writer.Write(obj);
1017 writer.Flush(); 1130 writer.Flush();
1131 if (WebUtil.DebugLevel >= 5)
1132 WebUtil.LogOutgoingDetail(buffer);
1018 } 1133 }
1019 1134
1020 length = (int)obj.Length; 1135 length = (int)obj.Length;
1021 request.ContentLength = length; 1136 request.ContentLength = length;
1022 byte[] data = buffer.ToArray(); 1137 byte[] data = buffer.ToArray();
1023 1138
1139<<<<<<< HEAD
1024 if (WebUtil.DebugLevel >= 5) 1140 if (WebUtil.DebugLevel >= 5)
1025 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 1141 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
1142=======
1143>>>>>>> avn/ubitvar
1026 1144
1027 Stream requestStream = null; 1145 Stream requestStream = null;
1028 try 1146 try
@@ -1070,8 +1188,18 @@ namespace OpenSim.Framework
1070 if (tickdiff > WebUtil.LongCallTime) 1188 if (tickdiff > WebUtil.LongCallTime)
1071 { 1189 {
1072 m_log.InfoFormat( 1190 m_log.InfoFormat(
1191<<<<<<< HEAD
1073 "[LOGHTTP]: Slow SynchronousRestForms request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 1192 "[LOGHTTP]: Slow SynchronousRestForms request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
1074 reqnum, verb, requestUrl, tickdiff, tickdata, 1193 reqnum, verb, requestUrl, tickdiff, tickdata,
1194=======
1195 "[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
1196 reqnum,
1197 verb,
1198 requestUrl,
1199 tickdiff,
1200 tickset,
1201 tickdata,
1202>>>>>>> avn/ubitvar
1075 obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj); 1203 obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
1076 } 1204 }
1077 else if (WebUtil.DebugLevel >= 4) 1205 else if (WebUtil.DebugLevel >= 4)
@@ -1208,6 +1336,8 @@ namespace OpenSim.Framework
1208 ht.ServicePoint.ConnectionLimit = maxConnections; 1336 ht.ServicePoint.ConnectionLimit = maxConnections;
1209 1337
1210 request.Method = verb; 1338 request.Method = verb;
1339 if (pTimeout != 0)
1340 request.Timeout = pTimeout * 1000;
1211 MemoryStream buffer = null; 1341 MemoryStream buffer = null;
1212 1342
1213 try 1343 try
@@ -1221,17 +1351,29 @@ namespace OpenSim.Framework
1221 XmlWriterSettings settings = new XmlWriterSettings(); 1351 XmlWriterSettings settings = new XmlWriterSettings();
1222 settings.Encoding = Encoding.UTF8; 1352 settings.Encoding = Encoding.UTF8;
1223 1353
1354<<<<<<< HEAD
1224 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 1355 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
1225 { 1356 {
1226 XmlSerializer serializer = new XmlSerializer(type); 1357 XmlSerializer serializer = new XmlSerializer(type);
1227 serializer.Serialize(writer, obj); 1358 serializer.Serialize(writer, obj);
1228 writer.Flush(); 1359 writer.Flush();
1229 } 1360 }
1361=======
1362 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
1363 {
1364 XmlSerializer serializer = new XmlSerializer(type);
1365 serializer.Serialize(writer, obj);
1366 writer.Flush();
1367 if (WebUtil.DebugLevel >= 5)
1368 WebUtil.LogOutgoingDetail(buffer);
1369 }
1370>>>>>>> avn/ubitvar
1230 1371
1231 int length = (int)buffer.Length; 1372 int length = (int)buffer.Length;
1232 request.ContentLength = length; 1373 request.ContentLength = length;
1233 byte[] data = buffer.ToArray(); 1374 byte[] data = buffer.ToArray();
1234 1375
1376<<<<<<< HEAD
1235 if (WebUtil.DebugLevel >= 5) 1377 if (WebUtil.DebugLevel >= 5)
1236 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 1378 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
1237 1379
@@ -1255,6 +1397,9 @@ namespace OpenSim.Framework
1255 } 1397 }
1256 } 1398 }
1257 1399
1400=======
1401 Stream requestStream = null;
1402>>>>>>> avn/ubitvar
1258 try 1403 try
1259 { 1404 {
1260 using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) 1405 using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs
index bf34419..e441cc8 100644
--- a/OpenSim/Region/Application/Application.cs
+++ b/OpenSim/Region/Application/Application.cs
@@ -75,6 +75,7 @@ namespace OpenSim
75 new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 75 new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
76 76
77 ServicePointManager.DefaultConnectionLimit = 12; 77 ServicePointManager.DefaultConnectionLimit = 12;
78 ServicePointManager.UseNagleAlgorithm = false;
78 79
79 // Add the arguments supplied when running the application to the configuration 80 // Add the arguments supplied when running the application to the configuration
80 ArgvConfigSource configSource = new ArgvConfigSource(args); 81 ArgvConfigSource configSource = new ArgvConfigSource(args);
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 5af8194..a350510 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -109,13 +109,19 @@ namespace OpenSim
109 m_timeInterval = startupConfig.GetInt("timer_Interval", 1200); 109 m_timeInterval = startupConfig.GetInt("timer_Interval", 1200);
110 } 110 }
111 111
112 AvatarWearable.MAX_WEARABLES = startupConfig.GetInt("max_wearables", AvatarWearable.MAX_WEARABLES);
112 string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty); 113 string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
113 FireAndForgetMethod asyncCallMethod; 114 FireAndForgetMethod asyncCallMethod;
114 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod)) 115 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
115 Util.FireAndForgetMethod = asyncCallMethod; 116 Util.FireAndForgetMethod = asyncCallMethod;
116 117
118<<<<<<< HEAD
117 stpMinThreads = startupConfig.GetInt("MinPoolThreads", 15); 119 stpMinThreads = startupConfig.GetInt("MinPoolThreads", 15);
118 stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 300); 120 stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 300);
121=======
122 stpMinThreads = startupConfig.GetInt("MinPoolThreads", 2 );
123 stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 25);
124>>>>>>> avn/ubitvar
119 m_consolePrompt = startupConfig.GetString("ConsolePrompt", @"Region (\R) "); 125 m_consolePrompt = startupConfig.GetString("ConsolePrompt", @"Region (\R) ");
120 } 126 }
121 127
@@ -267,12 +273,20 @@ namespace OpenSim
267 SavePrimsXml2); 273 SavePrimsXml2);
268 274
269 m_console.Commands.AddCommand("Archiving", false, "load oar", 275 m_console.Commands.AddCommand("Archiving", false, "load oar",
276<<<<<<< HEAD
277=======
278
279>>>>>>> avn/ubitvar
270 "load oar [--merge] [--skip-assets]" 280 "load oar [--merge] [--skip-assets]"
271 + " [--default-user \"User Name\"]" 281 + " [--default-user \"User Name\"]"
272 + " [--force-terrain] [--force-parcels]" 282 + " [--force-terrain] [--force-parcels]"
273 + " [--no-objects]" 283 + " [--no-objects]"
274 + " [--rotation degrees] [--rotation-center \"<x,y,z>\"]" 284 + " [--rotation degrees] [--rotation-center \"<x,y,z>\"]"
285<<<<<<< HEAD
275 + " [--displacement \"<x,y,z>\"]" 286 + " [--displacement \"<x,y,z>\"]"
287=======
288 + " [--displacement \"<x,y,z>\"]"
289>>>>>>> avn/ubitvar
276 + " [<OAR path>]", 290 + " [<OAR path>]",
277 "Load a region's data from an OAR archive.", 291 "Load a region's data from an OAR archive.",
278 "--merge will merge the OAR with the existing scene (suppresses terrain and parcel info loading).\n" 292 "--merge will merge the OAR with the existing scene (suppresses terrain and parcel info loading).\n"
@@ -500,7 +514,7 @@ namespace OpenSim
500 if (alert != null) 514 if (alert != null)
501 presence.ControllingClient.Kick(alert); 515 presence.ControllingClient.Kick(alert);
502 else 516 else
503 presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n"); 517 presence.ControllingClient.Kick("\nYou have been logged out by an administrator.\n");
504 518
505 presence.Scene.CloseAgent(presence.UUID, force); 519 presence.Scene.CloseAgent(presence.UUID, force);
506 break; 520 break;
@@ -1028,15 +1042,25 @@ namespace OpenSim
1028 cdt.AddColumn("Circuit code", 12); 1042 cdt.AddColumn("Circuit code", 12);
1029 cdt.AddColumn("Endpoint", 23); 1043 cdt.AddColumn("Endpoint", 23);
1030 cdt.AddColumn("Active?", 7); 1044 cdt.AddColumn("Active?", 7);
1045 cdt.AddColumn("ChildAgent?", 7);
1046 cdt.AddColumn("ping(ms)", 8);
1031 1047
1032 SceneManager.ForEachScene( 1048 SceneManager.ForEachScene(
1033 s => s.ForEachClient( 1049 s => s.ForEachClient(
1034 c => cdt.AddRow( 1050 c =>
1035 s.Name, 1051 {
1036 c.Name, 1052 bool child = false;
1037 c.CircuitCode.ToString(), 1053 if(c.SceneAgent != null && c.SceneAgent.IsChildAgent)
1038 c.RemoteEndPoint.ToString(), 1054 child = true;
1039 c.IsActive.ToString()))); 1055 cdt.AddRow(
1056 s.Name,
1057 c.Name,
1058 c.CircuitCode.ToString(),
1059 c.RemoteEndPoint.ToString(),
1060 c.IsActive.ToString(),
1061 child.ToString(),
1062 c.PingTimeMS);
1063 }));
1040 1064
1041 MainConsole.Instance.Output(cdt.ToString()); 1065 MainConsole.Instance.Output(cdt.ToString());
1042 } 1066 }
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 3be411a..760decd 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -112,6 +112,10 @@ namespace OpenSim
112 112
113 public List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>(); 113 public List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
114 114
115 private List<string> m_permsModules;
116
117 private bool m_securePermissionsLoading = true;
118
115 /// <value> 119 /// <value>
116 /// The config information passed into the OpenSimulator region server. 120 /// The config information passed into the OpenSimulator region server.
117 /// </value> 121 /// </value>
@@ -228,6 +232,14 @@ namespace OpenSim
228 CreatePIDFile(pidFile); 232 CreatePIDFile(pidFile);
229 233
230 userStatsURI = startupConfig.GetString("Stats_URI", String.Empty); 234 userStatsURI = startupConfig.GetString("Stats_URI", String.Empty);
235
236 m_securePermissionsLoading = startupConfig.GetBoolean("SecurePermissionsLoading", true);
237
238 string permissionModules = Util.GetConfigVarFromSections<string>(Config, "permissionmodules",
239 new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
240
241 m_permsModules = new List<string>(permissionModules.Split(','));
242
231 managedStatsURI = startupConfig.GetString("ManagedStatsRemoteFetchURI", String.Empty); 243 managedStatsURI = startupConfig.GetString("ManagedStatsRemoteFetchURI", String.Empty);
232 } 244 }
233 245
@@ -264,11 +276,21 @@ namespace OpenSim
264 276
265 base.StartupSpecific(); 277 base.StartupSpecific();
266 278
279<<<<<<< HEAD
267 if (EnableInitialPluginLoad) 280 if (EnableInitialPluginLoad)
268 LoadPlugins(); 281 LoadPlugins();
269 282
270 // We still want to post initalize any plugins even if loading has been disabled since a test may have 283 // We still want to post initalize any plugins even if loading has been disabled since a test may have
271 // inserted them manually. 284 // inserted them manually.
285=======
286 LoadPlugins();
287
288 if (m_plugins.Count == 0) // We failed to load any modules. Mono Addins glitch!
289 {
290 Environment.Exit(1);
291 }
292
293>>>>>>> avn/ubitvar
272 foreach (IApplicationPlugin plugin in m_plugins) 294 foreach (IApplicationPlugin plugin in m_plugins)
273 plugin.PostInitialise(); 295 plugin.PostInitialise();
274 296
@@ -290,10 +312,10 @@ namespace OpenSim
290 "help " + capitalizedTopic, 312 "help " + capitalizedTopic,
291 "Get help on plugin command '" + topic + "'", 313 "Get help on plugin command '" + topic + "'",
292 HandleCommanderHelp); 314 HandleCommanderHelp);
293 console.Commands.AddCommand(capitalizedTopic, false, "help " + capitalizedTopic, 315// console.Commands.AddCommand(capitalizedTopic, false, "help " + capitalizedTopic,
294 "help " + capitalizedTopic, 316// "help " + capitalizedTopic,
295 "Get help on plugin command '" + topic + "'", 317// "Get help on plugin command '" + topic + "'",
296 HandleCommanderHelp); 318// HandleCommanderHelp);
297 319
298 ICommander commander = null; 320 ICommander commander = null;
299 321
@@ -420,7 +442,32 @@ namespace OpenSim
420 } 442 }
421 else m_log.Error("[REGIONMODULES]: The new RegionModulesController is missing..."); 443 else m_log.Error("[REGIONMODULES]: The new RegionModulesController is missing...");
422 444
445 if (m_securePermissionsLoading)
446 {
447 foreach (string s in m_permsModules)
448 {
449 if (!scene.RegionModules.ContainsKey(s))
450 {
451 m_log.Fatal("[MODULES]: Required module " + s + " not found.");
452 Environment.Exit(0);
453 }
454 }
455
456 m_log.InfoFormat("[SCENE]: Secure permissions loading enabled, modules loaded: {0}", String.Join(" ", m_permsModules.ToArray()));
457 }
458
423 scene.SetModuleInterfaces(); 459 scene.SetModuleInterfaces();
460// First Step of bootreport sequence
461 if (scene.SnmpService != null)
462 {
463 scene.SnmpService.ColdStart(1,scene);
464 scene.SnmpService.LinkDown(scene);
465 }
466
467 if (scene.SnmpService != null)
468 {
469 scene.SnmpService.BootInfo("Loading prins", scene);
470 }
424 471
425 while (regionInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null) 472 while (regionInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null)
426 SetUpEstateOwner(scene); 473 SetUpEstateOwner(scene);
@@ -434,6 +481,11 @@ namespace OpenSim
434 scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID); 481 scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
435 scene.EventManager.TriggerParcelPrimCountUpdate(); 482 scene.EventManager.TriggerParcelPrimCountUpdate();
436 483
484 if (scene.SnmpService != null)
485 {
486 scene.SnmpService.BootInfo("Grid Registration in progress", scene);
487 }
488
437 try 489 try
438 { 490 {
439 scene.RegisterRegionWithGrid(); 491 scene.RegisterRegionWithGrid();
@@ -444,15 +496,29 @@ namespace OpenSim
444 "[STARTUP]: Registration of region with grid failed, aborting startup due to {0} {1}", 496 "[STARTUP]: Registration of region with grid failed, aborting startup due to {0} {1}",
445 e.Message, e.StackTrace); 497 e.Message, e.StackTrace);
446 498
499 if (scene.SnmpService != null)
500 {
501 scene.SnmpService.Critical("Grid registration failed. Startup aborted.", scene);
502 }
447 // Carrying on now causes a lot of confusion down the 503 // Carrying on now causes a lot of confusion down the
448 // line - we need to get the user's attention 504 // line - we need to get the user's attention
449 Environment.Exit(1); 505 Environment.Exit(1);
450 } 506 }
451 507
508 if (scene.SnmpService != null)
509 {
510 scene.SnmpService.BootInfo("Grid Registration done", scene);
511 }
512
452 // We need to do this after we've initialized the 513 // We need to do this after we've initialized the
453 // scripting engines. 514 // scripting engines.
454 scene.CreateScriptInstances(); 515 scene.CreateScriptInstances();
455 516
517 if (scene.SnmpService != null)
518 {
519 scene.SnmpService.BootInfo("ScriptEngine started", scene);
520 }
521
456 SceneManager.Add(scene); 522 SceneManager.Add(scene);
457 523
458 if (m_autoCreateClientStack) 524 if (m_autoCreateClientStack)
@@ -464,10 +530,20 @@ namespace OpenSim
464 } 530 }
465 } 531 }
466 532
533 if (scene.SnmpService != null)
534 {
535 scene.SnmpService.BootInfo("Initializing region modules", scene);
536 }
467 scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); }; 537 scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); };
468 538
469 mscene = scene; 539 mscene = scene;
470 540
541 if (scene.SnmpService != null)
542 {
543 scene.SnmpService.BootInfo("The region is operational", scene);
544 scene.SnmpService.LinkUp(scene);
545 }
546
471 return clientServers; 547 return clientServers;
472 } 548 }
473 549
@@ -583,6 +659,11 @@ namespace OpenSim
583 private void ShutdownRegion(Scene scene) 659 private void ShutdownRegion(Scene scene)
584 { 660 {
585 m_log.DebugFormat("[SHUTDOWN]: Shutting down region {0}", scene.RegionInfo.RegionName); 661 m_log.DebugFormat("[SHUTDOWN]: Shutting down region {0}", scene.RegionInfo.RegionName);
662 if (scene.SnmpService != null)
663 {
664 scene.SnmpService.BootInfo("The region is shutting down", scene);
665 scene.SnmpService.LinkDown(scene);
666 }
586 IRegionModulesController controller; 667 IRegionModulesController controller;
587 if (ApplicationRegistry.TryGet<IRegionModulesController>(out controller)) 668 if (ApplicationRegistry.TryGet<IRegionModulesController>(out controller))
588 { 669 {
@@ -751,7 +832,10 @@ namespace OpenSim
751 { 832 {
752 Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ); 833 Vector3 regionExtent = new Vector3(regionInfo.RegionSizeX, regionInfo.RegionSizeY, regionInfo.RegionSizeZ);
753 PhysicsScene physicsScene = GetPhysicsScene(regionInfo.RegionName, regionExtent); 834 PhysicsScene physicsScene = GetPhysicsScene(regionInfo.RegionName, regionExtent);
835<<<<<<< HEAD
754 836
837=======
838>>>>>>> avn/ubitvar
755 SceneCommunicationService sceneGridService = new SceneCommunicationService(); 839 SceneCommunicationService sceneGridService = new SceneCommunicationService();
756 840
757 return new Scene( 841 return new Scene(
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
index 774202e..4e6d196 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Timers;
29using System.Collections; 30using System.Collections;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.IO; 32using System.IO;
@@ -55,14 +56,16 @@ using PermissionMask = OpenSim.Framework.PermissionMask;
55namespace OpenSim.Region.ClientStack.Linden 56namespace OpenSim.Region.ClientStack.Linden
56{ 57{
57 public delegate void UpLoadedAsset( 58 public delegate void UpLoadedAsset(
58 string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, 59 string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder,
59 byte[] data, string inventoryType, string assetType); 60 byte[] data, string inventoryType, string assetType,
61 int cost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
62 bool IsAtestUpload, ref string error);
60 63
61 public delegate UUID UpdateItem(UUID itemID, byte[] data); 64 public delegate UUID UpdateItem(UUID itemID, byte[] data);
62 65
63 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); 66 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors);
64 67
65 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); 68 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost);
66 69
67 public delegate void NewAsset(AssetBase asset); 70 public delegate void NewAsset(AssetBase asset);
68 71
@@ -88,6 +91,7 @@ namespace OpenSim.Region.ClientStack.Linden
88 91
89 private Scene m_Scene; 92 private Scene m_Scene;
90 private Caps m_HostCapsObj; 93 private Caps m_HostCapsObj;
94 private ModelCost m_ModelCost;
91 95
92 private static readonly string m_requestPath = "0000/"; 96 private static readonly string m_requestPath = "0000/";
93 // private static readonly string m_mapLayerPath = "0001/"; 97 // private static readonly string m_mapLayerPath = "0001/";
@@ -99,8 +103,10 @@ namespace OpenSim.Region.ClientStack.Linden
99 private static readonly string m_copyFromNotecardPath = "0007/"; 103 private static readonly string m_copyFromNotecardPath = "0007/";
100 // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. 104 // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule.
101 private static readonly string m_getObjectPhysicsDataPath = "0101/"; 105 private static readonly string m_getObjectPhysicsDataPath = "0101/";
102 /* 0102 - 0103 RESERVED */ 106 private static readonly string m_getObjectCostPath = "0102/";
107 private static readonly string m_ResourceCostSelectedPath = "0103/";
103 private static readonly string m_UpdateAgentInformationPath = "0500/"; 108 private static readonly string m_UpdateAgentInformationPath = "0500/";
109 private static readonly string m_animSetTaskUpdatePath = "0260/";
104 110
105 // These are callbacks which will be setup by the scene so that we can update scene data when we 111 // These are callbacks which will be setup by the scene so that we can update scene data when we
106 // receive capability calls 112 // receive capability calls
@@ -115,12 +121,50 @@ namespace OpenSim.Region.ClientStack.Linden
115 private IAssetService m_assetService; 121 private IAssetService m_assetService;
116 private bool m_dumpAssetsToFile = false; 122 private bool m_dumpAssetsToFile = false;
117 private string m_regionName; 123 private string m_regionName;
124
118 private int m_levelUpload = 0; 125 private int m_levelUpload = 0;
119 126
127 private bool m_enableFreeTestUpload = false; // allows "TEST-" prefix hack
128 private bool m_ForceFreeTestUpload = false; // forces all uploads to be test
129
130 private bool m_enableModelUploadTextureToInventory = false; // place uploaded textures also in inventory
131 // may not be visible till relog
132
133 private bool m_RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!!
134 private UUID m_testAssetsCreatorID = UUID.Zero;
135
136 private float m_PrimScaleMin = 0.001f;
137
138 private enum FileAgentInventoryState : int
139 {
140 idle = 0,
141 processRequest = 1,
142 waitUpload = 2,
143 processUpload = 3
144 }
145 private FileAgentInventoryState m_FileAgentInventoryState = FileAgentInventoryState.idle;
146
120 public BunchOfCaps(Scene scene, Caps caps) 147 public BunchOfCaps(Scene scene, Caps caps)
121 { 148 {
122 m_Scene = scene; 149 m_Scene = scene;
123 m_HostCapsObj = caps; 150 m_HostCapsObj = caps;
151
152 // create a model upload cost provider
153 m_ModelCost = new ModelCost();
154 // tell it about scene object limits
155 m_ModelCost.NonPhysicalPrimScaleMax = m_Scene.m_maxNonphys;
156 m_ModelCost.PhysicalPrimScaleMax = m_Scene.m_maxPhys;
157
158// m_ModelCost.ObjectLinkedPartsMax = ??
159// m_ModelCost.PrimScaleMin = ??
160
161 m_PrimScaleMin = m_ModelCost.PrimScaleMin;
162 float modelTextureUploadFactor = m_ModelCost.ModelTextureCostFactor;
163 float modelUploadFactor = m_ModelCost.ModelMeshCostFactor;
164 float modelMinUploadCostFactor = m_ModelCost.ModelMinCostFactor;
165 float modelPrimCreationCost = m_ModelCost.primCreationCost;
166 float modelMeshByteCost = m_ModelCost.bytecost;
167
124 IConfigSource config = m_Scene.Config; 168 IConfigSource config = m_Scene.Config;
125 if (config != null) 169 if (config != null)
126 { 170 {
@@ -135,6 +179,37 @@ namespace OpenSim.Region.ClientStack.Linden
135 { 179 {
136 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); 180 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures);
137 } 181 }
182 // economy for model upload
183 IConfig EconomyConfig = config.Configs["Economy"];
184 if (EconomyConfig != null)
185 {
186 modelUploadFactor = EconomyConfig.GetFloat("MeshModelUploadCostFactor", modelUploadFactor);
187 modelTextureUploadFactor = EconomyConfig.GetFloat("MeshModelUploadTextureCostFactor", modelTextureUploadFactor);
188 modelMinUploadCostFactor = EconomyConfig.GetFloat("MeshModelMinCostFactor", modelMinUploadCostFactor);
189 // next 2 are normalized so final cost is afected by modelUploadFactor above and normal cost
190 modelPrimCreationCost = EconomyConfig.GetFloat("ModelPrimCreationCost", modelPrimCreationCost);
191 modelMeshByteCost = EconomyConfig.GetFloat("ModelMeshByteCost", modelMeshByteCost);
192
193 m_enableModelUploadTextureToInventory = EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", m_enableModelUploadTextureToInventory);
194
195 m_RestrictFreeTestUploadPerms = EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", m_RestrictFreeTestUploadPerms);
196 m_enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", m_enableFreeTestUpload);
197 m_ForceFreeTestUpload = EconomyConfig.GetBoolean("ForceFreeTestUpload", m_ForceFreeTestUpload);
198 string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", "");
199 if (testcreator != "")
200 {
201 UUID id;
202 UUID.TryParse(testcreator, out id);
203 if (id != null)
204 m_testAssetsCreatorID = id;
205 }
206
207 m_ModelCost.ModelMeshCostFactor = modelUploadFactor;
208 m_ModelCost.ModelTextureCostFactor = modelTextureUploadFactor;
209 m_ModelCost.ModelMinCostFactor = modelMinUploadCostFactor;
210 m_ModelCost.primCreationCost = modelPrimCreationCost;
211 m_ModelCost.bytecost = modelMeshByteCost;
212 }
138 } 213 }
139 214
140 m_assetService = m_Scene.AssetService; 215 m_assetService = m_Scene.AssetService;
@@ -146,6 +221,8 @@ namespace OpenSim.Region.ClientStack.Linden
146 ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; 221 ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset;
147 TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; 222 TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset;
148 GetClient = m_Scene.SceneGraph.GetControllingClient; 223 GetClient = m_Scene.SceneGraph.GetControllingClient;
224
225 m_FileAgentInventoryState = FileAgentInventoryState.idle;
149 } 226 }
150 227
151 /// <summary> 228 /// <summary>
@@ -173,13 +250,31 @@ namespace OpenSim.Region.ClientStack.Linden
173 //m_capsHandlers["MapLayer"] = 250 //m_capsHandlers["MapLayer"] =
174 // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST", 251 // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST",
175 // capsBase + m_mapLayerPath, 252 // capsBase + m_mapLayerPath,
176 // GetMapLayer); 253 // GetMapLayer);
254
255 IRequestHandler getObjectPhysicsDataHandler
256 = new RestStreamHandler(
257 "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null);
258 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler);
259
260 IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost);
261 m_HostCapsObj.RegisterHandler("GetObjectCost", getObjectCostHandler);
262 IRequestHandler ResourceCostSelectedHandler = new RestStreamHandler("POST", capsBase + m_ResourceCostSelectedPath, ResourceCostSelected);
263 m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler);
264
265
177 IRequestHandler req 266 IRequestHandler req
178 = new RestStreamHandler( 267 = new RestStreamHandler(
179 "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null); 268 "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null);
180 269
181 m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); 270 m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req);
182 m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); 271 m_HostCapsObj.RegisterHandler("UpdateScriptTask", req);
272
273// IRequestHandler animSetRequestHandler
274// = new RestStreamHandler(
275// "POST", capsBase + m_animSetTaskUpdatePath, AnimSetTaskInventory, "UpdateScript", null);
276
277// m_HostCapsObj.RegisterHandler("UpdateAnimSetTaskInventory", animSetRequestHandler);
183 } 278 }
184 catch (Exception e) 279 catch (Exception e)
185 { 280 {
@@ -191,7 +286,6 @@ namespace OpenSim.Region.ClientStack.Linden
191 { 286 {
192 try 287 try
193 { 288 {
194 // I don't think this one works...
195 m_HostCapsObj.RegisterHandler( 289 m_HostCapsObj.RegisterHandler(
196 "NewFileAgentInventory", 290 "NewFileAgentInventory",
197 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( 291 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>(
@@ -206,13 +300,11 @@ namespace OpenSim.Region.ClientStack.Linden
206 "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null); 300 "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null);
207 301
208 m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req); 302 m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req);
303 m_HostCapsObj.RegisterHandler("UpdateAnimSetAgentInventory", req);
209 m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req); 304 m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req);
210 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); 305 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req);
211 306
212 IRequestHandler getObjectPhysicsDataHandler 307
213 = new RestStreamHandler(
214 "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null);
215 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler);
216 308
217 IRequestHandler UpdateAgentInformationHandler 309 IRequestHandler UpdateAgentInformationHandler
218 = new RestStreamHandler( 310 = new RestStreamHandler(
@@ -271,6 +363,9 @@ namespace OpenSim.Region.ClientStack.Linden
271// m_log.DebugFormat( 363// m_log.DebugFormat(
272// "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); 364// "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID);
273 365
366 if (!m_HostCapsObj.WaitForActivation())
367 return string.Empty;
368
274 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) 369 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
275 { 370 {
276 m_log.WarnFormat( 371 m_log.WarnFormat(
@@ -400,62 +495,178 @@ namespace OpenSim.Region.ClientStack.Linden
400 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); 495 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString());
401 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); 496 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type);
402 497
498 // start by getting the client
499 IClientAPI client = null;
500 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
501
502 // check current state so we only have one service at a time
503 lock (m_ModelCost)
504 {
505 switch (m_FileAgentInventoryState)
506 {
507 case FileAgentInventoryState.processRequest:
508 case FileAgentInventoryState.processUpload:
509 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
510 resperror.message = "Uploader busy processing previus request";
511 resperror.identifier = UUID.Zero;
512
513 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
514 errorResponse.uploader = "";
515 errorResponse.state = "error";
516 errorResponse.error = resperror;
517 return errorResponse;
518 break;
519 case FileAgentInventoryState.waitUpload:
520 // todo stop current uploader server
521 break;
522 case FileAgentInventoryState.idle:
523 default:
524 break;
525 }
526
527 m_FileAgentInventoryState = FileAgentInventoryState.processRequest;
528 }
529
530 int cost = 0;
531 int nreqtextures = 0;
532 int nreqmeshs= 0;
533 int nreqinstances = 0;
534 bool IsAtestUpload = false;
535
536 string assetName = llsdRequest.name;
537
538 LLSDAssetUploadResponseData meshcostdata = new LLSDAssetUploadResponseData();
539
403 if (llsdRequest.asset_type == "texture" || 540 if (llsdRequest.asset_type == "texture" ||
404 llsdRequest.asset_type == "animation" || 541 llsdRequest.asset_type == "animation" ||
542 llsdRequest.asset_type == "animatn" || // this is the asset name actually used by viewers
543 llsdRequest.asset_type == "mesh" ||
405 llsdRequest.asset_type == "sound") 544 llsdRequest.asset_type == "sound")
406 { 545 {
407 ScenePresence avatar = null; 546 ScenePresence avatar = null;
408 IClientAPI client = null;
409 m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); 547 m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar);
410 548
411 // check user level 549 // check user level
412 if (avatar != null) 550 if (avatar != null)
413 { 551 {
414 client = avatar.ControllingClient;
415
416 if (avatar.UserLevel < m_levelUpload) 552 if (avatar.UserLevel < m_levelUpload)
417 { 553 {
418 if (client != null) 554 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
419 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); 555 resperror.message = "Insufficient permissions to upload";
556 resperror.identifier = UUID.Zero;
420 557
421 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); 558 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
422 errorResponse.uploader = ""; 559 errorResponse.uploader = "";
423 errorResponse.state = "error"; 560 errorResponse.state = "error";
561 errorResponse.error = resperror;
562 lock (m_ModelCost)
563 m_FileAgentInventoryState = FileAgentInventoryState.idle;
424 return errorResponse; 564 return errorResponse;
425 } 565 }
426 } 566 }
427 567
428 // check funds 568 // check test upload and funds
429 if (client != null) 569 if (client != null)
430 { 570 {
431 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); 571 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
432 572
573 int baseCost = 0;
433 if (mm != null) 574 if (mm != null)
575 baseCost = mm.UploadCharge;
576
577 string warning = String.Empty;
578
579 if (llsdRequest.asset_type == "mesh")
434 { 580 {
435 if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) 581 string error;
582 int modelcost;
583
584
585 if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost,
586 meshcostdata, out error, ref warning))
436 { 587 {
437 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); 588 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
589 resperror.message = error;
590 resperror.identifier = UUID.Zero;
438 591
439 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); 592 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
440 errorResponse.uploader = ""; 593 errorResponse.uploader = "";
441 errorResponse.state = "error"; 594 errorResponse.state = "error";
595 errorResponse.error = resperror;
596
597 lock (m_ModelCost)
598 m_FileAgentInventoryState = FileAgentInventoryState.idle;
442 return errorResponse; 599 return errorResponse;
443 } 600 }
601 cost = modelcost;
444 } 602 }
603 else
604 {
605 cost = baseCost;
606 }
607
608 if (cost > 0 && mm != null)
609 {
610 // check for test upload
611
612 if (m_ForceFreeTestUpload) // all are test
613 {
614 if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it
615 assetName = "TEST-" + assetName;
616
617 IsAtestUpload = true;
618 }
619
620 else if (m_enableFreeTestUpload) // only if prefixed with "TEST-"
621 {
622
623 IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-"));
624 }
625
626
627 if(IsAtestUpload) // let user know, still showing cost estimation
628 warning += "Upload will have no cost, for testing purposes only. Other uses are prohibited. Items will not work after 48 hours or on other regions";
629
630 // check funds
631 else
632 {
633 if (!mm.UploadCovered(client.AgentId, (int)cost))
634 {
635 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
636 resperror.message = "Insuficient funds";
637 resperror.identifier = UUID.Zero;
638
639 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
640 errorResponse.uploader = "";
641 errorResponse.state = "error";
642 errorResponse.error = resperror;
643 lock (m_ModelCost)
644 m_FileAgentInventoryState = FileAgentInventoryState.idle;
645 return errorResponse;
646 }
647 }
648 }
649
650 if (client != null && warning != String.Empty)
651 client.SendAgentAlertMessage(warning, true);
445 } 652 }
446 } 653 }
447 654
448 string assetName = llsdRequest.name;
449 string assetDes = llsdRequest.description; 655 string assetDes = llsdRequest.description;
450 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; 656 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
451 UUID newAsset = UUID.Random(); 657 UUID newAsset = UUID.Random();
452 UUID newInvItem = UUID.Random(); 658 UUID newInvItem = UUID.Random();
453 UUID parentFolder = llsdRequest.folder_id; 659 UUID parentFolder = llsdRequest.folder_id;
454 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 660 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
661 UUID texturesFolder = UUID.Zero;
662
663 if(!IsAtestUpload && m_enableModelUploadTextureToInventory)
664 texturesFolder = llsdRequest.texture_folder_id;
455 665
456 AssetUploader uploader = 666 AssetUploader uploader =
457 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, 667 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
458 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); 668 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost,
669 texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload);
459 670
460 m_HostCapsObj.HttpListener.AddStreamHandler( 671 m_HostCapsObj.HttpListener.AddStreamHandler(
461 new BinaryStreamHandler( 672 new BinaryStreamHandler(
@@ -473,10 +684,22 @@ namespace OpenSim.Region.ClientStack.Linden
473 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + 684 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
474 uploaderPath; 685 uploaderPath;
475 686
687
476 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); 688 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
477 uploadResponse.uploader = uploaderURL; 689 uploadResponse.uploader = uploaderURL;
478 uploadResponse.state = "upload"; 690 uploadResponse.state = "upload";
691 uploadResponse.upload_price = (int)cost;
692
693 if (llsdRequest.asset_type == "mesh")
694 {
695 uploadResponse.data = meshcostdata;
696 }
697
479 uploader.OnUpLoad += UploadCompleteHandler; 698 uploader.OnUpLoad += UploadCompleteHandler;
699
700 lock (m_ModelCost)
701 m_FileAgentInventoryState = FileAgentInventoryState.waitUpload;
702
480 return uploadResponse; 703 return uploadResponse;
481 } 704 }
482 705
@@ -488,8 +711,14 @@ namespace OpenSim.Region.ClientStack.Linden
488 /// <param name="data"></param> 711 /// <param name="data"></param>
489 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, 712 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
490 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, 713 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
491 string assetType) 714 string assetType, int cost,
715 UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
716 bool IsAtestUpload, ref string error)
492 { 717 {
718
719 lock (m_ModelCost)
720 m_FileAgentInventoryState = FileAgentInventoryState.processUpload;
721
493 m_log.DebugFormat( 722 m_log.DebugFormat(
494 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", 723 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}",
495 assetID, inventoryItem, inventoryType, assetType); 724 assetID, inventoryItem, inventoryType, assetType);
@@ -497,6 +726,34 @@ namespace OpenSim.Region.ClientStack.Linden
497 sbyte assType = 0; 726 sbyte assType = 0;
498 sbyte inType = 0; 727 sbyte inType = 0;
499 728
729 IClientAPI client = null;
730
731 UUID owner_id = m_HostCapsObj.AgentID;
732 UUID creatorID;
733
734 bool istest = IsAtestUpload && m_enableFreeTestUpload && (cost > 0);
735
736 bool restrictPerms = m_RestrictFreeTestUploadPerms && istest;
737
738 if (istest && m_testAssetsCreatorID != UUID.Zero)
739 creatorID = m_testAssetsCreatorID;
740 else
741 creatorID = owner_id;
742
743 string creatorIDstr = creatorID.ToString();
744
745 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
746 if (mm != null)
747 {
748 // make sure client still has enougth credit
749 if (!mm.UploadCovered(m_HostCapsObj.AgentID, (int)cost))
750 {
751 error = "Insufficient funds.";
752 return;
753 }
754 }
755
756 // strings to types
500 if (inventoryType == "sound") 757 if (inventoryType == "sound")
501 { 758 {
502 inType = (sbyte)InventoryType.Sound; 759 inType = (sbyte)InventoryType.Sound;
@@ -511,6 +768,12 @@ namespace OpenSim.Region.ClientStack.Linden
511 inType = (sbyte)InventoryType.Animation; 768 inType = (sbyte)InventoryType.Animation;
512 assType = (sbyte)AssetType.Animation; 769 assType = (sbyte)AssetType.Animation;
513 } 770 }
771 else if (inventoryType == "animset")
772 {
773 inType = (sbyte)CustomInventoryType.AnimationSet;
774 assType = (sbyte)CustomAssetType.AnimationSet;
775 m_log.Debug("got animset upload request");
776 }
514 else if (inventoryType == "wearable") 777 else if (inventoryType == "wearable")
515 { 778 {
516 inType = (sbyte)InventoryType.Wearable; 779 inType = (sbyte)InventoryType.Wearable;
@@ -526,6 +789,7 @@ namespace OpenSim.Region.ClientStack.Linden
526 } 789 }
527 else if (inventoryType == "object") 790 else if (inventoryType == "object")
528 { 791 {
792<<<<<<< HEAD
529 inType = (sbyte)InventoryType.Object; 793 inType = (sbyte)InventoryType.Object;
530 assType = (sbyte)AssetType.Object; 794 assType = (sbyte)AssetType.Object;
531 795
@@ -612,73 +876,255 @@ namespace OpenSim.Region.ClientStack.Linden
612 { 876 {
613 clientInv.SendBulkUpdateInventory(foldersToUpdate.ToArray(), itemsToUpdate.ToArray()); 877 clientInv.SendBulkUpdateInventory(foldersToUpdate.ToArray(), itemsToUpdate.ToArray());
614 } 878 }
615 879=======
616 for (int i = 0; i < mesh_list.Count; i++) 880 if (assetType == "mesh") // this code for now is for mesh models uploads only
617 { 881 {
618 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); 882 inType = (sbyte)InventoryType.Object;
883 assType = (sbyte)AssetType.Object;
884>>>>>>> avn/ubitvar
619 885
620 Primitive.TextureEntry textureEntry 886 List<Vector3> positions = new List<Vector3>();
621 = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); 887 List<Quaternion> rotations = new List<Quaternion>();
622 OSDMap inner_instance_list = (OSDMap)instance_list[i]; 888 OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data);
889
890 // compare and get updated information
891/* does nothing still we do need something to avoid special viewer to upload something diferent from the cost estimation
892 bool mismatchError = true;
893
894 while (mismatchError)
895 {
896 mismatchError = false;
897 }
623 898
624 OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; 899 if (mismatchError)
625 for (uint face = 0; face < face_list.Count; face++)
626 { 900 {
627 OSDMap faceMap = (OSDMap)face_list[(int)face]; 901 error = "Upload and fee estimation information don't match";
628 Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); 902 lock (m_ModelCost)
629 if(faceMap.ContainsKey("fullbright")) 903 m_FileAgentInventoryState = FileAgentInventoryState.idle;
630 f.Fullbright = faceMap["fullbright"].AsBoolean();
631 if (faceMap.ContainsKey ("diffuse_color"))
632 f.RGBA = faceMap["diffuse_color"].AsColor4();
633 904
634 int textureNum = faceMap["image"].AsInteger(); 905 return;
635 float imagerot = faceMap["imagerot"].AsInteger(); 906 }
636 float offsets = (float)faceMap["offsets"].AsReal(); 907*/
637 float offsett = (float)faceMap["offsett"].AsReal(); 908 OSDArray instance_list = (OSDArray)request["instance_list"];
638 float scales = (float)faceMap["scales"].AsReal(); 909 OSDArray mesh_list = (OSDArray)request["mesh_list"];
639 float scalet = (float)faceMap["scalet"].AsReal(); 910 OSDArray texture_list = (OSDArray)request["texture_list"];
911 SceneObjectGroup grp = null;
640 912
641 if(imagerot != 0) 913 // create and store texture assets
642 f.Rotation = imagerot; 914 bool doTextInv = (!istest && m_enableModelUploadTextureToInventory &&
915 texturesFolder != UUID.Zero);
643 916
644 if(offsets != 0)
645 f.OffsetU = offsets;
646 917
647 if (offsett != 0) 918 List<UUID> textures = new List<UUID>();
648 f.OffsetV = offsett;
649 919
650 if (scales != 0) 920
651 f.RepeatU = scales; 921// if (doTextInv)
922 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
652 923
653 if (scalet != 0) 924 if(client == null) // don't put textures in inventory if there is no client
654 f.RepeatV = scalet; 925 doTextInv = false;
655 926
656 if (textures.Count > textureNum) 927 for (int i = 0; i < texture_list.Count; i++)
657 f.TextureID = textures[textureNum]; 928 {
658 else 929 AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, creatorIDstr);
659 f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; 930 textureAsset.Data = texture_list[i].AsBinary();
931 if (istest)
932 textureAsset.Local = true;
933 m_assetService.Store(textureAsset);
934 textures.Add(textureAsset.FullID);
935
936 if (doTextInv)
937 {
938 string name = assetName;
939 if (name.Length > 25)
940 name = name.Substring(0, 24);
941 name += "_Texture#" + i.ToString();
942 InventoryItemBase texitem = new InventoryItemBase();
943 texitem.Owner = m_HostCapsObj.AgentID;
944 texitem.CreatorId = creatorIDstr;
945 texitem.CreatorData = String.Empty;
946 texitem.ID = UUID.Random();
947 texitem.AssetID = textureAsset.FullID;
948 texitem.Description = "mesh model texture";
949 texitem.Name = name;
950 texitem.AssetType = (int)AssetType.Texture;
951 texitem.InvType = (int)InventoryType.Texture;
952 texitem.Folder = texturesFolder;
953
954 texitem.CurrentPermissions
955 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export);
956
957 texitem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
958 texitem.EveryOnePermissions = 0;
959 texitem.NextPermissions = (uint)PermissionMask.All;
960 texitem.CreationDate = Util.UnixTimeSinceEpoch();
961
962 m_Scene.AddInventoryItem(client, texitem);
963 texitem = null;
964 }
965 }
966
967 // create and store meshs assets
968 List<UUID> meshAssets = new List<UUID>();
969 List<bool> meshAvatarSkeletons = new List<bool>();
970 List<bool> meshAvatarColliders = new List<bool>();
971
972 bool curAvSkeleton;
973 bool curAvCollider;
974 for (int i = 0; i < mesh_list.Count; i++)
975 {
976 curAvSkeleton = false;
977 curAvCollider = false;
660 978
661 textureEntry.FaceTextures[face] = f; 979 // we do need to parse the mesh now
980 OSD osd = OSDParser.DeserializeLLSDBinary(mesh_list[i]);
981 if (osd is OSDMap)
982 {
983 OSDMap mosd = (OSDMap)osd;
984 if (mosd.ContainsKey("skeleton"))
985 {
986 OSDMap skeleton = (OSDMap)mosd["skeleton"];
987 int sksize = skeleton["size"].AsInteger();
988 if (sksize > 0)
989 curAvSkeleton = true;
990 }
991 }
992
993 AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, creatorIDstr);
994 meshAsset.Data = mesh_list[i].AsBinary();
995 if (istest)
996 meshAsset.Local = true;
997 m_assetService.Store(meshAsset);
998 meshAssets.Add(meshAsset.FullID);
999 meshAvatarSkeletons.Add(curAvSkeleton);
1000 meshAvatarColliders.Add(curAvCollider);
1001
1002 // test code
1003 if (curAvSkeleton && client != null)
1004 {
1005 string name = assetName;
1006 if (name.Length > 25)
1007 name = name.Substring(0, 24);
1008 name += "_Mesh#" + i.ToString();
1009 InventoryItemBase meshitem = new InventoryItemBase();
1010 meshitem.Owner = m_HostCapsObj.AgentID;
1011 meshitem.CreatorId = creatorIDstr;
1012 meshitem.CreatorData = String.Empty;
1013 meshitem.ID = UUID.Random();
1014 meshitem.AssetID = meshAsset.FullID;
1015 meshitem.Description = "mesh ";
1016 meshitem.Name = name;
1017 meshitem.AssetType = (int)AssetType.Mesh;
1018 meshitem.InvType = (int)InventoryType.Mesh;
1019 // meshitem.Folder = UUID.Zero; // send to default
1020
1021 meshitem.Folder = parentFolder; // dont let it go to folder Meshes that viewers dont show
1022
1023 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current
1024 // (owner) permissions. This becomes a problem if next permissions are changed.
1025 meshitem.CurrentPermissions
1026 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
1027
1028 meshitem.BasePermissions = (uint)PermissionMask.All;
1029 meshitem.EveryOnePermissions = 0;
1030 meshitem.NextPermissions = (uint)PermissionMask.All;
1031 meshitem.CreationDate = Util.UnixTimeSinceEpoch();
1032
1033 m_Scene.AddInventoryItem(client, meshitem);
1034 meshitem = null;
1035 }
662 } 1036 }
663 1037
664 pbs.TextureEntry = textureEntry.GetBytes(); 1038 int skipedMeshs = 0;
1039 // build prims from instances
1040 for (int i = 0; i < instance_list.Count; i++)
1041 {
1042 OSDMap inner_instance_list = (OSDMap)instance_list[i];
665 1043
666 AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, ""); 1044 // skip prims that are 2 small
667 meshAsset.Data = mesh_list[i].AsBinary(); 1045 Vector3 scale = inner_instance_list["scale"].AsVector3();
668 m_assetService.Store(meshAsset);
669 1046
670 pbs.SculptEntry = true; 1047 if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin)
671 pbs.SculptTexture = meshAsset.FullID; 1048 {
672 pbs.SculptType = (byte)SculptType.Mesh; 1049 skipedMeshs++;
673 pbs.SculptData = meshAsset.Data; 1050 continue;
1051 }
1052
1053 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
1054
1055 Primitive.TextureEntry textureEntry
1056 = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
1057
1058
1059 OSDArray face_list = (OSDArray)inner_instance_list["face_list"];
1060 for (uint face = 0; face < face_list.Count; face++)
1061 {
1062 OSDMap faceMap = (OSDMap)face_list[(int)face];
1063 Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
1064 if (faceMap.ContainsKey("fullbright"))
1065 f.Fullbright = faceMap["fullbright"].AsBoolean();
1066 if (faceMap.ContainsKey("diffuse_color"))
1067 f.RGBA = faceMap["diffuse_color"].AsColor4();
1068
1069 int textureNum = faceMap["image"].AsInteger();
1070 float imagerot = faceMap["imagerot"].AsInteger();
1071 float offsets = (float)faceMap["offsets"].AsReal();
1072 float offsett = (float)faceMap["offsett"].AsReal();
1073 float scales = (float)faceMap["scales"].AsReal();
1074 float scalet = (float)faceMap["scalet"].AsReal();
1075
1076 if (imagerot != 0)
1077 f.Rotation = imagerot;
1078
1079 if (offsets != 0)
1080 f.OffsetU = offsets;
674 1081
675 Vector3 position = inner_instance_list["position"].AsVector3(); 1082 if (offsett != 0)
676 Vector3 scale = inner_instance_list["scale"].AsVector3(); 1083 f.OffsetV = offsett;
677 Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); 1084
1085 if (scales != 0)
1086 f.RepeatU = scales;
1087
1088 if (scalet != 0)
1089 f.RepeatV = scalet;
1090
1091 if (textures.Count > textureNum)
1092 f.TextureID = textures[textureNum];
1093 else
1094 f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE;
1095
1096 textureEntry.FaceTextures[face] = f;
1097 }
1098
1099 pbs.TextureEntry = textureEntry.GetBytes();
1100
1101 bool hasmesh = false;
1102 if (inner_instance_list.ContainsKey("mesh")) // seems to happen always but ...
1103 {
1104 int meshindx = inner_instance_list["mesh"].AsInteger();
1105 if (meshAssets.Count > meshindx)
1106 {
1107 pbs.SculptEntry = true;
1108 pbs.SculptType = (byte)SculptType.Mesh;
1109 pbs.SculptTexture = meshAssets[meshindx]; // actual asset UUID after meshs suport introduction
1110 // data will be requested from asset on rez (i hope)
1111 hasmesh = true;
1112 }
1113 }
1114
1115 Vector3 position = inner_instance_list["position"].AsVector3();
1116 Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();
1117
1118 // for now viwers do send fixed defaults
1119 // but this may change
1120// int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
1121 byte physicsShapeType = (byte)PhysShapeType.prim; // default for mesh is simple convex
1122 if(hasmesh)
1123 physicsShapeType = (byte) PhysShapeType.convex; // default for mesh is simple convex
1124// int material = inner_instance_list["material"].AsInteger();
1125 byte material = (byte)Material.Wood;
678 1126
679// no longer used - begin ------------------------ 1127// no longer used - begin ------------------------
680// int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
681// int material = inner_instance_list["material"].AsInteger();
682// int mesh = inner_instance_list["mesh"].AsInteger(); 1128// int mesh = inner_instance_list["mesh"].AsInteger();
683 1129
684// OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; 1130// OSDMap permissions = (OSDMap)inner_instance_list["permissions"];
@@ -693,24 +1139,49 @@ namespace OpenSim.Region.ClientStack.Linden
693// UUID owner_id = permissions["owner_id"].AsUUID(); 1139// UUID owner_id = permissions["owner_id"].AsUUID();
694// int owner_mask = permissions["owner_mask"].AsInteger(); 1140// int owner_mask = permissions["owner_mask"].AsInteger();
695// no longer used - end ------------------------ 1141// no longer used - end ------------------------
1142
1143
1144 SceneObjectPart prim
1145 = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero);
1146
1147 prim.Scale = scale;
1148 rotations.Add(rotation);
1149 positions.Add(position);
1150 prim.UUID = UUID.Random();
1151 prim.CreatorID = creatorID;
1152 prim.OwnerID = owner_id;
1153 prim.GroupID = UUID.Zero;
1154 prim.LastOwnerID = creatorID;
1155 prim.CreationDate = Util.UnixTimeSinceEpoch();
1156
1157 if (grp == null)
1158 prim.Name = assetName;
1159 else
1160 prim.Name = assetName + "#" + i.ToString();
696 1161
697 UUID owner_id = m_HostCapsObj.AgentID; 1162 prim.EveryoneMask = 0;
1163 prim.GroupMask = 0;
1164
1165 if (restrictPerms)
1166 {
1167 prim.BaseMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
1168 prim.OwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
1169 prim.NextOwnerMask = 0;
1170 }
1171 else
1172 {
1173 prim.BaseMask = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1174 prim.OwnerMask = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1175 prim.NextOwnerMask = (uint)PermissionMask.Transfer;
1176 }
698 1177
699 SceneObjectPart prim 1178 if(istest)
700 = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); 1179 prim.Description = "For testing only. Other uses are prohibited";
1180 else
1181 prim.Description = "";
701 1182
702 prim.Scale = scale; 1183 prim.Material = material;
703 //prim.OffsetPosition = position; 1184 prim.PhysicsShapeType = physicsShapeType;
704 rotations.Add(rotation);
705 positions.Add(position);
706 prim.UUID = UUID.Random();
707 prim.CreatorID = owner_id;
708 prim.OwnerID = owner_id;
709 prim.GroupID = UUID.Zero;
710 prim.LastOwnerID = prim.OwnerID;
711 prim.CreationDate = Util.UnixTimeSinceEpoch();
712 prim.Name = assetName;
713 prim.Description = "";
714 1185
715// prim.BaseMask = (uint)base_mask; 1186// prim.BaseMask = (uint)base_mask;
716// prim.EveryoneMask = (uint)everyone_mask; 1187// prim.EveryoneMask = (uint)everyone_mask;
@@ -718,52 +1189,64 @@ namespace OpenSim.Region.ClientStack.Linden
718// prim.NextOwnerMask = (uint)next_owner_mask; 1189// prim.NextOwnerMask = (uint)next_owner_mask;
719// prim.OwnerMask = (uint)owner_mask; 1190// prim.OwnerMask = (uint)owner_mask;
720 1191
721 if (grp == null) 1192 if (grp == null)
722 grp = new SceneObjectGroup(prim); 1193 {
723 else 1194 grp = new SceneObjectGroup(prim);
724 grp.AddPart(prim); 1195 grp.LastOwnerID = creatorID;
725 } 1196 }
1197 else
1198 grp.AddPart(prim);
1199 }
726 1200
727 Vector3 rootPos = positions[0]; 1201 Vector3 rootPos = positions[0];
728 1202
729 if (grp.Parts.Length > 1) 1203 if (grp.Parts.Length > 1)
730 { 1204 {
731 // Fix first link number 1205 // Fix first link number
732 grp.RootPart.LinkNum++; 1206 grp.RootPart.LinkNum++;
733 1207
734 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); 1208 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]);
735 Quaternion tmprot; 1209 Quaternion tmprot;
736 Vector3 offset; 1210 Vector3 offset;
737 1211
738 // fix children rotations and positions 1212 // fix children rotations and positions
739 for (int i = 1; i < rotations.Count; i++) 1213 for (int i = 1; i < rotations.Count; i++)
740 { 1214 {
741 tmprot = rotations[i]; 1215 tmprot = rotations[i];
742 tmprot = rootRotConj * tmprot; 1216 tmprot = rootRotConj * tmprot;
1217
1218 grp.Parts[i].RotationOffset = tmprot;
743 1219
744 grp.Parts[i].RotationOffset = tmprot; 1220 offset = positions[i] - rootPos;
745 1221
746 offset = positions[i] - rootPos; 1222 offset *= rootRotConj;
1223 grp.Parts[i].OffsetPosition = offset;
1224 }
747 1225
748 offset *= rootRotConj; 1226 grp.AbsolutePosition = rootPos;
749 grp.Parts[i].OffsetPosition = offset; 1227 grp.UpdateGroupRotationR(rotations[0]);
1228 }
1229 else
1230 {
1231 grp.AbsolutePosition = rootPos;
1232 grp.UpdateGroupRotationR(rotations[0]);
750 } 1233 }
751 1234
752 grp.AbsolutePosition = rootPos; 1235 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
753 grp.UpdateGroupRotationR(rotations[0]);
754 } 1236 }
755 else 1237
1238 else // not a mesh model
756 { 1239 {
757 grp.AbsolutePosition = rootPos; 1240 m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload");
758 grp.UpdateGroupRotationR(rotations[0]); 1241 return;
759 } 1242 }
760
761 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
762 } 1243 }
763 1244
764 AssetBase asset; 1245 AssetBase asset;
765 asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); 1246 asset = new AssetBase(assetID, assetName, assType, creatorIDstr);
766 asset.Data = data; 1247 asset.Data = data;
1248 if (istest)
1249 asset.Local = true;
767 if (AddNewAsset != null) 1250 if (AddNewAsset != null)
768 AddNewAsset(asset); 1251 AddNewAsset(asset);
769 else if (m_assetService != null) 1252 else if (m_assetService != null)
@@ -771,11 +1254,17 @@ namespace OpenSim.Region.ClientStack.Linden
771 1254
772 InventoryItemBase item = new InventoryItemBase(); 1255 InventoryItemBase item = new InventoryItemBase();
773 item.Owner = m_HostCapsObj.AgentID; 1256 item.Owner = m_HostCapsObj.AgentID;
774 item.CreatorId = m_HostCapsObj.AgentID.ToString(); 1257 item.CreatorId = creatorIDstr;
775 item.CreatorData = String.Empty; 1258 item.CreatorData = String.Empty;
776 item.ID = inventoryItem; 1259 item.ID = inventoryItem;
777 item.AssetID = asset.FullID; 1260 item.AssetID = asset.FullID;
778 item.Description = assetDescription; 1261 if (istest)
1262 {
1263 item.Description = "For testing only. Other uses are prohibited";
1264 item.Flags = (uint) (InventoryItemFlags.SharedSingleReference);
1265 }
1266 else
1267 item.Description = assetDescription;
779 item.Name = assetName; 1268 item.Name = assetName;
780 item.AssetType = assType; 1269 item.AssetType = assType;
781 item.InvType = inType; 1270 item.InvType = inType;
@@ -783,18 +1272,61 @@ namespace OpenSim.Region.ClientStack.Linden
783 1272
784 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current 1273 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current
785 // (owner) permissions. This becomes a problem if next permissions are changed. 1274 // (owner) permissions. This becomes a problem if next permissions are changed.
786 item.CurrentPermissions
787 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export);
788 1275
789 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; 1276 if (inType == (sbyte)CustomInventoryType.AnimationSet)
790 item.EveryOnePermissions = 0; 1277 {
791 item.NextPermissions = (uint)PermissionMask.All; 1278 AnimationSet.setCreateItemPermitions(item);
1279 }
1280
1281 else if (restrictPerms)
1282 {
1283 item.BasePermissions = (uint)(PermissionMask.Move | PermissionMask.Modify);
1284 item.CurrentPermissions = (uint)(PermissionMask.Move | PermissionMask.Modify);
1285 item.EveryOnePermissions = 0;
1286 item.NextPermissions = 0;
1287 }
1288 else
1289 {
1290 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1291 item.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1292 item.EveryOnePermissions = 0;
1293 item.NextPermissions = (uint)PermissionMask.Transfer;
1294 }
1295
792 item.CreationDate = Util.UnixTimeSinceEpoch(); 1296 item.CreationDate = Util.UnixTimeSinceEpoch();
793 1297
1298 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
1299
794 if (AddNewInventoryItem != null) 1300 if (AddNewInventoryItem != null)
795 { 1301 {
796 AddNewInventoryItem(m_HostCapsObj.AgentID, item); 1302 if (istest)
1303 {
1304 m_Scene.AddInventoryItem(client, item);
1305/*
1306 AddNewInventoryItem(m_HostCapsObj.AgentID, item, 0);
1307 if (client != null)
1308 client.SendAgentAlertMessage("Upload will have no cost, for personal test purposes only. Other uses are forbiden. Items may not work on a another region" , true);
1309 */
1310 }
1311 else
1312 {
1313 AddNewInventoryItem(m_HostCapsObj.AgentID, item, (uint)cost);
1314// if (client != null)
1315// {
1316// // let users see anything.. i don't so far
1317// string str;
1318// if (cost > 0)
1319// // dont remember where is money unit name to put here
1320// str = "Upload complete. charged " + cost.ToString() + "$";
1321// else
1322// str = "Upload complete";
1323// client.SendAgentAlertMessage(str, true);
1324// }
1325 }
797 } 1326 }
1327
1328 lock (m_ModelCost)
1329 m_FileAgentInventoryState = FileAgentInventoryState.idle;
798 } 1330 }
799 1331
800 /// <summary> 1332 /// <summary>
@@ -995,6 +1527,131 @@ namespace OpenSim.Region.ClientStack.Linden
995 return response; 1527 return response;
996 } 1528 }
997 1529
1530 public string GetObjectCost(string request, string path,
1531 string param, IOSHttpRequest httpRequest,
1532 IOSHttpResponse httpResponse)
1533 {
1534 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1535 OSDMap resp = new OSDMap();
1536
1537 OSDArray object_ids = (OSDArray)req["object_ids"];
1538
1539 for (int i = 0; i < object_ids.Count; i++)
1540 {
1541 UUID uuid = object_ids[i].AsUUID();
1542
1543 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1544
1545 if (part != null)
1546 {
1547 SceneObjectGroup grp = part.ParentGroup;
1548 if (grp != null)
1549 {
1550 float linksetCost;
1551 float linksetPhysCost;
1552 float partCost;
1553 float partPhysCost;
1554
1555 grp.GetResourcesCosts(part, out linksetCost, out linksetPhysCost, out partCost, out partPhysCost);
1556
1557 OSDMap object_data = new OSDMap();
1558 object_data["linked_set_resource_cost"] = linksetCost;
1559 object_data["resource_cost"] = partCost;
1560 object_data["physics_cost"] = partPhysCost;
1561 object_data["linked_set_physics_cost"] = linksetPhysCost;
1562
1563 resp[uuid.ToString()] = object_data;
1564 }
1565 else
1566 {
1567 OSDMap object_data = new OSDMap();
1568 object_data["linked_set_resource_cost"] = 0;
1569 object_data["resource_cost"] = 0;
1570 object_data["physics_cost"] = 0;
1571 object_data["linked_set_physics_cost"] = 0;
1572
1573 resp[uuid.ToString()] = object_data;
1574 }
1575
1576 }
1577 }
1578
1579 string response = OSDParser.SerializeLLSDXmlString(resp);
1580 return response;
1581 }
1582
1583 public string ResourceCostSelected(string request, string path,
1584 string param, IOSHttpRequest httpRequest,
1585 IOSHttpResponse httpResponse)
1586 {
1587 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1588 OSDMap resp = new OSDMap();
1589
1590
1591 float phys=0;
1592 float stream=0;
1593 float simul=0;
1594
1595 if (req.ContainsKey("selected_roots"))
1596 {
1597 OSDArray object_ids = (OSDArray)req["selected_roots"];
1598
1599 // should go by SOG suming costs for all parts
1600 // ll v3 works ok with several objects select we get the list and adds ok
1601 // FS calls per object so results are wrong guess fs bug
1602 for (int i = 0; i < object_ids.Count; i++)
1603 {
1604 UUID uuid = object_ids[i].AsUUID();
1605 float Physc;
1606 float simulc;
1607 float streamc;
1608
1609 SceneObjectGroup grp = m_Scene.GetGroupByPrim(uuid);
1610 if (grp != null)
1611 {
1612 grp.GetSelectedCosts(out Physc, out streamc, out simulc);
1613 phys += Physc;
1614 stream += streamc;
1615 simul += simulc;
1616 }
1617 }
1618 }
1619 else if (req.ContainsKey("selected_prims"))
1620 {
1621 OSDArray object_ids = (OSDArray)req["selected_prims"];
1622
1623 // don't see in use in any of the 2 viewers
1624 // guess it should be for edit linked but... nothing
1625 // should go to SOP per part
1626 for (int i = 0; i < object_ids.Count; i++)
1627 {
1628 UUID uuid = object_ids[i].AsUUID();
1629
1630 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1631 if (part != null)
1632 {
1633 phys += part.PhysicsCost;
1634 stream += part.StreamingCost;
1635 simul += part.SimulationCost;
1636 }
1637 }
1638 }
1639
1640 // if (simul != 0)
1641 {
1642 OSDMap object_data = new OSDMap();
1643
1644 object_data["physics"] = phys;
1645 object_data["streaming"] = stream;
1646 object_data["simulation"] = simul;
1647
1648 resp["selected"] = object_data;
1649 }
1650
1651 string response = OSDParser.SerializeLLSDXmlString(resp);
1652 return response;
1653 }
1654
998 public string UpdateAgentInformation(string request, string path, 1655 public string UpdateAgentInformation(string request, string path,
999 string param, IOSHttpRequest httpRequest, 1656 string param, IOSHttpRequest httpRequest,
1000 IOSHttpResponse httpResponse) 1657 IOSHttpResponse httpResponse)
@@ -1015,6 +1672,10 @@ namespace OpenSim.Region.ClientStack.Linden
1015 1672
1016 public class AssetUploader 1673 public class AssetUploader
1017 { 1674 {
1675 private static readonly ILog m_log =
1676 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1677
1678
1018 public event UpLoadedAsset OnUpLoad; 1679 public event UpLoadedAsset OnUpLoad;
1019 private UpLoadedAsset handlerUpLoad = null; 1680 private UpLoadedAsset handlerUpLoad = null;
1020 1681
@@ -1029,10 +1690,21 @@ namespace OpenSim.Region.ClientStack.Linden
1029 1690
1030 private string m_invType = String.Empty; 1691 private string m_invType = String.Empty;
1031 private string m_assetType = String.Empty; 1692 private string m_assetType = String.Empty;
1032 1693 private int m_cost;
1694 private string m_error = String.Empty;
1695
1696 private Timer m_timeoutTimer = new Timer();
1697 private UUID m_texturesFolder;
1698 private int m_nreqtextures;
1699 private int m_nreqmeshs;
1700 private int m_nreqinstances;
1701 private bool m_IsAtestUpload;
1702
1033 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, 1703 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
1034 UUID parentFolderID, string invType, string assetType, string path, 1704 UUID parentFolderID, string invType, string assetType, string path,
1035 IHttpServer httpServer, bool dumpAssetsToFile) 1705 IHttpServer httpServer, bool dumpAssetsToFile,
1706 int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
1707 bool IsAtestUpload)
1036 { 1708 {
1037 m_assetName = assetName; 1709 m_assetName = assetName;
1038 m_assetDes = description; 1710 m_assetDes = description;
@@ -1044,6 +1716,18 @@ namespace OpenSim.Region.ClientStack.Linden
1044 m_assetType = assetType; 1716 m_assetType = assetType;
1045 m_invType = invType; 1717 m_invType = invType;
1046 m_dumpAssetsToFile = dumpAssetsToFile; 1718 m_dumpAssetsToFile = dumpAssetsToFile;
1719 m_cost = totalCost;
1720
1721 m_texturesFolder = texturesFolder;
1722 m_nreqtextures = nreqtextures;
1723 m_nreqmeshs = nreqmeshs;
1724 m_nreqinstances = nreqinstances;
1725 m_IsAtestUpload = IsAtestUpload;
1726
1727 m_timeoutTimer.Elapsed += TimedOut;
1728 m_timeoutTimer.Interval = 120000;
1729 m_timeoutTimer.AutoReset = false;
1730 m_timeoutTimer.Start();
1047 } 1731 }
1048 1732
1049 /// <summary> 1733 /// <summary>
@@ -1058,12 +1742,14 @@ namespace OpenSim.Region.ClientStack.Linden
1058 UUID inv = inventoryItemID; 1742 UUID inv = inventoryItemID;
1059 string res = String.Empty; 1743 string res = String.Empty;
1060 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); 1744 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
1745/*
1061 uploadComplete.new_asset = newAssetID.ToString(); 1746 uploadComplete.new_asset = newAssetID.ToString();
1062 uploadComplete.new_inventory_item = inv; 1747 uploadComplete.new_inventory_item = inv;
1063 uploadComplete.state = "complete"; 1748 uploadComplete.state = "complete";
1064 1749
1065 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); 1750 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
1066 1751*/
1752 m_timeoutTimer.Stop();
1067 httpListener.RemoveStreamHandler("POST", uploaderPath); 1753 httpListener.RemoveStreamHandler("POST", uploaderPath);
1068 1754
1069 // TODO: probably make this a better set of extensions here 1755 // TODO: probably make this a better set of extensions here
@@ -1080,12 +1766,50 @@ namespace OpenSim.Region.ClientStack.Linden
1080 handlerUpLoad = OnUpLoad; 1766 handlerUpLoad = OnUpLoad;
1081 if (handlerUpLoad != null) 1767 if (handlerUpLoad != null)
1082 { 1768 {
1083 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); 1769 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType,
1770 m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload,
1771 ref m_error);
1084 } 1772 }
1773 if (m_IsAtestUpload)
1774 {
1775 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1776 resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions";
1777 resperror.identifier = inv;
1778
1779 uploadComplete.error = resperror;
1780 uploadComplete.state = "Upload4Testing";
1781 }
1782 else
1783 {
1784 if (m_error == String.Empty)
1785 {
1786 uploadComplete.new_asset = newAssetID.ToString();
1787 uploadComplete.new_inventory_item = inv;
1788 // if (m_texturesFolder != UUID.Zero)
1789 // uploadComplete.new_texture_folder_id = m_texturesFolder;
1790 uploadComplete.state = "complete";
1791 }
1792 else
1793 {
1794 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1795 resperror.message = m_error;
1796 resperror.identifier = inv;
1085 1797
1798 uploadComplete.error = resperror;
1799 uploadComplete.state = "failed";
1800 }
1801 }
1802
1803 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
1086 return res; 1804 return res;
1087 } 1805 }
1088 1806
1807 private void TimedOut(object sender, ElapsedEventArgs args)
1808 {
1809 m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload");
1810 httpListener.RemoveStreamHandler("POST", uploaderPath);
1811 }
1812
1089 ///Left this in and commented in case there are unforseen issues 1813 ///Left this in and commented in case there are unforseen issues
1090 //private void SaveAssetToFile(string filename, byte[] data) 1814 //private void SaveAssetToFile(string filename, byte[] data)
1091 //{ 1815 //{
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
new file mode 100644
index 0000000..546bcd9
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
@@ -0,0 +1,703 @@
1// Proprietary code of Avination Virtual Limited
2// (c) 2012 Melanie Thielker, Leal Duarte
3//
4
5using System;
6using System.IO;
7using System.Collections;
8using System.Collections.Generic;
9using System.Text;
10
11using OpenMetaverse;
12using OpenMetaverse.StructuredData;
13
14using OpenSim.Framework;
15using OpenSim.Region.Framework;
16using OpenSim.Region.Framework.Scenes;
17using OpenSim.Framework.Capabilities;
18
19using ComponentAce.Compression.Libs.zlib;
20
21using OSDArray = OpenMetaverse.StructuredData.OSDArray;
22using OSDMap = OpenMetaverse.StructuredData.OSDMap;
23
24namespace OpenSim.Region.ClientStack.Linden
25{
26 public struct ModelPrimLimits
27 {
28
29 }
30
31 public class ModelCost
32 {
33
34 // upload fee defaults
35 // fees are normalized to 1.0
36 // this parameters scale them to basic cost ( so 1.0 translates to 10 )
37
38 public float ModelMeshCostFactor = 0.0f; // scale total cost relative to basic (excluding textures)
39 public float ModelTextureCostFactor = 1.0f; // scale textures fee to basic.
40 public float ModelMinCostFactor = 0.0f; // 0.5f; // minimum total model free excluding textures
41
42 // itens costs in normalized values
43 // ie will be multiplied by basicCost and factors above
44 public float primCreationCost = 0.002f; // extra cost for each prim creation overhead
45 // weigthed size to normalized cost
46 public float bytecost = 1e-5f;
47
48 // mesh upload fees based on compressed data sizes
49 // several data sections are counted more that once
50 // to promote user optimization
51 // following parameters control how many extra times they are added
52 // to global size.
53 // LOD meshs
54 const float medSizeWth = 1f; // 2x
55 const float lowSizeWth = 1.5f; // 2.5x
56 const float lowestSizeWth = 2f; // 3x
57 // favor potencially physical optimized meshs versus automatic decomposition
58 const float physMeshSizeWth = 6f; // counts 7x
59 const float physHullSizeWth = 8f; // counts 9x
60
61 // stream cost area factors
62 // more or less like SL
63 const float highLodFactor = 17.36f;
64 const float midLodFactor = 277.78f;
65 const float lowLodFactor = 1111.11f;
66
67 // physics cost is below, identical to SL, assuming shape type convex
68 // server cost is below identical to SL assuming non scripted non physical object
69
70 // internal
71 const int bytesPerCoord = 6; // 3 coords, 2 bytes per each
72
73 // control prims dimensions
74 public float PrimScaleMin = 0.001f;
75 public float NonPhysicalPrimScaleMax = 256f;
76 public float PhysicalPrimScaleMax = 10f;
77 public int ObjectLinkedPartsMax = 512;
78
79 // storage for a single mesh asset cost parameters
80 private class ameshCostParam
81 {
82 // LOD sizes for size dependent streaming cost
83 public int highLODSize;
84 public int medLODSize;
85 public int lowLODSize;
86 public int lowestLODSize;
87 // normalized fee based on compressed data sizes
88 public float costFee;
89 // physics cost
90 public float physicsCost;
91 }
92
93 // calculates a mesh model costs
94 // returns false on error, with a reason on parameter error
95 // resources input LLSD request
96 // basicCost input region assets upload cost
97 // totalcost returns model total upload fee
98 // meshcostdata returns detailed costs for viewer
99 // avatarSkeleton if mesh includes a avatar skeleton
100 // useAvatarCollider if we should use physics mesh for avatar
101 public bool MeshModelCost(LLSDAssetResource resources, int basicCost, out int totalcost,
102 LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning)
103 {
104 totalcost = 0;
105 error = string.Empty;
106
107 bool avatarSkeleton = false;
108
109 if (resources == null ||
110 resources.instance_list == null ||
111 resources.instance_list.Array.Count == 0)
112 {
113 error = "missing model information.";
114 return false;
115 }
116
117 int numberInstances = resources.instance_list.Array.Count;
118
119 if( numberInstances > ObjectLinkedPartsMax )
120 {
121 error = "Model whould have more than " + ObjectLinkedPartsMax.ToString() + " linked prims";
122 return false;
123 }
124
125 meshcostdata.model_streaming_cost = 0.0;
126 meshcostdata.simulation_cost = 0.0;
127 meshcostdata.physics_cost = 0.0;
128 meshcostdata.resource_cost = 0.0;
129
130 meshcostdata.upload_price_breakdown.mesh_instance = 0;
131 meshcostdata.upload_price_breakdown.mesh_physics = 0;
132 meshcostdata.upload_price_breakdown.mesh_streaming = 0;
133 meshcostdata.upload_price_breakdown.model = 0;
134
135 int itmp;
136
137 // textures cost
138 if (resources.texture_list != null && resources.texture_list.Array.Count > 0)
139 {
140 float textures_cost = (float)(resources.texture_list.Array.Count * basicCost);
141 textures_cost *= ModelTextureCostFactor;
142
143 itmp = (int)(textures_cost + 0.5f); // round
144 meshcostdata.upload_price_breakdown.texture = itmp;
145 totalcost += itmp;
146 }
147
148 // meshs assets cost
149 float meshsfee = 0;
150 int numberMeshs = 0;
151 bool haveMeshs = false;
152
153 bool curskeleton;
154 bool curAvatarPhys;
155
156 List<ameshCostParam> meshsCosts = new List<ameshCostParam>();
157
158 if (resources.mesh_list != null && resources.mesh_list.Array.Count > 0)
159 {
160 numberMeshs = resources.mesh_list.Array.Count;
161
162 for (int i = 0; i < numberMeshs; i++)
163 {
164 ameshCostParam curCost = new ameshCostParam();
165 byte[] data = (byte[])resources.mesh_list.Array[i];
166
167 if (!MeshCost(data, curCost,out curskeleton, out curAvatarPhys, out error))
168 {
169 return false;
170 }
171
172 if (curskeleton)
173 {
174 if (avatarSkeleton)
175 {
176 error = "model can only contain a avatar skeleton";
177 return false;
178 }
179 avatarSkeleton = true;
180 }
181 meshsCosts.Add(curCost);
182 meshsfee += curCost.costFee;
183 }
184 haveMeshs = true;
185 }
186
187 // instances (prims) cost
188
189
190 int mesh;
191 int skipedSmall = 0;
192 for (int i = 0; i < numberInstances; i++)
193 {
194 Hashtable inst = (Hashtable)resources.instance_list.Array[i];
195
196 ArrayList ascale = (ArrayList)inst["scale"];
197 Vector3 scale;
198 double tmp;
199 tmp = (double)ascale[0];
200 scale.X = (float)tmp;
201 tmp = (double)ascale[1];
202 scale.Y = (float)tmp;
203 tmp = (double)ascale[2];
204 scale.Z = (float)tmp;
205
206 if (scale.X < PrimScaleMin || scale.Y < PrimScaleMin || scale.Z < PrimScaleMin)
207 {
208 skipedSmall++;
209 continue;
210 }
211
212 if (scale.X > NonPhysicalPrimScaleMax || scale.Y > NonPhysicalPrimScaleMax || scale.Z > NonPhysicalPrimScaleMax)
213 {
214 error = "Model contains parts with sides larger than " + NonPhysicalPrimScaleMax.ToString() + "m. Please ajust scale";
215 return false;
216 }
217
218 if (haveMeshs && inst.ContainsKey("mesh"))
219 {
220 mesh = (int)inst["mesh"];
221
222 if (mesh >= numberMeshs)
223 {
224 error = "Incoerent model information.";
225 return false;
226 }
227
228 // streamming cost
229
230 float sqdiam = scale.LengthSquared();
231
232 ameshCostParam curCost = meshsCosts[mesh];
233 float mesh_streaming = streamingCost(curCost, sqdiam);
234
235 meshcostdata.model_streaming_cost += mesh_streaming;
236 meshcostdata.physics_cost += curCost.physicsCost;
237 }
238 else // instance as no mesh ??
239 {
240 // to do later if needed
241 meshcostdata.model_streaming_cost += 0.5f;
242 meshcostdata.physics_cost += 1.0f;
243 }
244
245 // assume unscripted and static prim server cost
246 meshcostdata.simulation_cost += 0.5f;
247 // charge for prims creation
248 meshsfee += primCreationCost;
249 }
250
251 if (skipedSmall > 0)
252 {
253 if (skipedSmall > numberInstances / 2)
254 {
255 error = "Model contains too many prims smaller than " + PrimScaleMin.ToString() +
256 "m minimum allowed size. Please check scalling";
257 return false;
258 }
259 else
260 warning += skipedSmall.ToString() + " of the requested " +numberInstances.ToString() +
261 " model prims will not upload because they are smaller than " + PrimScaleMin.ToString() +
262 "m minimum allowed size. Please check scalling ";
263 }
264
265 if (meshcostdata.physics_cost <= meshcostdata.model_streaming_cost)
266 meshcostdata.resource_cost = meshcostdata.model_streaming_cost;
267 else
268 meshcostdata.resource_cost = meshcostdata.physics_cost;
269
270 if (meshcostdata.resource_cost < meshcostdata.simulation_cost)
271 meshcostdata.resource_cost = meshcostdata.simulation_cost;
272
273 // scale cost
274 // at this point a cost of 1.0 whould mean basic cost
275 meshsfee *= ModelMeshCostFactor;
276
277 if (meshsfee < ModelMinCostFactor)
278 meshsfee = ModelMinCostFactor;
279
280 // actually scale it to basic cost
281 meshsfee *= (float)basicCost;
282
283 meshsfee += 0.5f; // rounding
284
285 totalcost += (int)meshsfee;
286
287 // breakdown prices
288 // don't seem to be in use so removed code for now
289
290 return true;
291 }
292
293 // single mesh asset cost
294 private bool MeshCost(byte[] data, ameshCostParam cost,out bool skeleton, out bool avatarPhys, out string error)
295 {
296 cost.highLODSize = 0;
297 cost.medLODSize = 0;
298 cost.lowLODSize = 0;
299 cost.lowestLODSize = 0;
300 cost.physicsCost = 0.0f;
301 cost.costFee = 0.0f;
302
303 error = string.Empty;
304
305 skeleton = false;
306 avatarPhys = false;
307
308 if (data == null || data.Length == 0)
309 {
310 error = "Missing model information.";
311 return false;
312 }
313
314 OSD meshOsd = null;
315 int start = 0;
316
317 error = "Invalid model data";
318
319 using (MemoryStream ms = new MemoryStream(data))
320 {
321 try
322 {
323 OSD osd = OSDParser.DeserializeLLSDBinary(ms);
324 if (osd is OSDMap)
325 meshOsd = (OSDMap)osd;
326 else
327 return false;
328 }
329 catch (Exception e)
330 {
331 return false;
332 }
333 start = (int)ms.Position;
334 }
335
336 OSDMap map = (OSDMap)meshOsd;
337 OSDMap tmpmap;
338
339 int highlod_size = 0;
340 int medlod_size = 0;
341 int lowlod_size = 0;
342 int lowestlod_size = 0;
343 int skin_size = 0;
344
345 int hulls_size = 0;
346 int phys_nhulls;
347 int phys_hullsvertices = 0;
348
349 int physmesh_size = 0;
350 int phys_ntriangles = 0;
351
352 int submesh_offset = -1;
353
354 if (map.ContainsKey("skeleton"))
355 {
356 tmpmap = (OSDMap)map["skeleton"];
357 if (tmpmap.ContainsKey("offset") && tmpmap.ContainsKey("size"))
358 {
359 int sksize = tmpmap["size"].AsInteger();
360 if(sksize > 0)
361 skeleton = true;
362 }
363 }
364
365 if (map.ContainsKey("physics_convex"))
366 {
367 tmpmap = (OSDMap)map["physics_convex"];
368 if (tmpmap.ContainsKey("offset"))
369 submesh_offset = tmpmap["offset"].AsInteger() + start;
370 if (tmpmap.ContainsKey("size"))
371 hulls_size = tmpmap["size"].AsInteger();
372 }
373
374 if (submesh_offset < 0 || hulls_size == 0)
375 {
376 error = "Missing physics_convex block";
377 return false;
378 }
379
380 if (!hulls(data, submesh_offset, hulls_size, out phys_hullsvertices, out phys_nhulls))
381 {
382 error = "Bad physics_convex block";
383 return false;
384 }
385
386 submesh_offset = -1;
387
388 // only look for LOD meshs sizes
389
390 if (map.ContainsKey("high_lod"))
391 {
392 tmpmap = (OSDMap)map["high_lod"];
393 // see at least if there is a offset for this one
394 if (tmpmap.ContainsKey("offset"))
395 submesh_offset = tmpmap["offset"].AsInteger() + start;
396 if (tmpmap.ContainsKey("size"))
397 highlod_size = tmpmap["size"].AsInteger();
398 }
399
400 if (submesh_offset < 0 || highlod_size <= 0)
401 {
402 error = "Missing high_lod block";
403 return false;
404 }
405
406 bool haveprev = true;
407
408 if (map.ContainsKey("medium_lod"))
409 {
410 tmpmap = (OSDMap)map["medium_lod"];
411 if (tmpmap.ContainsKey("size"))
412 medlod_size = tmpmap["size"].AsInteger();
413 else
414 haveprev = false;
415 }
416
417 if (haveprev && map.ContainsKey("low_lod"))
418 {
419 tmpmap = (OSDMap)map["low_lod"];
420 if (tmpmap.ContainsKey("size"))
421 lowlod_size = tmpmap["size"].AsInteger();
422 else
423 haveprev = false;
424 }
425
426 if (haveprev && map.ContainsKey("lowest_lod"))
427 {
428 tmpmap = (OSDMap)map["lowest_lod"];
429 if (tmpmap.ContainsKey("size"))
430 lowestlod_size = tmpmap["size"].AsInteger();
431 }
432
433 if (map.ContainsKey("skin"))
434 {
435 tmpmap = (OSDMap)map["skin"];
436 if (tmpmap.ContainsKey("size"))
437 skin_size = tmpmap["size"].AsInteger();
438 }
439
440 cost.highLODSize = highlod_size;
441 cost.medLODSize = medlod_size;
442 cost.lowLODSize = lowlod_size;
443 cost.lowestLODSize = lowestlod_size;
444
445 submesh_offset = -1;
446
447 tmpmap = null;
448 if(map.ContainsKey("physics_mesh"))
449 tmpmap = (OSDMap)map["physics_mesh"];
450 else if (map.ContainsKey("physics_shape")) // old naming
451 tmpmap = (OSDMap)map["physics_shape"];
452
453 if(tmpmap != null)
454 {
455 if (tmpmap.ContainsKey("offset"))
456 submesh_offset = tmpmap["offset"].AsInteger() + start;
457 if (tmpmap.ContainsKey("size"))
458 physmesh_size = tmpmap["size"].AsInteger();
459
460 if (submesh_offset >= 0 || physmesh_size > 0)
461 {
462
463 if (!submesh(data, submesh_offset, physmesh_size, out phys_ntriangles))
464 {
465 error = "Model data parsing error";
466 return false;
467 }
468 }
469 }
470
471 // upload is done in convex shape type so only one hull
472 phys_hullsvertices++;
473 cost.physicsCost = 0.04f * phys_hullsvertices;
474
475 float sfee;
476
477 sfee = data.Length; // start with total compressed data size
478
479 // penalize lod meshs that should be more builder optimized
480 sfee += medSizeWth * medlod_size;
481 sfee += lowSizeWth * lowlod_size;
482 sfee += lowestSizeWth * lowlod_size;
483
484 // physics
485 // favor potencial optimized meshs versus automatic decomposition
486 if (physmesh_size != 0)
487 sfee += physMeshSizeWth * (physmesh_size + hulls_size / 4); // reduce cost of mandatory convex hull
488 else
489 sfee += physHullSizeWth * hulls_size;
490
491 // bytes to money
492 sfee *= bytecost;
493
494 cost.costFee = sfee;
495 return true;
496 }
497
498 // parses a LOD or physics mesh component
499 private bool submesh(byte[] data, int offset, int size, out int ntriangles)
500 {
501 ntriangles = 0;
502
503 OSD decodedMeshOsd = new OSD();
504 byte[] meshBytes = new byte[size];
505 System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
506 try
507 {
508 using (MemoryStream inMs = new MemoryStream(meshBytes))
509 {
510 using (MemoryStream outMs = new MemoryStream())
511 {
512 using (ZOutputStream zOut = new ZOutputStream(outMs))
513 {
514 byte[] readBuffer = new byte[4096];
515 int readLen = 0;
516 while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
517 {
518 zOut.Write(readBuffer, 0, readLen);
519 }
520 zOut.Flush();
521 outMs.Seek(0, SeekOrigin.Begin);
522
523 byte[] decompressedBuf = outMs.GetBuffer();
524 decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
525 }
526 }
527 }
528 }
529 catch (Exception e)
530 {
531 return false;
532 }
533
534 OSDArray decodedMeshOsdArray = null;
535 if ((!decodedMeshOsd is OSDArray))
536 return false;
537
538 byte[] dummy;
539
540 decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
541 foreach (OSD subMeshOsd in decodedMeshOsdArray)
542 {
543 if (subMeshOsd is OSDMap)
544 {
545 OSDMap subtmpmap = (OSDMap)subMeshOsd;
546 if (subtmpmap.ContainsKey("NoGeometry") && ((OSDBoolean)subtmpmap["NoGeometry"]))
547 continue;
548
549 if (!subtmpmap.ContainsKey("Position"))
550 return false;
551
552 if (subtmpmap.ContainsKey("TriangleList"))
553 {
554 dummy = subtmpmap["TriangleList"].AsBinary();
555 ntriangles += dummy.Length / bytesPerCoord;
556 }
557 else
558 return false;
559 }
560 }
561
562 return true;
563 }
564
565 // parses convex hulls component
566 private bool hulls(byte[] data, int offset, int size, out int nvertices, out int nhulls)
567 {
568 nvertices = 0;
569 nhulls = 1;
570
571 OSD decodedMeshOsd = new OSD();
572 byte[] meshBytes = new byte[size];
573 System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
574 try
575 {
576 using (MemoryStream inMs = new MemoryStream(meshBytes))
577 {
578 using (MemoryStream outMs = new MemoryStream())
579 {
580 using (ZOutputStream zOut = new ZOutputStream(outMs))
581 {
582 byte[] readBuffer = new byte[4096];
583 int readLen = 0;
584 while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
585 {
586 zOut.Write(readBuffer, 0, readLen);
587 }
588 zOut.Flush();
589 outMs.Seek(0, SeekOrigin.Begin);
590
591 byte[] decompressedBuf = outMs.GetBuffer();
592 decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
593 }
594 }
595 }
596 }
597 catch (Exception e)
598 {
599 return false;
600 }
601
602 OSDMap cmap = (OSDMap)decodedMeshOsd;
603 if (cmap == null)
604 return false;
605
606 byte[] dummy;
607
608 // must have one of this
609 if (cmap.ContainsKey("BoundingVerts"))
610 {
611 dummy = cmap["BoundingVerts"].AsBinary();
612 nvertices = dummy.Length / bytesPerCoord;
613 }
614 else
615 return false;
616
617/* upload is done with convex shape type
618 if (cmap.ContainsKey("HullList"))
619 {
620 dummy = cmap["HullList"].AsBinary();
621 nhulls += dummy.Length;
622 }
623
624
625 if (cmap.ContainsKey("Positions"))
626 {
627 dummy = cmap["Positions"].AsBinary();
628 nvertices = dummy.Length / bytesPerCoord;
629 }
630 */
631
632 return true;
633 }
634
635 // returns streaming cost from on mesh LODs sizes in curCost and square of prim size length
636 private float streamingCost(ameshCostParam curCost, float sqdiam)
637 {
638 // compute efective areas
639 float ma = 262144f;
640
641 float mh = sqdiam * highLodFactor;
642 if (mh > ma)
643 mh = ma;
644 float mm = sqdiam * midLodFactor;
645 if (mm > ma)
646 mm = ma;
647
648 float ml = sqdiam * lowLodFactor;
649 if (ml > ma)
650 ml = ma;
651
652 float mlst = ma;
653
654 mlst -= ml;
655 ml -= mm;
656 mm -= mh;
657
658 if (mlst < 1.0f)
659 mlst = 1.0f;
660 if (ml < 1.0f)
661 ml = 1.0f;
662 if (mm < 1.0f)
663 mm = 1.0f;
664 if (mh < 1.0f)
665 mh = 1.0f;
666
667 ma = mlst + ml + mm + mh;
668
669 // get LODs compressed sizes
670 // giving 384 bytes bonus
671 int lst = curCost.lowestLODSize - 384;
672 int l = curCost.lowLODSize - 384;
673 int m = curCost.medLODSize - 384;
674 int h = curCost.highLODSize - 384;
675
676 // use previus higher LOD size on missing ones
677 if (m <= 0)
678 m = h;
679 if (l <= 0)
680 l = m;
681 if (lst <= 0)
682 lst = l;
683
684 // force minumum sizes
685 if (lst < 16)
686 lst = 16;
687 if (l < 16)
688 l = 16;
689 if (m < 16)
690 m = 16;
691 if (h < 16)
692 h = 16;
693
694 // compute cost weighted by relative effective areas
695 float cost = (float)lst * mlst + (float)l * ml + (float)m * mm + (float)h * mh;
696 cost /= ma;
697
698 cost *= 0.004f; // overall tunning parameter
699
700 return cost;
701 }
702 }
703}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
index 9b9f6a7..5fb028c 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
@@ -78,7 +78,6 @@ namespace OpenSim.Region.ClientStack.Linden
78 private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>(); 78 private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>();
79 79
80 private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>(); 80 private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>();
81 private Dictionary<UUID, UUID> m_QueueUUIDAvatarMapping = new Dictionary<UUID, UUID>();
82 private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>(); 81 private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>();
83 82
84 #region INonSharedRegionModule methods 83 #region INonSharedRegionModule methods
@@ -178,6 +177,7 @@ namespace OpenSim.Region.ClientStack.Linden
178 } 177 }
179 178
180 /// <summary> 179 /// <summary>
180<<<<<<< HEAD
181 /// Always returns a valid queue 181 /// Always returns a valid queue
182 /// </summary> 182 /// </summary>
183 /// <param name="agentId"></param> 183 /// <param name="agentId"></param>
@@ -201,6 +201,8 @@ namespace OpenSim.Region.ClientStack.Linden
201 } 201 }
202 202
203 /// <summary> 203 /// <summary>
204=======
205>>>>>>> avn/ubitvar
204 /// May return a null queue 206 /// May return a null queue
205 /// </summary> 207 /// </summary>
206 /// <param name="agentId"></param> 208 /// <param name="agentId"></param>
@@ -263,28 +265,13 @@ namespace OpenSim.Region.ClientStack.Linden
263 lock (queues) 265 lock (queues)
264 queues.Remove(agentID); 266 queues.Remove(agentID);
265 267
266 List<UUID> removeitems = new List<UUID>();
267 lock (m_AvatarQueueUUIDMapping) 268 lock (m_AvatarQueueUUIDMapping)
268 m_AvatarQueueUUIDMapping.Remove(agentID); 269 m_AvatarQueueUUIDMapping.Remove(agentID);
269 270
270 UUID searchval = UUID.Zero; 271 lock (m_ids)
271
272 removeitems.Clear();
273
274 lock (m_QueueUUIDAvatarMapping)
275 { 272 {
276 foreach (UUID ky in m_QueueUUIDAvatarMapping.Keys) 273 if (!m_ids.ContainsKey(agentID))
277 { 274 m_ids.Remove(agentID);
278 searchval = m_QueueUUIDAvatarMapping[ky];
279
280 if (searchval == agentID)
281 {
282 removeitems.Add(ky);
283 }
284 }
285
286 foreach (UUID ky in removeitems)
287 m_QueueUUIDAvatarMapping.Remove(ky);
288 } 275 }
289 276
290 // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); 277 // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
@@ -303,61 +290,107 @@ namespace OpenSim.Region.ClientStack.Linden
303 public void OnRegisterCaps(UUID agentID, Caps caps) 290 public void OnRegisterCaps(UUID agentID, Caps caps)
304 { 291 {
305 // Register an event queue for the client 292 // Register an event queue for the client
293<<<<<<< HEAD
306 294
307 if (DebugLevel > 0) 295 if (DebugLevel > 0)
308 m_log.DebugFormat( 296 m_log.DebugFormat(
309 "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", 297 "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
310 agentID, caps, m_scene.RegionInfo.RegionName); 298 agentID, caps, m_scene.RegionInfo.RegionName);
311 299=======
312 // Let's instantiate a Queue for this agent right now 300 m_log.DebugFormat(
313 TryGetQueue(agentID); 301 "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
302 agentID, caps, m_scene.RegionInfo.RegionName);
303>>>>>>> avn/ubitvar
314 304
315 UUID eventQueueGetUUID; 305 UUID eventQueueGetUUID;
306 Queue<OSD> queue;
307 Random rnd = new Random(Environment.TickCount);
308 int nrnd = rnd.Next(30000000);
309 if (nrnd < 0)
310 nrnd = -nrnd;
316 311
317 lock (m_AvatarQueueUUIDMapping) 312 lock (queues)
318 { 313 {
319 // Reuse open queues. The client does! 314 if (queues.ContainsKey(agentID))
320 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) 315 queue = queues[agentID];
316 else
317 queue = null;
318
319 if (queue == null)
321 { 320 {
322 //m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); 321 queue = new Queue<OSD>();
323 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; 322 queues[agentID] = queue;
323
324 // push markers to handle old responses still waiting
325 // this will cost at most viewer getting two forced noevents
326 // even being a new queue better be safe
327 queue.Enqueue(null);
328 queue.Enqueue(null); // one should be enough
329
330 lock (m_AvatarQueueUUIDMapping)
331 {
332 eventQueueGetUUID = UUID.Random();
333 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
334 {
335 // oops this should not happen ?
336 m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID without a queue");
337 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
338 }
339 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
340 }
341 lock (m_ids)
342 {
343 if (!m_ids.ContainsKey(agentID))
344 m_ids.Add(agentID, nrnd);
345 else
346 m_ids[agentID] = nrnd;
347 }
324 } 348 }
325 else 349 else
326 { 350 {
327 eventQueueGetUUID = UUID.Random(); 351 // push markers to handle old responses still waiting
328 //m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!"); 352 // this will cost at most viewer getting two forced noevents
353 // even being a new queue better be safe
354 queue.Enqueue(null);
355 queue.Enqueue(null); // one should be enough
356
357 // reuse or not to reuse TODO FIX
358 lock (m_AvatarQueueUUIDMapping)
359 {
360 // Reuse open queues. The client does!
361 // Its reuse caps path not queues those are been reused already
362 if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
363 {
364 m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
365 eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
366 }
367 else
368 {
369 eventQueueGetUUID = UUID.Random();
370 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
371 m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!");
372 }
373 }
374 lock (m_ids)
375 {
376 // change to negative numbers so they are changed at end of sending first marker
377 // old data on a queue may be sent on a response for a new caps
378 // but at least will be sent with coerent IDs
379 if (!m_ids.ContainsKey(agentID))
380 m_ids.Add(agentID, -nrnd); // should not happen
381 else
382 m_ids[agentID] = -m_ids[agentID];
383 }
329 } 384 }
330 } 385 }
331 386
332 lock (m_QueueUUIDAvatarMapping)
333 {
334 if (!m_QueueUUIDAvatarMapping.ContainsKey(eventQueueGetUUID))
335 m_QueueUUIDAvatarMapping.Add(eventQueueGetUUID, agentID);
336 }
337
338 lock (m_AvatarQueueUUIDMapping)
339 {
340 if (!m_AvatarQueueUUIDMapping.ContainsKey(agentID))
341 m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID);
342 }
343
344 caps.RegisterPollHandler( 387 caps.RegisterPollHandler(
345 "EventQueueGet", 388 "EventQueueGet",
346 new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS)); 389 new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS));
347
348 Random rnd = new Random(Environment.TickCount);
349 lock (m_ids)
350 {
351 if (!m_ids.ContainsKey(agentID))
352 m_ids.Add(agentID, rnd.Next(30000000));
353 }
354 } 390 }
355 391
356 public bool HasEvents(UUID requestID, UUID agentID) 392 public bool HasEvents(UUID requestID, UUID agentID)
357 { 393 {
358 // Don't use this, because of race conditions at agent closing time
359 //Queue<OSD> queue = TryGetQueue(agentID);
360
361 Queue<OSD> queue = GetQueue(agentID); 394 Queue<OSD> queue = GetQueue(agentID);
362 if (queue != null) 395 if (queue != null)
363 lock (queue) 396 lock (queue)
@@ -366,7 +399,8 @@ namespace OpenSim.Region.ClientStack.Linden
366 return queue.Count > 0; 399 return queue.Count > 0;
367 } 400 }
368 401
369 return false; 402 //m_log.WarnFormat("POLLED FOR EVENTS BY {0} unknown agent", agentID);
403 return true;
370 } 404 }
371 405
372 /// <summary> 406 /// <summary>
@@ -395,55 +429,65 @@ namespace OpenSim.Region.ClientStack.Linden
395 return NoEvents(requestID, pAgentId); 429 return NoEvents(requestID, pAgentId);
396 } 430 }
397 431
398 OSD element; 432 OSD element = null;;
433 OSDArray array = new OSDArray();
434 int thisID = 0;
435 bool negativeID = false;
436
399 lock (queue) 437 lock (queue)
400 { 438 {
401 if (queue.Count == 0) 439 if (queue.Count == 0)
402 return NoEvents(requestID, pAgentId); 440 return NoEvents(requestID, pAgentId);
403 element = queue.Dequeue(); // 15s timeout
404 }
405
406 int thisID = 0;
407 lock (m_ids)
408 thisID = m_ids[pAgentId];
409
410 OSDArray array = new OSDArray();
411 if (element == null) // didn't have an event in 15s
412 {
413 // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
414 array.Add(EventQueueHelper.KeepAliveEvent());
415 //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", pAgentId, m_scene.RegionInfo.RegionName);
416 }
417 else
418 {
419 if (DebugLevel > 0)
420 LogOutboundDebugMessage(element, pAgentId);
421 441
422 array.Add(element); 442 lock (m_ids)
443 thisID = m_ids[pAgentId];
423 444
424 lock (queue) 445 if (thisID < 0)
425 { 446 {
426 while (queue.Count > 0) 447 negativeID = true;
427 { 448 thisID = -thisID;
428 element = queue.Dequeue(); 449 }
450
451 while (queue.Count > 0)
452 {
453 element = queue.Dequeue();
454 // add elements until a marker is found
455 // so they get into a response
456 if (element == null)
457 break;
458 if (DebugLevel > 0)
459 LogOutboundDebugMessage(element, pAgentId);
460 array.Add(element);
461 thisID++;
462 }
463 }
429 464
430 if (DebugLevel > 0) 465 OSDMap events = null;
431 LogOutboundDebugMessage(element, pAgentId);
432 466
433 array.Add(element); 467 if (array.Count > 0)
434 thisID++; 468 {
435 } 469 events = new OSDMap();
436 } 470 events.Add("events", array);
471 events.Add("id", new OSDInteger(thisID));
437 } 472 }
438 473
439 OSDMap events = new OSDMap(); 474 if (negativeID && element == null)
440 events.Add("events", array); 475 {
476 Random rnd = new Random(Environment.TickCount);
477 thisID = rnd.Next(30000000);
478 if (thisID < 0)
479 thisID = -thisID;
480 }
441 481
442 events.Add("id", new OSDInteger(thisID));
443 lock (m_ids) 482 lock (m_ids)
444 { 483 {
445 m_ids[pAgentId] = thisID + 1; 484 m_ids[pAgentId] = thisID + 1;
446 } 485 }
486
487 // if there where no elements before a marker send a NoEvents
488 if (array.Count == 0)
489 return NoEvents(requestID, pAgentId);
490
447 Hashtable responsedata = new Hashtable(); 491 Hashtable responsedata = new Hashtable();
448 responsedata["int_response_code"] = 200; 492 responsedata["int_response_code"] = 200;
449 responsedata["content_type"] = "application/xml"; 493 responsedata["content_type"] = "application/xml";
@@ -461,260 +505,12 @@ namespace OpenSim.Region.ClientStack.Linden
461 responsedata["content_type"] = "text/plain"; 505 responsedata["content_type"] = "text/plain";
462 responsedata["keepalive"] = false; 506 responsedata["keepalive"] = false;
463 responsedata["reusecontext"] = false; 507 responsedata["reusecontext"] = false;
464 responsedata["str_response_string"] = "Upstream error: "; 508 responsedata["str_response_string"] = "<llsd></llsd>";
465 responsedata["error_status_text"] = "Upstream error:"; 509 responsedata["error_status_text"] = "<llsd></llsd>";
466 responsedata["http_protocol_version"] = "HTTP/1.0"; 510 responsedata["http_protocol_version"] = "HTTP/1.0";
467 return responsedata; 511 return responsedata;
468 } 512 }
469 513
470// public Hashtable ProcessQueue(Hashtable request, UUID agentID, Caps caps)
471// {
472// // TODO: this has to be redone to not busy-wait (and block the thread),
473// // TODO: as soon as we have a non-blocking way to handle HTTP-requests.
474//
475//// if (m_log.IsDebugEnabled)
476//// {
477//// String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ ";
478//// foreach (object key in request.Keys)
479//// {
480//// debug += key.ToString() + "=" + request[key].ToString() + " ";
481//// }
482//// m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name);
483//// }
484//
485// Queue<OSD> queue = TryGetQueue(agentID);
486// OSD element;
487//
488// lock (queue)
489// element = queue.Dequeue(); // 15s timeout
490//
491// Hashtable responsedata = new Hashtable();
492//
493// int thisID = 0;
494// lock (m_ids)
495// thisID = m_ids[agentID];
496//
497// if (element == null)
498// {
499// //m_log.ErrorFormat("[EVENTQUEUE]: Nothing to process in " + m_scene.RegionInfo.RegionName);
500// if (thisID == -1) // close-request
501// {
502// m_log.ErrorFormat("[EVENTQUEUE]: 404 in " + m_scene.RegionInfo.RegionName);
503// responsedata["int_response_code"] = 404; //501; //410; //404;
504// responsedata["content_type"] = "text/plain";
505// responsedata["keepalive"] = false;
506// responsedata["str_response_string"] = "Closed EQG";
507// return responsedata;
508// }
509// responsedata["int_response_code"] = 502;
510// responsedata["content_type"] = "text/plain";
511// responsedata["keepalive"] = false;
512// responsedata["str_response_string"] = "Upstream error: ";
513// responsedata["error_status_text"] = "Upstream error:";
514// responsedata["http_protocol_version"] = "HTTP/1.0";
515// return responsedata;
516// }
517//
518// OSDArray array = new OSDArray();
519// if (element == null) // didn't have an event in 15s
520// {
521// // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
522// array.Add(EventQueueHelper.KeepAliveEvent());
523// //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
524// }
525// else
526// {
527// array.Add(element);
528//
529// if (element is OSDMap)
530// {
531// OSDMap ev = (OSDMap)element;
532// m_log.DebugFormat(
533// "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
534// ev["message"], m_scene.GetScenePresence(agentID).Name);
535// }
536//
537// lock (queue)
538// {
539// while (queue.Count > 0)
540// {
541// element = queue.Dequeue();
542//
543// if (element is OSDMap)
544// {
545// OSDMap ev = (OSDMap)element;
546// m_log.DebugFormat(
547// "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
548// ev["message"], m_scene.GetScenePresence(agentID).Name);
549// }
550//
551// array.Add(element);
552// thisID++;
553// }
554// }
555// }
556//
557// OSDMap events = new OSDMap();
558// events.Add("events", array);
559//
560// events.Add("id", new OSDInteger(thisID));
561// lock (m_ids)
562// {
563// m_ids[agentID] = thisID + 1;
564// }
565//
566// responsedata["int_response_code"] = 200;
567// responsedata["content_type"] = "application/xml";
568// responsedata["keepalive"] = false;
569// responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
570//
571// m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
572//
573// return responsedata;
574// }
575
576// public Hashtable EventQueuePath2(Hashtable request)
577// {
578// string capuuid = (string)request["uri"]; //path.Replace("/CAPS/EQG/","");
579// // pull off the last "/" in the path.
580// Hashtable responsedata = new Hashtable();
581// capuuid = capuuid.Substring(0, capuuid.Length - 1);
582// capuuid = capuuid.Replace("/CAPS/EQG/", "");
583// UUID AvatarID = UUID.Zero;
584// UUID capUUID = UUID.Zero;
585//
586// // parse the path and search for the avatar with it registered
587// if (UUID.TryParse(capuuid, out capUUID))
588// {
589// lock (m_QueueUUIDAvatarMapping)
590// {
591// if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID))
592// {
593// AvatarID = m_QueueUUIDAvatarMapping[capUUID];
594// }
595// }
596//
597// if (AvatarID != UUID.Zero)
598// {
599// return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID));
600// }
601// else
602// {
603// responsedata["int_response_code"] = 404;
604// responsedata["content_type"] = "text/plain";
605// responsedata["keepalive"] = false;
606// responsedata["str_response_string"] = "Not Found";
607// responsedata["error_status_text"] = "Not Found";
608// responsedata["http_protocol_version"] = "HTTP/1.0";
609// return responsedata;
610// // return 404
611// }
612// }
613// else
614// {
615// responsedata["int_response_code"] = 404;
616// responsedata["content_type"] = "text/plain";
617// responsedata["keepalive"] = false;
618// responsedata["str_response_string"] = "Not Found";
619// responsedata["error_status_text"] = "Not Found";
620// responsedata["http_protocol_version"] = "HTTP/1.0";
621// return responsedata;
622// // return 404
623// }
624// }
625
626 public OSD EventQueueFallBack(string path, OSD request, string endpoint)
627 {
628 // This is a fallback element to keep the client from loosing EventQueueGet
629 // Why does CAPS fail sometimes!?
630 m_log.Warn("[EVENTQUEUE]: In the Fallback handler! We lost the Queue in the rest handler!");
631 string capuuid = path.Replace("/CAPS/EQG/","");
632 capuuid = capuuid.Substring(0, capuuid.Length - 1);
633
634// UUID AvatarID = UUID.Zero;
635 UUID capUUID = UUID.Zero;
636 if (UUID.TryParse(capuuid, out capUUID))
637 {
638/* Don't remove this yet code cleaners!
639 * Still testing this!
640 *
641 lock (m_QueueUUIDAvatarMapping)
642 {
643 if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID))
644 {
645 AvatarID = m_QueueUUIDAvatarMapping[capUUID];
646 }
647 }
648
649
650 if (AvatarID != UUID.Zero)
651 {
652 // Repair the CAP!
653 //OpenSim.Framework.Capabilities.Caps caps = m_scene.GetCapsHandlerForUser(AvatarID);
654 //string capsBase = "/CAPS/EQG/";
655 //caps.RegisterHandler("EventQueueGet",
656 //new RestHTTPHandler("POST", capsBase + capUUID.ToString() + "/",
657 //delegate(Hashtable m_dhttpMethod)
658 //{
659 // return ProcessQueue(m_dhttpMethod, AvatarID, caps);
660 //}));
661 // start new ID sequence.
662 Random rnd = new Random(System.Environment.TickCount);
663 lock (m_ids)
664 {
665 if (!m_ids.ContainsKey(AvatarID))
666 m_ids.Add(AvatarID, rnd.Next(30000000));
667 }
668
669
670 int thisID = 0;
671 lock (m_ids)
672 thisID = m_ids[AvatarID];
673
674 BlockingLLSDQueue queue = GetQueue(AvatarID);
675 OSDArray array = new OSDArray();
676 LLSD element = queue.Dequeue(15000); // 15s timeout
677 if (element == null)
678 {
679
680 array.Add(EventQueueHelper.KeepAliveEvent());
681 }
682 else
683 {
684 array.Add(element);
685 while (queue.Count() > 0)
686 {
687 array.Add(queue.Dequeue(1));
688 thisID++;
689 }
690 }
691 OSDMap events = new OSDMap();
692 events.Add("events", array);
693
694 events.Add("id", new LLSDInteger(thisID));
695
696 lock (m_ids)
697 {
698 m_ids[AvatarID] = thisID + 1;
699 }
700
701 return events;
702 }
703 else
704 {
705 return new LLSD();
706 }
707*
708*/
709 }
710 else
711 {
712 //return new LLSD();
713 }
714
715 return new OSDString("shutdown404!");
716 }
717
718 public void DisableSimulator(ulong handle, UUID avatarID) 514 public void DisableSimulator(ulong handle, UUID avatarID)
719 { 515 {
720 OSD item = EventQueueHelper.DisableSimulator(handle); 516 OSD item = EventQueueHelper.DisableSimulator(handle);
@@ -723,9 +519,14 @@ namespace OpenSim.Region.ClientStack.Linden
723 519
724 public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY) 520 public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY)
725 { 521 {
522<<<<<<< HEAD
726 if (DebugLevel > 0) 523 if (DebugLevel > 0)
727 m_log.DebugFormat("{0} EnableSimulator. handle={1}, endPoint={2}, avatarID={3}", 524 m_log.DebugFormat("{0} EnableSimulator. handle={1}, endPoint={2}, avatarID={3}",
728 LogHeader, handle, endPoint, avatarID, regionSizeX, regionSizeY); 525 LogHeader, handle, endPoint, avatarID, regionSizeX, regionSizeY);
526=======
527 m_log.DebugFormat("{0} EnableSimulator. handle={1}, avatarID={2}, regionSize={3},{4}>",
528 LogHeader, handle, avatarID, regionSizeX, regionSizeY);
529>>>>>>> avn/ubitvar
729 530
730 OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY); 531 OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY);
731 Enqueue(item, avatarID); 532 Enqueue(item, avatarID);
@@ -734,10 +535,15 @@ namespace OpenSim.Region.ClientStack.Linden
734 public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath, 535 public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath,
735 ulong regionHandle, int regionSizeX, int regionSizeY) 536 ulong regionHandle, int regionSizeX, int regionSizeY)
736 { 537 {
538<<<<<<< HEAD
737 if (DebugLevel > 0) 539 if (DebugLevel > 0)
738 m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, endPoint={2}, avatarID={3}", 540 m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, endPoint={2}, avatarID={3}",
739 LogHeader, regionHandle, endPoint, avatarID, regionSizeX, regionSizeY); 541 LogHeader, regionHandle, endPoint, avatarID, regionSizeX, regionSizeY);
740 542
543=======
544 m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, avatarID={2}, regionSize={3},{4}>",
545 LogHeader, regionHandle, avatarID, regionSizeX, regionSizeY);
546>>>>>>> avn/ubitvar
741 OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath, regionHandle, regionSizeX, regionSizeY); 547 OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath, regionHandle, regionSizeX, regionSizeY);
742 Enqueue(item, avatarID); 548 Enqueue(item, avatarID);
743 } 549 }
@@ -747,9 +553,14 @@ namespace OpenSim.Region.ClientStack.Linden
747 uint locationID, uint flags, string capsURL, 553 uint locationID, uint flags, string capsURL,
748 UUID avatarID, int regionSizeX, int regionSizeY) 554 UUID avatarID, int regionSizeX, int regionSizeY)
749 { 555 {
556<<<<<<< HEAD
750 if (DebugLevel > 0) 557 if (DebugLevel > 0)
751 m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, endPoint={2}, avatarID={3}", 558 m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, endPoint={2}, avatarID={3}",
752 LogHeader, regionHandle, regionExternalEndPoint, avatarID, regionSizeX, regionSizeY); 559 LogHeader, regionHandle, regionExternalEndPoint, avatarID, regionSizeX, regionSizeY);
560=======
561 m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, avatarID={2}, regionSize={3},{4}>",
562 LogHeader, regionHandle, avatarID, regionSizeX, regionSizeY);
563>>>>>>> avn/ubitvar
753 564
754 OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint, 565 OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint,
755 locationID, flags, capsURL, avatarID, regionSizeX, regionSizeY); 566 locationID, flags, capsURL, avatarID, regionSizeX, regionSizeY);
@@ -760,9 +571,14 @@ namespace OpenSim.Region.ClientStack.Linden
760 IPEndPoint newRegionExternalEndPoint, 571 IPEndPoint newRegionExternalEndPoint,
761 string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY) 572 string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY)
762 { 573 {
574<<<<<<< HEAD
763 if (DebugLevel > 0) 575 if (DebugLevel > 0)
764 m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>", 576 m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>",
765 LogHeader, handle, avatarID, regionSizeX, regionSizeY); 577 LogHeader, handle, avatarID, regionSizeX, regionSizeY);
578=======
579 m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>",
580 LogHeader, handle, avatarID, regionSizeX, regionSizeY);
581>>>>>>> avn/ubitvar
766 582
767 OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint, 583 OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint,
768 capsURL, avatarID, sessionID, regionSizeX, regionSizeY); 584 capsURL, avatarID, sessionID, regionSizeX, regionSizeY);
@@ -827,4 +643,4 @@ namespace OpenSim.Region.ClientStack.Linden
827 Enqueue(item, avatarID); 643 Enqueue(item, avatarID);
828 } 644 }
829 } 645 }
830} \ No newline at end of file 646}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
index 384af74..8b7e4c1 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs
@@ -77,8 +77,13 @@ namespace OpenSim.Region.ClientStack.Linden
77 llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle))); 77 llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle)));
78 llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes())); 78 llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes()));
79 llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port)); 79 llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port));
80<<<<<<< HEAD
80 llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint) regionSizeX)); 81 llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint) regionSizeX));
81 llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint) regionSizeY)); 82 llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint) regionSizeY));
83=======
84 llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
85 llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
86>>>>>>> avn/ubitvar
82 87
83 OSDArray arr = new OSDArray(1); 88 OSDArray arr = new OSDArray(1);
84 arr.Add(llsdSimInfo); 89 arr.Add(llsdSimInfo);
@@ -157,6 +162,12 @@ namespace OpenSim.Region.ClientStack.Linden
157 uint locationID, uint flags, string capsURL, UUID agentID, 162 uint locationID, uint flags, string capsURL, UUID agentID,
158 int regionSizeX, int regionSizeY) 163 int regionSizeX, int regionSizeY)
159 { 164 {
165 // not sure why flags get overwritten here
166 if ((flags & (uint)TeleportFlags.IsFlying) != 0)
167 flags = (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.IsFlying;
168 else
169 flags = (uint)TeleportFlags.ViaLocation;
170
160 OSDMap info = new OSDMap(); 171 OSDMap info = new OSDMap();
161 info.Add("AgentID", OSD.FromUUID(agentID)); 172 info.Add("AgentID", OSD.FromUUID(agentID));
162 info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? 173 info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this?
@@ -165,7 +176,12 @@ namespace OpenSim.Region.ClientStack.Linden
165 info.Add("SimAccess", OSD.FromInteger(simAccess)); 176 info.Add("SimAccess", OSD.FromInteger(simAccess));
166 info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); 177 info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes()));
167 info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); 178 info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port));
179<<<<<<< HEAD
168 info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation 180 info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
181=======
182// info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
183 info.Add("TeleportFlags", OSD.FromUInteger(flags));
184>>>>>>> avn/ubitvar
169 info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX)); 185 info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
170 info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY)); 186 info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
171 187
@@ -204,8 +220,8 @@ namespace OpenSim.Region.ClientStack.Linden
204 {"sim-ip-and-port", new OSDString(simIpAndPort)}, 220 {"sim-ip-and-port", new OSDString(simIpAndPort)},
205 {"seed-capability", new OSDString(seedcap)}, 221 {"seed-capability", new OSDString(seedcap)},
206 {"region-handle", OSD.FromULong(regionHandle)}, 222 {"region-handle", OSD.FromULong(regionHandle)},
207 {"region-size-x", OSD.FromInteger(regionSizeX)}, 223 {"region-size-x", OSD.FromUInteger((uint)regionSizeX)},
208 {"region-size-y", OSD.FromInteger(regionSizeY)} 224 {"region-size-y", OSD.FromUInteger((uint)regionSizeY)}
209 }; 225 };
210 226
211 return BuildEvent("EstablishAgentCommunication", body); 227 return BuildEvent("EstablishAgentCommunication", body);
@@ -412,7 +428,7 @@ namespace OpenSim.Region.ClientStack.Linden
412 public static OSD partPhysicsProperties(uint localID, byte physhapetype, 428 public static OSD partPhysicsProperties(uint localID, byte physhapetype,
413 float density, float friction, float bounce, float gravmod) 429 float density, float friction, float bounce, float gravmod)
414 { 430 {
415 431
416 OSDMap physinfo = new OSDMap(6); 432 OSDMap physinfo = new OSDMap(6);
417 physinfo["LocalID"] = localID; 433 physinfo["LocalID"] = localID;
418 physinfo["Density"] = density; 434 physinfo["Density"] = density;
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
index f57d857..91efe8a 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs
@@ -27,11 +27,14 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Collections.Specialized; 31using System.Collections.Specialized;
31using System.Reflection; 32using System.Reflection;
32using System.IO; 33using System.IO;
34using System.Threading;
33using System.Web; 35using System.Web;
34using Mono.Addins; 36using Mono.Addins;
37using OpenSim.Framework.Monitoring;
35using log4net; 38using log4net;
36using Nini.Config; 39using Nini.Config;
37using OpenMetaverse; 40using OpenMetaverse;
@@ -57,12 +60,51 @@ namespace OpenSim.Region.ClientStack.Linden
57 private IAssetService m_AssetService; 60 private IAssetService m_AssetService;
58 private bool m_Enabled = true; 61 private bool m_Enabled = true;
59 private string m_URL; 62 private string m_URL;
63<<<<<<< HEAD
60 private string m_URL2; 64 private string m_URL2;
61 private string m_RedirectURL = null; 65 private string m_RedirectURL = null;
62 private string m_RedirectURL2 = null; 66 private string m_RedirectURL2 = null;
67=======
68
69 struct aPollRequest
70 {
71 public PollServiceMeshEventArgs thepoll;
72 public UUID reqID;
73 public Hashtable request;
74 }
75
76 public class aPollResponse
77 {
78 public Hashtable response;
79 public int bytes;
80 public int lod;
81 }
82
83
84 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
85
86 private static GetMeshHandler m_getMeshHandler;
87
88 private IAssetService m_assetService = null;
89
90 private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>();
91 private static Thread[] m_workerThreads = null;
92
93 private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue =
94 new OpenMetaverse.BlockingQueue<aPollRequest>();
95
96 private Dictionary<UUID, PollServiceMeshEventArgs> m_pollservices = new Dictionary<UUID, PollServiceMeshEventArgs>();
97>>>>>>> avn/ubitvar
63 98
64 #region Region Module interfaceBase Members 99 #region Region Module interfaceBase Members
65 100
101 ~GetMeshModule()
102 {
103 foreach (Thread t in m_workerThreads)
104 Watchdog.AbortThread(t.ManagedThreadId);
105
106 }
107
66 public Type ReplaceableInterface 108 public Type ReplaceableInterface
67 { 109 {
68 get { return null; } 110 get { return null; }
@@ -87,8 +129,12 @@ namespace OpenSim.Region.ClientStack.Linden
87 if (m_URL2 != string.Empty) 129 if (m_URL2 != string.Empty)
88 { 130 {
89 m_Enabled = true; 131 m_Enabled = true;
132<<<<<<< HEAD
90 m_RedirectURL2 = config.GetString("GetMesh2RedirectURL"); 133 m_RedirectURL2 = config.GetString("GetMesh2RedirectURL");
91 } 134 }
135=======
136
137>>>>>>> avn/ubitvar
92 } 138 }
93 139
94 public void AddRegion(Scene pScene) 140 public void AddRegion(Scene pScene)
@@ -97,6 +143,8 @@ namespace OpenSim.Region.ClientStack.Linden
97 return; 143 return;
98 144
99 m_scene = pScene; 145 m_scene = pScene;
146
147 m_assetService = pScene.AssetService;
100 } 148 }
101 149
102 public void RemoveRegion(Scene scene) 150 public void RemoveRegion(Scene scene)
@@ -105,6 +153,9 @@ namespace OpenSim.Region.ClientStack.Linden
105 return; 153 return;
106 154
107 m_scene.EventManager.OnRegisterCaps -= RegisterCaps; 155 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
156 m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps;
157 m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate;
158
108 m_scene = null; 159 m_scene = null;
109 } 160 }
110 161
@@ -115,6 +166,27 @@ namespace OpenSim.Region.ClientStack.Linden
115 166
116 m_AssetService = m_scene.RequestModuleInterface<IAssetService>(); 167 m_AssetService = m_scene.RequestModuleInterface<IAssetService>();
117 m_scene.EventManager.OnRegisterCaps += RegisterCaps; 168 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
169 // We'll reuse the same handler for all requests.
170 m_getMeshHandler = new GetMeshHandler(m_assetService);
171 m_scene.EventManager.OnDeregisterCaps += DeregisterCaps;
172 m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate;
173
174 if (m_workerThreads == null)
175 {
176 m_workerThreads = new Thread[2];
177
178 for (uint i = 0; i < 2; i++)
179 {
180 m_workerThreads[i] = Watchdog.StartThread(DoMeshRequests,
181 String.Format("MeshWorkerThread{0}", i),
182 ThreadPriority.Normal,
183 false,
184 false,
185 null,
186 int.MaxValue);
187 }
188 }
189
118 } 190 }
119 191
120 192
@@ -124,9 +196,147 @@ namespace OpenSim.Region.ClientStack.Linden
124 196
125 #endregion 197 #endregion
126 198
199 private void DoMeshRequests()
200 {
201 while (true)
202 {
203 aPollRequest poolreq = m_queue.Dequeue();
204
205 poolreq.thepoll.Process(poolreq);
206 }
207 }
208
209 // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent.
210 public void ThrottleUpdate(ScenePresence p)
211 {
212 UUID user = p.UUID;
213 int imagethrottle = p.ControllingClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Asset);
214 PollServiceMeshEventArgs args;
215 if (m_pollservices.TryGetValue(user, out args))
216 {
217 args.UpdateThrottle(imagethrottle, p);
218 }
219 }
220
221 private class PollServiceMeshEventArgs : PollServiceEventArgs
222 {
223 private List<Hashtable> requests =
224 new List<Hashtable>();
225 private Dictionary<UUID, aPollResponse> responses =
226 new Dictionary<UUID, aPollResponse>();
227
228 private Scene m_scene;
229 private MeshCapsDataThrottler m_throttler;
230 public PollServiceMeshEventArgs(string uri, UUID pId, Scene scene) :
231 base(null, uri, null, null, null, pId, int.MaxValue)
232 {
233 m_scene = scene;
234 m_throttler = new MeshCapsDataThrottler(100000, 1400000, 10000, scene, pId);
235 // x is request id, y is userid
236 HasEvents = (x, y) =>
237 {
238 lock (responses)
239 {
240 bool ret = m_throttler.hasEvents(x, responses);
241 m_throttler.ProcessTime();
242 return ret;
243
244 }
245 };
246 GetEvents = (x, y) =>
247 {
248 lock (responses)
249 {
250 try
251 {
252 return responses[x].response;
253 }
254 finally
255 {
256 m_throttler.ProcessTime();
257 responses.Remove(x);
258 }
259 }
260 };
261 // x is request id, y is request data hashtable
262 Request = (x, y) =>
263 {
264 aPollRequest reqinfo = new aPollRequest();
265 reqinfo.thepoll = this;
266 reqinfo.reqID = x;
267 reqinfo.request = y;
268
269 m_queue.Enqueue(reqinfo);
270 };
271
272 // this should never happen except possible on shutdown
273 NoEvents = (x, y) =>
274 {
275 /*
276 lock (requests)
277 {
278 Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
279 requests.Remove(request);
280 }
281 */
282 Hashtable response = new Hashtable();
283
284 response["int_response_code"] = 500;
285 response["str_response_string"] = "Script timeout";
286 response["content_type"] = "text/plain";
287 response["keepalive"] = false;
288 response["reusecontext"] = false;
289
290 return response;
291 };
292 }
293
294 public void Process(aPollRequest requestinfo)
295 {
296 Hashtable response;
297
298 UUID requestID = requestinfo.reqID;
299
300 // If the avatar is gone, don't bother to get the texture
301 if (m_scene.GetScenePresence(Id) == null)
302 {
303 response = new Hashtable();
304
305 response["int_response_code"] = 500;
306 response["str_response_string"] = "Script timeout";
307 response["content_type"] = "text/plain";
308 response["keepalive"] = false;
309 response["reusecontext"] = false;
310
311 lock (responses)
312 responses[requestID] = new aPollResponse() { bytes = 0, response = response, lod = 0 };
313
314 return;
315 }
316
317 response = m_getMeshHandler.Handle(requestinfo.request);
318 lock (responses)
319 {
320 responses[requestID] = new aPollResponse()
321 {
322 bytes = (int)response["int_bytes"],
323 lod = (int)response["int_lod"],
324 response = response
325 };
326
327 }
328 m_throttler.ProcessTime();
329 }
330
331 internal void UpdateThrottle(int pimagethrottle, ScenePresence p)
332 {
333 m_throttler.UpdateThrottle(pimagethrottle, p);
334 }
335 }
127 336
128 public void RegisterCaps(UUID agentID, Caps caps) 337 public void RegisterCaps(UUID agentID, Caps caps)
129 { 338 {
339<<<<<<< HEAD
130 UUID capID = UUID.Random(); 340 UUID capID = UUID.Random();
131 bool getMeshRegistered = false; 341 bool getMeshRegistered = false;
132 342
@@ -140,6 +350,35 @@ namespace OpenSim.Region.ClientStack.Linden
140 caps.RegisterHandler( 350 caps.RegisterHandler(
141 "GetMesh", 351 "GetMesh",
142 new GetMeshHandler("/CAPS/" + capID + "/", m_AssetService, "GetMesh", agentID.ToString(), m_RedirectURL)); 352 new GetMeshHandler("/CAPS/" + capID + "/", m_AssetService, "GetMesh", agentID.ToString(), m_RedirectURL));
353=======
354// UUID capID = UUID.Random();
355 if (m_URL == "localhost")
356 {
357 string capUrl = "/CAPS/" + UUID.Random() + "/";
358
359 // Register this as a poll service
360 PollServiceMeshEventArgs args = new PollServiceMeshEventArgs(capUrl, agentID, m_scene);
361
362 args.Type = PollServiceEventArgs.EventType.Mesh;
363 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
364
365 string hostName = m_scene.RegionInfo.ExternalHostName;
366 uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
367 string protocol = "http";
368
369 if (MainServer.Instance.UseSSL)
370 {
371 hostName = MainServer.Instance.SSLCommonName;
372 port = MainServer.Instance.SSLPort;
373 protocol = "https";
374 }
375 caps.RegisterHandler("GetMesh", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl));
376 m_pollservices[agentID] = args;
377 m_capsDict[agentID] = capUrl;
378
379
380
381>>>>>>> avn/ubitvar
143 } 382 }
144 else 383 else
145 { 384 {
@@ -164,6 +403,177 @@ namespace OpenSim.Region.ClientStack.Linden
164 caps.RegisterHandler("GetMesh2", m_URL2); 403 caps.RegisterHandler("GetMesh2", m_URL2);
165 } 404 }
166 } 405 }
406 private void DeregisterCaps(UUID agentID, Caps caps)
407 {
408 string capUrl;
409 PollServiceMeshEventArgs args;
410 if (m_capsDict.TryGetValue(agentID, out capUrl))
411 {
412 MainServer.Instance.RemoveHTTPHandler("", capUrl);
413 m_capsDict.Remove(agentID);
414 }
415 if (m_pollservices.TryGetValue(agentID, out args))
416 {
417 m_pollservices.Remove(agentID);
418 }
419 }
420
421 internal sealed class MeshCapsDataThrottler
422 {
423
424 private volatile int currenttime = 0;
425 private volatile int lastTimeElapsed = 0;
426 private volatile int BytesSent = 0;
427 private int Lod3 = 0;
428 private int Lod2 = 0;
429 private int Lod1 = 0;
430 private int UserSetThrottle = 0;
431 private int UDPSetThrottle = 0;
432 private int CapSetThrottle = 0;
433 private float CapThrottleDistributon = 0.30f;
434 private readonly Scene m_scene;
435 private ThrottleOutPacketType Throttle;
436 private readonly UUID User;
437
438 public MeshCapsDataThrottler(int pBytes, int max, int min, Scene pScene, UUID puser)
439 {
440 ThrottleBytes = pBytes;
441 lastTimeElapsed = Util.EnvironmentTickCount();
442 Throttle = ThrottleOutPacketType.Asset;
443 m_scene = pScene;
444 User = puser;
445 }
446
447
448 public bool hasEvents(UUID key, Dictionary<UUID, aPollResponse> responses)
449 {
450 const float ThirtyPercent = 0.30f;
451 const float FivePercent = 0.05f;
452 PassTime();
453 // Note, this is called IN LOCK
454 bool haskey = responses.ContainsKey(key);
455
456 if (responses.Count > 2)
457 {
458 SplitThrottle(ThirtyPercent);
459 }
460 else
461 {
462 SplitThrottle(FivePercent);
463 }
464
465 if (!haskey)
466 {
467 return false;
468 }
469 aPollResponse response;
470 if (responses.TryGetValue(key, out response))
471 {
472 float LOD3Over = (((ThrottleBytes*CapThrottleDistributon)%50000) + 1);
473 float LOD2Over = (((ThrottleBytes*CapThrottleDistributon)%10000) + 1);
474 // Normal
475 if (BytesSent + response.bytes <= ThrottleBytes)
476 {
477 BytesSent += response.bytes;
478
479 return true;
480 }
481 // Lod3 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little.
482 else if (response.bytes > ThrottleBytes && Lod3 <= ((LOD3Over < 1)? 1: LOD3Over) )
483 {
484 Interlocked.Increment(ref Lod3);
485 BytesSent += response.bytes;
486
487 return true;
488 }
489 // Lod2 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little.
490 else if (response.bytes > ThrottleBytes && Lod2 <= ((LOD2Over < 1) ? 1 : LOD2Over))
491 {
492 Interlocked.Increment(ref Lod2);
493 BytesSent += response.bytes;
494
495 return true;
496 }
497 else
498 {
499 return false;
500 }
501 }
502
503 return haskey;
504 }
505 public void SubtractBytes(int bytes,int lod)
506 {
507 BytesSent -= bytes;
508 }
509 private void SplitThrottle(float percentMultiplier)
510 {
511
512 if (CapThrottleDistributon != percentMultiplier) // don't switch it if it's already set at the % multipler
513 {
514 CapThrottleDistributon = percentMultiplier;
515 ScenePresence p;
516 if (m_scene.TryGetScenePresence(User, out p)) // If we don't get a user they're not here anymore.
517 {
518// AlterThrottle(UserSetThrottle, p);
519 UpdateThrottle(UserSetThrottle, p);
520 }
521 }
522 }
523
524 public void ProcessTime()
525 {
526 PassTime();
527 }
528
529
530 private void PassTime()
531 {
532 currenttime = Util.EnvironmentTickCount();
533 int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed);
534 //processTimeBasedActions(responses);
535 if (currenttime - timeElapsed >= 1000)
536 {
537 lastTimeElapsed = Util.EnvironmentTickCount();
538 BytesSent -= ThrottleBytes;
539 if (BytesSent < 0) BytesSent = 0;
540 if (BytesSent < ThrottleBytes)
541 {
542 Lod3 = 0;
543 Lod2 = 0;
544 Lod1 = 0;
545 }
546 }
547 }
548 private void AlterThrottle(int setting, ScenePresence p)
549 {
550 p.ControllingClient.SetAgentThrottleSilent((int)Throttle,setting);
551 }
552
553 public int ThrottleBytes
554 {
555 get { return CapSetThrottle; }
556 set { CapSetThrottle = value; }
557 }
558
559 internal void UpdateThrottle(int pimagethrottle, ScenePresence p)
560 {
561 // Client set throttle !
562 UserSetThrottle = pimagethrottle;
563 CapSetThrottle = (int)(pimagethrottle*CapThrottleDistributon);
564// UDPSetThrottle = (int) (pimagethrottle*(100 - CapThrottleDistributon));
565
566 float udp = 1.0f - CapThrottleDistributon;
567 if(udp < 0.7f)
568 udp = 0.7f;
569 UDPSetThrottle = (int) ((float)pimagethrottle * udp);
570 if (CapSetThrottle < 4068)
571 CapSetThrottle = 4068; // at least two discovery mesh
572 p.ControllingClient.SetAgentThrottleSilent((int) Throttle, UDPSetThrottle);
573 ProcessTime();
574
575 }
576 }
167 577
168 } 578 }
169} 579}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
index bb932f2..b9396b7 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs
@@ -27,18 +27,13 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Specialized; 30using System.Collections.Generic;
31using System.Drawing;
32using System.Drawing.Imaging;
33using System.Reflection; 31using System.Reflection;
34using System.IO; 32using System.Threading;
35using System.Web;
36using log4net; 33using log4net;
37using Nini.Config; 34using Nini.Config;
38using Mono.Addins; 35using Mono.Addins;
39using OpenMetaverse; 36using OpenMetaverse;
40using OpenMetaverse.StructuredData;
41using OpenMetaverse.Imaging;
42using OpenSim.Framework; 37using OpenSim.Framework;
43using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
44using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
@@ -47,6 +42,7 @@ using OpenSim.Region.Framework.Scenes;
47using OpenSim.Services.Interfaces; 42using OpenSim.Services.Interfaces;
48using Caps = OpenSim.Framework.Capabilities.Caps; 43using Caps = OpenSim.Framework.Capabilities.Caps;
49using OpenSim.Capabilities.Handlers; 44using OpenSim.Capabilities.Handlers;
45using OpenSim.Framework.Monitoring;
50 46
51namespace OpenSim.Region.ClientStack.Linden 47namespace OpenSim.Region.ClientStack.Linden
52{ 48{
@@ -54,16 +50,44 @@ namespace OpenSim.Region.ClientStack.Linden
54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")] 50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")]
55 public class GetTextureModule : INonSharedRegionModule 51 public class GetTextureModule : INonSharedRegionModule
56 { 52 {
57// private static readonly ILog m_log = 53
58// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 struct aPollRequest
59 55 {
56 public PollServiceTextureEventArgs thepoll;
57 public UUID reqID;
58 public Hashtable request;
59 public bool send503;
60 }
61
62 public class aPollResponse
63 {
64 public Hashtable response;
65 public int bytes;
66 }
67
68
69 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
70
60 private Scene m_scene; 71 private Scene m_scene;
61 private IAssetService m_assetService;
62 72
63 private bool m_Enabled = false; 73 private static GetTextureHandler m_getTextureHandler;
74
75 private IAssetService m_assetService = null;
76
77 private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>();
78 private static Thread[] m_workerThreads = null;
79
80 private string m_Url = "localhost";
81
82 private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue =
83 new OpenMetaverse.BlockingQueue<aPollRequest>();
64 84
85<<<<<<< HEAD
65 // TODO: Change this to a config option 86 // TODO: Change this to a config option
66 private string m_RedirectURL = null; 87 private string m_RedirectURL = null;
88=======
89 private Dictionary<UUID,PollServiceTextureEventArgs> m_pollservices = new Dictionary<UUID,PollServiceTextureEventArgs>();
90>>>>>>> avn/ubitvar
67 91
68 private string m_URL; 92 private string m_URL;
69 93
@@ -72,6 +96,7 @@ namespace OpenSim.Region.ClientStack.Linden
72 public void Initialise(IConfigSource source) 96 public void Initialise(IConfigSource source)
73 { 97 {
74 IConfig config = source.Configs["ClientStack.LindenCaps"]; 98 IConfig config = source.Configs["ClientStack.LindenCaps"];
99<<<<<<< HEAD
75 if (config == null) 100 if (config == null)
76 return; 101 return;
77 102
@@ -82,32 +107,100 @@ namespace OpenSim.Region.ClientStack.Linden
82 m_Enabled = true; 107 m_Enabled = true;
83 m_RedirectURL = config.GetString("GetTextureRedirectURL"); 108 m_RedirectURL = config.GetString("GetTextureRedirectURL");
84 } 109 }
110=======
111 if (config != null)
112 m_Url = config.GetString("Cap_GetTexture", "localhost");
113>>>>>>> avn/ubitvar
85 } 114 }
86 115
87 public void AddRegion(Scene s) 116 public void AddRegion(Scene s)
88 { 117 {
89 if (!m_Enabled)
90 return;
91
92 m_scene = s; 118 m_scene = s;
119 m_assetService = s.AssetService;
93 } 120 }
94 121
95 public void RemoveRegion(Scene s) 122 public void RemoveRegion(Scene s)
96 { 123 {
97 if (!m_Enabled)
98 return;
99
100 m_scene.EventManager.OnRegisterCaps -= RegisterCaps; 124 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
125 m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps;
126 m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate;
101 m_scene = null; 127 m_scene = null;
102 } 128 }
103 129
104 public void RegionLoaded(Scene s) 130 public void RegionLoaded(Scene s)
105 { 131 {
106 if (!m_Enabled) 132 // We'll reuse the same handler for all requests.
107 return; 133 m_getTextureHandler = new GetTextureHandler(m_assetService);
108 134
109 m_assetService = m_scene.RequestModuleInterface<IAssetService>();
110 m_scene.EventManager.OnRegisterCaps += RegisterCaps; 135 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
136 m_scene.EventManager.OnDeregisterCaps += DeregisterCaps;
137 m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate;
138
139 if (m_workerThreads == null)
140 {
141 m_workerThreads = new Thread[2];
142
143 for (uint i = 0; i < 2; i++)
144 {
145 m_workerThreads[i] = Watchdog.StartThread(DoTextureRequests,
146 String.Format("TextureWorkerThread{0}", i),
147 ThreadPriority.Normal,
148 false,
149 false,
150 null,
151 int.MaxValue);
152 }
153 }
154 }
155 private int ExtractImageThrottle(byte[] pthrottles)
156 {
157
158 byte[] adjData;
159 int pos = 0;
160
161 if (!BitConverter.IsLittleEndian)
162 {
163 byte[] newData = new byte[7 * 4];
164 Buffer.BlockCopy(pthrottles, 0, newData, 0, 7 * 4);
165
166 for (int i = 0; i < 7; i++)
167 Array.Reverse(newData, i * 4, 4);
168
169 adjData = newData;
170 }
171 else
172 {
173 adjData = pthrottles;
174 }
175
176 // 0.125f converts from bits to bytes
177 //int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
178 //pos += 4;
179 // int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
180 //pos += 4;
181 // int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
182 // pos += 4;
183 // int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
184 // pos += 4;
185 // int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
186 // pos += 4;
187 pos = pos + 20;
188 int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); //pos += 4;
189 //int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
190 return texture;
191 }
192
193 // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent.
194 public void ThrottleUpdate(ScenePresence p)
195 {
196 byte[] throttles = p.ControllingClient.GetThrottlesPacked(1);
197 UUID user = p.UUID;
198 int imagethrottle = ExtractImageThrottle(throttles);
199 PollServiceTextureEventArgs args;
200 if (m_pollservices.TryGetValue(user,out args))
201 {
202 args.UpdateThrottle(imagethrottle);
203 }
111 } 204 }
112 205
113 public void PostInitialise() 206 public void PostInitialise()
@@ -125,28 +218,306 @@ namespace OpenSim.Region.ClientStack.Linden
125 218
126 #endregion 219 #endregion
127 220
128 public void RegisterCaps(UUID agentID, Caps caps) 221 ~GetTextureModule()
129 { 222 {
130 UUID capID = UUID.Random(); 223 foreach (Thread t in m_workerThreads)
224 Watchdog.AbortThread(t.ManagedThreadId);
131 225
132 //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); 226 }
133 if (m_URL == "localhost") 227
228 private class PollServiceTextureEventArgs : PollServiceEventArgs
229 {
230 private List<Hashtable> requests =
231 new List<Hashtable>();
232 private Dictionary<UUID, aPollResponse> responses =
233 new Dictionary<UUID, aPollResponse>();
234
235 private Scene m_scene;
236 private CapsDataThrottler m_throttler = new CapsDataThrottler(100000, 1400000,10000);
237 public PollServiceTextureEventArgs(UUID pId, Scene scene) :
238 base(null, "", null, null, null, pId, int.MaxValue)
134 { 239 {
240<<<<<<< HEAD
135// m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); 241// m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName);
136 caps.RegisterHandler( 242 caps.RegisterHandler(
137 "GetTexture", 243 "GetTexture",
138 new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString(), m_RedirectURL)); 244 new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString(), m_RedirectURL));
245=======
246 m_scene = scene;
247 // x is request id, y is userid
248 HasEvents = (x, y) =>
249 {
250 lock (responses)
251 {
252 bool ret = m_throttler.hasEvents(x, responses);
253 m_throttler.ProcessTime();
254 return ret;
255
256 }
257 };
258 GetEvents = (x, y) =>
259 {
260 lock (responses)
261 {
262 try
263 {
264 return responses[x].response;
265 }
266 finally
267 {
268 responses.Remove(x);
269 }
270 }
271 };
272 // x is request id, y is request data hashtable
273 Request = (x, y) =>
274 {
275 aPollRequest reqinfo = new aPollRequest();
276 reqinfo.thepoll = this;
277 reqinfo.reqID = x;
278 reqinfo.request = y;
279 reqinfo.send503 = false;
280
281 lock (responses)
282 {
283 if (responses.Count > 0)
284 {
285 if (m_queue.Count >= 4)
286 {
287 // Never allow more than 4 fetches to wait
288 reqinfo.send503 = true;
289 }
290 }
291 }
292 m_queue.Enqueue(reqinfo);
293 };
294
295 // this should never happen except possible on shutdown
296 NoEvents = (x, y) =>
297 {
298/*
299 lock (requests)
300 {
301 Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
302 requests.Remove(request);
303 }
304*/
305 Hashtable response = new Hashtable();
306
307 response["int_response_code"] = 500;
308 response["str_response_string"] = "Script timeout";
309 response["content_type"] = "text/plain";
310 response["keepalive"] = false;
311 response["reusecontext"] = false;
312
313 return response;
314 };
315>>>>>>> avn/ubitvar
139 } 316 }
140 else 317
318 public void Process(aPollRequest requestinfo)
141 { 319 {
142// m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName); 320 Hashtable response;
321
322 UUID requestID = requestinfo.reqID;
323
324 if (requestinfo.send503)
325 {
326 response = new Hashtable();
327
328
329 response["int_response_code"] = 503;
330 response["str_response_string"] = "Throttled";
331 response["content_type"] = "text/plain";
332 response["keepalive"] = false;
333 response["reusecontext"] = false;
334
335 Hashtable headers = new Hashtable();
336 headers["Retry-After"] = 30;
337 response["headers"] = headers;
338
339 lock (responses)
340 responses[requestID] = new aPollResponse() {bytes = 0, response = response};
341
342 return;
343 }
344
345 // If the avatar is gone, don't bother to get the texture
346 if (m_scene.GetScenePresence(Id) == null)
347 {
348 response = new Hashtable();
349
350 response["int_response_code"] = 500;
351 response["str_response_string"] = "Script timeout";
352 response["content_type"] = "text/plain";
353 response["keepalive"] = false;
354 response["reusecontext"] = false;
355
356 lock (responses)
357 responses[requestID] = new aPollResponse() {bytes = 0, response = response};
358
359 return;
360 }
361
362 response = m_getTextureHandler.Handle(requestinfo.request);
363 lock (responses)
364 {
365 responses[requestID] = new aPollResponse()
366 {
367 bytes = (int) response["int_bytes"],
368 response = response
369 };
370
371 }
372 m_throttler.ProcessTime();
373 }
374
375 internal void UpdateThrottle(int pimagethrottle)
376 {
377 m_throttler.ThrottleBytes = pimagethrottle;
378 }
379 }
380
381 private void RegisterCaps(UUID agentID, Caps caps)
382 {
383 if (m_Url == "localhost")
384 {
385 string capUrl = "/CAPS/" + UUID.Random() + "/";
386
387 // Register this as a poll service
388 PollServiceTextureEventArgs args = new PollServiceTextureEventArgs(agentID, m_scene);
389
390 args.Type = PollServiceEventArgs.EventType.Texture;
391 MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args);
392
393 string hostName = m_scene.RegionInfo.ExternalHostName;
394 uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
395 string protocol = "http";
396
397 if (MainServer.Instance.UseSSL)
398 {
399 hostName = MainServer.Instance.SSLCommonName;
400 port = MainServer.Instance.SSLPort;
401 protocol = "https";
402 }
143 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>(); 403 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
144 if (handler != null) 404 if (handler != null)
405<<<<<<< HEAD
145 handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture", m_URL); 406 handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture", m_URL);
407=======
408 handler.RegisterExternalUserCapsHandler(agentID, caps, "GetTexture", capUrl);
409>>>>>>> avn/ubitvar
146 else 410 else
147 caps.RegisterHandler("GetTexture", m_URL); 411 caps.RegisterHandler("GetTexture", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl));
412 m_pollservices[agentID] = args;
413 m_capsDict[agentID] = capUrl;
414 }
415 else
416 {
417 caps.RegisterHandler("GetTexture", m_Url);
148 } 418 }
149 } 419 }
150 420
421 private void DeregisterCaps(UUID agentID, Caps caps)
422 {
423 PollServiceTextureEventArgs args;
424
425 MainServer.Instance.RemoveHTTPHandler("", m_URL);
426 m_capsDict.Remove(agentID);
427
428 if (m_pollservices.TryGetValue(agentID, out args))
429 {
430 m_pollservices.Remove(agentID);
431 }
432 }
433
434 private void DoTextureRequests()
435 {
436 while (true)
437 {
438 aPollRequest poolreq = m_queue.Dequeue();
439
440 poolreq.thepoll.Process(poolreq);
441 }
442 }
443 internal sealed class CapsDataThrottler
444 {
445
446 private volatile int currenttime = 0;
447 private volatile int lastTimeElapsed = 0;
448 private volatile int BytesSent = 0;
449 private int oversizedImages = 0;
450 public CapsDataThrottler(int pBytes, int max, int min)
451 {
452 ThrottleBytes = pBytes;
453 lastTimeElapsed = Util.EnvironmentTickCount();
454 }
455 public bool hasEvents(UUID key, Dictionary<UUID, GetTextureModule.aPollResponse> responses)
456 {
457 PassTime();
458 // Note, this is called IN LOCK
459 bool haskey = responses.ContainsKey(key);
460 if (!haskey)
461 {
462 return false;
463 }
464 GetTextureModule.aPollResponse response;
465 if (responses.TryGetValue(key, out response))
466 {
467 // This is any error response
468 if (response.bytes == 0)
469 return true;
470
471 // Normal
472 if (BytesSent + response.bytes <= ThrottleBytes)
473 {
474 BytesSent += response.bytes;
475 //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + 1000, unlockyn = false };
476 //m_actions.Add(timeBasedAction);
477 return true;
478 }
479 // Big textures
480 else if (response.bytes > ThrottleBytes && oversizedImages <= ((ThrottleBytes % 50000) + 1))
481 {
482 Interlocked.Increment(ref oversizedImages);
483 BytesSent += response.bytes;
484 //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + (((response.bytes % ThrottleBytes)+1)*1000) , unlockyn = false };
485 //m_actions.Add(timeBasedAction);
486 return true;
487 }
488 else
489 {
490 return false;
491 }
492 }
493
494 return haskey;
495 }
496
497 public void ProcessTime()
498 {
499 PassTime();
500 }
501
502 private void PassTime()
503 {
504 currenttime = Util.EnvironmentTickCount();
505 int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed);
506 //processTimeBasedActions(responses);
507 if (Util.EnvironmentTickCountSubtract(currenttime, timeElapsed) >= 1000)
508 {
509 lastTimeElapsed = Util.EnvironmentTickCount();
510 BytesSent -= ThrottleBytes;
511 if (BytesSent < 0) BytesSent = 0;
512 if (BytesSent < ThrottleBytes)
513 {
514 oversizedImages = 0;
515 }
516 }
517 }
518 public int ThrottleBytes;
519 }
151 } 520 }
521
522
152} 523}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
index 45d33cd..1b68603 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs
@@ -129,15 +129,15 @@ namespace OpenSim.Region.ClientStack.Linden
129// m_log.DebugFormat("[MESH UPLOAD FLAG MODULE]: MeshUploadFlag request"); 129// m_log.DebugFormat("[MESH UPLOAD FLAG MODULE]: MeshUploadFlag request");
130 130
131 OSDMap data = new OSDMap(); 131 OSDMap data = new OSDMap();
132 ScenePresence sp = m_scene.GetScenePresence(agentID); 132// ScenePresence sp = m_scene.GetScenePresence(m_agentID);
133 data["username"] = sp.Firstname + "." + sp.Lastname; 133// data["username"] = sp.Firstname + "." + sp.Lastname;
134 data["display_name_next_update"] = new OSDDate(DateTime.Now); 134// data["display_name_next_update"] = new OSDDate(DateTime.Now);
135 data["legacy_first_name"] = sp.Firstname; 135// data["legacy_first_name"] = sp.Firstname;
136 data["mesh_upload_status"] = "valid"; 136 data["mesh_upload_status"] = "valid";
137 data["display_name"] = sp.Firstname + " " + sp.Lastname; 137// data["display_name"] = sp.Firstname + " " + sp.Lastname;
138 data["legacy_last_name"] = sp.Lastname; 138// data["legacy_last_name"] = sp.Lastname;
139 data["id"] = agentID; 139// data["id"] = m_agentID;
140 data["is_display_name_default"] = true; 140// data["is_display_name_default"] = true;
141 141
142 //Send back data 142 //Send back data
143 Hashtable responsedata = new Hashtable(); 143 Hashtable responsedata = new Hashtable();
@@ -148,4 +148,4 @@ namespace OpenSim.Region.ClientStack.Linden
148 return responsedata; 148 return responsedata;
149 } 149 }
150 } 150 }
151} \ No newline at end of file 151}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs
deleted file mode 100644
index f69a0bb..0000000
--- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs
+++ /dev/null
@@ -1,297 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Specialized;
31using System.Reflection;
32using System.IO;
33using System.Web;
34using Mono.Addins;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Services.Interfaces;
45using Caps = OpenSim.Framework.Capabilities.Caps;
46using OpenSim.Framework.Capabilities;
47using PermissionMask = OpenSim.Framework.PermissionMask;
48
49namespace OpenSim.Region.ClientStack.Linden
50{
51 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NewFileAgentInventoryVariablePriceModule")]
52 public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule
53 {
54// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
56 private Scene m_scene;
57// private IAssetService m_assetService;
58 private bool m_dumpAssetsToFile = false;
59 private bool m_enabled = true;
60 private int m_levelUpload = 0;
61
62 #region Region Module interfaceBase Members
63
64
65 public Type ReplaceableInterface
66 {
67 get { return null; }
68 }
69
70 public void Initialise(IConfigSource source)
71 {
72 IConfig meshConfig = source.Configs["Mesh"];
73 if (meshConfig == null)
74 return;
75
76 m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true);
77 m_levelUpload = meshConfig.GetInt("LevelUpload", 0);
78 }
79
80 public void AddRegion(Scene pScene)
81 {
82 m_scene = pScene;
83 }
84
85 public void RemoveRegion(Scene scene)
86 {
87
88 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
89 m_scene = null;
90 }
91
92 public void RegionLoaded(Scene scene)
93 {
94
95// m_assetService = m_scene.RequestModuleInterface<IAssetService>();
96 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
97 }
98
99 #endregion
100
101
102 #region Region Module interface
103
104
105
106 public void Close() { }
107
108 public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } }
109
110
111 public void RegisterCaps(UUID agentID, Caps caps)
112 {
113 if(!m_enabled)
114 return;
115
116 UUID capID = UUID.Random();
117
118// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID);
119 caps.RegisterHandler(
120 "NewFileAgentInventoryVariablePrice",
121 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>(
122 "POST",
123 "/CAPS/" + capID.ToString(),
124 req => NewAgentInventoryRequest(req, agentID),
125 "NewFileAgentInventoryVariablePrice",
126 agentID.ToString()));
127 }
128
129 #endregion
130
131 public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID)
132 {
133 //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit
134 // you need to be aware of this
135
136 //if (llsdRequest.asset_type == "texture" ||
137 // llsdRequest.asset_type == "animation" ||
138 // llsdRequest.asset_type == "sound")
139 // {
140 // check user level
141
142 ScenePresence avatar = null;
143 IClientAPI client = null;
144 m_scene.TryGetScenePresence(agentID, out avatar);
145
146 if (avatar != null)
147 {
148 client = avatar.ControllingClient;
149
150 if (avatar.UserLevel < m_levelUpload)
151 {
152 if (client != null)
153 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
154
155 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
156 errorResponse.rsvp = "";
157 errorResponse.state = "error";
158 return errorResponse;
159 }
160 }
161
162 // check funds
163 IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>();
164
165 if (mm != null)
166 {
167 if (!mm.UploadCovered(agentID, mm.UploadCharge))
168 {
169 if (client != null)
170 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
171
172 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
173 errorResponse.rsvp = "";
174 errorResponse.state = "error";
175 return errorResponse;
176 }
177 }
178
179 // }
180
181 string assetName = llsdRequest.name;
182 string assetDes = llsdRequest.description;
183 string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/";
184 UUID newAsset = UUID.Random();
185 UUID newInvItem = UUID.Random();
186 UUID parentFolder = llsdRequest.folder_id;
187 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/";
188
189 AssetUploader uploader =
190 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
191 llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile);
192
193 MainServer.Instance.AddStreamHandler(
194 new BinaryStreamHandler(
195 "POST",
196 capsBase + uploaderPath,
197 uploader.uploaderCaps,
198 "NewFileAgentInventoryVariablePrice",
199 agentID.ToString()));
200
201 string protocol = "http://";
202
203 if (MainServer.Instance.UseSSL)
204 protocol = "https://";
205
206 string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase +
207 uploaderPath;
208
209
210 LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
211
212 uploadResponse.rsvp = uploaderURL;
213 uploadResponse.state = "upload";
214 uploadResponse.resource_cost = 0;
215 uploadResponse.upload_price = 0;
216
217 uploader.OnUpLoad += //UploadCompleteHandler;
218
219 delegate(
220 string passetName, string passetDescription, UUID passetID,
221 UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType,
222 string passetType)
223 {
224 UploadCompleteHandler(passetName, passetDescription, passetID,
225 pinventoryItem, pparentFolder, pdata, pinventoryType,
226 passetType,agentID);
227 };
228
229 return uploadResponse;
230 }
231
232 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
233 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
234 string assetType,UUID AgentID)
235 {
236// m_log.DebugFormat(
237// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem);
238
239 sbyte assType = 0;
240 sbyte inType = 0;
241
242 if (inventoryType == "sound")
243 {
244 inType = 1;
245 assType = 1;
246 }
247 else if (inventoryType == "animation")
248 {
249 inType = 19;
250 assType = 20;
251 }
252 else if (inventoryType == "wearable")
253 {
254 inType = 18;
255 switch (assetType)
256 {
257 case "bodypart":
258 assType = 13;
259 break;
260 case "clothing":
261 assType = 5;
262 break;
263 }
264 }
265 else if (inventoryType == "mesh")
266 {
267 inType = (sbyte)InventoryType.Mesh;
268 assType = (sbyte)AssetType.Mesh;
269 }
270
271 AssetBase asset;
272 asset = new AssetBase(assetID, assetName, assType, AgentID.ToString());
273 asset.Data = data;
274
275 if (m_scene.AssetService != null)
276 m_scene.AssetService.Store(asset);
277
278 InventoryItemBase item = new InventoryItemBase();
279 item.Owner = AgentID;
280 item.CreatorId = AgentID.ToString();
281 item.ID = inventoryItem;
282 item.AssetID = asset.FullID;
283 item.Description = assetDescription;
284 item.Name = assetName;
285 item.AssetType = assType;
286 item.InvType = inType;
287 item.Folder = parentFolder;
288 item.CurrentPermissions
289 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
290 item.BasePermissions = (uint)PermissionMask.All;
291 item.EveryOnePermissions = 0;
292 item.NextPermissions = (uint)PermissionMask.All;
293 item.CreationDate = Util.UnixTimeSinceEpoch();
294 m_scene.AddInventoryItem(item);
295 }
296 }
297}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs
index a133a69..5196368 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs
@@ -64,6 +64,8 @@ namespace OpenSim.Region.ClientStack.Linden
64 private Commands m_commands = new Commands(); 64 private Commands m_commands = new Commands();
65 public ICommands Commands { get { return m_commands; } } 65 public ICommands Commands { get { return m_commands; } }
66 66
67 public event ConsoleMessage OnConsoleMessage;
68
67 public void Initialise(IConfigSource source) 69 public void Initialise(IConfigSource source)
68 { 70 {
69 m_commands.AddCommand( "Help", false, "help", "help [<item>]", "Display help on a particular command or on a list of commands in a category", Help); 71 m_commands.AddCommand( "Help", false, "help", "help [<item>]", "Display help on a particular command or on a list of commands in a category", Help);
@@ -102,7 +104,7 @@ namespace OpenSim.Region.ClientStack.Linden
102 104
103 public void RegisterCaps(UUID agentID, Caps caps) 105 public void RegisterCaps(UUID agentID, Caps caps)
104 { 106 {
105 if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID)) 107 if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID) && !m_scene.Permissions.IsGod(agentID))
106 return; 108 return;
107 109
108 UUID capID = UUID.Random(); 110 UUID capID = UUID.Random();
@@ -118,6 +120,11 @@ namespace OpenSim.Region.ClientStack.Linden
118 OSD osd = OSD.FromString(message); 120 OSD osd = OSD.FromString(message);
119 121
120 m_eventQueue.Enqueue(EventQueueHelper.BuildEvent("SimConsoleResponse", osd), agentID); 122 m_eventQueue.Enqueue(EventQueueHelper.BuildEvent("SimConsoleResponse", osd), agentID);
123
124 ConsoleMessage handlerConsoleMessage = OnConsoleMessage;
125
126 if (handlerConsoleMessage != null)
127 handlerConsoleMessage( agentID, message);
121 } 128 }
122 129
123 public bool RunCommand(string command, UUID invokerID) 130 public bool RunCommand(string command, UUID invokerID)
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
index e258bcb..54542c9 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs
@@ -155,8 +155,13 @@ namespace OpenSim.Region.ClientStack.Linden
155 m_features["MeshRezEnabled"] = true; 155 m_features["MeshRezEnabled"] = true;
156 m_features["MeshUploadEnabled"] = true; 156 m_features["MeshUploadEnabled"] = true;
157 m_features["MeshXferEnabled"] = true; 157 m_features["MeshXferEnabled"] = true;
158
158 m_features["PhysicsMaterialsEnabled"] = true; 159 m_features["PhysicsMaterialsEnabled"] = true;
160<<<<<<< HEAD
159 161
162=======
163
164>>>>>>> avn/ubitvar
160 OSDMap typesMap = new OSDMap(); 165 OSDMap typesMap = new OSDMap();
161 typesMap["convex"] = true; 166 typesMap["convex"] = true;
162 typesMap["none"] = true; 167 typesMap["none"] = true;
@@ -164,6 +169,7 @@ namespace OpenSim.Region.ClientStack.Linden
164 m_features["PhysicsShapeTypes"] = typesMap; 169 m_features["PhysicsShapeTypes"] = typesMap;
165 170
166 // Extra information for viewers that want to use it 171 // Extra information for viewers that want to use it
172<<<<<<< HEAD
167 // TODO: Take these out of here into their respective modules, like map-server-url 173 // TODO: Take these out of here into their respective modules, like map-server-url
168 OSDMap extrasMap; 174 OSDMap extrasMap;
169 if(m_features.ContainsKey("OpenSimExtras")) 175 if(m_features.ContainsKey("OpenSimExtras"))
@@ -173,6 +179,15 @@ namespace OpenSim.Region.ClientStack.Linden
173 else 179 else
174 extrasMap = new OSDMap(); 180 extrasMap = new OSDMap();
175 181
182=======
183
184 OSDMap extrasMap = new OSDMap();
185
186 extrasMap["AvatarSkeleton"] = true;
187 extrasMap["AnimationSet"] = true;
188
189 // TODO: Take these out of here into their respective modules, like map-server-url
190>>>>>>> avn/ubitvar
176 if (m_SearchURL != string.Empty) 191 if (m_SearchURL != string.Empty)
177 extrasMap["search-server-url"] = m_SearchURL; 192 extrasMap["search-server-url"] = m_SearchURL;
178 if (!string.IsNullOrEmpty(m_DestinationGuideURL)) 193 if (!string.IsNullOrEmpty(m_DestinationGuideURL))
@@ -184,8 +199,13 @@ namespace OpenSim.Region.ClientStack.Linden
184 if (m_GridName != string.Empty) 199 if (m_GridName != string.Empty)
185 extrasMap["GridName"] = m_GridName; 200 extrasMap["GridName"] = m_GridName;
186 201
202<<<<<<< HEAD
187 if (extrasMap.Count > 0) 203 if (extrasMap.Count > 0)
188 m_features["OpenSimExtras"] = extrasMap; 204 m_features["OpenSimExtras"] = extrasMap;
205=======
206 m_features["OpenSimExtras"] = extrasMap;
207
208>>>>>>> avn/ubitvar
189 } 209 }
190 } 210 }
191 211
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
index 8cdebcd..c27d101 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
@@ -67,6 +67,8 @@ namespace OpenSim.Region.ClientStack.Linden
67 67
68 private IBakedTextureModule m_BakedTextureModule; 68 private IBakedTextureModule m_BakedTextureModule;
69 69
70 private IBakedTextureModule m_BakedTextureModule;
71
70 public void Initialise(IConfigSource source) 72 public void Initialise(IConfigSource source)
71 { 73 {
72 IConfig appearanceConfig = source.Configs["Appearance"]; 74 IConfig appearanceConfig = source.Configs["Appearance"];
@@ -89,7 +91,11 @@ namespace OpenSim.Region.ClientStack.Linden
89 s.EventManager.OnRemovePresence -= DeRegisterPresence; 91 s.EventManager.OnRemovePresence -= DeRegisterPresence;
90 m_BakedTextureModule = null; 92 m_BakedTextureModule = null;
91 m_scene = null; 93 m_scene = null;
94<<<<<<< HEAD
92 } 95 }
96=======
97 }
98>>>>>>> avn/ubitvar
93 99
94 100
95 101
@@ -103,6 +109,7 @@ namespace OpenSim.Region.ClientStack.Linden
103 109
104 private void DeRegisterPresence(UUID agentId) 110 private void DeRegisterPresence(UUID agentId)
105 { 111 {
112<<<<<<< HEAD
106 ScenePresence presence = null; 113 ScenePresence presence = null;
107 if (m_scene.TryGetScenePresence(agentId, out presence)) 114 if (m_scene.TryGetScenePresence(agentId, out presence))
108 { 115 {
@@ -261,8 +268,162 @@ namespace OpenSim.Region.ClientStack.Linden
261 } 268 }
262 } 269 }
263 } 270 }
271=======
272// ScenePresence presence = null;
273// if (m_scene.TryGetScenePresence(agentId, out presence))
274 {
275// presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings;
276 }
277
278>>>>>>> avn/ubitvar
279 }
280
281 private void RegisterNewPresence(ScenePresence presence)
282 {
283// presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings;
264 } 284 }
265 285
286/* not in use. work done in AvatarFactoryModule ValidateBakedTextureCache() and UpdateBakedTextureCache()
287 private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems)
288 {
289 // if cacheItems.Length > 0 viewer is giving us current textures information.
290 // baked ones should had been uploaded and in assets cache as local itens
291
292
293 if (cacheItems.Length == 0)
294 return; // no textures information, nothing to do
295
296 ScenePresence p = null;
297 if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
298 return; // what are we doing if there is no presence to cache for?
299
300 if (p.IsDeleted)
301 return; // does this really work?
302
303 int maxCacheitemsLoop = cacheItems.Length;
304 if (maxCacheitemsLoop > 20)
305 {
306 maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
307 m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
308 }
309
310 m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
311
312
313 // some nice debug
314 m_log.Debug("[Cacheitems]: " + cacheItems.Length);
315 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
316 {
317 m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
318 cacheItems[iter].TextureID);
319 }
320
321 // p.Appearance.WearableCacheItems is in memory primary cashID to textures mapper
322
323 WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems;
324
325 if (existingitems == null)
326 {
327 if (m_BakedTextureModule != null)
328 {
329 WearableCacheItem[] savedcache = null;
330 try
331 {
332 if (p.Appearance.WearableCacheItemsDirty)
333 {
334 savedcache = m_BakedTextureModule.Get(p.UUID);
335 p.Appearance.WearableCacheItems = savedcache;
336 p.Appearance.WearableCacheItemsDirty = false;
337 }
338 }
339
340 catch (Exception)
341 {
342 // The service logs a sufficient error message.
343 }
344
345
346 if (savedcache != null)
347 existingitems = savedcache;
348 }
349 }
350
351 // Existing items null means it's a fully new appearance
352 if (existingitems == null)
353 {
354 for (int i = 0; i < maxCacheitemsLoop; i++)
355 {
356 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
357 {
358 Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex];
359 if (face == null)
360 {
361 textureEntry.CreateFace(cacheItems[i].TextureIndex);
362 textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID =
363 AppearanceManager.DEFAULT_AVATAR_TEXTURE;
364 continue;
365 }
366 cacheItems[i].TextureID = face.TextureID;
367 if (m_scene.AssetService != null)
368 cacheItems[i].TextureAsset =
369 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
370 }
371 else
372 {
373 m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length);
374 }
375 }
376 }
377 else
378 {
379 for (int i = 0; i < maxCacheitemsLoop; i++)
380 {
381 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
382 {
383 Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex];
384 if (face == null)
385 {
386 textureEntry.CreateFace(cacheItems[i].TextureIndex);
387 textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID =
388 AppearanceManager.DEFAULT_AVATAR_TEXTURE;
389 continue;
390 }
391 cacheItems[i].TextureID =
392 face.TextureID;
393 }
394 else
395 {
396 m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length);
397 }
398 }
399
400 for (int i = 0; i < maxCacheitemsLoop; i++)
401 {
402 if (cacheItems[i].TextureAsset == null)
403 {
404 cacheItems[i].TextureAsset =
405 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
406 }
407 }
408 }
409 p.Appearance.WearableCacheItems = cacheItems;
410
411 if (m_BakedTextureModule != null)
412 {
413 m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems);
414 p.Appearance.WearableCacheItemsDirty = true;
415
416 }
417 else
418 p.Appearance.WearableCacheItemsDirty = false;
419
420 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
421 {
422 m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
423 cacheItems[iter].TextureID);
424 }
425 }
426 */
266 public void PostInitialise() 427 public void PostInitialise()
267 { 428 {
268 } 429 }
@@ -283,6 +444,7 @@ namespace OpenSim.Region.ClientStack.Linden
283 UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( 444 UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler(
284 caps, m_scene.AssetService, m_persistBakedTextures); 445 caps, m_scene.AssetService, m_persistBakedTextures);
285 446
447<<<<<<< HEAD
286 448
287 449
288 caps.RegisterHandler( 450 caps.RegisterHandler(
@@ -297,6 +459,28 @@ namespace OpenSim.Region.ClientStack.Linden
297 459
298 460
299 461
462=======
463 //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture));
464 if (m_URL == "localhost")
465 {
466 UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler(
467 caps, m_scene.AssetService, m_persistBakedTextures);
468
469 caps.RegisterHandler(
470 "UploadBakedTexture",
471 new RestStreamHandler(
472 "POST",
473 "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath,
474 avatarhandler.UploadBakedTexture,
475 "UploadBakedTexture",
476 agentID.ToString()));
477
478 }
479 else
480 {
481 caps.RegisterHandler("UploadBakedTexture", m_URL);
482 }
483>>>>>>> avn/ubitvar
300 } 484 }
301 } 485 }
302} 486}
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
index 025ffea..92f8c51 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
@@ -34,9 +34,7 @@ using log4net;
34using Nini.Config; 34using Nini.Config;
35using Mono.Addins; 35using Mono.Addins;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework; 37using OpenSim.Framework;
39using OpenSim.Framework.Monitoring;
40using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
@@ -45,6 +43,9 @@ using OpenSim.Framework.Capabilities;
45using OpenSim.Services.Interfaces; 43using OpenSim.Services.Interfaces;
46using Caps = OpenSim.Framework.Capabilities.Caps; 44using Caps = OpenSim.Framework.Capabilities.Caps;
47using OpenSim.Capabilities.Handlers; 45using OpenSim.Capabilities.Handlers;
46using OpenSim.Framework.Monitoring;
47using OpenMetaverse;
48using OpenMetaverse.StructuredData;
48 49
49namespace OpenSim.Region.ClientStack.Linden 50namespace OpenSim.Region.ClientStack.Linden
50{ 51{
@@ -63,7 +64,11 @@ namespace OpenSim.Region.ClientStack.Linden
63 public List<UUID> folders; 64 public List<UUID> folders;
64 } 65 }
65 66
67<<<<<<< HEAD
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 68 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
69=======
70 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
71>>>>>>> avn/ubitvar
67 72
68 /// <summary> 73 /// <summary>
69 /// Control whether requests will be processed asynchronously. 74 /// Control whether requests will be processed asynchronously.
@@ -312,7 +317,8 @@ namespace OpenSim.Region.ClientStack.Linden
312 { 317 {
313 if (!reqinfo.folders.Contains(folderID)) 318 if (!reqinfo.folders.Contains(folderID))
314 { 319 {
315 //TODO: Port COF handling from Avination 320 if (sp.COF != UUID.Zero && sp.COF == folderID)
321 highPriority = true;
316 reqinfo.folders.Add(folderID); 322 reqinfo.folders.Add(folderID);
317 } 323 }
318 } 324 }
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs b/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs
index 4d0568d..15d6f7f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs
@@ -234,6 +234,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
234 m_stopPacket = TexturePacketCount(); 234 m_stopPacket = TexturePacketCount();
235 } 235 }
236 236
237 //Give them at least two packets, to play nice with some broken viewers (SL also behaves this way)
238 if (m_stopPacket == 1 && m_layers[0].End > FIRST_PACKET_SIZE) m_stopPacket++;
239
237 m_currentPacket = StartPacket; 240 m_currentPacket = StartPacket;
238 } 241 }
239 } 242 }
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index e7dd9d3..806269f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -100,6 +100,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
100 public event AvatarPickerRequest OnAvatarPickerRequest; 100 public event AvatarPickerRequest OnAvatarPickerRequest;
101 public event StartAnim OnStartAnim; 101 public event StartAnim OnStartAnim;
102 public event StopAnim OnStopAnim; 102 public event StopAnim OnStopAnim;
103 public event ChangeAnim OnChangeAnim;
103 public event Action<IClientAPI> OnRequestAvatarsData; 104 public event Action<IClientAPI> OnRequestAvatarsData;
104 public event LinkObjects OnLinkObjects; 105 public event LinkObjects OnLinkObjects;
105 public event DelinkObjects OnDelinkObjects; 106 public event DelinkObjects OnDelinkObjects;
@@ -127,6 +128,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
127 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily; 128 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
128 public event UpdatePrimFlags OnUpdatePrimFlags; 129 public event UpdatePrimFlags OnUpdatePrimFlags;
129 public event UpdatePrimTexture OnUpdatePrimTexture; 130 public event UpdatePrimTexture OnUpdatePrimTexture;
131 public event ClientChangeObject onClientChangeObject;
130 public event UpdateVector OnUpdatePrimGroupPosition; 132 public event UpdateVector OnUpdatePrimGroupPosition;
131 public event UpdateVector OnUpdatePrimSinglePosition; 133 public event UpdateVector OnUpdatePrimSinglePosition;
132 public event UpdatePrimRotation OnUpdatePrimGroupRotation; 134 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
@@ -156,6 +158,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
156 public event RequestTaskInventory OnRequestTaskInventory; 158 public event RequestTaskInventory OnRequestTaskInventory;
157 public event UpdateInventoryItem OnUpdateInventoryItem; 159 public event UpdateInventoryItem OnUpdateInventoryItem;
158 public event CopyInventoryItem OnCopyInventoryItem; 160 public event CopyInventoryItem OnCopyInventoryItem;
161 public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
159 public event MoveInventoryItem OnMoveInventoryItem; 162 public event MoveInventoryItem OnMoveInventoryItem;
160 public event RemoveInventoryItem OnRemoveInventoryItem; 163 public event RemoveInventoryItem OnRemoveInventoryItem;
161 public event RemoveInventoryFolder OnRemoveInventoryFolder; 164 public event RemoveInventoryFolder OnRemoveInventoryFolder;
@@ -250,7 +253,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
250 public event ClassifiedInfoRequest OnClassifiedInfoRequest; 253 public event ClassifiedInfoRequest OnClassifiedInfoRequest;
251 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; 254 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
252 public event ClassifiedDelete OnClassifiedDelete; 255 public event ClassifiedDelete OnClassifiedDelete;
253 public event ClassifiedDelete OnClassifiedGodDelete; 256 public event ClassifiedGodDelete OnClassifiedGodDelete;
254 public event EventNotificationAddRequest OnEventNotificationAddRequest; 257 public event EventNotificationAddRequest OnEventNotificationAddRequest;
255 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; 258 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
256 public event EventGodDelete OnEventGodDelete; 259 public event EventGodDelete OnEventGodDelete;
@@ -281,10 +284,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
281 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; 284 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
282 public event SimWideDeletesDelegate OnSimWideDeletes; 285 public event SimWideDeletesDelegate OnSimWideDeletes;
283 public event SendPostcard OnSendPostcard; 286 public event SendPostcard OnSendPostcard;
287 public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
284 public event MuteListEntryUpdate OnUpdateMuteListEntry; 288 public event MuteListEntryUpdate OnUpdateMuteListEntry;
285 public event MuteListEntryRemove OnRemoveMuteListEntry; 289 public event MuteListEntryRemove OnRemoveMuteListEntry;
286 public event GodlikeMessage onGodlikeMessage; 290 public event GodlikeMessage onGodlikeMessage;
287 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 291 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
292 public event GenericCall2 OnUpdateThrottles;
288 293
289#pragma warning disable 0067 294#pragma warning disable 0067
290 public event GenericMessage OnGenericMessage; 295 public event GenericMessage OnGenericMessage;
@@ -333,7 +338,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
333 private PriorityQueue m_entityProps; 338 private PriorityQueue m_entityProps;
334 private Prioritizer m_prioritizer; 339 private Prioritizer m_prioritizer;
335 private bool m_disableFacelights = false; 340 private bool m_disableFacelights = false;
336 private volatile bool m_justEditedTerrain = false; 341
342 private bool m_VelocityInterpolate = false;
343 private const uint MaxTransferBytesPerPacket = 600;
344
337 /// <value> 345 /// <value>
338 /// List used in construction of data blocks for an object update packet. This is to stop us having to 346 /// List used in construction of data blocks for an object update packet. This is to stop us having to
339 /// continually recreate it. 347 /// continually recreate it.
@@ -345,14 +353,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
345 /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an 353 /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
346 /// ownerless phantom. 354 /// ownerless phantom.
347 /// 355 ///
348 /// All manipulation of this set has to occur under a lock 356 /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock
349 /// 357 ///
350 /// </value> 358 /// </value>
351 protected HashSet<uint> m_killRecord; 359// protected HashSet<uint> m_killRecord;
352 360
353// protected HashSet<uint> m_attachmentsSent; 361// protected HashSet<uint> m_attachmentsSent;
354 362
355 private int m_animationSequenceNumber = 1; 363 private bool m_deliverPackets = true;
364
356 private bool m_SendLogoutPacketWhenClosing = true; 365 private bool m_SendLogoutPacketWhenClosing = true;
357 366
358 /// <summary> 367 /// <summary>
@@ -398,6 +407,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
398 get { return m_startpos; } 407 get { return m_startpos; }
399 set { m_startpos = value; } 408 set { m_startpos = value; }
400 } 409 }
410 public bool DeliverPackets
411 {
412 get { return m_deliverPackets; }
413 set {
414 m_deliverPackets = value;
415 m_udpClient.m_deliverPackets = value;
416 }
417 }
401 public UUID AgentId { get { return m_agentId; } } 418 public UUID AgentId { get { return m_agentId; } }
402 public ISceneAgent SceneAgent { get; set; } 419 public ISceneAgent SceneAgent { get; set; }
403 public UUID ActiveGroupId { get { return m_activeGroupID; } private set { m_activeGroupID = value; } } 420 public UUID ActiveGroupId { get { return m_activeGroupID; } private set { m_activeGroupID = value; } }
@@ -405,6 +422,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
405 public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } private set { m_activeGroupPowers = value; } } 422 public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } private set { m_activeGroupPowers = value; } }
406 public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); } 423 public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); }
407 424
425 public int PingTimeMS
426 {
427 get
428 {
429 if (UDPClient != null)
430 return UDPClient.PingTimeMS;
431 return 0;
432 }
433 }
434
408 /// <summary> 435 /// <summary>
409 /// Entity update queues 436 /// Entity update queues
410 /// </summary> 437 /// </summary>
@@ -426,7 +453,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
426 public string Name { get { return FirstName + " " + LastName; } } 453 public string Name { get { return FirstName + " " + LastName; } }
427 454
428 public uint CircuitCode { get { return m_circuitCode; } } 455 public uint CircuitCode { get { return m_circuitCode; } }
429 public int NextAnimationSequenceNumber { get { return m_animationSequenceNumber++; } } 456 public int NextAnimationSequenceNumber
457 {
458 get { return m_udpServer.NextAnimationSequenceNumber; }
459 }
430 460
431 /// <summary> 461 /// <summary>
432 /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to 462 /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to
@@ -447,7 +477,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
447 set { m_disableFacelights = value; } 477 set { m_disableFacelights = value; }
448 } 478 }
449 479
480 public List<uint> SelectedObjects {get; private set;}
481
450 public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } } 482 public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } }
483
451 484
452 #endregion Properties 485 #endregion Properties
453 486
@@ -465,6 +498,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
465// DebugPacketLevel = 1; 498// DebugPacketLevel = 1;
466 499
467 CloseSyncLock = new Object(); 500 CloseSyncLock = new Object();
501 SelectedObjects = new List<uint>();
468 502
469 RegisterInterface<IClientIM>(this); 503 RegisterInterface<IClientIM>(this);
470 RegisterInterface<IClientInventory>(this); 504 RegisterInterface<IClientInventory>(this);
@@ -474,7 +508,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
474 m_entityUpdates = new PriorityQueue(m_scene.Entities.Count); 508 m_entityUpdates = new PriorityQueue(m_scene.Entities.Count);
475 m_entityProps = new PriorityQueue(m_scene.Entities.Count); 509 m_entityProps = new PriorityQueue(m_scene.Entities.Count);
476 m_fullUpdateDataBlocksBuilder = new List<ObjectUpdatePacket.ObjectDataBlock>(); 510 m_fullUpdateDataBlocksBuilder = new List<ObjectUpdatePacket.ObjectDataBlock>();
477 m_killRecord = new HashSet<uint>(); 511// m_killRecord = new HashSet<uint>();
478// m_attachmentsSent = new HashSet<uint>(); 512// m_attachmentsSent = new HashSet<uint>();
479 513
480 m_assetService = m_scene.RequestModuleInterface<IAssetService>(); 514 m_assetService = m_scene.RequestModuleInterface<IAssetService>();
@@ -504,12 +538,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
504 538
505 #region Client Methods 539 #region Client Methods
506 540
541
542 /// <summary>
543 /// Close down the client view
544 /// </summary>
507 public void Close() 545 public void Close()
508 { 546 {
509 Close(false); 547 Close(true, false);
510 } 548 }
511 549
512 public void Close(bool force) 550 public void Close(bool sendStop, bool force)
513 { 551 {
514 // We lock here to prevent race conditions between two threads calling close simultaneously (e.g. 552 // We lock here to prevent race conditions between two threads calling close simultaneously (e.g.
515 // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection. 553 // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection.
@@ -526,7 +564,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
526 } 564 }
527 565
528 IsActive = false; 566 IsActive = false;
529 CloseWithoutChecks(); 567 CloseWithoutChecks(sendStop);
530 } 568 }
531 } 569 }
532 570
@@ -539,12 +577,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
539 /// 577 ///
540 /// Callers must lock ClosingSyncLock before calling. 578 /// Callers must lock ClosingSyncLock before calling.
541 /// </remarks> 579 /// </remarks>
542 public void CloseWithoutChecks() 580 public void CloseWithoutChecks(bool sendStop)
543 { 581 {
544 m_log.DebugFormat( 582 m_log.DebugFormat(
545 "[CLIENT]: Close has been called for {0} attached to scene {1}", 583 "[CLIENT]: Close has been called for {0} attached to scene {1}",
546 Name, m_scene.RegionInfo.RegionName); 584 Name, m_scene.RegionInfo.RegionName);
547 585
586 if (sendStop)
587 {
588 // Send the STOP packet
589 DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
590 OutPacket(disable, ThrottleOutPacketType.Unknown);
591 }
592
548 // Shutdown the image manager 593 // Shutdown the image manager
549 ImageManager.Close(); 594 ImageManager.Close();
550 595
@@ -566,7 +611,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
566 611
567 // Disable UDP handling for this client 612 // Disable UDP handling for this client
568 m_udpClient.Shutdown(); 613 m_udpClient.Shutdown();
569 614
615
570 //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false)); 616 //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
571 //GC.Collect(); 617 //GC.Collect();
572 //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true)); 618 //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
@@ -677,7 +723,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
677 if (!m_packetHandlers.ContainsKey(packetType)) 723 if (!m_packetHandlers.ContainsKey(packetType))
678 { 724 {
679 m_packetHandlers.Add( 725 m_packetHandlers.Add(
726<<<<<<< HEAD
680 packetType, new PacketProcessor() { method = handler, Async = doAsync, InEngine = inEngine }); 727 packetType, new PacketProcessor() { method = handler, Async = doAsync, InEngine = inEngine });
728=======
729 packetType, new PacketProcessor() { method = handler, Async = doAsync });
730>>>>>>> avn/ubitvar
681 result = true; 731 result = true;
682 } 732 }
683 } 733 }
@@ -858,6 +908,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
858 908
859 public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) 909 public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
860 { 910 {
911 m_thisAgentUpdateArgs.CameraAtAxis.X = float.MinValue;
912 m_thisAgentUpdateArgs.ControlFlags = uint.MaxValue;
913
861 AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete); 914 AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
862 mov.SimData.ChannelVersion = m_channelVersion; 915 mov.SimData.ChannelVersion = m_channelVersion;
863 mov.AgentData.SessionID = m_sessionId; 916 mov.AgentData.SessionID = m_sessionId;
@@ -893,7 +946,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
893 reply.ChatData.OwnerID = ownerID; 946 reply.ChatData.OwnerID = ownerID;
894 reply.ChatData.SourceID = fromAgentID; 947 reply.ChatData.SourceID = fromAgentID;
895 948
896 OutPacket(reply, ThrottleOutPacketType.Task); 949 OutPacket(reply, ThrottleOutPacketType.Unknown);
897 } 950 }
898 951
899 /// <summary> 952 /// <summary>
@@ -926,32 +979,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
926 msg.MessageBlock.Message = Util.StringToBytes1024(im.message); 979 msg.MessageBlock.Message = Util.StringToBytes1024(im.message);
927 msg.MessageBlock.BinaryBucket = im.binaryBucket; 980 msg.MessageBlock.BinaryBucket = im.binaryBucket;
928 981
929 if (im.message.StartsWith("[grouptest]")) 982 OutPacket(msg, ThrottleOutPacketType.Task);
930 { // this block is test code for implementing group IM - delete when group IM is finished
931 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
932 if (eq != null)
933 {
934 im.dialog = 17;
935
936 //eq.ChatterboxInvitation(
937 // new UUID("00000000-68f9-1111-024e-222222111123"),
938 // "OpenSimulator Testing", im.fromAgentID, im.message, im.toAgentID, im.fromAgentName, im.dialog, 0,
939 // false, 0, new Vector3(), 1, im.imSessionID, im.fromGroup, im.binaryBucket);
940
941 eq.ChatterboxInvitation(
942 new UUID("00000000-68f9-1111-024e-222222111123"),
943 "OpenSimulator Testing", new UUID(im.fromAgentID), im.message, new UUID(im.toAgentID), im.fromAgentName, im.dialog, 0,
944 false, 0, new Vector3(), 1, new UUID(im.imSessionID), im.fromGroup, Util.StringToBytes256("OpenSimulator Testing"));
945
946 eq.ChatterBoxSessionAgentListUpdates(
947 new UUID("00000000-68f9-1111-024e-222222111123"),
948 new UUID(im.fromAgentID), new UUID(im.toAgentID), false, false, false);
949 }
950
951 Console.WriteLine("SendInstantMessage: " + msg);
952 }
953 else
954 OutPacket(msg, ThrottleOutPacketType.Task);
955 } 983 }
956 } 984 }
957 985
@@ -1182,6 +1210,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1182 OutPacket(GATRP, ThrottleOutPacketType.Task); 1210 OutPacket(GATRP, ThrottleOutPacketType.Task);
1183 } 1211 }
1184 1212
1213
1214 public virtual bool CanSendLayerData()
1215 {
1216 int n = m_udpClient.GetCatBytesInSendQueue(ThrottleOutPacketType.Land);
1217 if ( n > 100000)
1218 return false;
1219 return true;
1220 }
1221
1185 /// <summary> 1222 /// <summary>
1186 /// Send the region heightmap to the client 1223 /// Send the region heightmap to the client
1187 /// This method is only called when not doing intellegent terrain patch sending and 1224 /// This method is only called when not doing intellegent terrain patch sending and
@@ -1191,7 +1228,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1191 /// <param name="map">heightmap</param> 1228 /// <param name="map">heightmap</param>
1192 public virtual void SendLayerData(float[] map) 1229 public virtual void SendLayerData(float[] map)
1193 { 1230 {
1231<<<<<<< HEAD
1194 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData(), "LLClientView.DoSendLayerData"); 1232 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData(), "LLClientView.DoSendLayerData");
1233=======
1234 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData());
1235
1236 // Send it sync, and async. It's not that much data
1237 // and it improves user experience just so much!
1238// DoSendLayerData(map);
1239>>>>>>> avn/ubitvar
1195 } 1240 }
1196 1241
1197 /// <summary> 1242 /// <summary>
@@ -1205,6 +1250,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1205 try 1250 try
1206 { 1251 {
1207 // Send LayerData in typerwriter pattern 1252 // Send LayerData in typerwriter pattern
1253<<<<<<< HEAD
1208 //for (int y = 0; y < 16; y++) 1254 //for (int y = 0; y < 16; y++)
1209 //{ 1255 //{
1210 // for (int x = 0; x < 16; x++) 1256 // for (int x = 0; x < 16; x++)
@@ -1215,6 +1261,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1215 1261
1216 // Send LayerData in a spiral pattern. Fun! 1262 // Send LayerData in a spiral pattern. Fun!
1217 SendLayerTopRight(map, 0, 0, map.SizeX/Constants.TerrainPatchSize-1, map.SizeY/Constants.TerrainPatchSize-1); 1263 SendLayerTopRight(map, 0, 0, map.SizeX/Constants.TerrainPatchSize-1, map.SizeY/Constants.TerrainPatchSize-1);
1264=======
1265 for (int y = 0; y < 16; y++)
1266 {
1267 for (int x = 0; x < 16; x++)
1268 {
1269 SendLayerData(x, y, map);
1270 }
1271 }
1272>>>>>>> avn/ubitvar
1218 } 1273 }
1219 catch (Exception e) 1274 catch (Exception e)
1220 { 1275 {
@@ -1222,16 +1277,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1222 } 1277 }
1223 } 1278 }
1224 1279
1280<<<<<<< HEAD
1225 private void SendLayerTopRight(TerrainData map, int x1, int y1, int x2, int y2) 1281 private void SendLayerTopRight(TerrainData map, int x1, int y1, int x2, int y2)
1282=======
1283 // Legacy form of invocation that passes around a bare data array.
1284 // Just ignore what was passed and use the real terrain info that is part of the scene.
1285 // As a HORRIBLE kludge in an attempt to not change the definition of IClientAPI,
1286 // there is a special form for specifying multiple terrain patches to send.
1287 // The form is to pass 'px' as negative the number of patches to send and to
1288 // pass the float array as pairs of patch X and Y coordinates. So, passing 'px'
1289 // as -2 and map= [3, 5, 8, 4] would mean to send two terrain heightmap patches
1290 // and the patches to send are <3,5> and <8,4>.
1291 public void SendLayerData(int px, int py, float[] map)
1292>>>>>>> avn/ubitvar
1226 { 1293 {
1227 // Row 1294 if (px >= 0)
1228 for (int i = x1; i <= x2; i++) 1295 {
1229 SendLayerData(i, y1, map); 1296 SendLayerData(px, py, m_scene.Heightmap.GetTerrainData());
1297 }
1298 else
1299 {
1300 int numPatches = -px;
1301 int[] xPatches = new int[numPatches];
1302 int[] yPatches = new int[numPatches];
1303 for (int pp = 0; pp < numPatches; pp++)
1304 {
1305 xPatches[pp] = (int)map[pp * 2];
1306 yPatches[pp] = (int)map[pp * 2 + 1];
1307 }
1230 1308
1231 // Column 1309 // DebugSendingPatches("SendLayerData", xPatches, yPatches);
1232 for (int j = y1 + 1; j <= y2; j++)
1233 SendLayerData(x2, j, map);
1234 1310
1311<<<<<<< HEAD
1235 if (x2 - x1 > 0 && y2 - y1 > 0) 1312 if (x2 - x1 > 0 && y2 - y1 > 0)
1236 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2); 1313 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2);
1237 } 1314 }
@@ -1316,6 +1393,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1316 } 1393 }
1317 1394
1318 /// <summary> 1395 /// <summary>
1396=======
1397 SendLayerData(xPatches, yPatches, m_scene.Heightmap.GetTerrainData());
1398 }
1399 }
1400
1401 private void DebugSendingPatches(string pWho, int[] pX, int[] pY)
1402 {
1403 if (m_log.IsDebugEnabled)
1404 {
1405 int numPatches = pX.Length;
1406 string Xs = "";
1407 string Ys = "";
1408 for (int pp = 0; pp < numPatches; pp++)
1409 {
1410 Xs += String.Format("{0}", (int)pX[pp]) + ",";
1411 Ys += String.Format("{0}", (int)pY[pp]) + ",";
1412 }
1413 m_log.DebugFormat("{0} {1}: numPatches={2}, X={3}, Y={4}", LogHeader, pWho, numPatches, Xs, Ys);
1414 }
1415 }
1416
1417 /// <summary>
1418>>>>>>> avn/ubitvar
1319 /// Sends a terrain packet for the point specified. 1419 /// Sends a terrain packet for the point specified.
1320 /// This is a legacy call that has refarbed the terrain into a flat map of floats. 1420 /// This is a legacy call that has refarbed the terrain into a flat map of floats.
1321 /// We just use the terrain from the region we know about. 1421 /// We just use the terrain from the region we know about.
@@ -1367,6 +1467,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1367 } 1467 }
1368 } 1468 }
1369 1469
1470<<<<<<< HEAD
1370 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a 1471 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a
1371 // sub optimal editing experience. To alleviate this issue, when the user edits the terrain, we 1472 // sub optimal editing experience. To alleviate this issue, when the user edits the terrain, we
1372 // start skipping the queues until they're done editing the terrain. We also make them 1473 // start skipping the queues until they're done editing the terrain. We also make them
@@ -1395,6 +1496,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1395 layerpack.Header.Reliable = true; 1496 layerpack.Header.Reliable = true;
1396 OutPacket(layerpack, ThrottleOutPacketType.Land); 1497 OutPacket(layerpack, ThrottleOutPacketType.Land);
1397 } 1498 }
1499=======
1500 private void SendTheLayerPacket(LayerDataPacket layerpack)
1501 {
1502 OutPacket(layerpack, ThrottleOutPacketType.Land);
1503>>>>>>> avn/ubitvar
1398 } 1504 }
1399 1505
1400 /// <summary> 1506 /// <summary>
@@ -1735,11 +1841,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1735 pc.PingID.OldestUnacked = 0; 1841 pc.PingID.OldestUnacked = 0;
1736 1842
1737 OutPacket(pc, ThrottleOutPacketType.Unknown); 1843 OutPacket(pc, ThrottleOutPacketType.Unknown);
1844 UDPClient.m_lastStartpingTimeMS = Util.EnvironmentTickCount();
1738 } 1845 }
1739 1846
1740 public void SendKillObject(List<uint> localIDs) 1847 public void SendKillObject(List<uint> localIDs)
1741 { 1848 {
1742// m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, localID, regionHandle); 1849 // think we do need this
1850 // foreach (uint id in localIDs)
1851 // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, id, regionHandle);
1852
1853 // remove pending entities
1854 lock (m_entityProps.SyncRoot)
1855 m_entityProps.Remove(localIDs);
1856 lock (m_entityUpdates.SyncRoot)
1857 m_entityUpdates.Remove(localIDs);
1743 1858
1744 KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject); 1859 KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
1745 // TODO: don't create new blocks if recycling an old packet 1860 // TODO: don't create new blocks if recycling an old packet
@@ -1752,28 +1867,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1752 kill.Header.Reliable = true; 1867 kill.Header.Reliable = true;
1753 kill.Header.Zerocoded = true; 1868 kill.Header.Zerocoded = true;
1754 1869
1755 if (localIDs.Count == 1 && m_scene.GetScenePresence(localIDs[0]) != null) 1870 OutPacket(kill, ThrottleOutPacketType.Task);
1756 { 1871 }
1757 OutPacket(kill, ThrottleOutPacketType.Task);
1758 }
1759 else
1760 {
1761 // We MUST lock for both manipulating the kill record and sending the packet, in order to avoid a race
1762 // condition where a kill can be processed before an out-of-date update for the same object.
1763 // ProcessEntityUpdates() also takes the m_killRecord lock.
1764 lock (m_killRecord)
1765 {
1766 foreach (uint localID in localIDs)
1767 m_killRecord.Add(localID);
1768
1769 // The throttle queue used here must match that being used for updates. Otherwise, there is a
1770 // chance that a kill packet put on a separate queue will be sent to the client before an existing
1771 // update packet on another queue. Receiving updates after kills results in unowned and undeletable
1772 // scene objects in a viewer until that viewer is relogged in.
1773 OutPacket(kill, ThrottleOutPacketType.Task);
1774 }
1775 }
1776 }
1777 1872
1778 /// <summary> 1873 /// <summary>
1779 /// Send information about the items contained in a folder to the client. 1874 /// Send information about the items contained in a folder to the client.
@@ -1895,7 +1990,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1895 newBlock.CreationDate = item.CreationDate; 1990 newBlock.CreationDate = item.CreationDate;
1896 newBlock.SalePrice = item.SalePrice; 1991 newBlock.SalePrice = item.SalePrice;
1897 newBlock.SaleType = item.SaleType; 1992 newBlock.SaleType = item.SaleType;
1898 newBlock.Flags = item.Flags; 1993 newBlock.Flags = item.Flags & 0x2000ff;
1899 1994
1900 newBlock.CRC = 1995 newBlock.CRC =
1901 Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType, 1996 Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType,
@@ -2151,7 +2246,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2151 itemBlock.GroupID = item.GroupID; 2246 itemBlock.GroupID = item.GroupID;
2152 itemBlock.GroupOwned = item.GroupOwned; 2247 itemBlock.GroupOwned = item.GroupOwned;
2153 itemBlock.GroupMask = item.GroupPermissions; 2248 itemBlock.GroupMask = item.GroupPermissions;
2154 itemBlock.Flags = item.Flags; 2249 itemBlock.Flags = item.Flags & 0x2000ff;
2155 itemBlock.SalePrice = item.SalePrice; 2250 itemBlock.SalePrice = item.SalePrice;
2156 itemBlock.SaleType = item.SaleType; 2251 itemBlock.SaleType = item.SaleType;
2157 itemBlock.CreationDate = item.CreationDate; 2252 itemBlock.CreationDate = item.CreationDate;
@@ -2218,7 +2313,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2218 bulkUpdate.ItemData[0].GroupID = item.GroupID; 2313 bulkUpdate.ItemData[0].GroupID = item.GroupID;
2219 bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned; 2314 bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
2220 bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions; 2315 bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions;
2221 bulkUpdate.ItemData[0].Flags = item.Flags; 2316 bulkUpdate.ItemData[0].Flags = item.Flags & 0x2000ff;
2222 bulkUpdate.ItemData[0].SalePrice = item.SalePrice; 2317 bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
2223 bulkUpdate.ItemData[0].SaleType = item.SaleType; 2318 bulkUpdate.ItemData[0].SaleType = item.SaleType;
2224 2319
@@ -2234,9 +2329,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2234 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset); 2329 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
2235 } 2330 }
2236 2331
2237 /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
2238 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId) 2332 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
2239 { 2333 {
2334 SendInventoryItemCreateUpdate(Item, UUID.Zero, callbackId);
2335 }
2336
2337 /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
2338 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
2339 {
2240 const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff; 2340 const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
2241 2341
2242 UpdateCreateInventoryItemPacket InventoryReply 2342 UpdateCreateInventoryItemPacket InventoryReply
@@ -2246,6 +2346,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2246 // TODO: don't create new blocks if recycling an old packet 2346 // TODO: don't create new blocks if recycling an old packet
2247 InventoryReply.AgentData.AgentID = AgentId; 2347 InventoryReply.AgentData.AgentID = AgentId;
2248 InventoryReply.AgentData.SimApproved = true; 2348 InventoryReply.AgentData.SimApproved = true;
2349 InventoryReply.AgentData.TransactionID = transactionID;
2249 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1]; 2350 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
2250 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock(); 2351 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
2251 InventoryReply.InventoryData[0].ItemID = Item.ID; 2352 InventoryReply.InventoryData[0].ItemID = Item.ID;
@@ -2266,7 +2367,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2266 InventoryReply.InventoryData[0].GroupID = Item.GroupID; 2367 InventoryReply.InventoryData[0].GroupID = Item.GroupID;
2267 InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned; 2368 InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
2268 InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions; 2369 InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions;
2269 InventoryReply.InventoryData[0].Flags = Item.Flags; 2370 InventoryReply.InventoryData[0].Flags = Item.Flags & 0x2000ff;
2270 InventoryReply.InventoryData[0].SalePrice = Item.SalePrice; 2371 InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
2271 InventoryReply.InventoryData[0].SaleType = Item.SaleType; 2372 InventoryReply.InventoryData[0].SaleType = Item.SaleType;
2272 InventoryReply.InventoryData[0].CreationDate = Item.CreationDate; 2373 InventoryReply.InventoryData[0].CreationDate = Item.CreationDate;
@@ -2315,16 +2416,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2315 replytask.InventoryData.TaskID = taskID; 2416 replytask.InventoryData.TaskID = taskID;
2316 replytask.InventoryData.Serial = serial; 2417 replytask.InventoryData.Serial = serial;
2317 replytask.InventoryData.Filename = fileName; 2418 replytask.InventoryData.Filename = fileName;
2318 OutPacket(replytask, ThrottleOutPacketType.Asset); 2419 OutPacket(replytask, ThrottleOutPacketType.Task);
2319 } 2420 }
2320 2421
2321 public void SendXferPacket(ulong xferID, uint packet, byte[] data) 2422 public void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory)
2322 { 2423 {
2424 ThrottleOutPacketType type = ThrottleOutPacketType.Asset;
2425 if (isTaskInventory)
2426 type = ThrottleOutPacketType.Task;
2427
2323 SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket); 2428 SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
2324 sendXfer.XferID.ID = xferID; 2429 sendXfer.XferID.ID = xferID;
2325 sendXfer.XferID.Packet = packet; 2430 sendXfer.XferID.Packet = packet;
2326 sendXfer.DataPacket.Data = data; 2431 sendXfer.DataPacket.Data = data;
2327 OutPacket(sendXfer, ThrottleOutPacketType.Asset); 2432 OutPacket(sendXfer, type);
2328 } 2433 }
2329 2434
2330 public void SendAbortXferPacket(ulong xferID) 2435 public void SendAbortXferPacket(ulong xferID)
@@ -2385,9 +2490,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2385 { 2490 {
2386 if (agentid == AgentId) 2491 if (agentid == AgentId)
2387 { 2492 {
2493<<<<<<< HEAD
2388 ActiveGroupId = activegroupid; 2494 ActiveGroupId = activegroupid;
2389 ActiveGroupName = groupname; 2495 ActiveGroupName = groupname;
2390 ActiveGroupPowers = grouppowers; 2496 ActiveGroupPowers = grouppowers;
2497=======
2498 m_activeGroupID = activegroupid;
2499 m_activeGroupName = groupname;
2500 m_activeGroupPowers = grouppowers;
2501>>>>>>> avn/ubitvar
2391 } 2502 }
2392 2503
2393 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate); 2504 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
@@ -2514,6 +2625,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2514 OutPacket(sound, ThrottleOutPacketType.Task); 2625 OutPacket(sound, ThrottleOutPacketType.Task);
2515 } 2626 }
2516 2627
2628 public void SendTransferAbort(TransferRequestPacket transferRequest)
2629 {
2630 TransferAbortPacket abort = (TransferAbortPacket)PacketPool.Instance.GetPacket(PacketType.TransferAbort);
2631 abort.TransferInfo.TransferID = transferRequest.TransferInfo.TransferID;
2632 abort.TransferInfo.ChannelType = transferRequest.TransferInfo.ChannelType;
2633 m_log.Debug("[Assets] Aborting transfer; asset request failed");
2634 OutPacket(abort, ThrottleOutPacketType.Task);
2635 }
2636
2517 public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain) 2637 public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
2518 { 2638 {
2519 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger); 2639 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
@@ -2819,6 +2939,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2819 float friction = part.Friction; 2939 float friction = part.Friction;
2820 float bounce = part.Restitution; 2940 float bounce = part.Restitution;
2821 float gravmod = part.GravityModifier; 2941 float gravmod = part.GravityModifier;
2942
2822 eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId); 2943 eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId);
2823 } 2944 }
2824 } 2945 }
@@ -2889,8 +3010,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2889 LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType); 3010 LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
2890 return; 3011 return;
2891 } 3012 }
3013 int WearableOut = 0;
3014 bool isWearable = false;
3015
3016 if (req.AssetInf != null)
3017 isWearable =
3018 ((AssetType) req.AssetInf.Type ==
3019 AssetType.Bodypart || (AssetType) req.AssetInf.Type == AssetType.Clothing);
2892 3020
2893 //m_log.Debug("sending asset " + req.RequestAssetID); 3021
3022 //m_log.Debug("sending asset " + req.RequestAssetID + ", iswearable: " + isWearable);
3023
3024
3025 //if (isWearable)
3026 // m_log.Debug((AssetType)req.AssetInf.Type);
3027
2894 TransferInfoPacket Transfer = new TransferInfoPacket(); 3028 TransferInfoPacket Transfer = new TransferInfoPacket();
2895 Transfer.TransferInfo.ChannelType = 2; 3029 Transfer.TransferInfo.ChannelType = 2;
2896 Transfer.TransferInfo.Status = 0; 3030 Transfer.TransferInfo.Status = 0;
@@ -2912,7 +3046,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2912 Transfer.TransferInfo.Size = req.AssetInf.Data.Length; 3046 Transfer.TransferInfo.Size = req.AssetInf.Data.Length;
2913 Transfer.TransferInfo.TransferID = req.TransferRequestID; 3047 Transfer.TransferInfo.TransferID = req.TransferRequestID;
2914 Transfer.Header.Zerocoded = true; 3048 Transfer.Header.Zerocoded = true;
2915 OutPacket(Transfer, ThrottleOutPacketType.Asset); 3049 OutPacket(Transfer, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
2916 3050
2917 if (req.NumPackets == 1) 3051 if (req.NumPackets == 1)
2918 { 3052 {
@@ -2923,12 +3057,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2923 TransferPacket.TransferData.Data = req.AssetInf.Data; 3057 TransferPacket.TransferData.Data = req.AssetInf.Data;
2924 TransferPacket.TransferData.Status = 1; 3058 TransferPacket.TransferData.Status = 1;
2925 TransferPacket.Header.Zerocoded = true; 3059 TransferPacket.Header.Zerocoded = true;
2926 OutPacket(TransferPacket, ThrottleOutPacketType.Asset); 3060 OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
2927 } 3061 }
2928 else 3062 else
2929 { 3063 {
2930 int processedLength = 0; 3064 int processedLength = 0;
2931 int maxChunkSize = Settings.MAX_PACKET_SIZE - 100; 3065// int maxChunkSize = Settings.MAX_PACKET_SIZE - 100;
3066
3067 int maxChunkSize = (int) MaxTransferBytesPerPacket;
2932 int packetNumber = 0; 3068 int packetNumber = 0;
2933 3069
2934 while (processedLength < req.AssetInf.Data.Length) 3070 while (processedLength < req.AssetInf.Data.Length)
@@ -2954,7 +3090,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2954 TransferPacket.TransferData.Status = 1; 3090 TransferPacket.TransferData.Status = 1;
2955 } 3091 }
2956 TransferPacket.Header.Zerocoded = true; 3092 TransferPacket.Header.Zerocoded = true;
2957 OutPacket(TransferPacket, ThrottleOutPacketType.Asset); 3093 OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
2958 3094
2959 processedLength += chunkSize; 3095 processedLength += chunkSize;
2960 packetNumber++; 3096 packetNumber++;
@@ -2999,7 +3135,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2999 reply.Data.ParcelID = parcelID; 3135 reply.Data.ParcelID = parcelID;
3000 reply.Data.OwnerID = land.OwnerID; 3136 reply.Data.OwnerID = land.OwnerID;
3001 reply.Data.Name = Utils.StringToBytes(land.Name); 3137 reply.Data.Name = Utils.StringToBytes(land.Name);
3002 reply.Data.Desc = Utils.StringToBytes(land.Description); 3138 if (land != null && land.Description != null && land.Description != String.Empty)
3139 reply.Data.Desc = Utils.StringToBytes(land.Description.Substring(0, land.Description.Length > 254 ? 254: land.Description.Length));
3140 else
3141 reply.Data.Desc = new Byte[0];
3003 reply.Data.ActualArea = land.Area; 3142 reply.Data.ActualArea = land.Area;
3004 reply.Data.BillableArea = land.Area; // TODO: what is this? 3143 reply.Data.BillableArea = land.Area; // TODO: what is this?
3005 3144
@@ -3706,24 +3845,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3706 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count]; 3845 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count];
3707 AgentWearablesUpdatePacket.WearableDataBlock awb; 3846 AgentWearablesUpdatePacket.WearableDataBlock awb;
3708 int idx = 0; 3847 int idx = 0;
3709 for (int i = 0; i < wearables.Length; i++) 3848
3710 { 3849 for (int i = 0; i < wearables.Length; i++)
3711 for (int j = 0; j < wearables[i].Count; j++) 3850 {
3712 { 3851 for (int j = 0; j < wearables[i].Count; j++)
3713 awb = new AgentWearablesUpdatePacket.WearableDataBlock(); 3852 {
3714 awb.WearableType = (byte)i; 3853 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
3715 awb.AssetID = wearables[i][j].AssetID; 3854 awb.WearableType = (byte) i;
3716 awb.ItemID = wearables[i][j].ItemID; 3855 awb.AssetID = wearables[i][j].AssetID;
3717 aw.WearableData[idx] = awb; 3856 awb.ItemID = wearables[i][j].ItemID;
3718 idx++; 3857 aw.WearableData[idx] = awb;
3719 3858 idx++;
3720// m_log.DebugFormat( 3859
3721// "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}", 3860 // m_log.DebugFormat(
3722// awb.ItemID, awb.AssetID, i, Name); 3861 // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
3723 } 3862 // awb.ItemID, awb.AssetID, i, Name);
3724 } 3863 }
3864 }
3725 3865
3726 OutPacket(aw, ThrottleOutPacketType.Task); 3866 OutPacket(aw, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
3727 } 3867 }
3728 3868
3729 public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry) 3869 public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry)
@@ -3748,9 +3888,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3748 avp.Sender.IsTrial = false; 3888 avp.Sender.IsTrial = false;
3749 avp.Sender.ID = agentID; 3889 avp.Sender.ID = agentID;
3750 avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0]; 3890 avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0];
3891<<<<<<< HEAD
3751 avp.AppearanceHover = new AvatarAppearancePacket.AppearanceHoverBlock[0]; 3892 avp.AppearanceHover = new AvatarAppearancePacket.AppearanceHoverBlock[0];
3893=======
3894
3895 // this need be use in future
3896 // avp.AppearanceData[0].AppearanceVersion = 0;
3897 // avp.AppearanceData[0].CofVersion = 0;
3898
3899>>>>>>> avn/ubitvar
3752 //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString()); 3900 //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString());
3753 OutPacket(avp, ThrottleOutPacketType.Task); 3901 OutPacket(avp, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
3754 } 3902 }
3755 3903
3756 public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs) 3904 public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
@@ -3778,7 +3926,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3778 ani.AnimationSourceList[i].ObjectID = objectIDs[i]; 3926 ani.AnimationSourceList[i].ObjectID = objectIDs[i];
3779 } 3927 }
3780 ani.Header.Reliable = false; 3928 ani.Header.Reliable = false;
3781 OutPacket(ani, ThrottleOutPacketType.Task); 3929 OutPacket(ani, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
3782 } 3930 }
3783 3931
3784 #endregion 3932 #endregion
@@ -3807,7 +3955,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3807 objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; 3955 objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
3808 objupdate.ObjectData[0] = CreateAvatarUpdateBlock(presence); 3956 objupdate.ObjectData[0] = CreateAvatarUpdateBlock(presence);
3809 3957
3810 OutPacket(objupdate, ThrottleOutPacketType.Task); 3958 OutPacket(objupdate, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
3811 3959
3812 // We need to record the avatar local id since the root prim of an attachment points to this. 3960 // We need to record the avatar local id since the root prim of an attachment points to this.
3813// m_attachmentsSent.Add(avatar.LocalId); 3961// m_attachmentsSent.Add(avatar.LocalId);
@@ -3866,10 +4014,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3866 /// </summary> 4014 /// </summary>
3867 public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags) 4015 public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
3868 { 4016 {
4017<<<<<<< HEAD
3869 if (entity.UUID == m_agentId && !updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) 4018 if (entity.UUID == m_agentId && !updateFlags.HasFlag(PrimUpdateFlags.FullUpdate))
3870 { 4019 {
3871 ImprovedTerseObjectUpdatePacket packet 4020 ImprovedTerseObjectUpdatePacket packet
3872 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate); 4021 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
4022=======
4023 if (entity is SceneObjectPart)
4024 {
4025 SceneObjectPart e = (SceneObjectPart)entity;
4026 SceneObjectGroup g = e.ParentGroup;
4027 if (g.HasPrivateAttachmentPoint && g.OwnerID != AgentId)
4028 return; // Don't send updates for other people's HUDs
4029 }
4030
4031 uint priority = m_prioritizer.GetUpdatePriority(this, entity);
4032>>>>>>> avn/ubitvar
3873 4033
3874 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; 4034 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
3875 packet.RegionData.TimeDilation = Utils.FloatToUInt16(1, 0.0f, 1.0f); 4035 packet.RegionData.TimeDilation = Utils.FloatToUInt16(1, 0.0f, 1.0f);
@@ -3887,6 +4047,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3887 } 4047 }
3888 } 4048 }
3889 4049
4050
3890 /// <summary> 4051 /// <summary>
3891 /// Requeue an EntityUpdate when it was not acknowledged by the client. 4052 /// Requeue an EntityUpdate when it was not acknowledged by the client.
3892 /// We will update the priority and put it in the correct queue, merging update flags 4053 /// We will update the priority and put it in the correct queue, merging update flags
@@ -3894,8 +4055,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3894 /// The original update time is used for the merged update. 4055 /// The original update time is used for the merged update.
3895 /// </summary> 4056 /// </summary>
3896 private void ResendPrimUpdate(EntityUpdate update) 4057 private void ResendPrimUpdate(EntityUpdate update)
3897 { 4058 {
3898 // If the update exists in priority queue, it will be updated. 4059 // If the update exists in priority queue, it will be updated.
3899 // If it does not exist then it will be added with the current (rather than its original) priority 4060 // If it does not exist then it will be added with the current (rather than its original) priority
3900 uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity); 4061 uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
3901 4062
@@ -3919,7 +4080,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3919 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber); 4080 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
3920 4081
3921 // Count this as a resent packet since we are going to requeue all of the updates contained in it 4082 // Count this as a resent packet since we are going to requeue all of the updates contained in it
3922 Interlocked.Increment(ref m_udpClient.PacketsResent); 4083 Interlocked.Increment(ref m_udpClient.PacketsResent);
3923 4084
3924 // We're not going to worry about interlock yet since its not currently critical that this total count 4085 // We're not going to worry about interlock yet since its not currently critical that this total count
3925 // is 100% correct 4086 // is 100% correct
@@ -3928,18 +4089,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3928 foreach (EntityUpdate update in updates) 4089 foreach (EntityUpdate update in updates)
3929 ResendPrimUpdate(update); 4090 ResendPrimUpdate(update);
3930 } 4091 }
3931 4092
3932// OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>();
3933// OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>> compressedUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>>();
3934// OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3935// OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3936//
3937// OpenSim.Framework.Lazy<List<EntityUpdate>> objectUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3938// OpenSim.Framework.Lazy<List<EntityUpdate>> compressedUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3939// OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3940// OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3941
3942
3943 private void ProcessEntityUpdates(int maxUpdates) 4093 private void ProcessEntityUpdates(int maxUpdates)
3944 { 4094 {
3945 OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>(); 4095 OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>();
@@ -3952,15 +4102,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3952 OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); 4102 OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3953 OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); 4103 OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3954 4104
3955// objectUpdateBlocks.Value.Clear();
3956// compressedUpdateBlocks.Value.Clear();
3957// terseUpdateBlocks.Value.Clear();
3958// terseAgentUpdateBlocks.Value.Clear();
3959// objectUpdates.Value.Clear();
3960// compressedUpdates.Value.Clear();
3961// terseUpdates.Value.Clear();
3962// terseAgentUpdates.Value.Clear();
3963
3964 // Check to see if this is a flush 4105 // Check to see if this is a flush
3965 if (maxUpdates <= 0) 4106 if (maxUpdates <= 0)
3966 { 4107 {
@@ -3971,54 +4112,72 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3971 4112
3972 // We must lock for both manipulating the kill record and sending the packet, in order to avoid a race 4113 // We must lock for both manipulating the kill record and sending the packet, in order to avoid a race
3973 // condition where a kill can be processed before an out-of-date update for the same object. 4114 // condition where a kill can be processed before an out-of-date update for the same object.
3974 lock (m_killRecord) 4115 float avgTimeDilation = 1.0f;
4116 IEntityUpdate iupdate;
4117 Int32 timeinqueue; // this is just debugging code & can be dropped later
4118
4119 while (updatesThisCall < maxUpdates)
3975 { 4120 {
3976 float avgTimeDilation = 1.0f; 4121 lock (m_entityUpdates.SyncRoot)
3977 IEntityUpdate iupdate; 4122 if (!m_entityUpdates.TryDequeue(out iupdate, out timeinqueue))
3978 Int32 timeinqueue; // this is just debugging code & can be dropped later 4123 break;
4124
4125 EntityUpdate update = (EntityUpdate)iupdate;
4126
4127 avgTimeDilation += update.TimeDilation;
4128 avgTimeDilation *= 0.5f;
3979 4129
3980 while (updatesThisCall < maxUpdates) 4130 if (update.Entity is SceneObjectPart)
3981 { 4131 {
3982 lock (m_entityUpdates.SyncRoot) 4132 SceneObjectPart part = (SceneObjectPart)update.Entity;
3983 if (!m_entityUpdates.TryDequeue(out iupdate, out timeinqueue))
3984 break;
3985 4133
3986 EntityUpdate update = (EntityUpdate)iupdate; 4134 if (part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
3987 4135 continue;
3988 avgTimeDilation += update.TimeDilation;
3989 avgTimeDilation *= 0.5f;
3990 4136
3991 if (update.Entity is SceneObjectPart) 4137 if (part.ParentGroup.IsAttachment)
3992 { 4138 { // Someone else's HUD, why are we getting these?
3993 SceneObjectPart part = (SceneObjectPart)update.Entity; 4139 if (part.ParentGroup.OwnerID != AgentId && part.ParentGroup.HasPrivateAttachmentPoint)
3994
3995 // Please do not remove this unless you can demonstrate on the OpenSim mailing list that a client
3996 // will never receive an update after a prim kill. Even then, keeping the kill record may be a good
3997 // safety measure.
3998 //
3999 // If a Linden Lab 1.23.5 client (and possibly later and earlier) receives an object update
4000 // after a kill, it will keep displaying the deleted object until relog. OpenSim currently performs
4001 // updates and kills on different threads with different scheduling strategies, hence this protection.
4002 //
4003 // This doesn't appear to apply to child prims - a client will happily ignore these updates
4004 // after the root prim has been deleted.
4005 if (m_killRecord.Contains(part.LocalId))
4006 {
4007 // m_log.WarnFormat(
4008 // "[CLIENT]: Preventing update for prim with local id {0} after client for user {1} told it was deleted",
4009 // part.LocalId, Name);
4010 continue; 4140 continue;
4011 } 4141 ScenePresence sp;
4012 4142 // Owner is not in the sim, don't update it to
4013 if (part.ParentGroup.IsAttachment && m_disableFacelights) 4143 // anyone
4144 if (!m_scene.TryGetScenePresence(part.OwnerID, out sp))
4145 continue;
4146
4147 List<SceneObjectGroup> atts = sp.GetAttachments();
4148 bool found = false;
4149 foreach (SceneObjectGroup att in atts)
4014 { 4150 {
4015 if (part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand && 4151 if (att == part.ParentGroup)
4016 part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
4017 { 4152 {
4018 part.Shape.LightEntry = false; 4153 found = true;
4154 break;
4019 } 4155 }
4020 } 4156 }
4021 4157
4158 // It's an attachment of a valid avatar, but
4159 // doesn't seem to be attached, skip
4160 if (!found)
4161 continue;
4162
4163 // On vehicle crossing, the attachments are received
4164 // while the avatar is still a child. Don't send
4165 // updates here because the LocalId has not yet
4166 // been updated and the viewer will derender the
4167 // attachments until the avatar becomes root.
4168 if (sp.IsChildAgent)
4169 continue;
4170
4171 }
4172
4173 if (part.ParentGroup.IsAttachment && m_disableFacelights)
4174 {
4175 if (part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand &&
4176 part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
4177 {
4178 part.Shape.LightEntry = false;
4179 }
4180
4022 if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh)) 4181 if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh))
4023 { 4182 {
4024 // Ensure that mesh has at least 8 valid faces 4183 // Ensure that mesh has at least 8 valid faces
@@ -4027,233 +4186,216 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4027 part.Shape.ProfileHollow = 27500; 4186 part.Shape.ProfileHollow = 27500;
4028 } 4187 }
4029 } 4188 }
4030 4189
4031 #region UpdateFlags to packet type conversion 4190 if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh))
4032
4033 PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags;
4034
4035 bool canUseCompressed = true;
4036 bool canUseImproved = true;
4037
4038 // Compressed object updates only make sense for LL primitives
4039 if (!(update.Entity is SceneObjectPart))
4040 { 4191 {
4041 canUseCompressed = false; 4192 // Ensure that mesh has at least 8 valid faces
4193 part.Shape.ProfileBegin = 12500;
4194 part.Shape.ProfileEnd = 0;
4195 part.Shape.ProfileHollow = 27500;
4042 } 4196 }
4043 4197 }
4044 if (updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) 4198 else if (update.Entity is ScenePresence)
4199 {
4200 ScenePresence presence = (ScenePresence)update.Entity;
4201 if (presence.IsDeleted)
4202 continue;
4203 // If ParentUUID is not UUID.Zero and ParentID is 0, this
4204 // avatar is in the process of crossing regions while
4205 // sat on an object. In this state, we don't want any
4206 // updates because they will visually orbit the avatar.
4207 // Update will be forced once crossing is completed anyway.
4208 if (presence.ParentUUID != UUID.Zero && presence.ParentID == 0)
4209 continue;
4210 }
4211
4212 ++updatesThisCall;
4213
4214 #region UpdateFlags to packet type conversion
4215
4216 PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags;
4217
4218 bool canUseCompressed = true;
4219 bool canUseImproved = true;
4220
4221 // Compressed object updates only make sense for LL primitives
4222 if (!(update.Entity is SceneObjectPart))
4223 {
4224 canUseCompressed = false;
4225 }
4226
4227 if (updateFlags.HasFlag(PrimUpdateFlags.FullUpdate))
4228 {
4229 canUseCompressed = false;
4230 canUseImproved = false;
4231 }
4232 else
4233 {
4234 if (updateFlags.HasFlag(PrimUpdateFlags.Velocity) ||
4235 updateFlags.HasFlag(PrimUpdateFlags.Acceleration) ||
4236 updateFlags.HasFlag(PrimUpdateFlags.CollisionPlane) ||
4237 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4045 { 4238 {
4046 canUseCompressed = false; 4239 canUseCompressed = false;
4047 canUseImproved = false;
4048 } 4240 }
4049 else 4241
4242 if (updateFlags.HasFlag(PrimUpdateFlags.PrimFlags) ||
4243 updateFlags.HasFlag(PrimUpdateFlags.ParentID) ||
4244 updateFlags.HasFlag(PrimUpdateFlags.Scale) ||
4245 updateFlags.HasFlag(PrimUpdateFlags.PrimData) ||
4246 updateFlags.HasFlag(PrimUpdateFlags.Text) ||
4247 updateFlags.HasFlag(PrimUpdateFlags.NameValue) ||
4248 updateFlags.HasFlag(PrimUpdateFlags.ExtraData) ||
4249 updateFlags.HasFlag(PrimUpdateFlags.TextureAnim) ||
4250 updateFlags.HasFlag(PrimUpdateFlags.Sound) ||
4251 updateFlags.HasFlag(PrimUpdateFlags.Particles) ||
4252 updateFlags.HasFlag(PrimUpdateFlags.Material) ||
4253 updateFlags.HasFlag(PrimUpdateFlags.ClickAction) ||
4254 updateFlags.HasFlag(PrimUpdateFlags.MediaURL) ||
4255 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4050 { 4256 {
4051 if (updateFlags.HasFlag(PrimUpdateFlags.Velocity) || 4257 canUseImproved = false;
4052 updateFlags.HasFlag(PrimUpdateFlags.Acceleration) ||
4053 updateFlags.HasFlag(PrimUpdateFlags.CollisionPlane) ||
4054 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4055 {
4056 canUseCompressed = false;
4057 }
4058
4059 if (updateFlags.HasFlag(PrimUpdateFlags.PrimFlags) ||
4060 updateFlags.HasFlag(PrimUpdateFlags.ParentID) ||
4061 updateFlags.HasFlag(PrimUpdateFlags.Scale) ||
4062 updateFlags.HasFlag(PrimUpdateFlags.PrimData) ||
4063 updateFlags.HasFlag(PrimUpdateFlags.Text) ||
4064 updateFlags.HasFlag(PrimUpdateFlags.NameValue) ||
4065 updateFlags.HasFlag(PrimUpdateFlags.ExtraData) ||
4066 updateFlags.HasFlag(PrimUpdateFlags.TextureAnim) ||
4067 updateFlags.HasFlag(PrimUpdateFlags.Sound) ||
4068 updateFlags.HasFlag(PrimUpdateFlags.Particles) ||
4069 updateFlags.HasFlag(PrimUpdateFlags.Material) ||
4070 updateFlags.HasFlag(PrimUpdateFlags.ClickAction) ||
4071 updateFlags.HasFlag(PrimUpdateFlags.MediaURL) ||
4072 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4073 {
4074 canUseImproved = false;
4075 }
4076 } 4258 }
4259 }
4077 4260
4078 #endregion UpdateFlags to packet type conversion 4261 #endregion UpdateFlags to packet type conversion
4079
4080 #region Block Construction
4081
4082 // TODO: Remove this once we can build compressed updates
4083 canUseCompressed = false;
4084
4085 if (!canUseImproved && !canUseCompressed)
4086 {
4087 ObjectUpdatePacket.ObjectDataBlock updateBlock;
4088 4262
4089 if (update.Entity is ScenePresence) 4263 #region Block Construction
4090 {
4091 updateBlock = CreateAvatarUpdateBlock((ScenePresence)update.Entity);
4092 }
4093 else
4094 {
4095 SceneObjectPart part = (SceneObjectPart)update.Entity;
4096 updateBlock = CreatePrimUpdateBlock(part, AgentId);
4097
4098 // If the part has become a private hud since the update was scheduled then we do not
4099 // want to send it to other avatars.
4100 if (part.ParentGroup.IsAttachment
4101 && part.ParentGroup.HasPrivateAttachmentPoint
4102 && part.ParentGroup.AttachedAvatar != AgentId)
4103 continue;
4104
4105 // If the part has since been deleted, then drop the update. In the case of attachments,
4106 // this is to avoid spurious updates to other viewers since post-processing of attachments
4107 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4108 // of the test above).
4109 //
4110 // Actual deletions (kills) happen in another method.
4111 if (part.ParentGroup.IsDeleted)
4112 continue;
4113 }
4114 4264
4115 objectUpdateBlocks.Value.Add(updateBlock); 4265 // TODO: Remove this once we can build compressed updates
4116 objectUpdates.Value.Add(update); 4266 canUseCompressed = false;
4117 }
4118 else if (!canUseImproved)
4119 {
4120 SceneObjectPart part = (SceneObjectPart)update.Entity;
4121 ObjectUpdateCompressedPacket.ObjectDataBlock compressedBlock
4122 = CreateCompressedUpdateBlock(part, updateFlags);
4123
4124 // If the part has since been deleted, then drop the update. In the case of attachments,
4125 // this is to avoid spurious updates to other viewers since post-processing of attachments
4126 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4127 // of the test above).
4128 //
4129 // Actual deletions (kills) happen in another method.
4130 if (part.ParentGroup.IsDeleted)
4131 continue;
4132 4267
4133 compressedUpdateBlocks.Value.Add(compressedBlock); 4268 if (!canUseImproved && !canUseCompressed)
4134 compressedUpdates.Value.Add(update); 4269 {
4270 if (update.Entity is ScenePresence)
4271 {
4272 objectUpdateBlocks.Value.Add(CreateAvatarUpdateBlock((ScenePresence)update.Entity));
4135 } 4273 }
4136 else 4274 else
4137 { 4275 {
4138 if (update.Entity is ScenePresence && ((ScenePresence)update.Entity).UUID == AgentId) 4276 objectUpdateBlocks.Value.Add(CreatePrimUpdateBlock((SceneObjectPart)update.Entity, this.m_agentId));
4139 { 4277 }
4140 // Self updates go into a special list 4278 }
4141 terseAgentUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures))); 4279 else if (!canUseImproved)
4142 terseAgentUpdates.Value.Add(update); 4280 {
4143 } 4281 compressedUpdateBlocks.Value.Add(CreateCompressedUpdateBlock((SceneObjectPart)update.Entity, updateFlags));
4144 else 4282 }
4145 { 4283 else
4146 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseUpdateBlock 4284 {
4147 = CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures)); 4285 if (update.Entity is ScenePresence)
4286 // ALL presence updates go into a special list
4287 terseAgentUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures)));
4288 else
4289 // Everything else goes here
4290 terseUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures)));
4291 }
4148 4292
4149 // Everything else goes here 4293 #endregion Block Construction
4150 if (update.Entity is SceneObjectPart) 4294 }
4151 {
4152 SceneObjectPart part = (SceneObjectPart)update.Entity;
4153
4154 // If the part has become a private hud since the update was scheduled then we do not
4155 // want to send it to other avatars.
4156 if (part.ParentGroup.IsAttachment
4157 && part.ParentGroup.HasPrivateAttachmentPoint
4158 && part.ParentGroup.AttachedAvatar != AgentId)
4159 continue;
4160
4161 // If the part has since been deleted, then drop the update. In the case of attachments,
4162 // this is to avoid spurious updates to other viewers since post-processing of attachments
4163 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4164 // of the test above).
4165 //
4166 // Actual deletions (kills) happen in another method.
4167 if (part.ParentGroup.IsDeleted)
4168 continue;
4169 }
4170 4295
4171 terseUpdateBlocks.Value.Add(terseUpdateBlock); 4296 #region Packet Sending
4172 terseUpdates.Value.Add(update); 4297
4173 } 4298// const float TIME_DILATION = 1.0f;
4174 } 4299 ushort timeDilation = Utils.FloatToUInt16(avgTimeDilation, 0.0f, 1.0f);
4300
4301 if (terseAgentUpdateBlocks.IsValueCreated)
4302 {
4303 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseAgentUpdateBlocks.Value;
4304
4305 ImprovedTerseObjectUpdatePacket packet
4306 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
4307 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4308 packet.RegionData.TimeDilation = timeDilation;
4309 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4175 4310
4176 ++updatesThisCall; 4311 for (int i = 0; i < blocks.Count; i++)
4312 packet.ObjectData[i] = blocks[i];
4313
4314 OutPacket(packet, ThrottleOutPacketType.Unknown, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); });
4315 }
4316
4317 if (objectUpdateBlocks.IsValueCreated)
4318 {
4319 List<ObjectUpdatePacket.ObjectDataBlock> blocks = objectUpdateBlocks.Value;
4177 4320
4178 #endregion Block Construction 4321 ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
4179 } 4322 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4323 packet.RegionData.TimeDilation = timeDilation;
4324 packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4180 4325
4181 #region Packet Sending 4326 for (int i = 0; i < blocks.Count; i++)
4182 ushort timeDilation = Utils.FloatToUInt16(avgTimeDilation, 0.0f, 1.0f); 4327 packet.ObjectData[i] = blocks[i];
4328
4329 OutPacket(packet, ThrottleOutPacketType.Task, true);
4330 }
4331
4332 if (compressedUpdateBlocks.IsValueCreated)
4333 {
4334 List<ObjectUpdateCompressedPacket.ObjectDataBlock> blocks = compressedUpdateBlocks.Value;
4335
4336 ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed);
4337 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4338 packet.RegionData.TimeDilation = timeDilation;
4339 packet.ObjectData = new ObjectUpdateCompressedPacket.ObjectDataBlock[blocks.Count];
4183 4340
4184 if (terseAgentUpdateBlocks.IsValueCreated) 4341 for (int i = 0; i < blocks.Count; i++)
4185 { 4342 packet.ObjectData[i] = blocks[i];
4186 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseAgentUpdateBlocks.Value; 4343
4344 OutPacket(packet, ThrottleOutPacketType.Task, true);
4345 }
4346
4347 if (terseUpdateBlocks.IsValueCreated)
4348 {
4349 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseUpdateBlocks.Value;
4350
4351 ImprovedTerseObjectUpdatePacket packet
4352 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(
4353 PacketType.ImprovedTerseObjectUpdate);
4354 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4355 packet.RegionData.TimeDilation = timeDilation;
4356 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4357
4358 for (int i = 0; i < blocks.Count; i++)
4359 packet.ObjectData[i] = blocks[i];
4187 4360
4188 ImprovedTerseObjectUpdatePacket packet 4361 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); });
4189 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate); 4362 }
4190 4363
4191 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; 4364 #endregion Packet Sending
4192 packet.RegionData.TimeDilation = timeDilation; 4365 }
4193 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4194 4366
4195 for (int i = 0; i < blocks.Count; i++) 4367 // hack.. dont use
4196 packet.ObjectData[i] = blocks[i]; 4368 public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
4197 // If any of the packets created from this call go unacknowledged, all of the updates will be resent 4369 {
4198 OutPacket(packet, ThrottleOutPacketType.Unknown, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseAgentUpdates.Value, oPacket); }); 4370 if (ent is SceneObjectPart)
4199 } 4371 {
4372 SceneObjectPart part = (SceneObjectPart)ent;
4373 ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
4374 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4375 packet.RegionData.TimeDilation = 1;
4376 packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
4200 4377
4201 if (objectUpdateBlocks.IsValueCreated) 4378 ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, this.m_agentId);
4379 if (parentID.HasValue)
4202 { 4380 {
4203 List<ObjectUpdatePacket.ObjectDataBlock> blocks = objectUpdateBlocks.Value; 4381 blk.ParentID = parentID.Value;
4204
4205 ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
4206 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4207 packet.RegionData.TimeDilation = timeDilation;
4208 packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4209
4210 for (int i = 0; i < blocks.Count; i++)
4211 packet.ObjectData[i] = blocks[i];
4212 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4213 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(objectUpdates.Value, oPacket); });
4214 }
4215
4216 if (compressedUpdateBlocks.IsValueCreated)
4217 {
4218 List<ObjectUpdateCompressedPacket.ObjectDataBlock> blocks = compressedUpdateBlocks.Value;
4219
4220 ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed);
4221 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4222 packet.RegionData.TimeDilation = timeDilation;
4223 packet.ObjectData = new ObjectUpdateCompressedPacket.ObjectDataBlock[blocks.Count];
4224
4225 for (int i = 0; i < blocks.Count; i++)
4226 packet.ObjectData[i] = blocks[i];
4227 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4228 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(compressedUpdates.Value, oPacket); });
4229 } 4382 }
4230 4383
4231 if (terseUpdateBlocks.IsValueCreated) 4384 packet.ObjectData[0] = blk;
4232 {
4233 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseUpdateBlocks.Value;
4234
4235 ImprovedTerseObjectUpdatePacket packet
4236 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(
4237 PacketType.ImprovedTerseObjectUpdate);
4238 4385
4239 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; 4386 OutPacket(packet, ThrottleOutPacketType.Task, true);
4240 packet.RegionData.TimeDilation = timeDilation;
4241 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4242
4243 for (int i = 0; i < blocks.Count; i++)
4244 packet.ObjectData[i] = blocks[i];
4245 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4246 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); });
4247 }
4248 } 4387 }
4388<<<<<<< HEAD
4249 4389
4250// m_log.DebugFormat( 4390// m_log.DebugFormat(
4251// "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}", 4391// "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}",
4252// updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name); 4392// updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name);
4253// 4393//
4254 #endregion Packet Sending 4394 #endregion Packet Sending
4395=======
4396>>>>>>> avn/ubitvar
4255 } 4397 }
4256 4398
4257 public void ReprioritizeUpdates() 4399 public void ReprioritizeUpdates()
4258 { 4400 {
4259 lock (m_entityUpdates.SyncRoot) 4401 lock (m_entityUpdates.SyncRoot)
@@ -4572,11 +4714,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4572 4714
4573 // Pass in the delegate so that if this packet needs to be resent, we send the current properties 4715 // Pass in the delegate so that if this packet needs to be resent, we send the current properties
4574 // of the object rather than the properties when the packet was created 4716 // of the object rather than the properties when the packet was created
4575 OutPacket(packet, ThrottleOutPacketType.Task, true, 4717 // HACK : Remove intelligent resending until it's fixed in core
4576 delegate(OutgoingPacket oPacket) 4718 //OutPacket(packet, ThrottleOutPacketType.Task, true,
4577 { 4719 // delegate(OutgoingPacket oPacket)
4578 ResendPropertyUpdates(updates, oPacket); 4720 // {
4579 }); 4721 // ResendPropertyUpdates(updates, oPacket);
4722 // });
4723 OutPacket(packet, ThrottleOutPacketType.Task, true);
4580 4724
4581 // pbcnt += blocks.Count; 4725 // pbcnt += blocks.Count;
4582 // ppcnt++; 4726 // ppcnt++;
@@ -4602,11 +4746,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4602 // of the object rather than the properties when the packet was created 4746 // of the object rather than the properties when the packet was created
4603 List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>(); 4747 List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>();
4604 updates.Add(familyUpdates.Value[i]); 4748 updates.Add(familyUpdates.Value[i]);
4605 OutPacket(packet, ThrottleOutPacketType.Task, true, 4749 // HACK : Remove intelligent resending until it's fixed in core
4606 delegate(OutgoingPacket oPacket) 4750 //OutPacket(packet, ThrottleOutPacketType.Task, true,
4607 { 4751 // delegate(OutgoingPacket oPacket)
4608 ResendPropertyUpdates(updates, oPacket); 4752 // {
4609 }); 4753 // ResendPropertyUpdates(updates, oPacket);
4754 // });
4755 OutPacket(packet, ThrottleOutPacketType.Task, true);
4610 4756
4611 // fpcnt++; 4757 // fpcnt++;
4612 // fbcnt++; 4758 // fbcnt++;
@@ -4939,7 +5085,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4939 packet.ParcelData.Data = data; 5085 packet.ParcelData.Data = data;
4940 packet.ParcelData.SequenceID = sequence_id; 5086 packet.ParcelData.SequenceID = sequence_id;
4941 packet.Header.Zerocoded = true; 5087 packet.Header.Zerocoded = true;
4942 OutPacket(packet, ThrottleOutPacketType.Task); 5088// OutPacket(packet, ThrottleOutPacketType.Task);
5089 OutPacket(packet, ThrottleOutPacketType.Land);
4943 } 5090 }
4944 5091
4945 public void SendLandProperties( 5092 public void SendLandProperties(
@@ -5004,7 +5151,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5004 5151
5005 if (landData.SimwideArea > 0) 5152 if (landData.SimwideArea > 0)
5006 { 5153 {
5007 int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) * (float)m_scene.RegionInfo.ObjectCapacity * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); 5154 int simulatorCapacity = (int)((long)landData.SimwideArea * (long)m_scene.RegionInfo.ObjectCapacity * (long)m_scene.RegionInfo.RegionSettings.ObjectBonus / 65536L);
5155 // Never report more than sim total capacity
5156 if (simulatorCapacity > m_scene.RegionInfo.ObjectCapacity)
5157 simulatorCapacity = m_scene.RegionInfo.ObjectCapacity;
5008 updateMessage.SimWideMaxPrims = simulatorCapacity; 5158 updateMessage.SimWideMaxPrims = simulatorCapacity;
5009 } 5159 }
5010 else 5160 else
@@ -5039,7 +5189,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5039 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>(); 5189 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
5040 if (eq != null) 5190 if (eq != null)
5041 { 5191 {
5042 eq.ParcelProperties(updateMessage, this.AgentId); 5192
5193 OSD message_body = updateMessage.Serialize();
5194 // Add new fields here until OMV has them
5195 OSDMap bodyMap = (OSDMap)message_body;
5196 OSDArray parcelDataArray = (OSDArray)bodyMap["ParcelData"];
5197 OSDMap parcelData = (OSDMap)parcelDataArray[0];
5198 parcelData["SeeAVs"] = OSD.FromBoolean(landData.SeeAVs);
5199 parcelData["AnyAVSounds"] = OSD.FromBoolean(landData.AnyAVSounds);
5200 parcelData["GroupAVSounds"] = OSD.FromBoolean(landData.GroupAVSounds);
5201 OSDMap message = new OSDMap();
5202 message.Add("message", OSD.FromString("ParcelProperties"));
5203 message.Add("body", message_body);
5204
5205 eq.Enqueue (message, this.AgentId);
5206
5207// eq.ParcelProperties(updateMessage, this.AgentId);
5043 } 5208 }
5044 else 5209 else
5045 { 5210 {
@@ -5133,14 +5298,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5133 5298
5134 if (notifyCount > 0) 5299 if (notifyCount > 0)
5135 { 5300 {
5136 if (notifyCount > 32) 5301// if (notifyCount > 32)
5137 { 5302// {
5138 m_log.InfoFormat( 5303// m_log.InfoFormat(
5139 "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}" 5304// "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
5140 + " - a developer might want to investigate whether this is a hard limit", 32); 5305// + " - a developer might want to investigate whether this is a hard limit", 32);
5141 5306//
5142 notifyCount = 32; 5307// notifyCount = 32;
5143 } 5308// }
5144 5309
5145 ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock 5310 ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
5146 = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount]; 5311 = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
@@ -5195,41 +5360,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5195 { 5360 {
5196 ScenePresence presence = (ScenePresence)entity; 5361 ScenePresence presence = (ScenePresence)entity;
5197 5362
5363<<<<<<< HEAD
5198// m_log.DebugFormat( 5364// m_log.DebugFormat(
5199// "[LLCLIENTVIEW]: Sending terse update to {0} with pos {1}, vel {2} in {3}", 5365// "[LLCLIENTVIEW]: Sending terse update to {0} with pos {1}, vel {2} in {3}",
5200// Name, presence.OffsetPosition, presence.Velocity, m_scene.Name); 5366// Name, presence.OffsetPosition, presence.Velocity, m_scene.Name);
5201 5367=======
5202 attachPoint = presence.State;
5203 collisionPlane = presence.CollisionPlane;
5204 position = presence.OffsetPosition; 5368 position = presence.OffsetPosition;
5205 velocity = presence.Velocity; 5369 rotation = presence.Rotation;
5206 acceleration = Vector3.Zero;
5207
5208 // Interestingly, sending this to non-zero will cause the client's avatar to start moving & accelerating
5209 // in that direction, even though we don't model this on the server. Implementing this in the future
5210 // may improve movement smoothness.
5211// acceleration = new Vector3(1, 0, 0);
5212
5213 angularVelocity = presence.AngularVelocity; 5370 angularVelocity = presence.AngularVelocity;
5214
5215 // Whilst not in mouselook, an avatar will transmit only the Z rotation as this is the only axis
5216 // it rotates around.
5217 // In mouselook, X and Y co-ordinate will also be sent but when used in Rotation, these cause unwanted
5218 // excessive up and down movements of the camera when looking up and down.
5219 // See http://opensimulator.org/mantis/view.php?id=3274
5220 // This does not affect head movement, since this is controlled entirely by camera movement rather than
5221 // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change
5222 // the rotation in this case.
5223 rotation = presence.Rotation; 5371 rotation = presence.Rotation;
5224 5372
5225 if (!presence.IsSatOnObject) 5373 attachPoint = 0;
5226 { 5374// m_log.DebugFormat(
5227 rotation.X = 0; 5375// "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
5228 rotation.Y = 0; 5376>>>>>>> avn/ubitvar
5229 } 5377
5378 // attachPoint = presence.State; // Core: commented
5379 collisionPlane = presence.CollisionPlane;
5380 velocity = presence.Velocity;
5381 acceleration = Vector3.Zero;
5230 5382
5231 if (sendTexture) 5383 if (sendTexture)
5384 {
5232 textureEntry = presence.Appearance.Texture.GetBytes(); 5385 textureEntry = presence.Appearance.Texture.GetBytes();
5386 }
5233 else 5387 else
5234 textureEntry = null; 5388 textureEntry = null;
5235 } 5389 }
@@ -5333,10 +5487,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5333 5487
5334 protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data) 5488 protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data)
5335 { 5489 {
5490 Vector3 offsetPosition = data.OffsetPosition;
5491 Quaternion rotation = data.Rotation;
5492 uint parentID = data.ParentID;
5493
5336// m_log.DebugFormat( 5494// m_log.DebugFormat(
5337// "[LLCLIENTVIEW]: Sending full update to {0} with pos {1}, vel {2} in {3}", Name, data.OffsetPosition, data.Velocity, m_scene.Name); 5495// "[LLCLIENTVIEW]: Sending full update to {0} with pos {1}, vel {2} in {3}", Name, data.OffsetPosition, data.Velocity, m_scene.Name);
5338 5496
5339 byte[] objectData = new byte[76]; 5497 byte[] objectData = new byte[76];
5498<<<<<<< HEAD
5340 5499
5341 data.CollisionPlane.ToBytes(objectData, 0); 5500 data.CollisionPlane.ToBytes(objectData, 0);
5342 data.OffsetPosition.ToBytes(objectData, 16); 5501 data.OffsetPosition.ToBytes(objectData, 16);
@@ -5352,15 +5511,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5352 // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change 5511 // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change
5353 // the rotation in this case. 5512 // the rotation in this case.
5354 Quaternion rot = data.Rotation; 5513 Quaternion rot = data.Rotation;
5514=======
5515>>>>>>> avn/ubitvar
5355 5516
5356 if (!data.IsSatOnObject) 5517 Vector3 velocity = new Vector3(0, 0, 0);
5357 { 5518 Vector3 acceleration = new Vector3(0, 0, 0);
5358 rot.X = 0; 5519 rotation.Normalize();
5359 rot.Y = 0;
5360 }
5361 5520
5362 rot.ToBytes(objectData, 52); 5521 data.CollisionPlane.ToBytes(objectData, 0);
5363 //data.AngularVelocity.ToBytes(objectData, 64); 5522 offsetPosition.ToBytes(objectData, 16);
5523 velocity.ToBytes(objectData, 28);
5524 acceleration.ToBytes(objectData, 40);
5525 rotation.ToBytes(objectData, 52);
5526 data.AngularVelocity.ToBytes(objectData, 64);
5364 5527
5365 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); 5528 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
5366 5529
@@ -5386,7 +5549,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5386 update.PCode = (byte)PCode.Avatar; 5549 update.PCode = (byte)PCode.Avatar;
5387 update.ProfileCurve = 1; 5550 update.ProfileCurve = 1;
5388 update.PSBlock = Utils.EmptyBytes; 5551 update.PSBlock = Utils.EmptyBytes;
5389 update.Scale = new Vector3(0.45f, 0.6f, 1.9f); 5552 update.Scale = data.Appearance.AvatarSize;
5553// update.Scale.Z -= 0.2f;
5554
5390 update.Text = Utils.EmptyBytes; 5555 update.Text = Utils.EmptyBytes;
5391 update.TextColor = new byte[4]; 5556 update.TextColor = new byte[4];
5392 5557
@@ -5397,10 +5562,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5397 update.TextureEntry = Utils.EmptyBytes; 5562 update.TextureEntry = Utils.EmptyBytes;
5398// update.TextureEntry = (data.Appearance.Texture != null) ? data.Appearance.Texture.GetBytes() : Utils.EmptyBytes; 5563// update.TextureEntry = (data.Appearance.Texture != null) ? data.Appearance.Texture.GetBytes() : Utils.EmptyBytes;
5399 5564
5565/* all this flags seem related to prims and not avatars. This allow for wrong viewer side move of a avatar in prim edition mode (anv mantis 854)
5400 update.UpdateFlags = (uint)( 5566 update.UpdateFlags = (uint)(
5401 PrimFlags.Physics | PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner | 5567 PrimFlags.Physics | PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner |
5402 PrimFlags.ObjectYouOwner | PrimFlags.ObjectMove | PrimFlags.InventoryEmpty | PrimFlags.ObjectTransfer | 5568 PrimFlags.ObjectYouOwner | PrimFlags.ObjectMove | PrimFlags.InventoryEmpty | PrimFlags.ObjectTransfer |
5403 PrimFlags.ObjectOwnerModify); 5569 PrimFlags.ObjectOwnerModify);
5570*/
5571 update.UpdateFlags = 0;
5404 5572
5405 return update; 5573 return update;
5406 } 5574 }
@@ -5411,15 +5579,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5411 data.RelativePosition.ToBytes(objectData, 0); 5579 data.RelativePosition.ToBytes(objectData, 0);
5412 data.Velocity.ToBytes(objectData, 12); 5580 data.Velocity.ToBytes(objectData, 12);
5413 data.Acceleration.ToBytes(objectData, 24); 5581 data.Acceleration.ToBytes(objectData, 24);
5414 try 5582
5415 { 5583 Quaternion rotation = data.RotationOffset;
5416 data.RotationOffset.ToBytes(objectData, 36); 5584 rotation.Normalize();
5417 } 5585 rotation.ToBytes(objectData, 36);
5418 catch (Exception e)
5419 {
5420 m_log.Warn("[LLClientView]: exception converting quaternion to bytes, using Quaternion.Identity. Exception: " + e.ToString());
5421 OpenMetaverse.Quaternion.Identity.ToBytes(objectData, 36);
5422 }
5423 data.AngularVelocity.ToBytes(objectData, 48); 5586 data.AngularVelocity.ToBytes(objectData, 48);
5424 5587
5425 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); 5588 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
@@ -5433,7 +5596,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5433 //update.JointType = 0; 5596 //update.JointType = 0;
5434 update.Material = data.Material; 5597 update.Material = data.Material;
5435 update.MediaURL = Utils.EmptyBytes; // FIXME: Support this in OpenSim 5598 update.MediaURL = Utils.EmptyBytes; // FIXME: Support this in OpenSim
5599<<<<<<< HEAD
5436 5600
5601=======
5602/*
5603>>>>>>> avn/ubitvar
5437 if (data.ParentGroup.IsAttachment) 5604 if (data.ParentGroup.IsAttachment)
5438 { 5605 {
5439 update.NameValue 5606 update.NameValue
@@ -5458,6 +5625,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5458 // case for attachments may contain conflicting values that can end up crashing the viewer. 5625 // case for attachments may contain conflicting values that can end up crashing the viewer.
5459 update.State = data.ParentGroup.RootPart.Shape.State; 5626 update.State = data.ParentGroup.RootPart.Shape.State;
5460 } 5627 }
5628 */
5629
5630 if (data.ParentGroup.IsAttachment)
5631 {
5632 if (data.IsRoot)
5633 {
5634 update.NameValue = Util.StringToBytes256("AttachItemID STRING RW SV " + data.ParentGroup.FromItemID);
5635 }
5636 else
5637 update.NameValue = Utils.EmptyBytes;
5638
5639 int st = (int)data.ParentGroup.AttachmentPoint;
5640 update.State = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
5641 }
5642 else
5643 {
5644 update.NameValue = Utils.EmptyBytes;
5645 update.State = data.Shape.State; // not sure about this
5646 }
5647
5461 5648
5462 update.ObjectData = objectData; 5649 update.ObjectData = objectData;
5463 update.ParentID = data.ParentID; 5650 update.ParentID = data.ParentID;
@@ -5579,8 +5766,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5579 // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs 5766 // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
5580 // for each AgentUpdate packet. 5767 // for each AgentUpdate packet.
5581 AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false); 5768 AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
5582 5769
5583 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false); 5770 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
5771 AddLocalPacketHandler(PacketType.VelocityInterpolateOff, HandleVelocityInterpolateOff, false);
5772 AddLocalPacketHandler(PacketType.VelocityInterpolateOn, HandleVelocityInterpolateOn, false);
5584 AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false); 5773 AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
5585 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false); 5774 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
5586 AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false); 5775 AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false);
@@ -5732,6 +5921,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5732 AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false); 5921 AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
5733 AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false); 5922 AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
5734 AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode); 5923 AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
5924 AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments);
5735 AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false); 5925 AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
5736 AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents); 5926 AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
5737 AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery); 5927 AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
@@ -5798,6 +5988,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5798 AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest); 5988 AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest);
5799 AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes); 5989 AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes);
5800 AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard); 5990 AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard);
5991 AddLocalPacketHandler(PacketType.ChangeInventoryItemFlags, HandleChangeInventoryItemFlags);
5801 5992
5802 AddGenericPacketHandler("autopilot", HandleAutopilot); 5993 AddGenericPacketHandler("autopilot", HandleAutopilot);
5803 } 5994 }
@@ -5809,7 +6000,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5809 #region Scene/Avatar 6000 #region Scene/Avatar
5810 6001
5811 // Threshold for body rotation to be a significant agent update 6002 // Threshold for body rotation to be a significant agent update
5812 private const float QDELTA = 0.000001f; 6003 // use the abs of cos
6004 private const float QDELTABody = 1.0f - 0.0001f;
6005 private const float QDELTAHead = 1.0f - 0.0001f;
5813 // Threshold for camera rotation to be a significant agent update 6006 // Threshold for camera rotation to be a significant agent update
5814 private const float VDELTA = 0.01f; 6007 private const float VDELTA = 0.01f;
5815 6008
@@ -5832,18 +6025,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5832 /// <param name='x'></param> 6025 /// <param name='x'></param>
5833 private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x) 6026 private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
5834 { 6027 {
5835 float qdelta1 = 1 - (float)Math.Pow(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation), 2); 6028 float qdelta1 = Math.Abs(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation));
5836 //qdelta2 = 1 - (float)Math.Pow(Quaternion.Dot(x.HeadRotation, m_thisAgentUpdateArgs.HeadRotation), 2); 6029 //qdelta2 = Math.Abs(Quaternion.Dot(x.HeadRotation, m_thisAgentUpdateArgs.HeadRotation));
5837 6030
5838 bool movementSignificant = 6031 bool movementSignificant =
5839 (qdelta1 > QDELTA) // significant if body rotation above threshold 6032 (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
5840 // Ignoring head rotation altogether, because it's not being used for anything interesting up the stack
5841 // || (qdelta2 > QDELTA * 10) // significant if head rotation above threshold
5842 || (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
5843 || (x.ControlFlags != (byte)AgentManager.ControlFlags.NONE) // significant if user supplying any movement update commands 6033 || (x.ControlFlags != (byte)AgentManager.ControlFlags.NONE) // significant if user supplying any movement update commands
5844 || (x.Far != m_thisAgentUpdateArgs.Far) // significant if far distance changed
5845 || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed 6034 || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
5846 || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed 6035 || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
6036 || (qdelta1 < QDELTABody) // significant if body rotation above(below cos) threshold
6037 // Ignoring head rotation altogether, because it's not being used for anything interesting up the stack
6038 // || (qdelta2 < QDELTAHead) // significant if head rotation above(below cos) threshold
6039 || (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed
5847 ; 6040 ;
5848 //if (movementSignificant) 6041 //if (movementSignificant)
5849 //{ 6042 //{
@@ -5886,55 +6079,63 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5886 return cameraSignificant; 6079 return cameraSignificant;
5887 } 6080 }
5888 6081
5889 private bool HandleAgentUpdate(IClientAPI sener, Packet packet) 6082 private bool HandleAgentUpdate(IClientAPI sender, Packet packet)
5890 { 6083 {
5891 // We got here, which means that something in agent update was significant 6084 // We got here, which means that something in agent update was significant
5892 6085
5893 AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet; 6086 AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
5894 AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData; 6087 AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
5895 6088
5896 if (x.AgentID != AgentId || x.SessionID != SessionId) 6089 if (x.AgentID != AgentId || x.SessionID != SessionId)
6090 {
6091 PacketPool.Instance.ReturnPacket(packet);
5897 return false; 6092 return false;
6093 }
6094
6095 TotalAgentUpdates++;
5898 6096
5899 // Before we update the current m_thisAgentUpdateArgs, let's check this again
5900 // to see what exactly changed
5901 bool movement = CheckAgentMovementUpdateSignificance(x); 6097 bool movement = CheckAgentMovementUpdateSignificance(x);
5902 bool camera = CheckAgentCameraUpdateSignificance(x); 6098 bool camera = CheckAgentCameraUpdateSignificance(x);
5903 6099
5904 m_thisAgentUpdateArgs.AgentID = x.AgentID;
5905 m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
5906 m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
5907 m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
5908 m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
5909 m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
5910 m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
5911 m_thisAgentUpdateArgs.Far = x.Far;
5912 m_thisAgentUpdateArgs.Flags = x.Flags;
5913 m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
5914 m_thisAgentUpdateArgs.SessionID = x.SessionID;
5915 m_thisAgentUpdateArgs.State = x.State;
5916
5917 UpdateAgent handlerAgentUpdate = OnAgentUpdate;
5918 UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate;
5919 UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate;
5920
5921 // Was there a significant movement/state change? 6100 // Was there a significant movement/state change?
5922 if (movement) 6101 if (movement)
5923 { 6102 {
6103 m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
6104 m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
6105 m_thisAgentUpdateArgs.Far = x.Far;
6106 m_thisAgentUpdateArgs.Flags = x.Flags;
6107 m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
6108// m_thisAgentUpdateArgs.SessionID = x.SessionID;
6109 m_thisAgentUpdateArgs.State = x.State;
6110
6111 UpdateAgent handlerAgentUpdate = OnAgentUpdate;
6112 UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate;
6113
5924 if (handlerPreAgentUpdate != null) 6114 if (handlerPreAgentUpdate != null)
5925 OnPreAgentUpdate(this, m_thisAgentUpdateArgs); 6115 OnPreAgentUpdate(this, m_thisAgentUpdateArgs);
5926 6116
5927 if (handlerAgentUpdate != null) 6117 if (handlerAgentUpdate != null)
5928 OnAgentUpdate(this, m_thisAgentUpdateArgs); 6118 OnAgentUpdate(this, m_thisAgentUpdateArgs);
6119
6120 handlerAgentUpdate = null;
6121 handlerPreAgentUpdate = null;
5929 } 6122 }
6123
5930 // Was there a significant camera(s) change? 6124 // Was there a significant camera(s) change?
5931 if (camera) 6125 if (camera)
6126 {
6127 m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
6128 m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
6129 m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
6130 m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
6131
6132 UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate;
6133
5932 if (handlerAgentCameraUpdate != null) 6134 if (handlerAgentCameraUpdate != null)
5933 handlerAgentCameraUpdate(this, m_thisAgentUpdateArgs); 6135 handlerAgentCameraUpdate(this, m_thisAgentUpdateArgs);
5934 6136
5935 handlerAgentUpdate = null; 6137 handlerAgentCameraUpdate = null;
5936 handlerPreAgentUpdate = null; 6138 }
5937 handlerAgentCameraUpdate = null;
5938 6139
5939 PacketPool.Instance.ReturnPacket(packet); 6140 PacketPool.Instance.ReturnPacket(packet);
5940 6141
@@ -6150,6 +6351,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6150 return true; 6351 return true;
6151 } 6352 }
6152 6353
6354 private bool HandleVelocityInterpolateOff(IClientAPI sender, Packet Pack)
6355 {
6356 VelocityInterpolateOffPacket p = (VelocityInterpolateOffPacket)Pack;
6357 if (p.AgentData.SessionID != SessionId ||
6358 p.AgentData.AgentID != AgentId)
6359 return true;
6360
6361 m_VelocityInterpolate = false;
6362 return true;
6363 }
6364
6365 private bool HandleVelocityInterpolateOn(IClientAPI sender, Packet Pack)
6366 {
6367 VelocityInterpolateOnPacket p = (VelocityInterpolateOnPacket)Pack;
6368 if (p.AgentData.SessionID != SessionId ||
6369 p.AgentData.AgentID != AgentId)
6370 return true;
6371
6372 m_VelocityInterpolate = true;
6373 return true;
6374 }
6375
6376
6153 private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack) 6377 private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack)
6154 { 6378 {
6155 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; 6379 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
@@ -6503,7 +6727,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6503 { 6727 {
6504 // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore, 6728 // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore,
6505 // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit. 6729 // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit.
6506 m_justEditedTerrain = true; // Prevent terrain packet (Land layer) from being queued, make it unreliable
6507 if (OnModifyTerrain != null) 6730 if (OnModifyTerrain != null)
6508 { 6731 {
6509 for (int i = 0; i < modify.ParcelData.Length; i++) 6732 for (int i = 0; i < modify.ParcelData.Length; i++)
@@ -6519,7 +6742,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6519 } 6742 }
6520 } 6743 }
6521 } 6744 }
6522 m_justEditedTerrain = false; // Queue terrain packet (Land layer) if necessary, make it reliable again
6523 } 6745 }
6524 6746
6525 return true; 6747 return true;
@@ -6581,16 +6803,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6581 for (int i = 0; i < appear.VisualParam.Length; i++) 6803 for (int i = 0; i < appear.VisualParam.Length; i++)
6582 visualparams[i] = appear.VisualParam[i].ParamValue; 6804 visualparams[i] = appear.VisualParam[i].ParamValue;
6583 //var b = appear.WearableData[0]; 6805 //var b = appear.WearableData[0];
6584 6806
6585 Primitive.TextureEntry te = null; 6807 Primitive.TextureEntry te = null;
6586 if (appear.ObjectData.TextureEntry.Length > 1) 6808 if (appear.ObjectData.TextureEntry.Length > 1)
6587 te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); 6809 te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
6588 6810
6589 WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length]; 6811 WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length];
6590 for (int i=0; i<appear.WearableData.Length;i++) 6812 for (int i=0; i<appear.WearableData.Length;i++)
6591 cacheitems[i] = new WearableCacheItem(){CacheId = appear.WearableData[i].CacheID,TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)}; 6813 cacheitems[i] = new WearableCacheItem(){
6592 6814 CacheId = appear.WearableData[i].CacheID,
6815 TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)
6816 };
6593 6817
6818
6594 6819
6595 handlerSetAppearance(sender, te, visualparams,avSize, cacheitems); 6820 handlerSetAppearance(sender, te, visualparams,avSize, cacheitems);
6596 } 6821 }
@@ -6794,13 +7019,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6794 return true; 7019 return true;
6795 } 7020 }
6796 7021
6797 private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack) 7022 private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack)
6798 { 7023 {
7024 m_log.DebugFormat("[LLClientView] HandleCompleteAgentMovement");
7025
6799 Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion; 7026 Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
6800 if (handlerCompleteMovementToRegion != null) 7027 if (handlerCompleteMovementToRegion != null)
6801 { 7028 {
6802 handlerCompleteMovementToRegion(sender, true); 7029 handlerCompleteMovementToRegion(sender, true);
6803 } 7030 }
7031 else
7032 m_log.Debug("HandleCompleteAgentMovement NULL handler");
7033
6804 handlerCompleteMovementToRegion = null; 7034 handlerCompleteMovementToRegion = null;
6805 7035
6806 return true; 7036 return true;
@@ -6818,7 +7048,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6818 return true; 7048 return true;
6819 } 7049 }
6820 #endregion 7050 #endregion
6821 7051/*
6822 StartAnim handlerStartAnim = null; 7052 StartAnim handlerStartAnim = null;
6823 StopAnim handlerStopAnim = null; 7053 StopAnim handlerStopAnim = null;
6824 7054
@@ -6842,6 +7072,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
6842 } 7072 }
6843 } 7073 }
6844 return true; 7074 return true;
7075*/
7076 ChangeAnim handlerChangeAnim = null;
7077
7078 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
7079 {
7080 handlerChangeAnim = OnChangeAnim;
7081 if (handlerChangeAnim != null)
7082 {
7083 handlerChangeAnim(AgentAni.AnimationList[i].AnimID, AgentAni.AnimationList[i].StartAnim, false);
7084 }
7085 }
7086
7087 handlerChangeAnim = OnChangeAnim;
7088 if (handlerChangeAnim != null)
7089 {
7090 handlerChangeAnim(UUID.Zero, false, true);
7091 }
7092
7093 return true;
6845 } 7094 }
6846 7095
6847 private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack) 7096 private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack)
@@ -7087,6 +7336,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
7087 #endregion 7336 #endregion
7088 7337
7089 m_udpClient.SetThrottles(atpack.Throttle.Throttles); 7338 m_udpClient.SetThrottles(atpack.Throttle.Throttles);
7339 GenericCall2 handler = OnUpdateThrottles;
7340 if (handler != null)
7341 {
7342 handler();
7343 }
7090 return true; 7344 return true;
7091 } 7345 }
7092 7346
@@ -7359,6 +7613,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
7359 7613
7360 for (int i = 0; i < incomingselect.ObjectData.Length; i++) 7614 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
7361 { 7615 {
7616 if (!SelectedObjects.Contains(incomingselect.ObjectData[i].ObjectLocalID))
7617 SelectedObjects.Add(incomingselect.ObjectData[i].ObjectLocalID);
7362 handlerObjectSelect = OnObjectSelect; 7618 handlerObjectSelect = OnObjectSelect;
7363 if (handlerObjectSelect != null) 7619 if (handlerObjectSelect != null)
7364 { 7620 {
@@ -7385,6 +7641,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
7385 7641
7386 for (int i = 0; i < incomingdeselect.ObjectData.Length; i++) 7642 for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
7387 { 7643 {
7644 if (!SelectedObjects.Contains(incomingdeselect.ObjectData[i].ObjectLocalID))
7645 SelectedObjects.Add(incomingdeselect.ObjectData[i].ObjectLocalID);
7388 handlerObjectDeselect = OnObjectDeselect; 7646 handlerObjectDeselect = OnObjectDeselect;
7389 if (handlerObjectDeselect != null) 7647 if (handlerObjectDeselect != null)
7390 { 7648 {
@@ -7511,7 +7769,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
7511 physdata.Bounce = phsblock.Restitution; 7769 physdata.Bounce = phsblock.Restitution;
7512 physdata.Density = phsblock.Density; 7770 physdata.Density = phsblock.Density;
7513 physdata.Friction = phsblock.Friction; 7771 physdata.Friction = phsblock.Friction;
7514 physdata.GravitationModifier = phsblock.GravityMultiplier; 7772 physdata.GravitationModifier = phsblock.GravityMultiplier;
7515 } 7773 }
7516 7774
7517 handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this); 7775 handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
@@ -8097,6 +8355,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
8097 // surrounding scene 8355 // surrounding scene
8098 if ((ImageType)block.Type == ImageType.Baked) 8356 if ((ImageType)block.Type == ImageType.Baked)
8099 args.Priority *= 2.0f; 8357 args.Priority *= 2.0f;
8358 int wearableout = 0;
8100 8359
8101 ImageManager.EnqueueReq(args); 8360 ImageManager.EnqueueReq(args);
8102 } 8361 }
@@ -9106,7 +9365,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
9106 if ((locX >= m_scene.RegionInfo.WorldLocX) 9365 if ((locX >= m_scene.RegionInfo.WorldLocX)
9107 && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX)) 9366 && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
9108 && (locY >= m_scene.RegionInfo.WorldLocY) 9367 && (locY >= m_scene.RegionInfo.WorldLocY)
9368<<<<<<< HEAD
9109 && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)) ) 9369 && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)) )
9370=======
9371 && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)))
9372>>>>>>> avn/ubitvar
9110 { 9373 {
9111 tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle; 9374 tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
9112 tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX; 9375 tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
@@ -9146,16 +9409,61 @@ namespace OpenSim.Region.ClientStack.LindenUDP
9146 9409
9147 #region Parcel related packets 9410 #region Parcel related packets
9148 9411
9412 // acumulate several HandleRegionHandleRequest consecutive overlaping requests
9413 // to be done with minimal resources as possible
9414 // variables temporary here while in test
9415
9416 Queue<UUID> RegionHandleRequests = new Queue<UUID>();
9417 bool RegionHandleRequestsInService = false;
9418
9149 private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack) 9419 private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack)
9150 { 9420 {
9151 RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; 9421 UUID currentUUID;
9152 9422
9153 RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest; 9423 RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest;
9154 if (handlerRegionHandleRequest != null) 9424
9425 if (handlerRegionHandleRequest == null)
9426 return true;
9427
9428 RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
9429
9430 lock (RegionHandleRequests)
9431 {
9432 if (RegionHandleRequestsInService)
9433 {
9434 // we are already busy doing a previus request
9435 // so enqueue it
9436 RegionHandleRequests.Enqueue(rhrPack.RequestBlock.RegionID);
9437 return true;
9438 }
9439
9440 // else do it
9441 currentUUID = rhrPack.RequestBlock.RegionID;
9442 RegionHandleRequestsInService = true;
9443 }
9444
9445 while (true)
9155 { 9446 {
9156 handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID); 9447 handlerRegionHandleRequest(this, currentUUID);
9448
9449 lock (RegionHandleRequests)
9450 {
9451 // exit condition, nothing to do or closed
9452 // current code seems to assume we may loose the handler at anytime,
9453 // so keep checking it
9454 handlerRegionHandleRequest = OnRegionHandleRequest;
9455
9456 if (RegionHandleRequests.Count == 0 || !IsActive || handlerRegionHandleRequest == null)
9457 {
9458 RegionHandleRequests.Clear();
9459 RegionHandleRequestsInService = false;
9460 return true;
9461 }
9462 currentUUID = RegionHandleRequests.Dequeue();
9463 }
9157 } 9464 }
9158 return true; 9465
9466 return true; // actually unreached
9159 } 9467 }
9160 9468
9161 private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack) 9469 private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack)
@@ -10425,7 +10733,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
10425 handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID, 10733 handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID,
10426 Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName), 10734 Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName),
10427 UpdateMuteListEntry.MuteData.MuteType, 10735 UpdateMuteListEntry.MuteData.MuteType,
10428 UpdateMuteListEntry.AgentData.AgentID); 10736 UpdateMuteListEntry.MuteData.MuteFlags);
10429 return true; 10737 return true;
10430 } 10738 }
10431 return false; 10739 return false;
@@ -10440,8 +10748,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
10440 { 10748 {
10441 handlerRemoveMuteListEntry(this, 10749 handlerRemoveMuteListEntry(this,
10442 RemoveMuteListEntry.MuteData.MuteID, 10750 RemoveMuteListEntry.MuteData.MuteID,
10443 Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName), 10751 Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName));
10444 RemoveMuteListEntry.AgentData.AgentID);
10445 return true; 10752 return true;
10446 } 10753 }
10447 return false; 10754 return false;
@@ -10485,10 +10792,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP
10485 return false; 10792 return false;
10486 } 10793 }
10487 10794
10795 private bool HandleChangeInventoryItemFlags(IClientAPI client, Packet packet)
10796 {
10797 ChangeInventoryItemFlagsPacket ChangeInventoryItemFlags =
10798 (ChangeInventoryItemFlagsPacket)packet;
10799 ChangeInventoryItemFlags handlerChangeInventoryItemFlags = OnChangeInventoryItemFlags;
10800 if (handlerChangeInventoryItemFlags != null)
10801 {
10802 foreach(ChangeInventoryItemFlagsPacket.InventoryDataBlock b in ChangeInventoryItemFlags.InventoryData)
10803 handlerChangeInventoryItemFlags(this, b.ItemID, b.Flags);
10804 return true;
10805 }
10806 return false;
10807 }
10808
10488 private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack) 10809 private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack)
10489 { 10810 {
10490 return true; 10811 return true;
10491 } 10812 }
10813
10814 private bool HandleCreateNewOutfitAttachments(IClientAPI sender, Packet Pack)
10815 {
10816 CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack;
10817
10818 #region Packet Session and User Check
10819 if (m_checkPackets)
10820 {
10821 if (packet.AgentData.SessionID != SessionId ||
10822 packet.AgentData.AgentID != AgentId)
10823 return true;
10824 }
10825 #endregion
10826 MoveItemsAndLeaveCopy handlerMoveItemsAndLeaveCopy = null;
10827 List<InventoryItemBase> items = new List<InventoryItemBase>();
10828 foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData)
10829 {
10830 InventoryItemBase b = new InventoryItemBase();
10831 b.ID = n.OldItemID;
10832 b.Folder = n.OldFolderID;
10833 items.Add(b);
10834 }
10835
10836 handlerMoveItemsAndLeaveCopy = OnMoveItemsAndLeaveCopy;
10837 if (handlerMoveItemsAndLeaveCopy != null)
10838 {
10839 handlerMoveItemsAndLeaveCopy(this, items, packet.HeaderData.NewFolderID);
10840 }
10841
10842 return true;
10843 }
10492 10844
10493 private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack) 10845 private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack)
10494 { 10846 {
@@ -10915,6 +11267,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
10915 groupProfileReply.GroupData.MaturePublish = d.MaturePublish; 11267 groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
10916 groupProfileReply.GroupData.OwnerRole = d.OwnerRole; 11268 groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
10917 11269
11270 Scene scene = (Scene)m_scene;
11271 if (scene.Permissions.IsGod(sender.AgentId) && (!sender.IsGroupMember(groupProfileRequest.GroupData.GroupID)))
11272 {
11273 ScenePresence p;
11274 if (scene.TryGetScenePresence(sender.AgentId, out p))
11275 {
11276 if (p.GodLevel >= 200)
11277 {
11278 groupProfileReply.GroupData.OpenEnrollment = true;
11279 groupProfileReply.GroupData.MembershipFee = 0;
11280 }
11281 }
11282 }
11283
10918 OutPacket(groupProfileReply, ThrottleOutPacketType.Task); 11284 OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
10919 } 11285 }
10920 return true; 11286 return true;
@@ -11488,11 +11854,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11488 11854
11489 StartLure handlerStartLure = OnStartLure; 11855 StartLure handlerStartLure = OnStartLure;
11490 if (handlerStartLure != null) 11856 if (handlerStartLure != null)
11491 handlerStartLure(startLureRequest.Info.LureType, 11857 {
11492 Utils.BytesToString( 11858 for (int i = 0 ; i < startLureRequest.TargetData.Length ; i++)
11493 startLureRequest.Info.Message), 11859 {
11494 startLureRequest.TargetData[0].TargetID, 11860 handlerStartLure(startLureRequest.Info.LureType,
11495 this); 11861 Utils.BytesToString(
11862 startLureRequest.Info.Message),
11863 startLureRequest.TargetData[i].TargetID,
11864 this);
11865 }
11866 }
11496 return true; 11867 return true;
11497 } 11868 }
11498 private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack) 11869 private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack)
@@ -11606,10 +11977,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11606 } 11977 }
11607 #endregion 11978 #endregion
11608 11979
11609 ClassifiedDelete handlerClassifiedGodDelete = OnClassifiedGodDelete; 11980 ClassifiedGodDelete handlerClassifiedGodDelete = OnClassifiedGodDelete;
11610 if (handlerClassifiedGodDelete != null) 11981 if (handlerClassifiedGodDelete != null)
11611 handlerClassifiedGodDelete( 11982 handlerClassifiedGodDelete(
11612 classifiedGodDelete.Data.ClassifiedID, 11983 classifiedGodDelete.Data.ClassifiedID,
11984 classifiedGodDelete.Data.QueryID,
11613 this); 11985 this);
11614 return true; 11986 return true;
11615 } 11987 }
@@ -11912,13 +12284,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11912 /// <param name="simclient"></param> 12284 /// <param name="simclient"></param>
11913 /// <param name="packet"></param> 12285 /// <param name="packet"></param>
11914 /// <returns></returns> 12286 /// <returns></returns>
11915 protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet) 12287 // TODO: Convert old handler to use new method
12288 /*protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet)
11916 { 12289 {
11917 AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet; 12290 AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
11918 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse); 12291 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
11919 12292
11920 if (cachedtex.AgentData.SessionID != SessionId) 12293 if (cachedtex.AgentData.SessionID != SessionId)
11921 return false; 12294 return false;
12295
11922 12296
11923 12297
11924 // TODO: don't create new blocks if recycling an old packet 12298 // TODO: don't create new blocks if recycling an old packet
@@ -11966,6 +12340,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11966 } 12340 }
11967 } 12341 }
11968 12342
12343<<<<<<< HEAD
11969 if (cacheItems != null) 12344 if (cacheItems != null)
11970 { 12345 {
11971 // We need to make sure the asset stored in the bake is available on this server also by its assetid before we map it to a Cacheid. 12346 // We need to make sure the asset stored in the bake is available on this server also by its assetid before we map it to a Cacheid.
@@ -11985,13 +12360,69 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11985 { 12360 {
11986 WearableCacheItem item = 12361 WearableCacheItem item =
11987 WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex, cacheItems); 12362 WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex, cacheItems);
12363=======
12364 CachedTextureRequest handlerCachedTextureRequest = OnCachedTextureRequest;
12365 if (handlerCachedTextureRequest != null)
12366 {
12367 handlerCachedTextureRequest(simclient,cachedtex.AgentData.SerialNum,requestArgs);
12368 }
12369
12370 return true;
12371 }*/
12372
12373 protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet)
12374 {
12375 //m_log.Debug("texture cached: " + packet.ToString());
12376 AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
12377 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
12378
12379 if (cachedtex.AgentData.SessionID != SessionId)
12380 return false;
12381
12382 // TODO: don't create new blocks if recycling an old packet
12383 cachedresp.AgentData.AgentID = AgentId;
12384 cachedresp.AgentData.SessionID = m_sessionId;
12385 cachedresp.AgentData.SerialNum = cachedtex.AgentData.SerialNum;
12386 cachedresp.WearableData =
12387 new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
12388
12389 int maxWearablesLoop = cachedtex.WearableData.Length;
12390 if (maxWearablesLoop > AvatarWearable.MAX_WEARABLES)
12391 maxWearablesLoop = AvatarWearable.MAX_WEARABLES;
12392
12393 int cacheHits = 0;
12394
12395 // We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid
12396
12397 WearableCacheItem[] cacheItems = null;
12398
12399 ScenePresence p = m_scene.GetScenePresence(AgentId);
12400
12401 if (p != null && p.Appearance != null)
12402 {
12403 cacheItems = p.Appearance.WearableCacheItems;
12404 }
12405
12406 if (cacheItems != null)
12407 {
12408 for (int i = 0; i < maxWearablesLoop; i++)
12409 {
12410 int idx = cachedtex.WearableData[i].TextureIndex;
12411>>>>>>> avn/ubitvar
11988 12412
11989 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); 12413 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
11990 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex; 12414 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
11991 cachedresp.WearableData[i].HostName = new byte[0]; 12415 cachedresp.WearableData[i].HostName = new byte[0];
12416<<<<<<< HEAD
11992 if (item != null && cachedtex.WearableData[i].ID == item.CacheId) 12417 if (item != null && cachedtex.WearableData[i].ID == item.CacheId)
11993 { 12418 {
11994 cachedresp.WearableData[i].TextureID = item.TextureID; 12419 cachedresp.WearableData[i].TextureID = item.TextureID;
12420=======
12421 if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
12422 {
12423 cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
12424 cacheHits++;
12425>>>>>>> avn/ubitvar
11995 } 12426 }
11996 else 12427 else
11997 { 12428 {
@@ -12001,22 +12432,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12001 } 12432 }
12002 else 12433 else
12003 { 12434 {
12435<<<<<<< HEAD
12004 // Cached textures not available 12436 // Cached textures not available
12437=======
12438>>>>>>> avn/ubitvar
12005 for (int i = 0; i < maxWearablesLoop; i++) 12439 for (int i = 0; i < maxWearablesLoop; i++)
12006 { 12440 {
12007 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); 12441 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
12008 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex; 12442 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
12009 cachedresp.WearableData[i].TextureID = UUID.Zero; 12443 cachedresp.WearableData[i].TextureID = UUID.Zero;
12444<<<<<<< HEAD
12010 cachedresp.WearableData[i].HostName = new byte[0]; 12445 cachedresp.WearableData[i].HostName = new byte[0];
12011 } 12446 }
12012 } 12447 }
12013 12448
12449=======
12450 //UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
12451 cachedresp.WearableData[i].HostName = new byte[0];
12452 }
12453 }
12454
12455 m_log.DebugFormat("texture cached: hits {0}", cacheHits);
12456
12457>>>>>>> avn/ubitvar
12014 cachedresp.Header.Zerocoded = true; 12458 cachedresp.Header.Zerocoded = true;
12015 OutPacket(cachedresp, ThrottleOutPacketType.Task); 12459 OutPacket(cachedresp, ThrottleOutPacketType.Task);
12016 12460
12017 return true; 12461 return true;
12018 } 12462 }
12019 12463
12020 /// <summary> 12464 /// <summary>
12021 /// Send a response back to a client when it asks the asset server (via the region server) if it has 12465 /// Send a response back to a client when it asks the asset server (via the region server) if it has
12022 /// its appearance texture cached. 12466 /// its appearance texture cached.
@@ -12080,209 +12524,147 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12080 } 12524 }
12081 else 12525 else
12082 { 12526 {
12083// m_log.DebugFormat( 12527 ClientChangeObject updatehandler = onClientChangeObject;
12084// "[CLIENT]: Processing block {0} type {1} for {2} {3}",
12085// i, block.Type, part.Name, part.LocalId);
12086 12528
12087// // Do this once since fetch parts creates a new array. 12529 if (updatehandler != null)
12088// SceneObjectPart[] parts = part.ParentGroup.Parts; 12530 {
12089// for (int j = 0; j < parts.Length; j++) 12531 ObjectChangeData udata = new ObjectChangeData();
12090// {
12091// part.StoreUndoState();
12092// parts[j].IgnoreUndoUpdate = true;
12093// }
12094 12532
12095 UpdatePrimGroupRotation handlerUpdatePrimGroupRotation; 12533 /*ubit from ll JIRA:
12534 * 0x01 position
12535 * 0x02 rotation
12536 * 0x04 scale
12537
12538 * 0x08 LINK_SET
12539 * 0x10 UNIFORM for scale
12540 */
12096 12541
12097 switch (block.Type) 12542 // translate to internal changes
12098 { 12543 // not all cases .. just the ones older code did
12099 case 1:
12100 Vector3 pos1 = new Vector3(block.Data, 0);
12101 12544
12102 UpdateVector handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; 12545 switch (block.Type)
12103 if (handlerUpdatePrimSinglePosition != null) 12546 {
12104 { 12547 case 1: //change position sp
12105 // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); 12548 udata.position = new Vector3(block.Data, 0);
12106 handlerUpdatePrimSinglePosition(localId, pos1, this);
12107 }
12108 break;
12109 12549
12110 case 2: 12550 udata.change = ObjectChangeType.primP;
12111 Quaternion rot1 = new Quaternion(block.Data, 0, true); 12551 updatehandler(localId, udata, this);
12552 break;
12112 12553
12113 UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation; 12554 case 2: // rotation sp
12114 if (handlerUpdatePrimSingleRotation != null) 12555 udata.rotation = new Quaternion(block.Data, 0, true);
12115 {
12116 // m_log.Info("new tab rotation is " + rot1.X + " , " + rot1.Y + " , " + rot1.Z + " , " + rot1.W);
12117 handlerUpdatePrimSingleRotation(localId, rot1, this);
12118 }
12119 break;
12120 12556
12121 case 3: 12557 udata.change = ObjectChangeType.primR;
12122 Vector3 rotPos = new Vector3(block.Data, 0); 12558 updatehandler(localId, udata, this);
12123 Quaternion rot2 = new Quaternion(block.Data, 12, true); 12559 break;
12124 12560
12125 UpdatePrimSingleRotationPosition handlerUpdatePrimSingleRotationPosition = OnUpdatePrimSingleRotationPosition; 12561 case 3: // position plus rotation
12126 if (handlerUpdatePrimSingleRotationPosition != null) 12562 udata.position = new Vector3(block.Data, 0);
12127 { 12563 udata.rotation = new Quaternion(block.Data, 12, true);
12128 // m_log.Debug("new mouse rotation position is " + rotPos.X + " , " + rotPos.Y + " , " + rotPos.Z);
12129 // m_log.Info("new mouse rotation is " + rot2.X + " , " + rot2.Y + " , " + rot2.Z + " , " + rot2.W);
12130 handlerUpdatePrimSingleRotationPosition(localId, rot2, rotPos, this);
12131 }
12132 break;
12133 12564
12134 case 4: 12565 udata.change = ObjectChangeType.primPR;
12135 case 20: 12566 updatehandler(localId, udata, this);
12136 Vector3 scale4 = new Vector3(block.Data, 0); 12567 break;
12137 12568
12138 UpdateVector handlerUpdatePrimScale = OnUpdatePrimScale; 12569 case 4: // scale sp
12139 if (handlerUpdatePrimScale != null) 12570 udata.scale = new Vector3(block.Data, 0);
12140 { 12571 udata.change = ObjectChangeType.primS;
12141 // m_log.Debug("new scale is " + scale4.X + " , " + scale4.Y + " , " + scale4.Z);
12142 handlerUpdatePrimScale(localId, scale4, this);
12143 }
12144 break;
12145 12572
12146 case 5: 12573 updatehandler(localId, udata, this);
12147 Vector3 scale1 = new Vector3(block.Data, 12); 12574 break;
12148 Vector3 pos11 = new Vector3(block.Data, 0);
12149 12575
12150 handlerUpdatePrimScale = OnUpdatePrimScale; 12576 case 0x14: // uniform scale sp
12151 if (handlerUpdatePrimScale != null) 12577 udata.scale = new Vector3(block.Data, 0);
12152 {
12153 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12154 handlerUpdatePrimScale(localId, scale1, this);
12155 12578
12156 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; 12579 udata.change = ObjectChangeType.primUS;
12157 if (handlerUpdatePrimSinglePosition != null) 12580 updatehandler(localId, udata, this);
12158 { 12581 break;
12159 handlerUpdatePrimSinglePosition(localId, pos11, this);
12160 }
12161 }
12162 break;
12163 12582
12164 case 9: 12583 case 5: // scale and position sp
12165 Vector3 pos2 = new Vector3(block.Data, 0); 12584 udata.position = new Vector3(block.Data, 0);
12585 udata.scale = new Vector3(block.Data, 12);
12166 12586
12167 UpdateVector handlerUpdateVector = OnUpdatePrimGroupPosition; 12587 udata.change = ObjectChangeType.primPS;
12588 updatehandler(localId, udata, this);
12589 break;
12168 12590
12169 if (handlerUpdateVector != null) 12591 case 0x15: //uniform scale and position
12170 { 12592 udata.position = new Vector3(block.Data, 0);
12171 handlerUpdateVector(localId, pos2, this); 12593 udata.scale = new Vector3(block.Data, 12);
12172 }
12173 break;
12174 12594
12175 case 10: 12595 udata.change = ObjectChangeType.primPUS;
12176 Quaternion rot3 = new Quaternion(block.Data, 0, true); 12596 updatehandler(localId, udata, this);
12597 break;
12177 12598
12178 UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation; 12599 // now group related (bit 4)
12179 if (handlerUpdatePrimRotation != null) 12600 case 9: //( 8 + 1 )group position
12180 { 12601 udata.position = new Vector3(block.Data, 0);
12181 // Console.WriteLine("new rotation is " + rot3.X + " , " + rot3.Y + " , " + rot3.Z + " , " + rot3.W);
12182 handlerUpdatePrimRotation(localId, rot3, this);
12183 }
12184 break;
12185 12602
12186 case 11: 12603 udata.change = ObjectChangeType.groupP;
12187 Vector3 pos3 = new Vector3(block.Data, 0); 12604 updatehandler(localId, udata, this);
12188 Quaternion rot4 = new Quaternion(block.Data, 12, true); 12605 break;
12189 12606
12190 handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation; 12607 case 0x0A: // (8 + 2) group rotation
12191 if (handlerUpdatePrimGroupRotation != null) 12608 udata.rotation = new Quaternion(block.Data, 0, true);
12192 {
12193 // m_log.Debug("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
12194 // m_log.Debug("new group mouse rotation is " + rot4.X + " , " + rot4.Y + " , " + rot4.Z + " , " + rot4.W);
12195 handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
12196 }
12197 break;
12198 case 12:
12199 case 28:
12200 Vector3 scale7 = new Vector3(block.Data, 0);
12201 12609
12202 UpdateVector handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale; 12610 udata.change = ObjectChangeType.groupR;
12203 if (handlerUpdatePrimGroupScale != null) 12611 updatehandler(localId, udata, this);
12204 { 12612 break;
12205 // m_log.Debug("new scale is " + scale7.X + " , " + scale7.Y + " , " + scale7.Z);
12206 handlerUpdatePrimGroupScale(localId, scale7, this);
12207 }
12208 break;
12209 12613
12210 case 13: 12614 case 0x0B: //( 8 + 2 + 1) group rotation and position
12211 Vector3 scale2 = new Vector3(block.Data, 12); 12615 udata.position = new Vector3(block.Data, 0);
12212 Vector3 pos4 = new Vector3(block.Data, 0); 12616 udata.rotation = new Quaternion(block.Data, 12, true);
12213 12617
12214 handlerUpdatePrimScale = OnUpdatePrimScale; 12618 udata.change = ObjectChangeType.groupPR;
12215 if (handlerUpdatePrimScale != null) 12619 updatehandler(localId, udata, this);
12216 { 12620 break;
12217 //m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12218 handlerUpdatePrimScale(localId, scale2, this);
12219 12621
12220 // Change the position based on scale (for bug number 246) 12622 case 0x0C: // (8 + 4) group scale
12221 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; 12623 // only afects root prim and only sent by viewer editor object tab scaling
12222 // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); 12624 // mouse edition only allows uniform scaling
12223 if (handlerUpdatePrimSinglePosition != null) 12625 // SL MAY CHANGE THIS in viewers
12224 {
12225 handlerUpdatePrimSinglePosition(localId, pos4, this);
12226 }
12227 }
12228 break;
12229 12626
12230 case 29: 12627 udata.scale = new Vector3(block.Data, 0);
12231 Vector3 scale5 = new Vector3(block.Data, 12);
12232 Vector3 pos5 = new Vector3(block.Data, 0);
12233 12628
12234 handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale; 12629 udata.change = ObjectChangeType.groupS;
12235 if (handlerUpdatePrimGroupScale != null) 12630 updatehandler(localId, udata, this);
12236 {
12237 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12238 part.StoreUndoState(true);
12239 part.IgnoreUndoUpdate = true;
12240 handlerUpdatePrimGroupScale(localId, scale5, this);
12241 handlerUpdateVector = OnUpdatePrimGroupPosition;
12242 12631
12243 if (handlerUpdateVector != null) 12632 break;
12244 {
12245 handlerUpdateVector(localId, pos5, this);
12246 }
12247 12633
12248 part.IgnoreUndoUpdate = false; 12634 case 0x0D: //(8 + 4 + 1) group scale and position
12249 } 12635 // exception as above
12250 12636
12251 break; 12637 udata.position = new Vector3(block.Data, 0);
12638 udata.scale = new Vector3(block.Data, 12);
12252 12639
12253 case 21: 12640 udata.change = ObjectChangeType.groupPS;
12254 Vector3 scale6 = new Vector3(block.Data, 12); 12641 updatehandler(localId, udata, this);
12255 Vector3 pos6 = new Vector3(block.Data, 0); 12642 break;
12256 12643
12257 handlerUpdatePrimScale = OnUpdatePrimScale; 12644 case 0x1C: // (0x10 + 8 + 4 ) group scale UNIFORM
12258 if (handlerUpdatePrimScale != null) 12645 udata.scale = new Vector3(block.Data, 0);
12259 {
12260 part.StoreUndoState(false);
12261 part.IgnoreUndoUpdate = true;
12262 12646
12263 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); 12647 udata.change = ObjectChangeType.groupUS;
12264 handlerUpdatePrimScale(localId, scale6, this); 12648 updatehandler(localId, udata, this);
12265 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; 12649 break;
12266 if (handlerUpdatePrimSinglePosition != null)
12267 {
12268 handlerUpdatePrimSinglePosition(localId, pos6, this);
12269 }
12270 12650
12271 part.IgnoreUndoUpdate = false; 12651 case 0x1D: // (UNIFORM + GROUP + SCALE + POS)
12272 } 12652 udata.position = new Vector3(block.Data, 0);
12273 break; 12653 udata.scale = new Vector3(block.Data, 12);
12274 12654
12275 default: 12655 udata.change = ObjectChangeType.groupPUS;
12276 m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type)); 12656 updatehandler(localId, udata, this);
12277 break; 12657 break;
12658
12659 default:
12660 m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
12661 break;
12662 }
12278 } 12663 }
12279 12664
12280// for (int j = 0; j < parts.Length; j++)
12281// parts[j].IgnoreUndoUpdate = false;
12282 } 12665 }
12283 } 12666 }
12284 } 12667 }
12285
12286 return true; 12668 return true;
12287 } 12669 }
12288 12670
@@ -12342,7 +12724,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12342 /// <param name="throttles"></param> 12724 /// <param name="throttles"></param>
12343 public void SetChildAgentThrottle(byte[] throttles) 12725 public void SetChildAgentThrottle(byte[] throttles)
12344 { 12726 {
12345 m_udpClient.SetThrottles(throttles); 12727 SetChildAgentThrottle(throttles, 1.0f);
12728 }
12729
12730 public void SetChildAgentThrottle(byte[] throttles,float factor)
12731 {
12732 m_udpClient.SetThrottles(throttles, factor);
12733 GenericCall2 handler = OnUpdateThrottles;
12734 if (handler != null)
12735 {
12736 handler();
12737 }
12738 }
12739
12740 /// <summary>
12741 /// Sets the throttles from values supplied caller
12742 /// </summary>
12743 /// <param name="throttles"></param>
12744 public void SetAgentThrottleSilent(int throttle, int setting)
12745 {
12746 m_udpClient.ForceThrottleSetting(throttle,setting);
12747 }
12748
12749 public int GetAgentThrottleSilent(int throttle)
12750 {
12751 return m_udpClient.GetThrottleSetting(throttle);
12346 } 12752 }
12347 12753
12348 /// <summary> 12754 /// <summary>
@@ -12450,8 +12856,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12450 uint regionY = 0; 12856 uint regionY = 0;
12451 12857
12452 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY); 12858 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY);
12453 locx = Convert.ToSingle(args[0]) - (float)regionX; 12859 locx = (float)(Convert.ToDouble(args[0]) - (double)regionX);
12454 locy = Convert.ToSingle(args[1]) - (float)regionY; 12860 locy = (float)(Convert.ToDouble(args[1]) - (double)regionY);
12455 locz = Convert.ToSingle(args[2]); 12861 locz = Convert.ToSingle(args[2]);
12456 12862
12457 Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo; 12863 Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo;
@@ -12736,7 +13142,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12736// "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}", 13142// "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
12737// requestID, taskID, (SourceType)sourceType, Name); 13143// requestID, taskID, (SourceType)sourceType, Name);
12738 13144
13145
13146 //Note, the bool returned from the below function is useless since it is always false.
12739 m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived); 13147 m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
13148
12740 } 13149 }
12741 13150
12742 /// <summary> 13151 /// <summary>
@@ -12819,7 +13228,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12819 /// <returns></returns> 13228 /// <returns></returns>
12820 private static int CalculateNumPackets(byte[] data) 13229 private static int CalculateNumPackets(byte[] data)
12821 { 13230 {
12822 const uint m_maxPacketSize = 600; 13231// const uint m_maxPacketSize = 600;
13232 uint m_maxPacketSize = MaxTransferBytesPerPacket;
12823 int numPackets = 1; 13233 int numPackets = 1;
12824 13234
12825 if (data == null) 13235 if (data == null)
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
index 0394e54..9293882 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs
@@ -129,7 +129,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
129 public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection(); 129 public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection();
130 130
131 /// <summary>ACKs that are queued up, waiting to be sent to the client</summary> 131 /// <summary>ACKs that are queued up, waiting to be sent to the client</summary>
132 public readonly OpenSim.Framework.LocklessQueue<uint> PendingAcks = new OpenSim.Framework.LocklessQueue<uint>(); 132 public readonly DoubleLocklessQueue<uint> PendingAcks = new DoubleLocklessQueue<uint>();
133 133
134 /// <summary>Current packet sequence number</summary> 134 /// <summary>Current packet sequence number</summary>
135 public int CurrentSequence; 135 public int CurrentSequence;
@@ -181,7 +181,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
181 /// <summary>Throttle buckets for each packet category</summary> 181 /// <summary>Throttle buckets for each packet category</summary>
182 private readonly TokenBucket[] m_throttleCategories; 182 private readonly TokenBucket[] m_throttleCategories;
183 /// <summary>Outgoing queues for throttled packets</summary> 183 /// <summary>Outgoing queues for throttled packets</summary>
184 private readonly OpenSim.Framework.LocklessQueue<OutgoingPacket>[] m_packetOutboxes = new OpenSim.Framework.LocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT]; 184 private readonly DoubleLocklessQueue<OutgoingPacket>[] m_packetOutboxes = new DoubleLocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT];
185 /// <summary>A container that can hold one packet for each outbox, used to store 185 /// <summary>A container that can hold one packet for each outbox, used to store
186 /// dequeued packets that are being held for throttling</summary> 186 /// dequeued packets that are being held for throttling</summary>
187 private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT]; 187 private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT];
@@ -193,6 +193,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
193 193
194 private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC 194 private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC
195 private int m_maxRTO = 60000; 195 private int m_maxRTO = 60000;
196 public bool m_deliverPackets = true;
197
198 private float m_burstTime;
199
200 public int m_lastStartpingTimeMS;
201 public int m_pingMS;
202
203 public int PingTimeMS
204 {
205 get
206 {
207 if (m_pingMS < 10)
208 return 10;
209 if(m_pingMS > 2000)
210 return 2000;
211 return m_pingMS;
212 }
213 }
196 214
197 /// <summary> 215 /// <summary>
198 /// This is the percentage of the udp texture queue to add to the task queue since 216 /// This is the percentage of the udp texture queue to add to the task queue since
@@ -232,6 +250,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
232 if (maxRTO != 0) 250 if (maxRTO != 0)
233 m_maxRTO = maxRTO; 251 m_maxRTO = maxRTO;
234 252
253<<<<<<< HEAD
235 ProcessUnackedSends = true; 254 ProcessUnackedSends = true;
236 255
237 // Create a token bucket throttle for this client that has the scene token bucket as a parent 256 // Create a token bucket throttle for this client that has the scene token bucket as a parent
@@ -240,16 +259,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
240 string.Format("adaptive throttle for {0} in {1}", AgentID, server.Scene.Name), 259 string.Format("adaptive throttle for {0} in {1}", AgentID, server.Scene.Name),
241 parentThrottle, 0, rates.Total, rates.MinimumAdaptiveThrottleRate, rates.AdaptiveThrottlesEnabled); 260 parentThrottle, 0, rates.Total, rates.MinimumAdaptiveThrottleRate, rates.AdaptiveThrottlesEnabled);
242 261
262=======
263 m_burstTime = rates.BrustTime;
264 float m_burst = rates.ClientMaxRate * m_burstTime;
265
266 // Create a token bucket throttle for this client that has the scene token bucket as a parent
267 m_throttleClient = new AdaptiveTokenBucket(parentThrottle, rates.ClientMaxRate, m_burst, rates.AdaptiveThrottlesEnabled);
268>>>>>>> avn/ubitvar
243 // Create an array of token buckets for this clients different throttle categories 269 // Create an array of token buckets for this clients different throttle categories
244 m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT]; 270 m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];
245 271
246 m_cannibalrate = rates.CannibalizeTextureRate; 272 m_cannibalrate = rates.CannibalizeTextureRate;
247 273
274 m_burst = rates.Total * rates.BrustTime;
275
248 for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) 276 for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
249 { 277 {
250 ThrottleOutPacketType type = (ThrottleOutPacketType)i; 278 ThrottleOutPacketType type = (ThrottleOutPacketType)i;
251 279
252 // Initialize the packet outboxes, where packets sit while they are waiting for tokens 280 // Initialize the packet outboxes, where packets sit while they are waiting for tokens
281<<<<<<< HEAD
253 m_packetOutboxes[i] = new OpenSim.Framework.LocklessQueue<OutgoingPacket>(); 282 m_packetOutboxes[i] = new OpenSim.Framework.LocklessQueue<OutgoingPacket>();
254 283
255 // Initialize the token buckets that control the throttling for each category 284 // Initialize the token buckets that control the throttling for each category
@@ -257,6 +286,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
257 = new TokenBucket( 286 = new TokenBucket(
258 string.Format("{0} throttle for {1} in {2}", type, AgentID, server.Scene.Name), 287 string.Format("{0} throttle for {1} in {2}", type, AgentID, server.Scene.Name),
259 m_throttleClient, rates.GetRate(type), 0); 288 m_throttleClient, rates.GetRate(type), 0);
289=======
290 m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>();
291 // Initialize the token buckets that control the throttling for each category
292 m_throttleCategories[i] = new TokenBucket(m_throttleClient, rates.GetRate(type), m_burst);
293>>>>>>> avn/ubitvar
260 } 294 }
261 295
262 // Default the retransmission timeout to one second 296 // Default the retransmission timeout to one second
@@ -264,6 +298,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
264 298
265 // Initialize this to a sane value to prevent early disconnects 299 // Initialize this to a sane value to prevent early disconnects
266 TickLastPacketReceived = Environment.TickCount & Int32.MaxValue; 300 TickLastPacketReceived = Environment.TickCount & Int32.MaxValue;
301 m_pingMS = (int)(3.0 * server.TickCountResolution); // so filter doesnt start at 0;
267 } 302 }
268 303
269 /// <summary> 304 /// <summary>
@@ -302,8 +337,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
302 m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate; 337 m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate;
303 m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate; 338 m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate;
304 m_info.totalThrottle = (int)m_throttleClient.DripRate; 339 m_info.totalThrottle = (int)m_throttleClient.DripRate;
340<<<<<<< HEAD
305 m_info.targetThrottle = (int)m_throttleClient.TargetDripRate; 341 m_info.targetThrottle = (int)m_throttleClient.TargetDripRate;
306 m_info.maxThrottle = (int)m_throttleClient.MaxDripRate; 342 m_info.maxThrottle = (int)m_throttleClient.MaxDripRate;
343=======
344>>>>>>> avn/ubitvar
307 345
308 return m_info; 346 return m_info;
309 } 347 }
@@ -389,6 +427,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
389 427
390 public void SetThrottles(byte[] throttleData) 428 public void SetThrottles(byte[] throttleData)
391 { 429 {
430 SetThrottles(throttleData, 1.0f);
431 }
432
433 public void SetThrottles(byte[] throttleData, float factor)
434 {
392 byte[] adjData; 435 byte[] adjData;
393 int pos = 0; 436 int pos = 0;
394 437
@@ -408,13 +451,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
408 } 451 }
409 452
410 // 0.125f converts from bits to bytes 453 // 0.125f converts from bits to bytes
411 int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 454 float scale = 0.125f * factor;
412 int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 455 int resend = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
413 int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 456 int land = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
414 int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 457 int wind = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
415 int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 458 int cloud = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
416 int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; 459 int task = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
417 int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); 460 int texture = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4;
461 int asset = (int)(BitConverter.ToSingle(adjData, pos) * scale);
418 462
419 if (ThrottleDebugLevel > 0) 463 if (ThrottleDebugLevel > 0)
420 { 464 {
@@ -426,6 +470,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
426 470
427 // Make sure none of the throttles are set below our packet MTU, 471 // Make sure none of the throttles are set below our packet MTU,
428 // otherwise a throttle could become permanently clogged 472 // otherwise a throttle could become permanently clogged
473
474/* not using floats
429 resend = Math.Max(resend, LLUDPServer.MTU); 475 resend = Math.Max(resend, LLUDPServer.MTU);
430 land = Math.Max(land, LLUDPServer.MTU); 476 land = Math.Max(land, LLUDPServer.MTU);
431 wind = Math.Max(wind, LLUDPServer.MTU); 477 wind = Math.Max(wind, LLUDPServer.MTU);
@@ -433,12 +479,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
433 task = Math.Max(task, LLUDPServer.MTU); 479 task = Math.Max(task, LLUDPServer.MTU);
434 texture = Math.Max(texture, LLUDPServer.MTU); 480 texture = Math.Max(texture, LLUDPServer.MTU);
435 asset = Math.Max(asset, LLUDPServer.MTU); 481 asset = Math.Max(asset, LLUDPServer.MTU);
482*/
436 483
437 // Since most textures are now delivered through http, make it possible 484 // Since most textures are now delivered through http, make it possible
438 // to cannibalize some of the bw from the texture throttle to use for 485 // to cannibalize some of the bw from the texture throttle to use for
439 // the task queue (e.g. object updates) 486 // the task queue (e.g. object updates)
440 task = task + (int)(m_cannibalrate * texture); 487 task = task + (int)(m_cannibalrate * texture);
441 texture = (int)((1 - m_cannibalrate) * texture); 488 texture = (int)((1 - m_cannibalrate) * texture);
489<<<<<<< HEAD
442 490
443 //int total = resend + land + wind + cloud + task + texture + asset; 491 //int total = resend + land + wind + cloud + task + texture + asset;
444 492
@@ -449,6 +497,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
449 "[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}", 497 "[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}",
450 AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total); 498 AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total);
451 } 499 }
500=======
501
502 int total = resend + land + wind + cloud + task + texture + asset;
503
504 float m_burst = total * m_burstTime;
505
506 //m_log.DebugFormat("[LLUDPCLIENT]: {0} is setting throttles. Resend={1}, Land={2}, Wind={3}, Cloud={4}, Task={5}, Texture={6}, Asset={7}, Total={8}",
507 // AgentID, resend, land, wind, cloud, task, texture, asset, total);
508>>>>>>> avn/ubitvar
452 509
453 // Update the token buckets with new throttle values 510 // Update the token buckets with new throttle values
454 if (m_throttleClient.AdaptiveEnabled) 511 if (m_throttleClient.AdaptiveEnabled)
@@ -461,24 +518,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
461 518
462 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend]; 519 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend];
463 bucket.RequestedDripRate = resend; 520 bucket.RequestedDripRate = resend;
521 bucket.RequestedBurst = m_burst;
464 522
465 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land]; 523 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land];
466 bucket.RequestedDripRate = land; 524 bucket.RequestedDripRate = land;
525 bucket.RequestedBurst = m_burst;
467 526
468 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind]; 527 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind];
469 bucket.RequestedDripRate = wind; 528 bucket.RequestedDripRate = wind;
529 bucket.RequestedBurst = m_burst;
470 530
471 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud]; 531 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud];
472 bucket.RequestedDripRate = cloud; 532 bucket.RequestedDripRate = cloud;
533 bucket.RequestedBurst = m_burst;
473 534
474 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset]; 535 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset];
475 bucket.RequestedDripRate = asset; 536 bucket.RequestedDripRate = asset;
537 bucket.RequestedBurst = m_burst;
476 538
477 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task]; 539 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task];
478 bucket.RequestedDripRate = task; 540 bucket.RequestedDripRate = task;
541 bucket.RequestedBurst = m_burst;
479 542
480 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture]; 543 bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture];
481 bucket.RequestedDripRate = texture; 544 bucket.RequestedDripRate = texture;
545 bucket.RequestedBurst = m_burst;
482 546
483 // Reset the packed throttles cached data 547 // Reset the packed throttles cached data
484 m_packedThrottles = null; 548 m_packedThrottles = null;
@@ -496,25 +560,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP
496 int i = 0; 560 int i = 0;
497 561
498 // multiply by 8 to convert bytes back to bits 562 // multiply by 8 to convert bytes back to bits
499 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Resend].RequestedDripRate * 8 * multiplier; 563 multiplier *= 8;
564
565 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Resend].RequestedDripRate * multiplier;
500 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 566 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
501 567
502 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Land].RequestedDripRate * 8 * multiplier; 568 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Land].RequestedDripRate * multiplier;
503 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 569 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
504 570
505 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Wind].RequestedDripRate * 8 * multiplier; 571 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Wind].RequestedDripRate * multiplier;
506 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 572 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
507 573
508 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Cloud].RequestedDripRate * 8 * multiplier; 574 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Cloud].RequestedDripRate * multiplier;
509 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 575 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
510 576
511 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Task].RequestedDripRate * 8 * multiplier; 577 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Task].RequestedDripRate * multiplier;
512 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 578 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
513 579
514 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Texture].RequestedDripRate * 8 * multiplier; 580 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Texture].RequestedDripRate * multiplier;
515 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 581 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
516 582
517 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Asset].RequestedDripRate * 8 * multiplier; 583 rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Asset].RequestedDripRate * multiplier;
518 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; 584 Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4;
519 585
520 m_packedThrottles = data; 586 m_packedThrottles = data;
@@ -523,6 +589,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
523 return data; 589 return data;
524 } 590 }
525 591
592 public int GetCatBytesInSendQueue(ThrottleOutPacketType cat)
593 {
594 ;
595 int icat = (int)cat;
596 if (icat > 0 && icat < THROTTLE_CATEGORY_COUNT)
597 {
598 TokenBucket bucket = m_throttleCategories[icat];
599 return m_packetOutboxes[icat].Count;
600 }
601 else
602 return 0;
603 }
604
605
606 public int GetCatBytesCanSend(ThrottleOutPacketType cat, int timeMS)
607 {
608 int icat = (int)cat;
609 if (icat > 0 && icat < THROTTLE_CATEGORY_COUNT)
610 {
611 TokenBucket bucket = m_throttleCategories[icat];
612 return bucket.GetCatBytesCanSend(timeMS);
613 }
614 else
615 return 0;
616 }
617
526 /// <summary> 618 /// <summary>
527 /// Queue an outgoing packet if appropriate. 619 /// Queue an outgoing packet if appropriate.
528 /// </summary> 620 /// </summary>
@@ -534,32 +626,41 @@ namespace OpenSim.Region.ClientStack.LindenUDP
534 /// </returns> 626 /// </returns>
535 public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue) 627 public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue)
536 { 628 {
629 return EnqueueOutgoing(packet, forceQueue, false);
630 }
631
632 public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue, bool highPriority)
633 {
537 int category = (int)packet.Category; 634 int category = (int)packet.Category;
538 635
539 if (category >= 0 && category < m_packetOutboxes.Length) 636 if (category >= 0 && category < m_packetOutboxes.Length)
540 { 637 {
541 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; 638 DoubleLocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category];
639
640 if (m_deliverPackets == false)
641 {
642 queue.Enqueue(packet, highPriority);
643 return true;
644 }
645
542 TokenBucket bucket = m_throttleCategories[category]; 646 TokenBucket bucket = m_throttleCategories[category];
543 647
544 // Don't send this packet if there is already a packet waiting in the queue 648 // Don't send this packet if queue is not empty
545 // even if we have the tokens to send it, tokens should go to the already 649 if (queue.Count > 0 || m_nextPackets[category] != null)
546 // queued packets
547 if (queue.Count > 0)
548 { 650 {
549 queue.Enqueue(packet); 651 queue.Enqueue(packet, highPriority);
550 return true; 652 return true;
551 } 653 }
552 654
553
554 if (!forceQueue && bucket.RemoveTokens(packet.Buffer.DataLength)) 655 if (!forceQueue && bucket.RemoveTokens(packet.Buffer.DataLength))
555 { 656 {
556 // Enough tokens were removed from the bucket, the packet will not be queued 657 // enough tokens so it can be sent imediatly by caller
557 return false; 658 return false;
558 } 659 }
559 else 660 else
560 { 661 {
561 // Force queue specified or not enough tokens in the bucket, queue this packet 662 // Force queue specified or not enough tokens in the bucket, queue this packet
562 queue.Enqueue(packet); 663 queue.Enqueue(packet, highPriority);
563 return true; 664 return true;
564 } 665 }
565 } 666 }
@@ -588,8 +689,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
588 /// <returns>True if any packets were sent, otherwise false</returns> 689 /// <returns>True if any packets were sent, otherwise false</returns>
589 public bool DequeueOutgoing() 690 public bool DequeueOutgoing()
590 { 691 {
591 OutgoingPacket packet; 692// if (m_deliverPackets == false) return false;
592 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue; 693
694 OutgoingPacket packet = null;
695 DoubleLocklessQueue<OutgoingPacket> queue;
593 TokenBucket bucket; 696 TokenBucket bucket;
594 bool packetSent = false; 697 bool packetSent = false;
595 ThrottleOutPacketTypeFlags emptyCategories = 0; 698 ThrottleOutPacketTypeFlags emptyCategories = 0;
@@ -613,6 +716,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
613 m_udpServer.SendPacketFinal(nextPacket); 716 m_udpServer.SendPacketFinal(nextPacket);
614 m_nextPackets[i] = null; 717 m_nextPackets[i] = null;
615 packetSent = true; 718 packetSent = true;
719
720 if (m_packetOutboxes[i].Count < 5)
721 emptyCategories |= CategoryToFlag(i);
616 } 722 }
617 } 723 }
618 else 724 else
@@ -620,32 +726,47 @@ namespace OpenSim.Region.ClientStack.LindenUDP
620 // No dequeued packet waiting to be sent, try to pull one off 726 // No dequeued packet waiting to be sent, try to pull one off
621 // this queue 727 // this queue
622 queue = m_packetOutboxes[i]; 728 queue = m_packetOutboxes[i];
623 if (queue.Dequeue(out packet)) 729 if (queue != null)
624 { 730 {
625 // A packet was pulled off the queue. See if we have 731 bool success = false;
626 // enough tokens in the bucket to send it out 732 try
627 if (bucket.RemoveTokens(packet.Buffer.DataLength))
628 { 733 {
629 // Send the packet 734 success = queue.Dequeue(out packet);
630 m_udpServer.SendPacketFinal(packet);
631 packetSent = true;
632 } 735 }
633 else 736 catch
634 { 737 {
635 // Save the dequeued packet for the next iteration 738 m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>();
636 m_nextPackets[i] = packet;
637 } 739 }
740 if (success)
741 {
742 // A packet was pulled off the queue. See if we have
743 // enough tokens in the bucket to send it out
744 if (bucket.RemoveTokens(packet.Buffer.DataLength))
745 {
746 // Send the packet
747 m_udpServer.SendPacketFinal(packet);
748 packetSent = true;
749
750 if (queue.Count < 5)
751 emptyCategories |= CategoryToFlag(i);
752 }
753 else
754 {
755 // Save the dequeued packet for the next iteration
756 m_nextPackets[i] = packet;
757 }
638 758
639 // If the queue is empty after this dequeue, fire the queue 759 }
640 // empty callback now so it has a chance to fill before we 760 else
641 // get back here 761 {
642 if (queue.Count == 0) 762 // No packets in this queue. Fire the queue empty callback
763 // if it has not been called recently
643 emptyCategories |= CategoryToFlag(i); 764 emptyCategories |= CategoryToFlag(i);
765 }
644 } 766 }
645 else 767 else
646 { 768 {
647 // No packets in this queue. Fire the queue empty callback 769 m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>();
648 // if it has not been called recently
649 emptyCategories |= CategoryToFlag(i); 770 emptyCategories |= CategoryToFlag(i);
650 } 771 }
651 } 772 }
@@ -712,6 +833,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
712 RTO = Math.Min(RTO * 2, m_maxRTO); 833 RTO = Math.Min(RTO * 2, m_maxRTO);
713 } 834 }
714 835
836
837 const int MIN_CALLBACK_MS = 10;
838
715 /// <summary> 839 /// <summary>
716 /// Does an early check to see if this queue empty callback is already 840 /// Does an early check to see if this queue empty callback is already
717 /// running, then asynchronously firing the event 841 /// running, then asynchronously firing the event
@@ -719,24 +843,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
719 /// <param name="categories">Throttle categories to fire the callback for</param> 843 /// <param name="categories">Throttle categories to fire the callback for</param>
720 private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories) 844 private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories)
721 { 845 {
722// if (m_nextOnQueueEmpty != 0 && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty) 846 if (!m_isQueueEmptyRunning)
723 if (!m_isQueueEmptyRunning && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty)
724 { 847 {
725 m_isQueueEmptyRunning = true;
726
727 int start = Environment.TickCount & Int32.MaxValue; 848 int start = Environment.TickCount & Int32.MaxValue;
728 const int MIN_CALLBACK_MS = 30; 849
850 if (start < m_nextOnQueueEmpty)
851 return;
852
853 m_isQueueEmptyRunning = true;
729 854
730 m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; 855 m_nextOnQueueEmpty = start + MIN_CALLBACK_MS;
731 if (m_nextOnQueueEmpty == 0) 856 if (m_nextOnQueueEmpty == 0)
732 m_nextOnQueueEmpty = 1; 857 m_nextOnQueueEmpty = 1;
733 858
734 // Use a value of 0 to signal that FireQueueEmpty is running 859 if (HasUpdates(categories))
735// m_nextOnQueueEmpty = 0;
736
737 m_categories = categories;
738
739 if (HasUpdates(m_categories))
740 { 860 {
741 if (!m_udpServer.OqrEngine.IsRunning) 861 if (!m_udpServer.OqrEngine.IsRunning)
742 { 862 {
@@ -756,7 +876,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
756 } 876 }
757 877
758 private bool m_isQueueEmptyRunning; 878 private bool m_isQueueEmptyRunning;
759 private ThrottleOutPacketTypeFlags m_categories = 0; 879
760 880
761 /// <summary> 881 /// <summary>
762 /// Fires the OnQueueEmpty callback and sets the minimum time that it 882 /// Fires the OnQueueEmpty callback and sets the minimum time that it
@@ -767,6 +887,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
767 /// signature</param> 887 /// signature</param>
768 public void FireQueueEmpty(object o) 888 public void FireQueueEmpty(object o)
769 { 889 {
890<<<<<<< HEAD
770// m_log.DebugFormat("[LLUDPCLIENT]: FireQueueEmpty for {0} in {1}", AgentID, m_udpServer.Scene.Name); 891// m_log.DebugFormat("[LLUDPCLIENT]: FireQueueEmpty for {0} in {1}", AgentID, m_udpServer.Scene.Name);
771 892
772// int start = Environment.TickCount & Int32.MaxValue; 893// int start = Environment.TickCount & Int32.MaxValue;
@@ -776,24 +897,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP
776// { 897// {
777 ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; 898 ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o;
778 QueueEmpty callback = OnQueueEmpty; 899 QueueEmpty callback = OnQueueEmpty;
900=======
901 ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o;
902 QueueEmpty callback = OnQueueEmpty;
903>>>>>>> avn/ubitvar
779 904
780 if (callback != null) 905 if (callback != null)
781 { 906 {
782// if (m_udpServer.IsRunningOutbound) 907 // if (m_udpServer.IsRunningOutbound)
783// { 908 // {
784 try { callback(categories); } 909 try { callback(categories); }
785 catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } 910 catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); }
786// } 911 // }
787 } 912 }
788// }
789 913
790// m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; 914 m_isQueueEmptyRunning = false;
791// if (m_nextOnQueueEmpty == 0) 915 }
792// m_nextOnQueueEmpty = 1;
793 916
794// } 917 internal void ForceThrottleSetting(int throttle, int setting)
918 {
919 if (throttle > 0 && throttle < THROTTLE_CATEGORY_COUNT)
920 m_throttleCategories[throttle].RequestedDripRate = Math.Max(setting, LLUDPServer.MTU);
921 }
795 922
796 m_isQueueEmptyRunning = false; 923 internal int GetThrottleSetting(int throttle)
924 {
925 if (throttle > 0 && throttle < THROTTLE_CATEGORY_COUNT)
926 return (int)m_throttleCategories[throttle].RequestedDripRate;
927 else
928 return 0;
797 } 929 }
798 930
799 /// <summary> 931 /// <summary>
@@ -839,4 +971,33 @@ namespace OpenSim.Region.ClientStack.LindenUDP
839 } 971 }
840 } 972 }
841 } 973 }
974
975 public class DoubleLocklessQueue<T> : OpenSim.Framework.LocklessQueue<T>
976 {
977 OpenSim.Framework.LocklessQueue<T> highQueue = new OpenSim.Framework.LocklessQueue<T>();
978
979 public override int Count
980 {
981 get
982 {
983 return base.Count + highQueue.Count;
984 }
985 }
986
987 public override bool Dequeue(out T item)
988 {
989 if (highQueue.Dequeue(out item))
990 return true;
991
992 return base.Dequeue(out item);
993 }
994
995 public void Enqueue(T item, bool highPriority)
996 {
997 if (highPriority)
998 highQueue.Enqueue(item);
999 else
1000 Enqueue(item);
1001 }
1002 }
842} 1003}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index 76be91a..41e19fd 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -241,7 +241,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
241 /// <summary>Handlers for incoming packets</summary> 241 /// <summary>Handlers for incoming packets</summary>
242 //PacketEventDictionary packetEvents = new PacketEventDictionary(); 242 //PacketEventDictionary packetEvents = new PacketEventDictionary();
243 /// <summary>Incoming packets that are awaiting handling</summary> 243 /// <summary>Incoming packets that are awaiting handling</summary>
244 private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); 244 //private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>();
245
246 private DoubleQueue<IncomingPacket> packetInbox = new DoubleQueue<IncomingPacket>();
245 247
246 /// <summary>Bandwidth throttle for this UDP server</summary> 248 /// <summary>Bandwidth throttle for this UDP server</summary>
247 public TokenBucket Throttle { get; private set; } 249 public TokenBucket Throttle { get; private set; }
@@ -299,14 +301,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
299 /// <summary>Flag to signal when clients should send pings</summary> 301 /// <summary>Flag to signal when clients should send pings</summary>
300 protected bool m_sendPing; 302 protected bool m_sendPing;
301 303
304 private int m_animationSequenceNumber;
305
306 public int NextAnimationSequenceNumber
307 {
308 get
309 {
310 m_animationSequenceNumber++;
311 if (m_animationSequenceNumber > 2147482624)
312 m_animationSequenceNumber = 1;
313 return m_animationSequenceNumber;
314 }
315 }
316
317
318
319 private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>();
320
302 /// <summary> 321 /// <summary>
303 /// Event used to signal when queued packets are available for sending. 322 /// Event used to signal when queued packets are available for sending.
304 /// </summary> 323 /// </summary>
305 /// <remarks> 324 /// <remarks>
306 /// This allows the outbound loop to only operate when there is data to send rather than continuously polling. 325 /// This allows the outbound loop to only operate when there is data to send rather than continuously polling.
307 /// Some data is sent immediately and not queued. That data would not trigger this event. 326 /// Some data is sent immediately and not queued. That data would not trigger this event.
327 /// WRONG use. May be usefull in future revision
308 /// </remarks> 328 /// </remarks>
309 private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); 329// private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false);
310 330
311 private Pool<IncomingPacket> m_incomingPacketPool; 331 private Pool<IncomingPacket> m_incomingPacketPool;
312 332
@@ -388,16 +408,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
388 408
389 // Measure the resolution of Environment.TickCount 409 // Measure the resolution of Environment.TickCount
390 TickCountResolution = 0f; 410 TickCountResolution = 0f;
391 for (int i = 0; i < 5; i++) 411 for (int i = 0; i < 10; i++)
392 { 412 {
393 int start = Environment.TickCount; 413 int start = Environment.TickCount;
394 int now = start; 414 int now = start;
395 while (now == start) 415 while (now == start)
396 now = Environment.TickCount; 416 now = Environment.TickCount;
397 TickCountResolution += (float)(now - start) * 0.2f; 417 TickCountResolution += (float)(now - start) * 0.1f;
398 } 418 }
399 m_log.Info("[LLUDPSERVER]: Average Environment.TickCount resolution: " + TickCountResolution + "ms");
400 TickCountResolution = (float)Math.Ceiling(TickCountResolution); 419 TickCountResolution = (float)Math.Ceiling(TickCountResolution);
420 m_log.Info("[LLUDPSERVER]: Average Environment.TickCount resolution: " + TickCountResolution + "ms");
401 421
402 #endregion Environment.TickCount Measurement 422 #endregion Environment.TickCount Measurement
403 423
@@ -405,6 +425,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
405 int sceneThrottleBps = 0; 425 int sceneThrottleBps = 0;
406 bool usePools = false; 426 bool usePools = false;
407 427
428
429
408 IConfig config = configSource.Configs["ClientStack.LindenUDP"]; 430 IConfig config = configSource.Configs["ClientStack.LindenUDP"];
409 if (config != null) 431 if (config != null)
410 { 432 {
@@ -451,6 +473,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
451 } 473 }
452 #endregion BinaryStats 474 #endregion BinaryStats
453 475
476<<<<<<< HEAD
454 // FIXME: Can't add info here because don't know scene yet. 477 // FIXME: Can't add info here because don't know scene yet.
455// m_throttle 478// m_throttle
456// = new TokenBucket( 479// = new TokenBucket(
@@ -458,8 +481,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
458 481
459 Throttle = new TokenBucket("server throttle bucket", null, 0, sceneThrottleBps); 482 Throttle = new TokenBucket("server throttle bucket", null, 0, sceneThrottleBps);
460 483
484=======
485 m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps * 10e-3f);
486>>>>>>> avn/ubitvar
461 ThrottleRates = new ThrottleRates(configSource); 487 ThrottleRates = new ThrottleRates(configSource);
462 488
489 Random rnd = new Random(Util.EnvironmentTickCount());
490 m_animationSequenceNumber = rnd.Next(11474826);
491
463 if (usePools) 492 if (usePools)
464 EnablePools(); 493 EnablePools();
465 } 494 }
@@ -755,8 +784,151 @@ namespace OpenSim.Region.ClientStack.LindenUDP
755 if (UsePools) 784 if (UsePools)
756 EnablePoolStats(); 785 EnablePoolStats();
757 786
787<<<<<<< HEAD
758 LLUDPServerCommands commands = new LLUDPServerCommands(MainConsole.Instance, this); 788 LLUDPServerCommands commands = new LLUDPServerCommands(MainConsole.Instance, this);
759 commands.Register(); 789 commands.Register();
790=======
791 MainConsole.Instance.Commands.AddCommand(
792 "Debug", false, "debug lludp packet",
793 "debug lludp packet [--default] <level> [<avatar-first-name> <avatar-last-name>]",
794 "Turn on packet debugging",
795 "If level > 255 then all incoming and outgoing packets are logged.\n"
796 + "If level <= 255 then incoming AgentUpdate and outgoing SimStats and SimulatorViewerTimeMessage packets are not logged.\n"
797 + "If level <= 200 then incoming RequestImage and outgoing ImagePacket, ImageData, LayerData and CoarseLocationUpdate packets are not logged.\n"
798 + "If level <= 100 then incoming ViewerEffect and AgentAnimation and outgoing ViewerEffect and AvatarAnimation packets are not logged.\n"
799 + "If level <= 50 then outgoing ImprovedTerseObjectUpdate packets are not logged.\n"
800 + "If level <= 0 then no packets are logged.\n"
801 + "If --default is specified then the level becomes the default logging level for all subsequent agents.\n"
802 + "In this case, you cannot also specify an avatar name.\n"
803 + "If an avatar name is given then only packets from that avatar are logged.",
804 HandlePacketCommand);
805
806 MainConsole.Instance.Commands.AddCommand(
807 "Debug",
808 false,
809 "debug lludp start",
810 "debug lludp start <in|out|all>",
811 "Control LLUDP packet processing.",
812 "No effect if packet processing has already started.\n"
813 + "in - start inbound processing.\n"
814 + "out - start outbound processing.\n"
815 + "all - start in and outbound processing.\n",
816 HandleStartCommand);
817
818 MainConsole.Instance.Commands.AddCommand(
819 "Debug",
820 false,
821 "debug lludp stop",
822 "debug lludp stop <in|out|all>",
823 "Stop LLUDP packet processing.",
824 "No effect if packet processing has already stopped.\n"
825 + "in - stop inbound processing.\n"
826 + "out - stop outbound processing.\n"
827 + "all - stop in and outbound processing.\n",
828 HandleStopCommand);
829
830 MainConsole.Instance.Commands.AddCommand(
831 "Debug",
832 false,
833 "debug lludp pool",
834 "debug lludp pool <on|off>",
835 "Turn object pooling within the lludp component on or off.",
836 HandlePoolCommand);
837
838 MainConsole.Instance.Commands.AddCommand(
839 "Debug",
840 false,
841 "debug lludp status",
842 "debug lludp status",
843 "Return status of LLUDP packet processing.",
844 HandleStatusCommand);
845/* disabled
846 MainConsole.Instance.Commands.AddCommand(
847 "Debug",
848 false,
849 "debug lludp toggle agentupdate",
850 "debug lludp toggle agentupdate",
851 "Toggle whether agentupdate packets are processed or simply discarded.",
852 HandleAgentUpdateCommand);
853 */
854 }
855
856 private void HandlePacketCommand(string module, string[] args)
857 {
858 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
859 return;
860
861 bool setAsDefaultLevel = false;
862 OptionSet optionSet = new OptionSet().Add("default", o => setAsDefaultLevel = o != null);
863 List<string> filteredArgs = optionSet.Parse(args);
864
865 string name = null;
866
867 if (filteredArgs.Count == 6)
868 {
869 if (!setAsDefaultLevel)
870 {
871 name = string.Format("{0} {1}", filteredArgs[4], filteredArgs[5]);
872 }
873 else
874 {
875 MainConsole.Instance.OutputFormat("ERROR: Cannot specify a user name when setting default logging level");
876 return;
877 }
878 }
879
880 if (filteredArgs.Count > 3)
881 {
882 int newDebug;
883 if (int.TryParse(filteredArgs[3], out newDebug))
884 {
885 if (setAsDefaultLevel)
886 {
887 DefaultClientPacketDebugLevel = newDebug;
888 MainConsole.Instance.OutputFormat(
889 "Debug packet debug for new clients set to {0} in {1}", DefaultClientPacketDebugLevel, m_scene.Name);
890 }
891 else
892 {
893 m_scene.ForEachScenePresence(sp =>
894 {
895 if (name == null || sp.Name == name)
896 {
897 MainConsole.Instance.OutputFormat(
898 "Packet debug for {0} ({1}) set to {2} in {3}",
899 sp.Name, sp.IsChildAgent ? "child" : "root", newDebug, m_scene.Name);
900
901 sp.ControllingClient.DebugPacketLevel = newDebug;
902 }
903 });
904 }
905 }
906 else
907 {
908 MainConsole.Instance.Output("Usage: debug lludp packet [--default] 0..255 [<first-name> <last-name>]");
909 }
910 }
911 }
912
913 private void HandleStartCommand(string module, string[] args)
914 {
915 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
916 return;
917
918 if (args.Length != 4)
919 {
920 MainConsole.Instance.Output("Usage: debug lludp start <in|out|all>");
921 return;
922 }
923
924 string subCommand = args[3];
925
926 if (subCommand == "in" || subCommand == "all")
927 StartInbound();
928
929 if (subCommand == "out" || subCommand == "all")
930 StartOutbound();
931>>>>>>> avn/ubitvar
760 } 932 }
761 933
762 public bool HandlesRegion(Location x) 934 public bool HandlesRegion(Location x)
@@ -864,8 +1036,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
864 1036
865 PacketPool.Instance.ReturnPacket(packet); 1037 PacketPool.Instance.ReturnPacket(packet);
866 1038
867 if (packetQueued) 1039 /// WRONG use. May be usefull in future revision
868 m_dataPresentEvent.Set(); 1040// if (packetQueued)
1041// m_dataPresentEvent.Set();
869 } 1042 }
870 1043
871 /// <summary> 1044 /// <summary>
@@ -936,6 +1109,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
936 1109
937 #region Queue or Send 1110 #region Queue or Send
938 1111
1112 bool highPriority = false;
1113
1114 if (category != ThrottleOutPacketType.Unknown && (category & ThrottleOutPacketType.HighPriority) != 0)
1115 {
1116 category = (ThrottleOutPacketType)((int)category & 127);
1117 highPriority = true;
1118 }
1119
939 OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null); 1120 OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null);
940 1121
941 // If we were not provided a method for handling unacked, use the UDPServer default method 1122 // If we were not provided a method for handling unacked, use the UDPServer default method
@@ -945,6 +1126,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
945 // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will 1126 // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will
946 // continue to display the deleted object until relog. Therefore, we need to always queue a kill object 1127 // continue to display the deleted object until relog. Therefore, we need to always queue a kill object
947 // packet so that it isn't sent before a queued update packet. 1128 // packet so that it isn't sent before a queued update packet.
1129<<<<<<< HEAD
948 bool forceQueue = (type == PacketType.KillObject); 1130 bool forceQueue = (type == PacketType.KillObject);
949 1131
950// if (type == PacketType.ImprovedTerseObjectUpdate) 1132// if (type == PacketType.ImprovedTerseObjectUpdate)
@@ -956,15 +1138,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
956// else 1138// else
957// { 1139// {
958 if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, forceQueue)) 1140 if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, forceQueue))
1141=======
1142 bool requestQueue = type == PacketType.KillObject;
1143 if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, requestQueue, highPriority))
1144>>>>>>> avn/ubitvar
959 { 1145 {
960 SendPacketFinal(outgoingPacket); 1146 SendPacketFinal(outgoingPacket);
961 return true; 1147 return true;
962 } 1148 }
1149<<<<<<< HEAD
963 else 1150 else
964 { 1151 {
965 return false; 1152 return false;
966 } 1153 }
967// } 1154// }
1155=======
1156
1157 return false;
1158>>>>>>> avn/ubitvar
968 1159
969 #endregion Queue or Send 1160 #endregion Queue or Send
970 } 1161 }
@@ -1005,6 +1196,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1005 pc.PingID.OldestUnacked = 0; 1196 pc.PingID.OldestUnacked = 0;
1006 1197
1007 SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false, null); 1198 SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false, null);
1199 udpClient.m_lastStartpingTimeMS = Util.EnvironmentTickCount();
1008 } 1200 }
1009 1201
1010 public void CompletePing(LLUDPClient udpClient, byte pingID) 1202 public void CompletePing(LLUDPClient udpClient, byte pingID)
@@ -1102,7 +1294,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1102 int dataLength = buffer.DataLength; 1294 int dataLength = buffer.DataLength;
1103 1295
1104 // NOTE: I'm seeing problems with some viewers when ACKs are appended to zerocoded packets so I've disabled that here 1296 // NOTE: I'm seeing problems with some viewers when ACKs are appended to zerocoded packets so I've disabled that here
1105 if (!isZerocoded) 1297 if (!isZerocoded && !isResend && outgoingPacket.UnackedMethod == null)
1106 { 1298 {
1107 // Keep appending ACKs until there is no room left in the buffer or there are 1299 // Keep appending ACKs until there is no room left in the buffer or there are
1108 // no more ACKs to append 1300 // no more ACKs to append
@@ -1268,35 +1460,76 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1268 1460
1269 #region Packet to Client Mapping 1461 #region Packet to Client Mapping
1270 1462
1271 // UseCircuitCode handling 1463 // If there is already a client for this endpoint, don't process UseCircuitCode
1272 if (packet.Type == PacketType.UseCircuitCode) 1464 IClientAPI client = null;
1465 if (!m_scene.TryGetClient(endPoint, out client) || !(client is LLClientView))
1273 { 1466 {
1274 // We need to copy the endpoint so that it doesn't get changed when another thread reuses the 1467 // UseCircuitCode handling
1275 // buffer. 1468 if (packet.Type == PacketType.UseCircuitCode)
1276 object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; 1469 {
1470 // And if there is a UseCircuitCode pending, also drop it
1471 lock (m_pendingCache)
1472 {
1473 if (m_pendingCache.Contains(endPoint))
1474 return;
1277 1475
1476<<<<<<< HEAD
1278 Util.FireAndForget(HandleUseCircuitCode, array, "LLUDPServer.HandleUseCircuitCode"); 1477 Util.FireAndForget(HandleUseCircuitCode, array, "LLUDPServer.HandleUseCircuitCode");
1478=======
1479 m_pendingCache.AddOrUpdate(endPoint, new Queue<UDPPacketBuffer>(), 60);
1480 }
1481>>>>>>> avn/ubitvar
1279 1482
1280 return; 1483 // We need to copy the endpoint so that it doesn't get changed when another thread reuses the
1484 // buffer.
1485 object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet };
1486
1487 Util.FireAndForget(HandleUseCircuitCode, array);
1488
1489 return;
1490 }
1281 } 1491 }
1282 else if (packet.Type == PacketType.CompleteAgentMovement) 1492
1493 // If this is a pending connection, enqueue, don't process yet
1494 lock (m_pendingCache)
1283 { 1495 {
1284 // Send ack straight away to let the viewer know that we got it. 1496 Queue<UDPPacketBuffer> queue;
1285 SendAckImmediate(endPoint, packet.Header.Sequence); 1497 if (m_pendingCache.TryGetValue(endPoint, out queue))
1498 {
1499 //m_log.DebugFormat("[LLUDPSERVER]: Enqueued a {0} packet into the pending queue", packet.Type);
1500 queue.Enqueue(buffer);
1501 return;
1502 }
1286 1503
1287 // We need to copy the endpoint so that it doesn't get changed when another thread reuses the 1504/*
1288 // buffer. 1505 else if (packet.Type == PacketType.CompleteAgentMovement)
1289 object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; 1506 {
1507 // Send ack straight away to let the viewer know that we got it.
1508 SendAckImmediate(endPoint, packet.Header.Sequence);
1290 1509
1510<<<<<<< HEAD
1291 Util.FireAndForget( 1511 Util.FireAndForget(
1292 HandleCompleteMovementIntoRegion, array, "LLUDPServer.HandleCompleteMovementIntoRegion"); 1512 HandleCompleteMovementIntoRegion, array, "LLUDPServer.HandleCompleteMovementIntoRegion");
1513=======
1514 // We need to copy the endpoint so that it doesn't get changed when another thread reuses the
1515 // buffer.
1516 object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet };
1517>>>>>>> avn/ubitvar
1293 1518
1294 return; 1519 Util.FireAndForget(HandleCompleteMovementIntoRegion, array);
1520
1521 return;
1522 }
1523 */
1295 } 1524 }
1296 1525
1297 // Determine which agent this packet came from 1526 // Determine which agent this packet came from
1527<<<<<<< HEAD
1298 IClientAPI client; 1528 IClientAPI client;
1299 if (!Scene.TryGetClient(endPoint, out client) || !(client is LLClientView)) 1529 if (!Scene.TryGetClient(endPoint, out client) || !(client is LLClientView))
1530=======
1531 if (client == null || !(client is LLClientView))
1532>>>>>>> avn/ubitvar
1300 { 1533 {
1301 //m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName); 1534 //m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName);
1302 1535
@@ -1313,7 +1546,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1313 udpClient = ((LLClientView)client).UDPClient; 1546 udpClient = ((LLClientView)client).UDPClient;
1314 1547
1315 if (!udpClient.IsConnected) 1548 if (!udpClient.IsConnected)
1549 {
1550 m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet for a unConnected client in " + m_scene.RegionInfo.RegionName);
1316 return; 1551 return;
1552 }
1317 1553
1318 #endregion Packet to Client Mapping 1554 #endregion Packet to Client Mapping
1319 1555
@@ -1416,6 +1652,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1416 LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); 1652 LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length);
1417 #endregion BinaryStats 1653 #endregion BinaryStats
1418 1654
1655<<<<<<< HEAD
1419 if (packet.Type == PacketType.AgentUpdate) 1656 if (packet.Type == PacketType.AgentUpdate)
1420 { 1657 {
1421 if (DiscardInboundAgentUpdates) 1658 if (DiscardInboundAgentUpdates)
@@ -1434,6 +1671,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1434 return; 1671 return;
1435 } 1672 }
1436 } 1673 }
1674=======
1675// AgentUpdate mess removed from here
1676>>>>>>> avn/ubitvar
1437 1677
1438 #region Ping Check Handling 1678 #region Ping Check Handling
1439 1679
@@ -1444,7 +1684,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1444 // We don't need to do anything else with ping checks 1684 // We don't need to do anything else with ping checks
1445 StartPingCheckPacket startPing = (StartPingCheckPacket)packet; 1685 StartPingCheckPacket startPing = (StartPingCheckPacket)packet;
1446 CompletePing(udpClient, startPing.PingID.PingID); 1686 CompletePing(udpClient, startPing.PingID.PingID);
1447 1687
1448 if ((Environment.TickCount - m_elapsedMSSinceLastStatReport) >= 3000) 1688 if ((Environment.TickCount - m_elapsedMSSinceLastStatReport) >= 3000)
1449 { 1689 {
1450 udpClient.SendPacketStats(); 1690 udpClient.SendPacketStats();
@@ -1454,7 +1694,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1454 } 1694 }
1455 else if (packet.Type == PacketType.CompletePingCheck) 1695 else if (packet.Type == PacketType.CompletePingCheck)
1456 { 1696 {
1457 // We don't currently track client ping times 1697 int t = Util.EnvironmentTickCountSubtract(udpClient.m_lastStartpingTimeMS);
1698 int c = udpClient.m_pingMS;
1699 c = 800 * c + 200 * t;
1700 c /= 1000;
1701 udpClient.m_pingMS = c;
1458 return; 1702 return;
1459 } 1703 }
1460 1704
@@ -1474,7 +1718,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1474 incomingPacket = new IncomingPacket((LLClientView)client, packet); 1718 incomingPacket = new IncomingPacket((LLClientView)client, packet);
1475 } 1719 }
1476 1720
1477 packetInbox.Enqueue(incomingPacket); 1721// if (incomingPacket.Packet.Type == PacketType.AgentUpdate ||
1722// incomingPacket.Packet.Type == PacketType.ChatFromViewer)
1723 if (incomingPacket.Packet.Type == PacketType.ChatFromViewer)
1724 packetInbox.EnqueueHigh(incomingPacket);
1725 else
1726 packetInbox.EnqueueLow(incomingPacket);
1727
1478 } 1728 }
1479 1729
1480 #region BinaryStats 1730 #region BinaryStats
@@ -1591,7 +1841,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1591 1841
1592 try 1842 try
1593 { 1843 {
1594 // DateTime startTime = DateTime.Now; 1844// DateTime startTime = DateTime.Now;
1595 object[] array = (object[])o; 1845 object[] array = (object[])o;
1596 endPoint = (IPEndPoint)array[0]; 1846 endPoint = (IPEndPoint)array[0];
1597 UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; 1847 UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1];
@@ -1603,6 +1853,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1603 AuthenticateResponse sessionInfo; 1853 AuthenticateResponse sessionInfo;
1604 if (IsClientAuthorized(uccp, out sessionInfo)) 1854 if (IsClientAuthorized(uccp, out sessionInfo))
1605 { 1855 {
1856 AgentCircuitData aCircuit = m_scene.AuthenticateHandler.GetAgentCircuitData(uccp.CircuitCode.Code);
1857
1606 // Begin the process of adding the client to the simulator 1858 // Begin the process of adding the client to the simulator
1607 client 1859 client
1608 = AddClient( 1860 = AddClient(
@@ -1611,16 +1863,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1611 uccp.CircuitCode.SessionID, 1863 uccp.CircuitCode.SessionID,
1612 endPoint, 1864 endPoint,
1613 sessionInfo); 1865 sessionInfo);
1614 1866
1867 // This will be true if the client is new, e.g. not
1868 // an existing child agent, and there is no circuit data
1869 if (client != null && aCircuit == null)
1870 {
1871 m_scene.CloseAgent(client.AgentId, true);
1872 return;
1873 }
1874
1875 // Now we know we can handle more data
1876 Thread.Sleep(200);
1877
1878 // Obtain the pending queue and remove it from the cache
1879 Queue<UDPPacketBuffer> queue = null;
1880
1881 lock (m_pendingCache)
1882 {
1883 if (!m_pendingCache.TryGetValue(endPoint, out queue))
1884 {
1885 m_log.DebugFormat("[LLUDPSERVER]: Client created but no pending queue present");
1886 return;
1887
1888 }
1889 m_pendingCache.Remove(endPoint);
1890 }
1891
1892 m_log.DebugFormat("[LLUDPSERVER]: Client created, processing pending queue, {0} entries", queue.Count);
1893
1894 // Reinject queued packets
1895 while (queue.Count > 0)
1896 {
1897 UDPPacketBuffer buf = queue.Dequeue();
1898 PacketReceived(buf);
1899 }
1900
1901 queue = null;
1902
1615 // Send ack straight away to let the viewer know that the connection is active. 1903 // Send ack straight away to let the viewer know that the connection is active.
1616 // The client will be null if it already exists (e.g. if on a region crossing the client sends a use 1904 // The client will be null if it already exists (e.g. if on a region crossing the client sends a use
1617 // circuit code to the existing child agent. This is not particularly obvious. 1905 // circuit code to the existing child agent. This is not particularly obvious.
1618 SendAckImmediate(endPoint, uccp.Header.Sequence); 1906 SendAckImmediate(endPoint, uccp.Header.Sequence);
1619 1907
1620 // We only want to send initial data to new clients, not ones which are being converted from child to root. 1908 // We only want to send initial data to new clients, not ones which are being converted from child to root.
1621 if (client != null) 1909 if (client != null)
1622 { 1910 {
1911<<<<<<< HEAD
1623 AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(uccp.CircuitCode.Code); 1912 AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(uccp.CircuitCode.Code);
1913=======
1914>>>>>>> avn/ubitvar
1624 bool tp = (aCircuit.teleportFlags > 0); 1915 bool tp = (aCircuit.teleportFlags > 0);
1625 // Let's delay this for TP agents, otherwise the viewer doesn't know where to get resources from 1916 // Let's delay this for TP agents, otherwise the viewer doesn't know where to get resources from
1626 if (!tp && !client.SceneAgent.SentInitialDataToClient) 1917 if (!tp && !client.SceneAgent.SentInitialDataToClient)
@@ -1632,9 +1923,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1632 // Don't create clients for unauthorized requesters. 1923 // Don't create clients for unauthorized requesters.
1633 m_log.WarnFormat( 1924 m_log.WarnFormat(
1634 "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}", 1925 "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}",
1926<<<<<<< HEAD
1635 uccp.CircuitCode.ID, Scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint); 1927 uccp.CircuitCode.ID, Scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint);
1636 } 1928 }
1637 1929
1930=======
1931 uccp.CircuitCode.ID, m_scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint);
1932
1933 lock (m_pendingCache)
1934 m_pendingCache.Remove(endPoint);
1935 }
1936>>>>>>> avn/ubitvar
1638 // m_log.DebugFormat( 1937 // m_log.DebugFormat(
1639 // "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms", 1938 // "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms",
1640 // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); 1939 // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds);
@@ -1651,8 +1950,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1651 e.StackTrace); 1950 e.StackTrace);
1652 } 1951 }
1653 } 1952 }
1654 1953/*
1655 private void HandleCompleteMovementIntoRegion(object o) 1954 private void HandleCompleteMovementIntoRegion(object o)
1656 { 1955 {
1657 IPEndPoint endPoint = null; 1956 IPEndPoint endPoint = null;
1658 IClientAPI client = null; 1957 IClientAPI client = null;
@@ -1761,6 +2060,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1761 e.StackTrace); 2060 e.StackTrace);
1762 } 2061 }
1763 } 2062 }
2063*/
1764 2064
1765 /// <summary> 2065 /// <summary>
1766 /// Send an ack immediately to the given endpoint. 2066 /// Send an ack immediately to the given endpoint.
@@ -1818,6 +2118,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1818 uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) 2118 uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo)
1819 { 2119 {
1820 IClientAPI client = null; 2120 IClientAPI client = null;
2121 bool createNew = false;
1821 2122
1822 // We currently synchronize this code across the whole scene to avoid issues such as 2123 // We currently synchronize this code across the whole scene to avoid issues such as
1823 // http://opensimulator.org/mantis/view.php?id=5365 However, once locking per agent circuit can be done 2124 // http://opensimulator.org/mantis/view.php?id=5365 However, once locking per agent circuit can be done
@@ -1826,7 +2127,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1826 { 2127 {
1827 if (!Scene.TryGetClient(agentID, out client)) 2128 if (!Scene.TryGetClient(agentID, out client))
1828 { 2129 {
2130<<<<<<< HEAD
1829 LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, Throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO); 2131 LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, Throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO);
2132=======
2133 createNew = true;
2134 }
2135 else
2136 {
2137 if (client.SceneAgent == null)
2138 {
2139 m_scene.CloseAgent(agentID, true);
2140 createNew = true;
2141 }
2142 }
2143
2144 if (createNew)
2145 {
2146 LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, m_throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO);
2147>>>>>>> avn/ubitvar
1830 2148
1831 client = new LLClientView(Scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); 2149 client = new LLClientView(Scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode);
1832 client.OnLogout += LogoutHandler; 2150 client.OnLogout += LogoutHandler;
@@ -1856,15 +2174,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1856 { 2174 {
1857 ClientLogoutsDueToNoReceives++; 2175 ClientLogoutsDueToNoReceives++;
1858 2176
2177<<<<<<< HEAD
1859 m_log.WarnFormat( 2178 m_log.WarnFormat(
1860 "[LLUDPSERVER]: No packets received from {0} agent of {1} for {2}ms in {3}. Disconnecting.", 2179 "[LLUDPSERVER]: No packets received from {0} agent of {1} for {2}ms in {3}. Disconnecting.",
1861 client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, timeoutTicks, Scene.Name); 2180 client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, timeoutTicks, Scene.Name);
2181=======
2182 if (client.SceneAgent != null)
2183 {
2184 m_log.WarnFormat(
2185 "[LLUDPSERVER]: No packets received from {0} agent of {1} for {2}ms in {3}. Disconnecting.",
2186 client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, timeoutTicks, m_scene.Name);
2187>>>>>>> avn/ubitvar
1862 2188
1863 if (!client.SceneAgent.IsChildAgent) 2189 if (!client.SceneAgent.IsChildAgent)
1864 client.Kick("Simulator logged you out due to connection timeout."); 2190 client.Kick("Simulator logged you out due to connection timeout.");
2191 }
1865 } 2192 }
1866 2193
2194<<<<<<< HEAD
1867 Scene.CloseAgent(client.AgentId, true); 2195 Scene.CloseAgent(client.AgentId, true);
2196=======
2197 if (!m_scene.CloseAgent(client.AgentId, true))
2198 client.Close(true,true);
2199>>>>>>> avn/ubitvar
1868 } 2200 }
1869 2201
1870 private void IncomingPacketHandler() 2202 private void IncomingPacketHandler()
@@ -1877,6 +2209,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1877 2209
1878 while (IsRunningInbound) 2210 while (IsRunningInbound)
1879 { 2211 {
2212 m_scene.ThreadAlive(1);
1880 try 2213 try
1881 { 2214 {
1882 IncomingPacket incomingPacket = null; 2215 IncomingPacket incomingPacket = null;
@@ -1899,7 +2232,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1899 m_incomingPacketPool.ReturnObject(incomingPacket); 2232 m_incomingPacketPool.ReturnObject(incomingPacket);
1900 } 2233 }
1901 } 2234 }
1902 catch (Exception ex) 2235 catch(Exception ex)
1903 { 2236 {
1904 m_log.Error("[LLUDPSERVER]: Error in the incoming packet handler loop: " + ex.Message, ex); 2237 m_log.Error("[LLUDPSERVER]: Error in the incoming packet handler loop: " + ex.Message, ex);
1905 } 2238 }
@@ -1928,6 +2261,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1928 2261
1929 while (base.IsRunningOutbound) 2262 while (base.IsRunningOutbound)
1930 { 2263 {
2264 m_scene.ThreadAlive(2);
1931 try 2265 try
1932 { 2266 {
1933 m_packetSent = false; 2267 m_packetSent = false;
@@ -1986,13 +2320,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1986 2320
1987 // If nothing was sent, sleep for the minimum amount of time before a 2321 // If nothing was sent, sleep for the minimum amount of time before a
1988 // token bucket could get more tokens 2322 // token bucket could get more tokens
1989 //if (!m_packetSent) 2323
1990 // Thread.Sleep((int)TickCountResolution);
1991 //
1992 // Instead, now wait for data present to be explicitly signalled. Evidence so far is that with
1993 // modern mono it reduces CPU base load since there is no more continuous polling.
1994 if (!m_packetSent) 2324 if (!m_packetSent)
1995 m_dataPresentEvent.WaitOne(100); 2325 Thread.Sleep((int)TickCountResolution);
2326
2327 // .... wrong core code removed
2328
1996 2329
1997 Watchdog.UpdateThread(); 2330 Watchdog.UpdateThread();
1998 } 2331 }
@@ -2163,8 +2496,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2163 Packet packet = incomingPacket.Packet; 2496 Packet packet = incomingPacket.Packet;
2164 LLClientView client = incomingPacket.Client; 2497 LLClientView client = incomingPacket.Client;
2165 2498
2166 if (client.IsActive) 2499// if (client.IsActive)
2167 { 2500// {
2168 m_currentIncomingClient = client; 2501 m_currentIncomingClient = client;
2169 2502
2170 try 2503 try
@@ -2191,6 +2524,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2191 { 2524 {
2192 m_currentIncomingClient = null; 2525 m_currentIncomingClient = null;
2193 } 2526 }
2527<<<<<<< HEAD
2194 } 2528 }
2195 else 2529 else
2196 { 2530 {
@@ -2198,6 +2532,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2198 "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", 2532 "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}",
2199 packet.Type, client.Name, Scene.RegionInfo.RegionName); 2533 packet.Type, client.Name, Scene.RegionInfo.RegionName);
2200 } 2534 }
2535=======
2536// }
2537// else
2538// {
2539// m_log.DebugFormat(
2540// "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}",
2541// packet.Type, client.Name, m_scene.RegionInfo.RegionName);
2542// }
2543>>>>>>> avn/ubitvar
2201 2544
2202 IncomingPacketsProcessed++; 2545 IncomingPacketsProcessed++;
2203 } 2546 }
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index f62dc15..7171974 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -206,16 +206,16 @@ namespace OpenMetaverse
206 const int SIO_UDP_CONNRESET = -1744830452; 206 const int SIO_UDP_CONNRESET = -1744830452;
207 207
208 IPEndPoint ipep = new IPEndPoint(m_localBindAddress, m_udpPort); 208 IPEndPoint ipep = new IPEndPoint(m_localBindAddress, m_udpPort);
209
210 m_log.DebugFormat(
211 "[UDPBASE]: Binding UDP listener using internal IP address config {0}:{1}",
212 ipep.Address, ipep.Port);
213 209
214 m_udpSocket = new Socket( 210 m_udpSocket = new Socket(
215 AddressFamily.InterNetwork, 211 AddressFamily.InterNetwork,
216 SocketType.Dgram, 212 SocketType.Dgram,
217 ProtocolType.Udp); 213 ProtocolType.Udp);
218 214
215 // OpenSim may need this but in AVN, this messes up automated
216 // sim restarts badly
217 //m_udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false);
218
219 try 219 try
220 { 220 {
221 if (m_udpSocket.Ttl < 128) 221 if (m_udpSocket.Ttl < 128)
@@ -501,4 +501,4 @@ namespace OpenMetaverse
501 catch (ObjectDisposedException) { } 501 catch (ObjectDisposedException) { }
502 } 502 }
503 } 503 }
504} \ No newline at end of file 504}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs
index 7a2756b..076551f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs
@@ -69,6 +69,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
69 /// <summary>Amount of the texture throttle to steal for the task throttle</summary> 69 /// <summary>Amount of the texture throttle to steal for the task throttle</summary>
70 public double CannibalizeTextureRate; 70 public double CannibalizeTextureRate;
71 71
72 public int ClientMaxRate;
73 public float BrustTime;
74
72 /// <summary> 75 /// <summary>
73 /// Default constructor 76 /// Default constructor
74 /// </summary> 77 /// </summary>
@@ -88,7 +91,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
88 Texture = throttleConfig.GetInt("texture_default", 18500); 91 Texture = throttleConfig.GetInt("texture_default", 18500);
89 Asset = throttleConfig.GetInt("asset_default", 10500); 92 Asset = throttleConfig.GetInt("asset_default", 10500);
90 93
91 Total = throttleConfig.GetInt("client_throttle_max_bps", 0); 94 Total = Resend + Land + Wind + Cloud + Task + Texture + Asset;
95 // 3000000 bps default max
96 ClientMaxRate = throttleConfig.GetInt("client_throttle_max_bps", 375000);
97 if (ClientMaxRate > 1000000)
98 ClientMaxRate = 1000000; // no more than 8Mbps
99
100 BrustTime = (float)throttleConfig.GetInt("client_throttle_burtsTimeMS", 10);
101 BrustTime *= 1e-3f;
92 102
93 AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false); 103 AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false);
94 MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000); 104 MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000);
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
index 4616203..7a42d82 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
@@ -42,6 +42,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
42 public class TokenBucket 42 public class TokenBucket
43 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45<<<<<<< HEAD
45 46
46 public string Identifier { get; private set; } 47 public string Identifier { get; private set; }
47 48
@@ -52,16 +53,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
52 /// are defined over this interval. 53 /// are defined over this interval.
53 /// </summary> 54 /// </summary>
54 protected const Int32 m_ticksPerQuantum = 1000; 55 protected const Int32 m_ticksPerQuantum = 1000;
56=======
57 private static Int32 m_counter = 0;
58
59// private Int32 m_identifier;
60
61 protected const float m_timeScale = 1e-3f;
62>>>>>>> avn/ubitvar
55 63
56 /// <summary> 64 /// <summary>
57 /// This is the number of quantums worth of packets that can 65 /// This is the number of m_minimumDripRate bytes
58 /// be accommodated during a burst 66 /// allowed in a burst
67 /// roughtly, with this settings, the maximum time system will take
68 /// to recheck a bucket in ms
69 ///
59 /// </summary> 70 /// </summary>
60 protected const Double m_quantumsPerBurst = 1.5; 71 protected const float m_quantumsPerBurst = 5;
61 72
62 /// <summary> 73 /// <summary>
63 /// </summary> 74 /// </summary>
75<<<<<<< HEAD
64 protected const Int32 m_minimumDripRate = LLUDPServer.MTU; 76 protected const Int32 m_minimumDripRate = LLUDPServer.MTU;
77=======
78 protected const float m_minimumDripRate = 1400;
79>>>>>>> avn/ubitvar
65 80
66 /// <summary>Time of the last drip, in system ticks</summary> 81 /// <summary>Time of the last drip, in system ticks</summary>
67 protected Int32 m_lastDrip; 82 protected Int32 m_lastDrip;
@@ -70,12 +85,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
70 /// The number of bytes that can be sent at this moment. This is the 85 /// The number of bytes that can be sent at this moment. This is the
71 /// current number of tokens in the bucket 86 /// current number of tokens in the bucket
72 /// </summary> 87 /// </summary>
73 protected Int64 m_tokenCount; 88 protected float m_tokenCount;
74 89
75 /// <summary> 90 /// <summary>
76 /// Map of children buckets and their requested maximum burst rate 91 /// Map of children buckets and their requested maximum burst rate
77 /// </summary> 92 /// </summary>
93<<<<<<< HEAD
78 protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>(); 94 protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>();
95=======
96 protected Dictionary<TokenBucket, float> m_children = new Dictionary<TokenBucket, float>();
97
98#region Properties
99>>>>>>> avn/ubitvar
79 100
80 /// <summary> 101 /// <summary>
81 /// The parent bucket of this bucket, or null if this bucket has no 102 /// The parent bucket of this bucket, or null if this bucket has no
@@ -85,25 +106,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
85 public TokenBucket Parent { get; protected set; } 106 public TokenBucket Parent { get; protected set; }
86 107
87 /// <summary> 108 /// <summary>
88 /// Maximum burst rate in bytes per second. This is the maximum number 109 /// This is the maximum number
89 /// of tokens that can accumulate in the bucket at any one time. This 110 /// of tokens that can accumulate in the bucket at any one time. This
90 /// also sets the total request for leaf nodes 111 /// also sets the total request for leaf nodes
91 /// </summary> 112 /// </summary>
92 protected Int64 m_burstRate; 113 protected float m_burst;
93 public Int64 RequestedBurstRate 114 public float RequestedBurst
94 { 115 {
95 get { return m_burstRate; } 116 get { return m_burst; }
96 set { m_burstRate = (value < 0 ? 0 : value); } 117 set {
118 float rate = (value < 0 ? 0 : value);
119 if (rate < m_minimumDripRate)
120 rate = m_minimumDripRate;
121 else if (rate > m_minimumDripRate * m_quantumsPerBurst)
122 rate = m_minimumDripRate * m_quantumsPerBurst;
123
124 m_burst = rate;
125 }
97 } 126 }
98 127
99 public Int64 BurstRate 128 public float Burst
100 { 129 {
101 get { 130 get {
102 double rate = RequestedBurstRate * BurstRateModifier(); 131 float rate = RequestedBurst * BurstModifier();
103 if (rate < m_minimumDripRate * m_quantumsPerBurst) 132 if (rate < m_minimumDripRate)
104 rate = m_minimumDripRate * m_quantumsPerBurst; 133 rate = m_minimumDripRate;
105 134 return (float)rate;
106 return (Int64) rate;
107 } 135 }
108 } 136 }
109 137
@@ -115,6 +143,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
115 /// Can never be above MaxDripRate. 143 /// Can never be above MaxDripRate.
116 /// Tokens are added to the bucket at any time 144 /// Tokens are added to the bucket at any time
117 /// <seealso cref="RemoveTokens"/> is called, at the granularity of 145 /// <seealso cref="RemoveTokens"/> is called, at the granularity of
146<<<<<<< HEAD
118 /// the system tick interval (typically around 15-22ms) 147 /// the system tick interval (typically around 15-22ms)
119 /// FIXME: It is extremely confusing to be able to set a RequestedDripRate of 0 and then receive a positive 148 /// FIXME: It is extremely confusing to be able to set a RequestedDripRate of 0 and then receive a positive
120 /// number on get if TotalDripRequest is set. This also stops us being able to retrieve the fact that 149 /// number on get if TotalDripRequest is set. This also stops us being able to retrieve the fact that
@@ -168,12 +197,36 @@ namespace OpenSim.Region.ClientStack.LindenUDP
168 rate = (double)RequestedDripRate * Parent.DripRateModifier(); 197 rate = (double)RequestedDripRate * Parent.DripRateModifier();
169 } 198 }
170 199
200=======
201 /// the system tick interval (typically around 15-22ms)</remarks>
202 protected float m_dripRate;
203 public virtual float RequestedDripRate
204 {
205 get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); }
206 set {
207 m_dripRate = (value < 0 ? 0 : value);
208 m_totalDripRequest = m_dripRate;
209
210 if (m_parent != null)
211 m_parent.RegisterRequest(this,m_dripRate);
212 }
213 }
214
215 public virtual float DripRate
216 {
217 get {
218 float rate = Math.Min(RequestedDripRate,TotalDripRequest);
219 if (m_parent == null)
220 return rate;
221
222 rate *= m_parent.DripRateModifier();
223>>>>>>> avn/ubitvar
171 if (rate < m_minimumDripRate) 224 if (rate < m_minimumDripRate)
172 rate = m_minimumDripRate; 225 rate = m_minimumDripRate;
173 else if (MaxDripRate > 0 && rate > MaxDripRate) 226 else if (MaxDripRate > 0 && rate > MaxDripRate)
174 rate = MaxDripRate; 227 rate = MaxDripRate;
175 228
176 return (Int64)rate; 229 return (float)rate;
177 } 230 }
178 } 231 }
179 protected Int64 m_dripRate; 232 protected Int64 m_dripRate;
@@ -186,7 +239,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
186 /// <summary> 239 /// <summary>
187 /// The current total of the requested maximum burst rates of children buckets. 240 /// The current total of the requested maximum burst rates of children buckets.
188 /// </summary> 241 /// </summary>
242<<<<<<< HEAD
189 public Int64 TotalDripRequest { get; protected set; } 243 public Int64 TotalDripRequest { get; protected set; }
244=======
245 protected float m_totalDripRequest;
246 public float TotalDripRequest
247 {
248 get { return m_totalDripRequest; }
249 set { m_totalDripRequest = value; }
250 }
251
252#endregion Properties
253
254#region Constructor
255>>>>>>> avn/ubitvar
190 256
191 /// <summary> 257 /// <summary>
192 /// Default constructor 258 /// Default constructor
@@ -194,18 +260,34 @@ namespace OpenSim.Region.ClientStack.LindenUDP
194 /// <param name="identifier">Identifier for this token bucket</param> 260 /// <param name="identifier">Identifier for this token bucket</param>
195 /// <param name="parent">Parent bucket if this is a child bucket, or 261 /// <param name="parent">Parent bucket if this is a child bucket, or
196 /// null if this is a root bucket</param> 262 /// null if this is a root bucket</param>
263<<<<<<< HEAD
197 /// <param name="requestedDripRate"> 264 /// <param name="requestedDripRate">
198 /// Requested rate that the bucket fills, in bytes per 265 /// Requested rate that the bucket fills, in bytes per
199 /// second. If zero, the bucket always remains full. 266 /// second. If zero, the bucket always remains full.
200 /// </param> 267 /// </param>
201 public TokenBucket(string identifier, TokenBucket parent, Int64 requestedDripRate, Int64 maxDripRate) 268 public TokenBucket(string identifier, TokenBucket parent, Int64 requestedDripRate, Int64 maxDripRate)
269=======
270 /// <param name="maxBurst">Maximum size of the bucket in bytes, or
271 /// zero if this bucket has no maximum capacity</param>
272 /// <param name="dripRate">Rate that the bucket fills, in bytes per
273 /// second. If zero, the bucket always remains full</param>
274 public TokenBucket(TokenBucket parent, float dripRate, float MaxBurst)
275>>>>>>> avn/ubitvar
202 { 276 {
203 Identifier = identifier; 277 Identifier = identifier;
204 278
205 Parent = parent; 279 Parent = parent;
280<<<<<<< HEAD
206 RequestedDripRate = requestedDripRate; 281 RequestedDripRate = requestedDripRate;
207 MaxDripRate = maxDripRate; 282 MaxDripRate = maxDripRate;
208 m_lastDrip = Util.EnvironmentTickCount(); 283 m_lastDrip = Util.EnvironmentTickCount();
284=======
285 RequestedDripRate = dripRate;
286 RequestedBurst = MaxBurst;
287 // TotalDripRequest = dripRate; // this will be overwritten when a child node registers
288 // MaxBurst = (Int64)((double)dripRate * m_quantumsPerBurst);
289 m_lastDrip = Util.EnvironmentTickCount() + 100000;
290>>>>>>> avn/ubitvar
209 } 291 }
210 292
211 /// <summary> 293 /// <summary>
@@ -215,8 +297,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
215 /// hierarchy. However, if any of the parents is over-booked, then 297 /// hierarchy. However, if any of the parents is over-booked, then
216 /// the modifier will be less than 1. 298 /// the modifier will be less than 1.
217 /// </summary> 299 /// </summary>
218 protected double DripRateModifier() 300 protected float DripRateModifier()
219 { 301 {
302<<<<<<< HEAD
220 Int64 driprate = DripRate; 303 Int64 driprate = DripRate;
221 double modifier = driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest; 304 double modifier = driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest;
222 305
@@ -226,11 +309,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
226// driprate, TotalDripRequest, modifier, Identifier); 309// driprate, TotalDripRequest, modifier, Identifier);
227 310
228 return modifier; 311 return modifier;
312=======
313 float driprate = DripRate;
314 return driprate >= TotalDripRequest ? 1.0f : driprate / TotalDripRequest;
315>>>>>>> avn/ubitvar
229 } 316 }
230 317
231 /// <summary> 318 /// <summary>
232 /// </summary> 319 /// </summary>
233 protected double BurstRateModifier() 320 protected float BurstModifier()
234 { 321 {
235 // for now... burst rate is always m_quantumsPerBurst (constant) 322 // for now... burst rate is always m_quantumsPerBurst (constant)
236 // larger than drip rate so the ratio of burst requests is the 323 // larger than drip rate so the ratio of burst requests is the
@@ -242,15 +329,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
242 /// Register drip rate requested by a child of this throttle. Pass the 329 /// Register drip rate requested by a child of this throttle. Pass the
243 /// changes up the hierarchy. 330 /// changes up the hierarchy.
244 /// </summary> 331 /// </summary>
245 public void RegisterRequest(TokenBucket child, Int64 request) 332 public void RegisterRequest(TokenBucket child, float request)
246 { 333 {
247 lock (m_children) 334 lock (m_children)
248 { 335 {
249 m_children[child] = request; 336 m_children[child] = request;
250 337
338<<<<<<< HEAD
251 TotalDripRequest = 0; 339 TotalDripRequest = 0;
252 foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) 340 foreach (KeyValuePair<TokenBucket, Int64> cref in m_children)
253 TotalDripRequest += cref.Value; 341 TotalDripRequest += cref.Value;
342=======
343 m_totalDripRequest = 0;
344 foreach (KeyValuePair<TokenBucket, float> cref in m_children)
345 m_totalDripRequest += cref.Value;
346>>>>>>> avn/ubitvar
254 } 347 }
255 348
256 // Pass the new values up to the parent 349 // Pass the new values up to the parent
@@ -277,9 +370,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
277 { 370 {
278 m_children.Remove(child); 371 m_children.Remove(child);
279 372
373<<<<<<< HEAD
280 TotalDripRequest = 0; 374 TotalDripRequest = 0;
281 foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) 375 foreach (KeyValuePair<TokenBucket, Int64> cref in m_children)
282 TotalDripRequest += cref.Value; 376 TotalDripRequest += cref.Value;
377=======
378 m_totalDripRequest = 0;
379 foreach (KeyValuePair<TokenBucket, float> cref in m_children)
380 m_totalDripRequest += cref.Value;
381>>>>>>> avn/ubitvar
283 } 382 }
284 383
285 // Pass the new values up to the parent 384 // Pass the new values up to the parent
@@ -293,7 +392,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
293 /// <param name="amount">Number of tokens to remove from the bucket</param> 392 /// <param name="amount">Number of tokens to remove from the bucket</param>
294 /// <returns>True if the requested number of tokens were removed from 393 /// <returns>True if the requested number of tokens were removed from
295 /// the bucket, otherwise false</returns> 394 /// the bucket, otherwise false</returns>
296 public bool RemoveTokens(Int64 amount) 395 public bool RemoveTokens(int amount)
297 { 396 {
298 // Deposit tokens for this interval 397 // Deposit tokens for this interval
299 Drip(); 398 Drip();
@@ -310,19 +409,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
310 return false; 409 return false;
311 } 410 }
312 411
313 /// <summary> 412 public int GetCatBytesCanSend(int timeMS)
314 /// Deposit tokens into the bucket from a child bucket that did
315 /// not use all of its available tokens
316 /// </summary>
317 protected void Deposit(Int64 count)
318 { 413 {
319 m_tokenCount += count; 414// return (int)(m_tokenCount + timeMS * m_dripRate * 1e-3);
320 415 return (int)(timeMS * m_dripRate * 1e-3);
321 // Deposit the overflow in the parent bucket, this is how we share
322 // unused bandwidth
323 Int64 burstrate = BurstRate;
324 if (m_tokenCount > burstrate)
325 m_tokenCount = burstrate;
326 } 416 }
327 417
328 /// <summary> 418 /// <summary>
@@ -341,17 +431,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
341 return; 431 return;
342 } 432 }
343 433
344 // Determine the interval over which we are adding tokens, never add 434 Int32 now = Util.EnvironmentTickCount();
345 // more than a single quantum of tokens 435 Int32 deltaMS = now - m_lastDrip;
346 Int32 deltaMS = Math.Min(Util.EnvironmentTickCountSubtract(m_lastDrip), m_ticksPerQuantum); 436 m_lastDrip = now;
347 m_lastDrip = Util.EnvironmentTickCount();
348 437
349 // This can be 0 in the very unusual case that the timer wrapped
350 // It can be 0 if we try add tokens at a sub-tick rate
351 if (deltaMS <= 0) 438 if (deltaMS <= 0)
352 return; 439 return;
353 440
354 Deposit(deltaMS * DripRate / m_ticksPerQuantum); 441 m_tokenCount += deltaMS * DripRate * m_timeScale;
442
443 float burst = Burst;
444 if (m_tokenCount > burst)
445 m_tokenCount = burst;
355 } 446 }
356 } 447 }
357 448
@@ -362,6 +453,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
362 public bool AdaptiveEnabled { get; set; } 453 public bool AdaptiveEnabled { get; set; }
363 454
364 /// <summary> 455 /// <summary>
456<<<<<<< HEAD
365 /// Target drip rate for this bucket. 457 /// Target drip rate for this bucket.
366 /// </summary> 458 /// </summary>
367 /// <remarks>Usually set by the client. If adaptive is enabled then throttles will increase until we reach this.</remarks> 459 /// <remarks>Usually set by the client. If adaptive is enabled then throttles will increase until we reach this.</remarks>
@@ -371,6 +463,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
371 set 463 set
372 { 464 {
373 m_targetDripRate = Math.Max(value, m_minimumFlow); 465 m_targetDripRate = Math.Max(value, m_minimumFlow);
466=======
467 /// The minimum rate for flow control. Minimum drip rate is one
468 /// packet per second.
469 /// </summary>
470
471 protected const float m_minimumFlow = 50000;
472
473 // <summary>
474 // The maximum rate for flow control. Drip rate can never be
475 // greater than this.
476 // </summary>
477
478 protected float m_maxDripRate = 0;
479 public float MaxDripRate
480 {
481 get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); }
482 set
483 {
484 m_maxDripRate = (value == 0 ? m_totalDripRequest : Math.Max(value, m_minimumFlow));
485>>>>>>> avn/ubitvar
374 } 486 }
375 } 487 }
376 protected Int64 m_targetDripRate; 488 protected Int64 m_targetDripRate;
@@ -378,9 +490,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
378 // <summary> 490 // <summary>
379 // Adjust drip rate in response to network conditions. 491 // Adjust drip rate in response to network conditions.
380 // </summary> 492 // </summary>
381 public virtual Int64 AdjustedDripRate 493 public virtual float AdjustedDripRate
382 { 494 {
383 get { return m_dripRate; } 495 get { return m_dripRate; }
496<<<<<<< HEAD
384 set 497 set
385 { 498 {
386 m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value, m_minimumFlow, TargetDripRate); 499 m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value, m_minimumFlow, TargetDripRate);
@@ -388,6 +501,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
388 501
389 if (Parent != null) 502 if (Parent != null)
390 Parent.RegisterRequest(this, m_dripRate); 503 Parent.RegisterRequest(this, m_dripRate);
504=======
505 set {
506 m_dripRate = OpenSim.Framework.Util.Clamp<float>(value,m_minimumFlow,MaxDripRate);
507
508 if (m_parent != null)
509 m_parent.RegisterRequest(this,m_dripRate);
510>>>>>>> avn/ubitvar
391 } 511 }
392 } 512 }
393 513
@@ -396,6 +516,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
396 /// </summary> 516 /// </summary>
397 protected Int64 m_minimumFlow = 32000; 517 protected Int64 m_minimumFlow = 32000;
398 518
519<<<<<<< HEAD
399 /// <summary> 520 /// <summary>
400 /// Constructor for the AdaptiveTokenBucket class 521 /// Constructor for the AdaptiveTokenBucket class
401 /// <param name="identifier">Unique identifier for the client</param> 522 /// <param name="identifier">Unique identifier for the client</param>
@@ -416,6 +537,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
416 TargetDripRate = m_minimumFlow; 537 TargetDripRate = m_minimumFlow;
417 AdjustedDripRate = m_minimumFlow; 538 AdjustedDripRate = m_minimumFlow;
418 } 539 }
540=======
541 // <summary>
542 //
543 // </summary>
544 public AdaptiveTokenBucket(TokenBucket parent, float maxDripRate,float maxBurst, bool enabled)
545 : base(parent, maxDripRate,maxBurst)
546 {
547 m_enabled = enabled;
548
549 MaxDripRate = maxDripRate;
550
551 if (enabled)
552 AdjustedDripRate = m_maxDripRate * .5f;
553 else
554 AdjustedDripRate = m_maxDripRate;
555>>>>>>> avn/ubitvar
419 } 556 }
420 557
421 /// <summary> 558 /// <summary>
@@ -461,4 +598,4 @@ namespace OpenSim.Region.ClientStack.LindenUDP
461 AdjustedDripRate = m_minimumFlow; 598 AdjustedDripRate = m_minimumFlow;
462 } 599 }
463 } 600 }
464} \ No newline at end of file 601}
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
index c497b1c..d58ab94 100644
--- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs
+++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
@@ -101,13 +101,25 @@ namespace OpenSim.Region.ClientStack
101 // "OOB" Server 101 // "OOB" Server
102 if (m_networkServersInfo.ssl_listener) 102 if (m_networkServersInfo.ssl_listener)
103 { 103 {
104 BaseHttpServer server = new BaseHttpServer( 104 if (!m_networkServersInfo.ssl_external)
105 m_networkServersInfo.https_port, m_networkServersInfo.ssl_listener, m_networkServersInfo.cert_path, 105 {
106 m_networkServersInfo.cert_pass); 106 BaseHttpServer server = new BaseHttpServer(
107 m_networkServersInfo.https_port, m_networkServersInfo.ssl_listener, m_networkServersInfo.cert_path,
108 m_networkServersInfo.cert_pass);
107 109
108 m_log.InfoFormat("[REGION SERVER]: Starting HTTPS server on port {0}", server.Port); 110 m_log.InfoFormat("[REGION SERVER]: Starting HTTPS server on port {0}", server.Port);
109 MainServer.AddHttpServer(server); 111 MainServer.AddHttpServer(server);
110 server.Start(); 112 server.Start();
113 }
114 else
115 {
116 BaseHttpServer server = new BaseHttpServer(
117 m_networkServersInfo.https_port);
118
119 m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0} for external HTTPS", server.Port);
120 MainServer.AddHttpServer(server);
121 server.Start();
122 }
111 } 123 }
112 124
113 base.StartupSpecific(); 125 base.StartupSpecific();
@@ -129,8 +141,12 @@ namespace OpenSim.Region.ClientStack
129 PhysicsPluginManager physicsPluginManager; 141 PhysicsPluginManager physicsPluginManager;
130 physicsPluginManager = new PhysicsPluginManager(); 142 physicsPluginManager = new PhysicsPluginManager();
131 physicsPluginManager.LoadPluginsFromAssemblies("Physics"); 143 physicsPluginManager.LoadPluginsFromAssemblies("Physics");
144<<<<<<< HEAD
132 145
146=======
147
148>>>>>>> avn/ubitvar
133 return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config, osSceneIdentifier, regionExtent); 149 return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config, osSceneIdentifier, regionExtent);
134 } 150 }
135 } 151 }
136} \ No newline at end of file 152}
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
index f56d17d..1a19585 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
@@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
152 } 152 }
153 } 153 }
154 154
155 public void RequestCreateInventoryItem(IClientAPI remoteClient, 155 public bool RequestCreateInventoryItem(IClientAPI remoteClient,
156 UUID transactionID, UUID folderID, uint callbackID, 156 UUID transactionID, UUID folderID, uint callbackID,
157 string description, string name, sbyte invType, 157 string description, string name, sbyte invType,
158 sbyte type, byte wearableType, uint nextOwnerMask) 158 sbyte type, byte wearableType, uint nextOwnerMask)
@@ -162,6 +162,8 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
162 uploader.RequestCreateInventoryItem( 162 uploader.RequestCreateInventoryItem(
163 remoteClient, folderID, callbackID, 163 remoteClient, folderID, callbackID,
164 description, name, invType, type, wearableType, nextOwnerMask); 164 description, name, invType, type, wearableType, nextOwnerMask);
165
166 return true;
165 } 167 }
166 168
167 public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, 169 public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
@@ -170,6 +172,17 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
170 { 172 {
171 AssetXferUploader uploader = RequestXferUploader(transactionID); 173 AssetXferUploader uploader = RequestXferUploader(transactionID);
172 174
175 // Here we need to get the old asset to extract the
176 // texture UUIDs if it's a wearable.
177 if (item.Type == (int)AssetType.Bodypart ||
178 item.Type == (int)AssetType.Clothing ||
179 item.Type == (int)CustomAssetType.AnimationSet)
180 {
181 AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
182 if (oldAsset != null)
183 uploader.SetOldData(oldAsset.Data);
184 }
185
173 uploader.RequestUpdateTaskInventoryItem(remoteClient, item); 186 uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
174 } 187 }
175 188
@@ -178,7 +191,18 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
178 { 191 {
179 AssetXferUploader uploader = RequestXferUploader(transactionID); 192 AssetXferUploader uploader = RequestXferUploader(transactionID);
180 193
194 // Here we need to get the old asset to extract the
195 // texture UUIDs if it's a wearable.
196 if (item.AssetType == (int)AssetType.Bodypart ||
197 item.AssetType == (int)AssetType.Clothing ||
198 item.AssetType == (int)CustomAssetType.AnimationSet)
199 {
200 AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
201 if (oldAsset != null)
202 uploader.SetOldData(oldAsset.Data);
203 }
204
181 uploader.RequestUpdateInventoryItem(remoteClient, item); 205 uploader.RequestUpdateInventoryItem(remoteClient, item);
182 } 206 }
183 } 207 }
184} \ No newline at end of file 208}
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
index b67c0df..f489262 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -158,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
158 /// <param name="type"></param> 158 /// <param name="type"></param>
159 /// <param name="wearableType"></param> 159 /// <param name="wearableType"></param>
160 /// <param name="nextOwnerMask"></param> 160 /// <param name="nextOwnerMask"></param>
161 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, 161 public bool HandleItemCreationFromTransaction(IClientAPI remoteClient,
162 UUID transactionID, UUID folderID, uint callbackID, 162 UUID transactionID, UUID folderID, uint callbackID,
163 string description, string name, sbyte invType, 163 string description, string name, sbyte invType,
164 sbyte type, byte wearableType, uint nextOwnerMask) 164 sbyte type, byte wearableType, uint nextOwnerMask)
@@ -169,7 +169,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
169 AgentAssetTransactions transactions = 169 AgentAssetTransactions transactions =
170 GetUserTransactions(remoteClient.AgentId); 170 GetUserTransactions(remoteClient.AgentId);
171 171
172 transactions.RequestCreateInventoryItem(remoteClient, transactionID, 172 return transactions.RequestCreateInventoryItem(remoteClient, transactionID,
173 folderID, callbackID, description, name, invType, type, 173 folderID, callbackID, description, name, invType, type,
174 wearableType, nextOwnerMask); 174 wearableType, nextOwnerMask);
175 } 175 }
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index 49a96f4..345b53d 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Reflection; 30using System.Reflection;
31using System.Collections.Generic;
31using log4net; 32using log4net;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -40,6 +41,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
40{ 41{
41 public class AssetXferUploader 42 public class AssetXferUploader
42 { 43 {
44 // Viewer's notion of the default texture
45 private List<UUID> defaultIDs = new List<UUID> {
46 new UUID("5748decc-f629-461c-9a36-a35a221fe21f"),
47 new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"),
48 new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"),
49 new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97")
50 };
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 52
45 /// <summary> 53 /// <summary>
@@ -87,6 +95,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
87 95
88 private sbyte type = 0; 96 private sbyte type = 0;
89 private byte wearableType = 0; 97 private byte wearableType = 0;
98 private byte[] m_oldData = null;
90 public ulong XferID; 99 public ulong XferID;
91 private Scene m_Scene; 100 private Scene m_Scene;
92 101
@@ -129,18 +138,27 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
129 138
130 if (XferID == xferID) 139 if (XferID == xferID)
131 { 140 {
132 if (m_asset.Data.Length > 1) 141 lock (this)
133 { 142 {
134 byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; 143 int assetLength = m_asset.Data.Length;
135 Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); 144 int dataLength = data.Length;
136 Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); 145
137 m_asset.Data = destinationArray; 146 if (m_asset.Data.Length > 1)
138 } 147 {
139 else 148 byte[] destinationArray = new byte[assetLength + dataLength];
140 { 149 Array.Copy(m_asset.Data, 0, destinationArray, 0, assetLength);
141 byte[] buffer2 = new byte[data.Length - 4]; 150 Array.Copy(data, 0, destinationArray, assetLength, dataLength);
142 Array.Copy(data, 4, buffer2, 0, data.Length - 4); 151 m_asset.Data = destinationArray;
143 m_asset.Data = buffer2; 152 }
153 else
154 {
155 if (dataLength > 4)
156 {
157 byte[] buffer2 = new byte[dataLength - 4];
158 Array.Copy(data, 4, buffer2, 0, dataLength - 4);
159 m_asset.Data = buffer2;
160 }
161 }
144 } 162 }
145 163
146 ourClient.SendConfirmXfer(xferID, packetID); 164 ourClient.SendConfirmXfer(xferID, packetID);
@@ -244,10 +262,10 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
244 { 262 {
245 CompleteTaskItemUpdate(m_updateTaskItemData); 263 CompleteTaskItemUpdate(m_updateTaskItemData);
246 } 264 }
247// else if (m_storeLocal) 265 else if (m_asset.Local)
248// { 266 {
249// m_Scene.AssetService.Store(m_asset); 267 m_Scene.AssetService.Store(m_asset);
250// } 268 }
251 } 269 }
252 270
253 m_log.DebugFormat( 271 m_log.DebugFormat(
@@ -374,7 +392,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
374// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}", 392// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}",
375// m_asset.FullID, item.Name, ourClient.Name); 393// m_asset.FullID, item.Name, ourClient.Name);
376 394
395 ValidateAssets();
377 m_Scene.AssetService.Store(m_asset); 396 m_Scene.AssetService.Store(m_asset);
397 if (m_asset.FullID != UUID.Zero)
398 {
399 item.AssetID = m_asset.FullID;
400 m_Scene.InventoryService.UpdateItem(item);
401 }
378 402
379 m_transactions.RemoveXferUploader(m_transactionID); 403 m_transactions.RemoveXferUploader(m_transactionID);
380 404
@@ -391,6 +415,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
391// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}", 415// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}",
392// m_asset.FullID, taskItem.Name, ourClient.Name); 416// m_asset.FullID, taskItem.Name, ourClient.Name);
393 417
418 ValidateAssets();
394 m_Scene.AssetService.Store(m_asset); 419 m_Scene.AssetService.Store(m_asset);
395 420
396 m_transactions.RemoveXferUploader(m_transactionID); 421 m_transactions.RemoveXferUploader(m_transactionID);
@@ -398,6 +423,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
398 423
399 private void CompleteCreateItem(uint callbackID) 424 private void CompleteCreateItem(uint callbackID)
400 { 425 {
426 ValidateAssets();
401 m_Scene.AssetService.Store(m_asset); 427 m_Scene.AssetService.Store(m_asset);
402 428
403 InventoryItemBase item = new InventoryItemBase(); 429 InventoryItemBase item = new InventoryItemBase();
@@ -418,6 +444,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
418 item.Flags = (uint) wearableType; 444 item.Flags = (uint) wearableType;
419 item.CreationDate = Util.UnixTimeSinceEpoch(); 445 item.CreationDate = Util.UnixTimeSinceEpoch();
420 446
447 m_log.DebugFormat("[XFER]: Created item {0} with asset {1}",
448 item.ID, item.AssetID);
449
421 if (m_Scene.AddInventoryItem(item)) 450 if (m_Scene.AddInventoryItem(item))
422 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 451 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
423 else 452 else
@@ -426,5 +455,150 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
426 m_transactions.RemoveXferUploader(m_transactionID); 455 m_transactions.RemoveXferUploader(m_transactionID);
427 } 456 }
428 457
458<<<<<<< HEAD
459=======
460 private void ValidateAssets()
461 {
462 if (m_asset.Type == (sbyte)CustomAssetType.AnimationSet)
463 {
464 AnimationSet animSet = new AnimationSet(m_asset.Data);
465
466 bool allOk = animSet.Validate(x => {
467 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, x);
468 int required = (int)(PermissionMask.Transfer | PermissionMask.Copy);
469 if ((perms & required) != required)
470 return false;
471 return true;
472 });
473
474 if (!allOk)
475 m_asset.Data = animSet.ToBytes();
476 }
477
478 if (m_asset.Type == (sbyte)AssetType.Clothing ||
479 m_asset.Type == (sbyte)AssetType.Bodypart)
480 {
481 string content = System.Text.Encoding.ASCII.GetString(m_asset.Data);
482 string[] lines = content.Split(new char[] {'\n'});
483
484 List<string> validated = new List<string>();
485
486 Dictionary<int, UUID> allowed = ExtractTexturesFromOldData();
487
488 int textures = 0;
489
490 foreach (string line in lines)
491 {
492 try
493 {
494 if (line.StartsWith("textures "))
495 {
496 textures = Convert.ToInt32(line.Substring(9));
497 validated.Add(line);
498 }
499 else if (textures > 0)
500 {
501 string[] parts = line.Split(new char[] {' '});
502
503 UUID tx = new UUID(parts[1]);
504 int id = Convert.ToInt32(parts[0]);
505
506 if (defaultIDs.Contains(tx) || tx == UUID.Zero ||
507 (allowed.ContainsKey(id) && allowed[id] == tx))
508 {
509 validated.Add(parts[0] + " " + tx.ToString());
510 }
511 else
512 {
513 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx);
514 int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy);
515
516 if ((perms & full) != full)
517 {
518 m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId);
519 validated.Add(parts[0] + " " + UUID.Zero.ToString());
520 }
521 else
522 {
523 validated.Add(line);
524 }
525 }
526 textures--;
527 }
528 else
529 {
530 validated.Add(line);
531 }
532 }
533 catch
534 {
535 // If it's malformed, skip it
536 }
537 }
538
539 string final = String.Join("\n", validated.ToArray());
540
541 m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final);
542 }
543 }
544
545 /// <summary>
546 /// Get the asset data uploaded in this transfer.
547 /// </summary>
548 /// <returns>null if the asset has not finished uploading</returns>
549 public AssetBase GetAssetData()
550 {
551 if (m_uploadState == UploadState.Complete)
552 {
553 ValidateAssets();
554 return m_asset;
555 }
556
557 return null;
558 }
559
560 public void SetOldData(byte[] d)
561 {
562 m_oldData = d;
563 }
564
565 private Dictionary<int,UUID> ExtractTexturesFromOldData()
566 {
567 Dictionary<int,UUID> result = new Dictionary<int,UUID>();
568 if (m_oldData == null)
569 return result;
570
571 string content = System.Text.Encoding.ASCII.GetString(m_oldData);
572 string[] lines = content.Split(new char[] {'\n'});
573
574 int textures = 0;
575
576 foreach (string line in lines)
577 {
578 try
579 {
580 if (line.StartsWith("textures "))
581 {
582 textures = Convert.ToInt32(line.Substring(9));
583 }
584 else if (textures > 0)
585 {
586 string[] parts = line.Split(new char[] {' '});
587
588 UUID tx = new UUID(parts[1]);
589 int id = Convert.ToInt32(parts[0]);
590 result[id] = tx;
591 textures--;
592 }
593 }
594 catch
595 {
596 // If it's malformed, skip it
597 }
598 }
599
600 return result;
601 }
602>>>>>>> avn/ubitvar
429 } 603 }
430} \ No newline at end of file 604}
diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
index 4299726..7113f4f 100644
--- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
@@ -160,6 +160,8 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
160 { 160 {
161 byte[] fileData = NewFiles[fileName].Data; 161 byte[] fileData = NewFiles[fileName].Data;
162 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); 162 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
163 if (fileName.StartsWith("inventory_"))
164 transaction.isTaskInventory = true;
163 165
164 Transfers.Add(xferID, transaction); 166 Transfers.Add(xferID, transaction);
165 167
@@ -243,6 +245,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
243 public uint Packet = 0; 245 public uint Packet = 0;
244 public uint Serial = 1; 246 public uint Serial = 1;
245 public ulong XferID = 0; 247 public ulong XferID = 0;
248 public bool isTaskInventory = false;
246 249
247 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) 250 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
248 { 251 {
@@ -268,7 +271,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
268 byte[] transferData = new byte[Data.Length + 4]; 271 byte[] transferData = new byte[Data.Length + 4];
269 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); 272 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
270 Array.Copy(Data, 0, transferData, 4, Data.Length); 273 Array.Copy(Data, 0, transferData, 4, Data.Length);
271 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); 274 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData, isTaskInventory);
272 complete = true; 275 complete = true;
273 } 276 }
274 else 277 else
@@ -276,7 +279,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
276 byte[] transferData = new byte[1000 + 4]; 279 byte[] transferData = new byte[1000 + 4];
277 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); 280 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
278 Array.Copy(Data, 0, transferData, 4, 1000); 281 Array.Copy(Data, 0, transferData, 4, 1000);
279 Client.SendXferPacket(XferID, 0, transferData); 282 Client.SendXferPacket(XferID, 0, transferData, isTaskInventory);
280 Packet++; 283 Packet++;
281 DataPointer = 1000; 284 DataPointer = 1000;
282 } 285 }
@@ -297,7 +300,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
297 { 300 {
298 byte[] transferData = new byte[1000]; 301 byte[] transferData = new byte[1000];
299 Array.Copy(Data, DataPointer, transferData, 0, 1000); 302 Array.Copy(Data, DataPointer, transferData, 0, 1000);
300 Client.SendXferPacket(XferID, Packet, transferData); 303 Client.SendXferPacket(XferID, Packet, transferData, isTaskInventory);
301 Packet++; 304 Packet++;
302 DataPointer += 1000; 305 DataPointer += 1000;
303 } 306 }
@@ -306,7 +309,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
306 byte[] transferData = new byte[Data.Length - DataPointer]; 309 byte[] transferData = new byte[Data.Length - DataPointer];
307 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); 310 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
308 uint endPacket = Packet |= (uint) 0x80000000; 311 uint endPacket = Packet |= (uint) 0x80000000;
309 Client.SendXferPacket(XferID, endPacket, transferData); 312 Client.SendXferPacket(XferID, endPacket, transferData, isTaskInventory);
310 Packet++; 313 Packet++;
311 DataPointer += (Data.Length - DataPointer); 314 DataPointer += (Data.Length - DataPointer);
312 315
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 7d9c9a9..c4abc99 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -594,6 +594,11 @@ namespace OpenSim.Region.CoreModules.Asset
594 dir, dirSize); 594 dir, dirSize);
595 } 595 }
596 } 596 }
597 catch (DirectoryNotFoundException)
598 {
599 // If we get here, another node on the same box has
600 // already removed the directory. Continue with next.
601 }
597 catch (Exception e) 602 catch (Exception e)
598 { 603 {
599 m_log.Warn( 604 m_log.Warn(
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 2f67c4e..b24dc0c 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.Framework;
41using OpenSim.Region.Framework.Interfaces; 41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.Framework.Scenes.Serialization; 43using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces;
44 45
45namespace OpenSim.Region.CoreModules.Avatar.Attachments 46namespace OpenSim.Region.CoreModules.Avatar.Attachments
46{ 47{
@@ -303,6 +304,40 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
303 if (DebugLevel > 0) 304 if (DebugLevel > 0)
304 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name); 305 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
305 306
307 XmlDocument doc = new XmlDocument();
308 string stateData = String.Empty;
309
310 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
311 if (attServ != null)
312 {
313 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
314 stateData = attServ.Get(sp.UUID.ToString());
315 if (stateData != String.Empty)
316 {
317 try
318 {
319 doc.LoadXml(stateData);
320 }
321 catch { }
322 }
323 }
324
325 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
326
327 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
328 if (nodes.Count > 0)
329 {
330 foreach (XmlNode n in nodes)
331 {
332 XmlElement elem = (XmlElement)n;
333 string itemID = elem.GetAttribute("ItemID");
334 string xml = elem.InnerXml;
335
336 itemData[new UUID(itemID)] = xml;
337 }
338 }
339
340
306 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); 341 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments();
307 342
308 // Let's get all items at once, so they get cached 343 // Let's get all items at once, so they get cached
@@ -330,10 +365,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
330 365
331 try 366 try
332 { 367 {
368 string xmlData;
369 XmlDocument d = null;
370 UUID asset;
371 if (itemData.TryGetValue(attach.ItemID, out xmlData))
372 {
373 d = new XmlDocument();
374 d.LoadXml(xmlData);
375 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", attach.ItemID);
376 }
377
333 // If we're an NPC then skip all the item checks and manipulations since we don't have an 378 // If we're an NPC then skip all the item checks and manipulations since we don't have an
334 // inventory right now. 379 // inventory right now.
335 RezSingleAttachmentFromInventoryInternal( 380 RezSingleAttachmentFromInventoryInternal(
336 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true); 381 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true, d);
337 } 382 }
338 catch (Exception e) 383 catch (Exception e)
339 { 384 {
@@ -361,6 +406,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
361 406
362 Dictionary<SceneObjectGroup, string> scriptStates = new Dictionary<SceneObjectGroup, string>(); 407 Dictionary<SceneObjectGroup, string> scriptStates = new Dictionary<SceneObjectGroup, string>();
363 408
409<<<<<<< HEAD
364 foreach (SceneObjectGroup so in attachments) 410 foreach (SceneObjectGroup so in attachments)
365 { 411 {
366 // Scripts MUST be snapshotted before the object is 412 // Scripts MUST be snapshotted before the object is
@@ -376,12 +422,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
376 } 422 }
377 423
378 lock (sp.AttachmentsSyncLock) 424 lock (sp.AttachmentsSyncLock)
425=======
426 if (sp.PresenceType != PresenceType.Npc)
427>>>>>>> avn/ubitvar
379 { 428 {
380 foreach (SceneObjectGroup so in attachments) 429 foreach (SceneObjectGroup so in attachments)
381 UpdateDetachedObject(sp, so, scriptStates[so]); 430 {
382 431 // Scripts MUST be snapshotted before the object is
383 sp.ClearAttachments(); 432 // removed from the scene because doing otherwise will
433 // clobber the run flag
434 // This must be done outside the sp.AttachmentSyncLock so that there is no risk of a deadlock from
435 // scripts performing attachment operations at the same time. Getting object states stops the scripts.
436 scriptStates[so] = PrepareScriptInstanceForSave(so, false);
437 }
438
439 lock (sp.AttachmentsSyncLock)
440 {
441 foreach (SceneObjectGroup so in attachments)
442 UpdateDetachedObject(sp, so, scriptStates[so]);
443 sp.ClearAttachments();
444 }
384 } 445 }
446 else
447 {
448 lock (sp.AttachmentsSyncLock)
449 {
450 foreach (SceneObjectGroup so in attachments)
451 UpdateDetachedObject(sp, so, String.Empty);
452 sp.ClearAttachments();
453 }
454 }
385 } 455 }
386 456
387 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) 457 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent)
@@ -402,12 +472,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
402 sp.ClearAttachments(); 472 sp.ClearAttachments();
403 } 473 }
404 474
405 public bool AttachObject( 475 public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool append)
406 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool append)
407 { 476 {
408 if (!Enabled) 477 if (!Enabled)
409 return false; 478 return false;
410 479
480<<<<<<< HEAD
411 group.DetachFromBackup(); 481 group.DetachFromBackup();
412 482
413 bool success = AttachObjectInternal(sp, group, attachmentPt, silent, addToInventory, false, append); 483 bool success = AttachObjectInternal(sp, group, attachmentPt, silent, addToInventory, false, append);
@@ -416,6 +486,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
416 group.AttachToBackup(); 486 group.AttachToBackup();
417 487
418 return success; 488 return success;
489=======
490 return AttachObjectInternal(sp, group, attachmentPt, silent, useAttachData, addToInventory, false, append);
491>>>>>>> avn/ubitvar
419 } 492 }
420 493
421 /// <summary> 494 /// <summary>
@@ -428,10 +501,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
428 /// <param name='silent'></param> 501 /// <param name='silent'></param>
429 /// <param name='addToInventory'>If true then add object to user inventory.</param> 502 /// <param name='addToInventory'>If true then add object to user inventory.</param>
430 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param> 503 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param>
431 /// <param name='append'>Append to attachment point rather than replace.</param> 504 private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool resumeScripts, bool append)
432 private bool AttachObjectInternal(
433 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool resumeScripts, bool append)
434 { 505 {
506// m_log.DebugFormat(
507// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
508// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
509
510 if (sp.GetAttachments().Contains(group))
511 {
512// m_log.WarnFormat(
513// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
514// group.Name, group.LocalId, sp.Name, AttachmentPt);
515
516 return false;
517 }
518
435 if (group.GetSittingAvatarsCount() != 0) 519 if (group.GetSittingAvatarsCount() != 0)
436 { 520 {
437 if (DebugLevel > 0) 521 if (DebugLevel > 0)
@@ -443,6 +527,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
443 } 527 }
444 528
445 Vector3 attachPos = group.AbsolutePosition; 529 Vector3 attachPos = group.AbsolutePosition;
530
531 // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
532 // be removed when that functionality is implemented in opensim
533 attachmentPt &= 0x7f;
534
446 // If the attachment point isn't the same as the one previously used 535 // If the attachment point isn't the same as the one previously used
447 // set it's offset position = 0 so that it appears on the attachment point 536 // set it's offset position = 0 so that it appears on the attachment point
448 // and not in a weird location somewhere unknown. 537 // and not in a weird location somewhere unknown.
@@ -481,9 +570,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
481 attachPos = Vector3.Zero; 570 attachPos = Vector3.Zero;
482 } 571 }
483 572
484 group.AttachmentPoint = attachmentPt;
485 group.AbsolutePosition = attachPos;
486
487 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); 573 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
488 574
489 if (attachments.Contains(group)) 575 if (attachments.Contains(group))
@@ -516,6 +602,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
516 602
517 lock (sp.AttachmentsSyncLock) 603 lock (sp.AttachmentsSyncLock)
518 { 604 {
605 group.AttachmentPoint = attachmentPt;
606 group.AbsolutePosition = attachPos;
607
519 if (addToInventory && sp.PresenceType != PresenceType.Npc) 608 if (addToInventory && sp.PresenceType != PresenceType.Npc)
520 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append); 609 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append);
521 610
@@ -546,7 +635,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
546 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append); 635 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append);
547 } 636 }
548 637
549 public SceneObjectGroup RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) 638 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt)
639 {
640 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, null);
641 }
642
643 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt, XmlDocument doc)
550 { 644 {
551 if (!Enabled) 645 if (!Enabled)
552 return null; 646 return null;
@@ -584,7 +678,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
584 bool append = (AttachmentPt & 0x80) != 0; 678 bool append = (AttachmentPt & 0x80) != 0;
585 AttachmentPt &= 0x7f; 679 AttachmentPt &= 0x7f;
586 680
587 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append); 681 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append, doc);
588 } 682 }
589 683
590 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist) 684 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist)
@@ -649,26 +743,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
649 if (changed && m_scene.AvatarFactory != null) 743 if (changed && m_scene.AvatarFactory != null)
650 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); 744 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
651 745
746 so.RootPart.Shape.LastAttachPoint = (byte)so.AttachmentPoint;
747
652 sp.RemoveAttachment(so); 748 sp.RemoveAttachment(so);
653 so.FromItemID = UUID.Zero; 749 so.FromItemID = UUID.Zero;
654 750
751 so.AttachedAvatar = UUID.Zero;
752 so.ClearPartAttachmentData();
753
655 SceneObjectPart rootPart = so.RootPart; 754 SceneObjectPart rootPart = so.RootPart;
755
756 rootPart.SetParentLocalId(0);
656 so.AbsolutePosition = absolutePos; 757 so.AbsolutePosition = absolutePos;
657 if (absoluteRot != Quaternion.Identity) 758 if (absoluteRot != Quaternion.Identity)
658 { 759 {
659 so.UpdateGroupRotationR(absoluteRot); 760 so.UpdateGroupRotationR(absoluteRot);
660 } 761 }
661 so.AttachedAvatar = UUID.Zero; 762
662 rootPart.SetParentLocalId(0); 763 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
663 so.ClearPartAttachmentData(); 764
664 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive); 765 // not physical, not temporary, phaton, not volume detector
766// so.UpdatePrimFlags(rootPart.LocalId,false,false,true,rootPart.VolumeDetectActive);
767
768 // restore full physical state instead
769 so.ApplyPhysics();
770
665 so.HasGroupChanged = true; 771 so.HasGroupChanged = true;
666 so.RootPart.Shape.LastAttachPoint = (byte)so.AttachmentPoint;
667 rootPart.Rezzed = DateTime.Now; 772 rootPart.Rezzed = DateTime.Now;
668 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
669 so.AttachToBackup(); 773 so.AttachToBackup();
670 m_scene.EventManager.TriggerParcelPrimCountTainted(); 774 m_scene.EventManager.TriggerParcelPrimCountTainted();
671 rootPart.ScheduleFullUpdate(); 775
672 rootPart.ClearUndoState(); 776 rootPart.ClearUndoState();
673 777
674 List<UUID> uuids = new List<UUID>(); 778 List<UUID> uuids = new List<UUID>();
@@ -678,6 +782,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
678 } 782 }
679 783
680 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); 784 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero);
785
786 // Attach (NULL) stops scripts. We don't want that. Resume them.
787 so.ResumeScripts();
788 so.ScheduleGroupForTerseUpdate();
789 so.RootPart.ScheduleFullUpdate();
681 } 790 }
682 791
683 public void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup so) 792 public void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup so)
@@ -848,8 +957,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
848 957
849 so.AttachedAvatar = sp.UUID; 958 so.AttachedAvatar = sp.UUID;
850 959
851 if (so.RootPart.PhysActor != null) 960 foreach (SceneObjectPart part in so.Parts)
852 so.RootPart.RemoveFromPhysics(); 961 {
962// if (part.KeyframeMotion != null)
963// part.KeyframeMotion.Suspend();
964
965 if (part.PhysActor != null)
966 {
967 part.RemoveFromPhysics();
968 }
969 }
853 970
854 so.AbsolutePosition = attachOffset; 971 so.AbsolutePosition = attachOffset;
855 so.RootPart.AttachedPos = attachOffset; 972 so.RootPart.AttachedPos = attachOffset;
@@ -971,6 +1088,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
971 // Remove the object from the scene so no more updates 1088 // Remove the object from the scene so no more updates
972 // are sent. Doing this before the below changes will ensure 1089 // are sent. Doing this before the below changes will ensure
973 // updates can't cause "HUD artefacts" 1090 // updates can't cause "HUD artefacts"
1091
974 m_scene.DeleteSceneObject(so, false, false); 1092 m_scene.DeleteSceneObject(so, false, false);
975 1093
976 // Prepare sog for storage 1094 // Prepare sog for storage
@@ -992,7 +1110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
992 } 1110 }
993 1111
994 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( 1112 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
995 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append) 1113 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append, XmlDocument doc)
996 { 1114 {
997 if (m_invAccessModule == null) 1115 if (m_invAccessModule == null)
998 return null; 1116 return null;
@@ -1043,7 +1161,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1043 // This will throw if the attachment fails 1161 // This will throw if the attachment fails
1044 try 1162 try
1045 { 1163 {
1046 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, append); 1164 if (doc != null)
1165 {
1166 objatt.LoadScriptState(doc);
1167 objatt.ResetOwnerChangeFlag();
1168 }
1169
1170 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, true, append);
1047 } 1171 }
1048 catch (Exception e) 1172 catch (Exception e)
1049 { 1173 {
@@ -1197,7 +1321,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1197 AttachmentPt &= 0x7f; 1321 AttachmentPt &= 0x7f;
1198 1322
1199 // Calls attach with a Zero position 1323 // Calls attach with a Zero position
1200 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true, append)) 1324 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, true, append))
1201 { 1325 {
1202 if (DebugLevel > 0) 1326 if (DebugLevel > 0)
1203 m_log.Debug( 1327 m_log.Debug(
@@ -1205,7 +1329,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1205 + ", AttachmentPoint: " + AttachmentPt); 1329 + ", AttachmentPoint: " + AttachmentPt);
1206 1330
1207 // Save avatar attachment information 1331 // Save avatar attachment information
1208 m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); 1332 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
1209 } 1333 }
1210 } 1334 }
1211 catch (Exception e) 1335 catch (Exception e)
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index f1b002b..b632774 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -201,7 +201,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
201 Assert.That(so.Backup, Is.True); 201 Assert.That(so.Backup, Is.True);
202 202
203 m_numberOfAttachEventsFired = 0; 203 m_numberOfAttachEventsFired = 0;
204 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false); 204 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false, false);
205 205
206 // Check status on scene presence 206 // Check status on scene presence
207 Assert.That(sp.HasAttachments(), Is.True); 207 Assert.That(sp.HasAttachments(), Is.True);
@@ -249,7 +249,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
249 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "att1", sp.UUID); 249 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "att1", sp.UUID);
250 250
251 m_numberOfAttachEventsFired = 0; 251 m_numberOfAttachEventsFired = 0;
252 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Default, false, true, false); 252 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Default, false, true, false, false);
253 253
254 // Check status on scene presence 254 // Check status on scene presence
255 Assert.That(sp.HasAttachments(), Is.True); 255 Assert.That(sp.HasAttachments(), Is.True);
@@ -282,7 +282,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
282 282
283 // Test wearing a different attachment from the ground. 283 // Test wearing a different attachment from the ground.
284 { 284 {
285 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false); 285 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false, false);
286 286
287 // Check status on scene presence 287 // Check status on scene presence
288 Assert.That(sp.HasAttachments(), Is.True); 288 Assert.That(sp.HasAttachments(), Is.True);
@@ -315,7 +315,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
315 315
316 // Test rewearing an already worn attachment from ground. Nothing should happen. 316 // Test rewearing an already worn attachment from ground. Nothing should happen.
317 { 317 {
318 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false); 318 scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false, false);
319 319
320 // Check status on scene presence 320 // Check status on scene presence
321 Assert.That(sp.HasAttachments(), Is.True); 321 Assert.That(sp.HasAttachments(), Is.True);
@@ -373,7 +373,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
373 sp2.AbsolutePosition = new Vector3(0, 0, 0); 373 sp2.AbsolutePosition = new Vector3(0, 0, 0);
374 sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero); 374 sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero);
375 375
376 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false); 376 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false, false);
377 377
378 Assert.That(sp.HasAttachments(), Is.False); 378 Assert.That(sp.HasAttachments(), Is.False);
379 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); 379 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
@@ -671,7 +671,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
671 scene.EventManager.OnChatFromWorld += OnChatFromWorld; 671 scene.EventManager.OnChatFromWorld += OnChatFromWorld;
672 672
673 SceneObjectGroup rezzedSo 673 SceneObjectGroup rezzedSo
674 = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); 674 = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));
675 675
676 // Wait for chat to signal rezzed script has been started. 676 // Wait for chat to signal rezzed script has been started.
677 m_chatEvent.WaitOne(60000); 677 m_chatEvent.WaitOne(60000);
@@ -690,7 +690,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
690 Assert.That(scriptStateNodes.Count, Is.EqualTo(1)); 690 Assert.That(scriptStateNodes.Count, Is.EqualTo(1));
691 691
692 // Re-rez the attachment to check script running state 692 // Re-rez the attachment to check script running state
693 SceneObjectGroup reRezzedSo = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); 693 SceneObjectGroup reRezzedSo = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));
694 694
695 // Wait for chat to signal rezzed script has been started. 695 // Wait for chat to signal rezzed script has been started.
696 m_chatEvent.WaitOne(60000); 696 m_chatEvent.WaitOne(60000);
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index cfb082b..1e9cfba 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -188,27 +188,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
188 // Process the visual params, this may change height as well 188 // Process the visual params, this may change height as well
189 if (visualParams != null) 189 if (visualParams != null)
190 { 190 {
191 // string[] visualParamsStrings = new string[visualParams.Length];
192 // for (int i = 0; i < visualParams.Length; i++)
193 // visualParamsStrings[i] = visualParams[i].ToString();
194 // m_log.DebugFormat(
195 // "[AVFACTORY]: Setting visual params for {0} to {1}",
196 // client.Name, string.Join(", ", visualParamsStrings));
197/*
198 float oldHeight = sp.Appearance.AvatarHeight;
199 changed = sp.Appearance.SetVisualParams(visualParams);
200
201 if (sp.Appearance.AvatarHeight != oldHeight && sp.Appearance.AvatarHeight > 0)
202 ((ScenePresence)sp).SetHeight(sp.Appearance.AvatarHeight);
203 */
204// float oldoff = sp.Appearance.AvatarFeetOffset;
205// Vector3 oldbox = sp.Appearance.AvatarBoxSize;
206 changed = sp.Appearance.SetVisualParams(visualParams); 191 changed = sp.Appearance.SetVisualParams(visualParams);
207// float off = sp.Appearance.AvatarFeetOffset;
208// Vector3 box = sp.Appearance.AvatarBoxSize;
209// if(oldoff != off || oldbox != box)
210// ((ScenePresence)sp).SetSize(box,off);
211
212 } 192 }
213 193
214 // Process the baked texture array 194 // Process the baked texture array
@@ -222,9 +202,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
222 202
223// WriteBakedTexturesReport(sp, m_log.DebugFormat); 203// WriteBakedTexturesReport(sp, m_log.DebugFormat);
224 204
225 // If bake textures are missing and this is not an NPC, request a rebake from client 205 UpdateBakedTextureCache(sp, cacheItems);
226 if (!ValidateBakedTextureCache(sp) && (((ScenePresence)sp).PresenceType != PresenceType.Npc))
227 RequestRebake(sp, true);
228 206
229 // This appears to be set only in the final stage of the appearance 207 // This appears to be set only in the final stage of the appearance
230 // update transaction. In theory, we should be able to do an immediate 208 // update transaction. In theory, we should be able to do an immediate
@@ -377,114 +355,335 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
377 } 355 }
378 } 356 }
379 357
380 public bool ValidateBakedTextureCache(IScenePresence sp) 358 // called on textures update
359 public bool UpdateBakedTextureCache(IScenePresence sp, WearableCacheItem[] cacheItems)
381 { 360 {
382 bool defonly = true; // are we only using default textures 361 // npcs dont have baked cache
383 IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>(); 362 if (((ScenePresence)sp).isNPC)
384 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); 363 return true;
385 WearableCacheItem[] wearableCache = null; 364
386 365 // uploaded baked textures will be in assets local cache
387 // Cache wearable data for teleport. 366 IAssetService cache = m_scene.AssetService;
388 // Only makes sense if there's a bake module and a cache module 367 IBakedTextureModule m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
389 if (bakedModule != null && cache != null) 368
369 int validDirtyBakes = 0;
370 int hits = 0;
371
372 // our main cacheIDs mapper is p.Appearance.WearableCacheItems
373 WearableCacheItem[] wearableCache = sp.Appearance.WearableCacheItems;
374
375 if (wearableCache == null)
390 { 376 {
391 try 377 wearableCache = WearableCacheItem.GetDefaultCacheItem();
392 { 378 }
393 wearableCache = bakedModule.Get(sp.UUID); 379
394 } 380 List<UUID> missing = new List<UUID>();
395 catch (Exception) 381
396 { 382 // Process received baked textures
383 for (int i = 0; i < cacheItems.Length; i++)
384 {
385 int idx = (int)cacheItems[i].TextureIndex;
386 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx];
397 387
388 // No face
389 if (face == null)
390 {
391 // for some reason viewer is cleaning this
392 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx);
393 sp.Appearance.Texture.FaceTextures[idx].TextureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE;
394 wearableCache[idx].CacheId = UUID.Zero;
395 wearableCache[idx].TextureID = UUID.Zero;
396 wearableCache[idx].TextureAsset = null;
397 continue;
398 } 398 }
399 if (wearableCache != null) 399 else
400 { 400 {
401 for (int i = 0; i < wearableCache.Length; i++) 401 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
402 { 402 {
403 cache.Cache(wearableCache[i].TextureAsset); 403 wearableCache[idx].CacheId = UUID.Zero;
404 wearableCache[idx].TextureID = UUID.Zero;
405 wearableCache[idx].TextureAsset = null;
406 continue;
404 } 407 }
405 } 408
406 } 409/*
407 /* 410 if (face.TextureID == wearableCache[idx].TextureID && m_BakedTextureModule != null)
408 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
409 if (invService.GetRootFolder(userID) != null)
410 {
411 WearableCacheItem[] wearableCache = null;
412 if (bakedModule != null)
413 {
414 try
415 { 411 {
416 wearableCache = bakedModule.Get(userID); 412 if (wearableCache[idx].CacheId != cacheItems[i].CacheId)
417 appearance.WearableCacheItems = wearableCache;
418 appearance.WearableCacheItemsDirty = false;
419 foreach (WearableCacheItem item in wearableCache)
420 { 413 {
421 appearance.Texture.FaceTextures[item.TextureIndex].TextureID = item.TextureID; 414 wearableCache[idx].CacheId = cacheItems[i].CacheId;
415 validDirtyBakes++;
416
417 //assuming this can only happen if asset is in cache
422 } 418 }
419 hits++;
420 continue;
421 }
422*/
423 wearableCache[idx].TextureAsset = null;
424 if (cache != null)
425 wearableCache[idx].TextureAsset = cache.GetCached(face.TextureID.ToString());
426
427 if (wearableCache[idx].TextureAsset != null)
428 {
429 if ( wearableCache[idx].TextureID != face.TextureID ||
430 wearableCache[idx].CacheId != cacheItems[i].CacheId)
431 validDirtyBakes++;
432
433 wearableCache[idx].TextureID = face.TextureID;
434 wearableCache[idx].CacheId = cacheItems[i].CacheId;
435 hits++;
423 } 436 }
424 catch (Exception) 437 else
425 { 438 {
426 439 wearableCache[idx].CacheId = UUID.Zero;
440 wearableCache[idx].TextureID = UUID.Zero;
441 wearableCache[idx].TextureAsset = null;
442 missing.Add(face.TextureID);
443 continue;
427 } 444 }
428 } 445 }
429 */ 446 }
430 447
431 // Process the texture entry 448 sp.Appearance.WearableCacheItems = wearableCache;
432 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++) 449
450 if (missing.Count > 0)
433 { 451 {
434 int idx = AvatarAppearance.BAKE_INDICES[i]; 452 foreach (UUID id in missing)
435 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx]; 453 sp.ControllingClient.SendRebakeAvatarTextures(id);
454 }
436 455
437 // No face, so lets check our baked service cache, teleport or login. 456 if (validDirtyBakes > 0 && hits == cacheItems.Length)
438 if (face == null) 457 {
458 // if we got a full set of baked textures save all in BakedTextureModule
459 if (m_BakedTextureModule != null)
439 { 460 {
440 if (wearableCache != null) 461 m_log.Debug("[UpdateBakedCache] uploading to bakedModule cache");
462
463 m_BakedTextureModule.Store(sp.UUID);
464 }
465 }
466
467
468 // debug
469 m_log.Debug("[UpdateBakedCache] cache hits: " + hits.ToString() + " changed entries: " + validDirtyBakes.ToString() + " rebakes " + missing.Count);
470/*
471 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
472 {
473 int j = AvatarAppearance.BAKE_INDICES[iter];
474 m_log.Debug("[UpdateBCache] {" + iter + "/" +
475 sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" +
476 sp.Appearance.WearableCacheItems[j].CacheId + ", t-" +
477 sp.Appearance.WearableCacheItems[j].TextureID);
478 }
479*/
480 return (hits == cacheItems.Length);
481 }
482
483 // called when we get a new root avatar
484 public bool ValidateBakedTextureCache(IScenePresence sp)
485 {
486 int hits = 0;
487
488 if (((ScenePresence)sp).isNPC)
489 return true;
490
491 lock (m_setAppearanceLock)
492 {
493 IAssetService cache = m_scene.AssetService;
494 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
495 WearableCacheItem[] bakedModuleCache = null;
496
497 if (cache == null)
498 return false;
499
500 WearableCacheItem[] wearableCache = sp.Appearance.WearableCacheItems;
501
502 // big debug
503 m_log.DebugFormat("[AVFACTORY]: ValidateBakedTextureCache start for {0} {1}", sp.Name, sp.UUID);
504/*
505 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
506 {
507 int j = AvatarAppearance.BAKE_INDICES[iter];
508 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[j];
509 if (wearableCache == null)
441 { 510 {
442 // If we find the an appearance item, set it as the textureentry and the face 511 if (face != null)
443 WearableCacheItem searchitem = WearableCacheItem.SearchTextureIndex((uint) idx, wearableCache); 512 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t- " + face.TextureID);
444 if (searchitem != null)
445 {
446 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx);
447 sp.Appearance.Texture.FaceTextures[idx].TextureID = searchitem.TextureID;
448 face = sp.Appearance.Texture.FaceTextures[idx];
449 }
450 else 513 else
451 { 514 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t- No texture");
452 // if there is no texture entry and no baked cache, skip it
453 continue;
454 }
455 } 515 }
456 else 516 else
457 { 517 {
458 //No texture entry face and no cache. Skip this face. 518 if (face != null)
459 continue; 519 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " ft- " + face.TextureID +
520 "}: cc-" +
521 wearableCache[j].CacheId + ", ct-" +
522 wearableCache[j].TextureID
523 );
524 else
525 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t - No texture" +
526 "}: cc-" +
527 wearableCache[j].CacheId + ", ct-" +
528 wearableCache[j].TextureID
529 );
460 } 530 }
461 } 531 }
532<<<<<<< HEAD
462 533
463// m_log.DebugFormat( 534// m_log.DebugFormat(
464// "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}", 535// "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}",
465// face.TextureID, idx, client.Name, client.AgentId); 536// face.TextureID, idx, client.Name, client.AgentId);
537=======
538*/
539 bool wearableCacheValid = false;
540 if (wearableCache == null)
541 {
542 wearableCache = WearableCacheItem.GetDefaultCacheItem();
543 }
544 else
545 {
546 // we may have received a full cache
547 // check same coerence and store
548 wearableCacheValid = true;
549 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++)
550 {
551 int idx = AvatarAppearance.BAKE_INDICES[i];
552 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx];
553 if (face != null)
554 {
555 if (face.TextureID == wearableCache[idx].TextureID &&
556 face.TextureID != UUID.Zero)
557 {
558 if (wearableCache[idx].TextureAsset != null)
559 {
560 hits++;
561 wearableCache[idx].TextureAsset.Temporary = true;
562 wearableCache[idx].TextureAsset.Local = true;
563 cache.Store(wearableCache[idx].TextureAsset);
564 continue;
565 }
566 if (cache.GetCached((wearableCache[idx].TextureID).ToString()) != null)
567 {
568 hits++;
569 continue;
570 }
571 }
572 wearableCacheValid = false;
573 }
574 }
575
576 wearableCacheValid = (wearableCacheValid && (hits >= AvatarAppearance.BAKE_INDICES.Length - 1));
577 if (wearableCacheValid)
578 m_log.Debug("[ValidateBakedCache] have valid local cache");
579 }
580>>>>>>> avn/ubitvar
466 581
467 // if the texture is one of the "defaults" then skip it 582 bool checkExternal = false;
468 // this should probably be more intelligent (skirt texture doesnt matter
469 // if the avatar isnt wearing a skirt) but if any of the main baked
470 // textures is default then the rest should be as well
471 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
472 continue;
473
474 defonly = false; // found a non-default texture reference
475 583
584<<<<<<< HEAD
476 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) 585 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null)
477 return false; 586 return false;
478 } 587 }
588=======
589 if (!wearableCacheValid)
590 {
591 // only use external bake module on login condition check
592// ScenePresence ssp = null;
593// if (sp is ScenePresence)
594 {
595// ssp = (ScenePresence)sp;
596// checkExternal = (((uint)ssp.TeleportFlags & (uint)TeleportFlags.ViaLogin) != 0) &&
597// bakedModule != null;
598
599 // or do it anytime we dont have the cache
600 checkExternal = bakedModule != null;
601 }
602 }
479 603
480// m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1}", sp.Name, sp.UUID); 604 if (checkExternal)
605 {
606 hits = 0;
607 bool gotbacked = false;
481 608
482 // If we only found default textures, then the appearance is not cached 609 m_log.Debug("[ValidateBakedCache] local cache invalid, checking bakedModule");
483 return (defonly ? false : true); 610 try
611 {
612 bakedModuleCache = bakedModule.Get(sp.UUID);
613 }
614 catch (Exception e)
615 {
616 m_log.ErrorFormat(e.ToString());
617 bakedModuleCache = null;
618 }
619
620 if (bakedModuleCache != null)
621 {
622 m_log.Debug("[ValidateBakedCache] got bakedModule " + bakedModuleCache.Length + " cached textures");
623
624 for (int i = 0; i < bakedModuleCache.Length; i++)
625 {
626 int j = (int)bakedModuleCache[i].TextureIndex;
627
628 if (bakedModuleCache[i].TextureAsset != null)
629 {
630 wearableCache[j].TextureID = bakedModuleCache[i].TextureID;
631 wearableCache[j].CacheId = bakedModuleCache[i].CacheId;
632 wearableCache[j].TextureAsset = bakedModuleCache[i].TextureAsset;
633 bakedModuleCache[i].TextureAsset.Temporary = true;
634 bakedModuleCache[i].TextureAsset.Local = true;
635 cache.Store(bakedModuleCache[i].TextureAsset);
636 }
637 }
638 gotbacked = true;
639 }
640
641 if (gotbacked)
642 {
643 // force the ones we got
644 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++)
645 {
646 int idx = AvatarAppearance.BAKE_INDICES[i];
647 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx];
648
649 if (sp.Appearance.Texture.FaceTextures[idx] == null)
650 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint)idx);
651 sp.Appearance.Texture.FaceTextures[idx].TextureID = wearableCache[idx].TextureID;
652 face = sp.Appearance.Texture.FaceTextures[idx];
653
654 // this should be removed
655 if (face.TextureID != UUID.Zero && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE)
656 hits++;
657 continue;
658 }
659 }
660 }
661>>>>>>> avn/ubitvar
662
663 sp.Appearance.WearableCacheItems = wearableCache;
664
665 }
666
667 // debug
668 m_log.DebugFormat("[ValidateBakedCache]: Completed texture check for {0} {1} with {2} hits", sp.Name, sp.UUID, hits);
669/*
670 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
671 {
672 int j = AvatarAppearance.BAKE_INDICES[iter];
673 m_log.Debug("[ValidateBakedCache] {" + iter + "/" +
674 sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" +
675 sp.Appearance.WearableCacheItems[j].CacheId + ", t-" +
676 sp.Appearance.WearableCacheItems[j].TextureID);
677 }
678*/
679 return (hits >= AvatarAppearance.BAKE_INDICES.Length - 1); // skirt is optional
484 } 680 }
485 681
486 public int RequestRebake(IScenePresence sp, bool missingTexturesOnly) 682 public int RequestRebake(IScenePresence sp, bool missingTexturesOnly)
487 { 683 {
684 if (((ScenePresence)sp).isNPC)
685 return 0;
686
488 int texturesRebaked = 0; 687 int texturesRebaked = 0;
489// IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>(); 688// IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>();
490 689
@@ -497,14 +696,6 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
497 if (face == null) 696 if (face == null)
498 continue; 697 continue;
499 698
500// m_log.DebugFormat(
501// "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}",
502// face.TextureID, idx, client.Name, client.AgentId);
503
504 // if the texture is one of the "defaults" then skip it
505 // this should probably be more intelligent (skirt texture doesnt matter
506 // if the avatar isnt wearing a skirt) but if any of the main baked
507 // textures is default then the rest should be as well
508 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE) 699 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
509 continue; 700 continue;
510 701
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
index 9513408..b7ff4e0 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/Tests/AvatarFactoryModuleTests.cs
@@ -132,6 +132,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
132 for (byte i = 0; i < visualParams.Length; i++) 132 for (byte i = 0; i < visualParams.Length; i++)
133 visualParams[i] = i; 133 visualParams[i] = i;
134 134
135<<<<<<< HEAD
135 Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10)); 136 Primitive.TextureEntry bakedTextureEntry = new Primitive.TextureEntry(TestHelpers.ParseTail(0x10));
136 uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes); 137 uint eyesFaceIndex = (uint)AppearanceManager.BakeTypeToAgentTextureIndex(BakeType.Eyes);
137 Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex); 138 Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
@@ -144,6 +145,12 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
144 afm.SetAppearance(sp, bakedTextureEntry, visualParams, null); 145 afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
145 146
146 Assert.That(rebakeRequestsReceived, Is.EqualTo(0)); 147 Assert.That(rebakeRequestsReceived, Is.EqualTo(0));
148=======
149 afm.SetAppearance(sp, new Primitive.TextureEntry(TestHelpers.ParseTail(0x10)), visualParams, new WearableCacheItem[0]);
150
151 // TODO: Check baked texture
152 Assert.AreEqual(visualParams, sp.Appearance.VisualParams);
153>>>>>>> avn/ubitvar
147 } 154 }
148 155
149 [Test] 156 [Test]
@@ -181,7 +188,11 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
181 Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex); 188 Primitive.TextureEntryFace eyesFace = bakedTextureEntry.CreateFace(eyesFaceIndex);
182 eyesFace.TextureID = eyesTextureId; 189 eyesFace.TextureID = eyesTextureId;
183 190
191<<<<<<< HEAD
184 afm.SetAppearance(sp, bakedTextureEntry, visualParams, null); 192 afm.SetAppearance(sp, bakedTextureEntry, visualParams, null);
193=======
194 afm.SetAppearance(sp, bakedTextureEntry, visualParams, new WearableCacheItem[0]);
195>>>>>>> avn/ubitvar
185 afm.SaveBakedTextures(userId); 196 afm.SaveBakedTextures(userId);
186// Dictionary<BakeType, Primitive.TextureEntryFace> bakedTextures = afm.GetBakedTextureFaces(userId); 197// Dictionary<BakeType, Primitive.TextureEntryFace> bakedTextures = afm.GetBakedTextureFaces(userId);
187 198
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
index a9d2de0..2801ef0 100644
--- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
@@ -51,7 +51,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
51 private int m_saydistance = 20; 51 private int m_saydistance = 20;
52 private int m_shoutdistance = 100; 52 private int m_shoutdistance = 100;
53 private int m_whisperdistance = 10; 53 private int m_whisperdistance = 10;
54 54 private List<Scene> m_scenes = new List<Scene>();
55 private List<string> FreezeCache = new List<string>();
56 private string m_adminPrefix = "";
55 internal object m_syncy = new object(); 57 internal object m_syncy = new object();
56 58
57 internal IConfig m_config; 59 internal IConfig m_config;
@@ -78,16 +80,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
78 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); 80 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance);
79 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); 81 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance);
80 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); 82 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance);
83 m_adminPrefix = config.Configs["Chat"].GetString("admin_prefix", "");
81 } 84 }
82 85
83 public virtual void AddRegion(Scene scene) 86 public virtual void AddRegion(Scene scene)
84 { 87 {
85 if (!m_enabled) 88 if (!m_enabled) return;
86 return;
87 89
88 scene.EventManager.OnNewClient += OnNewClient; 90 lock (m_syncy)
89 scene.EventManager.OnChatFromWorld += OnChatFromWorld; 91 {
90 scene.EventManager.OnChatBroadcast += OnChatBroadcast; 92 if (!m_scenes.Contains(scene))
93 {
94 m_scenes.Add(scene);
95 scene.EventManager.OnNewClient += OnNewClient;
96 scene.EventManager.OnChatFromWorld += OnChatFromWorld;
97 scene.EventManager.OnChatBroadcast += OnChatBroadcast;
98 }
99 }
91 100
92 m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, 101 m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName,
93 m_whisperdistance, m_saydistance, m_shoutdistance); 102 m_whisperdistance, m_saydistance, m_shoutdistance);
@@ -107,12 +116,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
107 116
108 public virtual void RemoveRegion(Scene scene) 117 public virtual void RemoveRegion(Scene scene)
109 { 118 {
110 if (!m_enabled) 119 if (!m_enabled) return;
111 return;
112 120
113 scene.EventManager.OnNewClient -= OnNewClient; 121 lock (m_syncy)
114 scene.EventManager.OnChatFromWorld -= OnChatFromWorld; 122 {
115 scene.EventManager.OnChatBroadcast -= OnChatBroadcast; 123 if (m_scenes.Contains(scene))
124 {
125 scene.EventManager.OnNewClient -= OnNewClient;
126 scene.EventManager.OnChatFromWorld -= OnChatFromWorld;
127 scene.EventManager.OnChatBroadcast -= OnChatBroadcast;
128 m_scenes.Remove(scene);
129 }
130 }
116 } 131 }
117 132
118 public virtual void Close() 133 public virtual void Close()
@@ -169,7 +184,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
169 return; 184 return;
170 } 185 }
171 186
172 DeliverChatToAvatars(ChatSourceType.Agent, c); 187 if (FreezeCache.Contains(c.Sender.AgentId.ToString()))
188 {
189 if (c.Type != ChatTypeEnum.StartTyping || c.Type != ChatTypeEnum.StopTyping)
190 c.Sender.SendAgentAlertMessage("You may not talk as you are frozen.", false);
191 }
192 else
193 {
194 DeliverChatToAvatars(ChatSourceType.Agent, c);
195 }
173 } 196 }
174 197
175 public virtual void OnChatFromWorld(Object sender, OSChatMessage c) 198 public virtual void OnChatFromWorld(Object sender, OSChatMessage c)
@@ -183,33 +206,64 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
183 protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c) 206 protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c)
184 { 207 {
185 string fromName = c.From; 208 string fromName = c.From;
209 string fromNamePrefix = "";
186 UUID fromID = UUID.Zero; 210 UUID fromID = UUID.Zero;
187 UUID ownerID = UUID.Zero; 211 UUID ownerID = UUID.Zero;
188 UUID targetID = c.TargetUUID;
189 string message = c.Message; 212 string message = c.Message;
190 Scene scene = (Scene)c.Scene; 213 IScene scene = c.Scene;
214 UUID destination = c.Destination;
191 Vector3 fromPos = c.Position; 215 Vector3 fromPos = c.Position;
192 Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0); 216 Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0);
217<<<<<<< HEAD
218=======
219
220 bool checkParcelHide = false;
221 UUID sourceParcelID = UUID.Zero;
222 Vector3 hidePos = fromPos;
223>>>>>>> avn/ubitvar
193 224
194 if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; 225 if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel;
195 226
196 switch (sourceType) 227 switch (sourceType)
197 { 228 {
198 case ChatSourceType.Agent: 229 case ChatSourceType.Agent:
199 ScenePresence avatar = scene.GetScenePresence(c.Sender.AgentId); 230 if (!(scene is Scene))
231 {
232 m_log.WarnFormat("[CHAT]: scene {0} is not a Scene object, cannot obtain scene presence for {1}",
233 scene.RegionInfo.RegionName, c.Sender.AgentId);
234 return;
235 }
236 ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId);
200 fromPos = avatar.AbsolutePosition; 237 fromPos = avatar.AbsolutePosition;
201 fromName = avatar.Name; 238 fromName = avatar.Name;
202 fromID = c.Sender.AgentId; 239 fromID = c.Sender.AgentId;
240 if (avatar.GodLevel >= 200)
241 { // let gods speak to outside or things may get confusing
242 fromNamePrefix = m_adminPrefix;
243 checkParcelHide = false;
244 }
245 else
246 {
247 checkParcelHide = true;
248 }
249 destination = UUID.Zero; // Avatars cant "SayTo"
203 ownerID = c.Sender.AgentId; 250 ownerID = c.Sender.AgentId;
204 251
252 hidePos = fromPos;
205 break; 253 break;
206 254
207 case ChatSourceType.Object: 255 case ChatSourceType.Object:
208 fromID = c.SenderUUID; 256 fromID = c.SenderUUID;
209 257
210 if (c.SenderObject != null && c.SenderObject is SceneObjectPart) 258 if (c.SenderObject != null && c.SenderObject is SceneObjectPart)
259 {
211 ownerID = ((SceneObjectPart)c.SenderObject).OwnerID; 260 ownerID = ((SceneObjectPart)c.SenderObject).OwnerID;
212 261 if (((SceneObjectPart)c.SenderObject).ParentGroup.IsAttachment)
262 {
263 checkParcelHide = true;
264 hidePos = ((SceneObjectPart)c.SenderObject).ParentGroup.AbsolutePosition;
265 }
266 }
213 break; 267 break;
214 } 268 }
215 269
@@ -218,38 +272,68 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
218 message = message.Substring(0, 1000); 272 message = message.Substring(0, 1000);
219 273
220// m_log.DebugFormat( 274// m_log.DebugFormat(
221// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}, targetID {5}", 275// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}",
222// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType, targetID); 276// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType);
223 277
224 HashSet<UUID> receiverIDs = new HashSet<UUID>(); 278 HashSet<UUID> receiverIDs = new HashSet<UUID>();
225 279
226 if (targetID == UUID.Zero) 280 if (checkParcelHide)
281 {
282 checkParcelHide = false;
283 if (c.Type < ChatTypeEnum.DebugChannel && destination == UUID.Zero)
284 {
285 ILandObject srcland = (scene as Scene).LandChannel.GetLandObject(hidePos.X, hidePos.Y);
286 if (srcland != null && !srcland.LandData.SeeAVs)
287 {
288 sourceParcelID = srcland.LandData.GlobalID;
289 checkParcelHide = true;
290 }
291 }
292 }
293
294 foreach (Scene s in m_scenes)
227 { 295 {
228 // This should use ForEachClient, but clients don't have a position. 296 // This should use ForEachClient, but clients don't have a position.
229 // If camera is moved into client, then camera position can be used 297 // If camera is moved into client, then camera position can be used
230 scene.ForEachScenePresence( 298 // MT: No, it can't, as chat is heard from the avatar position, not
299 // the camera position.
300
301 s.ForEachScenePresence(
231 delegate(ScenePresence presence) 302 delegate(ScenePresence presence)
232 { 303 {
233 if (TrySendChatMessage( 304 if (destination != UUID.Zero && presence.UUID != destination)
234 presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false)) 305 return;
235 receiverIDs.Add(presence.UUID); 306 ILandObject Presencecheck = s.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y);
307 if (Presencecheck != null)
308 {
309 // This will pass all chat from objects. Not
310 // perfect, but it will do. For now. Better
311 // than the prior behavior of muting all
312 // objects on a parcel with access restrictions
313 if (checkParcelHide)
314 {
315 if (sourceParcelID != Presencecheck.LandData.GlobalID && presence.GodLevel < 200)
316 return;
317 }
318 if (c.Sender == null || Presencecheck.IsEitherBannedOrRestricted(c.Sender.AgentId) != true)
319 {
320 if (destination != UUID.Zero)
321 {
322 if (TrySendChatMessage(presence, fromPos, regionPos, fromID, ownerID, fromNamePrefix + fromName, c.Type, message, sourceType, true))
323 receiverIDs.Add(presence.UUID);
324 }
325 else
326 {
327 if (TrySendChatMessage(presence, fromPos, regionPos, fromID, ownerID, fromNamePrefix + fromName, c.Type, message, sourceType, false))
328 receiverIDs.Add(presence.UUID);
329 }
330 }
331 }
236 } 332 }
237 ); 333 );
238 } 334 }
239 else 335
240 { 336 (scene as Scene).EventManager.TriggerOnChatToClients(
241 // This is a send to a specific client eg from llRegionSayTo
242 // no need to check distance etc, jand send is as say
243 ScenePresence presence = scene.GetScenePresence(targetID);
244 if (presence != null && !presence.IsChildAgent)
245 {
246 if (TrySendChatMessage(
247 presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true))
248 receiverIDs.Add(presence.UUID);
249 }
250 }
251
252 scene.EventManager.TriggerOnChatToClients(
253 fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); 337 fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
254 } 338 }
255 339
@@ -291,9 +375,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
291 } 375 }
292 376
293 // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); 377 // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType);
294
295 HashSet<UUID> receiverIDs = new HashSet<UUID>(); 378 HashSet<UUID> receiverIDs = new HashSet<UUID>();
296 379
380<<<<<<< HEAD
297 ((Scene)c.Scene).ForEachRootClient( 381 ((Scene)c.Scene).ForEachRootClient(
298 delegate(IClientAPI client) 382 delegate(IClientAPI client)
299 { 383 {
@@ -313,6 +397,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
313 397
314 (c.Scene as Scene).EventManager.TriggerOnChatToClients( 398 (c.Scene as Scene).EventManager.TriggerOnChatToClients(
315 fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully); 399 fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully);
400=======
401 if (c.Scene != null)
402 {
403 ((Scene)c.Scene).ForEachRootClient
404 (
405 delegate(IClientAPI client)
406 {
407 // don't forward SayOwner chat from objects to
408 // non-owner agents
409 if ((c.Type == ChatTypeEnum.Owner) &&
410 (null != c.SenderObject) &&
411 (((SceneObjectPart)c.SenderObject).OwnerID != client.AgentId))
412 return;
413
414 client.SendChatMessage(c.Message, (byte)cType, CenterOfRegion, fromName, fromID, fromID,
415 (byte)sourceType, (byte)ChatAudibleLevel.Fully);
416 receiverIDs.Add(client.AgentId);
417 }
418 );
419 (c.Scene as Scene).EventManager.TriggerOnChatToClients(
420 fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully);
421 }
422>>>>>>> avn/ubitvar
316 } 423 }
317 424
318 /// <summary> 425 /// <summary>
@@ -364,6 +471,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
364 return true; 471 return true;
365 } 472 }
366 473
474 Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>();
475 public void ParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
476 {
477 System.Threading.Timer Timer;
478 if (flags == 0)
479 {
480 FreezeCache.Add(target.ToString());
481 System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(OnEndParcelFrozen);
482 Timer = new System.Threading.Timer(timeCB, target, 30000, 0);
483 Timers.Add(target, Timer);
484 }
485 else
486 {
487 FreezeCache.Remove(target.ToString());
488 Timers.TryGetValue(target, out Timer);
489 Timers.Remove(target);
490 Timer.Dispose();
491 }
492 }
493
494 private void OnEndParcelFrozen(object avatar)
495 {
496 UUID target = (UUID)avatar;
497 FreezeCache.Remove(target.ToString());
498 System.Threading.Timer Timer;
499 Timers.TryGetValue(target, out Timer);
500 Timers.Remove(target);
501 Timer.Dispose();
502 }
367 #region SimulatorFeaturesRequest 503 #region SimulatorFeaturesRequest
368 504
369 static OSDInteger m_SayRange, m_WhisperRange, m_ShoutRange; 505 static OSDInteger m_SayRange, m_WhisperRange, m_ShoutRange;
@@ -392,4 +528,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
392 528
393 #endregion 529 #endregion
394 } 530 }
395} \ No newline at end of file 531}
diff --git a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
index fc23b72..b0b7054 100644
--- a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs
@@ -183,10 +183,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
183 try 183 try
184 { 184 {
185 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 185 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
186<<<<<<< HEAD
186 187
187 if (obj == null) 188 if (obj == null)
188 return; 189 return;
189 190
191=======
192 if (obj == null)
193 return;
194>>>>>>> avn/ubitvar
190 if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0 195 if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0
191 || avatar.Scene.RegionInfo.RegionSettings.AllowDamage) 196 || avatar.Scene.RegionInfo.RegionSettings.AllowDamage)
192 { 197 {
diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs
index a896897..56819fa 100644
--- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs
@@ -203,8 +203,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog
203 { 203 {
204 m_scene.ForEachRootClient(delegate(IClientAPI client) 204 m_scene.ForEachRootClient(delegate(IClientAPI client)
205 { 205 {
206 client.SendBlueBoxMessage(fromAvatarID, fromAvatarName, 206 client.SendAgentAlertMessage(
207 message); 207 message, false);
208 }); 208 });
209 } 209 }
210 210
@@ -260,4 +260,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog
260 return result; 260 return result;
261 } 261 }
262 } 262 }
263} \ No newline at end of file 263}
diff --git a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs
index 3b6d970..adb838c 100644
--- a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs
@@ -49,6 +49,8 @@ using Caps = OpenSim.Framework.Capabilities.Caps;
49using OSDArray = OpenMetaverse.StructuredData.OSDArray; 49using OSDArray = OpenMetaverse.StructuredData.OSDArray;
50using OSDMap = OpenMetaverse.StructuredData.OSDMap; 50using OSDMap = OpenMetaverse.StructuredData.OSDMap;
51 51
52using Mono.Addins;
53
52namespace OpenSim.Region.CoreModules.Avatar.Gods 54namespace OpenSim.Region.CoreModules.Avatar.Gods
53{ 55{
54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodsModule")] 56 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodsModule")]
@@ -62,6 +64,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods
62 64
63 protected Scene m_scene; 65 protected Scene m_scene;
64 protected IDialogModule m_dialogModule; 66 protected IDialogModule m_dialogModule;
67
65 protected IDialogModule DialogModule 68 protected IDialogModule DialogModule
66 { 69 {
67 get 70 get
@@ -146,6 +149,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods
146 UUID godSessionID = userData["GodSessionID"].AsUUID(); 149 UUID godSessionID = userData["GodSessionID"].AsUUID();
147 uint kickFlags = userData["KickFlags"].AsUInteger(); 150 uint kickFlags = userData["KickFlags"].AsUInteger();
148 string reason = userData["Reason"].AsString(); 151 string reason = userData["Reason"].AsString();
152
149 ScenePresence god = m_scene.GetScenePresence(godID); 153 ScenePresence god = m_scene.GetScenePresence(godID);
150 if (god == null || god.ControllingClient.SessionId != godSessionID) 154 if (god == null || god.ControllingClient.SessionId != godSessionID)
151 return String.Empty; 155 return String.Empty;
diff --git a/OpenSim/Region/CoreModules/Avatar/Groups/GroupsModule.cs b/OpenSim/Region/CoreModules/Avatar/Groups/GroupsModule.cs
deleted file mode 100644
index b735c61..0000000
--- a/OpenSim/Region/CoreModules/Avatar/Groups/GroupsModule.cs
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38using Mono.Addins;
39
40namespace OpenSim.Region.CoreModules.Avatar.Groups
41{
42 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsModule")]
43 public class GroupsModule : ISharedRegionModule
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private Dictionary<UUID, GroupMembershipData> m_GroupMap =
49 new Dictionary<UUID, GroupMembershipData>();
50
51 private Dictionary<UUID, IClientAPI> m_ClientMap =
52 new Dictionary<UUID, IClientAPI>();
53
54 private UUID opensimulatorGroupID =
55 new UUID("00000000-68f9-1111-024e-222222111123");
56
57 private List<Scene> m_SceneList = new List<Scene>();
58
59 private static GroupMembershipData osGroup =
60 new GroupMembershipData();
61
62 private bool m_Enabled = false;
63
64 #region ISharedRegionModule Members
65
66 public void Initialise(IConfigSource config)
67 {
68 IConfig groupsConfig = config.Configs["Groups"];
69
70 if (groupsConfig == null)
71 {
72 m_log.Info("[GROUPS]: No configuration found. Using defaults");
73 }
74 else
75 {
76 m_Enabled = groupsConfig.GetBoolean("Enabled", false);
77 if (!m_Enabled)
78 {
79 m_log.Info("[GROUPS]: Groups disabled in configuration");
80 return;
81 }
82
83 if (groupsConfig.GetString("Module", "Default") != "Default")
84 {
85 m_Enabled = false;
86 return;
87 }
88 }
89
90 }
91
92 public void AddRegion(Scene scene)
93 {
94 if (!m_Enabled)
95 return;
96
97 lock (m_SceneList)
98 {
99 if (!m_SceneList.Contains(scene))
100 {
101 if (m_SceneList.Count == 0)
102 {
103 osGroup.GroupID = opensimulatorGroupID;
104 osGroup.GroupName = "OpenSimulator Testing";
105 osGroup.GroupPowers =
106 (uint)(GroupPowers.AllowLandmark |
107 GroupPowers.AllowSetHome);
108 m_GroupMap[opensimulatorGroupID] = osGroup;
109 }
110 m_SceneList.Add(scene);
111 }
112 }
113
114 scene.EventManager.OnNewClient += OnNewClient;
115 scene.EventManager.OnClientClosed += OnClientClosed;
116 // scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
117 }
118
119 public void RemoveRegion(Scene scene)
120 {
121 if (!m_Enabled)
122 return;
123
124 lock (m_SceneList)
125 {
126 if (m_SceneList.Contains(scene))
127 m_SceneList.Remove(scene);
128 }
129
130 scene.EventManager.OnNewClient -= OnNewClient;
131 scene.EventManager.OnClientClosed -= OnClientClosed;
132 }
133
134 public void RegionLoaded(Scene scene)
135 {
136 }
137
138 public void PostInitialise()
139 {
140 }
141
142 public void Close()
143 {
144 if (!m_Enabled)
145 return;
146
147// m_log.Debug("[GROUPS]: Shutting down group module.");
148
149 lock (m_ClientMap)
150 {
151 m_ClientMap.Clear();
152 }
153
154 lock (m_GroupMap)
155 {
156 m_GroupMap.Clear();
157 }
158 }
159
160 public string Name
161 {
162 get { return "GroupsModule"; }
163 }
164
165 public Type ReplaceableInterface
166 {
167 get { return null; }
168 }
169
170 #endregion
171
172 private void OnNewClient(IClientAPI client)
173 {
174 // Subscribe to instant messages
175// client.OnInstantMessage += OnInstantMessage;
176 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
177 client.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
178 lock (m_ClientMap)
179 {
180 if (!m_ClientMap.ContainsKey(client.AgentId))
181 {
182 m_ClientMap.Add(client.AgentId, client);
183 }
184 }
185
186 GroupMembershipData[] updateGroups = new GroupMembershipData[1];
187 updateGroups[0] = osGroup;
188
189 client.SendGroupMembership(updateGroups);
190 }
191
192 private void OnAgentDataUpdateRequest(IClientAPI remoteClient,
193 UUID AgentID, UUID SessionID)
194 {
195 UUID ActiveGroupID;
196 string ActiveGroupName;
197 ulong ActiveGroupPowers;
198
199 string firstname = remoteClient.FirstName;
200 string lastname = remoteClient.LastName;
201
202 string ActiveGroupTitle = "I IZ N0T";
203
204 ActiveGroupID = osGroup.GroupID;
205 ActiveGroupName = osGroup.GroupName;
206 ActiveGroupPowers = osGroup.GroupPowers;
207
208 remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname,
209 lastname, ActiveGroupPowers, ActiveGroupName,
210 ActiveGroupTitle);
211 }
212
213// private void OnInstantMessage(IClientAPI client, GridInstantMessage im)
214// {
215// }
216
217// private void OnGridInstantMessage(GridInstantMessage msg)
218// {
219// // Trigger the above event handler
220// OnInstantMessage(null, msg);
221// }
222
223 private void HandleUUIDGroupNameRequest(UUID id,IClientAPI remote_client)
224 {
225 string groupnamereply = "Unknown";
226 UUID groupUUID = UUID.Zero;
227
228 lock (m_GroupMap)
229 {
230 if (m_GroupMap.ContainsKey(id))
231 {
232 GroupMembershipData grp = m_GroupMap[id];
233 groupnamereply = grp.GroupName;
234 groupUUID = grp.GroupID;
235 }
236 }
237 remote_client.SendGroupNameReply(groupUUID, groupnamereply);
238 }
239
240 private void OnClientClosed(UUID agentID, Scene scene)
241 {
242 lock (m_ClientMap)
243 {
244 if (m_ClientMap.ContainsKey(agentID))
245 {
246// IClientAPI cli = m_ClientMap[agentID];
247// if (cli != null)
248// {
249// //m_log.Info("[GROUPS]: Removing all reference to groups for " + cli.Name);
250// }
251// else
252// {
253// //m_log.Info("[GROUPS]: Removing all reference to groups for " + agentID.ToString());
254// }
255 m_ClientMap.Remove(agentID);
256 }
257 }
258 }
259 }
260}
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs
index c33a296..55e30a0 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs
@@ -27,6 +27,7 @@
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection; 29using System.Reflection;
30using System.Timers;
30using log4net; 31using log4net;
31using Mono.Addins; 32using Mono.Addins;
32using Nini.Config; 33using Nini.Config;
@@ -44,6 +45,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
44 private static readonly ILog m_log = LogManager.GetLogger( 45 private static readonly ILog m_log = LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType); 46 MethodBase.GetCurrentMethod().DeclaringType);
46 47
48 private Timer m_logTimer = new Timer(10000);
49 private List<GridInstantMessage> m_logData = new List<GridInstantMessage>();
50 private string m_restUrl;
51
47 /// <value> 52 /// <value>
48 /// Is this module enabled? 53 /// Is this module enabled?
49 /// </value> 54 /// </value>
@@ -63,9 +68,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
63 "InstantMessageModule", "InstantMessageModule") != 68 "InstantMessageModule", "InstantMessageModule") !=
64 "InstantMessageModule") 69 "InstantMessageModule")
65 return; 70 return;
71 m_restUrl = config.Configs["Messaging"].GetString("LogURL", String.Empty);
66 } 72 }
67 73
68 m_enabled = true; 74 m_enabled = true;
75 m_logTimer.AutoReset = false;
76 m_logTimer.Elapsed += LogTimerElapsed;
69 } 77 }
70 78
71 public void AddRegion(Scene scene) 79 public void AddRegion(Scene scene)
@@ -150,6 +158,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
150 { 158 {
151 byte dialog = im.dialog; 159 byte dialog = im.dialog;
152 160
161 if (client != null && dialog == (byte)InstantMessageDialog.MessageFromAgent)
162 LogInstantMesssage(im);
163
153 if (dialog != (byte)InstantMessageDialog.MessageFromAgent 164 if (dialog != (byte)InstantMessageDialog.MessageFromAgent
154 && dialog != (byte)InstantMessageDialog.StartTyping 165 && dialog != (byte)InstantMessageDialog.StartTyping
155 && dialog != (byte)InstantMessageDialog.StopTyping 166 && dialog != (byte)InstantMessageDialog.StopTyping
@@ -159,6 +170,32 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
159 return; 170 return;
160 } 171 }
161 172
173 //DateTime dt = DateTime.UtcNow;
174
175 // Ticks from UtcNow, but make it look like local. Evil, huh?
176 //dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
177
178 //try
179 //{
180 // // Convert that to the PST timezone
181 // TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
182 // dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
183 //}
184 //catch
185 //{
186 // //m_log.Info("[OFFLINE MESSAGING]: No PST timezone found on this machine. Saving with local timestamp.");
187 //}
188
189 //// And make it look local again to fool the unix time util
190 //dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
191
192 // If client is null, this message comes from storage and IS offline
193 if (client != null)
194 im.offline = 0;
195
196 if (im.offline == 0)
197 im.timestamp = (uint)Util.UnixTimeSinceEpoch();
198
162 if (m_TransferModule != null) 199 if (m_TransferModule != null)
163 { 200 {
164 if (client != null) 201 if (client != null)
@@ -202,5 +239,35 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
202 // 239 //
203 OnInstantMessage(null, msg); 240 OnInstantMessage(null, msg);
204 } 241 }
242
243 private void LogInstantMesssage(GridInstantMessage im)
244 {
245 if (m_logData.Count < 20)
246 {
247 // Restart the log write timer
248 m_logTimer.Stop();
249 }
250 if (!m_logTimer.Enabled)
251 m_logTimer.Start();
252
253 lock (m_logData)
254 {
255 m_logData.Add(im);
256 }
257 }
258
259 private void LogTimerElapsed(object source, ElapsedEventArgs e)
260 {
261 lock (m_logData)
262 {
263 if (m_restUrl != String.Empty && m_logData.Count > 0)
264 {
265 bool success = SynchronousRestObjectRequester.MakeRequest<List<GridInstantMessage>, bool>("POST", m_restUrl + "/LogMessages/", m_logData);
266 if (!success)
267 m_log.ErrorFormat("[INSTANT MESSAGE]: Failed to save log data");
268 }
269 m_logData.Clear();
270 }
271 }
205 } 272 }
206} 273}
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs
index 2462ff8..5573c94 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs
@@ -50,6 +50,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 private bool m_Enabled = false; 52 private bool m_Enabled = false;
53 protected string m_MessageKey = String.Empty;
53 protected List<Scene> m_Scenes = new List<Scene>(); 54 protected List<Scene> m_Scenes = new List<Scene>();
54 protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>(); 55 protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>();
55 56
@@ -69,14 +70,17 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
69 public virtual void Initialise(IConfigSource config) 70 public virtual void Initialise(IConfigSource config)
70 { 71 {
71 IConfig cnf = config.Configs["Messaging"]; 72 IConfig cnf = config.Configs["Messaging"];
72 if (cnf != null && cnf.GetString( 73 if (cnf != null)
73 "MessageTransferModule", "MessageTransferModule") !=
74 "MessageTransferModule")
75 { 74 {
76 m_log.Debug("[MESSAGE TRANSFER]: Disabled by configuration"); 75 if (cnf.GetString("MessageTransferModule",
77 return; 76 "MessageTransferModule") != "MessageTransferModule")
78 } 77 {
78 return;
79 }
79 80
81 m_MessageKey = cnf.GetString("MessageKey", String.Empty);
82 }
83 m_log.Debug("[MESSAGE TRANSFER]: Module enabled");
80 m_Enabled = true; 84 m_Enabled = true;
81 } 85 }
82 86
@@ -135,6 +139,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
135 { 139 {
136 UUID toAgentID = new UUID(im.toAgentID); 140 UUID toAgentID = new UUID(im.toAgentID);
137 141
142 if (toAgentID == UUID.Zero)
143 return;
144
138 // Try root avatar only first 145 // Try root avatar only first
139 foreach (Scene scene in m_Scenes) 146 foreach (Scene scene in m_Scenes)
140 { 147 {
@@ -249,6 +256,19 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
249 && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id") 256 && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id")
250 && requestData.ContainsKey("binary_bucket")) 257 && requestData.ContainsKey("binary_bucket"))
251 { 258 {
259 if (m_MessageKey != String.Empty)
260 {
261 XmlRpcResponse error_resp = new XmlRpcResponse();
262 Hashtable error_respdata = new Hashtable();
263 error_respdata["success"] = "FALSE";
264 error_resp.Value = error_respdata;
265
266 if (!requestData.Contains("message_key"))
267 return error_resp;
268 if (m_MessageKey != (string)requestData["message_key"])
269 return error_resp;
270 }
271
252 // Do the easy way of validating the UUIDs 272 // Do the easy way of validating the UUIDs
253 UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID); 273 UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID);
254 UUID.TryParse((string)requestData["to_agent_id"], out toAgentID); 274 UUID.TryParse((string)requestData["to_agent_id"], out toAgentID);
@@ -425,34 +445,89 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
425 return resp; 445 return resp;
426 } 446 }
427 447
448<<<<<<< HEAD
428 /// <summary> 449 /// <summary>
429 /// delegate for sending a grid instant message asynchronously 450 /// delegate for sending a grid instant message asynchronously
430 /// </summary> 451 /// </summary>
431 public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result); 452 public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result);
453=======
454 private delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result);
455>>>>>>> avn/ubitvar
432 456
433 protected virtual void GridInstantMessageCompleted(IAsyncResult iar) 457 private class GIM {
434 { 458 public GridInstantMessage im;
435 GridInstantMessageDelegate icon = 459 public MessageResultNotification result;
436 (GridInstantMessageDelegate)iar.AsyncState; 460 };
437 icon.EndInvoke(iar);
438 }
439 461
462 private Queue<GIM> pendingInstantMessages = new Queue<GIM>();
463 private int numInstantMessageThreads = 0;
440 464
441 protected virtual void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result) 465 private void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result)
442 { 466 {
443 GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; 467 lock (pendingInstantMessages) {
468 if (numInstantMessageThreads >= 4) {
469 GIM gim = new GIM();
470 gim.im = im;
471 gim.result = result;
472 pendingInstantMessages.Enqueue(gim);
473 } else {
474 ++ numInstantMessageThreads;
475 //m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: ++numInstantMessageThreads={0}", numInstantMessageThreads);
476 GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsyncMain;
477 d.BeginInvoke(im, result, GridInstantMessageCompleted, d);
478 }
479 }
480 }
444 481
482<<<<<<< HEAD
445 d.BeginInvoke(im, result, GridInstantMessageCompleted, d); 483 d.BeginInvoke(im, result, GridInstantMessageCompleted, d);
484=======
485 private void GridInstantMessageCompleted(IAsyncResult iar)
486 {
487 GridInstantMessageDelegate d = (GridInstantMessageDelegate)iar.AsyncState;
488 d.EndInvoke(iar);
489>>>>>>> avn/ubitvar
446 } 490 }
447 491
448 /// <summary> 492 /// <summary>
449 /// Internal SendGridInstantMessage over XMLRPC method. 493 /// Internal SendGridInstantMessage over XMLRPC method.
450 /// </summary> 494 /// </summary>
495<<<<<<< HEAD
451 /// <remarks> 496 /// <remarks>
452 /// This is called from within a dedicated thread. 497 /// This is called from within a dedicated thread.
453 /// </remarks> 498 /// </remarks>
454 private void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result) 499 private void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result)
500=======
501 /// <param name="prevRegionHandle">
502 /// Pass in 0 the first time this method is called. It will be called recursively with the last
503 /// regionhandle tried
504 /// </param>
505 private void SendGridInstantMessageViaXMLRPCAsyncMain(GridInstantMessage im, MessageResultNotification result)
506>>>>>>> avn/ubitvar
455 { 507 {
508 GIM gim;
509 do {
510 try {
511 SendGridInstantMessageViaXMLRPCAsync(im, result, UUID.Zero);
512 } catch (Exception e) {
513 m_log.Error("[SendGridInstantMessageViaXMLRPC]: exception " + e.Message);
514 }
515 lock (pendingInstantMessages) {
516 if (pendingInstantMessages.Count > 0) {
517 gim = pendingInstantMessages.Dequeue();
518 im = gim.im;
519 result = gim.result;
520 } else {
521 gim = null;
522 -- numInstantMessageThreads;
523 //m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: --numInstantMessageThreads={0}", numInstantMessageThreads);
524 }
525 }
526 } while (gim != null);
527 }
528 private void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID)
529 {
530
456 UUID toAgentID = new UUID(im.toAgentID); 531 UUID toAgentID = new UUID(im.toAgentID);
457 UUID regionID; 532 UUID regionID;
458 bool needToLookupAgent; 533 bool needToLookupAgent;
@@ -494,6 +569,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
494 break; 569 break;
495 } 570 }
496 571
572<<<<<<< HEAD
497 // Try to send the message to the agent via the retrieved region. 573 // Try to send the message to the agent via the retrieved region.
498 Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); 574 Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
499 msgdata["region_handle"] = 0; 575 msgdata["region_handle"] = 0;
@@ -501,6 +577,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
501 577
502 // If the message delivery was successful, then cache the entry. 578 // If the message delivery was successful, then cache the entry.
503 if (imresult) 579 if (imresult)
580=======
581 if (upd != null)
582 {
583 GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(UUID.Zero,
584 upd.RegionID);
585 if (reginfo != null)
586>>>>>>> avn/ubitvar
504 { 587 {
505 lock (m_UserRegionMap) 588 lock (m_UserRegionMap)
506 { 589 {
@@ -622,6 +705,8 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
622 gim["position_z"] = msg.Position.Z.ToString(); 705 gim["position_z"] = msg.Position.Z.ToString();
623 gim["region_id"] = new UUID(msg.RegionID).ToString(); 706 gim["region_id"] = new UUID(msg.RegionID).ToString();
624 gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None); 707 gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None);
708 if (m_MessageKey != String.Empty)
709 gim["message_key"] = m_MessageKey;
625 return gim; 710 return gim;
626 } 711 }
627 712
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
index c75920d..76023bd 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
@@ -40,6 +40,13 @@ using OpenSim.Region.Framework.Scenes;
40 40
41namespace OpenSim.Region.CoreModules.Avatar.InstantMessage 41namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
42{ 42{
43 public struct SendReply
44 {
45 public bool Success;
46 public string Message;
47 public int Disposition;
48 }
49
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")] 50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")]
44 public class OfflineMessageModule : ISharedRegionModule 51 public class OfflineMessageModule : ISharedRegionModule
45 { 52 {
@@ -50,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
50 private string m_RestURL = String.Empty; 57 private string m_RestURL = String.Empty;
51 IMessageTransferModule m_TransferModule = null; 58 IMessageTransferModule m_TransferModule = null;
52 private bool m_ForwardOfflineGroupMessages = true; 59 private bool m_ForwardOfflineGroupMessages = true;
60 private Dictionary<IClientAPI, List<UUID>> m_repliesSent= new Dictionary<IClientAPI, List<UUID>>();
53 61
54 public void Initialise(IConfigSource config) 62 public void Initialise(IConfigSource config)
55 { 63 {
@@ -169,11 +177,21 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
169 private void OnNewClient(IClientAPI client) 177 private void OnNewClient(IClientAPI client)
170 { 178 {
171 client.OnRetrieveInstantMessages += RetrieveInstantMessages; 179 client.OnRetrieveInstantMessages += RetrieveInstantMessages;
180 client.OnLogout += OnClientLoggedOut;
181 }
182
183 public void OnClientLoggedOut(IClientAPI client)
184 {
185 m_repliesSent.Remove(client);
172 } 186 }
173 187
174 private void RetrieveInstantMessages(IClientAPI client) 188 private void RetrieveInstantMessages(IClientAPI client)
175 { 189 {
176 if (m_RestURL != "") 190 if (m_RestURL == String.Empty)
191 {
192 return;
193 }
194 else
177 { 195 {
178 m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId); 196 m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId);
179 197
@@ -181,28 +199,28 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
181 = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>( 199 = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>(
182 "POST", m_RestURL + "/RetrieveMessages/", client.AgentId); 200 "POST", m_RestURL + "/RetrieveMessages/", client.AgentId);
183 201
184 if (msglist == null) 202 if (msglist != null)
185 { 203 {
186 m_log.WarnFormat("[OFFLINE MESSAGING]: WARNING null message list."); 204 foreach (GridInstantMessage im in msglist)
187 return;
188 }
189
190 foreach (GridInstantMessage im in msglist)
191 {
192 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
193 // send it directly or else the item will be given twice
194 client.SendInstantMessage(im);
195 else
196 { 205 {
197 // Send through scene event manager so all modules get a chance 206 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
198 // to look at this message before it gets delivered. 207 // send it directly or else the item will be given twice
199 // 208 client.SendInstantMessage(im);
200 // Needed for proper state management for stored group 209 else
201 // invitations 210 {
202 // 211 // Send through scene event manager so all modules get a chance
203 Scene s = FindScene(client.AgentId); 212 // to look at this message before it gets delivered.
204 if (s != null) 213 //
205 s.EventManager.TriggerIncomingInstantMessage(im); 214 // Needed for proper state management for stored group
215 // invitations
216 //
217
218 im.offline = 1;
219
220 Scene s = FindScene(client.AgentId);
221 if (s != null)
222 s.EventManager.TriggerIncomingInstantMessage(im);
223 }
206 } 224 }
207 } 225 }
208 } 226 }
@@ -214,11 +232,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
214 im.dialog != (byte)InstantMessageDialog.MessageFromAgent && 232 im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
215 im.dialog != (byte)InstantMessageDialog.GroupNotice && 233 im.dialog != (byte)InstantMessageDialog.GroupNotice &&
216 im.dialog != (byte)InstantMessageDialog.GroupInvitation && 234 im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
217 im.dialog != (byte)InstantMessageDialog.InventoryOffered) 235 im.dialog != (byte)InstantMessageDialog.InventoryOffered &&
236 im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered)
218 { 237 {
219 return; 238 return;
220 } 239 }
221 240
241<<<<<<< HEAD
222 if (!m_ForwardOfflineGroupMessages) 242 if (!m_ForwardOfflineGroupMessages)
223 { 243 {
224 if (im.dialog == (byte)InstantMessageDialog.GroupNotice || 244 if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
@@ -228,6 +248,15 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
228 248
229 bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>( 249 bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>(
230 "POST", m_RestURL+"/SaveMessage/", im, 10000); 250 "POST", m_RestURL+"/SaveMessage/", im, 10000);
251=======
252 Scene scene = FindScene(new UUID(im.fromAgentID));
253 if (scene == null)
254 scene = m_SceneList[0];
255
256 SendReply reply = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, SendReply>(
257 "POST", m_RestURL+"/SaveMessage/?scope=" +
258 scene.RegionInfo.ScopeID.ToString(), im);
259>>>>>>> avn/ubitvar
231 260
232 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) 261 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
233 { 262 {
@@ -235,13 +264,38 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
235 if (client == null) 264 if (client == null)
236 return; 265 return;
237 266
238 client.SendInstantMessage(new GridInstantMessage( 267 if (reply.Message == String.Empty)
239 null, new UUID(im.toAgentID), 268 reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved");
240 "System", new UUID(im.fromAgentID), 269
241 (byte)InstantMessageDialog.MessageFromAgent, 270 bool sendReply = true;
242 "User is not logged in. "+ 271
243 (success ? "Message saved." : "Message not saved"), 272 switch (reply.Disposition)
244 false, new Vector3())); 273 {
274 case 0: // Normal
275 break;
276 case 1: // Only once per user
277 if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID)))
278 {
279 sendReply = false;
280 }
281 else
282 {
283 if (!m_repliesSent.ContainsKey(client))
284 m_repliesSent[client] = new List<UUID>();
285 m_repliesSent[client].Add(new UUID(im.toAgentID));
286 }
287 break;
288 }
289
290 if (sendReply)
291 {
292 client.SendInstantMessage(new GridInstantMessage(
293 null, new UUID(im.toAgentID),
294 "System", new UUID(im.fromAgentID),
295 (byte)InstantMessageDialog.MessageFromAgent,
296 reply.Message,
297 false, new Vector3()));
298 }
245 } 299 }
246 } 300 }
247 } 301 }
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
index 420520e..5295ba3 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
@@ -566,6 +566,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
566 return null; 566 return null;
567 } 567 }
568 568
569 return account;
570 /*
569 try 571 try
570 { 572 {
571 string encpass = Util.Md5Hash(pass); 573 string encpass = Util.Md5Hash(pass);
@@ -586,6 +588,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
586 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Could not authenticate password, {0}", e); 588 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Could not authenticate password, {0}", e);
587 return null; 589 return null;
588 } 590 }
591 */
589 } 592 }
590 593
591 /// <summary> 594 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
index bba48cc..18e18a9 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
@@ -165,8 +165,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
165 if (im.binaryBucket.Length < 17) // Invalid 165 if (im.binaryBucket.Length < 17) // Invalid
166 return; 166 return;
167 167
168 UUID receipientID = new UUID(im.toAgentID); 168 UUID recipientID = new UUID(im.toAgentID);
169 ScenePresence user = scene.GetScenePresence(receipientID); 169 ScenePresence user = scene.GetScenePresence(recipientID);
170 UUID copyID; 170 UUID copyID;
171 171
172 // First byte is the asset type 172 // First byte is the asset type
@@ -180,8 +180,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
180 "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory", 180 "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory",
181 folderID, new UUID(im.toAgentID)); 181 folderID, new UUID(im.toAgentID));
182 182
183<<<<<<< HEAD
183 InventoryFolderBase folderCopy 184 InventoryFolderBase folderCopy
184 = scene.GiveInventoryFolder(client, receipientID, client.AgentId, folderID, UUID.Zero); 185 = scene.GiveInventoryFolder(client, receipientID, client.AgentId, folderID, UUID.Zero);
186=======
187 InventoryFolderBase folderCopy
188 = scene.GiveInventoryFolder(recipientID, client.AgentId, folderID, UUID.Zero);
189>>>>>>> avn/ubitvar
185 190
186 if (folderCopy == null) 191 if (folderCopy == null)
187 { 192 {
@@ -239,6 +244,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
239 im.imSessionID = copyID.Guid; 244 im.imSessionID = copyID.Guid;
240 } 245 }
241 246
247 im.offline = 0;
248
242 // Send the IM to the recipient. The item is already 249 // Send the IM to the recipient. The item is already
243 // in their inventory, so it will not be lost if 250 // in their inventory, so it will not be lost if
244 // they are offline. 251 // they are offline.
@@ -258,8 +265,42 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
258 }); 265 });
259 } 266 }
260 } 267 }
261 else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted) 268 else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted ||
269 im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
262 { 270 {
271 UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
272 IInventoryService invService = scene.InventoryService;
273
274 // Special case: folder redirect.
275 // RLV uses this
276 if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
277 {
278 InventoryFolderBase folder = new InventoryFolderBase(inventoryID, client.AgentId);
279 folder = invService.GetFolder(folder);
280
281 if (folder != null)
282 {
283 if (im.binaryBucket.Length >= 16)
284 {
285 UUID destFolderID = new UUID(im.binaryBucket, 0);
286 if (destFolderID != UUID.Zero)
287 {
288 InventoryFolderBase destFolder = new InventoryFolderBase(destFolderID, client.AgentId);
289 destFolder = invService.GetFolder(destFolder);
290 if (destFolder != null)
291 {
292 if (folder.ParentID != destFolder.ID)
293 {
294 folder.ParentID = destFolder.ID;
295 invService.MoveFolder(folder);
296 client.SendBulkUpdateInventory(folder);
297 }
298 }
299 }
300 }
301 }
302 }
303
263 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); 304 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));
264 305
265 if (user != null) // Local 306 if (user != null) // Local
@@ -269,27 +310,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
269 else 310 else
270 { 311 {
271 if (m_TransferModule != null) 312 if (m_TransferModule != null)
272 m_TransferModule.SendInstantMessage(im, delegate(bool success) { 313 m_TransferModule.SendInstantMessage(im, delegate(bool success) {});
273
274 // justincc - FIXME: Comment out for now. This code was added in commit db91044 Mon Aug 22 2011
275 // and is apparently supposed to fix bulk inventory updates after accepting items. But
276 // instead it appears to cause two copies of an accepted folder for the receiving user in
277 // at least some cases. Folder/item update is already done when the offer is made (see code above)
278
279// // Send BulkUpdateInventory
280// IInventoryService invService = scene.InventoryService;
281// UUID inventoryEntityID = new UUID(im.imSessionID); // The inventory item /folder, back from it's trip
282//
283// InventoryFolderBase folder = new InventoryFolderBase(inventoryEntityID, client.AgentId);
284// folder = invService.GetFolder(folder);
285//
286// ScenePresence fromUser = scene.GetScenePresence(new UUID(im.fromAgentID));
287//
288// // If the user has left the scene by the time the message comes back then we can't send
289// // them the update.
290// if (fromUser != null)
291// fromUser.ControllingClient.SendBulkUpdateInventory(folder);
292 });
293 } 314 }
294 } 315 }
295 316
@@ -402,6 +423,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
402 previousParentFolderID = folder.ParentID; 423 previousParentFolderID = folder.ParentID;
403 folder.ParentID = trashFolder.ID; 424 folder.ParentID = trashFolder.ID;
404 invService.MoveFolder(folder); 425 invService.MoveFolder(folder);
426 client.SendBulkUpdateInventory(folder);
405 } 427 }
406 } 428 }
407 429
@@ -453,6 +475,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
453 /// <param name="im"></param> 475 /// <param name="im"></param>
454 private void OnGridInstantMessage(GridInstantMessage im) 476 private void OnGridInstantMessage(GridInstantMessage im)
455 { 477 {
478<<<<<<< HEAD
456 // Check if it's a type of message that we should handle 479 // Check if it's a type of message that we should handle
457 if (!((im.dialog == (byte) InstantMessageDialog.InventoryOffered) 480 if (!((im.dialog == (byte) InstantMessageDialog.InventoryOffered)
458 || (im.dialog == (byte) InstantMessageDialog.TaskInventoryOffered) 481 || (im.dialog == (byte) InstantMessageDialog.TaskInventoryOffered)
@@ -465,6 +488,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
465 "[INVENTORY TRANSFER]: {0} IM type received from grid. From={1} ({2}), To={3}", 488 "[INVENTORY TRANSFER]: {0} IM type received from grid. From={1} ({2}), To={3}",
466 (InstantMessageDialog)im.dialog, im.fromAgentID, im.fromAgentName, im.toAgentID); 489 (InstantMessageDialog)im.dialog, im.fromAgentID, im.fromAgentName, im.toAgentID);
467 490
491=======
492>>>>>>> avn/ubitvar
468 // Check if this is ours to handle 493 // Check if this is ours to handle
469 // 494 //
470 Scene scene = FindClientScene(new UUID(im.toAgentID)); 495 Scene scene = FindClientScene(new UUID(im.toAgentID));
@@ -475,32 +500,100 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
475 // Find agent to deliver to 500 // Find agent to deliver to
476 // 501 //
477 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); 502 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));
503 if (user == null)
504 return;
478 505
479 if (user != null) 506 // This requires a little bit of processing because we have to make the
507 // new item visible in the recipient's inventory here
508 //
509 if (im.dialog == (byte) InstantMessageDialog.InventoryOffered)
480 { 510 {
481 user.ControllingClient.SendInstantMessage(im); 511 if (im.binaryBucket.Length < 17) // Invalid
512 return;
513
514 UUID recipientID = new UUID(im.toAgentID);
482 515
483 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) 516 // First byte is the asset type
484 { 517 AssetType assetType = (AssetType)im.binaryBucket[0];
485 AssetType assetType = (AssetType)im.binaryBucket[0];
486 UUID inventoryID = new UUID(im.binaryBucket, 1);
487 518
488 IInventoryService invService = scene.InventoryService; 519 if (AssetType.Folder == assetType)
489 InventoryNodeBase node = null; 520 {
490 if (AssetType.Folder == assetType) 521 UUID folderID = new UUID(im.binaryBucket, 1);
522
523 InventoryFolderBase given =
524 new InventoryFolderBase(folderID, recipientID);
525 InventoryFolderBase folder =
526 scene.InventoryService.GetFolder(given);
527
528 if (folder != null)
529 user.ControllingClient.SendBulkUpdateInventory(folder);
530 }
531 else
532 {
533 UUID itemID = new UUID(im.binaryBucket, 1);
534
535 InventoryItemBase given =
536 new InventoryItemBase(itemID, recipientID);
537 InventoryItemBase item =
538 scene.InventoryService.GetItem(given);
539
540 if (item != null)
491 { 541 {
492 InventoryFolderBase folder = new InventoryFolderBase(inventoryID, new UUID(im.toAgentID)); 542 user.ControllingClient.SendBulkUpdateInventory(item);
493 node = invService.GetFolder(folder);
494 } 543 }
495 else 544 }
545 user.ControllingClient.SendInstantMessage(im);
546 }
547 if (im.dialog == (byte) InstantMessageDialog.TaskInventoryOffered)
548 {
549 if (im.binaryBucket.Length < 1) // Invalid
550 return;
551
552 UUID recipientID = new UUID(im.toAgentID);
553
554 // Bucket is the asset type
555 AssetType assetType = (AssetType)im.binaryBucket[0];
556
557 if (AssetType.Folder == assetType)
558 {
559 UUID folderID = new UUID(im.imSessionID);
560
561 InventoryFolderBase given =
562 new InventoryFolderBase(folderID, recipientID);
563 InventoryFolderBase folder =
564 scene.InventoryService.GetFolder(given);
565
566 if (folder != null)
567 user.ControllingClient.SendBulkUpdateInventory(folder);
568 }
569 else
570 {
571 UUID itemID = new UUID(im.imSessionID);
572
573 InventoryItemBase given =
574 new InventoryItemBase(itemID, recipientID);
575 InventoryItemBase item =
576 scene.InventoryService.GetItem(given);
577
578 if (item != null)
496 { 579 {
497 InventoryItemBase item = new InventoryItemBase(inventoryID, new UUID(im.toAgentID)); 580 user.ControllingClient.SendBulkUpdateInventory(item);
498 node = invService.GetItem(item);
499 } 581 }
500
501 if (node != null)
502 user.ControllingClient.SendBulkUpdateInventory(node);
503 } 582 }
583
584 // Fix up binary bucket since this may be 17 chars long here
585 Byte[] bucket = new Byte[1];
586 bucket[0] = im.binaryBucket[0];
587 im.binaryBucket = bucket;
588
589 user.ControllingClient.SendInstantMessage(im);
590 }
591 else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted ||
592 im.dialog == (byte) InstantMessageDialog.InventoryDeclined ||
593 im.dialog == (byte) InstantMessageDialog.TaskInventoryDeclined ||
594 im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
595 {
596 user.ControllingClient.SendInstantMessage(im);
504 } 597 }
505 } 598 }
506 } 599 }
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
index 465ffbc..c517a30 100644
--- a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
@@ -163,16 +163,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
163 scene.RegionInfo.RegionHandle, 163 scene.RegionInfo.RegionHandle,
164 (uint)presence.AbsolutePosition.X, 164 (uint)presence.AbsolutePosition.X,
165 (uint)presence.AbsolutePosition.Y, 165 (uint)presence.AbsolutePosition.Y,
166 (uint)Math.Ceiling(presence.AbsolutePosition.Z)); 166 (uint)presence.AbsolutePosition.Z + 2);
167 167
168 m_log.DebugFormat("[LURE MODULE]: TP invite with message {0}, type {1}", message, lureType); 168 m_log.DebugFormat("[LURE MODULE]: TP invite with message {0}, type {1}", message, lureType);
169 169
170 GridInstantMessage m = new GridInstantMessage(scene, client.AgentId, 170 GridInstantMessage m;
171 client.FirstName+" "+client.LastName, targetid, 171
172 (byte)InstantMessageDialog.RequestTeleport, false, 172 if (scene.Permissions.IsAdministrator(client.AgentId) && presence.GodLevel >= 200 && (!scene.Permissions.IsAdministrator(targetid)))
173 message, dest, false, presence.AbsolutePosition, 173 {
174 new Byte[0], true); 174 m = new GridInstantMessage(scene, client.AgentId,
175 175 client.FirstName+" "+client.LastName, targetid,
176 (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
177 message, dest, false, presence.AbsolutePosition,
178 new Byte[0], true);
179 }
180 else
181 {
182 m = new GridInstantMessage(scene, client.AgentId,
183 client.FirstName+" "+client.LastName, targetid,
184 (byte)InstantMessageDialog.RequestTeleport, false,
185 message, dest, false, presence.AbsolutePosition,
186 new Byte[0], true);
187 }
188
176 if (m_TransferModule != null) 189 if (m_TransferModule != null)
177 { 190 {
178 m_TransferModule.SendInstantMessage(m, 191 m_TransferModule.SendInstantMessage(m,
@@ -207,7 +220,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
207 { 220 {
208 // Forward remote teleport requests 221 // Forward remote teleport requests
209 // 222 //
210 if (msg.dialog != 22) 223 if (msg.dialog != (byte)InstantMessageDialog.RequestTeleport &&
224 msg.dialog != (byte)InstantMessageDialog.GodLikeRequestTeleport)
211 return; 225 return;
212 226
213 if (m_TransferModule != null) 227 if (m_TransferModule != null)
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index c20369c..bea2834 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -288,10 +288,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
288 // Notes 288 // Notes
289 client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest); 289 client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest);
290 client.OnAvatarNotesUpdate += NotesUpdate; 290 client.OnAvatarNotesUpdate += NotesUpdate;
291
292 // Preferences
293 client.OnUserInfoRequest += UserPreferencesRequest;
294 client.OnUpdateUserInfo += UpdateUserPreferences;
295 } 291 }
296 #endregion Region Event Handlers 292 #endregion Region Event Handlers
297 293
@@ -873,6 +869,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
873 } 869 }
874 #endregion Notes 870 #endregion Notes
875 871
872<<<<<<< HEAD
876 #region User Preferences 873 #region User Preferences
877 /// <summary> 874 /// <summary>
878 /// Updates the user preferences. 875 /// Updates the user preferences.
@@ -936,6 +933,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
936 } 933 }
937 #endregion User Preferences 934 #endregion User Preferences
938 935
936=======
937>>>>>>> avn/ubitvar
939 #region Avatar Properties 938 #region Avatar Properties
940 /// <summary> 939 /// <summary>
941 /// Update the avatars interests . 940 /// Update the avatars interests .
@@ -1402,5 +1401,185 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1402 return null; 1401 return null;
1403 } 1402 }
1404 #endregion Util 1403 #endregion Util
1404<<<<<<< HEAD
1405=======
1406
1407 #region Web Util
1408 /// <summary>
1409 /// Sends json-rpc request with a serializable type.
1410 /// </summary>
1411 /// <returns>
1412 /// OSD Map.
1413 /// </returns>
1414 /// <param name='parameters'>
1415 /// Serializable type .
1416 /// </param>
1417 /// <param name='method'>
1418 /// Json-rpc method to call.
1419 /// </param>
1420 /// <param name='uri'>
1421 /// URI of json-rpc service.
1422 /// </param>
1423 /// <param name='jsonId'>
1424 /// Id for our call.
1425 /// </param>
1426 bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
1427 {
1428 if (jsonId == null)
1429 throw new ArgumentNullException ("jsonId");
1430 if (uri == null)
1431 throw new ArgumentNullException ("uri");
1432 if (method == null)
1433 throw new ArgumentNullException ("method");
1434 if (parameters == null)
1435 throw new ArgumentNullException ("parameters");
1436
1437 // Prep our payload
1438 OSDMap json = new OSDMap();
1439
1440 json.Add("jsonrpc", OSD.FromString("2.0"));
1441 json.Add("id", OSD.FromString(jsonId));
1442 json.Add("method", OSD.FromString(method));
1443
1444 json.Add("params", OSD.SerializeMembers(parameters));
1445
1446 string jsonRequestData = OSDParser.SerializeJsonString(json);
1447 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1448
1449 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1450
1451 webRequest.ContentType = "application/json-rpc";
1452 webRequest.Method = "POST";
1453
1454 Stream dataStream = webRequest.GetRequestStream();
1455 dataStream.Write(content, 0, content.Length);
1456 dataStream.Close();
1457
1458 WebResponse webResponse = null;
1459 try
1460 {
1461 webResponse = webRequest.GetResponse();
1462 }
1463 catch (WebException e)
1464 {
1465 Console.WriteLine("Web Error" + e.Message);
1466 Console.WriteLine ("Please check input");
1467 return false;
1468 }
1469
1470 OSDMap mret = new OSDMap();
1471
1472 using (Stream rstream = webResponse.GetResponseStream())
1473 {
1474 try
1475 {
1476 mret = (OSDMap)OSDParser.DeserializeJson(rstream);
1477 }
1478 catch (Exception e)
1479 {
1480 m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
1481 if (webResponse != null)
1482 webResponse.Close();
1483 return false;
1484 }
1485 }
1486
1487 if (webResponse != null)
1488 webResponse.Close();
1489
1490 if (mret.ContainsKey("error"))
1491 return false;
1492
1493 // get params...
1494 OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]);
1495 return true;
1496 }
1497
1498 /// <summary>
1499 /// Sends json-rpc request with OSD parameter.
1500 /// </summary>
1501 /// <returns>
1502 /// The rpc request.
1503 /// </returns>
1504 /// <param name='data'>
1505 /// data - incoming as parameters, outgong as result/error
1506 /// </param>
1507 /// <param name='method'>
1508 /// Json-rpc method to call.
1509 /// </param>
1510 /// <param name='uri'>
1511 /// URI of json-rpc service.
1512 /// </param>
1513 /// <param name='jsonId'>
1514 /// If set to <c>true</c> json identifier.
1515 /// </param>
1516 bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
1517 {
1518 OSDMap map = new OSDMap();
1519
1520 map["jsonrpc"] = "2.0";
1521 if(string.IsNullOrEmpty(jsonId))
1522 map["id"] = UUID.Random().ToString();
1523 else
1524 map["id"] = jsonId;
1525
1526 map["method"] = method;
1527 map["params"] = data;
1528
1529 string jsonRequestData = OSDParser.SerializeJsonString(map);
1530 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1531
1532 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1533 webRequest.ContentType = "application/json-rpc";
1534 webRequest.Method = "POST";
1535
1536 Stream dataStream = webRequest.GetRequestStream();
1537 dataStream.Write(content, 0, content.Length);
1538 dataStream.Close();
1539
1540 WebResponse webResponse = null;
1541 try
1542 {
1543 webResponse = webRequest.GetResponse();
1544 }
1545 catch (WebException e)
1546 {
1547 Console.WriteLine("Web Error" + e.Message);
1548 Console.WriteLine ("Please check input");
1549 return false;
1550 }
1551
1552 OSDMap response = new OSDMap();
1553
1554 using (Stream rstream = webResponse.GetResponseStream())
1555 {
1556 try
1557 {
1558 response = (OSDMap)OSDParser.DeserializeJson(rstream);
1559 }
1560 catch (Exception e)
1561 {
1562 m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
1563 if (webResponse != null)
1564 webResponse.Close();
1565 return false;
1566 }
1567 }
1568
1569 if (webResponse != null)
1570 webResponse.Close();
1571
1572 if(response.ContainsKey("error"))
1573 {
1574 data = response["error"];
1575 return false;
1576 }
1577
1578 data = response;
1579
1580 return true;
1581 }
1582 #endregion Web Util
1583>>>>>>> avn/ubitvar
1405 } 1584 }
1406} 1585}
diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
index 817ef85..44eee89 100644
--- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -57,7 +57,7 @@ namespace OpenSim.Region.CoreModules.Framework
57 /// <summary> 57 /// <summary>
58 /// Each agent has its own capabilities handler. 58 /// Each agent has its own capabilities handler.
59 /// </summary> 59 /// </summary>
60 protected Dictionary<UUID, Caps> m_capsObjects = new Dictionary<UUID, Caps>(); 60 protected Dictionary<uint, Caps> m_capsObjects = new Dictionary<uint, Caps>();
61 61
62 protected Dictionary<UUID, string> m_capsPaths = new Dictionary<UUID, string>(); 62 protected Dictionary<UUID, string> m_capsPaths = new Dictionary<UUID, string>();
63 63
@@ -118,23 +118,46 @@ namespace OpenSim.Region.CoreModules.Framework
118 get { return null; } 118 get { return null; }
119 } 119 }
120 120
121 public void CreateCaps(UUID agentId) 121 public void CreateCaps(UUID agentId, uint circuitCode)
122 { 122 {
123 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId)) 123 int ts = Util.EnvironmentTickCount();
124 return; 124/* this as no business here...
125 * must be done elsewhere ( and is )
126 int flags = m_scene.GetUserFlags(agentId);
127
128 m_log.ErrorFormat("[CreateCaps]: banCheck {0} ", Util.EnvironmentTickCountSubtract(ts));
125 129
130 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId, flags))
131 return;
132*/
126 Caps caps; 133 Caps caps;
127 String capsObjectPath = GetCapsPath(agentId); 134 String capsObjectPath = GetCapsPath(agentId);
128 135
129 lock (m_capsObjects) 136 lock (m_capsObjects)
130 { 137 {
131 if (m_capsObjects.ContainsKey(agentId)) 138 if (m_capsObjects.ContainsKey(circuitCode))
132 { 139 {
133 Caps oldCaps = m_capsObjects[agentId]; 140 Caps oldCaps = m_capsObjects[circuitCode];
134 141
135 //m_log.WarnFormat( 142
136 // "[CAPS]: Recreating caps for agent {0} in region {1}. Old caps path {2}, new caps path {3}. ", 143 if (capsObjectPath == oldCaps.CapsObjectPath)
137 // agentId, m_scene.RegionInfo.RegionName, oldCaps.CapsObjectPath, capsObjectPath); 144 {
145 m_log.WarnFormat(
146 "[CAPS]: Reusing caps for agent {0} in region {1}. Old caps path {2}, new caps path {3}. ",
147 agentId, m_scene.RegionInfo.RegionName, oldCaps.CapsObjectPath, capsObjectPath);
148 return;
149 }
150 else
151 {
152 // not reusing add extra melanie cleanup
153 // Remove tge handlers. They may conflict with the
154 // new object created below
155 oldCaps.DeregisterHandlers();
156
157 // Better safe ... should not be needed but also
158 // no big deal
159 m_capsObjects.Remove(circuitCode);
160 }
138 } 161 }
139 162
140// m_log.DebugFormat( 163// m_log.DebugFormat(
@@ -145,13 +168,17 @@ namespace OpenSim.Region.CoreModules.Framework
145 (MainServer.Instance == null) ? 0: MainServer.Instance.Port, 168 (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
146 capsObjectPath, agentId, m_scene.RegionInfo.RegionName); 169 capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
147 170
148 m_capsObjects[agentId] = caps; 171 m_log.ErrorFormat("[CreateCaps]: new caps agent {0}, circuit {1}, path {2}, time {3} ",agentId,
149 } 172 circuitCode,caps.CapsObjectPath, Util.EnvironmentTickCountSubtract(ts));
150 173
174 m_capsObjects[circuitCode] = caps;
175 }
151 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps); 176 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
177// m_log.ErrorFormat("[CreateCaps]: end {0} ", Util.EnvironmentTickCountSubtract(ts));
178
152 } 179 }
153 180
154 public void RemoveCaps(UUID agentId) 181 public void RemoveCaps(UUID agentId, uint circuitCode)
155 { 182 {
156 m_log.DebugFormat("[CAPS]: Remove caps for agent {0} in region {1}", agentId, m_scene.RegionInfo.RegionName); 183 m_log.DebugFormat("[CAPS]: Remove caps for agent {0} in region {1}", agentId, m_scene.RegionInfo.RegionName);
157 lock (m_childrenSeeds) 184 lock (m_childrenSeeds)
@@ -164,14 +191,24 @@ namespace OpenSim.Region.CoreModules.Framework
164 191
165 lock (m_capsObjects) 192 lock (m_capsObjects)
166 { 193 {
167 if (m_capsObjects.ContainsKey(agentId)) 194 if (m_capsObjects.ContainsKey(circuitCode))
168 { 195 {
169 m_capsObjects[agentId].DeregisterHandlers(); 196 m_capsObjects[circuitCode].DeregisterHandlers();
170 m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsObjects[agentId]); 197 m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsObjects[circuitCode]);
171 m_capsObjects.Remove(agentId); 198 m_capsObjects.Remove(circuitCode);
172 } 199 }
173 else 200 else
174 { 201 {
202 foreach (KeyValuePair<uint, Caps> kvp in m_capsObjects)
203 {
204 if (kvp.Value.AgentID == agentId)
205 {
206 kvp.Value.DeregisterHandlers();
207 m_scene.EventManager.TriggerOnDeregisterCaps(agentId, kvp.Value);
208 m_capsObjects.Remove(kvp.Key);
209 return;
210 }
211 }
175 m_log.WarnFormat( 212 m_log.WarnFormat(
176 "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!", 213 "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
177 agentId, m_scene.RegionInfo.RegionName); 214 agentId, m_scene.RegionInfo.RegionName);
@@ -179,19 +216,30 @@ namespace OpenSim.Region.CoreModules.Framework
179 } 216 }
180 } 217 }
181 218
182 public Caps GetCapsForUser(UUID agentId) 219 public Caps GetCapsForUser(uint circuitCode)
183 { 220 {
184 lock (m_capsObjects) 221 lock (m_capsObjects)
185 { 222 {
186 if (m_capsObjects.ContainsKey(agentId)) 223 if (m_capsObjects.ContainsKey(circuitCode))
187 { 224 {
188 return m_capsObjects[agentId]; 225 return m_capsObjects[circuitCode];
189 } 226 }
190 } 227 }
191 228
192 return null; 229 return null;
193 } 230 }
194 231
232 public void ActivateCaps(uint circuitCode)
233 {
234 lock (m_capsObjects)
235 {
236 if (m_capsObjects.ContainsKey(circuitCode))
237 {
238 m_capsObjects[circuitCode].Activate();
239 }
240 }
241 }
242
195 public void SetAgentCapsSeeds(AgentCircuitData agent) 243 public void SetAgentCapsSeeds(AgentCircuitData agent)
196 { 244 {
197 lock (m_capsPaths) 245 lock (m_capsPaths)
@@ -289,9 +337,9 @@ namespace OpenSim.Region.CoreModules.Framework
289 337
290 lock (m_capsObjects) 338 lock (m_capsObjects)
291 { 339 {
292 foreach (KeyValuePair<UUID, Caps> kvp in m_capsObjects) 340 foreach (KeyValuePair<uint, Caps> kvp in m_capsObjects)
293 { 341 {
294 capsReport.AppendFormat("** User {0}:\n", kvp.Key); 342 capsReport.AppendFormat("** Circuit {0}:\n", kvp.Key);
295 Caps caps = kvp.Value; 343 Caps caps = kvp.Value;
296 344
297 for (IDictionaryEnumerator kvp2 = caps.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); ) 345 for (IDictionaryEnumerator kvp2 = caps.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
@@ -339,6 +387,7 @@ namespace OpenSim.Region.CoreModules.Framework
339 387
340 private void BuildDetailedStatsByCapReport(StringBuilder sb, string capName) 388 private void BuildDetailedStatsByCapReport(StringBuilder sb, string capName)
341 { 389 {
390 /*
342 sb.AppendFormat("Capability name {0}\n", capName); 391 sb.AppendFormat("Capability name {0}\n", capName);
343 392
344 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 393 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
@@ -384,10 +433,12 @@ namespace OpenSim.Region.CoreModules.Framework
384 } 433 }
385 434
386 sb.Append(cdt.ToString()); 435 sb.Append(cdt.ToString());
436 */
387 } 437 }
388 438
389 private void BuildSummaryStatsByCapReport(StringBuilder sb) 439 private void BuildSummaryStatsByCapReport(StringBuilder sb)
390 { 440 {
441 /*
391 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 442 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
392 cdt.AddColumn("Name", 34); 443 cdt.AddColumn("Name", 34);
393 cdt.AddColumn("Req Received", 12); 444 cdt.AddColumn("Req Received", 12);
@@ -444,10 +495,12 @@ namespace OpenSim.Region.CoreModules.Framework
444 cdt.AddRow(kvp.Key, kvp.Value, handledStats[kvp.Key]); 495 cdt.AddRow(kvp.Key, kvp.Value, handledStats[kvp.Key]);
445 496
446 sb.Append(cdt.ToString()); 497 sb.Append(cdt.ToString());
498 */
447 } 499 }
448 500
449 private void HandleShowCapsStatsByUserCommand(string module, string[] cmdParams) 501 private void HandleShowCapsStatsByUserCommand(string module, string[] cmdParams)
450 { 502 {
503 /*
451 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene) 504 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
452 return; 505 return;
453 506
@@ -478,10 +531,12 @@ namespace OpenSim.Region.CoreModules.Framework
478 } 531 }
479 532
480 MainConsole.Instance.Output(sb.ToString()); 533 MainConsole.Instance.Output(sb.ToString());
534 */
481 } 535 }
482 536
483 private void BuildDetailedStatsByUserReport(StringBuilder sb, ScenePresence sp) 537 private void BuildDetailedStatsByUserReport(StringBuilder sb, ScenePresence sp)
484 { 538 {
539 /*
485 sb.AppendFormat("Avatar name {0}, type {1}\n", sp.Name, sp.IsChildAgent ? "child" : "root"); 540 sb.AppendFormat("Avatar name {0}, type {1}\n", sp.Name, sp.IsChildAgent ? "child" : "root");
486 541
487 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 542 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
@@ -507,10 +562,12 @@ namespace OpenSim.Region.CoreModules.Framework
507 cdt.AddRow(ctr.Name, ctr.RequestsReceived, ctr.RequestsHandled); 562 cdt.AddRow(ctr.Name, ctr.RequestsReceived, ctr.RequestsHandled);
508 563
509 sb.Append(cdt.ToString()); 564 sb.Append(cdt.ToString());
565 */
510 } 566 }
511 567
512 private void BuildSummaryStatsByUserReport(StringBuilder sb) 568 private void BuildSummaryStatsByUserReport(StringBuilder sb)
513 { 569 {
570 /*
514 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 571 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
515 cdt.AddColumn("Name", 32); 572 cdt.AddColumn("Name", 32);
516 cdt.AddColumn("Type", 5); 573 cdt.AddColumn("Type", 5);
@@ -550,6 +607,7 @@ namespace OpenSim.Region.CoreModules.Framework
550 ); 607 );
551 608
552 sb.Append(cdt.ToString()); 609 sb.Append(cdt.ToString());
610 */
553 } 611 }
554 612
555 private class CapTableRow 613 private class CapTableRow
@@ -566,4 +624,4 @@ namespace OpenSim.Region.CoreModules.Framework
566 } 624 }
567 } 625 }
568 } 626 }
569} \ No newline at end of file 627}
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index 4be19f0..7937383 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -154,12 +154,25 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
154 // Add this agent in this region as a banned person 154 // Add this agent in this region as a banned person
155 public void Add(ulong pRegionHandle, UUID pAgentID) 155 public void Add(ulong pRegionHandle, UUID pAgentID)
156 { 156 {
157<<<<<<< HEAD
157 if (!m_bannedRegions.TryGetValue(pAgentID, out m_idCache)) 158 if (!m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
158 { 159 {
159 m_idCache = new ExpiringCache<ulong, DateTime>(); 160 m_idCache = new ExpiringCache<ulong, DateTime>();
160 m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(45)); 161 m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(45));
161 } 162 }
162 m_idCache.Add(pRegionHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15)); 163 m_idCache.Add(pRegionHandle, DateTime.Now + TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
164=======
165 this.Add(pRegionHandle, pAgentID, 45, 15);
166 }
167 public void Add(ulong pRegionHandle, UUID pAgentID, double newTime, double extendTime)
168 {
169 if (!m_bannedRegions.TryGetValue(pAgentID, out m_idCache))
170 {
171 m_idCache = new ExpiringCache<ulong, DateTime>();
172 m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(newTime));
173 }
174 m_idCache.Add(pRegionHandle, DateTime.Now + TimeSpan.FromSeconds(extendTime), TimeSpan.FromSeconds(extendTime));
175>>>>>>> avn/ubitvar
163 } 176 }
164 // Remove the agent from the region's banned list 177 // Remove the agent from the region's banned list
165 public void Remove(ulong pRegionHandle, UUID pAgentID) 178 public void Remove(ulong pRegionHandle, UUID pAgentID)
@@ -209,6 +222,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
209 { 222 {
210 string transferVersionName = "SIMULATION"; 223 string transferVersionName = "SIMULATION";
211 float maxTransferVersion = 0.3f; 224 float maxTransferVersion = 0.3f;
225<<<<<<< HEAD
212 226
213 IConfig hypergridConfig = source.Configs["Hypergrid"]; 227 IConfig hypergridConfig = source.Configs["Hypergrid"];
214 if (hypergridConfig != null) 228 if (hypergridConfig != null)
@@ -221,6 +235,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
221 if (m_GatekeeperURI != string.Empty && !m_GatekeeperURI.EndsWith("/")) 235 if (m_GatekeeperURI != string.Empty && !m_GatekeeperURI.EndsWith("/"))
222 m_GatekeeperURI += '/'; 236 m_GatekeeperURI += '/';
223 } 237 }
238=======
239>>>>>>> avn/ubitvar
224 240
225 IConfig transferConfig = source.Configs["EntityTransfer"]; 241 IConfig transferConfig = source.Configs["EntityTransfer"];
226 if (transferConfig != null) 242 if (transferConfig != null)
@@ -491,16 +507,23 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
491 } 507 }
492 508
493 // TODO: Get proper AVG Height 509 // TODO: Get proper AVG Height
494 float localAVHeight = 1.56f; 510 float localHalfAVHeight = 0.8f;
511 if (sp.Appearance != null)
512 localHalfAVHeight = sp.Appearance.AvatarHeight / 2;
513
495 float posZLimit = 22; 514 float posZLimit = 22;
496 515
497 // TODO: Check other Scene HeightField 516 // TODO: Check other Scene HeightField
498 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y]; 517 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
518<<<<<<< HEAD
519=======
520
521 posZLimit += localHalfAVHeight + 0.1f;
522>>>>>>> avn/ubitvar
499 523
500 float newPosZ = posZLimit + localAVHeight; 524 if ((position.Z < posZLimit) && !(Single.IsInfinity(posZLimit) || Single.IsNaN(posZLimit)))
501 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
502 { 525 {
503 position.Z = newPosZ; 526 position.Z = posZLimit;
504 } 527 }
505 528
506 if (sp.Flying) 529 if (sp.Flying)
@@ -599,9 +622,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
599 Util.RegionHandleToRegionLoc(regionHandle, out regX, out regY); 622 Util.RegionHandleToRegionLoc(regionHandle, out regX, out regY);
600 623
601 MapBlockData block = new MapBlockData(); 624 MapBlockData block = new MapBlockData();
625<<<<<<< HEAD
602 block.X = (ushort)regX; 626 block.X = (ushort)regX;
603 block.Y = (ushort)regY; 627 block.Y = (ushort)regY;
604 block.Access = (byte)SimAccess.Down; 628 block.Access = (byte)SimAccess.Down;
629=======
630 block.X = (ushort)(regX);
631 block.Y = (ushort)(regY);
632 block.Access = (byte)SimAccess.Down; // == not there
633>>>>>>> avn/ubitvar
605 634
606 List<MapBlockData> blocks = new List<MapBlockData>(); 635 List<MapBlockData> blocks = new List<MapBlockData>();
607 blocks.Add(block); 636 blocks.Add(block);
@@ -736,10 +765,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
736 return; 765 return;
737 } 766 }
738 767
768<<<<<<< HEAD
739 uint newRegionX, newRegionY, oldRegionX, oldRegionY; 769 uint newRegionX, newRegionY, oldRegionX, oldRegionY;
740 Util.RegionHandleToRegionLoc(reg.RegionHandle, out newRegionX, out newRegionY); 770 Util.RegionHandleToRegionLoc(reg.RegionHandle, out newRegionX, out newRegionY);
741 Util.RegionHandleToRegionLoc(sp.Scene.RegionInfo.RegionHandle, out oldRegionX, out oldRegionY); 771 Util.RegionHandleToRegionLoc(sp.Scene.RegionInfo.RegionHandle, out oldRegionX, out oldRegionY);
742 772
773=======
774>>>>>>> avn/ubitvar
743 ulong destinationHandle = finalDestination.RegionHandle; 775 ulong destinationHandle = finalDestination.RegionHandle;
744 776
745 // Let's do DNS resolution only once in this process, please! 777 // Let's do DNS resolution only once in this process, please!
@@ -762,7 +794,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
762 string version; 794 string version;
763 string myversion = string.Format("{0}/{1}", OutgoingTransferVersionName, MaxOutgoingTransferVersion); 795 string myversion = string.Format("{0}/{1}", OutgoingTransferVersionName, MaxOutgoingTransferVersion);
764 if (!Scene.SimulationService.QueryAccess( 796 if (!Scene.SimulationService.QueryAccess(
797<<<<<<< HEAD
765 finalDestination, sp.ControllingClient.AgentId, homeURI, true, position, myversion, sp.Scene.GetFormatsOffered(), out version, out reason)) 798 finalDestination, sp.ControllingClient.AgentId, homeURI, true, position, myversion, sp.Scene.GetFormatsOffered(), out version, out reason))
799=======
800 finalDestination, sp.ControllingClient.AgentId, homeURI, true, position, myversion, out version, out reason))
801>>>>>>> avn/ubitvar
766 { 802 {
767 sp.ControllingClient.SendTeleportFailed(reason); 803 sp.ControllingClient.SendTeleportFailed(reason);
768 804
@@ -808,7 +844,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
808 AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo(); 844 AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo();
809 agentCircuit.startpos = position; 845 agentCircuit.startpos = position;
810 agentCircuit.child = true; 846 agentCircuit.child = true;
811 agentCircuit.Appearance = sp.Appearance; 847
848// agentCircuit.Appearance = sp.Appearance;
849// agentCircuit.Appearance = new AvatarAppearance(sp.Appearance, true, false);
850 agentCircuit.Appearance = new AvatarAppearance();
851 agentCircuit.Appearance.AvatarHeight = sp.Appearance.AvatarHeight;
852
812 if (currentAgentCircuit != null) 853 if (currentAgentCircuit != null)
813 { 854 {
814 agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs; 855 agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs;
@@ -819,14 +860,48 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
819 agentCircuit.Id0 = currentAgentCircuit.Id0; 860 agentCircuit.Id0 = currentAgentCircuit.Id0;
820 } 861 }
821 862
863<<<<<<< HEAD
822 // if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY)) 864 // if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY))
823 float dist = (float)Math.Max(sp.Scene.DefaultDrawDistance, 865 float dist = (float)Math.Max(sp.Scene.DefaultDrawDistance,
824 (float)Math.Max(sp.Scene.RegionInfo.RegionSizeX, sp.Scene.RegionInfo.RegionSizeY)); 866 (float)Math.Max(sp.Scene.RegionInfo.RegionSizeX, sp.Scene.RegionInfo.RegionSizeY));
825 if (NeedsNewAgent(dist, oldRegionX, newRegionX, oldRegionY, newRegionY)) 867 if (NeedsNewAgent(dist, oldRegionX, newRegionX, oldRegionY, newRegionY))
868=======
869 IClientIPEndpoint ipepClient;
870
871 uint newRegionX, newRegionY, oldRegionX, oldRegionY;
872 Util.RegionHandleToRegionLoc(destinationHandle, out newRegionX, out newRegionY);
873 Util.RegionHandleToRegionLoc(sourceRegion.RegionHandle, out oldRegionX, out oldRegionY);
874 int oldSizeX = (int)sourceRegion.RegionSizeX;
875 int oldSizeY = (int)sourceRegion.RegionSizeY;
876 int newSizeX = finalDestination.RegionSizeX;
877 int newSizeY = finalDestination.RegionSizeY;
878
879 bool OutSideViewRange = NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY,
880 oldSizeX, oldSizeY, newSizeX, newSizeY);
881
882 if (OutSideViewRange)
883>>>>>>> avn/ubitvar
826 { 884 {
827 // brand new agent, let's create a new caps seed 885 m_log.DebugFormat(
886 "[ENTITY TRANSFER MODULE]: Determined that region {0} at {1},{2} needs new child agent for agent {3} from {4}",
887 finalDestination.RegionName, newRegionX, newRegionY, sp.Name, Scene.Name);
888
889 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Creating agent...");
890 #region IP Translation for NAT
891 // Uses ipepClient above
892 if (sp.ClientView.TryGet(out ipepClient))
893 {
894 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
895 }
896 #endregion
828 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath(); 897 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
829 } 898 }
899 else
900 {
901 agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
902 if (agentCircuit.CapsPath == null)
903 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
904 }
830 905
831 // We're going to fallback to V1 if the destination gives us anything smaller than 0.2 or we're forcing 906 // We're going to fallback to V1 if the destination gives us anything smaller than 0.2 or we're forcing
832 // use of the earlier protocol 907 // use of the earlier protocol
@@ -836,13 +911,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
836 float.TryParse(versionComponents[1], out versionNumber); 911 float.TryParse(versionComponents[1], out versionNumber);
837 912
838 if (versionNumber >= 0.2f && MaxOutgoingTransferVersion >= versionNumber) 913 if (versionNumber >= 0.2f && MaxOutgoingTransferVersion >= versionNumber)
914<<<<<<< HEAD
839 TransferAgent_V2(sp, agentCircuit, reg, finalDestination, endPoint, teleportFlags, oldRegionX, newRegionX, oldRegionY, newRegionY, version, out reason); 915 TransferAgent_V2(sp, agentCircuit, reg, finalDestination, endPoint, teleportFlags, oldRegionX, newRegionX, oldRegionY, newRegionY, version, out reason);
916=======
917 TransferAgent_V2(sp, agentCircuit, reg, finalDestination, endPoint, teleportFlags, OutSideViewRange , version, out reason);
918>>>>>>> avn/ubitvar
840 else 919 else
841 TransferAgent_V1(sp, agentCircuit, reg, finalDestination, endPoint, teleportFlags, oldRegionX, newRegionX, oldRegionY, newRegionY, version, out reason); 920 TransferAgent_V1(sp, agentCircuit, reg, finalDestination, endPoint, teleportFlags, OutSideViewRange, version, out reason);
842 } 921 }
843 922
844 private void TransferAgent_V1(ScenePresence sp, AgentCircuitData agentCircuit, GridRegion reg, GridRegion finalDestination, 923 private void TransferAgent_V1(ScenePresence sp, AgentCircuitData agentCircuit, GridRegion reg, GridRegion finalDestination,
845 IPEndPoint endPoint, uint teleportFlags, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, string version, out string reason) 924 IPEndPoint endPoint, uint teleportFlags, bool OutSideViewRange, string version, out string reason)
846 { 925 {
847 ulong destinationHandle = finalDestination.RegionHandle; 926 ulong destinationHandle = finalDestination.RegionHandle;
848 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); 927 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
@@ -851,6 +930,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
851 "[ENTITY TRANSFER MODULE]: Using TP V1 for {0} going from {1} to {2}", 930 "[ENTITY TRANSFER MODULE]: Using TP V1 for {0} going from {1} to {2}",
852 sp.Name, Scene.Name, finalDestination.RegionName); 931 sp.Name, Scene.Name, finalDestination.RegionName);
853 932
933 string capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
934
854 // Let's create an agent there if one doesn't exist yet. 935 // Let's create an agent there if one doesn't exist yet.
855 // NOTE: logout will always be false for a non-HG teleport. 936 // NOTE: logout will always be false for a non-HG teleport.
856 bool logout = false; 937 bool logout = false;
@@ -892,6 +973,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
892 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring); 973 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring);
893 974
894 // OK, it got this agent. Let's close some child agents 975 // OK, it got this agent. Let's close some child agents
976<<<<<<< HEAD
895 sp.CloseChildAgents(newRegionX, newRegionY); 977 sp.CloseChildAgents(newRegionX, newRegionY);
896 978
897 IClientIPEndpoint ipepClient; 979 IClientIPEndpoint ipepClient;
@@ -903,17 +985,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
903 m_log.DebugFormat( 985 m_log.DebugFormat(
904 "[ENTITY TRANSFER MODULE]: Determined that region {0} at {1},{2} needs new child agent for incoming agent {3} from {4}", 986 "[ENTITY TRANSFER MODULE]: Determined that region {0} at {1},{2} needs new child agent for incoming agent {3} from {4}",
905 finalDestination.RegionName, newRegionX, newRegionY, sp.Name, Scene.Name); 987 finalDestination.RegionName, newRegionX, newRegionY, sp.Name, Scene.Name);
988=======
989>>>>>>> avn/ubitvar
906 990
907 //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Creating agent...");
908 #region IP Translation for NAT
909 // Uses ipepClient above
910 if (sp.ClientView.TryGet(out ipepClient))
911 {
912 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
913 }
914 #endregion
915 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
916 991
992 if (OutSideViewRange)
993 {
917 if (m_eqModule != null) 994 if (m_eqModule != null)
918 { 995 {
919 // The EnableSimulator message makes the client establish a connection with the destination 996 // The EnableSimulator message makes the client establish a connection with the destination
@@ -943,15 +1020,14 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
943 sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint); 1020 sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint);
944 } 1021 }
945 } 1022 }
946 else
947 {
948 agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
949 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
950 }
951 1023
952 // Let's send a full update of the agent. This is a synchronous call. 1024 // Let's send a full update of the agent. This is a synchronous call.
953 AgentData agent = new AgentData(); 1025 AgentData agent = new AgentData();
954 sp.CopyTo(agent); 1026 sp.CopyTo(agent);
1027
1028 if ((teleportFlags & (uint)TeleportFlags.IsFlying) != 0)
1029 agent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
1030
955 agent.Position = agentCircuit.startpos; 1031 agent.Position = agentCircuit.startpos;
956 SetCallbackURL(agent, sp.Scene.RegionInfo); 1032 SetCallbackURL(agent, sp.Scene.RegionInfo);
957 1033
@@ -1053,7 +1129,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1053 return; 1129 return;
1054 } 1130 }
1055 1131
1056 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
1057 1132
1058 // For backwards compatibility 1133 // For backwards compatibility
1059 if (version == "Unknown" || version == string.Empty) 1134 if (version == "Unknown" || version == string.Empty)
@@ -1063,18 +1138,30 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1063 CrossAttachmentsIntoNewRegion(finalDestination, sp, true); 1138 CrossAttachmentsIntoNewRegion(finalDestination, sp, true);
1064 } 1139 }
1065 1140
1141 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
1142
1143
1066 // May need to logout or other cleanup 1144 // May need to logout or other cleanup
1067 AgentHasMovedAway(sp, logout); 1145// AgentHasMovedAway(sp, logout);
1146// AgentHasMovedAway(sp, true); // until logout use is checked
1068 1147
1069 // Well, this is it. The agent is over there. 1148 // Well, this is it. The agent is over there.
1070 KillEntity(sp.Scene, sp.LocalId); 1149// KillEntity(sp.Scene, sp.LocalId);
1150
1151 sp.HasMovedAway(!OutSideViewRange);
1152
1153 sp.CloseChildAgents(destinationHandle,finalDestination.RegionSizeX,finalDestination.RegionSizeY);
1071 1154
1072 // Now let's make it officially a child agent 1155 // Now let's make it officially a child agent
1073 sp.MakeChildAgent(); 1156 sp.MakeChildAgent(destinationHandle);
1074 1157
1075 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone 1158 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
1076 1159
1160<<<<<<< HEAD
1077 if (NeedsClosing(sp.Scene.DefaultDrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) 1161 if (NeedsClosing(sp.Scene.DefaultDrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
1162=======
1163 if (OutSideViewRange)
1164>>>>>>> avn/ubitvar
1078 { 1165 {
1079 if (!sp.Scene.IncomingPreCloseClient(sp)) 1166 if (!sp.Scene.IncomingPreCloseClient(sp))
1080 return; 1167 return;
@@ -1089,19 +1176,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1089 1176
1090 sp.Scene.CloseAgent(sp.UUID, false); 1177 sp.Scene.CloseAgent(sp.UUID, false);
1091 } 1178 }
1092 else
1093 {
1094 // now we have a child agent in this region.
1095 sp.Reset();
1096 }
1097 } 1179 }
1098 1180
1099 private void TransferAgent_V2(ScenePresence sp, AgentCircuitData agentCircuit, GridRegion reg, GridRegion finalDestination, 1181 private void TransferAgent_V2(ScenePresence sp, AgentCircuitData agentCircuit, GridRegion reg, GridRegion finalDestination,
1100 IPEndPoint endPoint, uint teleportFlags, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, string version, out string reason) 1182 IPEndPoint endPoint, uint teleportFlags, bool OutSideViewRange, string version, out string reason)
1101 { 1183 {
1102 ulong destinationHandle = finalDestination.RegionHandle; 1184 ulong destinationHandle = finalDestination.RegionHandle;
1103 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); 1185 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
1104 1186
1187 string capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);;
1188
1105 // Let's create an agent there if one doesn't exist yet. 1189 // Let's create an agent there if one doesn't exist yet.
1106 // NOTE: logout will always be false for a non-HG teleport. 1190 // NOTE: logout will always be false for a non-HG teleport.
1107 bool logout = false; 1191 bool logout = false;
@@ -1142,6 +1226,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1142 // Past this point we have to attempt clean up if the teleport fails, so update transfer state. 1226 // Past this point we have to attempt clean up if the teleport fails, so update transfer state.
1143 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring); 1227 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring);
1144 1228
1229<<<<<<< HEAD
1145 IClientIPEndpoint ipepClient; 1230 IClientIPEndpoint ipepClient;
1146 string capsPath = String.Empty; 1231 string capsPath = String.Empty;
1147 float dist = (float)Math.Max(sp.Scene.DefaultDrawDistance, 1232 float dist = (float)Math.Max(sp.Scene.DefaultDrawDistance,
@@ -1168,6 +1253,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1168 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); 1253 capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
1169 } 1254 }
1170 1255
1256=======
1257>>>>>>> avn/ubitvar
1171 // We need to set this here to avoid an unlikely race condition when teleporting to a neighbour simulator, 1258 // We need to set this here to avoid an unlikely race condition when teleporting to a neighbour simulator,
1172 // where that neighbour simulator could otherwise request a child agent create on the source which then 1259 // where that neighbour simulator could otherwise request a child agent create on the source which then
1173 // closes our existing agent which is still signalled as root. 1260 // closes our existing agent which is still signalled as root.
@@ -1189,6 +1276,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1189 AgentData agent = new AgentData(); 1276 AgentData agent = new AgentData();
1190 sp.CopyTo(agent); 1277 sp.CopyTo(agent);
1191 agent.Position = agentCircuit.startpos; 1278 agent.Position = agentCircuit.startpos;
1279
1280 if ((teleportFlags & (uint)TeleportFlags.IsFlying) != 0)
1281 agent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
1282
1192 agent.SenderWantsToWaitForRoot = true; 1283 agent.SenderWantsToWaitForRoot = true;
1193 //SetCallbackURL(agent, sp.Scene.RegionInfo); 1284 //SetCallbackURL(agent, sp.Scene.RegionInfo);
1194 1285
@@ -1224,25 +1315,29 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1224 1315
1225 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp); 1316 m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp);
1226 1317
1318 sp.HasMovedAway(!OutSideViewRange);
1319
1227 // Need to signal neighbours whether child agents may need closing irrespective of whether this 1320 // Need to signal neighbours whether child agents may need closing irrespective of whether this
1228 // one needed closing. We also need to close child agents as quickly as possible to avoid complicated 1321 // one needed closing. We also need to close child agents as quickly as possible to avoid complicated
1229 // race conditions with rapid agent releporting (e.g. from A1 to a non-neighbour B, back 1322 // race conditions with rapid agent releporting (e.g. from A1 to a non-neighbour B, back
1230 // to a neighbour A2 then off to a non-neighbour C). Closing child agents any later requires complex 1323 // to a neighbour A2 then off to a non-neighbour C). Closing child agents any later requires complex
1231 // distributed checks to avoid problems in rapid reteleporting scenarios and where child agents are 1324 // distributed checks to avoid problems in rapid reteleporting scenarios and where child agents are
1232 // abandoned without proper close by viewer but then re-used by an incoming connection. 1325 // abandoned without proper close by viewer but then re-used by an incoming connection.
1233 sp.CloseChildAgents(newRegionX, newRegionY); 1326 sp.CloseChildAgents(destinationHandle, finalDestination.RegionSizeX, finalDestination.RegionSizeY);
1234
1235 // May need to logout or other cleanup
1236 AgentHasMovedAway(sp, logout);
1237 1327
1328// AgentHasMovedAway(sp, true);
1238 // Well, this is it. The agent is over there. 1329 // Well, this is it. The agent is over there.
1239 KillEntity(sp.Scene, sp.LocalId); 1330// KillEntity(sp.Scene, sp.LocalId);
1240 1331
1241 // Now let's make it officially a child agent 1332 // Now let's make it officially a child agent
1242 sp.MakeChildAgent(); 1333 sp.MakeChildAgent(destinationHandle);
1243 1334
1244 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone 1335 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
1336<<<<<<< HEAD
1245 if (NeedsClosing(sp.Scene.DefaultDrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) 1337 if (NeedsClosing(sp.Scene.DefaultDrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
1338=======
1339 if (OutSideViewRange)
1340>>>>>>> avn/ubitvar
1246 { 1341 {
1247 if (!sp.Scene.IncomingPreCloseClient(sp)) 1342 if (!sp.Scene.IncomingPreCloseClient(sp))
1248 return; 1343 return;
@@ -1263,11 +1358,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1263 1358
1264 sp.Scene.CloseAgent(sp.UUID, false); 1359 sp.Scene.CloseAgent(sp.UUID, false);
1265 } 1360 }
1361/*
1266 else 1362 else
1267 { 1363 {
1268 // now we have a child agent in this region. 1364 // now we have a child agent in this region.
1269 sp.Reset(); 1365 sp.Reset();
1270 } 1366 }
1367 */
1271 } 1368 }
1272 1369
1273 /// <summary> 1370 /// <summary>
@@ -1351,7 +1448,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1351 protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout) 1448 protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout)
1352 { 1449 {
1353 if (sp.Scene.AttachmentsModule != null) 1450 if (sp.Scene.AttachmentsModule != null)
1354 sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, true); 1451 sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, logout);
1355 } 1452 }
1356 1453
1357 protected void KillEntity(Scene scene, uint localID) 1454 protected void KillEntity(Scene scene, uint localID)
@@ -1368,7 +1465,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1368 // This returns 'true' if the new region already has a child agent for our 1465 // This returns 'true' if the new region already has a child agent for our
1369 // incoming agent. The implication is that, if 'false', we have to create the 1466 // incoming agent. The implication is that, if 'false', we have to create the
1370 // child and then teleport into the region. 1467 // child and then teleport into the region.
1468<<<<<<< HEAD
1371 protected virtual bool NeedsNewAgent(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY) 1469 protected virtual bool NeedsNewAgent(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY)
1470=======
1471 protected virtual bool NeedsNewAgent(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY,
1472 int oldsizeX, int oldsizeY, int newsizeX, int newsizeY)
1473>>>>>>> avn/ubitvar
1372 { 1474 {
1373 if (m_regionCombinerModule != null && m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID)) 1475 if (m_regionCombinerModule != null && m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID))
1374 { 1476 {
@@ -1381,17 +1483,23 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1381 1483
1382 return !(newRegionX >= swCorner.X && newRegionX <= neCorner.X && newRegionY >= swCorner.Y && newRegionY <= neCorner.Y); 1484 return !(newRegionX >= swCorner.X && newRegionX <= neCorner.X && newRegionY >= swCorner.Y && newRegionY <= neCorner.Y);
1383 } 1485 }
1384 else 1486
1385 { 1487 return Util.IsOutsideView(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY,
1386 return Util.IsOutsideView(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY); 1488 oldsizeX, oldsizeY, newsizeX, newsizeY);
1387 }
1388 } 1489 }
1490<<<<<<< HEAD
1389 1491
1390 protected virtual bool NeedsClosing(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg) 1492=======
1493/*
1494 protected virtual bool NeedsClosing(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY,
1495 uint oldsizeX, uint oldsizeY, uint newsizeX, uint newsizeY, GridRegion reg)
1391 { 1496 {
1392 return Util.IsOutsideView(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY);
1393 }
1394 1497
1498 return Util.IsOutsideView(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY,
1499 oldsizeX, oldsizeY, newsizeX, newsizeY);
1500 }
1501*/
1502>>>>>>> avn/ubitvar
1395 #endregion 1503 #endregion
1396 1504
1397 #region Landmark Teleport 1505 #region Landmark Teleport
@@ -1472,14 +1580,20 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1472 1580
1473 #region Agent Crossings 1581 #region Agent Crossings
1474 1582
1583<<<<<<< HEAD
1475 // Given a position relative to the current region (which has previously been tested to 1584 // Given a position relative to the current region (which has previously been tested to
1476 // see that it is actually outside the current region), find the new region that the 1585 // see that it is actually outside the current region), find the new region that the
1477 // point is actually in. 1586 // point is actually in.
1478 // Returns the coordinates and information of the new region or 'null' of it doesn't exist. 1587 // Returns the coordinates and information of the new region or 'null' of it doesn't exist.
1479 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, 1588 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos,
1480 out string version, out Vector3 newpos, out string failureReason) 1589 out string version, out Vector3 newpos, out string failureReason)
1590=======
1591 public bool checkAgentAccessToRegion(ScenePresence agent, GridRegion destiny, Vector3 position, out string version, out string reason)
1592>>>>>>> avn/ubitvar
1481 { 1593 {
1594 reason = String.Empty;
1482 version = String.Empty; 1595 version = String.Empty;
1596<<<<<<< HEAD
1483 newpos = pos; 1597 newpos = pos;
1484 failureReason = string.Empty; 1598 failureReason = string.Empty;
1485 string homeURI = scene.GetAgentHomeURI(agentID); 1599 string homeURI = scene.GetAgentHomeURI(agentID);
@@ -1541,32 +1655,180 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1541 LogHeader, neighbourRegion.RegionName, 1655 LogHeader, neighbourRegion.RegionName,
1542 neighbourRegion.RegionLocX, neighbourRegion.RegionLocY, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY, 1656 neighbourRegion.RegionLocX, neighbourRegion.RegionLocY, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY,
1543 newpos.X, newpos.Y); 1657 newpos.X, newpos.Y);
1658=======
1659
1660 UUID agentID = agent.UUID;
1661 ulong destinyHandle = destiny.RegionHandle;
1662
1663 if (m_bannedRegionCache.IfBanned(destinyHandle, agentID))
1664 {
1665 reason = "Cannot connect to region";
1666 return false;
1667 }
1668
1669 Scene ascene = agent.Scene;
1670 string homeURI = ascene.GetAgentHomeURI(agentID);
1671 string myversion = string.Format("{0}/{1}", OutgoingTransferVersionName, MaxOutgoingTransferVersion);
1672
1673
1674 if (!ascene.SimulationService.QueryAccess(destiny, agentID, homeURI, false, position,
1675 myversion, out version, out reason))
1676 {
1677 m_bannedRegionCache.Add(destinyHandle, agentID, 30.0, 30.0);
1678 return false;
1679 }
1680
1681 return true;
1682 }
1683
1684 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version, out Vector3 newpos)
1685 {
1686 string r = String.Empty;
1687 return GetDestination(scene, agentID, pos, out version, out newpos, out r);
1688 }
1689
1690 // Given a position relative to the current region (which has previously been tested to
1691 // see that it is actually outside the current region), find the new region that the
1692 // point is actually in.
1693 // Returns the coordinates and information of the new region or 'null' of it doesn't exist.
1694
1695 // now only works for crossings
1696
1697 public GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos,
1698 out string version, out Vector3 newpos, out string failureReason)
1699 {
1700 version = String.Empty;
1701 newpos = pos;
1702 failureReason = string.Empty;
1703
1704// m_log.DebugFormat(
1705// "[ENTITY TRANSFER MODULE]: Crossing agent {0} at pos {1} in {2}", agent.Name, pos, scene.Name);
1706
1707 // Compute world location of the object's position
1708 double presenceWorldX = (double)scene.RegionInfo.WorldLocX + pos.X;
1709 double presenceWorldY = (double)scene.RegionInfo.WorldLocY + pos.Y;
1710
1711 // Call the grid service to lookup the region containing the new position.
1712 GridRegion neighbourRegion = GetRegionContainingWorldLocation(scene.GridService, scene.RegionInfo.ScopeID,
1713 presenceWorldX, presenceWorldY,
1714 Math.Max(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY));
1715
1716 if (neighbourRegion != null)
1717 {
1718 // Compute the entity's position relative to the new region
1719 newpos = new Vector3((float)(presenceWorldX - (double)neighbourRegion.RegionLocX),
1720 (float)(presenceWorldY - (double)neighbourRegion.RegionLocY),
1721 pos.Z);
1722
1723 if (m_bannedRegionCache.IfBanned(neighbourRegion.RegionHandle, agentID))
1724 {
1725 failureReason = "Cannot region cross into banned parcel";
1726 neighbourRegion = null;
1727 }
1728 else
1729 {
1730 // If not banned, make sure this agent is not in the list.
1731 m_bannedRegionCache.Remove(neighbourRegion.RegionHandle, agentID);
1732 }
1733
1734 // Check to see if we have access to the target region.
1735 string myversion = string.Format("{0}/{1}", OutgoingTransferVersionName, MaxOutgoingTransferVersion);
1736 string homeURI = scene.GetAgentHomeURI(agentID);
1737 if (neighbourRegion != null
1738 && !scene.SimulationService.QueryAccess(neighbourRegion, agentID, homeURI, false, newpos, myversion, out version, out failureReason))
1739 {
1740 // remember banned
1741 m_bannedRegionCache.Add(neighbourRegion.RegionHandle, agentID);
1742 neighbourRegion = null;
1743 }
1744 }
1745 else
1746 {
1747 // The destination region just doesn't exist
1748 failureReason = "Cannot cross into non-existent region";
1749 }
1750>>>>>>> avn/ubitvar
1751
1752 if (neighbourRegion == null)
1753 m_log.DebugFormat("{0} GetDestination: region not found. Old region name={1} at <{2},{3}> of size <{4},{5}>. Old pos={6}",
1754 LogHeader, scene.RegionInfo.RegionName,
1755 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
1756 scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY,
1757 pos);
1758 else
1759 m_log.DebugFormat("{0} GetDestination: new region={1} at <{2},{3}> of size <{4},{5}>, newpos=<{6},{7}>",
1760 LogHeader, neighbourRegion.RegionName,
1761 neighbourRegion.RegionLocX, neighbourRegion.RegionLocY, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY,
1762 newpos.X, newpos.Y);
1544 1763
1545 return neighbourRegion; 1764 return neighbourRegion;
1546 } 1765 }
1547 1766
1548 public bool Cross(ScenePresence agent, bool isFlying) 1767 public bool Cross(ScenePresence agent, bool isFlying)
1549 { 1768 {
1769<<<<<<< HEAD
1770=======
1771 agent.IsInTransit = true;
1772 CrossAsyncDelegate d = CrossAsync;
1773 d.BeginInvoke(agent, isFlying, CrossCompleted, d);
1774 return true;
1775 }
1776
1777 private void CrossCompleted(IAsyncResult iar)
1778 {
1779 CrossAsyncDelegate icon = (CrossAsyncDelegate)iar.AsyncState;
1780 ScenePresence agent = icon.EndInvoke(iar);
1781
1782 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
1783
1784 if(!agent.IsChildAgent)
1785 {
1786 // crossing failed
1787 agent.CrossToNewRegionFail();
1788 }
1789 agent.IsInTransit = false;
1790 }
1791
1792 public ScenePresence CrossAsync(ScenePresence agent, bool isFlying)
1793 {
1794 uint x;
1795 uint y;
1796>>>>>>> avn/ubitvar
1550 Vector3 newpos; 1797 Vector3 newpos;
1551 string version; 1798 string version;
1552 string failureReason; 1799 string failureReason;
1553 1800
1801<<<<<<< HEAD
1554 GridRegion neighbourRegion = GetDestination(agent.Scene, agent.UUID, agent.AbsolutePosition, 1802 GridRegion neighbourRegion = GetDestination(agent.Scene, agent.UUID, agent.AbsolutePosition,
1555 out version, out newpos, out failureReason); 1803 out version, out newpos, out failureReason);
1556 if (neighbourRegion == null) 1804 if (neighbourRegion == null)
1557 { 1805 {
1558 agent.ControllingClient.SendAlertMessage(failureReason); 1806 agent.ControllingClient.SendAlertMessage(failureReason);
1559 return false; 1807 return false;
1560 } 1808=======
1809 Vector3 pos = agent.AbsolutePosition + agent.Velocity;
1561 1810
1562 agent.IsInTransit = true; 1811 GridRegion neighbourRegion = GetDestination(agent.Scene, agent.UUID, pos,
1812 out version, out newpos, out failureReason);
1813 if (neighbourRegion == null)
1814 {
1815 if (failureReason != String.Empty)
1816 agent.ControllingClient.SendAlertMessage(failureReason);
1817 return agent;
1818>>>>>>> avn/ubitvar
1819 }
1563 1820
1564 CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync; 1821// agent.IsInTransit = true;
1565 d.BeginInvoke(agent, newpos, neighbourRegion, isFlying, version, CrossAgentToNewRegionCompleted, d);
1566 1822
1823<<<<<<< HEAD
1567 Scene.EventManager.TriggerCrossAgentToNewRegion(agent, isFlying, neighbourRegion); 1824 Scene.EventManager.TriggerCrossAgentToNewRegion(agent, isFlying, neighbourRegion);
1568 1825
1569 return true; 1826 return true;
1827=======
1828 CrossAgentToNewRegionAsync(agent, newpos, neighbourRegion, isFlying, version);
1829 agent.IsInTransit = false;
1830 return agent;
1831>>>>>>> avn/ubitvar
1570 } 1832 }
1571 1833
1572 1834
@@ -1691,12 +1953,23 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1691 1953
1692 public bool CrossAgentIntoNewRegionMain(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying) 1954 public bool CrossAgentIntoNewRegionMain(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying)
1693 { 1955 {
1956 int ts = Util.EnvironmentTickCount();
1694 try 1957 try
1695 { 1958 {
1696 AgentData cAgent = new AgentData(); 1959 AgentData cAgent = new AgentData();
1697 agent.CopyTo(cAgent); 1960 agent.CopyTo(cAgent);
1961<<<<<<< HEAD
1698 cAgent.Position = pos; 1962 cAgent.Position = pos;
1699 1963
1964=======
1965
1966// agent.Appearance.WearableCacheItems = null;
1967
1968 cAgent.Position = pos;
1969
1970 cAgent.ChildrenCapSeeds = agent.KnownRegions;
1971
1972>>>>>>> avn/ubitvar
1700 if (isFlying) 1973 if (isFlying)
1701 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY; 1974 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
1702 1975
@@ -1716,11 +1989,14 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1716 neighbourRegion.RegionName, agent.Name); 1989 neighbourRegion.RegionName, agent.Name);
1717 1990
1718 ReInstantiateScripts(agent); 1991 ReInstantiateScripts(agent);
1719 agent.AddToPhysicalScene(isFlying); 1992 if(agent.ParentID == 0 && agent.ParentUUID == UUID.Zero)
1993 agent.AddToPhysicalScene(isFlying);
1720 1994
1721 return false; 1995 return false;
1722 } 1996 }
1723 1997
1998 m_log.DebugFormat("[CrossAgentIntoNewRegionMain] ok, time {0}ms",Util.EnvironmentTickCountSubtract(ts));
1999
1724 } 2000 }
1725 catch (Exception e) 2001 catch (Exception e)
1726 { 2002 {
@@ -1738,7 +2014,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1738 public void CrossAgentToNewRegionPost(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, 2014 public void CrossAgentToNewRegionPost(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion,
1739 bool isFlying, string version) 2015 bool isFlying, string version)
1740 { 2016 {
1741 agent.ControllingClient.RequestClientInfo();
1742 2017
1743 string agentcaps; 2018 string agentcaps;
1744 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps)) 2019 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
@@ -1749,6 +2024,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1749 } 2024 }
1750 2025
1751 // No turning back 2026 // No turning back
2027
1752 agent.IsChildAgent = true; 2028 agent.IsChildAgent = true;
1753 2029
1754 string capsPath = neighbourRegion.ServerURI + CapsUtil.GetCapsSeedPath(agentcaps); 2030 string capsPath = neighbourRegion.ServerURI + CapsUtil.GetCapsSeedPath(agentcaps);
@@ -1760,7 +2036,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1760 if (m_eqModule != null) 2036 if (m_eqModule != null)
1761 { 2037 {
1762 m_eqModule.CrossRegion( 2038 m_eqModule.CrossRegion(
1763 neighbourRegion.RegionHandle, pos + agent.Velocity, vel2 /* agent.Velocity */, 2039 neighbourRegion.RegionHandle, pos, vel2 /* agent.Velocity */,
1764 neighbourRegion.ExternalEndPoint, 2040 neighbourRegion.ExternalEndPoint,
1765 capsPath, agent.UUID, agent.ControllingClient.SessionId, 2041 capsPath, agent.UUID, agent.ControllingClient.SessionId,
1766 neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY); 2042 neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY);
@@ -1768,10 +2044,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1768 else 2044 else
1769 { 2045 {
1770 m_log.ErrorFormat("{0} Using old CrossRegion packet. Varregion will not work!!", LogHeader); 2046 m_log.ErrorFormat("{0} Using old CrossRegion packet. Varregion will not work!!", LogHeader);
1771 agent.ControllingClient.CrossRegion(neighbourRegion.RegionHandle, pos + agent.Velocity, agent.Velocity, neighbourRegion.ExternalEndPoint, 2047 agent.ControllingClient.CrossRegion(neighbourRegion.RegionHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
1772 capsPath); 2048 capsPath);
1773 } 2049 }
1774 2050
2051<<<<<<< HEAD
1775 // SUCCESS! 2052 // SUCCESS!
1776 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.ReceivedAtDestination); 2053 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.ReceivedAtDestination);
1777 2054
@@ -1788,6 +2065,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1788 agent.SendOtherAgentsAvatarDataToClient(); 2065 agent.SendOtherAgentsAvatarDataToClient();
1789 agent.SendOtherAgentsAppearanceToClient(); 2066 agent.SendOtherAgentsAppearanceToClient();
1790 2067
2068=======
2069>>>>>>> avn/ubitvar
1791 // Backwards compatibility. Best effort 2070 // Backwards compatibility. Best effort
1792 if (version == "Unknown" || version == string.Empty) 2071 if (version == "Unknown" || version == string.Empty)
1793 { 2072 {
@@ -1796,14 +2075,31 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1796 CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true); 2075 CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true);
1797 } 2076 }
1798 2077
2078<<<<<<< HEAD
1799 // Next, let's close the child agent connections that are too far away. 2079 // Next, let's close the child agent connections that are too far away.
1800 uint neighbourx; 2080 uint neighbourx;
1801 uint neighboury; 2081 uint neighboury;
1802 Util.RegionHandleToRegionLoc(neighbourRegion.RegionHandle, out neighbourx, out neighboury); 2082 Util.RegionHandleToRegionLoc(neighbourRegion.RegionHandle, out neighbourx, out neighboury);
2083=======
2084 // SUCCESS!
2085 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.ReceivedAtDestination);
2086
2087 // Unlike a teleport, here we do not wait for the destination region to confirm the receipt.
2088 m_entityTransferStateMachine.UpdateInTransit(agent.UUID, AgentTransferState.CleaningUp);
1803 2089
1804 agent.CloseChildAgents(neighbourx, neighboury); 2090 // this may need the attachments
2091
2092 agent.HasMovedAway(true);
2093
2094 agent.MakeChildAgent(neighbourRegion.RegionHandle);
2095
2096 // FIXME: Possibly this should occur lower down after other commands to close other agents,
2097 // but not sure yet what the side effects would be.
2098 m_entityTransferStateMachine.ResetFromTransit(agent.UUID);
2099>>>>>>> avn/ubitvar
2100
2101 agent.CloseChildAgents(neighbourRegion.RegionHandle, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY);
1805 2102
1806 AgentHasMovedAway(agent, false);
1807 2103
1808 // the user may change their profile information in other region, 2104 // the user may change their profile information in other region,
1809 // so the userinfo in UserProfileCache is not reliable any more, delete it 2105 // so the userinfo in UserProfileCache is not reliable any more, delete it
@@ -1843,7 +2139,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1843 #region Enable Child Agent 2139 #region Enable Child Agent
1844 2140
1845 /// <summary> 2141 /// <summary>
1846 /// This informs a single neighbouring region about agent "avatar". 2142 /// This informs a single neighbouring region about agent "avatar", and avatar about it
1847 /// Calls an asynchronous method to do so.. so it doesn't lag the sim. 2143 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
1848 /// </summary> 2144 /// </summary>
1849 /// <param name="sp"></param> 2145 /// <param name="sp"></param>
@@ -1852,22 +2148,36 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1852 { 2148 {
1853 m_log.DebugFormat("[ENTITY TRANSFER]: Enabling child agent in new neighbour {0}", region.RegionName); 2149 m_log.DebugFormat("[ENTITY TRANSFER]: Enabling child agent in new neighbour {0}", region.RegionName);
1854 2150
2151 ulong currentRegionHandler = sp.Scene.RegionInfo.RegionHandle;
2152 ulong regionhandler = region.RegionHandle;
2153
2154 Dictionary<ulong, string> seeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
2155
2156 if (seeds.ContainsKey(regionhandler))
2157 seeds.Remove(regionhandler);
2158/*
2159 List<ulong> oldregions = new List<ulong>(seeds.Keys);
2160
2161 if (oldregions.Contains(currentRegionHandler))
2162 oldregions.Remove(currentRegionHandler);
2163*/
2164 if (!seeds.ContainsKey(currentRegionHandler))
2165 seeds.Add(currentRegionHandler, sp.ControllingClient.RequestClientInfo().CapsPath);
2166
1855 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); 2167 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
1856 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo(); 2168 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
1857 agent.BaseFolder = UUID.Zero; 2169 agent.BaseFolder = UUID.Zero;
1858 agent.InventoryFolder = UUID.Zero; 2170 agent.InventoryFolder = UUID.Zero;
1859 agent.startpos = new Vector3(128, 128, 70); 2171 agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, region);
1860 agent.child = true; 2172 agent.child = true;
1861 agent.Appearance = sp.Appearance; 2173 agent.Appearance = new AvatarAppearance();
1862 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath(); 2174 agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight;
1863 2175
1864 agent.ChildrenCapSeeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID)); 2176 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
1865 //m_log.DebugFormat("[XXX] Seeds 1 {0}", agent.ChildrenCapSeeds.Count);
1866 2177
1867 if (!agent.ChildrenCapSeeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle)) 2178 seeds.Add(regionhandler, agent.CapsPath);
1868 agent.ChildrenCapSeeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
1869 //m_log.DebugFormat("[XXX] Seeds 2 {0}", agent.ChildrenCapSeeds.Count);
1870 2179
2180<<<<<<< HEAD
1871 sp.AddNeighbourRegion(region.RegionHandle, agent.CapsPath); 2181 sp.AddNeighbourRegion(region.RegionHandle, agent.CapsPath);
1872 //foreach (ulong h in agent.ChildrenCapSeeds.Keys) 2182 //foreach (ulong h in agent.ChildrenCapSeeds.Keys)
1873 // m_log.DebugFormat("[XXX] --> {0}", h); 2183 // m_log.DebugFormat("[XXX] --> {0}", h);
@@ -1881,12 +2191,19 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1881 } 2191 }
1882 2192
1883 agent.ChildrenCapSeeds[region.RegionHandle] = agent.CapsPath; 2193 agent.ChildrenCapSeeds[region.RegionHandle] = agent.CapsPath;
2194=======
2195// agent.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
2196 agent.ChildrenCapSeeds = null;
2197>>>>>>> avn/ubitvar
1884 2198
1885 if (sp.Scene.CapsModule != null) 2199 if (sp.Scene.CapsModule != null)
1886 { 2200 {
1887 sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, agent.ChildrenCapSeeds); 2201 sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds);
1888 } 2202 }
1889 2203
2204 sp.KnownRegions = seeds;
2205 sp.AddNeighbourRegionSizeInfo(region);
2206
1890 if (currentAgentCircuit != null) 2207 if (currentAgentCircuit != null)
1891 { 2208 {
1892 agent.ServiceURLs = currentAgentCircuit.ServiceURLs; 2209 agent.ServiceURLs = currentAgentCircuit.ServiceURLs;
@@ -1896,7 +2213,24 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1896 agent.Mac = currentAgentCircuit.Mac; 2213 agent.Mac = currentAgentCircuit.Mac;
1897 agent.Id0 = currentAgentCircuit.Id0; 2214 agent.Id0 = currentAgentCircuit.Id0;
1898 } 2215 }
1899 2216/*
2217 AgentPosition agentpos = null;
2218
2219 if (oldregions.Count > 0)
2220 {
2221 agentpos = new AgentPosition();
2222 agentpos.AgentID = new UUID(sp.UUID.Guid);
2223 agentpos.SessionID = sp.ControllingClient.SessionId;
2224 agentpos.Size = sp.Appearance.AvatarSize;
2225 agentpos.Center = sp.CameraPosition;
2226 agentpos.Far = sp.DrawDistance;
2227 agentpos.Position = sp.AbsolutePosition;
2228 agentpos.Velocity = sp.Velocity;
2229 agentpos.RegionHandle = currentRegionHandler;
2230 agentpos.Throttles = sp.ControllingClient.GetThrottlesPacked(1);
2231 agentpos.ChildrenCapSeeds = seeds;
2232 }
2233*/
1900 IPEndPoint external = region.ExternalEndPoint; 2234 IPEndPoint external = region.ExternalEndPoint;
1901 if (external != null) 2235 if (external != null)
1902 { 2236 {
@@ -1905,7 +2239,23 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1905 InformClientOfNeighbourCompleted, 2239 InformClientOfNeighbourCompleted,
1906 d); 2240 d);
1907 } 2241 }
2242/*
2243 if(oldregions.Count >0)
2244 {
2245 uint neighbourx;
2246 uint neighboury;
2247 UUID scope = sp.Scene.RegionInfo.ScopeID;
2248 foreach (ulong handler in oldregions)
2249 {
2250 // crap code
2251 Utils.LongToUInts(handler, out neighbourx, out neighboury);
2252 GridRegion neighbour = sp.Scene.GridService.GetRegionByPosition(scope, (int)neighbourx, (int)neighboury);
2253 sp.Scene.SimulationService.UpdateAgent(neighbour, agentpos);
2254 }
2255 }
2256 */
1908 } 2257 }
2258
1909 #endregion 2259 #endregion
1910 2260
1911 #region Enable Child Agents 2261 #region Enable Child Agents
@@ -1915,146 +2265,157 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
1915 2265
1916 /// <summary> 2266 /// <summary>
1917 /// This informs all neighbouring regions about agent "avatar". 2267 /// This informs all neighbouring regions about agent "avatar".
2268 /// and as important informs the avatar about then
1918 /// </summary> 2269 /// </summary>
1919 /// <param name="sp"></param> 2270 /// <param name="sp"></param>
1920 public void EnableChildAgents(ScenePresence sp) 2271 public void EnableChildAgents(ScenePresence sp)
1921 { 2272 {
2273 // assumes that out of view range regions are disconnected by the previus region
2274
1922 List<GridRegion> neighbours = new List<GridRegion>(); 2275 List<GridRegion> neighbours = new List<GridRegion>();
1923 RegionInfo m_regionInfo = sp.Scene.RegionInfo; 2276 Scene spScene = sp.Scene;
2277 RegionInfo m_regionInfo = spScene.RegionInfo;
1924 2278
1925 if (m_regionInfo != null) 2279 if (m_regionInfo != null)
1926 { 2280 {
2281<<<<<<< HEAD
1927 neighbours = GetNeighbours(sp, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY); 2282 neighbours = GetNeighbours(sp, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
2283=======
2284 neighbours = GetNeighbors(sp, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
2285>>>>>>> avn/ubitvar
1928 } 2286 }
1929 else 2287 else
1930 { 2288 {
1931 m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?"); 2289 m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?");
1932 } 2290 }
1933 2291
1934 /// We need to find the difference between the new regions where there are no child agents 2292 ulong currentRegionHandler = m_regionInfo.RegionHandle;
1935 /// and the regions where there are already child agents. We only send notification to the former.
1936 List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
1937 neighbourHandles.Add(sp.Scene.RegionInfo.RegionHandle); // add this region too
1938 List<ulong> previousRegionNeighbourHandles;
1939 2293
1940 if (sp.Scene.CapsModule != null) 2294 LinkedList<ulong> previousRegionNeighbourHandles;
2295 Dictionary<ulong, string> seeds;
2296 ICapabilitiesModule capsModule = spScene.CapsModule;
2297
2298 if (capsModule != null)
1941 { 2299 {
1942 previousRegionNeighbourHandles = 2300 seeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(sp.UUID));
1943 new List<ulong>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID).Keys); 2301 previousRegionNeighbourHandles = new LinkedList<ulong>(seeds.Keys);
1944 } 2302 }
1945 else 2303 else
1946 { 2304 {
1947 previousRegionNeighbourHandles = new List<ulong>(); 2305 seeds = new Dictionary<ulong, string>();
2306 previousRegionNeighbourHandles = new LinkedList<ulong>();
1948 } 2307 }
1949 2308
1950 List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles); 2309 IClientAPI spClient = sp.ControllingClient;
1951 List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles);
1952
1953// Dump("Current Neighbors", neighbourHandles);
1954// Dump("Previous Neighbours", previousRegionNeighbourHandles);
1955// Dump("New Neighbours", newRegions);
1956// Dump("Old Neighbours", oldRegions);
1957 2310
1958 /// Update the scene presence's known regions here on this region 2311 if (!seeds.ContainsKey(currentRegionHandler))
1959 sp.DropOldNeighbours(oldRegions); 2312 seeds.Add(currentRegionHandler, spClient.RequestClientInfo().CapsPath);
1960 2313
1961 /// Collect as many seeds as possible 2314 AgentCircuitData currentAgentCircuit =
1962 Dictionary<ulong, string> seeds; 2315 spScene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
1963 if (sp.Scene.CapsModule != null)
1964 seeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
1965 else
1966 seeds = new Dictionary<ulong, string>();
1967 2316
1968 //m_log.Debug(" !!! No. of seeds: " + seeds.Count);
1969 if (!seeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle))
1970 seeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
1971
1972 /// Create the necessary child agents
1973 List<AgentCircuitData> cagents = new List<AgentCircuitData>(); 2317 List<AgentCircuitData> cagents = new List<AgentCircuitData>();
2318 List<ulong> newneighbours = new List<ulong>();
2319
1974 foreach (GridRegion neighbour in neighbours) 2320 foreach (GridRegion neighbour in neighbours)
1975 { 2321 {
1976 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle) 2322 ulong handler = neighbour.RegionHandle;
2323
2324 if (previousRegionNeighbourHandles.Contains(handler))
1977 { 2325 {
1978 AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); 2326 // agent already knows this region
1979 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo(); 2327 previousRegionNeighbourHandles.Remove(handler);
1980 agent.BaseFolder = UUID.Zero; 2328 continue;
1981 agent.InventoryFolder = UUID.Zero; 2329 }
1982 agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, neighbour);
1983 agent.child = true;
1984 agent.Appearance = sp.Appearance;
1985 if (currentAgentCircuit != null)
1986 {
1987 agent.ServiceURLs = currentAgentCircuit.ServiceURLs;
1988 agent.IPAddress = currentAgentCircuit.IPAddress;
1989 agent.Viewer = currentAgentCircuit.Viewer;
1990 agent.Channel = currentAgentCircuit.Channel;
1991 agent.Mac = currentAgentCircuit.Mac;
1992 agent.Id0 = currentAgentCircuit.Id0;
1993 }
1994 2330
1995 if (newRegions.Contains(neighbour.RegionHandle)) 2331 if (handler == currentRegionHandler)
1996 { 2332 continue;
1997 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
1998 sp.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath);
1999 seeds.Add(neighbour.RegionHandle, agent.CapsPath);
2000 }
2001 else
2002 {
2003 agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle);
2004 }
2005 2333
2006 cagents.Add(agent); 2334 // a new region to add
2335 AgentCircuitData agent = spClient.RequestClientInfo();
2336 agent.BaseFolder = UUID.Zero;
2337 agent.InventoryFolder = UUID.Zero;
2338 agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, neighbour);
2339 agent.child = true;
2340 agent.Appearance = new AvatarAppearance();
2341 agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight;
2342
2343 if (currentAgentCircuit != null)
2344 {
2345 agent.ServiceURLs = currentAgentCircuit.ServiceURLs;
2346 agent.IPAddress = currentAgentCircuit.IPAddress;
2347 agent.Viewer = currentAgentCircuit.Viewer;
2348 agent.Channel = currentAgentCircuit.Channel;
2349 agent.Mac = currentAgentCircuit.Mac;
2350 agent.Id0 = currentAgentCircuit.Id0;
2007 } 2351 }
2008 }
2009 2352
2010 /// Update all child agent with everyone's seeds 2353 newneighbours.Add(handler);
2011 foreach (AgentCircuitData a in cagents) 2354 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
2012 { 2355 seeds.Add(handler, agent.CapsPath);
2013 a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
2014 }
2015 2356
2016 if (sp.Scene.CapsModule != null) 2357 agent.ChildrenCapSeeds = null;
2017 { 2358 cagents.Add(agent);
2018 sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds);
2019 } 2359 }
2020 sp.KnownRegions = seeds;
2021 //avatar.Scene.DumpChildrenSeeds(avatar.UUID);
2022 //avatar.DumpKnownRegions();
2023 2360
2024 bool newAgent = false; 2361 if (previousRegionNeighbourHandles.Contains(currentRegionHandler))
2025 int count = 0; 2362 previousRegionNeighbourHandles.Remove(currentRegionHandler);
2026 foreach (GridRegion neighbour in neighbours) 2363
2027 { 2364 // previousRegionNeighbourHandles now contains regions to forget
2028 //m_log.WarnFormat("--> Going to send child agent to {0}", neighbour.RegionName); 2365 foreach (ulong handler in previousRegionNeighbourHandles)
2029 // Don't do it if there's already an agent in that region 2366 seeds.Remove(handler);
2030 if (newRegions.Contains(neighbour.RegionHandle)) 2367
2031 newAgent = true; 2368 /// Update all child agent with everyone's seeds
2032 else 2369 // foreach (AgentCircuitData a in cagents)
2033 newAgent = false; 2370 // a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
2034// continue; 2371
2372 if (capsModule != null)
2373 capsModule.SetChildrenSeed(sp.UUID, seeds);
2035 2374
2036 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle) 2375 sp.KnownRegions = seeds;
2376 sp.SetNeighbourRegionSizeInfo(neighbours);
2377
2378 AgentPosition agentpos = new AgentPosition();
2379 agentpos.AgentID = new UUID(sp.UUID.Guid);
2380 agentpos.SessionID = spClient.SessionId;
2381 agentpos.Size = sp.Appearance.AvatarSize;
2382 agentpos.Center = sp.CameraPosition;
2383 agentpos.Far = sp.DrawDistance;
2384 agentpos.Position = sp.AbsolutePosition;
2385 agentpos.Velocity = sp.Velocity;
2386 agentpos.RegionHandle = currentRegionHandler;
2387 agentpos.Throttles = spClient.GetThrottlesPacked(1);
2388 // agentpos.ChildrenCapSeeds = seeds;
2389
2390 Util.FireAndForget(delegate
2391 {
2392 Thread.Sleep(200); // the original delay that was at InformClientOfNeighbourAsync start
2393 int count = 0;
2394
2395 foreach (GridRegion neighbour in neighbours)
2037 { 2396 {
2397 ulong handler = neighbour.RegionHandle;
2038 try 2398 try
2039 { 2399 {
2040 // Let's put this back at sync, so that it doesn't clog 2400 if (newneighbours.Contains(handler))
2041 // the network, especially for regions in the same physical server. 2401 {
2042 // We're really not in a hurry here. 2402 InformClientOfNeighbourAsync(sp, cagents[count], neighbour,
2043 InformClientOfNeighbourAsync(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent); 2403 neighbour.ExternalEndPoint, true);
2044 //InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync; 2404 count++;
2045 //d.BeginInvoke(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent, 2405 }
2046 // InformClientOfNeighbourCompleted, 2406 else if (!previousRegionNeighbourHandles.Contains(handler))
2047 // d); 2407 {
2408 spScene.SimulationService.UpdateAgent(neighbour, agentpos);
2409 }
2048 } 2410 }
2049
2050 catch (ArgumentOutOfRangeException) 2411 catch (ArgumentOutOfRangeException)
2051 { 2412 {
2052 m_log.ErrorFormat( 2413 m_log.ErrorFormat(
2053 "[ENTITY TRANSFER MODULE]: Neighbour Regions response included the current region in the neighbour list. The following region will not display to the client: {0} for region {1} ({2}, {3}).", 2414 "[ENTITY TRANSFER MODULE]: Neighbour Regions response included the current region in the neighbour list. The following region will not display to the client: {0} for region {1} ({2}, {3}).",
2054 neighbour.ExternalHostName, 2415 neighbour.ExternalHostName,
2055 neighbour.RegionHandle, 2416 neighbour.RegionHandle,
2056 neighbour.RegionLocX, 2417 neighbour.RegionLocX,
2057 neighbour.RegionLocY); 2418 neighbour.RegionLocY);
2058 } 2419 }
2059 catch (Exception e) 2420 catch (Exception e)
2060 { 2421 {
@@ -2071,13 +2432,106 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2071 2432
2072 // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes. 2433 // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
2073 // throw e; 2434 // throw e;
2435 }
2436 }
2437 });
2438 }
2439
2440 // Computes the difference between two region bases.
2441 // Returns a vector of world coordinates (meters) from base of first region to the second.
2442 // The first region is the home region of the passed scene presence.
2443 Vector3 CalculateOffset(ScenePresence sp, GridRegion neighbour)
2444 {
2445 return new Vector3(sp.Scene.RegionInfo.WorldLocX - neighbour.RegionLocX,
2446 sp.Scene.RegionInfo.WorldLocY - neighbour.RegionLocY,
2447 0f);
2448 }
2449
2074 2450
2451 #region NotFoundLocationCache class
2452 // A collection of not found locations to make future lookups 'not found' lookups quick.
2453 // A simple expiring cache that keeps not found locations for some number of seconds.
2454 // A 'not found' location is presumed to be anywhere in the minimum sized region that
2455 // contains that point. A conservitive estimate.
2456 private class NotFoundLocationCache
2457 {
2458 private struct NotFoundLocation
2459 {
2460 public double minX, maxX, minY, maxY;
2461 public DateTime expireTime;
2462 }
2463 private List<NotFoundLocation> m_notFoundLocations = new List<NotFoundLocation>();
2464 public NotFoundLocationCache()
2465 {
2466 }
2467 // Add an area to the list of 'not found' places. The area is the snapped region
2468 // area around the added point.
2469 public void Add(double pX, double pY)
2470 {
2471 lock (m_notFoundLocations)
2472 {
2473 if (!LockedContains(pX, pY))
2474 {
2475 NotFoundLocation nfl = new NotFoundLocation();
2476 // A not found location is not found for at least a whole region sized area
2477 nfl.minX = pX - (pX % (double)Constants.RegionSize);
2478 nfl.minY = pY - (pY % (double)Constants.RegionSize);
2479 nfl.maxX = nfl.minX + (double)Constants.RegionSize;
2480 nfl.maxY = nfl.minY + (double)Constants.RegionSize;
2481 nfl.expireTime = DateTime.Now + TimeSpan.FromSeconds(30);
2482 m_notFoundLocations.Add(nfl);
2483 }
2484 }
2485
2486 }
2487 // Test to see of this point is in any of the 'not found' areas.
2488 // Return 'true' if the point is found inside the 'not found' areas.
2489 public bool Contains(double pX, double pY)
2490 {
2491 bool ret = false;
2492 lock (m_notFoundLocations)
2493 ret = LockedContains(pX, pY);
2494 return ret;
2495 }
2496 private bool LockedContains(double pX, double pY)
2497 {
2498 bool ret = false;
2499 this.DoExpiration();
2500 foreach (NotFoundLocation nfl in m_notFoundLocations)
2501 {
2502 if (pX >= nfl.minX && pX < nfl.maxX && pY >= nfl.minY && pY < nfl.maxY)
2503 {
2504 ret = true;
2505 break;
2075 } 2506 }
2076 } 2507 }
2077 count++; 2508 return ret;
2509 }
2510 private void DoExpiration()
2511 {
2512 List<NotFoundLocation> m_toRemove = null;
2513 DateTime now = DateTime.Now;
2514 foreach (NotFoundLocation nfl in m_notFoundLocations)
2515 {
2516 if (nfl.expireTime < now)
2517 {
2518 if (m_toRemove == null)
2519 m_toRemove = new List<NotFoundLocation>();
2520 m_toRemove.Add(nfl);
2521 }
2522 }
2523 if (m_toRemove != null)
2524 {
2525 foreach (NotFoundLocation nfl in m_toRemove)
2526 m_notFoundLocations.Remove(nfl);
2527 m_toRemove.Clear();
2528 }
2078 } 2529 }
2079 } 2530 }
2531 #endregion // NotFoundLocationCache class
2532 private NotFoundLocationCache m_notFoundLocationCache = new NotFoundLocationCache();
2080 2533
2534<<<<<<< HEAD
2081 // Computes the difference between two region bases. 2535 // Computes the difference between two region bases.
2082 // Returns a vector of world coordinates (meters) from base of first region to the second. 2536 // Returns a vector of world coordinates (meters) from base of first region to the second.
2083 // The first region is the home region of the passed scene presence. 2537 // The first region is the home region of the passed scene presence.
@@ -2197,6 +2651,27 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2197 double px, double py, uint pSizeHint) 2651 double px, double py, uint pSizeHint)
2198 { 2652 {
2199 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: query, loc=<{1},{2}>", LogHeader, px, py); 2653 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: query, loc=<{1},{2}>", LogHeader, px, py);
2654=======
2655// needed for current OSG or old grid code
2656
2657 public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID, double px, double py)
2658 {
2659 // Since we don't know how big the regions could be, we have to search a very large area
2660 // to find possible regions.
2661 return GetRegionContainingWorldLocation(pGridService, pScopeID, px, py, Constants.MaximumRegionSize);
2662 }
2663
2664 // Given a world position, get the GridRegion info for
2665 // the region containing that point.
2666 // Someday this should be a method on GridService.
2667 // 'pSizeHint' is the size of the source region but since the destination point can be anywhere
2668 // the size of the target region is unknown thus the search area might have to be very large.
2669 // Return 'null' if no such region exists.
2670 public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID,
2671 double px, double py, uint pSizeHint)
2672 {
2673 m_log.DebugFormat("{0} GetRegionContainingWorldLocation: call, XY=<{1},{2}>", LogHeader, px, py);
2674>>>>>>> avn/ubitvar
2200 GridRegion ret = null; 2675 GridRegion ret = null;
2201 const double fudge = 2.0; 2676 const double fudge = 2.0;
2202 2677
@@ -2289,55 +2764,71 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2289 private void InformClientOfNeighbourAsync(ScenePresence sp, AgentCircuitData a, GridRegion reg, 2764 private void InformClientOfNeighbourAsync(ScenePresence sp, AgentCircuitData a, GridRegion reg,
2290 IPEndPoint endPoint, bool newAgent) 2765 IPEndPoint endPoint, bool newAgent)
2291 { 2766 {
2292 // Let's wait just a little to give time to originating regions to catch up with closing child agents
2293 // after a cross here
2294 Thread.Sleep(500);
2295 2767
2768<<<<<<< HEAD
2296 Scene scene = sp.Scene; 2769 Scene scene = sp.Scene;
2297 2770
2298 m_log.DebugFormat( 2771 m_log.DebugFormat(
2299 "[ENTITY TRANSFER MODULE]: Informing {0} {1} about neighbour {2} {3} at ({4},{5})", 2772 "[ENTITY TRANSFER MODULE]: Informing {0} {1} about neighbour {2} {3} at ({4},{5})",
2300 sp.Name, sp.UUID, reg.RegionName, endPoint, reg.RegionCoordX, reg.RegionCoordY); 2773 sp.Name, sp.UUID, reg.RegionName, endPoint, reg.RegionCoordX, reg.RegionCoordY);
2774=======
2775 if (newAgent)
2776 {
2777 Scene scene = sp.Scene;
2778
2779 m_log.DebugFormat(
2780 "[ENTITY TRANSFER MODULE]: Informing {0} {1} about neighbour {2} {3} at ({4},{5})",
2781 sp.Name, sp.UUID, reg.RegionName, endPoint, reg.RegionCoordX, reg.RegionCoordY);
2782>>>>>>> avn/ubitvar
2301 2783
2302 string capsPath = reg.ServerURI + CapsUtil.GetCapsSeedPath(a.CapsPath); 2784 string capsPath = reg.ServerURI + CapsUtil.GetCapsSeedPath(a.CapsPath);
2303 2785
2304 string reason = String.Empty; 2786 string reason = String.Empty;
2305 2787
2788<<<<<<< HEAD
2306 bool regionAccepted = scene.SimulationService.CreateAgent(null, reg, a, (uint)TeleportFlags.Default, out reason); 2789 bool regionAccepted = scene.SimulationService.CreateAgent(null, reg, a, (uint)TeleportFlags.Default, out reason);
2790=======
2791 bool regionAccepted = scene.SimulationService.CreateAgent(reg, a, (uint)TeleportFlags.Default, out reason);
2792>>>>>>> avn/ubitvar
2307 2793
2308 if (regionAccepted && newAgent) 2794 if (regionAccepted)
2309 {
2310 if (m_eqModule != null)
2311 { 2795 {
2312 #region IP Translation for NAT 2796 // give time for createAgent to finish, since it is async and does grid services access
2313 IClientIPEndpoint ipepClient; 2797 Thread.Sleep(500);
2314 if (sp.ClientView.TryGet(out ipepClient)) 2798
2799 if (m_eqModule != null)
2315 { 2800 {
2316 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); 2801 #region IP Translation for NAT
2317 } 2802 IClientIPEndpoint ipepClient;
2318 #endregion 2803 if (sp.ClientView.TryGet(out ipepClient))
2804 {
2805 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
2806 }
2807 #endregion
2319 2808
2320 m_log.DebugFormat("{0} {1} is sending {2} EnableSimulator for neighbour region {3}(loc=<{4},{5}>,siz=<{6},{7}>) " + 2809 m_log.DebugFormat("{0} {1} is sending {2} EnableSimulator for neighbour region {3}(loc=<{4},{5}>,siz=<{6},{7}>) " +
2321 "and EstablishAgentCommunication with seed cap {8}", LogHeader, 2810 "and EstablishAgentCommunication with seed cap {8}", LogHeader,
2322 scene.RegionInfo.RegionName, sp.Name, 2811 scene.RegionInfo.RegionName, sp.Name,
2323 reg.RegionName, reg.RegionLocX, reg.RegionLocY, reg.RegionSizeX, reg.RegionSizeY , capsPath); 2812 reg.RegionName, reg.RegionLocX, reg.RegionLocY, reg.RegionSizeX, reg.RegionSizeY, capsPath);
2324 2813
2325 m_eqModule.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID, reg.RegionSizeX, reg.RegionSizeY); 2814 m_eqModule.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID, reg.RegionSizeX, reg.RegionSizeY);
2326 m_eqModule.EstablishAgentCommunication(sp.UUID, endPoint, capsPath, reg.RegionHandle, reg.RegionSizeX, reg.RegionSizeY); 2815 m_eqModule.EstablishAgentCommunication(sp.UUID, endPoint, capsPath, reg.RegionHandle, reg.RegionSizeX, reg.RegionSizeY);
2327 } 2816 }
2328 else 2817 else
2329 { 2818 {
2330 sp.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint); 2819 sp.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint);
2331 // TODO: make Event Queue disablable! 2820 // TODO: make Event Queue disablable!
2821 }
2822
2823 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Completed inform {0} {1} about neighbour {2}", sp.Name, sp.UUID, endPoint);
2332 } 2824 }
2333 2825
2334 m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Completed inform {0} {1} about neighbour {2}", sp.Name, sp.UUID, endPoint); 2826 if (!regionAccepted)
2827 m_log.WarnFormat(
2828 "[ENTITY TRANSFER MODULE]: Region {0} did not accept {1} {2}: {3}",
2829 reg.RegionName, sp.Name, sp.UUID, reason);
2335 } 2830 }
2336 2831
2337 if (!regionAccepted)
2338 m_log.WarnFormat(
2339 "[ENTITY TRANSFER MODULE]: Region {0} did not accept {1} {2}: {3}",
2340 reg.RegionName, sp.Name, sp.UUID, reason);
2341 } 2832 }
2342 2833
2343 /// <summary> 2834 /// <summary>
@@ -2357,6 +2848,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2357 extent.Y = (float)Util.WorldToRegionLoc((uint)megaRegionSize.Y); 2848 extent.Y = (float)Util.WorldToRegionLoc((uint)megaRegionSize.Y);
2358 } 2849 }
2359 2850
2851<<<<<<< HEAD
2852=======
2853
2854>>>>>>> avn/ubitvar
2360 swCorner.X = Scene.RegionInfo.RegionLocX - 1; 2855 swCorner.X = Scene.RegionInfo.RegionLocX - 1;
2361 swCorner.Y = Scene.RegionInfo.RegionLocY - 1; 2856 swCorner.Y = Scene.RegionInfo.RegionLocY - 1;
2362 neCorner.X = Scene.RegionInfo.RegionLocX + extent.X; 2857 neCorner.X = Scene.RegionInfo.RegionLocX + extent.X;
@@ -2370,7 +2865,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2370 /// <param name="pRegionLocX"></param> 2865 /// <param name="pRegionLocX"></param>
2371 /// <param name="pRegionLocY"></param> 2866 /// <param name="pRegionLocY"></param>
2372 /// <returns></returns> 2867 /// <returns></returns>
2868<<<<<<< HEAD
2373 protected List<GridRegion> GetNeighbours(ScenePresence avatar, uint pRegionLocX, uint pRegionLocY) 2869 protected List<GridRegion> GetNeighbours(ScenePresence avatar, uint pRegionLocX, uint pRegionLocY)
2870=======
2871 protected List<GridRegion> GetNeighbors(ScenePresence avatar, uint pRegionLocX, uint pRegionLocY)
2872>>>>>>> avn/ubitvar
2374 { 2873 {
2375 Scene pScene = avatar.Scene; 2874 Scene pScene = avatar.Scene;
2376 RegionInfo m_regionInfo = pScene.RegionInfo; 2875 RegionInfo m_regionInfo = pScene.RegionInfo;
@@ -2381,6 +2880,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2381 // view to include everything in the megaregion 2880 // view to include everything in the megaregion
2382 if (m_regionCombinerModule == null || !m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID)) 2881 if (m_regionCombinerModule == null || !m_regionCombinerModule.IsRootForMegaregion(Scene.RegionInfo.RegionID))
2383 { 2882 {
2883<<<<<<< HEAD
2384 // The area to check is as big as the current region. 2884 // The area to check is as big as the current region.
2385 // We presume all adjacent regions are the same size as this region. 2885 // We presume all adjacent regions are the same size as this region.
2386 uint dd = Math.Max((uint)avatar.Scene.DefaultDrawDistance, 2886 uint dd = Math.Max((uint)avatar.Scene.DefaultDrawDistance,
@@ -2395,6 +2895,32 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2395 neighbours 2895 neighbours
2396 = avatar.Scene.GridService.GetRegionRange( 2896 = avatar.Scene.GridService.GetRegionRange(
2397 m_regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY); 2897 m_regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY);
2898=======
2899 uint dd = (uint)avatar.DrawDistance;
2900
2901 // until avatar movement updates client connections, we need to seend at least this current region imediate Neighbors
2902 uint ddX = Math.Max(dd, Constants.RegionSize);
2903 uint ddY = Math.Max(dd, Constants.RegionSize);
2904
2905 ddX--;
2906 ddY--;
2907
2908 // reference to region edges. Should be avatar position
2909 uint startX = Util.RegionToWorldLoc(pRegionLocX);
2910 uint endX = startX + m_regionInfo.RegionSizeX;
2911 uint startY = Util.RegionToWorldLoc(pRegionLocY);
2912 uint endY = startY + m_regionInfo.RegionSizeY;
2913
2914 startX -= ddX;
2915 startY -= ddY;
2916 endX += ddX;
2917 endY += ddY;
2918
2919 neighbours
2920 = avatar.Scene.GridService.GetRegionRange(
2921 m_regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY);
2922
2923>>>>>>> avn/ubitvar
2398 } 2924 }
2399 else 2925 else
2400 { 2926 {
@@ -2408,6 +2934,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2408 (int)Util.RegionToWorldLoc((uint)swCorner.Y), (int)Util.RegionToWorldLoc((uint)neCorner.Y)); 2934 (int)Util.RegionToWorldLoc((uint)swCorner.Y), (int)Util.RegionToWorldLoc((uint)neCorner.Y));
2409 } 2935 }
2410 2936
2937<<<<<<< HEAD
2411// neighbours.ForEach( 2938// neighbours.ForEach(
2412// n => 2939// n =>
2413// m_log.DebugFormat( 2940// m_log.DebugFormat(
@@ -2420,59 +2947,72 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2420 r.RegionID == m_regionInfo.RegionID 2947 r.RegionID == m_regionInfo.RegionID
2421 || (r.RegionFlags != null && (r.RegionFlags & OpenSim.Framework.RegionFlags.RegionOnline) == 0)); 2948 || (r.RegionFlags != null && (r.RegionFlags & OpenSim.Framework.RegionFlags.RegionOnline) == 0));
2422 2949
2950=======
2951 // The r.RegionFlags == null check only needs to be made for simulators before 2015-01-14 (pre 0.8.1).
2952 neighbours.RemoveAll( r => r.RegionID == m_regionInfo.RegionID );
2953
2954>>>>>>> avn/ubitvar
2423 return neighbours; 2955 return neighbours;
2424 } 2956 }
2957 #endregion
2958
2959 #region Agent Arrived
2425 2960
2426 private List<ulong> NewNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) 2961 public void AgentArrivedAtDestination(UUID id)
2427 { 2962 {
2428 return currentNeighbours.FindAll(delegate(ulong handle) { return !previousNeighbours.Contains(handle); }); 2963 m_entityTransferStateMachine.SetAgentArrivedAtDestination(id);
2429 } 2964 }
2430 2965
2431 // private List<ulong> CommonNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) 2966 #endregion
2432 // { 2967
2433 // return currentNeighbours.FindAll(delegate(ulong handle) { return previousNeighbours.Contains(handle); }); 2968 #region Object Transfers
2434 // }
2435 2969
2436 private List<ulong> OldNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) 2970 public GridRegion GetObjectDestination(SceneObjectGroup grp, Vector3 targetPosition,out Vector3 newpos)
2437 { 2971 {
2438 return previousNeighbours.FindAll(delegate(ulong handle) { return !currentNeighbours.Contains(handle); }); 2972 newpos = targetPosition;
2439 }
2440 2973
2441 private List<ulong> NeighbourHandles(List<GridRegion> neighbours) 2974 Scene scene = grp.Scene;
2442 { 2975 if (scene == null)
2443 List<ulong> handles = new List<ulong>(); 2976 return null;
2444 foreach (GridRegion reg in neighbours) 2977
2978 int x = (int)targetPosition.X + (int)scene.RegionInfo.WorldLocX;
2979 if (targetPosition.X >= 0)
2980 x++;
2981 else
2982 x--;
2983
2984 int y = (int)targetPosition.Y + (int)scene.RegionInfo.WorldLocY;
2985 if (targetPosition.Y >= 0)
2986 y++;
2987 else
2988 y--;
2989
2990
2991 GridRegion neighbourRegion = scene.GridService.GetRegionByPosition(scene.RegionInfo.ScopeID,x,y);
2992 if (neighbourRegion == null)
2445 { 2993 {
2446 handles.Add(reg.RegionHandle); 2994 return null;
2447 } 2995 }
2448 return handles;
2449 }
2450 2996
2451// private void Dump(string msg, List<ulong> handles) 2997 float newRegionSizeX = neighbourRegion.RegionSizeX;
2452// { 2998 float newRegionSizeY = neighbourRegion.RegionSizeY;
2453// m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg); 2999 if (newRegionSizeX == 0)
2454// foreach (ulong handle in handles) 3000 newRegionSizeX = Constants.RegionSize;
2455// { 3001 if (newRegionSizeY == 0)
2456// uint x, y; 3002 newRegionSizeY = Constants.RegionSize;
2457// Utils.LongToUInts(handle, out x, out y);
2458// x = x / Constants.RegionSize;
2459// y = y / Constants.RegionSize;
2460// m_log.InfoFormat("({0}, {1})", x, y);
2461// }
2462// }
2463 3003
2464 #endregion
2465 3004
2466 #region Agent Arrived 3005 newpos.X = targetPosition.X - (neighbourRegion.RegionLocX - (int)scene.RegionInfo.WorldLocX);
3006 newpos.Y = targetPosition.Y - (neighbourRegion.RegionLocY - (int)scene.RegionInfo.WorldLocY);
2467 3007
2468 public void AgentArrivedAtDestination(UUID id)
2469 {
2470 m_entityTransferStateMachine.SetAgentArrivedAtDestination(id);
2471 }
2472 3008
2473 #endregion 3009 const float enterDistance = 0.2f;
3010 newpos.X = Util.Clamp(newpos.X, enterDistance, newRegionSizeX - enterDistance);
3011 newpos.Y = Util.Clamp(newpos.Y, enterDistance, newRegionSizeY - enterDistance);
3012
3013 return neighbourRegion;
3014 }
2474 3015
2475 #region Object Transfers
2476 3016
2477 /// <summary> 3017 /// <summary>
2478 /// Move the given scene object into a new region depending on which region its absolute position has moved 3018 /// Move the given scene object into a new region depending on which region its absolute position has moved
@@ -2496,6 +3036,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2496 if (scene == null) 3036 if (scene == null)
2497 return; 3037 return;
2498 3038
3039<<<<<<< HEAD
2499 if (grp.RootPart.DIE_AT_EDGE) 3040 if (grp.RootPart.DIE_AT_EDGE)
2500 { 3041 {
2501 // We remove the object here 3042 // We remove the object here
@@ -2510,6 +3051,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2510 return; 3051 return;
2511 } 3052 }
2512 3053
3054=======
3055>>>>>>> avn/ubitvar
2513 // Remember the old group position in case the region lookup fails so position can be restored. 3056 // Remember the old group position in case the region lookup fails so position can be restored.
2514 Vector3 oldGroupPosition = grp.RootPart.GroupPosition; 3057 Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
2515 3058
@@ -2562,7 +3105,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2562 /// true if the crossing itself was successful, false on failure 3105 /// true if the crossing itself was successful, false on failure
2563 /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region 3106 /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region
2564 /// </returns> 3107 /// </returns>
2565 protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, Vector3 newPosition, SceneObjectGroup grp, bool silent) 3108 public bool CrossPrimGroupIntoNewRegion(GridRegion destination, Vector3 newPosition, SceneObjectGroup grp, bool silent)
2566 { 3109 {
2567 //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<"); 3110 //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<");
2568 3111
@@ -2603,30 +3146,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
2603 grp, e); 3146 grp, e);
2604 } 3147 }
2605 } 3148 }
2606/*
2607 * done on caller ( not in attachments crossing for now)
2608 else
2609 {
2610
2611 if (!grp.IsDeleted)
2612 {
2613 PhysicsActor pa = grp.RootPart.PhysActor;
2614 if (pa != null)
2615 {
2616 pa.CrossingFailure();
2617 if (grp.RootPart.KeyframeMotion != null)
2618 {
2619 // moved to KeyframeMotion.CrossingFailure
2620// grp.RootPart.Velocity = Vector3.Zero;
2621 grp.RootPart.KeyframeMotion.CrossingFailure();
2622// grp.SendGroupRootTerseUpdate();
2623 }
2624 }
2625 }
2626
2627 m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: Prim crossing failed for {0}", grp);
2628 }
2629 */
2630 } 3149 }
2631 else 3150 else
2632 { 3151 {
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
index 6a04acf..54ec751 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs
@@ -299,7 +299,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
299 id, m_mod.Scene.RegionInfo.RegionName, currentState)); 299 id, m_mod.Scene.RegionInfo.RegionName, currentState));
300 } 300 }
301 301
302 int count = 200; 302 int count = 400;
303 303
304 // There should be no race condition here since no other code should be removing the agent transfer or 304 // There should be no race condition here since no other code should be removing the agent transfer or
305 // changing the state to another other than Transferring => ReceivedAtDestination. 305 // changing the state to another other than Transferring => ReceivedAtDestination.
@@ -354,4 +354,4 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
354 } 354 }
355 } 355 }
356 } 356 }
357} \ No newline at end of file 357}
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index fa23590..233b251 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -238,19 +238,19 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
238 238
239 return region; 239 return region;
240 } 240 }
241 241/* NEEDFIX
242 protected override bool NeedsClosing(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg) 242 protected override bool NeedsClosing(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg)
243 { 243 {
244 if (base.NeedsClosing(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) 244 if (base.NeedsClosing(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
245 return true; 245 return true;
246 246
247 int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID); 247 int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
248 if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) 248 if (flags == -1 || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0)
249 return true; 249 return true;
250 250
251 return false; 251 return false;
252 } 252 }
253 253*/
254 protected override void AgentHasMovedAway(ScenePresence sp, bool logout) 254 protected override void AgentHasMovedAway(ScenePresence sp, bool logout)
255 { 255 {
256 base.AgentHasMovedAway(sp, logout); 256 base.AgentHasMovedAway(sp, logout);
@@ -311,6 +311,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
311 return base.CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout); 311 return base.CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout);
312 } 312 }
313 313
314 public void TriggerTeleportHome(UUID id, IClientAPI client)
315 {
316 TeleportHome(id, client);
317 }
318
314 protected override bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason) 319 protected override bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason)
315 { 320 {
316 reason = "Please wear your grid's allowed appearance before teleporting to another grid"; 321 reason = "Please wear your grid's allowed appearance before teleporting to another grid";
@@ -429,11 +434,14 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
429 // return base.UpdateAgent(reg, finalDestination, agentData, sp); 434 // return base.UpdateAgent(reg, finalDestination, agentData, sp);
430 //} 435 //}
431 436
437<<<<<<< HEAD
432 public override void TriggerTeleportHome(UUID id, IClientAPI client) 438 public override void TriggerTeleportHome(UUID id, IClientAPI client)
433 { 439 {
434 TeleportHome(id, client); 440 TeleportHome(id, client);
435 } 441 }
436 442
443=======
444>>>>>>> avn/ubitvar
437 public override bool TeleportHome(UUID id, IClientAPI client) 445 public override bool TeleportHome(UUID id, IClientAPI client)
438 { 446 {
439 m_log.DebugFormat( 447 m_log.DebugFormat(
@@ -491,9 +499,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
491 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}", 499 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}",
492 aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName); 500 aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName);
493 501
494 DoTeleport( 502 DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
495 sp, homeGatekeeper, finalDestination,
496 position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
497 return true; 503 return true;
498 } 504 }
499 505
@@ -760,4 +766,4 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
760 return region; 766 return region;
761 } 767 }
762 } 768 }
763} \ No newline at end of file 769}
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
index 5a9efb8..dff9126 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
@@ -178,27 +178,36 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
178 sbyte assetType, 178 sbyte assetType,
179 byte wearableType, uint nextOwnerMask, int creationDate) 179 byte wearableType, uint nextOwnerMask, int creationDate)
180 { 180 {
181 m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Received request to create inventory item {0} in folder {1}", name, folderID); 181 m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Received request to create inventory item {0} in folder {1}, transactionID {2}", name,
182 folderID, transactionID);
182 183
183 if (!m_Scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId)) 184 if (!m_Scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
184 return; 185 return;
185 186
186 if (transactionID == UUID.Zero) 187 InventoryFolderBase f = new InventoryFolderBase(folderID, remoteClient.AgentId);
188 InventoryFolderBase folder = m_Scene.InventoryService.GetFolder(f);
189
190 if (folder == null || folder.Owner != remoteClient.AgentId)
191 return;
192
193 if (transactionID != UUID.Zero)
187 { 194 {
188 ScenePresence presence; 195 IAgentAssetTransactions agentTransactions = m_Scene.AgentTransactionsModule;
189 if (m_Scene.TryGetScenePresence(remoteClient.AgentId, out presence)) 196 if (agentTransactions != null)
190 { 197 {
191 byte[] data = null; 198 if (agentTransactions.HandleItemCreationFromTransaction(
199 remoteClient, transactionID, folderID, callbackID, description,
200 name, invType, assetType, wearableType, nextOwnerMask))
201 return;
202 }
203 }
192 204
193 if (invType == (sbyte)InventoryType.Landmark && presence != null) 205 ScenePresence presence;
194 { 206 if (m_Scene.TryGetScenePresence(remoteClient.AgentId, out presence))
195 string suffix = string.Empty, prefix = string.Empty; 207 {
196 string strdata = GenerateLandmark(presence, out prefix, out suffix); 208 byte[] data = null;
197 data = Encoding.ASCII.GetBytes(strdata);
198 name = prefix + name;
199 description += suffix;
200 }
201 209
210<<<<<<< HEAD
202 AssetBase asset = m_Scene.CreateAsset(name, description, assetType, data, remoteClient.AgentId); 211 AssetBase asset = m_Scene.CreateAsset(name, description, assetType, data, remoteClient.AgentId);
203 m_Scene.AssetService.Store(asset); 212 m_Scene.AssetService.Store(asset);
204 m_Scene.CreateNewInventoryItem( 213 m_Scene.CreateNewInventoryItem(
@@ -206,21 +215,28 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
206 name, description, 0, callbackID, asset.FullID, asset.Type, invType, nextOwnerMask, creationDate); 215 name, description, 0, callbackID, asset.FullID, asset.Type, invType, nextOwnerMask, creationDate);
207 } 216 }
208 else 217 else
218=======
219 if (invType == (sbyte)InventoryType.Landmark && presence != null)
220>>>>>>> avn/ubitvar
209 { 221 {
210 m_log.ErrorFormat( 222 string suffix = string.Empty, prefix = string.Empty;
211 "[INVENTORY ACCESS MODULE]: ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem", 223 string strdata = GenerateLandmark(presence, out prefix, out suffix);
212 remoteClient.AgentId); 224 data = Encoding.ASCII.GetBytes(strdata);
225 name = prefix + name;
226 description += suffix;
213 } 227 }
228
229 AssetBase asset = m_Scene.CreateAsset(name, description, assetType, data, remoteClient.AgentId);
230 m_Scene.AssetService.Store(asset);
231 m_Scene.CreateNewInventoryItem(
232 remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID,
233 name, description, 0, callbackID, asset, invType, nextOwnerMask, creationDate,transactionID);
214 } 234 }
215 else 235 else
216 { 236 {
217 IAgentAssetTransactions agentTransactions = m_Scene.AgentTransactionsModule; 237 m_log.ErrorFormat(
218 if (agentTransactions != null) 238 "[INVENTORY ACCESS MODULE]: ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
219 { 239 remoteClient.AgentId);
220 agentTransactions.HandleItemCreationFromTransaction(
221 remoteClient, transactionID, folderID, callbackID, description,
222 name, invType, assetType, wearableType, nextOwnerMask);
223 }
224 } 240 }
225 } 241 }
226 242
@@ -272,6 +288,20 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
272 288
273 remoteClient.SendAlertMessage("Script saved"); 289 remoteClient.SendAlertMessage("Script saved");
274 } 290 }
291 else if ((CustomInventoryType)item.InvType == CustomInventoryType.AnimationSet)
292 {
293 AnimationSet animSet = new AnimationSet(data);
294 if (!animSet.Validate(x => {
295 int perms = m_Scene.InventoryService.GetAssetPermissions(remoteClient.AgentId, x);
296 int required = (int)(PermissionMask.Transfer | PermissionMask.Copy);
297 if ((perms & required) != required)
298 return false;
299 return true;
300 }))
301 {
302 data = animSet.ToBytes();
303 }
304 }
275 305
276 AssetBase asset = 306 AssetBase asset =
277 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data, remoteClient.AgentId.ToString()); 307 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data, remoteClient.AgentId.ToString());
@@ -380,7 +410,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
380 bool asAttachment) 410 bool asAttachment)
381 { 411 {
382 CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); 412 CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero);
383// Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); 413 Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>();
414 // this possible is not needed if keyframes are saved
415 Dictionary<UUID, KeyframeMotion> originalKeyframes = new Dictionary<UUID, KeyframeMotion>();
384 416
385 Dictionary<SceneObjectGroup, KeyframeMotion> group2Keyframe = new Dictionary<SceneObjectGroup, KeyframeMotion>(); 417 Dictionary<SceneObjectGroup, KeyframeMotion> group2Keyframe = new Dictionary<SceneObjectGroup, KeyframeMotion>();
386 418
@@ -388,6 +420,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
388 { 420 {
389 if (objectGroup.RootPart.KeyframeMotion != null) 421 if (objectGroup.RootPart.KeyframeMotion != null)
390 { 422 {
423<<<<<<< HEAD
391 objectGroup.RootPart.KeyframeMotion.Pause(); 424 objectGroup.RootPart.KeyframeMotion.Pause();
392 group2Keyframe.Add(objectGroup, objectGroup.RootPart.KeyframeMotion); 425 group2Keyframe.Add(objectGroup, objectGroup.RootPart.KeyframeMotion);
393 objectGroup.RootPart.KeyframeMotion = null; 426 objectGroup.RootPart.KeyframeMotion = null;
@@ -406,6 +439,48 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
406// originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; 439// originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition;
407// 440//
408// objectGroup.AbsolutePosition = inventoryStoredPosition; 441// objectGroup.AbsolutePosition = inventoryStoredPosition;
442=======
443 objectGroup.RootPart.KeyframeMotion.Suspend();
444 }
445 objectGroup.RootPart.SetForce(Vector3.Zero);
446 objectGroup.RootPart.SetAngularImpulse(Vector3.Zero, false);
447
448 originalKeyframes[objectGroup.UUID] = objectGroup.RootPart.KeyframeMotion;
449 objectGroup.RootPart.KeyframeMotion = null;
450
451 Vector3 inventoryStoredPosition = new Vector3
452 (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
453 ? 250
454 : objectGroup.AbsolutePosition.X)
455 ,
456 (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize)
457 ? 250
458 : objectGroup.AbsolutePosition.Y,
459 objectGroup.AbsolutePosition.Z);
460
461 Quaternion inventoryStoredRotation = objectGroup.GroupRotation;
462 originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition;
463
464 // Restore attachment data after trip through the sim
465 if (objectGroup.RootPart.AttachPoint > 0)
466 {
467 inventoryStoredPosition = objectGroup.RootPart.AttachedPos;
468 inventoryStoredRotation = objectGroup.RootPart.AttachRotation;
469 }
470
471 // Trees could be attached and it's been done, but it makes
472 // no sense. State must be preserved because it's the tree type
473 if (objectGroup.RootPart.Shape.PCode != (byte) PCode.Tree &&
474 objectGroup.RootPart.Shape.PCode != (byte) PCode.NewTree)
475 {
476 objectGroup.RootPart.Shape.State = objectGroup.RootPart.AttachPoint;
477 if (objectGroup.RootPart.AttachPoint > 0)
478 objectGroup.RootPart.Shape.LastAttachPoint = objectGroup.RootPart.AttachPoint;
479 }
480
481 objectGroup.AbsolutePosition = inventoryStoredPosition;
482 objectGroup.RootPart.RotationOffset = inventoryStoredRotation;
483>>>>>>> avn/ubitvar
409 484
410 // Make sure all bits but the ones we want are clear 485 // Make sure all bits but the ones we want are clear
411 // on take. 486 // on take.
@@ -433,9 +508,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
433 else 508 else
434 itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment); 509 itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment);
435 510
436// // Restore the position of each group now that it has been stored to inventory. 511 // Restore the position of each group now that it has been stored to inventory.
437// foreach (SceneObjectGroup objectGroup in objlist) 512 foreach (SceneObjectGroup objectGroup in objlist)
438// objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; 513 {
514 objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
515 objectGroup.RootPart.KeyframeMotion = originalKeyframes[objectGroup.UUID];
516 if (objectGroup.RootPart.KeyframeMotion != null)
517 objectGroup.RootPart.KeyframeMotion.Resume();
518 }
439 519
440 InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); 520 InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);
441 521
@@ -492,7 +572,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
492 item.Name = asset.Name; 572 item.Name = asset.Name;
493 item.AssetType = asset.Type; 573 item.AssetType = asset.Type;
494 574
495 AddPermissions(item, objlist[0], objlist, remoteClient); 575 //preserve perms on return
576 if(DeRezAction.Return == action)
577 AddPermissions(item, objlist[0], objlist, null);
578 else
579 AddPermissions(item, objlist[0], objlist, remoteClient);
496 580
497 m_Scene.AddInventoryItem(item); 581 m_Scene.AddInventoryItem(item);
498 582
@@ -542,16 +626,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
542 IClientAPI remoteClient) 626 IClientAPI remoteClient)
543 { 627 {
544 uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7; 628 uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7;
545 uint allObjectsNextOwnerPerms = 0x7fffffff; 629 // For the porposes of inventory, an object is modify if the prims
546 uint allObjectsEveryOnePerms = 0x7fffffff; 630 // are modify. This allows renaming an object that contains no
547 uint allObjectsGroupPerms = 0x7fffffff; 631 // mod items.
548
549 foreach (SceneObjectGroup grp in objsForEffectivePermissions) 632 foreach (SceneObjectGroup grp in objsForEffectivePermissions)
550 { 633 {
551 effectivePerms &= grp.GetEffectivePermissions(); 634 uint groupPerms = grp.GetEffectivePermissions(true);
552 allObjectsNextOwnerPerms &= grp.RootPart.NextOwnerMask; 635 if ((grp.RootPart.BaseMask & (uint)PermissionMask.Modify) != 0)
553 allObjectsEveryOnePerms &= grp.RootPart.EveryoneMask; 636 groupPerms |= (uint)PermissionMask.Modify;
554 allObjectsGroupPerms &= grp.RootPart.GroupMask; 637
638 effectivePerms &= groupPerms;
555 } 639 }
556 effectivePerms |= (uint)PermissionMask.Move; 640 effectivePerms |= (uint)PermissionMask.Move;
557 641
@@ -565,11 +649,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
565 uint perms = effectivePerms; 649 uint perms = effectivePerms;
566 PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref perms); 650 PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref perms);
567 651
568 item.BasePermissions = perms & allObjectsNextOwnerPerms; 652 item.BasePermissions = perms & so.RootPart.NextOwnerMask;
569 item.CurrentPermissions = item.BasePermissions; 653 item.CurrentPermissions = item.BasePermissions;
570 item.NextPermissions = perms & allObjectsNextOwnerPerms; 654 item.NextPermissions = perms & so.RootPart.NextOwnerMask;
571 item.EveryOnePermissions = allObjectsEveryOnePerms & allObjectsNextOwnerPerms; 655 item.EveryOnePermissions = so.RootPart.EveryoneMask & so.RootPart.NextOwnerMask;
572 item.GroupPermissions = allObjectsGroupPerms & allObjectsNextOwnerPerms; 656 item.GroupPermissions = so.RootPart.GroupMask & so.RootPart.NextOwnerMask;
573 657
574 // apply next owner perms on rez 658 // apply next owner perms on rez
575 item.CurrentPermissions |= SceneObjectGroup.SLAM; 659 item.CurrentPermissions |= SceneObjectGroup.SLAM;
@@ -585,9 +669,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
585 669
586 item.BasePermissions = effectivePerms; 670 item.BasePermissions = effectivePerms;
587 item.CurrentPermissions = effectivePerms; 671 item.CurrentPermissions = effectivePerms;
588 item.NextPermissions = allObjectsNextOwnerPerms & effectivePerms; 672 item.NextPermissions = so.RootPart.NextOwnerMask & effectivePerms;
589 item.EveryOnePermissions = allObjectsEveryOnePerms & effectivePerms; 673 item.EveryOnePermissions = so.RootPart.EveryoneMask & effectivePerms;
590 item.GroupPermissions = allObjectsGroupPerms & effectivePerms; 674 item.GroupPermissions = so.RootPart.GroupMask & effectivePerms;
591 675
592 item.CurrentPermissions &= 676 item.CurrentPermissions &=
593 ((uint)PermissionMask.Copy | 677 ((uint)PermissionMask.Copy |
@@ -743,7 +827,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
743 if (so.FromFolderID != UUID.Zero && so.RootPart.OwnerID == remoteClient.AgentId) 827 if (so.FromFolderID != UUID.Zero && so.RootPart.OwnerID == remoteClient.AgentId)
744 { 828 {
745 InventoryFolderBase f = new InventoryFolderBase(so.FromFolderID, userID); 829 InventoryFolderBase f = new InventoryFolderBase(so.FromFolderID, userID);
746 folder = m_Scene.InventoryService.GetFolder(f); 830 if (f != null)
831 folder = m_Scene.InventoryService.GetFolder(f);
747 832
748 if(folder.Type == 14 || folder.Type == 16) 833 if(folder.Type == 14 || folder.Type == 16)
749 { 834 {
@@ -779,16 +864,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
779 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment) 864 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
780 { 865 {
781// m_log.DebugFormat("[INVENTORY ACCESS MODULE]: RezObject for {0}, item {1}", remoteClient.Name, itemID); 866// m_log.DebugFormat("[INVENTORY ACCESS MODULE]: RezObject for {0}, item {1}", remoteClient.Name, itemID);
782
783 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); 867 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
784 item = m_Scene.InventoryService.GetItem(item); 868 item = m_Scene.InventoryService.GetItem(item);
785 869
786 if (item == null) 870 if (item == null)
787 { 871 {
788 m_log.WarnFormat(
789 "[INVENTORY ACCESS MODULE]: Could not find item {0} for {1} in RezObject()",
790 itemID, remoteClient.Name);
791
792 return null; 872 return null;
793 } 873 }
794 874
@@ -856,12 +936,35 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
856 pos -= bbox / 2; 936 pos -= bbox / 2;
857 } 937 }
858 938
939 int primcount = 0;
940 foreach (SceneObjectGroup g in objlist)
941 primcount += g.PrimCount;
942
943 if (!m_Scene.Permissions.CanRezObject(
944 primcount, remoteClient.AgentId, pos)
945 && !attachment)
946 {
947 // The client operates in no fail mode. It will
948 // have already removed the item from the folder
949 // if it's no copy.
950 // Put it back if it's not an attachment
951 //
952 if (item != null)
953 {
954 if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
955 remoteClient.SendBulkUpdateInventory(item);
956 }
957
958 return null;
959 }
960
859 if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment)) 961 if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment))
860 return null; 962 return null;
861 963
862 for (int i = 0; i < objlist.Count; i++) 964 for (int i = 0; i < objlist.Count; i++)
863 { 965 {
864 group = objlist[i]; 966 group = objlist[i];
967 SceneObjectPart rootPart = group.RootPart;
865 968
866// m_log.DebugFormat( 969// m_log.DebugFormat(
867// "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", 970// "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}",
@@ -909,7 +1012,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
909 1012
910 if (attachment) 1013 if (attachment)
911 { 1014 {
912 group.RootPart.Flags |= PrimFlags.Phantom; 1015// group.RootPart.Flags |= PrimFlags.Phantom;
913 group.IsAttachment = true; 1016 group.IsAttachment = true;
914 } 1017 }
915 1018
@@ -934,8 +1037,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
934 1037
935 if (!attachment) 1038 if (!attachment)
936 { 1039 {
937 SceneObjectPart rootPart = group.RootPart;
938
939 if (rootPart.Shape.PCode == (byte)PCode.Prim) 1040 if (rootPart.Shape.PCode == (byte)PCode.Prim)
940 group.ClearPartAttachmentData(); 1041 group.ClearPartAttachmentData();
941 1042
@@ -953,6 +1054,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
953// remoteClient.Name); 1054// remoteClient.Name);
954 } 1055 }
955 1056
1057 group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
1058
956 if (item != null) 1059 if (item != null)
957 DoPostRezWhenFromItem(item, attachment); 1060 DoPostRezWhenFromItem(item, attachment);
958 1061
@@ -1033,10 +1136,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
1033 // object itself before we rez. 1136 // object itself before we rez.
1034 // 1137 //
1035 // Only do these for the first object if we are rezzing a coalescence. 1138 // Only do these for the first object if we are rezzing a coalescence.
1036 if (i == 0) 1139 // nahh dont mess with coalescence objects,
1140 // the name in inventory can be change for inventory purpuses only
1141 if (objlist.Count == 1)
1037 { 1142 {
1038 rootPart.Name = item.Name; 1143 rootPart.Name = item.Name;
1039 rootPart.Description = item.Description; 1144 rootPart.Description = item.Description;
1145 }
1146
1147 if ((item.Flags & (uint)InventoryItemFlags.ObjectSlamSale) != 0)
1148 {
1040 rootPart.ObjectSaleType = item.SaleType; 1149 rootPart.ObjectSaleType = item.SaleType;
1041 rootPart.SalePrice = item.SalePrice; 1150 rootPart.SalePrice = item.SalePrice;
1042 } 1151 }
@@ -1047,17 +1156,55 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
1047// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", 1156// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}",
1048// rootPart.OwnerID, item.Owner, item.CurrentPermissions); 1157// rootPart.OwnerID, item.Owner, item.CurrentPermissions);
1049 1158
1050 if ((rootPart.OwnerID != item.Owner) || (item.CurrentPermissions & SceneObjectGroup.SLAM) != 0) 1159 if ((rootPart.OwnerID != item.Owner) ||
1160 (item.CurrentPermissions & 16) != 0 ||
1161 (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0)
1051 { 1162 {
1052 //Need to kill the for sale here 1163 //Need to kill the for sale here
1053 rootPart.ObjectSaleType = 0; 1164 rootPart.ObjectSaleType = 0;
1054 rootPart.SalePrice = 10; 1165 rootPart.SalePrice = 10;
1055 } 1166
1167 if (m_Scene.Permissions.PropagatePermissions())
1168 {
1169 foreach (SceneObjectPart part in so.Parts)
1170 {
1171 part.GroupMask = 0; // DO NOT propagate here
1056 1172
1057 foreach (SceneObjectPart part in so.Parts) 1173 part.LastOwnerID = part.OwnerID;
1174 part.OwnerID = item.Owner;
1175 part.Inventory.ChangeInventoryOwner(item.Owner);
1176 }
1177
1178 so.ApplyNextOwnerPermissions();
1179
1180 // In case the user has changed flags on a received item
1181 // we have to apply those changes after the slam. Else we
1182 // get a net loss of permissions
1183 foreach (SceneObjectPart part in so.Parts)
1184 {
1185 if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
1186 {
1187 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
1188 part.EveryoneMask = item.EveryOnePermissions & part.BaseMask;
1189 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
1190 part.NextOwnerMask = item.NextPermissions & part.BaseMask;
1191 }
1192 }
1193 }
1194 }
1195 else
1058 { 1196 {
1059 part.FromUserInventoryItemID = fromUserInventoryItemId; 1197 foreach (SceneObjectPart part in so.Parts)
1060 part.ApplyPermissionsOnRez(item, true, m_Scene); 1198 {
1199 part.FromUserInventoryItemID = fromUserInventoryItemId;
1200
1201 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
1202 part.EveryoneMask = item.EveryOnePermissions;
1203 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
1204 part.NextOwnerMask = item.NextPermissions;
1205 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
1206 part.GroupMask = item.GroupPermissions;
1207 }
1061 } 1208 }
1062 1209
1063 rootPart.TrimPermissions(); 1210 rootPart.TrimPermissions();
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
index 7ecbd26..a536757 100644
--- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
@@ -336,6 +336,104 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
336 } 336 }
337 } 337 }
338 338
339<<<<<<< HEAD
340=======
341 /// <summary>
342 ///
343 /// </summary>
344 /// <param name="uuid"></param>
345 /// <param name="names">Caller please provide a properly instantiated array for names, string[2]</param>
346 /// <returns></returns>
347 private bool TryGetUserNames(UUID uuid, string[] names)
348 {
349 if (names == null)
350 names = new string[2];
351
352 if (TryGetUserNamesFromCache(uuid, names))
353 return true;
354
355 if (TryGetUserNamesFromServices(uuid, names))
356 return true;
357
358 return false;
359 }
360
361 private bool TryGetUserNamesFromCache(UUID uuid, string[] names)
362 {
363 lock (m_UserCache)
364 {
365 if (m_UserCache.ContainsKey(uuid))
366 {
367 names[0] = m_UserCache[uuid].FirstName;
368 names[1] = m_UserCache[uuid].LastName;
369
370 return true;
371 }
372 }
373
374 return false;
375 }
376
377 /// <summary>
378 /// Try to get the names bound to the given uuid, from the services.
379 /// </summary>
380 /// <returns>True if the name was found, false if not.</returns>
381 /// <param name='uuid'></param>
382 /// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param>
383 private bool TryGetUserNamesFromServices(UUID uuid, string[] names)
384 {
385 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid);
386
387 if (account != null)
388 {
389 names[0] = account.FirstName;
390 names[1] = account.LastName;
391
392 UserData user = new UserData();
393 user.FirstName = account.FirstName;
394 user.LastName = account.LastName;
395
396 lock (m_UserCache)
397 m_UserCache[uuid] = user;
398
399 return true;
400 }
401 else
402 {
403 // Let's try the GridUser service
404 GridUserInfo uInfo = m_Scenes[0].GridUserService.GetGridUserInfo(uuid.ToString());
405 if (uInfo != null)
406 {
407 string url, first, last, tmp;
408 UUID u;
409 if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp))
410 {
411 AddUser(uuid, first, last, url);
412
413 if (m_UserCache.ContainsKey(uuid))
414 {
415 names[0] = m_UserCache[uuid].FirstName;
416 names[1] = m_UserCache[uuid].LastName;
417
418 return true;
419 }
420 }
421 else
422 m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID);
423 }
424// else
425// {
426// m_log.DebugFormat("[USER MANAGEMENT MODULE]: No grid user found for {0}", uuid);
427// }
428
429 names[0] = "Unknown";
430 names[1] = "UserUMMTGUN9";
431
432 return false;
433 }
434 }
435
436>>>>>>> avn/ubitvar
339 #region IUserManagement 437 #region IUserManagement
340 438
341 public UUID GetUserIdByName(string name) 439 public UUID GetUserIdByName(string name)
diff --git a/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs b/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs
index ea5b34e..a5c7543 100644
--- a/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/Hypergrid/HGWorldMapModule.cs
@@ -138,9 +138,9 @@ namespace OpenSim.Region.CoreModules.Hypergrid
138 } 138 }
139 } 139 }
140 140
141 protected override List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) 141 protected override List<MapBlockData> GetAndSendBlocksInternal(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
142 { 142 {
143 List<MapBlockData> mapBlocks = base.GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag); 143 List<MapBlockData> mapBlocks = base.GetAndSendBlocksInternal(remoteClient, minX, minY, maxX, maxY, flag);
144 lock (m_SeenMapBlocks) 144 lock (m_SeenMapBlocks)
145 { 145 {
146 if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId)) 146 if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId))
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
index b1f3f9b..235fbbb 100644
--- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
+++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
@@ -28,15 +28,12 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Linq;
32using System.Net; 31using System.Net;
33using System.Net.Mail; 32using System.Net.Mail;
34using System.Net.Security; 33using System.Net.Security;
35using System.Reflection;
36using System.Text; 34using System.Text;
37using System.Threading; 35using System.Threading;
38using System.Security.Cryptography.X509Certificates; 36using System.Security.Cryptography.X509Certificates;
39using log4net;
40using Nini.Config; 37using Nini.Config;
41using OpenMetaverse; 38using OpenMetaverse;
42using OpenSim.Framework; 39using OpenSim.Framework;
@@ -46,6 +43,7 @@ using OpenSim.Framework.Servers.HttpServer;
46using OpenSim.Region.Framework.Interfaces; 43using OpenSim.Region.Framework.Interfaces;
47using OpenSim.Region.Framework.Scenes; 44using OpenSim.Region.Framework.Scenes;
48using Mono.Addins; 45using Mono.Addins;
46using Amib.Threading;
49 47
50/***************************************************** 48/*****************************************************
51 * 49 *
@@ -109,6 +107,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
109 private Dictionary<UUID, HttpRequestClass> m_pendingRequests; 107 private Dictionary<UUID, HttpRequestClass> m_pendingRequests;
110 private Scene m_scene; 108 private Scene m_scene;
111 // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); 109 // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
110 public static SmartThreadPool ThreadPool = null;
112 111
113 public HttpRequestModule() 112 public HttpRequestModule()
114 { 113 {
@@ -291,29 +290,18 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
291 return true; 290 return true;
292 } 291 }
293 292
294 public void StopHttpRequestsForScript(UUID id) 293 public void StopHttpRequest(uint m_localID, UUID m_itemID)
295 { 294 {
296 if (m_pendingRequests != null) 295 if (m_pendingRequests != null)
297 { 296 {
298 List<UUID> keysToRemove = null;
299
300 lock (HttpListLock) 297 lock (HttpListLock)
301 { 298 {
302 foreach (HttpRequestClass req in m_pendingRequests.Values) 299 HttpRequestClass tmpReq;
300 if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq))
303 { 301 {
304 if (req.ItemID == id) 302 tmpReq.Stop();
305 { 303 m_pendingRequests.Remove(m_itemID);
306 req.Stop();
307
308 if (keysToRemove == null)
309 keysToRemove = new List<UUID>();
310
311 keysToRemove.Add(req.ReqID);
312 }
313 } 304 }
314
315 if (keysToRemove != null)
316 keysToRemove.ForEach(keyToRemove => m_pendingRequests.Remove(keyToRemove));
317 } 305 }
318 } 306 }
319 } 307 }
@@ -331,13 +319,19 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
331 { 319 {
332 lock (HttpListLock) 320 lock (HttpListLock)
333 { 321 {
334 foreach (HttpRequestClass req in m_pendingRequests.Values) 322 foreach (UUID luid in m_pendingRequests.Keys)
335 { 323 {
336 if (req.Finished) 324 HttpRequestClass tmpReq;
337 return req; 325
326 if (m_pendingRequests.TryGetValue(luid, out tmpReq))
327 {
328 if (tmpReq.Finished)
329 {
330 return tmpReq;
331 }
332 }
338 } 333 }
339 } 334 }
340
341 return null; 335 return null;
342 } 336 }
343 337
@@ -364,9 +358,34 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
364 m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); 358 m_proxyurl = config.Configs["Startup"].GetString("HttpProxy");
365 m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); 359 m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");
366 360
361<<<<<<< HEAD
367 m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config); 362 m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config);
363=======
364 int maxThreads = 15;
365
366 IConfig httpConfig = config.Configs["HttpRequestModule"];
367 if (httpConfig != null)
368 {
369 maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads);
370 }
371>>>>>>> avn/ubitvar
368 372
369 m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); 373 m_pendingRequests = new Dictionary<UUID, HttpRequestClass>();
374
375 // First instance sets this up for all sims
376 if (ThreadPool == null)
377 {
378 STPStartInfo startInfo = new STPStartInfo();
379 startInfo.IdleTimeout = 20000;
380 startInfo.MaxWorkerThreads = maxThreads;
381 startInfo.MinWorkerThreads = 1;
382 startInfo.ThreadPriority = ThreadPriority.BelowNormal;
383 startInfo.StartSuspended = true;
384 startInfo.ThreadPoolName = "ScriptsHttpReq";
385
386 ThreadPool = new SmartThreadPool(startInfo);
387 ThreadPool.Start();
388 }
370 } 389 }
371 390
372 public void AddRegion(Scene scene) 391 public void AddRegion(Scene scene)
@@ -410,8 +429,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
410 429
411 public class HttpRequestClass : IServiceRequest 430 public class HttpRequestClass : IServiceRequest
412 { 431 {
413// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
414
415 // Constants for parameters 432 // Constants for parameters
416 // public const int HTTP_BODY_MAXLENGTH = 2; 433 // public const int HTTP_BODY_MAXLENGTH = 2;
417 // public const int HTTP_METHOD = 0; 434 // public const int HTTP_METHOD = 0;
@@ -438,6 +455,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
438 public string HttpMIMEType = "text/plain;charset=utf-8"; 455 public string HttpMIMEType = "text/plain;charset=utf-8";
439 public int HttpTimeout; 456 public int HttpTimeout;
440 public bool HttpVerifyCert = true; 457 public bool HttpVerifyCert = true;
458 public IWorkItemResult WorkItem = null;
459
441 //public bool HttpVerboseThrottle = true; // not implemented 460 //public bool HttpVerboseThrottle = true; // not implemented
442 public List<string> HttpCustomHeaders = null; 461 public List<string> HttpCustomHeaders = null;
443 public bool HttpPragmaNoCache = true; 462 public bool HttpPragmaNoCache = true;
@@ -485,15 +504,44 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
485 504
486 public void Process() 505 public void Process()
487 { 506 {
507 _finished = false;
508
509 lock (HttpRequestModule.ThreadPool)
510 WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null);
511 }
512
513 private object StpSendWrapper(object o)
514 {
488 SendRequest(); 515 SendRequest();
516 return null;
489 } 517 }
490 518
519 /*
520 * TODO: More work on the response codes. Right now
521 * returning 200 for success or 499 for exception
522 */
523
491 public void SendRequest() 524 public void SendRequest()
492 { 525 {
526 HttpWebResponse response = null;
527 Stream resStream = null;
528 StringBuilder sb = new StringBuilder();
529 byte[] buf = new byte[8192];
530 string tempString = null;
531 int count = 0;
532
493 try 533 try
494 { 534 {
535<<<<<<< HEAD
495 Request = (HttpWebRequest)WebRequest.Create(Url); 536 Request = (HttpWebRequest)WebRequest.Create(Url);
496 Request.AllowAutoRedirect = false; 537 Request.AllowAutoRedirect = false;
538=======
539 Request = (HttpWebRequest) WebRequest.Create(Url);
540
541 //This works around some buggy HTTP Servers like Lighttpd
542 Request.ServicePoint.Expect100Continue = false;
543
544>>>>>>> avn/ubitvar
497 Request.Method = HttpMethod; 545 Request.Method = HttpMethod;
498 Request.ContentType = HttpMIMEType; 546 Request.ContentType = HttpMIMEType;
499 547
@@ -501,7 +549,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
501 { 549 {
502 // We could hijack Connection Group Name to identify 550 // We could hijack Connection Group Name to identify
503 // a desired security exception. But at the moment we'll use a dummy header instead. 551 // a desired security exception. But at the moment we'll use a dummy header instead.
504// Request.ConnectionGroupName = "NoVerify";
505 Request.Headers.Add("NoVerifyCert", "true"); 552 Request.Headers.Add("NoVerifyCert", "true");
506 } 553 }
507// else 554// else
@@ -534,14 +581,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
534 } 581 }
535 } 582 }
536 583
537 if (ResponseHeaders != null) 584 foreach (KeyValuePair<string, string> entry in ResponseHeaders)
538 { 585 if (entry.Key.ToLower().Equals("user-agent"))
539 foreach (KeyValuePair<string, string> entry in ResponseHeaders) 586 Request.UserAgent = entry.Value;
540 if (entry.Key.ToLower().Equals("user-agent") && Request is HttpWebRequest) 587 else
541 ((HttpWebRequest)Request).UserAgent = entry.Value; 588 Request.Headers[entry.Key] = entry.Value;
542 else
543 Request.Headers[entry.Key] = entry.Value;
544 }
545 589
546 // Encode outbound data 590 // Encode outbound data
547 if (!string.IsNullOrEmpty(OutboundBody)) 591 if (!string.IsNullOrEmpty(OutboundBody))
@@ -553,12 +597,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
553 bstream.Write(data, 0, data.Length); 597 bstream.Write(data, 0, data.Length);
554 } 598 }
555 599
600 Request.Timeout = HttpTimeout;
556 try 601 try
557 { 602 {
558 IAsyncResult result = (IAsyncResult)Request.BeginGetResponse(ResponseCallback, null); 603 // execute the request
559 604 response = (HttpWebResponse) Request.GetResponse();
560 ThreadPool.RegisterWaitForSingleObject(
561 result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, HttpTimeout, true);
562 } 605 }
563 catch (WebException e) 606 catch (WebException e)
564 { 607 {
@@ -566,65 +609,74 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
566 { 609 {
567 throw; 610 throw;
568 } 611 }
612 response = (HttpWebResponse)e.Response;
613 }
569 614
570 HttpWebResponse response = (HttpWebResponse)e.Response; 615 Status = (int)response.StatusCode;
571 616
572 Status = (int)response.StatusCode; 617 resStream = response.GetResponseStream();
573 ResponseBody = response.StatusDescription;
574 _finished = true;
575 }
576 }
577 catch (Exception e)
578 {
579// m_log.Debug(
580// string.Format("[SCRIPTS HTTP REQUESTS]: Exception on request to {0} for {1} ", Url, ItemID), e);
581 618
582 Status = (int)OSHttpStatusCode.ClientErrorJoker; 619 do
583 ResponseBody = e.Message; 620 {
584 _finished = true; 621 // fill the buffer with data
585 } 622 count = resStream.Read(buf, 0, buf.Length);
586 }
587 623
588 private void ResponseCallback(IAsyncResult ar) 624 // make sure we read some data
589 { 625 if (count != 0)
590 HttpWebResponse response = null; 626 {
627 // translate from bytes to ASCII text
628 tempString = Util.UTF8.GetString(buf, 0, count);
591 629
592 try 630 // continue building the string
631 sb.Append(tempString);
632 if (sb.Length > 2048)
633 break;
634 }
635 } while (count > 0); // any more data to read?
636
637 ResponseBody = sb.ToString().Replace("\r", "");
638 }
639 catch (WebException e)
593 { 640 {
594 try 641 if (e.Status == WebExceptionStatus.ProtocolError)
595 {
596 response = (HttpWebResponse)Request.EndGetResponse(ar);
597 }
598 catch (WebException e)
599 { 642 {
600 if (e.Status != WebExceptionStatus.ProtocolError) 643 HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response;
644 Status = (int)webRsp.StatusCode;
645 try
601 { 646 {
602 throw; 647 using (Stream responseStream = webRsp.GetResponseStream())
648 {
649 ResponseBody = responseStream.GetStreamString();
650 }
603 } 651 }
604 652 catch
605 response = (HttpWebResponse)e.Response; 653 {
654 ResponseBody = webRsp.StatusDescription;
655 }
656 }
657 else
658 {
659 Status = (int)OSHttpStatusCode.ClientErrorJoker;
660 ResponseBody = e.Message;
606 } 661 }
607 662
608 Status = (int)response.StatusCode; 663 if (ResponseBody == null)
664 ResponseBody = String.Empty;
609 665
610 using (Stream stream = response.GetResponseStream()) 666 _finished = true;
611 { 667 return;
612 StreamReader reader = new StreamReader(stream, Encoding.UTF8);
613 ResponseBody = reader.ReadToEnd();
614 }
615 } 668 }
616 catch (Exception e) 669 catch (Exception e)
617 { 670 {
618 Status = (int)OSHttpStatusCode.ClientErrorJoker; 671 // Don't crash on anything else
619 ResponseBody = e.Message;
620
621// m_log.Debug(
622// string.Format("[SCRIPTS HTTP REQUESTS]: Exception on response to {0} for {1} ", Url, ItemID), e);
623 } 672 }
624 finally 673 finally
625 { 674 {
675 if (resStream != null)
676 resStream.Close();
626 if (response != null) 677 if (response != null)
627 response.Close(); 678 response.Close();
679<<<<<<< HEAD
628 680
629 // We need to resubmit 681 // We need to resubmit
630 if ( 682 if (
@@ -672,21 +724,28 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
672 { 724 {
673 _finished = true; 725 _finished = true;
674 } 726 }
727=======
728>>>>>>> avn/ubitvar
675 } 729 }
676 }
677 730
678 private void TimeoutCallback(object state, bool timedOut) 731 if (ResponseBody == null)
679 { 732 ResponseBody = String.Empty;
680 if (timedOut) 733
681 Request.Abort(); 734 _finished = true;
682 } 735 }
683 736
684 public void Stop() 737 public void Stop()
685 { 738 {
686// m_log.DebugFormat("[SCRIPTS HTTP REQUESTS]: Stopping request to {0} for {1} ", Url, ItemID); 739 try
687 740 {
688 if (Request != null) 741 if (!WorkItem.Cancel())
689 Request.Abort(); 742 {
743 WorkItem.Cancel(true);
744 }
745 }
746 catch (Exception)
747 {
748 }
690 } 749 }
691 } 750 }
692} \ No newline at end of file 751}
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index 99a3122..1983fed 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -42,40 +42,16 @@ using OpenSim.Region.Framework.Scenes;
42 42
43namespace OpenSim.Region.CoreModules.Scripting.LSLHttp 43namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
44{ 44{
45 /// <summary>
46 /// Data describing an external URL set up by a script.
47 /// </summary>
48 public class UrlData 45 public class UrlData
49 { 46 {
50 /// <summary>
51 /// Scene object part hosting the script
52 /// </summary>
53 public UUID hostID; 47 public UUID hostID;
54
55 /// <summary>
56 /// The item ID of the script that requested the URL.
57 /// </summary>
58 public UUID itemID; 48 public UUID itemID;
59
60 /// <summary>
61 /// The script engine that runs the script.
62 /// </summary>
63 public IScriptModule engine; 49 public IScriptModule engine;
64
65 /// <summary>
66 /// The generated URL.
67 /// </summary>
68 public string url; 50 public string url;
69
70 /// <summary>
71 /// The random UUID component of the generated URL.
72 /// </summary>
73 public UUID urlcode; 51 public UUID urlcode;
74
75 /// <summary>
76 /// The external requests currently being processed or awaiting retrieval for this URL.
77 /// </summary>
78 public Dictionary<UUID, RequestData> requests; 52 public Dictionary<UUID, RequestData> requests;
53 public bool isSsl;
54 public Scene scene;
79 } 55 }
80 56
81 public class RequestData 57 public class RequestData
@@ -89,7 +65,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
89 //public ManualResetEvent ev; 65 //public ManualResetEvent ev;
90 public bool requestDone; 66 public bool requestDone;
91 public int startTime; 67 public int startTime;
68 public bool responseSent;
92 public string uri; 69 public string uri;
70 public bool allowResponseType = false;
71 public UUID hostID;
72 public Scene scene;
93 } 73 }
94 74
95 /// <summary> 75 /// <summary>
@@ -102,20 +82,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
102 LogManager.GetLogger( 82 LogManager.GetLogger(
103 MethodBase.GetCurrentMethod().DeclaringType); 83 MethodBase.GetCurrentMethod().DeclaringType);
104 84
105 /// <summary> 85 private Dictionary<UUID, UrlData> m_RequestMap =
106 /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the request ID 86 new Dictionary<UUID, UrlData>();
107 /// randomly generated when a request is received for this URL.
108 /// </summary>
109 /// <remarks>
110 /// Manipulation or retrieval from this dictionary must be locked on m_UrlMap to preserve consistency with
111 /// m_UrlMap
112 /// </remarks>
113 private Dictionary<UUID, UrlData> m_RequestMap = new Dictionary<UUID, UrlData>();
114 87
115 /// <summary> 88 private Dictionary<string, UrlData> m_UrlMap =
116 /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the full URL 89 new Dictionary<string, UrlData>();
117 /// </summary>
118 private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>();
119 90
120 private uint m_HttpsPort = 0; 91 private uint m_HttpsPort = 0;
121 private IHttpServer m_HttpServer = null; 92 private IHttpServer m_HttpServer = null;
@@ -126,7 +97,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
126 /// <summary> 97 /// <summary>
127 /// The default maximum number of urls 98 /// The default maximum number of urls
128 /// </summary> 99 /// </summary>
129 public const int DefaultTotalUrls = 100; 100 public const int DefaultTotalUrls = 15000;
130 101
131 /// <summary> 102 /// <summary>
132 /// Maximum number of external urls that can be set up by this module. 103 /// Maximum number of external urls that can be set up by this module.
@@ -204,6 +175,17 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
204 175
205 public void RemoveRegion(Scene scene) 176 public void RemoveRegion(Scene scene)
206 { 177 {
178 // Drop references to that scene
179 foreach (KeyValuePair<string, UrlData> kvp in m_UrlMap)
180 {
181 if (kvp.Value.scene == scene)
182 kvp.Value.scene = null;
183 }
184 foreach (KeyValuePair<UUID, UrlData> kvp in m_RequestMap)
185 {
186 if (kvp.Value.scene == scene)
187 kvp.Value.scene = null;
188 }
207 } 189 }
208 190
209 public void Close() 191 public void Close()
@@ -221,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
221 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 203 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
222 return urlcode; 204 return urlcode;
223 } 205 }
224 string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; 206 string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString();
225 207
226 UrlData urlData = new UrlData(); 208 UrlData urlData = new UrlData();
227 urlData.hostID = host.UUID; 209 urlData.hostID = host.UUID;
@@ -229,20 +211,22 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
229 urlData.engine = engine; 211 urlData.engine = engine;
230 urlData.url = url; 212 urlData.url = url;
231 urlData.urlcode = urlcode; 213 urlData.urlcode = urlcode;
214 urlData.isSsl = false;
232 urlData.requests = new Dictionary<UUID, RequestData>(); 215 urlData.requests = new Dictionary<UUID, RequestData>();
233 216 urlData.scene = host.ParentGroup.Scene;
217
234 m_UrlMap[url] = urlData; 218 m_UrlMap[url] = urlData;
235 219
236 string uri = "/lslhttp/" + urlcode.ToString() + "/"; 220 string uri = "/lslhttp/" + urlcode.ToString();
237 221
238 PollServiceEventArgs args 222 PollServiceEventArgs args
239 = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); 223 = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
240 args.Type = PollServiceEventArgs.EventType.LslHttp; 224 args.Type = PollServiceEventArgs.EventType.LslHttp;
241 m_HttpServer.AddPollServiceHTTPHandler(uri, args); 225 m_HttpServer.AddPollServiceHTTPHandler(uri, args);
242 226
243 m_log.DebugFormat( 227// m_log.DebugFormat(
244 "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", 228// "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
245 uri, itemID, host.Name, host.LocalId); 229// uri, itemID, host.Name, host.LocalId);
246 230
247 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 231 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
248 } 232 }
@@ -267,7 +251,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
267 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 251 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
268 return urlcode; 252 return urlcode;
269 } 253 }
270 string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; 254 string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString();
271 255
272 UrlData urlData = new UrlData(); 256 UrlData urlData = new UrlData();
273 urlData.hostID = host.UUID; 257 urlData.hostID = host.UUID;
@@ -275,20 +259,22 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
275 urlData.engine = engine; 259 urlData.engine = engine;
276 urlData.url = url; 260 urlData.url = url;
277 urlData.urlcode = urlcode; 261 urlData.urlcode = urlcode;
262 urlData.isSsl = true;
278 urlData.requests = new Dictionary<UUID, RequestData>(); 263 urlData.requests = new Dictionary<UUID, RequestData>();
279 264
265
280 m_UrlMap[url] = urlData; 266 m_UrlMap[url] = urlData;
281 267
282 string uri = "/lslhttps/" + urlcode.ToString() + "/"; 268 string uri = "/lslhttps/" + urlcode.ToString();
283 269
284 PollServiceEventArgs args 270 PollServiceEventArgs args
285 = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); 271 = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
286 args.Type = PollServiceEventArgs.EventType.LslHttp; 272 args.Type = PollServiceEventArgs.EventType.LslHttp;
287 m_HttpsServer.AddPollServiceHTTPHandler(uri, args); 273 m_HttpsServer.AddPollServiceHTTPHandler(uri, args);
288 274
289 m_log.DebugFormat( 275// m_log.DebugFormat(
290 "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", 276// "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
291 uri, itemID, host.Name, host.LocalId); 277// uri, itemID, host.Name, host.LocalId);
292 278
293 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 279 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
294 } 280 }
@@ -307,12 +293,15 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
307 return; 293 return;
308 } 294 }
309 295
310 foreach (UUID req in data.requests.Keys) 296 lock (m_RequestMap)
311 m_RequestMap.Remove(req); 297 {
312 298 foreach (UUID req in data.requests.Keys)
313 m_log.DebugFormat( 299 m_RequestMap.Remove(req);
314 "[URL MODULE]: Releasing url {0} for {1} in {2}", 300 }
315 url, data.itemID, data.hostID); 301
302// m_log.DebugFormat(
303// "[URL MODULE]: Releasing url {0} for {1} in {2}",
304// url, data.itemID, data.hostID);
316 305
317 RemoveUrl(data); 306 RemoveUrl(data);
318 m_UrlMap.Remove(url); 307 m_UrlMap.Remove(url);
@@ -337,29 +326,39 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
337 326
338 public void HttpResponse(UUID request, int status, string body) 327 public void HttpResponse(UUID request, int status, string body)
339 { 328 {
340 lock (m_UrlMap) 329 lock (m_RequestMap)
341 { 330 {
342 if (m_RequestMap.ContainsKey(request)) 331 if (m_RequestMap.ContainsKey(request))
343 { 332 {
344 UrlData urlData = m_RequestMap[request]; 333 UrlData urlData = m_RequestMap[request];
345 string responseBody = body; 334 if (!urlData.requests[request].responseSent)
346 if (urlData.requests[request].responseType.Equals("text/plain"))
347 { 335 {
348 string value; 336 string responseBody = body;
349 if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) 337
338 // If we have no OpenID from built-in browser, disable this
339 if (!urlData.requests[request].allowResponseType)
340 urlData.requests[request].responseType = "text/plain";
341
342 if (urlData.requests[request].responseType.Equals("text/plain"))
350 { 343 {
351 if (value != null && value.IndexOf("MSIE") >= 0) 344 string value;
345 if (urlData.requests[request].headers.TryGetValue("user-agent", out value))
352 { 346 {
353 // wrap the html escaped response if the target client is IE 347 if (value != null && value.IndexOf("MSIE") >= 0)
354 // It ignores "text/plain" if the body is html 348 {
355 responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; 349 // wrap the html escaped response if the target client is IE
350 // It ignores "text/plain" if the body is html
351 responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>";
352 }
356 } 353 }
357 } 354 }
355
356 urlData.requests[request].responseCode = status;
357 urlData.requests[request].responseBody = body;
358 //urlData.requests[request].ev.Set();
359 urlData.requests[request].requestDone = true;
360 urlData.requests[request].responseSent = true;
358 } 361 }
359 urlData.requests[request].responseCode = status;
360 urlData.requests[request].responseBody = responseBody;
361 //urlData.requests[request].ev.Set();
362 urlData.requests[request].requestDone =true;
363 } 362 }
364 else 363 else
365 { 364 {
@@ -370,7 +369,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
370 369
371 public string GetHttpHeader(UUID requestId, string header) 370 public string GetHttpHeader(UUID requestId, string header)
372 { 371 {
373 lock (m_UrlMap) 372 lock (m_RequestMap)
374 { 373 {
375 if (m_RequestMap.ContainsKey(requestId)) 374 if (m_RequestMap.ContainsKey(requestId))
376 { 375 {
@@ -384,7 +383,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
384 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); 383 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
385 } 384 }
386 } 385 }
387
388 return String.Empty; 386 return String.Empty;
389 } 387 }
390 388
@@ -408,8 +406,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
408 { 406 {
409 RemoveUrl(url.Value); 407 RemoveUrl(url.Value);
410 removeURLs.Add(url.Key); 408 removeURLs.Add(url.Key);
411 foreach (UUID req in url.Value.requests.Keys) 409 lock (m_RequestMap)
412 m_RequestMap.Remove(req); 410 {
411 foreach (UUID req in url.Value.requests.Keys)
412 m_RequestMap.Remove(req);
413 }
413 } 414 }
414 } 415 }
415 416
@@ -430,9 +431,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
430 { 431 {
431 RemoveUrl(url.Value); 432 RemoveUrl(url.Value);
432 removeURLs.Add(url.Key); 433 removeURLs.Add(url.Key);
433 434 lock (m_RequestMap)
434 foreach (UUID req in url.Value.requests.Keys) 435 {
435 m_RequestMap.Remove(req); 436 foreach (UUID req in url.Value.requests.Keys)
437 m_RequestMap.Remove(req);
438 }
436 } 439 }
437 } 440 }
438 441
@@ -441,123 +444,128 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
441 } 444 }
442 } 445 }
443 446
447
444 private void RemoveUrl(UrlData data) 448 private void RemoveUrl(UrlData data)
445 { 449 {
446 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/"); 450 if (data.isSsl)
451 m_HttpsServer.RemoveHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/");
452 else
453 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
447 } 454 }
448 455
449 private Hashtable NoEvents(UUID requestID, UUID sessionID) 456 private Hashtable NoEvents(UUID requestID, UUID sessionID)
450 { 457 {
451 Hashtable response = new Hashtable(); 458 Hashtable response = new Hashtable();
452 UrlData urlData; 459 UrlData url;
453 460 int startTime = 0;
454 lock (m_UrlMap) 461 lock (m_RequestMap)
455 { 462 {
456 // We need to return a 404 here in case the request URL was removed at exactly the same time that a
457 // request was made. In this case, the request thread can outrace llRemoveURL() and still be polling
458 // for the request ID.
459 if (!m_RequestMap.ContainsKey(requestID)) 463 if (!m_RequestMap.ContainsKey(requestID))
460 {
461 response["int_response_code"] = 404;
462 response["str_response_string"] = "";
463 response["keepalive"] = false;
464 response["reusecontext"] = false;
465
466 return response; 464 return response;
467 } 465 url = m_RequestMap[requestID];
466 startTime = url.requests[requestID].startTime;
467 }
468 468
469 urlData = m_RequestMap[requestID]; 469 if (System.Environment.TickCount - startTime > 25000)
470 {
471 response["int_response_code"] = 500;
472 response["str_response_string"] = "Script timeout";
473 response["content_type"] = "text/plain";
474 response["keepalive"] = false;
475 response["reusecontext"] = false;
470 476
471 if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) 477 //remove from map
478 lock (url.requests)
479 {
480 url.requests.Remove(requestID);
481 }
482 lock (m_RequestMap)
472 { 483 {
473 response["int_response_code"] = 500;
474 response["str_response_string"] = "Script timeout";
475 response["content_type"] = "text/plain";
476 response["keepalive"] = false;
477 response["reusecontext"] = false;
478
479 //remove from map
480 urlData.requests.Remove(requestID);
481 m_RequestMap.Remove(requestID); 484 m_RequestMap.Remove(requestID);
482
483 return response;
484 } 485 }
486
487 return response;
485 } 488 }
486 489
490
487 return response; 491 return response;
488 } 492 }
489 493
490 private bool HasEvents(UUID requestID, UUID sessionID) 494 private bool HasEvents(UUID requestID, UUID sessionID)
491 { 495 {
492 lock (m_UrlMap) 496 UrlData url=null;
497
498 lock (m_RequestMap)
493 { 499 {
494 // We return true here because an external URL request that happened at the same time as an llRemoveURL()
495 // can still make it through to HttpRequestHandler(). That will return without setting up a request
496 // when it detects that the URL has been removed. The poller, however, will continue to ask for
497 // events for that request, so here we will signal that there are events and in GetEvents we will
498 // return a 404.
499 if (!m_RequestMap.ContainsKey(requestID)) 500 if (!m_RequestMap.ContainsKey(requestID))
500 { 501 {
501 return true; 502 return false;
502 } 503 }
503 504 url = m_RequestMap[requestID];
504 UrlData urlData = m_RequestMap[requestID]; 505 }
505 506 lock (url.requests)
506 if (!urlData.requests.ContainsKey(requestID)) 507 {
508 if (!url.requests.ContainsKey(requestID))
507 { 509 {
508 return true; 510 return false;
509 } 511 }
510 512 else
511 // Trigger return of timeout response.
512 if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000)
513 { 513 {
514 return true; 514 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
515 {
516 return true;
517 }
518 if (url.requests[requestID].requestDone)
519 return true;
520 else
521 return false;
515 } 522 }
516
517 return urlData.requests[requestID].requestDone;
518 } 523 }
519 } 524 }
520
521 private Hashtable GetEvents(UUID requestID, UUID sessionID) 525 private Hashtable GetEvents(UUID requestID, UUID sessionID)
522 { 526 {
523 Hashtable response; 527 UrlData url = null;
528 RequestData requestData = null;
524 529
525 lock (m_UrlMap) 530 lock (m_RequestMap)
526 { 531 {
527 UrlData url = null;
528 RequestData requestData = null;
529
530 if (!m_RequestMap.ContainsKey(requestID)) 532 if (!m_RequestMap.ContainsKey(requestID))
531 return NoEvents(requestID, sessionID); 533 return NoEvents(requestID,sessionID);
532
533 url = m_RequestMap[requestID]; 534 url = m_RequestMap[requestID];
535 }
536 lock (url.requests)
537 {
534 requestData = url.requests[requestID]; 538 requestData = url.requests[requestID];
539 }
540
541 if (!requestData.requestDone)
542 return NoEvents(requestID,sessionID);
543
544 Hashtable response = new Hashtable();
535 545
536 if (!requestData.requestDone) 546 if (System.Environment.TickCount - requestData.startTime > 25000)
537 return NoEvents(requestID, sessionID); 547 {
538 548 response["int_response_code"] = 500;
539 response = new Hashtable(); 549 response["str_response_string"] = "Script timeout";
540 550 response["content_type"] = "text/plain";
541 if (System.Environment.TickCount - requestData.startTime > 25000)
542 {
543 response["int_response_code"] = 500;
544 response["str_response_string"] = "Script timeout";
545 response["content_type"] = "text/plain";
546 response["keepalive"] = false;
547 response["reusecontext"] = false;
548 return response;
549 }
550
551 //put response
552 response["int_response_code"] = requestData.responseCode;
553 response["str_response_string"] = requestData.responseBody;
554 response["content_type"] = requestData.responseType;
555 // response["content_type"] = "text/plain";
556 response["keepalive"] = false; 551 response["keepalive"] = false;
557 response["reusecontext"] = false; 552 response["reusecontext"] = false;
558 553 return response;
559 //remove from map 554 }
555 //put response
556 response["int_response_code"] = requestData.responseCode;
557 response["str_response_string"] = requestData.responseBody;
558 response["content_type"] = requestData.responseType;
559 response["keepalive"] = false;
560 response["reusecontext"] = false;
561
562 //remove from map
563 lock (url.requests)
564 {
560 url.requests.Remove(requestID); 565 url.requests.Remove(requestID);
566 }
567 lock (m_RequestMap)
568 {
561 m_RequestMap.Remove(requestID); 569 m_RequestMap.Remove(requestID);
562 } 570 }
563 571
@@ -566,41 +574,45 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
566 574
567 public void HttpRequestHandler(UUID requestID, Hashtable request) 575 public void HttpRequestHandler(UUID requestID, Hashtable request)
568 { 576 {
569 string uri = request["uri"].ToString(); 577 lock (request)
570 bool is_ssl = uri.Contains("lslhttps");
571
572 try
573 { 578 {
574 Hashtable headers = (Hashtable)request["headers"]; 579 string uri = request["uri"].ToString();
580 bool is_ssl = uri.Contains("lslhttps");
575 581
576// string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; 582 try
577
578 int pos1 = uri.IndexOf("/");// /lslhttp
579 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
580 int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/
581 string uri_tmp = uri.Substring(0, pos3 + 1);
582 //HTTP server code doesn't provide us with QueryStrings
583 string pathInfo;
584 string queryString;
585 queryString = "";
586
587 pathInfo = uri.Substring(pos3);
588
589 UrlData urlData = null;
590
591 lock (m_UrlMap)
592 { 583 {
593 string url; 584 Hashtable headers = (Hashtable)request["headers"];
594 585
595 if (is_ssl) 586// string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
596 url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; 587
588 int pos1 = uri.IndexOf("/");// /lslhttp
589 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
590 int pos3 = pos2 + 37; // /lslhttp/urlcode
591 string uri_tmp = uri.Substring(0, pos3);
592 //HTTP server code doesn't provide us with QueryStrings
593 string pathInfo;
594 string queryString;
595 queryString = "";
596
597 pathInfo = uri.Substring(pos3);
598
599 UrlData url = null;
600 string urlkey;
601 if (!is_ssl)
602 urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
603 //m_UrlMap[];
597 else 604 else
598 url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; 605 urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
599 606
600 // Avoid a race - the request URL may have been released via llRequestUrl() whilst this 607 if (m_UrlMap.ContainsKey(urlkey))
601 // request was being processed. 608 {
602 if (!m_UrlMap.TryGetValue(url, out urlData)) 609 url = m_UrlMap[urlkey];
610 }
611 else
612 {
613 //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
603 return; 614 return;
615 }
604 616
605 //for llGetHttpHeader support we need to store original URI here 617 //for llGetHttpHeader support we need to store original URI here
606 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers 618 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
@@ -611,6 +623,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
611 requestData.requestDone = false; 623 requestData.requestDone = false;
612 requestData.startTime = System.Environment.TickCount; 624 requestData.startTime = System.Environment.TickCount;
613 requestData.uri = uri; 625 requestData.uri = uri;
626 requestData.hostID = url.hostID;
627 requestData.scene = url.scene;
614 if (requestData.headers == null) 628 if (requestData.headers == null)
615 requestData.headers = new Dictionary<string, string>(); 629 requestData.headers = new Dictionary<string, string>();
616 630
@@ -619,8 +633,33 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
619 string key = (string)header.Key; 633 string key = (string)header.Key;
620 string value = (string)header.Value; 634 string value = (string)header.Value;
621 requestData.headers.Add(key, value); 635 requestData.headers.Add(key, value);
636 if (key == "cookie")
637 {
638 string[] parts = value.Split(new char[] {'='});
639 if (parts[0] == "agni_sl_session_id" && parts.Length > 1)
640 {
641 string cookie = Uri.UnescapeDataString(parts[1]);
642 string[] crumbs = cookie.Split(new char[] {':'});
643 UUID owner;
644 if (crumbs.Length == 2 && UUID.TryParse(crumbs[0], out owner))
645 {
646 if (crumbs[1].Length == 32)
647 {
648 Scene scene = requestData.scene;
649 if (scene != null)
650 {
651 SceneObjectPart host = scene.GetSceneObjectPart(requestData.hostID);
652 if (host != null)
653 {
654 if (host.OwnerID == owner)
655 requestData.allowResponseType = true;
656 }
657 }
658 }
659 }
660 }
661 }
622 } 662 }
623
624 foreach (DictionaryEntry de in request) 663 foreach (DictionaryEntry de in request)
625 { 664 {
626 if (de.Key.ToString() == "querystringkeys") 665 if (de.Key.ToString() == "querystringkeys")
@@ -631,13 +670,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
631 if (request.ContainsKey(key)) 670 if (request.ContainsKey(key))
632 { 671 {
633 string val = (String)request[key]; 672 string val = (String)request[key];
634 queryString = queryString + key + "=" + val + "&"; 673 if (key != "")
674 {
675 queryString = queryString + key + "=" + val + "&";
676 }
677 else
678 {
679 queryString = queryString + val + "&";
680 }
635 } 681 }
636 } 682 }
637
638 if (queryString.Length > 1) 683 if (queryString.Length > 1)
639 queryString = queryString.Substring(0, queryString.Length - 1); 684 queryString = queryString.Substring(0, queryString.Length - 1);
685
640 } 686 }
687
641 } 688 }
642 689
643 //if this machine is behind DNAT/port forwarding, currently this is being 690 //if this machine is behind DNAT/port forwarding, currently this is being
@@ -645,23 +692,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
645 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; 692 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
646 requestData.headers["x-path-info"] = pathInfo; 693 requestData.headers["x-path-info"] = pathInfo;
647 requestData.headers["x-query-string"] = queryString; 694 requestData.headers["x-query-string"] = queryString;
648 requestData.headers["x-script-url"] = urlData.url; 695 requestData.headers["x-script-url"] = url.url;
649 696
650 urlData.requests.Add(requestID, requestData); 697 //requestData.ev = new ManualResetEvent(false);
651 m_RequestMap.Add(requestID, urlData); 698 lock (url.requests)
652 } 699 {
700 url.requests.Add(requestID, requestData);
701 }
702 lock (m_RequestMap)
703 {
704 //add to request map
705 m_RequestMap.Add(requestID, url);
706 }
653 707
654 urlData.engine.PostScriptEvent( 708 url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
655 urlData.itemID, 709
656 "http_request", 710 //send initial response?
657 new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); 711// Hashtable response = new Hashtable();
658 } 712
659 catch (Exception we) 713 return;
660 { 714
661 //Hashtable response = new Hashtable(); 715 }
662 m_log.Warn("[HttpRequestHandler]: http-in request failed"); 716 catch (Exception we)
663 m_log.Warn(we.Message); 717 {
664 m_log.Warn(we.StackTrace); 718 //Hashtable response = new Hashtable();
719 m_log.Warn("[HttpRequestHandler]: http-in request failed");
720 m_log.Warn(we.Message);
721 m_log.Warn(we.StackTrace);
722 }
665 } 723 }
666 } 724 }
667 725
diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
index 6da2222..ad33f23 100644
--- a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
@@ -271,6 +271,8 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
271 return "modInvokeR"; 271 return "modInvokeR";
272 else if (sid.ReturnType == typeof(object[])) 272 else if (sid.ReturnType == typeof(object[]))
273 return "modInvokeL"; 273 return "modInvokeL";
274 else if (sid.ReturnType == typeof(void))
275 return "modInvokeN";
274 276
275 m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); 277 m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name);
276 } 278 }
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
index 4cecd85..2fc89fc 100644
--- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
@@ -861,4 +861,4 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
861 return null; 861 return null;
862 } 862 }
863 } 863 }
864} \ No newline at end of file 864}
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 3484387..1c3a714 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -96,6 +96,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
96 // private static readonly ILog m_log = 96 // private static readonly ILog m_log =
97 // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 97 // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
98 98
99 private const int DEBUG_CHANNEL = 2147483647;
100
99 private ListenerManager m_listenerManager; 101 private ListenerManager m_listenerManager;
100 private Queue m_pending; 102 private Queue m_pending;
101 private Queue m_pendingQ; 103 private Queue m_pendingQ;
@@ -366,14 +368,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
366 /// <param name='msg'> 368 /// <param name='msg'>
367 /// Message. 369 /// Message.
368 /// </param> 370 /// </param>
369 public void DeliverMessageTo(UUID target, int channel, Vector3 pos, 371 public bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error)
370 string name, UUID id, string msg)
371 { 372 {
373 error = null;
374
375 if (channel == DEBUG_CHANNEL)
376 return true;
377
372 // Is id an avatar? 378 // Is id an avatar?
373 ScenePresence sp = m_scene.GetScenePresence(target); 379 ScenePresence sp = m_scene.GetScenePresence(target);
374 380
375 if (sp != null) 381 if (sp != null)
376 { 382 {
383<<<<<<< HEAD
377 // ignore if a child agent this is restricted to inside one 384 // ignore if a child agent this is restricted to inside one
378 // region 385 // region
379 if (sp.IsChildAgent) 386 if (sp.IsChildAgent)
@@ -386,41 +393,50 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
386 List<SceneObjectGroup> attachments = sp.GetAttachments(); 393 List<SceneObjectGroup> attachments = sp.GetAttachments();
387 if (attachments.Count == 0) 394 if (attachments.Count == 0)
388 return; 395 return;
396=======
397 // Send message to avatar
398 if (channel == 0)
399 {
400 // Channel 0 goes to viewer ONLY
401 m_scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, target, false, false);
402 return true;
403 }
404>>>>>>> avn/ubitvar
389 405
390 // Get uuid of attachments 406 List<SceneObjectGroup> attachments = sp.GetAttachments();
391 List<UUID> targets = new List<UUID>();
392 foreach (SceneObjectGroup sog in attachments)
393 {
394 if (!sog.IsDeleted)
395 targets.Add(sog.UUID);
396 }
397 407
398 // Need to check each attachment 408 if (attachments.Count == 0)
399 foreach (ListenerInfo li 409 return true;
400 in m_listenerManager.GetListeners(UUID.Zero,
401 channel, name, id, msg))
402 {
403 if (li.GetHostID().Equals(id))
404 continue;
405 410
406 if (m_scene.GetSceneObjectPart( 411 // Get uuid of attachments
407 li.GetHostID()) == null) 412 List<UUID> targets = new List<UUID>();
408 { 413 foreach (SceneObjectGroup sog in attachments)
409 continue; 414 {
410 } 415 if (!sog.IsDeleted)
416 targets.Add(sog.UUID);
417 }
411 418
412 if (targets.Contains(li.GetHostID())) 419 // Need to check each attachment
413 QueueMessage(new ListenerInfo(li, name, id, msg)); 420 foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
414 } 421 {
422 if (li.GetHostID().Equals(id))
423 continue;
424
425 if (m_scene.GetSceneObjectPart(li.GetHostID()) == null)
426 continue;
427
428 if (targets.Contains(li.GetHostID()))
429 QueueMessage(new ListenerInfo(li, name, id, msg));
415 } 430 }
416 431
417 return; 432 return true;
418 } 433 }
419 434
420 // No avatar found so look for an object 435 SceneObjectPart part = m_scene.GetSceneObjectPart(target);
421 foreach (ListenerInfo li 436 if (part == null) // Not even an object
422 in m_listenerManager.GetListeners(UUID.Zero, channel, 437 return true; // No error
423 name, id, msg)) 438
439 foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
424 { 440 {
425 // Dont process if this message is from yourself! 441 // Dont process if this message is from yourself!
426 if (li.GetHostID().Equals(id)) 442 if (li.GetHostID().Equals(id))
@@ -438,7 +454,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
438 } 454 }
439 } 455 }
440 456
441 return; 457 return true;
442 } 458 }
443 459
444 protected void QueueMessage(ListenerInfo li) 460 protected void QueueMessage(ListenerInfo li)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/UserProfiles/LocalUserProfilesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/UserProfiles/LocalUserProfilesServiceConnector.cs
index 4701ee6..323535a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/UserProfiles/LocalUserProfilesServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/UserProfiles/LocalUserProfilesServiceConnector.cs
@@ -153,8 +153,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Profile
153 Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest); 153 Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest);
154 Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate); 154 Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate);
155 Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate); 155 Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate);
156 Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate);
157 Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest);
158 Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest); 156 Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest);
159 Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData); 157 Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData);
160 Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData); 158 Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData);
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
index 16f42a7..f027810 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
@@ -139,6 +139,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication
139 139
140 #region IAuthenticationService 140 #region IAuthenticationService
141 141
142 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
143 {
144 // Not implemented at the regions
145 realID = UUID.Zero;
146 return string.Empty;
147 }
148
142 public string Authenticate(UUID principalID, string password, int lifetime) 149 public string Authenticate(UUID principalID, string password, int lifetime)
143 { 150 {
144 // Not implemented at the regions 151 // Not implemented at the regions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
index aa5f889..8df30d4 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
@@ -198,4 +198,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
198 Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected"); 198 Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected");
199 } 199 }
200 } 200 }
201} \ No newline at end of file 201}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 860a526..d786c80 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -53,7 +53,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
53 /// </remarks> 53 /// </remarks>
54 54
55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")] 55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")]
56<<<<<<< HEAD
56 public class MapImageServiceModule : IMapImageUploadModule, ISharedRegionModule 57 public class MapImageServiceModule : IMapImageUploadModule, ISharedRegionModule
58=======
59 public class MapImageServiceModule : ISharedRegionModule, IMapImageUploadModule
60>>>>>>> avn/ubitvar
57 { 61 {
58 private static readonly ILog m_log = 62 private static readonly ILog m_log =
59 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 63 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -93,9 +97,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
93 if (config == null) 97 if (config == null)
94 return; 98 return;
95 99
100<<<<<<< HEAD
96 int refreshminutes = Convert.ToInt32(config.GetString("RefreshTime")); 101 int refreshminutes = Convert.ToInt32(config.GetString("RefreshTime"));
97 102
98 // if refresh is less than zero, disable the module 103 // if refresh is less than zero, disable the module
104=======
105 int refreshminutes = Convert.ToInt32(config.GetString("RefreshTime", "-1"));
106>>>>>>> avn/ubitvar
99 if (refreshminutes < 0) 107 if (refreshminutes < 0)
100 { 108 {
101 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Negative refresh time given in config. Module disabled."); 109 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Negative refresh time given in config. Module disabled.");
@@ -128,7 +136,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
128 m_refreshTimer.Interval = m_refreshtime; 136 m_refreshTimer.Interval = m_refreshtime;
129 m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh); 137 m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh);
130 138
139<<<<<<< HEAD
131 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with refresh time {0} min and service object {1}", 140 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with refresh time {0} min and service object {1}",
141=======
142 if (m_refreshtime > 0)
143 {
144 m_refreshTimer.Enabled = true;
145 m_refreshTimer.AutoReset = true;
146 m_refreshTimer.Interval = m_refreshtime;
147 m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh);
148 }
149
150 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with refresh time {0} min and service object {1}",
151>>>>>>> avn/ubitvar
132 refreshminutes, service); 152 refreshminutes, service);
133 } 153 }
134 else 154 else
@@ -154,7 +174,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
154 // v2 Map generation on startup is now handled by scene to allow bmp to be shared with 174 // v2 Map generation on startup is now handled by scene to allow bmp to be shared with
155 // v1 service and not generate map tiles twice as was previous behavior 175 // v1 service and not generate map tiles twice as was previous behavior
156 //scene.EventManager.OnRegionReadyStatusChange += s => { if (s.Ready) UploadMapTile(s); }; 176 //scene.EventManager.OnRegionReadyStatusChange += s => { if (s.Ready) UploadMapTile(s); };
177<<<<<<< HEAD
157 178
179=======
180>>>>>>> avn/ubitvar
158 scene.RegisterModuleInterface<IMapImageUploadModule>(this); 181 scene.RegisterModuleInterface<IMapImageUploadModule>(this);
159 } 182 }
160 183
@@ -212,9 +235,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
212 // If the region/maptile is legacy sized, just upload the one tile like it has always been done 235 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
213 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize) 236 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
214 { 237 {
238<<<<<<< HEAD
215 ConvertAndUploadMaptile(mapTile, 239 ConvertAndUploadMaptile(mapTile,
216 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, 240 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
217 scene.RegionInfo.RegionName); 241 scene.RegionInfo.RegionName);
242=======
243 ConvertAndUploadMaptile(mapTile, scene,
244 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
245 scene.RegionInfo.RegionName);
246>>>>>>> avn/ubitvar
218 } 247 }
219 else 248 else
220 { 249 {
@@ -234,10 +263,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
234 (int)Constants.RegionSize, (int)Constants.RegionSize); 263 (int)Constants.RegionSize, (int)Constants.RegionSize);
235 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat)) 264 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
236 { 265 {
266<<<<<<< HEAD
237 ConvertAndUploadMaptile(subMapTile, 267 ConvertAndUploadMaptile(subMapTile,
238 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize), 268 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
239 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize), 269 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
240 scene.Name); 270 scene.Name);
271=======
272 ConvertAndUploadMaptile(subMapTile, scene,
273 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
274 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
275 scene.Name);
276>>>>>>> avn/ubitvar
241 } 277 }
242 } 278 }
243 } 279 }
@@ -247,8 +283,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
247 ///<summary> 283 ///<summary>
248 /// 284 ///
249 ///</summary> 285 ///</summary>
250 private void UploadMapTile(IScene scene) 286 public void UploadMapTile(IScene scene)
251 { 287 {
288<<<<<<< HEAD
289=======
290 m_log.DebugFormat("{0}: upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
291
292>>>>>>> avn/ubitvar
252 // Create a JPG map tile and upload it to the AddMapTile API 293 // Create a JPG map tile and upload it to the AddMapTile API
253 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 294 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
254 if (tileGenerator == null) 295 if (tileGenerator == null)
@@ -259,6 +300,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
259 300
260 using (Bitmap mapTile = tileGenerator.CreateMapTile()) 301 using (Bitmap mapTile = tileGenerator.CreateMapTile())
261 { 302 {
303<<<<<<< HEAD
262 if (mapTile != null) 304 if (mapTile != null)
263 { 305 {
264 UploadMapTile(scene, mapTile); 306 UploadMapTile(scene, mapTile);
@@ -274,6 +316,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
274 { 316 {
275 byte[] jpgData = Utils.EmptyBytes; 317 byte[] jpgData = Utils.EmptyBytes;
276 318
319=======
320 // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
321 // is no static map tile.
322 if (mapTile == null)
323 return;
324
325 UploadMapTile(scene, mapTile);
326 }
327 }
328
329 private void ConvertAndUploadMaptile(Image tileImage, IScene scene, uint locX, uint locY, string regionName)
330 {
331 byte[] jpgData = Utils.EmptyBytes;
332
333>>>>>>> avn/ubitvar
277 using (MemoryStream stream = new MemoryStream()) 334 using (MemoryStream stream = new MemoryStream())
278 { 335 {
279 tileImage.Save(stream, ImageFormat.Jpeg); 336 tileImage.Save(stream, ImageFormat.Jpeg);
@@ -282,7 +339,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
282 if (jpgData != Utils.EmptyBytes) 339 if (jpgData != Utils.EmptyBytes)
283 { 340 {
284 string reason = string.Empty; 341 string reason = string.Empty;
342<<<<<<< HEAD
285 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, out reason)) 343 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, out reason))
344=======
345 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason))
346>>>>>>> avn/ubitvar
286 { 347 {
287 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader, 348 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
288 regionName, locX, locY, reason); 349 regionName, locX, locY, reason);
@@ -290,8 +351,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
290 } 351 }
291 else 352 else
292 { 353 {
354<<<<<<< HEAD
293 m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, regionName); 355 m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, regionName);
356=======
357 m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, scene.RegionInfo.RegionName);
358>>>>>>> avn/ubitvar
294 } 359 }
295 } 360 }
296 } 361 }
297} \ No newline at end of file 362}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
index adf3a91..50238a5 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
@@ -269,7 +269,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
269 return true; 269 return true;
270 } 270 }
271 271
272<<<<<<< HEAD
272 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string theirversion, List<UUID> features, out string version, out string reason) 273 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string theirversion, List<UUID> features, out string version, out string reason)
274=======
275 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string theirversion, out string version, out string reason)
276>>>>>>> avn/ubitvar
273 { 277 {
274 reason = "Communications failure"; 278 reason = "Communications failure";
275 version = ServiceVersion; 279 version = ServiceVersion;
@@ -298,7 +302,29 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
298 302
299 } 303 }
300 304
305<<<<<<< HEAD
301 return m_scenes[destination.RegionID].QueryAccess(agentID, agentHomeURI, viaTeleport, position, features, out reason); 306 return m_scenes[destination.RegionID].QueryAccess(agentID, agentHomeURI, viaTeleport, position, features, out reason);
307=======
308
309 // not really need on a grid running var regions sims
310
311 uint size = m_scenes[destination.RegionID].RegionInfo.RegionSizeX;
312
313 float theirVersionNumber = 0f;
314 string[] versionComponents = theirversion.Split(new char[] { '/' });
315 if (versionComponents.Length >= 2)
316 float.TryParse(versionComponents[1], out theirVersionNumber);
317
318 // Var regions here, and the requesting simulator is in an older version.
319 // We will forbide this, because it crashes the viewers
320 if (theirVersionNumber < 0.3f && size > 256)
321 {
322 reason = "Destination is a variable-sized region, and source is an old simulator. Consider upgrading.";
323 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Request to access this variable-sized region from {0} simulator was denied", theirVersionNumber);
324 return false;
325 }
326 return m_scenes[destination.RegionID].QueryAccess(agentID, position, out reason);
327>>>>>>> avn/ubitvar
302 } 328 }
303 329
304 //m_log.Debug("[LOCAL COMMS]: region not found for QueryAccess"); 330 //m_log.Debug("[LOCAL COMMS]: region not found for QueryAccess");
@@ -335,7 +361,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
335 m_scenes[destination.RegionID].CloseAgent(id, false, auth_token); 361 m_scenes[destination.RegionID].CloseAgent(id, false, auth_token);
336 return true; 362 return true;
337 } 363 }
338
339 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); 364 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
340 return false; 365 return false;
341 } 366 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
index dca3dd7..7044d92 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
@@ -206,7 +206,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
206 return m_remoteConnector.UpdateAgent(destination, cAgentData); 206 return m_remoteConnector.UpdateAgent(destination, cAgentData);
207 } 207 }
208 208
209<<<<<<< HEAD
209 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, List<UUID> features, out string version, out string reason) 210 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, List<UUID> features, out string version, out string reason)
211=======
212 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, out string version, out string reason)
213>>>>>>> avn/ubitvar
210 { 214 {
211 reason = "Communications failure"; 215 reason = "Communications failure";
212 version = "Unknown"; 216 version = "Unknown";
@@ -215,12 +219,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
215 return false; 219 return false;
216 220
217 // Try local first 221 // Try local first
222<<<<<<< HEAD
218 if (m_localBackend.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, features, out version, out reason)) 223 if (m_localBackend.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, features, out version, out reason))
224=======
225 if (m_localBackend.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, out version, out reason))
226 return true;
227>>>>>>> avn/ubitvar
219 return true; 228 return true;
220 229
221 // else do the remote thing 230 // else do the remote thing
222 if (!m_localBackend.IsLocalRegion(destination.RegionID)) 231 if (!m_localBackend.IsLocalRegion(destination.RegionID))
232<<<<<<< HEAD
223 return m_remoteConnector.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, features, out version, out reason); 233 return m_remoteConnector.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, features, out version, out reason);
234=======
235 return m_remoteConnector.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, sversion, out version, out reason);
236
237>>>>>>> avn/ubitvar
224 238
225 return false; 239 return false;
226 } 240 }
@@ -238,7 +252,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
238 return false; 252 return false;
239 } 253 }
240 254
241
242 public bool CloseAgent(GridRegion destination, UUID id, string auth_token) 255 public bool CloseAgent(GridRegion destination, UUID id, string auth_token)
243 { 256 {
244 if (destination == null) 257 if (destination == null)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
index 6d4ac39..cf9a7b4 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
@@ -129,6 +129,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner 129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner
130 // user account service?! 130 // user account service?!
131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService); 131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService);
132 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
132 } 133 }
133 134
134 public void RemoveRegion(Scene scene) 135 public void RemoveRegion(Scene scene)
@@ -181,6 +182,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
181 return UserAccountService.GetUserAccount(scopeID, Email); 182 return UserAccountService.GetUserAccount(scopeID, Email);
182 } 183 }
183 184
185 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
186 {
187 return null;
188 }
189
184 public List<UserAccount> GetUserAccounts(UUID scopeID, string query) 190 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
185 { 191 {
186 return UserAccountService.GetUserAccounts(scopeID, query); 192 return UserAccountService.GetUserAccounts(scopeID, query);
@@ -203,4 +209,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
203 209
204 #endregion 210 #endregion
205 } 211 }
206} \ No newline at end of file 212}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
index 5aa87d3..afbba30 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
@@ -34,6 +34,7 @@ using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces; 35using OpenSim.Services.Interfaces;
36using OpenSim.Services.Connectors; 36using OpenSim.Services.Connectors;
37using OpenSim.Framework;
37 38
38using OpenMetaverse; 39using OpenMetaverse;
39 40
@@ -103,6 +104,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
103 return; 104 return;
104 105
105 scene.RegisterModuleInterface<IUserAccountService>(this); 106 scene.RegisterModuleInterface<IUserAccountService>(this);
107 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
108
109 scene.EventManager.OnNewClient += OnNewClient;
106 } 110 }
107 111
108 public void RemoveRegion(Scene scene) 112 public void RemoveRegion(Scene scene)
@@ -117,6 +121,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
117 return; 121 return;
118 } 122 }
119 123
124 // When a user actually enters the sim, clear them from
125 // cache so the sim will have the current values for
126 // flags, title, etc. And country, don't forget country!
127 private void OnNewClient(IClientAPI client)
128 {
129 m_Cache.Remove(client.Name);
130 }
131
120 #region Overwritten methods from IUserAccountService 132 #region Overwritten methods from IUserAccountService
121 133
122 public override UserAccount GetUserAccount(UUID scopeID, UUID userID) 134 public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
index ed52e48..53610d9 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
@@ -34,7 +34,7 @@ using log4net;
34 34
35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts 35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
36{ 36{
37 public class UserAccountCache 37 public class UserAccountCache : IUserAccountCacheModule
38 { 38 {
39 private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours! 39 private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours!
40 40
@@ -97,5 +97,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
97 97
98 return null; 98 return null;
99 } 99 }
100
101 public void Remove(string name)
102 {
103 if (!m_NameCache.Contains(name))
104 return;
105
106 UUID uuid = UUID.Zero;
107 if (m_NameCache.TryGetValue(name, out uuid))
108 {
109 m_NameCache.Remove(name);
110 m_UUIDCache.Remove(uuid);
111 }
112 }
100 } 113 }
101} 114}
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index 9c6706f..f0b0f4a 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -160,10 +160,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
160 160
161 private IAssetService m_assetService = null; 161 private IAssetService m_assetService = null;
162 162
163 private UUID m_defaultUser;
163 164
165<<<<<<< HEAD
164 private UUID m_defaultUser; 166 private UUID m_defaultUser;
165 167
166 public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string,object>options) 168 public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string,object>options)
169=======
170 public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string, object> options)
171>>>>>>> avn/ubitvar
167 { 172 {
168 m_rootScene = scene; 173 m_rootScene = scene;
169 174
@@ -172,7 +177,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
172 m_defaultUser = (UUID)options["default-user"]; 177 m_defaultUser = (UUID)options["default-user"];
173 m_log.InfoFormat("Using User {0} as default user", m_defaultUser.ToString()); 178 m_log.InfoFormat("Using User {0} as default user", m_defaultUser.ToString());
174 } 179 }
180<<<<<<< HEAD
175 else 181 else
182=======
183 else
184>>>>>>> avn/ubitvar
176 { 185 {
177 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner; 186 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
178 } 187 }
@@ -189,8 +198,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
189 + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); 198 + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
190 m_log.Error(e); 199 m_log.Error(e);
191 } 200 }
192 201
193 m_errorMessage = String.Empty; 202 m_errorMessage = String.Empty;
203<<<<<<< HEAD
204=======
205
206>>>>>>> avn/ubitvar
194 m_merge = options.ContainsKey("merge"); 207 m_merge = options.ContainsKey("merge");
195 m_forceTerrain = options.ContainsKey("force-terrain"); 208 m_forceTerrain = options.ContainsKey("force-terrain");
196 m_forceParcels = options.ContainsKey("force-parcels"); 209 m_forceParcels = options.ContainsKey("force-parcels");
@@ -199,18 +212,34 @@ namespace OpenSim.Region.CoreModules.World.Archiver
199 m_requestId = requestId; 212 m_requestId = requestId;
200 m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero; 213 m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero;
201 m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f; 214 m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f;
215<<<<<<< HEAD
202 m_rotationCenter = options.ContainsKey("rotation-center") ? (Vector3)options["rotation-center"] 216 m_rotationCenter = options.ContainsKey("rotation-center") ? (Vector3)options["rotation-center"]
203 : new Vector3(scene.RegionInfo.RegionSizeX / 2f, scene.RegionInfo.RegionSizeY / 2f, 0f); 217 : new Vector3(scene.RegionInfo.RegionSizeX / 2f, scene.RegionInfo.RegionSizeY / 2f, 0f);
204 218
205 // Zero can never be a valid user or group id 219 // Zero can never be a valid user or group id
206 m_validUserUuids[UUID.Zero] = false; 220 m_validUserUuids[UUID.Zero] = false;
207 m_validGroupUuids[UUID.Zero] = false; 221 m_validGroupUuids[UUID.Zero] = false;
222=======
223 m_rotationCenter = options.ContainsKey("rotation-center") ? (Vector3)options["rotation-center"]
224 : new Vector3(scene.RegionInfo.RegionSizeX / 2f, scene.RegionInfo.RegionSizeY / 2f, 0f);
225
226 m_requestId = requestId;
227
228 // Zero can never be a valid user id (or group)
229 m_validUserUuids[UUID.Zero] = false;
230 m_validGroupUuids[UUID.Zero] = false;
231
232>>>>>>> avn/ubitvar
208 233
209 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>(); 234 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
210 m_assetService = m_rootScene.AssetService; 235 m_assetService = m_rootScene.AssetService;
211 } 236 }
212 237
238<<<<<<< HEAD
213 public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object>options) 239 public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object>options)
240=======
241 public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object> options)
242>>>>>>> avn/ubitvar
214 { 243 {
215 m_rootScene = scene; 244 m_rootScene = scene;
216 m_loadPath = null; 245 m_loadPath = null;
@@ -220,7 +249,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
220 m_requestId = requestId; 249 m_requestId = requestId;
221 250
222 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner; 251 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
252<<<<<<< HEAD
223 253
254=======
255
256>>>>>>> avn/ubitvar
224 // Zero can never be a valid user id 257 // Zero can never be a valid user id
225 m_validUserUuids[UUID.Zero] = false; 258 m_validUserUuids[UUID.Zero] = false;
226 259
@@ -294,15 +327,24 @@ namespace OpenSim.Region.CoreModules.World.Archiver
294 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) 327 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
295 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); 328 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
296 } 329 }
330<<<<<<< HEAD
297 else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain)) 331 else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain))
332=======
333 else if ((!m_merge || m_forceTerrain) && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
334>>>>>>> avn/ubitvar
298 { 335 {
299 LoadTerrain(scene, filePath, data); 336 LoadTerrain(scene, filePath, data);
300 } 337 }
301 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) 338 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
302 { 339 {
303 LoadRegionSettings(scene, filePath, data, dearchivedScenes); 340 LoadRegionSettings(scene, filePath, data, dearchivedScenes);
341<<<<<<< HEAD
304 } 342 }
305 else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels)) 343 else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels))
344=======
345 }
346 else if ((!m_merge || m_forceParcels) && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
347>>>>>>> avn/ubitvar
306 { 348 {
307 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); 349 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data));
308 } 350 }
@@ -523,7 +565,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
523 } 565 }
524 } 566 }
525 567
568<<<<<<< HEAD
526 569
570=======
571>>>>>>> avn/ubitvar
527 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero); 572 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero);
528 573
529 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned 574 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
@@ -540,6 +585,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
540 } 585 }
541 586
542 ModifySceneObject(scene, sceneObject); 587 ModifySceneObject(scene, sceneObject);
588<<<<<<< HEAD
589=======
590
591>>>>>>> avn/ubitvar
543 592
544 if (scene.AddRestoredSceneObject(sceneObject, true, false)) 593 if (scene.AddRestoredSceneObject(sceneObject, true, false))
545 { 594 {
@@ -600,6 +649,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver
600 // being no copy/no mod for everyone 649 // being no copy/no mod for everyone
601 lock (part.TaskInventory) 650 lock (part.TaskInventory)
602 { 651 {
652<<<<<<< HEAD
653=======
654 // And zap any troublesome sit target information
655 part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
656 part.SitTargetPosition = new Vector3(0, 0, 0);
657
658 // Fix ownership/creator of inventory items
659 // Not doing so results in inventory items
660 // being no copy/no mod for everyone
661 part.TaskInventory.LockItemsForRead(true);
662>>>>>>> avn/ubitvar
603 TaskInventoryDictionary inv = part.TaskInventory; 663 TaskInventoryDictionary inv = part.TaskInventory;
604 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv) 664 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
605 { 665 {
@@ -620,11 +680,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver
620 if (!ResolveGroupUuid(kvp.Value.GroupID)) 680 if (!ResolveGroupUuid(kvp.Value.GroupID))
621 kvp.Value.GroupID = UUID.Zero; 681 kvp.Value.GroupID = UUID.Zero;
622 } 682 }
683<<<<<<< HEAD
684=======
685 part.TaskInventory.LockItemsForRead(false);
686>>>>>>> avn/ubitvar
623 } 687 }
624 } 688 }
625 } 689 }
626 690
691<<<<<<< HEAD
627 692
693=======
694>>>>>>> avn/ubitvar
628 /// <summary> 695 /// <summary>
629 /// Load serialized parcels. 696 /// Load serialized parcels.
630 /// </summary> 697 /// </summary>
@@ -645,7 +712,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
645 parcel.AABBMin += parcelDisp; 712 parcel.AABBMin += parcelDisp;
646 parcel.AABBMax += parcelDisp; 713 parcel.AABBMax += parcelDisp;
647 } 714 }
715<<<<<<< HEAD
648 716
717=======
718
719>>>>>>> avn/ubitvar
649 // Validate User and Group UUID's 720 // Validate User and Group UUID's
650 721
651 if (!ResolveGroupUuid(parcel.GroupID)) 722 if (!ResolveGroupUuid(parcel.GroupID))
@@ -660,14 +731,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver
660 } 731 }
661 else 732 else
662 { 733 {
734<<<<<<< HEAD
663 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; 735 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
736=======
737 parcel.OwnerID = m_defaultUser;
738 parcel.GroupID = UUID.Zero;
739>>>>>>> avn/ubitvar
664 parcel.IsGroupOwned = false; 740 parcel.IsGroupOwned = false;
665 } 741 }
666 } 742 }
667 else 743 else
668 { 744 {
669 if (!ResolveUserUuid(scene, parcel.OwnerID)) 745 if (!ResolveUserUuid(scene, parcel.OwnerID))
746<<<<<<< HEAD
670 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; 747 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
748=======
749 parcel.OwnerID = m_defaultUser;
750
751 if (!ResolveGroupUuid(parcel.GroupID))
752 parcel.GroupID = UUID.Zero;
753>>>>>>> avn/ubitvar
671 } 754 }
672 755
673 List<LandAccessEntry> accessList = new List<LandAccessEntry>(); 756 List<LandAccessEntry> accessList = new List<LandAccessEntry>();
@@ -796,7 +879,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
796 if (data == null) 879 if (data == null)
797 return false; 880 return false;
798 } 881 }
882<<<<<<< HEAD
799 883
884=======
885>>>>>>> avn/ubitvar
800 //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); 886 //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
801 887
802 AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString()); 888 AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString());
@@ -918,7 +1004,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
918 private bool LoadTerrain(Scene scene, string terrainPath, byte[] data) 1004 private bool LoadTerrain(Scene scene, string terrainPath, byte[] data)
919 { 1005 {
920 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); 1006 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
1007<<<<<<< HEAD
921 1008
1009=======
1010
1011>>>>>>> avn/ubitvar
922 using (MemoryStream ms = new MemoryStream(data)) 1012 using (MemoryStream ms = new MemoryStream(data))
923 { 1013 {
924 if (m_displacement != Vector3.Zero || m_rotation != 0f) 1014 if (m_displacement != Vector3.Zero || m_rotation != 0f)
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
index 6a09caf..0fb8a32 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
@@ -111,6 +111,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
111 String defaultUser = ""; 111 String defaultUser = "";
112 float rotation = 0f; 112 float rotation = 0f;
113 Vector3 rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0); 113 Vector3 rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0);
114<<<<<<< HEAD
114 115
115 OptionSet options = new OptionSet(); 116 OptionSet options = new OptionSet();
116 options.Add("m|merge", delegate (string v) { mergeOar = (v != null); }); 117 options.Add("m|merge", delegate (string v) { mergeOar = (v != null); });
@@ -122,6 +123,20 @@ namespace OpenSim.Region.CoreModules.World.Archiver
122 options.Add("no-objects", delegate (string v) { noObjects = (v != null); }); 123 options.Add("no-objects", delegate (string v) { noObjects = (v != null); });
123 options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; }); 124 options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; });
124 options.Add("displacement=", delegate (string v) { 125 options.Add("displacement=", delegate (string v) {
126=======
127
128 OptionSet options = new OptionSet();
129 options.Add("m|merge", delegate(string v) { mergeOar = (v != null); });
130 options.Add("s|skip-assets", delegate(string v) { skipAssets = (v != null); });
131 options.Add("force-terrain", delegate(string v) { forceTerrain = (v != null); });
132 options.Add("forceterrain", delegate(string v) { forceTerrain = (v != null); }); // downward compatibility
133 options.Add("force-parcels", delegate(string v) { forceParcels = (v != null); });
134 options.Add("forceparcels", delegate(string v) { forceParcels = (v != null); }); // downward compatibility
135 options.Add("no-objects", delegate(string v) { noObjects = (v != null); });
136 options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; });
137 options.Add("displacement=", delegate(string v)
138 {
139>>>>>>> avn/ubitvar
125 try 140 try
126 { 141 {
127 displacement = v == null ? Vector3.Zero : Vector3.Parse(v); 142 displacement = v == null ? Vector3.Zero : Vector3.Parse(v);
@@ -148,7 +163,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
148 // Convert to radians for internals 163 // Convert to radians for internals
149 rotation = Util.Clamp<float>(rotation, -359f, 359f) / 180f * (float)Math.PI; 164 rotation = Util.Clamp<float>(rotation, -359f, 359f) / 180f * (float)Math.PI;
150 }); 165 });
166<<<<<<< HEAD
151 options.Add("rotation-center=", delegate (string v) { 167 options.Add("rotation-center=", delegate (string v) {
168=======
169 options.Add("rotation-center=", delegate(string v)
170 {
171>>>>>>> avn/ubitvar
152 try 172 try
153 { 173 {
154 rotationCenter = v == null ? Vector3.Zero : Vector3.Parse(v); 174 rotationCenter = v == null ? Vector3.Zero : Vector3.Parse(v);
@@ -288,12 +308,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver
288 Dictionary<string, object> archiveOptions = new Dictionary<string, object>(); 308 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
289 DearchiveRegion(loadPath, Guid.Empty, archiveOptions); 309 DearchiveRegion(loadPath, Guid.Empty, archiveOptions);
290 } 310 }
311<<<<<<< HEAD
291 312
292 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options) 313 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options)
293 { 314 {
294 m_log.InfoFormat( 315 m_log.InfoFormat(
295 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath); 316 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
296 317
318=======
319
320 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string, object> options)
321 {
322 m_log.InfoFormat(
323 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
324
325>>>>>>> avn/ubitvar
297 new ArchiveReadRequest(Scene, loadPath, requestId, options).DearchiveRegion(); 326 new ArchiveReadRequest(Scene, loadPath, requestId, options).DearchiveRegion();
298 } 327 }
299 328
@@ -302,7 +331,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
302 Dictionary<string, object> archiveOptions = new Dictionary<string, object>(); 331 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
303 DearchiveRegion(loadStream, Guid.Empty, archiveOptions); 332 DearchiveRegion(loadStream, Guid.Empty, archiveOptions);
304 } 333 }
334<<<<<<< HEAD
305 335
336=======
337
338>>>>>>> avn/ubitvar
306 public void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options) 339 public void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options)
307 { 340 {
308 new ArchiveReadRequest(Scene, loadStream, requestId, options).DearchiveRegion(); 341 new ArchiveReadRequest(Scene, loadStream, requestId, options).DearchiveRegion();
diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
index db66c83..895b55d 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs
@@ -271,18 +271,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
271 271
272 if (asset != null) 272 if (asset != null)
273 { 273 {
274 if (m_options.ContainsKey("verbose")) 274// m_log.DebugFormat("[ARCHIVER]: Writing asset {0}", id);
275 m_log.InfoFormat("[ARCHIVER]: Writing asset {0}", id);
276
277 m_foundAssetUuids.Add(asset.FullID); 275 m_foundAssetUuids.Add(asset.FullID);
278 276
279 m_assetsArchiver.WriteAsset(PostProcess(asset)); 277 m_assetsArchiver.WriteAsset(PostProcess(asset));
280 } 278 }
281 else 279 else
282 { 280 {
283 if (m_options.ContainsKey("verbose")) 281// m_log.DebugFormat("[ARCHIVER]: Recording asset {0} as not found", id);
284 m_log.InfoFormat("[ARCHIVER]: Recording asset {0} as not found", id);
285
286 m_notFoundAssetUuids.Add(new UUID(id)); 282 m_notFoundAssetUuids.Add(new UUID(id));
287 } 283 }
288 284
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
index 80fa08a..e6e6485 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
@@ -95,6 +95,10 @@ namespace OpenSim.Region.CoreModules.World.Estate
95 95
96 m_commands = new EstateManagementCommands(this); 96 m_commands = new EstateManagementCommands(this);
97 m_commands.Initialise(); 97 m_commands.Initialise();
98
99 m_regionChangeTimer.Interval = 10000;
100 m_regionChangeTimer.Elapsed += RaiseRegionInfoChange;
101 m_regionChangeTimer.AutoReset = false;
98 } 102 }
99 103
100 public void RemoveRegion(Scene scene) {} 104 public void RemoveRegion(Scene scene) {}
@@ -587,6 +591,16 @@ namespace OpenSim.Region.CoreModules.World.Estate
587 IRestartModule restartModule = Scene.RequestModuleInterface<IRestartModule>(); 591 IRestartModule restartModule = Scene.RequestModuleInterface<IRestartModule>();
588 if (restartModule != null) 592 if (restartModule != null)
589 { 593 {
594 if (timeInSeconds == -1)
595 {
596 m_delayCount++;
597 if (m_delayCount > 3)
598 return;
599
600 restartModule.DelayRestart(3600, "Restart delayed by region manager");
601 return;
602 }
603
590 List<int> times = new List<int>(); 604 List<int> times = new List<int>();
591 while (timeInSeconds > 0) 605 while (timeInSeconds > 0)
592 { 606 {
@@ -1477,7 +1491,68 @@ namespace OpenSim.Region.CoreModules.World.Estate
1477 sendRegionHandshake(client); 1491 sendRegionHandshake(client);
1478 } 1492 }
1479 1493
1494<<<<<<< HEAD
1480 private uint GetEstateFlags() 1495 private uint GetEstateFlags()
1496=======
1497 public uint GetRegionFlags()
1498 {
1499 RegionFlags flags = RegionFlags.None;
1500
1501 // Fully implemented
1502 //
1503 if (Scene.RegionInfo.RegionSettings.AllowDamage)
1504 flags |= RegionFlags.AllowDamage;
1505 if (Scene.RegionInfo.RegionSettings.BlockTerraform)
1506 flags |= RegionFlags.BlockTerraform;
1507 if (!Scene.RegionInfo.RegionSettings.AllowLandResell)
1508 flags |= RegionFlags.BlockLandResell;
1509 if (Scene.RegionInfo.RegionSettings.DisableCollisions)
1510 flags |= RegionFlags.SkipCollisions;
1511 if (Scene.RegionInfo.RegionSettings.DisableScripts)
1512 flags |= RegionFlags.SkipScripts;
1513 if (Scene.RegionInfo.RegionSettings.DisablePhysics)
1514 flags |= RegionFlags.SkipPhysics;
1515 if (Scene.RegionInfo.RegionSettings.BlockFly)
1516 flags |= RegionFlags.NoFly;
1517 if (Scene.RegionInfo.RegionSettings.RestrictPushing)
1518 flags |= RegionFlags.RestrictPushObject;
1519 if (Scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
1520 flags |= RegionFlags.AllowParcelChanges;
1521 if (Scene.RegionInfo.RegionSettings.BlockShowInSearch)
1522 flags |= RegionFlags.BlockParcelSearch;
1523 if (Scene.RegionInfo.RegionSettings.GodBlockSearch)
1524 flags |= (RegionFlags)(1 << 11);
1525 if (Scene.RegionInfo.RegionSettings.Casino)
1526 flags |= (RegionFlags)(1 << 10);
1527
1528 if (Scene.RegionInfo.RegionSettings.FixedSun)
1529 flags |= RegionFlags.SunFixed;
1530 if (Scene.RegionInfo.RegionSettings.Sandbox)
1531 flags |= RegionFlags.Sandbox;
1532 if (Scene.RegionInfo.EstateSettings.AllowVoice)
1533 flags |= RegionFlags.AllowVoice;
1534 if (Scene.RegionInfo.EstateSettings.AllowLandmark)
1535 flags |= RegionFlags.AllowLandmark;
1536 if (Scene.RegionInfo.EstateSettings.AllowSetHome)
1537 flags |= RegionFlags.AllowSetHome;
1538 if (Scene.RegionInfo.EstateSettings.BlockDwell)
1539 flags |= RegionFlags.BlockDwell;
1540 if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
1541 flags |= RegionFlags.ResetHomeOnTeleport;
1542
1543
1544 // TODO: SkipUpdateInterestList
1545
1546 // Omitted
1547 //
1548 // Omitted: NullLayer (what is that?)
1549 // Omitted: SkipAgentAction (what does it do?)
1550
1551 return (uint)flags;
1552 }
1553
1554 public uint GetEstateFlags()
1555>>>>>>> avn/ubitvar
1481 { 1556 {
1482 RegionFlags flags = RegionFlags.None; 1557 RegionFlags flags = RegionFlags.None;
1483 1558
diff --git a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs
index 73c592d..378826d 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs
@@ -40,23 +40,33 @@ namespace OpenSim.Region.CoreModules.World.Land
40 //Land types set with flags in ParcelOverlay. 40 //Land types set with flags in ParcelOverlay.
41 //Only one of these can be used. 41 //Only one of these can be used.
42 public const float BAN_LINE_SAFETY_HIEGHT = 100; 42 public const float BAN_LINE_SAFETY_HIEGHT = 100;
43 public const byte LAND_FLAG_PROPERTY_BORDER_SOUTH = 128; //Equals 10000000
44 public const byte LAND_FLAG_PROPERTY_BORDER_WEST = 64; //Equals 01000000
45 43
46 //RequestResults (I think these are right, they seem to work): 44 //RequestResults (I think these are right, they seem to work):
47 public const int LAND_RESULT_MULTIPLE = 1; // The request they made contained more than a single peice of land 45 public const int LAND_RESULT_MULTIPLE = 1; // The request they made contained more than a single peice of land
48 public const int LAND_RESULT_SINGLE = 0; // The request they made contained only a single piece of land 46 public const int LAND_RESULT_SINGLE = 0; // The request they made contained only a single piece of land
49 47
50 //ParcelSelectObjects 48 //ParcelSelectObjects
49 public const int LAND_SELECT_OBJECTS_OWNER = 2;
51 public const int LAND_SELECT_OBJECTS_GROUP = 4; 50 public const int LAND_SELECT_OBJECTS_GROUP = 4;
52 public const int LAND_SELECT_OBJECTS_OTHER = 8; 51 public const int LAND_SELECT_OBJECTS_OTHER = 8;
53 public const int LAND_SELECT_OBJECTS_OWNER = 2; 52
54 public const byte LAND_TYPE_IS_BEING_AUCTIONED = 5; //Equals 00000101 53
55 public const byte LAND_TYPE_IS_FOR_SALE = 4; //Equals 00000100 54 public const byte LAND_TYPE_PUBLIC = 0; //Equals 00000000
56 public const byte LAND_TYPE_OWNED_BY_GROUP = 2; //Equals 00000010 55 // types 1 to 7 are exclusive
57 public const byte LAND_TYPE_OWNED_BY_OTHER = 1; //Equals 00000001 56 public const byte LAND_TYPE_OWNED_BY_OTHER = 1; //Equals 00000001
57 public const byte LAND_TYPE_OWNED_BY_GROUP = 2; //Equals 00000010
58 public const byte LAND_TYPE_OWNED_BY_REQUESTER = 3; //Equals 00000011 58 public const byte LAND_TYPE_OWNED_BY_REQUESTER = 3; //Equals 00000011
59 public const byte LAND_TYPE_PUBLIC = 0; //Equals 00000000 59 public const byte LAND_TYPE_IS_FOR_SALE = 4; //Equals 00000100
60 public const byte LAND_TYPE_IS_BEING_AUCTIONED = 5; //Equals 00000101
61 public const byte LAND_TYPE_unused6 = 6;
62 public const byte LAND_TYPE_unused7 = 7;
63 // next are flags
64 public const byte LAND_FLAG_unused8 = 0x08; // this may become excluside in future
65 public const byte LAND_FLAG_HIDEAVATARS = 0x10;
66 public const byte LAND_FLAG_LOCALSOUND = 0x20;
67 public const byte LAND_FLAG_PROPERTY_BORDER_WEST = 0x40; //Equals 01000000
68 public const byte LAND_FLAG_PROPERTY_BORDER_SOUTH = 0x80; //Equals 10000000
69
60 70
61 //These are other constants. Yay! 71 //These are other constants. Yay!
62 public const int START_LAND_LOCAL_ID = 1; 72 public const int START_LAND_LOCAL_ID = 1;
@@ -203,7 +213,13 @@ namespace OpenSim.Region.CoreModules.World.Land
203 m_landManagementModule.setParcelOtherCleanTime(remoteClient, localID, otherCleanTime); 213 m_landManagementModule.setParcelOtherCleanTime(remoteClient, localID, otherCleanTime);
204 } 214 }
205 } 215 }
206 216 public void sendClientInitialLandInfo(IClientAPI remoteClient)
217 {
218 if (m_landManagementModule != null)
219 {
220 m_landManagementModule.sendClientInitialLandInfo(remoteClient);
221 }
222 }
207 #endregion 223 #endregion
208 } 224 }
209} 225}
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index 25e1454..8bd46f6 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -69,7 +69,11 @@ namespace OpenSim.Region.CoreModules.World.Land
69 /// <summary> 69 /// <summary>
70 /// Minimum land unit size in region co-ordinates. 70 /// Minimum land unit size in region co-ordinates.
71 /// </summary> 71 /// </summary>
72<<<<<<< HEAD
72 public const int LandUnit = 4; 73 public const int LandUnit = 4;
74=======
75 public const int landUnit = 4;
76>>>>>>> avn/ubitvar
73 77
74 private static readonly string remoteParcelRequestPath = "0009/"; 78 private static readonly string remoteParcelRequestPath = "0009/";
75 79
@@ -89,20 +93,30 @@ namespace OpenSim.Region.CoreModules.World.Land
89 /// <value> 93 /// <value>
90 /// Land objects keyed by local id 94 /// Land objects keyed by local id
91 /// </value> 95 /// </value>
92 private readonly Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>(); 96// private readonly Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>();
97
98 //ubit: removed the readonly so i can move it around
99 private Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>();
93 100
94 private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; 101 private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
95 102
96 private bool m_allowedForcefulBans = true; 103 private bool m_allowedForcefulBans = true;
104 private UUID DefaultGodParcelGroup;
105 private string DefaultGodParcelName;
97 106
98 // caches ExtendedLandData 107 // caches ExtendedLandData
99 private Cache parcelInfoCache; 108 private Cache parcelInfoCache;
109<<<<<<< HEAD
100 110
101 111
102 /// <summary> 112 /// <summary>
103 /// Record positions that avatar's are currently being forced to move to due to parcel entry restrictions. 113 /// Record positions that avatar's are currently being forced to move to due to parcel entry restrictions.
104 /// </summary> 114 /// </summary>
105 private Dictionary<UUID, Vector3> forcedPosition = new Dictionary<UUID, Vector3>(); 115 private Dictionary<UUID, Vector3> forcedPosition = new Dictionary<UUID, Vector3>();
116=======
117 private Dictionary<UUID, Vector3> forcedPosition =
118 new Dictionary<UUID, Vector3>();
119>>>>>>> avn/ubitvar
106 120
107 // Enables limiting parcel layer info transmission when doing simple updates 121 // Enables limiting parcel layer info transmission when doing simple updates
108 private bool shouldLimitParcelLayerInfoToViewDistance { get; set; } 122 private bool shouldLimitParcelLayerInfoToViewDistance { get; set; }
@@ -118,6 +132,7 @@ namespace OpenSim.Region.CoreModules.World.Land
118 132
119 public void Initialise(IConfigSource source) 133 public void Initialise(IConfigSource source)
120 { 134 {
135<<<<<<< HEAD
121 shouldLimitParcelLayerInfoToViewDistance = true; 136 shouldLimitParcelLayerInfoToViewDistance = true;
122 parcelLayerViewDistance = 128; 137 parcelLayerViewDistance = 128;
123 IConfig landManagementConfig = source.Configs["LandManagement"]; 138 IConfig landManagementConfig = source.Configs["LandManagement"];
@@ -125,13 +140,24 @@ namespace OpenSim.Region.CoreModules.World.Land
125 { 140 {
126 shouldLimitParcelLayerInfoToViewDistance = landManagementConfig.GetBoolean("LimitParcelLayerUpdateDistance", shouldLimitParcelLayerInfoToViewDistance); 141 shouldLimitParcelLayerInfoToViewDistance = landManagementConfig.GetBoolean("LimitParcelLayerUpdateDistance", shouldLimitParcelLayerInfoToViewDistance);
127 parcelLayerViewDistance = landManagementConfig.GetInt("ParcelLayerViewDistance", parcelLayerViewDistance); 142 parcelLayerViewDistance = landManagementConfig.GetInt("ParcelLayerViewDistance", parcelLayerViewDistance);
143=======
144 IConfig cnf = source.Configs["LandManagement"];
145 if (cnf != null)
146 {
147 DefaultGodParcelGroup = new UUID(cnf.GetString("DefaultAdministratorGroupUUID", UUID.Zero.ToString()));
148 DefaultGodParcelName = cnf.GetString("DefaultAdministratorParcelName", "Default Parcel");
149>>>>>>> avn/ubitvar
128 } 150 }
129 } 151 }
130 152
131 public void AddRegion(Scene scene) 153 public void AddRegion(Scene scene)
132 { 154 {
133 m_scene = scene; 155 m_scene = scene;
156<<<<<<< HEAD
134 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit]; 157 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
158=======
159 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
160>>>>>>> avn/ubitvar
135 landChannel = new LandChannel(scene, this); 161 landChannel = new LandChannel(scene, this);
136 162
137 parcelInfoCache = new Cache(); 163 parcelInfoCache = new Cache();
@@ -154,7 +180,7 @@ namespace OpenSim.Region.CoreModules.World.Land
154 m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage; 180 m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage;
155 m_scene.EventManager.OnSetAllowForcefulBan += EventManagerOnSetAllowedForcefulBan; 181 m_scene.EventManager.OnSetAllowForcefulBan += EventManagerOnSetAllowedForcefulBan;
156 m_scene.EventManager.OnRegisterCaps += EventManagerOnRegisterCaps; 182 m_scene.EventManager.OnRegisterCaps += EventManagerOnRegisterCaps;
157 183
158 lock (m_scene) 184 lock (m_scene)
159 { 185 {
160 m_scene.LandChannel = (ILandChannel)landChannel; 186 m_scene.LandChannel = (ILandChannel)landChannel;
@@ -204,13 +230,14 @@ namespace OpenSim.Region.CoreModules.World.Land
204 client.OnParcelFreezeUser += ClientOnParcelFreezeUser; 230 client.OnParcelFreezeUser += ClientOnParcelFreezeUser;
205 client.OnSetStartLocationRequest += ClientOnSetHome; 231 client.OnSetStartLocationRequest += ClientOnSetHome;
206 232
207 233/* avatar is still a child here position is unknown
208 EntityBase presenceEntity; 234 EntityBase presenceEntity;
209 if (m_scene.Entities.TryGetValue(client.AgentId, out presenceEntity) && presenceEntity is ScenePresence) 235 if (m_scene.Entities.TryGetValue(client.AgentId, out presenceEntity) && presenceEntity is ScenePresence)
210 { 236 {
211 SendLandUpdate((ScenePresence)presenceEntity, true); 237 SendLandUpdate((ScenePresence)presenceEntity, true);
212 SendParcelOverlay(client); 238 SendParcelOverlay(client);
213 } 239 }
240*/
214 } 241 }
215 242
216 public void EventMakeChildAgent(ScenePresence avatar) 243 public void EventMakeChildAgent(ScenePresence avatar)
@@ -220,48 +247,6 @@ namespace OpenSim.Region.CoreModules.World.Land
220 247
221 void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) 248 void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
222 { 249 {
223 //If we are forcing a position for them to go
224 if (forcedPosition.ContainsKey(remoteClient.AgentId))
225 {
226 ScenePresence clientAvatar = m_scene.GetScenePresence(remoteClient.AgentId);
227
228 //Putting the user into flying, both keeps the avatar in fligth when it bumps into something and stopped from going another direction AND
229 //When the avatar walks into a ban line on the ground, it prevents getting stuck
230 agentData.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
231
232 //Make sure we stop if they get about to the right place to prevent yoyo and prevents getting stuck on banlines
233 if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) < .2)
234 {
235// m_log.DebugFormat(
236// "[LAND MANAGEMENT MODULE]: Stopping force position of {0} because {1} is close enough to {2}",
237// clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
238
239 forcedPosition.Remove(remoteClient.AgentId);
240 }
241 //if we are far away, teleport
242 else if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) > 3)
243 {
244 Vector3 forcePosition = forcedPosition[remoteClient.AgentId];
245// m_log.DebugFormat(
246// "[LAND MANAGEMENT MODULE]: Teleporting out {0} because {1} is too far from avatar position {2}",
247// clientAvatar.Name, clientAvatar.AbsolutePosition, forcePosition);
248
249 m_scene.RequestTeleportLocation(remoteClient, m_scene.RegionInfo.RegionHandle,
250 forcePosition, clientAvatar.Lookat, (uint)Constants.TeleportFlags.ForceRedirect);
251
252 forcedPosition.Remove(remoteClient.AgentId);
253 }
254 else
255 {
256// m_log.DebugFormat(
257// "[LAND MANAGEMENT MODULE]: Forcing {0} from {1} to {2}",
258// clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
259
260 //Forces them toward the forced position we want if they aren't there yet
261 agentData.UseClientAgentPosition = true;
262 agentData.ClientAgentPosition = forcedPosition[remoteClient.AgentId];
263 }
264 }
265 } 250 }
266 251
267 public void Close() 252 public void Close()
@@ -314,7 +299,11 @@ namespace OpenSim.Region.CoreModules.World.Land
314 { 299 {
315 m_landList.Clear(); 300 m_landList.Clear();
316 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; 301 m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
302<<<<<<< HEAD
317 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit]; 303 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
304=======
305 m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
306>>>>>>> avn/ubitvar
318 } 307 }
319 } 308 }
320 309
@@ -324,16 +313,22 @@ namespace OpenSim.Region.CoreModules.World.Land
324 /// <returns>The parcel created.</returns> 313 /// <returns>The parcel created.</returns>
325 protected ILandObject CreateDefaultParcel() 314 protected ILandObject CreateDefaultParcel()
326 { 315 {
316<<<<<<< HEAD
327 m_log.DebugFormat( 317 m_log.DebugFormat(
328 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName); 318 "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
329 319
330 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene); 320 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
321=======
322 m_log.DebugFormat("{0} Creating default parcel for region {1}", LogHeader, m_scene.RegionInfo.RegionName);
323
324 ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
325>>>>>>> avn/ubitvar
331 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, 326 fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0,
332 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY)); 327 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
333 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; 328 fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
334 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); 329 fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
335 330
336 return AddLandObject(fullSimParcel); 331 return AddLandObject(fullSimParcel);
337 } 332 }
338 333
339 public List<ILandObject> AllParcels() 334 public List<ILandObject> AllParcels()
@@ -382,10 +377,17 @@ namespace OpenSim.Region.CoreModules.World.Land
382 private void ForceAvatarToPosition(ScenePresence avatar, Vector3? position) 377 private void ForceAvatarToPosition(ScenePresence avatar, Vector3? position)
383 { 378 {
384 if (m_scene.Permissions.IsGod(avatar.UUID)) return; 379 if (m_scene.Permissions.IsGod(avatar.UUID)) return;
385 if (position.HasValue) 380
386 { 381 if (!position.HasValue)
387 forcedPosition[avatar.ControllingClient.AgentId] = (Vector3)position; 382 return;
388 } 383
384// land should have no word on avatar physics
385// bool isFlying = avatar.PhysicsActor.Flying;
386// avatar.RemoveFromPhysicalScene();
387
388 avatar.AbsolutePosition = (Vector3)position;
389
390// avatar.AddToPhysicalScene(isFlying);
389 } 391 }
390 392
391 public void SendYouAreRestrictedNotice(ScenePresence avatar) 393 public void SendYouAreRestrictedNotice(ScenePresence avatar)
@@ -405,36 +407,14 @@ namespace OpenSim.Region.CoreModules.World.Land
405 } 407 }
406 408
407 if (parcelAvatarIsEntering != null) 409 if (parcelAvatarIsEntering != null)
408 { 410 EnforceBans(parcelAvatarIsEntering, avatar);
409 if (avatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT)
410 {
411 if (parcelAvatarIsEntering.IsBannedFromLand(avatar.UUID))
412 {
413 SendYouAreBannedNotice(avatar);
414 ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
415 }
416 else if (parcelAvatarIsEntering.IsRestrictedFromLand(avatar.UUID))
417 {
418 SendYouAreRestrictedNotice(avatar);
419 ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
420 }
421 else
422 {
423 avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
424 }
425 }
426 else
427 {
428 avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
429 }
430 }
431 } 411 }
432 } 412 }
433 413
434 public void SendOutNearestBanLine(IClientAPI client) 414 public void SendOutNearestBanLine(IClientAPI client)
435 { 415 {
436 ScenePresence sp = m_scene.GetScenePresence(client.AgentId); 416 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
437 if (sp == null || sp.IsChildAgent) 417 if (sp == null)
438 return; 418 return;
439 419
440 List<ILandObject> checkLandParcels = ParcelsNearPoint(sp.AbsolutePosition); 420 List<ILandObject> checkLandParcels = ParcelsNearPoint(sp.AbsolutePosition);
@@ -454,32 +434,49 @@ namespace OpenSim.Region.CoreModules.World.Land
454 return; 434 return;
455 } 435 }
456 436
437 public void sendClientInitialLandInfo(IClientAPI remoteClient)
438 {
439 ScenePresence avatar;
440
441 if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out avatar))
442 return;
443
444
445 if (!avatar.IsChildAgent)
446 {
447 ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
448 if (over == null)
449 return;
450
451 avatar.currentParcelUUID = over.LandData.GlobalID;
452 over.SendLandUpdateToClient(avatar.ControllingClient);
453 }
454 SendParcelOverlay(remoteClient);
455 }
456
457 public void SendLandUpdate(ScenePresence avatar, bool force) 457 public void SendLandUpdate(ScenePresence avatar, bool force)
458 { 458 {
459<<<<<<< HEAD
459 ILandObject over = GetLandObject((int)Math.Min(((int)m_scene.RegionInfo.RegionSizeX - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))), 460 ILandObject over = GetLandObject((int)Math.Min(((int)m_scene.RegionInfo.RegionSizeX - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
460 (int)Math.Min(((int)m_scene.RegionInfo.RegionSizeY - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y)))); 461 (int)Math.Min(((int)m_scene.RegionInfo.RegionSizeY - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
462=======
463 if (avatar.IsChildAgent)
464 return;
465
466 ILandObject over = GetLandObjectClipedXY(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
467>>>>>>> avn/ubitvar
461 468
462 if (over != null) 469 if (over != null)
463 { 470 {
464 if (force) 471 bool NotsameID = (avatar.currentParcelUUID != over.LandData.GlobalID);
472 if (force || NotsameID)
465 { 473 {
466 if (!avatar.IsChildAgent) 474 over.SendLandUpdateToClient(avatar.ControllingClient);
467 { 475// sl doesnt seem to send this now, as it used 2
468 over.SendLandUpdateToClient(avatar.ControllingClient); 476// SendParcelOverlay(avatar.ControllingClient);
469 m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID, 477 avatar.currentParcelUUID = over.LandData.GlobalID;
470 m_scene.RegionInfo.RegionID); 478 m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
471 } 479 m_scene.RegionInfo.RegionID);
472 }
473
474 if (avatar.currentParcelUUID != over.LandData.GlobalID)
475 {
476 if (!avatar.IsChildAgent)
477 {
478 over.SendLandUpdateToClient(avatar.ControllingClient);
479 avatar.currentParcelUUID = over.LandData.GlobalID;
480 m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
481 m_scene.RegionInfo.RegionID);
482 }
483 } 480 }
484 } 481 }
485 } 482 }
@@ -531,6 +528,7 @@ namespace OpenSim.Region.CoreModules.World.Land
531 //when we are finally in a safe place, lets release the forced position lock 528 //when we are finally in a safe place, lets release the forced position lock
532 forcedPosition.Remove(clientAvatar.ControllingClient.AgentId); 529 forcedPosition.Remove(clientAvatar.ControllingClient.AgentId);
533 } 530 }
531 EnforceBans(parcel, clientAvatar);
534 } 532 }
535 } 533 }
536 534
@@ -589,7 +587,7 @@ namespace OpenSim.Region.CoreModules.World.Land
589 requiredPowers = GroupPowers.LandManageBanned; 587 requiredPowers = GroupPowers.LandManageBanned;
590 588
591 if (m_scene.Permissions.CanEditParcelProperties(agentID, 589 if (m_scene.Permissions.CanEditParcelProperties(agentID,
592 land, requiredPowers)) 590 land, requiredPowers, false))
593 { 591 {
594 land.UpdateAccessList(flags, transactionID, sequenceID, 592 land.UpdateAccessList(flags, transactionID, sequenceID,
595 sections, entries, remote_client); 593 sections, entries, remote_client);
@@ -623,20 +621,28 @@ namespace OpenSim.Region.CoreModules.World.Land
623 new_land.LandData.LocalID = newLandLocalID; 621 new_land.LandData.LocalID = newLandLocalID;
624 622
625 bool[,] landBitmap = new_land.GetLandBitmap(); 623 bool[,] landBitmap = new_land.GetLandBitmap();
624<<<<<<< HEAD
626 // m_log.DebugFormat("{0} AddLandObject. new_land.bitmapSize=({1},{2}). newLocalID={3}", 625 // m_log.DebugFormat("{0} AddLandObject. new_land.bitmapSize=({1},{2}). newLocalID={3}",
627 // LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), newLandLocalID); 626 // LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), newLandLocalID);
628 627
628=======
629>>>>>>> avn/ubitvar
629 if (landBitmap.GetLength(0) != m_landIDList.GetLength(0) || landBitmap.GetLength(1) != m_landIDList.GetLength(1)) 630 if (landBitmap.GetLength(0) != m_landIDList.GetLength(0) || landBitmap.GetLength(1) != m_landIDList.GetLength(1))
630 { 631 {
631 // Going to variable sized regions can cause mismatches 632 // Going to variable sized regions can cause mismatches
632 m_log.ErrorFormat("{0} AddLandObject. Added land bitmap different size than region ID map. bitmapSize=({1},{2}), landIDSize=({3},{4})", 633 m_log.ErrorFormat("{0} AddLandObject. Added land bitmap different size than region ID map. bitmapSize=({1},{2}), landIDSize=({3},{4})",
634<<<<<<< HEAD
633 LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1) ); 635 LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1) );
636=======
637 LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1));
638>>>>>>> avn/ubitvar
634 } 639 }
635 else 640 else
636 { 641 {
637 // If other land objects still believe that they occupy any parts of the same space, 642 // If other land objects still believe that they occupy any parts of the same space,
638 // then do not allow the add to proceed. 643 // then do not allow the add to proceed.
639 for (int x = 0; x < landBitmap.GetLength(0); x++) 644 for (int x = 0; x < landBitmap.GetLength(0); x++)
645<<<<<<< HEAD
640 { 646 {
641 for (int y = 0; y < landBitmap.GetLength(1); y++) 647 for (int y = 0; y < landBitmap.GetLength(1); y++)
642 { 648 {
@@ -663,15 +669,50 @@ namespace OpenSim.Region.CoreModules.World.Land
663 } 669 }
664 670
665 for (int x = 0; x < landBitmap.GetLength(0); x++) 671 for (int x = 0; x < landBitmap.GetLength(0); x++)
672=======
673>>>>>>> avn/ubitvar
666 { 674 {
667 for (int y = 0; y < landBitmap.GetLength(1); y++) 675 for (int y = 0; y < landBitmap.GetLength(1); y++)
668 { 676 {
669 if (landBitmap[x, y]) 677 if (landBitmap[x, y])
670 { 678 {
679<<<<<<< HEAD
671 // m_log.DebugFormat( 680 // m_log.DebugFormat(
672 // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}", 681 // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
673 // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName); 682 // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
674 683
684=======
685 int lastRecordedLandId = m_landIDList[x, y];
686
687 if (lastRecordedLandId > 0)
688 {
689 ILandObject lastRecordedLo = m_landList[lastRecordedLandId];
690
691 if (lastRecordedLo.LandBitmap[x, y])
692 {
693 m_log.ErrorFormat(
694 "{0}: Cannot add parcel \"{1}\", local ID {2} at tile {3},{4} because this is still occupied by parcel \"{5}\", local ID {6} in {7}",
695 LogHeader, new_land.LandData.Name, new_land.LandData.LocalID, x, y,
696 lastRecordedLo.LandData.Name, lastRecordedLo.LandData.LocalID, m_scene.Name);
697
698 return null;
699 }
700 }
701 }
702 }
703 }
704
705 for (int x = 0; x < landBitmap.GetLength(0); x++)
706 {
707 for (int y = 0; y < landBitmap.GetLength(1); y++)
708 {
709 if (landBitmap[x, y])
710 {
711 // m_log.DebugFormat(
712 // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
713 // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
714
715>>>>>>> avn/ubitvar
675 m_landIDList[x, y] = newLandLocalID; 716 m_landIDList[x, y] = newLandLocalID;
676 } 717 }
677 } 718 }
@@ -723,27 +764,28 @@ namespace OpenSim.Region.CoreModules.World.Land
723 /// </summary> 764 /// </summary>
724 public void Clear(bool setupDefaultParcel) 765 public void Clear(bool setupDefaultParcel)
725 { 766 {
726 List<ILandObject> parcels; 767 Dictionary<int, ILandObject> landworkList;
768 // move to work pointer since we are deleting it all
727 lock (m_landList) 769 lock (m_landList)
728 { 770 {
729 parcels = new List<ILandObject>(m_landList.Values); 771 landworkList = m_landList;
772 m_landList = new Dictionary<int, ILandObject>();
730 } 773 }
731 774
732 foreach (ILandObject lo in parcels) 775 // this 2 methods have locks (now)
776 ResetSimLandObjects();
777
778 if (setupDefaultParcel)
779 CreateDefaultParcel();
780
781 // fire outside events unlocked
782 foreach (ILandObject lo in landworkList.Values)
733 { 783 {
734 //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID); 784 //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID);
735 m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID); 785 m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID);
736 } 786 }
787 landworkList.Clear();
737 788
738 lock (m_landList)
739 {
740 m_landList.Clear();
741
742 ResetSimLandObjects();
743 }
744
745 if (setupDefaultParcel)
746 CreateDefaultParcel();
747 } 789 }
748 790
749 private void performFinalLandJoin(ILandObject master, ILandObject slave) 791 private void performFinalLandJoin(ILandObject master, ILandObject slave)
@@ -787,6 +829,7 @@ namespace OpenSim.Region.CoreModules.World.Land
787 /// <returns>Land object at the point supplied</returns> 829 /// <returns>Land object at the point supplied</returns>
788 public ILandObject GetLandObject(float x_float, float y_float) 830 public ILandObject GetLandObject(float x_float, float y_float)
789 { 831 {
832<<<<<<< HEAD
790 return GetLandObject((int)x_float, (int)y_float, true /* returnNullIfLandObjectNotFound */); 833 return GetLandObject((int)x_float, (int)y_float, true /* returnNullIfLandObjectNotFound */);
791 /* 834 /*
792 int x; 835 int x;
@@ -812,9 +855,31 @@ namespace OpenSim.Region.CoreModules.World.Land
812 { 855 {
813 return null; 856 return null;
814 } 857 }
858=======
859 return GetLandObject((int)x_float, (int)y_float, true);
860 }
815 861
816 lock (m_landList) 862 // if x,y is off region this will return the parcel at cliped x,y
863 // as did code it replaces
864 public ILandObject GetLandObjectClipedXY(float x, float y)
865 {
866 //do clip inline
867 int avx = (int)x;
868 if (avx < 0)
869 avx = 0;
870 else if (avx >= m_scene.RegionInfo.RegionSizeX)
871 avx = (int)Constants.RegionSize - 1;
872
873 int avy = (int)y;
874 if (avy < 0)
875 avy = 0;
876 else if (avy >= m_scene.RegionInfo.RegionSizeY)
877 avy = (int)Constants.RegionSize - 1;
878>>>>>>> avn/ubitvar
879
880 lock (m_landIDList)
817 { 881 {
882<<<<<<< HEAD
818 // Corner case. If an autoreturn happens during sim startup 883 // Corner case. If an autoreturn happens during sim startup
819 // we will come here with the list uninitialized 884 // we will come here with the list uninitialized
820 // 885 //
@@ -837,6 +902,16 @@ namespace OpenSim.Region.CoreModules.World.Land
837 } 902 }
838 903
839 return null; 904 return null;
905=======
906 try
907 {
908 return m_landList[m_landIDList[avx / landUnit, avy / landUnit]];
909 }
910 catch (IndexOutOfRangeException)
911 {
912 return null;
913 }
914>>>>>>> avn/ubitvar
840 } 915 }
841 */ 916 */
842 } 917 }
@@ -848,6 +923,7 @@ namespace OpenSim.Region.CoreModules.World.Land
848 return GetLandObject(x, y, false /* returnNullIfLandObjectNotFound */); 923 return GetLandObject(x, y, false /* returnNullIfLandObjectNotFound */);
849 } 924 }
850 925
926<<<<<<< HEAD
851 /// <summary> 927 /// <summary>
852 /// Given a region position, return the parcel land object for that location 928 /// Given a region position, return the parcel land object for that location
853 /// </summary> 929 /// </summary>
@@ -862,16 +938,37 @@ namespace OpenSim.Region.CoreModules.World.Land
862 private ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectOutsideBounds) 938 private ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectOutsideBounds)
863 { 939 {
864 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0) 940 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
941=======
942 public ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectOutsideBounds)
943 {
944 if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
945>>>>>>> avn/ubitvar
865 { 946 {
866 // These exceptions here will cause a lot of complaints from the users specifically because 947 // These exceptions here will cause a lot of complaints from the users specifically because
867 // they happen every time at border crossings 948 // they happen every time at border crossings
868 if (returnNullIfLandObjectOutsideBounds) 949 if (returnNullIfLandObjectOutsideBounds)
869 return null; 950 return null;
870 else 951 else
952<<<<<<< HEAD
871 throw new Exception( 953 throw new Exception(
872 String.Format("{0} GetLandObject for non-existent position. Region={1}, pos=<{2},{3}", 954 String.Format("{0} GetLandObject for non-existent position. Region={1}, pos=<{2},{3}",
873 LogHeader, m_scene.RegionInfo.RegionName, x, y) 955 LogHeader, m_scene.RegionInfo.RegionName, x, y)
874 ); 956 );
957=======
958 throw new Exception("Error: Parcel not found at point " + x + ", " + y);
959 }
960
961 lock (m_landIDList)
962 {
963 try
964 {
965 return m_landList[m_landIDList[x / 4, y / 4]];
966 }
967 catch (IndexOutOfRangeException)
968 {
969 return null;
970 }
971>>>>>>> avn/ubitvar
875 } 972 }
876 973
877 return m_landList[m_landIDList[x / 4, y / 4]]; 974 return m_landList[m_landIDList[x / 4, y / 4]];
@@ -890,6 +987,19 @@ namespace OpenSim.Region.CoreModules.World.Land
890 return ret; 987 return ret;
891 } 988 }
892 989
990 // Create a 'parcel is here' bitmap for the parcel identified by the passed landID
991 private bool[,] CreateBitmapForID(int landID)
992 {
993 bool[,] ret = new bool[m_landIDList.GetLength(0), m_landIDList.GetLength(1)];
994
995 for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
996 for (int yy = 0; yy < m_landIDList.GetLength(0); yy++)
997 if (m_landIDList[xx, yy] == landID)
998 ret[xx, yy] = true;
999
1000 return ret;
1001 }
1002
893 #endregion 1003 #endregion
894 1004
895 #region Parcel Modification 1005 #region Parcel Modification
@@ -1033,7 +1143,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1033 1143
1034 //If we are still here, then they are subdividing within one piece of land 1144 //If we are still here, then they are subdividing within one piece of land
1035 //Check owner 1145 //Check owner
1036 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin)) 1146 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin, true))
1037 { 1147 {
1038 return; 1148 return;
1039 } 1149 }
@@ -1043,6 +1153,8 @@ namespace OpenSim.Region.CoreModules.World.Land
1043 newLand.LandData.Name = newLand.LandData.Name; 1153 newLand.LandData.Name = newLand.LandData.Name;
1044 newLand.LandData.GlobalID = UUID.Random(); 1154 newLand.LandData.GlobalID = UUID.Random();
1045 newLand.LandData.Dwell = 0; 1155 newLand.LandData.Dwell = 0;
1156 // Clear "Show in search" on the cut out parcel to prevent double-charging
1157 newLand.LandData.Flags &= ~(uint)ParcelFlags.ShowDirectory;
1046 1158
1047 newLand.SetLandBitmap(newLand.GetSquareLandBitmap(start_x, start_y, end_x, end_y)); 1159 newLand.SetLandBitmap(newLand.GetSquareLandBitmap(start_x, start_y, end_x, end_y));
1048 1160
@@ -1057,12 +1169,19 @@ namespace OpenSim.Region.CoreModules.World.Land
1057 1169
1058 //Now add the new land object 1170 //Now add the new land object
1059 ILandObject result = AddLandObject(newLand); 1171 ILandObject result = AddLandObject(newLand);
1172<<<<<<< HEAD
1060 1173
1061 if (result != null) 1174 if (result != null)
1062 { 1175 {
1063 UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData); 1176 UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData);
1064 result.SendLandUpdateToAvatarsOverMe(); 1177 result.SendLandUpdateToAvatarsOverMe();
1065 } 1178 }
1179=======
1180 UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData);
1181 result.SendLandUpdateToAvatarsOverMe();
1182 startLandObject.SendLandUpdateToAvatarsOverMe();
1183 m_scene.ForEachClient(SendParcelOverlay);
1184>>>>>>> avn/ubitvar
1066 } 1185 }
1067 1186
1068 /// <summary> 1187 /// <summary>
@@ -1104,7 +1223,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1104 { 1223 {
1105 return; 1224 return;
1106 } 1225 }
1107 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, masterLandObject, GroupPowers.LandDivideJoin)) 1226 if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, masterLandObject, GroupPowers.LandDivideJoin, true))
1108 { 1227 {
1109 return; 1228 return;
1110 } 1229 }
@@ -1127,6 +1246,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1127 } 1246 }
1128 1247
1129 masterLandObject.SendLandUpdateToAvatarsOverMe(); 1248 masterLandObject.SendLandUpdateToAvatarsOverMe();
1249 m_scene.ForEachClient(SendParcelOverlay);
1130 } 1250 }
1131 1251
1132 public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id) 1252 public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
@@ -1143,11 +1263,14 @@ namespace OpenSim.Region.CoreModules.World.Land
1143 1263
1144 #region Parcel Updating 1264 #region Parcel Updating
1145 1265
1266<<<<<<< HEAD
1146 // Send parcel layer info for the whole region 1267 // Send parcel layer info for the whole region
1147 public void SendParcelOverlay(IClientAPI remote_client) 1268 public void SendParcelOverlay(IClientAPI remote_client)
1148 { 1269 {
1149 SendParcelOverlay(remote_client, 0, 0, (int)Constants.MaximumRegionSize); 1270 SendParcelOverlay(remote_client, 0, 0, (int)Constants.MaximumRegionSize);
1150 } 1271 }
1272=======
1273>>>>>>> avn/ubitvar
1151 1274
1152 /// <summary> 1275 /// <summary>
1153 /// Send the parcel overlay blocks to the client. We send the overlay packets 1276 /// Send the parcel overlay blocks to the client. We send the overlay packets
@@ -1164,11 +1287,15 @@ namespace OpenSim.Region.CoreModules.World.Land
1164 /// <param name="layerViewDistance">Distance from x,y position to send parcel layer info</param> 1287 /// <param name="layerViewDistance">Distance from x,y position to send parcel layer info</param>
1165 private void SendParcelOverlay(IClientAPI remote_client, int xPlace, int yPlace, int layerViewDistance) 1288 private void SendParcelOverlay(IClientAPI remote_client, int xPlace, int yPlace, int layerViewDistance)
1166 { 1289 {
1290 if (remote_client.SceneAgent.PresenceType == PresenceType.Npc)
1291 return;
1292
1167 const int LAND_BLOCKS_PER_PACKET = 1024; 1293 const int LAND_BLOCKS_PER_PACKET = 1024;
1168 1294
1169 byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET]; 1295 byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1170 int byteArrayCount = 0; 1296 int byteArrayCount = 0;
1171 int sequenceID = 0; 1297 int sequenceID = 0;
1298<<<<<<< HEAD
1172 1299
1173 int xLow = 0; 1300 int xLow = 0;
1174 int xHigh = (int)m_scene.RegionInfo.RegionSizeX; 1301 int xHigh = (int)m_scene.RegionInfo.RegionSizeX;
@@ -1182,6 +1309,13 @@ namespace OpenSim.Region.CoreModules.World.Land
1182 int txHigh = xPlace + layerViewDistance; 1309 int txHigh = xPlace + layerViewDistance;
1183 // If the distance is outside the region area, move the view distance to ba all in the region 1310 // If the distance is outside the region area, move the view distance to ba all in the region
1184 if (txLow < xLow) 1311 if (txLow < xLow)
1312=======
1313
1314 // Layer data is in landUnit (4m) chunks
1315 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y += landUnit)
1316 {
1317 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x += landUnit)
1318>>>>>>> avn/ubitvar
1185 { 1319 {
1186 txLow = xLow; 1320 txLow = xLow;
1187 txHigh = Math.Min(yLow + (layerViewDistance * 2), xHigh); 1321 txHigh = Math.Min(yLow + (layerViewDistance * 2), xHigh);
@@ -1194,6 +1328,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1194 xLow = txLow; 1328 xLow = txLow;
1195 xHigh = txHigh; 1329 xHigh = txHigh;
1196 1330
1331<<<<<<< HEAD
1197 int tyLow = yPlace - layerViewDistance; 1332 int tyLow = yPlace - layerViewDistance;
1198 int tyHigh = yPlace + layerViewDistance; 1333 int tyHigh = yPlace + layerViewDistance;
1199 if (tyLow < yLow) 1334 if (tyLow < yLow)
@@ -1211,6 +1346,9 @@ namespace OpenSim.Region.CoreModules.World.Land
1211 } 1346 }
1212 // m_log.DebugFormat("{0} SendParcelOverlay: place=<{1},{2}>, vDist={3}, xLH=<{4},{5}, yLH=<{6},{7}>", 1347 // m_log.DebugFormat("{0} SendParcelOverlay: place=<{1},{2}>, vDist={3}, xLH=<{4},{5}, yLH=<{6},{7}>",
1213 // LogHeader, xPlace, yPlace, layerViewDistance, xLow, xHigh, yLow, yHigh); 1348 // LogHeader, xPlace, yPlace, layerViewDistance, xLow, xHigh, yLow, yHigh);
1349=======
1350 ILandObject currentParcelBlock = GetLandObject(x, y);
1351>>>>>>> avn/ubitvar
1214 1352
1215 // Layer data is in landUnit (4m) chunks 1353 // Layer data is in landUnit (4m) chunks
1216 for (int y = yLow; y < yHigh / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++) 1354 for (int y = yLow; y < yHigh / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
@@ -1221,6 +1359,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1221 byteArrayCount++; 1359 byteArrayCount++;
1222 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET) 1360 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
1223 { 1361 {
1362<<<<<<< HEAD
1224 // m_log.DebugFormat("{0} SendParcelOverlay, sending packet, bytes={1}", LogHeader, byteArray.Length); 1363 // m_log.DebugFormat("{0} SendParcelOverlay, sending packet, bytes={1}", LogHeader, byteArray.Length);
1225 remote_client.SendLandParcelOverlay(byteArray, sequenceID); 1364 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1226 byteArrayCount = 0; 1365 byteArrayCount = 0;
@@ -1298,6 +1437,95 @@ namespace OpenSim.Region.CoreModules.World.Land
1298 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH); 1437 tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
1299 } 1438 }
1300 1439
1440=======
1441 // types
1442 if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId)
1443 {
1444 //Owner Flag
1445 tempByte = (byte)LandChannel.LAND_TYPE_OWNED_BY_REQUESTER;
1446 }
1447 else if (currentParcelBlock.LandData.IsGroupOwned && remote_client.IsGroupMember(currentParcelBlock.LandData.GroupID))
1448 {
1449 tempByte = (byte)LandChannel.LAND_TYPE_OWNED_BY_GROUP;
1450 }
1451 else if (currentParcelBlock.LandData.SalePrice > 0 &&
1452 (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
1453 currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
1454 {
1455 //Sale type
1456 tempByte = (byte)LandChannel.LAND_TYPE_IS_FOR_SALE;
1457 }
1458 else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
1459 {
1460 //Public type
1461 tempByte = (byte)LandChannel.LAND_TYPE_PUBLIC; // this does nothing, its zero
1462 }
1463 // LAND_TYPE_IS_BEING_AUCTIONED still unsuported
1464 else
1465 {
1466 //Other Flag
1467 tempByte = (byte)LandChannel.LAND_TYPE_OWNED_BY_OTHER;
1468 }
1469
1470 // now flags
1471 // border control
1472
1473 ILandObject westParcel = null;
1474 ILandObject southParcel = null;
1475 if (x > 0)
1476 {
1477 westParcel = GetLandObject((x - 1), y);
1478 }
1479 if (y > 0)
1480 {
1481 southParcel = GetLandObject(x, (y - 1));
1482 }
1483
1484 if (x == 0)
1485 {
1486 tempByte |= (byte)LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST;
1487 }
1488 else if (westParcel != null && westParcel != currentParcelBlock)
1489 {
1490 tempByte |= (byte)LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST;
1491 }
1492
1493 if (y == 0)
1494 {
1495 tempByte |= (byte)LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH;
1496 }
1497 else if (southParcel != null && southParcel != currentParcelBlock)
1498 {
1499 tempByte |= (byte)LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH;
1500 }
1501
1502 // local sound
1503 if ((currentParcelBlock.LandData.Flags & (uint)ParcelFlags.SoundLocal) != 0)
1504 tempByte |= (byte)LandChannel.LAND_FLAG_LOCALSOUND;
1505
1506 // hide avatars
1507 if (!currentParcelBlock.LandData.SeeAVs)
1508 tempByte |= (byte)LandChannel.LAND_FLAG_HIDEAVATARS;
1509
1510
1511 byteArray[byteArrayCount] = tempByte;
1512 byteArrayCount++;
1513 if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
1514 {
1515 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1516 byteArrayCount = 0;
1517 sequenceID++;
1518 byteArray = new byte[LAND_BLOCKS_PER_PACKET];
1519 }
1520 }
1521 }
1522
1523 }
1524
1525 if (byteArrayCount > 0)
1526 {
1527 remote_client.SendLandParcelOverlay(byteArray, sequenceID);
1528>>>>>>> avn/ubitvar
1301 } 1529 }
1302 1530
1303 return tempByte; 1531 return tempByte;
@@ -1320,8 +1548,11 @@ namespace OpenSim.Region.CoreModules.World.Land
1320 { 1548 {
1321 if (!temp.Contains(currentParcel)) 1549 if (!temp.Contains(currentParcel))
1322 { 1550 {
1323 currentParcel.ForceUpdateLandInfo(); 1551 if (!currentParcel.IsEitherBannedOrRestricted(remote_client.AgentId))
1324 temp.Add(currentParcel); 1552 {
1553 currentParcel.ForceUpdateLandInfo();
1554 temp.Add(currentParcel);
1555 }
1325 } 1556 }
1326 } 1557 }
1327 } 1558 }
@@ -1338,8 +1569,50 @@ namespace OpenSim.Region.CoreModules.World.Land
1338 temp[i].SendLandProperties(sequence_id, snap_selection, requestResult, remote_client); 1569 temp[i].SendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
1339 } 1570 }
1340 1571
1572<<<<<<< HEAD
1341 // Also send the layer data around the point of interest 1573 // Also send the layer data around the point of interest
1342 SendParcelOverlay(remote_client, (start_x + end_x) / 2, (start_y + end_y) / 2, parcelLayerViewDistance); 1574 SendParcelOverlay(remote_client, (start_x + end_x) / 2, (start_y + end_y) / 2, parcelLayerViewDistance);
1575=======
1576// SendParcelOverlay(remote_client);
1577 }
1578
1579 public void UpdateLandProperties(ILandObject land, LandUpdateArgs args, IClientAPI remote_client)
1580 {
1581 bool snap_selection = false;
1582 bool needOverlay = false;
1583 if (land.UpdateLandProperties(args, remote_client, out snap_selection, out needOverlay))
1584 {
1585 //the proprieties to who changed them
1586 ScenePresence av = m_scene.GetScenePresence(remote_client.AgentId);
1587 if(av.IsChildAgent || land != GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y))
1588 land.SendLandProperties(-10000, false, LandChannel.LAND_RESULT_SINGLE, remote_client);
1589 else
1590 land.SendLandProperties(0, false, LandChannel.LAND_RESULT_SINGLE, remote_client);
1591
1592 UUID parcelID = land.LandData.GlobalID;
1593 m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
1594 {
1595 if (avatar.IsDeleted || avatar.isNPC)
1596 return;
1597
1598 IClientAPI client = avatar.ControllingClient;
1599 if (needOverlay)
1600 SendParcelOverlay(client);
1601
1602 if (avatar.IsChildAgent)
1603 return;
1604
1605 ILandObject aland = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
1606 if (aland != null)
1607 {
1608 if (client != remote_client && land == aland)
1609 aland.SendLandProperties(0, false, LandChannel.LAND_RESULT_SINGLE, client);
1610 }
1611 if (avatar.currentParcelUUID == parcelID)
1612 avatar.currentParcelUUID = parcelID; // force parcel flags review
1613 });
1614 }
1615>>>>>>> avn/ubitvar
1343 } 1616 }
1344 1617
1345 public void ClientOnParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client) 1618 public void ClientOnParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
@@ -1352,7 +1625,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1352 1625
1353 if (land != null) 1626 if (land != null)
1354 { 1627 {
1355 land.UpdateLandProperties(args, remote_client); 1628 UpdateLandProperties(land, args, remote_client);
1356 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client); 1629 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client);
1357 } 1630 }
1358 } 1631 }
@@ -1408,7 +1681,6 @@ namespace OpenSim.Region.CoreModules.World.Land
1408 land.LandData.GroupID = UUID.Zero; 1681 land.LandData.GroupID = UUID.Zero;
1409 land.LandData.IsGroupOwned = false; 1682 land.LandData.IsGroupOwned = false;
1410 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); 1683 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
1411
1412 m_scene.ForEachClient(SendParcelOverlay); 1684 m_scene.ForEachClient(SendParcelOverlay);
1413 land.SendLandUpdateToClient(true, remote_client); 1685 land.SendLandUpdateToClient(true, remote_client);
1414 UpdateLandObject(land.LandData.LocalID, land.LandData); 1686 UpdateLandObject(land.LandData.LocalID, land.LandData);
@@ -1459,7 +1731,6 @@ namespace OpenSim.Region.CoreModules.World.Land
1459 land.LandData.SalePrice = 0; 1731 land.LandData.SalePrice = 0;
1460 land.LandData.AuthBuyerID = UUID.Zero; 1732 land.LandData.AuthBuyerID = UUID.Zero;
1461 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); 1733 land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
1462
1463 m_scene.ForEachClient(SendParcelOverlay); 1734 m_scene.ForEachClient(SendParcelOverlay);
1464 land.SendLandUpdateToClient(true, remote_client); 1735 land.SendLandUpdateToClient(true, remote_client);
1465 UpdateLandObject(land.LandData.LocalID, land.LandData); 1736 UpdateLandObject(land.LandData.LocalID, land.LandData);
@@ -1545,9 +1816,12 @@ namespace OpenSim.Region.CoreModules.World.Land
1545 1816
1546 private void EventManagerOnIncomingLandDataFromStorage(List<LandData> data) 1817 private void EventManagerOnIncomingLandDataFromStorage(List<LandData> data)
1547 { 1818 {
1548// m_log.DebugFormat( 1819 lock (m_landList)
1549// "[LAND MANAGMENT MODULE]: Processing {0} incoming parcels on {1}", data.Count, m_scene.Name); 1820 {
1821 for (int i = 0; i < data.Count; i++)
1822 IncomingLandObjectFromStorage(data[i]);
1550 1823
1824<<<<<<< HEAD
1551 // Prevent race conditions from any auto-creation of new parcels for varregions whilst we are still loading 1825 // Prevent race conditions from any auto-creation of new parcels for varregions whilst we are still loading
1552 // the existing parcels. 1826 // the existing parcels.
1553 lock (m_landList) 1827 lock (m_landList)
@@ -1559,13 +1833,23 @@ namespace OpenSim.Region.CoreModules.World.Land
1559 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++) 1833 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
1560 { 1834 {
1561 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++) 1835 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++)
1836=======
1837 // Layer data is in landUnit (4m) chunks
1838 for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / landUnit); y++)
1839 {
1840 for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / landUnit); x++)
1841>>>>>>> avn/ubitvar
1562 { 1842 {
1563 if (m_landIDList[x, y] == 0) 1843 if (m_landIDList[x, y] == 0)
1564 { 1844 {
1565 if (m_landList.Count == 1) 1845 if (m_landList.Count == 1)
1566 { 1846 {
1567 m_log.DebugFormat( 1847 m_log.DebugFormat(
1848<<<<<<< HEAD
1568 "[{0}]: Auto-extending land parcel as landID at {1},{2} is 0 and only one land parcel is present in {3}", 1849 "[{0}]: Auto-extending land parcel as landID at {1},{2} is 0 and only one land parcel is present in {3}",
1850=======
1851 "[{0}]: Auto-extending land parcel as landID at {1},{2} is 0 and only one land parcel is present in {3}",
1852>>>>>>> avn/ubitvar
1569 LogHeader, x, y, m_scene.Name); 1853 LogHeader, x, y, m_scene.Name);
1570 1854
1571 int onlyParcelID = 0; 1855 int onlyParcelID = 0;
@@ -1588,11 +1872,19 @@ namespace OpenSim.Region.CoreModules.World.Land
1588 else if (m_landList.Count > 1) 1872 else if (m_landList.Count > 1)
1589 { 1873 {
1590 m_log.DebugFormat( 1874 m_log.DebugFormat(
1875<<<<<<< HEAD
1591 "{0}: Auto-creating land parcel as landID at {1},{2} is 0 and more than one land parcel is present in {3}", 1876 "{0}: Auto-creating land parcel as landID at {1},{2} is 0 and more than one land parcel is present in {3}",
1592 LogHeader, x, y, m_scene.Name); 1877 LogHeader, x, y, m_scene.Name);
1593 1878
1594 // There are several other parcels so we must create a new one for the unassigned space 1879 // There are several other parcels so we must create a new one for the unassigned space
1595 ILandObject newLand = new LandObject(UUID.Zero, false, m_scene); 1880 ILandObject newLand = new LandObject(UUID.Zero, false, m_scene);
1881=======
1882 "{0}: Auto-creating land parcel as landID at {1},{2} is 0 and more than one land parcel is present in {3}",
1883 LogHeader, x, y, m_scene.Name);
1884
1885 // There are several other parcels so we must create a new one for the unassigned space
1886 ILandObject newLand = new LandObject(UUID.Zero, false, m_scene);
1887>>>>>>> avn/ubitvar
1596 // Claim all the unclaimed "0" ids 1888 // Claim all the unclaimed "0" ids
1597 newLand.SetLandBitmap(CreateBitmapForID(0)); 1889 newLand.SetLandBitmap(CreateBitmapForID(0));
1598 newLand.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; 1890 newLand.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
@@ -1603,7 +1895,11 @@ namespace OpenSim.Region.CoreModules.World.Land
1603 { 1895 {
1604 // We should never reach this point as the separate code path when no land data exists should have fired instead. 1896 // We should never reach this point as the separate code path when no land data exists should have fired instead.
1605 m_log.WarnFormat( 1897 m_log.WarnFormat(
1898<<<<<<< HEAD
1606 "{0}: Ignoring request to auto-create parcel in {1} as there are no other parcels present", 1899 "{0}: Ignoring request to auto-create parcel in {1} as there are no other parcels present",
1900=======
1901 "{0}: Ignoring request to auto-create parcel in {1} as there are no other parcels present",
1902>>>>>>> avn/ubitvar
1607 LogHeader, m_scene.Name); 1903 LogHeader, m_scene.Name);
1608 } 1904 }
1609 } 1905 }
@@ -1614,9 +1910,16 @@ namespace OpenSim.Region.CoreModules.World.Land
1614 1910
1615 private void IncomingLandObjectFromStorage(LandData data) 1911 private void IncomingLandObjectFromStorage(LandData data)
1616 { 1912 {
1913<<<<<<< HEAD
1617 ILandObject new_land = new LandObject(data, m_scene); 1914 ILandObject new_land = new LandObject(data, m_scene);
1915=======
1916
1917 ILandObject new_land = new LandObject(data.OwnerID, data.IsGroupOwned, m_scene);
1918 new_land.LandData = data.Copy();
1919>>>>>>> avn/ubitvar
1618 new_land.SetLandBitmapFromByteArray(); 1920 new_land.SetLandBitmapFromByteArray();
1619 AddLandObject(new_land); 1921 AddLandObject(new_land);
1922// new_land.SendLandUpdateToAvatarsOverMe();
1620 } 1923 }
1621 1924
1622 public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient) 1925 public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient)
@@ -1773,6 +2076,19 @@ namespace OpenSim.Region.CoreModules.World.Land
1773 land_update.ObscureMusic = properties.ObscureMusic; 2076 land_update.ObscureMusic = properties.ObscureMusic;
1774 land_update.ObscureMedia = properties.ObscureMedia; 2077 land_update.ObscureMedia = properties.ObscureMedia;
1775 2078
2079 if (args.ContainsKey("see_avs"))
2080 {
2081 land_update.SeeAVs = args["see_avs"].AsBoolean();
2082 land_update.AnyAVSounds = args["any_av_sounds"].AsBoolean();
2083 land_update.GroupAVSounds = args["group_av_sounds"].AsBoolean();
2084 }
2085 else
2086 {
2087 land_update.SeeAVs = true;
2088 land_update.AnyAVSounds = true;
2089 land_update.GroupAVSounds = true;
2090 }
2091
1776 ILandObject land; 2092 ILandObject land;
1777 lock (m_landList) 2093 lock (m_landList)
1778 { 2094 {
@@ -1781,13 +2097,14 @@ namespace OpenSim.Region.CoreModules.World.Land
1781 2097
1782 if (land != null) 2098 if (land != null)
1783 { 2099 {
1784 land.UpdateLandProperties(land_update, client); 2100 UpdateLandProperties(land,land_update, client);
1785 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(land_update, parcelID, client); 2101 m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(land_update, parcelID, client);
1786 } 2102 }
1787 else 2103 else
1788 { 2104 {
1789 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID); 2105 m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID);
1790 } 2106 }
2107
1791 return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty()); 2108 return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
1792 } 2109 }
1793 // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the 2110 // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the
@@ -1940,14 +2257,93 @@ namespace OpenSim.Region.CoreModules.World.Land
1940 2257
1941 if (land == null) return; 2258 if (land == null) return;
1942 2259
1943 if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions)) 2260 if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions, false))
1944 return; 2261 return;
1945 2262
1946 land.LandData.OtherCleanTime = otherCleanTime; 2263 land.LandData.OtherCleanTime = otherCleanTime;
1947 2264
1948 UpdateLandObject(localID, land.LandData); 2265 UpdateLandObject(localID, land.LandData);
1949 } 2266 }
1950 2267
2268 public void ClientOnParcelGodMark(IClientAPI client, UUID god, int landID)
2269 {
2270 ILandObject land = null;
2271 List<ILandObject> Land = ((Scene)client.Scene).LandChannel.AllParcels();
2272 foreach (ILandObject landObject in Land)
2273 {
2274 if (landObject.LandData.LocalID == landID)
2275 {
2276 land = landObject;
2277 }
2278 }
2279 land.DeedToGroup(DefaultGodParcelGroup);
2280 land.LandData.Name = DefaultGodParcelName;
2281 land.SendLandUpdateToAvatarsOverMe();
2282 }
2283
2284 private void ClientOnSimWideDeletes(IClientAPI client, UUID agentID, int flags, UUID targetID)
2285 {
2286 ScenePresence SP;
2287 ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out SP);
2288 List<SceneObjectGroup> returns = new List<SceneObjectGroup>();
2289 if (SP.UserLevel != 0)
2290 {
2291 if (flags == 0) //All parcels, scripted or not
2292 {
2293 ((Scene)client.Scene).ForEachSOG(delegate(SceneObjectGroup e)
2294 {
2295 if (e.OwnerID == targetID)
2296 {
2297 returns.Add(e);
2298 }
2299 }
2300 );
2301 }
2302 if (flags == 4) //All parcels, scripted object
2303 {
2304 ((Scene)client.Scene).ForEachSOG(delegate(SceneObjectGroup e)
2305 {
2306 if (e.OwnerID == targetID)
2307 {
2308 if (e.ContainsScripts())
2309 {
2310 returns.Add(e);
2311 }
2312 }
2313 }
2314 );
2315 }
2316 if (flags == 4) //not target parcel, scripted object
2317 {
2318 ((Scene)client.Scene).ForEachSOG(delegate(SceneObjectGroup e)
2319 {
2320 if (e.OwnerID == targetID)
2321 {
2322 ILandObject landobject = ((Scene)client.Scene).LandChannel.GetLandObject(e.AbsolutePosition.X, e.AbsolutePosition.Y);
2323 if (landobject.LandData.OwnerID != e.OwnerID)
2324 {
2325 if (e.ContainsScripts())
2326 {
2327 returns.Add(e);
2328 }
2329 }
2330 }
2331 }
2332 );
2333 }
2334 foreach (SceneObjectGroup ol in returns)
2335 {
2336 ReturnObject(ol, client);
2337 }
2338 }
2339 }
2340 public void ReturnObject(SceneObjectGroup obj, IClientAPI client)
2341 {
2342 SceneObjectGroup[] objs = new SceneObjectGroup[1];
2343 objs[0] = obj;
2344 ((Scene)client.Scene).returnObjects(objs, client.AgentId);
2345 }
2346
1951 Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>(); 2347 Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>();
1952 2348
1953 public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) 2349 public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
@@ -1961,7 +2357,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1961 if (targetAvatar.UserLevel == 0) 2357 if (targetAvatar.UserLevel == 0)
1962 { 2358 {
1963 ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y); 2359 ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
1964 if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze)) 2360 if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze, true))
1965 return; 2361 return;
1966 if (flags == 0) 2362 if (flags == 0)
1967 { 2363 {
@@ -1983,7 +2379,6 @@ namespace OpenSim.Region.CoreModules.World.Land
1983 } 2379 }
1984 } 2380 }
1985 } 2381 }
1986
1987 private void OnEndParcelFrozen(object avatar) 2382 private void OnEndParcelFrozen(object avatar)
1988 { 2383 {
1989 ScenePresence targetAvatar = (ScenePresence)avatar; 2384 ScenePresence targetAvatar = (ScenePresence)avatar;
@@ -1994,6 +2389,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1994 targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false); 2389 targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false);
1995 } 2390 }
1996 2391
2392
1997 public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) 2393 public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
1998 { 2394 {
1999 ScenePresence targetAvatar = null; 2395 ScenePresence targetAvatar = null;
@@ -2010,15 +2406,16 @@ namespace OpenSim.Region.CoreModules.World.Land
2010 2406
2011 // Check if you even have permission to do this 2407 // Check if you even have permission to do this
2012 ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y); 2408 ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
2013 if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) && 2409 if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze, true) &&
2014 !m_scene.Permissions.IsAdministrator(client.AgentId)) 2410 !m_scene.Permissions.IsAdministrator(client.AgentId))
2015 return; 2411 return;
2412
2016 Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land); 2413 Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
2017 2414
2018 targetAvatar.TeleportWithMomentum(pos, null); 2415 targetAvatar.TeleportWithMomentum(pos, null);
2019 targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname); 2416 targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
2020 parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected."); 2417 parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
2021 2418
2022 if ((flags & 1) != 0) // Ban TODO: Remove magic number 2419 if ((flags & 1) != 0) // Ban TODO: Remove magic number
2023 { 2420 {
2024 LandAccessEntry entry = new LandAccessEntry(); 2421 LandAccessEntry entry = new LandAccessEntry();
@@ -2171,6 +2568,7 @@ namespace OpenSim.Region.CoreModules.World.Land
2171 2568
2172 private void AppendParcelsSummaryReport(StringBuilder report) 2569 private void AppendParcelsSummaryReport(StringBuilder report)
2173 { 2570 {
2571<<<<<<< HEAD
2174 report.AppendFormat("Land information for {0}\n", m_scene.Name); 2572 report.AppendFormat("Land information for {0}\n", m_scene.Name);
2175 2573
2176 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 2574 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
@@ -2180,12 +2578,24 @@ namespace OpenSim.Region.CoreModules.World.Land
2180 cdt.AddColumn("Starts", ConsoleDisplayUtil.VectorSize); 2578 cdt.AddColumn("Starts", ConsoleDisplayUtil.VectorSize);
2181 cdt.AddColumn("Ends", ConsoleDisplayUtil.VectorSize); 2579 cdt.AddColumn("Ends", ConsoleDisplayUtil.VectorSize);
2182 cdt.AddColumn("Owner", ConsoleDisplayUtil.UserNameSize); 2580 cdt.AddColumn("Owner", ConsoleDisplayUtil.UserNameSize);
2581=======
2582 report.AppendFormat("Land information for {0}\n", m_scene.RegionInfo.RegionName);
2583 report.AppendFormat(
2584 "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n",
2585 "Parcel Name",
2586 "Local ID",
2587 "Area",
2588 "AABBMin",
2589 "AABBMax",
2590 "Owner");
2591>>>>>>> avn/ubitvar
2183 2592
2184 lock (m_landList) 2593 lock (m_landList)
2185 { 2594 {
2186 foreach (ILandObject lo in m_landList.Values) 2595 foreach (ILandObject lo in m_landList.Values)
2187 { 2596 {
2188 LandData ld = lo.LandData; 2597 LandData ld = lo.LandData;
2598<<<<<<< HEAD
2189 string ownerName; 2599 string ownerName;
2190 if (ld.IsGroupOwned) 2600 if (ld.IsGroupOwned)
2191 { 2601 {
@@ -2198,6 +2608,35 @@ namespace OpenSim.Region.CoreModules.World.Land
2198 } 2608 }
2199 cdt.AddRow( 2609 cdt.AddRow(
2200 ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, ownerName); 2610 ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, ownerName);
2611=======
2612
2613 report.AppendFormat(
2614 "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n",
2615 ld.Name, ld.LocalID, ld.Area, ld.AABBMin, ld.AABBMax, m_userManager.GetUserName(ld.OwnerID));
2616 }
2617 }
2618
2619 }
2620
2621 public void EnforceBans(ILandObject land, ScenePresence avatar)
2622 {
2623 if (avatar.AbsolutePosition.Z > LandChannel.BAN_LINE_SAFETY_HIEGHT)
2624 return;
2625
2626 if (land.IsEitherBannedOrRestricted(avatar.UUID))
2627 {
2628 if (land.ContainsPoint(Convert.ToInt32(avatar.lastKnownAllowedPosition.X), Convert.ToInt32(avatar.lastKnownAllowedPosition.Y)))
2629 {
2630 Vector3? pos = m_scene.GetNearestAllowedPosition(avatar);
2631 if (pos == null)
2632 m_scene.TeleportClientHome(avatar.UUID, avatar.ControllingClient);
2633 else
2634 ForceAvatarToPosition(avatar, (Vector3)pos);
2635 }
2636 else
2637 {
2638 ForceAvatarToPosition(avatar, avatar.lastKnownAllowedPosition);
2639>>>>>>> avn/ubitvar
2201 } 2640 }
2202 } 2641 }
2203 2642
@@ -2214,8 +2653,6 @@ namespace OpenSim.Region.CoreModules.World.Land
2214 cdl.AddRow("Description", ld.Description); 2653 cdl.AddRow("Description", ld.Description);
2215 cdl.AddRow("Snapshot ID", ld.SnapshotID); 2654 cdl.AddRow("Snapshot ID", ld.SnapshotID);
2216 cdl.AddRow("Area", ld.Area); 2655 cdl.AddRow("Area", ld.Area);
2217 cdl.AddRow("Starts", lo.StartPoint);
2218 cdl.AddRow("Ends", lo.EndPoint);
2219 cdl.AddRow("AABB Min", ld.AABBMin); 2656 cdl.AddRow("AABB Min", ld.AABBMin);
2220 cdl.AddRow("AABB Max", ld.AABBMax); 2657 cdl.AddRow("AABB Max", ld.AABBMax);
2221 string ownerName; 2658 string ownerName;
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index a0c1b9d..3b81d6b 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -46,11 +46,20 @@ namespace OpenSim.Region.CoreModules.World.Land
46 46
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private static readonly string LogHeader = "[LAND OBJECT]"; 48 private static readonly string LogHeader = "[LAND OBJECT]";
49<<<<<<< HEAD
49 50
50 private readonly int landUnit = 4; 51 private readonly int landUnit = 4;
51 52
52 private int m_lastSeqId = 0; 53 private int m_lastSeqId = 0;
53 54
55=======
56
57 private readonly int landUnit = 4;
58
59 private int m_lastSeqId = 0;
60 private int m_expiryCounter = 0;
61
62>>>>>>> avn/ubitvar
54 protected Scene m_scene; 63 protected Scene m_scene;
55 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>(); 64 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
56 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>(); 65 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
@@ -58,7 +67,16 @@ namespace OpenSim.Region.CoreModules.World.Land
58 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>(); 67 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>();
59 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds 68 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds
60 69
70<<<<<<< HEAD
61 public bool[,] LandBitmap { get; set; } 71 public bool[,] LandBitmap { get; set; }
72=======
73 private bool[,] m_landBitmap;
74 public bool[,] LandBitmap
75 {
76 get { return m_landBitmap; }
77 set { m_landBitmap = value; }
78 }
79>>>>>>> avn/ubitvar
62 80
63 #endregion 81 #endregion
64 82
@@ -69,7 +87,17 @@ namespace OpenSim.Region.CoreModules.World.Land
69 return free; 87 return free;
70 } 88 }
71 89
90<<<<<<< HEAD
72 public LandData LandData { get; set; } 91 public LandData LandData { get; set; }
92=======
93 protected LandData m_landData;
94 public LandData LandData
95 {
96 get { return m_landData; }
97
98 set { m_landData = value; }
99 }
100>>>>>>> avn/ubitvar
73 101
74 public IPrimCounts PrimCounts { get; set; } 102 public IPrimCounts PrimCounts { get; set; }
75 103
@@ -141,6 +169,8 @@ namespace OpenSim.Region.CoreModules.World.Land
141 else 169 else
142 LandData.GroupID = UUID.Zero; 170 LandData.GroupID = UUID.Zero;
143 LandData.IsGroupOwned = is_group_owned; 171 LandData.IsGroupOwned = is_group_owned;
172
173 m_scene.EventManager.OnFrame += OnFrame;
144 } 174 }
145 175
146 #endregion 176 #endregion
@@ -195,10 +225,34 @@ namespace OpenSim.Region.CoreModules.World.Land
195 else 225 else
196 { 226 {
197 // Normal Calculations 227 // Normal Calculations
228<<<<<<< HEAD
198 int parcelMax = (int)(((float)LandData.Area / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY)) 229 int parcelMax = (int)(((float)LandData.Area / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
199 * (float)m_scene.RegionInfo.ObjectCapacity 230 * (float)m_scene.RegionInfo.ObjectCapacity
200 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); 231 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
201 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL! 232 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL!
233=======
234 int parcelMax = (int)( (long)LandData.Area
235 * (long)m_scene.RegionInfo.ObjectCapacity
236 * (long)m_scene.RegionInfo.RegionSettings.ObjectBonus
237 / (long)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY) );
238 //m_log.DebugFormat("Area: {0}, Capacity {1}, Bonus {2}, Parcel {3}", LandData.Area, m_scene.RegionInfo.ObjectCapacity, m_scene.RegionInfo.RegionSettings.ObjectBonus, parcelMax);
239 return parcelMax;
240 }
241 }
242
243 private int GetParcelBasePrimCount()
244 {
245 if (overrideParcelMaxPrimCount != null)
246 {
247 return overrideParcelMaxPrimCount(this);
248 }
249 else
250 {
251 // Normal Calculations
252 int parcelMax = (int)((long)LandData.Area
253 * (long)m_scene.RegionInfo.ObjectCapacity
254 / 65536L);
255>>>>>>> avn/ubitvar
202 return parcelMax; 256 return parcelMax;
203 } 257 }
204 } 258 }
@@ -212,8 +266,15 @@ namespace OpenSim.Region.CoreModules.World.Land
212 else 266 else
213 { 267 {
214 //Normal Calculations 268 //Normal Calculations
269<<<<<<< HEAD
215 int simMax = (int)(((float)LandData.SimwideArea / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY)) 270 int simMax = (int)(((float)LandData.SimwideArea / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
216 * (float)m_scene.RegionInfo.ObjectCapacity); 271 * (float)m_scene.RegionInfo.ObjectCapacity);
272=======
273 int simMax = (int)( (long)LandData.SimwideArea
274 * (long)m_scene.RegionInfo.ObjectCapacity
275 / (long)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY) );
276 // m_log.DebugFormat("Simwide Area: {0}, Capacity {1}, SimMax {2}", LandData.SimwideArea, m_scene.RegionInfo.ObjectCapacity, simMax);
277>>>>>>> avn/ubitvar
217 return simMax; 278 return simMax;
218 } 279 }
219 } 280 }
@@ -224,6 +285,9 @@ namespace OpenSim.Region.CoreModules.World.Land
224 285
225 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client) 286 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
226 { 287 {
288 if (remote_client.SceneAgent.PresenceType == PresenceType.Npc)
289 return;
290
227 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>(); 291 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
228 // uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome)); 292 // uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
229 uint regionFlags = (uint)(RegionFlags.PublicAllowed 293 uint regionFlags = (uint)(RegionFlags.PublicAllowed
@@ -248,14 +312,15 @@ namespace OpenSim.Region.CoreModules.World.Land
248 remote_client.SendLandProperties(seq_id, 312 remote_client.SendLandProperties(seq_id,
249 snap_selection, request_result, this, 313 snap_selection, request_result, this,
250 (float)m_scene.RegionInfo.RegionSettings.ObjectBonus, 314 (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
251 GetParcelMaxPrimCount(), 315 GetParcelBasePrimCount(),
252 GetSimulatorMaxPrimCount(), regionFlags); 316 GetSimulatorMaxPrimCount(), regionFlags);
253 } 317 }
254 318
255 public void UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client) 319 public bool UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client, out bool snap_selection, out bool needOverlay)
256 { 320 {
257 //Needs later group support 321 //Needs later group support
258 bool snap_selection = false; 322 snap_selection = false;
323 needOverlay = false;
259 LandData newData = LandData.Copy(); 324 LandData newData = LandData.Copy();
260 325
261 uint allowedDelta = 0; 326 uint allowedDelta = 0;
@@ -264,7 +329,7 @@ namespace OpenSim.Region.CoreModules.World.Land
264 // ParcelFlags.ForSaleObjects 329 // ParcelFlags.ForSaleObjects
265 // ParcelFlags.LindenHome 330 // ParcelFlags.LindenHome
266 331
267 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions)) 332 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, false))
268 { 333 {
269 allowedDelta |= (uint)(ParcelFlags.AllowLandmark | 334 allowedDelta |= (uint)(ParcelFlags.AllowLandmark |
270 ParcelFlags.AllowTerraform | 335 ParcelFlags.AllowTerraform |
@@ -277,9 +342,12 @@ namespace OpenSim.Region.CoreModules.World.Land
277 ParcelFlags.AllowAPrimitiveEntry | 342 ParcelFlags.AllowAPrimitiveEntry |
278 ParcelFlags.AllowGroupObjectEntry | 343 ParcelFlags.AllowGroupObjectEntry |
279 ParcelFlags.AllowFly); 344 ParcelFlags.AllowFly);
345 newData.SeeAVs = args.SeeAVs;
346 newData.AnyAVSounds = args.AnyAVSounds;
347 newData.GroupAVSounds = args.GroupAVSounds;
280 } 348 }
281 349
282 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandSetSale)) 350 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandSetSale, true))
283 { 351 {
284 if (args.AuthBuyerID != newData.AuthBuyerID || 352 if (args.AuthBuyerID != newData.AuthBuyerID ||
285 args.SalePrice != newData.SalePrice) 353 args.SalePrice != newData.SalePrice)
@@ -302,30 +370,30 @@ namespace OpenSim.Region.CoreModules.World.Land
302 allowedDelta |= (uint)ParcelFlags.ForSale; 370 allowedDelta |= (uint)ParcelFlags.ForSale;
303 } 371 }
304 372
305 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.FindPlaces)) 373 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.FindPlaces, false))
306 { 374 {
307 newData.Category = args.Category; 375 newData.Category = args.Category;
308 376
309 allowedDelta |= (uint)(ParcelFlags.ShowDirectory | 377 allowedDelta |= (uint)(ParcelFlags.ShowDirectory |
310 ParcelFlags.AllowPublish | 378 ParcelFlags.AllowPublish |
311 ParcelFlags.MaturePublish); 379 ParcelFlags.MaturePublish) | (uint)(1 << 23);
312 } 380 }
313 381
314 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandChangeIdentity)) 382 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandChangeIdentity, false))
315 { 383 {
316 newData.Description = args.Desc; 384 newData.Description = args.Desc;
317 newData.Name = args.Name; 385 newData.Name = args.Name;
318 newData.SnapshotID = args.SnapshotID; 386 newData.SnapshotID = args.SnapshotID;
319 } 387 }
320 388
321 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.SetLandingPoint)) 389 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.SetLandingPoint, false))
322 { 390 {
323 newData.LandingType = args.LandingType; 391 newData.LandingType = args.LandingType;
324 newData.UserLocation = args.UserLocation; 392 newData.UserLocation = args.UserLocation;
325 newData.UserLookAt = args.UserLookAt; 393 newData.UserLookAt = args.UserLookAt;
326 } 394 }
327 395
328 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.ChangeMedia)) 396 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.ChangeMedia, false))
329 { 397 {
330 newData.MediaAutoScale = args.MediaAutoScale; 398 newData.MediaAutoScale = args.MediaAutoScale;
331 newData.MediaID = args.MediaID; 399 newData.MediaID = args.MediaID;
@@ -346,7 +414,7 @@ namespace OpenSim.Region.CoreModules.World.Land
346 ParcelFlags.UseEstateVoiceChan); 414 ParcelFlags.UseEstateVoiceChan);
347 } 415 }
348 416
349 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandManagePasses)) 417 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandManagePasses, false))
350 { 418 {
351 newData.PassHours = args.PassHours; 419 newData.PassHours = args.PassHours;
352 newData.PassPrice = args.PassPrice; 420 newData.PassPrice = args.PassPrice;
@@ -354,13 +422,13 @@ namespace OpenSim.Region.CoreModules.World.Land
354 allowedDelta |= (uint)ParcelFlags.UsePassList; 422 allowedDelta |= (uint)ParcelFlags.UsePassList;
355 } 423 }
356 424
357 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageAllowed)) 425 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageAllowed, false))
358 { 426 {
359 allowedDelta |= (uint)(ParcelFlags.UseAccessGroup | 427 allowedDelta |= (uint)(ParcelFlags.UseAccessGroup |
360 ParcelFlags.UseAccessList); 428 ParcelFlags.UseAccessList);
361 } 429 }
362 430
363 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageBanned)) 431 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageBanned, false))
364 { 432 {
365 allowedDelta |= (uint)(ParcelFlags.UseBanList | 433 allowedDelta |= (uint)(ParcelFlags.UseBanList |
366 ParcelFlags.DenyAnonymous | 434 ParcelFlags.DenyAnonymous |
@@ -371,10 +439,24 @@ namespace OpenSim.Region.CoreModules.World.Land
371 { 439 {
372 uint preserve = LandData.Flags & ~allowedDelta; 440 uint preserve = LandData.Flags & ~allowedDelta;
373 newData.Flags = preserve | (args.ParcelFlags & allowedDelta); 441 newData.Flags = preserve | (args.ParcelFlags & allowedDelta);
442<<<<<<< HEAD
374 443
375 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); 444 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
376 SendLandUpdateToAvatarsOverMe(snap_selection); 445 SendLandUpdateToAvatarsOverMe(snap_selection);
377 } 446 }
447=======
448
449 uint curdelta = LandData.Flags ^ newData.Flags;
450 curdelta &= (uint)(ParcelFlags.SoundLocal);
451
452 if(curdelta != 0 || newData.SeeAVs != LandData.SeeAVs)
453 needOverlay = true;
454
455 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
456 return true;
457 }
458 return false;
459>>>>>>> avn/ubitvar
378 } 460 }
379 461
380 public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area) 462 public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
@@ -395,7 +477,7 @@ namespace OpenSim.Region.CoreModules.World.Land
395 UUID previousOwner = LandData.OwnerID; 477 UUID previousOwner = LandData.OwnerID;
396 478
397 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); 479 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
398 m_scene.EventManager.TriggerParcelPrimCountUpdate(); 480// m_scene.EventManager.TriggerParcelPrimCountUpdate();
399 SendLandUpdateToAvatarsOverMe(true); 481 SendLandUpdateToAvatarsOverMe(true);
400 482
401 if (sellObjects) SellLandObjects(previousOwner); 483 if (sellObjects) SellLandObjects(previousOwner);
@@ -568,6 +650,7 @@ namespace OpenSim.Region.CoreModules.World.Land
568 650
569 public void SendLandUpdateToAvatarsOverMe(bool snap_selection) 651 public void SendLandUpdateToAvatarsOverMe(bool snap_selection)
570 { 652 {
653 m_scene.EventManager.TriggerParcelPrimCountUpdate();
571 m_scene.ForEachRootScenePresence(delegate(ScenePresence avatar) 654 m_scene.ForEachRootScenePresence(delegate(ScenePresence avatar)
572 { 655 {
573 ILandObject over = null; 656 ILandObject over = null;
@@ -594,6 +677,7 @@ namespace OpenSim.Region.CoreModules.World.Land
594 avatar.Invulnerable = true; 677 avatar.Invulnerable = true;
595 678
596 SendLandUpdateToClient(snap_selection, avatar.ControllingClient); 679 SendLandUpdateToClient(snap_selection, avatar.ControllingClient);
680 avatar.currentParcelUUID = LandData.GlobalID;
597 } 681 }
598 } 682 }
599 }); 683 });
@@ -722,10 +806,17 @@ namespace OpenSim.Region.CoreModules.World.Land
722 /// </summary> 806 /// </summary>
723 private void UpdateAABBAndAreaValues() 807 private void UpdateAABBAndAreaValues()
724 { 808 {
809<<<<<<< HEAD
725 int min_x = 10000; 810 int min_x = 10000;
726 int min_y = 10000; 811 int min_y = 10000;
727 int max_x = 0; 812 int max_x = 0;
728 int max_y = 0; 813 int max_y = 0;
814=======
815 int min_x = Int32.MaxValue;
816 int min_y = Int32.MaxValue;
817 int max_x = Int32.MinValue;
818 int max_y = Int32.MinValue;
819>>>>>>> avn/ubitvar
729 int tempArea = 0; 820 int tempArea = 0;
730 int x, y; 821 int x, y;
731 for (x = 0; x < LandBitmap.GetLength(0); x++) 822 for (x = 0; x < LandBitmap.GetLength(0); x++)
@@ -734,10 +825,21 @@ namespace OpenSim.Region.CoreModules.World.Land
734 { 825 {
735 if (LandBitmap[x, y] == true) 826 if (LandBitmap[x, y] == true)
736 { 827 {
828<<<<<<< HEAD
737 if (min_x > x) min_x = x; 829 if (min_x > x) min_x = x;
738 if (min_y > y) min_y = y; 830 if (min_y > y) min_y = y;
739 if (max_x < x) max_x = x; 831 if (max_x < x) max_x = x;
740 if (max_y < y) max_y = y; 832 if (max_y < y) max_y = y;
833=======
834 if (min_x > x)
835 min_x = x;
836 if (min_y > y)
837 min_y = y;
838 if (max_x < x)
839 max_x = x;
840 if (max_y < y)
841 max_y = y;
842>>>>>>> avn/ubitvar
741 tempArea += landUnit * landUnit; //16sqm peice of land 843 tempArea += landUnit * landUnit; //16sqm peice of land
742 } 844 }
743 } 845 }
@@ -745,6 +847,7 @@ namespace OpenSim.Region.CoreModules.World.Land
745 int tx = min_x * landUnit; 847 int tx = min_x * landUnit;
746 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1)) 848 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
747 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1); 849 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
850<<<<<<< HEAD
748 int ty = min_y * landUnit; 851 int ty = min_y * landUnit;
749 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1)) 852 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1))
750 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1); 853 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1);
@@ -763,6 +866,45 @@ namespace OpenSim.Region.CoreModules.World.Land
763 LandData.AABBMax 866 LandData.AABBMax
764 = new Vector3( 867 = new Vector3(
765 (float)(max_x * landUnit), (float)(max_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); 868 (float)(max_x * landUnit), (float)(max_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
869=======
870
871 int htx;
872 if (tx >= ((int)m_scene.RegionInfo.RegionSizeX))
873 htx = (int)m_scene.RegionInfo.RegionSizeX - 1;
874 else
875 htx = tx;
876
877 int ty = min_y * landUnit;
878 int hty;
879
880 if (ty >= ((int)m_scene.RegionInfo.RegionSizeY))
881 hty = (int)m_scene.RegionInfo.RegionSizeY - 1;
882 else
883 hty = ty;
884
885 LandData.AABBMin =
886 new Vector3(
887 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0);
888
889 max_x++;
890 tx = max_x * landUnit;
891 if (tx >= ((int)m_scene.RegionInfo.RegionSizeX))
892 htx = (int)m_scene.RegionInfo.RegionSizeX - 1;
893 else
894 htx = tx;
895
896 max_y++;
897 ty = max_y * 4;
898
899 if (ty >= ((int)m_scene.RegionInfo.RegionSizeY))
900 hty = (int)m_scene.RegionInfo.RegionSizeY - 1;
901 else
902 hty = ty;
903
904 LandData.AABBMax
905 = new Vector3(
906 (float)(tx), (float)(ty), m_scene != null ? (float)m_scene.Heightmap[htx, hty] : 0);
907>>>>>>> avn/ubitvar
766 908
767 LandData.Area = tempArea; 909 LandData.Area = tempArea;
768 } 910 }
@@ -778,7 +920,10 @@ namespace OpenSim.Region.CoreModules.World.Land
778 public void SetLandBitmap(bool[,] bitmap) 920 public void SetLandBitmap(bool[,] bitmap)
779 { 921 {
780 LandBitmap = bitmap; 922 LandBitmap = bitmap;
923<<<<<<< HEAD
781 // m_log.DebugFormat("{0} SetLandBitmap. BitmapSize=<{1},{2}>", LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1)); 924 // m_log.DebugFormat("{0} SetLandBitmap. BitmapSize=<{1},{2}>", LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
925=======
926>>>>>>> avn/ubitvar
782 ForceUpdateLandInfo(); 927 ForceUpdateLandInfo();
783 } 928 }
784 929
@@ -879,13 +1024,37 @@ namespace OpenSim.Region.CoreModules.World.Land
879 private byte[] ConvertLandBitmapToBytes() 1024 private byte[] ConvertLandBitmapToBytes()
880 { 1025 {
881 byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8]; 1026 byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
1027<<<<<<< HEAD
882 byte tempByte = 0; 1028 byte tempByte = 0;
883 int byteNum = 0; 1029 int byteNum = 0;
884 int i = 0; 1030 int i = 0;
1031=======
1032 int tempByte = 0;
1033 int i, byteNum = 0;
1034 int mask = 1;
1035 i = 0;
1036>>>>>>> avn/ubitvar
885 for (int y = 0; y < LandBitmap.GetLength(1); y++) 1037 for (int y = 0; y < LandBitmap.GetLength(1); y++)
886 { 1038 {
887 for (int x = 0; x < LandBitmap.GetLength(0); x++) 1039 for (int x = 0; x < LandBitmap.GetLength(0); x++)
888 { 1040 {
1041 if (LandBitmap[x, y])
1042 tempByte |= mask;
1043 mask = mask << 1;
1044 if (mask == 0x100)
1045 {
1046 mask = 1;
1047 tempConvertArr[byteNum++] = (byte)tempByte;
1048 tempByte = 0;
1049 }
1050 }
1051 }
1052
1053 if(tempByte != 0 && byteNum < 512)
1054 tempConvertArr[byteNum] = (byte)tempByte;
1055
1056
1057/*
889 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8)); 1058 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
890 if (i % 8 == 0) 1059 if (i % 8 == 0)
891 { 1060 {
@@ -894,10 +1063,14 @@ namespace OpenSim.Region.CoreModules.World.Land
894 i = 0; 1063 i = 0;
895 byteNum++; 1064 byteNum++;
896 } 1065 }
1066<<<<<<< HEAD
897 } 1067 }
898 } 1068 }
899 // m_log.DebugFormat("{0} ConvertLandBitmapToBytes. BitmapSize=<{1},{2}>", 1069 // m_log.DebugFormat("{0} ConvertLandBitmapToBytes. BitmapSize=<{1},{2}>",
900 // LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1)); 1070 // LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
1071=======
1072 */
1073>>>>>>> avn/ubitvar
901 return tempConvertArr; 1074 return tempConvertArr;
902 } 1075 }
903 1076
@@ -951,7 +1124,7 @@ namespace OpenSim.Region.CoreModules.World.Land
951 1124
952 public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client) 1125 public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
953 { 1126 {
954 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions)) 1127 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
955 { 1128 {
956 List<uint> resultLocalIDs = new List<uint>(); 1129 List<uint> resultLocalIDs = new List<uint>();
957 try 1130 try
@@ -1001,7 +1174,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1001 /// </param> 1174 /// </param>
1002 public void SendLandObjectOwners(IClientAPI remote_client) 1175 public void SendLandObjectOwners(IClientAPI remote_client)
1003 { 1176 {
1004 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions)) 1177 if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
1005 { 1178 {
1006 Dictionary<UUID, int> primCount = new Dictionary<UUID, int>(); 1179 Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
1007 List<UUID> groups = new List<UUID>(); 1180 List<UUID> groups = new List<UUID>();
@@ -1233,6 +1406,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1233 public void SetMediaUrl(string url) 1406 public void SetMediaUrl(string url)
1234 { 1407 {
1235 LandData.MediaURL = url; 1408 LandData.MediaURL = url;
1409 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
1236 SendLandUpdateToAvatarsOverMe(); 1410 SendLandUpdateToAvatarsOverMe();
1237 } 1411 }
1238 1412
@@ -1243,6 +1417,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1243 public void SetMusicUrl(string url) 1417 public void SetMusicUrl(string url)
1244 { 1418 {
1245 LandData.MusicURL = url; 1419 LandData.MusicURL = url;
1420 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
1246 SendLandUpdateToAvatarsOverMe(); 1421 SendLandUpdateToAvatarsOverMe();
1247 } 1422 }
1248 1423
@@ -1257,6 +1432,17 @@ namespace OpenSim.Region.CoreModules.World.Land
1257 1432
1258 #endregion 1433 #endregion
1259 1434
1435 private void OnFrame()
1436 {
1437 m_expiryCounter++;
1438
1439 if (m_expiryCounter >= 50)
1440 {
1441 ExpireAccessList();
1442 m_expiryCounter = 0;
1443 }
1444 }
1445
1260 private void ExpireAccessList() 1446 private void ExpireAccessList()
1261 { 1447 {
1262 List<LandAccessEntry> delete = new List<LandAccessEntry>(); 1448 List<LandAccessEntry> delete = new List<LandAccessEntry>();
@@ -1267,7 +1453,22 @@ namespace OpenSim.Region.CoreModules.World.Land
1267 delete.Add(entry); 1453 delete.Add(entry);
1268 } 1454 }
1269 foreach (LandAccessEntry entry in delete) 1455 foreach (LandAccessEntry entry in delete)
1456 {
1270 LandData.ParcelAccessList.Remove(entry); 1457 LandData.ParcelAccessList.Remove(entry);
1458 ScenePresence presence;
1459
1460 if (m_scene.TryGetScenePresence(entry.AgentID, out presence) && (!presence.IsChildAgent))
1461 {
1462 ILandObject land = m_scene.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y);
1463 if (land.LandData.LocalID == LandData.LocalID)
1464 {
1465 Vector3 pos = m_scene.GetNearestAllowedPosition(presence, land);
1466 presence.TeleportWithMomentum(pos, null);
1467 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
1468 }
1469 }
1470 m_log.DebugFormat("[LAND]: Removing entry {0} because it has expired", entry.AgentID);
1471 }
1271 1472
1272 if (delete.Count > 0) 1473 if (delete.Count > 0)
1273 m_scene.EventManager.TriggerLandObjectUpdated((uint)LandData.LocalID, this); 1474 m_scene.EventManager.TriggerLandObjectUpdated((uint)LandData.LocalID, this);
diff --git a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
index 9b51cc8..771fdd2 100644
--- a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs
@@ -207,7 +207,7 @@ namespace OpenSim.Region.CoreModules.World.Land
207 if (m_ParcelCounts.TryGetValue(landData.GlobalID, out parcelCounts)) 207 if (m_ParcelCounts.TryGetValue(landData.GlobalID, out parcelCounts))
208 { 208 {
209 UUID landOwner = landData.OwnerID; 209 UUID landOwner = landData.OwnerID;
210 int partCount = obj.Parts.Length; 210 int partCount = obj.GetPartCount();
211 211
212 m_SimwideCounts[landOwner] += partCount; 212 m_SimwideCounts[landOwner] += partCount;
213 if (parcelCounts.Users.ContainsKey(obj.OwnerID)) 213 if (parcelCounts.Users.ContainsKey(obj.OwnerID))
@@ -597,4 +597,4 @@ namespace OpenSim.Region.CoreModules.World.Land
597 } 597 }
598 } 598 }
599 } 599 }
600} \ No newline at end of file 600}
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
index 796a15f..a228e7a 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
@@ -104,6 +104,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
104 104
105 terrainRenderer.Initialise(m_scene, m_config); 105 terrainRenderer.Initialise(m_scene, m_config);
106 106
107<<<<<<< HEAD
107 mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height, 108 mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height,
108 System.Drawing.Imaging.PixelFormat.Format24bppRgb); 109 System.Drawing.Imaging.PixelFormat.Format24bppRgb);
109 //long t = System.Environment.TickCount; 110 //long t = System.Environment.TickCount;
@@ -112,6 +113,16 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
112 //} 113 //}
113 //t = System.Environment.TickCount - t; 114 //t = System.Environment.TickCount - t;
114 //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t); 115 //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
116=======
117 mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height,
118 System.Drawing.Imaging.PixelFormat.Format24bppRgb);
119 //long t = System.Environment.TickCount;
120 //for (int i = 0; i < 10; ++i) {
121 terrainRenderer.TerrainToBitmap(mapbmp);
122 //}
123 //t = System.Environment.TickCount - t;
124 //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
125>>>>>>> avn/ubitvar
115 126
116 if (drawPrimVolume) 127 if (drawPrimVolume)
117 { 128 {
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
index 9f23141..a9cc993 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
@@ -270,8 +270,14 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
270 270
271 // the heigthfield might have some jumps in values. Rendered land is smooth, though, 271 // the heigthfield might have some jumps in values. Rendered land is smooth, though,
272 // as a slope is rendered at that place. So average 4 neighbour values to emulate that. 272 // as a slope is rendered at that place. So average 4 neighbour values to emulate that.
273<<<<<<< HEAD
273 private float getHeight(ITerrainChannel hm, int x, int y) { 274 private float getHeight(ITerrainChannel hm, int x, int y) {
274 if (x < (hm.Width - 1) && y < (hm.Height - 1)) 275 if (x < (hm.Width - 1) && y < (hm.Height - 1))
276=======
277 private float getHeight(ITerrainChannel hm, int x, int y)
278 {
279 if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1))
280>>>>>>> avn/ubitvar
275 return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); 281 return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112);
276 else 282 else
277 return (float)hm[x, y]; 283 return (float)hm[x, y];
@@ -291,6 +297,14 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
291 LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height); 297 LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
292 } 298 }
293 299
300 ITerrainChannel hm = m_scene.Heightmap;
301
302 if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height)
303 {
304 m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>",
305 "[TEXTURED MAP TILE RENDERER]", mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
306 }
307
294 // These textures should be in the AssetCache anyway, as every client conneting to this 308 // These textures should be in the AssetCache anyway, as every client conneting to this
295 // region needs them. Except on start, when the map is recreated (before anyone connected), 309 // region needs them. Except on start, when the map is recreated (before anyone connected),
296 // and on change of the estate settings (textures and terrain values), when the map should 310 // and on change of the estate settings (textures and terrain values), when the map should
@@ -371,8 +385,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
371 // first, rescale h to 0.0 - 1.0 385 // first, rescale h to 0.0 - 1.0
372 hmod = (hmod - low) / (high - low); 386 hmod = (hmod - low) / (high - low);
373 // now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4 387 // now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4
374 if (hmod < 1f/3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod * 3f); 388 if (hmod < 1f / 3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod * 3f);
375 else if (hmod < 2f/3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod * 3f) - 1f); 389 else if (hmod < 2f / 3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod * 3f) - 1f);
376 else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod * 3f) - 2f); 390 else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod * 3f) - 2f);
377 } 391 }
378 392
diff --git a/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs
index 0a4e83e..f13d648 100644
--- a/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs
+++ b/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs
@@ -190,6 +190,9 @@ namespace OpenSim.Region.CoreModules.World.LightShare
190 190
191 public void SendProfileToClient(IClientAPI client, RegionLightShareData wl) 191 public void SendProfileToClient(IClientAPI client, RegionLightShareData wl)
192 { 192 {
193 if (client == null)
194 return;
195
193 if (m_enableWindlight) 196 if (m_enableWindlight)
194 { 197 {
195 if (m_scene.RegionInfo.WindlightSettings.valid) 198 if (m_scene.RegionInfo.WindlightSettings.valid)
@@ -207,8 +210,8 @@ namespace OpenSim.Region.CoreModules.World.LightShare
207 210
208 private void EventManager_OnMakeRootAgent(ScenePresence presence) 211 private void EventManager_OnMakeRootAgent(ScenePresence presence)
209 { 212 {
210// m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client {0}", presence.Name); 213 if (m_enableWindlight && m_scene.RegionInfo.WindlightSettings.valid)
211 214 m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client");
212 SendProfileToClient(presence.ControllingClient); 215 SendProfileToClient(presence.ControllingClient);
213 } 216 }
214 217
diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
index 2abc910..0e0f05f 100644
--- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
+++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
@@ -173,6 +173,13 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
173 return false; 173 return false;
174 } 174 }
175 175
176 if ((perms & (uint)PermissionMask.Copy) == 0)
177 {
178 if (m_dialogModule != null)
179 m_dialogModule.SendAlertToUser(remoteClient, "This sale has been blocked by the permissions system");
180 return false;
181 }
182
176 AssetBase asset = m_scene.CreateAsset( 183 AssetBase asset = m_scene.CreateAsset(
177 group.GetPartName(localID), 184 group.GetPartName(localID),
178 group.GetPartDescription(localID), 185 group.GetPartDescription(localID),
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index 780ec69..12e8fb1 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -43,8 +43,8 @@ using PermissionMask = OpenSim.Framework.PermissionMask;
43 43
44namespace OpenSim.Region.CoreModules.World.Permissions 44namespace OpenSim.Region.CoreModules.World.Permissions
45{ 45{
46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PermissionsModule")] 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DefaultPermissionsModule")]
47 public class PermissionsModule : INonSharedRegionModule, IPermissionsModule 47 public class DefaultPermissionsModule : INonSharedRegionModule, IPermissionsModule
48 { 48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
@@ -349,7 +349,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
349 349
350 public string Name 350 public string Name
351 { 351 {
352 get { return "PermissionsModule"; } 352 get { return "DefaultPermissionsModule"; }
353 } 353 }
354 354
355 public Type ReplaceableInterface 355 public Type ReplaceableInterface
@@ -1052,7 +1052,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
1052 return GenericObjectPermission(editorID, objectID, false); 1052 return GenericObjectPermission(editorID, objectID, false);
1053 } 1053 }
1054 1054
1055 private bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p, Scene scene) 1055 private bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p, Scene scene, bool allowManager)
1056 { 1056 {
1057 DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); 1057 DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1058 if (m_bypassPermissions) return m_bypassPermissionsValue; 1058 if (m_bypassPermissions) return m_bypassPermissionsValue;
diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs
index 75a8295..e6a0205 100644
--- a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs
+++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs
@@ -29,6 +29,8 @@ using System;
29using System.Linq; 29using System.Linq;
30using System.Reflection; 30using System.Reflection;
31using System.Timers; 31using System.Timers;
32using System.IO;
33using System.Diagnostics;
32using System.Threading; 34using System.Threading;
33using System.Collections.Generic; 35using System.Collections.Generic;
34using log4net; 36using log4net;
@@ -57,13 +59,24 @@ namespace OpenSim.Region.CoreModules.World.Region
57 protected UUID m_Initiator; 59 protected UUID m_Initiator;
58 protected bool m_Notice = false; 60 protected bool m_Notice = false;
59 protected IDialogModule m_DialogModule = null; 61 protected IDialogModule m_DialogModule = null;
62 protected string m_MarkerPath = String.Empty;
63 private int[] m_CurrentAlerts = null;
60 64
61 public void Initialise(IConfigSource config) 65 public void Initialise(IConfigSource config)
62 { 66 {
67 IConfig restartConfig = config.Configs["RestartModule"];
68 if (restartConfig != null)
69 {
70 m_MarkerPath = restartConfig.GetString("MarkerPath", String.Empty);
71 }
63 } 72 }
64 73
65 public void AddRegion(Scene scene) 74 public void AddRegion(Scene scene)
66 { 75 {
76 if (m_MarkerPath != String.Empty)
77 File.Delete(Path.Combine(m_MarkerPath,
78 scene.RegionInfo.RegionID.ToString()));
79
67 m_Scene = scene; 80 m_Scene = scene;
68 81
69 scene.RegisterModuleInterface<IRestartModule>(this); 82 scene.RegisterModuleInterface<IRestartModule>(this);
@@ -118,10 +131,14 @@ namespace OpenSim.Region.CoreModules.World.Region
118 public void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice) 131 public void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice)
119 { 132 {
120 if (m_CountdownTimer != null) 133 if (m_CountdownTimer != null)
121 return; 134 {
135 m_CountdownTimer.Stop();
136 m_CountdownTimer = null;
137 }
122 138
123 if (alerts == null) 139 if (alerts == null)
124 { 140 {
141 CreateMarkerFile();
125 m_Scene.RestartNow(); 142 m_Scene.RestartNow();
126 return; 143 return;
127 } 144 }
@@ -129,25 +146,28 @@ namespace OpenSim.Region.CoreModules.World.Region
129 m_Message = message; 146 m_Message = message;
130 m_Initiator = initiator; 147 m_Initiator = initiator;
131 m_Notice = notice; 148 m_Notice = notice;
149 m_CurrentAlerts = alerts;
132 m_Alerts = new List<int>(alerts); 150 m_Alerts = new List<int>(alerts);
133 m_Alerts.Sort(); 151 m_Alerts.Sort();
134 m_Alerts.Reverse(); 152 m_Alerts.Reverse();
135 153
136 if (m_Alerts[0] == 0) 154 if (m_Alerts[0] == 0)
137 { 155 {
156 CreateMarkerFile();
138 m_Scene.RestartNow(); 157 m_Scene.RestartNow();
139 return; 158 return;
140 } 159 }
141 160
142 int nextInterval = DoOneNotice(); 161 int nextInterval = DoOneNotice(true);
143 162
144 SetTimer(nextInterval); 163 SetTimer(nextInterval);
145 } 164 }
146 165
147 public int DoOneNotice() 166 public int DoOneNotice(bool sendOut)
148 { 167 {
149 if (m_Alerts.Count == 0 || m_Alerts[0] == 0) 168 if (m_Alerts.Count == 0 || m_Alerts[0] == 0)
150 { 169 {
170 CreateMarkerFile();
151 m_Scene.RestartNow(); 171 m_Scene.RestartNow();
152 return 0; 172 return 0;
153 } 173 }
@@ -168,34 +188,37 @@ namespace OpenSim.Region.CoreModules.World.Region
168 188
169 m_Alerts.RemoveAt(0); 189 m_Alerts.RemoveAt(0);
170 190
171 int minutes = currentAlert / 60; 191 if (sendOut)
172 string currentAlertString = String.Empty;
173 if (minutes > 0)
174 { 192 {
175 if (minutes == 1) 193 int minutes = currentAlert / 60;
176 currentAlertString += "1 minute"; 194 string currentAlertString = String.Empty;
177 else 195 if (minutes > 0)
178 currentAlertString += String.Format("{0} minutes", minutes); 196 {
197 if (minutes == 1)
198 currentAlertString += "1 minute";
199 else
200 currentAlertString += String.Format("{0} minutes", minutes);
201 if ((currentAlert % 60) != 0)
202 currentAlertString += " and ";
203 }
179 if ((currentAlert % 60) != 0) 204 if ((currentAlert % 60) != 0)
180 currentAlertString += " and "; 205 {
181 } 206 int seconds = currentAlert % 60;
182 if ((currentAlert % 60) != 0) 207 if (seconds == 1)
183 { 208 currentAlertString += "1 second";
184 int seconds = currentAlert % 60; 209 else
185 if (seconds == 1) 210 currentAlertString += String.Format("{0} seconds", seconds);
186 currentAlertString += "1 second"; 211 }
187 else
188 currentAlertString += String.Format("{0} seconds", seconds);
189 }
190 212
191 string msg = String.Format(m_Message, currentAlertString); 213 string msg = String.Format(m_Message, currentAlertString);
192 214
193 if (m_DialogModule != null && msg != String.Empty) 215 if (m_DialogModule != null && msg != String.Empty)
194 { 216 {
195 if (m_Notice) 217 if (m_Notice)
196 m_DialogModule.SendGeneralAlert(msg); 218 m_DialogModule.SendGeneralAlert(msg);
197 else 219 else
198 m_DialogModule.SendNotificationToUsersInRegion(m_Initiator, "System", msg); 220 m_DialogModule.SendNotificationToUsersInRegion(m_Initiator, "System", msg);
221 }
199 } 222 }
200 223
201 return currentAlert - nextAlert; 224 return currentAlert - nextAlert;
@@ -226,7 +249,27 @@ namespace OpenSim.Region.CoreModules.World.Region
226 249
227 private void OnTimer(object source, ElapsedEventArgs e) 250 private void OnTimer(object source, ElapsedEventArgs e)
228 { 251 {
229 SetTimer(DoOneNotice()); 252 int nextInterval = DoOneNotice(true);
253
254 SetTimer(nextInterval);
255 }
256
257 public void DelayRestart(int seconds, string message)
258 {
259 if (m_CountdownTimer == null)
260 return;
261
262 m_CountdownTimer.Stop();
263 m_CountdownTimer = null;
264
265 m_Alerts = new List<int>(m_CurrentAlerts);
266 m_Alerts.Add(seconds);
267 m_Alerts.Sort();
268 m_Alerts.Reverse();
269
270 int nextInterval = DoOneNotice(false);
271
272 SetTimer(nextInterval);
230 } 273 }
231 274
232 public void AbortRestart(string message) 275 public void AbortRestart(string message)
@@ -236,8 +279,12 @@ namespace OpenSim.Region.CoreModules.World.Region
236 m_CountdownTimer.Stop(); 279 m_CountdownTimer.Stop();
237 m_CountdownTimer = null; 280 m_CountdownTimer = null;
238 if (m_DialogModule != null && message != String.Empty) 281 if (m_DialogModule != null && message != String.Empty)
239 m_DialogModule.SendGeneralAlert(message); 282 m_DialogModule.SendNotificationToUsersInRegion(UUID.Zero, "System", message);
283 //m_DialogModule.SendGeneralAlert(message);
240 } 284 }
285 if (m_MarkerPath != String.Empty)
286 File.Delete(Path.Combine(m_MarkerPath,
287 m_Scene.RegionInfo.RegionID.ToString()));
241 } 288 }
242 289
243 private void HandleRegionRestart(string module, string[] args) 290 private void HandleRegionRestart(string module, string[] args)
@@ -282,5 +329,25 @@ namespace OpenSim.Region.CoreModules.World.Region
282 329
283 ScheduleRestart(UUID.Zero, args[3], times.ToArray(), notice); 330 ScheduleRestart(UUID.Zero, args[3], times.ToArray(), notice);
284 } 331 }
332
333 protected void CreateMarkerFile()
334 {
335 if (m_MarkerPath == String.Empty)
336 return;
337
338 string path = Path.Combine(m_MarkerPath, m_Scene.RegionInfo.RegionID.ToString());
339 try
340 {
341 string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
342 FileStream fs = File.Create(path);
343 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
344 Byte[] buf = enc.GetBytes(pidstring);
345 fs.Write(buf, 0, buf.Length);
346 fs.Close();
347 }
348 catch (Exception)
349 {
350 }
351 }
285 } 352 }
286} \ No newline at end of file 353}
diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
index d093224..9c99c19 100644
--- a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
+++ b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs
@@ -48,6 +48,18 @@ namespace OpenSim.Region.CoreModules.World.Sound
48 48
49 private Scene m_scene; 49 private Scene m_scene;
50 50
51 public enum SoundFlags: byte
52 {
53 NONE = 0,
54 LOOP = 1 << 0,
55 SYNC_MASTER = 1<<1,
56 SYNC_SLAVE = 1<<2,
57 SYNC_PENDING = 1<<3,
58 QUEUE = 1<<4,
59 STOP = 1<<5,
60 SYNC_MASK = SYNC_MASTER | SYNC_SLAVE | SYNC_PENDING
61 }
62
51 public bool Enabled { get; private set; } 63 public bool Enabled { get; private set; }
52 64
53 public float MaxDistance { get; private set; } 65 public float MaxDistance { get; private set; }
@@ -124,26 +136,30 @@ namespace OpenSim.Region.CoreModules.World.Sound
124 if (radius == 0) 136 if (radius == 0)
125 radius = MaxDistance; 137 radius = MaxDistance;
126 138
127 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) 139 if (part.SoundQueueing)
140 flags |= (byte)SoundFlags.QUEUE;
141
142 if (grp.IsAttachment)
128 { 143 {
129 double dis = Util.GetDistanceTo(sp.AbsolutePosition, position); 144 ScenePresence ssp = null;
130 if (dis > MaxDistance) // Max audio distance 145 if (!m_scene.TryGetScenePresence(grp.AttachedAvatar, out ssp))
131 return; 146 return;
132 147
133 if (grp.IsAttachment) 148 if (!ssp.ParcelAllowThisAvatarSounds)
134 { 149 return;
135 if (grp.HasPrivateAttachmentPoint && sp.ControllingClient.AgentId != grp.OwnerID)
136 return;
137 150
138 if (sp.ControllingClient.AgentId == grp.OwnerID) 151 if (grp.HasPrivateAttachmentPoint)
139 dis = 0; 152 {
153 ssp.ControllingClient.SendPlayAttachedSound(soundID, objectID,
154 ownerID, (float)gain, flags);
155 return;
140 } 156 }
157 }
141 158
142 // Scale by distance 159 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
143 double thisSpGain = gain * ((radius - dis) / radius); 160 {
144
145 sp.ControllingClient.SendPlayAttachedSound(soundID, objectID, 161 sp.ControllingClient.SendPlayAttachedSound(soundID, objectID,
146 ownerID, (float)thisSpGain, flags); 162 ownerID, (float)gain, flags);
147 }); 163 });
148 } 164 }
149 165
@@ -151,20 +167,33 @@ namespace OpenSim.Region.CoreModules.World.Sound
151 UUID soundId, UUID ownerID, UUID objectID, UUID parentID, double gain, Vector3 position, UInt64 handle, float radius) 167 UUID soundId, UUID ownerID, UUID objectID, UUID parentID, double gain, Vector3 position, UInt64 handle, float radius)
152 { 168 {
153 SceneObjectPart part; 169 SceneObjectPart part;
170 ScenePresence ssp = null;
154 if (!m_scene.TryGetSceneObjectPart(objectID, out part)) 171 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
155 { 172 {
156 ScenePresence sp; 173 if (!m_scene.TryGetScenePresence(ownerID, out ssp))
157 if (!m_scene.TryGetScenePresence(ownerID, out sp)) 174 return;
175 if (!ssp.ParcelAllowThisAvatarSounds)
158 return; 176 return;
159 } 177 }
160 else 178 else
161 { 179 {
162 SceneObjectGroup grp = part.ParentGroup; 180 SceneObjectGroup grp = part.ParentGroup;
163 181
164 if (grp.IsAttachment && grp.AttachmentPoint > 30) 182 if (grp.IsAttachment)
165 { 183 {
166 objectID = ownerID; 184 if (!m_scene.TryGetScenePresence(grp.AttachedAvatar, out ssp))
167 parentID = ownerID; 185 return;
186
187 if (!ssp.ParcelAllowThisAvatarSounds)
188 return;
189
190 if (grp.HasPrivateAttachmentPoint)
191 {
192 ssp.ControllingClient.SendTriggeredSound(soundId, ownerID,
193 objectID, parentID, handle, position,
194 (float)gain);
195 return;
196 }
168 } 197 }
169 } 198 }
170 199
@@ -174,16 +203,12 @@ namespace OpenSim.Region.CoreModules.World.Sound
174 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) 203 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
175 { 204 {
176 double dis = Util.GetDistanceTo(sp.AbsolutePosition, position); 205 double dis = Util.GetDistanceTo(sp.AbsolutePosition, position);
177 206 if (dis > radius) // Max audio distance
178 if (dis > MaxDistance) // Max audio distance
179 return; 207 return;
180 208
181 // Scale by distance
182 double thisSpGain = gain * ((radius - dis) / radius);
183
184 sp.ControllingClient.SendTriggeredSound(soundId, ownerID, 209 sp.ControllingClient.SendTriggeredSound(soundId, ownerID,
185 objectID, parentID, handle, position, 210 objectID, parentID, handle, position,
186 (float)thisSpGain); 211 (float)gain);
187 }); 212 });
188 } 213 }
189 214
@@ -198,40 +223,13 @@ namespace OpenSim.Region.CoreModules.World.Sound
198 223
199 private static void StopSound(SceneObjectPart m_host) 224 private static void StopSound(SceneObjectPart m_host)
200 { 225 {
201 m_host.AdjustSoundGain(0); 226// m_host.AdjustSoundGain(0);
202 // Xantor 20080528: Clear prim data of sound instead 227 m_host.Sound = UUID.Zero;
203 if (m_host.ParentGroup.LoopSoundSlavePrims.Contains(m_host)) 228 m_host.SoundFlags = (byte)SoundFlags.STOP;
204 { 229 m_host.SoundRadius = 0;
205 if (m_host.ParentGroup.LoopSoundMasterPrim == m_host) 230 m_host.SoundGain = 0;
206 { 231 m_host.ScheduleFullUpdate();
207 foreach (SceneObjectPart part in m_host.ParentGroup.LoopSoundSlavePrims) 232 m_host.SendFullUpdateToAllClients();
208 {
209 part.Sound = UUID.Zero;
210 part.SoundFlags = 1 << 5;
211 part.SoundRadius = 0;
212 part.ScheduleFullUpdate();
213 part.SendFullUpdateToAllClients();
214 }
215 m_host.ParentGroup.LoopSoundMasterPrim = null;
216 m_host.ParentGroup.LoopSoundSlavePrims.Clear();
217 }
218 else
219 {
220 m_host.Sound = UUID.Zero;
221 m_host.SoundFlags = 1 << 5;
222 m_host.SoundRadius = 0;
223 m_host.ScheduleFullUpdate();
224 m_host.SendFullUpdateToAllClients();
225 }
226 }
227 else
228 {
229 m_host.Sound = UUID.Zero;
230 m_host.SoundFlags = 1 << 5;
231 m_host.SoundRadius = 0;
232 m_host.ScheduleFullUpdate();
233 m_host.SendFullUpdateToAllClients();
234 }
235 } 233 }
236 234
237 public virtual void PreloadSound(UUID objectID, UUID soundID, float radius) 235 public virtual void PreloadSound(UUID objectID, UUID soundID, float radius)
@@ -248,7 +246,7 @@ namespace OpenSim.Region.CoreModules.World.Sound
248 246
249 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) 247 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
250 { 248 {
251 if (!(Util.GetDistanceTo(sp.AbsolutePosition, part.AbsolutePosition) >= MaxDistance)) 249 if (Util.GetDistanceTo(sp.AbsolutePosition, part.AbsolutePosition) < radius)
252 sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID); 250 sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
253 }); 251 });
254 } 252 }
@@ -262,21 +260,24 @@ namespace OpenSim.Region.CoreModules.World.Sound
262 // 20080530 Updated to remove code duplication 260 // 20080530 Updated to remove code duplication
263 // 20080530 Stop sound if there is one, otherwise volume only changes don't work 261 // 20080530 Stop sound if there is one, otherwise volume only changes don't work
264 public void LoopSound(UUID objectID, UUID soundID, 262 public void LoopSound(UUID objectID, UUID soundID,
265 double volume, double radius, bool isMaster) 263 double volume, double radius, bool isMaster, bool isSlave)
266 { 264 {
267 SceneObjectPart m_host; 265 SceneObjectPart m_host;
268 if (!m_scene.TryGetSceneObjectPart(objectID, out m_host)) 266 if (!m_scene.TryGetSceneObjectPart(objectID, out m_host))
269 return; 267 return;
270 268
269 byte iflags = 1; // looping
271 if (isMaster) 270 if (isMaster)
272 m_host.ParentGroup.LoopSoundMasterPrim = m_host; 271 iflags |= (byte)SoundFlags.SYNC_MASTER;
273 272 // TODO check viewer seems to accept both
274 if (m_host.Sound != UUID.Zero) 273 if (isSlave)
275 StopSound(m_host); 274 iflags |= (byte)SoundFlags.SYNC_SLAVE;
275 if (m_host.SoundQueueing)
276 iflags |= (byte)SoundFlags.QUEUE;
276 277
277 m_host.Sound = soundID; 278 m_host.Sound = soundID;
278 m_host.SoundGain = volume; 279 m_host.SoundGain = volume;
279 m_host.SoundFlags = 1; // looping 280 m_host.SoundFlags = iflags;
280 m_host.SoundRadius = radius; 281 m_host.SoundRadius = radius;
281 282
282 m_host.ScheduleFullUpdate(); 283 m_host.ScheduleFullUpdate();
@@ -301,42 +302,19 @@ namespace OpenSim.Region.CoreModules.World.Sound
301 Vector3 position = part.AbsolutePosition; // region local 302 Vector3 position = part.AbsolutePosition; // region local
302 ulong regionHandle = m_scene.RegionInfo.RegionHandle; 303 ulong regionHandle = m_scene.RegionInfo.RegionHandle;
303 304
304 if (useMaster) 305 if(triggered)
305 { 306 TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius);
306 if (isMaster)
307 {
308 if (triggered)
309 TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius);
310 else
311 PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius);
312 part.ParentGroup.PlaySoundMasterPrim = part;
313 if (triggered)
314 TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius);
315 else
316 PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius);
317 foreach (SceneObjectPart prim in part.ParentGroup.PlaySoundSlavePrims)
318 {
319 position = prim.AbsolutePosition; // region local
320 if (triggered)
321 TriggerSound(soundID, part.OwnerID, prim.UUID, parentID, volume, position, regionHandle, radius);
322 else
323 PlayAttachedSound(soundID, part.OwnerID, prim.UUID, volume, position, flags, radius);
324 }
325 part.ParentGroup.PlaySoundSlavePrims.Clear();
326 part.ParentGroup.PlaySoundMasterPrim = null;
327 }
328 else
329 {
330 part.ParentGroup.PlaySoundSlavePrims.Add(part);
331 }
332 }
333 else 307 else
334 { 308 {
335 if (triggered) 309 byte bflags = 0;
336 TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius); 310
337 else 311 if (isMaster)
338 PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius); 312 bflags |= (byte)SoundFlags.SYNC_MASTER;
339 } 313 // TODO check viewer seems to accept both
314 if (useMaster)
315 bflags |= (byte)SoundFlags.SYNC_SLAVE;
316 PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, bflags, radius);
317 }
340 } 318 }
341 319
342 public void TriggerSoundLimited(UUID objectID, UUID sound, 320 public void TriggerSoundLimited(UUID objectID, UUID sound,
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
index 36917e9..b456aa1 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
64 64
65 for (int i = 0; i < rounds; i++) 65 for (int i = 0; i < rounds; i++)
66 { 66 {
67 smoothFunction.FloodEffect(map, bitmap, 1.0); 67 smoothFunction.FloodEffect(map, bitmap, 1.0, 0, map.Width - 1, 0, map.Height - 1);
68 } 68 }
69 } 69 }
70 70
@@ -99,7 +99,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
99 } 99 }
100 } 100 }
101 101
102 raiseFunction.FloodEffect(map, bitmap, height); 102 raiseFunction.FloodEffect(map, bitmap, height, 0, map.Width - 1, 0, map.Height - 1);
103 } 103 }
104 } 104 }
105 } 105 }
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
index dc76ad5..3222524 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
@@ -84,7 +84,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
84 for (y = 0; y < map.Height; y++) 84 for (y = 0; y < map.Height; y++)
85 { 85 {
86 if (cliffMask[x, y]) 86 if (cliffMask[x, y])
87 eroder.PaintEffect(map, allowMask, x, y, -1, 4, 0.1); 87 eroder.PaintEffect(map, allowMask, x, y, -1, 4, 0.1,0,map.Width - 1,0,map.Height - 1);
88 } 88 }
89 } 89 }
90 90
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
index 89087b1..80396c4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
@@ -53,4 +53,4 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
53 53
54 #endregion 54 #endregion
55 } 55 }
56} \ No newline at end of file 56}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
index 774e7b2..0c4171e 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
@@ -33,15 +33,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 double sum = 0.0; 39 double sum = 0.0;
39 double steps = 0.0; 40 double steps = 0.0;
40 41
41 int x, y; 42 int x, y;
42 for (x = 0; x < map.Width; x++) 43 for (x = startX; x <= endX; x++)
43 { 44 {
44 for (y = 0; y < map.Height; y++) 45 for (y = startY; y <= endY; y++)
45 { 46 {
46 if (fillArea[x, y]) 47 if (fillArea[x, y])
47 { 48 {
@@ -55,9 +56,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
55 56
56 double str = 0.1 * strength; // == 0.2 in the default client 57 double str = 0.1 * strength; // == 0.2 in the default client
57 58
58 for (x = 0; x < map.Width; x++) 59 for (x = startX; x <= endX; x++)
59 { 60 {
60 for (y = 0; y < map.Height; y++) 61 for (y = startY; y <= endY; y++)
61 { 62 {
62 if (fillArea[x, y]) 63 if (fillArea[x, y])
63 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); 64 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
index 3e87390..a275a86 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
@@ -33,13 +33,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 int x; 39 int x,y;
39 for (x = 0; x < map.Width; x++) 40 for (x = startX; x <= endX; x++)
40 { 41 {
41 int y; 42 for (y = startY; y <= endY; y++)
42 for (y = 0; y < map.Height; y++)
43 { 43 {
44 if (fillArea[x, y]) 44 if (fillArea[x, y])
45 { 45 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
index b6c635c..236584a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
@@ -35,18 +35,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
35 { 35 {
36 #region ITerrainFloodEffect Members 36 #region ITerrainFloodEffect Members
37 37
38 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 38 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
39 int startX, int endX, int startY, int endY)
39 { 40 {
40 int x; 41 int x, y;
41 for (x = 0; x < map.Width; x++) 42 for (x = startX; x <= endX; x++)
42 { 43 {
43 int y; 44 for (y = startY; y <= endY; y++)
44 for (y = 0; y < map.Height; y++)
45 { 45 {
46 if (fillArea[x, y]) 46 if (fillArea[x, y])
47 { 47 {
48 double noise = TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0); 48 double noise = TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0);
49<<<<<<< HEAD
49 50
51=======
52>>>>>>> avn/ubitvar
50 map[x, y] += noise * strength; 53 map[x, y] += noise * strength;
51 } 54 }
52 } 55 }
@@ -55,4 +58,4 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
55 58
56 #endregion 59 #endregion
57 } 60 }
58} \ No newline at end of file 61}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
index 3bdc5e7..6ccd5df 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
@@ -33,13 +33,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 int x; 39 int x,y;
39 for (x = 0; x < map.Width; x++) 40 for (x = startX; x <= endX; x++)
40 { 41 {
41 int y; 42 for (y = startY; y <= endY; y++)
42 for (y = 0; y < map.Height; y++)
43 { 43 {
44 if (fillArea[x, y]) 44 if (fillArea[x, y])
45 { 45 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
index c5527fa..4230133 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
@@ -46,13 +46,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
46 /// <param name="map">the current heightmap</param> 46 /// <param name="map">the current heightmap</param>
47 /// <param name="fillArea">array indicating which sections of the map are to be reverted</param> 47 /// <param name="fillArea">array indicating which sections of the map are to be reverted</param>
48 /// <param name="strength">unused</param> 48 /// <param name="strength">unused</param>
49 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 49 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
50 int startX, int endX, int startY, int endY)
50 { 51 {
51 int x; 52 int x, y;
52 for (x = 0; x < map.Width; x++) 53 for (x = startX; x <= endX; x++)
53 { 54 {
54 int y; 55 for (y = startY; y <= endY; y++)
55 for (y = 0; y < map.Height; y++)
56 { 56 {
57 if (fillArea[x, y]) 57 if (fillArea[x, y])
58 { 58 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
index 6b07747..6c0d60d 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
@@ -33,16 +33,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 double area = strength; 39 double area = strength;
39 double step = strength / 4.0; 40 double step = strength / 4.0;
40 41
41 double[,] manipulate = new double[map.Width,map.Height]; 42 double[,] manipulate = new double[map.Width,map.Height];
42 int x, y; 43 int x, y;
43 for (x = 0; x < map.Width; x++) 44 for (x = startX; x <= endX; x++)
44 { 45 {
45 for (y = 0; y < map.Height; y++) 46 for (y = startY; y <= endY; y++)
46 { 47 {
47 if (!fillArea[x, y]) 48 if (!fillArea[x, y])
48 continue; 49 continue;
@@ -64,9 +65,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
64 manipulate[x, y] = average / avgsteps; 65 manipulate[x, y] = average / avgsteps;
65 } 66 }
66 } 67 }
67 for (x = 0; x < map.Width; x++) 68 for (x = startX; x <= endX; x++)
68 { 69 {
69 for (y = 0; y < map.Height; y++) 70 for (y = startY; y <= endY; y++)
70 { 71 {
71 if (!fillArea[x, y]) 72 if (!fillArea[x, y])
72 continue; 73 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
index 3984a30..6324aca 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
@@ -32,6 +32,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
32{ 32{
33 public interface ITerrainFloodEffect 33 public interface ITerrainFloodEffect
34 { 34 {
35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); 35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength,
36 int startX, int endX, int startY, int endY);
36 } 37 }
37} \ No newline at end of file 38} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
index b73defd..d0b05e4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
@@ -31,6 +31,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
31{ 31{
32 public interface ITerrainPaintableEffect 32 public interface ITerrainPaintableEffect
33 { 33 {
34 void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z, double strength, double duration); 34 void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z,
35 double strength, double duration, int startX, int endX, int startY, int endY);
35 } 36 }
36} 37}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
index 7a78cd8..7358ba3 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
@@ -151,7 +151,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
151 151
152 #region ITerrainPaintableEffect Members 152 #region ITerrainPaintableEffect Members
153 153
154 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 154 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
155 double strength, double duration, int startX, int endX, int startY, int endY)
155 { 156 {
156 strength = TerrainUtil.MetersToSphericalStrength(strength); 157 strength = TerrainUtil.MetersToSphericalStrength(strength);
157 158
@@ -163,18 +164,23 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
163 ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); 164 ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height);
164 165
165 // Fill with rain 166 // Fill with rain
166 for (x = 0; x < water.Width; x++) 167 for (x = startX; x <= endX; x++)
167 for (y = 0; y < water.Height; y++) 168 {
168 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); 169 for (y = startY; y <= endY; y++)
170 {
171 if (mask[x, y])
172 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
173 }
174 }
169 175
170 for (int i = 0; i < rounds; i++) 176 for (int i = 0; i < rounds; i++)
171 { 177 {
172 // Erode underlying terrain 178 // Erode underlying terrain
173 for (x = 0; x < water.Width; x++) 179 for (x = startX; x <= endX; x++)
174 { 180 {
175 for (y = 0; y < water.Height; y++) 181 for (y = startY; y <= endY; y++)
176 { 182 {
177 if (mask[x,y]) 183 if (mask[x, y])
178 { 184 {
179 const double solConst = (1.0 / rounds); 185 const double solConst = (1.0 / rounds);
180 double sedDelta = water[x, y] * solConst; 186 double sedDelta = water[x, y] * solConst;
@@ -185,9 +191,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
185 } 191 }
186 192
187 // Move water 193 // Move water
188 for (x = 0; x < water.Width; x++) 194 for (x = startX; x <= endX; x++)
189 { 195 {
190 for (y = 0; y < water.Height; y++) 196 for (y = startY; y <= endY; y++)
191 { 197 {
192 if (water[x, y] <= 0) 198 if (water[x, y] <= 0)
193 continue; 199 continue;
@@ -296,7 +302,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
296 double sedimentDeposit = sediment[x, y] - waterCapacity; 302 double sedimentDeposit = sediment[x, y] - waterCapacity;
297 if (sedimentDeposit > 0) 303 if (sedimentDeposit > 0)
298 { 304 {
299 if (mask[x,y]) 305 if (mask[x, y])
300 { 306 {
301 sediment[x, y] -= sedimentDeposit; 307 sediment[x, y] -= sedimentDeposit;
302 map[x, y] += sedimentDeposit; 308 map[x, y] += sedimentDeposit;
@@ -309,10 +315,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
309 // Deposit any remainder (should be minimal) 315 // Deposit any remainder (should be minimal)
310 for (x = 0; x < water.Width; x++) 316 for (x = 0; x < water.Width; x++)
311 for (y = 0; y < water.Height; y++) 317 for (y = 0; y < water.Height; y++)
312 if (mask[x,y] && sediment[x, y] > 0) 318 if (mask[x, y] && sediment[x, y] > 0)
313 map[x, y] += sediment[x, y]; 319 map[x, y] += sediment[x, y];
314 } 320 }
315
316 #endregion 321 #endregion
317 } 322 }
318} 323}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
index 9aa3dff..8937f63 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
@@ -35,16 +35,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 { 35 {
36 #region ITerrainPaintableEffect Members 36 #region ITerrainPaintableEffect Members
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength); 41 strength = TerrainUtil.MetersToSphericalStrength(strength);
41 42
42 int x, y; 43 int x, y;
43 44
44 // blend in map 45 // blend in map
45 for (x = 0; x < map.Width; x++) 46 for (x = startX; x <= endX; x++)
46 { 47 {
47 for (y = 0; y < map.Height; y++) 48 for (y = startY; y <= endY; y++)
48 { 49 {
49 if (!mask[x,y]) 50 if (!mask[x,y])
50 continue; 51 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
index 68145f2..bbf9407 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
@@ -34,34 +34,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
34 { 34 {
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
38 double strength, double duration, int startX, int endX, int startY, int endY)
38 { 39 {
39 int s = (int) (Math.Pow(2, strength) + 0.5); 40 int s = (int) (Math.Pow(2, strength) + 0.5);
40 41
41 int x; 42 int x, y;
42 int xFrom = (int)(rx-s+0.5);
43 int xTo = (int)(rx+s+0.5) + 1;
44 int yFrom = (int)(ry-s+0.5);
45 int yTo = (int)(ry+s+0.5) + 1;
46 43
47 if (xFrom < 0) 44 for (x = startX; x <= endX; x++)
48 xFrom = 0;
49
50 if (yFrom < 0)
51 yFrom = 0;
52
53 if (xTo > map.Width)
54 xTo = map.Width;
55
56 if (yTo > map.Width)
57 yTo = map.Width;
58
59 for (x = xFrom; x < xTo; x++)
60 { 45 {
61 int y; 46 for (y = startY; y <= endY; y++)
62 for (y = yFrom; y < yTo; y++)
63 { 47 {
64 if (!mask[x,y]) 48 if (!mask[x, y])
65 continue; 49 continue;
66 50
67 // Calculate a cos-sphere and add it to the heighmap 51 // Calculate a cos-sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
index e7df3f8..46d47b4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
@@ -35,17 +35,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 { 35 {
36 #region ITerrainPaintableEffect Members 36 #region ITerrainPaintableEffect Members
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength); 41 strength = TerrainUtil.MetersToSphericalStrength(strength);
41 42
42 int x; 43 int x, y;
43 for (x = 0; x < map.Width; x++) 44
45 for (x = startX; x <= endX; x++)
44 { 46 {
45 int y; 47 for (y = startY; y <= endY; y++)
46 for (y = 0; y < map.Height; y++)
47 { 48 {
48 if (!mask[x,y]) 49 if (!mask[x, y])
49 continue; 50 continue;
50 51
51 // Calculate a sphere and add it to the heighmap 52 // Calculate a sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
index b199df3..281690d 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
@@ -152,18 +152,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
152 152
153 #region ITerrainPaintableEffect Members 153 #region ITerrainPaintableEffect Members
154 154
155 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 155 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
156 double strength, double duration, int startX, int endX, int startY, int endY)
156 { 157 {
157 strength = TerrainUtil.MetersToSphericalStrength(strength); 158 strength = TerrainUtil.MetersToSphericalStrength(strength);
158 159
159 int x; 160 int x, y;
160 161
161 for (x = 0; x < map.Width; x++) 162 for (x = startX; x <= endX; x++)
162 { 163 {
163 int y; 164 for (y = startY; y <= endY; y++)
164 for (y = 0; y < map.Height; y++)
165 { 165 {
166 if (!mask[x,y]) 166 if (!mask[x, y])
167 continue; 167 continue;
168 168
169 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 169 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
index bd9a8a0..1b704bb 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
@@ -35,38 +35,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 int s = (int) (Math.Pow(2, strength) + 0.5); 41 int s = (int) (Math.Pow(2, strength) + 0.5);
41 42
42 int x; 43 int x,y;
43 int xFrom = (int)(rx-s+0.5);
44 int xTo = (int)(rx+s+0.5) + 1;
45 int yFrom = (int)(ry-s+0.5);
46 int yTo = (int)(ry+s+0.5) + 1;
47 44
48 if (xFrom < 0) 45 for (x = startX; x <= endX; x++)
49 xFrom = 0;
50
51 if (yFrom < 0)
52 yFrom = 0;
53
54 if (xTo > map.Width)
55 xTo = map.Width;
56
57 if (yTo > map.Width)
58 yTo = map.Width;
59
60 for (x = xFrom; x < xTo; x++)
61 { 46 {
62 int y; 47 for (y = startY; y <= endY; y++)
63 for (y = yFrom; y < yTo; y++)
64 { 48 {
65 if (!mask[x,y]) 49 if (!mask[x, y])
66 continue; 50 continue;
67 51
68 // Calculate a cos-sphere and add it to the heighmap 52 // Calculate a cos-sphere and add it to the heighmap
69 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); 53 double r = Math.Sqrt((x - rx) * (x - rx) + ((y - ry) * (y - ry)));
70 double z = Math.Cos(r * Math.PI / (s * 2)); 54 double z = Math.Cos(r * Math.PI / (s * 2));
71 if (z > 0.0) 55 if (z > 0.0)
72 map[x, y] += z * duration; 56 map[x, y] += z * duration;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
index 4b28275..efc5324 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
@@ -41,7 +41,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
41 41
42 #region ITerrainPaintableEffect Members 42 #region ITerrainPaintableEffect Members
43 43
44 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 44 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
45 double strength, double duration, int startX, int endX, int startY, int endY)
45 { 46 {
46 strength = TerrainUtil.MetersToSphericalStrength(strength); 47 strength = TerrainUtil.MetersToSphericalStrength(strength);
47 duration = 0.03; //MCP Should be read from ini file 48 duration = 0.03; //MCP Should be read from ini file
@@ -51,13 +52,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
51 if (duration < 0) 52 if (duration < 0)
52 return; 53 return;
53 54
54 int x; 55 int x,y;
55 for (x = 0; x < map.Width; x++) 56 for (x = startX; x <= endX; x++)
56 { 57 {
57 int y; 58 for (y = startY; y <= endY; y++)
58 for (y = 0; y < map.Height; y++)
59 { 59 {
60 if (!mask[x,y]) 60 if (!mask[x, y])
61 continue; 61 continue;
62 62
63 // Calculate a sphere and add it to the heighmap 63 // Calculate a sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
index 4834c86..65dd0a6 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
@@ -34,7 +34,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
34 { 34 {
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
38 double strength, double duration, int startX, int endX, int startY, int endY)
38 { 39 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 40 strength = TerrainUtil.MetersToSphericalStrength(strength);
40 41
@@ -47,10 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
47 48
48 49
49 // compute delta map 50 // compute delta map
50 for (x = 0; x < map.Width; x++) 51 for (x = startX; x <= endX; x++)
51 { 52 {
52 for (y = 0; y < map.Height; y++) 53 for (y = startY; y <= endY; y++)
53 { 54 {
55 if (!mask[x, y])
56 continue;
57
54 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 58 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
55 59
56 if (z > 0) // add in non-zero amount 60 if (z > 0) // add in non-zero amount
@@ -73,11 +77,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
73 } 77 }
74 } 78 }
75 // blend in map 79 // blend in map
76 for (x = 0; x < map.Width; x++) 80 for (x = startX; x <= endX; x++)
77 { 81 {
78 for (y = 0; y < map.Height; y++) 82 for (y = startY; y <= endY; y++)
79 { 83 {
80 if (!mask[x,y]) 84 if (!mask[x, y])
81 continue; 85 continue;
82 86
83 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 87 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
index f31c8b6..f52fe07 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
@@ -148,16 +148,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
148 148
149 #region ITerrainPaintableEffect Members 149 #region ITerrainPaintableEffect Members
150 150
151 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 151 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
152 double strength, double duration, int startX, int endX, int startY, int endY)
152 { 153 {
153 strength = TerrainUtil.MetersToSphericalStrength(strength); 154 strength = TerrainUtil.MetersToSphericalStrength(strength);
154 155
155 int x; 156 int x,y;
156 157
157 for (x = 0; x < map.Width; x++) 158 for (x = startX; x <= endX; x++)
158 { 159 {
159 int y; 160 for (y = startY; y <= endY; y++)
160 for (y = 0; y < map.Height; y++)
161 { 161 {
162 if (!mask[x,y]) 162 if (!mask[x,y])
163 continue; 163 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 932652c..925de2a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -75,6 +75,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
75 #endregion 75 #endregion
76 76
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78<<<<<<< HEAD
79=======
80
81#pragma warning disable 414
82 private static readonly string LogHeader = "[TERRAIN MODULE]";
83#pragma warning restore 414
84
85 private readonly Commander m_commander = new Commander("terrain");
86>>>>>>> avn/ubitvar
78 87
79#pragma warning disable 414 88#pragma warning disable 414
80 private static readonly string LogHeader = "[TERRAIN MODULE]"; 89 private static readonly string LogHeader = "[TERRAIN MODULE]";
@@ -86,6 +95,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
86 private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>(); 95 private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
87 private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = 96 private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
88 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 97 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
98<<<<<<< HEAD
89 private Dictionary<string, ITerrainEffect> m_plugineffects; 99 private Dictionary<string, ITerrainEffect> m_plugineffects;
90 private Dictionary<string, ITerrainModifier> m_modifyOperations = 100 private Dictionary<string, ITerrainModifier> m_modifyOperations =
91 new Dictionary<string, ITerrainModifier>(); 101 new Dictionary<string, ITerrainModifier>();
@@ -94,6 +104,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
94 private Scene m_scene; 104 private Scene m_scene;
95 private volatile bool m_tainted; 105 private volatile bool m_tainted;
96 private readonly Stack<LandUndoState> m_undo = new Stack<LandUndoState>(5); 106 private readonly Stack<LandUndoState> m_undo = new Stack<LandUndoState>(5);
107=======
108
109 private Dictionary<string, ITerrainEffect> m_plugineffects;
110 private ITerrainChannel m_channel;
111 private ITerrainChannel m_baked;
112 private Scene m_scene;
113 private volatile bool m_tainted;
114
115>>>>>>> avn/ubitvar
97 private String m_InitialTerrain = "pinhead-island"; 116 private String m_InitialTerrain = "pinhead-island";
98 117
99 // If true, send terrain patch updates to clients based on their view distance 118 // If true, send terrain patch updates to clients based on their view distance
@@ -107,13 +126,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
107 private bool[,] updated; // for each patch, whether it needs to be sent to this client 126 private bool[,] updated; // for each patch, whether it needs to be sent to this client
108 private int updateCount; // number of patches that need to be sent 127 private int updateCount; // number of patches that need to be sent
109 public ScenePresence Presence; // a reference to the client to send to 128 public ScenePresence Presence; // a reference to the client to send to
129<<<<<<< HEAD
110 public TerrainData Terrain; // reference to the underlying terrain 130 public TerrainData Terrain; // reference to the underlying terrain
131=======
132>>>>>>> avn/ubitvar
111 public PatchUpdates(TerrainData terrData, ScenePresence pPresence) 133 public PatchUpdates(TerrainData terrData, ScenePresence pPresence)
112 { 134 {
113 updated = new bool[terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize]; 135 updated = new bool[terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize];
114 updateCount = 0; 136 updateCount = 0;
115 Presence = pPresence; 137 Presence = pPresence;
138<<<<<<< HEAD
116 Terrain = terrData; 139 Terrain = terrData;
140=======
141>>>>>>> avn/ubitvar
117 // Initially, send all patches to the client 142 // Initially, send all patches to the client
118 SetAll(true); 143 SetAll(true);
119 } 144 }
@@ -122,17 +147,26 @@ namespace OpenSim.Region.CoreModules.World.Terrain
122 { 147 {
123 return (updateCount > 0); 148 return (updateCount > 0);
124 } 149 }
150<<<<<<< HEAD
125 151
152=======
153>>>>>>> avn/ubitvar
126 public void SetByXY(int x, int y, bool state) 154 public void SetByXY(int x, int y, bool state)
127 { 155 {
128 this.SetByPatch(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, state); 156 this.SetByPatch(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, state);
129 } 157 }
158<<<<<<< HEAD
130 159
160=======
161>>>>>>> avn/ubitvar
131 public bool GetByPatch(int patchX, int patchY) 162 public bool GetByPatch(int patchX, int patchY)
132 { 163 {
133 return updated[patchX, patchY]; 164 return updated[patchX, patchY];
134 } 165 }
166<<<<<<< HEAD
135 167
168=======
169>>>>>>> avn/ubitvar
136 public void SetByPatch(int patchX, int patchY, bool state) 170 public void SetByPatch(int patchX, int patchY, bool state)
137 { 171 {
138 bool prevState = updated[patchX, patchY]; 172 bool prevState = updated[patchX, patchY];
@@ -142,12 +176,20 @@ namespace OpenSim.Region.CoreModules.World.Terrain
142 updateCount--; 176 updateCount--;
143 updated[patchX, patchY] = state; 177 updated[patchX, patchY] = state;
144 } 178 }
179<<<<<<< HEAD
145 180
146 public void SetAll(bool state) 181 public void SetAll(bool state)
147 { 182 {
148 updateCount = 0; 183 updateCount = 0;
149 for(int xx = 0; xx < updated.GetLength(0); xx++) 184 for(int xx = 0; xx < updated.GetLength(0); xx++)
150 for(int yy = 0; yy < updated.GetLength(1); yy++) 185 for(int yy = 0; yy < updated.GetLength(1); yy++)
186=======
187 public void SetAll(bool state)
188 {
189 updateCount = 0;
190 for (int xx = 0; xx < updated.GetLength(0); xx++)
191 for (int yy = 0; yy < updated.GetLength(1); yy++)
192>>>>>>> avn/ubitvar
151 updated[xx, yy] = state; 193 updated[xx, yy] = state;
152 if (state) 194 if (state)
153 updateCount = updated.GetLength(0) * updated.GetLength(1); 195 updateCount = updated.GetLength(0) * updated.GetLength(1);
@@ -164,9 +206,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
164 terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize) 206 terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize)
165 ); 207 );
166 } 208 }
209<<<<<<< HEAD
167 for(int xx = 0; xx < terrData.SizeX; xx += Constants.TerrainPatchSize) 210 for(int xx = 0; xx < terrData.SizeX; xx += Constants.TerrainPatchSize)
168 { 211 {
169 for(int yy = 0; yy < terrData.SizeY; yy += Constants.TerrainPatchSize) 212 for(int yy = 0; yy < terrData.SizeY; yy += Constants.TerrainPatchSize)
213=======
214 for (int xx = 0; xx < terrData.SizeX; xx += Constants.TerrainPatchSize)
215 {
216 for (int yy = 0; yy < terrData.SizeY; yy += Constants.TerrainPatchSize)
217>>>>>>> avn/ubitvar
170 { 218 {
171 // Only set tainted. The patch bit may be set if the patch was to be sent later. 219 // Only set tainted. The patch bit may be set if the patch was to be sent later.
172 if (terrData.IsTaintedAt(xx, yy, false)) 220 if (terrData.IsTaintedAt(xx, yy, false))
@@ -227,12 +275,20 @@ namespace OpenSim.Region.CoreModules.World.Terrain
227 (int)m_scene.RegionInfo.RegionSizeY, 275 (int)m_scene.RegionInfo.RegionSizeY,
228 (int)m_scene.RegionInfo.RegionSizeZ); 276 (int)m_scene.RegionInfo.RegionSizeZ);
229 m_scene.Heightmap = m_channel; 277 m_scene.Heightmap = m_channel;
278<<<<<<< HEAD
230 UpdateRevertMap(); 279 UpdateRevertMap();
280=======
281 UpdateBakedMap();
282>>>>>>> avn/ubitvar
231 } 283 }
232 else 284 else
233 { 285 {
234 m_channel = m_scene.Heightmap; 286 m_channel = m_scene.Heightmap;
287<<<<<<< HEAD
235 UpdateRevertMap(); 288 UpdateRevertMap();
289=======
290 UpdateBakedMap();
291>>>>>>> avn/ubitvar
236 } 292 }
237 293
238 m_scene.RegisterModuleInterface<ITerrainModule>(this); 294 m_scene.RegisterModuleInterface<ITerrainModule>(this);
@@ -240,7 +296,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
240 m_scene.EventManager.OnClientClosed += EventManager_OnClientClosed; 296 m_scene.EventManager.OnClientClosed += EventManager_OnClientClosed;
241 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; 297 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
242 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; 298 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
299<<<<<<< HEAD
243 m_scene.EventManager.OnFrame += EventManager_OnFrame; 300 m_scene.EventManager.OnFrame += EventManager_OnFrame;
301=======
302 m_scene.EventManager.OnTerrainCheckUpdates += EventManager_TerrainCheckUpdates;
303>>>>>>> avn/ubitvar
244 } 304 }
245 305
246 InstallDefaultEffects(); 306 InstallDefaultEffects();
@@ -279,7 +339,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
279 // remove the commands 339 // remove the commands
280 m_scene.UnregisterModuleCommander(m_commander.Name); 340 m_scene.UnregisterModuleCommander(m_commander.Name);
281 // remove the event-handlers 341 // remove the event-handlers
342<<<<<<< HEAD
282 m_scene.EventManager.OnFrame -= EventManager_OnFrame; 343 m_scene.EventManager.OnFrame -= EventManager_OnFrame;
344=======
345 m_scene.EventManager.OnTerrainCheckUpdates -= EventManager_TerrainCheckUpdates;
346>>>>>>> avn/ubitvar
283 m_scene.EventManager.OnTerrainTick -= EventManager_OnTerrainTick; 347 m_scene.EventManager.OnTerrainTick -= EventManager_OnTerrainTick;
284 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole; 348 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
285 m_scene.EventManager.OnClientClosed -= EventManager_OnClientClosed; 349 m_scene.EventManager.OnClientClosed -= EventManager_OnClientClosed;
@@ -334,7 +398,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
334 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height); 398 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height);
335 m_scene.Heightmap = channel; 399 m_scene.Heightmap = channel;
336 m_channel = channel; 400 m_channel = channel;
337 UpdateRevertMap(); 401 UpdateBakedMap();
338 } 402 }
339 catch(NotImplementedException) 403 catch(NotImplementedException)
340 { 404 {
@@ -426,7 +490,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
426 { 490 {
427 ITerrainChannel channel = loader.Value.LoadStream(stream); 491 ITerrainChannel channel = loader.Value.LoadStream(stream);
428 m_channel.Merge(channel, displacement, radianRotation, rotationDisplacement); 492 m_channel.Merge(channel, displacement, radianRotation, rotationDisplacement);
493<<<<<<< HEAD
429 UpdateRevertMap(); 494 UpdateRevertMap();
495=======
496 UpdateBakedMap();
497>>>>>>> avn/ubitvar
430 } 498 }
431 catch(NotImplementedException) 499 catch(NotImplementedException)
432 { 500 {
@@ -506,16 +574,48 @@ namespace OpenSim.Region.CoreModules.World.Terrain
506 574
507 // Someone diddled terrain outside the normal code paths. Set the taintedness for all clients. 575 // Someone diddled terrain outside the normal code paths. Set the taintedness for all clients.
508 // ITerrainModule.TaintTerrain() 576 // ITerrainModule.TaintTerrain()
577<<<<<<< HEAD
509 public void TaintTerrain() 578 public void TaintTerrain()
510 { 579 {
511 lock(m_perClientPatchUpdates) 580 lock(m_perClientPatchUpdates)
512 { 581 {
513 // Set the flags for all clients so the tainted patches will be sent out 582 // Set the flags for all clients so the tainted patches will be sent out
514 foreach(PatchUpdates pups in m_perClientPatchUpdates.Values) 583 foreach(PatchUpdates pups in m_perClientPatchUpdates.Values)
584=======
585 public void TaintTerrain ()
586 {
587 lock (m_perClientPatchUpdates)
588 {
589 // Set the flags for all clients so the tainted patches will be sent out
590 foreach (PatchUpdates pups in m_perClientPatchUpdates.Values)
591>>>>>>> avn/ubitvar
515 { 592 {
516 pups.SetAll(m_scene.Heightmap.GetTerrainData()); 593 pups.SetAll(m_scene.Heightmap.GetTerrainData());
517 } 594 }
518 } 595 }
596<<<<<<< HEAD
597=======
598 }
599
600 // ITerrainModule.PushTerrain()
601 public void PushTerrain(IClientAPI pClient)
602 {
603 ScenePresence presence = m_scene.GetScenePresence(pClient.AgentId);
604 if (presence != null)
605 {
606 lock (m_perClientPatchUpdates)
607 {
608 PatchUpdates pups;
609 if (!m_perClientPatchUpdates.TryGetValue(pClient.AgentId, out pups))
610 {
611 // There is a ScenePresence without a send patch map. Create one.
612 pups = new PatchUpdates(m_scene.Heightmap.GetTerrainData(), presence);
613 m_perClientPatchUpdates.Add(presence.UUID, pups);
614 }
615 pups.SetAll(true);
616 }
617 }
618>>>>>>> avn/ubitvar
519 } 619 }
520 620
521 // ITerrainModule.PushTerrain() 621 // ITerrainModule.PushTerrain()
@@ -636,7 +736,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
636 m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere(); 736 m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere();
637 m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere(); 737 m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere();
638 m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere(); 738 m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere();
639 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert); 739 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_baked);
640 m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere(); 740 m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere();
641 m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere(); 741 m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere();
642 m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere(); 742 m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere();
@@ -647,7 +747,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
647 m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea(); 747 m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea();
648 m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea(); 748 m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea();
649 m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); 749 m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea();
650 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); 750 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_baked);
651 751
652 // Terrain Modifier operations 752 // Terrain Modifier operations
653 m_modifyOperations["min"] = new MinModifier(this); 753 m_modifyOperations["min"] = new MinModifier(this);
@@ -673,10 +773,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
673 } 773 }
674 774
675 /// <summary> 775 /// <summary>
676 /// Saves the current state of the region into the revert map buffer. 776 /// Saves the current state of the region into the baked map buffer.
777
677 /// </summary> 778 /// </summary>
678 public void UpdateRevertMap() 779 public void UpdateBakedMap()
679 { 780 {
781<<<<<<< HEAD
680 /* 782 /*
681 int x; 783 int x;
682 for (x = 0; x < m_channel.Width; x++) 784 for (x = 0; x < m_channel.Width; x++)
@@ -689,6 +791,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
689 } 791 }
690 */ 792 */
691 m_revert = m_channel.MakeCopy(); 793 m_revert = m_channel.MakeCopy();
794=======
795 m_baked = m_channel.MakeCopy();
796 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_baked);
797 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_baked);
798>>>>>>> avn/ubitvar
692 } 799 }
693 800
694 /// <summary> 801 /// <summary>
@@ -715,11 +822,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
715 { 822 {
716 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, 823 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
717 fileWidth, fileHeight, 824 fileWidth, fileHeight,
825<<<<<<< HEAD
718 (int)m_scene.RegionInfo.RegionSizeX, 826 (int)m_scene.RegionInfo.RegionSizeX,
719 (int)m_scene.RegionInfo.RegionSizeY); 827 (int)m_scene.RegionInfo.RegionSizeY);
828=======
829 (int) m_scene.RegionInfo.RegionSizeX,
830 (int) m_scene.RegionInfo.RegionSizeY);
831>>>>>>> avn/ubitvar
720 m_scene.Heightmap = channel; 832 m_scene.Heightmap = channel;
721 m_channel = channel; 833 m_channel = channel;
722 UpdateRevertMap(); 834 UpdateBakedMap();
723 } 835 }
724 836
725 return; 837 return;
@@ -782,12 +894,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
782 } 894 }
783 895
784 /// <summary> 896 /// <summary>
897<<<<<<< HEAD
785 /// Called before processing of every simulation frame. 898 /// Called before processing of every simulation frame.
899=======
900>>>>>>> avn/ubitvar
786 /// This is used to check to see of any of the terrain is tainted and, if so, schedule 901 /// This is used to check to see of any of the terrain is tainted and, if so, schedule
787 /// updates for all the presences. 902 /// updates for all the presences.
788 /// This also checks to see if there are updates that need to be sent for each presence. 903 /// This also checks to see if there are updates that need to be sent for each presence.
789 /// This is where the logic is to send terrain updates to clients. 904 /// This is where the logic is to send terrain updates to clients.
790 /// </summary> 905 /// </summary>
906<<<<<<< HEAD
791 private void EventManager_OnFrame() 907 private void EventManager_OnFrame()
792 { 908 {
793 TerrainData terrData = m_channel.GetTerrainData(); 909 TerrainData terrData = m_channel.GetTerrainData();
@@ -798,6 +914,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
798 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 914 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
799 { 915 {
800 if (terrData.IsTaintedAt(x, y)) 916 if (terrData.IsTaintedAt(x, y))
917=======
918 private void EventManager_TerrainCheckUpdates()
919 {
920 // this needs fixing
921 TerrainData terrData = m_channel.GetTerrainData();
922
923 bool shouldTaint = false;
924 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
925 {
926 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
927 {
928 if (terrData.IsTaintedAt(x, y,true))
929>>>>>>> avn/ubitvar
801 { 930 {
802 // Found a patch that was modified. Push this flag into the clients. 931 // Found a patch that was modified. Push this flag into the clients.
803 SendToClients(terrData, x, y); 932 SendToClients(terrData, x, y);
@@ -815,6 +944,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
815 m_scene.EventManager.TriggerTerrainTainted(); 944 m_scene.EventManager.TriggerTerrainTainted();
816 m_tainted = true; 945 m_tainted = true;
817 } 946 }
947<<<<<<< HEAD
948=======
949
950>>>>>>> avn/ubitvar
818 } 951 }
819 952
820 /// <summary> 953 /// <summary>
@@ -883,11 +1016,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain
883 presence.ControllingClient.OnLandUndo -= client_OnLandUndo; 1016 presence.ControllingClient.OnLandUndo -= client_OnLandUndo;
884 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain; 1017 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain;
885 } 1018 }
1019<<<<<<< HEAD
886 1020
887 lock(m_perClientPatchUpdates) 1021 lock(m_perClientPatchUpdates)
888 m_perClientPatchUpdates.Remove(client); 1022 m_perClientPatchUpdates.Remove(client);
889 } 1023 }
1024=======
1025>>>>>>> avn/ubitvar
890 1026
1027 lock (m_perClientPatchUpdates)
1028 m_perClientPatchUpdates.Remove(client);
1029 }
1030
891 /// <summary> 1031 /// <summary>
892 /// Scan over changes in the terrain and limit height changes. This enforces the 1032 /// Scan over changes in the terrain and limit height changes. This enforces the
893 /// non-estate owner limits on rate of terrain editting. 1033 /// non-estate owner limits on rate of terrain editting.
@@ -898,12 +1038,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain
898 TerrainData terrData = m_channel.GetTerrainData(); 1038 TerrainData terrData = m_channel.GetTerrainData();
899 1039
900 bool wasLimited = false; 1040 bool wasLimited = false;
1041<<<<<<< HEAD
901 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize) 1042 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
902 { 1043 {
903 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 1044 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
904 { 1045 {
905 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */)) 1046 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */))
906 { 1047 {
1048=======
1049 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
1050 {
1051 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
1052 {
1053 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */))
1054 {
1055>>>>>>> avn/ubitvar
907 // If we should respect the estate settings then 1056 // If we should respect the estate settings then
908 // fixup and height deltas that don't respect them. 1057 // fixup and height deltas that don't respect them.
909 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values. 1058 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values.
@@ -926,13 +1075,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain
926 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit; 1075 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
927 1076
928 // loop through the height map for this patch and compare it against 1077 // loop through the height map for this patch and compare it against
1078<<<<<<< HEAD
929 // the revert map 1079 // the revert map
930 for(int x = xStart; x < xStart + Constants.TerrainPatchSize; x++) 1080 for(int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
1081=======
1082 // the baked map
1083 for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
1084>>>>>>> avn/ubitvar
931 { 1085 {
932 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++) 1086 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++)
933 { 1087 {
934 float requestedHeight = terrData[x, y]; 1088 float requestedHeight = terrData[x, y];
1089<<<<<<< HEAD
935 float bakedHeight = (float)m_revert[x, y]; 1090 float bakedHeight = (float)m_revert[x, y];
1091=======
1092 float bakedHeight = (float)m_baked[x, y];
1093>>>>>>> avn/ubitvar
936 float requestedDelta = requestedHeight - bakedHeight; 1094 float requestedDelta = requestedHeight - bakedHeight;
937 1095
938 if (requestedDelta > maxDelta) 1096 if (requestedDelta > maxDelta)
@@ -953,6 +1111,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
953 1111
954 private void client_OnLandUndo(IClientAPI client) 1112 private void client_OnLandUndo(IClientAPI client)
955 { 1113 {
1114<<<<<<< HEAD
956 lock(m_undo) 1115 lock(m_undo)
957 { 1116 {
958 if (m_undo.Count > 0) 1117 if (m_undo.Count > 0)
@@ -962,6 +1121,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
962 goback.PlaybackState(); 1121 goback.PlaybackState();
963 } 1122 }
964 } 1123 }
1124=======
1125
1126>>>>>>> avn/ubitvar
965 } 1127 }
966 1128
967 /// <summary> 1129 /// <summary>
@@ -971,6 +1133,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
971 /// <param name="x">The patch corner to send</param> 1133 /// <param name="x">The patch corner to send</param>
972 /// <param name="y">The patch corner to send</param> 1134 /// <param name="y">The patch corner to send</param>
973 private void SendToClients(TerrainData terrData, int x, int y) 1135 private void SendToClients(TerrainData terrData, int x, int y)
1136<<<<<<< HEAD
974 { 1137 {
975 if (m_sendTerrainUpdatesByViewDistance) 1138 if (m_sendTerrainUpdatesByViewDistance)
976 { 1139 {
@@ -1138,6 +1301,181 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1138 ret.Add(new PatchesToSend(x, y, dist)); 1301 ret.Add(new PatchesToSend(x, y, dist));
1139 } 1302 }
1140 } 1303 }
1304=======
1305 {
1306 // Add that this patch needs to be sent to the accounting for each client.
1307 lock (m_perClientPatchUpdates)
1308 {
1309 m_scene.ForEachScenePresence(presence =>
1310 {
1311 PatchUpdates thisClientUpdates;
1312 if (!m_perClientPatchUpdates.TryGetValue(presence.UUID, out thisClientUpdates))
1313 {
1314 // There is a ScenePresence without a send patch map. Create one.
1315 thisClientUpdates = new PatchUpdates(terrData, presence);
1316 m_perClientPatchUpdates.Add(presence.UUID, thisClientUpdates);
1317 }
1318 thisClientUpdates.SetByXY(x, y, true);
1319 }
1320 );
1321 }
1322 }
1323
1324 private class PatchesToSend : IComparable<PatchesToSend>
1325 {
1326 public int PatchX;
1327 public int PatchY;
1328 public float Dist;
1329 public PatchesToSend(int pX, int pY, float pDist)
1330 {
1331 PatchX = pX;
1332 PatchY = pY;
1333 Dist = pDist;
1334 }
1335 public int CompareTo(PatchesToSend other)
1336 {
1337 return Dist.CompareTo(other.Dist);
1338 }
1339 }
1340
1341 // Called each frame time to see if there are any patches to send to any of the
1342 // ScenePresences.
1343 // Loop through all the per-client info and send any patches necessary.
1344 private void CheckSendingPatchesToClients()
1345 {
1346 lock (m_perClientPatchUpdates)
1347 {
1348 foreach (PatchUpdates pups in m_perClientPatchUpdates.Values)
1349 {
1350 // throught acording to land queue free to send bytes
1351 if (!pups.Presence.ControllingClient.CanSendLayerData())
1352 continue;
1353
1354 if (pups.HasUpdates())
1355 {
1356 // There is something that could be sent to this client.
1357 List<PatchesToSend> toSend = GetModifiedPatchesInViewDistance(pups);
1358 if (toSend.Count > 0)
1359 {
1360 // m_log.DebugFormat("{0} CheckSendingPatchesToClient: sending {1} patches to {2} in region {3}",
1361 // LogHeader, toSend.Count, pups.Presence.Name, m_scene.RegionInfo.RegionName);
1362 // Sort the patches to send by the distance from the presence
1363 toSend.Sort();
1364 /*
1365 foreach (PatchesToSend pts in toSend)
1366 {
1367 pups.Presence.ControllingClient.SendLayerData(pts.PatchX, pts.PatchY, null);
1368 // presence.ControllingClient.SendLayerData(xs.ToArray(), ys.ToArray(), null, TerrainPatch.LayerType.Land);
1369 }
1370 */
1371
1372 int[] xPieces = new int[toSend.Count];
1373 int[] yPieces = new int[toSend.Count];
1374 float[] patchPieces = new float[toSend.Count * 2];
1375 int pieceIndex = 0;
1376 foreach (PatchesToSend pts in toSend)
1377 {
1378 patchPieces[pieceIndex++] = pts.PatchX;
1379 patchPieces[pieceIndex++] = pts.PatchY;
1380 }
1381 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces);
1382 }
1383 }
1384 }
1385 }
1386 }
1387
1388 private List<PatchesToSend> GetModifiedPatchesInViewDistance(PatchUpdates pups)
1389 {
1390 List<PatchesToSend> ret = new List<PatchesToSend>();
1391
1392 int npatchs = 0;
1393
1394 ScenePresence presence = pups.Presence;
1395 if (presence == null)
1396 return ret;
1397
1398 float minz = presence.AbsolutePosition.Z;
1399 if (presence.CameraPosition.Z < minz)
1400 minz = presence.CameraPosition.Z;
1401
1402 // this limit should be max terrainheight + max draw
1403 if (minz > 1500f)
1404 return ret;
1405
1406 int DrawDistance = (int)presence.DrawDistance;
1407
1408 DrawDistance = DrawDistance / Constants.TerrainPatchSize;
1409
1410 int testposX;
1411 int testposY;
1412
1413 if (Math.Abs(presence.AbsolutePosition.X - presence.CameraPosition.X) > 30
1414 || Math.Abs(presence.AbsolutePosition.Y - presence.CameraPosition.Y) > 30)
1415 {
1416 testposX = (int)presence.CameraPosition.X / Constants.TerrainPatchSize;
1417 testposY = (int)presence.CameraPosition.Y / Constants.TerrainPatchSize;
1418 }
1419 else
1420 {
1421 testposX = (int)presence.AbsolutePosition.X / Constants.TerrainPatchSize;
1422 testposY = (int)presence.AbsolutePosition.Y / Constants.TerrainPatchSize;
1423 }
1424 int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize;
1425 int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize;
1426
1427 // Compute the area of patches within our draw distance
1428 int startX = testposX - DrawDistance;
1429 if (startX < 0)
1430 startX = 0;
1431 else if (startX > limitX)
1432 startX = limitX;
1433
1434 int startY = testposY - DrawDistance;
1435 if (startY < 0)
1436 startY = 0;
1437 else if (startY > limitY)
1438 startY = limitY;
1439
1440 int endX = testposX + DrawDistance;
1441 if (endX < 0)
1442 endX = 0;
1443 else if (endX > limitX)
1444 endX = limitX;
1445
1446 int endY = testposY + DrawDistance;
1447 if (endY < 0)
1448 endY = 0;
1449 else if (endY > limitY)
1450 endY = limitY;
1451
1452 int distx;
1453 int disty;
1454 int distsq;
1455
1456 DrawDistance *= DrawDistance;
1457
1458 for (int x = startX; x < endX; x++)
1459 {
1460 for (int y = startY; y < endY; y++)
1461 {
1462 if (pups.GetByPatch(x, y))
1463 {
1464 distx = x - testposX;
1465 disty = y - testposY;
1466 distsq = distx * distx + disty * disty;
1467 if (distsq < DrawDistance)
1468 {
1469 pups.SetByPatch(x, y, false);
1470 ret.Add(new PatchesToSend(x, y, (float)distsq));
1471 if (npatchs++ > 65536)
1472 {
1473 y = endY;
1474 x = endX;
1475 }
1476 }
1477 }
1478>>>>>>> avn/ubitvar
1141 } 1479 }
1142 } 1480 }
1143 return ret; 1481 return ret;
@@ -1161,6 +1499,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1161 int zx = (int)(west + 0.5); 1499 int zx = (int)(west + 0.5);
1162 int zy = (int)(north + 0.5); 1500 int zy = (int)(north + 0.5);
1163 1501
1502<<<<<<< HEAD
1164 int dx; 1503 int dx;
1165 for(dx=-n; dx<=n; dx++) 1504 for(dx=-n; dx<=n; dx++)
1166 { 1505 {
@@ -1176,16 +1515,52 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1176 allowMask[x, y] = true; 1515 allowMask[x, y] = true;
1177 allowed = true; 1516 allowed = true;
1178 } 1517 }
1518=======
1519
1520 int startX = zx - n;
1521 if (startX < 0)
1522 startX = 0;
1523
1524 int startY = zy - n;
1525 if (startY < 0)
1526 startY = 0;
1527
1528 int endX = zx + n;
1529 if (endX >= m_channel.Width)
1530 endX = m_channel.Width - 1;
1531 int endY = zy + n;
1532 if (endY >= m_channel.Height)
1533 endY = m_channel.Height - 1;
1534
1535 int x, y;
1536
1537 for (x = startX; x <= endX; x++)
1538 {
1539 for (y = startY; y <= endY; y++)
1540 {
1541 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
1542 {
1543 allowMask[x, y] = true;
1544 allowed = true;
1545>>>>>>> avn/ubitvar
1179 } 1546 }
1180 } 1547 }
1181 } 1548 }
1182 if (allowed) 1549 if (allowed)
1183 { 1550 {
1184 StoreUndoState(); 1551 StoreUndoState();
1552<<<<<<< HEAD
1185 m_painteffects[(StandardTerrainEffects)action].PaintEffect( 1553 m_painteffects[(StandardTerrainEffects)action].PaintEffect(
1186 m_channel, allowMask, west, south, height, size, seconds); 1554 m_channel, allowMask, west, south, height, size, seconds);
1187 1555
1188 //revert changes outside estate limits 1556 //revert changes outside estate limits
1557=======
1558 m_painteffects[(StandardTerrainEffects) action].PaintEffect(
1559 m_channel, allowMask, west, south, height, size, seconds,
1560 startX, endX, startY, endY);
1561
1562 //block changes outside estate limits
1563>>>>>>> avn/ubitvar
1189 if (!god) 1564 if (!god)
1190 EnforceEstateLimits(); 1565 EnforceEstateLimits();
1191 } 1566 }
@@ -1225,9 +1600,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1225 if (allowed) 1600 if (allowed)
1226 { 1601 {
1227 StoreUndoState(); 1602 StoreUndoState();
1603<<<<<<< HEAD
1228 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size); 1604 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size);
1229 1605
1230 //revert changes outside estate limits 1606 //revert changes outside estate limits
1607=======
1608 m_floodeffects[(StandardTerrainEffects) action].FloodEffect(m_channel, fillArea, size);
1609
1610 //block changes outside estate limits
1611>>>>>>> avn/ubitvar
1231 if (!god) 1612 if (!god)
1232 EnforceEstateLimits(); 1613 EnforceEstateLimits();
1233 } 1614 }
@@ -1260,6 +1641,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1260 1641
1261 private void StoreUndoState() 1642 private void StoreUndoState()
1262 { 1643 {
1644<<<<<<< HEAD
1263 lock(m_undo) 1645 lock(m_undo)
1264 { 1646 {
1265 if (m_undo.Count > 0) 1647 if (m_undo.Count > 0)
@@ -1275,22 +1657,36 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1275 LandUndoState nUndo = new LandUndoState(this, m_channel); 1657 LandUndoState nUndo = new LandUndoState(this, m_channel);
1276 m_undo.Push(nUndo); 1658 m_undo.Push(nUndo);
1277 } 1659 }
1660=======
1661>>>>>>> avn/ubitvar
1278 } 1662 }
1279 1663
1280 #region Console Commands 1664 #region Console Commands
1281 1665
1282 private void InterfaceLoadFile(Object[] args) 1666 private void InterfaceLoadFile(Object[] args)
1283 { 1667 {
1668<<<<<<< HEAD
1284 LoadFromFile((string)args[0]); 1669 LoadFromFile((string)args[0]);
1670=======
1671 LoadFromFile((string) args[0]);
1672>>>>>>> avn/ubitvar
1285 } 1673 }
1286 1674
1287 private void InterfaceLoadTileFile(Object[] args) 1675 private void InterfaceLoadTileFile(Object[] args)
1288 { 1676 {
1677<<<<<<< HEAD
1289 LoadFromFile((string)args[0], 1678 LoadFromFile((string)args[0],
1290 (int)args[1], 1679 (int)args[1],
1291 (int)args[2], 1680 (int)args[2],
1292 (int)args[3], 1681 (int)args[3],
1293 (int)args[4]); 1682 (int)args[4]);
1683=======
1684 LoadFromFile((string) args[0],
1685 (int) args[1],
1686 (int) args[2],
1687 (int) args[3],
1688 (int) args[4]);
1689>>>>>>> avn/ubitvar
1294 } 1690 }
1295 1691
1296 private void InterfaceSaveFile(Object[] args) 1692 private void InterfaceSaveFile(Object[] args)
@@ -1309,15 +1705,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1309 1705
1310 private void InterfaceBakeTerrain(Object[] args) 1706 private void InterfaceBakeTerrain(Object[] args)
1311 { 1707 {
1312 UpdateRevertMap(); 1708 UpdateBakedMap();
1313 } 1709 }
1314 1710
1315 private void InterfaceRevertTerrain(Object[] args) 1711 private void InterfaceRevertTerrain(Object[] args)
1316 { 1712 {
1317 int x, y; 1713 int x, y;
1714<<<<<<< HEAD
1318 for(x = 0; x < m_channel.Width; x++) 1715 for(x = 0; x < m_channel.Width; x++)
1319 for(y = 0; y < m_channel.Height; y++) 1716 for(y = 0; y < m_channel.Height; y++)
1320 m_channel[x, y] = m_revert[x, y]; 1717 m_channel[x, y] = m_revert[x, y];
1718=======
1719 for (x = 0; x < m_channel.Width; x++)
1720 for (y = 0; y < m_channel.Height; y++)
1721 m_channel[x, y] = m_baked[x, y];
1722>>>>>>> avn/ubitvar
1321 1723
1322 } 1724 }
1323 1725
@@ -1327,9 +1729,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1327 1729
1328 if (direction.ToLower().StartsWith("y")) 1730 if (direction.ToLower().StartsWith("y"))
1329 { 1731 {
1732<<<<<<< HEAD
1330 for(int x = 0; x < m_channel.Width; x++) 1733 for(int x = 0; x < m_channel.Width; x++)
1331 { 1734 {
1332 for(int y = 0; y < m_channel.Height / 2; y++) 1735 for(int y = 0; y < m_channel.Height / 2; y++)
1736=======
1737 for (int x = 0; x < m_channel.Width; x++)
1738 {
1739 for (int y = 0; y < m_channel.Height / 2; y++)
1740>>>>>>> avn/ubitvar
1333 { 1741 {
1334 double height = m_channel[x, y]; 1742 double height = m_channel[x, y];
1335 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y]; 1743 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y];
@@ -1341,9 +1749,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1341 } 1749 }
1342 else if (direction.ToLower().StartsWith("x")) 1750 else if (direction.ToLower().StartsWith("x"))
1343 { 1751 {
1752<<<<<<< HEAD
1344 for(int y = 0; y < m_channel.Height; y++) 1753 for(int y = 0; y < m_channel.Height; y++)
1345 { 1754 {
1346 for(int x = 0; x < m_channel.Width / 2; x++) 1755 for(int x = 0; x < m_channel.Width / 2; x++)
1756=======
1757 for (int y = 0; y < m_channel.Height; y++)
1758 {
1759 for (int x = 0; x < m_channel.Width / 2; x++)
1760>>>>>>> avn/ubitvar
1347 { 1761 {
1348 double height = m_channel[x, y]; 1762 double height = m_channel[x, y];
1349 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y]; 1763 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y];
@@ -1420,45 +1834,81 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1420 1834
1421 private void InterfaceElevateTerrain(Object[] args) 1835 private void InterfaceElevateTerrain(Object[] args)
1422 { 1836 {
1837 double val = (double)args[0];
1838
1423 int x, y; 1839 int x, y;
1840<<<<<<< HEAD
1424 for(x = 0; x < m_channel.Width; x++) 1841 for(x = 0; x < m_channel.Width; x++)
1425 for(y = 0; y < m_channel.Height; y++) 1842 for(y = 0; y < m_channel.Height; y++)
1426 m_channel[x, y] += (double)args[0]; 1843 m_channel[x, y] += (double)args[0];
1844=======
1845 for (x = 0; x < m_channel.Width; x++)
1846 for (y = 0; y < m_channel.Height; y++)
1847 m_channel[x, y] += val;
1848>>>>>>> avn/ubitvar
1427 } 1849 }
1428 1850
1429 private void InterfaceMultiplyTerrain(Object[] args) 1851 private void InterfaceMultiplyTerrain(Object[] args)
1430 { 1852 {
1431 int x, y; 1853 int x, y;
1854<<<<<<< HEAD
1432 for(x = 0; x < m_channel.Width; x++) 1855 for(x = 0; x < m_channel.Width; x++)
1433 for(y = 0; y < m_channel.Height; y++) 1856 for(y = 0; y < m_channel.Height; y++)
1434 m_channel[x, y] *= (double)args[0]; 1857 m_channel[x, y] *= (double)args[0];
1858=======
1859 double val = (double)args[0];
1860
1861 for (x = 0; x < m_channel.Width; x++)
1862 for (y = 0; y < m_channel.Height; y++)
1863 m_channel[x, y] *= val;
1864>>>>>>> avn/ubitvar
1435 } 1865 }
1436 1866
1437 private void InterfaceLowerTerrain(Object[] args) 1867 private void InterfaceLowerTerrain(Object[] args)
1438 { 1868 {
1439 int x, y; 1869 int x, y;
1870<<<<<<< HEAD
1440 for(x = 0; x < m_channel.Width; x++) 1871 for(x = 0; x < m_channel.Width; x++)
1441 for(y = 0; y < m_channel.Height; y++) 1872 for(y = 0; y < m_channel.Height; y++)
1442 m_channel[x, y] -= (double)args[0]; 1873 m_channel[x, y] -= (double)args[0];
1874=======
1875 double val = (double)args[0];
1876
1877 for (x = 0; x < m_channel.Width; x++)
1878 for (y = 0; y < m_channel.Height; y++)
1879 m_channel[x, y] -= val;
1880>>>>>>> avn/ubitvar
1443 } 1881 }
1444 1882
1445 public void InterfaceFillTerrain(Object[] args) 1883 public void InterfaceFillTerrain(Object[] args)
1446 { 1884 {
1447 int x, y; 1885 int x, y;
1886 double val = (double)args[0];
1448 1887
1888<<<<<<< HEAD
1449 for(x = 0; x < m_channel.Width; x++) 1889 for(x = 0; x < m_channel.Width; x++)
1450 for(y = 0; y < m_channel.Height; y++) 1890 for(y = 0; y < m_channel.Height; y++)
1451 m_channel[x, y] = (double)args[0]; 1891 m_channel[x, y] = (double)args[0];
1892=======
1893 for (x = 0; x < m_channel.Width; x++)
1894 for (y = 0; y < m_channel.Height; y++)
1895 m_channel[x, y] = val;
1896>>>>>>> avn/ubitvar
1452 } 1897 }
1453 1898
1454 private void InterfaceMinTerrain(Object[] args) 1899 private void InterfaceMinTerrain(Object[] args)
1455 { 1900 {
1456 int x, y; 1901 int x, y;
1902<<<<<<< HEAD
1457 for(x = 0; x < m_channel.Width; x++) 1903 for(x = 0; x < m_channel.Width; x++)
1904=======
1905 double val = (double)args[0];
1906 for (x = 0; x < m_channel.Width; x++)
1907>>>>>>> avn/ubitvar
1458 { 1908 {
1459 for(y = 0; y < m_channel.Height; y++) 1909 for(y = 0; y < m_channel.Height; y++)
1460 { 1910 {
1461 m_channel[x, y] = Math.Max((double)args[0], m_channel[x, y]); 1911 m_channel[x, y] = Math.Max(val, m_channel[x, y]);
1462 } 1912 }
1463 } 1913 }
1464 } 1914 }
@@ -1466,13 +1916,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1466 private void InterfaceMaxTerrain(Object[] args) 1916 private void InterfaceMaxTerrain(Object[] args)
1467 { 1917 {
1468 int x, y; 1918 int x, y;
1919<<<<<<< HEAD
1469 for(x = 0; x < m_channel.Width; x++) 1920 for(x = 0; x < m_channel.Width; x++)
1921=======
1922 double val = (double)args[0];
1923 for (x = 0; x < m_channel.Width; x++)
1924>>>>>>> avn/ubitvar
1470 { 1925 {
1471 for(y = 0; y < m_channel.Height; y++) 1926 for(y = 0; y < m_channel.Height; y++)
1472 { 1927 {
1473 m_channel[x, y] = Math.Min((double)args[0], m_channel[x, y]); 1928 m_channel[x, y] = Math.Min(val, m_channel[x, y]);
1474 } 1929 }
1475 } 1930 }
1931<<<<<<< HEAD
1476 } 1932 }
1477 1933
1478 private void InterfaceShow(Object[] args) 1934 private void InterfaceShow(Object[] args)
@@ -1488,6 +1944,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1488 double height = m_channel[(int)point.X, (int)point.Y]; 1944 double height = m_channel[(int)point.X, (int)point.Y];
1489 1945
1490 Console.WriteLine("Terrain height at {0} is {1}", point, height); 1946 Console.WriteLine("Terrain height at {0} is {1}", point, height);
1947=======
1948>>>>>>> avn/ubitvar
1491 } 1949 }
1492 1950
1493 private void InterfaceShowDebugStats(Object[] args) 1951 private void InterfaceShowDebugStats(Object[] args)
@@ -1620,9 +2078,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1620 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); 2078 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
1621 2079
1622 Command bakeRegionCommand = 2080 Command bakeRegionCommand =
1623 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); 2081 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions baked map.");
1624 Command revertRegionCommand = 2082 Command revertRegionCommand =
1625 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); 2083 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the baked map terrain into the regions heightmap.");
1626 2084
1627 Command flipCommand = 2085 Command flipCommand =
1628 new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); 2086 new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis");
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
index 29e80ef..40db370 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
@@ -60,7 +60,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
60 TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize); 60 TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
61 ITerrainPaintableEffect effect = new RaiseSphere(); 61 ITerrainPaintableEffect effect = new RaiseSphere();
62 62
63<<<<<<< HEAD
63 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); 64 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0);
65=======
66 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
67 0, midRegion - 1,0, (int)Constants.RegionSize -1);
68>>>>>>> avn/ubitvar
64 Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128)."); 69 Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
65 Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128)."); 70 Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
66 Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128)."); 71 Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
@@ -79,7 +84,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
79 } 84 }
80 effect = new LowerSphere(); 85 effect = new LowerSphere();
81 86
87<<<<<<< HEAD
82 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); 88 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0);
89=======
90 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
91 0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
92>>>>>>> avn/ubitvar
83 Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128)."); 93 Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
84 Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128)."); 94 Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
85 Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128)."); 95 Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
index 9534ad3..77c10b8 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
@@ -79,9 +79,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
79 /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting 79 /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting
80 /// Note we create a 256x256 dimension texture even if the actual terrain is larger. 80 /// Note we create a 256x256 dimension texture even if the actual terrain is larger.
81 /// </remarks> 81 /// </remarks>
82<<<<<<< HEAD
82 public static Bitmap Splat(ITerrainChannel terrain, 83 public static Bitmap Splat(ITerrainChannel terrain,
83 UUID[] textureIDs, float[] startHeights, float[] heightRanges, 84 UUID[] textureIDs, float[] startHeights, float[] heightRanges,
84 Vector3d regionPosition, IAssetService assetService, bool textureTerrain) 85 Vector3d regionPosition, IAssetService assetService, bool textureTerrain)
86=======
87 public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain)
88>>>>>>> avn/ubitvar
85 { 89 {
86 Debug.Assert(textureIDs.Length == 4); 90 Debug.Assert(textureIDs.Length == 4);
87 Debug.Assert(startHeights.Length == 4); 91 Debug.Assert(startHeights.Length == 4);
@@ -195,12 +199,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
195 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) 199 using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
196 gfx.FillRectangle(brush, 0, 0, 256, 256); 200 gfx.FillRectangle(brush, 0, 0, 256, 256);
197 } 201 }
202 else
203 {
204 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
205 {
206 detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256);
207 }
208 }
198 } 209 }
210<<<<<<< HEAD
199 else 211 else
212=======
213
214 #region Layer Map
215
216 float[,] layermap = new float[256 , 256];
217
218 int xFactor = terrain.Width / 256;
219 int yFactor = terrain.Height / 256;
220
221 for (int y = 0; y < 256; y++)
222>>>>>>> avn/ubitvar
200 { 223 {
201 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) 224 if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
202 { 225 {
226<<<<<<< HEAD
203 detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); 227 detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256);
228=======
229 float height = (float)terrain[x * xFactor, y * yFactor];
230
231 float pctX = (float)x / 255f;
232 float pctY = (float)y / 255f;
233
234 // Use bilinear interpolation between the four corners of start height and
235 // height range to select the current values at this position
236 float startHeight = ImageUtils.Bilinear(
237 startHeights[0],
238 startHeights[2],
239 startHeights[1],
240 startHeights[3],
241 pctX, pctY);
242 startHeight = Utils.Clamp(startHeight, 0f, 255f);
243
244 float heightRange = ImageUtils.Bilinear(
245 heightRanges[0],
246 heightRanges[2],
247 heightRanges[1],
248 heightRanges[3],
249 pctX, pctY);
250 heightRange = Utils.Clamp(heightRange, 0f, 255f);
251
252 // Generate two frequencies of perlin noise based on our global position
253 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
254 Vector3 vec = new Vector3
255 (
256 ((float)regionPosition.X + (x * xFactor)) * 0.20319f,
257 ((float)regionPosition.Y + (y * yFactor)) * 0.20319f,
258 height * 0.25f
259 );
260
261 float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
262 float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
263 float noise = (lowFreq + highFreq) * 2f;
264
265 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
266 float layer = ((height + noise - startHeight) / heightRange) * 4f;
267 if (Single.IsNaN(layer)) layer = 0f;
268 layermap[x,y] = Utils.Clamp(layer, 0f, 3f);
269>>>>>>> avn/ubitvar
204 } 270 }
205 } 271 }
206 } 272 }
@@ -220,6 +286,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
220 { 286 {
221 for (int x = 0; x < 256; x++) 287 for (int x = 0; x < 256; x++)
222 { 288 {
289<<<<<<< HEAD
223 float height = (float)terrain[x * xFactor, y * yFactor]; 290 float height = (float)terrain[x * xFactor, y * yFactor];
224 291
225 float pctX = (float)x / 255f; 292 float pctX = (float)x / 255f;
@@ -261,6 +328,58 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
261 if (Single.IsNaN(layer)) 328 if (Single.IsNaN(layer))
262 layer = 0f; 329 layer = 0f;
263 layermap[x, y] = Utils.Clamp(layer, 0f, 3f); 330 layermap[x, y] = Utils.Clamp(layer, 0f, 3f);
331=======
332 // Get handles to all of the texture data arrays
333 BitmapData[] datas = new BitmapData[]
334 {
335 detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
336 detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
337 detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
338 detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
339 };
340
341 int[] comps = new int[]
342 {
343 (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
344 (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
345 (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
346 (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
347 };
348
349 for (int y = 0; y < 256; y++)
350 {
351 for (int x = 0; x < 256; x++)
352 {
353 float layer = layermap[x, y];
354
355 // Select two textures
356 int l0 = (int)Math.Floor(layer);
357 int l1 = Math.Min(l0 + 1, 3);
358
359 byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
360 byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
361 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
362
363 float aB = *(ptrA + 0);
364 float aG = *(ptrA + 1);
365 float aR = *(ptrA + 2);
366
367 float bB = *(ptrB + 0);
368 float bG = *(ptrB + 1);
369 float bR = *(ptrB + 2);
370
371 float layerDiff = layer - l0;
372
373 // Interpolate between the two selected textures
374 *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
375 *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
376 *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
377 }
378 }
379
380 for (int i = 0; i < 4; i++)
381 detailTexture[i].UnlockBits(datas[i]);
382>>>>>>> avn/ubitvar
264 } 383 }
265 } 384 }
266 385
@@ -352,7 +471,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
352 b.Dispose(); 471 b.Dispose();
353 return result; 472 return result;
354 } 473 }
474<<<<<<< HEAD
355 475
476=======
477>>>>>>> avn/ubitvar
356 public static Bitmap SplatSimple(float[] heightmap) 478 public static Bitmap SplatSimple(float[] heightmap)
357 { 479 {
358 const float BASE_HSV_H = 93f / 360f; 480 const float BASE_HSV_H = 93f / 360f;
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
index dd91951..d8420d9 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
@@ -80,6 +80,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
80 80
81 private bool m_Enabled = false; 81 private bool m_Enabled = false;
82 82
83 private Bitmap lastImage = null;
84 private DateTime lastImageTime = DateTime.MinValue;
85
83 #region Region Module interface 86 #region Region Module interface
84 87
85 public void Initialise(IConfigSource source) 88 public void Initialise(IConfigSource source)
@@ -118,14 +121,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
118 121
119 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); 122 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
120 if (renderers.Count > 0) 123 if (renderers.Count > 0)
121 { 124 m_log.Info("[MAPTILE]: Loaded prim mesher " + renderers[0]);
122 m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
123 m_log.DebugFormat("[WARP 3D IMAGE MODULE]: Loaded prim mesher {0}", m_primMesher);
124 }
125 else 125 else
126 { 126 m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled");
127 m_log.Debug("[WARP 3D IMAGE MODULE]: No prim mesher loaded, prim rendering will be disabled");
128 }
129 127
130 m_scene.RegisterModuleInterface<IMapImageGenerator>(this); 128 m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
131 } 129 }
@@ -158,18 +156,50 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
158 156
159 public Bitmap CreateMapTile() 157 public Bitmap CreateMapTile()
160 { 158 {
159<<<<<<< HEAD
161 // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); 160 // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f);
162 // Camera above the middle of the region 161 // Camera above the middle of the region
163 Vector3 camPos = new Vector3( 162 Vector3 camPos = new Vector3(
164 m_scene.RegionInfo.RegionSizeX/2 - 0.5f, 163 m_scene.RegionInfo.RegionSizeX/2 - 0.5f,
165 m_scene.RegionInfo.RegionSizeY/2 - 0.5f, 164 m_scene.RegionInfo.RegionSizeY/2 - 0.5f,
165=======
166 /* this must be on all map, not just its image
167 if ((DateTime.Now - lastImageTime).TotalSeconds < 3600)
168 {
169 return (Bitmap)lastImage.Clone();
170 }
171 */
172
173 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
174 if (renderers.Count > 0)
175 {
176 m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
177 }
178
179 Vector3 camPos = new Vector3(
180 m_scene.RegionInfo.RegionSizeX / 2 - 0.5f,
181 m_scene.RegionInfo.RegionSizeY / 2 - 0.5f,
182>>>>>>> avn/ubitvar
166 221.7025033688163f); 183 221.7025033688163f);
167 // Viewport viewing down onto the region 184 // Viewport viewing down onto the region
168 Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, 185 Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f,
169 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, 186 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY,
187<<<<<<< HEAD
170 (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY ); 188 (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY );
171 // Fill the viewport and return the image 189 // Fill the viewport and return the image
172 return CreateMapTile(viewport, false); 190 return CreateMapTile(viewport, false);
191=======
192 (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY);
193
194 Bitmap tile = CreateMapTile(viewport, false);
195 m_primMesher = null;
196 return tile;
197/*
198 lastImage = tile;
199 lastImageTime = DateTime.Now;
200 return (Bitmap)lastImage.Clone();
201 */
202>>>>>>> avn/ubitvar
173 } 203 }
174 204
175 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) 205 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures)
@@ -285,9 +315,15 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
285 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; 315 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
286 316
287 renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); 317 renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f);
318<<<<<<< HEAD
288 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f, 319 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f,
289 waterHeight, 320 waterHeight,
290 m_scene.RegionInfo.RegionSizeY/2 - 0.5f ); 321 m_scene.RegionInfo.RegionSizeY/2 - 0.5f );
322=======
323 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX / 2 - 0.5f,
324 waterHeight,
325 m_scene.RegionInfo.RegionSizeY / 2 - 0.5f);
326>>>>>>> avn/ubitvar
291 327
292 warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); 328 warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR));
293 waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif 329 waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif
@@ -316,7 +352,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
316 warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); 352 warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
317 obj.addVertex(new warp_Vertex(pos, 353 obj.addVertex(new warp_Vertex(pos,
318 x / (float)m_scene.RegionInfo.RegionSizeX, 354 x / (float)m_scene.RegionInfo.RegionSizeX,
355<<<<<<< HEAD
319 (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) ); 356 (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) );
357=======
358 (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY));
359>>>>>>> avn/ubitvar
320 } 360 }
321 } 361 }
322 362
@@ -384,7 +424,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
384 warp_Texture texture; 424 warp_Texture texture;
385 using ( 425 using (
386 Bitmap image 426 Bitmap image
427<<<<<<< HEAD
387 = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, 428 = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges,
429=======
430 = TerrainSplat.Splat(
431 terrain, textureIDs, startHeights, heightRanges,
432>>>>>>> avn/ubitvar
388 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) 433 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
389 { 434 {
390 texture = new warp_Texture(image); 435 texture = new warp_Texture(image);
@@ -660,6 +705,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
660 #endregion Rendering Methods 705 #endregion Rendering Methods
661 706
662 #region Static Helpers 707 #region Static Helpers
708 // Note: axis change.
709 private static warp_Vector ConvertVector(float x, float y, float z)
710 {
711 return new warp_Vector(x, z, y);
712 }
663 713
664 // Note: axis change. 714 // Note: axis change.
665 private static warp_Vector ConvertVector(float x, float y, float z) 715 private static warp_Vector ConvertVector(float x, float y, float z)
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
index d862f18..553d057 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
@@ -141,20 +141,98 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
141 141
142 private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags) 142 private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags)
143 { 143 {
144<<<<<<< HEAD
144 List<MapBlockData> blocks = new List<MapBlockData>(); 145 List<MapBlockData> blocks = new List<MapBlockData>();
145 if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4)) 146 if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4))
147=======
148 Util.FireAndForget(x =>
149>>>>>>> avn/ubitvar
146 { 150 {
151 List<MapBlockData> blocks = new List<MapBlockData>();
152 if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4))
153 {
154 // final block, closing the search result
155 AddFinalBlock(blocks);
156
157 // flags are agent flags sent from the viewer.
158 // they have different values depending on different viewers, apparently
159 remoteClient.SendMapBlock(blocks, flags);
160 remoteClient.SendAlertMessage("Use a search string with at least 3 characters");
161 return;
162 }
163
164 //m_log.DebugFormat("MAP NAME=({0})", mapName);
165
166 // Hack to get around the fact that ll V3 now drops the port from the
167 // map name. See https://jira.secondlife.com/browse/VWR-28570
168 //
169 // Caller, use this magic form instead:
170 // secondlife://http|!!mygrid.com|8002|Region+Name/128/128
171 // or url encode if possible.
172 // the hacks we do with this viewer...
173 //
174 string mapNameOrig = mapName;
175 if (mapName.Contains("|"))
176 mapName = mapName.Replace('|', ':');
177 if (mapName.Contains("+"))
178 mapName = mapName.Replace('+', ' ');
179 if (mapName.Contains("!"))
180 mapName = mapName.Replace('!', '/');
181
182 // try to fetch from GridServer
183 List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
184 // if (regionInfos.Count == 0)
185 // remoteClient.SendAlertMessage("Hyperlink could not be established.");
186
187 //m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions", mapName, regionInfos.Count);
188
189 MapBlockData data;
190 if (regionInfos.Count > 0)
191 {
192 foreach (GridRegion info in regionInfos)
193 {
194 data = new MapBlockData();
195 data.Agents = 0;
196 data.Access = info.Access;
197 if (flags == 2) // V2 sends this
198 {
199 List<MapBlockData> datas = WorldMap.Map2BlockFromGridRegion(info, flags);
200 // ugh! V2-3 is very sensitive about the result being
201 // exactly the same as the requested name
202
203 if (regionInfos.Count == 1 && (mapName != mapNameOrig))
204 datas.ForEach(d => d.Name = mapNameOrig);
205
206 blocks.AddRange(datas);
207 }
208 else
209 {
210 MapBlockData block = new MapBlockData();
211 WorldMap.MapBlockFromGridRegion(block,info, flags);
212 blocks.Add(block);
213 }
214 // ugh! V2-3 is very sensitive about the result being
215 // exactly the same as the requested name
216 if (regionInfos.Count == 1 && mapNameOrig.Contains("|") || mapNameOrig.Contains("+"))
217 data.Name = mapNameOrig;
218 else
219 data.Name = info.RegionName;
220 data.RegionFlags = 0; // TODO not used?
221 data.WaterHeight = 0; // not used
222 data.X = (ushort)(info.RegionLocX / Constants.RegionSize);
223 data.Y = (ushort)(info.RegionLocY / Constants.RegionSize);
224 blocks.Add(data);
225 }
226 }
227
147 // final block, closing the search result 228 // final block, closing the search result
148 AddFinalBlock(blocks); 229 AddFinalBlock(blocks);
149 230
150 // flags are agent flags sent from the viewer. 231 // flags are agent flags sent from the viewer.
151 // they have different values depending on different viewers, apparently 232 // they have different values depending on different viewers, apparently
152 remoteClient.SendMapBlock(blocks, flags); 233 remoteClient.SendMapBlock(blocks, flags);
153 remoteClient.SendAlertMessage("Use a search string with at least 3 characters");
154 return;
155 }
156
157 234
235<<<<<<< HEAD
158 List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20); 236 List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
159 237
160 string mapNameOrig = mapName; 238 string mapNameOrig = mapName;
@@ -221,6 +299,19 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
221 //else if (regionInfos.Count == 1) 299 //else if (regionInfos.Count == 1)
222 // remoteClient.SendAlertMessage("Region found!"); 300 // remoteClient.SendAlertMessage("Region found!");
223 } 301 }
302=======
303 // send extra user messages for V3
304 // because the UI is very confusing
305 // while we don't fix the hard-coded urls
306 if (flags == 2)
307 {
308 if (regionInfos.Count == 0)
309 remoteClient.SendAgentAlertMessage("No regions found with that name.", true);
310// else if (regionInfos.Count == 1)
311// remoteClient.SendAgentAlertMessage("Region found!", false);
312 }
313 });
314>>>>>>> avn/ubitvar
224 } 315 }
225 316
226 private void AddFinalBlock(List<MapBlockData> blocks) 317 private void AddFinalBlock(List<MapBlockData> blocks)
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index db1187e..2fbd017 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -68,10 +68,21 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
68 private static readonly UUID STOP_UUID = UUID.Random(); 68 private static readonly UUID STOP_UUID = UUID.Random();
69 private static readonly string m_mapLayerPath = "0001/"; 69 private static readonly string m_mapLayerPath = "0001/";
70 70
71<<<<<<< HEAD
71 private IMapImageGenerator m_mapImageGenerator; 72 private IMapImageGenerator m_mapImageGenerator;
72 private IMapImageUploadModule m_mapImageServiceModule; 73 private IMapImageUploadModule m_mapImageServiceModule;
73 74
74 private OpenSim.Framework.BlockingQueue<MapRequestState> requests = new OpenSim.Framework.BlockingQueue<MapRequestState>(); 75 private OpenSim.Framework.BlockingQueue<MapRequestState> requests = new OpenSim.Framework.BlockingQueue<MapRequestState>();
76=======
77 private ManualResetEvent queueEvent = new ManualResetEvent(false);
78 private Queue<MapRequestState> requests = new Queue<MapRequestState>();
79
80 private ManualResetEvent m_mapBlockRequestEvent = new ManualResetEvent(false);
81 private Dictionary<UUID, Queue<MapBlockRequestData>> m_mapBlockRequests = new Dictionary<UUID, Queue<MapBlockRequestData>>();
82
83 private IMapImageGenerator m_mapImageGenerator;
84 private IMapImageUploadModule m_mapImageServiceModule;
85>>>>>>> avn/ubitvar
75 86
76 protected Scene m_scene; 87 protected Scene m_scene;
77 private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>(); 88 private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>();
@@ -79,15 +90,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
79 private int blacklistTimeout = 10*60*1000; // 10 minutes 90 private int blacklistTimeout = 10*60*1000; // 10 minutes
80 private byte[] myMapImageJPEG; 91 private byte[] myMapImageJPEG;
81 protected volatile bool m_Enabled = false; 92 protected volatile bool m_Enabled = false;
82 private Dictionary<UUID, MapRequestState> m_openRequests = new Dictionary<UUID, MapRequestState>();
83 private Dictionary<string, int> m_blacklistedurls = new Dictionary<string, int>(); 93 private Dictionary<string, int> m_blacklistedurls = new Dictionary<string, int>();
84 private Dictionary<ulong, int> m_blacklistedregions = new Dictionary<ulong, int>(); 94 private Dictionary<ulong, int> m_blacklistedregions = new Dictionary<ulong, int>();
85 private Dictionary<ulong, string> m_cachedRegionMapItemsAddress = new Dictionary<ulong, string>(); 95 private Dictionary<ulong, string> m_cachedRegionMapItemsAddress = new Dictionary<ulong, string>();
86 private List<UUID> m_rootAgents = new List<UUID>(); 96 private List<UUID> m_rootAgents = new List<UUID>();
87 private volatile bool threadrunning = false; 97 private volatile bool threadrunning = false;
88 98
89 private IServiceThrottleModule m_ServiceThrottle;
90
91 //private int CacheRegionsDistance = 256; 99 //private int CacheRegionsDistance = 256;
92 100
93 #region INonSharedRegionModule Members 101 #region INonSharedRegionModule Members
@@ -98,7 +106,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
98 if (Util.GetConfigVarFromSections<string>( 106 if (Util.GetConfigVarFromSections<string>(
99 config, "WorldMapModule", configSections, "WorldMap") == "WorldMap") 107 config, "WorldMapModule", configSections, "WorldMap") == "WorldMap")
100 m_Enabled = true; 108 m_Enabled = true;
101 109
102 blacklistTimeout 110 blacklistTimeout
103 = Util.GetConfigVarFromSections<int>(config, "BlacklistTimeout", configSections, 10 * 60) * 1000; 111 = Util.GetConfigVarFromSections<int>(config, "BlacklistTimeout", configSections, 10 * 60) * 1000;
104 } 112 }
@@ -146,7 +154,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
146 if (!m_Enabled) 154 if (!m_Enabled)
147 return; 155 return;
148 156
157<<<<<<< HEAD
149 m_ServiceThrottle = scene.RequestModuleInterface<IServiceThrottleModule>(); 158 m_ServiceThrottle = scene.RequestModuleInterface<IServiceThrottleModule>();
159=======
160 m_mapImageGenerator = m_scene.RequestModuleInterface<IMapImageGenerator>();
161 m_mapImageServiceModule = m_scene.RequestModuleInterface<IMapImageUploadModule>();
162 }
163>>>>>>> avn/ubitvar
150 164
151 m_mapImageGenerator = m_scene.RequestModuleInterface<IMapImageGenerator>(); 165 m_mapImageGenerator = m_scene.RequestModuleInterface<IMapImageGenerator>();
152 m_mapImageServiceModule = m_scene.RequestModuleInterface<IMapImageUploadModule>(); 166 m_mapImageServiceModule = m_scene.RequestModuleInterface<IMapImageUploadModule>();
@@ -197,13 +211,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
197 m_scene.EventManager.OnMakeRootAgent += MakeRootAgent; 211 m_scene.EventManager.OnMakeRootAgent += MakeRootAgent;
198 m_scene.EventManager.OnRegionUp += OnRegionUp; 212 m_scene.EventManager.OnRegionUp += OnRegionUp;
199 213
200// StartThread(new object()); 214 StartThread(new object());
201 } 215 }
202 216
203 // this has to be called with a lock on m_scene 217 // this has to be called with a lock on m_scene
204 protected virtual void RemoveHandlers() 218 protected virtual void RemoveHandlers()
205 { 219 {
206// StopThread(); 220 StopThread();
207 221
208 m_scene.EventManager.OnRegionUp -= OnRegionUp; 222 m_scene.EventManager.OnRegionUp -= OnRegionUp;
209 m_scene.EventManager.OnMakeRootAgent -= MakeRootAgent; 223 m_scene.EventManager.OnMakeRootAgent -= MakeRootAgent;
@@ -261,6 +275,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
261 // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is 275 // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is
262 // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks. 276 // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks.
263 277
278<<<<<<< HEAD
264 if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048) 279 if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048)
265 { 280 {
266 ScenePresence avatarPresence = null; 281 ScenePresence avatarPresence = null;
@@ -309,6 +324,56 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
309 } 324 }
310 } 325 }
311 } 326 }
327=======
328 //if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048)
329 //{
330 // ScenePresence avatarPresence = null;
331
332 // m_scene.TryGetScenePresence(agentID, out avatarPresence);
333
334 // if (avatarPresence != null)
335 // {
336 // bool lookup = false;
337
338 // lock (cachedMapBlocks)
339 // {
340 // if (cachedMapBlocks.Count > 0 && ((cachedTime + 1800) > Util.UnixTimeSinceEpoch()))
341 // {
342 // List<MapBlockData> mapBlocks;
343
344 // mapBlocks = cachedMapBlocks;
345 // avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0);
346 // }
347 // else
348 // {
349 // lookup = true;
350 // }
351 // }
352 // if (lookup)
353 // {
354 // List<MapBlockData> mapBlocks = new List<MapBlockData>(); ;
355
356 // List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
357 // (int)(m_scene.RegionInfo.RegionLocX - 8) * (int)Constants.RegionSize,
358 // (int)(m_scene.RegionInfo.RegionLocX + 8) * (int)Constants.RegionSize,
359 // (int)(m_scene.RegionInfo.RegionLocY - 8) * (int)Constants.RegionSize,
360 // (int)(m_scene.RegionInfo.RegionLocY + 8) * (int)Constants.RegionSize);
361 // foreach (GridRegion r in regions)
362 // {
363 // MapBlockData block = new MapBlockData();
364 // MapBlockFromGridRegion(block, r, 0);
365 // mapBlocks.Add(block);
366 // }
367 // avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0);
368
369 // lock (cachedMapBlocks)
370 // cachedMapBlocks = mapBlocks;
371
372 // cachedTime = Util.UnixTimeSinceEpoch();
373 // }
374 // }
375 //}
376>>>>>>> avn/ubitvar
312 377
313 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); 378 LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
314 mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse()); 379 mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse());
@@ -335,7 +400,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
335 protected static OSDMapLayer GetOSDMapLayerResponse() 400 protected static OSDMapLayer GetOSDMapLayerResponse()
336 { 401 {
337 OSDMapLayer mapLayer = new OSDMapLayer(); 402 OSDMapLayer mapLayer = new OSDMapLayer();
403// mapLayer.Right = 2048;
338 mapLayer.Right = 5000; 404 mapLayer.Right = 5000;
405// mapLayer.Top = 2048;
339 mapLayer.Top = 5000; 406 mapLayer.Top = 5000;
340 mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006"); 407 mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006");
341 408
@@ -365,6 +432,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
365 { 432 {
366 m_rootAgents.Remove(AgentId); 433 m_rootAgents.Remove(AgentId);
367 } 434 }
435 lock (m_mapBlockRequestEvent)
436 {
437 if (m_mapBlockRequests.ContainsKey(AgentId))
438 m_mapBlockRequests.Remove(AgentId);
439 }
368 } 440 }
369 #endregion 441 #endregion
370 442
@@ -387,6 +459,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
387 ThreadPriority.BelowNormal, 459 ThreadPriority.BelowNormal,
388 true, 460 true,
389 true); 461 true);
462 Watchdog.StartThread(
463 MapBlockSendThread,
464 string.Format("MapBlockSendThread ({0})", m_scene.RegionInfo.RegionName),
465 ThreadPriority.BelowNormal,
466 true,
467 true);
390 } 468 }
391 469
392 /// <summary> 470 /// <summary>
@@ -402,7 +480,27 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
402 st.itemtype=0; 480 st.itemtype=0;
403 st.regionhandle=0; 481 st.regionhandle=0;
404 482
405 requests.Enqueue(st); 483 lock (requests)
484 {
485 queueEvent.Set();
486 requests.Enqueue(st);
487 }
488
489 MapBlockRequestData req = new MapBlockRequestData();
490
491 req.client = null;
492 req.minX = 0;
493 req.maxX = 0;
494 req.minY = 0;
495 req.maxY = 0;
496 req.flags = 0;
497
498 lock (m_mapBlockRequestEvent)
499 {
500 m_mapBlockRequests[UUID.Zero] = new Queue<MapBlockRequestData>();
501 m_mapBlockRequests[UUID.Zero].Enqueue(req);
502 m_mapBlockRequestEvent.Set();
503 }
406 } 504 }
407 505
408 public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags, 506 public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags,
@@ -418,7 +516,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
418 uint xstart = 0; 516 uint xstart = 0;
419 uint ystart = 0; 517 uint ystart = 0;
420 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart); 518 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
519<<<<<<< HEAD
421 if (itemtype == (int)GridItemType.AgentLocations) 520 if (itemtype == (int)GridItemType.AgentLocations)
521=======
522
523 if (itemtype == 6) // Service 6 right now (MAP_ITEM_AGENTS_LOCATION; green dots)
524>>>>>>> avn/ubitvar
422 { 525 {
423 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) 526 if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
424 { 527 {
@@ -428,12 +531,22 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
428 mapItemReply mapitem = new mapItemReply(); 531 mapItemReply mapitem = new mapItemReply();
429 if (m_scene.GetRootAgentCount() <= 1) 532 if (m_scene.GetRootAgentCount() <= 1)
430 { 533 {
534<<<<<<< HEAD
431 mapitem = new mapItemReply( 535 mapitem = new mapItemReply(
432 xstart + 1, 536 xstart + 1,
433 ystart + 1, 537 ystart + 1,
434 UUID.Zero, 538 UUID.Zero,
435 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()), 539 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
436 0, 0); 540 0, 0);
541=======
542 mapitem = new mapItemReply();
543 mapitem.x = xstart + 1;
544 mapitem.y = ystart + 1;
545 mapitem.id = UUID.Zero;
546 mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString());
547 mapitem.Extra = 0;
548 mapitem.Extra2 = 0;
549>>>>>>> avn/ubitvar
437 mapitems.Add(mapitem); 550 mapitems.Add(mapitem);
438 } 551 }
439 else 552 else
@@ -443,12 +556,22 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
443 // Don't send a green dot for yourself 556 // Don't send a green dot for yourself
444 if (sp.UUID != remoteClient.AgentId) 557 if (sp.UUID != remoteClient.AgentId)
445 { 558 {
559<<<<<<< HEAD
446 mapitem = new mapItemReply( 560 mapitem = new mapItemReply(
447 xstart + (uint)sp.AbsolutePosition.X, 561 xstart + (uint)sp.AbsolutePosition.X,
448 ystart + (uint)sp.AbsolutePosition.Y, 562 ystart + (uint)sp.AbsolutePosition.Y,
449 UUID.Zero, 563 UUID.Zero,
450 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()), 564 Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
451 1, 0); 565 1, 0);
566=======
567 mapitem = new mapItemReply();
568 mapitem.x = xstart + (uint)sp.AbsolutePosition.X;
569 mapitem.y = ystart + (uint)sp.AbsolutePosition.Y;
570 mapitem.id = UUID.Zero;
571 mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString());
572 mapitem.Extra = 1;
573 mapitem.Extra2 = 0;
574>>>>>>> avn/ubitvar
452 mapitems.Add(mapitem); 575 mapitems.Add(mapitem);
453 } 576 }
454 }); 577 });
@@ -493,6 +616,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
493 float x = (min.X+max.X)/2; 616 float x = (min.X+max.X)/2;
494 float y = (min.Y+max.Y)/2; 617 float y = (min.Y+max.Y)/2;
495 618
619<<<<<<< HEAD
496 mapitem = new mapItemReply( 620 mapitem = new mapItemReply(
497 xstart + (uint)x, 621 xstart + (uint)x,
498 ystart + (uint)y, 622 ystart + (uint)y,
@@ -501,6 +625,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
501 parcel.Area, 625 parcel.Area,
502 parcel.SalePrice 626 parcel.SalePrice
503 ); 627 );
628=======
629 mapitem = new mapItemReply();
630 mapitem.x = xstart + (uint)x;
631 mapitem.y = ystart +(uint)y;
632 // mapitem.z = (uint)m_scene.GetGroundHeight(x,y);
633 mapitem.id = parcel.GlobalID;
634 mapitem.name = parcel.Name;
635 mapitem.Extra = parcel.Area;
636 mapitem.Extra2 = parcel.SalePrice;
637>>>>>>> avn/ubitvar
504 mapitems.Add(mapitem); 638 mapitems.Add(mapitem);
505 } 639 }
506 } 640 }
@@ -525,6 +659,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
525 SceneObjectGroup sog = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject); 659 SceneObjectGroup sog = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject);
526 if (sog != null) 660 if (sog != null)
527 { 661 {
662<<<<<<< HEAD
528 mapitem = new mapItemReply( 663 mapitem = new mapItemReply(
529 xstart + (uint)sog.AbsolutePosition.X, 664 xstart + (uint)sog.AbsolutePosition.X,
530 ystart + (uint)sog.AbsolutePosition.Y, 665 ystart + (uint)sog.AbsolutePosition.Y,
@@ -533,6 +668,15 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
533 0, // color (not used) 668 0, // color (not used)
534 0 // 0 = telehub / 1 = infohub 669 0 // 0 = telehub / 1 = infohub
535 ); 670 );
671=======
672 mapitem = new mapItemReply();
673 mapitem.x = xstart + (uint)sog.AbsolutePosition.X;
674 mapitem.y = ystart + (uint)sog.AbsolutePosition.Y;
675 mapitem.id = UUID.Zero;
676 mapitem.name = sog.Name;
677 mapitem.Extra = 0; // color (not used)
678 mapitem.Extra2 = 0; // 0 = telehub / 1 = infohub
679>>>>>>> avn/ubitvar
536 mapitems.Add(mapitem); 680 mapitems.Add(mapitem);
537 681
538 remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags); 682 remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags);
@@ -552,12 +696,26 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
552 /// </summary> 696 /// </summary>
553 public void process() 697 public void process()
554 { 698 {
555 //const int MAX_ASYNC_REQUESTS = 20; 699 const int MAX_ASYNC_REQUESTS = 20;
556 try 700 try
557 { 701 {
558 while (true) 702 while (true)
559 { 703 {
560 MapRequestState st = requests.Dequeue(1000); 704 MapRequestState st = new MapRequestState();
705 bool valid = false;
706 queueEvent.WaitOne();
707 lock (requests)
708 {
709 if (requests.Count > 0)
710 {
711 st = requests.Dequeue();
712 valid = true;
713 }
714 if (requests.Count == 0)
715 queueEvent.Reset();
716 }
717 if (!valid)
718 continue;
561 719
562 // end gracefully 720 // end gracefully
563 if (st.agentID == STOP_UUID) 721 if (st.agentID == STOP_UUID)
@@ -575,13 +733,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
575 if (dorequest && !m_blacklistedregions.ContainsKey(st.regionhandle)) 733 if (dorequest && !m_blacklistedregions.ContainsKey(st.regionhandle))
576 { 734 {
577 while (nAsyncRequests >= MAX_ASYNC_REQUESTS) // hit the break 735 while (nAsyncRequests >= MAX_ASYNC_REQUESTS) // hit the break
578 Thread.Sleep(80); 736 Thread.Sleep(100);
579 737
580 RequestMapItemsDelegate d = RequestMapItemsAsync;
581 d.BeginInvoke(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle, RequestMapItemsCompleted, null);
582 //OSDMap response = RequestMapItemsAsync(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle);
583 //RequestMapItemsCompleted(response);
584 Interlocked.Increment(ref nAsyncRequests); 738 Interlocked.Increment(ref nAsyncRequests);
739 Util.FireAndForget(x =>
740 {
741 RequestMapItemsAsync(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle);
742 });
585 } 743 }
586 } 744 }
587 745
@@ -597,17 +755,15 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
597 Watchdog.RemoveThread(); 755 Watchdog.RemoveThread();
598 } 756 }
599 757
600 const int MAX_ASYNC_REQUESTS = 20;
601
602 /// <summary> 758 /// <summary>
603 /// Enqueues the map item request into the services throttle processing thread 759 /// Enqueues the map item request into the processing thread
604 /// </summary> 760 /// </summary>
605 /// <param name="state"></param> 761 /// <param name="state"></param>
606 public void EnqueueMapItemRequest(MapRequestState st) 762 public void EnqueueMapItemRequest(MapRequestState state)
607 { 763 {
608 764 lock (requests)
609 m_ServiceThrottle.Enqueue("map-item", st.regionhandle.ToString() + st.agentID.ToString(), delegate
610 { 765 {
766<<<<<<< HEAD
611 if (st.agentID != UUID.Zero) 767 if (st.agentID != UUID.Zero)
612 { 768 {
613 bool dorequest = true; 769 bool dorequest = true;
@@ -723,6 +879,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
723 } 879 }
724 } 880 }
725 } 881 }
882=======
883 queueEvent.Set();
884 requests.Enqueue(state);
885>>>>>>> avn/ubitvar
726 } 886 }
727 } 887 }
728 888
@@ -749,8 +909,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
749 EnqueueMapItemRequest(st); 909 EnqueueMapItemRequest(st);
750 } 910 }
751 911
752 private delegate OSDMap RequestMapItemsDelegate(UUID id, uint flags,
753 uint EstateID, bool godlike, uint itemtype, ulong regionhandle);
754 /// <summary> 912 /// <summary>
755 /// Does the actual remote mapitem request 913 /// Does the actual remote mapitem request
756 /// This should be called from an asynchronous thread 914 /// This should be called from an asynchronous thread
@@ -765,7 +923,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
765 /// <param name="itemtype">passed in from packet</param> 923 /// <param name="itemtype">passed in from packet</param>
766 /// <param name="regionhandle">Region we're looking up</param> 924 /// <param name="regionhandle">Region we're looking up</param>
767 /// <returns></returns> 925 /// <returns></returns>
768 private OSDMap RequestMapItemsAsync(UUID id, uint flags, 926 private void RequestMapItemsAsync(UUID id, uint flags,
769 uint EstateID, bool godlike, uint itemtype, ulong regionhandle) 927 uint EstateID, bool godlike, uint itemtype, ulong regionhandle)
770 { 928 {
771// m_log.DebugFormat("[WORLDMAP]: RequestMapItemsAsync; region handle: {0} {1}", regionhandle, itemtype); 929// m_log.DebugFormat("[WORLDMAP]: RequestMapItemsAsync; region handle: {0} {1}", regionhandle, itemtype);
@@ -788,7 +946,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
788 } 946 }
789 947
790 if (blacklisted) 948 if (blacklisted)
791 return new OSDMap(); 949 {
950 Interlocked.Decrement(ref nAsyncRequests);
951 return;
952 }
792 953
793 UUID requestID = UUID.Random(); 954 UUID requestID = UUID.Random();
794 lock (m_cachedRegionMapItemsAddress) 955 lock (m_cachedRegionMapItemsAddress)
@@ -796,6 +957,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
796 if (m_cachedRegionMapItemsAddress.ContainsKey(regionhandle)) 957 if (m_cachedRegionMapItemsAddress.ContainsKey(regionhandle))
797 httpserver = m_cachedRegionMapItemsAddress[regionhandle]; 958 httpserver = m_cachedRegionMapItemsAddress[regionhandle];
798 } 959 }
960
799 if (httpserver.Length == 0) 961 if (httpserver.Length == 0)
800 { 962 {
801 uint x = 0, y = 0; 963 uint x = 0, y = 0;
@@ -840,18 +1002,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
840 1002
841 // Can't find the http server 1003 // Can't find the http server
842 if (httpserver.Length == 0 || blacklisted) 1004 if (httpserver.Length == 0 || blacklisted)
843 return new OSDMap(); 1005 {
844 1006 Interlocked.Decrement(ref nAsyncRequests);
845 MapRequestState mrs = new MapRequestState(); 1007 return;
846 mrs.agentID = id; 1008 }
847 mrs.EstateID = EstateID;
848 mrs.flags = flags;
849 mrs.godlike = godlike;
850 mrs.itemtype=itemtype;
851 mrs.regionhandle = regionhandle;
852
853 lock (m_openRequests)
854 m_openRequests.Add(requestID, mrs);
855 1009
856 WebRequest mapitemsrequest = null; 1010 WebRequest mapitemsrequest = null;
857 try 1011 try
@@ -861,7 +1015,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
861 catch (Exception e) 1015 catch (Exception e)
862 { 1016 {
863 m_log.DebugFormat("[WORLD MAP]: Access to {0} failed with {1}", httpserver, e); 1017 m_log.DebugFormat("[WORLD MAP]: Access to {0} failed with {1}", httpserver, e);
864 return new OSDMap(); 1018 Interlocked.Decrement(ref nAsyncRequests);
1019 return;
865 } 1020 }
866 1021
867 mapitemsrequest.Method = "POST"; 1022 mapitemsrequest.Method = "POST";
@@ -895,13 +1050,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
895 1050
896 m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); 1051 m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver);
897 1052
898 return responseMap; 1053 Interlocked.Decrement(ref nAsyncRequests);
1054 return;
899 } 1055 }
900 catch 1056 catch
901 { 1057 {
902 m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); 1058 m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver);
903 responseMap["connect"] = OSD.FromBoolean(false); 1059 Interlocked.Decrement(ref nAsyncRequests);
904 return responseMap; 1060 return;
905 } 1061 }
906 finally 1062 finally
907 { 1063 {
@@ -910,26 +1066,24 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
910 } 1066 }
911 1067
912 string response_mapItems_reply = null; 1068 string response_mapItems_reply = null;
913 { 1069 { // get the response
1070 StreamReader sr = null;
914 try 1071 try
915 { 1072 {
916 using (WebResponse webResponse = mapitemsrequest.GetResponse()) 1073 WebResponse webResponse = mapitemsrequest.GetResponse();
1074 if (webResponse != null)
917 { 1075 {
918 if (webResponse != null) 1076 sr = new StreamReader(webResponse.GetResponseStream());
919 { 1077 response_mapItems_reply = sr.ReadToEnd().Trim();
920 using (Stream s = webResponse.GetResponseStream()) 1078 }
921 using (StreamReader sr = new StreamReader(s)) 1079 else
922 response_mapItems_reply = sr.ReadToEnd().Trim(); 1080 {
923 } 1081 Interlocked.Decrement(ref nAsyncRequests);
924 else 1082 return;
925 { 1083 }
926 return new OSDMap();
927 }
928 }
929 } 1084 }
930 catch (WebException) 1085 catch (WebException)
931 { 1086 {
932 responseMap["connect"] = OSD.FromBoolean(false);
933 lock (m_blacklistedurls) 1087 lock (m_blacklistedurls)
934 { 1088 {
935 if (!m_blacklistedurls.ContainsKey(httpserver)) 1089 if (!m_blacklistedurls.ContainsKey(httpserver))
@@ -938,19 +1092,25 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
938 1092
939 m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); 1093 m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver);
940 1094
941 return responseMap; 1095 Interlocked.Decrement(ref nAsyncRequests);
1096 return;
942 } 1097 }
943 catch 1098 catch
944 { 1099 {
945 m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); 1100 m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver);
946 responseMap["connect"] = OSD.FromBoolean(false);
947 lock (m_blacklistedregions) 1101 lock (m_blacklistedregions)
948 { 1102 {
949 if (!m_blacklistedregions.ContainsKey(regionhandle)) 1103 if (!m_blacklistedregions.ContainsKey(regionhandle))
950 m_blacklistedregions.Add(regionhandle, Environment.TickCount); 1104 m_blacklistedregions.Add(regionhandle, Environment.TickCount);
951 } 1105 }
952 1106
953 return responseMap; 1107 Interlocked.Decrement(ref nAsyncRequests);
1108 return;
1109 }
1110 finally
1111 {
1112 if (sr != null)
1113 sr.Close();
954 } 1114 }
955 1115
956 OSD rezResponse = null; 1116 OSD rezResponse = null;
@@ -964,15 +1124,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
964 catch (Exception ex) 1124 catch (Exception ex)
965 { 1125 {
966 m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message); 1126 m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message);
967 responseMap["connect"] = OSD.FromBoolean(false);
968
969 lock (m_blacklistedregions) 1127 lock (m_blacklistedregions)
970 { 1128 {
971 if (!m_blacklistedregions.ContainsKey(regionhandle)) 1129 if (!m_blacklistedregions.ContainsKey(regionhandle))
972 m_blacklistedregions.Add(regionhandle, Environment.TickCount); 1130 m_blacklistedregions.Add(regionhandle, Environment.TickCount);
973 } 1131 }
974 1132
975 return responseMap; 1133 Interlocked.Decrement(ref nAsyncRequests);
1134 return;
976 } 1135 }
977 } 1136 }
978 1137
@@ -986,7 +1145,78 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
986 } 1145 }
987 } 1146 }
988 1147
989 return responseMap; 1148 Interlocked.Decrement(ref nAsyncRequests);
1149
1150 if (id != UUID.Zero)
1151 {
1152 ScenePresence av = null;
1153 m_scene.TryGetScenePresence(id, out av);
1154 if (av != null)
1155 {
1156 if (responseMap.ContainsKey(itemtype.ToString()))
1157 {
1158 List<mapItemReply> returnitems = new List<mapItemReply>();
1159 OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()];
1160 for (int i = 0; i < itemarray.Count; i++)
1161 {
1162 OSDMap mapitem = (OSDMap)itemarray[i];
1163 mapItemReply mi = new mapItemReply();
1164 mi.x = (uint)mapitem["X"].AsInteger();
1165 mi.y = (uint)mapitem["Y"].AsInteger();
1166 mi.id = mapitem["ID"].AsUUID();
1167 mi.Extra = mapitem["Extra"].AsInteger();
1168 mi.Extra2 = mapitem["Extra2"].AsInteger();
1169 mi.name = mapitem["Name"].AsString();
1170 returnitems.Add(mi);
1171 }
1172 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags);
1173 }
1174
1175 // Service 7 (MAP_ITEM_LAND_FOR_SALE)
1176 itemtype = 7;
1177
1178 if (responseMap.ContainsKey(itemtype.ToString()))
1179 {
1180 List<mapItemReply> returnitems = new List<mapItemReply>();
1181 OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()];
1182 for (int i = 0; i < itemarray.Count; i++)
1183 {
1184 OSDMap mapitem = (OSDMap)itemarray[i];
1185 mapItemReply mi = new mapItemReply();
1186 mi.x = (uint)mapitem["X"].AsInteger();
1187 mi.y = (uint)mapitem["Y"].AsInteger();
1188 mi.id = mapitem["ID"].AsUUID();
1189 mi.Extra = mapitem["Extra"].AsInteger();
1190 mi.Extra2 = mapitem["Extra2"].AsInteger();
1191 mi.name = mapitem["Name"].AsString();
1192 returnitems.Add(mi);
1193 }
1194 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags);
1195 }
1196
1197 // Service 1 (MAP_ITEM_TELEHUB)
1198 itemtype = 1;
1199
1200 if (responseMap.ContainsKey(itemtype.ToString()))
1201 {
1202 List<mapItemReply> returnitems = new List<mapItemReply>();
1203 OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()];
1204 for (int i = 0; i < itemarray.Count; i++)
1205 {
1206 OSDMap mapitem = (OSDMap)itemarray[i];
1207 mapItemReply mi = new mapItemReply();
1208 mi.x = (uint)mapitem["X"].AsInteger();
1209 mi.y = (uint)mapitem["Y"].AsInteger();
1210 mi.id = mapitem["ID"].AsUUID();
1211 mi.Extra = mapitem["Extra"].AsInteger();
1212 mi.Extra2 = mapitem["Extra2"].AsInteger();
1213 mi.name = mapitem["Name"].AsString();
1214 returnitems.Add(mi);
1215 }
1216 av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags);
1217 }
1218 }
1219 }
990 } 1220 }
991 1221
992 /// <summary> 1222 /// <summary>
@@ -996,8 +1226,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
996 /// <param name="minY"></param> 1226 /// <param name="minY"></param>
997 /// <param name="maxX"></param> 1227 /// <param name="maxX"></param>
998 /// <param name="maxY"></param> 1228 /// <param name="maxY"></param>
999 public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) 1229 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
1000 { 1230 {
1231<<<<<<< HEAD
1232=======
1233 m_log.DebugFormat("[WoldMapModule] RequestMapBlocks {0}={1}={2}={3} {4}", minX, minY, maxX, maxY, flag);
1234/* this flag does not seem to mean what his says
1235>>>>>>> avn/ubitvar
1001 if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible 1236 if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible
1002 { 1237 {
1003 List<MapBlockData> response = new List<MapBlockData>(); 1238 List<MapBlockData> response = new List<MapBlockData>();
@@ -1006,15 +1241,24 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1006 // on an unloaded square. 1241 // on an unloaded square.
1007 // But make sure: Look whether the one we requested is in there 1242 // But make sure: Look whether the one we requested is in there
1008 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1243 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1244<<<<<<< HEAD
1009 (int)Util.RegionToWorldLoc((uint)minX), (int)Util.RegionToWorldLoc((uint)maxX), 1245 (int)Util.RegionToWorldLoc((uint)minX), (int)Util.RegionToWorldLoc((uint)maxX),
1010 (int)Util.RegionToWorldLoc((uint)minY), (int)Util.RegionToWorldLoc((uint)maxY) ); 1246 (int)Util.RegionToWorldLoc((uint)minY), (int)Util.RegionToWorldLoc((uint)maxY) );
1011 1247
1012 m_log.DebugFormat("[WORLD MAP MODULE] RequestMapBlocks min=<{0},{1}>, max=<{2},{3}>, flag={4}, cntFound={5}", 1248 m_log.DebugFormat("[WORLD MAP MODULE] RequestMapBlocks min=<{0},{1}>, max=<{2},{3}>, flag={4}, cntFound={5}",
1013 minX, minY, maxX, maxY, flag.ToString("X"), regions.Count); 1249 minX, minY, maxX, maxY, flag.ToString("X"), regions.Count);
1250=======
1251 (int)Util.RegionToWorldLoc((uint)minX),
1252 (int)Util.RegionToWorldLoc((uint)maxX),
1253 (int)Util.RegionToWorldLoc((uint)minY),
1254 (int)Util.RegionToWorldLoc((uint)maxY) );
1255
1256>>>>>>> avn/ubitvar
1014 if (regions != null) 1257 if (regions != null)
1015 { 1258 {
1016 foreach (GridRegion r in regions) 1259 foreach (GridRegion r in regions)
1017 { 1260 {
1261<<<<<<< HEAD
1018 if (r.RegionLocX == Util.RegionToWorldLoc((uint)minX) 1262 if (r.RegionLocX == Util.RegionToWorldLoc((uint)minX)
1019 && r.RegionLocY == Util.RegionToWorldLoc((uint)minY) ) 1263 && r.RegionLocY == Util.RegionToWorldLoc((uint)minY) )
1020 { 1264 {
@@ -1024,6 +1268,20 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1024 response.AddRange(Map2BlockFromGridRegion(r, flag)); 1268 response.AddRange(Map2BlockFromGridRegion(r, flag));
1025 else 1269 else
1026 response.Add(MapBlockFromGridRegion(r, flag)); 1270 response.Add(MapBlockFromGridRegion(r, flag));
1271=======
1272 if (r.RegionLocX == Util.RegionToWorldLoc((uint)minX) &&
1273 r.RegionLocY == Util.RegionToWorldLoc((uint)minY))
1274 {
1275 // found it => add it to response
1276 MapBlockData block = new MapBlockData();
1277 if ((flag & 2) == 2)
1278 response.AddRange(Map2BlockFromGridRegion(r, flag));
1279 else
1280 {
1281 MapBlockFromGridRegion(block, r, flag);
1282 response.Add(block);
1283 }
1284>>>>>>> avn/ubitvar
1027 break; 1285 break;
1028 } 1286 }
1029 } 1287 }
@@ -1036,7 +1294,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1036 block.X = (ushort)minX; 1294 block.X = (ushort)minX;
1037 block.Y = (ushort)minY; 1295 block.Y = (ushort)minY;
1038 block.Access = (byte)SimAccess.Down; // means 'simulator is offline' 1296 block.Access = (byte)SimAccess.Down; // means 'simulator is offline'
1297<<<<<<< HEAD
1039 // block.Access = (byte)SimAccess.NonExistent; 1298 // block.Access = (byte)SimAccess.NonExistent;
1299=======
1300>>>>>>> avn/ubitvar
1040 response.Add(block); 1301 response.Add(block);
1041 } 1302 }
1042 // The lower 16 bits are an unsigned int16 1303 // The lower 16 bits are an unsigned int16
@@ -1045,14 +1306,74 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1045 else 1306 else
1046 { 1307 {
1047 // normal mapblock request. Use the provided values 1308 // normal mapblock request. Use the provided values
1309 */
1048 GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag); 1310 GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag);
1049 } 1311 // }
1050 } 1312 }
1051 1313
1052 protected virtual List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) 1314 protected virtual List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
1053 { 1315 {
1316 MapBlockRequestData req = new MapBlockRequestData();
1317
1318 req.client = remoteClient;
1319 req.minX = minX;
1320 req.maxX = maxX;
1321 req.minY = minY;
1322 req.maxY = maxY;
1323 req.flags = flag;
1324
1325 lock (m_mapBlockRequestEvent)
1326 {
1327 if (!m_mapBlockRequests.ContainsKey(remoteClient.AgentId))
1328 m_mapBlockRequests[remoteClient.AgentId] = new Queue<MapBlockRequestData>();
1329 m_mapBlockRequests[remoteClient.AgentId].Enqueue(req);
1330 m_mapBlockRequestEvent.Set();
1331 }
1332
1333 return new List<MapBlockData>();
1334 }
1335
1336 protected void MapBlockSendThread()
1337 {
1338 while (true)
1339 {
1340 List<MapBlockRequestData> thisRunData = new List<MapBlockRequestData>();
1341
1342 m_mapBlockRequestEvent.WaitOne();
1343 lock (m_mapBlockRequestEvent)
1344 {
1345 int total = 0;
1346 foreach (Queue<MapBlockRequestData> q in m_mapBlockRequests.Values)
1347 {
1348 if (q.Count > 0)
1349 thisRunData.Add(q.Dequeue());
1350
1351 total += q.Count;
1352 }
1353
1354 if (total == 0)
1355 m_mapBlockRequestEvent.Reset();
1356 }
1357
1358 foreach (MapBlockRequestData req in thisRunData)
1359 {
1360 // Null client stops thread
1361 if (req.client == null)
1362 return;
1363
1364 GetAndSendBlocksInternal(req.client, req.minX, req.minY, req.maxX, req.maxY, req.flags);
1365 }
1366
1367 Thread.Sleep(50);
1368 }
1369 }
1370
1371 protected virtual List<MapBlockData> GetAndSendBlocksInternal(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
1372 {
1373 List<MapBlockData> allBlocks = new List<MapBlockData>();
1054 List<MapBlockData> mapBlocks = new List<MapBlockData>(); 1374 List<MapBlockData> mapBlocks = new List<MapBlockData>();
1055 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, 1375 List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
1376<<<<<<< HEAD
1056 (int)Util.RegionToWorldLoc((uint)(minX - 4)), (int)Util.RegionToWorldLoc((uint)(maxX + 4)), 1377 (int)Util.RegionToWorldLoc((uint)(minX - 4)), (int)Util.RegionToWorldLoc((uint)(maxX + 4)),
1057 (int)Util.RegionToWorldLoc((uint)(minY - 4)), (int)Util.RegionToWorldLoc((uint)(maxY + 4)) ); 1378 (int)Util.RegionToWorldLoc((uint)(minY - 4)), (int)Util.RegionToWorldLoc((uint)(maxY + 4)) );
1058 //m_log.DebugFormat("{0} GetAndSendBlocks. min=<{1},{2}>, max=<{3},{4}>, cntFound={5}", 1379 //m_log.DebugFormat("{0} GetAndSendBlocks. min=<{1},{2}>, max=<{3},{4}>, cntFound={5}",
@@ -1064,14 +1385,65 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1064 mapBlocks.AddRange(Map2BlockFromGridRegion(r, flag)); 1385 mapBlocks.AddRange(Map2BlockFromGridRegion(r, flag));
1065 else 1386 else
1066 mapBlocks.Add(MapBlockFromGridRegion(r, flag)); 1387 mapBlocks.Add(MapBlockFromGridRegion(r, flag));
1388=======
1389 minX * (int)Constants.RegionSize,
1390 maxX * (int)Constants.RegionSize,
1391 minY * (int)Constants.RegionSize,
1392 maxY * (int)Constants.RegionSize);
1393// (minX - 4) * (int)Constants.RegionSize,
1394// (maxX + 4) * (int)Constants.RegionSize,
1395// (minY - 4) * (int)Constants.RegionSize,
1396// (maxY + 4) * (int)Constants.RegionSize);
1397
1398 //mb it means this
1399 if(regions.Count == 0 && (flag & 0x10000) != 0)
1400 {
1401 MapBlockData block = new MapBlockData();
1402 block.X = (ushort)minX;
1403 block.Y = (ushort)minY;
1404 block.MapImageId = UUID.Zero;
1405 block.Access = (byte)SimAccess.NonExistent;
1406 allBlocks.Add(block);
1407 mapBlocks.Add(block);
1408 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
1409 return allBlocks;
1410>>>>>>> avn/ubitvar
1067 } 1411 }
1068 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
1069 1412
1070 return mapBlocks; 1413 foreach (GridRegion r in regions)
1414 {
1415 MapBlockData block = new MapBlockData();
1416 if ((flag & 2) == 2)
1417 {
1418 List<MapBlockData> blocks = Map2BlockFromGridRegion(r, flag);
1419 mapBlocks.AddRange(blocks);
1420 allBlocks.AddRange(blocks);
1421 }
1422 else
1423 {
1424 MapBlockFromGridRegion(block, r, flag);
1425 mapBlocks.Add(block);
1426 allBlocks.Add(block);
1427 }
1428 if (mapBlocks.Count >= 10)
1429 {
1430 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
1431 mapBlocks.Clear();
1432 Thread.Sleep(50);
1433 }
1434 }
1435 if (mapBlocks.Count > 0)
1436 remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
1437
1438 return allBlocks;
1071 } 1439 }
1072 1440
1441<<<<<<< HEAD
1073 // Fill a passed MapBlockData from a GridRegion 1442 // Fill a passed MapBlockData from a GridRegion
1074 public MapBlockData MapBlockFromGridRegion(GridRegion r, uint flag) 1443 public MapBlockData MapBlockFromGridRegion(GridRegion r, uint flag)
1444=======
1445 public void MapBlockFromGridRegion(MapBlockData block, GridRegion r, uint flag)
1446>>>>>>> avn/ubitvar
1075 { 1447 {
1076 MapBlockData block = new MapBlockData(); 1448 MapBlockData block = new MapBlockData();
1077 1449
@@ -1089,12 +1461,54 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1089 break; 1461 break;
1090 } 1462 }
1091 block.Name = r.RegionName; 1463 block.Name = r.RegionName;
1464<<<<<<< HEAD
1092 block.X = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocX); 1465 block.X = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocX);
1093 block.Y = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocY); 1466 block.Y = (ushort)Util.WorldToRegionLoc((uint)r.RegionLocY);
1094 block.SizeX = (ushort) r.RegionSizeX; 1467 block.SizeX = (ushort) r.RegionSizeX;
1095 block.SizeY = (ushort) r.RegionSizeY; 1468 block.SizeY = (ushort) r.RegionSizeY;
1096 1469
1097 return block; 1470 return block;
1471=======
1472 block.X = (ushort)(r.RegionLocX / Constants.RegionSize);
1473 block.Y = (ushort)(r.RegionLocY / Constants.RegionSize);
1474 block.SizeX = (ushort)r.RegionSizeX;
1475 block.SizeY = (ushort)r.RegionSizeY;
1476 }
1477
1478 public List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag)
1479 {
1480 List<MapBlockData> blocks = new List<MapBlockData>();
1481 MapBlockData block = new MapBlockData();
1482 if (r == null)
1483 {
1484 block.Access = (byte)SimAccess.Down;
1485 block.MapImageId = UUID.Zero;
1486 blocks.Add(block);
1487 }
1488 else
1489 {
1490 block.Access = r.Access;
1491 switch (flag & 0xffff)
1492 {
1493 case 0:
1494 block.MapImageId = r.TerrainImage;
1495 break;
1496 case 2:
1497 block.MapImageId = r.ParcelImage;
1498 break;
1499 default:
1500 block.MapImageId = UUID.Zero;
1501 break;
1502 }
1503 block.Name = r.RegionName;
1504 block.X = (ushort)(r.RegionLocX / Constants.RegionSize);
1505 block.Y = (ushort)(r.RegionLocY / Constants.RegionSize);
1506 block.SizeX = (ushort)r.RegionSizeX;
1507 block.SizeY = (ushort)r.RegionSizeY;
1508 blocks.Add(block);
1509 }
1510 return blocks;
1511>>>>>>> avn/ubitvar
1098 } 1512 }
1099 1513
1100 public List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag) 1514 public List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag)
@@ -1338,9 +1752,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1338 uint xstart = 0; 1752 uint xstart = 0;
1339 uint ystart = 0; 1753 uint ystart = 0;
1340 1754
1755<<<<<<< HEAD
1341 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); 1756 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle,out xstart,out ystart);
1342 // m_log.DebugFormat("{0} HandleRemoteMapItemRequest. loc=<{1},{2}>", 1757 // m_log.DebugFormat("{0} HandleRemoteMapItemRequest. loc=<{1},{2}>",
1343 // LogHeader, Util.WorldToRegionLoc(xstart), Util.WorldToRegionLoc(ystart)); 1758 // LogHeader, Util.WorldToRegionLoc(xstart), Util.WorldToRegionLoc(ystart));
1759=======
1760 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
1761>>>>>>> avn/ubitvar
1344 1762
1345 // Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots) 1763 // Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots)
1346 1764
@@ -1362,7 +1780,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1362 } 1780 }
1363 else 1781 else
1364 { 1782 {
1365 OSDArray responsearr = new OSDArray(m_scene.GetRootAgentCount()); 1783 OSDArray responsearr = new OSDArray(); // Don't preallocate. MT (m_scene.GetRootAgentCount());
1366 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) 1784 m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
1367 { 1785 {
1368 OSDMap responsemapdata = new OSDMap(); 1786 OSDMap responsemapdata = new OSDMap();
@@ -1460,6 +1878,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1460 return; 1878 return;
1461 1879
1462 m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.Name); 1880 m_log.DebugFormat("[WORLD MAP]: Generating map image for {0}", m_scene.Name);
1881<<<<<<< HEAD
1463 1882
1464 using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile()) 1883 using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile())
1465 { 1884 {
@@ -1475,6 +1894,23 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1475 { 1894 {
1476 byte[] data; 1895 byte[] data;
1477 1896
1897=======
1898
1899 using (Bitmap mapbmp = m_mapImageGenerator.CreateMapTile())
1900 {
1901 // V1 (This Module)
1902 GenerateMaptile(mapbmp);
1903
1904 // v2/3 (MapImageServiceModule)
1905 m_mapImageServiceModule.UploadMapTile(m_scene, mapbmp);
1906 }
1907 }
1908
1909 private void GenerateMaptile(Bitmap mapbmp)
1910 {
1911 byte[] data;
1912
1913>>>>>>> avn/ubitvar
1478 try 1914 try
1479 { 1915 {
1480 data = OpenJPEG.EncodeFromImage(mapbmp, true); 1916 data = OpenJPEG.EncodeFromImage(mapbmp, true);
@@ -1553,6 +1989,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1553 { 1989 {
1554 m_rootAgents.Remove(avatar.UUID); 1990 m_rootAgents.Remove(avatar.UUID);
1555 } 1991 }
1992
1993 lock (m_mapBlockRequestEvent)
1994 {
1995 if (m_mapBlockRequests.ContainsKey(avatar.UUID))
1996 m_mapBlockRequests.Remove(avatar.UUID);
1997 }
1556 } 1998 }
1557 1999
1558 public void OnRegionUp(GridRegion otherRegion) 2000 public void OnRegionUp(GridRegion otherRegion)
@@ -1585,7 +2027,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1585 int regionSizeX = (int)m_scene.RegionInfo.RegionSizeX; 2027 int regionSizeX = (int)m_scene.RegionInfo.RegionSizeX;
1586 int regionSizeY = (int)m_scene.RegionInfo.RegionSizeY; 2028 int regionSizeY = (int)m_scene.RegionInfo.RegionSizeY;
1587 2029
2030<<<<<<< HEAD
1588 int landTileSize = LandManagementModule.LandUnit; 2031 int landTileSize = LandManagementModule.LandUnit;
2032=======
2033 int landTileSize = LandManagementModule.landUnit;
2034>>>>>>> avn/ubitvar
1589 int regionLandTilesX = regionSizeX / landTileSize; 2035 int regionLandTilesX = regionSizeX / landTileSize;
1590 int regionLandTilesY = regionSizeY / landTileSize; 2036 int regionLandTilesY = regionSizeY / landTileSize;
1591 2037
@@ -1608,6 +2054,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1608 { 2054 {
1609 using (SolidBrush transparent = new SolidBrush(background)) 2055 using (SolidBrush transparent = new SolidBrush(background))
1610 g.FillRectangle(transparent, 0, 0, regionSizeX, regionSizeY); 2056 g.FillRectangle(transparent, 0, 0, regionSizeX, regionSizeY);
2057<<<<<<< HEAD
2058=======
2059
2060>>>>>>> avn/ubitvar
1611 2061
1612 foreach (ILandObject land in parcels) 2062 foreach (ILandObject land in parcels)
1613 { 2063 {
@@ -1630,6 +2080,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1630 2080
1631 using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9))) 2081 using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)))
1632 { 2082 {
2083<<<<<<< HEAD
1633 for (int x = 0 ; x < regionLandTilesX ; x++) 2084 for (int x = 0 ; x < regionLandTilesX ; x++)
1634 { 2085 {
1635 for (int y = 0 ; y < regionLandTilesY ; y++) 2086 for (int y = 0 ; y < regionLandTilesY ; y++)
@@ -1639,6 +2090,18 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1639 yellow, x * landTileSize, 2090 yellow, x * landTileSize,
1640 regionSizeX - landTileSize - (y * landTileSize), 2091 regionSizeX - landTileSize - (y * landTileSize),
1641 landTileSize, 2092 landTileSize,
2093=======
2094 for (int x = 0; x < regionLandTilesX ; x++)
2095 {
2096 for (int y = 0; y < regionLandTilesY ; y++)
2097 {
2098 if (saleBitmap[x, y])
2099 g.FillRectangle(
2100 yellow,
2101 x * landTileSize,
2102 regionSizeX - landTileSize - (y * landTileSize),
2103 landTileSize,
2104>>>>>>> avn/ubitvar
1642 landTileSize); 2105 landTileSize);
1643 } 2106 }
1644 } 2107 }
@@ -1668,4 +2131,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1668 public uint itemtype; 2131 public uint itemtype;
1669 public ulong regionhandle; 2132 public ulong regionhandle;
1670 } 2133 }
2134
2135 public struct MapBlockRequestData
2136 {
2137 public IClientAPI client;
2138 public int minX;
2139 public int minY;
2140 public int maxX;
2141 public int maxY;
2142 public uint flags;
2143 }
1671} 2144}
diff --git a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
index 600e826..7472050 100644
--- a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
+++ b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
@@ -402,6 +402,7 @@ namespace OpenSim.Region.DataSnapshot
402 string url = services[i].Trim(); 402 string url = services[i].Trim();
403 using (RestClient cli = new RestClient(url)) 403 using (RestClient cli = new RestClient(url))
404 { 404 {
405<<<<<<< HEAD
405 cli.AddQueryParameter("service", serviceName); 406 cli.AddQueryParameter("service", serviceName);
406 cli.AddQueryParameter("host", m_hostname); 407 cli.AddQueryParameter("host", m_hostname);
407 cli.AddQueryParameter("port", m_listener_port); 408 cli.AddQueryParameter("port", m_listener_port);
@@ -435,6 +436,28 @@ namespace OpenSim.Region.DataSnapshot
435 // string responseStr = Util.UTF8.GetString(response); 436 // string responseStr = Util.UTF8.GetString(response);
436 m_log.Info("[DATASNAPSHOT]: data service " + url + " notified. Secret: " + m_Secret); 437 m_log.Info("[DATASNAPSHOT]: data service " + url + " notified. Secret: " + m_Secret);
437 } 438 }
439=======
440 m_log.Warn("[DATASNAPSHOT]: Ignoring unknown exception " + e.ToString());
441 }
442
443 byte[] response = new byte[1024];
444 // int n = 0;
445 try
446 {
447 // n = reply.Read(response, 0, 1024);
448 reply.Read(response, 0, 1024);
449 }
450 catch (Exception e)
451 {
452 m_log.WarnFormat("[DATASNAPSHOT]: Unable to decode reply from data service. Ignoring. {0}", e.StackTrace);
453 }
454 // This is not quite working, so...
455 // string responseStr = Util.UTF8.GetString(response);
456 m_log.Info("[DATASNAPSHOT]: data service " + url + " notified. Secret: " + m_Secret);
457
458 if(reply != null)
459 reply.Close();
460>>>>>>> avn/ubitvar
438 } 461 }
439 462
440 } 463 }
diff --git a/OpenSim/Region/Framework/Interfaces/IAgentAssetTransactions.cs b/OpenSim/Region/Framework/Interfaces/IAgentAssetTransactions.cs
index 0cc8fb6..e0aad2b 100644
--- a/OpenSim/Region/Framework/Interfaces/IAgentAssetTransactions.cs
+++ b/OpenSim/Region/Framework/Interfaces/IAgentAssetTransactions.cs
@@ -36,7 +36,7 @@ namespace OpenSim.Region.Framework.Interfaces
36 void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, 36 void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID,
37 InventoryItemBase item); 37 InventoryItemBase item);
38 38
39 void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, 39 bool HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID,
40 uint callbackID, string description, string name, sbyte invType, 40 uint callbackID, string description, string name, sbyte invType,
41 sbyte type, byte wearableType, uint nextOwnerMask); 41 sbyte type, byte wearableType, uint nextOwnerMask);
42 42
diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
index d9901bd..3c1247f 100644
--- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using OpenMetaverse; 31using OpenMetaverse;
31using OpenSim.Framework; 32using OpenSim.Framework;
@@ -89,7 +90,7 @@ namespace OpenSim.Region.Framework.Interfaces
89 /// <param name="addToInventory">If true then add object to user inventory</param> 90 /// <param name="addToInventory">If true then add object to user inventory</param>
90 /// <param name="append">Append to attachment point rather than replace.</param> 91 /// <param name="append">Append to attachment point rather than replace.</param>
91 /// <returns>true if the object was successfully attached, false otherwise</returns> 92 /// <returns>true if the object was successfully attached, false otherwise</returns>
92 bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent, bool addToInventory, bool append); 93 bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent, bool useAttachmentInfo, bool addToInventory, bool append);
93 94
94 /// <summary> 95 /// <summary>
95 /// Rez an attachment from user inventory and change inventory status to match. 96 /// Rez an attachment from user inventory and change inventory status to match.
@@ -98,7 +99,11 @@ namespace OpenSim.Region.Framework.Interfaces
98 /// <param name="itemID"></param> 99 /// <param name="itemID"></param>
99 /// <param name="AttachmentPt"></param> 100 /// <param name="AttachmentPt"></param>
100 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns> 101 /// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
101 SceneObjectGroup RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt); 102 ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt);
103
104 // Same as above, but also load script states from a separate doc
105 ISceneEntity RezSingleAttachmentFromInventory(
106 IScenePresence presence, UUID itemID, uint AttachmentPt, XmlDocument doc);
102 107
103 /// <summary> 108 /// <summary>
104 /// Rez multiple attachments from a user's inventory 109 /// Rez multiple attachments from a user's inventory
@@ -130,7 +135,6 @@ namespace OpenSim.Region.Framework.Interfaces
130 /// <param name="grp">The attachment to detach.</param> 135 /// <param name="grp">The attachment to detach.</param>
131 void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup grp); 136 void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup grp);
132 137
133 /// <summary>
134 /// Update the position of an attachment. 138 /// Update the position of an attachment.
135 /// </summary> 139 /// </summary>
136 /// <param name="sog"></param> 140 /// <param name="sog"></param>
diff --git a/OpenSim/Region/Framework/Interfaces/IBakedTextureModule.cs b/OpenSim/Region/Framework/Interfaces/IBakedTextureModule.cs
index b536a49..570d31c 100644
--- a/OpenSim/Region/Framework/Interfaces/IBakedTextureModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IBakedTextureModule.cs
@@ -35,6 +35,7 @@ namespace OpenSim.Services.Interfaces
35 public interface IBakedTextureModule 35 public interface IBakedTextureModule
36 { 36 {
37 WearableCacheItem[] Get(UUID id); 37 WearableCacheItem[] Get(UUID id);
38 void Store(UUID id, WearableCacheItem[] data); 38 void Store(UUID id);
39 void UpdateMeshAvatar(UUID id);
39 } 40 }
40} 41}
diff --git a/OpenSim/Region/Framework/Interfaces/ICapabilitiesModule.cs b/OpenSim/Region/Framework/Interfaces/ICapabilitiesModule.cs
index 522c82d..30d404e 100644
--- a/OpenSim/Region/Framework/Interfaces/ICapabilitiesModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/ICapabilitiesModule.cs
@@ -40,19 +40,19 @@ namespace OpenSim.Region.Framework.Interfaces
40 /// </summary> 40 /// </summary>
41 /// <param name="agentId"></param> 41 /// <param name="agentId"></param>
42 /// <param name="capsObjectPath"></param> 42 /// <param name="capsObjectPath"></param>
43 void CreateCaps(UUID agentId); 43 void CreateCaps(UUID agentId, uint circuitCode);
44 44
45 /// <summary> 45 /// <summary>
46 /// Remove the caps handler for a given agent. 46 /// Remove the caps handler for a given agent.
47 /// </summary> 47 /// </summary>
48 /// <param name="agentId"></param> 48 /// <param name="agentId"></param>
49 void RemoveCaps(UUID agentId); 49 void RemoveCaps(UUID agentId, uint circuitCode);
50 50
51 /// <summary> 51 /// <summary>
52 /// Will return null if the agent doesn't have a caps handler registered 52 /// Will return null if the agent doesn't have a caps handler registered
53 /// </summary> 53 /// </summary>
54 /// <param name="agentId"></param> 54 /// <param name="agentId"></param>
55 Caps GetCapsForUser(UUID agentId); 55 Caps GetCapsForUser(uint circuitCode);
56 56
57 void SetAgentCapsSeeds(AgentCircuitData agent); 57 void SetAgentCapsSeeds(AgentCircuitData agent);
58 58
@@ -65,5 +65,7 @@ namespace OpenSim.Region.Framework.Interfaces
65 void DropChildSeed(UUID agentID, ulong handle); 65 void DropChildSeed(UUID agentID, ulong handle);
66 66
67 string GetCapsPath(UUID agentId); 67 string GetCapsPath(UUID agentId);
68
69 void ActivateCaps(uint circuitCode);
68 } 70 }
69} 71}
diff --git a/OpenSim/Region/Framework/Interfaces/IDynamicMenuModule.cs b/OpenSim/Region/Framework/Interfaces/IDynamicMenuModule.cs
index 08b71e4..4d000b6 100644
--- a/OpenSim/Region/Framework/Interfaces/IDynamicMenuModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IDynamicMenuModule.cs
@@ -43,6 +43,7 @@ namespace OpenSim.Region.Framework.Interfaces
43 public enum UserMode : int 43 public enum UserMode : int
44 { 44 {
45 Normal = 0, 45 Normal = 0,
46 RegionManager = 2,
46 God = 3 47 God = 3
47 } 48 }
48 49
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index 9ffda51..b85fd8b 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -133,6 +133,8 @@ namespace OpenSim.Region.Framework.Interfaces
133 /// </returns> 133 /// </returns>
134 bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource); 134 bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
135 135
136 ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
137
136 /// <summary> 138 /// <summary>
137 /// Stop and remove a script which is in this prim's inventory from the scene. 139 /// Stop and remove a script which is in this prim's inventory from the scene.
138 /// </summary> 140 /// </summary>
@@ -244,7 +246,7 @@ namespace OpenSim.Region.Framework.Interfaces
244 /// <param name="objlist">The scene objects</param> 246 /// <param name="objlist">The scene objects</param>
245 /// <param name="veclist">Relative offsets for each object</param> 247 /// <param name="veclist">Relative offsets for each object</param>
246 /// <returns>true = success, false = the scene object asset couldn't be found</returns> 248 /// <returns>true = success, false = the scene object asset couldn't be found</returns>
247 bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist); 249 bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist, out Vector3 bbox, out float offsetHeight);
248 250
249 /// <summary> 251 /// <summary>
250 /// Update an existing inventory item. 252 /// Update an existing inventory item.
@@ -318,5 +320,6 @@ namespace OpenSim.Region.Framework.Interfaces
318 /// A <see cref="Dictionary`2"/> 320 /// A <see cref="Dictionary`2"/>
319 /// </returns> 321 /// </returns>
320 Dictionary<UUID, string> GetScriptStates(); 322 Dictionary<UUID, string> GetScriptStates();
323 Dictionary<UUID, string> GetScriptStates(bool oldIDs);
321 } 324 }
322} 325}
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 1ebef90..50448b4 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -36,6 +36,7 @@ using OpenSim.Region.Framework.Scenes;
36namespace OpenSim.Region.Framework.Interfaces 36namespace OpenSim.Region.Framework.Interfaces
37{ 37{
38 public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version); 38 public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version);
39 public delegate ScenePresence CrossAsyncDelegate(ScenePresence agent, bool isFlying);
39 40
40 public interface IEntityTransferModule 41 public interface IEntityTransferModule
41 { 42 {
@@ -92,10 +93,17 @@ namespace OpenSim.Region.Framework.Interfaces
92 93
93 void EnableChildAgent(ScenePresence agent, GridRegion region); 94 void EnableChildAgent(ScenePresence agent, GridRegion region);
94 95
96<<<<<<< HEAD
95 GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version, 97 GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version,
96 out Vector3 newpos, out string reason); 98 out Vector3 newpos, out string reason);
97 99
100=======
101 GridRegion GetDestination(Scene scene, UUID agentID, Vector3 pos, out string version, out Vector3 newpos);
102 GridRegion GetObjectDestination(SceneObjectGroup grp, Vector3 targetPosition, out Vector3 newpos);
103 bool checkAgentAccessToRegion(ScenePresence agent, GridRegion destiny, Vector3 position, out string version, out string reason);
104>>>>>>> avn/ubitvar
98 void Cross(SceneObjectGroup sog, Vector3 position, bool silent); 105 void Cross(SceneObjectGroup sog, Vector3 position, bool silent);
106 bool CrossPrimGroupIntoNewRegion(GridRegion destination, Vector3 newPosition, SceneObjectGroup grp, bool silent);
99 107
100 ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version); 108 ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version);
101 109
diff --git a/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs b/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs
index 124504c..2f9b222 100644
--- a/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs
+++ b/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs
@@ -58,6 +58,7 @@ namespace OpenSim.Region.Framework.Interfaces
58 public interface IHttpRequestModule 58 public interface IHttpRequestModule
59 { 59 {
60 UUID MakeHttpRequest(string url, string parameters, string body); 60 UUID MakeHttpRequest(string url, string parameters, string body);
61<<<<<<< HEAD
61 62
62 /// <summary> 63 /// <summary>
63 /// Starts the http request. 64 /// Starts the http request.
@@ -87,6 +88,10 @@ namespace OpenSim.Region.Framework.Interfaces
87 /// <param name='id'></param> 88 /// <param name='id'></param>
88 void StopHttpRequestsForScript(UUID id); 89 void StopHttpRequestsForScript(UUID id);
89 90
91=======
92 UUID StartHttpRequest(uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body);
93 void StopHttpRequest(uint m_localID, UUID m_itemID);
94>>>>>>> avn/ubitvar
90 IServiceRequest GetNextCompletedRequest(); 95 IServiceRequest GetNextCompletedRequest();
91 void RemoveCompletedRequest(UUID id); 96 void RemoveCompletedRequest(UUID id);
92 } 97 }
diff --git a/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs b/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs
index 6a7d4a1..eb79711 100644
--- a/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IMapImageUploadModule.cs
@@ -25,13 +25,29 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28<<<<<<< HEAD
28using System.Drawing; 29using System.Drawing;
29using OpenSim.Framework; 30using OpenSim.Framework;
31=======
32using OpenMetaverse;
33using OpenSim.Framework;
34using System.Drawing;
35>>>>>>> avn/ubitvar
30 36
31namespace OpenSim.Region.Framework.Interfaces 37namespace OpenSim.Region.Framework.Interfaces
32{ 38{
33 public interface IMapImageUploadModule 39 public interface IMapImageUploadModule
34 { 40 {
41<<<<<<< HEAD
42 void UploadMapTile(IScene scene, Bitmap mapTile);
43 }
44}
45=======
46 /// <summary>
47 /// Upload a new maptile
48 /// </summary>
49 void UploadMapTile(IScene scene);
35 void UploadMapTile(IScene scene, Bitmap mapTile); 50 void UploadMapTile(IScene scene, Bitmap mapTile);
36 } 51 }
37} \ No newline at end of file 52}
53>>>>>>> avn/ubitvar
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
index 99bc87d..445342d 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs
@@ -127,7 +127,12 @@ namespace OpenSim.Region.Framework.Interfaces
127 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param> 127 /// <param name="requestId">If supplied, this request Id is later returned in the saved event</param>
128 /// <param name="options"> 128 /// <param name="options">
129 /// Dictionary of options. 129 /// Dictionary of options.
130<<<<<<< HEAD
130 /// </param> 131 /// </param>
131 void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string,object> options); 132 void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string,object> options);
133=======
134 /// </param>
135 void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options);
136>>>>>>> avn/ubitvar
132 } 137 }
133} 138}
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionConsole.cs b/OpenSim/Region/Framework/Interfaces/IRegionConsole.cs
index 4d261d6..5d5ce34 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionConsole.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionConsole.cs
@@ -30,8 +30,12 @@ using OpenSim.Framework;
30 30
31namespace OpenSim.Region.Framework.Interfaces 31namespace OpenSim.Region.Framework.Interfaces
32{ 32{
33 public delegate void ConsoleMessage(UUID toAgentID, string message);
34
33 public interface IRegionConsole 35 public interface IRegionConsole
34 { 36 {
37 event ConsoleMessage OnConsoleMessage;
38
35 bool RunCommand(string command, UUID invokerID); 39 bool RunCommand(string command, UUID invokerID);
36 void SendConsoleOutput(UUID agentID, string message); 40 void SendConsoleOutput(UUID agentID, string message);
37 void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn); 41 void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn);
diff --git a/OpenSim/Region/Framework/Interfaces/IRestartModule.cs b/OpenSim/Region/Framework/Interfaces/IRestartModule.cs
index c68550f..9b25beb 100644
--- a/OpenSim/Region/Framework/Interfaces/IRestartModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRestartModule.cs
@@ -35,5 +35,6 @@ namespace OpenSim.Region.Framework.Interfaces
35 TimeSpan TimeUntilRestart { get; } 35 TimeSpan TimeUntilRestart { get; }
36 void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice); 36 void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice);
37 void AbortRestart(string message); 37 void AbortRestart(string message);
38 void DelayRestart(int seconds, string message);
38 } 39 }
39} 40}
diff --git a/OpenSim/Region/Framework/Interfaces/ISearchModule.cs b/OpenSim/Region/Framework/Interfaces/ISearchModule.cs
index 64bf72c..d56d188 100644
--- a/OpenSim/Region/Framework/Interfaces/ISearchModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISearchModule.cs
@@ -31,6 +31,6 @@ namespace OpenSim.Framework
31{ 31{
32 public interface ISearchModule 32 public interface ISearchModule
33 { 33 {
34 34 void Refresh();
35 } 35 }
36} 36}
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
index 8948f04..13358cb 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataService.cs
@@ -125,6 +125,8 @@ namespace OpenSim.Region.Framework.Interfaces
125 /// <param name="regionUUID">the region UUID</param> 125 /// <param name="regionUUID">the region UUID</param>
126 void RemoveRegionEnvironmentSettings(UUID regionUUID); 126 void RemoveRegionEnvironmentSettings(UUID regionUUID);
127 127
128 UUID[] GetObjectIDs(UUID regionID);
129
128 void SaveExtra(UUID regionID, string name, string value); 130 void SaveExtra(UUID regionID, string name, string value);
129 131
130 void RemoveExtra(UUID regionID, string name); 132 void RemoveExtra(UUID regionID, string name);
diff --git a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
index 917b5d1..e09f775 100644
--- a/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISimulationDataStore.cs
@@ -115,6 +115,7 @@ namespace OpenSim.Region.Framework.Interfaces
115 RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID); 115 RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID);
116 void StoreRegionWindlightSettings(RegionLightShareData wl); 116 void StoreRegionWindlightSettings(RegionLightShareData wl);
117 void RemoveRegionWindlightSettings(UUID regionID); 117 void RemoveRegionWindlightSettings(UUID regionID);
118 UUID[] GetObjectIDs(UUID regionID);
118 119
119 /// <summary> 120 /// <summary>
120 /// Load Environment settings from region storage 121 /// Load Environment settings from region storage
diff --git a/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
new file mode 100644
index 0000000..e01f649
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
@@ -0,0 +1,27 @@
1///////////////////////////////////////////////////////////////////
2//
3// (c) Careminster LImited, Melanie Thielker and the Meta7 Team
4//
5// This file is not open source. All rights reserved
6// Mod 2
7
8using OpenSim.Region.Framework.Scenes;
9
10public interface ISnmpModule
11{
12 void Trap(int code, string Message, Scene scene);
13 void Critical(string Message, Scene scene);
14 void Warning(string Message, Scene scene);
15 void Major(string Message, Scene scene);
16 void ColdStart(int step , Scene scene);
17 void Shutdown(int step , Scene scene);
18 //
19 // Node Start/stop events
20 //
21 void LinkUp(Scene scene);
22 void LinkDown(Scene scene);
23 void BootInfo(string data, Scene scene);
24 void trapDebug(string Module,string data, Scene scene);
25 void trapXMRE(int data, string Message, Scene scene);
26
27}
diff --git a/OpenSim/Region/Framework/Interfaces/ISoundModule.cs b/OpenSim/Region/Framework/Interfaces/ISoundModule.cs
index 8372ddd..f7c6513 100644
--- a/OpenSim/Region/Framework/Interfaces/ISoundModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/ISoundModule.cs
@@ -95,7 +95,7 @@ namespace OpenSim.Region.Framework.Interfaces
95 /// <param name="radius">Sound radius</param> 95 /// <param name="radius">Sound radius</param>
96 /// <param name="isMaster">Set object to sync master if true</param> 96 /// <param name="isMaster">Set object to sync master if true</param>
97 void LoopSound(UUID objectID, UUID soundID, double gain, 97 void LoopSound(UUID objectID, UUID soundID, double gain,
98 double radius, bool isMaster); 98 double radius, bool isMaster, bool isSlave);
99 99
100 /// <summary> 100 /// <summary>
101 /// Trigger or play an attached sound in this part's inventory. 101 /// Trigger or play an attached sound in this part's inventory.
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
index 28f797a..ff18519 100644
--- a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs
@@ -28,6 +28,11 @@ using System.IO;
28 28
29using OpenSim.Framework; 29using OpenSim.Framework;
30 30
31<<<<<<< HEAD
32=======
33using System.IO;
34using OpenSim.Framework;
35>>>>>>> avn/ubitvar
31using OpenMetaverse; 36using OpenMetaverse;
32 37
33namespace OpenSim.Region.Framework.Interfaces 38namespace OpenSim.Region.Framework.Interfaces
@@ -43,7 +48,13 @@ namespace OpenSim.Region.Framework.Interfaces
43 /// Use this if you change terrain data outside of the terrain module (e.g. in osTerrainSetHeight) 48 /// Use this if you change terrain data outside of the terrain module (e.g. in osTerrainSetHeight)
44 /// </summary> 49 /// </summary>
45 void TaintTerrain(); 50 void TaintTerrain();
46 51
52 /// <summary>
53 /// When a client initially connects, all the terrain must be pushed to the viewer.
54 /// This call causes all the terrain patches to be sent to the client.
55 /// </summary>
56 void PushTerrain(IClientAPI pClient);
57
47 /// <summary> 58 /// <summary>
48 /// When a client initially connects, all the terrain must be pushed to the viewer. 59 /// When a client initially connects, all the terrain must be pushed to the viewer.
49 /// This call causes all the terrain patches to be sent to the client. 60 /// This call causes all the terrain patches to be sent to the client.
@@ -60,6 +71,8 @@ namespace OpenSim.Region.Framework.Interfaces
60 void LoadFromStream(string filename, Stream stream); 71 void LoadFromStream(string filename, Stream stream);
61 void LoadFromStream(string filename, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement, Stream stream); 72 void LoadFromStream(string filename, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement, Stream stream);
62 void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap); 73 void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap);
74 void LoadFromStream(string filename, Vector3 displacement,
75 float radianRotation, Vector2 rotationDisplacement, Stream stream);
63 /// <summary> 76 /// <summary>
64 /// Save a terrain to a stream. 77 /// Save a terrain to a stream.
65 /// </summary> 78 /// </summary>
diff --git a/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs b/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs
new file mode 100644
index 0000000..d1a4d8e
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IUserAccountCacheModule.cs
@@ -0,0 +1,13 @@
1///////////////////////////////////////////////////////////////////
2//
3// (c) Careminster Limited, Melanie Thielker and the Meta7 Team
4//
5// This file is not open source. All rights reserved
6//
7
8using OpenSim.Region.Framework.Scenes;
9
10public interface IUserAccountCacheModule
11{
12 void Remove(string name);
13}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index d76a0d7..20e0199 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -127,7 +127,7 @@ namespace OpenSim.Region.Framework.Interfaces
127 /// <param name='msg'> 127 /// <param name='msg'>
128 /// Message. 128 /// Message.
129 /// </param> 129 /// </param>
130 void DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg); 130 bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error);
131 131
132 /// <summary> 132 /// <summary>
133 /// Are there any listen events ready to be dispatched? 133 /// Are there any listen events ready to be dispatched?
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldMapModule.cs b/OpenSim/Region/Framework/Interfaces/IWorldMapModule.cs
index 9c781e1..08dc3e3 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldMapModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldMapModule.cs
@@ -37,6 +37,10 @@ namespace OpenSim.Region.Framework.Interfaces
37 /// </summary> 37 /// </summary>
38 void GenerateMaptile(); 38 void GenerateMaptile();
39 List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag); 39 List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag);
40<<<<<<< HEAD
40 MapBlockData MapBlockFromGridRegion(GridRegion r, uint flag); 41 MapBlockData MapBlockFromGridRegion(GridRegion r, uint flag);
42=======
43 void MapBlockFromGridRegion(MapBlockData block, GridRegion r, uint flag);
44>>>>>>> avn/ubitvar
41 } 45 }
42} 46}
diff --git a/OpenSim/Region/Framework/Scenes/Animation/MovementAnimationOverrides.cs b/OpenSim/Region/Framework/Scenes/Animation/MovementAnimationOverrides.cs
new file mode 100644
index 0000000..31fdb2c
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Animation/MovementAnimationOverrides.cs
@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Xml;
30using System.Collections.Generic;
31using System.Reflection;
32using System.Threading;
33using System.Timers;
34using Timer = System.Timers.Timer;
35using OpenMetaverse;
36using log4net;
37using Nini.Config;
38using OpenSim.Framework;
39using OpenSim.Framework.Client;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes.Animation;
42using OpenSim.Region.Framework.Scenes.Types;
43using OpenSim.Region.Physics.Manager;
44using GridRegion = OpenSim.Services.Interfaces.GridRegion;
45using OpenSim.Services.Interfaces;
46using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags;
47
48namespace OpenSim.Region.Framework.Scenes
49{
50 public class MovementAnimationOverrides
51 {
52 private static readonly ILog m_log =
53 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private Dictionary<string, UUID> m_overrides = new Dictionary<string, UUID>();
56 public void SetOverride(string state, UUID animID)
57 {
58 if (animID == UUID.Zero)
59 {
60 if (state == "ALL")
61 m_overrides.Clear();
62 else
63 m_overrides.Remove(state);
64 return;
65 }
66
67 m_log.DebugFormat("Setting override for {0} to {1}", state, animID);
68
69 lock (m_overrides)
70 m_overrides[state] = animID;
71 }
72
73 public UUID GetOverriddenAnimation(string state)
74 {
75 lock (m_overrides)
76 {
77 if (m_overrides.ContainsKey(state))
78 return m_overrides[state];
79 }
80
81 return UUID.Zero;
82 }
83
84 public Dictionary<string, UUID> CloneAOPairs()
85 {
86 lock (m_overrides)
87 {
88 return new Dictionary<string, UUID>(m_overrides);
89 }
90 }
91
92 public void CopyAOPairsFrom(Dictionary<string, UUID> src)
93 {
94 lock (m_overrides)
95 {
96 m_overrides.Clear();
97 m_overrides = new Dictionary<string, UUID>(src);
98 }
99 }
100 }
101}
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 5beee73..ade908d 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
48 48
49 public AnimationSet Animations 49 public AnimationSet Animations
50 { 50 {
51 get { return m_animations; } 51 get { return m_animations; }
52 } 52 }
53 protected AnimationSet m_animations = new AnimationSet(); 53 protected AnimationSet m_animations = new AnimationSet();
54 54
@@ -56,39 +56,42 @@ namespace OpenSim.Region.Framework.Scenes.Animation
56 /// The current movement animation 56 /// The current movement animation
57 /// </value> 57 /// </value>
58 public string CurrentMovementAnimation { get; private set; } 58 public string CurrentMovementAnimation { get; private set; }
59 59
60 private int m_animTickFall; 60 private int m_animTickFall;
61 public int m_animTickJump; // ScenePresence has to see this to control +Z force 61 private int m_animTickLand;
62 public bool m_jumping = false; 62 private int m_animTickJump;
63 public float m_jumpVelocity = 0f; 63
64// private int m_landing = 0; 64 public bool m_jumping = false;
65
66 // private int m_landing = 0;
65 67
66 /// <summary> 68 /// <summary>
67 /// Is the avatar falling? 69 /// Is the avatar falling?
68 /// </summary> 70 /// </summary>
69 public bool Falling { get; private set; } 71 public bool Falling { get; private set; }
70 72
71 private float m_fallHeight; 73 private float m_lastFallVelocity;
72 74
73 /// <value> 75 /// <value>
74 /// The scene presence that this animator applies to 76 /// The scene presence that this animator applies to
75 /// </value> 77 /// </value>
76 protected ScenePresence m_scenePresence; 78 protected ScenePresence m_scenePresence;
77 79
78 public ScenePresenceAnimator(ScenePresence sp) 80 public ScenePresenceAnimator(ScenePresence sp)
79 { 81 {
80 m_scenePresence = sp; 82 m_scenePresence = sp;
81 CurrentMovementAnimation = "CROUCH"; 83 CurrentMovementAnimation = "CROUCH";
82 } 84 }
83 85
84 public void AddAnimation(UUID animID, UUID objectID) 86 public void AddAnimation(UUID animID, UUID objectID)
85 { 87 {
86 if (m_scenePresence.IsChildAgent) 88 if (m_scenePresence.IsChildAgent)
87 return; 89 return;
88 90
91 // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Adding animation {0} for {1}", animID, m_scenePresence.Name);
89 if (m_scenePresence.Scene.DebugAnimations) 92 if (m_scenePresence.Scene.DebugAnimations)
90 m_log.DebugFormat( 93 m_log.DebugFormat(
91 "[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}", 94 "[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}",
92 GetAnimName(animID), animID, m_scenePresence.Name); 95 GetAnimName(animID), animID, m_scenePresence.Name);
93 96
94 if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID)) 97 if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID))
@@ -110,7 +113,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
110 if (animID == UUID.Zero) 113 if (animID == UUID.Zero)
111 return; 114 return;
112 115
113// m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}", animID, name, m_scenePresence.Name); 116 // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}", animID, name, m_scenePresence.Name);
114 117
115 AddAnimation(animID, objectID); 118 AddAnimation(animID, objectID);
116 } 119 }
@@ -130,7 +133,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
130 133
131 if (m_scenePresence.Scene.DebugAnimations) 134 if (m_scenePresence.Scene.DebugAnimations)
132 m_log.DebugFormat( 135 m_log.DebugFormat(
133 "[SCENE PRESENCE ANIMATOR]: Removing animation {0} {1} for {2}", 136 "[SCENE PRESENCE ANIMATOR]: Removing animation {0} {1} for {2}",
134 GetAnimName(animID), animID, m_scenePresence.Name); 137 GetAnimName(animID), animID, m_scenePresence.Name);
135 138
136 if (m_animations.Remove(animID, allowNoDefault)) 139 if (m_animations.Remove(animID, allowNoDefault))
@@ -140,6 +143,22 @@ namespace OpenSim.Region.Framework.Scenes.Animation
140 } 143 }
141 } 144 }
142 145
146 public void avnChangeAnim(UUID animID, bool addRemove, bool sendPack)
147 {
148 if (m_scenePresence.IsChildAgent)
149 return;
150
151 if (animID != UUID.Zero)
152 {
153 if (addRemove)
154 m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero);
155 else
156 m_animations.Remove(animID, false);
157 }
158 if (sendPack)
159 SendAnimPack();
160 }
161
143 // Called from scripts 162 // Called from scripts
144 public void RemoveAnimation(string name) 163 public void RemoveAnimation(string name)
145 { 164 {
@@ -164,12 +183,19 @@ namespace OpenSim.Region.Framework.Scenes.Animation
164 183
165 m_animations.Clear(); 184 m_animations.Clear();
166 } 185 }
167 186
187
188 UUID aoSitGndAnim = UUID.Zero;
189
168 /// <summary> 190 /// <summary>
169 /// The movement animation is reserved for "main" animations 191 /// The movement animation is reserved for "main" animations
170 /// that are mutually exclusive, e.g. flying and sitting. 192 /// that are mutually exclusive, e.g. flying and sitting.
171 /// </summary> 193 /// </summary>
172 /// <returns>'true' if the animation was updated</returns> 194 /// <returns>'true' if the animation was updated</returns>
195 ///
196
197
198
173 public bool TrySetMovementAnimation(string anim) 199 public bool TrySetMovementAnimation(string anim)
174 { 200 {
175 bool ret = false; 201 bool ret = false;
@@ -179,17 +205,50 @@ namespace OpenSim.Region.Framework.Scenes.Animation
179// "[SCENE PRESENCE ANIMATOR]: Setting movement animation {0} for {1}", 205// "[SCENE PRESENCE ANIMATOR]: Setting movement animation {0} for {1}",
180// anim, m_scenePresence.Name); 206// anim, m_scenePresence.Name);
181 207
182 if (m_animations.TrySetDefaultAnimation( 208 if (aoSitGndAnim != UUID.Zero)
183 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID)) 209 {
210 avnChangeAnim(aoSitGndAnim, false, true);
211 aoSitGndAnim = UUID.Zero;
212 }
213
214 UUID overridenAnim = m_scenePresence.Overrides.GetOverriddenAnimation(anim);
215 if (overridenAnim != UUID.Zero)
216 {
217 if (anim == "SITGROUND")
218 {
219 UUID defsit = DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"];
220 if (defsit == UUID.Zero)
221 return false;
222 m_animations.SetDefaultAnimation(defsit, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID);
223 aoSitGndAnim = overridenAnim;
224 avnChangeAnim(overridenAnim, true, false);
225 }
226 else
227 {
228 m_animations.SetDefaultAnimation(overridenAnim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID);
229 }
230 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { (int)Changed.ANIMATION });
231 SendAnimPack();
232 ret = true;
233 }
234 else
184 { 235 {
236 // translate sit and sitground state animations
237 if (anim == "SIT" || anim == "SITGROUND")
238 anim = m_scenePresence.sitAnimation;
239
240 if (m_animations.TrySetDefaultAnimation(
241 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID))
242 {
185// m_log.DebugFormat( 243// m_log.DebugFormat(
186// "[SCENE PRESENCE ANIMATOR]: Updating movement animation to {0} for {1}", 244// "[SCENE PRESENCE ANIMATOR]: Updating movement animation to {0} for {1}",
187// anim, m_scenePresence.Name); 245// anim, m_scenePresence.Name);
188 246
189 // 16384 is CHANGED_ANIMATION 247 // 16384 is CHANGED_ANIMATION
190 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { (int)Changed.ANIMATION}); 248 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { (int)Changed.ANIMATION });
191 SendAnimPack(); 249 SendAnimPack();
192 ret = true; 250 ret = true;
251 }
193 } 252 }
194 } 253 }
195 else 254 else
@@ -201,78 +260,119 @@ namespace OpenSim.Region.Framework.Scenes.Animation
201 return ret; 260 return ret;
202 } 261 }
203 262
263 public enum motionControlStates : byte
264 {
265 sitted = 0,
266 flying,
267 falling,
268 jumping,
269 landing,
270 onsurface
271 }
272
273 public motionControlStates currentControlState = motionControlStates.onsurface;
274
204 /// <summary> 275 /// <summary>
205 /// This method determines the proper movement related animation 276 /// This method determines the proper movement related animation
206 /// </summary> 277 /// </summary>
207 private string DetermineMovementAnimation() 278 private string DetermineMovementAnimation()
208 { 279 {
209 const float FALL_DELAY = 800f; 280 const int FALL_DELAY = 800;
210 const float PREJUMP_DELAY = 200f; 281 const int PREJUMP_DELAY = 200;
211 const float JUMP_PERIOD = 800f; 282 const int JUMP_PERIOD = 800;
212 #region Inputs 283 #region Inputs
213 284
285 if (m_scenePresence.IsInTransit)
286 return CurrentMovementAnimation;
287
288 if (m_scenePresence.SitGround)
289 {
290 currentControlState = motionControlStates.sitted;
291 return "SITGROUND";
292 }
293 if (m_scenePresence.ParentID != 0 || m_scenePresence.ParentUUID != UUID.Zero)
294 {
295 currentControlState = motionControlStates.sitted;
296 return "SIT";
297 }
298
214 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; 299 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
215 PhysicsActor actor = m_scenePresence.PhysicsActor; 300 PhysicsActor actor = m_scenePresence.PhysicsActor;
216 301
217 // Create forward and left vectors from the current avatar rotation 302 const AgentManager.ControlFlags ANYXYMASK = (
218 Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_scenePresence.Rotation); 303 AgentManager.ControlFlags.AGENT_CONTROL_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS |
219 Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix); 304 AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG |
220 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); 305 AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS |
306 AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG
307 );
221 308
222 // Check control flags 309 // Check control flags
223 bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS); 310 /* not in use
224 bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); 311 bool heldForward = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)) != 0);
225 bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); 312 bool heldBack = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG)) != 0);
226 bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG); 313 bool heldLeft = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS)) != 0);
314 bool heldRight = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG)) != 0);
315 */
227 bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; 316 bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
228 bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; 317 bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
229 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; 318 // bool heldUp = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS)) != 0);
230 bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; 319 // excluded nudge up so it doesn't trigger jump state
320 bool heldUp = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_POS)) != 0);
321 bool heldDown = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG)) != 0);
231 //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; 322 //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY;
232 //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK; 323 //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK;
233 if (heldForward || heldBack || heldLeft || heldRight || heldUp || heldDown) 324
325 bool heldOnXY = ((controlFlags & ANYXYMASK) != 0);
326 if (heldOnXY || heldUp || heldDown)
234 { 327 {
235 heldTurnLeft = false; 328 heldTurnLeft = false;
236 heldTurnRight = false; 329 heldTurnRight = false;
237 } 330 }
238 331
239 // Direction in which the avatar is trying to move
240 Vector3 move = Vector3.Zero;
241 if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; }
242 if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; }
243 if (heldLeft) { move.X += left.X; move.Y += left.Y; }
244 if (heldRight) { move.X -= left.X; move.Y -= left.Y; }
245 if (heldUp) { move.Z += 1; }
246 if (heldDown) { move.Z -= 1; }
247
248 // Is the avatar trying to move?
249// bool moving = (move != Vector3.Zero);
250 #endregion Inputs 332 #endregion Inputs
251 333
334 // no physics actor case
335 if (actor == null)
336 {
337 // well what to do?
338
339 currentControlState = motionControlStates.onsurface;
340 if (heldOnXY)
341 return "WALK";
342
343 return "STAND";
344 }
345
252 #region Flying 346 #region Flying
253 347
254 if (actor != null && actor.Flying) 348 bool isColliding = actor.IsColliding;
349
350 if (actor.Flying)
255 { 351 {
256 m_animTickFall = 0; 352 m_animTickFall = 0;
257 m_animTickJump = 0; 353 m_animTickJump = 0;
258 m_jumping = false; 354 m_jumping = false;
259 Falling = false; 355 Falling = false;
260 m_jumpVelocity = 0f;
261 actor.Selected = false;
262 m_fallHeight = actor.Position.Z; // save latest flying height
263 356
264 if (move.X != 0f || move.Y != 0f) 357 currentControlState = motionControlStates.flying;
358
359 if (heldOnXY)
265 { 360 {
266 return (m_scenePresence.Scene.m_useFlySlow ? "FLYSLOW" : "FLY"); 361 return (m_scenePresence.Scene.m_useFlySlow ? "FLYSLOW" : "FLY");
267 } 362 }
268 else if (move.Z > 0f) 363 else if (heldUp)
269 { 364 {
270 return "HOVER_UP"; 365 return "HOVER_UP";
271 } 366 }
272 else if (move.Z < 0f) 367 else if (heldDown)
273 { 368 {
274 if (actor != null && actor.IsColliding) 369 if (isColliding)
370 {
371 actor.Flying = false;
372 currentControlState = motionControlStates.landing;
373 m_animTickLand = Environment.TickCount;
275 return "LAND"; 374 return "LAND";
375 }
276 else 376 else
277 return "HOVER_DOWN"; 377 return "HOVER_DOWN";
278 } 378 }
@@ -281,128 +381,142 @@ namespace OpenSim.Region.Framework.Scenes.Animation
281 return "HOVER"; 381 return "HOVER";
282 } 382 }
283 } 383 }
384 else
385 {
386 if (isColliding && currentControlState == motionControlStates.flying)
387 {
388 currentControlState = motionControlStates.landing;
389 m_animTickLand = Environment.TickCount;
390 return "LAND";
391 }
392 }
284 393
285 #endregion Flying 394 #endregion Flying
286 395
287 #region Falling/Floating/Landing 396 #region Falling/Floating/Landing
288 397
289 if ((actor == null || !actor.IsColliding) && !m_jumping) 398 if (!isColliding && currentControlState != motionControlStates.jumping)
290 { 399 {
291 float fallElapsed = (float)(Environment.TickCount - m_animTickFall); 400 float fallVelocity = actor.Velocity.Z;
292 float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f;
293 401
294 if (!m_jumping && (fallVelocity < -3.0f)) 402 if (fallVelocity < -2.5f)
295 Falling = true; 403 Falling = true;
296 404
297 if (m_animTickFall == 0 || (fallVelocity >= 0.0f)) 405 if (m_animTickFall == 0 || (fallVelocity >= -0.5f))
298 { 406 {
299 // not falling yet, or going up
300 // reset start of fall time
301 m_animTickFall = Environment.TickCount; 407 m_animTickFall = Environment.TickCount;
302 } 408 }
303 else if (!m_jumping && (fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f) && (m_scenePresence.WasFlying)) 409 else
304 { 410 {
305 // Falling long enough to trigger the animation 411 int fallElapsed = (Environment.TickCount - m_animTickFall);
306 return "FALLDOWN"; 412 if ((fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f))
413 {
414 currentControlState = motionControlStates.falling;
415 m_lastFallVelocity = fallVelocity;
416 // Falling long enough to trigger the animation
417 return "FALLDOWN";
418 }
307 } 419 }
308 420
309 // Check if the user has stopped walking just now 421 // Check if the user has stopped walking just now
310 if (CurrentMovementAnimation == "WALK" && (move == Vector3.Zero)) 422 if (CurrentMovementAnimation == "WALK" && !heldOnXY && !heldDown && !heldUp)
311 return "STAND"; 423 return "STAND";
312 424
313 return CurrentMovementAnimation; 425 return CurrentMovementAnimation;
314 } 426 }
315 427
316 #endregion Falling/Floating/Landing 428 m_animTickFall = 0;
317 429
430 #endregion Falling/Floating/Landing
318 431
319 #region Jumping // section added for jumping... 432 #region Jumping // section added for jumping...
320 433
321 int jumptime; 434 if (isColliding && heldUp && currentControlState != motionControlStates.jumping)
322 jumptime = Environment.TickCount - m_animTickJump;
323
324 if ((move.Z > 0f) && (!m_jumping))
325 { 435 {
326 // Start jumping, prejump 436 // Start jumping, prejump
327 m_animTickFall = 0; 437 currentControlState = motionControlStates.jumping;
328 m_jumping = true; 438 m_jumping = true;
329 Falling = false; 439 Falling = false;
330 actor.Selected = true; // borrowed for jumping flag
331 m_animTickJump = Environment.TickCount; 440 m_animTickJump = Environment.TickCount;
332 m_jumpVelocity = 0.35f;
333 return "PREJUMP"; 441 return "PREJUMP";
334 } 442 }
335 443
336 if (m_jumping) 444 if (currentControlState == motionControlStates.jumping)
337 { 445 {
446 int jumptime = Environment.TickCount - m_animTickJump;
338 if ((jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding) 447 if ((jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding)
339 { 448 {
340 // end jumping 449 // end jumping
341 m_jumping = false; 450 m_jumping = false;
342 Falling = false; 451 Falling = false;
343 actor.Selected = false; // borrowed for jumping flag 452 actor.Selected = false; // borrowed for jumping flag
344 m_jumpVelocity = 0f; 453 m_animTickLand = Environment.TickCount;
345 m_animTickFall = Environment.TickCount; 454 currentControlState = motionControlStates.landing;
346 return "LAND"; 455 return "LAND";
347 } 456 }
348 else if (jumptime > JUMP_PERIOD) 457 else if (jumptime > JUMP_PERIOD)
349 { 458 {
350 // jump down 459 // jump down
351 m_jumpVelocity = 0f;
352 return "JUMP"; 460 return "JUMP";
353 } 461 }
354 else if (jumptime > PREJUMP_DELAY) 462 else if (jumptime > PREJUMP_DELAY)
355 { 463 {
356 // jump up 464 // jump up
357 m_jumping = true; 465 m_jumping = true;
358 m_jumpVelocity = 10f;
359 return "JUMP"; 466 return "JUMP";
360 } 467 }
468 return CurrentMovementAnimation;
361 } 469 }
362 470
363 #endregion Jumping 471 #endregion Jumping
364 472
365 #region Ground Movement 473 #region Ground Movement
366 474
367 if (CurrentMovementAnimation == "FALLDOWN") 475 if (currentControlState == motionControlStates.falling)
368 { 476 {
369 Falling = false; 477 Falling = false;
370 m_animTickFall = Environment.TickCount; 478 currentControlState = motionControlStates.landing;
479 m_animTickLand = Environment.TickCount;
371 // TODO: SOFT_LAND support 480 // TODO: SOFT_LAND support
372 float fallHeight = m_fallHeight - actor.Position.Z; 481 float fallVsq = m_lastFallVelocity * m_lastFallVelocity;
373 if (fallHeight > 15.0f) 482 if (fallVsq > 300f) // aprox 20*h
374 return "STANDUP"; 483 return "STANDUP";
375 else if (fallHeight > 8.0f) 484 else if (fallVsq > 160f)
376 return "SOFT_LAND"; 485 return "SOFT_LAND";
377 else 486 else
378 return "LAND"; 487 return "LAND";
379 } 488 }
380 else if ((CurrentMovementAnimation == "LAND") || (CurrentMovementAnimation == "SOFT_LAND") || (CurrentMovementAnimation == "STANDUP")) 489
490
491 if (currentControlState == motionControlStates.landing)
381 { 492 {
382 int landElapsed = Environment.TickCount - m_animTickFall; 493 Falling = false;
494 int landElapsed = Environment.TickCount - m_animTickLand;
383 int limit = 1000; 495 int limit = 1000;
384 if (CurrentMovementAnimation == "LAND") 496 if (CurrentMovementAnimation == "LAND")
385 limit = 350; 497 limit = 350;
386 // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client 498 // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client
387 499
388 if ((m_animTickFall != 0) && (landElapsed <= limit)) 500 if ((m_animTickLand != 0) && (landElapsed <= limit))
389 { 501 {
390 return CurrentMovementAnimation; 502 return CurrentMovementAnimation;
391 } 503 }
392 else 504 else
393 { 505 {
394 m_fallHeight = actor.Position.Z; // save latest flying height 506 currentControlState = motionControlStates.onsurface;
507 m_animTickLand = 0;
395 return "STAND"; 508 return "STAND";
396 } 509 }
397 } 510 }
398 511
399 // next section moved outside paren. and realigned for jumping 512 // next section moved outside paren. and realigned for jumping
400 if (move.X != 0f || move.Y != 0f) 513
514 if (heldOnXY)
401 { 515 {
402 m_fallHeight = actor.Position.Z; // save latest flying height 516 currentControlState = motionControlStates.onsurface;
403 Falling = false; 517 Falling = false;
404 // Walking / crouchwalking / running 518 // Walking / crouchwalking / running
405 if (move.Z < 0f) 519 if (heldDown)
406 { 520 {
407 return "CROUCHWALK"; 521 return "CROUCHWALK";
408 } 522 }
@@ -416,11 +530,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation
416 return "WALK"; 530 return "WALK";
417 } 531 }
418 } 532 }
419 else if (!m_jumping) 533 else
420 { 534 {
535 currentControlState = motionControlStates.onsurface;
421 Falling = false; 536 Falling = false;
422 // Not walking 537 // Not walking
423 if (move.Z < 0) 538 if (heldDown)
424 return "CROUCH"; 539 return "CROUCH";
425 else if (heldTurnLeft) 540 else if (heldTurnLeft)
426 return "TURNLEFT"; 541 return "TURNLEFT";
@@ -431,8 +546,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation
431 } 546 }
432 #endregion Ground Movement 547 #endregion Ground Movement
433 548
434 Falling = false;
435
436 return CurrentMovementAnimation; 549 return CurrentMovementAnimation;
437 } 550 }
438 551
@@ -442,7 +555,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
442 /// <returns>'true' if the animation was changed</returns> 555 /// <returns>'true' if the animation was changed</returns>
443 public bool UpdateMovementAnimations() 556 public bool UpdateMovementAnimations()
444 { 557 {
445// m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Updating movement animations for {0}", m_scenePresence.Name); 558 // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Updating movement animations for {0}", m_scenePresence.Name);
446 559
447 bool ret = false; 560 bool ret = false;
448 lock (m_animations) 561 lock (m_animations)
@@ -450,7 +563,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
450 string newMovementAnimation = DetermineMovementAnimation(); 563 string newMovementAnimation = DetermineMovementAnimation();
451 if (CurrentMovementAnimation != newMovementAnimation) 564 if (CurrentMovementAnimation != newMovementAnimation)
452 { 565 {
453 CurrentMovementAnimation = DetermineMovementAnimation(); 566 CurrentMovementAnimation = newMovementAnimation;
454 567
455// m_log.DebugFormat( 568// m_log.DebugFormat(
456// "[SCENE PRESENCE ANIMATOR]: Determined animation {0} for {1} in UpdateMovementAnimations()", 569// "[SCENE PRESENCE ANIMATOR]: Determined animation {0} for {1} in UpdateMovementAnimations()",
@@ -464,6 +577,24 @@ namespace OpenSim.Region.Framework.Scenes.Animation
464 return ret; 577 return ret;
465 } 578 }
466 579
580 public bool ForceUpdateMovementAnimations()
581 {
582 lock (m_animations)
583 {
584 CurrentMovementAnimation = DetermineMovementAnimation();
585 return TrySetMovementAnimation(CurrentMovementAnimation);
586 }
587 }
588
589 public bool SetMovementAnimations(string motionState)
590 {
591 lock (m_animations)
592 {
593 CurrentMovementAnimation = motionState;
594 return TrySetMovementAnimation(CurrentMovementAnimation);
595 }
596 }
597
467 public UUID[] GetAnimationArray() 598 public UUID[] GetAnimationArray()
468 { 599 {
469 UUID[] animIDs; 600 UUID[] animIDs;
@@ -472,19 +603,19 @@ namespace OpenSim.Region.Framework.Scenes.Animation
472 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); 603 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
473 return animIDs; 604 return animIDs;
474 } 605 }
475 606
476 public BinBVHAnimation GenerateRandomAnimation() 607 public BinBVHAnimation GenerateRandomAnimation()
477 { 608 {
478 int rnditerations = 3; 609 int rnditerations = 3;
479 BinBVHAnimation anim = new BinBVHAnimation(); 610 BinBVHAnimation anim = new BinBVHAnimation();
480 List<string> parts = new List<string>(); 611 List<string> parts = new List<string>();
481 parts.Add("mPelvis");parts.Add("mHead");parts.Add("mTorso"); 612 parts.Add("mPelvis"); parts.Add("mHead"); parts.Add("mTorso");
482 parts.Add("mHipLeft");parts.Add("mHipRight");parts.Add("mHipLeft");parts.Add("mKneeLeft"); 613 parts.Add("mHipLeft"); parts.Add("mHipRight"); parts.Add("mHipLeft"); parts.Add("mKneeLeft");
483 parts.Add("mKneeRight");parts.Add("mCollarLeft");parts.Add("mCollarRight");parts.Add("mNeck"); 614 parts.Add("mKneeRight"); parts.Add("mCollarLeft"); parts.Add("mCollarRight"); parts.Add("mNeck");
484 parts.Add("mElbowLeft");parts.Add("mElbowRight");parts.Add("mWristLeft");parts.Add("mWristRight"); 615 parts.Add("mElbowLeft"); parts.Add("mElbowRight"); parts.Add("mWristLeft"); parts.Add("mWristRight");
485 parts.Add("mShoulderLeft");parts.Add("mShoulderRight");parts.Add("mAnkleLeft");parts.Add("mAnkleRight"); 616 parts.Add("mShoulderLeft"); parts.Add("mShoulderRight"); parts.Add("mAnkleLeft"); parts.Add("mAnkleRight");
486 parts.Add("mEyeRight");parts.Add("mChest");parts.Add("mToeLeft");parts.Add("mToeRight"); 617 parts.Add("mEyeRight"); parts.Add("mChest"); parts.Add("mToeLeft"); parts.Add("mToeRight");
487 parts.Add("mFootLeft");parts.Add("mFootRight");parts.Add("mEyeLeft"); 618 parts.Add("mFootLeft"); parts.Add("mFootRight"); parts.Add("mEyeLeft");
488 anim.HandPose = 1; 619 anim.HandPose = 1;
489 anim.InPoint = 0; 620 anim.InPoint = 0;
490 anim.OutPoint = (rnditerations * .10f); 621 anim.OutPoint = (rnditerations * .10f);
@@ -508,12 +639,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation
508 for (int i = 0; i < rnditerations; i++) 639 for (int i = 0; i < rnditerations; i++)
509 { 640 {
510 anim.Joints[j].rotationkeys[i] = new binBVHJointKey(); 641 anim.Joints[j].rotationkeys[i] = new binBVHJointKey();
511 anim.Joints[j].rotationkeys[i].time = (i*.10f); 642 anim.Joints[j].rotationkeys[i].time = (i * .10f);
512 anim.Joints[j].rotationkeys[i].key_element.X = ((float) rnd.NextDouble()*2 - 1); 643 anim.Joints[j].rotationkeys[i].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
513 anim.Joints[j].rotationkeys[i].key_element.Y = ((float) rnd.NextDouble()*2 - 1); 644 anim.Joints[j].rotationkeys[i].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
514 anim.Joints[j].rotationkeys[i].key_element.Z = ((float) rnd.NextDouble()*2 - 1); 645 anim.Joints[j].rotationkeys[i].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
515 anim.Joints[j].positionkeys[i] = new binBVHJointKey(); 646 anim.Joints[j].positionkeys[i] = new binBVHJointKey();
516 anim.Joints[j].positionkeys[i].time = (i*.10f); 647 anim.Joints[j].positionkeys[i].time = (i * .10f);
517 anim.Joints[j].positionkeys[i].key_element.X = 0; 648 anim.Joints[j].positionkeys[i].key_element.X = 0;
518 anim.Joints[j].positionkeys[i].key_element.Y = 0; 649 anim.Joints[j].positionkeys[i].key_element.Y = 0;
519 anim.Joints[j].positionkeys[i].key_element.Z = 0; 650 anim.Joints[j].positionkeys[i].key_element.Z = 0;
@@ -540,20 +671,17 @@ namespace OpenSim.Region.Framework.Scenes.Animation
540 /// <param name="objectIDs"></param> 671 /// <param name="objectIDs"></param>
541 public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs) 672 public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs)
542 { 673 {
543 if (m_scenePresence.IsChildAgent) 674 m_scenePresence.SendAnimPack(animations, seqs, objectIDs);
544 return; 675 }
545 676
546// m_log.DebugFormat( 677 public void GetArrays(out UUID[] animIDs, out int[] sequenceNums, out UUID[] objectIDs)
547// "[SCENE PRESENCE ANIMATOR]: Sending anim pack with animations '{0}', sequence '{1}', uuids '{2}'", 678 {
548// string.Join(",", Array.ConvertAll<UUID, string>(animations, a => a.ToString())), 679 animIDs = null;
549// string.Join(",", Array.ConvertAll<int, string>(seqs, s => s.ToString())), 680 sequenceNums = null;
550// string.Join(",", Array.ConvertAll<UUID, string>(objectIDs, o => o.ToString()))); 681 objectIDs = null;
551 682
552 m_scenePresence.Scene.ForEachClient( 683 if (m_animations != null)
553 delegate(IClientAPI client) 684 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
554 {
555 client.SendAnimations(animations, seqs, m_scenePresence.ControllingClient.AgentId, objectIDs);
556 });
557 } 685 }
558 686
559 public void SendAnimPackToClient(IClientAPI client) 687 public void SendAnimPackToClient(IClientAPI client)
@@ -575,7 +703,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
575 public void SendAnimPack() 703 public void SendAnimPack()
576 { 704 {
577 //m_log.Debug("Sending animation pack to all"); 705 //m_log.Debug("Sending animation pack to all");
578 706
579 if (m_scenePresence.IsChildAgent) 707 if (m_scenePresence.IsChildAgent)
580 return; 708 return;
581 709
@@ -585,7 +713,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
585 713
586 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); 714 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
587 715
588 SendAnimPack(animIDs, sequenceNums, objectIDs); 716 // SendAnimPack(animIDs, sequenceNums, objectIDs);
717 m_scenePresence.SendAnimPack(animIDs, sequenceNums, objectIDs);
589 } 718 }
590 719
591 public string GetAnimName(UUID animId) 720 public string GetAnimName(UUID animId)
diff --git a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs
new file mode 100644
index 0000000..075724e
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs
@@ -0,0 +1,304 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27// Ubit 2012
28
29using System;
30using System.Reflection;
31using System.Collections.Generic;
32using OpenMetaverse;
33using OpenSim.Framework;
34using log4net;
35
36namespace OpenSim.Region.Framework.Scenes
37{
38 public struct CollisionForSoundInfo
39 {
40 public uint colliderID;
41 public Vector3 position;
42 public float relativeVel;
43 }
44
45 public static class CollisionSounds
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private const int MaxMaterials = 7;
50 // part part
51
52 private static UUID snd_StoneStone = new UUID("be7295c0-a158-11e1-b3dd-0800200c9a66");
53 private static UUID snd_StoneMetal = new UUID("be7295c0-a158-11e1-b3dd-0800201c9a66");
54 private static UUID snd_StoneGlass = new UUID("be7295c0-a158-11e1-b3dd-0800202c9a66");
55 private static UUID snd_StoneWood = new UUID("be7295c0-a158-11e1-b3dd-0800203c9a66");
56 private static UUID snd_StoneFlesh = new UUID("be7295c0-a158-11e1-b3dd-0800204c9a66");
57 private static UUID snd_StonePlastic = new UUID("be7295c0-a158-11e1-b3dd-0800205c9a66");
58 private static UUID snd_StoneRubber = new UUID("be7295c0-a158-11e1-b3dd-0800206c9a66");
59
60 private static UUID snd_MetalMetal = new UUID("be7295c0-a158-11e1-b3dd-0801201c9a66");
61 private static UUID snd_MetalGlass = new UUID("be7295c0-a158-11e1-b3dd-0801202c9a66");
62 private static UUID snd_MetalWood = new UUID("be7295c0-a158-11e1-b3dd-0801203c9a66");
63 private static UUID snd_MetalFlesh = new UUID("be7295c0-a158-11e1-b3dd-0801204c9a66");
64 private static UUID snd_MetalPlastic = new UUID("be7295c0-a158-11e1-b3dd-0801205c9a66");
65 private static UUID snd_MetalRubber = new UUID("be7295c0-a158-11e1-b3dd-0801206c9a66");
66
67 private static UUID snd_GlassGlass = new UUID("be7295c0-a158-11e1-b3dd-0802202c9a66");
68 private static UUID snd_GlassWood = new UUID("be7295c0-a158-11e1-b3dd-0802203c9a66");
69 private static UUID snd_GlassFlesh = new UUID("be7295c0-a158-11e1-b3dd-0802204c9a66");
70 private static UUID snd_GlassPlastic = new UUID("be7295c0-a158-11e1-b3dd-0802205c9a66");
71 private static UUID snd_GlassRubber = new UUID("be7295c0-a158-11e1-b3dd-0802206c9a66");
72
73 private static UUID snd_WoodWood = new UUID("be7295c0-a158-11e1-b3dd-0803203c9a66");
74 private static UUID snd_WoodFlesh = new UUID("be7295c0-a158-11e1-b3dd-0803204c9a66");
75 private static UUID snd_WoodPlastic = new UUID("be7295c0-a158-11e1-b3dd-0803205c9a66");
76 private static UUID snd_WoodRubber = new UUID("be7295c0-a158-11e1-b3dd-0803206c9a66");
77
78 private static UUID snd_FleshFlesh = new UUID("be7295c0-a158-11e1-b3dd-0804204c9a66");
79 private static UUID snd_FleshPlastic = new UUID("be7295c0-a158-11e1-b3dd-0804205c9a66");
80 private static UUID snd_FleshRubber = new UUID("be7295c0-a158-11e1-b3dd-0804206c9a66");
81
82 private static UUID snd_PlasticPlastic = new UUID("be7295c0-a158-11e1-b3dd-0805205c9a66");
83 private static UUID snd_PlasticRubber = new UUID("be7295c0-a158-11e1-b3dd-0805206c9a66");
84
85 private static UUID snd_RubberRubber = new UUID("be7295c0-a158-11e1-b3dd-0806206c9a66");
86
87 // terrain part
88 private static UUID snd_TerrainStone = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
89 private static UUID snd_TerrainMetal = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
90 private static UUID snd_TerrainGlass = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
91 private static UUID snd_TerrainWood = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
92 private static UUID snd_TerrainFlesh = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
93 private static UUID snd_TerrainPlastic = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
94 private static UUID snd_TerrainRubber = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66");
95
96 public static UUID[] m_TerrainPart = {
97 snd_TerrainStone,
98 snd_TerrainMetal,
99 snd_TerrainGlass,
100 snd_TerrainWood,
101 snd_TerrainFlesh,
102 snd_TerrainPlastic,
103 snd_TerrainRubber
104 };
105
106 // simetric sounds
107 public static UUID[] m_PartPart = {
108 snd_StoneStone, snd_StoneMetal, snd_StoneGlass, snd_StoneWood, snd_StoneFlesh, snd_StonePlastic, snd_StoneRubber,
109 snd_StoneMetal, snd_MetalMetal, snd_MetalGlass, snd_MetalWood, snd_MetalFlesh, snd_MetalPlastic, snd_MetalRubber,
110 snd_StoneGlass, snd_MetalGlass, snd_GlassGlass, snd_GlassWood, snd_GlassFlesh, snd_GlassPlastic, snd_GlassRubber,
111 snd_StoneWood, snd_MetalWood, snd_GlassWood, snd_WoodWood, snd_WoodFlesh, snd_WoodPlastic, snd_WoodRubber,
112 snd_StoneFlesh, snd_MetalFlesh, snd_GlassFlesh, snd_WoodFlesh, snd_FleshFlesh, snd_FleshPlastic, snd_FleshRubber,
113 snd_StonePlastic, snd_MetalPlastic, snd_GlassPlastic, snd_WoodPlastic, snd_FleshPlastic, snd_PlasticPlastic, snd_PlasticRubber,
114 snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
115 };
116
117 public static void PartCollisionSound(SceneObjectPart part, List<CollisionForSoundInfo> collidersinfolist)
118 {
119 if (collidersinfolist.Count == 0 || part == null)
120 return;
121
122 if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
123 return;
124
125 if (part.ParentGroup == null)
126 return;
127
128 if (part.CollisionSoundType < 0)
129 return;
130
131 float volume = 0.0f;
132 bool HaveSound = false;
133
134 UUID soundID = part.CollisionSound;
135
136 if (part.CollisionSoundType > 0)
137 {
138 // soundID = part.CollisionSound;
139 volume = part.CollisionSoundVolume;
140 if (volume == 0.0f)
141 return;
142 HaveSound = true;
143 }
144
145 bool doneownsound = false;
146
147 int thisMaterial = (int)part.Material;
148 if (thisMaterial >= MaxMaterials)
149 thisMaterial = 3;
150 int thisMatScaled = thisMaterial * MaxMaterials;
151
152 CollisionForSoundInfo colInfo;
153 uint id;
154
155 for(int i = 0; i< collidersinfolist.Count; i++)
156 {
157 colInfo = collidersinfolist[i];
158
159 id = colInfo.colliderID;
160 if (id == 0) // terrain collision
161 {
162 if (!doneownsound)
163 {
164 if (!HaveSound)
165 {
166 volume = Math.Abs(colInfo.relativeVel);
167 if (volume < 0.2f)
168 continue;
169
170 volume *= volume * .0625f; // 4m/s == full volume
171 if (volume > 1.0f)
172 volume = 1.0f;
173
174 soundID = m_TerrainPart[thisMaterial];
175 }
176 part.SendCollisionSound(soundID, volume, colInfo.position);
177 doneownsound = true;
178 }
179 continue;
180 }
181
182 SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
183 if (otherPart != null)
184 {
185 if (otherPart.CollisionSoundType < 0 || otherPart.VolumeDetectActive)
186 continue;
187
188 if (!HaveSound)
189 {
190 if (otherPart.CollisionSoundType > 0)
191 {
192 soundID = otherPart.CollisionSound;
193 volume = otherPart.CollisionSoundVolume;
194 if (volume == 0.0f)
195 continue;
196 }
197 else
198 {
199 volume = Math.Abs(colInfo.relativeVel);
200 if (volume < 0.2f)
201 continue;
202
203 volume *= volume * .0625f; // 4m/s == full volume
204 if (volume > 1.0f)
205 volume = 1.0f;
206
207 int otherMaterial = (int)otherPart.Material;
208 if (otherMaterial >= MaxMaterials)
209 otherMaterial = 3;
210
211 soundID = m_PartPart[thisMatScaled + otherMaterial];
212 }
213 }
214
215 if (doneownsound)
216 otherPart.SendCollisionSound(soundID, volume, colInfo.position);
217 else
218 {
219 part.SendCollisionSound(soundID, volume, colInfo.position);
220 doneownsound = true;
221 }
222 }
223 }
224 }
225
226 public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> collidersinfolist)
227 {
228 if (collidersinfolist.Count == 0 || av == null)
229 return;
230
231 UUID soundID;
232 int otherMaterial;
233
234 int thisMaterial = 4; // flesh
235
236 int thisMatScaled = thisMaterial * MaxMaterials;
237
238 // bool doneownsound = false;
239
240 CollisionForSoundInfo colInfo;
241 uint id;
242 float volume;
243
244 for(int i = 0; i< collidersinfolist.Count; i++)
245 {
246 colInfo = collidersinfolist[i];
247
248 id = colInfo.colliderID;
249
250 if (id == 0) // no terrain collision sounds for now
251 {
252 continue;
253// volume = Math.Abs(colInfo.relativeVel);
254// if (volume < 0.2f)
255// continue;
256
257 }
258
259 SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(id);
260 if (otherPart != null)
261 {
262 if (otherPart.CollisionSoundType < 0)
263 continue;
264 if (otherPart.CollisionSoundType > 0 && otherPart.CollisionSoundVolume > 0f)
265 otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, colInfo.position);
266 else
267 {
268 volume = Math.Abs(colInfo.relativeVel);
269 // Most noral collisions (running into walls, stairs)
270 // should never be heard.
271 if (volume < 3.2f)
272 continue;
273// m_log.DebugFormat("Collision speed was {0}", volume);
274
275 // Cap to 0.2 times volume because climbing stairs should not be noisy
276 // Also changed scaling
277 volume *= volume * .0125f; // 4m/s == volume 0.2
278 if (volume > 0.2f)
279 volume = 0.2f;
280 otherMaterial = (int)otherPart.Material;
281 if (otherMaterial >= MaxMaterials)
282 otherMaterial = 3;
283
284 soundID = m_PartPart[thisMatScaled + otherMaterial];
285 otherPart.SendCollisionSound(soundID, volume, colInfo.position);
286 }
287 continue;
288 }
289/*
290 else if (!doneownsound)
291 {
292 ScenePresence otherav = av.Scene.GetScenePresence(Id);
293 if (otherav != null && (!otherav.IsChildAgent))
294 {
295 soundID = snd_FleshFlesh;
296 av.SendCollisionSound(soundID, 1.0);
297 doneownsound = true;
298 }
299 }
300 */
301 }
302 }
303 }
304}
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index d325240..22b8e4d 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -80,6 +80,7 @@ namespace OpenSim.Region.Framework.Scenes
80 public event OnTerrainTaintedDelegate OnTerrainTainted; 80 public event OnTerrainTaintedDelegate OnTerrainTainted;
81 81
82 public delegate void OnTerrainTickDelegate(); 82 public delegate void OnTerrainTickDelegate();
83 public delegate void OnTerrainCheckUpdatesDelegate();
83 84
84 /// <summary> 85 /// <summary>
85 /// Triggered if the terrain has been edited 86 /// Triggered if the terrain has been edited
@@ -89,6 +90,11 @@ namespace OpenSim.Region.Framework.Scenes
89 /// but is used by core solely to update the physics engine. 90 /// but is used by core solely to update the physics engine.
90 /// </remarks> 91 /// </remarks>
91 public event OnTerrainTickDelegate OnTerrainTick; 92 public event OnTerrainTickDelegate OnTerrainTick;
93 public event OnTerrainCheckUpdatesDelegate OnTerrainCheckUpdates;
94
95 public delegate void OnTerrainUpdateDelegate();
96
97 public event OnTerrainUpdateDelegate OnTerrainUpdate;
92 98
93 public delegate void OnBackupDelegate(ISimulationDataService datastore, bool forceBackup); 99 public delegate void OnBackupDelegate(ISimulationDataService datastore, bool forceBackup);
94 100
@@ -339,8 +345,6 @@ namespace OpenSim.Region.Framework.Scenes
339 /// in <see cref="Scene.SetScriptRunning"/> 345 /// in <see cref="Scene.SetScriptRunning"/>
340 /// via <see cref="OpenSim.Framework.IClientAPI.OnSetScriptRunning"/>, 346 /// via <see cref="OpenSim.Framework.IClientAPI.OnSetScriptRunning"/>,
341 /// via <see cref="OpenSim.Region.ClientStack.LindenUDP.HandleSetScriptRunning"/> 347 /// via <see cref="OpenSim.Region.ClientStack.LindenUDP.HandleSetScriptRunning"/>
342 /// XXX: This is only triggered when it is the client that starts the script, not in other situations where
343 /// a script is started, unlike OnStopScript!
344 /// </remarks> 348 /// </remarks>
345 public event StartScript OnStartScript; 349 public event StartScript OnStartScript;
346 350
@@ -354,7 +358,6 @@ namespace OpenSim.Region.Framework.Scenes
354 /// in <see cref="SceneObjectPartInventory.CreateScriptInstance"/>, 358 /// in <see cref="SceneObjectPartInventory.CreateScriptInstance"/>,
355 /// <see cref="SceneObjectPartInventory.StopScriptInstance"/>, 359 /// <see cref="SceneObjectPartInventory.StopScriptInstance"/>,
356 /// <see cref="Scene.SetScriptRunning"/> 360 /// <see cref="Scene.SetScriptRunning"/>
357 /// XXX: This is triggered when a sciprt is stopped for any reason, unlike OnStartScript!
358 /// </remarks> 361 /// </remarks>
359 public event StopScript OnStopScript; 362 public event StopScript OnStopScript;
360 363
@@ -858,6 +861,10 @@ namespace OpenSim.Region.Framework.Scenes
858 public event ParcelPrimCountTainted OnParcelPrimCountTainted; 861 public event ParcelPrimCountTainted OnParcelPrimCountTainted;
859 public event GetScriptRunning OnGetScriptRunning; 862 public event GetScriptRunning OnGetScriptRunning;
860 863
864 public delegate void ThrottleUpdate(ScenePresence scenePresence);
865
866 public event ThrottleUpdate OnThrottleUpdate;
867
861 /// <summary> 868 /// <summary>
862 /// RegisterCapsEvent is called by Scene after the Caps object 869 /// RegisterCapsEvent is called by Scene after the Caps object
863 /// has been instantiated and before it is return to the 870 /// has been instantiated and before it is return to the
@@ -1377,7 +1384,9 @@ namespace OpenSim.Region.Framework.Scenes
1377 { 1384 {
1378 try 1385 try
1379 { 1386 {
1387// m_log.ErrorFormat("[EVENT MANAGER]: OnRemovePresenceDelegate: {0}",d.Target.ToString());
1380 d(agentId); 1388 d(agentId);
1389// m_log.ErrorFormat("[EVENT MANAGER]: OnRemovePresenceDelegate done ");
1381 } 1390 }
1382 catch (Exception e) 1391 catch (Exception e)
1383 { 1392 {
@@ -1451,6 +1460,26 @@ namespace OpenSim.Region.Framework.Scenes
1451 } 1460 }
1452 } 1461 }
1453 } 1462 }
1463 public void TriggerTerrainUpdate()
1464 {
1465 OnTerrainUpdateDelegate handlerTerrainUpdate = OnTerrainUpdate;
1466 if (handlerTerrainUpdate != null)
1467 {
1468 foreach (OnTerrainUpdateDelegate d in handlerTerrainUpdate.GetInvocationList())
1469 {
1470 try
1471 {
1472 d();
1473 }
1474 catch (Exception e)
1475 {
1476 m_log.ErrorFormat(
1477 "[EVENT MANAGER]: Delegate for TriggerTerrainUpdate failed - continuing. {0} {1}",
1478 e.Message, e.StackTrace);
1479 }
1480 }
1481 }
1482 }
1454 1483
1455 public void TriggerTerrainTick() 1484 public void TriggerTerrainTick()
1456 { 1485 {
@@ -1473,6 +1502,27 @@ namespace OpenSim.Region.Framework.Scenes
1473 } 1502 }
1474 } 1503 }
1475 1504
1505 public void TriggerTerrainCheckUpdates()
1506 {
1507 OnTerrainCheckUpdatesDelegate TerrainCheckUpdates = OnTerrainCheckUpdates;
1508 if (TerrainCheckUpdates != null)
1509 {
1510 foreach (OnTerrainCheckUpdatesDelegate d in TerrainCheckUpdates.GetInvocationList())
1511 {
1512 try
1513 {
1514 d();
1515 }
1516 catch (Exception e)
1517 {
1518 m_log.ErrorFormat(
1519 "[EVENT MANAGER]: Delegate for TerrainCheckUpdates failed - continuing. {0} {1}",
1520 e.Message, e.StackTrace);
1521 }
1522 }
1523 }
1524 }
1525
1476 public void TriggerTerrainTainted() 1526 public void TriggerTerrainTainted()
1477 { 1527 {
1478 OnTerrainTaintedDelegate handlerTerrainTainted = OnTerrainTainted; 1528 OnTerrainTaintedDelegate handlerTerrainTainted = OnTerrainTainted;
@@ -1808,6 +1858,7 @@ namespace OpenSim.Region.Framework.Scenes
1808 m_log.ErrorFormat( 1858 m_log.ErrorFormat(
1809 "[EVENT MANAGER]: Delegate for TriggerRemoveScript failed - continuing. {0} {1}", 1859 "[EVENT MANAGER]: Delegate for TriggerRemoveScript failed - continuing. {0} {1}",
1810 e.Message, e.StackTrace); 1860 e.Message, e.StackTrace);
1861 m_log.ErrorFormat(Environment.StackTrace);
1811 } 1862 }
1812 } 1863 }
1813 } 1864 }
@@ -2073,7 +2124,10 @@ namespace OpenSim.Region.Framework.Scenes
2073 { 2124 {
2074 try 2125 try
2075 { 2126 {
2127// m_log.ErrorFormat("[EVENT MANAGER]: TriggerClientClosed: {0}", d.Target.ToString());
2076 d(ClientID, scene); 2128 d(ClientID, scene);
2129// m_log.ErrorFormat("[EVENT MANAGER]: TriggerClientClosed done ");
2130
2077 } 2131 }
2078 catch (Exception e) 2132 catch (Exception e)
2079 { 2133 {
@@ -3107,6 +3161,7 @@ namespace OpenSim.Region.Framework.Scenes
3107 { 3161 {
3108 foreach (Action<Scene> d in handler.GetInvocationList()) 3162 foreach (Action<Scene> d in handler.GetInvocationList())
3109 { 3163 {
3164 m_log.InfoFormat("[EVENT MANAGER]: TriggerSceneShuttingDown invoque {0}", d.Method.Name.ToString());
3110 try 3165 try
3111 { 3166 {
3112 d(s); 3167 d(s);
@@ -3119,6 +3174,7 @@ namespace OpenSim.Region.Framework.Scenes
3119 } 3174 }
3120 } 3175 }
3121 } 3176 }
3177 m_log.Info("[EVENT MANAGER]: TriggerSceneShuttingDown done");
3122 } 3178 }
3123 3179
3124 public void TriggerOnRegionStarted(Scene scene) 3180 public void TriggerOnRegionStarted(Scene scene)
@@ -3310,6 +3366,15 @@ namespace OpenSim.Region.Framework.Scenes
3310 } 3366 }
3311 } 3367 }
3312 3368
3369 public void TriggerThrottleUpdate(ScenePresence scenePresence)
3370 {
3371 ThrottleUpdate handler = OnThrottleUpdate;
3372 if (handler != null)
3373 {
3374 handler(scenePresence);
3375 }
3376 }
3377
3313// public void TriggerGatherUuids(SceneObjectPart sop, IDictionary<UUID, AssetType> assetUuids) 3378// public void TriggerGatherUuids(SceneObjectPart sop, IDictionary<UUID, AssetType> assetUuids)
3314// { 3379// {
3315// GatherUuids handler = OnGatherUuids; 3380// GatherUuids handler = OnGatherUuids;
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
index 646403f..2b95a4c 100644
--- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
+++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
@@ -292,14 +292,17 @@ namespace OpenSim.Region.Framework.Scenes
292 292
293 private void StartTimer() 293 private void StartTimer()
294 { 294 {
295 KeyframeTimer.Add(this); 295 lock (m_frames)
296 m_timerStopped = false; 296 {
297 KeyframeTimer.Add(this);
298 m_timerStopped = false;
299 }
297 } 300 }
298 301
299 private void StopTimer() 302 private void StopTimer()
300 { 303 {
301 m_timerStopped = true; 304 lock (m_frames)
302 KeyframeTimer.Remove(this); 305 m_timerStopped = true;
303 } 306 }
304 307
305 public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data) 308 public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data)
@@ -348,6 +351,7 @@ namespace OpenSim.Region.Framework.Scenes
348 m_group = grp; 351 m_group = grp;
349 m_scene = grp.Scene; 352 m_scene = grp.Scene;
350 353
354<<<<<<< HEAD
351 Vector3 grppos = grp.AbsolutePosition; 355 Vector3 grppos = grp.AbsolutePosition;
352 Vector3 offset = grppos - m_serializedPosition; 356 Vector3 offset = grppos - m_serializedPosition;
353 // avoid doing it more than once 357 // avoid doing it more than once
@@ -366,6 +370,27 @@ namespace OpenSim.Region.Framework.Scenes
366 k.StartPosition += offset; 370 k.StartPosition += offset;
367 k.Position += offset; 371 k.Position += offset;
368 m_frames[i]=k; 372 m_frames[i]=k;
373=======
374 lock (m_frames)
375 {
376 Vector3 grppos = grp.AbsolutePosition;
377 Vector3 offset = grppos - m_serializedPosition;
378 // avoid doing it more than once
379 // current this will happen draging a prim to other region
380 m_serializedPosition = grppos;
381
382 m_basePosition += offset;
383 m_currentFrame.Position += offset;
384
385 m_nextPosition += offset;
386
387 for (int i = 0; i < m_frames.Count; i++)
388 {
389 Keyframe k = m_frames[i];
390 k.Position += offset;
391 m_frames[i] = k;
392 }
393>>>>>>> avn/ubitvar
369 } 394 }
370 395
371 if (m_running) 396 if (m_running)
@@ -410,25 +435,28 @@ namespace OpenSim.Region.Framework.Scenes
410 m_keyframes.CopyTo(newmotion.m_keyframes, 0); 435 m_keyframes.CopyTo(newmotion.m_keyframes, 0);
411 } 436 }
412 437
413 newmotion.m_frames = new List<Keyframe>(m_frames); 438 lock (m_frames)
439 {
440 newmotion.m_frames = new List<Keyframe>(m_frames);
414 441
415 newmotion.m_basePosition = m_basePosition; 442 newmotion.m_basePosition = m_basePosition;
416 newmotion.m_baseRotation = m_baseRotation; 443 newmotion.m_baseRotation = m_baseRotation;
417 444
418 if (m_selected) 445 if (m_selected)
419 newmotion.m_serializedPosition = m_serializedPosition;
420 else
421 {
422 if (m_group != null)
423 newmotion.m_serializedPosition = m_group.AbsolutePosition;
424 else
425 newmotion.m_serializedPosition = m_serializedPosition; 446 newmotion.m_serializedPosition = m_serializedPosition;
426 } 447 else
448 {
449 if (m_group != null)
450 newmotion.m_serializedPosition = m_group.AbsolutePosition;
451 else
452 newmotion.m_serializedPosition = m_serializedPosition;
453 }
427 454
428 newmotion.m_currentFrame = m_currentFrame; 455 newmotion.m_currentFrame = m_currentFrame;
429 456
430 newmotion.m_iterations = m_iterations; 457 newmotion.m_iterations = m_iterations;
431 newmotion.m_running = m_running; 458 newmotion.m_running = m_running;
459 }
432 460
433 if (m_running && !m_waitingCrossing) 461 if (m_running && !m_waitingCrossing)
434 StartTimer(); 462 StartTimer();
@@ -458,19 +486,18 @@ namespace OpenSim.Region.Framework.Scenes
458 } 486 }
459 else 487 else
460 { 488 {
461 m_running = false;
462 StopTimer(); 489 StopTimer();
490 m_running = false;
463 } 491 }
464 } 492 }
465 493
466 public void Stop() 494 public void Stop()
467 { 495 {
496 StopTimer();
468 m_running = false; 497 m_running = false;
469 m_isCrossing = false; 498 m_isCrossing = false;
470 m_waitingCrossing = false; 499 m_waitingCrossing = false;
471 500
472 StopTimer();
473
474 m_basePosition = m_group.AbsolutePosition; 501 m_basePosition = m_group.AbsolutePosition;
475 m_baseRotation = m_group.GroupRotation; 502 m_baseRotation = m_group.GroupRotation;
476 503
@@ -483,14 +510,34 @@ namespace OpenSim.Region.Framework.Scenes
483 510
484 public void Pause() 511 public void Pause()
485 { 512 {
486 m_running = false;
487 StopTimer(); 513 StopTimer();
514 m_running = false;
488 515
489 m_group.RootPart.Velocity = Vector3.Zero; 516 m_group.RootPart.Velocity = Vector3.Zero;
490 m_group.RootPart.AngularVelocity = Vector3.Zero; 517 m_group.RootPart.AngularVelocity = Vector3.Zero;
491 m_group.SendGroupRootTerseUpdate(); 518 m_group.SendGroupRootTerseUpdate();
492// m_group.RootPart.ScheduleTerseUpdate(); 519// m_group.RootPart.ScheduleTerseUpdate();
520 }
493 521
522 public void Suspend()
523 {
524 lock (m_frames)
525 {
526 if (m_timerStopped)
527 return;
528 m_timerStopped = true;
529 }
530 }
531
532 public void Resume()
533 {
534 lock (m_frames)
535 {
536 if (!m_timerStopped)
537 return;
538 if (m_running && !m_waitingCrossing)
539 StartTimer();
540 }
494 } 541 }
495 542
496 private void GetNextList() 543 private void GetNextList()
@@ -581,6 +628,7 @@ namespace OpenSim.Region.Framework.Scenes
581 628
582 pos = (Vector3)k.Position; 629 pos = (Vector3)k.Position;
583 rot = (Quaternion)k.Rotation; 630 rot = (Quaternion)k.Rotation;
631
584 } 632 }
585 633
586 m_basePosition = pos; 634 m_basePosition = pos;
@@ -592,15 +640,41 @@ namespace OpenSim.Region.Framework.Scenes
592 640
593 public void OnTimer(double tickDuration) 641 public void OnTimer(double tickDuration)
594 { 642 {
643 if (!Monitor.TryEnter(m_frames))
644 return;
645 if (m_timerStopped)
646 KeyframeTimer.Remove(this);
647 else
648 DoOnTimer(tickDuration);
649 Monitor.Exit(m_frames);
650 }
651
652 private void Done()
653 {
654 KeyframeTimer.Remove(this);
655 m_timerStopped = true;
656 m_running = false;
657 m_isCrossing = false;
658 m_waitingCrossing = false;
659
660 m_basePosition = m_group.AbsolutePosition;
661 m_baseRotation = m_group.GroupRotation;
662
663 m_group.RootPart.Velocity = Vector3.Zero;
664 m_group.RootPart.AngularVelocity = Vector3.Zero;
665 m_group.SendGroupRootTerseUpdate();
666 // m_group.RootPart.ScheduleTerseUpdate();
667 m_frames.Clear();
668 }
669
670 private void DoOnTimer(double tickDuration)
671 {
595 if (m_skipLoops > 0) 672 if (m_skipLoops > 0)
596 { 673 {
597 m_skipLoops--; 674 m_skipLoops--;
598 return; 675 return;
599 } 676 }
600 677
601 if (m_timerStopped) // trap events still in air even after a timer.stop
602 return;
603
604 if (m_group == null) 678 if (m_group == null)
605 return; 679 return;
606 680
@@ -612,7 +686,6 @@ namespace OpenSim.Region.Framework.Scenes
612 { 686 {
613 m_group.RootPart.Velocity = Vector3.Zero; 687 m_group.RootPart.Velocity = Vector3.Zero;
614 m_group.SendGroupRootTerseUpdate(); 688 m_group.SendGroupRootTerseUpdate();
615
616 } 689 }
617 return; 690 return;
618 } 691 }
@@ -635,6 +708,7 @@ namespace OpenSim.Region.Framework.Scenes
635 708
636 if (m_frames.Count == 0) 709 if (m_frames.Count == 0)
637 { 710 {
711<<<<<<< HEAD
638 if (!m_running) return; 712 if (!m_running) return;
639 713
640 GetNextList(); 714 GetNextList();
@@ -656,11 +730,33 @@ namespace OpenSim.Region.Framework.Scenes
656 730
657 return; 731 return;
658 } 732 }
733=======
734 lock (m_frames)
735 {
736 GetNextList();
659 737
660 m_currentFrame = m_frames[0]; 738 if (m_frames.Count == 0)
661 m_currentFrame.TimeMS += (int)tickDuration; 739 {
740 Done();
741 Scene scene = m_group.Scene;
662 742
743 IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>();
744 foreach (IScriptModule m in scriptModules)
745 {
746 if (m == null)
747 continue;
748 m.PostObjectEvent(m_group.RootPart.UUID, "moving_end", new object[0]);
749 }
750>>>>>>> avn/ubitvar
751
752 return;
753 }
754
755 m_currentFrame = m_frames[0];
756 m_currentFrame.TimeMS += (int)tickDuration;
757 }
663 //force a update on a keyframe transition 758 //force a update on a keyframe transition
759 m_nextPosition = m_group.AbsolutePosition;
664 update = true; 760 update = true;
665 } 761 }
666 762
@@ -681,9 +777,13 @@ namespace OpenSim.Region.Framework.Scenes
681 // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation); 777 // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation);
682 778
683 m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation; 779 m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation;
684 m_frames.RemoveAt(0); 780
685 if (m_frames.Count > 0) 781 lock (m_frames)
686 m_currentFrame = m_frames[0]; 782 {
783 m_frames.RemoveAt(0);
784 if (m_frames.Count > 0)
785 m_currentFrame = m_frames[0];
786 }
687 787
688 update = true; 788 update = true;
689 } 789 }
@@ -695,14 +795,19 @@ namespace OpenSim.Region.Framework.Scenes
695 Vector3 positionThisStep = m_currentFrame.StartPosition + (m_currentFrame.Position.Value - m_currentFrame.StartPosition) * completed; 795 Vector3 positionThisStep = m_currentFrame.StartPosition + (m_currentFrame.Position.Value - m_currentFrame.StartPosition) * completed;
696 Vector3 motionThisStep = positionThisStep - m_group.AbsolutePosition; 796 Vector3 motionThisStep = positionThisStep - m_group.AbsolutePosition;
697 797
798<<<<<<< HEAD
698 float mag = Vector3.Mag(motionThisStep); 799 float mag = Vector3.Mag(motionThisStep);
699 800
700 if ((mag >= 0.02f) || lastStep) 801 if ((mag >= 0.02f) || lastStep)
701 { 802 {
702 m_nextPosition = m_group.AbsolutePosition + motionThisStep; 803 m_nextPosition = m_group.AbsolutePosition + motionThisStep;
703 m_group.AbsolutePosition = m_nextPosition; 804 m_group.AbsolutePosition = m_nextPosition;
805=======
806 m_nextPosition = m_group.AbsolutePosition + motionThisFrame;
807
808 if (Vector3.Mag(motionThisFrame) >= 0.05f)
809>>>>>>> avn/ubitvar
704 update = true; 810 update = true;
705 }
706 811
707 //int totalSteps = m_currentFrame.TimeTotal / (int)tickDuration; 812 //int totalSteps = m_currentFrame.TimeTotal / (int)tickDuration;
708 //m_log.DebugFormat("KeyframeMotion.OnTimer: step {0}/{1}, curPosition={2}, finalPosition={3}, motionThisStep={4} (scene {5})", 813 //m_log.DebugFormat("KeyframeMotion.OnTimer: step {0}/{1}, curPosition={2}, finalPosition={3}, motionThisStep={4} (scene {5})",
@@ -714,6 +819,7 @@ namespace OpenSim.Region.Framework.Scenes
714 819
715 Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, completed); 820 Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, completed);
716 step.Normalize(); 821 step.Normalize();
822<<<<<<< HEAD
717/* use simpler change detection 823/* use simpler change detection
718* float angle = 0; 824* float angle = 0;
719 825
@@ -751,8 +857,45 @@ namespace OpenSim.Region.Framework.Scenes
751 || lastStep) 857 || lastStep)
752 // assuming w is a dependente var 858 // assuming w is a dependente var
753 859
860=======
861 /* use simpler change detection
862 * float angle = 0;
863
864 float aa = current.X * current.X + current.Y * current.Y + current.Z * current.Z + current.W * current.W;
865 float bb = step.X * step.X + step.Y * step.Y + step.Z * step.Z + step.W * step.W;
866 float aa_bb = aa * bb;
867
868 if (aa_bb == 0)
869 {
870 angle = 0;
871 }
872 else
873 {
874 float ab = current.X * step.X +
875 current.Y * step.Y +
876 current.Z * step.Z +
877 current.W * step.W;
878 float q = (ab * ab) / aa_bb;
879
880 if (q > 1.0f)
881 {
882 angle = 0;
883 }
884 else
885 {
886 angle = (float)Math.Acos(2 * q - 1);
887 }
888 }
889
890 if (angle > 0.01f)
891 */
892 if (Math.Abs(step.X - current.X) > 0.001f
893 || Math.Abs(step.Y - current.Y) > 0.001f
894 || Math.Abs(step.Z - current.Z) > 0.001f)
895 // assuming w is a dependente var
896>>>>>>> avn/ubitvar
754 { 897 {
755// m_group.UpdateGroupRotationR(step); 898 // m_group.UpdateGroupRotationR(step);
756 m_group.RootPart.RotationOffset = step; 899 m_group.RootPart.RotationOffset = step;
757 900
758 //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2); 901 //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2);
@@ -763,18 +906,31 @@ namespace OpenSim.Region.Framework.Scenes
763 906
764 if (update) 907 if (update)
765 { 908 {
909 m_group.AbsolutePosition = m_nextPosition;
766 m_group.SendGroupRootTerseUpdate(); 910 m_group.SendGroupRootTerseUpdate();
767 } 911 }
768 } 912 }
769 913
770 public Byte[] Serialize() 914 public Byte[] Serialize()
771 { 915 {
916 bool timerWasStopped;
917 lock (m_frames)
918 {
919 timerWasStopped = m_timerStopped;
920 }
772 StopTimer(); 921 StopTimer();
773 922
774 SceneObjectGroup tmp = m_group; 923 SceneObjectGroup tmp = m_group;
775 m_group = null; 924 m_group = null;
776 if (!m_selected && tmp != null) 925 if (!m_selected && tmp != null)
777 m_serializedPosition = tmp.AbsolutePosition; 926 m_serializedPosition = tmp.AbsolutePosition;
927<<<<<<< HEAD
928=======
929 fmt.Serialize(ms, this);
930 m_group = tmp;
931 if (!timerWasStopped && m_running && !m_waitingCrossing)
932 StartTimer();
933>>>>>>> avn/ubitvar
778 934
779 using (MemoryStream ms = new MemoryStream()) 935 using (MemoryStream ms = new MemoryStream())
780 { 936 {
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
index 1b10e3c..c0405ad 100644
--- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs
+++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
@@ -91,6 +91,11 @@ namespace OpenSim.Region.Framework.Scenes
91 return 0; 91 return 0;
92 92
93 uint priority; 93 uint priority;
94
95
96 // HACK
97 return GetPriorityByBestAvatarResponsiveness(client, entity);
98
94 99
95 switch (m_scene.UpdatePrioritizationScheme) 100 switch (m_scene.UpdatePrioritizationScheme)
96 { 101 {
@@ -157,30 +162,31 @@ namespace OpenSim.Region.Framework.Scenes
157 162
158 private uint GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity) 163 private uint GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity)
159 { 164 {
160 uint pqueue = ComputeDistancePriority(client,entity,true); 165 uint pqueue = 2; // keep compiler happy
161 166
162 ScenePresence presence = m_scene.GetScenePresence(client.AgentId); 167 ScenePresence presence = m_scene.GetScenePresence(client.AgentId);
163 if (presence != null) 168 if (presence != null)
164 { 169 {
165 if (!presence.IsChildAgent) 170 // All avatars other than our own go into pqueue 1
171 if (entity is ScenePresence)
172 return 1;
173
174 if (entity is SceneObjectPart)
166 { 175 {
167 // All avatars other than our own go into pqueue 1 176 // Attachments are high priority,
168 if (entity is ScenePresence) 177 if (((SceneObjectPart)entity).ParentGroup.IsAttachment)
169 return 1; 178 return 2;
170 179
171 if (entity is SceneObjectPart) 180 pqueue = ComputeDistancePriority(client, entity, false);
172 { 181
173 // Attachments are high priority, 182 // Non physical prims are lower priority than physical prims
174 if (((SceneObjectPart)entity).ParentGroup.IsAttachment) 183 PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor;
175 return 1; 184 if (physActor == null || !physActor.IsPhysical)
176 185 pqueue++;
177 // Non physical prims are lower priority than physical prims
178 PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor;
179 if (physActor == null || !physActor.IsPhysical)
180 pqueue++;
181 }
182 } 186 }
183 } 187 }
188 else
189 pqueue = ComputeDistancePriority(client, entity, false);
184 190
185 return pqueue; 191 return pqueue;
186 } 192 }
@@ -212,25 +218,43 @@ namespace OpenSim.Region.Framework.Scenes
212 } 218 }
213 219
214 // Use the camera position for local agents and avatar position for remote agents 220 // Use the camera position for local agents and avatar position for remote agents
215 Vector3 presencePos = (presence.IsChildAgent) ? 221 // Why would I want that? They could be camming but I still see them at the
216 presence.AbsolutePosition : 222 // avatar position, so why should I update them as if they were at their
217 presence.CameraPosition; 223 // camera positions? Makes no sense!
224 // TODO: Fix this mess
225 //Vector3 presencePos = (presence.IsChildAgent) ?
226 // presence.AbsolutePosition :
227 // presence.CameraPosition;
228
229 Vector3 presencePos = presence.AbsolutePosition;
218 230
219 // Compute the distance... 231 // Compute the distance...
220 double distance = Vector3.Distance(presencePos, entityPos); 232 double distance = Vector3.Distance(presencePos, entityPos);
221 233
222 // And convert the distance to a priority queue, this computation gives queues 234 // And convert the distance to a priority queue, this computation gives queues
223 // at 10, 20, 40, 80, 160, 320, 640, and 1280m 235 // at 10, 20, 40, 80, 160, 320, 640, and 1280m
224 uint pqueue = PriorityQueue.NumberOfImmediateQueues; 236 uint pqueue = PriorityQueue.NumberOfImmediateQueues + 1; // reserve attachments queue
225 uint queues = PriorityQueue.NumberOfQueues - PriorityQueue.NumberOfImmediateQueues; 237 uint queues = PriorityQueue.NumberOfQueues - PriorityQueue.NumberOfImmediateQueues;
226 238/*
227 for (int i = 0; i < queues - 1; i++) 239 for (int i = 0; i < queues - 1; i++)
228 { 240 {
229 if (distance < 10 * Math.Pow(2.0,i)) 241 if (distance < 30 * Math.Pow(2.0,i))
230 break; 242 break;
231 pqueue++; 243 pqueue++;
232 } 244 }
233 245*/
246 if (distance > 10f)
247 {
248 float tmp = (float)Math.Log((double)distance) * 1.4426950408889634073599246810019f - 3.3219280948873623478703194294894f;
249 // for a map identical to original:
250 // now
251 // 1st constant is 1/(log(2)) (natural log) so we get log2(distance)
252 // 2st constant makes it be log2(distance/10)
253 pqueue += (uint)tmp;
254 if (pqueue > queues - 1)
255 pqueue = queues - 1;
256 }
257
234 // If this is a root agent, then determine front & back 258 // If this is a root agent, then determine front & back
235 // Bump up the priority queue (drop the priority) for any objects behind the avatar 259 // Bump up the priority queue (drop the priority) for any objects behind the avatar
236 if (useFrontBack && ! presence.IsChildAgent) 260 if (useFrontBack && ! presence.IsChildAgent)
diff --git a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs
new file mode 100644
index 0000000..10ac37c
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32
33namespace OpenSim.Region.Framework.Scenes
34{
35 public static class SOPMaterialData
36 {
37 public enum SopMaterial : int // redundante and not in use for now
38 {
39 Stone = 0,
40 Metal = 1,
41 Glass = 2,
42 Wood = 3,
43 Flesh = 4,
44 Plastic = 5,
45 Rubber = 6,
46 light = 7 // compatibility with old viewers
47 }
48
49 private struct MaterialData
50 {
51 public float friction;
52 public float bounce;
53 public MaterialData(float f, float b)
54 {
55 friction = f;
56 bounce = b;
57 }
58 }
59
60 private static MaterialData[] m_materialdata = {
61 new MaterialData(0.8f,0.4f), // Stone
62 new MaterialData(0.3f,0.4f), // Metal
63 new MaterialData(0.2f,0.7f), // Glass
64 new MaterialData(0.6f,0.5f), // Wood
65 new MaterialData(0.9f,0.3f), // Flesh
66 new MaterialData(0.4f,0.7f), // Plastic
67 new MaterialData(0.9f,0.95f), // Rubber
68 new MaterialData(0.0f,0.0f) // light ??
69 };
70
71 public static Material MaxMaterial
72 {
73 get { return (Material)(m_materialdata.Length - 1); }
74 }
75
76 public static float friction(Material material)
77 {
78 int indx = (int)material;
79 if (indx < m_materialdata.Length)
80 return (m_materialdata[indx].friction);
81 else
82 return 0;
83 }
84
85 public static float bounce(Material material)
86 {
87 int indx = (int)material;
88 if (indx < m_materialdata.Length)
89 return (m_materialdata[indx].bounce);
90 else
91 return 0;
92 }
93
94 }
95} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs
new file mode 100644
index 0000000..9cb901a
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs
@@ -0,0 +1,791 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Physics.Manager;
33using System.Text;
34using System.IO;
35using System.Xml;
36using OpenSim.Framework.Serialization;
37using OpenSim.Framework.Serialization.External;
38using OpenSim.Region.Framework.Scenes.Serialization;
39
40namespace OpenSim.Region.Framework.Scenes
41{
42 public class SOPVehicle
43 {
44 public VehicleData vd;
45
46 public Vehicle Type
47 {
48 get { return vd.m_type; }
49 }
50
51 public SOPVehicle()
52 {
53 vd = new VehicleData();
54 ProcessTypeChange(Vehicle.TYPE_NONE); // is needed?
55 }
56
57 public void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
58 {
59 float len;
60 float timestep = 0.01f;
61 switch (pParam)
62 {
63 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
64 if (pValue < 0f) pValue = 0f;
65 if (pValue > 1f) pValue = 1f;
66 vd.m_angularDeflectionEfficiency = pValue;
67 break;
68 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
69 if (pValue < timestep) pValue = timestep;
70 vd.m_angularDeflectionTimescale = pValue;
71 break;
72 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
73 if (pValue < timestep) pValue = timestep;
74 else if (pValue > 120) pValue = 120;
75 vd.m_angularMotorDecayTimescale = pValue;
76 break;
77 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
78 if (pValue < timestep) pValue = timestep;
79 vd.m_angularMotorTimescale = pValue;
80 break;
81 case Vehicle.BANKING_EFFICIENCY:
82 if (pValue < -1f) pValue = -1f;
83 if (pValue > 1f) pValue = 1f;
84 vd.m_bankingEfficiency = pValue;
85 break;
86 case Vehicle.BANKING_MIX:
87 if (pValue < 0f) pValue = 0f;
88 if (pValue > 1f) pValue = 1f;
89 vd.m_bankingMix = pValue;
90 break;
91 case Vehicle.BANKING_TIMESCALE:
92 if (pValue < timestep) pValue = timestep;
93 vd.m_bankingTimescale = pValue;
94 break;
95 case Vehicle.BUOYANCY:
96 if (pValue < -1f) pValue = -1f;
97 if (pValue > 1f) pValue = 1f;
98 vd.m_VehicleBuoyancy = pValue;
99 break;
100 case Vehicle.HOVER_EFFICIENCY:
101 if (pValue < 0f) pValue = 0f;
102 if (pValue > 1f) pValue = 1f;
103 vd.m_VhoverEfficiency = pValue;
104 break;
105 case Vehicle.HOVER_HEIGHT:
106 vd.m_VhoverHeight = pValue;
107 break;
108 case Vehicle.HOVER_TIMESCALE:
109 if (pValue < timestep) pValue = timestep;
110 vd.m_VhoverTimescale = pValue;
111 break;
112 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
113 if (pValue < 0f) pValue = 0f;
114 if (pValue > 1f) pValue = 1f;
115 vd.m_linearDeflectionEfficiency = pValue;
116 break;
117 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
118 if (pValue < timestep) pValue = timestep;
119 vd.m_linearDeflectionTimescale = pValue;
120 break;
121 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
122 if (pValue < timestep) pValue = timestep;
123 else if (pValue > 120) pValue = 120;
124 vd.m_linearMotorDecayTimescale = pValue;
125 break;
126 case Vehicle.LINEAR_MOTOR_TIMESCALE:
127 if (pValue < timestep) pValue = timestep;
128 vd.m_linearMotorTimescale = pValue;
129 break;
130 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
131 if (pValue < 0f) pValue = 0f;
132 if (pValue > 1f) pValue = 1f;
133 vd.m_verticalAttractionEfficiency = pValue;
134 break;
135 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
136 if (pValue < timestep) pValue = timestep;
137 vd.m_verticalAttractionTimescale = pValue;
138 break;
139
140 // These are vector properties but the engine lets you use a single float value to
141 // set all of the components to the same value
142 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
143 if (pValue < timestep) pValue = timestep;
144 vd.m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
145 break;
146 case Vehicle.ANGULAR_MOTOR_DIRECTION:
147 vd.m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
148 len = vd.m_angularMotorDirection.Length();
149 if (len > 12.566f)
150 vd.m_angularMotorDirection *= (12.566f / len);
151 break;
152 case Vehicle.LINEAR_FRICTION_TIMESCALE:
153 if (pValue < timestep) pValue = timestep;
154 vd.m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
155 break;
156 case Vehicle.LINEAR_MOTOR_DIRECTION:
157 vd.m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
158 len = vd.m_linearMotorDirection.Length();
159 if (len > 30.0f)
160 vd.m_linearMotorDirection *= (30.0f / len);
161 break;
162 case Vehicle.LINEAR_MOTOR_OFFSET:
163 vd.m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
164 len = vd.m_linearMotorOffset.Length();
165 if (len > 100.0f)
166 vd.m_linearMotorOffset *= (100.0f / len);
167 break;
168 }
169 }//end ProcessFloatVehicleParam
170
171 public void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
172 {
173 float len;
174 float timestep = 0.01f;
175 switch (pParam)
176 {
177 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
178 if (pValue.X < timestep) pValue.X = timestep;
179 if (pValue.Y < timestep) pValue.Y = timestep;
180 if (pValue.Z < timestep) pValue.Z = timestep;
181
182 vd.m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
183 break;
184 case Vehicle.ANGULAR_MOTOR_DIRECTION:
185 vd.m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
186 // Limit requested angular speed to 2 rps= 4 pi rads/sec
187 len = vd.m_angularMotorDirection.Length();
188 if (len > 12.566f)
189 vd.m_angularMotorDirection *= (12.566f / len);
190 break;
191 case Vehicle.LINEAR_FRICTION_TIMESCALE:
192 if (pValue.X < timestep) pValue.X = timestep;
193 if (pValue.Y < timestep) pValue.Y = timestep;
194 if (pValue.Z < timestep) pValue.Z = timestep;
195 vd.m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
196 break;
197 case Vehicle.LINEAR_MOTOR_DIRECTION:
198 vd.m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
199 len = vd.m_linearMotorDirection.Length();
200 if (len > 30.0f)
201 vd.m_linearMotorDirection *= (30.0f / len);
202 break;
203 case Vehicle.LINEAR_MOTOR_OFFSET:
204 vd.m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
205 len = vd.m_linearMotorOffset.Length();
206 if (len > 100.0f)
207 vd.m_linearMotorOffset *= (100.0f / len);
208 break;
209 }
210 }//end ProcessVectorVehicleParam
211
212 public void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
213 {
214 switch (pParam)
215 {
216 case Vehicle.REFERENCE_FRAME:
217 vd.m_referenceFrame = pValue;
218 break;
219 }
220 }//end ProcessRotationVehicleParam
221
222 public void ProcessVehicleFlags(int pParam, bool remove)
223 {
224 if (remove)
225 {
226 vd.m_flags &= ~((VehicleFlag)pParam);
227 }
228 else
229 {
230 vd.m_flags |= (VehicleFlag)pParam;
231 }
232 }//end ProcessVehicleFlags
233
234 public void ProcessTypeChange(Vehicle pType)
235 {
236 vd.m_linearMotorDirection = Vector3.Zero;
237 vd.m_angularMotorDirection = Vector3.Zero;
238 vd.m_linearMotorOffset = Vector3.Zero;
239 vd.m_referenceFrame = Quaternion.Identity;
240
241 // Set Defaults For Type
242 vd.m_type = pType;
243 switch (pType)
244 {
245 case Vehicle.TYPE_NONE:
246 vd.m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
247 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
248 vd.m_linearMotorTimescale = 1000;
249 vd.m_linearMotorDecayTimescale = 120;
250 vd.m_angularMotorTimescale = 1000;
251 vd.m_angularMotorDecayTimescale = 1000;
252 vd.m_VhoverHeight = 0;
253 vd.m_VhoverEfficiency = 1;
254 vd.m_VhoverTimescale = 1000;
255 vd.m_VehicleBuoyancy = 0;
256 vd.m_linearDeflectionEfficiency = 0;
257 vd.m_linearDeflectionTimescale = 1000;
258 vd.m_angularDeflectionEfficiency = 0;
259 vd.m_angularDeflectionTimescale = 1000;
260 vd.m_bankingEfficiency = 0;
261 vd.m_bankingMix = 1;
262 vd.m_bankingTimescale = 1000;
263 vd.m_verticalAttractionEfficiency = 0;
264 vd.m_verticalAttractionTimescale = 1000;
265
266 vd.m_flags = (VehicleFlag)0;
267 break;
268
269 case Vehicle.TYPE_SLED:
270 vd.m_linearFrictionTimescale = new Vector3(30, 1, 1000);
271 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
272 vd.m_linearMotorTimescale = 1000;
273 vd.m_linearMotorDecayTimescale = 120;
274 vd.m_angularMotorTimescale = 1000;
275 vd.m_angularMotorDecayTimescale = 120;
276 vd.m_VhoverHeight = 0;
277 vd.m_VhoverEfficiency = 1;
278 vd.m_VhoverTimescale = 10;
279 vd.m_VehicleBuoyancy = 0;
280 vd.m_linearDeflectionEfficiency = 1;
281 vd.m_linearDeflectionTimescale = 1;
282 vd.m_angularDeflectionEfficiency = 0;
283 vd.m_angularDeflectionTimescale = 1000;
284 vd.m_bankingEfficiency = 0;
285 vd.m_bankingMix = 1;
286 vd.m_bankingTimescale = 10;
287 vd.m_flags &=
288 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
289 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
290 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
291 break;
292 case Vehicle.TYPE_CAR:
293 vd.m_linearFrictionTimescale = new Vector3(100, 2, 1000);
294 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
295 vd.m_linearMotorTimescale = 1;
296 vd.m_linearMotorDecayTimescale = 60;
297 vd.m_angularMotorTimescale = 1;
298 vd.m_angularMotorDecayTimescale = 0.8f;
299 vd.m_VhoverHeight = 0;
300 vd.m_VhoverEfficiency = 0;
301 vd.m_VhoverTimescale = 1000;
302 vd.m_VehicleBuoyancy = 0;
303 vd.m_linearDeflectionEfficiency = 1;
304 vd.m_linearDeflectionTimescale = 2;
305 vd.m_angularDeflectionEfficiency = 0;
306 vd.m_angularDeflectionTimescale = 10;
307 vd.m_verticalAttractionEfficiency = 1f;
308 vd.m_verticalAttractionTimescale = 10f;
309 vd.m_bankingEfficiency = -0.2f;
310 vd.m_bankingMix = 1;
311 vd.m_bankingTimescale = 1;
312 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
313 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY |
314 VehicleFlag.LIMIT_MOTOR_UP | VehicleFlag.HOVER_UP_ONLY);
315 break;
316 case Vehicle.TYPE_BOAT:
317 vd.m_linearFrictionTimescale = new Vector3(10, 3, 2);
318 vd.m_angularFrictionTimescale = new Vector3(10, 10, 10);
319 vd.m_linearMotorTimescale = 5;
320 vd.m_linearMotorDecayTimescale = 60;
321 vd.m_angularMotorTimescale = 4;
322 vd.m_angularMotorDecayTimescale = 4;
323 vd.m_VhoverHeight = 0;
324 vd.m_VhoverEfficiency = 0.5f;
325 vd.m_VhoverTimescale = 2;
326 vd.m_VehicleBuoyancy = 1;
327 vd.m_linearDeflectionEfficiency = 0.5f;
328 vd.m_linearDeflectionTimescale = 3;
329 vd.m_angularDeflectionEfficiency = 0.5f;
330 vd.m_angularDeflectionTimescale = 5;
331 vd.m_verticalAttractionEfficiency = 0.5f;
332 vd.m_verticalAttractionTimescale = 5f;
333 vd.m_bankingEfficiency = -0.3f;
334 vd.m_bankingMix = 0.8f;
335 vd.m_bankingTimescale = 1;
336 vd.m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
337 VehicleFlag.HOVER_GLOBAL_HEIGHT |
338 VehicleFlag.HOVER_UP_ONLY |
339 VehicleFlag.LIMIT_ROLL_ONLY);
340 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
341 VehicleFlag.LIMIT_MOTOR_UP |
342 VehicleFlag.HOVER_WATER_ONLY);
343 break;
344 case Vehicle.TYPE_AIRPLANE:
345 vd.m_linearFrictionTimescale = new Vector3(200, 10, 5);
346 vd.m_angularFrictionTimescale = new Vector3(20, 20, 20);
347 vd.m_linearMotorTimescale = 2;
348 vd.m_linearMotorDecayTimescale = 60;
349 vd.m_angularMotorTimescale = 4;
350 vd.m_angularMotorDecayTimescale = 8;
351 vd.m_VhoverHeight = 0;
352 vd.m_VhoverEfficiency = 0.5f;
353 vd.m_VhoverTimescale = 1000;
354 vd.m_VehicleBuoyancy = 0;
355 vd.m_linearDeflectionEfficiency = 0.5f;
356 vd.m_linearDeflectionTimescale = 0.5f;
357 vd.m_angularDeflectionEfficiency = 1;
358 vd.m_angularDeflectionTimescale = 2;
359 vd.m_verticalAttractionEfficiency = 0.9f;
360 vd.m_verticalAttractionTimescale = 2f;
361 vd.m_bankingEfficiency = 1;
362 vd.m_bankingMix = 0.7f;
363 vd.m_bankingTimescale = 2;
364 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
365 VehicleFlag.HOVER_TERRAIN_ONLY |
366 VehicleFlag.HOVER_GLOBAL_HEIGHT |
367 VehicleFlag.HOVER_UP_ONLY |
368 VehicleFlag.NO_DEFLECTION_UP |
369 VehicleFlag.LIMIT_MOTOR_UP);
370 vd.m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
371 break;
372 case Vehicle.TYPE_BALLOON:
373 vd.m_linearFrictionTimescale = new Vector3(5, 5, 5);
374 vd.m_angularFrictionTimescale = new Vector3(10, 10, 10);
375 vd.m_linearMotorTimescale = 5;
376 vd.m_linearMotorDecayTimescale = 60;
377 vd.m_angularMotorTimescale = 6;
378 vd.m_angularMotorDecayTimescale = 10;
379 vd.m_VhoverHeight = 5;
380 vd.m_VhoverEfficiency = 0.8f;
381 vd.m_VhoverTimescale = 10;
382 vd.m_VehicleBuoyancy = 1;
383 vd.m_linearDeflectionEfficiency = 0;
384 vd.m_linearDeflectionTimescale = 5;
385 vd.m_angularDeflectionEfficiency = 0;
386 vd.m_angularDeflectionTimescale = 5;
387 vd.m_verticalAttractionEfficiency = 0f;
388 vd.m_verticalAttractionTimescale = 1000f;
389 vd.m_bankingEfficiency = 0;
390 vd.m_bankingMix = 0.7f;
391 vd.m_bankingTimescale = 5;
392 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
393 VehicleFlag.HOVER_TERRAIN_ONLY |
394 VehicleFlag.HOVER_UP_ONLY |
395 VehicleFlag.NO_DEFLECTION_UP |
396 VehicleFlag.LIMIT_MOTOR_UP);
397 vd.m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY |
398 VehicleFlag.HOVER_GLOBAL_HEIGHT);
399 break;
400 }
401 }
402 public void SetVehicle(PhysicsActor ph)
403 {
404 if (ph == null)
405 return;
406 ph.SetVehicle(vd);
407 }
408
409 private XmlTextWriter writer;
410
411 private void XWint(string name, int i)
412 {
413 writer.WriteElementString(name, i.ToString());
414 }
415
416 private void XWfloat(string name, float f)
417 {
418 writer.WriteElementString(name, f.ToString(Utils.EnUsCulture));
419 }
420
421 private void XWVector(string name, Vector3 vec)
422 {
423 writer.WriteStartElement(name);
424 writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture));
425 writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture));
426 writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture));
427 writer.WriteEndElement();
428 }
429
430 private void XWQuat(string name, Quaternion quat)
431 {
432 writer.WriteStartElement(name);
433 writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture));
434 writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture));
435 writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture));
436 writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture));
437 writer.WriteEndElement();
438 }
439
440 public void ToXml2(XmlTextWriter twriter)
441 {
442 writer = twriter;
443 writer.WriteStartElement("Vehicle");
444
445 XWint("TYPE", (int)vd.m_type);
446 XWint("FLAGS", (int)vd.m_flags);
447
448 // Linear properties
449 XWVector("LMDIR", vd.m_linearMotorDirection);
450 XWVector("LMFTIME", vd.m_linearFrictionTimescale);
451 XWfloat("LMDTIME", vd.m_linearMotorDecayTimescale);
452 XWfloat("LMTIME", vd.m_linearMotorTimescale);
453 XWVector("LMOFF", vd.m_linearMotorOffset);
454
455 //Angular properties
456 XWVector("AMDIR", vd.m_angularMotorDirection);
457 XWfloat("AMTIME", vd.m_angularMotorTimescale);
458 XWfloat("AMDTIME", vd.m_angularMotorDecayTimescale);
459 XWVector("AMFTIME", vd.m_angularFrictionTimescale);
460
461 //Deflection properties
462 XWfloat("ADEFF", vd.m_angularDeflectionEfficiency);
463 XWfloat("ADTIME", vd.m_angularDeflectionTimescale);
464 XWfloat("LDEFF", vd.m_linearDeflectionEfficiency);
465 XWfloat("LDTIME", vd.m_linearDeflectionTimescale);
466
467 //Banking properties
468 XWfloat("BEFF", vd.m_bankingEfficiency);
469 XWfloat("BMIX", vd.m_bankingMix);
470 XWfloat("BTIME", vd.m_bankingTimescale);
471
472 //Hover and Buoyancy properties
473 XWfloat("HHEI", vd.m_VhoverHeight);
474 XWfloat("HEFF", vd.m_VhoverEfficiency);
475 XWfloat("HTIME", vd.m_VhoverTimescale);
476 XWfloat("VBUO", vd.m_VehicleBuoyancy);
477
478 //Attractor properties
479 XWfloat("VAEFF", vd.m_verticalAttractionEfficiency);
480 XWfloat("VATIME", vd.m_verticalAttractionTimescale);
481
482 XWQuat("REF_FRAME", vd.m_referenceFrame);
483
484 writer.WriteEndElement();
485 writer = null;
486 }
487
488
489
490 XmlTextReader reader;
491
492 private int XRint()
493 {
494 return reader.ReadElementContentAsInt();
495 }
496
497 private float XRfloat()
498 {
499 return reader.ReadElementContentAsFloat();
500 }
501
502 public Vector3 XRvector()
503 {
504 Vector3 vec;
505 reader.ReadStartElement();
506 vec.X = reader.ReadElementContentAsFloat();
507 vec.Y = reader.ReadElementContentAsFloat();
508 vec.Z = reader.ReadElementContentAsFloat();
509 reader.ReadEndElement();
510 return vec;
511 }
512
513 public Quaternion XRquat()
514 {
515 Quaternion q;
516 reader.ReadStartElement();
517 q.X = reader.ReadElementContentAsFloat();
518 q.Y = reader.ReadElementContentAsFloat();
519 q.Z = reader.ReadElementContentAsFloat();
520 q.W = reader.ReadElementContentAsFloat();
521 reader.ReadEndElement();
522 return q;
523 }
524
525 public static bool EReadProcessors(
526 Dictionary<string, Action> processors,
527 XmlTextReader xtr)
528 {
529 bool errors = false;
530
531 string nodeName = string.Empty;
532 while (xtr.NodeType != XmlNodeType.EndElement)
533 {
534 nodeName = xtr.Name;
535
536 // m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName);
537
538 Action p = null;
539 if (processors.TryGetValue(xtr.Name, out p))
540 {
541 // m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName);
542
543 try
544 {
545 p();
546 }
547 catch (Exception e)
548 {
549 errors = true;
550 if (xtr.NodeType == XmlNodeType.EndElement)
551 xtr.Read();
552 }
553 }
554 else
555 {
556 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
557 xtr.ReadOuterXml(); // ignore
558 }
559 }
560
561 return errors;
562 }
563
564
565 public string ToXml2()
566 {
567 MemoryStream ms = new MemoryStream(512);
568 UTF8Encoding enc = new UTF8Encoding();
569 XmlTextWriter xwriter = new XmlTextWriter(ms, enc);
570 ToXml2(xwriter);
571 xwriter.Flush();
572 string s = ms.GetStreamString();
573 xwriter.Close();
574 return s;
575 }
576
577 public static SOPVehicle FromXml2(string text)
578 {
579 if (text == String.Empty)
580 return null;
581
582 UTF8Encoding enc = new UTF8Encoding();
583 MemoryStream ms = new MemoryStream(enc.GetBytes(text));
584 XmlTextReader xreader = new XmlTextReader(ms);
585
586 SOPVehicle v = new SOPVehicle();
587 bool error;
588
589 v.FromXml2(xreader, out error);
590
591 xreader.Close();
592
593 if (error)
594 {
595 v = null;
596 return null;
597 }
598 return v;
599 }
600
601 public static SOPVehicle FromXml2(XmlTextReader reader)
602 {
603 SOPVehicle vehicle = new SOPVehicle();
604
605 bool errors = false;
606
607 vehicle.FromXml2(reader, out errors);
608 if (errors)
609 return null;
610
611 return vehicle;
612 }
613
614 private void FromXml2(XmlTextReader _reader, out bool errors)
615 {
616 errors = false;
617 reader = _reader;
618
619 Dictionary<string, Action> m_VehicleXmlProcessors
620 = new Dictionary<string, Action>();
621
622 m_VehicleXmlProcessors.Add("TYPE", ProcessXR_type);
623 m_VehicleXmlProcessors.Add("FLAGS", ProcessXR_flags);
624
625 // Linear properties
626 m_VehicleXmlProcessors.Add("LMDIR", ProcessXR_linearMotorDirection);
627 m_VehicleXmlProcessors.Add("LMFTIME", ProcessXR_linearFrictionTimescale);
628 m_VehicleXmlProcessors.Add("LMDTIME", ProcessXR_linearMotorDecayTimescale);
629 m_VehicleXmlProcessors.Add("LMTIME", ProcessXR_linearMotorTimescale);
630 m_VehicleXmlProcessors.Add("LMOFF", ProcessXR_linearMotorOffset);
631
632 //Angular properties
633 m_VehicleXmlProcessors.Add("AMDIR", ProcessXR_angularMotorDirection);
634 m_VehicleXmlProcessors.Add("AMTIME", ProcessXR_angularMotorTimescale);
635 m_VehicleXmlProcessors.Add("AMDTIME", ProcessXR_angularMotorDecayTimescale);
636 m_VehicleXmlProcessors.Add("AMFTIME", ProcessXR_angularFrictionTimescale);
637
638 //Deflection properties
639 m_VehicleXmlProcessors.Add("ADEFF", ProcessXR_angularDeflectionEfficiency);
640 m_VehicleXmlProcessors.Add("ADTIME", ProcessXR_angularDeflectionTimescale);
641 m_VehicleXmlProcessors.Add("LDEFF", ProcessXR_linearDeflectionEfficiency);
642 m_VehicleXmlProcessors.Add("LDTIME", ProcessXR_linearDeflectionTimescale);
643
644 //Banking properties
645 m_VehicleXmlProcessors.Add("BEFF", ProcessXR_bankingEfficiency);
646 m_VehicleXmlProcessors.Add("BMIX", ProcessXR_bankingMix);
647 m_VehicleXmlProcessors.Add("BTIME", ProcessXR_bankingTimescale);
648
649 //Hover and Buoyancy properties
650 m_VehicleXmlProcessors.Add("HHEI", ProcessXR_VhoverHeight);
651 m_VehicleXmlProcessors.Add("HEFF", ProcessXR_VhoverEfficiency);
652 m_VehicleXmlProcessors.Add("HTIME", ProcessXR_VhoverTimescale);
653
654 m_VehicleXmlProcessors.Add("VBUO", ProcessXR_VehicleBuoyancy);
655
656 //Attractor properties
657 m_VehicleXmlProcessors.Add("VAEFF", ProcessXR_verticalAttractionEfficiency);
658 m_VehicleXmlProcessors.Add("VATIME", ProcessXR_verticalAttractionTimescale);
659
660 m_VehicleXmlProcessors.Add("REF_FRAME", ProcessXR_referenceFrame);
661
662 vd = new VehicleData();
663
664 reader.ReadStartElement("Vehicle", String.Empty);
665
666 errors = EReadProcessors(
667 m_VehicleXmlProcessors,
668 reader);
669
670 reader.ReadEndElement();
671 reader = null;
672 }
673
674 private void ProcessXR_type()
675 {
676 vd.m_type = (Vehicle)XRint();
677 }
678 private void ProcessXR_flags()
679 {
680 vd.m_flags = (VehicleFlag)XRint();
681 }
682 // Linear properties
683 private void ProcessXR_linearMotorDirection()
684 {
685 vd.m_linearMotorDirection = XRvector();
686 }
687
688 private void ProcessXR_linearFrictionTimescale()
689 {
690 vd.m_linearFrictionTimescale = XRvector();
691 }
692
693 private void ProcessXR_linearMotorDecayTimescale()
694 {
695 vd.m_linearMotorDecayTimescale = XRfloat();
696 }
697 private void ProcessXR_linearMotorTimescale()
698 {
699 vd.m_linearMotorTimescale = XRfloat();
700 }
701 private void ProcessXR_linearMotorOffset()
702 {
703 vd.m_linearMotorOffset = XRvector();
704 }
705
706
707 //Angular properties
708 private void ProcessXR_angularMotorDirection()
709 {
710 vd.m_angularMotorDirection = XRvector();
711 }
712 private void ProcessXR_angularMotorTimescale()
713 {
714 vd.m_angularMotorTimescale = XRfloat();
715 }
716 private void ProcessXR_angularMotorDecayTimescale()
717 {
718 vd.m_angularMotorDecayTimescale = XRfloat();
719 }
720 private void ProcessXR_angularFrictionTimescale()
721 {
722 vd.m_angularFrictionTimescale = XRvector();
723 }
724
725 //Deflection properties
726 private void ProcessXR_angularDeflectionEfficiency()
727 {
728 vd.m_angularDeflectionEfficiency = XRfloat();
729 }
730 private void ProcessXR_angularDeflectionTimescale()
731 {
732 vd.m_angularDeflectionTimescale = XRfloat();
733 }
734 private void ProcessXR_linearDeflectionEfficiency()
735 {
736 vd.m_linearDeflectionEfficiency = XRfloat();
737 }
738 private void ProcessXR_linearDeflectionTimescale()
739 {
740 vd.m_linearDeflectionTimescale = XRfloat();
741 }
742
743 //Banking properties
744 private void ProcessXR_bankingEfficiency()
745 {
746 vd.m_bankingEfficiency = XRfloat();
747 }
748 private void ProcessXR_bankingMix()
749 {
750 vd.m_bankingMix = XRfloat();
751 }
752 private void ProcessXR_bankingTimescale()
753 {
754 vd.m_bankingTimescale = XRfloat();
755 }
756
757 //Hover and Buoyancy properties
758 private void ProcessXR_VhoverHeight()
759 {
760 vd.m_VhoverHeight = XRfloat();
761 }
762 private void ProcessXR_VhoverEfficiency()
763 {
764 vd.m_VhoverEfficiency = XRfloat();
765 }
766 private void ProcessXR_VhoverTimescale()
767 {
768 vd.m_VhoverTimescale = XRfloat();
769 }
770
771 private void ProcessXR_VehicleBuoyancy()
772 {
773 vd.m_VehicleBuoyancy = XRfloat();
774 }
775
776 //Attractor properties
777 private void ProcessXR_verticalAttractionEfficiency()
778 {
779 vd.m_verticalAttractionEfficiency = XRfloat();
780 }
781 private void ProcessXR_verticalAttractionTimescale()
782 {
783 vd.m_verticalAttractionTimescale = XRfloat();
784 }
785
786 private void ProcessXR_referenceFrame()
787 {
788 vd.m_referenceFrame = XRquat();
789 }
790 }
791}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index b838177..e289666 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -106,12 +106,12 @@ namespace OpenSim.Region.Framework.Scenes
106 engine.StartProcessing(); 106 engine.StartProcessing();
107 } 107 }
108 108
109 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item) 109 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item, uint cost)
110 { 110 {
111 IMoneyModule money = RequestModuleInterface<IMoneyModule>(); 111 IMoneyModule money = RequestModuleInterface<IMoneyModule>();
112 if (money != null) 112 if (money != null)
113 { 113 {
114 money.ApplyUploadCharge(agentID, money.UploadCharge, "Asset upload"); 114 money.ApplyUploadCharge(agentID, (int)cost, "Asset upload");
115 } 115 }
116 116
117 AddInventoryItem(item); 117 AddInventoryItem(item);
@@ -182,7 +182,7 @@ namespace OpenSim.Region.Framework.Scenes
182 return false; 182 return false;
183 } 183 }
184 } 184 }
185 185
186 if (InventoryService.AddItem(item)) 186 if (InventoryService.AddItem(item))
187 { 187 {
188 int userlevel = 0; 188 int userlevel = 0;
@@ -338,8 +338,7 @@ namespace OpenSim.Region.Framework.Scenes
338 338
339 // Update item with new asset 339 // Update item with new asset
340 item.AssetID = asset.FullID; 340 item.AssetID = asset.FullID;
341 if (group.UpdateInventoryItem(item)) 341 group.UpdateInventoryItem(item);
342 remoteClient.SendAlertMessage("Script saved");
343 342
344 part.SendPropertiesToClient(remoteClient); 343 part.SendPropertiesToClient(remoteClient);
345 344
@@ -350,12 +349,7 @@ namespace OpenSim.Region.Framework.Scenes
350 { 349 {
351 // Needs to determine which engine was running it and use that 350 // Needs to determine which engine was running it and use that
352 // 351 //
353 part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0); 352 errors = part.Inventory.CreateScriptInstanceEr(item.ItemID, 0, false, DefaultScriptEngine, 1);
354 errors = part.Inventory.GetScriptErrors(item.ItemID);
355 }
356 else
357 {
358 remoteClient.SendAlertMessage("Script saved");
359 } 353 }
360 354
361 // Tell anyone managing scripts that a script has been reloaded/changed 355 // Tell anyone managing scripts that a script has been reloaded/changed
@@ -421,6 +415,7 @@ namespace OpenSim.Region.Framework.Scenes
421 if (item.Owner != remoteClient.AgentId) 415 if (item.Owner != remoteClient.AgentId)
422 return; 416 return;
423 417
418 item.Flags = (item.Flags & ~(uint)255) | (itemUpd.Flags & (uint)255);
424 item.Name = itemUpd.Name; 419 item.Name = itemUpd.Name;
425 item.Description = itemUpd.Description; 420 item.Description = itemUpd.Description;
426 421
@@ -886,8 +881,14 @@ namespace OpenSim.Region.Framework.Scenes
886 return; 881 return;
887 } 882 }
888 883
884<<<<<<< HEAD
889 if (newName == String.Empty) 885 if (newName == String.Empty)
890 newName = item.Name; 886 newName = item.Name;
887=======
888 if (newName == null) newName = item.Name;
889
890 AssetBase asset = AssetService.Get(item.AssetID.ToString());
891>>>>>>> avn/ubitvar
891 892
892 if (remoteClient.AgentId == oldAgentID 893 if (remoteClient.AgentId == oldAgentID
893 || (LibraryService != null 894 || (LibraryService != null
@@ -929,6 +930,24 @@ namespace OpenSim.Region.Framework.Scenes
929 } 930 }
930 931
931 /// <summary> 932 /// <summary>
933 /// Move an item within the agent's inventory, and leave a copy (used in making a new outfit)
934 /// </summary>
935 public void MoveInventoryItemsLeaveCopy(IClientAPI remoteClient, List<InventoryItemBase> items, UUID destfolder)
936 {
937 List<InventoryItemBase> moveitems = new List<InventoryItemBase>();
938 foreach (InventoryItemBase b in items)
939 {
940 CopyInventoryItem(remoteClient, 0, remoteClient.AgentId, b.ID, b.Folder, null);
941 InventoryItemBase n = InventoryService.GetItem(b);
942 n.Folder = destfolder;
943 moveitems.Add(n);
944 remoteClient.SendInventoryItemCreateUpdate(n, 0);
945 }
946
947 MoveInventoryItem(remoteClient, moveitems);
948 }
949
950 /// <summary>
932 /// Move an item within the agent's inventory. 951 /// Move an item within the agent's inventory.
933 /// </summary> 952 /// </summary>
934 /// <param name="remoteClient"></param> 953 /// <param name="remoteClient"></param>
@@ -963,12 +982,31 @@ namespace OpenSim.Region.Framework.Scenes
963 public void CreateNewInventoryItem( 982 public void CreateNewInventoryItem(
964 IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID, 983 IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
965 string name, string description, uint flags, uint callbackID, 984 string name, string description, uint flags, uint callbackID,
985<<<<<<< HEAD
966 UUID assetID, sbyte assetType, sbyte invType, uint nextOwnerMask, int creationDate) 986 UUID assetID, sbyte assetType, sbyte invType, uint nextOwnerMask, int creationDate)
967 { 987 {
968 CreateNewInventoryItem( 988 CreateNewInventoryItem(
969 remoteClient, creatorID, creatorData, folderID, name, description, flags, callbackID, assetID, assetType, invType, 989 remoteClient, creatorID, creatorData, folderID, name, description, flags, callbackID, assetID, assetType, invType,
970 (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All | (uint)PermissionMask.Export, 0, nextOwnerMask, 0, 990 (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All | (uint)PermissionMask.Export, 0, nextOwnerMask, 0,
971 creationDate, true); 991 creationDate, true);
992=======
993 AssetBase asset, sbyte invType, uint nextOwnerMask, int creationDate, UUID transationID)
994 {
995 CreateNewInventoryItem(
996 remoteClient, creatorID, creatorData, folderID, name, description, flags, callbackID, asset, invType,
997 (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All | (uint)PermissionMask.Export, 0, nextOwnerMask, 0, creationDate, transationID);
998 }
999
1000
1001 private void CreateNewInventoryItem(
1002 IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
1003 string name, string description, uint flags, uint callbackID, AssetBase asset, sbyte invType,
1004 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
1005 {
1006 CreateNewInventoryItem(remoteClient, creatorID, creatorData, folderID,
1007 name, description, flags, callbackID, asset, invType,
1008 baseMask, currentMask, everyoneMask, nextOwnerMask, groupMask, creationDate, UUID.Zero);
1009>>>>>>> avn/ubitvar
972 } 1010 }
973 1011
974 /// <summary> 1012 /// <summary>
@@ -992,9 +1030,14 @@ namespace OpenSim.Region.Framework.Scenes
992 /// <param name="creationDate">Unix timestamp at which this item was created.</param> 1030 /// <param name="creationDate">Unix timestamp at which this item was created.</param>
993 private void CreateNewInventoryItem( 1031 private void CreateNewInventoryItem(
994 IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID, 1032 IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
1033<<<<<<< HEAD
995 string name, string description, uint flags, uint callbackID, UUID assetID, sbyte assetType, sbyte invType, 1034 string name, string description, uint flags, uint callbackID, UUID assetID, sbyte assetType, sbyte invType,
996 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate, 1035 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate,
997 bool assetUpload) 1036 bool assetUpload)
1037=======
1038 string name, string description, uint flags, uint callbackID, AssetBase asset, sbyte invType,
1039 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate,UUID transationID)
1040>>>>>>> avn/ubitvar
998 { 1041 {
999 InventoryItemBase item = new InventoryItemBase(); 1042 InventoryItemBase item = new InventoryItemBase();
1000 item.Owner = remoteClient.AgentId; 1043 item.Owner = remoteClient.AgentId;
@@ -1015,9 +1058,17 @@ namespace OpenSim.Region.Framework.Scenes
1015 item.BasePermissions = baseMask; 1058 item.BasePermissions = baseMask;
1016 item.CreationDate = creationDate; 1059 item.CreationDate = creationDate;
1017 1060
1061<<<<<<< HEAD
1018 if (AddInventoryItem(item, assetUpload)) 1062 if (AddInventoryItem(item, assetUpload))
1063=======
1064 // special AnimationSet case
1065 if (item.InvType == (int)CustomInventoryType.AnimationSet)
1066 AnimationSet.enforceItemPermitions(item,true);
1067
1068 if (AddInventoryItem(item))
1069>>>>>>> avn/ubitvar
1019 { 1070 {
1020 remoteClient.SendInventoryItemCreateUpdate(item, callbackID); 1071 remoteClient.SendInventoryItemCreateUpdate(item, transationID, callbackID);
1021 } 1072 }
1022 else 1073 else
1023 { 1074 {
@@ -1233,6 +1284,7 @@ namespace OpenSim.Region.Framework.Scenes
1233 agentItem.BasePermissions = taskItem.BasePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move); 1284 agentItem.BasePermissions = taskItem.BasePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
1234 if (taskItem.InvType == (int)InventoryType.Object) 1285 if (taskItem.InvType == (int)InventoryType.Object)
1235 { 1286 {
1287<<<<<<< HEAD
1236 // Bake the new base permissions from folded permissions 1288 // Bake the new base permissions from folded permissions
1237 // The folded perms are in the lowest 3 bits of the current perms 1289 // The folded perms are in the lowest 3 bits of the current perms
1238 // We use base permissions here to avoid baking the "Locked" status 1290 // We use base permissions here to avoid baking the "Locked" status
@@ -1244,6 +1296,13 @@ namespace OpenSim.Region.Framework.Scenes
1244 agentItem.BasePermissions = perms | (uint)PermissionMask.Move; 1296 agentItem.BasePermissions = perms | (uint)PermissionMask.Move;
1245 // Newly given items cannot be "locked" on rez. Make sure by 1297 // Newly given items cannot be "locked" on rez. Make sure by
1246 // setting current equal to base. 1298 // setting current equal to base.
1299=======
1300 uint perms = taskItem.BasePermissions & taskItem.NextPermissions;
1301 PermissionsUtil.ApplyFoldedPermissions(taskItem.CurrentPermissions, ref perms);
1302// agentItem.BasePermissions = perms | (uint)PermissionMask.Move;
1303// agentItem.CurrentPermissions = agentItem.BasePermissions;
1304 agentItem.BasePermissions = perms | (uint)PermissionMask.Move;
1305>>>>>>> avn/ubitvar
1247 } 1306 }
1248 1307
1249 agentItem.CurrentPermissions = agentItem.BasePermissions; 1308 agentItem.CurrentPermissions = agentItem.BasePermissions;
@@ -1327,6 +1386,10 @@ namespace OpenSim.Region.Framework.Scenes
1327 { 1386 {
1328 SceneObjectPart part = GetSceneObjectPart(primLocalId); 1387 SceneObjectPart part = GetSceneObjectPart(primLocalId);
1329 1388
1389 // Can't move a null item
1390 if (itemId == UUID.Zero)
1391 return;
1392
1330 if (null == part) 1393 if (null == part)
1331 { 1394 {
1332 m_log.WarnFormat( 1395 m_log.WarnFormat(
@@ -1437,21 +1500,28 @@ namespace OpenSim.Region.Framework.Scenes
1437 return; 1500 return;
1438 } 1501 }
1439 1502
1440 if (part.OwnerID != destPart.OwnerID) 1503 // Can't transfer this
1504 //
1505 if (part.OwnerID != destPart.OwnerID && (srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1506 return;
1507
1508 bool overrideNoMod = false;
1509 if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0)
1510 overrideNoMod = true;
1511
1512 if (part.OwnerID != destPart.OwnerID && (destPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
1441 { 1513 {
1442 // Source must have transfer permissions 1514 // object cannot copy items to an object owned by a different owner
1443 if ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) 1515 // unless llAllowInventoryDrop has been called
1444 return;
1445 1516
1446 // Object cannot copy items to an object owned by a different owner 1517 return;
1447 // unless llAllowInventoryDrop has been called on the destination
1448 if ((destPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
1449 return;
1450 } 1518 }
1451 1519
1452 // must have both move and modify permission to put an item in an object 1520 // must have both move and modify permission to put an item in an object
1453 if ((part.OwnerMask & ((uint)PermissionMask.Move | (uint)PermissionMask.Modify)) == 0) 1521 if (((part.OwnerMask & (uint)PermissionMask.Modify) == 0) && (!overrideNoMod))
1522 {
1454 return; 1523 return;
1524 }
1455 1525
1456 TaskInventoryItem destTaskItem = new TaskInventoryItem(); 1526 TaskInventoryItem destTaskItem = new TaskInventoryItem();
1457 1527
@@ -1507,10 +1577,20 @@ namespace OpenSim.Region.Framework.Scenes
1507 1577
1508 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items) 1578 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
1509 { 1579 {
1580<<<<<<< HEAD
1510 ScenePresence avatar; 1581 ScenePresence avatar;
1511 IClientAPI remoteClient = null; 1582 IClientAPI remoteClient = null;
1512 if (TryGetScenePresence(destID, out avatar)) 1583 if (TryGetScenePresence(destID, out avatar))
1513 remoteClient = avatar.ControllingClient; 1584 remoteClient = avatar.ControllingClient;
1585=======
1586 SceneObjectPart destPart = GetSceneObjectPart(destID);
1587 if (destPart != null) // Move into a prim
1588 {
1589 foreach(UUID itemID in items)
1590 MoveTaskInventoryItem(destID, host, itemID);
1591 return destID; // Prim folder ID == prim ID
1592 }
1593>>>>>>> avn/ubitvar
1514 1594
1515 InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID); 1595 InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
1516 1596
@@ -1696,12 +1776,12 @@ namespace OpenSim.Region.Framework.Scenes
1696 AgentTransactionsModule.HandleTaskItemUpdateFromTransaction( 1776 AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
1697 remoteClient, part, transactionID, currentItem); 1777 remoteClient, part, transactionID, currentItem);
1698 1778
1699 if ((InventoryType)itemInfo.InvType == InventoryType.Notecard) 1779// if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
1700 remoteClient.SendAlertMessage("Notecard saved"); 1780// remoteClient.SendAgentAlertMessage("Notecard saved", false);
1701 else if ((InventoryType)itemInfo.InvType == InventoryType.LSL) 1781// else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
1702 remoteClient.SendAlertMessage("Script saved"); 1782// remoteClient.SendAgentAlertMessage("Script saved", false);
1703 else 1783// else
1704 remoteClient.SendAlertMessage("Item saved"); 1784// remoteClient.SendAgentAlertMessage("Item saved", false);
1705 } 1785 }
1706 1786
1707 // Base ALWAYS has move 1787 // Base ALWAYS has move
@@ -2075,23 +2155,32 @@ namespace OpenSim.Region.Framework.Scenes
2075 // build a list of eligible objects 2155 // build a list of eligible objects
2076 List<uint> deleteIDs = new List<uint>(); 2156 List<uint> deleteIDs = new List<uint>();
2077 List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>(); 2157 List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
2078 2158 List<SceneObjectGroup> takeGroups = new List<SceneObjectGroup>();
2079 // Start with true for both, then remove the flags if objects
2080 // that we can't derez are part of the selection
2081 bool permissionToTake = true;
2082 bool permissionToTakeCopy = true;
2083 bool permissionToDelete = true;
2084 2159
2085 foreach (uint localID in localIDs) 2160 foreach (uint localID in localIDs)
2086 { 2161 {
2162 // Start with true for both, then remove the flags if objects
2163 // that we can't derez are part of the selection
2164 bool permissionToTake = true;
2165 bool permissionToTakeCopy = true;
2166 bool permissionToDelete = true;
2167
2087 // Invalid id 2168 // Invalid id
2088 SceneObjectPart part = GetSceneObjectPart(localID); 2169 SceneObjectPart part = GetSceneObjectPart(localID);
2089 if (part == null) 2170 if (part == null)
2171 {
2172 //Client still thinks the object exists, kill it
2173 deleteIDs.Add(localID);
2090 continue; 2174 continue;
2175 }
2091 2176
2092 // Already deleted by someone else 2177 // Already deleted by someone else
2093 if (part.ParentGroup.IsDeleted) 2178 if (part.ParentGroup.IsDeleted)
2179 {
2180 //Client still thinks the object exists, kill it
2181 deleteIDs.Add(localID);
2094 continue; 2182 continue;
2183 }
2095 2184
2096 // Can't delete child prims 2185 // Can't delete child prims
2097 if (part != part.ParentGroup.RootPart) 2186 if (part != part.ParentGroup.RootPart)
@@ -2099,9 +2188,6 @@ namespace OpenSim.Region.Framework.Scenes
2099 2188
2100 SceneObjectGroup grp = part.ParentGroup; 2189 SceneObjectGroup grp = part.ParentGroup;
2101 2190
2102 deleteIDs.Add(localID);
2103 deleteGroups.Add(grp);
2104
2105 // If child prims have invalid perms, fix them 2191 // If child prims have invalid perms, fix them
2106 grp.AdjustChildPrimPermissions(false); 2192 grp.AdjustChildPrimPermissions(false);
2107 2193
@@ -2121,89 +2207,206 @@ namespace OpenSim.Region.Framework.Scenes
2121 } 2207 }
2122 else 2208 else
2123 { 2209 {
2124 if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId)) 2210 if (action == DeRezAction.TakeCopy)
2211 {
2212 if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId))
2213 permissionToTakeCopy = false;
2214 }
2215 else
2216 {
2125 permissionToTakeCopy = false; 2217 permissionToTakeCopy = false;
2126 2218 }
2127 if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId)) 2219 if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId))
2128 permissionToTake = false; 2220 permissionToTake = false;
2129 2221
2130 if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId)) 2222 if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId))
2131 permissionToDelete = false; 2223 permissionToDelete = false;
2132 } 2224 }
2133 }
2134
2135 // Handle god perms
2136 if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
2137 {
2138 permissionToTake = true;
2139 permissionToTakeCopy = true;
2140 permissionToDelete = true;
2141 }
2142
2143 // If we're re-saving, we don't even want to delete
2144 if (action == DeRezAction.SaveToExistingUserInventoryItem)
2145 permissionToDelete = false;
2146 2225
2147 // if we want to take a copy, we also don't want to delete 2226 // Handle god perms
2148 // Note: after this point, the permissionToTakeCopy flag 2227 if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
2149 // becomes irrelevant. It already includes the permissionToTake
2150 // permission and after excluding no copy items here, we can
2151 // just use that.
2152 if (action == DeRezAction.TakeCopy)
2153 {
2154 // If we don't have permission, stop right here
2155 if (!permissionToTakeCopy)
2156 { 2228 {
2157 remoteClient.SendAlertMessage("You don't have permission to take the object"); 2229 permissionToTake = true;
2158 return; 2230 permissionToTakeCopy = true;
2231 permissionToDelete = true;
2159 } 2232 }
2160 2233
2161 permissionToTake = true; 2234 // If we're re-saving, we don't even want to delete
2162 // Don't delete 2235 if (action == DeRezAction.SaveToExistingUserInventoryItem)
2163 permissionToDelete = false; 2236 permissionToDelete = false;
2164 }
2165 2237
2166 if (action == DeRezAction.Return) 2238 // if we want to take a copy, we also don't want to delete
2167 { 2239 // Note: after this point, the permissionToTakeCopy flag
2168 if (remoteClient != null) 2240 // becomes irrelevant. It already includes the permissionToTake
2241 // permission and after excluding no copy items here, we can
2242 // just use that.
2243 if (action == DeRezAction.TakeCopy)
2169 { 2244 {
2170 if (Permissions.CanReturnObjects( 2245 // If we don't have permission, stop right here
2171 null, 2246 if (!permissionToTakeCopy)
2172 remoteClient.AgentId,
2173 deleteGroups))
2174 { 2247 {
2175 permissionToTake = true; 2248 remoteClient.SendAlertMessage("You don't have permission to take the object");
2176 permissionToDelete = true; 2249 return;
2250 }
2251
2252 permissionToTake = true;
2253 // Don't delete
2254 permissionToDelete = false;
2255 }
2177 2256
2178 foreach (SceneObjectGroup g in deleteGroups) 2257 if (action == DeRezAction.Return)
2258 {
2259 if (remoteClient != null)
2260 {
2261 if (Permissions.CanReturnObjects(
2262 null,
2263 remoteClient.AgentId,
2264 new List<SceneObjectGroup>() {grp}))
2179 { 2265 {
2180 AddReturn(g.OwnerID == g.GroupID ? g.LastOwnerID : g.OwnerID, g.Name, g.AbsolutePosition, "parcel owner return"); 2266 permissionToTake = true;
2267 permissionToDelete = true;
2268
2269 AddReturn(grp.OwnerID == grp.GroupID ? grp.LastOwnerID : grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
2181 } 2270 }
2182 } 2271 }
2272 else // Auto return passes through here with null agent
2273 {
2274 permissionToTake = true;
2275 permissionToDelete = true;
2276 }
2183 } 2277 }
2184 else // Auto return passes through here with null agent 2278
2279 if (permissionToTake && (!permissionToDelete))
2280 takeGroups.Add(grp);
2281
2282 if (permissionToDelete)
2185 { 2283 {
2186 permissionToTake = true; 2284 if (permissionToTake)
2187 permissionToDelete = true; 2285 deleteGroups.Add(grp);
2286 deleteIDs.Add(grp.LocalId);
2188 } 2287 }
2189 } 2288 }
2190 2289
2290<<<<<<< HEAD
2191 // OK, we're done with permissions. Let's check if any part of the code prevents the objects from being deleted 2291 // OK, we're done with permissions. Let's check if any part of the code prevents the objects from being deleted
2192 bool canDelete = EventManager.TriggerDeRezRequested(remoteClient, deleteGroups, action); 2292 bool canDelete = EventManager.TriggerDeRezRequested(remoteClient, deleteGroups, action);
2193 2293
2194 if (permissionToTake && (action != DeRezAction.Delete || this.m_useTrashOnDelete)) 2294 if (permissionToTake && (action != DeRezAction.Delete || this.m_useTrashOnDelete))
2295=======
2296 SendKillObject(deleteIDs);
2297
2298 if (deleteGroups.Count > 0)
2299>>>>>>> avn/ubitvar
2195 { 2300 {
2301 foreach (SceneObjectGroup g in deleteGroups)
2302 deleteIDs.Remove(g.LocalId);
2303
2196 m_asyncSceneObjectDeleter.DeleteToInventory( 2304 m_asyncSceneObjectDeleter.DeleteToInventory(
2197 action, destinationID, deleteGroups, remoteClient, 2305 action, destinationID, deleteGroups, remoteClient,
2306<<<<<<< HEAD
2198 permissionToDelete && canDelete); 2307 permissionToDelete && canDelete);
2199 } 2308 }
2200 else if (permissionToDelete && canDelete) 2309 else if (permissionToDelete && canDelete)
2310=======
2311 true);
2312 }
2313 if (takeGroups.Count > 0)
2314 {
2315 m_asyncSceneObjectDeleter.DeleteToInventory(
2316 action, destinationID, takeGroups, remoteClient,
2317 false);
2318 }
2319 if (deleteIDs.Count > 0)
2320>>>>>>> avn/ubitvar
2201 { 2321 {
2202 foreach (SceneObjectGroup g in deleteGroups) 2322 foreach (SceneObjectGroup g in deleteGroups)
2203 DeleteSceneObject(g, false); 2323 DeleteSceneObject(g, true);
2204 } 2324 }
2205 } 2325 }
2206 2326
2327 public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
2328 {
2329 itemID = UUID.Zero;
2330 if (grp != null)
2331 {
2332 Vector3 inventoryStoredPosition = new Vector3(
2333 Math.Min(grp.AbsolutePosition.X, RegionInfo.RegionSizeX - 6),
2334 Math.Min(grp.AbsolutePosition.Y, RegionInfo.RegionSizeY - 6),
2335 grp.AbsolutePosition.Z);
2336
2337 Vector3 originalPosition = grp.AbsolutePosition;
2338
2339 grp.AbsolutePosition = inventoryStoredPosition;
2340
2341 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
2342
2343 grp.AbsolutePosition = originalPosition;
2344
2345 AssetBase asset = CreateAsset(
2346 grp.GetPartName(grp.LocalId),
2347 grp.GetPartDescription(grp.LocalId),
2348 (sbyte)AssetType.Object,
2349 Utils.StringToBytes(sceneObjectXml),
2350 remoteClient.AgentId);
2351 AssetService.Store(asset);
2352
2353 InventoryItemBase item = new InventoryItemBase();
2354 item.CreatorId = grp.RootPart.CreatorID.ToString();
2355 item.CreatorData = grp.RootPart.CreatorData;
2356 item.Owner = remoteClient.AgentId;
2357 item.ID = UUID.Random();
2358 item.AssetID = asset.FullID;
2359 item.Description = asset.Description;
2360 item.Name = asset.Name;
2361 item.AssetType = asset.Type;
2362 item.InvType = (int)InventoryType.Object;
2363
2364 InventoryFolderBase folder = InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.Object);
2365 if (folder != null)
2366 item.Folder = folder.ID;
2367 else // oopsies
2368 item.Folder = UUID.Zero;
2369
2370 // Set up base perms properly
2371 uint permsBase = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify);
2372 permsBase &= grp.RootPart.BaseMask;
2373 permsBase |= (uint)PermissionMask.Move;
2374
2375 // Make sure we don't lock it
2376 grp.RootPart.NextOwnerMask |= (uint)PermissionMask.Move;
2377
2378 if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
2379 {
2380 item.BasePermissions = permsBase & grp.RootPart.NextOwnerMask;
2381 item.CurrentPermissions = permsBase & grp.RootPart.NextOwnerMask;
2382 item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
2383 item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
2384 item.GroupPermissions = permsBase & grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
2385 }
2386 else
2387 {
2388 item.BasePermissions = permsBase;
2389 item.CurrentPermissions = permsBase & grp.RootPart.OwnerMask;
2390 item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
2391 item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask;
2392 item.GroupPermissions = permsBase & grp.RootPart.GroupMask;
2393 }
2394 item.CreationDate = Util.UnixTimeSinceEpoch();
2395
2396 // sets itemID so client can show item as 'attached' in inventory
2397 grp.FromItemID = item.ID;
2398
2399 if (AddInventoryItem(item))
2400 remoteClient.SendInventoryItemCreateUpdate(item, 0);
2401 else
2402 m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
2403
2404 itemID = item.ID;
2405 return item.AssetID;
2406 }
2407 return UUID.Zero;
2408 }
2409
2207 /// <summary> 2410 /// <summary>
2208 /// Returns the list of Scene Objects in an asset. 2411 /// Returns the list of Scene Objects in an asset.
2209 /// </summary> 2412 /// </summary>
@@ -2232,10 +2435,34 @@ namespace OpenSim.Region.Framework.Scenes
2232 2435
2233 string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(assetData)); 2436 string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(assetData));
2234 2437
2438<<<<<<< HEAD
2235 try 2439 try
2440=======
2441 if (e == null || attachment) // Single
2442 {
2443 SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
2444/*
2445 if (!attachment)
2446 {
2447 g.RootPart.AttachPoint = g.RootPart.Shape.State;
2448 g.RootPart.AttachedPos = g.AbsolutePosition;
2449 g.RootPart.AttachRotation = g.GroupRotation;
2450 if (g.RootPart.Shape.PCode != (byte)PCode.NewTree &&
2451 g.RootPart.Shape.PCode != (byte)PCode.Tree)
2452 g.RootPart.Shape.State = 0;
2453 }
2454*/
2455 objlist.Add(g);
2456 veclist.Add(new Vector3(0, 0, 0));
2457 bbox = g.GetAxisAlignedBoundingBox(out offsetHeight);
2458 return true;
2459 }
2460 else
2461>>>>>>> avn/ubitvar
2236 { 2462 {
2237 using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) 2463 using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
2238 { 2464 {
2465<<<<<<< HEAD
2239 using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) 2466 using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment }))
2240 { 2467 {
2241 reader.Read(); 2468 reader.Read();
@@ -2299,6 +2526,28 @@ namespace OpenSim.Region.Framework.Scenes
2299 return false; 2526 return false;
2300 } 2527 }
2301 } 2528 }
2529=======
2530 SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
2531/*
2532 g.RootPart.AttachPoint = g.RootPart.Shape.State;
2533 g.RootPart.AttachedPos = g.AbsolutePosition;
2534 g.RootPart.AttachRotation = g.GroupRotation;
2535 if (g.RootPart.Shape.PCode != (byte)PCode.NewTree &&
2536 g.RootPart.Shape.PCode != (byte)PCode.Tree)
2537 g.RootPart.Shape.State = 0;
2538*/
2539 objlist.Add(g);
2540
2541 XmlElement el = (XmlElement)n;
2542 string rawX = el.GetAttribute("offsetx");
2543 string rawY = el.GetAttribute("offsety");
2544 string rawZ = el.GetAttribute("offsetz");
2545
2546 float x = Convert.ToSingle(rawX);
2547 float y = Convert.ToSingle(rawY);
2548 float z = Convert.ToSingle(rawZ);
2549 veclist.Add(new Vector3(x, y, z));
2550>>>>>>> avn/ubitvar
2302 } 2551 }
2303 } 2552 }
2304 catch (Exception e) 2553 catch (Exception e)
@@ -2371,7 +2620,7 @@ namespace OpenSim.Region.Framework.Scenes
2371 RayStart, RayEnd, RayTargetID, Quaternion.Identity, 2620 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2372 BypassRayCast, bRayEndIsIntersection, true, scale, false); 2621 BypassRayCast, bRayEndIsIntersection, true, scale, false);
2373 2622
2374 RezObject(part, item, pos, null, Vector3.Zero, 0); 2623 RezObject(part, item, pos, null, Vector3.Zero, 0, false);
2375 } 2624 }
2376 } 2625 }
2377 2626
@@ -2387,15 +2636,18 @@ namespace OpenSim.Region.Framework.Scenes
2387 /// <param name="param"></param> 2636 /// <param name="param"></param>
2388 /// <returns>The SceneObjectGroup(s) rezzed, or null if rez was unsuccessful</returns> 2637 /// <returns>The SceneObjectGroup(s) rezzed, or null if rez was unsuccessful</returns>
2389 public virtual List<SceneObjectGroup> RezObject( 2638 public virtual List<SceneObjectGroup> RezObject(
2390 SceneObjectPart sourcePart, TaskInventoryItem item, Vector3 pos, Quaternion? rot, Vector3 vel, int param) 2639 SceneObjectPart sourcePart, TaskInventoryItem item, Vector3 pos, Quaternion? rot, Vector3 vel, int param, bool atRoot)
2391 { 2640 {
2392 if (null == item) 2641 if (null == item)
2393 return null; 2642 return null;
2394 2643
2395 List<SceneObjectGroup> objlist; 2644 List<SceneObjectGroup> objlist;
2396 List<Vector3> veclist; 2645 List<Vector3> veclist;
2397 2646 Vector3 bbox;
2398 bool success = sourcePart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist); 2647 float offsetHeight;
2648
2649 bool success = sourcePart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist,out bbox, out offsetHeight);
2650
2399 if (!success) 2651 if (!success)
2400 return null; 2652 return null;
2401 2653
@@ -2412,10 +2664,69 @@ namespace OpenSim.Region.Framework.Scenes
2412 sourcePart.Inventory.RemoveInventoryItem(item.ItemID); 2664 sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
2413 } 2665 }
2414 2666
2667 SceneObjectGroup sog;
2668
2669 bool fixrot = false;
2670 Quaternion netRot = Quaternion.Identity;
2671
2672 // position adjust
2673 if (totalPrims > 1) // nothing to do on a single prim
2674 {
2675 if (objlist.Count == 1)
2676 {
2677 // current object position is root position
2678 if(!atRoot)
2679 {
2680 sog = objlist[0];
2681 Quaternion orot;
2682 if (rot == null)
2683 orot = sog.RootPart.GetWorldRotation();
2684 else
2685 orot = rot.Value;
2686 // possible should be bbox, but geometric center looks better
2687 Vector3 off = sog.GetGeometricCenter();
2688// Vector3 off = bbox * 0.5f;
2689 off *= orot;
2690 pos -= off;
2691 }
2692 }
2693 else
2694 {
2695 //veclist[] are relative to bbox corner with min X,Y and Z
2696 // rez at root, and rot will be referenced to first object in list
2697 if (rot == null)
2698 {
2699 // use original rotations
2700 if (atRoot)
2701 pos -= veclist[0];
2702 else
2703 pos -= bbox / 2;
2704 }
2705 else
2706 {
2707 fixrot = true;
2708 sog = objlist[0];
2709 netRot = Quaternion.Conjugate(sog.RootPart.GetWorldRotation());
2710 netRot = netRot * rot.Value;
2711 Vector3 off;
2712 if (atRoot)
2713 off = veclist[0];
2714 else
2715 off = bbox / 2;
2716 off *= netRot;
2717 pos -= off;
2718 }
2719 }
2720 }
2721
2415 for (int i = 0; i < objlist.Count; i++) 2722 for (int i = 0; i < objlist.Count; i++)
2416 { 2723 {
2417 SceneObjectGroup group = objlist[i]; 2724 SceneObjectGroup group = objlist[i];
2418 Vector3 curpos = pos + veclist[i]; 2725 Vector3 curpos;
2726 if(fixrot)
2727 curpos = pos + veclist[i] * netRot;
2728 else
2729 curpos = pos + veclist[i];
2419 2730
2420 if (group.IsAttachment == false && group.RootPart.Shape.State != 0) 2731 if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
2421 { 2732 {
@@ -2424,7 +2735,17 @@ namespace OpenSim.Region.Framework.Scenes
2424 } 2735 }
2425 2736
2426 group.FromPartID = sourcePart.UUID; 2737 group.FromPartID = sourcePart.UUID;
2427 AddNewSceneObject(group, true, curpos, rot, vel); 2738 if( i == 0)
2739 AddNewSceneObject(group, true, curpos, rot, vel);
2740 else
2741 {
2742 Quaternion crot = objlist[i].RootPart.GetWorldRotation();
2743 if (fixrot)
2744 {
2745 crot *= netRot;
2746 }
2747 AddNewSceneObject(group, true, curpos, crot, vel);
2748 }
2428 2749
2429 // We can only call this after adding the scene object, since the scene object references the scene 2750 // We can only call this after adding the scene object, since the scene object references the scene
2430 // to find out if scripts should be activated at all. 2751 // to find out if scripts should be activated at all.
@@ -2455,6 +2776,9 @@ namespace OpenSim.Region.Framework.Scenes
2455 2776
2456 public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running) 2777 public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
2457 { 2778 {
2779 if (!Permissions.CanEditScript(itemID, objectID, controllingClient.AgentId))
2780 return;
2781
2458 SceneObjectPart part = GetSceneObjectPart(objectID); 2782 SceneObjectPart part = GetSceneObjectPart(objectID);
2459 if (part == null) 2783 if (part == null)
2460 return; 2784 return;
@@ -2511,7 +2835,10 @@ namespace OpenSim.Region.Framework.Scenes
2511 } 2835 }
2512 else 2836 else
2513 { 2837 {
2514 if (!Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)) 2838 if (!Permissions.IsGod(remoteClient.AgentId) && sog.OwnerID != remoteClient.AgentId)
2839 continue;
2840
2841 if (!Permissions.CanTransferObject(sog.UUID, groupID))
2515 continue; 2842 continue;
2516 2843
2517 if (sog.GroupID != groupID) 2844 if (sog.GroupID != groupID)
@@ -2622,7 +2949,18 @@ namespace OpenSim.Region.Framework.Scenes
2622 return; 2949 return;
2623 } 2950 }
2624 2951
2952 bool oldUsePhysics = (root.Flags & PrimFlags.Physics) != 0;
2625 m_sceneGraph.LinkObjects(root, children); 2953 m_sceneGraph.LinkObjects(root, children);
2954
2955 ScenePresence sp;
2956 if (TryGetScenePresence(agentId, out sp))
2957 {
2958 root.SendPropertiesToClient(sp.ControllingClient);
2959 if (oldUsePhysics && (root.Flags & PrimFlags.Physics) == 0)
2960 {
2961 sp.ControllingClient.SendAlertMessage("Object physics canceled");
2962 }
2963 }
2626 } 2964 }
2627 2965
2628 private string PermissionString(uint permissions) 2966 private string PermissionString(uint permissions)
diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
index ef2125b..3d9c028 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Scenes
50 /// <param name='targetID'></param> 50 /// <param name='targetID'></param>
51 /// <param name='fromAgent'></param> 51 /// <param name='fromAgent'></param>
52 /// <param name='broadcast'></param> 52 /// <param name='broadcast'></param>
53 protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName, 53 public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
54 UUID fromID, UUID targetID, bool fromAgent, bool broadcast) 54 UUID fromID, UUID targetID, bool fromAgent, bool broadcast)
55 { 55 {
56 OSChatMessage args = new OSChatMessage(); 56 OSChatMessage args = new OSChatMessage();
@@ -61,6 +61,7 @@ namespace OpenSim.Region.Framework.Scenes
61 args.Position = fromPos; 61 args.Position = fromPos;
62 args.SenderUUID = fromID; 62 args.SenderUUID = fromID;
63 args.Scene = this; 63 args.Scene = this;
64 args.Destination = targetID;
64 65
65 if (fromAgent) 66 if (fromAgent)
66 { 67 {
@@ -75,7 +76,7 @@ namespace OpenSim.Region.Framework.Scenes
75 } 76 }
76 77
77 args.From = fromName; 78 args.From = fromName;
78 args.TargetUUID = targetID; 79 //args.
79 80
80// m_log.DebugFormat( 81// m_log.DebugFormat(
81// "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}", 82// "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}",
@@ -86,7 +87,7 @@ namespace OpenSim.Region.Framework.Scenes
86 else 87 else
87 EventManager.TriggerOnChatFromWorld(this, args); 88 EventManager.TriggerOnChatFromWorld(this, args);
88 } 89 }
89 90
90 protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName, 91 protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
91 UUID fromID, bool fromAgent, bool broadcast) 92 UUID fromID, bool fromAgent, bool broadcast)
92 { 93 {
@@ -130,19 +131,6 @@ namespace OpenSim.Region.Framework.Scenes
130 { 131 {
131 SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true); 132 SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
132 } 133 }
133 /// <summary>
134 ///
135 /// </summary>
136 /// <param name="message"></param>
137 /// <param name="type"></param>
138 /// <param name="fromPos"></param>
139 /// <param name="fromName"></param>
140 /// <param name="fromAgentID"></param>
141 /// <param name="targetID"></param>
142 public void SimChatToAgent(UUID targetID, byte[] message, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
143 {
144 SimChat(message, ChatTypeEnum.Say, 0, fromPos, fromName, fromID, targetID, fromAgent, false);
145 }
146 134
147 /// <summary> 135 /// <summary>
148 /// 136 ///
@@ -179,27 +167,47 @@ namespace OpenSim.Region.Framework.Scenes
179 /// <param name="remoteClient"></param> 167 /// <param name="remoteClient"></param>
180 public void SelectPrim(uint primLocalID, IClientAPI remoteClient) 168 public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
181 { 169 {
170 /*
171 SceneObjectPart part = GetSceneObjectPart(primLocalID);
172
173 if (null == part)
174 return;
175
176 if (part.IsRoot)
177 {
178 SceneObjectGroup sog = part.ParentGroup;
179 sog.SendPropertiesToClient(remoteClient);
180
181 // A prim is only tainted if it's allowed to be edited by the person clicking it.
182 if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)
183 || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId))
184 {
185 sog.IsSelected = true;
186 EventManager.TriggerParcelPrimCountTainted();
187 }
188 }
189 else
190 {
191 part.SendPropertiesToClient(remoteClient);
192 }
193 */
182 SceneObjectPart part = GetSceneObjectPart(primLocalID); 194 SceneObjectPart part = GetSceneObjectPart(primLocalID);
183 195
184 if (null == part) 196 if (null == part)
185 return; 197 return;
186 198
187 if (part.IsRoot) 199 SceneObjectGroup sog = part.ParentGroup;
188 { 200 if (sog == null)
189 SceneObjectGroup sog = part.ParentGroup; 201 return;
190 sog.SendPropertiesToClient(remoteClient);
191 sog.IsSelected = true;
192 202
193 // A prim is only tainted if it's allowed to be edited by the person clicking it. 203 part.SendPropertiesToClient(remoteClient);
194 if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId) 204
195 || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId)) 205 // A prim is only tainted if it's allowed to be edited by the person clicking it.
196 { 206 if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)
197 EventManager.TriggerParcelPrimCountTainted(); 207 || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId))
198 }
199 }
200 else
201 { 208 {
202 part.SendPropertiesToClient(remoteClient); 209 part.IsSelected = true;
210 EventManager.TriggerParcelPrimCountTainted();
203 } 211 }
204 } 212 }
205 213
@@ -252,7 +260,7 @@ namespace OpenSim.Region.Framework.Scenes
252 SceneObjectPart part = GetSceneObjectPart(primLocalID); 260 SceneObjectPart part = GetSceneObjectPart(primLocalID);
253 if (part == null) 261 if (part == null)
254 return; 262 return;
255 263 /*
256 // A deselect packet contains all the local prims being deselected. However, since selection is still 264 // A deselect packet contains all the local prims being deselected. However, since selection is still
257 // group based we only want the root prim to trigger a full update - otherwise on objects with many prims 265 // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
258 // we end up sending many duplicate ObjectUpdates 266 // we end up sending many duplicate ObjectUpdates
@@ -263,7 +271,9 @@ namespace OpenSim.Region.Framework.Scenes
263 // handled by group, but by prim. Legacy cruft. 271 // handled by group, but by prim. Legacy cruft.
264 // TODO: Make selection flagging per prim! 272 // TODO: Make selection flagging per prim!
265 // 273 //
266 part.ParentGroup.IsSelected = false; 274 if (Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId)
275 || Permissions.CanMoveObject(part.ParentGroup.UUID, remoteClient.AgentId))
276 part.ParentGroup.IsSelected = false;
267 277
268 part.ParentGroup.ScheduleGroupForFullUpdate(); 278 part.ParentGroup.ScheduleGroupForFullUpdate();
269 279
@@ -280,6 +290,26 @@ namespace OpenSim.Region.Framework.Scenes
280 part.UUID, remoteClient.AgentId)) 290 part.UUID, remoteClient.AgentId))
281 EventManager.TriggerParcelPrimCountTainted(); 291 EventManager.TriggerParcelPrimCountTainted();
282 } 292 }
293 */
294
295 bool oldgprSelect = part.ParentGroup.IsSelected;
296
297 // This is wrong, wrong, wrong. Selection should not be
298 // handled by group, but by prim. Legacy cruft.
299 // TODO: Make selection flagging per prim!
300 //
301 if (Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId)
302 || Permissions.CanMoveObject(part.ParentGroup.UUID, remoteClient.AgentId))
303 {
304 part.IsSelected = false;
305 if (!part.ParentGroup.IsAttachment && oldgprSelect != part.ParentGroup.IsSelected)
306 EventManager.TriggerParcelPrimCountTainted();
307 }
308
309 // restore targetOmega
310 if (part.AngularVelocity != Vector3.Zero)
311 part.ScheduleTerseUpdate();
312
283 } 313 }
284 314
285 public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount, 315 public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
@@ -434,12 +464,26 @@ namespace OpenSim.Region.Framework.Scenes
434 } 464 }
435 }); 465 });
436 } 466 }
437 467
438 private bool ShouldSendDiscardableEffect(IClientAPI thisClient, ScenePresence other) 468 private bool ShouldSendDiscardableEffect(IClientAPI thisClient, ScenePresence other)
439 { 469 {
440 return Vector3.Distance(other.CameraPosition, thisClient.SceneAgent.AbsolutePosition) < 10; 470 return Vector3.Distance(other.CameraPosition, thisClient.SceneAgent.AbsolutePosition) < 10;
441 } 471 }
442 472
473 private class DescendentsRequestData
474 {
475 public IClientAPI RemoteClient;
476 public UUID FolderID;
477 public UUID OwnerID;
478 public bool FetchFolders;
479 public bool FetchItems;
480 public int SortOrder;
481 }
482
483 private Queue<DescendentsRequestData> m_descendentsRequestQueue = new Queue<DescendentsRequestData>();
484 private Object m_descendentsRequestLock = new Object();
485 private bool m_descendentsRequestProcessing = false;
486
443 /// <summary> 487 /// <summary>
444 /// Tell the client about the various child items and folders contained in the requested folder. 488 /// Tell the client about the various child items and folders contained in the requested folder.
445 /// </summary> 489 /// </summary>
@@ -476,17 +520,38 @@ namespace OpenSim.Region.Framework.Scenes
476 } 520 }
477 } 521 }
478 522
479 // We're going to send the reply async, because there may be 523 lock (m_descendentsRequestLock)
480 // an enormous quantity of packets -- basically the entire inventory! 524 {
481 // We don't want to block the client thread while all that is happening. 525 if (!m_descendentsRequestProcessing)
482 SendInventoryDelegate d = SendInventoryAsync; 526 {
483 d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d); 527 m_descendentsRequestProcessing = true;
528
529 // We're going to send the reply async, because there may be
530 // an enormous quantity of packets -- basically the entire inventory!
531 // We don't want to block the client thread while all that is happening.
532 SendInventoryDelegate d = SendInventoryAsync;
533 d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
534
535 return;
536 }
537
538 DescendentsRequestData req = new DescendentsRequestData();
539 req.RemoteClient = remoteClient;
540 req.FolderID = folderID;
541 req.OwnerID = ownerID;
542 req.FetchFolders = fetchFolders;
543 req.FetchItems = fetchItems;
544 req.SortOrder = sortOrder;
545
546 m_descendentsRequestQueue.Enqueue(req);
547 }
484 } 548 }
485 549
486 delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder); 550 delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
487 551
488 void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder) 552 void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
489 { 553 {
554<<<<<<< HEAD
490 try 555 try
491 { 556 {
492 SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems); 557 SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
@@ -497,12 +562,31 @@ namespace OpenSim.Region.Framework.Scenes
497 string.Format( 562 string.Format(
498 "[AGENT INVENTORY]: Error in SendInventoryAsync() for {0} with folder ID {1}. Exception ", e)); 563 "[AGENT INVENTORY]: Error in SendInventoryAsync() for {0} with folder ID {1}. Exception ", e));
499 } 564 }
565=======
566 Thread.Sleep(20);
567 SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
568>>>>>>> avn/ubitvar
500 } 569 }
501 570
502 void SendInventoryComplete(IAsyncResult iar) 571 void SendInventoryComplete(IAsyncResult iar)
503 { 572 {
504 SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState; 573 SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
505 d.EndInvoke(iar); 574 d.EndInvoke(iar);
575
576 lock (m_descendentsRequestLock)
577 {
578 if (m_descendentsRequestQueue.Count > 0)
579 {
580 DescendentsRequestData req = m_descendentsRequestQueue.Dequeue();
581
582 d = SendInventoryAsync;
583 d.BeginInvoke(req.RemoteClient, req.FolderID, req.OwnerID, req.FetchFolders, req.FetchItems, req.SortOrder, SendInventoryComplete, d);
584
585 return;
586 }
587
588 m_descendentsRequestProcessing = false;
589 }
506 } 590 }
507 591
508 /// <summary> 592 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index 535d87a..4d90726 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -70,7 +70,7 @@ namespace OpenSim.Region.Framework.Scenes
70 public delegate bool IsGridGodHandler(UUID user, Scene requestFromScene); 70 public delegate bool IsGridGodHandler(UUID user, Scene requestFromScene);
71 public delegate bool IsAdministratorHandler(UUID user); 71 public delegate bool IsAdministratorHandler(UUID user);
72 public delegate bool EditParcelHandler(UUID user, ILandObject parcel, Scene scene); 72 public delegate bool EditParcelHandler(UUID user, ILandObject parcel, Scene scene);
73 public delegate bool EditParcelPropertiesHandler(UUID user, ILandObject parcel, GroupPowers p, Scene scene); 73 public delegate bool EditParcelPropertiesHandler(UUID user, ILandObject parcel, GroupPowers p, Scene scene, bool allowManager);
74 public delegate bool SellParcelHandler(UUID user, ILandObject parcel, Scene scene); 74 public delegate bool SellParcelHandler(UUID user, ILandObject parcel, Scene scene);
75 public delegate bool AbandonParcelHandler(UUID user, ILandObject parcel, Scene scene); 75 public delegate bool AbandonParcelHandler(UUID user, ILandObject parcel, Scene scene);
76 public delegate bool ReclaimParcelHandler(UUID user, ILandObject parcel, Scene scene); 76 public delegate bool ReclaimParcelHandler(UUID user, ILandObject parcel, Scene scene);
@@ -763,7 +763,7 @@ namespace OpenSim.Region.Framework.Scenes
763 763
764 #region EDIT PARCEL 764 #region EDIT PARCEL
765 765
766 public bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p) 766 public bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p, bool allowManager)
767 { 767 {
768 EditParcelPropertiesHandler handler = OnEditParcelProperties; 768 EditParcelPropertiesHandler handler = OnEditParcelProperties;
769 if (handler != null) 769 if (handler != null)
@@ -771,7 +771,7 @@ namespace OpenSim.Region.Framework.Scenes
771 Delegate[] list = handler.GetInvocationList(); 771 Delegate[] list = handler.GetInvocationList();
772 foreach (EditParcelPropertiesHandler h in list) 772 foreach (EditParcelPropertiesHandler h in list)
773 { 773 {
774 if (h(user, parcel, p, m_scene) == false) 774 if (h(user, parcel, p, m_scene, allowManager) == false)
775 return false; 775 return false;
776 } 776 }
777 } 777 }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index fe99ae5..deb8d39 100755
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -105,9 +105,15 @@ namespace OpenSim.Region.Framework.Scenes
105 /// <summary> 105 /// <summary>
106 /// If false then physical objects are disabled, though collisions will continue as normal. 106 /// If false then physical objects are disabled, though collisions will continue as normal.
107 /// </summary> 107 /// </summary>
108<<<<<<< HEAD
108 public bool PhysicsEnabled 109 public bool PhysicsEnabled
109 { 110 {
110 get 111 get
112=======
113 public bool PhysicsEnabled
114 {
115 get
116>>>>>>> avn/ubitvar
111 { 117 {
112 return m_physicsEnabled; 118 return m_physicsEnabled;
113 } 119 }
@@ -228,9 +234,16 @@ namespace OpenSim.Region.Framework.Scenes
228 public bool m_allowScriptCrossings = true; 234 public bool m_allowScriptCrossings = true;
229 235
230 /// <summary> 236 /// <summary>
237<<<<<<< HEAD
231 /// Can avatars cross from and to this region? 238 /// Can avatars cross from and to this region?
232 /// </summary> 239 /// </summary>
233 public bool AllowAvatarCrossing { get; set; } 240 public bool AllowAvatarCrossing { get; set; }
241=======
242 /// Max prims an Physical object will hold
243 /// </summary>
244 ///
245 public int m_linksetPhysCapacity = 0;
246>>>>>>> avn/ubitvar
234 247
235 public bool m_useFlySlow; 248 public bool m_useFlySlow;
236 public bool m_useTrashOnDelete = true; 249 public bool m_useTrashOnDelete = true;
@@ -281,14 +294,21 @@ namespace OpenSim.Region.Framework.Scenes
281 } 294 }
282 } 295 }
283 296
297 protected float m_maxDrawDistance = 512.0f;
298// protected float m_maxDrawDistance = 256.0f;
299 public float MaxDrawDistance
300 {
301 get { return m_maxDrawDistance; }
302 }
303
284 private List<string> m_AllowedViewers = new List<string>(); 304 private List<string> m_AllowedViewers = new List<string>();
285 private List<string> m_BannedViewers = new List<string>(); 305 private List<string> m_BannedViewers = new List<string>();
286 306
287 // TODO: need to figure out how allow client agents but deny 307 // TODO: need to figure out how allow client agents but deny
288 // root agents when ACL denies access to root agent 308 // root agents when ACL denies access to root agent
289 public bool m_strictAccessControl = true; 309 public bool m_strictAccessControl = true;
290 310 public bool m_seeIntoBannedRegion = false;
291 public int MaxUndoCount { get; set; } 311 public int MaxUndoCount = 5;
292 312
293 public bool SeeIntoRegion { get; set; } 313 public bool SeeIntoRegion { get; set; }
294 314
@@ -306,11 +326,13 @@ namespace OpenSim.Region.Framework.Scenes
306 326
307 protected int m_splitRegionID; 327 protected int m_splitRegionID;
308 protected Timer m_restartWaitTimer = new Timer(); 328 protected Timer m_restartWaitTimer = new Timer();
329 protected Timer m_timerWatchdog = new Timer();
309 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 330 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
310 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 331 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
311 protected string m_simulatorVersion = "OpenSimulator Server"; 332 protected string m_simulatorVersion = "OpenSimulator Server";
312 protected AgentCircuitManager m_authenticateHandler; 333 protected AgentCircuitManager m_authenticateHandler;
313 protected SceneCommunicationService m_sceneGridService; 334 protected SceneCommunicationService m_sceneGridService;
335 protected ISnmpModule m_snmpService = null;
314 336
315 protected ISimulationDataService m_SimulationDataService; 337 protected ISimulationDataService m_SimulationDataService;
316 protected IEstateDataService m_EstateDataService; 338 protected IEstateDataService m_EstateDataService;
@@ -406,8 +428,13 @@ namespace OpenSim.Region.Framework.Scenes
406 private int m_update_presences = 1; // Update scene presence movements 428 private int m_update_presences = 1; // Update scene presence movements
407 private int m_update_events = 1; 429 private int m_update_events = 1;
408 private int m_update_backup = 200; 430 private int m_update_backup = 200;
431<<<<<<< HEAD
409 private int m_update_terrain = 50; 432 private int m_update_terrain = 50;
410 // private int m_update_land = 1; 433 // private int m_update_land = 1;
434=======
435 private int m_update_terrain = 1000;
436 private int m_update_land = 10;
437>>>>>>> avn/ubitvar
411 private int m_update_coarse_locations = 50; 438 private int m_update_coarse_locations = 50;
412 private int m_update_temp_cleaning = 180; 439 private int m_update_temp_cleaning = 180;
413 440
@@ -421,7 +448,6 @@ namespace OpenSim.Region.Framework.Scenes
421 private int backupMS; 448 private int backupMS;
422 private int terrainMS; 449 private int terrainMS;
423 private int landMS; 450 private int landMS;
424 private int spareMS;
425 451
426 // A temporary configuration flag to enable using FireAndForget to process 452 // A temporary configuration flag to enable using FireAndForget to process
427 // collisions from the physics engine. There is a problem with collisions 453 // collisions from the physics engine. There is a problem with collisions
@@ -439,6 +465,7 @@ namespace OpenSim.Region.Framework.Scenes
439 /// </summary> 465 /// </summary>
440 private int m_lastFrameTick; 466 private int m_lastFrameTick;
441 467
468 public bool CombineRegions = false;
442 /// <summary> 469 /// <summary>
443 /// Tick at which the last maintenance run occurred. 470 /// Tick at which the last maintenance run occurred.
444 /// </summary> 471 /// </summary>
@@ -470,7 +497,7 @@ namespace OpenSim.Region.Framework.Scenes
470 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing 497 private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing
471 private volatile bool m_backingup; 498 private volatile bool m_backingup;
472 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); 499 private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>();
473 private Dictionary<UUID, SceneObjectGroup> m_groupsWithTargets = new Dictionary<UUID, SceneObjectGroup>(); 500 private Dictionary<UUID, int> m_groupsWithTargets = new Dictionary<UUID, int>();
474 501
475 private string m_defaultScriptEngine; 502 private string m_defaultScriptEngine;
476 503
@@ -485,6 +512,11 @@ namespace OpenSim.Region.Framework.Scenes
485 /// </summary> 512 /// </summary>
486 private int m_LastLogin; 513 private int m_LastLogin;
487 514
515 private int m_lastIncoming;
516 private int m_lastOutgoing;
517 private int m_hbRestarts = 0;
518
519
488 /// <summary> 520 /// <summary>
489 /// Thread that runs the scene loop. 521 /// Thread that runs the scene loop.
490 /// </summary> 522 /// </summary>
@@ -527,11 +559,22 @@ namespace OpenSim.Region.Framework.Scenes
527 } 559 }
528 private volatile bool m_active; 560 private volatile bool m_active;
529 561
562<<<<<<< HEAD
530 /// <summary> 563 /// <summary>
531 /// If true then updates are running. This may be true for a short period after a scene is de-activated. 564 /// If true then updates are running. This may be true for a short period after a scene is de-activated.
532 /// </summary> 565 /// </summary>
533 public bool IsRunning { get { return m_isRunning; } } 566 public bool IsRunning { get { return m_isRunning; } }
534 private volatile bool m_isRunning; 567 private volatile bool m_isRunning;
568=======
569// private int m_lastUpdate;
570 private bool m_firstHeartbeat = true;
571
572 private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
573 private bool m_reprioritizationEnabled = true;
574 private double m_reprioritizationInterval = 5000.0;
575 private double m_rootReprioritizationDistance = 10.0;
576 private double m_childReprioritizationDistance = 20.0;
577>>>>>>> avn/ubitvar
535 578
536 private Timer m_mapGenerationTimer = new Timer(); 579 private Timer m_mapGenerationTimer = new Timer();
537 private bool m_generateMaptiles; 580 private bool m_generateMaptiles;
@@ -564,6 +607,19 @@ namespace OpenSim.Region.Framework.Scenes
564 get { return m_sceneGridService; } 607 get { return m_sceneGridService; }
565 } 608 }
566 609
610 public ISnmpModule SnmpService
611 {
612 get
613 {
614 if (m_snmpService == null)
615 {
616 m_snmpService = RequestModuleInterface<ISnmpModule>();
617 }
618
619 return m_snmpService;
620 }
621 }
622
567 public ISimulationDataService SimulationDataService 623 public ISimulationDataService SimulationDataService
568 { 624 {
569 get 625 get
@@ -868,6 +924,12 @@ namespace OpenSim.Region.Framework.Scenes
868 m_sceneGridService = sceneGridService; 924 m_sceneGridService = sceneGridService;
869 m_SimulationDataService = simDataService; 925 m_SimulationDataService = simDataService;
870 m_EstateDataService = estateDataService; 926 m_EstateDataService = estateDataService;
927<<<<<<< HEAD
928=======
929 m_regionHandle = RegionInfo.RegionHandle;
930 m_lastIncoming = 0;
931 m_lastOutgoing = 0;
932>>>>>>> avn/ubitvar
871 933
872 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); 934 m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
873 m_asyncSceneObjectDeleter.Enabled = true; 935 m_asyncSceneObjectDeleter.Enabled = true;
@@ -926,6 +988,25 @@ namespace OpenSim.Region.Framework.Scenes
926 EventManager.OnLandObjectRemoved += 988 EventManager.OnLandObjectRemoved +=
927 new EventManager.LandObjectRemoved(simDataService.RemoveLandObject); 989 new EventManager.LandObjectRemoved(simDataService.RemoveLandObject);
928 990
991<<<<<<< HEAD
992=======
993 m_sceneGraph = new SceneGraph(this);
994 m_sceneGraph.PhysicsScene = physicsScene;
995
996 // If the scene graph has an Unrecoverable error, restart this sim.
997 // Currently the only thing that causes it to happen is two kinds of specific
998 // Physics based crashes.
999 //
1000 // Out of memory
1001 // Operating system has killed the plugin
1002 m_sceneGraph.UnRecoverableError
1003 += () =>
1004 {
1005 m_log.ErrorFormat("[SCENE]: Restarting region {0} due to unrecoverable physics crash", Name);
1006 RestartNow();
1007 };
1008
1009>>>>>>> avn/ubitvar
929 RegisterDefaultSceneEvents(); 1010 RegisterDefaultSceneEvents();
930 1011
931 // XXX: Don't set the public property since we don't want to activate here. This needs to be handled 1012 // XXX: Don't set the public property since we don't want to activate here. This needs to be handled
@@ -947,6 +1028,7 @@ namespace OpenSim.Region.Framework.Scenes
947 StartDisabled = startupConfig.GetBoolean("StartDisabled", false); 1028 StartDisabled = startupConfig.GetBoolean("StartDisabled", false);
948 1029
949 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance); 1030 m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance);
1031 m_defaultDrawDistance = startupConfig.GetFloat("MaxDrawDistance", m_maxDrawDistance);
950 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup); 1032 UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup);
951 if (!UseBackup) 1033 if (!UseBackup)
952 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); 1034 m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName);
@@ -958,9 +1040,8 @@ namespace OpenSim.Region.Framework.Scenes
958 1040
959 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20); 1041 MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20);
960 1042
961 PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims); 1043 PhysicalPrims = startupConfig.GetBoolean("physical_prim", true);
962 CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims); 1044 CollidablePrims = startupConfig.GetBoolean("collidable_prim", true);
963
964 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys); 1045 m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys);
965 if (RegionInfo.NonphysPrimMin > 0) 1046 if (RegionInfo.NonphysPrimMin > 0)
966 { 1047 {
@@ -980,11 +1061,24 @@ namespace OpenSim.Region.Framework.Scenes
980 } 1061 }
981 1062
982 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); 1063 m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys);
1064
983 if (RegionInfo.PhysPrimMax > 0) 1065 if (RegionInfo.PhysPrimMax > 0)
984 { 1066 {
985 m_maxPhys = RegionInfo.PhysPrimMax; 1067 m_maxPhys = RegionInfo.PhysPrimMax;
986 } 1068 }
987 1069
1070 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity);
1071 if (RegionInfo.LinksetCapacity > 0)
1072 {
1073 m_linksetCapacity = RegionInfo.LinksetCapacity;
1074 }
1075
1076 m_linksetPhysCapacity = startupConfig.GetInt("LinksetPhysPrims", m_linksetPhysCapacity);
1077
1078
1079 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
1080 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
1081
988 // Here, if clamping is requested in either global or 1082 // Here, if clamping is requested in either global or
989 // local config, it will be used 1083 // local config, it will be used
990 // 1084 //
@@ -994,13 +1088,7 @@ namespace OpenSim.Region.Framework.Scenes
994 m_clampPrimSize = true; 1088 m_clampPrimSize = true;
995 } 1089 }
996 1090
997 m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); 1091 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete",m_useTrashOnDelete);
998 if (RegionInfo.LinksetCapacity > 0)
999 {
1000 m_linksetCapacity = RegionInfo.LinksetCapacity;
1001 }
1002
1003 m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete);
1004 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); 1092 m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries);
1005 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); 1093 m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings);
1006 m_dontPersistBefore = 1094 m_dontPersistBefore =
@@ -1011,11 +1099,11 @@ namespace OpenSim.Region.Framework.Scenes
1011 m_persistAfter *= 10000000; 1099 m_persistAfter *= 10000000;
1012 1100
1013 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); 1101 m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine");
1014 1102 m_log.InfoFormat("[SCENE]: Default script engine {0}", m_defaultScriptEngine);
1015 SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest");
1016 TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false);
1017 1103
1018 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); 1104 m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
1105 m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion);
1106 CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false);
1019 1107
1020 string[] possibleMapConfigSections = new string[] { "Map", "Startup" }; 1108 string[] possibleMapConfigSections = new string[] { "Map", "Startup" };
1021 1109
@@ -1061,7 +1149,7 @@ namespace OpenSim.Region.Framework.Scenes
1061 1149
1062 if (grant.Length > 0) 1150 if (grant.Length > 0)
1063 { 1151 {
1064 foreach (string viewer in grant.Split('|')) 1152 foreach (string viewer in grant.Split(','))
1065 { 1153 {
1066 m_AllowedViewers.Add(viewer.Trim().ToLower()); 1154 m_AllowedViewers.Add(viewer.Trim().ToLower());
1067 } 1155 }
@@ -1073,7 +1161,7 @@ namespace OpenSim.Region.Framework.Scenes
1073 1161
1074 if (grant.Length > 0) 1162 if (grant.Length > 0)
1075 { 1163 {
1076 foreach (string viewer in grant.Split('|')) 1164 foreach (string viewer in grant.Split(','))
1077 { 1165 {
1078 m_BannedViewers.Add(viewer.Trim().ToLower()); 1166 m_BannedViewers.Add(viewer.Trim().ToLower());
1079 } 1167 }
@@ -1191,6 +1279,10 @@ namespace OpenSim.Region.Framework.Scenes
1191 StatsReporter.OnSendStatsResult += SendSimStatsPackets; 1279 StatsReporter.OnSendStatsResult += SendSimStatsPackets;
1192 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; 1280 StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats;
1193 1281
1282<<<<<<< HEAD
1283=======
1284 MainConsole.Instance.Commands.AddCommand("scene", false, "gc collect", "gc collect", "gc collect", "Cause the garbage collector to make a single pass", HandleGcCollect);
1285>>>>>>> avn/ubitvar
1194 } 1286 }
1195 1287
1196 public Scene(RegionInfo regInfo, PhysicsScene physicsScene) 1288 public Scene(RegionInfo regInfo, PhysicsScene physicsScene)
@@ -1214,13 +1306,15 @@ namespace OpenSim.Region.Framework.Scenes
1214 1306
1215 PhysicalPrims = true; 1307 PhysicalPrims = true;
1216 CollidablePrims = true; 1308 CollidablePrims = true;
1217 PhysicsEnabled = true; 1309 // this is done above acording to config
1310 // PhysicsEnabled = true;
1218 1311
1219 AllowAvatarCrossing = true; 1312 AllowAvatarCrossing = true;
1220 1313
1221 PeriodicBackup = true; 1314 PeriodicBackup = true;
1222 UseBackup = true; 1315 UseBackup = true;
1223 1316
1317<<<<<<< HEAD
1224 IsReprioritizationEnabled = true; 1318 IsReprioritizationEnabled = true;
1225 UpdatePrioritizationScheme = UpdatePrioritizationSchemes.Time; 1319 UpdatePrioritizationScheme = UpdatePrioritizationSchemes.Time;
1226 ReprioritizationInterval = 5000; 1320 ReprioritizationInterval = 5000;
@@ -1231,9 +1325,12 @@ namespace OpenSim.Region.Framework.Scenes
1231 RootReprioritizationDistance = 10.0; 1325 RootReprioritizationDistance = 10.0;
1232 ChildReprioritizationDistance = 20.0; 1326 ChildReprioritizationDistance = 20.0;
1233 1327
1328=======
1329>>>>>>> avn/ubitvar
1234 m_eventManager = new EventManager(); 1330 m_eventManager = new EventManager();
1235 1331
1236 m_permissions = new ScenePermissions(this); 1332 m_permissions = new ScenePermissions(this);
1333
1237 } 1334 }
1238 1335
1239 #endregion 1336 #endregion
@@ -1279,6 +1376,7 @@ namespace OpenSim.Region.Framework.Scenes
1279 { 1376 {
1280 if (RegionInfo.RegionHandle != otherRegion.RegionHandle) 1377 if (RegionInfo.RegionHandle != otherRegion.RegionHandle)
1281 { 1378 {
1379<<<<<<< HEAD
1282 //// If these are cast to INT because long + negative values + abs returns invalid data 1380 //// If these are cast to INT because long + negative values + abs returns invalid data
1283 //int resultX = Math.Abs((int)xcell - (int)RegionInfo.RegionLocX); 1381 //int resultX = Math.Abs((int)xcell - (int)RegionInfo.RegionLocX);
1284 //int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY); 1382 //int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY);
@@ -1293,6 +1391,9 @@ namespace OpenSim.Region.Framework.Scenes
1293 // RegionInfo.RegionName, otherRegion.RegionName, newRegionX, newRegionY); 1391 // RegionInfo.RegionName, otherRegion.RegionName, newRegionX, newRegionY);
1294 1392
1295 if (!Util.IsOutsideView(dist, thisRegionX, newRegionX, thisRegionY, newRegionY)) 1393 if (!Util.IsOutsideView(dist, thisRegionX, newRegionX, thisRegionY, newRegionY))
1394=======
1395 if (isNeighborRegion(otherRegion))
1396>>>>>>> avn/ubitvar
1296 { 1397 {
1297 // Let the grid service module know, so this can be cached 1398 // Let the grid service module know, so this can be cached
1298 m_eventManager.TriggerOnRegionUp(otherRegion); 1399 m_eventManager.TriggerOnRegionUp(otherRegion);
@@ -1327,6 +1428,21 @@ namespace OpenSim.Region.Framework.Scenes
1327 } 1428 }
1328 } 1429 }
1329 1430
1431 public bool isNeighborRegion(GridRegion otherRegion)
1432 {
1433 int tmp = otherRegion.RegionLocX - (int)RegionInfo.WorldLocX; ;
1434
1435 if (tmp < -otherRegion.RegionSizeX && tmp > RegionInfo.RegionSizeX)
1436 return false;
1437
1438 tmp = otherRegion.RegionLocY - (int)RegionInfo.WorldLocY;
1439
1440 if (tmp < -otherRegion.RegionSizeY && tmp > RegionInfo.RegionSizeY)
1441 return false;
1442
1443 return true;
1444 }
1445
1330 public void AddNeighborRegion(RegionInfo region) 1446 public void AddNeighborRegion(RegionInfo region)
1331 { 1447 {
1332 lock (m_neighbours) 1448 lock (m_neighbours)
@@ -1458,8 +1574,11 @@ namespace OpenSim.Region.Framework.Scenes
1458 // Stop all client threads. 1574 // Stop all client threads.
1459 ForEachScenePresence(delegate(ScenePresence avatar) { CloseAgent(avatar.UUID, false); }); 1575 ForEachScenePresence(delegate(ScenePresence avatar) { CloseAgent(avatar.UUID, false); });
1460 1576
1461 m_log.Debug("[SCENE]: Persisting changed objects"); 1577 m_log.Debug("[SCENE]: TriggerSceneShuttingDown");
1462 EventManager.TriggerSceneShuttingDown(this); 1578 EventManager.TriggerSceneShuttingDown(this);
1579
1580 m_log.Debug("[SCENE]: Persisting changed objects");
1581
1463 Backup(false); 1582 Backup(false);
1464 m_sceneGraph.Close(); 1583 m_sceneGraph.Close();
1465 1584
@@ -1473,6 +1592,7 @@ namespace OpenSim.Region.Framework.Scenes
1473 // attempt to reference a null or disposed physics scene. 1592 // attempt to reference a null or disposed physics scene.
1474 if (PhysicsScene != null) 1593 if (PhysicsScene != null)
1475 { 1594 {
1595 m_log.Debug("[SCENE]: Dispose Physics");
1476 PhysicsScene phys = PhysicsScene; 1596 PhysicsScene phys = PhysicsScene;
1477 // remove the physics engine from both Scene and SceneGraph 1597 // remove the physics engine from both Scene and SceneGraph
1478 PhysicsScene = null; 1598 PhysicsScene = null;
@@ -1504,10 +1624,28 @@ namespace OpenSim.Region.Framework.Scenes
1504// m_log.DebugFormat("[SCENE]: Starting Heartbeat timer for {0}", RegionInfo.RegionName); 1624// m_log.DebugFormat("[SCENE]: Starting Heartbeat timer for {0}", RegionInfo.RegionName);
1505 if (m_heartbeatThread != null) 1625 if (m_heartbeatThread != null)
1506 { 1626 {
1627 m_hbRestarts++;
1628 if(m_hbRestarts > 10)
1629 Environment.Exit(1);
1630 m_log.ErrorFormat("[SCENE]: Restarting heartbeat thread because it hasn't reported in in region {0}", RegionInfo.RegionName);
1631
1632//int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
1633//System.Diagnostics.Process proc = new System.Diagnostics.Process();
1634//proc.EnableRaisingEvents=false;
1635//proc.StartInfo.FileName = "/bin/kill";
1636//proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
1637//proc.Start();
1638//proc.WaitForExit();
1639//Thread.Sleep(1000);
1640//Environment.Exit(1);
1507 m_heartbeatThread.Abort(); 1641 m_heartbeatThread.Abort();
1642 Watchdog.AbortThread(m_heartbeatThread.ManagedThreadId);
1508 m_heartbeatThread = null; 1643 m_heartbeatThread = null;
1509 } 1644 }
1510 1645
1646// m_sceneGraph.PreparePhysicsSimulation();
1647
1648
1511 m_heartbeatThread 1649 m_heartbeatThread
1512 = WorkManager.StartThread( 1650 = WorkManager.StartThread(
1513 Heartbeat, string.Format("Heartbeat-({0})", RegionInfo.RegionName.Replace(" ", "_")), ThreadPriority.Normal, false, false); 1651 Heartbeat, string.Format("Heartbeat-({0})", RegionInfo.RegionName.Replace(" ", "_")), ThreadPriority.Normal, false, false);
@@ -1687,6 +1825,7 @@ namespace OpenSim.Region.Framework.Scenes
1687 endFrame = Frame + frames; 1825 endFrame = Frame + frames;
1688 1826
1689 float physicsFPS = 0f; 1827 float physicsFPS = 0f;
1828<<<<<<< HEAD
1690 int previousFrameTick, tmpMS; 1829 int previousFrameTick, tmpMS;
1691 1830
1692 // These variables will be used to save the precise frame time using the 1831 // These variables will be used to save the precise frame time using the
@@ -1703,22 +1842,42 @@ namespace OpenSim.Region.Framework.Scenes
1703 // Begin the stopwatch to keep track of the time that the frame 1842 // Begin the stopwatch to keep track of the time that the frame
1704 // started running to determine how long the frame took to complete 1843 // started running to determine how long the frame took to complete
1705 totalFrameStopwatch.Start(); 1844 totalFrameStopwatch.Start();
1845=======
1846 int tmpMS;
1847 int previousFrameTick;
1848 int maintc;
1849 int sleepMS;
1850 int framestart;
1851>>>>>>> avn/ubitvar
1706 1852
1707 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) 1853 while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
1708 { 1854 {
1855 framestart = Util.EnvironmentTickCount();
1709 ++Frame; 1856 ++Frame;
1710 1857
1711 // m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); 1858 // m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
1712 1859
1860<<<<<<< HEAD
1713 agentMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0; 1861 agentMS = eventMS = backupMS = terrainMS = landMS = spareMS = 0;
1862=======
1863 agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1864>>>>>>> avn/ubitvar
1714 1865
1715 try 1866 try
1716 { 1867 {
1717 EventManager.TriggerRegionHeartbeatStart(this); 1868 EventManager.TriggerRegionHeartbeatStart(this);
1718 1869
1719 // Apply taints in terrain module to terrain in physics scene 1870 // Apply taints in terrain module to terrain in physics scene
1871
1872 tmpMS = Util.EnvironmentTickCount();
1873 if (Frame % 4 == 0)
1874 {
1875 CheckTerrainUpdates();
1876 }
1877
1720 if (Frame % m_update_terrain == 0) 1878 if (Frame % m_update_terrain == 0)
1721 { 1879 {
1880<<<<<<< HEAD
1722 // At several points inside the code there was a need to 1881 // At several points inside the code there was a need to
1723 // create a more precise measurement of time elapsed. 1882 // create a more precise measurement of time elapsed.
1724 // This led to the addition of variables that have a 1883 // This led to the addition of variables that have a
@@ -1749,6 +1908,12 @@ namespace OpenSim.Region.Framework.Scenes
1749 // feel right modifying the code to that degree at this 1908 // feel right modifying the code to that degree at this
1750 // point in time, the precise values all begin with the 1909 // point in time, the precise values all begin with the
1751 // keyword precise 1910 // keyword precise
1911=======
1912 UpdateTerrain();
1913 }
1914
1915 terrainMS = Util.EnvironmentTickCountSubtract(tmpMS);
1916>>>>>>> avn/ubitvar
1752 1917
1753 tmpMS = Util.EnvironmentTickCount(); 1918 tmpMS = Util.EnvironmentTickCount();
1754 1919
@@ -1816,6 +1981,19 @@ namespace OpenSim.Region.Framework.Scenes
1816 1981
1817 agentMS += Util.EnvironmentTickCountSubtract(tmpMS); 1982 agentMS += Util.EnvironmentTickCountSubtract(tmpMS);
1818 1983
1984<<<<<<< HEAD
1985=======
1986
1987 // Delete temp-on-rez stuff
1988 if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
1989 {
1990 tmpMS = Util.EnvironmentTickCount();
1991 m_cleaningTemps = true;
1992 Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; });
1993 tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpMS);
1994 }
1995
1996>>>>>>> avn/ubitvar
1819 if (Frame % m_update_events == 0) 1997 if (Frame % m_update_events == 0)
1820 { 1998 {
1821 tmpMS = Util.EnvironmentTickCount(); 1999 tmpMS = Util.EnvironmentTickCount();
@@ -1891,6 +2069,7 @@ namespace OpenSim.Region.Framework.Scenes
1891 preciseSimFrameTime += 2069 preciseSimFrameTime +=
1892 simFrameStopwatch.Elapsed.TotalMilliseconds; 2070 simFrameStopwatch.Elapsed.TotalMilliseconds;
1893 2071
2072<<<<<<< HEAD
1894 if (!UpdateOnTimer) 2073 if (!UpdateOnTimer)
1895 { 2074 {
1896 Watchdog.UpdateThread(); 2075 Watchdog.UpdateThread();
@@ -1918,13 +2097,40 @@ namespace OpenSim.Region.Framework.Scenes
1918 previousFrameTick = m_lastFrameTick; 2097 previousFrameTick = m_lastFrameTick;
1919 frameMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick); 2098 frameMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick);
1920 m_lastFrameTick = Util.EnvironmentTickCount(); 2099 m_lastFrameTick = Util.EnvironmentTickCount();
2100=======
2101 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1921 2102
1922 // if (Frame%m_update_avatars == 0)
1923 // UpdateInWorldTime();
1924 StatsReporter.AddPhysicsFPS(physicsFPS); 2103 StatsReporter.AddPhysicsFPS(physicsFPS);
1925 StatsReporter.AddTimeDilation(TimeDilation); 2104 StatsReporter.AddTimeDilation(TimeDilation);
1926 StatsReporter.AddFPS(1); 2105 StatsReporter.AddFPS(1);
1927 2106
2107 StatsReporter.addAgentMS(agentMS);
2108 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
2109 StatsReporter.addOtherMS(otherMS);
2110 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
2111
2112 previousFrameTick = m_lastFrameTick;
2113 m_lastFrameTick = Util.EnvironmentTickCount();
2114 tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
2115 tmpMS = (int)(MinFrameTime * 1000) - tmpMS;
2116
2117 m_firstHeartbeat = false;
2118
2119 sleepMS = Util.EnvironmentTickCount();
2120
2121 if (tmpMS > 0)
2122 Thread.Sleep(tmpMS);
2123
2124 sleepMS = Util.EnvironmentTickCountSubtract(sleepMS);
2125 frameMS = Util.EnvironmentTickCountSubtract(framestart);
2126 StatsReporter.addSleepMS(sleepMS);
2127 StatsReporter.addFrameMS(frameMS);
2128>>>>>>> avn/ubitvar
2129
2130 // if (Frame%m_update_avatars == 0)
2131 // UpdateInWorldTime();
2132
2133<<<<<<< HEAD
1928 StatsReporter.addFrameMS(frameMS); 2134 StatsReporter.addFrameMS(frameMS);
1929 StatsReporter.addAgentMS(agentMS); 2135 StatsReporter.addAgentMS(agentMS);
1930 StatsReporter.addPhysicsMS(physicsMS + physicsMS2); 2136 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
@@ -1932,6 +2138,8 @@ namespace OpenSim.Region.Framework.Scenes
1932 StatsReporter.AddSpareMS(spareMS); 2138 StatsReporter.AddSpareMS(spareMS);
1933 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS()); 2139 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1934 StatsReporter.AddScriptMS((int) GetAndResetScriptExecutionTime()); 2140 StatsReporter.AddScriptMS((int) GetAndResetScriptExecutionTime());
2141=======
2142>>>>>>> avn/ubitvar
1935 2143
1936 // Send the correct time values to the stats reporter for the 2144 // Send the correct time values to the stats reporter for the
1937 // frame times 2145 // frame times
@@ -1982,7 +2190,7 @@ namespace OpenSim.Region.Framework.Scenes
1982 public void AddGroupTarget(SceneObjectGroup grp) 2190 public void AddGroupTarget(SceneObjectGroup grp)
1983 { 2191 {
1984 lock (m_groupsWithTargets) 2192 lock (m_groupsWithTargets)
1985 m_groupsWithTargets[grp.UUID] = grp; 2193 m_groupsWithTargets[grp.UUID] = 0;
1986 } 2194 }
1987 2195
1988 public void RemoveGroupTarget(SceneObjectGroup grp) 2196 public void RemoveGroupTarget(SceneObjectGroup grp)
@@ -1993,18 +2201,24 @@ namespace OpenSim.Region.Framework.Scenes
1993 2201
1994 private void CheckAtTargets() 2202 private void CheckAtTargets()
1995 { 2203 {
1996 List<SceneObjectGroup> objs = null; 2204 List<UUID> objs = null;
1997 2205
1998 lock (m_groupsWithTargets) 2206 lock (m_groupsWithTargets)
1999 { 2207 {
2000 if (m_groupsWithTargets.Count != 0) 2208 if (m_groupsWithTargets.Count != 0)
2001 objs = new List<SceneObjectGroup>(m_groupsWithTargets.Values); 2209 objs = new List<UUID>(m_groupsWithTargets.Keys);
2002 } 2210 }
2003 2211
2004 if (objs != null) 2212 if (objs != null)
2005 { 2213 {
2006 foreach (SceneObjectGroup entry in objs) 2214 foreach (UUID entry in objs)
2007 entry.checkAtTargets(); 2215 {
2216 SceneObjectGroup grp = GetSceneObjectGroup(entry);
2217 if (grp == null)
2218 m_groupsWithTargets.Remove(entry);
2219 else
2220 grp.checkAtTargets();
2221 }
2008 } 2222 }
2009 } 2223 }
2010 2224
@@ -2028,6 +2242,11 @@ namespace OpenSim.Region.Framework.Scenes
2028 EventManager.TriggerTerrainTick(); 2242 EventManager.TriggerTerrainTick();
2029 } 2243 }
2030 2244
2245 private void CheckTerrainUpdates()
2246 {
2247 EventManager.TriggerTerrainCheckUpdates();
2248 }
2249
2031 /// <summary> 2250 /// <summary>
2032 /// Back up queued up changes 2251 /// Back up queued up changes
2033 /// </summary> 2252 /// </summary>
@@ -2079,7 +2298,7 @@ namespace OpenSim.Region.Framework.Scenes
2079 msg.fromAgentName = "Server"; 2298 msg.fromAgentName = "Server";
2080 msg.dialog = (byte)19; // Object msg 2299 msg.dialog = (byte)19; // Object msg
2081 msg.fromGroup = false; 2300 msg.fromGroup = false;
2082 msg.offline = (byte)0; 2301 msg.offline = (byte)1;
2083 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID; 2302 msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
2084 msg.Position = Vector3.Zero; 2303 msg.Position = Vector3.Zero;
2085 msg.RegionID = RegionInfo.RegionID.Guid; 2304 msg.RegionID = RegionInfo.RegionID.Guid;
@@ -2315,7 +2534,7 @@ namespace OpenSim.Region.Framework.Scenes
2315 return PhysicsScene.SupportsRaycastWorldFiltered(); 2534 return PhysicsScene.SupportsRaycastWorldFiltered();
2316 } 2535 }
2317 2536
2318 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) 2537 public object RayCastFiltered(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2319 { 2538 {
2320 if (PhysicsScene == null) 2539 if (PhysicsScene == null)
2321 return null; 2540 return null;
@@ -2337,14 +2556,24 @@ namespace OpenSim.Region.Framework.Scenes
2337 /// <returns></returns> 2556 /// <returns></returns>
2338 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) 2557 public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter)
2339 { 2558 {
2559
2560 float wheight = (float)RegionInfo.RegionSettings.WaterHeight;
2561 Vector3 wpos = Vector3.Zero;
2562 // Check for water surface intersection from above
2563 if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) )
2564 {
2565 float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z);
2566 wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X));
2567 wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y));
2568 wpos.Z = wheight;
2569 }
2570
2340 Vector3 pos = Vector3.Zero; 2571 Vector3 pos = Vector3.Zero;
2341 if (RayEndIsIntersection == (byte)1) 2572 if (RayEndIsIntersection == (byte)1)
2342 { 2573 {
2343 pos = RayEnd; 2574 pos = RayEnd;
2344 return pos;
2345 } 2575 }
2346 2576 else if (RayTargetID != UUID.Zero)
2347 if (RayTargetID != UUID.Zero)
2348 { 2577 {
2349 SceneObjectPart target = GetSceneObjectPart(RayTargetID); 2578 SceneObjectPart target = GetSceneObjectPart(RayTargetID);
2350 2579
@@ -2389,13 +2618,10 @@ namespace OpenSim.Region.Framework.Scenes
2389 //pos.Z -= 0.25F; 2618 //pos.Z -= 0.25F;
2390 2619
2391 } 2620 }
2392
2393 return pos;
2394 } 2621 }
2395 else 2622 else
2396 { 2623 {
2397 // We don't have a target here, so we're going to raytrace all the objects in the scene. 2624 // We don't have a target here, so we're going to raytrace all the objects in the scene.
2398
2399 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); 2625 EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
2400 2626
2401 // Un-comment the following line to print the raytrace results to the console. 2627 // Un-comment the following line to print the raytrace results to the console.
@@ -2403,15 +2629,18 @@ namespace OpenSim.Region.Framework.Scenes
2403 2629
2404 if (ei.HitTF) 2630 if (ei.HitTF)
2405 { 2631 {
2632<<<<<<< HEAD
2406 pos = ei.ipoint; 2633 pos = ei.ipoint;
2407 } 2634 }
2635=======
2636 pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
2637 }
2638>>>>>>> avn/ubitvar
2408 else 2639 else
2409 { 2640 {
2410 // fall back to our stupid functionality 2641 // fall back to our stupid functionality
2411 pos = RayEnd; 2642 pos = RayEnd;
2412 } 2643 }
2413
2414 return pos;
2415 } 2644 }
2416 } 2645 }
2417 else 2646 else
@@ -2422,8 +2651,12 @@ namespace OpenSim.Region.Framework.Scenes
2422 //increase height so its above the ground. 2651 //increase height so its above the ground.
2423 //should be getting the normal of the ground at the rez point and using that? 2652 //should be getting the normal of the ground at the rez point and using that?
2424 pos.Z += scale.Z / 2f; 2653 pos.Z += scale.Z / 2f;
2425 return pos; 2654// return pos;
2426 } 2655 }
2656
2657 // check against posible water intercept
2658 if (wpos.Z > pos.Z) pos = wpos;
2659 return pos;
2427 } 2660 }
2428 2661
2429 2662
@@ -2514,12 +2747,12 @@ namespace OpenSim.Region.Framework.Scenes
2514 { 2747 {
2515 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates)) 2748 if (m_sceneGraph.AddRestoredSceneObject(sceneObject, attachToBackup, alreadyPersisted, sendClientUpdates))
2516 { 2749 {
2750 sceneObject.IsDeleted = false;
2517 EventManager.TriggerObjectAddedToScene(sceneObject); 2751 EventManager.TriggerObjectAddedToScene(sceneObject);
2518 return true; 2752 return true;
2519 } 2753 }
2520 2754
2521 return false; 2755 return false;
2522
2523 } 2756 }
2524 2757
2525 /// <summary> 2758 /// <summary>
@@ -2611,6 +2844,15 @@ namespace OpenSim.Region.Framework.Scenes
2611 /// </summary> 2844 /// </summary>
2612 public void DeleteAllSceneObjects() 2845 public void DeleteAllSceneObjects()
2613 { 2846 {
2847 DeleteAllSceneObjects(false);
2848 }
2849
2850 /// <summary>
2851 /// Delete every object from the scene. This does not include attachments worn by avatars.
2852 /// </summary>
2853 public void DeleteAllSceneObjects(bool exceptNoCopy)
2854 {
2855 List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>();
2614 lock (Entities) 2856 lock (Entities)
2615 { 2857 {
2616 EntityBase[] entities = Entities.GetEntities(); 2858 EntityBase[] entities = Entities.GetEntities();
@@ -2619,11 +2861,24 @@ namespace OpenSim.Region.Framework.Scenes
2619 if (e is SceneObjectGroup) 2861 if (e is SceneObjectGroup)
2620 { 2862 {
2621 SceneObjectGroup sog = (SceneObjectGroup)e; 2863 SceneObjectGroup sog = (SceneObjectGroup)e;
2622 if (!sog.IsAttachment) 2864 if (sog != null && !sog.IsAttachment)
2623 DeleteSceneObject((SceneObjectGroup)e, false); 2865 {
2866 if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0))
2867 {
2868 DeleteSceneObject((SceneObjectGroup)e, false);
2869 }
2870 else
2871 {
2872 toReturn.Add((SceneObjectGroup)e);
2873 }
2874 }
2624 } 2875 }
2625 } 2876 }
2626 } 2877 }
2878 if (toReturn.Count > 0)
2879 {
2880 returnObjects(toReturn.ToArray(), UUID.Zero);
2881 }
2627 } 2882 }
2628 2883
2629 /// <summary> 2884 /// <summary>
@@ -2654,6 +2909,14 @@ namespace OpenSim.Region.Framework.Scenes
2654 else 2909 else
2655 group.StopScriptInstances(); 2910 group.StopScriptInstances();
2656 2911
2912 List<UUID> avatars = group.GetSittingAvatars();
2913 foreach (UUID av in avatars)
2914 {
2915 ScenePresence p = GetScenePresence(av);
2916 if (p != null && p.ParentUUID == UUID.Zero)
2917 p.StandUp();
2918 }
2919
2657 SceneObjectPart[] partList = group.Parts; 2920 SceneObjectPart[] partList = group.Parts;
2658 2921
2659 foreach (SceneObjectPart part in partList) 2922 foreach (SceneObjectPart part in partList)
@@ -2681,6 +2944,8 @@ namespace OpenSim.Region.Framework.Scenes
2681 } 2944 }
2682 2945
2683 group.DeleteGroupFromScene(silent); 2946 group.DeleteGroupFromScene(silent);
2947 if (!silent)
2948 SendKillObject(new List<uint>() { group.LocalId });
2684 2949
2685 // m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID); 2950 // m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
2686 } 2951 }
@@ -2717,6 +2982,11 @@ namespace OpenSim.Region.Framework.Scenes
2717 return false; 2982 return false;
2718 } 2983 }
2719 2984
2985
2986 public void updateScenePartGroup(SceneObjectPart part, SceneObjectGroup grp)
2987 {
2988 m_sceneGraph.updateScenePartGroup(part, grp);
2989 }
2720 /// <summary> 2990 /// <summary>
2721 /// Move the given scene object into a new region depending on which region its absolute position has moved 2991 /// Move the given scene object into a new region depending on which region its absolute position has moved
2722 /// into. 2992 /// into.
@@ -2743,10 +3013,55 @@ namespace OpenSim.Region.Framework.Scenes
2743 m_log.Warn("[SCENE]: exception when trying to remove the prim that crossed the border."); 3013 m_log.Warn("[SCENE]: exception when trying to remove the prim that crossed the border.");
2744 } 3014 }
2745 return; 3015 return;
3016<<<<<<< HEAD
3017=======
3018 }
3019
3020 if (grp.RootPart.RETURN_AT_EDGE)
3021 {
3022 // We remove the object here
3023 try
3024 {
3025 List<SceneObjectGroup> objects = new List<SceneObjectGroup>();
3026 objects.Add(grp);
3027 SceneObjectGroup[] objectsArray = objects.ToArray();
3028 returnObjects(objectsArray, UUID.Zero);
3029 }
3030 catch (Exception)
3031 {
3032 m_log.Warn("[SCENE]: exception when trying to return the prim that crossed the border.");
3033 }
3034 return;
3035 }
3036
3037 if (EntityTransferModule != null)
3038 EntityTransferModule.Cross(grp, attemptedPosition, silent);
3039 }
3040
3041 // Simple test to see if a position is in the current region.
3042 // This test is mostly used to see if a region crossing is necessary.
3043 // Assuming the position is relative to the region so anything outside its bounds.
3044 // Return 'true' if position inside region.
3045 public bool PositionIsInCurrentRegion(Vector3 pos)
3046 {
3047 bool ret = false;
3048 int xx = (int)Math.Floor(pos.X);
3049 int yy = (int)Math.Floor(pos.Y);
3050 if (xx < 0 || yy < 0)
3051 return false;
3052
3053 IRegionCombinerModule regionCombinerModule = RequestModuleInterface<IRegionCombinerModule>();
3054 if (regionCombinerModule == null)
3055 {
3056 // Regular region. Just check for region size
3057 if (xx < RegionInfo.RegionSizeX && yy < RegionInfo.RegionSizeY )
3058 ret = true;
3059>>>>>>> avn/ubitvar
2746 } 3060 }
2747 3061
2748 if (grp.RootPart.RETURN_AT_EDGE) 3062 if (grp.RootPart.RETURN_AT_EDGE)
2749 { 3063 {
3064<<<<<<< HEAD
2750 // We remove the object here 3065 // We remove the object here
2751 try 3066 try
2752 { 3067 {
@@ -2795,6 +3110,16 @@ namespace OpenSim.Region.Framework.Scenes
2795 3110
2796 } 3111 }
2797 3112
3113=======
3114 // We're in a mega-region so see if we are still in that larger region
3115 ret = regionCombinerModule.PositionIsInMegaregion(this.RegionInfo.RegionID, xx, yy);
3116 }
3117
3118 return ret;
3119
3120 }
3121
3122>>>>>>> avn/ubitvar
2798 /// <summary> 3123 /// <summary>
2799 /// Called when objects or attachments cross the border, or teleport, between regions. 3124 /// Called when objects or attachments cross the border, or teleport, between regions.
2800 /// </summary> 3125 /// </summary>
@@ -2816,8 +3141,55 @@ namespace OpenSim.Region.Framework.Scenes
2816 return false; 3141 return false;
2817 } 3142 }
2818 3143
3144<<<<<<< HEAD
2819 if (!EntityTransferModule.HandleIncomingSceneObject(newObject, newPosition)) 3145 if (!EntityTransferModule.HandleIncomingSceneObject(newObject, newPosition))
2820 return false; 3146 return false;
3147=======
3148 // If the user is banned, we won't let any of their objects
3149 // enter. Period.
3150 //
3151 if (RegionInfo.EstateSettings.IsBanned(newObject.OwnerID, 36))
3152 {
3153 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", newObject.OwnerID);
3154 return false;
3155 }
3156
3157 if (newPosition != Vector3.Zero)
3158 newObject.RootPart.GroupPosition = newPosition;
3159
3160 if (!AddSceneObject(newObject))
3161 {
3162 m_log.DebugFormat(
3163 "[INTERREGION]: Problem adding scene object {0} in {1} ", newObject.UUID, RegionInfo.RegionName);
3164 return false;
3165 }
3166
3167 if (!newObject.IsAttachment)
3168 {
3169 // FIXME: It would be better to never add the scene object at all rather than add it and then delete
3170 // it
3171 if (!Permissions.CanObjectEntry(newObject.UUID, true, newObject.AbsolutePosition))
3172 {
3173 // Deny non attachments based on parcel settings
3174 //
3175 m_log.Info("[INTERREGION]: Denied prim crossing because of parcel settings");
3176
3177 DeleteSceneObject(newObject, false);
3178
3179 return false;
3180 }
3181
3182 // For attachments, we need to wait until the agent is root
3183 // before we restart the scripts, or else some functions won't work.
3184 newObject.RootPart.ParentGroup.CreateScriptInstances(0, false, DefaultScriptEngine, GetStateSource(newObject));
3185 newObject.ResumeScripts();
3186
3187 // AddSceneObject already does this and doing it again messes
3188 // up region crossings, so don't.
3189 //if (newObject.RootPart.KeyframeMotion != null)
3190 // newObject.RootPart.KeyframeMotion.UpdateSceneObject(newObject);
3191 }
3192>>>>>>> avn/ubitvar
2821 3193
2822 // Do this as late as possible so that listeners have full access to the incoming object 3194 // Do this as late as possible so that listeners have full access to the incoming object
2823 EventManager.TriggerOnIncomingSceneObject(newObject); 3195 EventManager.TriggerOnIncomingSceneObject(newObject);
@@ -2834,6 +3206,23 @@ namespace OpenSim.Region.Framework.Scenes
2834 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns> 3206 /// <returns>True if the SceneObjectGroup was added, False if it was not</returns>
2835 public bool AddSceneObject(SceneObjectGroup sceneObject) 3207 public bool AddSceneObject(SceneObjectGroup sceneObject)
2836 { 3208 {
3209 if (sceneObject.OwnerID == UUID.Zero)
3210 {
3211 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero", sceneObject.UUID);
3212 return false;
3213 }
3214
3215 // If the user is banned, we won't let any of their objects
3216 // enter. Period.
3217 //
3218 int flags = GetUserFlags(sceneObject.OwnerID);
3219 if (RegionInfo.EstateSettings.IsBanned(sceneObject.OwnerID, flags))
3220 {
3221 m_log.InfoFormat("[INTERREGION]: Denied prim crossing for banned avatar {0}", sceneObject.OwnerID);
3222
3223 return false;
3224 }
3225
2837 // Force allocation of new LocalId 3226 // Force allocation of new LocalId
2838 // 3227 //
2839 SceneObjectPart[] parts = sceneObject.Parts; 3228 SceneObjectPart[] parts = sceneObject.Parts;
@@ -2870,22 +3259,64 @@ namespace OpenSim.Region.Framework.Scenes
2870 // information that this is due to a teleport/border cross rather than an ordinary attachment. 3259 // information that this is due to a teleport/border cross rather than an ordinary attachment.
2871 // We currently do this in Scene.MakeRootAgent() instead. 3260 // We currently do this in Scene.MakeRootAgent() instead.
2872 if (AttachmentsModule != null) 3261 if (AttachmentsModule != null)
2873 AttachmentsModule.AttachObject(sp, grp, 0, false, false, true); 3262 AttachmentsModule.AttachObject(sp, grp, 0, false, false, false, true);
2874 } 3263 }
2875 else 3264 else
2876 { 3265 {
3266 m_log.DebugFormat("[SCENE]: Attachment {0} arrived and scene presence was not found, setting to temp", sceneObject.UUID);
2877 RootPrim.RemFlag(PrimFlags.TemporaryOnRez); 3267 RootPrim.RemFlag(PrimFlags.TemporaryOnRez);
2878 RootPrim.AddFlag(PrimFlags.TemporaryOnRez); 3268 RootPrim.AddFlag(PrimFlags.TemporaryOnRez);
2879 } 3269 }
3270 if (sceneObject.OwnerID == UUID.Zero)
3271 {
3272 m_log.ErrorFormat("[SCENE]: Owner ID for {0} was zero after attachment processing. BUG!", sceneObject.UUID);
3273 return false;
3274 }
2880 } 3275 }
2881 else 3276 else
2882 { 3277 {
3278 if (sceneObject.OwnerID == UUID.Zero)
3279 {
3280 m_log.ErrorFormat("[SCENE]: Owner ID for non-attachment {0} was zero", sceneObject.UUID);
3281 return false;
3282 }
2883 AddRestoredSceneObject(sceneObject, true, false); 3283 AddRestoredSceneObject(sceneObject, true, false);
2884 } 3284 }
2885 3285
2886 return true; 3286 return true;
2887 } 3287 }
2888 3288
3289<<<<<<< HEAD
3290=======
3291 private int GetStateSource(SceneObjectGroup sog)
3292 {
3293 ScenePresence sp = GetScenePresence(sog.OwnerID);
3294
3295 if (sp != null)
3296 return sp.GetStateSource();
3297
3298 return 2; // StateSource.PrimCrossing
3299 }
3300
3301 public int GetUserFlags(UUID user)
3302 {
3303 //Unfortunately the SP approach means that the value is cached until region is restarted
3304 /*
3305 ScenePresence sp;
3306 if (TryGetScenePresence(user, out sp))
3307 {
3308 return sp.UserFlags;
3309 }
3310 else
3311 {
3312 */
3313 UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user);
3314 if (uac == null)
3315 return 0;
3316 return uac.UserFlags;
3317 //}
3318 }
3319>>>>>>> avn/ubitvar
2889 #endregion 3320 #endregion
2890 3321
2891 #region Add/Remove Avatar Methods 3322 #region Add/Remove Avatar Methods
@@ -2921,9 +3352,15 @@ namespace OpenSim.Region.Framework.Scenes
2921 vialogin 3352 vialogin
2922 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 3353 = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0
2923 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; 3354 || (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0;
3355<<<<<<< HEAD
2924 3356
2925 // CheckHeartbeat(); 3357 // CheckHeartbeat();
2926 3358
3359=======
3360
3361 CheckHeartbeat();
3362
3363>>>>>>> avn/ubitvar
2927 sp = GetScenePresence(client.AgentId); 3364 sp = GetScenePresence(client.AgentId);
2928 3365
2929 // XXX: Not sure how good it is to add a new client if a scene presence already exists. Possibly this 3366 // XXX: Not sure how good it is to add a new client if a scene presence already exists. Possibly this
@@ -2933,6 +3370,7 @@ namespace OpenSim.Region.Framework.Scenes
2933 if (sp == null) 3370 if (sp == null)
2934 { 3371 {
2935 m_log.DebugFormat( 3372 m_log.DebugFormat(
3373<<<<<<< HEAD
2936 "[SCENE]: Adding new child scene presence {0} {1} to scene {2} at pos {3}", 3374 "[SCENE]: Adding new child scene presence {0} {1} to scene {2} at pos {3}",
2937 client.Name, client.AgentId, RegionInfo.RegionName, client.StartPos); 3375 client.Name, client.AgentId, RegionInfo.RegionName, client.StartPos);
2938 3376
@@ -2954,6 +3392,30 @@ namespace OpenSim.Region.Framework.Scenes
2954 m_eventManager.TriggerOnNewPresence(sp); 3392 m_eventManager.TriggerOnNewPresence(sp);
2955 3393
2956 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags; 3394 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags;
3395=======
3396 "[SCENE]: Adding new child scene presence {0} {1} to scene {2} at pos {3}, tpflags: {4}",
3397 client.Name, client.AgentId, RegionInfo.RegionName, client.StartPos,
3398 ((TPFlags)aCircuit.teleportFlags).ToString());
3399
3400 m_clientManager.Add(client);
3401 SubscribeToClientEvents(client);
3402
3403 sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type);
3404
3405 sp.TeleportFlags = (TPFlags)aCircuit.teleportFlags;
3406
3407/* done in completMovement
3408 InventoryFolderBase cof = InventoryService.GetFolderForType(client.AgentId, (AssetType)46);
3409 if (cof == null)
3410 sp.COF = UUID.Zero;
3411 else
3412 sp.COF = cof.ID;
3413
3414 m_log.DebugFormat("[SCENE]: COF for {0} is {1}", client.AgentId, sp.COF);
3415 */
3416 m_eventManager.TriggerOnNewPresence(sp);
3417
3418>>>>>>> avn/ubitvar
2957 } 3419 }
2958 else 3420 else
2959 { 3421 {
@@ -2992,6 +3454,15 @@ namespace OpenSim.Region.Framework.Scenes
2992 return sp; 3454 return sp;
2993 } 3455 }
2994 3456
3457 public string GetAgentHomeURI(UUID agentID)
3458 {
3459 AgentCircuitData circuit = AuthenticateHandler.GetAgentCircuitData(agentID);
3460 if (circuit != null && circuit.ServiceURLs != null && circuit.ServiceURLs.ContainsKey("HomeURI"))
3461 return circuit.ServiceURLs["HomeURI"].ToString();
3462 else
3463 return null;
3464 }
3465
2995 /// <summary> 3466 /// <summary>
2996 /// Returns the Home URI of the agent, or null if unknown. 3467 /// Returns the Home URI of the agent, or null if unknown.
2997 /// </summary> 3468 /// </summary>
@@ -3088,19 +3559,15 @@ namespace OpenSim.Region.Framework.Scenes
3088 // and the scene presence and the client, if they exist 3559 // and the scene presence and the client, if they exist
3089 try 3560 try
3090 { 3561 {
3091 // We need to wait for the client to make UDP contact first.
3092 // It's the UDP contact that creates the scene presence
3093 ScenePresence sp = WaitGetScenePresence(agentID); 3562 ScenePresence sp = WaitGetScenePresence(agentID);
3563
3094 if (sp != null) 3564 if (sp != null)
3095 { 3565 {
3096 PresenceService.LogoutAgent(sp.ControllingClient.SessionId); 3566 PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
3097 3567
3098 CloseAgent(sp.UUID, false); 3568 CloseAgent(sp.UUID, false);
3099 } 3569 }
3100 else 3570
3101 {
3102 m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID);
3103 }
3104 // BANG! SLASH! 3571 // BANG! SLASH!
3105 m_authenticateHandler.RemoveCircuit(agentID); 3572 m_authenticateHandler.RemoveCircuit(agentID);
3106 3573
@@ -3137,7 +3604,7 @@ namespace OpenSim.Region.Framework.Scenes
3137 3604
3138 public virtual void SubscribeToClientTerrainEvents(IClientAPI client) 3605 public virtual void SubscribeToClientTerrainEvents(IClientAPI client)
3139 { 3606 {
3140 client.OnRegionHandShakeReply += SendLayerData; 3607// client.OnRegionHandShakeReply += SendLayerData;
3141 } 3608 }
3142 3609
3143 public virtual void SubscribeToClientPrimEvents(IClientAPI client) 3610 public virtual void SubscribeToClientPrimEvents(IClientAPI client)
@@ -3145,6 +3612,8 @@ namespace OpenSim.Region.Framework.Scenes
3145 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition; 3612 client.OnUpdatePrimGroupPosition += m_sceneGraph.UpdatePrimGroupPosition;
3146 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition; 3613 client.OnUpdatePrimSinglePosition += m_sceneGraph.UpdatePrimSinglePosition;
3147 3614
3615 client.onClientChangeObject += m_sceneGraph.ClientChangeObject;
3616
3148 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation; 3617 client.OnUpdatePrimGroupRotation += m_sceneGraph.UpdatePrimGroupRotation;
3149 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation; 3618 client.OnUpdatePrimGroupMouseRotation += m_sceneGraph.UpdatePrimGroupRotation;
3150 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation; 3619 client.OnUpdatePrimSingleRotation += m_sceneGraph.UpdatePrimSingleRotation;
@@ -3201,6 +3670,7 @@ namespace OpenSim.Region.Framework.Scenes
3201 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory; 3670 client.OnFetchInventory += m_asyncInventorySender.HandleFetchInventory;
3202 client.OnUpdateInventoryItem += UpdateInventoryItemAsset; 3671 client.OnUpdateInventoryItem += UpdateInventoryItemAsset;
3203 client.OnCopyInventoryItem += CopyInventoryItem; 3672 client.OnCopyInventoryItem += CopyInventoryItem;
3673 client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy;
3204 client.OnMoveInventoryItem += MoveInventoryItem; 3674 client.OnMoveInventoryItem += MoveInventoryItem;
3205 client.OnRemoveInventoryItem += RemoveInventoryItem; 3675 client.OnRemoveInventoryItem += RemoveInventoryItem;
3206 client.OnRemoveInventoryFolder += RemoveInventoryFolder; 3676 client.OnRemoveInventoryFolder += RemoveInventoryFolder;
@@ -3262,7 +3732,7 @@ namespace OpenSim.Region.Framework.Scenes
3262 3732
3263 public virtual void UnSubscribeToClientTerrainEvents(IClientAPI client) 3733 public virtual void UnSubscribeToClientTerrainEvents(IClientAPI client)
3264 { 3734 {
3265 client.OnRegionHandShakeReply -= SendLayerData; 3735// client.OnRegionHandShakeReply -= SendLayerData;
3266 } 3736 }
3267 3737
3268 public virtual void UnSubscribeToClientPrimEvents(IClientAPI client) 3738 public virtual void UnSubscribeToClientPrimEvents(IClientAPI client)
@@ -3270,6 +3740,8 @@ namespace OpenSim.Region.Framework.Scenes
3270 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition; 3740 client.OnUpdatePrimGroupPosition -= m_sceneGraph.UpdatePrimGroupPosition;
3271 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition; 3741 client.OnUpdatePrimSinglePosition -= m_sceneGraph.UpdatePrimSinglePosition;
3272 3742
3743 client.onClientChangeObject -= m_sceneGraph.ClientChangeObject;
3744
3273 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3745 client.OnUpdatePrimGroupRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3274 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation; 3746 client.OnUpdatePrimGroupMouseRotation -= m_sceneGraph.UpdatePrimGroupRotation;
3275 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation; 3747 client.OnUpdatePrimSingleRotation -= m_sceneGraph.UpdatePrimSingleRotation;
@@ -3518,6 +3990,10 @@ namespace OpenSim.Region.Framework.Scenes
3518 /// <param name='closeChildAgents'> 3990 /// <param name='closeChildAgents'>
3519 /// Close the neighbour child agents associated with this client. 3991 /// Close the neighbour child agents associated with this client.
3520 /// </param> 3992 /// </param>
3993 ///
3994
3995 private object m_removeClientPrivLock = new Object();
3996
3521 public void RemoveClient(UUID agentID, bool closeChildAgents) 3997 public void RemoveClient(UUID agentID, bool closeChildAgents)
3522 { 3998 {
3523 AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID); 3999 AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID);
@@ -3534,8 +4010,13 @@ namespace OpenSim.Region.Framework.Scenes
3534 } 4010 }
3535 4011
3536 // TODO: Can we now remove this lock? 4012 // TODO: Can we now remove this lock?
4013<<<<<<< HEAD
3537 lock (acd) 4014 lock (acd)
3538 { 4015 {
4016=======
4017 lock (m_removeClientPrivLock)
4018 {
4019>>>>>>> avn/ubitvar
3539 bool isChildAgent = false; 4020 bool isChildAgent = false;
3540 4021
3541 ScenePresence avatar = GetScenePresence(agentID); 4022 ScenePresence avatar = GetScenePresence(agentID);
@@ -3579,8 +4060,13 @@ namespace OpenSim.Region.Framework.Scenes
3579 // TODO: We shouldn't use closeChildAgents here - it's being used by the NPC module to stop 4060 // TODO: We shouldn't use closeChildAgents here - it's being used by the NPC module to stop
3580 // unnecessary operations. This should go away once NPCs have no accompanying IClientAPI 4061 // unnecessary operations. This should go away once NPCs have no accompanying IClientAPI
3581 if (closeChildAgents && CapsModule != null) 4062 if (closeChildAgents && CapsModule != null)
4063<<<<<<< HEAD
3582 CapsModule.RemoveCaps(agentID); 4064 CapsModule.RemoveCaps(agentID);
3583 4065
4066=======
4067 CapsModule.RemoveCaps(agentID, avatar.ControllingClient.CircuitCode);
4068
4069>>>>>>> avn/ubitvar
3584 if (closeChildAgents && !isChildAgent) 4070 if (closeChildAgents && !isChildAgent)
3585 { 4071 {
3586 List<ulong> regions = avatar.KnownRegionHandles; 4072 List<ulong> regions = avatar.KnownRegionHandles;
@@ -3591,13 +4077,21 @@ namespace OpenSim.Region.Framework.Scenes
3591 } 4077 }
3592 4078
3593 m_eventManager.TriggerClientClosed(agentID, this); 4079 m_eventManager.TriggerClientClosed(agentID, this);
4080// m_log.Debug("[Scene]TriggerClientClosed done");
3594 m_eventManager.TriggerOnRemovePresence(agentID); 4081 m_eventManager.TriggerOnRemovePresence(agentID);
4082<<<<<<< HEAD
3595 4083
4084=======
4085// m_log.Debug("[Scene]TriggerOnRemovePresence done");
4086
4087>>>>>>> avn/ubitvar
3596 if (!isChildAgent) 4088 if (!isChildAgent)
3597 { 4089 {
3598 if (AttachmentsModule != null) 4090 if (AttachmentsModule != null)
3599 { 4091 {
4092// m_log.Debug("[Scene]DeRezAttachments");
3600 AttachmentsModule.DeRezAttachments(avatar); 4093 AttachmentsModule.DeRezAttachments(avatar);
4094// m_log.Debug("[Scene]DeRezAttachments done");
3601 } 4095 }
3602 4096
3603 ForEachClient( 4097 ForEachClient(
@@ -3611,7 +4105,11 @@ namespace OpenSim.Region.Framework.Scenes
3611 4105
3612 // It's possible for child agents to have transactions if changes are being made cross-border. 4106 // It's possible for child agents to have transactions if changes are being made cross-border.
3613 if (AgentTransactionsModule != null) 4107 if (AgentTransactionsModule != null)
4108 {
4109// m_log.Debug("[Scene]RemoveAgentAssetTransactions");
3614 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID); 4110 AgentTransactionsModule.RemoveAgentAssetTransactions(agentID);
4111 }
4112 m_log.Debug("[Scene] The avatar has left the building");
3615 } 4113 }
3616 catch (Exception e) 4114 catch (Exception e)
3617 { 4115 {
@@ -3730,7 +4228,14 @@ namespace OpenSim.Region.Framework.Scenes
3730 /// or other applications where a full grid/Hypergrid presence may not be required.</param> 4228 /// or other applications where a full grid/Hypergrid presence may not be required.</param>
3731 /// <returns>True if the region accepts this agent. False if it does not. False will 4229 /// <returns>True if the region accepts this agent. False if it does not. False will
3732 /// also return a reason.</returns> 4230 /// also return a reason.</returns>
4231<<<<<<< HEAD
3733 public bool NewUserConnection(AgentCircuitData acd, uint teleportFlags, GridRegion source, out string reason, bool requirePresenceLookup) 4232 public bool NewUserConnection(AgentCircuitData acd, uint teleportFlags, GridRegion source, out string reason, bool requirePresenceLookup)
4233=======
4234 ///
4235 private object m_newUserConnLock = new object();
4236
4237 public bool NewUserConnection(AgentCircuitData acd, uint teleportFlags, out string reason, bool requirePresenceLookup)
4238>>>>>>> avn/ubitvar
3734 { 4239 {
3735 bool vialogin = ((teleportFlags & (uint)TPFlags.ViaLogin) != 0 || 4240 bool vialogin = ((teleportFlags & (uint)TPFlags.ViaLogin) != 0 ||
3736 (teleportFlags & (uint)TPFlags.ViaHGLogin) != 0); 4241 (teleportFlags & (uint)TPFlags.ViaHGLogin) != 0);
@@ -3763,6 +4268,8 @@ namespace OpenSim.Region.Framework.Scenes
3763 (source == null) ? "" : string.Format("From region {0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI) 4268 (source == null) ? "" : string.Format("From region {0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI)
3764 ); 4269 );
3765 4270
4271// m_log.DebugFormat("NewUserConnection stack {0}", Environment.StackTrace);
4272
3766 if (!LoginsEnabled) 4273 if (!LoginsEnabled)
3767 { 4274 {
3768 reason = "Logins Disabled"; 4275 reason = "Logins Disabled";
@@ -3890,7 +4397,7 @@ namespace OpenSim.Region.Framework.Scenes
3890 } 4397 }
3891 4398
3892 // TODO: can we remove this lock? 4399 // TODO: can we remove this lock?
3893 lock (acd) 4400 lock (m_newUserConnLock)
3894 { 4401 {
3895 if (sp != null && !sp.IsChildAgent) 4402 if (sp != null && !sp.IsChildAgent)
3896 { 4403 {
@@ -3917,6 +4424,12 @@ namespace OpenSim.Region.Framework.Scenes
3917 // We need the circuit data here for some of the subsequent checks. (groups, for example) 4424 // We need the circuit data here for some of the subsequent checks. (groups, for example)
3918 // If the checks fail, we remove the circuit. 4425 // If the checks fail, we remove the circuit.
3919 acd.teleportFlags = teleportFlags; 4426 acd.teleportFlags = teleportFlags;
4427
4428 // Remove any preexisting circuit - we don't want duplicates
4429 // This is a stab at preventing avatar "ghosting"
4430 if (vialogin)
4431 m_authenticateHandler.RemoveCircuit(acd.AgentID);
4432
3920 m_authenticateHandler.AddNewCircuit(acd.circuitcode, acd); 4433 m_authenticateHandler.AddNewCircuit(acd.circuitcode, acd);
3921 4434
3922 land = LandChannel.GetLandObject(acd.startpos.X, acd.startpos.Y); 4435 land = LandChannel.GetLandObject(acd.startpos.X, acd.startpos.Y);
@@ -3924,6 +4437,9 @@ namespace OpenSim.Region.Framework.Scenes
3924 // On login test land permisions 4437 // On login test land permisions
3925 if (vialogin) 4438 if (vialogin)
3926 { 4439 {
4440 IUserAccountCacheModule cache = RequestModuleInterface<IUserAccountCacheModule>();
4441 if (cache != null)
4442 cache.Remove(acd.firstname + " " + acd.lastname);
3927 if (land != null && !TestLandRestrictions(acd.AgentID, out reason, ref acd.startpos.X, ref acd.startpos.Y)) 4443 if (land != null && !TestLandRestrictions(acd.AgentID, out reason, ref acd.startpos.X, ref acd.startpos.Y))
3928 { 4444 {
3929 m_authenticateHandler.RemoveCircuit(acd.circuitcode); 4445 m_authenticateHandler.RemoveCircuit(acd.circuitcode);
@@ -3978,7 +4494,7 @@ namespace OpenSim.Region.Framework.Scenes
3978 if (CapsModule != null) 4494 if (CapsModule != null)
3979 { 4495 {
3980 CapsModule.SetAgentCapsSeeds(acd); 4496 CapsModule.SetAgentCapsSeeds(acd);
3981 CapsModule.CreateCaps(acd.AgentID); 4497 CapsModule.CreateCaps(acd.AgentID, acd.circuitcode);
3982 } 4498 }
3983 } 4499 }
3984 else 4500 else
@@ -3991,15 +4507,21 @@ namespace OpenSim.Region.Framework.Scenes
3991 { 4507 {
3992 m_log.DebugFormat( 4508 m_log.DebugFormat(
3993 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}", 4509 "[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
4510<<<<<<< HEAD
3994 acd.AgentID, RegionInfo.RegionName); 4511 acd.AgentID, RegionInfo.RegionName);
3995 4512
3996 sp.AdjustKnownSeeds(); 4513 sp.AdjustKnownSeeds();
4514=======
4515 acd.AgentID, RegionInfo.RegionName);
4516>>>>>>> avn/ubitvar
3997 4517
3998 if (CapsModule != null) 4518 if (CapsModule != null)
3999 { 4519 {
4000 CapsModule.SetAgentCapsSeeds(acd); 4520 CapsModule.SetAgentCapsSeeds(acd);
4001 CapsModule.CreateCaps(acd.AgentID); 4521 CapsModule.CreateCaps(acd.AgentID, acd.circuitcode);
4002 } 4522 }
4523
4524 sp.AdjustKnownSeeds();
4003 } 4525 }
4004 } 4526 }
4005 4527
@@ -4009,6 +4531,11 @@ namespace OpenSim.Region.Framework.Scenes
4009 CacheUserName(null, acd); 4531 CacheUserName(null, acd);
4010 } 4532 }
4011 4533
4534 if (CapsModule != null)
4535 {
4536 CapsModule.ActivateCaps(acd.circuitcode);
4537 }
4538
4012 if (vialogin) 4539 if (vialogin)
4013 { 4540 {
4014// CleanDroppedAttachments(); 4541// CleanDroppedAttachments();
@@ -4078,6 +4605,8 @@ namespace OpenSim.Region.Framework.Scenes
4078 } 4605 }
4079 4606
4080 // Honor parcel landing type and position. 4607 // Honor parcel landing type and position.
4608 /*
4609 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
4081 if (land != null) 4610 if (land != null)
4082 { 4611 {
4083 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 4612 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -4092,6 +4621,7 @@ namespace OpenSim.Region.Framework.Scenes
4092 } 4621 }
4093 } 4622 }
4094 } 4623 }
4624 */// This is now handled properly in ScenePresence.MakeRootAgent
4095 } 4625 }
4096 4626
4097 return true; 4627 return true;
@@ -4116,12 +4646,21 @@ namespace OpenSim.Region.Framework.Scenes
4116 { 4646 {
4117 if (posX < 0) 4647 if (posX < 0)
4118 posX = 0; 4648 posX = 0;
4649<<<<<<< HEAD
4119 else if (posX >= (float)RegionInfo.RegionSizeX) 4650 else if (posX >= (float)RegionInfo.RegionSizeX)
4120 posX = (float)RegionInfo.RegionSizeX - 0.001f; 4651 posX = (float)RegionInfo.RegionSizeX - 0.001f;
4121 if (posY < 0) 4652 if (posY < 0)
4122 posY = 0; 4653 posY = 0;
4123 else if (posY >= (float)RegionInfo.RegionSizeY) 4654 else if (posY >= (float)RegionInfo.RegionSizeY)
4124 posY = (float)RegionInfo.RegionSizeY - 0.001f; 4655 posY = (float)RegionInfo.RegionSizeY - 0.001f;
4656=======
4657 else if (posX >= RegionInfo.RegionSizeX)
4658 posX = RegionInfo.RegionSizeX - 0.5f;
4659 if (posY < 0)
4660 posY = 0;
4661 else if (posY >= RegionInfo.RegionSizeY)
4662 posY = RegionInfo.RegionSizeY - 0.5f;
4663>>>>>>> avn/ubitvar
4125 4664
4126 reason = String.Empty; 4665 reason = String.Empty;
4127 if (Permissions.IsGod(agentID)) 4666 if (Permissions.IsGod(agentID))
@@ -4225,7 +4764,8 @@ namespace OpenSim.Region.Framework.Scenes
4225 { 4764 {
4226 if (RegionInfo.EstateSettings != null) 4765 if (RegionInfo.EstateSettings != null)
4227 { 4766 {
4228 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID)) 4767 int flags = GetUserFlags(agent.AgentID);
4768 if (RegionInfo.EstateSettings.IsBanned(agent.AgentID, flags))
4229 { 4769 {
4230 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist", 4770 m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
4231 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName); 4771 agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
@@ -4414,6 +4954,22 @@ namespace OpenSim.Region.Framework.Scenes
4414 m_log.DebugFormat( 4954 m_log.DebugFormat(
4415 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName); 4955 "[SCENE]: Incoming child agent update for {0} in {1}", cAgentData.AgentID, RegionInfo.RegionName);
4416 4956
4957 if (!LoginsEnabled)
4958 {
4959// reason = "Logins Disabled";
4960 m_log.DebugFormat(
4961 "[SCENE]: update for {0} in {1} refused: Logins Disabled", cAgentData.AgentID, RegionInfo.RegionName);
4962 return false;
4963 }
4964 // We have to wait until the viewer contacts this region after receiving EAC.
4965 // That calls AddNewClient, which finally creates the ScenePresence
4966 int flags = GetUserFlags(cAgentData.AgentID);
4967 if (RegionInfo.EstateSettings.IsBanned(cAgentData.AgentID, flags))
4968 {
4969 m_log.DebugFormat("[SCENE]: Denying root agent entry to {0}: banned", cAgentData.AgentID);
4970 return false;
4971 }
4972
4417 // TODO: This check should probably be in QueryAccess(). 4973 // TODO: This check should probably be in QueryAccess().
4418 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, RegionInfo.RegionSizeX / 2, RegionInfo.RegionSizeY / 2); 4974 ILandObject nearestParcel = GetNearestAllowedParcel(cAgentData.AgentID, RegionInfo.RegionSizeX / 2, RegionInfo.RegionSizeY / 2);
4419 if (nearestParcel == null) 4975 if (nearestParcel == null)
@@ -4431,8 +4987,14 @@ namespace OpenSim.Region.Framework.Scenes
4431 // a UseCircuitCode packet which in turn calls AddNewAgent which finally creates the ScenePresence. 4987 // a UseCircuitCode packet which in turn calls AddNewAgent which finally creates the ScenePresence.
4432 ScenePresence sp = WaitGetScenePresence(cAgentData.AgentID); 4988 ScenePresence sp = WaitGetScenePresence(cAgentData.AgentID);
4433 4989
4434 if (sp != null) 4990 if (sp != null)
4435 { 4991 {
4992 if (!sp.IsChildAgent)
4993 {
4994 m_log.WarnFormat("[SCENE]: Ignoring a child update on a root agent {0} {1} in {2}",
4995 sp.Name, sp.UUID, Name);
4996 return false;
4997 }
4436 if (cAgentData.SessionID != sp.ControllingClient.SessionId) 4998 if (cAgentData.SessionID != sp.ControllingClient.SessionId)
4437 { 4999 {
4438 m_log.WarnFormat( 5000 m_log.WarnFormat(
@@ -4517,7 +5079,7 @@ namespace OpenSim.Region.Framework.Scenes
4517 /// <param name='agentID'></param> 5079 /// <param name='agentID'></param>
4518 protected virtual ScenePresence WaitGetScenePresence(UUID agentID) 5080 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
4519 { 5081 {
4520 int ntimes = 20; 5082 int ntimes = 30;
4521 ScenePresence sp = null; 5083 ScenePresence sp = null;
4522 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) 5084 while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0))
4523 Thread.Sleep(1000); 5085 Thread.Sleep(1000);
@@ -4567,6 +5129,16 @@ namespace OpenSim.Region.Framework.Scenes
4567 return false; 5129 return false;
4568 } 5130 }
4569 5131
5132// public bool IncomingCloseAgent(UUID agentID)
5133// {
5134// return IncomingCloseAgent(agentID, false);
5135// }
5136
5137// public bool IncomingCloseChildAgent(UUID agentID)
5138// {
5139// return IncomingCloseAgent(agentID, true);
5140// }
5141
4570 /// <summary> 5142 /// <summary>
4571 /// Tell a single client to prepare to close. 5143 /// Tell a single client to prepare to close.
4572 /// </summary> 5144 /// </summary>
@@ -4629,6 +5201,20 @@ namespace OpenSim.Region.Framework.Scenes
4629 5201
4630 if (sp == null) 5202 if (sp == null)
4631 { 5203 {
5204 // If there is no scene presence, we may be handling a dead
5205 // client. These can keep an avatar from reentering a region
5206 // and since they don't get cleaned up they will stick
5207 // around until region restart. So, if there is no SP,
5208 // remove the client as well.
5209 IClientAPI client = null;
5210 if (m_clientManager.TryGetValue(agentID, out client))
5211 {
5212 m_clientManager.Remove(agentID);
5213 if (CapsModule != null)
5214 CapsModule.RemoveCaps(agentID, 0);
5215 m_log.DebugFormat( "[SCENE]: Dead client for agent ID {0} was cleaned up in {1}", agentID, Name);
5216 return true;
5217 }
4632 m_log.DebugFormat( 5218 m_log.DebugFormat(
4633 "[SCENE]: Called CloseClient() with agent ID {0} but no such presence is in {1}", 5219 "[SCENE]: Called CloseClient() with agent ID {0} but no such presence is in {1}",
4634 agentID, Name); 5220 agentID, Name);
@@ -4663,7 +5249,15 @@ namespace OpenSim.Region.Framework.Scenes
4663 sp.LifecycleState = ScenePresenceState.Removing; 5249 sp.LifecycleState = ScenePresenceState.Removing;
4664 } 5250 }
4665 5251
5252<<<<<<< HEAD
4666 sp.ControllingClient.Close(force); 5253 sp.ControllingClient.Close(force);
5254=======
5255 if (sp != null)
5256 {
5257 sp.ControllingClient.Close(force, force);
5258 return true;
5259 }
5260>>>>>>> avn/ubitvar
4667 5261
4668 return true; 5262 return true;
4669 } 5263 }
@@ -4825,7 +5419,10 @@ namespace OpenSim.Region.Framework.Scenes
4825 5419
4826 public LandData GetLandData(float x, float y) 5420 public LandData GetLandData(float x, float y)
4827 { 5421 {
4828 return LandChannel.GetLandObject(x, y).LandData; 5422 ILandObject parcel = LandChannel.GetLandObject(x, y);
5423 if (parcel == null)
5424 return null;
5425 return parcel.LandData;
4829 } 5426 }
4830 5427
4831 /// <summary> 5428 /// <summary>
@@ -4841,7 +5438,10 @@ namespace OpenSim.Region.Framework.Scenes
4841 public LandData GetLandData(uint x, uint y) 5438 public LandData GetLandData(uint x, uint y)
4842 { 5439 {
4843 m_log.DebugFormat("[SCENE]: returning land for {0},{1}", x, y); 5440 m_log.DebugFormat("[SCENE]: returning land for {0},{1}", x, y);
4844 return LandChannel.GetLandObject((int)x, (int)y).LandData; 5441 ILandObject parcel = LandChannel.GetLandObject((int)x, (int)y);
5442 if (parcel == null)
5443 return null;
5444 return parcel.LandData;
4845 } 5445 }
4846 5446
4847 #endregion 5447 #endregion
@@ -5229,7 +5829,7 @@ namespace OpenSim.Region.Framework.Scenes
5229 { 5829 {
5230 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 5830 if ((grp.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
5231 { 5831 {
5232 if (grp.RootPart.Expires <= DateTime.Now) 5832 if (grp.GetSittingAvatarsCount() == 0 && grp.RootPart.Expires <= DateTime.Now)
5233 DeleteSceneObject(grp, false); 5833 DeleteSceneObject(grp, false);
5234 } 5834 }
5235 } 5835 }
@@ -5243,35 +5843,85 @@ namespace OpenSim.Region.Framework.Scenes
5243 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID); 5843 SimulationDataService.RemoveObject(uuid, RegionInfo.RegionID);
5244 } 5844 }
5245 5845
5246 public int GetHealth() 5846 public int GetHealth(out int flags, out string message)
5247 { 5847 {
5248 // Returns: 5848 // Returns:
5249 // 1 = sim is up and accepting http requests. The heartbeat has 5849 // 1 = sim is up and accepting http requests. The heartbeat has
5250 // stopped and the sim is probably locked up, but a remote 5850 // stopped and the sim is probably locked up, but a remote
5251 // admin restart may succeed 5851 // admin restart may succeed
5252 // 5852 //
5253 // 2 = Sim is up and the heartbeat is running. The sim is likely 5853 // 2 = Sim is up and the heartbeat is running. The sim is likely
5254 // usable for people within and logins _may_ work 5854 // usable for people within
5855 //
5856 // 3 = Sim is up and one packet thread is running. Sim is
5857 // unstable and will not accept new logins
5255 // 5858 //
5256 // 3 = We have seen a new user enter within the past 4 minutes 5859 // 4 = Sim is up and both packet threads are running. Sim is
5860 // likely usable
5861 //
5862 // 5 = We have seen a new user enter within the past 4 minutes
5257 // which can be seen as positive confirmation of sim health 5863 // which can be seen as positive confirmation of sim health
5258 // 5864 //
5865<<<<<<< HEAD
5259 int health = 1; // Start at 1, means we're up 5866 int health = 1; // Start at 1, means we're up
5867=======
5868
5869 flags = 0;
5870 message = String.Empty;
5871
5872 CheckHeartbeat();
5873
5874 if (m_firstHeartbeat || (m_lastIncoming == 0 && m_lastOutgoing == 0))
5875 {
5876 // We're still starting
5877 // 0 means "in startup", it can't happen another way, since
5878 // to get here, we must be able to accept http connections
5879 return 0;
5880 }
5881
5882 int health=1; // Start at 1, means we're up
5883>>>>>>> avn/ubitvar
5260 5884
5261 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000) 5885 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) < 1000)
5262 health += 1; 5886 {
5887 health+=1;
5888 flags |= 1;
5889 }
5890
5891 if (Util.EnvironmentTickCountSubtract(m_lastIncoming) < 1000)
5892 {
5893 health+=1;
5894 flags |= 2;
5895 }
5896
5897 if (Util.EnvironmentTickCountSubtract(m_lastOutgoing) < 1000)
5898 {
5899 health+=1;
5900 flags |= 4;
5901 }
5263 else 5902 else
5903 {
5904int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
5905System.Diagnostics.Process proc = new System.Diagnostics.Process();
5906proc.EnableRaisingEvents=false;
5907proc.StartInfo.FileName = "/bin/kill";
5908proc.StartInfo.Arguments = "-QUIT " + pid.ToString();
5909proc.Start();
5910proc.WaitForExit();
5911Thread.Sleep(1000);
5912Environment.Exit(1);
5913 }
5914
5915 if (flags != 7)
5264 return health; 5916 return health;
5265 5917
5266 // A login in the last 4 mins? We can't be doing too badly 5918 // A login in the last 4 mins? We can't be doing too badly
5267 // 5919 //
5268 if ((Util.EnvironmentTickCountSubtract(m_LastLogin)) < 240000) 5920 if (Util.EnvironmentTickCountSubtract(m_LastLogin) < 240000)
5269 health++; 5921 health++;
5270 else 5922 else
5271 return health; 5923 return health;
5272 5924
5273// CheckHeartbeat();
5274
5275 return health; 5925 return health;
5276 } 5926 }
5277 5927
@@ -5359,7 +6009,7 @@ namespace OpenSim.Region.Framework.Scenes
5359 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 6009 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
5360 if (wasUsingPhysics) 6010 if (wasUsingPhysics)
5361 { 6011 {
5362 jointProxyObject.UpdatePrimFlags(false, false, true, false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock 6012 jointProxyObject.UpdatePrimFlags(false, false, true, false,false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock
5363 } 6013 }
5364 } 6014 }
5365 6015
@@ -5462,14 +6112,14 @@ namespace OpenSim.Region.Framework.Scenes
5462 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z; 6112 return (((vsn.X * xdiff) + (vsn.Y * ydiff)) / (-1 * vsn.Z)) + p0.Z;
5463 } 6113 }
5464 6114
5465// private void CheckHeartbeat() 6115 private void CheckHeartbeat()
5466// { 6116 {
5467// if (m_firstHeartbeat) 6117 if (m_firstHeartbeat)
5468// return; 6118 return;
5469// 6119
5470// if (Util.EnvironmentTickCountSubtract(m_lastFrameTick) > 2000) 6120 if ((Util.EnvironmentTickCountSubtract(m_lastFrameTick)) > 5000)
5471// StartTimer(); 6121 Start();
5472// } 6122 }
5473 6123
5474 public override ISceneObject DeserializeObject(string representation) 6124 public override ISceneObject DeserializeObject(string representation)
5475 { 6125 {
@@ -5526,8 +6176,13 @@ namespace OpenSim.Region.Framework.Scenes
5526 //Go to the edge, this happens in teleporting to a region with no available parcels 6176 //Go to the edge, this happens in teleporting to a region with no available parcels
5527 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar); 6177 Vector3 nearestRegionEdgePoint = GetNearestRegionEdgePosition(avatar);
5528 6178
6179<<<<<<< HEAD
5529 //m_log.Debug("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString()); 6180 //m_log.Debug("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
5530 6181
6182=======
6183 //Debug.WriteLine("They are really in a place they don't belong, sending them to: " + nearestRegionEdgePoint.ToString());
6184
6185>>>>>>> avn/ubitvar
5531 return nearestRegionEdgePoint; 6186 return nearestRegionEdgePoint;
5532 } 6187 }
5533 6188
@@ -5783,7 +6438,55 @@ namespace OpenSim.Region.Framework.Scenes
5783 mapModule.GenerateMaptile(); 6438 mapModule.GenerateMaptile();
5784 } 6439 }
5785 6440
5786 private void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e) 6441// public void CleanDroppedAttachments()
6442// {
6443// List<SceneObjectGroup> objectsToDelete =
6444// new List<SceneObjectGroup>();
6445//
6446// lock (m_cleaningAttachments)
6447// {
6448// ForEachSOG(delegate (SceneObjectGroup grp)
6449// {
6450// if (grp.RootPart.Shape.PCode == 0 && grp.RootPart.Shape.State != 0 && (!objectsToDelete.Contains(grp)))
6451// {
6452// UUID agentID = grp.OwnerID;
6453// if (agentID == UUID.Zero)
6454// {
6455// objectsToDelete.Add(grp);
6456// return;
6457// }
6458//
6459// ScenePresence sp = GetScenePresence(agentID);
6460// if (sp == null)
6461// {
6462// objectsToDelete.Add(grp);
6463// return;
6464// }
6465// }
6466// });
6467// }
6468//
6469// foreach (SceneObjectGroup grp in objectsToDelete)
6470// {
6471// m_log.InfoFormat("[SCENE]: Deleting dropped attachment {0} of user {1}", grp.UUID, grp.OwnerID);
6472// DeleteSceneObject(grp, true);
6473// }
6474// }
6475
6476 public void ThreadAlive(int threadCode)
6477 {
6478 switch(threadCode)
6479 {
6480 case 1: // Incoming
6481 m_lastIncoming = Util.EnvironmentTickCount();
6482 break;
6483 case 2: // Incoming
6484 m_lastOutgoing = Util.EnvironmentTickCount();
6485 break;
6486 }
6487 }
6488
6489 public void RegenerateMaptileAndReregister(object sender, ElapsedEventArgs e)
5787 { 6490 {
5788 RegenerateMaptile(); 6491 RegenerateMaptile();
5789 6492
@@ -5810,7 +6513,11 @@ namespace OpenSim.Region.Framework.Scenes
5810 /// <param name='position'></param> 6513 /// <param name='position'></param>
5811 /// <param name='reason'></param> 6514 /// <param name='reason'></param>
5812 /// <returns></returns> 6515 /// <returns></returns>
6516<<<<<<< HEAD
5813 public bool QueryAccess(UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, List<UUID> features, out string reason) 6517 public bool QueryAccess(UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, List<UUID> features, out string reason)
6518=======
6519 public bool QueryAccess(UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, out string reason)
6520>>>>>>> avn/ubitvar
5814 { 6521 {
5815 reason = string.Empty; 6522 reason = string.Empty;
5816 6523
@@ -5820,8 +6527,14 @@ namespace OpenSim.Region.Framework.Scenes
5820 return true; 6527 return true;
5821 } 6528 }
5822 6529
6530<<<<<<< HEAD
5823 if (!AllowAvatarCrossing && !viaTeleport) 6531 if (!AllowAvatarCrossing && !viaTeleport)
5824 return false; 6532 return false;
6533=======
6534
6535// if (!AllowAvatarCrossing && !viaTeleport)
6536// return false;
6537>>>>>>> avn/ubitvar
5825 6538
5826 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. 6539 // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check.
5827 // However, the long term fix is to make sure root agent count is always accurate. 6540 // However, the long term fix is to make sure root agent count is always accurate.
@@ -5949,7 +6662,19 @@ namespace OpenSim.Region.Framework.Scenes
5949 return true; 6662 return true;
5950 } 6663 }
5951 6664
5952 /// <summary> 6665 public void StartTimerWatchdog()
6666 {
6667 m_timerWatchdog.Interval = 1000;
6668 m_timerWatchdog.Elapsed += TimerWatchdog;
6669 m_timerWatchdog.AutoReset = true;
6670 m_timerWatchdog.Start();
6671 }
6672
6673 public void TimerWatchdog(object sender, ElapsedEventArgs e)
6674 {
6675 CheckHeartbeat();
6676 }
6677
5953 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the 6678 /// This method deals with movement when an avatar is automatically moving (but this is distinct from the
5954 /// autopilot that moves an avatar to a sit target!. 6679 /// autopilot that moves an avatar to a sit target!.
5955 /// </summary> 6680 /// </summary>
@@ -6028,6 +6753,11 @@ namespace OpenSim.Region.Framework.Scenes
6028 return m_SpawnPoint - 1; 6753 return m_SpawnPoint - 1;
6029 } 6754 }
6030 6755
6756 private void HandleGcCollect(string module, string[] args)
6757 {
6758 GC.Collect();
6759 }
6760
6031 /// <summary> 6761 /// <summary>
6032 /// Wrappers to get physics modules retrieve assets. 6762 /// Wrappers to get physics modules retrieve assets.
6033 /// </summary> 6763 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index 7ff3d40..c4671f0 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -1,3 +1,4 @@
1<<<<<<< HEAD
1/* 2/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 3 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 4 * See CONTRIBUTORS.TXT for a full list of copyright holders.
@@ -634,3 +635,603 @@ namespace OpenSim.Region.Framework.Scenes
634 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep); 635 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep);
635 } 636 }
636} 637}
638=======
639/*
640 * Copyright (c) Contributors, http://opensimulator.org/
641 * See CONTRIBUTORS.TXT for a full list of copyright holders.
642 *
643 * Redistribution and use in source and binary forms, with or without
644 * modification, are permitted provided that the following conditions are met:
645 * * Redistributions of source code must retain the above copyright
646 * notice, this list of conditions and the following disclaimer.
647 * * Redistributions in binary form must reproduce the above copyright
648 * notice, this list of conditions and the following disclaimer in the
649 * documentation and/or other materials provided with the distribution.
650 * * Neither the name of the OpenSimulator Project nor the
651 * names of its contributors may be used to endorse or promote products
652 * derived from this software without specific prior written permission.
653 *
654 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
655 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
656 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
657 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
658 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
659 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
660 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
661 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
662 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
663 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
664 */
665
666using System;
667using System.Collections.Generic;
668using System.Reflection;
669using System.Threading;
670using OpenMetaverse;
671using log4net;
672using Nini.Config;
673using OpenSim.Framework;
674using OpenSim.Framework.Console;
675
676using OpenSim.Region.Framework.Interfaces;
677using GridRegion = OpenSim.Services.Interfaces.GridRegion;
678
679namespace OpenSim.Region.Framework.Scenes
680{
681 public abstract class SceneBase : IScene
682 {
683 protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
684 protected static readonly string LogHeader = "[SCENE]";
685
686 #region Events
687
688 public event restart OnRestart;
689
690 #endregion
691
692 #region Fields
693
694 public string Name { get { return RegionInfo.RegionName; } }
695
696 public IConfigSource Config
697 {
698 get { return GetConfig(); }
699 }
700
701 protected virtual IConfigSource GetConfig()
702 {
703 return null;
704 }
705
706 /// <value>
707 /// All the region modules attached to this scene.
708 /// </value>
709 public Dictionary<string, IRegionModuleBase> RegionModules
710 {
711 get { return m_regionModules; }
712 }
713 private Dictionary<string, IRegionModuleBase> m_regionModules = new Dictionary<string, IRegionModuleBase>();
714
715 /// <value>
716 /// The module interfaces available from this scene.
717 /// </value>
718 protected Dictionary<Type, List<object>> ModuleInterfaces = new Dictionary<Type, List<object>>();
719
720 protected Dictionary<string, object> ModuleAPIMethods = new Dictionary<string, object>();
721
722 /// <value>
723 /// The module commanders available from this scene
724 /// </value>
725 protected Dictionary<string, ICommander> m_moduleCommanders = new Dictionary<string, ICommander>();
726
727 /// <value>
728 /// Registered classes that are capable of creating entities.
729 /// </value>
730 protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
731
732 /// <summary>
733 /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
734 /// dispensed.
735 /// </summary>
736 protected uint m_lastAllocatedLocalId = 720000;
737
738 private readonly Mutex _primAllocateMutex = new Mutex(false);
739
740 protected readonly ClientManager m_clientManager = new ClientManager();
741
742 public bool LoginsEnabled
743 {
744 get
745 {
746 return m_loginsEnabled;
747 }
748
749 set
750 {
751 if (m_loginsEnabled != value)
752 {
753 m_loginsEnabled = value;
754 EventManager.TriggerRegionLoginsStatusChange(this);
755 }
756 }
757 }
758 private bool m_loginsEnabled;
759
760 public bool Ready
761 {
762 get
763 {
764 return m_ready;
765 }
766
767 set
768 {
769 if (m_ready != value)
770 {
771 m_ready = value;
772 EventManager.TriggerRegionReadyStatusChange(this);
773 }
774 }
775 }
776 private bool m_ready;
777
778 public float TimeDilation
779 {
780 get { return 1.0f; }
781 }
782
783 protected ulong m_regionHandle;
784 protected string m_regionName;
785
786 public ITerrainChannel Heightmap;
787
788 /// <value>
789 /// Allows retrieval of land information for this scene.
790 /// </value>
791 public ILandChannel LandChannel;
792
793 /// <value>
794 /// Manage events that occur in this scene (avatar movement, script rez, etc.). Commonly used by region modules
795 /// to subscribe to scene events.
796 /// </value>
797 public EventManager EventManager
798 {
799 get { return m_eventManager; }
800 }
801 protected EventManager m_eventManager;
802
803 protected ScenePermissions m_permissions;
804 public ScenePermissions Permissions
805 {
806 get { return m_permissions; }
807 }
808
809 protected string m_datastore;
810
811 /* Used by the loadbalancer plugin on GForge */
812 protected RegionStatus m_regStatus;
813 public RegionStatus RegionStatus
814 {
815 get { return m_regStatus; }
816 set { m_regStatus = value; }
817 }
818
819 #endregion
820
821 public SceneBase(RegionInfo regInfo)
822 {
823 RegionInfo = regInfo;
824 }
825
826 #region Update Methods
827
828 /// <summary>
829 /// Called to update the scene loop by a number of frames and until shutdown.
830 /// </summary>
831 /// <param name="frames">
832 /// Number of frames to update. Exits on shutdown even if there are frames remaining.
833 /// If -1 then updates until shutdown.
834 /// </param>
835 public abstract void Update(int frames);
836
837 #endregion
838
839 #region Terrain Methods
840
841 /// <summary>
842 /// Loads the World heightmap
843 /// </summary>
844 public abstract void LoadWorldMap();
845
846 /// <summary>
847 /// Send the region heightmap to the client
848 /// </summary>
849 /// <param name="RemoteClient">Client to send to</param>
850 public virtual void SendLayerData(IClientAPI RemoteClient)
851 {
852// RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
853 ITerrainModule terrModule = RequestModuleInterface<ITerrainModule>();
854 if (terrModule != null)
855 {
856 terrModule.PushTerrain(RemoteClient);
857 }
858 }
859
860 #endregion
861
862 #region Add/Remove Agent/Avatar
863
864 public abstract ISceneAgent AddNewAgent(IClientAPI client, PresenceType type);
865
866 public abstract bool CloseAgent(UUID agentID, bool force);
867
868 public bool TryGetScenePresence(UUID agentID, out object scenePresence)
869 {
870 scenePresence = null;
871 ScenePresence sp = null;
872 if (TryGetScenePresence(agentID, out sp))
873 {
874 scenePresence = sp;
875 return true;
876 }
877
878 return false;
879 }
880
881 /// <summary>
882 /// Try to get a scene presence from the scene
883 /// </summary>
884 /// <param name="agentID"></param>
885 /// <param name="scenePresence">null if there is no scene presence with the given agent id</param>
886 /// <returns>true if there was a scene presence with the given id, false otherwise.</returns>
887 public abstract bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence);
888
889 #endregion
890
891 /// <summary>
892 ///
893 /// </summary>
894 /// <returns></returns>
895 public virtual RegionInfo RegionInfo { get; private set; }
896
897 #region admin stuff
898
899 public abstract void OtherRegionUp(GridRegion otherRegion);
900
901 public virtual string GetSimulatorVersion()
902 {
903 return "OpenSimulator Server";
904 }
905
906 #endregion
907
908 #region Shutdown
909
910 /// <summary>
911 /// Tidy before shutdown
912 /// </summary>
913 public virtual void Close()
914 {
915 try
916 {
917 EventManager.TriggerShutdown();
918 }
919 catch (Exception e)
920 {
921 m_log.Error(string.Format("[SCENE]: SceneBase.cs: Close() - Failed with exception ", e));
922 }
923 }
924
925 #endregion
926
927 /// <summary>
928 /// Returns a new unallocated local ID
929 /// </summary>
930 /// <returns>A brand new local ID</returns>
931 public uint AllocateLocalId()
932 {
933 uint myID;
934
935 _primAllocateMutex.WaitOne();
936 myID = ++m_lastAllocatedLocalId;
937 _primAllocateMutex.ReleaseMutex();
938
939 return myID;
940 }
941
942 public uint AllocatePresenceLocalId()
943 {
944 uint myID;
945
946 _primAllocateMutex.WaitOne();
947 myID = ++m_lastAllocatedLocalId;
948 ++m_lastAllocatedLocalId;
949 _primAllocateMutex.ReleaseMutex();
950
951 return myID;
952 }
953
954 #region Module Methods
955
956 /// <summary>
957 /// Add a region-module to this scene. TODO: This will replace AddModule in the future.
958 /// </summary>
959 /// <param name="name"></param>
960 /// <param name="module"></param>
961 public void AddRegionModule(string name, IRegionModuleBase module)
962 {
963 if (!RegionModules.ContainsKey(name))
964 {
965 RegionModules.Add(name, module);
966 }
967 }
968
969 public void RemoveRegionModule(string name)
970 {
971 RegionModules.Remove(name);
972 }
973
974 /// <summary>
975 /// Register a module commander.
976 /// </summary>
977 /// <param name="commander"></param>
978 public void RegisterModuleCommander(ICommander commander)
979 {
980 lock (m_moduleCommanders)
981 {
982 m_moduleCommanders.Add(commander.Name, commander);
983 }
984 }
985
986 /// <summary>
987 /// Unregister a module commander and all its commands
988 /// </summary>
989 /// <param name="name"></param>
990 public void UnregisterModuleCommander(string name)
991 {
992 lock (m_moduleCommanders)
993 {
994 ICommander commander;
995 if (m_moduleCommanders.TryGetValue(name, out commander))
996 m_moduleCommanders.Remove(name);
997 }
998 }
999
1000 /// <summary>
1001 /// Get a module commander
1002 /// </summary>
1003 /// <param name="name"></param>
1004 /// <returns>The module commander, null if no module commander with that name was found</returns>
1005 public ICommander GetCommander(string name)
1006 {
1007 lock (m_moduleCommanders)
1008 {
1009 if (m_moduleCommanders.ContainsKey(name))
1010 return m_moduleCommanders[name];
1011 }
1012
1013 return null;
1014 }
1015
1016 public Dictionary<string, ICommander> GetCommanders()
1017 {
1018 return m_moduleCommanders;
1019 }
1020
1021 /// <summary>
1022 /// Register an interface to a region module. This allows module methods to be called directly as
1023 /// well as via events. If there is already a module registered for this interface, it is not replaced
1024 /// (is this the best behaviour?)
1025 /// </summary>
1026 /// <param name="mod"></param>
1027 public void RegisterModuleInterface<M>(M mod)
1028 {
1029// m_log.DebugFormat("[SCENE BASE]: Registering interface {0}", typeof(M));
1030
1031 List<Object> l = null;
1032 if (!ModuleInterfaces.TryGetValue(typeof(M), out l))
1033 {
1034 l = new List<Object>();
1035 ModuleInterfaces.Add(typeof(M), l);
1036 }
1037
1038 if (l.Count > 0)
1039 return;
1040
1041 l.Add(mod);
1042
1043 if (mod is IEntityCreator)
1044 {
1045 IEntityCreator entityCreator = (IEntityCreator)mod;
1046 foreach (PCode pcode in entityCreator.CreationCapabilities)
1047 {
1048 m_entityCreators[pcode] = entityCreator;
1049 }
1050 }
1051 }
1052
1053 public void UnregisterModuleInterface<M>(M mod)
1054 {
1055 List<Object> l;
1056 if (ModuleInterfaces.TryGetValue(typeof(M), out l))
1057 {
1058 if (l.Remove(mod))
1059 {
1060 if (mod is IEntityCreator)
1061 {
1062 IEntityCreator entityCreator = (IEntityCreator)mod;
1063 foreach (PCode pcode in entityCreator.CreationCapabilities)
1064 {
1065 m_entityCreators[pcode] = null;
1066 }
1067 }
1068 }
1069 }
1070 }
1071
1072 public void StackModuleInterface<M>(M mod)
1073 {
1074 List<Object> l;
1075 if (ModuleInterfaces.ContainsKey(typeof(M)))
1076 l = ModuleInterfaces[typeof(M)];
1077 else
1078 l = new List<Object>();
1079
1080 if (l.Contains(mod))
1081 return;
1082
1083 l.Add(mod);
1084
1085 if (mod is IEntityCreator)
1086 {
1087 IEntityCreator entityCreator = (IEntityCreator)mod;
1088 foreach (PCode pcode in entityCreator.CreationCapabilities)
1089 {
1090 m_entityCreators[pcode] = entityCreator;
1091 }
1092 }
1093
1094 ModuleInterfaces[typeof(M)] = l;
1095 }
1096
1097 /// <summary>
1098 /// For the given interface, retrieve the region module which implements it.
1099 /// </summary>
1100 /// <returns>null if there is no registered module implementing that interface</returns>
1101 public T RequestModuleInterface<T>()
1102 {
1103 if (ModuleInterfaces.ContainsKey(typeof(T)) &&
1104 (ModuleInterfaces[typeof(T)].Count > 0))
1105 return (T)ModuleInterfaces[typeof(T)][0];
1106 else
1107 return default(T);
1108 }
1109
1110 /// <summary>
1111 /// For the given interface, retrieve an array of region modules that implement it.
1112 /// </summary>
1113 /// <returns>an empty array if there are no registered modules implementing that interface</returns>
1114 public T[] RequestModuleInterfaces<T>()
1115 {
1116 if (ModuleInterfaces.ContainsKey(typeof(T)))
1117 {
1118 List<T> ret = new List<T>();
1119
1120 foreach (Object o in ModuleInterfaces[typeof(T)])
1121 ret.Add((T)o);
1122 return ret.ToArray();
1123 }
1124 else
1125 {
1126 return new T[] {};
1127 }
1128 }
1129
1130 #endregion
1131
1132 /// <summary>
1133 /// Call this from a region module to add a command to the OpenSim console.
1134 /// </summary>
1135 /// <param name="mod"></param>
1136 /// <param name="command"></param>
1137 /// <param name="shorthelp"></param>
1138 /// <param name="longhelp"></param>
1139 /// <param name="callback"></param>
1140 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
1141 {
1142 AddCommand(module, command, shorthelp, longhelp, string.Empty, callback);
1143 }
1144
1145 /// <summary>
1146 /// Call this from a region module to add a command to the OpenSim console.
1147 /// </summary>
1148 /// <param name="mod">
1149 /// The use of IRegionModuleBase is a cheap trick to get a different method signature,
1150 /// though all new modules should be using interfaces descended from IRegionModuleBase anyway.
1151 /// </param>
1152 /// <param name="category">
1153 /// Category of the command. This is the section under which it will appear when the user asks for help
1154 /// </param>
1155 /// <param name="command"></param>
1156 /// <param name="shorthelp"></param>
1157 /// <param name="longhelp"></param>
1158 /// <param name="callback"></param>
1159 public void AddCommand(
1160 string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
1161 {
1162 AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback);
1163 }
1164
1165 /// <summary>
1166 /// Call this from a region module to add a command to the OpenSim console.
1167 /// </summary>
1168 /// <param name="mod"></param>
1169 /// <param name="command"></param>
1170 /// <param name="shorthelp"></param>
1171 /// <param name="longhelp"></param>
1172 /// <param name="descriptivehelp"></param>
1173 /// <param name="callback"></param>
1174 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
1175 {
1176 string moduleName = "";
1177
1178 if (module != null)
1179 moduleName = module.Name;
1180
1181 AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
1182 }
1183
1184 /// <summary>
1185 /// Call this from a region module to add a command to the OpenSim console.
1186 /// </summary>
1187 /// <param name="category">
1188 /// Category of the command. This is the section under which it will appear when the user asks for help
1189 /// </param>
1190 /// <param name="mod"></param>
1191 /// <param name="command"></param>
1192 /// <param name="shorthelp"></param>
1193 /// <param name="longhelp"></param>
1194 /// <param name="descriptivehelp"></param>
1195 /// <param name="callback"></param>
1196 public void AddCommand(
1197 string category, IRegionModuleBase module, string command,
1198 string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
1199 {
1200 if (MainConsole.Instance == null)
1201 return;
1202
1203 bool shared = false;
1204
1205 if (module != null)
1206 shared = module is ISharedRegionModule;
1207
1208 MainConsole.Instance.Commands.AddCommand(
1209 category, shared, command, shorthelp, longhelp, descriptivehelp, callback);
1210 }
1211
1212 public virtual ISceneObject DeserializeObject(string representation)
1213 {
1214 return null;
1215 }
1216
1217 public virtual bool AllowScriptCrossings
1218 {
1219 get { return false; }
1220 }
1221
1222 public virtual void Start()
1223 {
1224 }
1225
1226 public void Restart()
1227 {
1228 // This has to be here to fire the event
1229 restart handlerPhysicsCrash = OnRestart;
1230 if (handlerPhysicsCrash != null)
1231 handlerPhysicsCrash(RegionInfo);
1232 }
1233
1234 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep);
1235 }
1236}
1237>>>>>>> avn/ubitvar
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index c8c8714..df7a72a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -219,8 +219,11 @@ namespace OpenSim.Region.Framework.Scenes
219 } 219 }
220 } 220 }
221 221
222 public delegate void SendCloseChildAgentDelegate(UUID agentID, ulong regionHandle);
223
222 /// <summary> 224 /// <summary>
223 /// Closes a child agent on a given region 225 /// This Closes child agents on neighboring regions
226 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
224 /// </summary> 227 /// </summary>
225 protected void SendCloseChildAgent(UUID agentID, ulong regionHandle, string auth_token) 228 protected void SendCloseChildAgent(UUID agentID, ulong regionHandle, string auth_token)
226 { 229 {
@@ -248,7 +251,7 @@ namespace OpenSim.Region.Framework.Scenes
248 { 251 {
249 foreach (ulong handle in regionslst) 252 foreach (ulong handle in regionslst)
250 { 253 {
251 // We must take a copy here since handle is acts like a reference when used in an iterator. 254 // We must take a copy here since handle acts like a reference when used in an iterator.
252 // This leads to race conditions if directly passed to SendCloseChildAgent with more than one neighbour region. 255 // This leads to race conditions if directly passed to SendCloseChildAgent with more than one neighbour region.
253 ulong handleCopy = handle; 256 ulong handleCopy = handle;
254 Util.FireAndForget( 257 Util.FireAndForget(
@@ -257,10 +260,10 @@ namespace OpenSim.Region.Framework.Scenes
257 "SceneCommunicationService.SendCloseChildAgentConnections"); 260 "SceneCommunicationService.SendCloseChildAgentConnections");
258 } 261 }
259 } 262 }
260 263
261 public List<GridRegion> RequestNamedRegions(string name, int maxNumber) 264 public List<GridRegion> RequestNamedRegions(string name, int maxNumber)
262 { 265 {
263 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); 266 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber);
264 } 267 }
265 } 268 }
266} \ No newline at end of file 269}
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index c2e9b61..3f6a7f8 100755
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -41,6 +41,12 @@ namespace OpenSim.Region.Framework.Scenes
41{ 41{
42 public delegate void PhysicsCrash(); 42 public delegate void PhysicsCrash();
43 43
44 public delegate void AttachToBackupDelegate(SceneObjectGroup sog);
45
46 public delegate void DetachFromBackupDelegate(SceneObjectGroup sog);
47
48 public delegate void ChangedBackupDelegate(SceneObjectGroup sog);
49
44 /// <summary> 50 /// <summary>
45 /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components 51 /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components
46 /// should be migrated out over time. 52 /// should be migrated out over time.
@@ -54,11 +60,15 @@ namespace OpenSim.Region.Framework.Scenes
54 protected internal event PhysicsCrash UnRecoverableError; 60 protected internal event PhysicsCrash UnRecoverableError;
55 private PhysicsCrash handlerPhysicsCrash = null; 61 private PhysicsCrash handlerPhysicsCrash = null;
56 62
63 public event AttachToBackupDelegate OnAttachToBackup;
64 public event DetachFromBackupDelegate OnDetachFromBackup;
65 public event ChangedBackupDelegate OnChangeBackup;
66
57 #endregion 67 #endregion
58 68
59 #region Fields 69 #region Fields
60 70
61 protected object m_presenceLock = new object(); 71 protected OpenMetaverse.ReaderWriterLockSlim m_scenePresencesLock = new OpenMetaverse.ReaderWriterLockSlim();
62 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); 72 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>();
63 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); 73 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>();
64 74
@@ -129,13 +139,18 @@ namespace OpenSim.Region.Framework.Scenes
129 139
130 protected internal void Close() 140 protected internal void Close()
131 { 141 {
132 lock (m_presenceLock) 142 m_scenePresencesLock.EnterWriteLock();
143 try
133 { 144 {
134 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); 145 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
135 List<ScenePresence> newlist = new List<ScenePresence>(); 146 List<ScenePresence> newlist = new List<ScenePresence>();
136 m_scenePresenceMap = newmap; 147 m_scenePresenceMap = newmap;
137 m_scenePresenceArray = newlist; 148 m_scenePresenceArray = newlist;
138 } 149 }
150 finally
151 {
152 m_scenePresencesLock.ExitWriteLock();
153 }
139 154
140 lock (SceneObjectGroupsByFullID) 155 lock (SceneObjectGroupsByFullID)
141 SceneObjectGroupsByFullID.Clear(); 156 SceneObjectGroupsByFullID.Clear();
@@ -256,13 +271,54 @@ namespace OpenSim.Region.Framework.Scenes
256 protected internal bool AddRestoredSceneObject( 271 protected internal bool AddRestoredSceneObject(
257 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 272 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
258 { 273 {
274 if (!m_parentScene.CombineRegions)
275 {
276 // temporary checks to remove after varsize suport
277 float regionSizeX = m_parentScene.RegionInfo.RegionSizeX;
278 if (regionSizeX == 0)
279 regionSizeX = Constants.RegionSize;
280 float regionSizeY = m_parentScene.RegionInfo.RegionSizeY;
281 if (regionSizeY == 0)
282 regionSizeY = Constants.RegionSize;
283
284 // KF: Check for out-of-region, move inside and make static.
285 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
286 sceneObject.RootPart.GroupPosition.Y,
287 sceneObject.RootPart.GroupPosition.Z);
288 if (!(((sceneObject.RootPart.Shape.PCode == (byte)PCode.Prim) && (sceneObject.RootPart.Shape.State != 0))) && (npos.X < 0.0 || npos.Y < 0.0 || npos.Z < 0.0 ||
289 npos.X > regionSizeX ||
290 npos.Y > regionSizeY))
291 {
292 if (npos.X < 0.0) npos.X = 1.0f;
293 if (npos.Y < 0.0) npos.Y = 1.0f;
294 if (npos.Z < 0.0) npos.Z = 0.0f;
295 if (npos.X > regionSizeX) npos.X = regionSizeX - 1.0f;
296 if (npos.Y > regionSizeY) npos.Y = regionSizeY - 1.0f;
297
298 SceneObjectPart rootpart = sceneObject.RootPart;
299 rootpart.GroupPosition = npos;
300
301 foreach (SceneObjectPart part in sceneObject.Parts)
302 {
303 if (part == rootpart)
304 continue;
305 part.GroupPosition = npos;
306 }
307 rootpart.Velocity = Vector3.Zero;
308 rootpart.AngularVelocity = Vector3.Zero;
309 rootpart.Acceleration = Vector3.Zero;
310 }
311 }
312
313 bool ret = AddSceneObject(sceneObject, attachToBackup, sendClientUpdates);
314
259 if (attachToBackup && (!alreadyPersisted)) 315 if (attachToBackup && (!alreadyPersisted))
260 { 316 {
261 sceneObject.ForceInventoryPersistence(); 317 sceneObject.ForceInventoryPersistence();
262 sceneObject.HasGroupChanged = true; 318 sceneObject.HasGroupChanged = true;
263 } 319 }
264 320
265 return AddSceneObject(sceneObject, attachToBackup, sendClientUpdates); 321 return ret;
266 } 322 }
267 323
268 /// <summary> 324 /// <summary>
@@ -279,12 +335,16 @@ namespace OpenSim.Region.Framework.Scenes
279 /// </returns> 335 /// </returns>
280 protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) 336 protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
281 { 337 {
282 // Ensure that we persist this new scene object if it's not an 338
339 bool ret = AddSceneObject(sceneObject, attachToBackup, sendClientUpdates);
340
341 // Ensure that we persist this new scene object if it's not an
283 // attachment 342 // attachment
343
284 if (attachToBackup) 344 if (attachToBackup)
285 sceneObject.HasGroupChanged = true; 345 sceneObject.HasGroupChanged = true;
286 346
287 return AddSceneObject(sceneObject, attachToBackup, sendClientUpdates); 347 return ret;
288 } 348 }
289 349
290 /// <summary> 350 /// <summary>
@@ -319,9 +379,8 @@ namespace OpenSim.Region.Framework.Scenes
319 if (pa != null && pa.IsPhysical && vel != Vector3.Zero) 379 if (pa != null && pa.IsPhysical && vel != Vector3.Zero)
320 { 380 {
321 sceneObject.RootPart.ApplyImpulse((vel * sceneObject.GetMass()), false); 381 sceneObject.RootPart.ApplyImpulse((vel * sceneObject.GetMass()), false);
322 sceneObject.Velocity = vel;
323 } 382 }
324 383
325 return true; 384 return true;
326 } 385 }
327 386
@@ -346,6 +405,11 @@ namespace OpenSim.Region.Framework.Scenes
346 /// </returns> 405 /// </returns>
347 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) 406 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
348 { 407 {
408 if (sceneObject == null)
409 {
410 m_log.ErrorFormat("[SCENEGRAPH]: Tried to add null scene object");
411 return false;
412 }
349 if (sceneObject.UUID == UUID.Zero) 413 if (sceneObject.UUID == UUID.Zero)
350 { 414 {
351 m_log.ErrorFormat( 415 m_log.ErrorFormat(
@@ -378,9 +442,9 @@ namespace OpenSim.Region.Framework.Scenes
378 { 442 {
379 Vector3 scale = part.Shape.Scale; 443 Vector3 scale = part.Shape.Scale;
380 444
381 scale.X = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.X)); 445 scale.X = Util.Clamp(scale.X, m_parentScene.m_minNonphys, m_parentScene.m_maxNonphys);
382 scale.Y = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.Y)); 446 scale.Y = Util.Clamp(scale.Y, m_parentScene.m_minNonphys, m_parentScene.m_maxNonphys);
383 scale.Z = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.Z)); 447 scale.Z = Util.Clamp(scale.Z, m_parentScene.m_minNonphys, m_parentScene.m_maxNonphys);
384 448
385 part.Shape.Scale = scale; 449 part.Shape.Scale = scale;
386 } 450 }
@@ -401,36 +465,39 @@ namespace OpenSim.Region.Framework.Scenes
401 465
402 sceneObject.AttachToScene(m_parentScene); 466 sceneObject.AttachToScene(m_parentScene);
403 467
404 if (sendClientUpdates)
405 sceneObject.ScheduleGroupForFullUpdate();
406
407 Entities.Add(sceneObject); 468 Entities.Add(sceneObject);
408 469
409 if (attachToBackup)
410 sceneObject.AttachToBackup();
411
412 lock (SceneObjectGroupsByFullID) 470 lock (SceneObjectGroupsByFullID)
413 SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; 471 SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject;
414 472
415 lock (SceneObjectGroupsByFullPartID) 473 foreach (SceneObjectPart part in parts)
416 { 474 {
417 foreach (SceneObjectPart part in parts) 475 lock (SceneObjectGroupsByFullPartID)
418 SceneObjectGroupsByFullPartID[part.UUID] = sceneObject; 476 SceneObjectGroupsByFullPartID[part.UUID] = sceneObject;
419 }
420
421 lock (SceneObjectGroupsByLocalPartID)
422 {
423// m_log.DebugFormat(
424// "[SCENE GRAPH]: Adding scene object {0} {1} {2} to SceneObjectGroupsByLocalPartID in {3}",
425// sceneObject.Name, sceneObject.UUID, sceneObject.LocalId, m_parentScene.RegionInfo.RegionName);
426 477
427 foreach (SceneObjectPart part in parts) 478 lock (SceneObjectGroupsByLocalPartID)
428 SceneObjectGroupsByLocalPartID[part.LocalId] = sceneObject; 479 SceneObjectGroupsByLocalPartID[part.LocalId] = sceneObject;
429 } 480 }
430 481
482 if (sendClientUpdates)
483 sceneObject.ScheduleGroupForFullUpdate();
484
485 if (attachToBackup)
486 sceneObject.AttachToBackup();
487
431 return true; 488 return true;
432 } 489 }
433 490
491 public void updateScenePartGroup(SceneObjectPart part, SceneObjectGroup grp)
492 {
493 // no tests, caller has responsability...
494 lock (SceneObjectGroupsByFullPartID)
495 SceneObjectGroupsByFullPartID[part.UUID] = grp;
496
497 lock (SceneObjectGroupsByLocalPartID)
498 SceneObjectGroupsByLocalPartID[part.LocalId] = grp;
499 }
500
434 /// <summary> 501 /// <summary>
435 /// Delete an object from the scene 502 /// Delete an object from the scene
436 /// </summary> 503 /// </summary>
@@ -471,25 +538,23 @@ namespace OpenSim.Region.Framework.Scenes
471 if ((grp.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics) 538 if ((grp.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics)
472 RemovePhysicalPrim(grp.PrimCount); 539 RemovePhysicalPrim(grp.PrimCount);
473 } 540 }
474 541
542 bool ret = Entities.Remove(uuid);
543
475 lock (SceneObjectGroupsByFullID) 544 lock (SceneObjectGroupsByFullID)
476 SceneObjectGroupsByFullID.Remove(grp.UUID); 545 SceneObjectGroupsByFullID.Remove(grp.UUID);
477 546
478 lock (SceneObjectGroupsByFullPartID) 547 SceneObjectPart[] parts = grp.Parts;
548 for (int i = 0; i < parts.Length; i++)
479 { 549 {
480 SceneObjectPart[] parts = grp.Parts; 550 lock (SceneObjectGroupsByFullPartID)
481 for (int i = 0; i < parts.Length; i++)
482 SceneObjectGroupsByFullPartID.Remove(parts[i].UUID); 551 SceneObjectGroupsByFullPartID.Remove(parts[i].UUID);
483 }
484 552
485 lock (SceneObjectGroupsByLocalPartID) 553 lock (SceneObjectGroupsByLocalPartID)
486 {
487 SceneObjectPart[] parts = grp.Parts;
488 for (int i = 0; i < parts.Length; i++)
489 SceneObjectGroupsByLocalPartID.Remove(parts[i].LocalId); 554 SceneObjectGroupsByLocalPartID.Remove(parts[i].LocalId);
490 } 555 }
491 556
492 return Entities.Remove(uuid); 557 return ret;
493 } 558 }
494 559
495 /// <summary> 560 /// <summary>
@@ -504,6 +569,30 @@ namespace OpenSim.Region.Framework.Scenes
504 m_updateList[obj.UUID] = obj; 569 m_updateList[obj.UUID] = obj;
505 } 570 }
506 571
572 public void FireAttachToBackup(SceneObjectGroup obj)
573 {
574 if (OnAttachToBackup != null)
575 {
576 OnAttachToBackup(obj);
577 }
578 }
579
580 public void FireDetachFromBackup(SceneObjectGroup obj)
581 {
582 if (OnDetachFromBackup != null)
583 {
584 OnDetachFromBackup(obj);
585 }
586 }
587
588 public void FireChangeBackup(SceneObjectGroup obj)
589 {
590 if (OnChangeBackup != null)
591 {
592 OnChangeBackup(obj);
593 }
594 }
595
507 /// <summary> 596 /// <summary>
508 /// Process all pending updates 597 /// Process all pending updates
509 /// </summary> 598 /// </summary>
@@ -595,7 +684,8 @@ namespace OpenSim.Region.Framework.Scenes
595 684
596 Entities[presence.UUID] = presence; 685 Entities[presence.UUID] = presence;
597 686
598 lock (m_presenceLock) 687 m_scenePresencesLock.EnterWriteLock();
688 try
599 { 689 {
600 m_numChildAgents++; 690 m_numChildAgents++;
601 691
@@ -621,6 +711,10 @@ namespace OpenSim.Region.Framework.Scenes
621 m_scenePresenceMap = newmap; 711 m_scenePresenceMap = newmap;
622 m_scenePresenceArray = newlist; 712 m_scenePresenceArray = newlist;
623 } 713 }
714 finally
715 {
716 m_scenePresencesLock.ExitWriteLock();
717 }
624 718
625 return presence; 719 return presence;
626 } 720 }
@@ -637,7 +731,8 @@ namespace OpenSim.Region.Framework.Scenes
637 agentID); 731 agentID);
638 } 732 }
639 733
640 lock (m_presenceLock) 734 m_scenePresencesLock.EnterWriteLock();
735 try
641 { 736 {
642 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); 737 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
643 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); 738 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
@@ -659,6 +754,10 @@ namespace OpenSim.Region.Framework.Scenes
659 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); 754 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
660 } 755 }
661 } 756 }
757 finally
758 {
759 m_scenePresencesLock.ExitWriteLock();
760 }
662 } 761 }
663 762
664 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) 763 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
@@ -887,7 +986,7 @@ namespace OpenSim.Region.Framework.Scenes
887 m_log.WarnFormat( 986 m_log.WarnFormat(
888 "[SCENE GRAPH]: Found scene object {0} {1} {2} via SceneObjectGroupsByLocalPartID index but it doesn't contain part with local id {3}. Removing from entry from index in {4}.", 987 "[SCENE GRAPH]: Found scene object {0} {1} {2} via SceneObjectGroupsByLocalPartID index but it doesn't contain part with local id {3}. Removing from entry from index in {4}.",
889 sog.Name, sog.UUID, sog.LocalId, localID, m_parentScene.RegionInfo.RegionName); 988 sog.Name, sog.UUID, sog.LocalId, localID, m_parentScene.RegionInfo.RegionName);
890 989 m_log.WarnFormat("stack: {0}", Environment.StackTrace);
891 SceneObjectGroupsByLocalPartID.Remove(localID); 990 SceneObjectGroupsByLocalPartID.Remove(localID);
892 } 991 }
893 } 992 }
@@ -1223,6 +1322,52 @@ namespace OpenSim.Region.Framework.Scenes
1223 1322
1224 #region Client Event handlers 1323 #region Client Event handlers
1225 1324
1325 protected internal void ClientChangeObject(uint localID, object odata, IClientAPI remoteClient)
1326 {
1327 SceneObjectPart part = GetSceneObjectPart(localID);
1328 ObjectChangeData data = (ObjectChangeData)odata;
1329
1330 if (part != null)
1331 {
1332 SceneObjectGroup grp = part.ParentGroup;
1333 if (grp != null)
1334 {
1335 if (m_parentScene.Permissions.CanEditObject(grp.UUID, remoteClient.AgentId))
1336 {
1337 // These two are exceptions SL makes in the interpretation
1338 // of the change flags. Must check them here because otherwise
1339 // the group flag (see below) would be lost
1340 if (data.change == ObjectChangeType.groupS)
1341 data.change = ObjectChangeType.primS;
1342 if (data.change == ObjectChangeType.groupPS)
1343 data.change = ObjectChangeType.primPS;
1344 part.StoreUndoState(data.change); // lets test only saving what we changed
1345 grp.doChangeObject(part, (ObjectChangeData)data);
1346 }
1347 else
1348 {
1349 // Is this any kind of group operation?
1350 if ((data.change & ObjectChangeType.Group) != 0)
1351 {
1352 // Is a move and/or rotation requested?
1353 if ((data.change & (ObjectChangeType.Position | ObjectChangeType.Rotation)) != 0)
1354 {
1355 // Are we allowed to move it?
1356 if (m_parentScene.Permissions.CanMoveObject(grp.UUID, remoteClient.AgentId))
1357 {
1358 // Strip all but move and rotation from request
1359 data.change &= (ObjectChangeType.Group | ObjectChangeType.Position | ObjectChangeType.Rotation);
1360
1361 part.StoreUndoState(data.change);
1362 grp.doChangeObject(part, (ObjectChangeData)data);
1363 }
1364 }
1365 }
1366 }
1367 }
1368 }
1369 }
1370
1226 /// <summary> 1371 /// <summary>
1227 /// Update the scale of an individual prim. 1372 /// Update the scale of an individual prim.
1228 /// </summary> 1373 /// </summary>
@@ -1237,7 +1382,17 @@ namespace OpenSim.Region.Framework.Scenes
1237 { 1382 {
1238 if (m_parentScene.Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId)) 1383 if (m_parentScene.Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId))
1239 { 1384 {
1385 bool physbuild = false;
1386 if (part.ParentGroup.RootPart.PhysActor != null)
1387 {
1388 part.ParentGroup.RootPart.PhysActor.Building = true;
1389 physbuild = true;
1390 }
1391
1240 part.Resize(scale); 1392 part.Resize(scale);
1393
1394 if (physbuild)
1395 part.ParentGroup.RootPart.PhysActor.Building = false;
1241 } 1396 }
1242 } 1397 }
1243 } 1398 }
@@ -1249,7 +1404,17 @@ namespace OpenSim.Region.Framework.Scenes
1249 { 1404 {
1250 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId)) 1405 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1251 { 1406 {
1407 bool physbuild = false;
1408 if (group.RootPart.PhysActor != null)
1409 {
1410 group.RootPart.PhysActor.Building = true;
1411 physbuild = true;
1412 }
1413
1252 group.GroupResize(scale); 1414 group.GroupResize(scale);
1415
1416 if (physbuild)
1417 group.RootPart.PhysActor.Building = false;
1253 } 1418 }
1254 } 1419 }
1255 } 1420 }
@@ -1388,8 +1553,13 @@ namespace OpenSim.Region.Framework.Scenes
1388 { 1553 {
1389 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0)) 1554 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1390 { 1555 {
1391 if (m_parentScene.AttachmentsModule != null) 1556 // Set the new attachment point data in the object
1392 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos); 1557 byte attachmentPoint = group.GetAttachmentPoint();
1558 group.UpdateGroupPosition(pos);
1559 group.IsAttachment = false;
1560 group.AbsolutePosition = group.RootPart.AttachedPos;
1561 group.AttachmentPoint = attachmentPoint;
1562 group.HasGroupChanged = true;
1393 } 1563 }
1394 else 1564 else
1395 { 1565 {
@@ -1447,6 +1617,7 @@ namespace OpenSim.Region.Framework.Scenes
1447 // VolumeDetect can't be set via UI and will always be off when a change is made there 1617 // VolumeDetect can't be set via UI and will always be off when a change is made there
1448 // now only change volume dtc if phantom off 1618 // now only change volume dtc if phantom off
1449 1619
1620 bool wantedPhys = UsePhysics;
1450 if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data 1621 if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data
1451 { 1622 {
1452 bool vdtc; 1623 bool vdtc;
@@ -1463,10 +1634,17 @@ namespace OpenSim.Region.Framework.Scenes
1463 if (part != null) 1634 if (part != null)
1464 { 1635 {
1465 part.UpdateExtraPhysics(PhysData); 1636 part.UpdateExtraPhysics(PhysData);
1466 if (part.UpdatePhysRequired) 1637 if (part.UpdatePhysRequired && remoteClient != null)
1467 remoteClient.SendPartPhysicsProprieties(part); 1638 remoteClient.SendPartPhysicsProprieties(part);
1468 } 1639 }
1469 } 1640 }
1641
1642 if (wantedPhys != group.UsesPhysics && remoteClient != null)
1643 {
1644 remoteClient.SendAlertMessage("Object physics canceled because exceeds the limit of " +
1645 m_parentScene.m_linksetPhysCapacity + " physical prims with shape type not set to None");
1646 group.RootPart.ScheduleFullUpdate();
1647 }
1470 } 1648 }
1471 } 1649 }
1472 } 1650 }
@@ -1611,6 +1789,7 @@ namespace OpenSim.Region.Framework.Scenes
1611 { 1789 {
1612 part.Material = Convert.ToByte(material); 1790 part.Material = Convert.ToByte(material);
1613 group.HasGroupChanged = true; 1791 group.HasGroupChanged = true;
1792 remoteClient.SendPartPhysicsProprieties(part);
1614 } 1793 }
1615 } 1794 }
1616 } 1795 }
@@ -1689,12 +1868,14 @@ namespace OpenSim.Region.Framework.Scenes
1689 return; 1868 return;
1690 1869
1691 Monitor.Enter(m_updateLock); 1870 Monitor.Enter(m_updateLock);
1871
1692 try 1872 try
1693 { 1873 {
1874
1694 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); 1875 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1695 1876
1696 // We do this in reverse to get the link order of the prims correct 1877 // We do this in reverse to get the link order of the prims correct
1697 for (int i = 0 ; i < children.Count ; i++) 1878 for (int i = 0; i < children.Count; i++)
1698 { 1879 {
1699 SceneObjectGroup child = children[i].ParentGroup; 1880 SceneObjectGroup child = children[i].ParentGroup;
1700 1881
@@ -1705,9 +1886,13 @@ namespace OpenSim.Region.Framework.Scenes
1705 // Make sure no child prim is set for sale 1886 // Make sure no child prim is set for sale
1706 // So that, on delink, no prims are unwittingly 1887 // So that, on delink, no prims are unwittingly
1707 // left for sale and sold off 1888 // left for sale and sold off
1708 child.RootPart.ObjectSaleType = 0; 1889
1709 child.RootPart.SalePrice = 10; 1890 if (child != null)
1710 childGroups.Add(child); 1891 {
1892 child.RootPart.ObjectSaleType = 0;
1893 child.RootPart.SalePrice = 10;
1894 childGroups.Add(child);
1895 }
1711 } 1896 }
1712 1897
1713 foreach (SceneObjectGroup child in childGroups) 1898 foreach (SceneObjectGroup child in childGroups)
@@ -1736,6 +1921,17 @@ namespace OpenSim.Region.Framework.Scenes
1736 } 1921 }
1737 finally 1922 finally
1738 { 1923 {
1924/*
1925 lock (SceneObjectGroupsByLocalPartID)
1926 {
1927 foreach (SceneObjectPart part in parentGroup.Parts)
1928 SceneObjectGroupsByLocalPartID[part.LocalId] = parentGroup;
1929 }
1930*/
1931 parentGroup.AdjustChildPrimPermissions();
1932 parentGroup.HasGroupChanged = true;
1933 parentGroup.ProcessBackup(m_parentScene.SimulationDataService, true);
1934 parentGroup.ScheduleGroupForFullUpdate();
1739 Monitor.Exit(m_updateLock); 1935 Monitor.Exit(m_updateLock);
1740 } 1936 }
1741 } 1937 }
@@ -1777,21 +1973,23 @@ namespace OpenSim.Region.Framework.Scenes
1777 1973
1778 SceneObjectGroup group = part.ParentGroup; 1974 SceneObjectGroup group = part.ParentGroup;
1779 if (!affectedGroups.Contains(group)) 1975 if (!affectedGroups.Contains(group))
1976 {
1780 affectedGroups.Add(group); 1977 affectedGroups.Add(group);
1978 }
1781 } 1979 }
1782 } 1980 }
1783 } 1981 }
1784 1982
1785 foreach (SceneObjectPart child in childParts) 1983 if (childParts.Count > 0)
1786 { 1984 {
1787 // Unlink all child parts from their groups 1985 foreach (SceneObjectPart child in childParts)
1788 // 1986 {
1789 child.ParentGroup.DelinkFromGroup(child, true); 1987 // Unlink all child parts from their groups
1790 1988 //
1791 // These are not in affected groups and will not be 1989 child.ParentGroup.DelinkFromGroup(child, true);
1792 // handled further. Do the honors here. 1990 child.ParentGroup.HasGroupChanged = true;
1793 child.ParentGroup.HasGroupChanged = true; 1991 child.ParentGroup.ScheduleGroupForFullUpdate();
1794 child.ParentGroup.ScheduleGroupForFullUpdate(); 1992 }
1795 } 1993 }
1796 1994
1797 foreach (SceneObjectPart root in rootParts) 1995 foreach (SceneObjectPart root in rootParts)
@@ -1805,52 +2003,58 @@ namespace OpenSim.Region.Framework.Scenes
1805 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts); 2003 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1806 int numChildren = newSet.Count; 2004 int numChildren = newSet.Count;
1807 2005
2006 if (numChildren == 1)
2007 break;
2008
1808 // If there are prims left in a link set, but the root is 2009 // If there are prims left in a link set, but the root is
1809 // slated for unlink, we need to do this 2010 // slated for unlink, we need to do this
2011 // Unlink the remaining set
1810 // 2012 //
1811 if (numChildren != 1) 2013 bool sendEventsToRemainder = false;
1812 { 2014 if (numChildren == 2) // only one child prim no re-link needed
1813 // Unlink the remaining set 2015 sendEventsToRemainder = true;
1814 //
1815 bool sendEventsToRemainder = true;
1816 if (numChildren > 1)
1817 sendEventsToRemainder = false;
1818 2016
1819 foreach (SceneObjectPart p in newSet) 2017 foreach (SceneObjectPart p in newSet)
2018 {
2019 if (p != group.RootPart)
1820 { 2020 {
1821 if (p != group.RootPart) 2021 group.DelinkFromGroup(p, sendEventsToRemainder);
1822 group.DelinkFromGroup(p, sendEventsToRemainder); 2022 if (sendEventsToRemainder) // finish single child prim now
2023 {
2024 p.ParentGroup.HasGroupChanged = true;
2025 p.ParentGroup.ScheduleGroupForFullUpdate();
2026 }
1823 } 2027 }
2028 }
1824 2029
1825 // If there is more than one prim remaining, we 2030 // If there is more than one prim remaining, we
1826 // need to re-link 2031 // need to re-link
2032 //
2033 if (numChildren > 2)
2034 {
2035 // Remove old root
1827 // 2036 //
1828 if (numChildren > 2) 2037 if (newSet.Contains(root))
2038 newSet.Remove(root);
2039
2040 // Preserve link ordering
2041 //
2042 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1829 { 2043 {
1830 // Remove old root 2044 return a.LinkNum.CompareTo(b.LinkNum);
1831 // 2045 });
1832 if (newSet.Contains(root))
1833 newSet.Remove(root);
1834
1835 // Preserve link ordering
1836 //
1837 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1838 {
1839 return a.LinkNum.CompareTo(b.LinkNum);
1840 });
1841 2046
1842 // Determine new root 2047 // Determine new root
1843 // 2048 //
1844 SceneObjectPart newRoot = newSet[0]; 2049 SceneObjectPart newRoot = newSet[0];
1845 newSet.RemoveAt(0); 2050 newSet.RemoveAt(0);
1846 2051
1847 foreach (SceneObjectPart newChild in newSet) 2052 foreach (SceneObjectPart newChild in newSet)
1848 newChild.ClearUpdateSchedule(); 2053 newChild.ClearUpdateSchedule();
1849 2054
1850 LinkObjects(newRoot, newSet); 2055 LinkObjects(newRoot, newSet);
1851 if (!affectedGroups.Contains(newRoot.ParentGroup)) 2056// if (!affectedGroups.Contains(newRoot.ParentGroup))
1852 affectedGroups.Add(newRoot.ParentGroup); 2057// affectedGroups.Add(newRoot.ParentGroup);
1853 }
1854 } 2058 }
1855 } 2059 }
1856 2060
@@ -1858,6 +2062,12 @@ namespace OpenSim.Region.Framework.Scenes
1858 // 2062 //
1859 foreach (SceneObjectGroup g in affectedGroups) 2063 foreach (SceneObjectGroup g in affectedGroups)
1860 { 2064 {
2065 // Child prims that have been unlinked and deleted will
2066 // return unless the root is deleted. This will remove them
2067 // from the database. They will be rewritten immediately,
2068 // minus the rows for the unlinked child prims.
2069 g.AdjustChildPrimPermissions();
2070 m_parentScene.SimulationDataService.RemoveObject(g.UUID, m_parentScene.RegionInfo.RegionID);
1861 g.TriggerScriptChangedEvent(Changed.LINK); 2071 g.TriggerScriptChangedEvent(Changed.LINK);
1862 g.HasGroupChanged = true; // Persist 2072 g.HasGroupChanged = true; // Persist
1863 g.ScheduleGroupForFullUpdate(); 2073 g.ScheduleGroupForFullUpdate();
@@ -1931,54 +2141,63 @@ namespace OpenSim.Region.Framework.Scenes
1931 /// <param name="GroupID"></param> 2141 /// <param name="GroupID"></param>
1932 /// <param name="rot"></param> 2142 /// <param name="rot"></param>
1933 /// <returns>null if duplication fails, otherwise the duplicated object</returns> 2143 /// <returns>null if duplication fails, otherwise the duplicated object</returns>
1934 public SceneObjectGroup DuplicateObject( 2144 /// <summary>
1935 uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot) 2145 public SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
1936 { 2146 {
1937 Monitor.Enter(m_updateLock); 2147// m_log.DebugFormat(
2148// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
2149// originalPrimID, offset, AgentID);
1938 2150
1939 try 2151 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
2152 if (original != null)
1940 { 2153 {
1941 // m_log.DebugFormat( 2154 if (m_parentScene.Permissions.CanDuplicateObject(
1942 // "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", 2155 original.PrimCount, original.UUID, AgentID, original.AbsolutePosition))
1943 // originalPrimID, offset, AgentID);
1944
1945 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
1946 if (original == null)
1947 { 2156 {
2157<<<<<<< HEAD
1948 m_log.WarnFormat( 2158 m_log.WarnFormat(
1949 "[SCENEGRAPH]: Attempt to duplicate nonexistent prim id {0} by {1}", originalPrimID, AgentID); 2159 "[SCENEGRAPH]: Attempt to duplicate nonexistent prim id {0} by {1}", originalPrimID, AgentID);
2160=======
2161 SceneObjectGroup copy = original.Copy(true);
2162 copy.AbsolutePosition = copy.AbsolutePosition + offset;
2163>>>>>>> avn/ubitvar
1950 2164
1951 return null; 2165 if (original.OwnerID != AgentID)
1952 } 2166 {
2167 copy.SetOwnerId(AgentID);
2168 copy.SetRootPartOwner(copy.RootPart, AgentID, GroupID);
1953 2169
1954 if (!m_parentScene.Permissions.CanDuplicateObject( 2170 SceneObjectPart[] partList = copy.Parts;
1955 original.PrimCount, original.UUID, AgentID, original.AbsolutePosition))
1956 return null;
1957 2171
1958 SceneObjectGroup copy = original.Copy(true); 2172 if (m_parentScene.Permissions.PropagatePermissions())
1959 copy.AbsolutePosition = copy.AbsolutePosition + offset; 2173 {
2174 foreach (SceneObjectPart child in partList)
2175 {
2176 child.Inventory.ChangeInventoryOwner(AgentID);
2177 child.TriggerScriptChangedEvent(Changed.OWNER);
2178 child.ApplyNextOwnerPermissions();
2179 }
2180 }
2181 }
1960 2182
1961 if (original.OwnerID != AgentID) 2183 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
1962 { 2184 Entities.Add(copy);
1963 copy.SetOwnerId(AgentID);
1964 copy.SetRootPartOwner(copy.RootPart, AgentID, GroupID);
1965 2185
1966 SceneObjectPart[] partList = copy.Parts; 2186 lock (SceneObjectGroupsByFullID)
2187 SceneObjectGroupsByFullID[copy.UUID] = copy;
1967 2188
1968 if (m_parentScene.Permissions.PropagatePermissions()) 2189 SceneObjectPart[] parts = copy.Parts;
2190 foreach (SceneObjectPart part in parts)
1969 { 2191 {
1970 foreach (SceneObjectPart child in partList) 2192 lock (SceneObjectGroupsByFullPartID)
1971 { 2193 SceneObjectGroupsByFullPartID[part.UUID] = copy;
1972 child.Inventory.ChangeInventoryOwner(AgentID); 2194 lock (SceneObjectGroupsByLocalPartID)
1973 child.TriggerScriptChangedEvent(Changed.OWNER); 2195 SceneObjectGroupsByLocalPartID[part.LocalId] = copy;
1974 child.ApplyNextOwnerPermissions();
1975 }
1976 } 2196 }
1977 2197
1978 copy.RootPart.ObjectSaleType = 0; 2198 // PROBABLE END OF FIXME
1979 copy.RootPart.SalePrice = 10;
1980 }
1981 2199
2200<<<<<<< HEAD
1982 // FIXME: This section needs to be refactored so that it just calls AddSceneObject() 2201 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
1983 Entities.Add(copy); 2202 Entities.Add(copy);
1984 2203
@@ -2027,24 +2246,41 @@ namespace OpenSim.Region.Framework.Scenes
2027 { 2246 {
2028 copy.UpdateGroupRotationR(rot); 2247 copy.UpdateGroupRotationR(rot);
2029 } 2248 }
2249=======
2250 // Since we copy from a source group that is in selected
2251 // state, but the copy is shown deselected in the viewer,
2252 // We need to clear the selection flag here, else that
2253 // prim never gets persisted at all. The client doesn't
2254 // think it's selected, so it will never send a deselect...
2255 copy.IsSelected = false;
2256>>>>>>> avn/ubitvar
2257
2258 m_numPrim += copy.Parts.Length;
2259
2260 if (rot != Quaternion.Identity)
2261 {
2262 copy.UpdateGroupRotationR(rot);
2263 }
2030 2264
2031 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 1); 2265 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 1);
2032 copy.HasGroupChanged = true; 2266 copy.HasGroupChanged = true;
2033 copy.ScheduleGroupForFullUpdate(); 2267 copy.ScheduleGroupForFullUpdate();
2034 copy.ResumeScripts(); 2268 copy.ResumeScripts();
2035 2269
2036 // required for physics to update it's position 2270 // required for physics to update it's position
2037 copy.AbsolutePosition = copy.AbsolutePosition; 2271 copy.AbsolutePosition = copy.AbsolutePosition;
2038 2272
2039 return copy; 2273 return copy;
2274 }
2040 } 2275 }
2041 finally 2276 else
2042 { 2277 {
2043 Monitor.Exit(m_updateLock); 2278 m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
2044 } 2279 }
2280
2281 return null;
2045 } 2282 }
2046 2283
2047 /// <summary>
2048 /// Calculates the distance between two Vector3s 2284 /// Calculates the distance between two Vector3s
2049 /// </summary> 2285 /// </summary>
2050 /// <param name="v1"></param> 2286 /// <param name="v1"></param>
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index 28f7896..c5c083a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -99,11 +99,11 @@ namespace OpenSim.Region.Framework.Scenes
99 } 99 }
100 } 100 }
101 101
102 private readonly List<Scene> m_localScenes = new List<Scene>(); 102 private readonly DoubleDictionary<UUID, string, Scene> m_localScenes = new DoubleDictionary<UUID, string, Scene>();
103 103
104 public List<Scene> Scenes 104 public List<Scene> Scenes
105 { 105 {
106 get { return new List<Scene>(m_localScenes); } 106 get { return new List<Scene>(m_localScenes.FindAll(delegate(Scene s) { return true; })); }
107 } 107 }
108 108
109 /// <summary> 109 /// <summary>
@@ -120,13 +120,10 @@ namespace OpenSim.Region.Framework.Scenes
120 { 120 {
121 if (CurrentScene == null) 121 if (CurrentScene == null)
122 { 122 {
123 lock (m_localScenes) 123 List<Scene> sceneList = Scenes;
124 { 124 if (sceneList.Count == 0)
125 if (m_localScenes.Count > 0) 125 return null;
126 return m_localScenes[0]; 126 return sceneList[0];
127 else
128 return null;
129 }
130 } 127 }
131 else 128 else
132 { 129 {
@@ -138,41 +135,35 @@ namespace OpenSim.Region.Framework.Scenes
138 public SceneManager() 135 public SceneManager()
139 { 136 {
140 m_instance = this; 137 m_instance = this;
141 m_localScenes = new List<Scene>(); 138 m_localScenes = new DoubleDictionary<UUID, string, Scene>();
142 } 139 }
143 140
144 public void Close() 141 public void Close()
145 { 142 {
143 List<Scene> localScenes = null;
144
146 lock (m_localScenes) 145 lock (m_localScenes)
147 { 146 {
148 for (int i = 0; i < m_localScenes.Count; i++) 147 localScenes = Scenes;
149 { 148 }
150 m_localScenes[i].Close(); 149
151 } 150 for (int i = 0; i < localScenes.Count; i++)
151 {
152 localScenes[i].Close();
152 } 153 }
153 } 154 }
154 155
155 public void Close(Scene cscene) 156 public void Close(Scene cscene)
156 { 157 {
157 lock (m_localScenes) 158 if (!m_localScenes.ContainsKey(cscene.RegionInfo.RegionID))
158 { 159 return;
159 if (m_localScenes.Contains(cscene)) 160 cscene.Close();
160 {
161 for (int i = 0; i < m_localScenes.Count; i++)
162 {
163 if (m_localScenes[i].Equals(cscene))
164 {
165 m_localScenes[i].Close();
166 }
167 }
168 }
169 }
170 } 161 }
171 162
172 public void Add(Scene scene) 163 public void Add(Scene scene)
173 { 164 {
174 lock (m_localScenes) 165 lock (m_localScenes)
175 m_localScenes.Add(scene); 166 m_localScenes.Add(scene.RegionInfo.RegionID, scene.RegionInfo.RegionName, scene);
176 167
177 scene.OnRestart += HandleRestart; 168 scene.OnRestart += HandleRestart;
178 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; 169 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange;
@@ -184,15 +175,8 @@ namespace OpenSim.Region.Framework.Scenes
184 175
185 lock (m_localScenes) 176 lock (m_localScenes)
186 { 177 {
187 for (int i = 0; i < m_localScenes.Count; i++) 178 m_localScenes.TryGetValue(rdata.RegionID, out restartedScene);
188 { 179 m_localScenes.Remove(rdata.RegionID);
189 if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName)
190 {
191 restartedScene = m_localScenes[i];
192 m_localScenes.RemoveAt(i);
193 break;
194 }
195 }
196 } 180 }
197 181
198 // If the currently selected scene has been restarted, then we can't reselect here since we the scene 182 // If the currently selected scene has been restarted, then we can't reselect here since we the scene
@@ -207,39 +191,36 @@ namespace OpenSim.Region.Framework.Scenes
207 private void HandleRegionReadyStatusChange(IScene scene) 191 private void HandleRegionReadyStatusChange(IScene scene)
208 { 192 {
209 lock (m_localScenes) 193 lock (m_localScenes)
210 AllRegionsReady = m_localScenes.TrueForAll(s => s.Ready); 194 AllRegionsReady = m_localScenes.FindAll(s => !s.Ready).Count == 0;
211 } 195 }
212 196
213 public void SendSimOnlineNotification(ulong regionHandle) 197 public void SendSimOnlineNotification(ulong regionHandle)
214 { 198 {
215 RegionInfo Result = null; 199 RegionInfo Result = null;
216 200
217 lock (m_localScenes) 201 Scene s = m_localScenes.FindValue(delegate(Scene x)
218 {
219 for (int i = 0; i < m_localScenes.Count; i++)
220 {
221 if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
222 { 202 {
223 // Inform other regions to tell their avatar about me 203 if (x.RegionInfo.RegionHandle == regionHandle)
224 Result = m_localScenes[i].RegionInfo; 204 return true;
225 } 205 return false;
226 } 206 });
207
208 if (s != null)
209 {
210 List<Scene> sceneList = Scenes;
227 211
228 if (Result != null) 212 for (int i = 0; i < sceneList.Count; i++)
229 { 213 {
230 for (int i = 0; i < m_localScenes.Count; i++) 214 if (sceneList[i]!= s)
231 { 215 {
232 if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) 216 // Inform other regions to tell their avatar about me
233 { 217 //sceneList[i].OtherRegionUp(Result);
234 // Inform other regions to tell their avatar about me
235 //m_localScenes[i].OtherRegionUp(Result);
236 }
237 } 218 }
238 } 219 }
239 else 220 }
240 { 221 else
241 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); 222 {
242 } 223 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up");
243 } 224 }
244 } 225 }
245 226
@@ -368,16 +349,12 @@ namespace OpenSim.Region.Framework.Scenes
368 } 349 }
369 else 350 else
370 { 351 {
371 lock (m_localScenes) 352 Scene s;
353
354 if (m_localScenes.TryGetValue(regionName, out s))
372 { 355 {
373 foreach (Scene scene in m_localScenes) 356 CurrentScene = s;
374 { 357 return true;
375 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0)
376 {
377 CurrentScene = scene;
378 return true;
379 }
380 }
381 } 358 }
382 359
383 return false; 360 return false;
@@ -386,18 +363,14 @@ namespace OpenSim.Region.Framework.Scenes
386 363
387 public bool TrySetCurrentScene(UUID regionID) 364 public bool TrySetCurrentScene(UUID regionID)
388 { 365 {
389 m_log.Debug("Searching for Region: '" + regionID + "'"); 366// m_log.Debug("Searching for Region: '" + regionID + "'");
390 367
391 lock (m_localScenes) 368 Scene s;
369
370 if (m_localScenes.TryGetValue(regionID, out s))
392 { 371 {
393 foreach (Scene scene in m_localScenes) 372 CurrentScene = s;
394 { 373 return true;
395 if (scene.RegionInfo.RegionID == regionID)
396 {
397 CurrentScene = scene;
398 return true;
399 }
400 }
401 } 374 }
402 375
403 return false; 376 return false;
@@ -405,52 +378,24 @@ namespace OpenSim.Region.Framework.Scenes
405 378
406 public bool TryGetScene(string regionName, out Scene scene) 379 public bool TryGetScene(string regionName, out Scene scene)
407 { 380 {
408 lock (m_localScenes) 381 return m_localScenes.TryGetValue(regionName, out scene);
409 {
410 foreach (Scene mscene in m_localScenes)
411 {
412 if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0)
413 {
414 scene = mscene;
415 return true;
416 }
417 }
418 }
419
420 scene = null;
421 return false;
422 } 382 }
423 383
424 public bool TryGetScene(UUID regionID, out Scene scene) 384 public bool TryGetScene(UUID regionID, out Scene scene)
425 { 385 {
426 lock (m_localScenes) 386 return m_localScenes.TryGetValue(regionID, out scene);
427 {
428 foreach (Scene mscene in m_localScenes)
429 {
430 if (mscene.RegionInfo.RegionID == regionID)
431 {
432 scene = mscene;
433 return true;
434 }
435 }
436 }
437
438 scene = null;
439 return false;
440 } 387 }
441 388
442 public bool TryGetScene(uint locX, uint locY, out Scene scene) 389 public bool TryGetScene(uint locX, uint locY, out Scene scene)
443 { 390 {
444 lock (m_localScenes) 391 List<Scene> sceneList = Scenes;
392 foreach (Scene mscene in sceneList)
445 { 393 {
446 foreach (Scene mscene in m_localScenes) 394 if (mscene.RegionInfo.RegionLocX == locX &&
395 mscene.RegionInfo.RegionLocY == locY)
447 { 396 {
448 if (mscene.RegionInfo.RegionLocX == locX && 397 scene = mscene;
449 mscene.RegionInfo.RegionLocY == locY) 398 return true;
450 {
451 scene = mscene;
452 return true;
453 }
454 } 399 }
455 } 400 }
456 401
@@ -460,16 +405,14 @@ namespace OpenSim.Region.Framework.Scenes
460 405
461 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) 406 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene)
462 { 407 {
463 lock (m_localScenes) 408 List<Scene> sceneList = Scenes;
409 foreach (Scene mscene in sceneList)
464 { 410 {
465 foreach (Scene mscene in m_localScenes) 411 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) &&
412 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port))
466 { 413 {
467 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && 414 scene = mscene;
468 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) 415 return true;
469 {
470 scene = mscene;
471 return true;
472 }
473 } 416 }
474 } 417 }
475 418
@@ -511,15 +454,10 @@ namespace OpenSim.Region.Framework.Scenes
511 454
512 public RegionInfo GetRegionInfo(UUID regionID) 455 public RegionInfo GetRegionInfo(UUID regionID)
513 { 456 {
514 lock (m_localScenes) 457 Scene s;
458 if (m_localScenes.TryGetValue(regionID, out s))
515 { 459 {
516 foreach (Scene scene in m_localScenes) 460 return s.RegionInfo;
517 {
518 if (scene.RegionInfo.RegionID == regionID)
519 {
520 return scene.RegionInfo;
521 }
522 }
523 } 461 }
524 462
525 return null; 463 return null;
@@ -537,14 +475,12 @@ namespace OpenSim.Region.Framework.Scenes
537 475
538 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) 476 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
539 { 477 {
540 lock (m_localScenes) 478 List<Scene> sceneList = Scenes;
479 foreach (Scene scene in sceneList)
541 { 480 {
542 foreach (Scene scene in m_localScenes) 481 if (scene.TryGetScenePresence(avatarId, out avatar))
543 { 482 {
544 if (scene.TryGetScenePresence(avatarId, out avatar)) 483 return true;
545 {
546 return true;
547 }
548 } 484 }
549 } 485 }
550 486
@@ -554,15 +490,13 @@ namespace OpenSim.Region.Framework.Scenes
554 490
555 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar) 491 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar)
556 { 492 {
557 lock (m_localScenes) 493 List<Scene> sceneList = Scenes;
494 foreach (Scene scene in sceneList)
558 { 495 {
559 foreach (Scene scene in m_localScenes) 496 avatar = scene.GetScenePresence(avatarId);
560 {
561 avatar = scene.GetScenePresence(avatarId);
562 497
563 if (avatar != null && !avatar.IsChildAgent) 498 if (avatar != null && !avatar.IsChildAgent)
564 return true; 499 return true;
565 }
566 } 500 }
567 501
568 avatar = null; 502 avatar = null;
@@ -572,21 +506,19 @@ namespace OpenSim.Region.Framework.Scenes
572 public void CloseScene(Scene scene) 506 public void CloseScene(Scene scene)
573 { 507 {
574 lock (m_localScenes) 508 lock (m_localScenes)
575 m_localScenes.Remove(scene); 509 m_localScenes.Remove(scene.RegionInfo.RegionID);
576 510
577 scene.Close(); 511 scene.Close();
578 } 512 }
579 513
580 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 514 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
581 { 515 {
582 lock (m_localScenes) 516 List<Scene> sceneList = Scenes;
517 foreach (Scene scene in sceneList)
583 { 518 {
584 foreach (Scene scene in m_localScenes) 519 if (scene.TryGetAvatarByName(avatarName, out avatar))
585 { 520 {
586 if (scene.TryGetAvatarByName(avatarName, out avatar)) 521 return true;
587 {
588 return true;
589 }
590 } 522 }
591 } 523 }
592 524
@@ -596,14 +528,12 @@ namespace OpenSim.Region.Framework.Scenes
596 528
597 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp) 529 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp)
598 { 530 {
599 lock (m_localScenes) 531 List<Scene> sceneList = Scenes;
532 foreach (Scene scene in sceneList)
600 { 533 {
601 foreach (Scene scene in m_localScenes) 534 sp = scene.GetScenePresence(firstName, lastName);
602 { 535 if (sp != null && !sp.IsChildAgent)
603 sp = scene.GetScenePresence(firstName, lastName); 536 return true;
604 if (sp != null && !sp.IsChildAgent)
605 return true;
606 }
607 } 537 }
608 538
609 sp = null; 539 sp = null;
@@ -612,8 +542,8 @@ namespace OpenSim.Region.Framework.Scenes
612 542
613 public void ForEachScene(Action<Scene> action) 543 public void ForEachScene(Action<Scene> action)
614 { 544 {
615 lock (m_localScenes) 545 List<Scene> sceneList = Scenes;
616 m_localScenes.ForEach(action); 546 sceneList.ForEach(action);
617 } 547 }
618 } 548 }
619} 549}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
index 81cef5b..79de6c0 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
@@ -88,10 +88,6 @@ namespace OpenSim.Region.Framework.Scenes
88 /// <summary> 88 /// <summary>
89 /// Stop and remove the scripts contained in all the prims in this group 89 /// Stop and remove the scripts contained in all the prims in this group
90 /// </summary> 90 /// </summary>
91 /// <param name="sceneObjectBeingDeleted">
92 /// Should be true if these scripts are being removed because the scene
93 /// object is being deleted. This will prevent spurious updates to the client.
94 /// </param>
95 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 91 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
96 { 92 {
97 SceneObjectPart[] parts = m_parts.GetArray(); 93 SceneObjectPart[] parts = m_parts.GetArray();
@@ -254,6 +250,11 @@ namespace OpenSim.Region.Framework.Scenes
254 250
255 public uint GetEffectivePermissions() 251 public uint GetEffectivePermissions()
256 { 252 {
253 return GetEffectivePermissions(false);
254 }
255
256 public uint GetEffectivePermissions(bool useBase)
257 {
257 uint perms=(uint)(PermissionMask.Modify | 258 uint perms=(uint)(PermissionMask.Modify |
258 PermissionMask.Copy | 259 PermissionMask.Copy |
259 PermissionMask.Move | 260 PermissionMask.Move |
@@ -265,8 +266,15 @@ namespace OpenSim.Region.Framework.Scenes
265 for (int i = 0; i < parts.Length; i++) 266 for (int i = 0; i < parts.Length; i++)
266 { 267 {
267 SceneObjectPart part = parts[i]; 268 SceneObjectPart part = parts[i];
269<<<<<<< HEAD
268// m_log.DebugFormat("[SCENE OBJECT GROUP INVENTORY]: Effective perms of {0} are {1}", part.Name, (OpenMetaverse.PermissionMask)part.OwnerMask); 270// m_log.DebugFormat("[SCENE OBJECT GROUP INVENTORY]: Effective perms of {0} are {1}", part.Name, (OpenMetaverse.PermissionMask)part.OwnerMask);
269 ownerMask &= part.OwnerMask; 271 ownerMask &= part.OwnerMask;
272=======
273 if (useBase)
274 ownerMask &= part.BaseMask;
275 else
276 ownerMask &= part.OwnerMask;
277>>>>>>> avn/ubitvar
270 perms &= part.Inventory.MaskEffectivePermissions(); 278 perms &= part.Inventory.MaskEffectivePermissions();
271 } 279 }
272 280
@@ -408,6 +416,9 @@ namespace OpenSim.Region.Framework.Scenes
408 416
409 public void ResumeScripts() 417 public void ResumeScripts()
410 { 418 {
419 if (m_scene.RegionInfo.RegionSettings.DisableScripts)
420 return;
421
411 SceneObjectPart[] parts = m_parts.GetArray(); 422 SceneObjectPart[] parts = m_parts.GetArray();
412 for (int i = 0; i < parts.Length; i++) 423 for (int i = 0; i < parts.Length; i++)
413 parts[i].Inventory.ResumeScripts(); 424 parts[i].Inventory.ResumeScripts();
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 866a43c..a703377 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -24,12 +24,13 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.ComponentModel; 29using System.ComponentModel;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Drawing; 31using System.Drawing;
32using System.IO; 32using System.IO;
33using System.Diagnostics;
33using System.Linq; 34using System.Linq;
34using System.Threading; 35using System.Threading;
35using System.Xml; 36using System.Xml;
@@ -44,6 +45,7 @@ using PermissionMask = OpenSim.Framework.PermissionMask;
44 45
45namespace OpenSim.Region.Framework.Scenes 46namespace OpenSim.Region.Framework.Scenes
46{ 47{
48
47 [Flags] 49 [Flags]
48 public enum scriptEvents 50 public enum scriptEvents
49 { 51 {
@@ -79,14 +81,14 @@ namespace OpenSim.Region.Framework.Scenes
79 object_rez = 4194304 81 object_rez = 4194304
80 } 82 }
81 83
82 struct scriptPosTarget 84 public struct scriptPosTarget
83 { 85 {
84 public Vector3 targetPos; 86 public Vector3 targetPos;
85 public float tolerance; 87 public float tolerance;
86 public uint handle; 88 public uint handle;
87 } 89 }
88 90
89 struct scriptRotTarget 91 public struct scriptRotTarget
90 { 92 {
91 public Quaternion targetRot; 93 public Quaternion targetRot;
92 public float tolerance; 94 public float tolerance;
@@ -120,8 +122,17 @@ namespace OpenSim.Region.Framework.Scenes
120 /// since the group's last persistent backup 122 /// since the group's last persistent backup
121 /// </summary> 123 /// </summary>
122 private bool m_hasGroupChanged = false; 124 private bool m_hasGroupChanged = false;
125<<<<<<< HEAD
123 private long timeFirstChanged; 126 private long timeFirstChanged;
124 private long timeLastChanged; 127 private long timeLastChanged;
128=======
129 private long timeFirstChanged = 0;
130 private long timeLastChanged = 0;
131 private long m_maxPersistTime = 0;
132 private long m_minPersistTime = 0;
133// private Random m_rand;
134 private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>();
135>>>>>>> avn/ubitvar
125 136
126 /// <summary> 137 /// <summary>
127 /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage 138 /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage
@@ -138,9 +149,44 @@ namespace OpenSim.Region.Framework.Scenes
138 { 149 {
139 if (value) 150 if (value)
140 { 151 {
152
153 if (m_isBackedUp)
154 {
155 m_scene.SceneGraph.FireChangeBackup(this);
156 }
141 timeLastChanged = DateTime.Now.Ticks; 157 timeLastChanged = DateTime.Now.Ticks;
142 if (!m_hasGroupChanged) 158 if (!m_hasGroupChanged)
143 timeFirstChanged = DateTime.Now.Ticks; 159 timeFirstChanged = DateTime.Now.Ticks;
160 if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null)
161 {
162/*
163 if (m_rand == null)
164 {
165 byte[] val = new byte[16];
166 m_rootPart.UUID.ToBytes(val, 0);
167 m_rand = new Random(BitConverter.ToInt32(val, 0));
168 }
169 */
170 if (m_scene.GetRootAgentCount() == 0)
171 {
172 //If the region is empty, this change has been made by an automated process
173 //and thus we delay the persist time by a random amount between 1.5 and 2.5.
174
175// float factor = 1.5f + (float)(m_rand.NextDouble());
176 float factor = 2.0f;
177 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
178 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
179 }
180 else
181 {
182 //If the region is not empty, we want to obey the minimum and maximum persist times
183 //but add a random factor so we stagger the object persistance a little
184// m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
185// m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
186 m_maxPersistTime = m_scene.m_persistAfter;
187 m_minPersistTime = m_scene.m_dontPersistBefore;
188 }
189 }
144 } 190 }
145 m_hasGroupChanged = value; 191 m_hasGroupChanged = value;
146 192
@@ -159,6 +205,7 @@ namespace OpenSim.Region.Framework.Scenes
159 /// the prims in the database still use the old SceneGroupID. That's a problem if the group 205 /// the prims in the database still use the old SceneGroupID. That's a problem if the group
160 /// is deleted, because we delete groups by searching for prims by their SceneGroupID. 206 /// is deleted, because we delete groups by searching for prims by their SceneGroupID.
161 /// </summary> 207 /// </summary>
208<<<<<<< HEAD
162 public bool GroupContainsForeignPrims 209 public bool GroupContainsForeignPrims
163 { 210 {
164 private set 211 private set
@@ -171,6 +218,9 @@ namespace OpenSim.Region.Framework.Scenes
171 get { return m_groupContainsForeignPrims; } 218 get { return m_groupContainsForeignPrims; }
172 } 219 }
173 220
221=======
222 public bool HasGroupChangedDueToDelink { get; set; }
223>>>>>>> avn/ubitvar
174 224
175 private bool isTimeToPersist() 225 private bool isTimeToPersist()
176 { 226 {
@@ -180,8 +230,19 @@ namespace OpenSim.Region.Framework.Scenes
180 return false; 230 return false;
181 if (m_scene.ShuttingDown) 231 if (m_scene.ShuttingDown)
182 return true; 232 return true;
233
234 if (m_minPersistTime == 0 || m_maxPersistTime == 0)
235 {
236 m_maxPersistTime = m_scene.m_persistAfter;
237 m_minPersistTime = m_scene.m_dontPersistBefore;
238 }
239
183 long currentTime = DateTime.Now.Ticks; 240 long currentTime = DateTime.Now.Ticks;
184 if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) 241
242 if (timeLastChanged == 0) timeLastChanged = currentTime;
243 if (timeFirstChanged == 0) timeFirstChanged = currentTime;
244
245 if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
185 return true; 246 return true;
186 return false; 247 return false;
187 } 248 }
@@ -239,6 +300,11 @@ namespace OpenSim.Region.Framework.Scenes
239 { 300 {
240 AttachmentPoint = 0; 301 AttachmentPoint = 0;
241 302
303 // Don't zap trees
304 if (RootPart.Shape.PCode == (byte)PCode.Tree ||
305 RootPart.Shape.PCode == (byte)PCode.NewTree)
306 return;
307
242 // Even though we don't use child part state parameters for attachments any more, we still need to set 308 // Even though we don't use child part state parameters for attachments any more, we still need to set
243 // these to zero since having them non-zero in rezzed scene objects will crash some clients. Even if 309 // these to zero since having them non-zero in rezzed scene objects will crash some clients. Even if
244 // we store them correctly, scene objects that we receive from elsewhere might not. 310 // we store them correctly, scene objects that we receive from elsewhere might not.
@@ -284,6 +350,7 @@ namespace OpenSim.Region.Framework.Scenes
284 get { return RootPart.VolumeDetectActive; } 350 get { return RootPart.VolumeDetectActive; }
285 } 351 }
286 352
353<<<<<<< HEAD
287 private Vector3 lastPhysGroupPos; 354 private Vector3 lastPhysGroupPos;
288 private Quaternion lastPhysGroupRot; 355 private Quaternion lastPhysGroupRot;
289 356
@@ -291,6 +358,14 @@ namespace OpenSim.Region.Framework.Scenes
291 /// Is this entity set to be saved in persistent storage? 358 /// Is this entity set to be saved in persistent storage?
292 /// </summary> 359 /// </summary>
293 public bool Backup { get; private set; } 360 public bool Backup { get; private set; }
361=======
362 private bool m_isBackedUp;
363>>>>>>> avn/ubitvar
364
365 public bool IsBackedUp
366 {
367 get { return m_isBackedUp; }
368 }
294 369
295 protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>(); 370 protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>();
296 371
@@ -298,15 +373,25 @@ namespace OpenSim.Region.Framework.Scenes
298 protected SceneObjectPart m_rootPart; 373 protected SceneObjectPart m_rootPart;
299 // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>(); 374 // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
300 375
301 private Dictionary<uint, scriptPosTarget> m_targets = new Dictionary<uint, scriptPosTarget>(); 376 private SortedDictionary<uint, scriptPosTarget> m_targets = new SortedDictionary<uint, scriptPosTarget>();
302 private Dictionary<uint, scriptRotTarget> m_rotTargets = new Dictionary<uint, scriptRotTarget>(); 377 private SortedDictionary<uint, scriptRotTarget> m_rotTargets = new SortedDictionary<uint, scriptRotTarget>();
378
379 public SortedDictionary<uint, scriptPosTarget> AtTargets
380 {
381 get { return m_targets; }
382 }
383
384 public SortedDictionary<uint, scriptRotTarget> RotTargets
385 {
386 get { return m_rotTargets; }
387 }
303 388
304 private bool m_scriptListens_atTarget; 389 private bool m_scriptListens_atTarget;
305 private bool m_scriptListens_notAtTarget; 390 private bool m_scriptListens_notAtTarget;
306
307 private bool m_scriptListens_atRotTarget; 391 private bool m_scriptListens_atRotTarget;
308 private bool m_scriptListens_notAtRotTarget; 392 private bool m_scriptListens_notAtRotTarget;
309 393
394 public bool m_dupeInProgress = false;
310 internal Dictionary<UUID, string> m_savedScriptState; 395 internal Dictionary<UUID, string> m_savedScriptState;
311 396
312 #region Properties 397 #region Properties
@@ -343,6 +428,16 @@ namespace OpenSim.Region.Framework.Scenes
343 get { return m_parts.Count; } 428 get { return m_parts.Count; }
344 } 429 }
345 430
431// protected Quaternion m_rotation = Quaternion.Identity;
432//
433// public virtual Quaternion Rotation
434// {
435// get { return m_rotation; }
436// set {
437// m_rotation = value;
438// }
439// }
440
346 public Quaternion GroupRotation 441 public Quaternion GroupRotation
347 { 442 {
348 get { return m_rootPart.RotationOffset; } 443 get { return m_rootPart.RotationOffset; }
@@ -456,6 +551,10 @@ namespace OpenSim.Region.Framework.Scenes
456 public uint ParentID; 551 public uint ParentID;
457 } 552 }
458 553
554
555 public bool inTransit = false;
556 public delegate SceneObjectGroup SOGCrossDelegate(SceneObjectGroup sog,Vector3 pos);
557
459 /// <summary> 558 /// <summary>
460 /// The absolute position of this scene object in the scene 559 /// The absolute position of this scene object in the scene
461 /// </summary> 560 /// </summary>
@@ -465,9 +564,13 @@ namespace OpenSim.Region.Framework.Scenes
465 set 564 set
466 { 565 {
467 Vector3 val = value; 566 Vector3 val = value;
468 567 if (Scene != null
469 if (Scene != null) 568 && !Scene.PositionIsInCurrentRegion(val)
569 && !IsAttachmentCheckFull()
570 && !Scene.LoadingPrims
571 )
470 { 572 {
573<<<<<<< HEAD
471 if ( 574 if (
472 !Scene.PositionIsInCurrentRegion(val) 575 !Scene.PositionIsInCurrentRegion(val)
473 && !IsAttachmentCheckFull() 576 && !IsAttachmentCheckFull()
@@ -600,7 +703,15 @@ namespace OpenSim.Region.Framework.Scenes
600 val.X = Util.Clamp<float>(oldp.X, 0.5f, (float)m_scene.RegionInfo.RegionSizeX - 0.5f); 703 val.X = Util.Clamp<float>(oldp.X, 0.5f, (float)m_scene.RegionInfo.RegionSizeX - 0.5f);
601 val.Y = Util.Clamp<float>(oldp.Y, 0.5f, (float)m_scene.RegionInfo.RegionSizeY - 0.5f); 704 val.Y = Util.Clamp<float>(oldp.Y, 0.5f, (float)m_scene.RegionInfo.RegionSizeY - 0.5f);
602 val.Z = Util.Clamp<float>(oldp.Z, 0.5f, Constants.RegionHeight); 705 val.Z = Util.Clamp<float>(oldp.Z, 0.5f, Constants.RegionHeight);
706=======
707 if (!inTransit)
708 {
709 inTransit = true;
710 SOGCrossDelegate d = CrossAsync;
711 d.BeginInvoke(this, val, CrossAsyncCompleted, d);
712>>>>>>> avn/ubitvar
603 } 713 }
714 return;
604 } 715 }
605 716
606 if (RootPart.GetStatusSandbox()) 717 if (RootPart.GetStatusSandbox())
@@ -608,38 +719,235 @@ namespace OpenSim.Region.Framework.Scenes
608 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 719 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
609 { 720 {
610 RootPart.ScriptSetPhysicsStatus(false); 721 RootPart.ScriptSetPhysicsStatus(false);
611 722
612 if (Scene != null) 723 if (Scene != null)
613 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), 724 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
614 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); 725 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
615 726
616 return; 727 return;
617 } 728 }
618 } 729 }
619 730
620 // Restuff the new GroupPosition into each SOP of the linkset. 731 bool triggerScriptEvent = m_rootPart.GroupPosition != val;
621 // This has the affect of resetting and tainting the physics actors. 732 if (m_dupeInProgress || IsDeleted)
733 triggerScriptEvent = false;
734
735 m_rootPart.GroupPosition = val;
736
737 // Restuff the new GroupPosition into each child SOP of the linkset.
738 // this is needed because physics may not have linksets but just loose SOPs in world
739
622 SceneObjectPart[] parts = m_parts.GetArray(); 740 SceneObjectPart[] parts = m_parts.GetArray();
623 for (int i = 0; i < parts.Length; i++)
624 parts[i].GroupPosition = val;
625 741
626 //if (m_rootPart.PhysActor != null) 742 foreach (SceneObjectPart part in parts)
627 //{ 743 {
628 //m_rootPart.PhysActor.Position = 744 if (part != m_rootPart)
629 //new PhysicsVector(m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y, 745 part.GroupPosition = val;
630 //m_rootPart.GroupPosition.Z); 746 }
631 //m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 747
632 //} 748 foreach (ScenePresence av in m_linkedAvatars)
633 749 {
750 av.sitSOGmoved();
751 }
752
753
754 // now that position is changed tell it to scripts
755 if (triggerScriptEvent)
756 {
757 foreach (SceneObjectPart part in parts)
758 {
759 part.TriggerScriptChangedEvent(Changed.POSITION);
760 }
761 }
762
634 if (Scene != null) 763 if (Scene != null)
635 Scene.EventManager.TriggerParcelPrimCountTainted(); 764 Scene.EventManager.TriggerParcelPrimCountTainted();
765
636 } 766 }
637 } 767 }
638 768
639 public override Vector3 Velocity 769 public SceneObjectGroup CrossAsync(SceneObjectGroup sog, Vector3 val)
640 { 770 {
641 get { return RootPart.Velocity; } 771 Scene sogScene = sog.m_scene;
642 set { RootPart.Velocity = value; } 772 IEntityTransferModule entityTransfer = sogScene.RequestModuleInterface<IEntityTransferModule>();
773
774 Vector3 newpos = Vector3.Zero;
775 OpenSim.Services.Interfaces.GridRegion destination = null;
776
777 if (sog.RootPart.DIE_AT_EDGE)
778 {
779 try
780 {
781 sogScene.DeleteSceneObject(sog, false);
782 }
783 catch (Exception)
784 {
785 m_log.Warn("[SCENE]: exception when trying to remove the prim that crossed the border.");
786 }
787 return sog;
788 }
789
790 if (sog.RootPart.RETURN_AT_EDGE)
791 {
792 // We remove the object here
793 try
794 {
795 List<uint> localIDs = new List<uint>();
796 localIDs.Add(sog.RootPart.LocalId);
797 sogScene.AddReturn(sog.OwnerID, sog.Name, sog.AbsolutePosition,
798 "Returned at region cross");
799 sogScene.DeRezObjects(null, localIDs, UUID.Zero, DeRezAction.Return, UUID.Zero);
800 }
801 catch (Exception)
802 {
803 m_log.Warn("[SCENE]: exception when trying to return the prim that crossed the border.");
804 }
805 return sog;
806 }
807
808 if (sog.m_rootPart.KeyframeMotion != null)
809 sog.m_rootPart.KeyframeMotion.StartCrossingCheck();
810
811 if (entityTransfer == null)
812 return sog;
813
814 destination = entityTransfer.GetObjectDestination(sog, val, out newpos);
815 if (destination == null)
816 return sog;
817
818 if (sog.m_linkedAvatars.Count == 0)
819 {
820 entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, true);
821 return sog;
822 }
823
824 string reason = String.Empty;
825 string version = String.Empty;
826
827 foreach (ScenePresence av in sog.m_linkedAvatars)
828 {
829 // We need to cross these agents. First, let's find
830 // out if any of them can't cross for some reason.
831 // We have to deny the crossing entirely if any
832 // of them are banned. Alternatively, we could
833 // unsit banned agents....
834
835 // We set the avatar position as being the object
836 // position to get the region to send to
837 if(!entityTransfer.checkAgentAccessToRegion(av, destination, newpos, out version, out reason))
838 {
839 return sog;
840 }
841 m_log.DebugFormat("[SCENE OBJECT]: Avatar {0} needs to be crossed to {1}", av.Name, destination.RegionName);
842 }
843
844 // We unparent the SP quietly so that it won't
845 // be made to stand up
846
847 List<avtocrossInfo> avsToCross = new List<avtocrossInfo>();
848
849 foreach (ScenePresence av in sog.m_linkedAvatars)
850 {
851 avtocrossInfo avinfo = new avtocrossInfo();
852 SceneObjectPart parentPart = sogScene.GetSceneObjectPart(av.ParentID);
853 if (parentPart != null)
854 av.ParentUUID = parentPart.UUID;
855
856 avinfo.av = av;
857 avinfo.ParentID = av.ParentID;
858 avsToCross.Add(avinfo);
859
860 av.PrevSitOffset = av.OffsetPosition;
861 av.ParentID = 0;
862 }
863
864 if (entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, true))
865 {
866 foreach (avtocrossInfo avinfo in avsToCross)
867 {
868 ScenePresence av = avinfo.av;
869 if (!av.IsInTransit) // just in case...
870 {
871 m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar {0} to {1}", av.Name, val);
872
873 av.IsInTransit = true;
874
875// CrossAgentToNewRegionDelegate d = entityTransfer.CrossAgentToNewRegionAsync;
876// d.BeginInvoke(av, val, destination, av.Flying, version, CrossAgentToNewRegionCompleted, d);
877 entityTransfer.CrossAgentToNewRegionAsync(av, newpos, destination, av.Flying, version);
878 if(av.IsChildAgent)
879 {
880 if (av.ParentUUID != UUID.Zero)
881 {
882 av.ClearControls();
883 av.ParentPart = null;
884 }
885 }
886 av.ParentUUID = UUID.Zero;
887 // In any case
888 av.IsInTransit = false;
889
890 m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", av.Firstname, av.Lastname);
891 }
892 else
893 m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar already in transit {0} to {1}", av.Name, val);
894 }
895 avsToCross.Clear();
896 return sog;
897 }
898 else // cross failed, put avas back ??
899 {
900 foreach (avtocrossInfo avinfo in avsToCross)
901 {
902 ScenePresence av = avinfo.av;
903 av.ParentUUID = UUID.Zero;
904 av.ParentID = avinfo.ParentID;
905 }
906 }
907 avsToCross.Clear();
908
909 return sog;
910 }
911
912 public void CrossAsyncCompleted(IAsyncResult iar)
913 {
914 SOGCrossDelegate icon = (SOGCrossDelegate)iar.AsyncState;
915 SceneObjectGroup sog = icon.EndInvoke(iar);
916
917 if (!sog.IsDeleted)
918 {
919 SceneObjectPart rootp = sog.m_rootPart;
920 Vector3 oldp = rootp.GroupPosition;
921 oldp.X = Util.Clamp<float>(oldp.X, 0.5f, sog.m_scene.RegionInfo.RegionSizeX - 0.5f);
922 oldp.Y = Util.Clamp<float>(oldp.Y, 0.5f, sog.m_scene.RegionInfo.RegionSizeY - 0.5f);
923 rootp.GroupPosition = oldp;
924
925 SceneObjectPart[] parts = sog.m_parts.GetArray();
926
927 foreach (SceneObjectPart part in parts)
928 {
929 if (part != rootp)
930 part.GroupPosition = oldp;
931 }
932
933 foreach (ScenePresence av in sog.m_linkedAvatars)
934 {
935 av.sitSOGmoved();
936 }
937
938 sog.Velocity = Vector3.Zero;
939
940 if (sog.m_rootPart.KeyframeMotion != null)
941 sog.m_rootPart.KeyframeMotion.CrossingFailure();
942
943 if (sog.RootPart.PhysActor != null)
944 {
945 sog.RootPart.PhysActor.CrossingFailure();
946 }
947
948 sog.inTransit = false;
949 sog.ScheduleGroupForFullUpdate();
950 }
643 } 951 }
644 952
645 private void CrossAgentToNewRegionCompleted(ScenePresence agent) 953 private void CrossAgentToNewRegionCompleted(ScenePresence agent)
@@ -649,6 +957,7 @@ namespace OpenSim.Region.Framework.Scenes
649 { 957 {
650 if (agent.ParentUUID != UUID.Zero) 958 if (agent.ParentUUID != UUID.Zero)
651 { 959 {
960 agent.HandleForceReleaseControls(agent.ControllingClient,agent.UUID);
652 agent.ParentPart = null; 961 agent.ParentPart = null;
653// agent.ParentPosition = Vector3.Zero; 962// agent.ParentPosition = Vector3.Zero;
654// agent.ParentUUID = UUID.Zero; 963// agent.ParentUUID = UUID.Zero;
@@ -666,6 +975,12 @@ namespace OpenSim.Region.Framework.Scenes
666 m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname); 975 m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
667 } 976 }
668 977
978 public override Vector3 Velocity
979 {
980 get { return RootPart.Velocity; }
981 set { RootPart.Velocity = value; }
982 }
983
669 public override uint LocalId 984 public override uint LocalId
670 { 985 {
671 get { return m_rootPart.LocalId; } 986 get { return m_rootPart.LocalId; }
@@ -740,6 +1055,11 @@ namespace OpenSim.Region.Framework.Scenes
740 m_isSelected = value; 1055 m_isSelected = value;
741 // Tell physics engine that group is selected 1056 // Tell physics engine that group is selected
742 1057
1058 // this is not right
1059 // but ode engines should only really need to know about root part
1060 // so they can put entire object simulation on hold and not colliding
1061 // keep as was for now
1062
743 PhysicsActor pa = m_rootPart.PhysActor; 1063 PhysicsActor pa = m_rootPart.PhysActor;
744 if (pa != null) 1064 if (pa != null)
745 { 1065 {
@@ -761,13 +1081,47 @@ namespace OpenSim.Region.Framework.Scenes
761 } 1081 }
762 } 1082 }
763 1083
1084 public void PartSelectChanged(bool partSelect)
1085 {
1086 // any part selected makes group selected
1087 if (m_isSelected == partSelect)
1088 return;
1089
1090 if (partSelect)
1091 {
1092 IsSelected = partSelect;
1093// if (!IsAttachment)
1094// ScheduleGroupForFullUpdate();
1095 }
1096 else
1097 {
1098 // bad bad bad 2 heavy for large linksets
1099 // since viewer does send lot of (un)selects
1100 // this needs to be replaced by a specific list or count ?
1101 // but that will require extra code in several places
1102
1103 SceneObjectPart[] parts = m_parts.GetArray();
1104 for (int i = 0; i < parts.Length; i++)
1105 {
1106 SceneObjectPart part = parts[i];
1107 if (part.IsSelected)
1108 return;
1109 }
1110 IsSelected = partSelect;
1111// if (!IsAttachment)
1112// {
1113// ScheduleGroupForFullUpdate();
1114// }
1115 }
1116 }
1117 // PlaySoundMasterPrim no longer in use to remove
764 private SceneObjectPart m_PlaySoundMasterPrim = null; 1118 private SceneObjectPart m_PlaySoundMasterPrim = null;
765 public SceneObjectPart PlaySoundMasterPrim 1119 public SceneObjectPart PlaySoundMasterPrim
766 { 1120 {
767 get { return m_PlaySoundMasterPrim; } 1121 get { return m_PlaySoundMasterPrim; }
768 set { m_PlaySoundMasterPrim = value; } 1122 set { m_PlaySoundMasterPrim = value; }
769 } 1123 }
770 1124 // PlaySoundSlavePrims no longer in use to remove
771 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>(); 1125 private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
772 public List<SceneObjectPart> PlaySoundSlavePrims 1126 public List<SceneObjectPart> PlaySoundSlavePrims
773 { 1127 {
@@ -775,6 +1129,7 @@ namespace OpenSim.Region.Framework.Scenes
775 set { m_PlaySoundSlavePrims = value; } 1129 set { m_PlaySoundSlavePrims = value; }
776 } 1130 }
777 1131
1132 // LoopSoundMasterPrim no longer in use to remove
778 private SceneObjectPart m_LoopSoundMasterPrim = null; 1133 private SceneObjectPart m_LoopSoundMasterPrim = null;
779 public SceneObjectPart LoopSoundMasterPrim 1134 public SceneObjectPart LoopSoundMasterPrim
780 { 1135 {
@@ -782,6 +1137,7 @@ namespace OpenSim.Region.Framework.Scenes
782 set { m_LoopSoundMasterPrim = value; } 1137 set { m_LoopSoundMasterPrim = value; }
783 } 1138 }
784 1139
1140 // m_LoopSoundSlavePrims no longer in use to remove
785 private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>(); 1141 private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
786 public List<SceneObjectPart> LoopSoundSlavePrims 1142 public List<SceneObjectPart> LoopSoundSlavePrims
787 { 1143 {
@@ -861,6 +1217,7 @@ namespace OpenSim.Region.Framework.Scenes
861 /// </summary> 1217 /// </summary>
862 public SceneObjectGroup() 1218 public SceneObjectGroup()
863 { 1219 {
1220
864 } 1221 }
865 1222
866 /// <summary> 1223 /// <summary>
@@ -878,8 +1235,8 @@ namespace OpenSim.Region.Framework.Scenes
878 /// Constructor. This object is added to the scene later via AttachToScene() 1235 /// Constructor. This object is added to the scene later via AttachToScene()
879 /// </summary> 1236 /// </summary>
880 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) 1237 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
881 :this(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)) 1238 {
882 { 1239 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
883 } 1240 }
884 1241
885 /// <summary> 1242 /// <summary>
@@ -954,7 +1311,14 @@ namespace OpenSim.Region.Framework.Scenes
954 /// </summary> 1311 /// </summary>
955 public virtual void AttachToBackup() 1312 public virtual void AttachToBackup()
956 { 1313 {
1314<<<<<<< HEAD
957 if (CanBeBackedUp) 1315 if (CanBeBackedUp)
1316=======
1317 if (IsAttachment) return;
1318 m_scene.SceneGraph.FireAttachToBackup(this);
1319
1320 if (InSceneBackup)
1321>>>>>>> avn/ubitvar
958 { 1322 {
959// m_log.DebugFormat( 1323// m_log.DebugFormat(
960// "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID); 1324// "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID);
@@ -1001,6 +1365,13 @@ namespace OpenSim.Region.Framework.Scenes
1001 1365
1002 ApplyPhysics(); 1366 ApplyPhysics();
1003 1367
1368 if (RootPart.PhysActor != null)
1369 RootPart.Force = RootPart.Force;
1370 if (RootPart.PhysActor != null)
1371 RootPart.Torque = RootPart.Torque;
1372 if (RootPart.PhysActor != null)
1373 RootPart.Buoyancy = RootPart.Buoyancy;
1374
1004 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 1375 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
1005 // for the same object with very different properties. The caller must schedule the update. 1376 // for the same object with very different properties. The caller must schedule the update.
1006 //ScheduleGroupForFullUpdate(); 1377 //ScheduleGroupForFullUpdate();
@@ -1016,6 +1387,10 @@ namespace OpenSim.Region.Framework.Scenes
1016 EntityIntersection result = new EntityIntersection(); 1387 EntityIntersection result = new EntityIntersection();
1017 1388
1018 SceneObjectPart[] parts = m_parts.GetArray(); 1389 SceneObjectPart[] parts = m_parts.GetArray();
1390
1391 // Find closest hit here
1392 float idist = float.MaxValue;
1393
1019 for (int i = 0; i < parts.Length; i++) 1394 for (int i = 0; i < parts.Length; i++)
1020 { 1395 {
1021 SceneObjectPart part = parts[i]; 1396 SceneObjectPart part = parts[i];
@@ -1030,11 +1405,6 @@ namespace OpenSim.Region.Framework.Scenes
1030 1405
1031 EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters); 1406 EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
1032 1407
1033 // This may need to be updated to the maximum draw distance possible..
1034 // We might (and probably will) be checking for prim creation from other sims
1035 // when the camera crosses the border.
1036 float idist = Constants.RegionSize;
1037
1038 if (inter.HitTF) 1408 if (inter.HitTF)
1039 { 1409 {
1040 // We need to find the closest prim to return to the testcaller along the ray 1410 // We need to find the closest prim to return to the testcaller along the ray
@@ -1045,10 +1415,11 @@ namespace OpenSim.Region.Framework.Scenes
1045 result.obj = part; 1415 result.obj = part;
1046 result.normal = inter.normal; 1416 result.normal = inter.normal;
1047 result.distance = inter.distance; 1417 result.distance = inter.distance;
1418
1419 idist = inter.distance;
1048 } 1420 }
1049 } 1421 }
1050 } 1422 }
1051
1052 return result; 1423 return result;
1053 } 1424 }
1054 1425
@@ -1060,25 +1431,36 @@ namespace OpenSim.Region.Framework.Scenes
1060 /// <returns></returns> 1431 /// <returns></returns>
1061 public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ) 1432 public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ)
1062 { 1433 {
1434<<<<<<< HEAD
1063 maxX = -256f; 1435 maxX = -256f;
1064 maxY = -256f; 1436 maxY = -256f;
1065 maxZ = -256f; 1437 maxZ = -256f;
1066 minX = 10000f; 1438 minX = 10000f;
1067 minY = 10000f; 1439 minY = 10000f;
1068 minZ = 10000f; 1440 minZ = 10000f;
1441=======
1442 maxX = float.MinValue;
1443 maxY = float.MinValue;
1444 maxZ = float.MinValue;
1445 minX = float.MaxValue;
1446 minY = float.MaxValue;
1447 minZ = float.MaxValue;
1448>>>>>>> avn/ubitvar
1069 1449
1070 SceneObjectPart[] parts = m_parts.GetArray(); 1450 SceneObjectPart[] parts = m_parts.GetArray();
1071 for (int i = 0; i < parts.Length; i++) 1451 foreach (SceneObjectPart part in parts)
1072 { 1452 {
1073 SceneObjectPart part = parts[i];
1074
1075 Vector3 worldPos = part.GetWorldPosition(); 1453 Vector3 worldPos = part.GetWorldPosition();
1076 Vector3 offset = worldPos - AbsolutePosition; 1454 Vector3 offset = worldPos - AbsolutePosition;
1077 Quaternion worldRot; 1455 Quaternion worldRot;
1078 if (part.ParentID == 0) 1456 if (part.ParentID == 0)
1457 {
1079 worldRot = part.RotationOffset; 1458 worldRot = part.RotationOffset;
1459 }
1080 else 1460 else
1461 {
1081 worldRot = part.GetWorldRotation(); 1462 worldRot = part.GetWorldRotation();
1463 }
1082 1464
1083 Vector3 frontTopLeft; 1465 Vector3 frontTopLeft;
1084 Vector3 frontTopRight; 1466 Vector3 frontTopRight;
@@ -1090,6 +1472,8 @@ namespace OpenSim.Region.Framework.Scenes
1090 Vector3 backBottomLeft; 1472 Vector3 backBottomLeft;
1091 Vector3 backBottomRight; 1473 Vector3 backBottomRight;
1092 1474
1475 // Vector3[] corners = new Vector3[8];
1476
1093 Vector3 orig = Vector3.Zero; 1477 Vector3 orig = Vector3.Zero;
1094 1478
1095 frontTopLeft.X = orig.X - (part.Scale.X / 2); 1479 frontTopLeft.X = orig.X - (part.Scale.X / 2);
@@ -1124,6 +1508,38 @@ namespace OpenSim.Region.Framework.Scenes
1124 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 1508 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
1125 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 1509 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
1126 1510
1511
1512
1513 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
1514 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
1515 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
1516 //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
1517 //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
1518 //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
1519 //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
1520 //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
1521
1522 //for (int i = 0; i < 8; i++)
1523 //{
1524 // corners[i] = corners[i] * worldRot;
1525 // corners[i] += offset;
1526
1527 // if (corners[i].X > maxX)
1528 // maxX = corners[i].X;
1529 // if (corners[i].X < minX)
1530 // minX = corners[i].X;
1531
1532 // if (corners[i].Y > maxY)
1533 // maxY = corners[i].Y;
1534 // if (corners[i].Y < minY)
1535 // minY = corners[i].Y;
1536
1537 // if (corners[i].Z > maxZ)
1538 // maxZ = corners[i].Y;
1539 // if (corners[i].Z < minZ)
1540 // minZ = corners[i].Z;
1541 //}
1542
1127 frontTopLeft = frontTopLeft * worldRot; 1543 frontTopLeft = frontTopLeft * worldRot;
1128 frontTopRight = frontTopRight * worldRot; 1544 frontTopRight = frontTopRight * worldRot;
1129 frontBottomLeft = frontBottomLeft * worldRot; 1545 frontBottomLeft = frontBottomLeft * worldRot;
@@ -1145,6 +1561,15 @@ namespace OpenSim.Region.Framework.Scenes
1145 backTopLeft += offset; 1561 backTopLeft += offset;
1146 backTopRight += offset; 1562 backTopRight += offset;
1147 1563
1564 //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
1565 //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
1566 //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
1567 //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
1568 //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
1569 //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
1570 //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
1571 //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
1572
1148 if (frontTopRight.X > maxX) 1573 if (frontTopRight.X > maxX)
1149 maxX = frontTopRight.X; 1574 maxX = frontTopRight.X;
1150 if (frontTopLeft.X > maxX) 1575 if (frontTopLeft.X > maxX)
@@ -1288,17 +1713,118 @@ namespace OpenSim.Region.Framework.Scenes
1288 1713
1289 #endregion 1714 #endregion
1290 1715
1716 public void GetResourcesCosts(SceneObjectPart apart,
1717 out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost)
1718 {
1719 // this information may need to be cached
1720
1721 float cost;
1722 float tmpcost;
1723
1724 bool ComplexCost = false;
1725
1726 SceneObjectPart p;
1727 SceneObjectPart[] parts;
1728
1729 lock (m_parts)
1730 {
1731 parts = m_parts.GetArray();
1732 }
1733
1734 int nparts = parts.Length;
1735
1736
1737 for (int i = 0; i < nparts; i++)
1738 {
1739 p = parts[i];
1740
1741 if (p.UsesComplexCost)
1742 {
1743 ComplexCost = true;
1744 break;
1745 }
1746 }
1747
1748 if (ComplexCost)
1749 {
1750 linksetResCost = 0;
1751 linksetPhysCost = 0;
1752 partCost = 0;
1753 partPhysCost = 0;
1754
1755 for (int i = 0; i < nparts; i++)
1756 {
1757 p = parts[i];
1758
1759 cost = p.StreamingCost;
1760 tmpcost = p.SimulationCost;
1761 if (tmpcost > cost)
1762 cost = tmpcost;
1763 tmpcost = p.PhysicsCost;
1764 if (tmpcost > cost)
1765 cost = tmpcost;
1766
1767 linksetPhysCost += tmpcost;
1768 linksetResCost += cost;
1769
1770 if (p == apart)
1771 {
1772 partCost = cost;
1773 partPhysCost = tmpcost;
1774 }
1775 }
1776 }
1777 else
1778 {
1779 partPhysCost = 1.0f;
1780 partCost = 1.0f;
1781 linksetResCost = (float)nparts;
1782 linksetPhysCost = linksetResCost;
1783 }
1784 }
1785
1786 public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost)
1787 {
1788 SceneObjectPart p;
1789 SceneObjectPart[] parts;
1790
1791 lock (m_parts)
1792 {
1793 parts = m_parts.GetArray();
1794 }
1795
1796 int nparts = parts.Length;
1797
1798 PhysCost = 0;
1799 StreamCost = 0;
1800 SimulCost = 0;
1801
1802 for (int i = 0; i < nparts; i++)
1803 {
1804 p = parts[i];
1805
1806 StreamCost += p.StreamingCost;
1807 SimulCost += p.SimulationCost;
1808 PhysCost += p.PhysicsCost;
1809 }
1810 }
1811
1291 public void SaveScriptedState(XmlTextWriter writer) 1812 public void SaveScriptedState(XmlTextWriter writer)
1292 { 1813 {
1814 SaveScriptedState(writer, false);
1815 }
1816
1817 public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
1818 {
1293 XmlDocument doc = new XmlDocument(); 1819 XmlDocument doc = new XmlDocument();
1294 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1820 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
1295 1821
1296 SceneObjectPart[] parts = m_parts.GetArray(); 1822 SceneObjectPart[] parts = m_parts.GetArray();
1297 for (int i = 0; i < parts.Length; i++) 1823 for (int i = 0; i < parts.Length; i++)
1298 { 1824 {
1299 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(); 1825 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
1300 foreach (KeyValuePair<UUID, string> kvp in pstates) 1826 foreach (KeyValuePair<UUID, string> kvp in pstates)
1301 states.Add(kvp.Key, kvp.Value); 1827 states[kvp.Key] = kvp.Value;
1302 } 1828 }
1303 1829
1304 if (states.Count > 0) 1830 if (states.Count > 0)
@@ -1317,6 +1843,183 @@ namespace OpenSim.Region.Framework.Scenes
1317 } 1843 }
1318 } 1844 }
1319 1845
1846<<<<<<< HEAD
1847
1848 /// <summary>
1849 ///
1850 /// </summary>
1851 /// <param name="part"></param>
1852 private void SetPartAsNonRoot(SceneObjectPart part)
1853 {
1854 part.ParentID = m_rootPart.LocalId;
1855 part.ClearUndoState();
1856=======
1857 /// <summary>
1858 /// Add the avatar to this linkset (avatar is sat).
1859 /// </summary>
1860 /// <param name="agentID"></param>
1861 public void AddAvatar(UUID agentID)
1862 {
1863 ScenePresence presence;
1864 if (m_scene.TryGetScenePresence(agentID, out presence))
1865 {
1866 if (!m_linkedAvatars.Contains(presence))
1867 {
1868 m_linkedAvatars.Add(presence);
1869 }
1870 }
1871 }
1872
1873 /// <summary>
1874 /// Delete the avatar from this linkset (avatar is unsat).
1875 /// </summary>
1876 /// <param name="agentID"></param>
1877 public void DeleteAvatar(UUID agentID)
1878 {
1879 ScenePresence presence;
1880 if (m_scene.TryGetScenePresence(agentID, out presence))
1881 {
1882 if (m_linkedAvatars.Contains(presence))
1883 {
1884 m_linkedAvatars.Remove(presence);
1885 }
1886 }
1887 }
1888
1889 /// <summary>
1890 /// Returns the list of linked presences (avatars sat on this group)
1891 /// </summary>
1892 /// <param name="agentID"></param>
1893 public List<ScenePresence> GetLinkedAvatars()
1894 {
1895 return m_linkedAvatars;
1896>>>>>>> avn/ubitvar
1897 }
1898
1899 /// <summary>
1900 /// Attach this scene object to the given avatar.
1901 /// </summary>
1902 /// <param name="agentID"></param>
1903 /// <param name="attachmentpoint"></param>
1904 /// <param name="AttachOffset"></param>
1905 private void AttachToAgent(
1906 ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
1907 {
1908 if (avatar != null)
1909 {
1910 // don't attach attachments to child agents
1911 if (avatar.IsChildAgent) return;
1912
1913 // Remove from database and parcel prim count
1914 m_scene.DeleteFromStorage(so.UUID);
1915 m_scene.EventManager.TriggerParcelPrimCountTainted();
1916
1917 so.AttachedAvatar = avatar.UUID;
1918
1919 if (so.RootPart.PhysActor != null)
1920 {
1921 m_scene.PhysicsScene.RemovePrim(so.RootPart.PhysActor);
1922 so.RootPart.PhysActor = null;
1923 }
1924
1925 so.AbsolutePosition = attachOffset;
1926 so.RootPart.AttachedPos = attachOffset;
1927 so.IsAttachment = true;
1928 so.RootPart.SetParentLocalId(avatar.LocalId);
1929 so.AttachmentPoint = attachmentpoint;
1930
1931 avatar.AddAttachment(this);
1932
1933 if (!silent)
1934 {
1935 // Killing it here will cause the client to deselect it
1936 // It then reappears on the avatar, deselected
1937 // through the full update below
1938 //
1939 if (IsSelected)
1940 {
1941 m_scene.SendKillObject(new List<uint> { m_rootPart.LocalId });
1942 }
1943
1944 IsSelected = false; // fudge....
1945 ScheduleGroupForFullUpdate();
1946 }
1947 }
1948 else
1949 {
1950 m_log.WarnFormat(
1951 "[SOG]: Tried to add attachment {0} to avatar with UUID {1} in region {2} but the avatar is not present",
1952 UUID, avatar.ControllingClient.AgentId, Scene.RegionInfo.RegionName);
1953 }
1954 }
1955
1956 public byte GetAttachmentPoint()
1957 {
1958 return m_rootPart.Shape.State;
1959 }
1960
1961 public void DetachToGround()
1962 {
1963 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
1964 if (avatar == null)
1965 return;
1966 m_rootPart.Shape.LastAttachPoint = m_rootPart.Shape.State;
1967 m_rootPart.AttachedPos = m_rootPart.OffsetPosition;
1968 avatar.RemoveAttachment(this);
1969
1970 Vector3 detachedpos = new Vector3(127f,127f,127f);
1971 if (avatar == null)
1972 return;
1973
1974 detachedpos = avatar.AbsolutePosition;
1975 FromItemID = UUID.Zero;
1976
1977 AbsolutePosition = detachedpos;
1978 AttachedAvatar = UUID.Zero;
1979
1980 //SceneObjectPart[] parts = m_parts.GetArray();
1981 //for (int i = 0; i < parts.Length; i++)
1982 // parts[i].AttachedAvatar = UUID.Zero;
1983
1984 m_rootPart.SetParentLocalId(0);
1985 AttachmentPoint = (byte)0;
1986 // must check if buildind should be true or false here
1987// m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false);
1988 ApplyPhysics();
1989
1990 HasGroupChanged = true;
1991 RootPart.Rezzed = DateTime.Now;
1992 RootPart.RemFlag(PrimFlags.TemporaryOnRez);
1993 AttachToBackup();
1994 m_scene.EventManager.TriggerParcelPrimCountTainted();
1995 m_rootPart.ScheduleFullUpdate();
1996 m_rootPart.ClearUndoState();
1997 }
1998
1999 public void DetachToInventoryPrep()
2000 {
2001 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
2002 //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
2003 if (avatar != null)
2004 {
2005 //detachedpos = avatar.AbsolutePosition;
2006 avatar.RemoveAttachment(this);
2007 }
2008
2009 AttachedAvatar = UUID.Zero;
2010
2011 /*SceneObjectPart[] parts = m_parts.GetArray();
2012 for (int i = 0; i < parts.Length; i++)
2013 parts[i].AttachedAvatar = UUID.Zero;*/
2014
2015 m_rootPart.SetParentLocalId(0);
2016 //m_rootPart.SetAttachmentPoint((byte)0);
2017 IsAttachment = false;
2018 AbsolutePosition = m_rootPart.AttachedPos;
2019 //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
2020 //AttachToBackup();
2021 //m_rootPart.ScheduleFullUpdate();
2022 }
1320 2023
1321 /// <summary> 2024 /// <summary>
1322 /// 2025 ///
@@ -1358,7 +2061,10 @@ namespace OpenSim.Region.Framework.Scenes
1358 public void AddPart(SceneObjectPart part) 2061 public void AddPart(SceneObjectPart part)
1359 { 2062 {
1360 part.SetParent(this); 2063 part.SetParent(this);
1361 part.LinkNum = m_parts.Add(part.UUID, part); 2064 m_parts.Add(part.UUID, part);
2065
2066 part.LinkNum = m_parts.Count;
2067
1362 if (part.LinkNum == 2) 2068 if (part.LinkNum == 2)
1363 RootPart.LinkNum = 1; 2069 RootPart.LinkNum = 1;
1364 } 2070 }
@@ -1384,6 +2090,14 @@ namespace OpenSim.Region.Framework.Scenes
1384 parts[i].UUID = UUID.Random(); 2090 parts[i].UUID = UUID.Random();
1385 } 2091 }
1386 2092
2093 // helper provided for parts.
2094 public int GetSceneMaxUndo()
2095 {
2096 if (m_scene != null)
2097 return m_scene.MaxUndoCount;
2098 return 5;
2099 }
2100
1387 // justincc: I don't believe this hack is needed any longer, especially since the physics 2101 // justincc: I don't believe this hack is needed any longer, especially since the physics
1388 // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false 2102 // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
1389 // this method was preventing proper reload of scene objects. 2103 // this method was preventing proper reload of scene objects.
@@ -1405,11 +2119,21 @@ namespace OpenSim.Region.Framework.Scenes
1405 // Setting this SOG's absolute position also loops through and sets the positions 2119 // Setting this SOG's absolute position also loops through and sets the positions
1406 // of the SOP's in this SOG's linkset. This has the side affect of making sure 2120 // of the SOP's in this SOG's linkset. This has the side affect of making sure
1407 // the physics world matches the simulated world. 2121 // the physics world matches the simulated world.
1408 AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works? 2122 // AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
1409 2123
1410 // teravus: AbsolutePosition is NOT a normal property! 2124 // teravus: AbsolutePosition is NOT a normal property!
1411 // the code in the getter of AbsolutePosition is significantly different then the code in the setter! 2125 // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
1412 // jhurliman: Then why is it a property instead of two methods? 2126 // jhurliman: Then why is it a property instead of two methods?
2127
2128 // do only what is supposed to do
2129 Vector3 groupPosition = m_rootPart.GroupPosition;
2130 SceneObjectPart[] parts = m_parts.GetArray();
2131
2132 foreach (SceneObjectPart part in parts)
2133 {
2134 if (part != m_rootPart)
2135 part.GroupPosition = groupPosition;
2136 }
1413 } 2137 }
1414 2138
1415 public UUID GetPartsFullID(uint localID) 2139 public UUID GetPartsFullID(uint localID)
@@ -1441,7 +2165,7 @@ namespace OpenSim.Region.Framework.Scenes
1441// "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}", 2165// "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}",
1442// remoteClient.Name, part.Name, part.LocalId, offsetPos); 2166// remoteClient.Name, part.Name, part.LocalId, offsetPos);
1443 2167
1444 part.StoreUndoState(); 2168// part.StoreUndoState();
1445 part.OnGrab(offsetPos, remoteClient); 2169 part.OnGrab(offsetPos, remoteClient);
1446 } 2170 }
1447 2171
@@ -1461,28 +2185,43 @@ namespace OpenSim.Region.Framework.Scenes
1461 /// <param name="silent">If true then deletion is not broadcast to clients</param> 2185 /// <param name="silent">If true then deletion is not broadcast to clients</param>
1462 public void DeleteGroupFromScene(bool silent) 2186 public void DeleteGroupFromScene(bool silent)
1463 { 2187 {
2188 // We need to keep track of this state in case this group is still queued for backup.
2189 IsDeleted = true;
2190
2191 DetachFromBackup();
2192
1464 SceneObjectPart[] parts = m_parts.GetArray(); 2193 SceneObjectPart[] parts = m_parts.GetArray();
1465 for (int i = 0; i < parts.Length; i++) 2194 for (int i = 0; i < parts.Length; i++)
1466 { 2195 {
1467 SceneObjectPart part = parts[i]; 2196 SceneObjectPart part = parts[i];
1468 2197
1469 Scene.ForEachScenePresence(sp => 2198 if (Scene != null)
1470 { 2199 {
2200<<<<<<< HEAD
1471 if (!sp.IsChildAgent && sp.ParentID == part.LocalId) 2201 if (!sp.IsChildAgent && sp.ParentID == part.LocalId)
1472 sp.StandUp(); 2202 sp.StandUp();
1473 2203
1474 if (!silent) 2204 if (!silent)
2205=======
2206 Scene.ForEachRootScenePresence(delegate(ScenePresence avatar)
2207>>>>>>> avn/ubitvar
1475 { 2208 {
1476 part.ClearUpdateSchedule(); 2209 if (avatar.ParentID == LocalId)
1477 if (part == m_rootPart) 2210 avatar.StandUp();
2211
2212 if (!silent)
1478 { 2213 {
1479 if (!IsAttachment 2214 part.ClearUpdateSchedule();
1480 || AttachedAvatar == sp.UUID 2215 if (part == m_rootPart)
1481 || !HasPrivateAttachmentPoint) 2216 {
1482 sp.ControllingClient.SendKillObject(new List<uint> { part.LocalId }); 2217 if (!IsAttachment
2218 || AttachedAvatar == avatar.ControllingClient.AgentId
2219 || !HasPrivateAttachmentPoint)
2220 avatar.ControllingClient.SendKillObject(new List<uint> { part.LocalId });
2221 }
1483 } 2222 }
1484 } 2223 });
1485 }); 2224 }
1486 } 2225 }
1487 } 2226 }
1488 2227
@@ -1553,28 +2292,43 @@ namespace OpenSim.Region.Framework.Scenes
1553 /// </summary> 2292 /// </summary>
1554 public void ApplyPhysics() 2293 public void ApplyPhysics()
1555 { 2294 {
1556 // Apply physics to the root prim
1557 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive);
1558
1559 // Apply physics to child prims
1560 SceneObjectPart[] parts = m_parts.GetArray(); 2295 SceneObjectPart[] parts = m_parts.GetArray();
1561 if (parts.Length > 1) 2296 if (parts.Length > 1)
1562 { 2297 {
2298 ResetChildPrimPhysicsPositions();
2299
2300 // Apply physics to the root prim
2301 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true);
2302
2303
1563 for (int i = 0; i < parts.Length; i++) 2304 for (int i = 0; i < parts.Length; i++)
1564 { 2305 {
1565 SceneObjectPart part = parts[i]; 2306 SceneObjectPart part = parts[i];
1566 if (part.LocalId != m_rootPart.LocalId) 2307 if (part.LocalId != m_rootPart.LocalId)
1567 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive); 2308 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true);
1568 } 2309 }
1569
1570 // Hack to get the physics scene geometries in the right spot 2310 // Hack to get the physics scene geometries in the right spot
1571 ResetChildPrimPhysicsPositions(); 2311// ResetChildPrimPhysicsPositions();
2312 if (m_rootPart.PhysActor != null)
2313 {
2314 m_rootPart.PhysActor.Building = false;
2315 }
2316 }
2317 else
2318 {
2319 // Apply physics to the root prim
2320 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false);
1572 } 2321 }
1573 } 2322 }
1574 2323
1575 public void SetOwnerId(UUID userId) 2324 public void SetOwnerId(UUID userId)
1576 { 2325 {
1577 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 2326 ForEachPart(delegate(SceneObjectPart part)
2327 {
2328
2329 part.OwnerID = userId;
2330
2331 });
1578 } 2332 }
1579 2333
1580 public void ForEachPart(Action<SceneObjectPart> whatToDo) 2334 public void ForEachPart(Action<SceneObjectPart> whatToDo)
@@ -1599,18 +2353,24 @@ namespace OpenSim.Region.Framework.Scenes
1599 return; 2353 return;
1600 } 2354 }
1601 2355
1602 if (IsDeleted || UUID == UUID.Zero) 2356 if (IsDeleted || inTransit || UUID == UUID.Zero)
1603 { 2357 {
1604// m_log.DebugFormat( 2358// m_log.DebugFormat(
1605// "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID); 2359// "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID);
1606 return; 2360 return;
1607 } 2361 }
1608 2362
2363 if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
2364 return;
2365
1609 // Since this is the top of the section of call stack for backing up a particular scene object, don't let 2366 // Since this is the top of the section of call stack for backing up a particular scene object, don't let
1610 // any exception propogate upwards. 2367 // any exception propogate upwards.
1611 try 2368 try
1612 { 2369 {
1613 if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart 2370 if (!m_scene.ShuttingDown || // if shutting down then there will be nothing to handle the return so leave till next restart
2371 !m_scene.LoginsEnabled || // We're starting up or doing maintenance, don't mess with things
2372 m_scene.LoadingPrims) // Land may not be valid yet
2373
1614 { 2374 {
1615 ILandObject parcel = m_scene.LandChannel.GetLandObject( 2375 ILandObject parcel = m_scene.LandChannel.GetLandObject(
1616 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); 2376 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
@@ -1637,6 +2397,7 @@ namespace OpenSim.Region.Framework.Scenes
1637 } 2397 }
1638 } 2398 }
1639 } 2399 }
2400
1640 } 2401 }
1641 2402
1642 if (m_scene.UseBackup && HasGroupChanged) 2403 if (m_scene.UseBackup && HasGroupChanged)
@@ -1644,10 +2405,31 @@ namespace OpenSim.Region.Framework.Scenes
1644 // don't backup while it's selected or you're asking for changes mid stream. 2405 // don't backup while it's selected or you're asking for changes mid stream.
1645 if (isTimeToPersist() || forcedBackup) 2406 if (isTimeToPersist() || forcedBackup)
1646 { 2407 {
2408 if (m_rootPart.PhysActor != null &&
2409 (!m_rootPart.PhysActor.IsPhysical))
2410 {
2411 // Possible ghost prim
2412 if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
2413 {
2414 foreach (SceneObjectPart part in m_parts.GetArray())
2415 {
2416 // Re-set physics actor positions and
2417 // orientations
2418 part.GroupPosition = m_rootPart.GroupPosition;
2419 }
2420 }
2421 }
1647// m_log.DebugFormat( 2422// m_log.DebugFormat(
1648// "[SCENE]: Storing {0}, {1} in {2}", 2423// "[SCENE]: Storing {0}, {1} in {2}",
1649// Name, UUID, m_scene.RegionInfo.RegionName); 2424// Name, UUID, m_scene.RegionInfo.RegionName);
1650 2425
2426 if (RootPart.Shape.PCode == 9 && RootPart.Shape.State != 0)
2427 {
2428 RootPart.Shape.LastAttachPoint = RootPart.Shape.State;
2429 RootPart.Shape.State = 0;
2430 ScheduleGroupForFullUpdate();
2431 }
2432
1651 SceneObjectGroup backup_group = Copy(false); 2433 SceneObjectGroup backup_group = Copy(false);
1652 backup_group.RootPart.Velocity = RootPart.Velocity; 2434 backup_group.RootPart.Velocity = RootPart.Velocity;
1653 backup_group.RootPart.Acceleration = RootPart.Acceleration; 2435 backup_group.RootPart.Acceleration = RootPart.Acceleration;
@@ -1657,13 +2439,22 @@ namespace OpenSim.Region.Framework.Scenes
1657 GroupContainsForeignPrims = false; 2439 GroupContainsForeignPrims = false;
1658 2440
1659 m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this); 2441 m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
2442
1660 datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID); 2443 datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
1661 2444
1662 backup_group.ForEachPart(delegate(SceneObjectPart part) 2445 backup_group.ForEachPart(delegate(SceneObjectPart part)
1663 { 2446 {
1664 part.Inventory.ProcessInventoryBackup(datastore); 2447 part.Inventory.ProcessInventoryBackup(datastore);
2448
2449 // take the change to delete things
2450 if(part.KeyframeMotion != null)
2451 {
2452 part.KeyframeMotion.Delete();
2453 part.KeyframeMotion = null;
2454 }
1665 }); 2455 });
1666 2456
2457
1667 backup_group = null; 2458 backup_group = null;
1668 } 2459 }
1669// else 2460// else
@@ -1713,6 +2504,7 @@ namespace OpenSim.Region.Framework.Scenes
1713 /// <returns></returns> 2504 /// <returns></returns>
1714 public SceneObjectGroup Copy(bool userExposed) 2505 public SceneObjectGroup Copy(bool userExposed)
1715 { 2506 {
2507<<<<<<< HEAD
1716 // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up 2508 // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up
1717 // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator 2509 // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator
1718 // but not between regions on different simulators). Really, all copying should be done explicitly. 2510 // but not between regions on different simulators). Really, all copying should be done explicitly.
@@ -1721,18 +2513,32 @@ namespace OpenSim.Region.Framework.Scenes
1721 dupe.Backup = false; 2513 dupe.Backup = false;
1722 dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>(); 2514 dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
1723 dupe.m_sittingAvatars = new List<ScenePresence>(); 2515 dupe.m_sittingAvatars = new List<ScenePresence>();
2516=======
2517 m_dupeInProgress = true;
2518 SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone();
2519 dupe.m_isBackedUp = false;
2520 dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
2521
2522 dupe.inTransit = inTransit; // this shouldn't be needed TEST
2523
2524 // new group as no sitting avatars
2525 dupe.m_linkedAvatars = new List<ScenePresence>();
2526 dupe.m_sittingAvatars = new List<UUID>();
2527
2528>>>>>>> avn/ubitvar
1724 dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); 2529 dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
1725 dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; 2530 dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
2531
1726 2532
1727 if (userExposed) 2533 if (userExposed)
1728 dupe.m_rootPart.TrimPermissions(); 2534 dupe.m_rootPart.TrimPermissions();
1729 2535
1730 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray()); 2536 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
1731 2537
1732 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 2538 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1733 { 2539 {
1734 return p1.LinkNum.CompareTo(p2.LinkNum); 2540 return p1.LinkNum.CompareTo(p2.LinkNum);
1735 } 2541 }
1736 ); 2542 );
1737 2543
1738 foreach (SceneObjectPart part in partList) 2544 foreach (SceneObjectPart part in partList)
@@ -1742,43 +2548,56 @@ namespace OpenSim.Region.Framework.Scenes
1742 { 2548 {
1743 newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); 2549 newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed);
1744 newPart.LinkNum = part.LinkNum; 2550 newPart.LinkNum = part.LinkNum;
1745 } 2551// if (userExposed)
2552 newPart.ParentID = dupe.m_rootPart.LocalId;
2553 }
1746 else 2554 else
1747 { 2555 {
1748 newPart = dupe.m_rootPart; 2556 newPart = dupe.m_rootPart;
1749 } 2557 }
2558/*
2559 bool isphys = ((newPart.Flags & PrimFlags.Physics) != 0);
2560 bool isphan = ((newPart.Flags & PrimFlags.Phantom) != 0);
1750 2561
1751 // Need to duplicate the physics actor as well 2562 // Need to duplicate the physics actor as well
1752 PhysicsActor originalPartPa = part.PhysActor; 2563 if (userExposed && (isphys || !isphan || newPart.VolumeDetectActive))
1753 if (originalPartPa != null && userExposed)
1754 { 2564 {
1755 PrimitiveBaseShape pbs = newPart.Shape; 2565 PrimitiveBaseShape pbs = newPart.Shape;
1756
1757 newPart.PhysActor 2566 newPart.PhysActor
1758 = m_scene.PhysicsScene.AddPrimShape( 2567 = m_scene.PhysicsScene.AddPrimShape(
1759 string.Format("{0}/{1}", newPart.Name, newPart.UUID), 2568 string.Format("{0}/{1}", newPart.Name, newPart.UUID),
1760 pbs, 2569 pbs,
1761 newPart.AbsolutePosition, 2570 newPart.AbsolutePosition,
1762 newPart.Scale, 2571 newPart.Scale,
1763 newPart.RotationOffset, 2572 newPart.GetWorldRotation(),
1764 originalPartPa.IsPhysical, 2573 isphys,
2574 isphan,
1765 newPart.LocalId); 2575 newPart.LocalId);
1766 2576
1767 newPart.DoPhysicsPropertyUpdate(originalPartPa.IsPhysical, true); 2577 newPart.DoPhysicsPropertyUpdate(isphys, true);
1768 } 2578 */
2579 if (userExposed)
2580 newPart.ApplyPhysics((uint)newPart.Flags,newPart.VolumeDetectActive,true);
2581// }
2582 // copy keyframemotion
1769 if (part.KeyframeMotion != null) 2583 if (part.KeyframeMotion != null)
1770 newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe); 2584 newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe);
1771 } 2585 }
1772 2586
1773 if (userExposed) 2587 if (userExposed)
1774 { 2588 {
1775 dupe.UpdateParentIDs(); 2589// done above dupe.UpdateParentIDs();
2590
2591 if (dupe.m_rootPart.PhysActor != null)
2592 dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building
2593
1776 dupe.HasGroupChanged = true; 2594 dupe.HasGroupChanged = true;
1777 dupe.AttachToBackup(); 2595 dupe.AttachToBackup();
1778 2596
1779 ScheduleGroupForFullUpdate(); 2597 ScheduleGroupForFullUpdate();
1780 } 2598 }
1781 2599
2600 m_dupeInProgress = false;
1782 return dupe; 2601 return dupe;
1783 } 2602 }
1784 2603
@@ -1790,7 +2609,13 @@ namespace OpenSim.Region.Framework.Scenes
1790 /// <param name="cGroupID"></param> 2609 /// <param name="cGroupID"></param>
1791 public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) 2610 public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
1792 { 2611 {
1793 SetRootPart(part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed)); 2612 SceneObjectPart newpart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed);
2613// SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed);
2614// newpart.LocalId = m_scene.AllocateLocalId();
2615
2616 SetRootPart(newpart);
2617 if (userExposed)
2618 RootPart.Velocity = Vector3.Zero; // In case source is moving
1794 } 2619 }
1795 2620
1796 public void ScriptSetPhysicsStatus(bool usePhysics) 2621 public void ScriptSetPhysicsStatus(bool usePhysics)
@@ -1848,13 +2673,14 @@ namespace OpenSim.Region.Framework.Scenes
1848 2673
1849 if (pa != null) 2674 if (pa != null)
1850 { 2675 {
1851 pa.AddForce(impulse, true); 2676 // false to be applied as a impulse
2677 pa.AddForce(impulse, false);
1852 m_scene.PhysicsScene.AddPhysicsActorTaint(pa); 2678 m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
1853 } 2679 }
1854 } 2680 }
1855 } 2681 }
1856 2682
1857 public void applyAngularImpulse(Vector3 impulse) 2683 public void ApplyAngularImpulse(Vector3 impulse)
1858 { 2684 {
1859 PhysicsActor pa = RootPart.PhysActor; 2685 PhysicsActor pa = RootPart.PhysActor;
1860 2686
@@ -1862,21 +2688,8 @@ namespace OpenSim.Region.Framework.Scenes
1862 { 2688 {
1863 if (!IsAttachment) 2689 if (!IsAttachment)
1864 { 2690 {
1865 pa.AddAngularForce(impulse, true); 2691 // false to be applied as a impulse
1866 m_scene.PhysicsScene.AddPhysicsActorTaint(pa); 2692 pa.AddAngularForce(impulse, false);
1867 }
1868 }
1869 }
1870
1871 public void setAngularImpulse(Vector3 impulse)
1872 {
1873 PhysicsActor pa = RootPart.PhysActor;
1874
1875 if (pa != null)
1876 {
1877 if (!IsAttachment)
1878 {
1879 pa.Torque = impulse;
1880 m_scene.PhysicsScene.AddPhysicsActorTaint(pa); 2693 m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
1881 } 2694 }
1882 } 2695 }
@@ -1884,21 +2697,15 @@ namespace OpenSim.Region.Framework.Scenes
1884 2697
1885 public Vector3 GetTorque() 2698 public Vector3 GetTorque()
1886 { 2699 {
1887 PhysicsActor pa = RootPart.PhysActor; 2700 return RootPart.Torque;
1888
1889 if (pa != null)
1890 {
1891 if (!IsAttachment)
1892 {
1893 Vector3 torque = pa.Torque;
1894 return torque;
1895 }
1896 }
1897
1898 return Vector3.Zero;
1899 } 2701 }
1900 2702
2703<<<<<<< HEAD
1901 public void MoveToTarget(Vector3 target, float tau) 2704 public void MoveToTarget(Vector3 target, float tau)
2705=======
2706 // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object
2707 public void moveToTarget(Vector3 target, float tau)
2708>>>>>>> avn/ubitvar
1902 { 2709 {
1903 if (IsAttachment) 2710 if (IsAttachment)
1904 { 2711 {
@@ -1925,6 +2732,7 @@ namespace OpenSim.Region.Framework.Scenes
1925 if (IsAttachment) 2732 if (IsAttachment)
1926 { 2733 {
1927 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); 2734 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
2735<<<<<<< HEAD
1928 2736
1929 if (avatar != null) 2737 if (avatar != null)
1930 avatar.ResetMoveToTarget(); 2738 avatar.ResetMoveToTarget();
@@ -1938,10 +2746,64 @@ namespace OpenSim.Region.Framework.Scenes
1938 pa.PIDActive = false; 2746 pa.PIDActive = false;
1939 2747
1940 ScheduleGroupForTerseUpdate(); 2748 ScheduleGroupForTerseUpdate();
2749=======
2750 if (avatar != null)
2751 {
2752 avatar.ResetMoveToTarget();
2753 }
2754 }
2755 else
2756 {
2757 PhysicsActor pa = RootPart.PhysActor;
2758
2759 if (pa != null)
2760 pa.PIDActive = false;
2761
2762 RootPart.ScheduleTerseUpdate(); // send a stop information
2763 }
2764 }
2765
2766 public void rotLookAt(Quaternion target, float strength, float damping)
2767 {
2768 SceneObjectPart rootpart = m_rootPart;
2769 if (rootpart != null)
2770 {
2771 if (IsAttachment)
2772 {
2773 /*
2774 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2775 if (avatar != null)
2776 {
2777 Rotate the Av?
2778 } */
2779 }
2780 else
2781 {
2782 if (rootpart.PhysActor != null)
2783 { // APID must be implemented in your physics system for this to function.
2784 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
2785 rootpart.PhysActor.APIDStrength = strength;
2786 rootpart.PhysActor.APIDDamping = damping;
2787 rootpart.PhysActor.APIDActive = true;
2788 }
2789>>>>>>> avn/ubitvar
1941 } 2790 }
1942 } 2791 }
1943 } 2792 }
2793
2794 public void stopLookAt()
2795 {
2796 SceneObjectPart rootpart = m_rootPart;
2797 if (rootpart != null)
2798 {
2799 if (rootpart.PhysActor != null)
2800 { // APID must be implemented in your physics system for this to function.
2801 rootpart.PhysActor.APIDActive = false;
2802 }
2803 }
1944 2804
2805 }
2806
1945 /// <summary> 2807 /// <summary>
1946 /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds. 2808 /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
1947 /// </summary> 2809 /// </summary>
@@ -1958,7 +2820,7 @@ namespace OpenSim.Region.Framework.Scenes
1958 { 2820 {
1959 pa.PIDHoverHeight = height; 2821 pa.PIDHoverHeight = height;
1960 pa.PIDHoverType = hoverType; 2822 pa.PIDHoverType = hoverType;
1961 pa.PIDTau = tau; 2823 pa.PIDHoverTau = tau;
1962 pa.PIDHoverActive = true; 2824 pa.PIDHoverActive = true;
1963 } 2825 }
1964 else 2826 else
@@ -1999,6 +2861,9 @@ namespace OpenSim.Region.Framework.Scenes
1999 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) 2861 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
2000 { 2862 {
2001 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2863 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
2864// SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed);
2865// newPart.LocalId = m_scene.AllocateLocalId();
2866
2002 AddPart(newPart); 2867 AddPart(newPart);
2003 2868
2004 SetPartAsNonRoot(newPart); 2869 SetPartAsNonRoot(newPart);
@@ -2048,6 +2913,7 @@ namespace OpenSim.Region.Framework.Scenes
2048 2913
2049 #endregion 2914 #endregion
2050 2915
2916
2051 public override void Update() 2917 public override void Update()
2052 { 2918 {
2053 // Check that the group was not deleted before the scheduled update 2919 // Check that the group was not deleted before the scheduled update
@@ -2055,7 +2921,7 @@ namespace OpenSim.Region.Framework.Scenes
2055 // an object has been deleted from a scene before update was processed. 2921 // an object has been deleted from a scene before update was processed.
2056 // A more fundamental overhaul of the update mechanism is required to eliminate all 2922 // A more fundamental overhaul of the update mechanism is required to eliminate all
2057 // the race conditions. 2923 // the race conditions.
2058 if (IsDeleted) 2924 if (IsDeleted || inTransit)
2059 return; 2925 return;
2060 2926
2061 // Even temporary objects take part in physics (e.g. temp-on-rez bullets) 2927 // Even temporary objects take part in physics (e.g. temp-on-rez bullets)
@@ -2066,18 +2932,17 @@ namespace OpenSim.Region.Framework.Scenes
2066 // check to see if the physical position or rotation warrant an update. 2932 // check to see if the physical position or rotation warrant an update.
2067 if (m_rootPart.UpdateFlag == UpdateRequired.NONE) 2933 if (m_rootPart.UpdateFlag == UpdateRequired.NONE)
2068 { 2934 {
2069 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2935 // rootpart SendScheduledUpdates will check if a update is needed
2070 2936 m_rootPart.UpdateFlag = UpdateRequired.TERSE;
2071 if (UsePhysics && !AbsolutePosition.ApproxEquals(lastPhysGroupPos, 0.02f)) 2937 }
2072 {
2073 m_rootPart.UpdateFlag = UpdateRequired.TERSE;
2074 lastPhysGroupPos = AbsolutePosition;
2075 }
2076 2938
2077 if (UsePhysics && !GroupRotation.ApproxEquals(lastPhysGroupRot, 0.1f)) 2939 if (IsAttachment)
2940 {
2941 ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
2942 if (sp != null)
2078 { 2943 {
2079 m_rootPart.UpdateFlag = UpdateRequired.TERSE; 2944 sp.SendAttachmentScheduleUpdate(this);
2080 lastPhysGroupRot = GroupRotation; 2945 return;
2081 } 2946 }
2082 } 2947 }
2083 2948
@@ -2137,20 +3002,30 @@ namespace OpenSim.Region.Framework.Scenes
2137 /// Immediately send a full update for this scene object. 3002 /// Immediately send a full update for this scene object.
2138 /// </summary> 3003 /// </summary>
2139 public void SendGroupFullUpdate() 3004 public void SendGroupFullUpdate()
2140 { 3005 {
2141 if (IsDeleted) 3006 if (IsDeleted)
2142 return; 3007 return;
2143 3008
2144// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); 3009// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
2145 3010
2146 RootPart.SendFullUpdateToAllClients(); 3011 if (IsAttachment)
3012 {
3013 ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
3014 if (sp != null)
3015 {
3016 sp.SendAttachmentUpdate(this,UpdateRequired.FULL);
3017 return;
3018 }
3019 }
3020
3021 RootPart.SendFullUpdateToAllClientsInternal();
2147 3022
2148 SceneObjectPart[] parts = m_parts.GetArray(); 3023 SceneObjectPart[] parts = m_parts.GetArray();
2149 for (int i = 0; i < parts.Length; i++) 3024 for (int i = 0; i < parts.Length; i++)
2150 { 3025 {
2151 SceneObjectPart part = parts[i]; 3026 SceneObjectPart part = parts[i];
2152 if (part != RootPart) 3027 if (part != RootPart)
2153 part.SendFullUpdateToAllClients(); 3028 part.SendFullUpdateToAllClientsInternal();
2154 } 3029 }
2155 } 3030 }
2156 3031
@@ -2162,7 +3037,7 @@ namespace OpenSim.Region.Framework.Scenes
2162 /// </summary> 3037 /// </summary>
2163 public void SendGroupRootTerseUpdate() 3038 public void SendGroupRootTerseUpdate()
2164 { 3039 {
2165 if (IsDeleted) 3040 if (IsDeleted || inTransit)
2166 return; 3041 return;
2167 3042
2168 RootPart.SendTerseUpdateToAllClients(); 3043 RootPart.SendTerseUpdateToAllClients();
@@ -2181,12 +3056,22 @@ namespace OpenSim.Region.Framework.Scenes
2181 /// </summary> 3056 /// </summary>
2182 public void SendGroupTerseUpdate() 3057 public void SendGroupTerseUpdate()
2183 { 3058 {
2184 if (IsDeleted) 3059 if (IsDeleted || inTransit)
2185 return; 3060 return;
2186 3061
3062 if (IsAttachment)
3063 {
3064 ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
3065 if (sp != null)
3066 {
3067 sp.SendAttachmentUpdate(this, UpdateRequired.TERSE);
3068 return;
3069 }
3070 }
3071
2187 SceneObjectPart[] parts = m_parts.GetArray(); 3072 SceneObjectPart[] parts = m_parts.GetArray();
2188 for (int i = 0; i < parts.Length; i++) 3073 for (int i = 0; i < parts.Length; i++)
2189 parts[i].SendTerseUpdateToAllClients(); 3074 parts[i].SendTerseUpdateToAllClientsInternal();
2190 } 3075 }
2191 3076
2192 /// <summary> 3077 /// <summary>
@@ -2294,9 +3179,41 @@ namespace OpenSim.Region.Framework.Scenes
2294 return; 3179 return;
2295 } 3180 }
2296 3181
3182 // physical prims count limit
3183 // not very eficient :(
3184
3185 if (UsesPhysics && m_scene.m_linksetPhysCapacity > 0 && (PrimCount + objectGroup.PrimCount) >
3186 m_scene.m_linksetPhysCapacity)
3187 {
3188 int cntr = 0;
3189 foreach (SceneObjectPart part in Parts)
3190 {
3191 if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
3192 cntr++;
3193 }
3194 foreach (SceneObjectPart part in objectGroup.Parts)
3195 {
3196 if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
3197 cntr++;
3198 }
3199
3200 if (cntr > m_scene.m_linksetPhysCapacity)
3201 {
3202 // cancel physics
3203 RootPart.Flags &= ~PrimFlags.Physics;
3204 ApplyPhysics();
3205 }
3206 }
3207
3208
2297 // 'linkPart' == the root of the group being linked into this group 3209 // 'linkPart' == the root of the group being linked into this group
2298 SceneObjectPart linkPart = objectGroup.m_rootPart; 3210 SceneObjectPart linkPart = objectGroup.m_rootPart;
2299 3211
3212 if (m_rootPart.PhysActor != null)
3213 m_rootPart.PhysActor.Building = true;
3214 if (linkPart.PhysActor != null)
3215 linkPart.PhysActor.Building = true;
3216
2300 // physics flags from group to be applied to linked parts 3217 // physics flags from group to be applied to linked parts
2301 bool grpusephys = UsesPhysics; 3218 bool grpusephys = UsesPhysics;
2302 bool grptemporary = IsTemporary; 3219 bool grptemporary = IsTemporary;
@@ -2313,22 +3230,24 @@ namespace OpenSim.Region.Framework.Scenes
2313 // First move the new group's root SOP's position to be relative to ours 3230 // First move the new group's root SOP's position to be relative to ours
2314 // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not, 3231 // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not,
2315 // this code can be reordered to have a more logical flow.) 3232 // this code can be reordered to have a more logical flow.)
2316 linkPart.OffsetPosition = linkPart.GroupPosition - AbsolutePosition; 3233 linkPart.setOffsetPosition(linkPart.GroupPosition - AbsolutePosition);
2317 // Assign the new parent to the root of the old group 3234 // Assign the new parent to the root of the old group
2318 linkPart.ParentID = m_rootPart.LocalId; 3235 linkPart.ParentID = m_rootPart.LocalId;
2319 // Now that it's a child, it's group position is our root position 3236 // Now that it's a child, it's group position is our root position
2320 linkPart.GroupPosition = AbsolutePosition; 3237 linkPart.setGroupPosition(AbsolutePosition);
2321 3238
2322 Vector3 axPos = linkPart.OffsetPosition;
2323 // Rotate the linking root SOP's position to be relative to the new root prim 3239 // Rotate the linking root SOP's position to be relative to the new root prim
2324 Quaternion parentRot = m_rootPart.RotationOffset; 3240 Quaternion parentRot = m_rootPart.RotationOffset;
2325 axPos *= Quaternion.Inverse(parentRot);
2326 linkPart.OffsetPosition = axPos;
2327 3241
2328 // Make the linking root SOP's rotation relative to the new root prim 3242 // Make the linking root SOP's rotation relative to the new root prim
2329 Quaternion oldRot = linkPart.RotationOffset; 3243 Quaternion oldRot = linkPart.RotationOffset;
2330 Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; 3244 Quaternion newRot = Quaternion.Conjugate(parentRot) * oldRot;
2331 linkPart.RotationOffset = newRot; 3245 linkPart.setRotationOffset(newRot);
3246
3247 Vector3 axPos = linkPart.OffsetPosition;
3248 axPos *= Quaternion.Conjugate(parentRot);
3249 linkPart.OffsetPosition = axPos;
3250
2332 3251
2333 // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset. 3252 // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset.
2334 // Now that we know this SOG has at least two SOPs in it, the new root 3253 // Now that we know this SOG has at least two SOPs in it, the new root
@@ -2358,10 +3277,12 @@ namespace OpenSim.Region.Framework.Scenes
2358 m_parts.Add(linkPart.UUID, linkPart); 3277 m_parts.Add(linkPart.UUID, linkPart);
2359 3278
2360 linkPart.SetParent(this); 3279 linkPart.SetParent(this);
3280 m_scene.updateScenePartGroup(linkPart, this);
3281
2361 linkPart.CreateSelected = true; 3282 linkPart.CreateSelected = true;
2362 3283
2363 // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now 3284 // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
2364 linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive); 3285 linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true);
2365 3286
2366 // If the added SOP is physical, also tell the physics engine about the link relationship. 3287 // If the added SOP is physical, also tell the physics engine about the link relationship.
2367 if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) 3288 if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
@@ -2371,6 +3292,7 @@ namespace OpenSim.Region.Framework.Scenes
2371 } 3292 }
2372 3293
2373 linkPart.LinkNum = linkNum++; 3294 linkPart.LinkNum = linkNum++;
3295 linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
2374 3296
2375 // Get a list of the SOP's in the old group in order of their linknum's. 3297 // Get a list of the SOP's in the old group in order of their linknum's.
2376 SceneObjectPart[] ogParts = objectGroup.Parts; 3298 SceneObjectPart[] ogParts = objectGroup.Parts;
@@ -2389,7 +3311,7 @@ namespace OpenSim.Region.Framework.Scenes
2389 3311
2390 // Update the physics flags for the newly added SOP 3312 // Update the physics flags for the newly added SOP
2391 // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??) 3313 // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??)
2392 part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive); 3314 part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true);
2393 3315
2394 // If the added SOP is physical, also tell the physics engine about the link relationship. 3316 // If the added SOP is physical, also tell the physics engine about the link relationship.
2395 if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) 3317 if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
@@ -2407,7 +3329,7 @@ namespace OpenSim.Region.Framework.Scenes
2407 objectGroup.IsDeleted = true; 3329 objectGroup.IsDeleted = true;
2408 3330
2409 objectGroup.m_parts.Clear(); 3331 objectGroup.m_parts.Clear();
2410 3332
2411 // Can't do this yet since backup still makes use of the root part without any synchronization 3333 // Can't do this yet since backup still makes use of the root part without any synchronization
2412// objectGroup.m_rootPart = null; 3334// objectGroup.m_rootPart = null;
2413 3335
@@ -2423,6 +3345,9 @@ namespace OpenSim.Region.Framework.Scenes
2423 // unmoved prims! 3345 // unmoved prims!
2424 ResetChildPrimPhysicsPositions(); 3346 ResetChildPrimPhysicsPositions();
2425 3347
3348 if (m_rootPart.PhysActor != null)
3349 m_rootPart.PhysActor.Building = false;
3350
2426 //HasGroupChanged = true; 3351 //HasGroupChanged = true;
2427 //ScheduleGroupForFullUpdate(); 3352 //ScheduleGroupForFullUpdate();
2428 } 3353 }
@@ -2490,7 +3415,10 @@ namespace OpenSim.Region.Framework.Scenes
2490// m_log.DebugFormat( 3415// m_log.DebugFormat(
2491// "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", 3416// "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
2492// linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); 3417// linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
2493 3418
3419 if (m_rootPart.PhysActor != null)
3420 m_rootPart.PhysActor.Building = true;
3421
2494 linkPart.ClearUndoState(); 3422 linkPart.ClearUndoState();
2495 3423
2496 Vector3 worldPos = linkPart.GetWorldPosition(); 3424 Vector3 worldPos = linkPart.GetWorldPosition();
@@ -2545,20 +3473,18 @@ namespace OpenSim.Region.Framework.Scenes
2545 linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition; 3473 linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition;
2546 linkPart.OffsetPosition = new Vector3(0, 0, 0); 3474 linkPart.OffsetPosition = new Vector3(0, 0, 0);
2547 */ 3475 */
2548 linkPart.GroupPosition = worldPos; 3476 linkPart.setGroupPosition(worldPos);
2549 linkPart.OffsetPosition = Vector3.Zero; 3477 linkPart.setOffsetPosition(Vector3.Zero);
2550 linkPart.RotationOffset = worldRot; 3478 linkPart.setRotationOffset(worldRot);
2551 3479
2552 // Create a new SOG to go around this unlinked and unattached SOP 3480 // Create a new SOG to go around this unlinked and unattached SOP
2553 SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart); 3481 SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
2554 3482
2555 m_scene.AddNewSceneObject(objectGroup, true); 3483 m_scene.AddNewSceneObject(objectGroup, true);
2556 3484
2557 if (sendEvents)
2558 linkPart.TriggerScriptChangedEvent(Changed.LINK);
2559
2560 linkPart.Rezzed = RootPart.Rezzed; 3485 linkPart.Rezzed = RootPart.Rezzed;
2561 3486
3487<<<<<<< HEAD
2562 // We must persist the delinked group to the database immediately, for safety. The problem 3488 // We must persist the delinked group to the database immediately, for safety. The problem
2563 // is that although in memory the new group has a new SceneGroupID, in the database it 3489 // is that although in memory the new group has a new SceneGroupID, in the database it
2564 // still has the parent group's SceneGroupID (until the next backup). This means that if the 3490 // still has the parent group's SceneGroupID (until the next backup). This means that if the
@@ -2569,6 +3495,22 @@ namespace OpenSim.Region.Framework.Scenes
2569 // not happen. (We can't use a just-in-time trick like GroupContainsForeignPrims in this case 3495 // not happen. (We can't use a just-in-time trick like GroupContainsForeignPrims in this case
2570 // because the delinked group doesn't know when the source group is deleted.) 3496 // because the delinked group doesn't know when the source group is deleted.)
2571 m_scene.ForceSceneObjectBackup(objectGroup); 3497 m_scene.ForceSceneObjectBackup(objectGroup);
3498=======
3499 // When we delete a group, we currently have to force persist to the database if the object id has changed
3500 // (since delete works by deleting all rows which have a given object id)
3501
3502 // this is as it seems to be in sl now
3503 if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
3504 linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
3505
3506 if (m_rootPart.PhysActor != null)
3507 m_rootPart.PhysActor.Building = false;
3508
3509 objectGroup.HasGroupChangedDueToDelink = true;
3510>>>>>>> avn/ubitvar
3511
3512 if (sendEvents)
3513 linkPart.TriggerScriptChangedEvent(Changed.LINK);
2572 3514
2573 return objectGroup; 3515 return objectGroup;
2574 } 3516 }
@@ -2579,7 +3521,13 @@ namespace OpenSim.Region.Framework.Scenes
2579 /// <param name="objectGroup"></param> 3521 /// <param name="objectGroup"></param>
2580 public virtual void DetachFromBackup() 3522 public virtual void DetachFromBackup()
2581 { 3523 {
3524<<<<<<< HEAD
2582 if (Backup && Scene != null) 3525 if (Backup && Scene != null)
3526=======
3527 if (m_scene != null)
3528 m_scene.SceneGraph.FireDetachFromBackup(this);
3529 if (m_isBackedUp && Scene != null)
3530>>>>>>> avn/ubitvar
2583 m_scene.EventManager.OnBackup -= ProcessBackup; 3531 m_scene.EventManager.OnBackup -= ProcessBackup;
2584 3532
2585 Backup = false; 3533 Backup = false;
@@ -2595,14 +3543,14 @@ namespace OpenSim.Region.Framework.Scenes
2595 Quaternion parentRot = oldGroupRotation; 3543 Quaternion parentRot = oldGroupRotation;
2596 Quaternion oldRot = part.RotationOffset; 3544 Quaternion oldRot = part.RotationOffset;
2597 3545
2598 // Move our position to not be relative to the old parent 3546 // Move our position in world
2599 Vector3 axPos = part.OffsetPosition; 3547 Vector3 axPos = part.OffsetPosition;
2600 axPos *= parentRot; 3548 axPos *= parentRot;
2601 part.OffsetPosition = axPos; 3549 Vector3 newPos = oldGroupPosition + axPos;
2602 part.GroupPosition = oldGroupPosition + part.OffsetPosition; 3550 part.setGroupPosition(newPos);
2603 part.OffsetPosition = Vector3.Zero; 3551 part.setOffsetPosition(Vector3.Zero);
2604 3552
2605 // Compution our rotation to be not relative to the old parent 3553 // Compution our rotation in world
2606 Quaternion worldRot = parentRot * oldRot; 3554 Quaternion worldRot = parentRot * oldRot;
2607 part.RotationOffset = worldRot; 3555 part.RotationOffset = worldRot;
2608 3556
@@ -2613,29 +3561,32 @@ namespace OpenSim.Region.Framework.Scenes
2613 3561
2614 part.LinkNum = linkNum; 3562 part.LinkNum = linkNum;
2615 3563
3564 m_scene.updateScenePartGroup(part, this);
3565
2616 // Compute the new position of this SOP relative to the group position 3566 // Compute the new position of this SOP relative to the group position
2617 part.OffsetPosition = part.GroupPosition - AbsolutePosition; 3567 part.setOffsetPosition(newPos - AbsolutePosition);
2618 3568
2619 // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times. 3569 // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times.
2620 // It would have the affect of setting the physics engine position multiple 3570 // It would have the affect of setting the physics engine position multiple
2621 // times. In theory, that is not necessary but I don't have a good linkset 3571 // times. In theory, that is not necessary but I don't have a good linkset
2622 // test to know that cleaning up this code wouldn't break things.) 3572 // test to know that cleaning up this code wouldn't break things.)
2623 3573
2624 // Rotate the relative position by the rotation of the group
2625 Quaternion rootRotation = m_rootPart.RotationOffset;
2626 Vector3 pos = part.OffsetPosition;
2627 pos *= Quaternion.Inverse(rootRotation);
2628 part.OffsetPosition = pos;
2629
2630 // Compute the SOP's rotation relative to the rotation of the group. 3574 // Compute the SOP's rotation relative to the rotation of the group.
2631 parentRot = m_rootPart.RotationOffset; 3575 parentRot = m_rootPart.RotationOffset;
3576
2632 oldRot = part.RotationOffset; 3577 oldRot = part.RotationOffset;
2633 Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; 3578 Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot;
2634 part.RotationOffset = newRot; 3579 part.setRotationOffset(newRot);
3580
3581 Vector3 pos = part.OffsetPosition;
3582 pos *= Quaternion.Conjugate(parentRot);
3583
3584 part.OffsetPosition = pos; // update position and orientation on physics also
2635 3585
2636 // Since this SOP's state has changed, push those changes into the physics engine 3586 // Since this SOP's state has changed, push those changes into the physics engine
2637 // and the simulator. 3587 // and the simulator.
2638 part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect); 3588 // done on caller
3589// part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
2639 } 3590 }
2640 3591
2641 /// <summary> 3592 /// <summary>
@@ -2663,10 +3614,14 @@ namespace OpenSim.Region.Framework.Scenes
2663 { 3614 {
2664 if (!BlockGrabOverride && !part.BlockGrab) 3615 if (!BlockGrabOverride && !part.BlockGrab)
2665 { 3616 {
2666 Vector3 llmoveforce = pos - AbsolutePosition; 3617/* Vector3 llmoveforce = pos - AbsolutePosition;
2667 Vector3 grabforce = llmoveforce; 3618 Vector3 grabforce = llmoveforce;
2668 grabforce = (grabforce / 10) * pa.Mass; 3619 grabforce = (grabforce / 10) * pa.Mass;
2669 pa.AddForce(grabforce, true); 3620 */
3621 // empirically convert distance diference to a impulse
3622 Vector3 grabforce = pos - AbsolutePosition;
3623 grabforce = grabforce * (pa.Mass/ 10.0f);
3624 pa.AddForce(grabforce, false);
2670 m_scene.PhysicsScene.AddPhysicsActorTaint(pa); 3625 m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
2671 } 3626 }
2672 } 3627 }
@@ -2880,6 +3835,8 @@ namespace OpenSim.Region.Framework.Scenes
2880 /// <param name="SetVolumeDetect"></param> 3835 /// <param name="SetVolumeDetect"></param>
2881 public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect) 3836 public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect)
2882 { 3837 {
3838 HasGroupChanged = true;
3839
2883 SceneObjectPart selectionPart = GetPart(localID); 3840 SceneObjectPart selectionPart = GetPart(localID);
2884 3841
2885 if (Scene != null) 3842 if (Scene != null)
@@ -2905,8 +3862,12 @@ namespace OpenSim.Region.Framework.Scenes
2905 { 3862 {
2906 SceneObjectPart[] parts = m_parts.GetArray(); 3863 SceneObjectPart[] parts = m_parts.GetArray();
2907 3864
2908 if (Scene != null) 3865 if (Scene != null && UsePhysics)
2909 { 3866 {
3867 int maxprims = m_scene.m_linksetPhysCapacity;
3868 bool checkShape = (maxprims > 0 &&
3869 parts.Length > maxprims);
3870
2910 for (int i = 0; i < parts.Length; i++) 3871 for (int i = 0; i < parts.Length; i++)
2911 { 3872 {
2912 SceneObjectPart part = parts[i]; 3873 SceneObjectPart part = parts[i];
@@ -2917,11 +3878,34 @@ namespace OpenSim.Region.Framework.Scenes
2917 UsePhysics = false; // Reset physics 3878 UsePhysics = false; // Reset physics
2918 break; 3879 break;
2919 } 3880 }
3881
3882 if (checkShape && part.PhysicsShapeType != (byte)PhysicsShapeType.None)
3883 {
3884 if (--maxprims < 0)
3885 {
3886 UsePhysics = false;
3887 break;
3888 }
3889 }
2920 } 3890 }
2921 } 3891 }
2922 3892
2923 for (int i = 0; i < parts.Length; i++) 3893 if (parts.Length > 1)
2924 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); 3894 {
3895 m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
3896
3897 for (int i = 0; i < parts.Length; i++)
3898 {
3899
3900 if (parts[i].UUID != m_rootPart.UUID)
3901 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
3902 }
3903
3904 if (m_rootPart.PhysActor != null)
3905 m_rootPart.PhysActor.Building = false;
3906 }
3907 else
3908 m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false);
2925 } 3909 }
2926 } 3910 }
2927 3911
@@ -2934,6 +3918,17 @@ namespace OpenSim.Region.Framework.Scenes
2934 } 3918 }
2935 } 3919 }
2936 3920
3921
3922
3923 /// <summary>
3924 /// Gets the number of parts
3925 /// </summary>
3926 /// <returns></returns>
3927 public int GetPartCount()
3928 {
3929 return Parts.Count();
3930 }
3931
2937 /// <summary> 3932 /// <summary>
2938 /// Update the texture entry for this part 3933 /// Update the texture entry for this part
2939 /// </summary> 3934 /// </summary>
@@ -2978,7 +3973,27 @@ namespace OpenSim.Region.Framework.Scenes
2978 { 3973 {
2979 RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF); 3974 RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF);
2980 3975
3976<<<<<<< HEAD
2981 AdjustChildPrimPermissions(Scene.Permissions.IsGod(AgentID)); 3977 AdjustChildPrimPermissions(Scene.Permissions.IsGod(AgentID));
3978=======
3979 bool god = Scene.Permissions.IsGod(AgentID);
3980
3981 if (field == 1 && god)
3982 {
3983 ForEachPart(part =>
3984 {
3985 part.BaseMask = RootPart.BaseMask;
3986 });
3987 }
3988
3989 AdjustChildPrimPermissions();
3990>>>>>>> avn/ubitvar
3991
3992 if (field == 1 && god) // Base mask was set. Update all child part inventories
3993 {
3994 foreach (SceneObjectPart part in Parts)
3995 part.Inventory.ApplyGodPermissions(RootPart.BaseMask);
3996 }
2982 3997
2983 HasGroupChanged = true; 3998 HasGroupChanged = true;
2984 3999
@@ -3025,8 +4040,6 @@ namespace OpenSim.Region.Framework.Scenes
3025 4040
3026 PhysicsActor pa = m_rootPart.PhysActor; 4041 PhysicsActor pa = m_rootPart.PhysActor;
3027 4042
3028 RootPart.StoreUndoState(true);
3029
3030 if (Scene != null) 4043 if (Scene != null)
3031 { 4044 {
3032 scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X)); 4045 scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X));
@@ -3054,7 +4067,6 @@ namespace OpenSim.Region.Framework.Scenes
3054 SceneObjectPart obPart = parts[i]; 4067 SceneObjectPart obPart = parts[i];
3055 if (obPart.UUID != m_rootPart.UUID) 4068 if (obPart.UUID != m_rootPart.UUID)
3056 { 4069 {
3057// obPart.IgnoreUndoUpdate = true;
3058 Vector3 oldSize = new Vector3(obPart.Scale); 4070 Vector3 oldSize = new Vector3(obPart.Scale);
3059 4071
3060 float f = 1.0f; 4072 float f = 1.0f;
@@ -3166,8 +4178,6 @@ namespace OpenSim.Region.Framework.Scenes
3166 z *= a; 4178 z *= a;
3167 } 4179 }
3168 } 4180 }
3169
3170// obPart.IgnoreUndoUpdate = false;
3171 } 4181 }
3172 } 4182 }
3173 } 4183 }
@@ -3177,9 +4187,7 @@ namespace OpenSim.Region.Framework.Scenes
3177 prevScale.Y *= y; 4187 prevScale.Y *= y;
3178 prevScale.Z *= z; 4188 prevScale.Z *= z;
3179 4189
3180// RootPart.IgnoreUndoUpdate = true;
3181 RootPart.Resize(prevScale); 4190 RootPart.Resize(prevScale);
3182// RootPart.IgnoreUndoUpdate = false;
3183 4191
3184 for (int i = 0; i < parts.Length; i++) 4192 for (int i = 0; i < parts.Length; i++)
3185 { 4193 {
@@ -3187,8 +4195,6 @@ namespace OpenSim.Region.Framework.Scenes
3187 4195
3188 if (obPart.UUID != m_rootPart.UUID) 4196 if (obPart.UUID != m_rootPart.UUID)
3189 { 4197 {
3190 obPart.IgnoreUndoUpdate = true;
3191
3192 Vector3 currentpos = new Vector3(obPart.OffsetPosition); 4198 Vector3 currentpos = new Vector3(obPart.OffsetPosition);
3193 currentpos.X *= x; 4199 currentpos.X *= x;
3194 currentpos.Y *= y; 4200 currentpos.Y *= y;
@@ -3201,16 +4207,12 @@ namespace OpenSim.Region.Framework.Scenes
3201 4207
3202 obPart.Resize(newSize); 4208 obPart.Resize(newSize);
3203 obPart.UpdateOffSet(currentpos); 4209 obPart.UpdateOffSet(currentpos);
3204
3205 obPart.IgnoreUndoUpdate = false;
3206 } 4210 }
3207 4211
3208// obPart.IgnoreUndoUpdate = false; 4212 HasGroupChanged = true;
3209// obPart.StoreUndoState(); 4213 m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
4214 ScheduleGroupForTerseUpdate();
3210 } 4215 }
3211
3212// m_log.DebugFormat(
3213// "[SCENE OBJECT GROUP]: Finished group resizing {0} {1} to {2}", Name, LocalId, RootPart.Scale);
3214 } 4216 }
3215 4217
3216 #endregion 4218 #endregion
@@ -3223,14 +4225,6 @@ namespace OpenSim.Region.Framework.Scenes
3223 /// <param name="pos"></param> 4225 /// <param name="pos"></param>
3224 public void UpdateGroupPosition(Vector3 pos) 4226 public void UpdateGroupPosition(Vector3 pos)
3225 { 4227 {
3226// m_log.DebugFormat("[SCENE OBJECT GROUP]: Updating group position on {0} {1} to {2}", Name, LocalId, pos);
3227
3228 RootPart.StoreUndoState(true);
3229
3230// SceneObjectPart[] parts = m_parts.GetArray();
3231// for (int i = 0; i < parts.Length; i++)
3232// parts[i].StoreUndoState();
3233
3234 if (m_scene.EventManager.TriggerGroupMove(UUID, pos)) 4228 if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
3235 { 4229 {
3236 if (IsAttachment) 4230 if (IsAttachment)
@@ -3263,21 +4257,17 @@ namespace OpenSim.Region.Framework.Scenes
3263 /// </summary> 4257 /// </summary>
3264 /// <param name="pos"></param> 4258 /// <param name="pos"></param>
3265 /// <param name="localID"></param> 4259 /// <param name="localID"></param>
4260 ///
4261
3266 public void UpdateSinglePosition(Vector3 pos, uint localID) 4262 public void UpdateSinglePosition(Vector3 pos, uint localID)
3267 { 4263 {
3268 SceneObjectPart part = GetPart(localID); 4264 SceneObjectPart part = GetPart(localID);
3269 4265
3270// SceneObjectPart[] parts = m_parts.GetArray();
3271// for (int i = 0; i < parts.Length; i++)
3272// parts[i].StoreUndoState();
3273
3274 if (part != null) 4266 if (part != null)
3275 { 4267 {
3276// m_log.DebugFormat( 4268// unlock parts position change
3277// "[SCENE OBJECT GROUP]: Updating single position of {0} {1} to {2}", part.Name, part.LocalId, pos); 4269 if (m_rootPart.PhysActor != null)
3278 4270 m_rootPart.PhysActor.Building = true;
3279 part.StoreUndoState(false);
3280 part.IgnoreUndoUpdate = true;
3281 4271
3282 if (part.UUID == m_rootPart.UUID) 4272 if (part.UUID == m_rootPart.UUID)
3283 { 4273 {
@@ -3288,8 +4278,10 @@ namespace OpenSim.Region.Framework.Scenes
3288 part.UpdateOffSet(pos); 4278 part.UpdateOffSet(pos);
3289 } 4279 }
3290 4280
4281 if (m_rootPart.PhysActor != null)
4282 m_rootPart.PhysActor.Building = false;
4283
3291 HasGroupChanged = true; 4284 HasGroupChanged = true;
3292 part.IgnoreUndoUpdate = false;
3293 } 4285 }
3294 } 4286 }
3295 4287
@@ -3299,13 +4291,7 @@ namespace OpenSim.Region.Framework.Scenes
3299 /// <param name="newPos"></param> 4291 /// <param name="newPos"></param>
3300 public void UpdateRootPosition(Vector3 newPos) 4292 public void UpdateRootPosition(Vector3 newPos)
3301 { 4293 {
3302// m_log.DebugFormat( 4294 // needs to be called with phys building true
3303// "[SCENE OBJECT GROUP]: Updating root position of {0} {1} to {2}", Name, LocalId, pos);
3304
3305// SceneObjectPart[] parts = m_parts.GetArray();
3306// for (int i = 0; i < parts.Length; i++)
3307// parts[i].StoreUndoState();
3308
3309 Vector3 oldPos; 4295 Vector3 oldPos;
3310 4296
3311 if (IsAttachment) 4297 if (IsAttachment)
@@ -3326,12 +4312,19 @@ namespace OpenSim.Region.Framework.Scenes
3326 } 4312 }
3327 4313
3328 AbsolutePosition = newPos; 4314 AbsolutePosition = newPos;
3329 4315
3330 if (IsAttachment) 4316 if (IsAttachment)
3331 m_rootPart.AttachedPos = newPos; 4317 m_rootPart.AttachedPos = newPos;
3332 4318
3333 HasGroupChanged = true; 4319 HasGroupChanged = true;
3334 ScheduleGroupForTerseUpdate(); 4320 if (m_rootPart.Undoing)
4321 {
4322 ScheduleGroupForFullUpdate();
4323 }
4324 else
4325 {
4326 ScheduleGroupForTerseUpdate();
4327 }
3335 } 4328 }
3336 4329
3337 #endregion 4330 #endregion
@@ -3344,24 +4337,16 @@ namespace OpenSim.Region.Framework.Scenes
3344 /// <param name="rot"></param> 4337 /// <param name="rot"></param>
3345 public void UpdateGroupRotationR(Quaternion rot) 4338 public void UpdateGroupRotationR(Quaternion rot)
3346 { 4339 {
3347// m_log.DebugFormat(
3348// "[SCENE OBJECT GROUP]: Updating group rotation R of {0} {1} to {2}", Name, LocalId, rot);
3349
3350// SceneObjectPart[] parts = m_parts.GetArray();
3351// for (int i = 0; i < parts.Length; i++)
3352// parts[i].StoreUndoState();
3353
3354 m_rootPart.StoreUndoState(true);
3355
3356 m_rootPart.UpdateRotation(rot); 4340 m_rootPart.UpdateRotation(rot);
3357 4341
4342/* this is done by rootpart RotationOffset set called by UpdateRotation
3358 PhysicsActor actor = m_rootPart.PhysActor; 4343 PhysicsActor actor = m_rootPart.PhysActor;
3359 if (actor != null) 4344 if (actor != null)
3360 { 4345 {
3361 actor.Orientation = m_rootPart.RotationOffset; 4346 actor.Orientation = m_rootPart.RotationOffset;
3362 m_scene.PhysicsScene.AddPhysicsActorTaint(actor); 4347 m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
3363 } 4348 }
3364 4349*/
3365 HasGroupChanged = true; 4350 HasGroupChanged = true;
3366 ScheduleGroupForTerseUpdate(); 4351 ScheduleGroupForTerseUpdate();
3367 } 4352 }
@@ -3373,16 +4358,6 @@ namespace OpenSim.Region.Framework.Scenes
3373 /// <param name="rot"></param> 4358 /// <param name="rot"></param>
3374 public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot) 4359 public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
3375 { 4360 {
3376// m_log.DebugFormat(
3377// "[SCENE OBJECT GROUP]: Updating group rotation PR of {0} {1} to {2}", Name, LocalId, rot);
3378
3379// SceneObjectPart[] parts = m_parts.GetArray();
3380// for (int i = 0; i < parts.Length; i++)
3381// parts[i].StoreUndoState();
3382
3383 RootPart.StoreUndoState(true);
3384 RootPart.IgnoreUndoUpdate = true;
3385
3386 m_rootPart.UpdateRotation(rot); 4361 m_rootPart.UpdateRotation(rot);
3387 4362
3388 PhysicsActor actor = m_rootPart.PhysActor; 4363 PhysicsActor actor = m_rootPart.PhysActor;
@@ -3401,8 +4376,6 @@ namespace OpenSim.Region.Framework.Scenes
3401 4376
3402 HasGroupChanged = true; 4377 HasGroupChanged = true;
3403 ScheduleGroupForTerseUpdate(); 4378 ScheduleGroupForTerseUpdate();
3404
3405 RootPart.IgnoreUndoUpdate = false;
3406 } 4379 }
3407 4380
3408 /// <summary> 4381 /// <summary>
@@ -3415,13 +4388,11 @@ namespace OpenSim.Region.Framework.Scenes
3415 SceneObjectPart part = GetPart(localID); 4388 SceneObjectPart part = GetPart(localID);
3416 4389
3417 SceneObjectPart[] parts = m_parts.GetArray(); 4390 SceneObjectPart[] parts = m_parts.GetArray();
3418 for (int i = 0; i < parts.Length; i++)
3419 parts[i].StoreUndoState();
3420 4391
3421 if (part != null) 4392 if (part != null)
3422 { 4393 {
3423// m_log.DebugFormat( 4394 if (m_rootPart.PhysActor != null)
3424// "[SCENE OBJECT GROUP]: Updating single rotation of {0} {1} to {2}", part.Name, part.LocalId, rot); 4395 m_rootPart.PhysActor.Building = true;
3425 4396
3426 if (part.UUID == m_rootPart.UUID) 4397 if (part.UUID == m_rootPart.UUID)
3427 { 4398 {
@@ -3431,6 +4402,9 @@ namespace OpenSim.Region.Framework.Scenes
3431 { 4402 {
3432 part.UpdateRotation(rot); 4403 part.UpdateRotation(rot);
3433 } 4404 }
4405
4406 if (m_rootPart.PhysActor != null)
4407 m_rootPart.PhysActor.Building = false;
3434 } 4408 }
3435 } 4409 }
3436 4410
@@ -3444,12 +4418,8 @@ namespace OpenSim.Region.Framework.Scenes
3444 SceneObjectPart part = GetPart(localID); 4418 SceneObjectPart part = GetPart(localID);
3445 if (part != null) 4419 if (part != null)
3446 { 4420 {
3447// m_log.DebugFormat( 4421 if (m_rootPart.PhysActor != null)
3448// "[SCENE OBJECT GROUP]: Updating single position and rotation of {0} {1} to {2}", 4422 m_rootPart.PhysActor.Building = true;
3449// part.Name, part.LocalId, rot);
3450
3451 part.StoreUndoState();
3452 part.IgnoreUndoUpdate = true;
3453 4423
3454 if (part.UUID == m_rootPart.UUID) 4424 if (part.UUID == m_rootPart.UUID)
3455 { 4425 {
@@ -3462,7 +4432,8 @@ namespace OpenSim.Region.Framework.Scenes
3462 part.OffsetPosition = pos; 4432 part.OffsetPosition = pos;
3463 } 4433 }
3464 4434
3465 part.IgnoreUndoUpdate = false; 4435 if (m_rootPart.PhysActor != null)
4436 m_rootPart.PhysActor.Building = false;
3466 } 4437 }
3467 } 4438 }
3468 4439
@@ -3472,15 +4443,12 @@ namespace OpenSim.Region.Framework.Scenes
3472 /// <param name="rot"></param> 4443 /// <param name="rot"></param>
3473 public void UpdateRootRotation(Quaternion rot) 4444 public void UpdateRootRotation(Quaternion rot)
3474 { 4445 {
3475// m_log.DebugFormat( 4446 // needs to be called with phys building true
3476// "[SCENE OBJECT GROUP]: Updating root rotation of {0} {1} to {2}",
3477// Name, LocalId, rot);
3478
3479 Quaternion axRot = rot; 4447 Quaternion axRot = rot;
3480 Quaternion oldParentRot = m_rootPart.RotationOffset; 4448 Quaternion oldParentRot = m_rootPart.RotationOffset;
3481 4449
3482 m_rootPart.StoreUndoState(); 4450 //Don't use UpdateRotation because it schedules an update prematurely
3483 m_rootPart.UpdateRotation(rot); 4451 m_rootPart.RotationOffset = rot;
3484 4452
3485 PhysicsActor pa = m_rootPart.PhysActor; 4453 PhysicsActor pa = m_rootPart.PhysActor;
3486 4454
@@ -3496,35 +4464,145 @@ namespace OpenSim.Region.Framework.Scenes
3496 SceneObjectPart prim = parts[i]; 4464 SceneObjectPart prim = parts[i];
3497 if (prim.UUID != m_rootPart.UUID) 4465 if (prim.UUID != m_rootPart.UUID)
3498 { 4466 {
3499 prim.IgnoreUndoUpdate = true; 4467 Quaternion NewRot = oldParentRot * prim.RotationOffset;
4468 NewRot = Quaternion.Inverse(axRot) * NewRot;
4469 prim.RotationOffset = NewRot;
4470
3500 Vector3 axPos = prim.OffsetPosition; 4471 Vector3 axPos = prim.OffsetPosition;
4472
3501 axPos *= oldParentRot; 4473 axPos *= oldParentRot;
3502 axPos *= Quaternion.Inverse(axRot); 4474 axPos *= Quaternion.Inverse(axRot);
3503 prim.OffsetPosition = axPos; 4475 prim.OffsetPosition = axPos;
3504 Quaternion primsRot = prim.RotationOffset;
3505 Quaternion newRot = oldParentRot * primsRot;
3506 newRot = Quaternion.Inverse(axRot) * newRot;
3507 prim.RotationOffset = newRot;
3508 prim.ScheduleTerseUpdate();
3509 prim.IgnoreUndoUpdate = false;
3510 } 4476 }
3511 } 4477 }
3512 4478
3513// for (int i = 0; i < parts.Length; i++) 4479 HasGroupChanged = true;
3514// { 4480 ScheduleGroupForFullUpdate();
3515// SceneObjectPart childpart = parts[i]; 4481 }
3516// if (childpart != m_rootPart)
3517// {
3518//// childpart.IgnoreUndoUpdate = false;
3519//// childpart.StoreUndoState();
3520// }
3521// }
3522 4482
3523 m_rootPart.ScheduleTerseUpdate(); 4483 private enum updatetype :int
4484 {
4485 none = 0,
4486 partterse = 1,
4487 partfull = 2,
4488 groupterse = 3,
4489 groupfull = 4
4490 }
3524 4491
3525// m_log.DebugFormat( 4492 public void doChangeObject(SceneObjectPart part, ObjectChangeData data)
3526// "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}", 4493 {
3527// Name, LocalId, rot); 4494 // TODO this still as excessive *.Schedule*Update()s
4495
4496 if (part != null && part.ParentGroup != null)
4497 {
4498 ObjectChangeType change = data.change;
4499 bool togroup = ((change & ObjectChangeType.Group) != 0);
4500 // bool uniform = ((what & ObjectChangeType.UniformScale) != 0); not in use
4501
4502 SceneObjectGroup group = part.ParentGroup;
4503 PhysicsActor pha = group.RootPart.PhysActor;
4504
4505 updatetype updateType = updatetype.none;
4506
4507 if (togroup)
4508 {
4509 // related to group
4510 if ((change & (ObjectChangeType.Rotation | ObjectChangeType.Position)) != 0)
4511 {
4512 if ((change & ObjectChangeType.Rotation) != 0)
4513 {
4514 group.RootPart.UpdateRotation(data.rotation);
4515 updateType = updatetype.none;
4516 }
4517 if ((change & ObjectChangeType.Position) != 0)
4518 {
4519 if (IsAttachment || m_scene.Permissions.CanObjectEntry(group.UUID, false, data.position))
4520 UpdateGroupPosition(data.position);
4521 updateType = updatetype.groupterse;
4522 }
4523 else
4524 // ugly rotation update of all parts
4525 {
4526 group.ResetChildPrimPhysicsPositions();
4527 }
4528
4529 }
4530 if ((change & ObjectChangeType.Scale) != 0)
4531 {
4532 if (pha != null)
4533 pha.Building = true;
4534
4535 group.GroupResize(data.scale);
4536 updateType = updatetype.none;
4537
4538 if (pha != null)
4539 pha.Building = false;
4540 }
4541 }
4542 else
4543 {
4544 // related to single prim in a link-set ( ie group)
4545 if (pha != null)
4546 pha.Building = true;
4547
4548 // root part is special
4549 // parts offset positions or rotations need to change also
4550
4551 if (part == group.RootPart)
4552 {
4553 if ((change & ObjectChangeType.Rotation) != 0)
4554 group.UpdateRootRotation(data.rotation);
4555 if ((change & ObjectChangeType.Position) != 0)
4556 group.UpdateRootPosition(data.position);
4557 if ((change & ObjectChangeType.Scale) != 0)
4558 part.Resize(data.scale);
4559 }
4560 else
4561 {
4562 if ((change & ObjectChangeType.Position) != 0)
4563 {
4564 part.OffsetPosition = data.position;
4565 updateType = updatetype.partterse;
4566 }
4567 if ((change & ObjectChangeType.Rotation) != 0)
4568 {
4569 part.UpdateRotation(data.rotation);
4570 updateType = updatetype.none;
4571 }
4572 if ((change & ObjectChangeType.Scale) != 0)
4573 {
4574 part.Resize(data.scale);
4575 updateType = updatetype.none;
4576 }
4577 }
4578
4579 if (pha != null)
4580 pha.Building = false;
4581 }
4582
4583 if (updateType != updatetype.none)
4584 {
4585 group.HasGroupChanged = true;
4586
4587 switch (updateType)
4588 {
4589 case updatetype.partterse:
4590 part.ScheduleTerseUpdate();
4591 break;
4592 case updatetype.partfull:
4593 part.ScheduleFullUpdate();
4594 break;
4595 case updatetype.groupterse:
4596 group.ScheduleGroupForTerseUpdate();
4597 break;
4598 case updatetype.groupfull:
4599 group.ScheduleGroupForFullUpdate();
4600 break;
4601 default:
4602 break;
4603 }
4604 }
4605 }
3528 } 4606 }
3529 4607
3530 #endregion 4608 #endregion
@@ -3565,6 +4643,8 @@ namespace OpenSim.Region.Framework.Scenes
3565 waypoint.handle = handle; 4643 waypoint.handle = handle;
3566 lock (m_rotTargets) 4644 lock (m_rotTargets)
3567 { 4645 {
4646 if (m_rotTargets.Count >= 8)
4647 m_rotTargets.Remove(m_rotTargets.ElementAt(0).Key);
3568 m_rotTargets.Add(handle, waypoint); 4648 m_rotTargets.Add(handle, waypoint);
3569 } 4649 }
3570 m_scene.AddGroupTarget(this); 4650 m_scene.AddGroupTarget(this);
@@ -3590,6 +4670,8 @@ namespace OpenSim.Region.Framework.Scenes
3590 waypoint.handle = handle; 4670 waypoint.handle = handle;
3591 lock (m_targets) 4671 lock (m_targets)
3592 { 4672 {
4673 if (m_targets.Count >= 8)
4674 m_targets.Remove(m_targets.ElementAt(0).Key);
3593 m_targets.Add(handle, waypoint); 4675 m_targets.Add(handle, waypoint);
3594 } 4676 }
3595 m_scene.AddGroupTarget(this); 4677 m_scene.AddGroupTarget(this);
@@ -3623,10 +4705,11 @@ namespace OpenSim.Region.Framework.Scenes
3623 scriptPosTarget target = m_targets[idx]; 4705 scriptPosTarget target = m_targets[idx];
3624 if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance) 4706 if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
3625 { 4707 {
4708 at_target = true;
4709
3626 // trigger at_target 4710 // trigger at_target
3627 if (m_scriptListens_atTarget) 4711 if (m_scriptListens_atTarget)
3628 { 4712 {
3629 at_target = true;
3630 scriptPosTarget att = new scriptPosTarget(); 4713 scriptPosTarget att = new scriptPosTarget();
3631 att.targetPos = target.targetPos; 4714 att.targetPos = target.targetPos;
3632 att.tolerance = target.tolerance; 4715 att.tolerance = target.tolerance;
@@ -3744,11 +4827,50 @@ namespace OpenSim.Region.Framework.Scenes
3744 } 4827 }
3745 } 4828 }
3746 } 4829 }
3747 4830
4831 public Vector3 GetGeometricCenter()
4832 {
4833 // this is not real geometric center but a average of positions relative to root prim acording to
4834 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
4835 // ignoring tortured prims details since sl also seems to ignore
4836 // so no real use in doing it on physics
4837
4838 Vector3 gc = Vector3.Zero;
4839
4840 int nparts = m_parts.Count;
4841 if (nparts <= 1)
4842 return gc;
4843
4844 SceneObjectPart[] parts = m_parts.GetArray();
4845 nparts = parts.Length; // just in case it changed
4846 if (nparts <= 1)
4847 return gc;
4848
4849 Quaternion parentRot = RootPart.RotationOffset;
4850 Vector3 pPos;
4851
4852 // average all parts positions
4853 for (int i = 0; i < nparts; i++)
4854 {
4855 // do it directly
4856 // gc += parts[i].GetWorldPosition();
4857 if (parts[i] != RootPart)
4858 {
4859 pPos = parts[i].OffsetPosition;
4860 gc += pPos;
4861 }
4862
4863 }
4864 gc /= nparts;
4865
4866 // relative to root:
4867// gc -= AbsolutePosition;
4868 return gc;
4869 }
4870
3748 public float GetMass() 4871 public float GetMass()
3749 { 4872 {
3750 float retmass = 0f; 4873 float retmass = 0f;
3751
3752 SceneObjectPart[] parts = m_parts.GetArray(); 4874 SceneObjectPart[] parts = m_parts.GetArray();
3753 for (int i = 0; i < parts.Length; i++) 4875 for (int i = 0; i < parts.Length; i++)
3754 retmass += parts[i].GetMass(); 4876 retmass += parts[i].GetMass();
@@ -3756,6 +4878,39 @@ namespace OpenSim.Region.Framework.Scenes
3756 return retmass; 4878 return retmass;
3757 } 4879 }
3758 4880
4881 // center of mass of full object
4882 public Vector3 GetCenterOfMass()
4883 {
4884 PhysicsActor pa = RootPart.PhysActor;
4885
4886 if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
4887 {
4888 // physics knows better about center of mass of physical prims
4889 Vector3 tmp = pa.CenterOfMass;
4890 return tmp;
4891 }
4892
4893 Vector3 Ptot = Vector3.Zero;
4894 float totmass = 0f;
4895 float m;
4896
4897 SceneObjectPart[] parts = m_parts.GetArray();
4898 for (int i = 0; i < parts.Length; i++)
4899 {
4900 m = parts[i].GetMass();
4901 Ptot += parts[i].GetPartCenterOfMass() * m;
4902 totmass += m;
4903 }
4904
4905 if (totmass == 0)
4906 totmass = 0;
4907 else
4908 totmass = 1 / totmass;
4909 Ptot *= totmass;
4910
4911 return Ptot;
4912 }
4913
3759 /// <summary> 4914 /// <summary>
3760 /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that 4915 /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that
3761 /// the physics engine can use it. 4916 /// the physics engine can use it.
@@ -3935,6 +5090,14 @@ namespace OpenSim.Region.Framework.Scenes
3935 FromItemID = uuid; 5090 FromItemID = uuid;
3936 } 5091 }
3937 5092
5093 public void ResetOwnerChangeFlag()
5094 {
5095 ForEachPart(delegate(SceneObjectPart part)
5096 {
5097 part.ResetOwnerChangeFlag();
5098 });
5099 }
5100
3938 #endregion 5101 #endregion
3939 } 5102 }
3940} 5103}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index f6e8c7f..1cfa8ed 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -64,7 +64,8 @@ namespace OpenSim.Region.Framework.Scenes
64 TELEPORT = 512, 64 TELEPORT = 512,
65 REGION_RESTART = 1024, 65 REGION_RESTART = 1024,
66 MEDIA = 2048, 66 MEDIA = 2048,
67 ANIMATION = 16384 67 ANIMATION = 16384,
68 POSITION = 32768
68 } 69 }
69 70
70 // I don't really know where to put this except here. 71 // I don't really know where to put this except here.
@@ -123,7 +124,18 @@ namespace OpenSim.Region.Framework.Scenes
123 /// Denote all sides of the prim 124 /// Denote all sides of the prim
124 /// </value> 125 /// </value>
125 public const int ALL_SIDES = -1; 126 public const int ALL_SIDES = -1;
126 127
128 private const scriptEvents PhysicsNeededSubsEvents = (
129 scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
130 scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
131 );
132 private const scriptEvents PhyscicsPhantonSubsEvents = (
133 scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
134 );
135 private const scriptEvents PhyscicsVolumeDtcSubsEvents = (
136 scriptEvents.collision_start | scriptEvents.collision_end
137 );
138
127 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 139 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
128 140
129 /// <summary> 141 /// <summary>
@@ -160,7 +172,7 @@ namespace OpenSim.Region.Framework.Scenes
160 /// </remarks> 172 /// </remarks>
161 public bool IsRoot 173 public bool IsRoot
162 { 174 {
163 get { return ParentGroup.RootPart == this; } 175 get { return Object.ReferenceEquals(ParentGroup.RootPart, this); }
164 } 176 }
165 177
166 /// <summary> 178 /// <summary>
@@ -233,6 +245,15 @@ namespace OpenSim.Region.Framework.Scenes
233 245
234 public uint TimeStampTerse; 246 public uint TimeStampTerse;
235 247
248 // The following two are to hold the attachment data
249 // while an object is inworld
250 [XmlIgnore]
251 public byte AttachPoint = 0;
252
253 [XmlIgnore]
254 public Quaternion AttachRotation = Quaternion.Identity;
255
256 [XmlIgnore]
236 public int STATUS_ROTATE_X; 257 public int STATUS_ROTATE_X;
237 258
238 public int STATUS_ROTATE_Y; 259 public int STATUS_ROTATE_Y;
@@ -259,8 +280,7 @@ namespace OpenSim.Region.Framework.Scenes
259 280
260 public Vector3 RotationAxis = Vector3.One; 281 public Vector3 RotationAxis = Vector3.One;
261 282
262 public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this 283 public bool VolumeDetectActive;
263 // Certainly this must be a persistant setting finally
264 284
265 public bool IsWaitingForFirstSpinUpdatePacket; 285 public bool IsWaitingForFirstSpinUpdatePacket;
266 286
@@ -300,10 +320,10 @@ namespace OpenSim.Region.Framework.Scenes
300 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 320 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
301 private Vector3 m_sitTargetPosition; 321 private Vector3 m_sitTargetPosition;
302 private string m_sitAnimation = "SIT"; 322 private string m_sitAnimation = "SIT";
323 private bool m_occupied; // KF if any av is sitting on this prim
303 private string m_text = String.Empty; 324 private string m_text = String.Empty;
304 private string m_touchName = String.Empty; 325 private string m_touchName = String.Empty;
305 private readonly List<UndoState> m_undo = new List<UndoState>(5); 326 private UndoRedoState m_UndoRedo = null;
306 private readonly List<UndoState> m_redo = new List<UndoState>(5);
307 327
308 private bool m_passTouches = false; 328 private bool m_passTouches = false;
309 private bool m_passCollisions = false; 329 private bool m_passCollisions = false;
@@ -331,14 +351,20 @@ namespace OpenSim.Region.Framework.Scenes
331 protected Vector3 m_lastVelocity; 351 protected Vector3 m_lastVelocity;
332 protected Vector3 m_lastAcceleration; 352 protected Vector3 m_lastAcceleration;
333 protected Vector3 m_lastAngularVelocity; 353 protected Vector3 m_lastAngularVelocity;
334 protected int m_lastTerseSent; 354 protected int m_lastUpdateSentTime;
355 protected float m_buoyancy = 0.0f;
356 protected Vector3 m_force;
357 protected Vector3 m_torque;
335 358
336 protected byte m_physicsShapeType = (byte)PhysShapeType.prim; 359 protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
337 protected float m_density = 1000.0f; // in kg/m^3 360 protected float m_density = 1000.0f; // in kg/m^3
338 protected float m_gravitymod = 1.0f; 361 protected float m_gravitymod = 1.0f;
339 protected float m_friction = 0.6f; // wood 362 protected float m_friction = 0.6f; // wood
340 protected float m_bounce = 0.5f; // wood 363 protected float m_bounce = 0.5f; // wood
341 364
365
366 protected bool m_isSelected = false;
367
342 /// <summary> 368 /// <summary>
343 /// Stores media texture data 369 /// Stores media texture data
344 /// </summary> 370 /// </summary>
@@ -350,15 +376,23 @@ namespace OpenSim.Region.Framework.Scenes
350 private Vector3 m_cameraAtOffset; 376 private Vector3 m_cameraAtOffset;
351 private bool m_forceMouselook; 377 private bool m_forceMouselook;
352 378
353 // TODO: Collision sound should have default. 379
380 // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
381 private sbyte m_collisionSoundType;
354 private UUID m_collisionSound; 382 private UUID m_collisionSound;
355 private float m_collisionSoundVolume; 383 private float m_collisionSoundVolume;
356 384
385 private int LastColSoundSentTime;
386
387
388 private SOPVehicle m_vehicleParams = null;
389
357 public KeyframeMotion KeyframeMotion 390 public KeyframeMotion KeyframeMotion
358 { 391 {
359 get; set; 392 get; set;
360 } 393 }
361 394
395
362 #endregion Fields 396 #endregion Fields
363 397
364// ~SceneObjectPart() 398// ~SceneObjectPart()
@@ -388,6 +422,7 @@ namespace OpenSim.Region.Framework.Scenes
388 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from 422 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
389 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log 423 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
390 m_inventory = new SceneObjectPartInventory(this); 424 m_inventory = new SceneObjectPartInventory(this);
425 LastColSoundSentTime = Util.EnvironmentTickCount();
391 } 426 }
392 427
393 /// <summary> 428 /// <summary>
@@ -402,7 +437,7 @@ namespace OpenSim.Region.Framework.Scenes
402 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, 437 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
403 Quaternion rotationOffset, Vector3 offsetPosition) : this() 438 Quaternion rotationOffset, Vector3 offsetPosition) : this()
404 { 439 {
405 m_name = "Primitive"; 440 m_name = "Object";
406 441
407 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed); 442 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
408 LastOwnerID = CreatorID = OwnerID = ownerID; 443 LastOwnerID = CreatorID = OwnerID = ownerID;
@@ -441,7 +476,7 @@ namespace OpenSim.Region.Framework.Scenes
441 private uint _ownerMask = (uint)(PermissionMask.All | PermissionMask.Export); 476 private uint _ownerMask = (uint)(PermissionMask.All | PermissionMask.Export);
442 private uint _groupMask = (uint)PermissionMask.None; 477 private uint _groupMask = (uint)PermissionMask.None;
443 private uint _everyoneMask = (uint)PermissionMask.None; 478 private uint _everyoneMask = (uint)PermissionMask.None;
444 private uint _nextOwnerMask = (uint)PermissionMask.All; 479 private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
445 private PrimFlags _flags = PrimFlags.None; 480 private PrimFlags _flags = PrimFlags.None;
446 private DateTime m_expires; 481 private DateTime m_expires;
447 private DateTime m_rezzed; 482 private DateTime m_rezzed;
@@ -539,12 +574,16 @@ namespace OpenSim.Region.Framework.Scenes
539 } 574 }
540 575
541 /// <value> 576 /// <value>
542 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 577 /// Get the inventory list
543 /// </value> 578 /// </value>
544 public TaskInventoryDictionary TaskInventory 579 public TaskInventoryDictionary TaskInventory
545 { 580 {
546 get { return m_inventory.Items; } 581 get {
547 set { m_inventory.Items = value; } 582 return m_inventory.Items;
583 }
584 set {
585 m_inventory.Items = value;
586 }
548 } 587 }
549 588
550 /// <summary> 589 /// <summary>
@@ -594,20 +633,6 @@ namespace OpenSim.Region.Framework.Scenes
594 } 633 }
595 } 634 }
596 635
597 public byte Material
598 {
599 get { return (byte) m_material; }
600 set
601 {
602 m_material = (Material)value;
603
604 PhysicsActor pa = PhysActor;
605
606 if (pa != null)
607 pa.SetMaterial((int)value);
608 }
609 }
610
611 [XmlIgnore] 636 [XmlIgnore]
612 public bool PassTouches 637 public bool PassTouches
613 { 638 {
@@ -633,6 +658,19 @@ namespace OpenSim.Region.Framework.Scenes
633 } 658 }
634 } 659 }
635 660
661 public bool IsSelected
662 {
663 get { return m_isSelected; }
664 set
665 {
666 m_isSelected = value;
667 if (ParentGroup != null)
668 ParentGroup.PartSelectChanged(value);
669
670 }
671 }
672
673
636 public Dictionary<int, string> CollisionFilter 674 public Dictionary<int, string> CollisionFilter
637 { 675 {
638 get { return m_CollisionFilter; } 676 get { return m_CollisionFilter; }
@@ -707,14 +745,12 @@ namespace OpenSim.Region.Framework.Scenes
707 set { m_LoopSoundSlavePrims = value; } 745 set { m_LoopSoundSlavePrims = value; }
708 } 746 }
709 747
710
711 public Byte[] TextureAnimation 748 public Byte[] TextureAnimation
712 { 749 {
713 get { return m_TextureAnimation; } 750 get { return m_TextureAnimation; }
714 set { m_TextureAnimation = value; } 751 set { m_TextureAnimation = value; }
715 } 752 }
716 753
717
718 public Byte[] ParticleSystem 754 public Byte[] ParticleSystem
719 { 755 {
720 get { return m_particleSystem; } 756 get { return m_particleSystem; }
@@ -742,18 +778,32 @@ namespace OpenSim.Region.Framework.Scenes
742 set { m_damage = value; } 778 set { m_damage = value; }
743 } 779 }
744 780
781
782
783
784 public void setGroupPosition(Vector3 pos)
785 {
786 m_groupPosition = pos;
787 }
788
745 /// <summary> 789 /// <summary>
746 /// The position of the entire group that this prim belongs to. 790 /// The position of the entire group that this prim belongs to.
747 /// </summary> 791 /// </summary>
792 ///
793
794
748 public Vector3 GroupPosition 795 public Vector3 GroupPosition
749 { 796 {
750 get 797 get
751 { 798 {
752 // If this is a linkset, we don't want the physics engine mucking up our group position here. 799 // If this is a linkset, we don't want the physics engine mucking up our group position here.
753 PhysicsActor actor = PhysActor; 800 PhysicsActor actor = PhysActor;
754 // If physical and the root prim of a linkset, the position of the group is what physics thinks. 801 if (ParentID == 0)
755 if (actor != null && ParentID == 0) 802 {
756 m_groupPosition = actor.Position; 803 if (actor != null)
804 m_groupPosition = actor.Position;
805 return m_groupPosition;
806 }
757 807
758 // If I'm an attachment, my position is reported as the position of who I'm attached to 808 // If I'm an attachment, my position is reported as the position of who I'm attached to
759 if (ParentGroup.IsAttachment) 809 if (ParentGroup.IsAttachment)
@@ -763,21 +813,23 @@ namespace OpenSim.Region.Framework.Scenes
763 return sp.AbsolutePosition; 813 return sp.AbsolutePosition;
764 } 814 }
765 815
816 // use root prim's group position. Physics may have updated it
817 if (ParentGroup.RootPart != this)
818 m_groupPosition = ParentGroup.RootPart.GroupPosition;
766 return m_groupPosition; 819 return m_groupPosition;
767 } 820 }
768 set 821 set
769 { 822 {
770 m_groupPosition = value; 823 m_groupPosition = value;
771
772 PhysicsActor actor = PhysActor; 824 PhysicsActor actor = PhysActor;
773 if (actor != null) 825 if (actor != null && ParentGroup.Scene.PhysicsScene != null)
774 { 826 {
775 try 827 try
776 { 828 {
777 // Root prim actually goes at Position 829 // Root prim actually goes at Position
778 if (ParentID == 0) 830 if (ParentID == 0)
779 { 831 {
780 actor.Position = value; 832 actor.Position = value;
781 } 833 }
782 else 834 else
783 { 835 {
@@ -798,12 +850,17 @@ namespace OpenSim.Region.Framework.Scenes
798 } 850 }
799 } 851 }
800 852
853 public void setOffsetPosition(Vector3 pos)
854 {
855 m_offsetPosition = pos;
856 }
857
801 public Vector3 OffsetPosition 858 public Vector3 OffsetPosition
802 { 859 {
803 get { return m_offsetPosition; } 860 get { return m_offsetPosition; }
804 set 861 set
805 { 862 {
806// StoreUndoState(); 863 Vector3 oldpos = m_offsetPosition;
807 m_offsetPosition = value; 864 m_offsetPosition = value;
808 865
809 if (ParentGroup != null && !ParentGroup.IsDeleted) 866 if (ParentGroup != null && !ParentGroup.IsDeleted)
@@ -815,10 +872,26 @@ namespace OpenSim.Region.Framework.Scenes
815 actor.Orientation = GetWorldRotation(); 872 actor.Orientation = GetWorldRotation();
816 873
817 // Tell the physics engines that this prim changed. 874 // Tell the physics engines that this prim changed.
818 if (ParentGroup.Scene != null) 875 if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
819 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 876 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
820 } 877 }
878
879 if (!m_parentGroup.m_dupeInProgress)
880 {
881 List<ScenePresence> avs = ParentGroup.GetLinkedAvatars();
882 foreach (ScenePresence av in avs)
883 {
884 if (av.ParentID == m_localId)
885 {
886 Vector3 offset = (m_offsetPosition - oldpos);
887 av.AbsolutePosition += offset;
888// av.SendAvatarDataToAllAgents();
889 av.SendTerseUpdateToAllClients();
890 }
891 }
892 }
821 } 893 }
894 TriggerScriptChangedEvent(Changed.POSITION);
822 } 895 }
823 } 896 }
824 897
@@ -840,6 +913,11 @@ namespace OpenSim.Region.Framework.Scenes
840 } 913 }
841 } 914 }
842 915
916 public void setRotationOffset(Quaternion q)
917 {
918 m_rotationOffset = q;
919 }
920
843 public Quaternion RotationOffset 921 public Quaternion RotationOffset
844 { 922 {
845 get 923 get
@@ -869,7 +947,7 @@ namespace OpenSim.Region.Framework.Scenes
869 947
870 set 948 set
871 { 949 {
872 StoreUndoState(); 950// StoreUndoState();
873 m_rotationOffset = value; 951 m_rotationOffset = value;
874 952
875 PhysicsActor actor = PhysActor; 953 PhysicsActor actor = PhysActor;
@@ -960,7 +1038,7 @@ namespace OpenSim.Region.Framework.Scenes
960 get 1038 get
961 { 1039 {
962 PhysicsActor actor = PhysActor; 1040 PhysicsActor actor = PhysActor;
963 if ((actor != null) && actor.IsPhysical) 1041 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
964 { 1042 {
965 m_angularVelocity = actor.RotationalVelocity; 1043 m_angularVelocity = actor.RotationalVelocity;
966 } 1044 }
@@ -968,6 +1046,7 @@ namespace OpenSim.Region.Framework.Scenes
968 } 1046 }
969 set 1047 set
970 { 1048 {
1049<<<<<<< HEAD
971 if (Util.IsNanOrInfinity(value)) 1050 if (Util.IsNanOrInfinity(value))
972 m_angularVelocity = Vector3.Zero; 1051 m_angularVelocity = Vector3.Zero;
973 else 1052 else
@@ -976,12 +1055,21 @@ namespace OpenSim.Region.Framework.Scenes
976 PhysicsActor actor = PhysActor; 1055 PhysicsActor actor = PhysActor;
977 if ((actor != null) && actor.IsPhysical) 1056 if ((actor != null) && actor.IsPhysical)
978 actor.RotationalVelocity = m_angularVelocity; 1057 actor.RotationalVelocity = m_angularVelocity;
1058=======
1059 m_angularVelocity = value;
1060 PhysicsActor actor = PhysActor;
1061 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this && VehicleType == (int)Vehicle.TYPE_NONE)
1062 {
1063 actor.RotationalVelocity = m_angularVelocity;
1064 }
1065>>>>>>> avn/ubitvar
979 } 1066 }
980 } 1067 }
981 1068
982 /// <summary></summary> 1069 /// <summary></summary>
983 public Vector3 Acceleration 1070 public Vector3 Acceleration
984 { 1071 {
1072<<<<<<< HEAD
985 get { return m_acceleration; } 1073 get { return m_acceleration; }
986 set 1074 set
987 { 1075 {
@@ -990,6 +1078,19 @@ namespace OpenSim.Region.Framework.Scenes
990 else 1078 else
991 m_acceleration = value; 1079 m_acceleration = value;
992 } 1080 }
1081=======
1082 get
1083 {
1084 PhysicsActor actor = PhysActor;
1085 if (actor != null)
1086 {
1087 m_acceleration = actor.Acceleration;
1088 }
1089 return m_acceleration;
1090 }
1091
1092 set { m_acceleration = value; }
1093>>>>>>> avn/ubitvar
993 } 1094 }
994 1095
995 public string Description { get; set; } 1096 public string Description { get; set; }
@@ -1056,7 +1157,10 @@ namespace OpenSim.Region.Framework.Scenes
1056 public PrimitiveBaseShape Shape 1157 public PrimitiveBaseShape Shape
1057 { 1158 {
1058 get { return m_shape; } 1159 get { return m_shape; }
1059 set { m_shape = value;} 1160 set
1161 {
1162 m_shape = value;
1163 }
1060 } 1164 }
1061 1165
1062 /// <summary> 1166 /// <summary>
@@ -1069,7 +1173,6 @@ namespace OpenSim.Region.Framework.Scenes
1069 { 1173 {
1070 if (m_shape != null) 1174 if (m_shape != null)
1071 { 1175 {
1072 StoreUndoState();
1073 1176
1074 m_shape.Scale = value; 1177 m_shape.Scale = value;
1075 1178
@@ -1137,10 +1240,7 @@ namespace OpenSim.Region.Framework.Scenes
1137 { 1240 {
1138 get 1241 get
1139 { 1242 {
1140 if (ParentGroup.IsAttachment) 1243 return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
1141 return GroupPosition;
1142
1143 return m_offsetPosition + m_groupPosition;
1144 } 1244 }
1145 } 1245 }
1146 1246
@@ -1309,6 +1409,13 @@ namespace OpenSim.Region.Framework.Scenes
1309 _flags = value; 1409 _flags = value;
1310 } 1410 }
1311 } 1411 }
1412
1413 [XmlIgnore]
1414 public bool IsOccupied // KF If an av is sittingon this prim
1415 {
1416 get { return m_occupied; }
1417 set { m_occupied = value; }
1418 }
1312 1419
1313 /// <summary> 1420 /// <summary>
1314 /// ID of the avatar that is sat on us if we have a sit target. If there is no such avatar then is UUID.Zero 1421 /// ID of the avatar that is sat on us if we have a sit target. If there is no such avatar then is UUID.Zero
@@ -1359,12 +1466,41 @@ namespace OpenSim.Region.Framework.Scenes
1359 set { m_sitAnimation = value; } 1466 set { m_sitAnimation = value; }
1360 } 1467 }
1361 1468
1469 public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
1470
1471 // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
1472 // runtime thing.. do not persist
1473 [XmlIgnore]
1474 public sbyte CollisionSoundType
1475 {
1476 get
1477 {
1478 return m_collisionSoundType;
1479 }
1480 set
1481 {
1482 m_collisionSoundType = value;
1483 if (value == -1)
1484 m_collisionSound = invalidCollisionSoundUUID;
1485 else if (value == 0)
1486 m_collisionSound = UUID.Zero;
1487 }
1488 }
1489
1362 public UUID CollisionSound 1490 public UUID CollisionSound
1363 { 1491 {
1364 get { return m_collisionSound; } 1492 get { return m_collisionSound; }
1365 set 1493 set
1366 { 1494 {
1367 m_collisionSound = value; 1495 m_collisionSound = value;
1496
1497 if (value == invalidCollisionSoundUUID)
1498 m_collisionSoundType = -1;
1499 else if (value == UUID.Zero)
1500 m_collisionSoundType = 0;
1501 else
1502 m_collisionSoundType = 1;
1503
1368 aggregateScriptEvents(); 1504 aggregateScriptEvents();
1369 } 1505 }
1370 } 1506 }
@@ -1375,6 +1511,125 @@ namespace OpenSim.Region.Framework.Scenes
1375 set { m_collisionSoundVolume = value; } 1511 set { m_collisionSoundVolume = value; }
1376 } 1512 }
1377 1513
1514 public float Buoyancy
1515 {
1516 get
1517 {
1518 if (ParentGroup.RootPart == this)
1519 return m_buoyancy;
1520
1521 return ParentGroup.RootPart.Buoyancy;
1522 }
1523 set
1524 {
1525 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1526 {
1527 ParentGroup.RootPart.Buoyancy = value;
1528 return;
1529 }
1530 m_buoyancy = value;
1531 if (PhysActor != null)
1532 PhysActor.Buoyancy = value;
1533 }
1534 }
1535
1536 public Vector3 Force
1537 {
1538 get
1539 {
1540 if (ParentGroup.RootPart == this)
1541 return m_force;
1542
1543 return ParentGroup.RootPart.Force;
1544 }
1545
1546 set
1547 {
1548 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1549 {
1550 ParentGroup.RootPart.Force = value;
1551 return;
1552 }
1553 m_force = value;
1554 if (PhysActor != null)
1555 PhysActor.Force = value;
1556 }
1557 }
1558
1559 public Vector3 Torque
1560 {
1561 get
1562 {
1563 if (ParentGroup.RootPart == this)
1564 return m_torque;
1565
1566 return ParentGroup.RootPart.Torque;
1567 }
1568
1569 set
1570 {
1571 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1572 {
1573 ParentGroup.RootPart.Torque = value;
1574 return;
1575 }
1576 m_torque = value;
1577 if (PhysActor != null)
1578 PhysActor.Torque = value;
1579 }
1580 }
1581
1582 public byte Material
1583 {
1584 get { return (byte)m_material; }
1585 set
1586 {
1587 if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
1588 {
1589 bool update = false;
1590
1591 if (m_material != (Material)value)
1592 {
1593 update = true;
1594 m_material = (Material)value;
1595 }
1596
1597 if (m_friction != SOPMaterialData.friction(m_material))
1598 {
1599 update = true;
1600 m_friction = SOPMaterialData.friction(m_material);
1601 }
1602
1603 if (m_bounce != SOPMaterialData.bounce(m_material))
1604 {
1605 update = true;
1606 m_bounce = SOPMaterialData.bounce(m_material);
1607 }
1608
1609 if (update)
1610 {
1611 if (PhysActor != null)
1612 {
1613 PhysActor.SetMaterial((int)value);
1614 }
1615 if(ParentGroup != null)
1616 ParentGroup.HasGroupChanged = true;
1617 ScheduleFullUpdateIfNone();
1618 UpdatePhysRequired = true;
1619 }
1620 }
1621 }
1622 }
1623
1624 // not a propriety to move to methods place later
1625 private bool HasMesh()
1626 {
1627 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1628 return true;
1629 return false;
1630 }
1631
1632 // not a propriety to move to methods place later
1378 public byte DefaultPhysicsShapeType() 1633 public byte DefaultPhysicsShapeType()
1379 { 1634 {
1380 byte type; 1635 byte type;
@@ -1387,6 +1642,65 @@ namespace OpenSim.Region.Framework.Scenes
1387 return type; 1642 return type;
1388 } 1643 }
1389 1644
1645 [XmlIgnore]
1646 public bool UsesComplexCost
1647 {
1648 get
1649 {
1650 byte pst = PhysicsShapeType;
1651 if(pst == (byte) PhysShapeType.none || pst == (byte) PhysShapeType.convex || HasMesh())
1652 return true;
1653 return false;
1654 }
1655 }
1656
1657 [XmlIgnore]
1658 public float PhysicsCost
1659 {
1660 get
1661 {
1662 if(PhysicsShapeType == (byte)PhysShapeType.none)
1663 return 0;
1664
1665 float cost = 0.1f;
1666 if (PhysActor != null)
1667 cost = PhysActor.PhysicsCost;
1668 else
1669 cost = 0.1f;
1670
1671 if ((Flags & PrimFlags.Physics) != 0)
1672 cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
1673 return cost;
1674 }
1675 }
1676
1677 [XmlIgnore]
1678 public float StreamingCost
1679 {
1680 get
1681 {
1682 float cost;
1683 if (PhysActor != null)
1684 cost = PhysActor.StreamCost;
1685 else
1686 cost = 1.0f;
1687 return 1.0f;
1688 }
1689 }
1690
1691 [XmlIgnore]
1692 public float SimulationCost
1693 {
1694 get
1695 {
1696 // ignoring scripts. Don't like considering them for this
1697 if((Flags & PrimFlags.Physics) != 0)
1698 return 1.0f;
1699
1700 return 0.5f;
1701 }
1702 }
1703
1390 public byte PhysicsShapeType 1704 public byte PhysicsShapeType
1391 { 1705 {
1392 get { return m_physicsShapeType; } 1706 get { return m_physicsShapeType; }
@@ -1420,11 +1734,14 @@ namespace OpenSim.Region.Framework.Scenes
1420 } 1734 }
1421 else if (PhysActor == null) 1735 else if (PhysActor == null)
1422 { 1736 {
1423 ApplyPhysics((uint)Flags, VolumeDetectActive); 1737 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
1738 UpdatePhysicsSubscribedEvents();
1424 } 1739 }
1425 else 1740 else
1426 { 1741 {
1427 PhysActor.PhysicsShapeType = m_physicsShapeType; 1742 PhysActor.PhysicsShapeType = m_physicsShapeType;
1743// if (Shape.SculptEntry)
1744// CheckSculptAndLoad();
1428 } 1745 }
1429 1746
1430 if (ParentGroup != null) 1747 if (ParentGroup != null)
@@ -1526,6 +1843,7 @@ namespace OpenSim.Region.Framework.Scenes
1526 } 1843 }
1527 } 1844 }
1528 1845
1846
1529 #endregion Public Properties with only Get 1847 #endregion Public Properties with only Get
1530 1848
1531 private uint ApplyMask(uint val, bool set, uint mask) 1849 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1614,6 +1932,7 @@ namespace OpenSim.Region.Framework.Scenes
1614 1932
1615 public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim) 1933 public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
1616 { 1934 {
1935<<<<<<< HEAD
1617 byte[] data; 1936 byte[] data;
1618 1937
1619 if (pTexAnim.Flags == Primitive.TextureAnimMode.ANIM_OFF) 1938 if (pTexAnim.Flags == Primitive.TextureAnimMode.ANIM_OFF)
@@ -1625,6 +1944,13 @@ namespace OpenSim.Region.Framework.Scenes
1625 data = new byte[16]; 1944 data = new byte[16];
1626 int pos = 0; 1945 int pos = 0;
1627 1946
1947=======
1948 if (((int)pTexAnim.Flags & 1) != 0) // ANIM_ON
1949 {
1950 byte[] data = new byte[16];
1951 int pos = 0;
1952
1953>>>>>>> avn/ubitvar
1628 // The flags don't like conversion from uint to byte, so we have to do 1954 // The flags don't like conversion from uint to byte, so we have to do
1629 // it the crappy way. See the above function :( 1955 // it the crappy way. See the above function :(
1630 1956
@@ -1636,9 +1962,17 @@ namespace OpenSim.Region.Framework.Scenes
1636 Utils.FloatToBytes(pTexAnim.Start).CopyTo(data, pos); 1962 Utils.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
1637 Utils.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4); 1963 Utils.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4);
1638 Utils.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8); 1964 Utils.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
1965<<<<<<< HEAD
1639 } 1966 }
1967=======
1968>>>>>>> avn/ubitvar
1640 1969
1641 m_TextureAnimation = data; 1970 m_TextureAnimation = data;
1971 }
1972 else
1973 {
1974 m_TextureAnimation = Utils.EmptyBytes;
1975 }
1642 } 1976 }
1643 1977
1644 public void AdjustSoundGain(double volume) 1978 public void AdjustSoundGain(double volume)
@@ -1680,6 +2014,61 @@ namespace OpenSim.Region.Framework.Scenes
1680 } 2014 }
1681 } 2015 }
1682 2016
2017 // SetVelocity for LSL llSetVelocity.. may need revision if having other uses in future
2018 public void SetVelocity(Vector3 pVel, bool localGlobalTF)
2019 {
2020 if (ParentGroup == null || ParentGroup.IsDeleted)
2021 return;
2022
2023 if (ParentGroup.IsAttachment)
2024 return; // don't work on attachments (for now ??)
2025
2026 SceneObjectPart root = ParentGroup.RootPart;
2027
2028 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
2029 return;
2030
2031 PhysicsActor pa = root.PhysActor;
2032
2033 if (pa == null || !pa.IsPhysical)
2034 return;
2035
2036 if (localGlobalTF)
2037 {
2038 pVel = pVel * GetWorldRotation();
2039 }
2040
2041 ParentGroup.Velocity = pVel;
2042 }
2043
2044 // SetAngularVelocity for LSL llSetAngularVelocity.. may need revision if having other uses in future
2045 public void SetAngularVelocity(Vector3 pAngVel, bool localGlobalTF)
2046 {
2047 if (ParentGroup == null || ParentGroup.IsDeleted)
2048 return;
2049
2050 if (ParentGroup.IsAttachment)
2051 return; // don't work on attachments (for now ??)
2052
2053 SceneObjectPart root = ParentGroup.RootPart;
2054
2055 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
2056 return;
2057
2058 PhysicsActor pa = root.PhysActor;
2059
2060 if (pa == null || !pa.IsPhysical)
2061 return;
2062
2063 if (localGlobalTF)
2064 {
2065 pAngVel = pAngVel * GetWorldRotation();
2066 }
2067
2068 root.AngularVelocity = pAngVel;
2069 }
2070
2071
1683 /// <summary> 2072 /// <summary>
1684 /// hook to the physics scene to apply angular impulse 2073 /// hook to the physics scene to apply angular impulse
1685 /// This is sent up to the group, which then finds the root prim 2074 /// This is sent up to the group, which then finds the root prim
@@ -1700,7 +2089,7 @@ namespace OpenSim.Region.Framework.Scenes
1700 impulse = newimpulse; 2089 impulse = newimpulse;
1701 } 2090 }
1702 2091
1703 ParentGroup.applyAngularImpulse(impulse); 2092 ParentGroup.ApplyAngularImpulse(impulse);
1704 } 2093 }
1705 2094
1706 /// <summary> 2095 /// <summary>
@@ -1710,20 +2099,24 @@ namespace OpenSim.Region.Framework.Scenes
1710 /// </summary> 2099 /// </summary>
1711 /// <param name="impulsei">Vector force</param> 2100 /// <param name="impulsei">Vector force</param>
1712 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 2101 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1713 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 2102
2103 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
2104 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1714 { 2105 {
1715 Vector3 impulse = impulsei; 2106 Vector3 torque = torquei;
1716 2107
1717 if (localGlobalTF) 2108 if (localGlobalTF)
1718 { 2109 {
2110/*
1719 Quaternion grot = GetWorldRotation(); 2111 Quaternion grot = GetWorldRotation();
1720 Quaternion AXgrot = grot; 2112 Quaternion AXgrot = grot;
1721 Vector3 AXimpulsei = impulsei; 2113 Vector3 AXimpulsei = impulsei;
1722 Vector3 newimpulse = AXimpulsei * AXgrot; 2114 Vector3 newimpulse = AXimpulsei * AXgrot;
1723 impulse = newimpulse; 2115 */
2116 torque *= GetWorldRotation();
1724 } 2117 }
1725 2118
1726 ParentGroup.setAngularImpulse(impulse); 2119 Torque = torque;
1727 } 2120 }
1728 2121
1729 /// <summary> 2122 /// <summary>
@@ -1731,7 +2124,9 @@ namespace OpenSim.Region.Framework.Scenes
1731 /// </summary> 2124 /// </summary>
1732 /// <param name="rootObjectFlags"></param> 2125 /// <param name="rootObjectFlags"></param>
1733 /// <param name="VolumeDetectActive"></param> 2126 /// <param name="VolumeDetectActive"></param>
1734 public void ApplyPhysics(uint rootObjectFlags, bool _VolumeDetectActive) 2127 /// <param name="building"></param>
2128
2129 public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
1735 { 2130 {
1736 VolumeDetectActive = _VolumeDetectActive; 2131 VolumeDetectActive = _VolumeDetectActive;
1737 2132
@@ -1741,8 +2136,8 @@ namespace OpenSim.Region.Framework.Scenes
1741 if (PhysicsShapeType == (byte)PhysShapeType.none) 2136 if (PhysicsShapeType == (byte)PhysShapeType.none)
1742 return; 2137 return;
1743 2138
1744 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 2139 bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
1745 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 2140 bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
1746 2141
1747 if (_VolumeDetectActive) 2142 if (_VolumeDetectActive)
1748 isPhantom = true; 2143 isPhantom = true;
@@ -1756,7 +2151,8 @@ namespace OpenSim.Region.Framework.Scenes
1756 if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment 2151 if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment
1757 && !(Shape.PathCurve == (byte)Extrusion.Flexible)) 2152 && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1758 { 2153 {
1759 AddToPhysics(isPhysical, isPhantom, isPhysical); 2154 AddToPhysics(isPhysical, isPhantom, building, isPhysical);
2155 UpdatePhysicsSubscribedEvents(); // not sure if appliable here
1760 } 2156 }
1761 else 2157 else
1762 PhysActor = null; // just to be sure 2158 PhysActor = null; // just to be sure
@@ -1785,7 +2181,7 @@ namespace OpenSim.Region.Framework.Scenes
1785 /// <param name="linkNum"></param> 2181 /// <param name="linkNum"></param>
1786 /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param> 2182 /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
1787 /// <returns></returns> 2183 /// <returns></returns>
1788 public SceneObjectPart Copy(uint localID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed) 2184 public SceneObjectPart Copy(uint plocalID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
1789 { 2185 {
1790 // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up 2186 // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up
1791 // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator 2187 // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator
@@ -1815,6 +2211,12 @@ namespace OpenSim.Region.Framework.Scenes
1815 dupe.Category = Category; 2211 dupe.Category = Category;
1816 dupe.m_rezzed = m_rezzed; 2212 dupe.m_rezzed = m_rezzed;
1817 2213
2214 dupe.m_UndoRedo = null;
2215 dupe.m_isSelected = false;
2216
2217 dupe.IgnoreUndoUpdate = false;
2218 dupe.Undoing = false;
2219
1818 dupe.m_inventory = new SceneObjectPartInventory(dupe); 2220 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1819 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 2221 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1820 2222
@@ -1829,7 +2231,8 @@ namespace OpenSim.Region.Framework.Scenes
1829 } 2231 }
1830 2232
1831 // Move afterwards ResetIDs as it clears the localID 2233 // Move afterwards ResetIDs as it clears the localID
1832 dupe.LocalId = localID; 2234 dupe.LocalId = plocalID;
2235
1833 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 2236 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1834 dupe.LastOwnerID = OwnerID; 2237 dupe.LastOwnerID = OwnerID;
1835 2238
@@ -1856,8 +2259,12 @@ namespace OpenSim.Region.Framework.Scenes
1856*/ 2259*/
1857 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0); 2260 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
1858 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 2261 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
2262// dupe.UpdatePhysicsSubscribedEvents(); // not sure...
1859 } 2263 }
1860 2264
2265 if (dupe.PhysActor != null)
2266 dupe.PhysActor.LocalID = plocalID;
2267
1861 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 2268 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1862 2269
1863// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 2270// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1876,10 +2283,10 @@ namespace OpenSim.Region.Framework.Scenes
1876 { 2283 {
1877 if (asset != null) 2284 if (asset != null)
1878 SculptTextureCallback(asset); 2285 SculptTextureCallback(asset);
1879 else 2286// else
1880 m_log.WarnFormat( 2287// m_log.WarnFormat(
1881 "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data", 2288// "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
1882 Name, UUID, id); 2289// Name, UUID, id);
1883 } 2290 }
1884*/ 2291*/
1885 /// <summary> 2292 /// <summary>
@@ -1978,6 +2385,7 @@ namespace OpenSim.Region.Framework.Scenes
1978 2385
1979 /// <summary> 2386 /// <summary>
1980 /// Do a physics propery update for this part. 2387 /// Do a physics propery update for this part.
2388 /// now also updates phantom and volume detector
1981 /// </summary> 2389 /// </summary>
1982 /// <param name="UsePhysics"></param> 2390 /// <param name="UsePhysics"></param>
1983 /// <param name="isNew"></param> 2391 /// <param name="isNew"></param>
@@ -2003,64 +2411,69 @@ namespace OpenSim.Region.Framework.Scenes
2003 { 2411 {
2004 if (pa.IsPhysical) // implies UsePhysics==false for this block 2412 if (pa.IsPhysical) // implies UsePhysics==false for this block
2005 { 2413 {
2006 if (!isNew) 2414 if (!isNew) // implies UsePhysics==false for this block
2415 {
2007 ParentGroup.Scene.RemovePhysicalPrim(1); 2416 ParentGroup.Scene.RemovePhysicalPrim(1);
2008 2417
2009 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 2418 Velocity = new Vector3(0, 0, 0);
2010 pa.OnOutOfBounds -= PhysicsOutOfBounds; 2419 Acceleration = new Vector3(0, 0, 0);
2011 pa.delink(); 2420 if (ParentGroup.RootPart == this)
2421 AngularVelocity = new Vector3(0, 0, 0);
2012 2422
2013 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 2423 if (pa.Phantom && !VolumeDetectActive)
2014 { 2424 {
2015 // destroy all joints connected to this now deactivated body 2425 RemoveFromPhysics();
2016 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa); 2426 return;
2017 } 2427 }
2018 2428
2019 // stop client-side interpolation of all joint proxy objects that have just been deleted 2429 pa.IsPhysical = UsePhysics;
2020 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 2430 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
2021 // which stops client-side interpolation of deactivated joint proxy objects. 2431 pa.OnOutOfBounds -= PhysicsOutOfBounds;
2432 pa.delink();
2433 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
2434 {
2435 // destroy all joints connected to this now deactivated body
2436 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
2437 }
2438 }
2022 } 2439 }
2023 2440
2024 if (!UsePhysics && !isNew) 2441 if (pa.IsPhysical != UsePhysics)
2025 { 2442 pa.IsPhysical = UsePhysics;
2026 // reset velocity to 0 on physics switch-off. Without that, the client thinks the
2027 // prim still has velocity and continues to interpolate its position along the old
2028 // velocity-vector.
2029 Velocity = new Vector3(0, 0, 0);
2030 Acceleration = new Vector3(0, 0, 0);
2031 AngularVelocity = new Vector3(0, 0, 0);
2032 //RotationalVelocity = new Vector3(0, 0, 0);
2033 }
2034 2443
2035 pa.IsPhysical = UsePhysics; 2444 if (UsePhysics)
2445 {
2446 if (ParentGroup.RootPart.KeyframeMotion != null)
2447 ParentGroup.RootPart.KeyframeMotion.Stop();
2448 ParentGroup.RootPart.KeyframeMotion = null;
2449 ParentGroup.Scene.AddPhysicalPrim(1);
2036 2450
2037 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2451 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
2038 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2452 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
2039 /// that's not wholesome. Had to make Scene public
2040 //PhysActor = null;
2041 2453
2042 if ((Flags & PrimFlags.Phantom) == 0) 2454 if (ParentID != 0 && ParentID != LocalId)
2043 {
2044 if (UsePhysics)
2045 { 2455 {
2046 if (ParentGroup.RootPart.KeyframeMotion != null) 2456 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
2047 ParentGroup.RootPart.KeyframeMotion.Stop();
2048 ParentGroup.RootPart.KeyframeMotion = null;
2049 ParentGroup.Scene.AddPhysicalPrim(1);
2050
2051 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
2052 pa.OnOutOfBounds += PhysicsOutOfBounds;
2053 if (ParentID != 0 && ParentID != LocalId)
2054 {
2055 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
2056 2457
2057 if (parentPa != null) 2458 if (parentPa != null)
2058 { 2459 {
2059 pa.link(parentPa); 2460 pa.link(parentPa);
2060 }
2061 } 2461 }
2062 } 2462 }
2063 } 2463 }
2464 }
2465
2466 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2467 if (pa.Phantom != phan)
2468 pa.Phantom = phan;
2469
2470// some engines dont' have this check still
2471// if (VolumeDetectActive != pa.IsVolumeDtc)
2472 {
2473 if (VolumeDetectActive)
2474 pa.SetVolumeDetect(1);
2475 else
2476 pa.SetVolumeDetect(0);
2064 } 2477 }
2065 2478
2066 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2479 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
@@ -2163,42 +2576,63 @@ namespace OpenSim.Region.Framework.Scenes
2163 2576
2164 public Vector3 GetGeometricCenter() 2577 public Vector3 GetGeometricCenter()
2165 { 2578 {
2579 // this is not real geometric center but a average of positions relative to root prim acording to
2580 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
2581 // ignoring tortured prims details since sl also seems to ignore
2582 // so no real use in doing it on physics
2583 if (ParentGroup.IsDeleted)
2584 return new Vector3(0, 0, 0);
2585
2586 return ParentGroup.GetGeometricCenter();
2587 }
2588
2589 public float GetMass()
2590 {
2166 PhysicsActor pa = PhysActor; 2591 PhysicsActor pa = PhysActor;
2167 2592
2168 if (pa != null) 2593 if (pa != null)
2169 return pa.GeometricCenter; 2594 return pa.Mass;
2170 else 2595 else
2171 return Vector3.Zero; 2596 return 0;
2172 } 2597 }
2173 2598
2174 public Vector3 GetCenterOfMass() 2599 public Vector3 GetCenterOfMass()
2175 { 2600 {
2601 if (ParentGroup.RootPart == this)
2602 {
2603 if (ParentGroup.IsDeleted)
2604 return AbsolutePosition;
2605 return ParentGroup.GetCenterOfMass();
2606 }
2607
2176 PhysicsActor pa = PhysActor; 2608 PhysicsActor pa = PhysActor;
2177 2609
2178 if (pa != null) 2610 if (pa != null)
2179 return pa.CenterOfMass; 2611 {
2612 Vector3 tmp = pa.CenterOfMass;
2613 return tmp;
2614 }
2180 else 2615 else
2181 return Vector3.Zero; 2616 return AbsolutePosition;
2182 } 2617 }
2183 2618
2184 public float GetMass() 2619 public Vector3 GetPartCenterOfMass()
2185 { 2620 {
2186 PhysicsActor pa = PhysActor; 2621 PhysicsActor pa = PhysActor;
2187 2622
2188 if (pa != null) 2623 if (pa != null)
2189 return pa.Mass; 2624 {
2625 Vector3 tmp = pa.CenterOfMass;
2626 return tmp;
2627 }
2190 else 2628 else
2191 return 0; 2629 return AbsolutePosition;
2192 } 2630 }
2193 2631
2632
2194 public Vector3 GetForce() 2633 public Vector3 GetForce()
2195 { 2634 {
2196 PhysicsActor pa = PhysActor; 2635 return Force;
2197
2198 if (pa != null)
2199 return pa.Force;
2200 else
2201 return Vector3.Zero;
2202 } 2636 }
2203 2637
2204 /// <summary> 2638 /// <summary>
@@ -2313,6 +2747,7 @@ namespace OpenSim.Region.Framework.Scenes
2313 detobj.velVector = obj.Velocity; 2747 detobj.velVector = obj.Velocity;
2314 detobj.colliderType = 0; 2748 detobj.colliderType = 0;
2315 detobj.groupUUID = obj.GroupID; 2749 detobj.groupUUID = obj.GroupID;
2750 detobj.linkNumber = LinkNum; // pass my link number
2316 2751
2317 return detobj; 2752 return detobj;
2318 } 2753 }
@@ -2328,6 +2763,7 @@ namespace OpenSim.Region.Framework.Scenes
2328 detobj.velVector = av.Velocity; 2763 detobj.velVector = av.Velocity;
2329 detobj.colliderType = 0; 2764 detobj.colliderType = 0;
2330 detobj.groupUUID = av.ControllingClient.ActiveGroupId; 2765 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
2766 detobj.linkNumber = LinkNum; // pass my link number
2331 2767
2332 return detobj; 2768 return detobj;
2333 } 2769 }
@@ -2343,6 +2779,7 @@ namespace OpenSim.Region.Framework.Scenes
2343 detobj.velVector = Vector3.Zero; 2779 detobj.velVector = Vector3.Zero;
2344 detobj.colliderType = 0; 2780 detobj.colliderType = 0;
2345 detobj.groupUUID = UUID.Zero; 2781 detobj.groupUUID = UUID.Zero;
2782 detobj.linkNumber = LinkNum; // pass my link number not sure needed.. but no harm
2346 2783
2347 return detobj; 2784 return detobj;
2348 } 2785 }
@@ -2413,14 +2850,15 @@ namespace OpenSim.Region.Framework.Scenes
2413 2850
2414 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify) 2851 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
2415 { 2852 {
2416 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0) 2853 bool sendToRoot = true;
2417 {
2418 ColliderArgs LandCollidingMessage = new ColliderArgs();
2419 List<DetectedObject> colliding = new List<DetectedObject>();
2420
2421 colliding.Add(CreateDetObjectForGround());
2422 LandCollidingMessage.Colliders = colliding;
2423 2854
2855 ColliderArgs LandCollidingMessage = new ColliderArgs();
2856 List<DetectedObject> colliding = new List<DetectedObject>();
2857
2858 colliding.Add(CreateDetObjectForGround());
2859 LandCollidingMessage.Colliders = colliding;
2860
2861<<<<<<< HEAD
2424 DoNotify(notify, LocalId, LandCollidingMessage); 2862 DoNotify(notify, LocalId, LandCollidingMessage);
2425 } 2863 }
2426 } 2864 }
@@ -2448,6 +2886,19 @@ namespace OpenSim.Region.Framework.Scenes
2448 else 2886 else
2449 { 2887 {
2450 notify(id, collargs); 2888 notify(id, collargs);
2889=======
2890 if (Inventory.ContainsScripts())
2891 {
2892 if (!PassCollisions)
2893 sendToRoot = false;
2894 }
2895 if ((ScriptEvents & ev) != 0)
2896 notify(LocalId, LandCollidingMessage);
2897
2898 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
2899 {
2900 notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
2901>>>>>>> avn/ubitvar
2451 } 2902 }
2452 } 2903 }
2453 2904
@@ -2463,44 +2914,81 @@ namespace OpenSim.Region.Framework.Scenes
2463 List<uint> endedColliders = new List<uint>(); 2914 List<uint> endedColliders = new List<uint>();
2464 List<uint> startedColliders = new List<uint>(); 2915 List<uint> startedColliders = new List<uint>();
2465 2916
2466 // calculate things that started colliding this time 2917 if (collissionswith.Count == 0)
2467 // and build up list of colliders this time
2468 foreach (uint localid in collissionswith.Keys)
2469 { 2918 {
2470 thisHitColliders.Add(localid); 2919 if (m_lastColliders.Count == 0)
2471 if (!m_lastColliders.Contains(localid)) 2920 return; // nothing to do
2472 startedColliders.Add(localid);
2473 }
2474 2921
2475 // calculate things that ended colliding 2922 foreach (uint localID in m_lastColliders)
2476 foreach (uint localID in m_lastColliders) 2923 {
2477 {
2478 if (!thisHitColliders.Contains(localID))
2479 endedColliders.Add(localID); 2924 endedColliders.Add(localID);
2925 }
2926 m_lastColliders.Clear();
2480 } 2927 }
2481 2928
2482 //add the items that started colliding this time to the last colliders list. 2929 else
2483 foreach (uint localID in startedColliders) 2930 {
2484 m_lastColliders.Add(localID); 2931 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
2485 2932
2486 // remove things that ended colliding from the last colliders list 2933 // calculate things that started colliding this time
2487 foreach (uint localID in endedColliders) 2934 // and build up list of colliders this time
2488 m_lastColliders.Remove(localID); 2935 if (!VolumeDetectActive && CollisionSoundType >= 0)
2936 {
2937 CollisionForSoundInfo soundinfo;
2938 ContactPoint curcontact;
2489 2939
2490 // play the sound. 2940 foreach (uint id in collissionswith.Keys)
2491 if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) 2941 {
2492 { 2942 thisHitColliders.Add(id);
2493 ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>(); 2943 if (!m_lastColliders.Contains(id))
2494 if (soundModule != null) 2944 {
2945 startedColliders.Add(id);
2946
2947 curcontact = collissionswith[id];
2948 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
2949 {
2950 soundinfo = new CollisionForSoundInfo();
2951 soundinfo.colliderID = id;
2952 soundinfo.position = curcontact.Position;
2953 soundinfo.relativeVel = curcontact.RelativeSpeed;
2954 soundinfolist.Add(soundinfo);
2955 }
2956 }
2957 }
2958 }
2959 else
2960 {
2961 foreach (uint id in collissionswith.Keys)
2962 {
2963 thisHitColliders.Add(id);
2964 if (!m_lastColliders.Contains(id))
2965 startedColliders.Add(id);
2966 }
2967 }
2968
2969 // calculate things that ended colliding
2970 foreach (uint localID in m_lastColliders)
2495 { 2971 {
2496 soundModule.SendSound(UUID, CollisionSound, 2972 if (!thisHitColliders.Contains(localID))
2497 CollisionSoundVolume, true, 0, 0, false, 2973 endedColliders.Add(localID);
2498 false);
2499 } 2974 }
2975
2976 //add the items that started colliding this time to the last colliders list.
2977 foreach (uint localID in startedColliders)
2978 m_lastColliders.Add(localID);
2979
2980 // remove things that ended colliding from the last colliders list
2981 foreach (uint localID in endedColliders)
2982 m_lastColliders.Remove(localID);
2983
2984 // play sounds.
2985 if (soundinfolist.Count > 0)
2986 CollisionSounds.PartCollisionSound(this, soundinfolist);
2500 } 2987 }
2501 2988
2502 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); 2989 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
2503 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); 2990 if (!VolumeDetectActive)
2991 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
2504 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); 2992 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
2505 2993
2506 if (startedColliders.Contains(0)) 2994 if (startedColliders.Contains(0))
@@ -2511,6 +2999,35 @@ namespace OpenSim.Region.Framework.Scenes
2511 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); 2999 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd);
2512 } 3000 }
2513 3001
3002 // The Collision sounds code calls this
3003 public void SendCollisionSound(UUID soundID, double volume, Vector3 position)
3004 {
3005 if (soundID == UUID.Zero)
3006 return;
3007
3008 ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
3009 if (soundModule == null)
3010 return;
3011
3012 if (volume > 1)
3013 volume = 1;
3014 if (volume < 0)
3015 volume = 0;
3016
3017 int now = Util.EnvironmentTickCount();
3018 if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
3019 return;
3020
3021 LastColSoundSentTime = now;
3022
3023 UUID ownerID = OwnerID;
3024 UUID objectID = ParentGroup.RootPart.UUID;
3025 UUID parentID = ParentGroup.UUID;
3026 ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
3027
3028 soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, 0 );
3029 }
3030
2514 public void PhysicsOutOfBounds(Vector3 pos) 3031 public void PhysicsOutOfBounds(Vector3 pos)
2515 { 3032 {
2516 // Note: This is only being called on the root prim at this time. 3033 // Note: This is only being called on the root prim at this time.
@@ -2529,7 +3046,12 @@ namespace OpenSim.Region.Framework.Scenes
2529 3046
2530 if (pa != null) 3047 if (pa != null)
2531 { 3048 {
3049<<<<<<< HEAD
2532 Vector3 newpos = pa.Position; 3050 Vector3 newpos = pa.Position;
3051=======
3052 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0);
3053
3054>>>>>>> avn/ubitvar
2533 if (!ParentGroup.Scene.PositionIsInCurrentRegion(newpos)) 3055 if (!ParentGroup.Scene.PositionIsInCurrentRegion(newpos))
2534 { 3056 {
2535 // Setting position outside current region will start region crossing 3057 // Setting position outside current region will start region crossing
@@ -2538,7 +3060,7 @@ namespace OpenSim.Region.Framework.Scenes
2538 } 3060 }
2539 //ParentGroup.RootPart.m_groupPosition = newpos; 3061 //ParentGroup.RootPart.m_groupPosition = newpos;
2540 } 3062 }
2541 3063/* ubit: there are no flexible links
2542 if (pa != null && ParentID != 0 && ParentGroup != null) 3064 if (pa != null && ParentID != 0 && ParentGroup != null)
2543 { 3065 {
2544 // Special case where a child object is requesting property updates. 3066 // Special case where a child object is requesting property updates.
@@ -2558,7 +3080,7 @@ namespace OpenSim.Region.Framework.Scenes
2558 // m_log.DebugFormat("{0} PhysicsRequestingTerseUpdate child: pos={1}, rot={2}, offPos={3}, offRot={4}", 3080 // m_log.DebugFormat("{0} PhysicsRequestingTerseUpdate child: pos={1}, rot={2}, offPos={3}, offRot={4}",
2559 // "[SCENE OBJECT PART]", pa.Position, pa.Orientation, m_offsetPosition, RotationOffset); 3081 // "[SCENE OBJECT PART]", pa.Position, pa.Orientation, m_offsetPosition, RotationOffset);
2560 } 3082 }
2561 3083*/
2562 ScheduleTerseUpdate(); 3084 ScheduleTerseUpdate();
2563 } 3085 }
2564 3086
@@ -2811,7 +3333,19 @@ namespace OpenSim.Region.Framework.Scenes
2811 3333
2812// m_log.DebugFormat( 3334// m_log.DebugFormat(
2813// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId); 3335// "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
2814 3336
3337
3338 if (ParentGroup.IsAttachment)
3339 {
3340 ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
3341 if (sp != null)
3342 {
3343 sp.SendAttachmentUpdate(this, UpdateRequired.FULL);
3344 }
3345 }
3346
3347/* this does nothing
3348SendFullUpdateToClient(remoteClient, Position) ignores position parameter
2815 if (IsRoot) 3349 if (IsRoot)
2816 { 3350 {
2817 if (ParentGroup.IsAttachment) 3351 if (ParentGroup.IsAttachment)
@@ -2823,6 +3357,7 @@ namespace OpenSim.Region.Framework.Scenes
2823 SendFullUpdateToClient(remoteClient, AbsolutePosition); 3357 SendFullUpdateToClient(remoteClient, AbsolutePosition);
2824 } 3358 }
2825 } 3359 }
3360*/
2826 else 3361 else
2827 { 3362 {
2828 SendFullUpdateToClient(remoteClient); 3363 SendFullUpdateToClient(remoteClient);
@@ -2832,17 +3367,55 @@ namespace OpenSim.Region.Framework.Scenes
2832 /// <summary> 3367 /// <summary>
2833 /// Send a full update for this part to all clients. 3368 /// Send a full update for this part to all clients.
2834 /// </summary> 3369 /// </summary>
2835 public void SendFullUpdateToAllClients() 3370 public void SendFullUpdateToAllClientsInternal()
2836 { 3371 {
2837 if (ParentGroup == null) 3372 if (ParentGroup == null)
2838 return; 3373 return;
2839 3374
3375 // Update the "last" values
3376 m_lastPosition = OffsetPosition;
3377 m_lastRotation = RotationOffset;
3378 m_lastVelocity = Velocity;
3379 m_lastAcceleration = Acceleration;
3380 m_lastAngularVelocity = AngularVelocity;
3381 m_lastUpdateSentTime = Environment.TickCount;
3382
2840 ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) 3383 ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
2841 { 3384 {
2842 SendFullUpdate(avatar.ControllingClient); 3385 SendFullUpdate(avatar.ControllingClient);
2843 }); 3386 });
2844 } 3387 }
2845 3388
3389 public void SendFullUpdateToAllClients()
3390 {
3391 if (ParentGroup == null)
3392 return;
3393
3394 // Update the "last" values
3395 m_lastPosition = OffsetPosition;
3396 m_lastRotation = RotationOffset;
3397 m_lastVelocity = Velocity;
3398 m_lastAcceleration = Acceleration;
3399 m_lastAngularVelocity = AngularVelocity;
3400 m_lastUpdateSentTime = Environment.TickCount;
3401
3402 if (ParentGroup.IsAttachment)
3403 {
3404 ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
3405 if (sp != null)
3406 {
3407 sp.SendAttachmentUpdate(this, UpdateRequired.FULL);
3408 }
3409 }
3410 else
3411 {
3412 ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
3413 {
3414 SendFullUpdate(avatar.ControllingClient);
3415 });
3416 }
3417 }
3418
2846 /// <summary> 3419 /// <summary>
2847 /// Sends a full update to the client 3420 /// Sends a full update to the client
2848 /// </summary> 3421 /// </summary>
@@ -2863,9 +3436,9 @@ namespace OpenSim.Region.Framework.Scenes
2863 return; 3436 return;
2864 3437
2865 // Suppress full updates during attachment editing 3438 // Suppress full updates during attachment editing
2866 // 3439 // sl Does send them
2867 if (ParentGroup.IsSelected && ParentGroup.IsAttachment) 3440 // if (ParentGroup.IsSelected && ParentGroup.IsAttachment)
2868 return; 3441 // return;
2869 3442
2870 if (ParentGroup.IsDeleted) 3443 if (ParentGroup.IsDeleted)
2871 return; 3444 return;
@@ -2895,8 +3468,8 @@ namespace OpenSim.Region.Framework.Scenes
2895 { 3468 {
2896 const float ROTATION_TOLERANCE = 0.01f; 3469 const float ROTATION_TOLERANCE = 0.01f;
2897 const float VELOCITY_TOLERANCE = 0.001f; 3470 const float VELOCITY_TOLERANCE = 0.001f;
2898 const float POSITION_TOLERANCE = 0.05f; 3471 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2899 const int TIME_MS_TOLERANCE = 3000; 3472 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2900 3473
2901 switch (UpdateFlag) 3474 switch (UpdateFlag)
2902 { 3475 {
@@ -2910,40 +3483,74 @@ namespace OpenSim.Region.Framework.Scenes
2910 Velocity.ApproxEquals(Vector3.Zero, VELOCITY_TOLERANCE) || 3483 Velocity.ApproxEquals(Vector3.Zero, VELOCITY_TOLERANCE) ||
2911 !AngularVelocity.ApproxEquals(m_lastAngularVelocity, VELOCITY_TOLERANCE) || 3484 !AngularVelocity.ApproxEquals(m_lastAngularVelocity, VELOCITY_TOLERANCE) ||
2912 !OffsetPosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 3485 !OffsetPosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
2913 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 3486 Environment.TickCount - m_lastUpdateSentTime > TIME_MS_TOLERANCE)
2914 { 3487 {
2915 SendTerseUpdateToAllClients(); 3488 SendTerseUpdateToAllClientsInternal();
2916
2917 // Update the "last" values
2918 m_lastPosition = OffsetPosition;
2919 m_lastRotation = RotationOffset;
2920 m_lastVelocity = Velocity;
2921 m_lastAcceleration = Acceleration;
2922 m_lastAngularVelocity = AngularVelocity;
2923 m_lastTerseSent = Environment.TickCount;
2924 } 3489 }
2925 break; 3490 break;
2926 } 3491 }
2927 case UpdateRequired.FULL: 3492 case UpdateRequired.FULL:
2928 { 3493 {
2929 ClearUpdateSchedule(); 3494 ClearUpdateSchedule();
2930 SendFullUpdateToAllClients(); 3495 SendFullUpdateToAllClientsInternal();
2931 break; 3496 break;
2932 } 3497 }
2933 } 3498 }
2934 } 3499 }
2935 3500
3501
2936 /// <summary> 3502 /// <summary>
2937 /// Send a terse update to all clients 3503 /// Send a terse update to all clients
2938 /// </summary> 3504 /// </summary>
2939 public void SendTerseUpdateToAllClients() 3505 public void SendTerseUpdateToAllClientsInternal()
2940 { 3506 {
3507 if (ParentGroup == null || ParentGroup.Scene == null)
3508 return;
3509
3510 // Update the "last" values
3511 m_lastPosition = OffsetPosition;
3512 m_lastRotation = RotationOffset;
3513 m_lastVelocity = Velocity;
3514 m_lastAcceleration = Acceleration;
3515 m_lastAngularVelocity = AngularVelocity;
3516 m_lastUpdateSentTime = Environment.TickCount;
3517
2941 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client) 3518 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
2942 { 3519 {
2943 SendTerseUpdateToClient(client); 3520 SendTerseUpdateToClient(client);
2944 }); 3521 });
2945 } 3522 }
2946 3523
3524 public void SendTerseUpdateToAllClients()
3525 {
3526 if (ParentGroup == null || ParentGroup.Scene == null)
3527 return;
3528
3529 // Update the "last" values
3530 m_lastPosition = OffsetPosition;
3531 m_lastRotation = RotationOffset;
3532 m_lastVelocity = Velocity;
3533 m_lastAcceleration = Acceleration;
3534 m_lastAngularVelocity = AngularVelocity;
3535 m_lastUpdateSentTime = Environment.TickCount;
3536
3537 if (ParentGroup.IsAttachment)
3538 {
3539 ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
3540 if (sp != null)
3541 {
3542 sp.SendAttachmentUpdate(this, UpdateRequired.TERSE);
3543 }
3544 }
3545 else
3546 {
3547 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
3548 {
3549 SendTerseUpdateToClient(client);
3550 });
3551 }
3552 }
3553
2947 public void SetAxisRotation(int axis, int rotate) 3554 public void SetAxisRotation(int axis, int rotate)
2948 { 3555 {
2949 ParentGroup.SetAxisRotation(axis, rotate); 3556 ParentGroup.SetAxisRotation(axis, rotate);
@@ -2961,10 +3568,13 @@ namespace OpenSim.Region.Framework.Scenes
2961 3568
2962 public void SetBuoyancy(float fvalue) 3569 public void SetBuoyancy(float fvalue)
2963 { 3570 {
2964 PhysicsActor pa = PhysActor; 3571 Buoyancy = fvalue;
2965 3572/*
2966 if (pa != null) 3573 if (PhysActor != null)
2967 pa.Buoyancy = fvalue; 3574 {
3575 PhysActor.Buoyancy = fvalue;
3576 }
3577 */
2968 } 3578 }
2969 3579
2970 public void SetDieAtEdge(bool p) 3580 public void SetDieAtEdge(bool p)
@@ -2980,47 +3590,111 @@ namespace OpenSim.Region.Framework.Scenes
2980 PhysicsActor pa = PhysActor; 3590 PhysicsActor pa = PhysActor;
2981 3591
2982 if (pa != null) 3592 if (pa != null)
2983 pa.FloatOnWater = floatYN == 1; 3593 pa.FloatOnWater = (floatYN == 1);
2984 } 3594 }
2985 3595
2986 public void SetForce(Vector3 force) 3596 public void SetForce(Vector3 force)
2987 { 3597 {
2988 PhysicsActor pa = PhysActor; 3598 Force = force;
3599 }
2989 3600
2990 if (pa != null) 3601 public SOPVehicle VehicleParams
2991 pa.Force = force; 3602 {
3603 get
3604 {
3605 return m_vehicleParams;
3606 }
3607 set
3608 {
3609 m_vehicleParams = value;
3610 }
3611 }
3612
3613
3614 public int VehicleType
3615 {
3616 get
3617 {
3618 if (m_vehicleParams == null)
3619 return (int)Vehicle.TYPE_NONE;
3620 else
3621 return (int)m_vehicleParams.Type;
3622 }
3623 set
3624 {
3625 SetVehicleType(value);
3626 }
2992 } 3627 }
2993 3628
2994 public void SetVehicleType(int type) 3629 public void SetVehicleType(int type)
2995 { 3630 {
2996 PhysicsActor pa = PhysActor; 3631 m_vehicleParams = null;
3632
3633 if (type == (int)Vehicle.TYPE_NONE)
3634 {
3635 if (_parentID ==0 && PhysActor != null)
3636 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3637 return;
3638 }
3639 m_vehicleParams = new SOPVehicle();
3640 m_vehicleParams.ProcessTypeChange((Vehicle)type);
3641 {
3642 if (_parentID ==0 && PhysActor != null)
3643 PhysActor.VehicleType = type;
3644 return;
3645 }
3646 }
2997 3647
2998 if (pa != null) 3648 public void SetVehicleFlags(int param, bool remove)
2999 pa.VehicleType = type; 3649 {
3650 if (m_vehicleParams == null)
3651 return;
3652
3653 m_vehicleParams.ProcessVehicleFlags(param, remove);
3654
3655 if (_parentID ==0 && PhysActor != null)
3656 {
3657 PhysActor.VehicleFlags(param, remove);
3658 }
3000 } 3659 }
3001 3660
3002 public void SetVehicleFloatParam(int param, float value) 3661 public void SetVehicleFloatParam(int param, float value)
3003 { 3662 {
3004 PhysicsActor pa = PhysActor; 3663 if (m_vehicleParams == null)
3664 return;
3005 3665
3006 if (pa != null) 3666 m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
3007 pa.VehicleFloatParam(param, value); 3667
3668 if (_parentID == 0 && PhysActor != null)
3669 {
3670 PhysActor.VehicleFloatParam(param, value);
3671 }
3008 } 3672 }
3009 3673
3010 public void SetVehicleVectorParam(int param, Vector3 value) 3674 public void SetVehicleVectorParam(int param, Vector3 value)
3011 { 3675 {
3012 PhysicsActor pa = PhysActor; 3676 if (m_vehicleParams == null)
3677 return;
3013 3678
3014 if (pa != null) 3679 m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
3015 pa.VehicleVectorParam(param, value); 3680
3681 if (_parentID == 0 && PhysActor != null)
3682 {
3683 PhysActor.VehicleVectorParam(param, value);
3684 }
3016 } 3685 }
3017 3686
3018 public void SetVehicleRotationParam(int param, Quaternion rotation) 3687 public void SetVehicleRotationParam(int param, Quaternion rotation)
3019 { 3688 {
3020 PhysicsActor pa = PhysActor; 3689 if (m_vehicleParams == null)
3690 return;
3021 3691
3022 if (pa != null) 3692 m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
3023 pa.VehicleRotationParam(param, rotation); 3693
3694 if (_parentID == 0 && PhysActor != null)
3695 {
3696 PhysActor.VehicleRotationParam(param, rotation);
3697 }
3024 } 3698 }
3025 3699
3026 /// <summary> 3700 /// <summary>
@@ -3221,14 +3895,6 @@ namespace OpenSim.Region.Framework.Scenes
3221 hasProfileCut = hasDimple; // is it the same thing? 3895 hasProfileCut = hasDimple; // is it the same thing?
3222 } 3896 }
3223 3897
3224 public void SetVehicleFlags(int param, bool remove)
3225 {
3226 PhysicsActor pa = PhysActor;
3227
3228 if (pa != null)
3229 pa.VehicleFlags(param, remove);
3230 }
3231
3232 public void SetGroup(UUID groupID, IClientAPI client) 3898 public void SetGroup(UUID groupID, IClientAPI client)
3233 { 3899 {
3234 // Scene.AddNewPrims() calls with client == null so can't use this. 3900 // Scene.AddNewPrims() calls with client == null so can't use this.
@@ -3237,8 +3903,8 @@ namespace OpenSim.Region.Framework.Scenes
3237// Name, groupID, OwnerID); 3903// Name, groupID, OwnerID);
3238 3904
3239 GroupID = groupID; 3905 GroupID = groupID;
3240 if (client != null) 3906// if (client != null)
3241 SendPropertiesToClient(client); 3907// SendPropertiesToClient(client);
3242 UpdateFlag = UpdateRequired.FULL; 3908 UpdateFlag = UpdateRequired.FULL;
3243 } 3909 }
3244 3910
@@ -3330,70 +3996,26 @@ namespace OpenSim.Region.Framework.Scenes
3330 3996
3331 public void StopMoveToTarget() 3997 public void StopMoveToTarget()
3332 { 3998 {
3999<<<<<<< HEAD
3333 ParentGroup.StopMoveToTarget(); 4000 ParentGroup.StopMoveToTarget();
3334 } 4001=======
4002 ParentGroup.stopMoveToTarget();
3335 4003
3336 public void StoreUndoState() 4004// ParentGroup.ScheduleGroupForTerseUpdate();
3337 { 4005 //ParentGroup.ScheduleGroupForFullUpdate();
3338 StoreUndoState(false); 4006>>>>>>> avn/ubitvar
3339 } 4007 }
3340 4008
3341 public void StoreUndoState(bool forGroup) 4009 public void StoreUndoState(ObjectChangeType change)
3342 { 4010 {
3343 if (ParentGroup == null || ParentGroup.Scene == null) 4011 if (m_UndoRedo == null)
3344 return; 4012 m_UndoRedo = new UndoRedoState(5);
3345
3346 if (Undoing)
3347 {
3348// m_log.DebugFormat(
3349// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3350 return;
3351 }
3352 4013
3353 if (IgnoreUndoUpdate) 4014 lock (m_UndoRedo)
3354 { 4015 {
3355// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId); 4016 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3356 return;
3357 }
3358
3359 lock (m_undo)
3360 {
3361 if (m_undo.Count > 0)
3362 {
3363 UndoState last = m_undo[m_undo.Count - 1];
3364 if (last != null)
3365 {
3366 // TODO: May need to fix for group comparison
3367 if (last.Compare(this))
3368 {
3369// m_log.DebugFormat(
3370// "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3371// Name, LocalId, m_undo.Count);
3372
3373 return;
3374 }
3375 }
3376 }
3377
3378// m_log.DebugFormat(
3379// "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3380// Name, LocalId, forGroup, m_undo.Count);
3381
3382 if (ParentGroup.Scene.MaxUndoCount > 0)
3383 { 4017 {
3384 UndoState nUndo = new UndoState(this, forGroup); 4018 m_UndoRedo.StoreUndo(this, change);
3385
3386 m_undo.Add(nUndo);
3387
3388 if (m_undo.Count > ParentGroup.Scene.MaxUndoCount)
3389 m_undo.RemoveAt(0);
3390
3391 if (m_redo.Count > 0)
3392 m_redo.Clear();
3393
3394// m_log.DebugFormat(
3395// "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3396// Name, LocalId, forGroup, m_undo.Count);
3397 } 4019 }
3398 } 4020 }
3399 } 4021 }
@@ -3405,88 +4027,46 @@ namespace OpenSim.Region.Framework.Scenes
3405 { 4027 {
3406 get 4028 get
3407 { 4029 {
3408 lock (m_undo) 4030 if (m_UndoRedo == null)
3409 return m_undo.Count; 4031 return 0;
4032 return m_UndoRedo.Count;
3410 } 4033 }
3411 } 4034 }
3412 4035
3413 public void Undo() 4036 public void Undo()
3414 { 4037 {
3415 lock (m_undo) 4038 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3416 { 4039 return;
3417// m_log.DebugFormat(
3418// "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
3419// Name, LocalId, m_undo.Count);
3420
3421 if (m_undo.Count > 0)
3422 {
3423 UndoState goback = m_undo[m_undo.Count - 1];
3424 m_undo.RemoveAt(m_undo.Count - 1);
3425
3426 UndoState nUndo = null;
3427
3428 if (ParentGroup.Scene.MaxUndoCount > 0)
3429 {
3430 nUndo = new UndoState(this, goback.ForGroup);
3431 }
3432
3433 goback.PlaybackState(this);
3434
3435 if (nUndo != null)
3436 {
3437 m_redo.Add(nUndo);
3438
3439 if (m_redo.Count > ParentGroup.Scene.MaxUndoCount)
3440 m_redo.RemoveAt(0);
3441 }
3442 }
3443 4040
3444// m_log.DebugFormat( 4041 lock (m_UndoRedo)
3445// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 4042 {
3446// Name, LocalId, m_undo.Count); 4043 Undoing = true;
4044 m_UndoRedo.Undo(this);
4045 Undoing = false;
3447 } 4046 }
3448 } 4047 }
3449 4048
3450 public void Redo() 4049 public void Redo()
3451 { 4050 {
3452 lock (m_undo) 4051 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3453 { 4052 return;
3454// m_log.DebugFormat(
3455// "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
3456// Name, LocalId, m_redo.Count);
3457
3458 if (m_redo.Count > 0)
3459 {
3460 UndoState gofwd = m_redo[m_redo.Count - 1];
3461 m_redo.RemoveAt(m_redo.Count - 1);
3462
3463 if (ParentGroup.Scene.MaxUndoCount > 0)
3464 {
3465 UndoState nUndo = new UndoState(this, gofwd.ForGroup);
3466
3467 m_undo.Add(nUndo);
3468
3469 if (m_undo.Count > ParentGroup.Scene.MaxUndoCount)
3470 m_undo.RemoveAt(0);
3471 }
3472
3473 gofwd.PlayfwdState(this);
3474 4053
3475// m_log.DebugFormat( 4054 lock (m_UndoRedo)
3476// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 4055 {
3477// Name, LocalId, m_redo.Count); 4056 Undoing = true;
3478 } 4057 m_UndoRedo.Redo(this);
4058 Undoing = false;
3479 } 4059 }
3480 } 4060 }
3481 4061
3482 public void ClearUndoState() 4062 public void ClearUndoState()
3483 { 4063 {
3484// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 4064 if (m_UndoRedo == null || Undoing)
4065 return;
3485 4066
3486 lock (m_undo) 4067 lock (m_UndoRedo)
3487 { 4068 {
3488 m_undo.Clear(); 4069 m_UndoRedo.Clear();
3489 m_redo.Clear();
3490 } 4070 }
3491 } 4071 }
3492 4072
@@ -4038,7 +4618,7 @@ namespace OpenSim.Region.Framework.Scenes
4038 if (god) 4618 if (god)
4039 { 4619 {
4040 BaseMask = ApplyMask(BaseMask, set, mask); 4620 BaseMask = ApplyMask(BaseMask, set, mask);
4041 Inventory.ApplyGodPermissions(_baseMask); 4621 Inventory.ApplyGodPermissions(BaseMask);
4042 } 4622 }
4043 4623
4044 break; 4624 break;
@@ -4069,7 +4649,7 @@ namespace OpenSim.Region.Framework.Scenes
4069 } 4649 }
4070 NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) & 4650 NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) &
4071 baseMask; 4651 baseMask;
4072 // Prevent the client from creating no mod, no copy 4652 // Prevent the client from creating no copy, no transfer
4073 // objects 4653 // objects
4074 if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0) 4654 if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0)
4075 NextOwnerMask |= (uint)PermissionMask.Transfer; 4655 NextOwnerMask |= (uint)PermissionMask.Transfer;
@@ -4087,20 +4667,20 @@ namespace OpenSim.Region.Framework.Scenes
4087 { 4667 {
4088 bool update = false; 4668 bool update = false;
4089 4669
4090 if (BaseMask != source.BaseMask || 4670 uint prevOwnerMask = OwnerMask;
4091 OwnerMask != source.OwnerMask || 4671 uint prevGroupMask = GroupMask;
4092 GroupMask != source.GroupMask || 4672 uint prevEveryoneMask = EveryoneMask;
4093 EveryoneMask != source.EveryoneMask || 4673 uint prevNextOwnerMask = NextOwnerMask;
4094 NextOwnerMask != source.NextOwnerMask)
4095 update = true;
4096 4674
4097 BaseMask = source.BaseMask; 4675 OwnerMask = source.OwnerMask & BaseMask;
4098 OwnerMask = source.OwnerMask; 4676 GroupMask = source.GroupMask & BaseMask;
4099 GroupMask = source.GroupMask; 4677 EveryoneMask = source.EveryoneMask & BaseMask;
4100 EveryoneMask = source.EveryoneMask; 4678 NextOwnerMask = source.NextOwnerMask & BaseMask;
4101 NextOwnerMask = source.NextOwnerMask;
4102 4679
4103 if (update) 4680 if (OwnerMask != prevOwnerMask ||
4681 GroupMask != prevGroupMask ||
4682 EveryoneMask != prevEveryoneMask ||
4683 NextOwnerMask != prevNextOwnerMask)
4104 SendFullUpdateToAllClients(); 4684 SendFullUpdateToAllClients();
4105 } 4685 }
4106 4686
@@ -4151,6 +4731,7 @@ namespace OpenSim.Region.Framework.Scenes
4151 } 4731 }
4152 } 4732 }
4153 4733
4734
4154 public void UpdateExtraPhysics(ExtraPhysicsData physdata) 4735 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4155 { 4736 {
4156 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null) 4737 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
@@ -4178,7 +4759,7 @@ namespace OpenSim.Region.Framework.Scenes
4178 /// <param name="SetTemporary"></param> 4759 /// <param name="SetTemporary"></param>
4179 /// <param name="SetPhantom"></param> 4760 /// <param name="SetPhantom"></param>
4180 /// <param name="SetVD"></param> 4761 /// <param name="SetVD"></param>
4181 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4762 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
4182 { 4763 {
4183 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4764 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
4184 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4765 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -4188,99 +4769,110 @@ namespace OpenSim.Region.Framework.Scenes
4188 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4769 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
4189 return; 4770 return;
4190 4771
4191 PhysicsActor pa = PhysActor; 4772 VolumeDetectActive = SetVD;
4192
4193 // Special cases for VD. VD can only be called from a script
4194 // and can't be combined with changes to other states. So we can rely
4195 // that...
4196 // ... if VD is changed, all others are not.
4197 // ... if one of the others is changed, VD is not.
4198 if (SetVD) // VD is active, special logic applies
4199 {
4200 // State machine logic for VolumeDetect
4201 // More logic below
4202 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
4203
4204 if (phanReset) // Phantom changes from on to off switch VD off too
4205 {
4206 SetVD = false; // Switch it of for the course of this routine
4207 VolumeDetectActive = false; // and also permanently
4208 4773
4209 if (pa != null) 4774 // volume detector implies phantom
4210 pa.SetVolumeDetect(0); // Let physics know about it too 4775 if (VolumeDetectActive)
4211 }
4212 else
4213 {
4214 // If volumedetect is active we don't want phantom to be applied.
4215 // If this is a new call to VD out of the state "phantom"
4216 // this will also cause the prim to be visible to physics
4217 SetPhantom = false;
4218 }
4219 }
4220
4221 if (UsePhysics && IsJoint())
4222 {
4223 SetPhantom = true; 4776 SetPhantom = true;
4224 }
4225 4777
4226 if (UsePhysics) 4778 if (UsePhysics)
4227 {
4228 AddFlag(PrimFlags.Physics); 4779 AddFlag(PrimFlags.Physics);
4229 if (!wasUsingPhysics)
4230 {
4231 DoPhysicsPropertyUpdate(UsePhysics, false);
4232 }
4233 }
4234 else 4780 else
4235 {
4236 RemFlag(PrimFlags.Physics); 4781 RemFlag(PrimFlags.Physics);
4237 if (wasUsingPhysics)
4238 {
4239 DoPhysicsPropertyUpdate(UsePhysics, false);
4240 }
4241 }
4242 4782
4243 if (SetPhantom 4783 if (SetPhantom)
4244 || ParentGroup.IsAttachment
4245 || PhysicsShapeType == (byte)PhysShapeType.none
4246 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
4247 {
4248 AddFlag(PrimFlags.Phantom); 4784 AddFlag(PrimFlags.Phantom);
4785 else
4786 RemFlag(PrimFlags.Phantom);
4249 4787
4250 if (PhysActor != null) 4788 if (SetTemporary)
4789 AddFlag(PrimFlags.TemporaryOnRez);
4790 else
4791 RemFlag(PrimFlags.TemporaryOnRez);
4792
4793
4794 if (ParentGroup.Scene == null)
4795 return;
4796
4797 PhysicsActor pa = PhysActor;
4798
4799 if (pa != null && building && pa.Building != building)
4800 pa.Building = building;
4801
4802 if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
4803 || (Shape.PathCurve == (byte)Extrusion.Flexible))
4804 {
4805 if (pa != null)
4251 { 4806 {
4807 if(wasUsingPhysics)
4808 ParentGroup.Scene.RemovePhysicalPrim(1);
4252 RemoveFromPhysics(); 4809 RemoveFromPhysics();
4253 pa = null;
4254 } 4810 }
4811
4812 Velocity = new Vector3(0, 0, 0);
4813 Acceleration = new Vector3(0, 0, 0);
4814 if (ParentGroup.RootPart == this)
4815 AngularVelocity = new Vector3(0, 0, 0);
4255 } 4816 }
4256 else // Not phantom 4817
4818 else
4257 { 4819 {
4258 RemFlag(PrimFlags.Phantom); 4820 if (ParentGroup.Scene.CollidablePrims)
4259
4260 if (ParentGroup.Scene == null)
4261 return;
4262
4263 if (ParentGroup.Scene.CollidablePrims && pa == null)
4264 { 4821 {
4265 AddToPhysics(UsePhysics, SetPhantom, false); 4822 if (pa == null)
4266 pa = PhysActor; 4823 {
4267 4824 AddToPhysics(UsePhysics, SetPhantom, building, false);
4268 if (pa != null) 4825 pa = PhysActor;
4826/*
4827 if (pa != null)
4828 {
4829 if (
4830// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4831// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4832// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4833// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4834// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4835// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4836 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4837 ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4838 (CollisionSound != UUID.Zero)
4839 )
4840 {
4841 pa.OnCollisionUpdate += PhysicsCollision;
4842 pa.SubscribeEvents(1000);
4843 }
4844 }
4845*/
4846 if (pa != null)
4847 {
4848 pa.SetMaterial(Material);
4849 DoPhysicsPropertyUpdate(UsePhysics, true);
4850 }
4851 }
4852 else // it already has a physical representation
4269 { 4853 {
4854<<<<<<< HEAD
4270 pa.SetMaterial(Material); 4855 pa.SetMaterial(Material);
4271 pa.Position = GetWorldPosition(); 4856 pa.Position = GetWorldPosition();
4272 pa.Orientation = GetWorldRotation(); 4857 pa.Orientation = GetWorldRotation();
4273 DoPhysicsPropertyUpdate(UsePhysics, true); 4858 DoPhysicsPropertyUpdate(UsePhysics, true);
4859=======
4860 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4861/* moved into DoPhysicsPropertyUpdate
4862 if(VolumeDetectActive)
4863 pa.SetVolumeDetect(1);
4864 else
4865 pa.SetVolumeDetect(0);
4866*/
4867>>>>>>> avn/ubitvar
4274 4868
4275 SubscribeForCollisionEvents(); 4869 if (pa.Building != building)
4870 pa.Building = building;
4276 } 4871 }
4277 }
4278 else // it already has a physical representation
4279 {
4280 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
4281 }
4282 }
4283 4872
4873 UpdatePhysicsSubscribedEvents();
4874 }
4875 }
4284 if (SetVD) 4876 if (SetVD)
4285 { 4877 {
4286 // If the above logic worked (this is urgent candidate to unit tests!) 4878 // If the above logic worked (this is urgent candidate to unit tests!)
@@ -4294,6 +4886,7 @@ namespace OpenSim.Region.Framework.Scenes
4294 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active 4886 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
4295 VolumeDetectActive = true; 4887 VolumeDetectActive = true;
4296 } 4888 }
4889 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4297 } 4890 }
4298 else if (SetVD != wasVD) 4891 else if (SetVD != wasVD)
4299 { 4892 {
@@ -4305,105 +4898,51 @@ namespace OpenSim.Region.Framework.Scenes
4305 RemFlag(PrimFlags.Phantom); 4898 RemFlag(PrimFlags.Phantom);
4306 VolumeDetectActive = false; 4899 VolumeDetectActive = false;
4307 } 4900 }
4308 4901 // and last in case we have a new actor and not building
4309 if (SetTemporary)
4310 {
4311 AddFlag(PrimFlags.TemporaryOnRez);
4312 }
4313 else
4314 {
4315 RemFlag(PrimFlags.TemporaryOnRez);
4316 }
4317
4318 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4319 4902
4320 if (ParentGroup != null) 4903 if (ParentGroup != null)
4321 { 4904 {
4322 ParentGroup.HasGroupChanged = true; 4905 ParentGroup.HasGroupChanged = true;
4323 ScheduleFullUpdate(); 4906 ScheduleFullUpdate();
4324 } 4907 }
4325 4908
4326// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); 4909// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
4327 } 4910 }
4328 4911
4329 /// <summary> 4912 /// <summary>
4330 /// Subscribe for physics collision events if needed for scripts and sounds
4331 /// </summary>
4332 public void SubscribeForCollisionEvents()
4333 {
4334 PhysicsActor pa = PhysActor;
4335
4336 if (pa != null)
4337 {
4338 if (
4339 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4340 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4341 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4342 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4343 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4344 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4345 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
4346 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4347 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4348 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4349 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4350 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4351 (CollisionSound != UUID.Zero)
4352 )
4353 {
4354 if (!pa.SubscribedEvents())
4355 {
4356 // If not already subscribed for event, set up for a collision event.
4357 pa.OnCollisionUpdate += PhysicsCollision;
4358 pa.SubscribeEvents(1000);
4359 }
4360 }
4361 else
4362 {
4363 // There is no need to be subscribed to collisions so, if subscribed, remove subscription
4364 if (pa.SubscribedEvents())
4365 {
4366 pa.OnCollisionUpdate -= PhysicsCollision;
4367 pa.UnSubscribeEvents();
4368 }
4369 }
4370 }
4371 }
4372
4373 /// <summary>
4374 /// Adds this part to the physics scene. 4913 /// Adds this part to the physics scene.
4914 /// and sets the PhysActor property
4375 /// </summary> 4915 /// </summary>
4376 /// <remarks>This method also sets the PhysActor property.</remarks> 4916 /// <param name="isPhysical">Add this prim as physical.</param>
4377 /// <param name="rigidBody">Add this prim with a rigid body.</param> 4917 /// <param name="isPhantom">Add this prim as phantom.</param>
4378 /// <returns> 4918 /// <param name="building">tells physics to delay full construction of object</param>
4379 /// The physics actor. null if there was a failure. 4919 /// <param name="applyDynamics">applies velocities, force and torque</param>
4380 /// </returns> 4920 private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
4381 private void AddToPhysics(bool isPhysical, bool isPhantom, bool applyDynamics) 4921 {
4382 {
4383 PhysicsActor pa; 4922 PhysicsActor pa;
4384 4923
4385 Vector3 velocity = Velocity; 4924 Vector3 velocity = Velocity;
4386 Vector3 rotationalVelocity = AngularVelocity;; 4925 Vector3 rotationalVelocity = AngularVelocity;;
4387 4926
4388 try 4927 try
4389 { 4928 {
4390 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape( 4929 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4391 string.Format("{0}/{1}", Name, UUID), 4930 string.Format("{0}/{1}", Name, UUID),
4392 Shape, 4931 Shape,
4393 AbsolutePosition, 4932 AbsolutePosition,
4394 Scale, 4933 Scale,
4395 GetWorldRotation(), 4934 GetWorldRotation(),
4396 isPhysical, 4935 isPhysical,
4397 isPhantom, 4936 isPhantom,
4398 PhysicsShapeType, 4937 PhysicsShapeType,
4399 m_localId); 4938 m_localId);
4400 } 4939 }
4401 catch (Exception e) 4940 catch (Exception e)
4402 { 4941 {
4403 m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom. e={1}", m_uuid, e); 4942 m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom. e={1}", m_uuid, e);
4404 pa = null; 4943 pa = null;
4405 } 4944 }
4406 4945
4407 if (pa != null) 4946 if (pa != null)
4408 { 4947 {
4409 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 4948 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
@@ -4416,9 +4955,16 @@ namespace OpenSim.Region.Framework.Scenes
4416 4955
4417 if (VolumeDetectActive) // change if not the default only 4956 if (VolumeDetectActive) // change if not the default only
4418 pa.SetVolumeDetect(1); 4957 pa.SetVolumeDetect(1);
4958
4959 if (m_vehicleParams != null && LocalId == ParentGroup.RootPart.LocalId)
4960 m_vehicleParams.SetVehicle(pa);
4961
4419 // we are going to tell rest of code about physics so better have this here 4962 // we are going to tell rest of code about physics so better have this here
4420 PhysActor = pa; 4963 PhysActor = pa;
4421 4964
4965 // DoPhysicsPropertyUpdate(isPhysical, true);
4966 // lets expand it here just with what it really needs to do
4967
4422 if (isPhysical) 4968 if (isPhysical)
4423 { 4969 {
4424 if (ParentGroup.RootPart.KeyframeMotion != null) 4970 if (ParentGroup.RootPart.KeyframeMotion != null)
@@ -4440,19 +4986,34 @@ namespace OpenSim.Region.Framework.Scenes
4440 } 4986 }
4441 } 4987 }
4442 4988
4443 if (applyDynamics) 4989 if (applyDynamics)
4444 // do independent of isphysical so parameters get setted (at least some) 4990 // do independent of isphysical so parameters get setted (at least some)
4445 { 4991 {
4446 Velocity = velocity; 4992 Velocity = velocity;
4447 AngularVelocity = rotationalVelocity; 4993 AngularVelocity = rotationalVelocity;
4448// pa.Velocity = velocity; 4994// pa.Velocity = velocity;
4449 pa.RotationalVelocity = rotationalVelocity; 4995 pa.RotationalVelocity = rotationalVelocity;
4996
4997 // if not vehicle and root part apply force and torque
4998 if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE)
4999 && LocalId == ParentGroup.RootPart.LocalId)
5000 {
5001 pa.Force = Force;
5002 pa.Torque = Torque;
5003 }
4450 } 5004 }
4451 5005
4452 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa); 5006// if (Shape.SculptEntry)
5007// CheckSculptAndLoad();
5008// else
5009 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
5010
5011 if (!building)
5012 pa.Building = false;
4453 } 5013 }
4454 5014
4455 PhysActor = pa; 5015 PhysActor = pa;
5016
4456 ParentGroup.Scene.EventManager.TriggerObjectAddedToPhysicalScene(this); 5017 ParentGroup.Scene.EventManager.TriggerObjectAddedToPhysicalScene(this);
4457 } 5018 }
4458 5019
@@ -4461,14 +5022,21 @@ namespace OpenSim.Region.Framework.Scenes
4461 /// </summary> 5022 /// </summary>
4462 /// <remarks> 5023 /// <remarks>
4463 /// This isn't the same as turning off physical, since even without being physical the prim has a physics 5024 /// This isn't the same as turning off physical, since even without being physical the prim has a physics
4464 /// representation for collision detection. Rather, this would be used in situations such as making a prim 5025 /// representation for collision detection.
4465 /// phantom.
4466 /// </remarks> 5026 /// </remarks>
4467 public void RemoveFromPhysics() 5027 public void RemoveFromPhysics()
4468 { 5028 {
4469 ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this); 5029 PhysicsActor pa = PhysActor;
4470 if (ParentGroup.Scene.PhysicsScene != null) 5030 if (pa != null)
4471 ParentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 5031 {
5032 pa.OnCollisionUpdate -= PhysicsCollision;
5033 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
5034 pa.OnOutOfBounds -= PhysicsOutOfBounds;
5035
5036 ParentGroup.Scene.PhysicsScene.RemovePrim(pa);
5037
5038 ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this);
5039 }
4472 PhysActor = null; 5040 PhysActor = null;
4473 } 5041 }
4474 5042
@@ -4600,6 +5168,8 @@ namespace OpenSim.Region.Framework.Scenes
4600 { 5168 {
4601// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId); 5169// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
4602 5170
5171 return;
5172
4603 if (ParentGroup.IsDeleted) 5173 if (ParentGroup.IsDeleted)
4604 return; 5174 return;
4605 5175
@@ -4723,6 +5293,44 @@ namespace OpenSim.Region.Framework.Scenes
4723 } 5293 }
4724 } 5294 }
4725 5295
5296
5297 private void UpdatePhysicsSubscribedEvents()
5298 {
5299 PhysicsActor pa = PhysActor;
5300 if (pa == null)
5301 return;
5302
5303 pa.OnCollisionUpdate -= PhysicsCollision;
5304
5305 bool hassound = (!VolumeDetectActive && CollisionSoundType >= 0 && ((Flags & PrimFlags.Physics) != 0));
5306
5307 scriptEvents CombinedEvents = AggregateScriptEvents;
5308
5309 // merge with root part
5310 if (ParentGroup != null && ParentGroup.RootPart != null)
5311 CombinedEvents |= ParentGroup.RootPart.AggregateScriptEvents;
5312
5313 // submit to this part case
5314 if (VolumeDetectActive)
5315 CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
5316 else if ((Flags & PrimFlags.Phantom) != 0)
5317 CombinedEvents &= PhyscicsPhantonSubsEvents;
5318 else
5319 CombinedEvents &= PhysicsNeededSubsEvents;
5320
5321 if (hassound || CombinedEvents != 0)
5322 {
5323 // subscribe to physics updates.
5324 pa.OnCollisionUpdate += PhysicsCollision;
5325 pa.SubscribeEvents(50); // 20 reports per second
5326 }
5327 else
5328 {
5329 pa.UnSubscribeEvents();
5330 }
5331 }
5332
5333
4726 public void aggregateScriptEvents() 5334 public void aggregateScriptEvents()
4727 { 5335 {
4728 if (ParentGroup == null || ParentGroup.RootPart == null) 5336 if (ParentGroup == null || ParentGroup.RootPart == null)
@@ -4759,8 +5367,32 @@ namespace OpenSim.Region.Framework.Scenes
4759 { 5367 {
4760 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; 5368 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
4761 } 5369 }
4762 5370/*
4763 SubscribeForCollisionEvents(); 5371 PhysicsActor pa = PhysActor;
5372 if (pa != null)
5373 {
5374 if (
5375// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
5376// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
5377// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
5378// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
5379// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
5380// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
5381 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero)
5382 )
5383 {
5384 // subscribe to physics updates.
5385 pa.OnCollisionUpdate += PhysicsCollision;
5386 pa.SubscribeEvents(1000);
5387 }
5388 else
5389 {
5390 pa.UnSubscribeEvents();
5391 pa.OnCollisionUpdate -= PhysicsCollision;
5392 }
5393 }
5394 */
5395 UpdatePhysicsSubscribedEvents();
4764 5396
4765 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) 5397 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
4766 //{ 5398 //{
@@ -4969,6 +5601,18 @@ namespace OpenSim.Region.Framework.Scenes
4969 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5601 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4970 } 5602 }
4971 5603
5604 public void ResetOwnerChangeFlag()
5605 {
5606 List<UUID> inv = Inventory.GetInventoryList();
5607
5608 foreach (UUID itemID in inv)
5609 {
5610 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5611 item.OwnerChanged = false;
5612 Inventory.UpdateInventoryItem(item, false, false);
5613 }
5614 }
5615
4972 /// <summary> 5616 /// <summary>
4973 /// Record an avatar sitting on this part. 5617 /// Record an avatar sitting on this part.
4974 /// </summary> 5618 /// </summary>
@@ -5062,4 +5706,4 @@ namespace OpenSim.Region.Framework.Scenes
5062 } 5706 }
5063 } 5707 }
5064 } 5708 }
5065} \ No newline at end of file 5709}
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index ec39726..7af0b20 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -46,9 +46,12 @@ namespace OpenSim.Region.Framework.Scenes
46 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 private string m_inventoryFileName = String.Empty;
50 private byte[] m_inventoryFileData = new byte[0]; 49 private byte[] m_inventoryFileData = new byte[0];
51 private uint m_inventoryFileNameSerial = 0; 50 private uint m_inventoryFileNameSerial = 0;
51 private bool m_inventoryPrivileged = false;
52 private object m_inventoryFileLock = new object();
53
54 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
52 55
53 /// <value> 56 /// <value>
54 /// The part to which the inventory belongs. 57 /// The part to which the inventory belongs.
@@ -85,7 +88,9 @@ namespace OpenSim.Region.Framework.Scenes
85 /// </value> 88 /// </value>
86 protected internal TaskInventoryDictionary Items 89 protected internal TaskInventoryDictionary Items
87 { 90 {
88 get { return m_items; } 91 get {
92 return m_items;
93 }
89 set 94 set
90 { 95 {
91 m_items = value; 96 m_items = value;
@@ -134,38 +139,45 @@ namespace OpenSim.Region.Framework.Scenes
134 public void ResetInventoryIDs() 139 public void ResetInventoryIDs()
135 { 140 {
136 if (null == m_part) 141 if (null == m_part)
137 return; 142 m_items.LockItemsForWrite(true);
138 143
139 lock (m_items) 144 if (Items.Count == 0)
140 { 145 {
141 if (0 == m_items.Count) 146 m_items.LockItemsForWrite(false);
142 return; 147 return;
148 }
143 149
144 IList<TaskInventoryItem> items = GetInventoryItems(); 150 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
145 m_items.Clear(); 151 Items.Clear();
146 152
147 foreach (TaskInventoryItem item in items) 153 foreach (TaskInventoryItem item in items)
148 { 154 {
149 item.ResetIDs(m_part.UUID); 155 item.ResetIDs(m_part.UUID);
150 m_items.Add(item.ItemID, item); 156 Items.Add(item.ItemID, item);
151 }
152 } 157 }
158 m_items.LockItemsForWrite(false);
153 } 159 }
154 160
155 public void ResetObjectID() 161 public void ResetObjectID()
156 { 162 {
157 lock (Items) 163 m_items.LockItemsForWrite(true);
164
165 if (Items.Count == 0)
158 { 166 {
159 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 167 m_items.LockItemsForWrite(false);
160 Items.Clear(); 168 return;
161
162 foreach (TaskInventoryItem item in items)
163 {
164 item.ParentPartID = m_part.UUID;
165 item.ParentID = m_part.UUID;
166 Items.Add(item.ItemID, item);
167 }
168 } 169 }
170
171 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
172 Items.Clear();
173
174 foreach (TaskInventoryItem item in items)
175 {
176 item.ParentPartID = m_part.UUID;
177 item.ParentID = m_part.UUID;
178 Items.Add(item.ItemID, item);
179 }
180 m_items.LockItemsForWrite(false);
169 } 181 }
170 182
171 /// <summary> 183 /// <summary>
@@ -174,17 +186,14 @@ namespace OpenSim.Region.Framework.Scenes
174 /// <param name="ownerId"></param> 186 /// <param name="ownerId"></param>
175 public void ChangeInventoryOwner(UUID ownerId) 187 public void ChangeInventoryOwner(UUID ownerId)
176 { 188 {
177 lock (Items) 189 List<TaskInventoryItem> items = GetInventoryItems();
178 {
179 if (0 == Items.Count)
180 {
181 return;
182 }
183 }
184 190
191 if (items.Count == 0)
192 return;
193
194 m_items.LockItemsForWrite(true);
185 HasInventoryChanged = true; 195 HasInventoryChanged = true;
186 m_part.ParentGroup.HasGroupChanged = true; 196 m_part.ParentGroup.HasGroupChanged = true;
187 List<TaskInventoryItem> items = GetInventoryItems();
188 foreach (TaskInventoryItem item in items) 197 foreach (TaskInventoryItem item in items)
189 { 198 {
190 if (ownerId != item.OwnerID) 199 if (ownerId != item.OwnerID)
@@ -195,6 +204,7 @@ namespace OpenSim.Region.Framework.Scenes
195 item.PermsGranter = UUID.Zero; 204 item.PermsGranter = UUID.Zero;
196 item.OwnerChanged = true; 205 item.OwnerChanged = true;
197 } 206 }
207 m_items.LockItemsForWrite(false);
198 } 208 }
199 209
200 /// <summary> 210 /// <summary>
@@ -203,12 +213,11 @@ namespace OpenSim.Region.Framework.Scenes
203 /// <param name="groupID"></param> 213 /// <param name="groupID"></param>
204 public void ChangeInventoryGroup(UUID groupID) 214 public void ChangeInventoryGroup(UUID groupID)
205 { 215 {
206 lock (Items) 216 m_items.LockItemsForWrite(true);
217 if (0 == Items.Count)
207 { 218 {
208 if (0 == Items.Count) 219 m_items.LockItemsForWrite(false);
209 { 220 return;
210 return;
211 }
212 } 221 }
213 222
214 // Don't let this set the HasGroupChanged flag for attachments 223 // Don't let this set the HasGroupChanged flag for attachments
@@ -220,12 +229,15 @@ namespace OpenSim.Region.Framework.Scenes
220 m_part.ParentGroup.HasGroupChanged = true; 229 m_part.ParentGroup.HasGroupChanged = true;
221 } 230 }
222 231
223 List<TaskInventoryItem> items = GetInventoryItems(); 232 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
224 foreach (TaskInventoryItem item in items) 233 foreach (TaskInventoryItem item in items)
225 { 234 {
226 if (groupID != item.GroupID) 235 if (groupID != item.GroupID)
236 {
227 item.GroupID = groupID; 237 item.GroupID = groupID;
238 }
228 } 239 }
240 m_items.LockItemsForWrite(false);
229 } 241 }
230 242
231 private void QueryScriptStates() 243 private void QueryScriptStates()
@@ -233,15 +245,18 @@ namespace OpenSim.Region.Framework.Scenes
233 if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null) 245 if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null)
234 return; 246 return;
235 247
236 lock (Items) 248 Items.LockItemsForRead(true);
249 foreach (TaskInventoryItem item in Items.Values)
237 { 250 {
238 foreach (TaskInventoryItem item in Items.Values) 251 if (item.InvType == (int)InventoryType.LSL)
239 { 252 {
240 bool running; 253 bool running;
241 if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running)) 254 if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running))
242 item.ScriptRunning = running; 255 item.ScriptRunning = running;
243 } 256 }
244 } 257 }
258
259 Items.LockItemsForRead(false);
245 } 260 }
246 261
247 public bool TryGetScriptInstanceRunning(UUID itemId, out bool running) 262 public bool TryGetScriptInstanceRunning(UUID itemId, out bool running)
@@ -318,7 +333,10 @@ namespace OpenSim.Region.Framework.Scenes
318 { 333 {
319 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL); 334 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
320 foreach (TaskInventoryItem item in scripts) 335 foreach (TaskInventoryItem item in scripts)
336 {
321 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); 337 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
338 m_part.RemoveScriptEvents(item.ItemID);
339 }
322 } 340 }
323 341
324 /// <summary> 342 /// <summary>
@@ -340,7 +358,10 @@ namespace OpenSim.Region.Framework.Scenes
340// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); 358// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName);
341 359
342 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 360 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
361 {
362 StoreScriptError(item.ItemID, "no permission");
343 return false; 363 return false;
364 }
344 365
345 m_part.AddFlag(PrimFlags.Scripted); 366 m_part.AddFlag(PrimFlags.Scripted);
346 367
@@ -350,14 +371,13 @@ namespace OpenSim.Region.Framework.Scenes
350 if (stateSource == 2 && // Prim crossing 371 if (stateSource == 2 && // Prim crossing
351 m_part.ParentGroup.Scene.m_trustBinaries) 372 m_part.ParentGroup.Scene.m_trustBinaries)
352 { 373 {
353 lock (m_items) 374 m_items.LockItemsForWrite(true);
354 { 375 m_items[item.ItemID].PermsMask = 0;
355 m_items[item.ItemID].PermsMask = 0; 376 m_items[item.ItemID].PermsGranter = UUID.Zero;
356 m_items[item.ItemID].PermsGranter = UUID.Zero; 377 m_items.LockItemsForWrite(false);
357 }
358
359 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 378 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
360 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 379 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
380 StoreScriptErrors(item.ItemID, null);
361 m_part.ParentGroup.AddActiveScriptCount(1); 381 m_part.ParentGroup.AddActiveScriptCount(1);
362 m_part.ScheduleFullUpdate(); 382 m_part.ScheduleFullUpdate();
363 return true; 383 return true;
@@ -366,6 +386,8 @@ namespace OpenSim.Region.Framework.Scenes
366 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 386 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
367 if (null == asset) 387 if (null == asset)
368 { 388 {
389 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
390 StoreScriptError(item.ItemID, msg);
369 m_log.ErrorFormat( 391 m_log.ErrorFormat(
370 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 392 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
371 item.Name, item.ItemID, m_part.AbsolutePosition, 393 item.Name, item.ItemID, m_part.AbsolutePosition,
@@ -378,16 +400,18 @@ namespace OpenSim.Region.Framework.Scenes
378 if (m_part.ParentGroup.m_savedScriptState != null) 400 if (m_part.ParentGroup.m_savedScriptState != null)
379 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID); 401 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
380 402
381 lock (m_items) 403 m_items.LockItemsForWrite(true);
382 {
383 m_items[item.ItemID].OldItemID = item.OldItemID;
384 m_items[item.ItemID].PermsMask = 0;
385 m_items[item.ItemID].PermsGranter = UUID.Zero;
386 }
387 404
405 m_items[item.ItemID].OldItemID = item.OldItemID;
406 m_items[item.ItemID].PermsMask = 0;
407 m_items[item.ItemID].PermsGranter = UUID.Zero;
408
409 m_items.LockItemsForWrite(false);
410
388 string script = Utils.BytesToString(asset.Data); 411 string script = Utils.BytesToString(asset.Data);
389 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 412 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
390 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 413 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
414 StoreScriptErrors(item.ItemID, null);
391 if (!item.ScriptRunning) 415 if (!item.ScriptRunning)
392 m_part.ParentGroup.Scene.EventManager.TriggerStopScript( 416 m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
393 m_part.LocalId, item.ItemID); 417 m_part.LocalId, item.ItemID);
@@ -466,22 +490,138 @@ namespace OpenSim.Region.Framework.Scenes
466 return stateID; 490 return stateID;
467 } 491 }
468 492
493 /// <summary>
494 /// Start a script which is in this prim's inventory.
495 /// Some processing may occur in the background, but this routine returns asap.
496 /// </summary>
497 /// <param name="itemId">
498 /// A <see cref="UUID"/>
499 /// </param>
469 public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 500 public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
470 { 501 {
471 TaskInventoryItem item = GetInventoryItem(itemId); 502 lock (m_scriptErrors)
472 if (item != null) 503 {
504 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
505 m_scriptErrors.Remove(itemId);
506 }
507 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
508 return true;
509 }
510
511 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
512 {
513 m_items.LockItemsForRead(true);
514
515 if (m_items.ContainsKey(itemId))
473 { 516 {
474 return CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 517 TaskInventoryItem it = m_items[itemId];
518 m_items.LockItemsForRead(false);
519
520 CreateScriptInstance(it, startParam, postOnRez, engine, stateSource);
475 } 521 }
476 else 522 else
477 { 523 {
478 m_log.ErrorFormat( 524 m_items.LockItemsForRead(false);
479 "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 525 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
480 itemId, m_part.Name, m_part.UUID,
481 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 526 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
527 StoreScriptError(itemId, msg);
528 m_log.ErrorFormat(
529 "[PRIM INVENTORY]: " +
530 "Couldn't start script with ID {0} since it {1}", itemId, msg);
531 }
532 }
482 533
483 return false; 534 /// <summary>
535 /// Start a script which is in this prim's inventory and return any compilation error messages.
536 /// </summary>
537 /// <param name="itemId">
538 /// A <see cref="UUID"/>
539 /// </param>
540 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
541 {
542 ArrayList errors;
543
544 // Indicate to CreateScriptInstanceInternal() we want it to
545 // post any compilation/loading error messages
546 lock (m_scriptErrors)
547 {
548 m_scriptErrors[itemId] = null;
484 } 549 }
550
551 // Perform compilation/loading
552 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
553
554 // Wait for and retrieve any errors
555 lock (m_scriptErrors)
556 {
557 while ((errors = m_scriptErrors[itemId]) == null)
558 {
559 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
560 {
561 m_log.ErrorFormat(
562 "[PRIM INVENTORY]: " +
563 "timedout waiting for script {0} errors", itemId);
564 errors = m_scriptErrors[itemId];
565 if (errors == null)
566 {
567 errors = new ArrayList(1);
568 errors.Add("timedout waiting for errors");
569 }
570 break;
571 }
572 }
573 m_scriptErrors.Remove(itemId);
574 }
575 return errors;
576 }
577
578 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
579 private void StoreScriptErrors(UUID itemId, ArrayList errors)
580 {
581 lock (m_scriptErrors)
582 {
583 // If compilation/loading initiated via CreateScriptInstance(),
584 // it does not want the errors, so just get out
585 if (!m_scriptErrors.ContainsKey(itemId))
586 {
587 return;
588 }
589
590 // Initiated via CreateScriptInstanceEr(), if we know what the
591 // errors are, save them and wake CreateScriptInstanceEr().
592 if (errors != null)
593 {
594 m_scriptErrors[itemId] = errors;
595 System.Threading.Monitor.PulseAll(m_scriptErrors);
596 return;
597 }
598 }
599
600 // Initiated via CreateScriptInstanceEr() but we don't know what
601 // the errors are yet, so retrieve them from the script engine.
602 // This may involve some waiting internal to GetScriptErrors().
603 errors = GetScriptErrors(itemId);
604
605 // Get a default non-null value to indicate success.
606 if (errors == null)
607 {
608 errors = new ArrayList();
609 }
610
611 // Post to CreateScriptInstanceEr() and wake it up
612 lock (m_scriptErrors)
613 {
614 m_scriptErrors[itemId] = errors;
615 System.Threading.Monitor.PulseAll(m_scriptErrors);
616 }
617 }
618
619 // Like StoreScriptErrors(), but just posts a single string message
620 private void StoreScriptError(UUID itemId, string message)
621 {
622 ArrayList errors = new ArrayList(1);
623 errors.Add(message);
624 StoreScriptErrors(itemId, errors);
485 } 625 }
486 626
487 /// <summary> 627 /// <summary>
@@ -494,15 +634,7 @@ namespace OpenSim.Region.Framework.Scenes
494 /// </param> 634 /// </param>
495 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 635 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
496 { 636 {
497 bool scriptPresent = false; 637 if (m_items.ContainsKey(itemId))
498
499 lock (m_items)
500 {
501 if (m_items.ContainsKey(itemId))
502 scriptPresent = true;
503 }
504
505 if (scriptPresent)
506 { 638 {
507 if (!sceneObjectBeingDeleted) 639 if (!sceneObjectBeingDeleted)
508 m_part.RemoveScriptEvents(itemId); 640 m_part.RemoveScriptEvents(itemId);
@@ -573,14 +705,16 @@ namespace OpenSim.Region.Framework.Scenes
573 /// <returns></returns> 705 /// <returns></returns>
574 private bool InventoryContainsName(string name) 706 private bool InventoryContainsName(string name)
575 { 707 {
576 lock (m_items) 708 m_items.LockItemsForRead(true);
709 foreach (TaskInventoryItem item in m_items.Values)
577 { 710 {
578 foreach (TaskInventoryItem item in m_items.Values) 711 if (item.Name == name)
579 { 712 {
580 if (item.Name == name) 713 m_items.LockItemsForRead(false);
581 return true; 714 return true;
582 } 715 }
583 } 716 }
717 m_items.LockItemsForRead(false);
584 return false; 718 return false;
585 } 719 }
586 720
@@ -622,8 +756,9 @@ namespace OpenSim.Region.Framework.Scenes
622 /// <param name="item"></param> 756 /// <param name="item"></param>
623 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 757 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
624 { 758 {
625 List<TaskInventoryItem> il = GetInventoryItems(); 759 m_items.LockItemsForRead(true);
626 760 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
761 m_items.LockItemsForRead(false);
627 foreach (TaskInventoryItem i in il) 762 foreach (TaskInventoryItem i in il)
628 { 763 {
629 if (i.Name == item.Name) 764 if (i.Name == item.Name)
@@ -661,14 +796,14 @@ namespace OpenSim.Region.Framework.Scenes
661 item.Name = name; 796 item.Name = name;
662 item.GroupID = m_part.GroupID; 797 item.GroupID = m_part.GroupID;
663 798
664 lock (m_items) 799 m_items.LockItemsForWrite(true);
665 m_items.Add(item.ItemID, item); 800 m_items.Add(item.ItemID, item);
666 801 m_items.LockItemsForWrite(false);
667 if (allowedDrop) 802 if (allowedDrop)
668 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 803 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
669 else 804 else
670 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 805 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
671 806
672 m_inventorySerial++; 807 m_inventorySerial++;
673 //m_inventorySerial += 2; 808 //m_inventorySerial += 2;
674 HasInventoryChanged = true; 809 HasInventoryChanged = true;
@@ -684,15 +819,15 @@ namespace OpenSim.Region.Framework.Scenes
684 /// <param name="items"></param> 819 /// <param name="items"></param>
685 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 820 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
686 { 821 {
687 lock (m_items) 822 m_items.LockItemsForWrite(true);
823 foreach (TaskInventoryItem item in items)
688 { 824 {
689 foreach (TaskInventoryItem item in items) 825 m_items.Add(item.ItemID, item);
690 { 826// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
691 m_items.Add(item.ItemID, item);
692// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
693 }
694 m_inventorySerial++;
695 } 827 }
828 m_items.LockItemsForWrite(false);
829
830 m_inventorySerial++;
696 } 831 }
697 832
698 /// <summary> 833 /// <summary>
@@ -703,23 +838,24 @@ namespace OpenSim.Region.Framework.Scenes
703 public TaskInventoryItem GetInventoryItem(UUID itemId) 838 public TaskInventoryItem GetInventoryItem(UUID itemId)
704 { 839 {
705 TaskInventoryItem item; 840 TaskInventoryItem item;
706 841 m_items.LockItemsForRead(true);
707 lock (m_items) 842 m_items.TryGetValue(itemId, out item);
708 m_items.TryGetValue(itemId, out item); 843 m_items.LockItemsForRead(false);
709
710 return item; 844 return item;
711 } 845 }
712 846
713 public TaskInventoryItem GetInventoryItem(string name) 847 public TaskInventoryItem GetInventoryItem(string name)
714 { 848 {
715 lock (m_items) 849 m_items.LockItemsForRead(true);
850 foreach (TaskInventoryItem item in m_items.Values)
716 { 851 {
717 foreach (TaskInventoryItem item in m_items.Values) 852 if (item.Name == name)
718 { 853 {
719 if (item.Name == name) 854 m_items.LockItemsForRead(false);
720 return item; 855 return item;
721 } 856 }
722 } 857 }
858 m_items.LockItemsForRead(false);
723 859
724 return null; 860 return null;
725 } 861 }
@@ -728,19 +864,20 @@ namespace OpenSim.Region.Framework.Scenes
728 { 864 {
729 List<TaskInventoryItem> items = new List<TaskInventoryItem>(); 865 List<TaskInventoryItem> items = new List<TaskInventoryItem>();
730 866
731 lock (m_items) 867 m_items.LockItemsForRead(true);
868
869 foreach (TaskInventoryItem item in m_items.Values)
732 { 870 {
733 foreach (TaskInventoryItem item in m_items.Values) 871 if (item.Name == name)
734 { 872 items.Add(item);
735 if (item.Name == name)
736 items.Add(item);
737 }
738 } 873 }
739 874
875 m_items.LockItemsForRead(false);
876
740 return items; 877 return items;
741 } 878 }
742 879
743 public bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist) 880 public bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist, out Vector3 bbox, out float offsetHeight)
744 { 881 {
745 AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 882 AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
746 883
@@ -751,18 +888,29 @@ namespace OpenSim.Region.Framework.Scenes
751 item.AssetID, item.Name, m_part.Name); 888 item.AssetID, item.Name, m_part.Name);
752 objlist = null; 889 objlist = null;
753 veclist = null; 890 veclist = null;
891 bbox = Vector3.Zero;
892 offsetHeight = 0;
754 return false; 893 return false;
755 } 894 }
895<<<<<<< HEAD
756 896
757 Vector3 bbox; 897 Vector3 bbox;
758 float offsetHeight; 898 float offsetHeight;
759 899
760 m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); 900 m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight);
901=======
902
903 bool single = m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight);
904>>>>>>> avn/ubitvar
761 905
762 for (int i = 0; i < objlist.Count; i++) 906 for (int i = 0; i < objlist.Count; i++)
763 { 907 {
764 SceneObjectGroup group = objlist[i]; 908 SceneObjectGroup group = objlist[i];
765 909/*
910 group.RootPart.AttachPoint = group.RootPart.Shape.State;
911 group.RootPart.AttachedPos = group.AbsolutePosition;
912 group.RootPart.AttachRotation = group.GroupRotation;
913*/
766 group.ResetIDs(); 914 group.ResetIDs();
767 915
768 SceneObjectPart rootPart = group.GetPart(group.UUID); 916 SceneObjectPart rootPart = group.GetPart(group.UUID);
@@ -771,12 +919,14 @@ namespace OpenSim.Region.Framework.Scenes
771 // in the serialization, transfer the correct name from the inventory to the 919 // in the serialization, transfer the correct name from the inventory to the
772 // object itself before we rez. 920 // object itself before we rez.
773 // Only do these for the first object if we are rezzing a coalescence. 921 // Only do these for the first object if we are rezzing a coalescence.
774 if (i == 0) 922 // nahh dont mess with coalescence objects,
923 // the name in inventory can be change for inventory purpuses only
924 if (objlist.Count == 1)
775 { 925 {
776 rootPart.Name = item.Name; 926 rootPart.Name = item.Name;
777 rootPart.Description = item.Description; 927 rootPart.Description = item.Description;
778 } 928 }
779 929/* reverted to old code till part.ApplyPermissionsOnRez is better reviewed/fixed
780 group.SetGroup(m_part.GroupID, null); 930 group.SetGroup(m_part.GroupID, null);
781 931
782 foreach (SceneObjectPart part in group.Parts) 932 foreach (SceneObjectPart part in group.Parts)
@@ -792,7 +942,49 @@ namespace OpenSim.Region.Framework.Scenes
792 942
793 part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene); 943 part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene);
794 } 944 }
945*/
946// old code start
947 SceneObjectPart[] partList = group.Parts;
948
949 group.SetGroup(m_part.GroupID, null);
795 950
951 // TODO: Remove magic number badness
952 if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number
953 {
954 if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions())
955 {
956 foreach (SceneObjectPart part in partList)
957 {
958 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
959 part.EveryoneMask = item.EveryonePermissions;
960 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
961 part.NextOwnerMask = item.NextPermissions;
962 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
963 part.GroupMask = item.GroupPermissions;
964 }
965
966 group.ApplyNextOwnerPermissions();
967 }
968 }
969
970 foreach (SceneObjectPart part in partList)
971 {
972 // TODO: Remove magic number badness
973 if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number
974 {
975 part.LastOwnerID = part.OwnerID;
976 part.OwnerID = item.OwnerID;
977 part.Inventory.ChangeInventoryOwner(item.OwnerID);
978 }
979
980 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
981 part.EveryoneMask = item.EveryonePermissions;
982 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
983 part.NextOwnerMask = item.NextPermissions;
984 if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
985 part.GroupMask = item.GroupPermissions;
986 }
987// old code end
796 rootPart.TrimPermissions(); 988 rootPart.TrimPermissions();
797 } 989 }
798 990
@@ -817,8 +1009,9 @@ namespace OpenSim.Region.Framework.Scenes
817 1009
818 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) 1010 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
819 { 1011 {
820 TaskInventoryItem it = GetInventoryItem(item.ItemID); 1012 m_items.LockItemsForWrite(true);
821 if (it != null) 1013
1014 if (m_items.ContainsKey(item.ItemID))
822 { 1015 {
823// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); 1016// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name);
824 1017
@@ -831,14 +1024,10 @@ namespace OpenSim.Region.Framework.Scenes
831 item.GroupID = m_part.GroupID; 1024 item.GroupID = m_part.GroupID;
832 1025
833 if (item.AssetID == UUID.Zero) 1026 if (item.AssetID == UUID.Zero)
834 item.AssetID = it.AssetID; 1027 item.AssetID = m_items[item.ItemID].AssetID;
835 1028
836 lock (m_items) 1029 m_items[item.ItemID] = item;
837 { 1030 m_inventorySerial++;
838 m_items[item.ItemID] = item;
839 m_inventorySerial++;
840 }
841
842 if (fireScriptEvents) 1031 if (fireScriptEvents)
843 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 1032 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
844 1033
@@ -847,7 +1036,7 @@ namespace OpenSim.Region.Framework.Scenes
847 HasInventoryChanged = true; 1036 HasInventoryChanged = true;
848 m_part.ParentGroup.HasGroupChanged = true; 1037 m_part.ParentGroup.HasGroupChanged = true;
849 } 1038 }
850 1039 m_items.LockItemsForWrite(false);
851 return true; 1040 return true;
852 } 1041 }
853 else 1042 else
@@ -858,8 +1047,9 @@ namespace OpenSim.Region.Framework.Scenes
858 item.ItemID, m_part.Name, m_part.UUID, 1047 item.ItemID, m_part.Name, m_part.UUID,
859 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 1048 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
860 } 1049 }
861 return false; 1050 m_items.LockItemsForWrite(false);
862 1051
1052 return false;
863 } 1053 }
864 1054
865 /// <summary> 1055 /// <summary>
@@ -870,160 +1060,187 @@ namespace OpenSim.Region.Framework.Scenes
870 /// in this prim's inventory.</returns> 1060 /// in this prim's inventory.</returns>
871 public int RemoveInventoryItem(UUID itemID) 1061 public int RemoveInventoryItem(UUID itemID)
872 { 1062 {
873 TaskInventoryItem item = GetInventoryItem(itemID); 1063 m_items.LockItemsForRead(true);
874 if (item != null) 1064
1065 if (m_items.ContainsKey(itemID))
875 { 1066 {
876 int type = m_items[itemID].InvType; 1067 int type = m_items[itemID].InvType;
1068 m_items.LockItemsForRead(false);
877 if (type == 10) // Script 1069 if (type == 10) // Script
878 { 1070 {
1071<<<<<<< HEAD
879 // route it through here, to handle script cleanup tasks 1072 // route it through here, to handle script cleanup tasks
880 RemoveScriptInstance(itemID, false); 1073 RemoveScriptInstance(itemID, false);
1074=======
1075 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
1076>>>>>>> avn/ubitvar
881 } 1077 }
1078 m_items.LockItemsForWrite(true);
882 m_items.Remove(itemID); 1079 m_items.Remove(itemID);
1080 m_items.LockItemsForWrite(false);
883 m_inventorySerial++; 1081 m_inventorySerial++;
884 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 1082 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
885 1083
886 HasInventoryChanged = true; 1084 HasInventoryChanged = true;
887 m_part.ParentGroup.HasGroupChanged = true; 1085 m_part.ParentGroup.HasGroupChanged = true;
888 1086
889 if (!ContainsScripts()) 1087 int scriptcount = 0;
1088 m_items.LockItemsForRead(true);
1089 foreach (TaskInventoryItem item in m_items.Values)
1090 {
1091 if (item.Type == 10)
1092 {
1093 scriptcount++;
1094 }
1095 }
1096 m_items.LockItemsForRead(false);
1097
1098
1099 if (scriptcount <= 0)
1100 {
890 m_part.RemFlag(PrimFlags.Scripted); 1101 m_part.RemFlag(PrimFlags.Scripted);
1102 }
891 1103
892 m_part.ScheduleFullUpdate(); 1104 m_part.ScheduleFullUpdate();
893 1105
894 return type; 1106 return type;
895
896 } 1107 }
897 else 1108 else
898 { 1109 {
1110 m_items.LockItemsForRead(false);
899 m_log.ErrorFormat( 1111 m_log.ErrorFormat(
900 "[PRIM INVENTORY]: " + 1112 "[PRIM INVENTORY]: " +
901 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 1113 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
902 itemID, m_part.Name, m_part.UUID, 1114 itemID, m_part.Name, m_part.UUID);
903 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
904 } 1115 }
905 1116
906 return -1; 1117 return -1;
907 } 1118 }
908 1119
909 private bool CreateInventoryFile() 1120
1121 /// <summary>
1122 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
1123 /// </summary>
1124 /// <param name="xferManager"></param>
1125 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
910 { 1126 {
911// m_log.DebugFormat(
912// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}",
913// m_part.Name, m_part.UUID, m_part.LocalId, m_inventorySerial);
914 1127
915 if (m_inventoryFileName == String.Empty || 1128 lock (m_inventoryFileLock)
916 m_inventoryFileNameSerial < m_inventorySerial)
917 { 1129 {
918 // Something changed, we need to create a new file 1130 string filename = "inventory_" + UUID.Random().ToString() + ".tmp";
919 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp";
920 m_inventoryFileNameSerial = m_inventorySerial;
921 1131
922 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 1132 bool changed = false;
923 1133 if (m_inventoryFileNameSerial < m_inventorySerial)
924 lock (m_items)
925 { 1134 {
926 foreach (TaskInventoryItem item in m_items.Values) 1135 m_inventoryFileNameSerial = m_inventorySerial;
927 { 1136 changed = true;
928// m_log.DebugFormat( 1137 }
929// "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}",
930// item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId);
931
932 UUID ownerID = item.OwnerID;
933 uint everyoneMask = 0;
934 uint baseMask = item.BasePermissions;
935 uint ownerMask = item.CurrentPermissions;
936 uint groupMask = item.GroupPermissions;
937 1138
938 invString.AddItemStart(); 1139 if (m_inventoryFileData.Length < 2)
939 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 1140 changed = true;
940 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
941 1141
942 invString.AddPermissionsStart(); 1142 bool includeAssets = false;
1143 if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId))
1144 includeAssets = true;
943 1145
944 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 1146 if (m_inventoryPrivileged != includeAssets)
945 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 1147 changed = true;
946 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
947 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
948 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
949 1148
950 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
951 invString.AddNameValueLine("owner_id", ownerID.ToString());
952 1149
953 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 1150 Items.LockItemsForRead(true);
954 1151
955 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 1152 if (m_inventorySerial == 0) // No inventory
956 invString.AddSectionEnd(); 1153 {
1154 Items.LockItemsForRead(false);
1155 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1156
1157 return;
1158 }
957 1159
958 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 1160 if (m_items.Count == 0) // No inventory
959 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); 1161 {
960 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); 1162 Items.LockItemsForRead(false);
961 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 1163 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1164 return;
1165 }
962 1166
963 invString.AddSaleStart(); 1167 if (!changed)
964 invString.AddNameValueLine("sale_type", "not"); 1168 {
965 invString.AddNameValueLine("sale_price", "0"); 1169 Items.LockItemsForRead(false);
966 invString.AddSectionEnd();
967 1170
968 invString.AddNameValueLine("name", item.Name + "|"); 1171 xferManager.AddNewFile(filename,
969 invString.AddNameValueLine("desc", item.Description + "|"); 1172 m_inventoryFileData);
1173 client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial,
1174 Util.StringToBytes256(filename));
970 1175
971 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 1176 return;
972 invString.AddSectionEnd();
973 }
974 } 1177 }
975 1178
976 m_inventoryFileData = Utils.StringToBytes(invString.BuildString); 1179 m_inventoryPrivileged = includeAssets;
977 1180
978 return true; 1181 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
979 }
980
981 // No need to recreate, the existing file is fine
982 return false;
983 }
984 1182
985 /// <summary> 1183 foreach (TaskInventoryItem item in m_items.Values)
986 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
987 /// </summary>
988 /// <param name="xferManager"></param>
989 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
990 {
991 lock (m_items)
992 {
993 // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing
994 // a new script if any previous deletion has left the prim inventory empty.
995 if (m_items.Count == 0) // No inventory
996 { 1184 {
997// m_log.DebugFormat( 1185 UUID ownerID = item.OwnerID;
998// "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items", 1186 uint everyoneMask = 0;
999// m_part.Name, m_part.LocalId, m_part.UUID, client.Name); 1187 uint baseMask = item.BasePermissions;
1188 uint ownerMask = item.CurrentPermissions;
1189 uint groupMask = item.GroupPermissions;
1000 1190
1001 client.SendTaskInventory(m_part.UUID, 0, new byte[0]); 1191 invString.AddItemStart();
1002 return; 1192 invString.AddNameValueLine("item_id", item.ItemID.ToString());
1193 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
1194
1195 invString.AddPermissionsStart();
1196
1197 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
1198 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
1199 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
1200 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
1201 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
1202
1203 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
1204 invString.AddNameValueLine("owner_id", ownerID.ToString());
1205
1206 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
1207
1208 invString.AddNameValueLine("group_id", item.GroupID.ToString());
1209 invString.AddSectionEnd();
1210
1211 if (includeAssets)
1212 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
1213 else
1214 invString.AddNameValueLine("asset_id", UUID.Zero.ToString());
1215 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
1216 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
1217 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
1218
1219 invString.AddSaleStart();
1220 invString.AddNameValueLine("sale_type", "not");
1221 invString.AddNameValueLine("sale_price", "0");
1222 invString.AddSectionEnd();
1223
1224 invString.AddNameValueLine("name", item.Name + "|");
1225 invString.AddNameValueLine("desc", item.Description + "|");
1226
1227 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
1228 invString.AddSectionEnd();
1003 } 1229 }
1004 1230
1005 CreateInventoryFile(); 1231 Items.LockItemsForRead(false);
1006 1232
1007 // In principle, we should only do the rest if the inventory changed; 1233 m_inventoryFileData = Utils.StringToBytes(invString.BuildString);
1008 // by sending m_inventorySerial to the client, it ought to know 1234
1009 // that nothing changed and that it doesn't need to request the file.
1010 // Unfortunately, it doesn't look like the client optimizes this;
1011 // the client seems to always come back and request the Xfer,
1012 // no matter what value m_inventorySerial has.
1013 // FIXME: Could probably be > 0 here rather than > 2
1014 if (m_inventoryFileData.Length > 2) 1235 if (m_inventoryFileData.Length > 2)
1015 { 1236 {
1016 // Add the file for Xfer 1237 xferManager.AddNewFile(filename, m_inventoryFileData);
1017 // m_log.DebugFormat( 1238 client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial,
1018 // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}", 1239 Util.StringToBytes256(filename));
1019 // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId); 1240 return;
1020
1021 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
1022 } 1241 }
1023 1242
1024 // Tell the client we're ready to Xfer the file 1243 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1025 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
1026 Util.StringToBytes256(m_inventoryFileName));
1027 } 1244 }
1028 } 1245 }
1029 1246
@@ -1033,13 +1250,26 @@ namespace OpenSim.Region.Framework.Scenes
1033 /// <param name="datastore"></param> 1250 /// <param name="datastore"></param>
1034 public void ProcessInventoryBackup(ISimulationDataService datastore) 1251 public void ProcessInventoryBackup(ISimulationDataService datastore)
1035 { 1252 {
1036 if (HasInventoryChanged) 1253// Removed this because linking will cause an immediate delete of the new
1037 { 1254// child prim from the database and the subsequent storing of the prim sees
1255// the inventory of it as unchanged and doesn't store it at all. The overhead
1256// of storing prim inventory needlessly is much less than the aggravation
1257// of prim inventory loss.
1258// if (HasInventoryChanged)
1259// {
1260 Items.LockItemsForRead(true);
1261 try
1262 {
1263 datastore.StorePrimInventory(m_part.UUID, Items.Values);
1264 }
1265 catch {}
1266
1038 HasInventoryChanged = false; 1267 HasInventoryChanged = false;
1039 List<TaskInventoryItem> items = GetInventoryItems();
1040 datastore.StorePrimInventory(m_part.UUID, items);
1041 1268
1042 } 1269 Items.LockItemsForRead(false);
1270
1271
1272// }
1043 } 1273 }
1044 1274
1045 public class InventoryStringBuilder 1275 public class InventoryStringBuilder
@@ -1105,65 +1335,63 @@ namespace OpenSim.Region.Framework.Scenes
1105 { 1335 {
1106 uint mask=0x7fffffff; 1336 uint mask=0x7fffffff;
1107 1337
1108 lock (m_items) 1338 foreach (TaskInventoryItem item in m_items.Values)
1109 { 1339 {
1110 foreach (TaskInventoryItem item in m_items.Values) 1340 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1341 mask &= ~((uint)PermissionMask.Copy >> 13);
1342 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1343 mask &= ~((uint)PermissionMask.Transfer >> 13);
1344 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1345 mask &= ~((uint)PermissionMask.Modify >> 13);
1346
1347 if (item.InvType == (int)InventoryType.Object)
1111 { 1348 {
1112 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1349 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1113 mask &= ~((uint)PermissionMask.Copy >> 13); 1350 mask &= ~((uint)PermissionMask.Copy >> 13);
1114 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1351 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1115 mask &= ~((uint)PermissionMask.Transfer >> 13); 1352 mask &= ~((uint)PermissionMask.Transfer >> 13);
1116 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1353 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1117 mask &= ~((uint)PermissionMask.Modify >> 13); 1354 mask &= ~((uint)PermissionMask.Modify >> 13);
1118
1119 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1120 mask &= ~(uint)PermissionMask.Copy;
1121 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1122 mask &= ~(uint)PermissionMask.Transfer;
1123 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1124 mask &= ~(uint)PermissionMask.Modify;
1125 } 1355 }
1356
1357 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1358 mask &= ~(uint)PermissionMask.Copy;
1359 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1360 mask &= ~(uint)PermissionMask.Transfer;
1361 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1362 mask &= ~(uint)PermissionMask.Modify;
1126 } 1363 }
1127
1128 return mask; 1364 return mask;
1129 } 1365 }
1130 1366
1131 public void ApplyNextOwnerPermissions() 1367 public void ApplyNextOwnerPermissions()
1132 { 1368 {
1133 lock (m_items) 1369 foreach (TaskInventoryItem item in m_items.Values)
1134 { 1370 {
1135 foreach (TaskInventoryItem item in m_items.Values) 1371 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
1136 { 1372 {
1137// m_log.DebugFormat ( 1373 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1138// "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}", 1374 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1139// item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions); 1375 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1140 1376 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1141 if (item.InvType == (int)InventoryType.Object) 1377 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1142 { 1378 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1143 uint perms = item.CurrentPermissions;
1144 PermissionsUtil.ApplyFoldedPermissions(perms, ref perms);
1145 item.CurrentPermissions = perms;
1146 }
1147
1148 item.CurrentPermissions &= item.NextPermissions;
1149 item.BasePermissions &= item.NextPermissions;
1150 item.EveryonePermissions &= item.NextPermissions;
1151 item.OwnerChanged = true;
1152 item.PermsMask = 0;
1153 item.PermsGranter = UUID.Zero;
1154 } 1379 }
1380 item.CurrentPermissions &= item.NextPermissions;
1381 item.BasePermissions &= item.NextPermissions;
1382 item.EveryonePermissions &= item.NextPermissions;
1383 item.OwnerChanged = true;
1384 item.PermsMask = 0;
1385 item.PermsGranter = UUID.Zero;
1155 } 1386 }
1156 } 1387 }
1157 1388
1158 public void ApplyGodPermissions(uint perms) 1389 public void ApplyGodPermissions(uint perms)
1159 { 1390 {
1160 lock (m_items) 1391 foreach (TaskInventoryItem item in m_items.Values)
1161 { 1392 {
1162 foreach (TaskInventoryItem item in m_items.Values) 1393 item.CurrentPermissions = perms;
1163 { 1394 item.BasePermissions = perms;
1164 item.CurrentPermissions = perms;
1165 item.BasePermissions = perms;
1166 }
1167 } 1395 }
1168 1396
1169 m_inventorySerial++; 1397 m_inventorySerial++;
@@ -1176,14 +1404,11 @@ namespace OpenSim.Region.Framework.Scenes
1176 /// <returns></returns> 1404 /// <returns></returns>
1177 public bool ContainsScripts() 1405 public bool ContainsScripts()
1178 { 1406 {
1179 lock (m_items) 1407 foreach (TaskInventoryItem item in m_items.Values)
1180 { 1408 {
1181 foreach (TaskInventoryItem item in m_items.Values) 1409 if (item.InvType == (int)InventoryType.LSL)
1182 { 1410 {
1183 if (item.InvType == (int)InventoryType.LSL) 1411 return true;
1184 {
1185 return true;
1186 }
1187 } 1412 }
1188 } 1413 }
1189 1414
@@ -1197,17 +1422,15 @@ namespace OpenSim.Region.Framework.Scenes
1197 public int ScriptCount() 1422 public int ScriptCount()
1198 { 1423 {
1199 int count = 0; 1424 int count = 0;
1200 lock (m_items) 1425 Items.LockItemsForRead(true);
1426 foreach (TaskInventoryItem item in m_items.Values)
1201 { 1427 {
1202 foreach (TaskInventoryItem item in m_items.Values) 1428 if (item.InvType == (int)InventoryType.LSL)
1203 { 1429 {
1204 if (item.InvType == (int)InventoryType.LSL) 1430 count++;
1205 {
1206 count++;
1207 }
1208 } 1431 }
1209 } 1432 }
1210 1433 Items.LockItemsForRead(false);
1211 return count; 1434 return count;
1212 } 1435 }
1213 /// <summary> 1436 /// <summary>
@@ -1243,11 +1466,8 @@ namespace OpenSim.Region.Framework.Scenes
1243 { 1466 {
1244 List<UUID> ret = new List<UUID>(); 1467 List<UUID> ret = new List<UUID>();
1245 1468
1246 lock (m_items) 1469 foreach (TaskInventoryItem item in m_items.Values)
1247 { 1470 ret.Add(item.ItemID);
1248 foreach (TaskInventoryItem item in m_items.Values)
1249 ret.Add(item.ItemID);
1250 }
1251 1471
1252 return ret; 1472 return ret;
1253 } 1473 }
@@ -1256,8 +1476,9 @@ namespace OpenSim.Region.Framework.Scenes
1256 { 1476 {
1257 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1477 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1258 1478
1259 lock (m_items) 1479 Items.LockItemsForRead(true);
1260 ret = new List<TaskInventoryItem>(m_items.Values); 1480 ret = new List<TaskInventoryItem>(m_items.Values);
1481 Items.LockItemsForRead(false);
1261 1482
1262 return ret; 1483 return ret;
1263 } 1484 }
@@ -1266,18 +1487,24 @@ namespace OpenSim.Region.Framework.Scenes
1266 { 1487 {
1267 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1488 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1268 1489
1269 lock (m_items) 1490 Items.LockItemsForRead(true);
1270 { 1491
1271 foreach (TaskInventoryItem item in m_items.Values) 1492 foreach (TaskInventoryItem item in m_items.Values)
1272 if (item.InvType == (int)type) 1493 if (item.InvType == (int)type)
1273 ret.Add(item); 1494 ret.Add(item);
1274 } 1495
1496 Items.LockItemsForRead(false);
1275 1497
1276 return ret; 1498 return ret;
1277 } 1499 }
1278 1500
1279 public Dictionary<UUID, string> GetScriptStates() 1501 public Dictionary<UUID, string> GetScriptStates()
1280 { 1502 {
1503 return GetScriptStates(false);
1504 }
1505
1506 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1507 {
1281 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1508 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
1282 1509
1283 if (m_part.ParentGroup.Scene == null) // Group not in a scene 1510 if (m_part.ParentGroup.Scene == null) // Group not in a scene
@@ -1303,14 +1530,21 @@ namespace OpenSim.Region.Framework.Scenes
1303 string n = e.GetXMLState(item.ItemID); 1530 string n = e.GetXMLState(item.ItemID);
1304 if (n != String.Empty) 1531 if (n != String.Empty)
1305 { 1532 {
1306 if (!ret.ContainsKey(item.ItemID)) 1533 if (oldIDs)
1307 ret[item.ItemID] = n; 1534 {
1535 if (!ret.ContainsKey(item.OldItemID))
1536 ret[item.OldItemID] = n;
1537 }
1538 else
1539 {
1540 if (!ret.ContainsKey(item.ItemID))
1541 ret[item.ItemID] = n;
1542 }
1308 break; 1543 break;
1309 } 1544 }
1310 } 1545 }
1311 } 1546 }
1312 } 1547 }
1313
1314 return ret; 1548 return ret;
1315 } 1549 }
1316 1550
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 2f19b50..4bccb7d 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -90,7 +90,17 @@ namespace OpenSim.Region.Framework.Scenes
90 m_scene.EventManager.TriggerScenePresenceUpdated(this); 90 m_scene.EventManager.TriggerScenePresenceUpdated(this);
91 } 91 }
92 92
93 public PresenceType PresenceType { get; private set; } 93 public bool isNPC { get; private set; }
94
95 private PresenceType m_presenceType;
96 public PresenceType PresenceType {
97 get {return m_presenceType;}
98 private set
99 {
100 m_presenceType = value;
101 isNPC = (m_presenceType == PresenceType.Npc);
102 }
103 }
94 104
95 private ScenePresenceStateMachine m_stateMachine; 105 private ScenePresenceStateMachine m_stateMachine;
96 106
@@ -142,13 +152,100 @@ namespace OpenSim.Region.Framework.Scenes
142 /// </summary> 152 /// </summary>
143 public static readonly float SIGNIFICANT_MOVEMENT = 2.0f; 153 public static readonly float SIGNIFICANT_MOVEMENT = 2.0f;
144 154
145 public UUID currentParcelUUID = UUID.Zero; 155 private UUID m_previusParcelUUID = UUID.Zero;
156 private UUID m_currentParcelUUID = UUID.Zero;
157 private bool m_previusParcelHide = false;
158 private bool m_currentParcelHide = false;
159 private object parcelLock = new Object();
160
161 public UUID currentParcelUUID
162 {
163 get { return m_currentParcelUUID; }
164 set
165 {
166 lock (parcelLock)
167 {
168 bool oldhide = m_currentParcelHide;
169 bool checksame = true;
170 if (value != m_currentParcelUUID)
171 {
172 m_previusParcelHide = m_currentParcelHide;
173 m_previusParcelUUID = m_currentParcelUUID;
174 checksame = false;
175 }
176 m_currentParcelUUID = value;
177 m_currentParcelHide = false;
178
179 ILandObject land = m_scene.LandChannel.GetLandObject(AbsolutePosition.X, AbsolutePosition.Y);
180 if (land != null && !land.LandData.SeeAVs)
181 m_currentParcelHide = true;
182
183 if (m_previusParcelUUID != UUID.Zero || checksame)
184 ParcelCrossCheck(m_currentParcelUUID,m_previusParcelUUID,m_currentParcelHide, m_previusParcelHide, oldhide,checksame);
185 }
186 }
187 }
188
189 public void sitSOGmoved()
190 {
191 if (IsDeleted || !IsSatOnObject)
192 //what me? nahh
193 return;
194 if (IsInTransit)
195 return;
196
197 ILandObject land = m_scene.LandChannel.GetLandObject(AbsolutePosition.X, AbsolutePosition.Y);
198 if (land == null)
199 return; //??
200 UUID parcelID = land.LandData.GlobalID;
201 if (m_currentParcelUUID != parcelID)
202 currentParcelUUID = parcelID;
203 }
204
205
206 public bool ParcelAllowThisAvatarSounds
207 {
208 get
209 {
210 try
211 {
212 lock (parcelLock)
213 {
214 ILandObject land = m_scene.LandChannel.GetLandObject(AbsolutePosition.X, AbsolutePosition.Y);
215 if (land == null)
216 return true;
217 if (land.LandData.AnyAVSounds)
218 return true;
219 if (!land.LandData.GroupAVSounds)
220 return false;
221 return land.LandData.GroupID == ControllingClient.ActiveGroupId;
222 }
223 }
224 catch
225 {
226 return true;
227 }
228 }
229 }
146 230
231 public bool ParcelHideThisAvatar
232 {
233 get
234 {
235 return m_currentParcelHide;
236 }
237 }
238
147 /// <value> 239 /// <value>
148 /// The animator for this avatar 240 /// The animator for this avatar
149 /// </value> 241 /// </value>
150 public ScenePresenceAnimator Animator { get; private set; } 242 public ScenePresenceAnimator Animator { get; private set; }
151 243
244 /// <value>
245 /// Server Side Animation Override
246 /// </value>
247 public MovementAnimationOverrides Overrides { get; private set; }
248 public String sitAnimation = "SIT";
152 /// <summary> 249 /// <summary>
153 /// Attachments recorded on this avatar. 250 /// Attachments recorded on this avatar.
154 /// </summary> 251 /// </summary>
@@ -192,14 +289,7 @@ namespace OpenSim.Region.Framework.Scenes
192 set { PhysicsActor.Flying = value; } 289 set { PhysicsActor.Flying = value; }
193 } 290 }
194 291
195 // add for fly velocity control 292 public bool IsColliding
196 private bool FlyingOld {get; set;}
197 public bool WasFlying
198 {
199 get; private set;
200 }
201
202 public bool IsColliding
203 { 293 {
204 get { return PhysicsActor != null && PhysicsActor.IsColliding; } 294 get { return PhysicsActor != null && PhysicsActor.IsColliding; }
205 // We would expect setting IsColliding to be private but it's used by a hack in Scene 295 // We would expect setting IsColliding to be private but it's used by a hack in Scene
@@ -247,7 +337,7 @@ namespace OpenSim.Region.Framework.Scenes
247 337
248 protected ulong crossingFromRegion; 338 protected ulong crossingFromRegion;
249 339
250 private readonly Vector3[] Dir_Vectors = new Vector3[11]; 340 private readonly Vector3[] Dir_Vectors = new Vector3[12];
251 341
252 protected Timer m_reprioritization_timer; 342 protected Timer m_reprioritization_timer;
253 protected bool m_reprioritizing; 343 protected bool m_reprioritizing;
@@ -303,7 +393,7 @@ namespace OpenSim.Region.Framework.Scenes
303 /// <summary> 393 /// <summary>
304 /// Implemented Control Flags 394 /// Implemented Control Flags
305 /// </summary> 395 /// </summary>
306 private enum Dir_ControlFlags 396 private enum Dir_ControlFlags:uint
307 { 397 {
308 DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, 398 DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
309 DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, 399 DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
@@ -315,6 +405,7 @@ namespace OpenSim.Region.Framework.Scenes
315 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 405 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
316 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS, 406 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
317 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG, 407 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
408 DIR_CONTROL_FLAG_UP_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS,
318 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 409 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
319 } 410 }
320 411
@@ -413,11 +504,18 @@ namespace OpenSim.Region.Framework.Scenes
413 } 504 }
414 505
415 private ulong m_rootRegionHandle; 506 private ulong m_rootRegionHandle;
507 private Vector3 m_rootRegionPosition = new Vector3();
416 508
417 public ulong RegionHandle 509 public ulong RegionHandle
418 { 510 {
419 get { return m_rootRegionHandle; } 511 get { return m_rootRegionHandle; }
420 private set { m_rootRegionHandle = value; } 512 private set
513 {
514 m_rootRegionHandle = value;
515 // position rounded to lower multiple of 256m
516 m_rootRegionPosition.X = (float)((m_rootRegionHandle >> 32) & 0xffffff00);
517 m_rootRegionPosition.Y = (float)(m_rootRegionHandle & 0xffffff00);
518 }
421 } 519 }
422 520
423 #region Client Camera 521 #region Client Camera
@@ -449,11 +547,8 @@ namespace OpenSim.Region.Framework.Scenes
449 get 547 get
450 { 548 {
451 Vector3 a = new Vector3(CameraAtAxis.X, CameraAtAxis.Y, 0); 549 Vector3 a = new Vector3(CameraAtAxis.X, CameraAtAxis.Y, 0);
452 550 a.Normalize();
453 if (a == Vector3.Zero) 551 return a;
454 return a;
455
456 return Util.GetNormalizedVector(a);
457 } 552 }
458 } 553 }
459 #endregion 554 #endregion
@@ -505,6 +600,7 @@ namespace OpenSim.Region.Framework.Scenes
505 } 600 }
506 } 601 }
507 602
603
508 public byte State { get; set; } 604 public byte State { get; set; }
509 605
510 private AgentManager.ControlFlags m_AgentControlFlags; 606 private AgentManager.ControlFlags m_AgentControlFlags;
@@ -557,10 +653,21 @@ namespace OpenSim.Region.Framework.Scenes
557 // in the sim unless the avatar is on a sit target. While 653 // in the sim unless the avatar is on a sit target. While
558 // on a sit target, m_pos will contain the desired offset 654 // on a sit target, m_pos will contain the desired offset
559 // without the parent rotation applied. 655 // without the parent rotation applied.
656<<<<<<< HEAD
560 SceneObjectPart sitPart = ParentPart; 657 SceneObjectPart sitPart = ParentPart;
561 658
562 if (sitPart != null) 659 if (sitPart != null)
563 return sitPart.ParentGroup.AbsolutePosition + (m_pos * sitPart.GetWorldRotation()); 660 return sitPart.ParentGroup.AbsolutePosition + (m_pos * sitPart.GetWorldRotation());
661=======
662 if (ParentPart != null)
663 {
664 SceneObjectPart rootPart = ParentPart.ParentGroup.RootPart;
665 // if (sitPart != null)
666 // return sitPart.AbsolutePosition + (m_pos * sitPart.GetWorldRotation());
667 if (rootPart != null)
668 return rootPart.AbsolutePosition + (m_pos * rootPart.GetWorldRotation());
669 }
670>>>>>>> avn/ubitvar
564 } 671 }
565 672
566 return m_pos; 673 return m_pos;
@@ -661,24 +768,7 @@ namespace OpenSim.Region.Framework.Scenes
661 m_velocity = value; 768 m_velocity = value;
662 } 769 }
663 } 770 }
664/*
665 public override Vector3 AngularVelocity
666 {
667 get
668 {
669 if (PhysicsActor != null)
670 {
671 m_rotationalvelocity = PhysicsActor.RotationalVelocity;
672
673 // m_log.DebugFormat(
674 // "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
675 // m_velocity, Name, Scene.RegionInfo.RegionName);
676 }
677 771
678 return m_rotationalvelocity;
679 }
680 }
681*/
682 private Quaternion m_bodyRot = Quaternion.Identity; 772 private Quaternion m_bodyRot = Quaternion.Identity;
683 773
684 /// <summary> 774 /// <summary>
@@ -794,22 +884,29 @@ namespace OpenSim.Region.Framework.Scenes
794 else 884 else
795 seeds = new Dictionary<ulong, string>(); 885 seeds = new Dictionary<ulong, string>();
796 886
887/* we can't do this anymore
797 List<ulong> old = new List<ulong>(); 888 List<ulong> old = new List<ulong>();
798 foreach (ulong handle in seeds.Keys) 889 foreach (ulong handle in seeds.Keys)
799 { 890 {
800 uint x, y; 891 uint x, y;
801 Util.RegionHandleToRegionLoc(handle, out x, out y); 892 Util.RegionHandleToRegionLoc(handle, out x, out y);
893<<<<<<< HEAD
802 894
803 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) 895 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY))
896=======
897no information to check this
898// if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY,))
899>>>>>>> avn/ubitvar
804 { 900 {
805 old.Add(handle); 901 old.Add(handle);
806 } 902 }
807 } 903 }
904
808 DropOldNeighbours(old); 905 DropOldNeighbours(old);
809 906
810 if (Scene.CapsModule != null) 907 if (Scene.CapsModule != null)
811 Scene.CapsModule.SetChildrenSeed(UUID, seeds); 908 Scene.CapsModule.SetChildrenSeed(UUID, seeds);
812 909*/
813 KnownRegions = seeds; 910 KnownRegions = seeds;
814 //m_log.Debug(" ++++++++++AFTER+++++++++++++ "); 911 //m_log.Debug(" ++++++++++AFTER+++++++++++++ ");
815 //DumpKnownRegions(); 912 //DumpKnownRegions();
@@ -852,13 +949,6 @@ namespace OpenSim.Region.Framework.Scenes
852 } 949 }
853 } 950 }
854 951
855 private float m_speedModifier = 1.0f;
856
857 public float SpeedModifier
858 {
859 get { return m_speedModifier; }
860 set { m_speedModifier = value; }
861 }
862 952
863 /// <summary> 953 /// <summary>
864 /// Modifier for agent movement if we get an AGENT_CONTROL_STOP whilst walking or running 954 /// Modifier for agent movement if we get an AGENT_CONTROL_STOP whilst walking or running
@@ -866,7 +956,20 @@ namespace OpenSim.Region.Framework.Scenes
866 /// <remarks> 956 /// <remarks>
867 /// AGENT_CONTRL_STOP comes about if user holds down space key on viewers. 957 /// AGENT_CONTRL_STOP comes about if user holds down space key on viewers.
868 /// </remarks> 958 /// </remarks>
869 private float AgentControlStopSlowWhilstMoving = 0.5f; 959 private const float AgentControlStopSlowVel = 0.2f;
960 // velocities
961 public const float AgentControlNudgeVel = 1.0f; // setting this diferent from normal as no effect currently
962 public const float AgentControlNormalVel = 1.0f;
963
964 // old normal speed was tuned to match sl normal plus Fast modifiers
965 // so we need to rescale it
966 private float m_speedModifier = 1.0f;
967
968 public float SpeedModifier
969 {
970 get { return m_speedModifier; }
971 set { m_speedModifier = value; }
972 }
870 973
871 private bool m_forceFly; 974 private bool m_forceFly;
872 975
@@ -907,6 +1010,7 @@ namespace OpenSim.Region.Framework.Scenes
907 IsLoggingIn = false; 1010 IsLoggingIn = false;
908 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 1011 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
909 Animator = new ScenePresenceAnimator(this); 1012 Animator = new ScenePresenceAnimator(this);
1013 Overrides = new MovementAnimationOverrides();
910 PresenceType = type; 1014 PresenceType = type;
911 // DrawDistance = world.DefaultDrawDistance; 1015 // DrawDistance = world.DefaultDrawDistance;
912 DrawDistance = Constants.RegionSize; 1016 DrawDistance = Constants.RegionSize;
@@ -917,7 +1021,7 @@ namespace OpenSim.Region.Framework.Scenes
917 m_name = String.Format("{0} {1}", Firstname, Lastname); 1021 m_name = String.Format("{0} {1}", Firstname, Lastname);
918 m_scene = world; 1022 m_scene = world;
919 m_uuid = client.AgentId; 1023 m_uuid = client.AgentId;
920 LocalId = m_scene.AllocateLocalId(); 1024 LocalId = m_scene.AllocatePresenceLocalId();
921 1025
922 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); 1026 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
923 if (account != null) 1027 if (account != null)
@@ -930,7 +1034,7 @@ namespace OpenSim.Region.Framework.Scenes
930 1034
931 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 1035 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
932 if (gm != null) 1036 if (gm != null)
933 Grouptitle = gm.GetGroupTitle(m_uuid); 1037 Grouptitle = gm.GetGroupTitle(m_uuid);
934 1038
935 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); 1039 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>();
936 1040
@@ -988,8 +1092,10 @@ namespace OpenSim.Region.Framework.Scenes
988 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 1092 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
989 ControllingClient.OnStartAnim += HandleStartAnim; 1093 ControllingClient.OnStartAnim += HandleStartAnim;
990 ControllingClient.OnStopAnim += HandleStopAnim; 1094 ControllingClient.OnStopAnim += HandleStopAnim;
1095 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
991 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 1096 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
992 ControllingClient.OnAutoPilotGo += MoveToTarget; 1097 ControllingClient.OnAutoPilotGo += MoveToTarget;
1098 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
993 1099
994 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 1100 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
995 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 1101 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -997,6 +1103,7 @@ namespace OpenSim.Region.Framework.Scenes
997 1103
998 private void SetDirectionVectors() 1104 private void SetDirectionVectors()
999 { 1105 {
1106<<<<<<< HEAD
1000 Dir_Vectors[0] = Vector3.UnitX; //FORWARD 1107 Dir_Vectors[0] = Vector3.UnitX; //FORWARD
1001 Dir_Vectors[1] = -Vector3.UnitX; //BACK 1108 Dir_Vectors[1] = -Vector3.UnitX; //BACK
1002 Dir_Vectors[2] = Vector3.UnitY; //LEFT 1109 Dir_Vectors[2] = Vector3.UnitY; //LEFT
@@ -1010,6 +1117,41 @@ namespace OpenSim.Region.Framework.Scenes
1010 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 1117 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
1011 } 1118 }
1012 1119
1120=======
1121 Dir_Vectors[0] = new Vector3(AgentControlNormalVel,0,0); //FORWARD
1122 Dir_Vectors[1] = new Vector3(-AgentControlNormalVel,0,0);; //BACK
1123 Dir_Vectors[2] = new Vector3(0,AgentControlNormalVel,0); //LEFT
1124 Dir_Vectors[3] = new Vector3(0,-AgentControlNormalVel,0); //RIGHT
1125 Dir_Vectors[4] = new Vector3(0,0,AgentControlNormalVel); //UP
1126 Dir_Vectors[5] = new Vector3(0,0,-AgentControlNormalVel); //DOWN
1127 Dir_Vectors[6] = new Vector3(AgentControlNudgeVel, 0f, 0f); //FORWARD_NUDGE
1128 Dir_Vectors[7] = new Vector3(-AgentControlNudgeVel, 0f, 0f); //BACK_NUDGE
1129 Dir_Vectors[8] = new Vector3(0f, AgentControlNudgeVel, 0f); //LEFT_NUDGE
1130 Dir_Vectors[9] = new Vector3(0f, -AgentControlNudgeVel, 0f); //RIGHT_NUDGE
1131 Dir_Vectors[10] = new Vector3(0f, 0f, AgentControlNudgeVel); //UP_Nudge
1132 Dir_Vectors[11] = new Vector3(0f, 0f, -AgentControlNudgeVel); //DOWN_Nudge
1133 }
1134
1135/* dont see any use for this
1136 private Vector3[] GetWalkDirectionVectors()
1137 {
1138 Vector3[] vector = new Vector3[12];
1139 vector[0] = new Vector3(CameraUpAxis.Z, 0f, -CameraAtAxis.Z); //FORWARD
1140 vector[1] = new Vector3(-CameraUpAxis.Z, 0f, CameraAtAxis.Z); //BACK
1141 vector[2] = Vector3.UnitY; //LEFT
1142 vector[3] = -Vector3.UnitY; //RIGHT
1143 vector[4] = new Vector3(CameraAtAxis.Z, 0f, CameraUpAxis.Z); //UP
1144 vector[5] = new Vector3(-CameraAtAxis.Z, 0f, -CameraUpAxis.Z); //DOWN
1145 vector[6] = new Vector3(CameraUpAxis.Z, 0f, -CameraAtAxis.Z); //FORWARD_NUDGE
1146 vector[7] = new Vector3(-CameraUpAxis.Z, 0f, CameraAtAxis.Z); //BACK_NUDGE
1147 vector[8] = Vector3.UnitY; //LEFT_NUDGE
1148 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
1149 vector[10] = new Vector3(CameraAtAxis.Z, 0f, CameraUpAxis.Z); //UP_NUDGE
1150 vector[11] = new Vector3(-CameraAtAxis.Z, 0f, -CameraUpAxis.Z); //DOWN_NUDGE
1151 return vector;
1152 }
1153*/
1154>>>>>>> avn/ubitvar
1013 #endregion 1155 #endregion
1014 1156
1015 #region Status Methods 1157 #region Status Methods
@@ -1026,18 +1168,25 @@ namespace OpenSim.Region.Framework.Scenes
1026 /// This method is on the critical path for transferring an avatar from one region to another. Delay here 1168 /// This method is on the critical path for transferring an avatar from one region to another. Delay here
1027 /// delays that crossing. 1169 /// delays that crossing.
1028 /// </remarks> 1170 /// </remarks>
1171
1172
1173 // only in use as part of completemovement
1174 // other uses need fix
1029 private bool MakeRootAgent(Vector3 pos, bool isFlying) 1175 private bool MakeRootAgent(Vector3 pos, bool isFlying)
1030 { 1176 {
1177 int ts = Util.EnvironmentTickCount();
1178
1031 lock (m_completeMovementLock) 1179 lock (m_completeMovementLock)
1032 { 1180 {
1033 if (!IsChildAgent) 1181 if (!IsChildAgent)
1034 return false; 1182 return false;
1035 1183
1184 m_log.DebugFormat("[MakeRootAgent] enter lock: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1036 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 1185 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
1037 1186
1038 // m_log.InfoFormat( 1187 // m_log.InfoFormat(
1039 // "[SCENE]: Upgrading child to root agent for {0} in {1}", 1188 // "[SCENE]: Upgrading child to root agent for {0} in {1}",
1040 // Name, m_scene.RegionInfo.RegionName); 1189 // Name, m_scene.RegionInfo.RegionName);
1041 1190
1042 if (ParentUUID != UUID.Zero) 1191 if (ParentUUID != UUID.Zero)
1043 { 1192 {
@@ -1046,20 +1195,28 @@ namespace OpenSim.Region.Framework.Scenes
1046 if (part == null) 1195 if (part == null)
1047 { 1196 {
1048 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID); 1197 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
1198 ParentID = 0;
1199 ParentPart = null;
1200 PrevSitOffset = Vector3.Zero;
1201 HandleForceReleaseControls(ControllingClient, UUID); // needs testing
1202 IsLoggingIn = false;
1049 } 1203 }
1050 else 1204 else
1051 { 1205 {
1206<<<<<<< HEAD
1052 part.AddSittingAvatar(this); 1207 part.AddSittingAvatar(this);
1053 // ParentPosition = part.GetWorldPosition(); 1208 // ParentPosition = part.GetWorldPosition();
1209=======
1210 part.ParentGroup.AddAvatar(UUID);
1211 if (part.SitTargetPosition != Vector3.Zero)
1212 part.SitTargetAvatar = UUID;
1213>>>>>>> avn/ubitvar
1054 ParentID = part.LocalId; 1214 ParentID = part.LocalId;
1055 ParentPart = part; 1215 ParentPart = part;
1056 m_pos = PrevSitOffset; 1216 m_pos = PrevSitOffset;
1057 // pos = ParentPosition;
1058 pos = part.GetWorldPosition(); 1217 pos = part.GetWorldPosition();
1059 } 1218 }
1060 ParentUUID = UUID.Zero; 1219 ParentUUID = UUID.Zero;
1061
1062 // Animator.TrySetMovementAnimation("SIT");
1063 } 1220 }
1064 else 1221 else
1065 { 1222 {
@@ -1069,15 +1226,18 @@ namespace OpenSim.Region.Framework.Scenes
1069 IsChildAgent = false; 1226 IsChildAgent = false;
1070 } 1227 }
1071 1228
1229 m_log.DebugFormat("[MakeRootAgent] out lock: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1230
1072 // Must reset this here so that a teleport to a region next to an existing region does not keep the flag 1231 // Must reset this here so that a teleport to a region next to an existing region does not keep the flag
1073 // set and prevent the close of the connection on a subsequent re-teleport. 1232 // set and prevent the close of the connection on a subsequent re-teleport.
1074 // Should not be needed if we are not trying to tell this region to close 1233 // Should not be needed if we are not trying to tell this region to close
1075// DoNotCloseAfterTeleport = false; 1234 // DoNotCloseAfterTeleport = false;
1076 1235
1077 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 1236 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
1078 if (gm != null) 1237 if (gm != null)
1079 Grouptitle = gm.GetGroupTitle(m_uuid); 1238 Grouptitle = gm.GetGroupTitle(m_uuid);
1080 1239
1240<<<<<<< HEAD
1081 AgentCircuitData aCircuit = m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode); 1241 AgentCircuitData aCircuit = m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode);
1082 uint teleportFlags = (aCircuit == null) ? 0 : aCircuit.teleportFlags; 1242 uint teleportFlags = (aCircuit == null) ? 0 : aCircuit.teleportFlags;
1083 if ((teleportFlags & (uint)TeleportFlags.ViaHGLogin) != 0) 1243 if ((teleportFlags & (uint)TeleportFlags.ViaHGLogin) != 0)
@@ -1088,11 +1248,16 @@ namespace OpenSim.Region.Framework.Scenes
1088 // But we have a trick that can force them to update the name anyway. 1248 // But we have a trick that can force them to update the name anyway.
1089 ForceViewersUpdateName(); 1249 ForceViewersUpdateName();
1090 } 1250 }
1251=======
1252 m_log.DebugFormat("[MakeRootAgent] Grouptitle: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1253>>>>>>> avn/ubitvar
1091 1254
1092 RegionHandle = m_scene.RegionInfo.RegionHandle; 1255 RegionHandle = m_scene.RegionInfo.RegionHandle;
1093 1256
1094 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 1257 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
1258 m_log.DebugFormat("[MakeRootAgent] TriggerSetRootAgentScene: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1095 1259
1260<<<<<<< HEAD
1096 UUID groupUUID = ControllingClient.ActiveGroupId; 1261 UUID groupUUID = ControllingClient.ActiveGroupId;
1097 string groupName = string.Empty; 1262 string groupName = string.Empty;
1098 ulong groupPowers = 0; 1263 ulong groupPowers = 0;
@@ -1145,6 +1310,11 @@ namespace OpenSim.Region.Framework.Scenes
1145 } 1310 }
1146 */ 1311 */
1147 1312
1313=======
1314
1315 if (ParentID == 0)
1316 {
1317>>>>>>> avn/ubitvar
1148 CheckAndAdjustLandingPoint(ref pos); 1318 CheckAndAdjustLandingPoint(ref pos);
1149 1319
1150 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 1320 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
@@ -1166,7 +1336,7 @@ namespace OpenSim.Region.Framework.Scenes
1166 1336
1167 if (pos.X < m_scene.RegionInfo.RegionSizeX && pos.Y < m_scene.RegionInfo.RegionSizeY) 1337 if (pos.X < m_scene.RegionInfo.RegionSizeX && pos.Y < m_scene.RegionInfo.RegionSizeY)
1168 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1338 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
1169 1339
1170 float newPosZ = posZLimit + localAVHeight / 2; 1340 float newPosZ = posZLimit + localAVHeight / 2;
1171 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 1341 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
1172 { 1342 {
@@ -1190,6 +1360,7 @@ namespace OpenSim.Region.Framework.Scenes
1190 else 1360 else
1191 { 1361 {
1192 AddToPhysicalScene(isFlying); 1362 AddToPhysicalScene(isFlying);
1363<<<<<<< HEAD
1193 } 1364 }
1194 1365
1195 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a 1366 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a
@@ -1198,6 +1369,11 @@ namespace OpenSim.Region.Framework.Scenes
1198 // the value to a negative position which does not trigger the border cross. 1369 // the value to a negative position which does not trigger the border cross.
1199 // This may not be the best location for this. 1370 // This may not be the best location for this.
1200 CheckForBorderCrossing(); 1371 CheckForBorderCrossing();
1372=======
1373 // reset camera to avatar pos
1374 CameraPosition = pos;
1375 }
1376>>>>>>> avn/ubitvar
1201 1377
1202 if (ForceFly) 1378 if (ForceFly)
1203 { 1379 {
@@ -1207,6 +1383,7 @@ namespace OpenSim.Region.Framework.Scenes
1207 { 1383 {
1208 Flying = false; 1384 Flying = false;
1209 } 1385 }
1386<<<<<<< HEAD
1210 } 1387 }
1211 1388
1212 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1389 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
@@ -1239,8 +1416,24 @@ namespace OpenSim.Region.Framework.Scenes
1239 string.Format("Start attachment scripts for {0} in {1}", Name, Scene.Name), 1416 string.Format("Start attachment scripts for {0} in {1}", Name, Scene.Name),
1240 true); 1417 true);
1241 } 1418 }
1419=======
1420
1421 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a
1422 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
1423 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
1424 // the value to a negative position which does not trigger the border cross.
1425 // This may not be the best location for this.
1426
1427
1428 // its not
1429// CheckForBorderCrossing();
1430>>>>>>> avn/ubitvar
1242 } 1431 }
1432
1433 m_log.DebugFormat("[MakeRootAgent] position and physical: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1434 m_scene.SwapRootAgentCount(false);
1243 1435
1436<<<<<<< HEAD
1244 SendAvatarDataToAllClients(); 1437 SendAvatarDataToAllClients();
1245 1438
1246 // send the animations of the other presences to me 1439 // send the animations of the other presences to me
@@ -1249,6 +1442,8 @@ namespace OpenSim.Region.Framework.Scenes
1249 if (presence != this) 1442 if (presence != this)
1250 presence.Animator.SendAnimPackToClient(ControllingClient); 1443 presence.Animator.SendAnimPackToClient(ControllingClient);
1251 }); 1444 });
1445=======
1446>>>>>>> avn/ubitvar
1252 1447
1253 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1448 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
1254 // stall on the border crossing since the existing child agent will still have the last movement 1449 // stall on the border crossing since the existing child agent will still have the last movement
@@ -1256,6 +1451,7 @@ namespace OpenSim.Region.Framework.Scenes
1256 MovementFlag = ForceUpdateMovementFlagValue; 1451 MovementFlag = ForceUpdateMovementFlagValue;
1257 1452
1258 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1453 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1454 m_log.DebugFormat("[MakeRootAgent] TriggerOnMakeRootAgent and done: {0}ms", Util.EnvironmentTickCountSubtract(ts));
1259 1455
1260 return true; 1456 return true;
1261 } 1457 }
@@ -1347,11 +1543,19 @@ namespace OpenSim.Region.Framework.Scenes
1347 /// It doesn't get called for a teleport. Reason being, an agent that 1543 /// It doesn't get called for a teleport. Reason being, an agent that
1348 /// teleports out may not end up anywhere near this region 1544 /// teleports out may not end up anywhere near this region
1349 /// </remarks> 1545 /// </remarks>
1350 public void MakeChildAgent() 1546 public void MakeChildAgent(ulong newRegionHandle)
1351 { 1547 {
1352 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd; 1548 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1353 1549
1354 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1550 RegionHandle = newRegionHandle;
1551
1552 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1} from root region {2}",
1553 Name, Scene.RegionInfo.RegionName, newRegionHandle);
1554
1555 // Reset the m_originRegionID as it has dual use as a flag to signal that the UpdateAgent() call orignating
1556 // from the source simulator has completed on a V2 teleport.
1557 lock (m_originRegionIDAccessLock)
1558 m_originRegionID = UUID.Zero;
1355 1559
1356 // Reset the m_originRegionID as it has dual use as a flag to signal that the UpdateAgent() call orignating 1560 // Reset the m_originRegionID as it has dual use as a flag to signal that the UpdateAgent() call orignating
1357 // from the source simulator has completed on a V2 teleport. 1561 // from the source simulator has completed on a V2 teleport.
@@ -1371,7 +1575,7 @@ namespace OpenSim.Region.Framework.Scenes
1371 else 1575 else
1372 Animator.ResetAnimations(); 1576 Animator.ResetAnimations();
1373 1577
1374 1578
1375// m_log.DebugFormat( 1579// m_log.DebugFormat(
1376// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1580// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
1377// Name, UUID, m_scene.RegionInfo.RegionName); 1581// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1385,8 +1589,15 @@ namespace OpenSim.Region.Framework.Scenes
1385 RemoveFromPhysicalScene(); 1589 RemoveFromPhysicalScene();
1386 ParentID = 0; // Child agents can't be sitting 1590 ParentID = 0; // Child agents can't be sitting
1387 1591
1592// we dont have land information for child
1593 m_previusParcelHide = false;
1594 m_previusParcelUUID = UUID.Zero;
1595 m_currentParcelHide = false;
1596 m_currentParcelUUID = UUID.Zero;
1388 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1597 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
1389 1598
1599 CollisionPlane = Vector4.UnitW;
1600
1390 m_scene.EventManager.TriggerOnMakeChildAgent(this); 1601 m_scene.EventManager.TriggerOnMakeChildAgent(this);
1391 } 1602 }
1392 1603
@@ -1473,6 +1684,9 @@ namespace OpenSim.Region.Framework.Scenes
1473 1684
1474 public void StopFlying() 1685 public void StopFlying()
1475 { 1686 {
1687 if (IsInTransit)
1688 return;
1689
1476 Vector3 pos = AbsolutePosition; 1690 Vector3 pos = AbsolutePosition;
1477 if (Appearance.AvatarHeight != 127.0f) 1691 if (Appearance.AvatarHeight != 127.0f)
1478 pos += new Vector3(0f, 0f, (Appearance.AvatarHeight / 6f)); 1692 pos += new Vector3(0f, 0f, (Appearance.AvatarHeight / 6f));
@@ -1492,7 +1706,7 @@ namespace OpenSim.Region.Framework.Scenes
1492 else 1706 else
1493 CollisionPlane = new Vector4(0, 0, 0, pos.Z - (1.56f / 6f)); 1707 CollisionPlane = new Vector4(0, 0, 0, pos.Z - (1.56f / 6f));
1494 1708
1495 ControllingClient.SendAgentTerseUpdate(this); 1709 SendAgentTerseUpdate(this);
1496 } 1710 }
1497 1711
1498 /// <summary> 1712 /// <summary>
@@ -1578,15 +1792,46 @@ namespace OpenSim.Region.Framework.Scenes
1578 // holds the seed cap for the child agent in that region 1792 // holds the seed cap for the child agent in that region
1579 private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>(); 1793 private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>();
1580 1794
1581 public void AddNeighbourRegion(ulong regionHandle, string cap) 1795 struct spRegionSizeInfo
1796 {
1797 public int sizeX;
1798 public int sizeY;
1799 }
1800
1801 private Dictionary<ulong, spRegionSizeInfo> m_knownChildRegionsSizeInfo = new Dictionary<ulong, spRegionSizeInfo>();
1802
1803
1804 public void AddNeighbourRegionSizeInfo(GridRegion region)
1582 { 1805 {
1583 lock (m_knownChildRegions) 1806 lock (m_knownChildRegions)
1584 { 1807 {
1585 if (!m_knownChildRegions.ContainsKey(regionHandle)) 1808 spRegionSizeInfo sizeInfo = new spRegionSizeInfo();
1809 sizeInfo.sizeX = region.RegionSizeX;
1810 sizeInfo.sizeY = region.RegionSizeY;
1811 ulong regionHandle = region.RegionHandle;
1812
1813 if (!m_knownChildRegionsSizeInfo.ContainsKey(regionHandle))
1586 { 1814 {
1587 uint x, y; 1815 m_knownChildRegionsSizeInfo.Add(regionHandle, sizeInfo);
1588 Utils.LongToUInts(regionHandle, out x, out y); 1816
1589 m_knownChildRegions.Add(regionHandle, cap); 1817 }
1818 else
1819 m_knownChildRegionsSizeInfo[regionHandle] = sizeInfo;
1820 }
1821 }
1822
1823 public void SetNeighbourRegionSizeInfo(List<GridRegion> regionsList)
1824 {
1825 lock (m_knownChildRegions)
1826 {
1827 m_knownChildRegionsSizeInfo.Clear();
1828 foreach (GridRegion region in regionsList)
1829 {
1830 spRegionSizeInfo sizeInfo = new spRegionSizeInfo();
1831 sizeInfo.sizeX = region.RegionSizeX;
1832 sizeInfo.sizeY = region.RegionSizeY;
1833 ulong regionHandle = region.RegionHandle;
1834 m_knownChildRegionsSizeInfo.Add(regionHandle, sizeInfo);
1590 } 1835 }
1591 } 1836 }
1592 } 1837 }
@@ -1600,6 +1845,7 @@ namespace OpenSim.Region.Framework.Scenes
1600 //if (m_knownChildRegions.ContainsKey(regionHandle)) 1845 //if (m_knownChildRegions.ContainsKey(regionHandle))
1601 // m_log.DebugFormat(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); 1846 // m_log.DebugFormat(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count);
1602 m_knownChildRegions.Remove(regionHandle); 1847 m_knownChildRegions.Remove(regionHandle);
1848 m_knownChildRegionsSizeInfo.Remove(regionHandle);
1603 } 1849 }
1604 } 1850 }
1605 1851
@@ -1612,6 +1858,13 @@ namespace OpenSim.Region.Framework.Scenes
1612 } 1858 }
1613 } 1859 }
1614 1860
1861 public void DropThisRootRegionFromNeighbours()
1862 {
1863 ulong handle = m_scene.RegionInfo.RegionHandle;
1864 RemoveNeighbourRegion(handle);
1865 Scene.CapsModule.DropChildSeed(UUID, handle);
1866 }
1867
1615 public Dictionary<ulong, string> KnownRegions 1868 public Dictionary<ulong, string> KnownRegions
1616 { 1869 {
1617 get 1870 get
@@ -1662,12 +1915,17 @@ namespace OpenSim.Region.Framework.Scenes
1662 public void SetSize(Vector3 size, float feetoffset) 1915 public void SetSize(Vector3 size, float feetoffset)
1663 { 1916 {
1664 if (PhysicsActor != null && !IsChildAgent) 1917 if (PhysicsActor != null && !IsChildAgent)
1918<<<<<<< HEAD
1665 { 1919 {
1666 // Eventually there will be a physics call that sets avatar size that includes offset info. 1920 // Eventually there will be a physics call that sets avatar size that includes offset info.
1667 // For the moment, just set the size as passed. 1921 // For the moment, just set the size as passed.
1668 PhysicsActor.Size = size; 1922 PhysicsActor.Size = size;
1669 // PhysicsActor.setAvatarSize(size, feetoffset); 1923 // PhysicsActor.setAvatarSize(size, feetoffset);
1670 } 1924 }
1925=======
1926 PhysicsActor.setAvatarSize(size, feetoffset);
1927
1928>>>>>>> avn/ubitvar
1671 } 1929 }
1672 1930
1673 private bool WaitForUpdateAgent(IClientAPI client) 1931 private bool WaitForUpdateAgent(IClientAPI client)
@@ -1704,12 +1962,15 @@ namespace OpenSim.Region.Framework.Scenes
1704 /// </param> 1962 /// </param>
1705 public void CompleteMovement(IClientAPI client, bool openChildAgents) 1963 public void CompleteMovement(IClientAPI client, bool openChildAgents)
1706 { 1964 {
1707// DateTime startTime = DateTime.Now; 1965 int ts = Util.EnvironmentTickCount();
1708 1966
1709 m_log.InfoFormat( 1967 m_log.InfoFormat(
1710 "[SCENE PRESENCE]: Completing movement of {0} into region {1} in position {2}", 1968 "[SCENE PRESENCE]: Completing movement of {0} into region {1} in position {2}",
1711 client.Name, Scene.Name, AbsolutePosition); 1969 client.Name, Scene.Name, AbsolutePosition);
1970
1971 m_inTransit = true;
1712 1972
1973<<<<<<< HEAD
1713 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); // Get this ahead of time because IsInTransit modifies 'm_AgentControlFlags' 1974 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); // Get this ahead of time because IsInTransit modifies 'm_AgentControlFlags'
1714 1975
1715 IsInTransit = true; 1976 IsInTransit = true;
@@ -1742,16 +2003,38 @@ namespace OpenSim.Region.Framework.Scenes
1742 pos.Z = ground + 1.5f; 2003 pos.Z = ground + 1.5f;
1743 AbsolutePosition = pos; 2004 AbsolutePosition = pos;
1744 } 2005 }
2006=======
2007 try
2008 {
2009 // Make sure it's not a login agent. We don't want to wait for updates during login
2010 if (!isNPC && (m_teleportFlags & TeleportFlags.ViaLogin) == 0)
2011 {
2012
2013 // Let's wait until UpdateAgent (called by departing region) is done
2014 if (!WaitForUpdateAgent(client))
2015 // The sending region never sent the UpdateAgent data, we have to refuse
2016 return;
2017 }
2018
2019 m_log.DebugFormat("[CompleteMovement] WaitForUpdateAgent: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2020
2021 bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
2022>>>>>>> avn/ubitvar
1745 2023
1746 if (!MakeRootAgent(AbsolutePosition, flying)) 2024 if (!MakeRootAgent(AbsolutePosition, flying))
1747 { 2025 {
1748 m_log.DebugFormat( 2026 m_log.DebugFormat(
2027<<<<<<< HEAD
1749 "[SCENE PRESENCE]: Aborting CompleteMovement call for {0} in {1} as they are already root", 2028 "[SCENE PRESENCE]: Aborting CompleteMovement call for {0} in {1} as they are already root",
2029=======
2030 "[SCENE PRESENCE]: Aborting CompleteMovement call for {0} in {1} as they are already root",
2031>>>>>>> avn/ubitvar
1750 Name, Scene.Name); 2032 Name, Scene.Name);
1751 2033
1752 return; 2034 return;
1753 } 2035 }
1754 2036
2037<<<<<<< HEAD
1755 // Tell the client that we're totally ready 2038 // Tell the client that we're totally ready
1756 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look); 2039 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
1757 2040
@@ -1832,6 +2115,249 @@ namespace OpenSim.Region.Framework.Scenes
1832 sog.ScheduleGroupForFullUpdate(); 2115 sog.ScheduleGroupForFullUpdate();
1833 } 2116 }
1834 } 2117 }
2118=======
2119 m_log.DebugFormat("[CompleteMovement] MakeRootAgent: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2120
2121 Vector3 look = Lookat;
2122 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01))
2123 {
2124 look = Velocity;
2125 look.Z = 0;
2126 look.Normalize();
2127 if ((Math.Abs(look.X) < 0.01) && (Math.Abs(look.Y) < 0.01) )
2128 look = new Vector3(0.99f, 0.042f, 0);
2129 }
2130
2131// start sending terrain patchs
2132 if (!isNPC)
2133 Scene.SendLayerData(ControllingClient);
2134
2135 if (!IsChildAgent && !isNPC)
2136 {
2137 InventoryFolderBase cof = m_scene.InventoryService.GetFolderForType(client.AgentId, (AssetType)46);
2138 if (cof == null)
2139 COF = UUID.Zero;
2140 else
2141 COF = cof.ID;
2142
2143 m_log.DebugFormat("[ScenePresence]: CompleteMovement COF for {0} is {1}", client.AgentId, COF);
2144 }
2145
2146 // Tell the client that we're totally ready
2147 ControllingClient.MoveAgentIntoRegion(m_scene.RegionInfo, AbsolutePosition, look);
2148
2149 m_log.DebugFormat("[CompleteMovement] MoveAgentIntoRegion: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2150
2151 if (!string.IsNullOrEmpty(m_callbackURI))
2152 {
2153 // We cannot sleep here since this would hold up the inbound packet processing thread, as
2154 // CompleteMovement() is executed synchronously. However, it might be better to delay the release
2155 // here until we know for sure that the agent is active in this region. Sending AgentMovementComplete
2156 // is not enough for Imprudence clients - there appears to be a small delay (<200ms, <500ms) until they regard this
2157 // region as the current region, meaning that a close sent before then will fail the teleport.
2158 // System.Threading.Thread.Sleep(2000);
2159
2160 m_log.DebugFormat(
2161 "[SCENE PRESENCE]: Releasing {0} {1} with callback to {2}",
2162 client.Name, client.AgentId, m_callbackURI);
2163
2164 UUID originID;
2165
2166 lock (m_originRegionIDAccessLock)
2167 originID = m_originRegionID;
2168
2169 Scene.SimulationService.ReleaseAgent(originID, UUID, m_callbackURI);
2170 m_callbackURI = null;
2171 }
2172// else
2173// {
2174// m_log.DebugFormat(
2175// "[SCENE PRESENCE]: No callback provided on CompleteMovement of {0} {1} to {2}",
2176// client.Name, client.AgentId, m_scene.RegionInfo.RegionName);
2177// }
2178
2179 m_log.DebugFormat("[CompleteMovement] ReleaseAgent: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2180
2181 m_previusParcelHide = false;
2182 m_previusParcelUUID = UUID.Zero;
2183 m_currentParcelHide = false;
2184 m_currentParcelUUID = UUID.Zero;
2185
2186 // send initial land overlay and parcel
2187 ILandChannel landch = m_scene.LandChannel;
2188 if (landch != null)
2189 landch.sendClientInitialLandInfo(client);
2190
2191 if (!IsChildAgent)
2192 {
2193
2194 // ValidateAndSendAppearanceAndAgentData();
2195
2196 // do it here in line
2197 // so sequence is clear
2198
2199 // verify baked textures and cache
2200>>>>>>> avn/ubitvar
2201
2202
2203 bool cachedbaked = false;
2204
2205 if (isNPC)
2206 cachedbaked = true;
2207 else
2208 {
2209 if (m_scene.AvatarFactory != null)
2210 cachedbaked = m_scene.AvatarFactory.ValidateBakedTextureCache(this);
2211
2212 // not sure we need this
2213 if (!cachedbaked)
2214 {
2215 if (m_scene.AvatarFactory != null)
2216 m_scene.AvatarFactory.QueueAppearanceSave(UUID);
2217 }
2218 }
2219
2220 List<ScenePresence> allpresences = m_scene.GetScenePresences();
2221
2222 // send avatar object to all presences including us, so they cross it into region
2223 // then hide if necessary
2224 SendInitialAvatarDataToAllAgents(allpresences);
2225
2226 // send this look
2227 SendAppearanceToAgent(this);
2228
2229 // send this animations
2230
2231 UUID[] animIDs = null;
2232 int[] animseqs = null;
2233 UUID[] animsobjs = null;
2234
2235 if (Animator != null)
2236 Animator.GetArrays(out animIDs, out animseqs, out animsobjs);
2237
2238 bool haveAnims = (animIDs != null && animseqs != null && animsobjs != null);
2239
2240 if (haveAnims)
2241 SendAnimPackToAgent(this, animIDs, animseqs, animsobjs);
2242
2243 // we should be able to receive updates, etc
2244 // so release them
2245 m_inTransit = false;
2246
2247 // send look and animations to others
2248 // if not cached we send greys
2249 // uncomented if will wait till avatar does baking
2250 //if (cachedbaked)
2251 {
2252 foreach (ScenePresence p in allpresences)
2253 {
2254 if (p == this)
2255 continue;
2256
2257 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
2258 continue;
2259
2260 SendAppearanceToAgentNF(p);
2261 if (haveAnims)
2262 SendAnimPackToAgentNF(p, animIDs, animseqs, animsobjs);
2263 }
2264 } // greys if
2265
2266 m_log.DebugFormat("[CompleteMovement] ValidateAndSendAppearanceAndAgentData: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2267
2268 // attachments
2269
2270 if (isNPC || (TeleportFlags & TeleportFlags.ViaLogin) != 0)
2271 {
2272 if (Scene.AttachmentsModule != null)
2273 // Util.FireAndForget(
2274 // o =>
2275 // {
2276 if (!isNPC)
2277 Scene.AttachmentsModule.RezAttachments(this);
2278 else
2279 Util.FireAndForget(x =>
2280 {
2281 Scene.AttachmentsModule.RezAttachments(this);
2282 });
2283 // });
2284 }
2285 else
2286 {
2287 if (m_attachments.Count > 0)
2288 {
2289 m_log.DebugFormat(
2290 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
2291
2292 foreach (SceneObjectGroup sog in m_attachments)
2293 {
2294 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
2295 sog.ResumeScripts();
2296 }
2297
2298 foreach (ScenePresence p in allpresences)
2299 {
2300 if (p == this)
2301 {
2302 SendTerseUpdateToAgentNF(this);
2303 SendAttachmentsToAgentNF(this);
2304 continue;
2305 }
2306
2307 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
2308 continue;
2309
2310 SendTerseUpdateToAgentNF(p);
2311 SendAttachmentsToAgentNF(p);
2312 }
2313 }
2314 }
2315
2316 m_log.DebugFormat("[CompleteMovement] attachments: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2317 if (openChildAgents)
2318 {
2319 // Create child agents in neighbouring regions
2320 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
2321 if (m_agentTransfer != null)
2322 {
2323 m_agentTransfer.EnableChildAgents(this);
2324 }
2325 }
2326 }
2327
2328 m_log.DebugFormat("[CompleteMovement] openChildAgents: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2329
2330 // send the rest of the world
2331 if (m_teleportFlags > 0 && !isNPC || m_currentParcelHide)
2332 SendInitialDataToMe();
2333
2334 m_log.DebugFormat("[CompleteMovement] SendInitialDataToMe: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2335
2336 if (!IsChildAgent && openChildAgents)
2337 {
2338 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
2339 if (friendsModule != null)
2340 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
2341
2342 m_log.DebugFormat("[CompleteMovement] friendsModule: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2343
2344 }
2345 }
2346 finally
2347 {
2348 m_inTransit = false;
2349 }
2350 // if hide force a check
2351 // if (!IsChildAgent && newhide)
2352 // {
2353 // ParcelLoginCheck(m_currentParcelUUID);
2354 // m_currentParcelHide = newhide;
2355 // }
2356
2357 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
2358
2359 m_log.DebugFormat("[CompleteMovement] end: {0}ms", Util.EnvironmentTickCountSubtract(ts));
2360 }
1835 2361
1836 /// <summary> 2362 /// <summary>
1837 /// Callback for the Camera view block check. Gets called with the results of the camera view block test 2363 /// Callback for the Camera view block check. Gets called with the results of the camera view block test
@@ -1921,6 +2447,9 @@ namespace OpenSim.Region.Framework.Scenes
1921 return; 2447 return;
1922 } 2448 }
1923 2449
2450 if (IsInTransit)
2451 return;
2452
1924 #region Sanity Checking 2453 #region Sanity Checking
1925 2454
1926 // This is irritating. Really. 2455 // This is irritating. Really.
@@ -1955,8 +2484,15 @@ namespace OpenSim.Region.Framework.Scenes
1955 // When we get to the point of re-computing neighbors everytime this 2484 // When we get to the point of re-computing neighbors everytime this
1956 // changes, then start using the agent's drawdistance rather than the 2485 // changes, then start using the agent's drawdistance rather than the
1957 // region's draw distance. 2486 // region's draw distance.
2487<<<<<<< HEAD
1958 DrawDistance = agentData.Far; 2488 DrawDistance = agentData.Far;
1959 // DrawDistance = Scene.DefaultDrawDistance; 2489 // DrawDistance = Scene.DefaultDrawDistance;
2490=======
2491
2492 DrawDistance = Util.Clamp(agentData.Far, 32, m_scene.MaxDrawDistance);
2493
2494// DrawDistance = Scene.DefaultDrawDistance;
2495>>>>>>> avn/ubitvar
1960 2496
1961 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 2497 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1962 2498
@@ -1977,6 +2513,7 @@ namespace OpenSim.Region.Framework.Scenes
1977// (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) 2513// (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
1978// m_updateCount = UPDATE_COUNT; 2514// m_updateCount = UPDATE_COUNT;
1979 2515
2516
1980 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) 2517 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
1981 { 2518 {
1982 StandUp(); 2519 StandUp();
@@ -2032,7 +2569,7 @@ namespace OpenSim.Region.Framework.Scenes
2032 2569
2033 // We need to send this back to the client in order to stop the edit beams 2570 // We need to send this back to the client in order to stop the edit beams
2034 if ((oldState & (uint)AgentState.Editing) != 0 && State == (uint)AgentState.None) 2571 if ((oldState & (uint)AgentState.Editing) != 0 && State == (uint)AgentState.None)
2035 ControllingClient.SendAgentTerseUpdate(this); 2572 SendAgentTerseUpdate(this);
2036 2573
2037 PhysicsActor actor = PhysicsActor; 2574 PhysicsActor actor = PhysicsActor;
2038 2575
@@ -2045,10 +2582,8 @@ namespace OpenSim.Region.Framework.Scenes
2045 2582
2046 if (AllowMovement && !SitGround) 2583 if (AllowMovement && !SitGround)
2047 { 2584 {
2048// m_log.DebugFormat("[SCENE PRESENCE]: Initial body rotation {0} for {1}", agentData.BodyRotation, Name); 2585// m_log.DebugFormat("[SCENE PRESENCE]: Initial body rotation {0} for {1}", agentData.BodyRotation, Name);
2049
2050 bool update_rotation = false; 2586 bool update_rotation = false;
2051
2052 if (agentData.BodyRotation != Rotation) 2587 if (agentData.BodyRotation != Rotation)
2053 { 2588 {
2054 Rotation = agentData.BodyRotation; 2589 Rotation = agentData.BodyRotation;
@@ -2075,7 +2610,7 @@ namespace OpenSim.Region.Framework.Scenes
2075 bool DCFlagKeyPressed = false; 2610 bool DCFlagKeyPressed = false;
2076 Vector3 agent_control_v3 = Vector3.Zero; 2611 Vector3 agent_control_v3 = Vector3.Zero;
2077 2612
2078 bool newFlying = actor.Flying; 2613 bool newFlying = false;
2079 2614
2080 if (ForceFly) 2615 if (ForceFly)
2081 newFlying = true; 2616 newFlying = true;
@@ -2096,6 +2631,19 @@ namespace OpenSim.Region.Framework.Scenes
2096 { 2631 {
2097 bool bAllowUpdateMoveToPosition = false; 2632 bool bAllowUpdateMoveToPosition = false;
2098 2633
2634<<<<<<< HEAD
2635=======
2636 Vector3[] dirVectors;
2637
2638 // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying
2639 // this prevents 'jumping' in inappropriate situations.
2640// if (!Flying && (m_mouseLook || m_leftButtonDown))
2641// dirVectors = GetWalkDirectionVectors();
2642// else
2643 dirVectors = Dir_Vectors;
2644
2645
2646>>>>>>> avn/ubitvar
2099 // A DIR_CONTROL_FLAG occurs when the user is trying to move in a particular direction. 2647 // A DIR_CONTROL_FLAG occurs when the user is trying to move in a particular direction.
2100 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 2648 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
2101 { 2649 {
@@ -2115,10 +2663,10 @@ namespace OpenSim.Region.Framework.Scenes
2115 // Why did I get this? 2663 // Why did I get this?
2116 } 2664 }
2117 2665
2118 if (((MovementFlag & (uint)DCF) == 0) & !AgentControlStopActive) 2666 if (((MovementFlag & (uint)DCF) == 0))
2119 { 2667 {
2120 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF); 2668 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF);
2121 MovementFlag += (uint)DCF; 2669 MovementFlag |= (uint)DCF;
2122 update_movementflag = true; 2670 update_movementflag = true;
2123 } 2671 }
2124 } 2672 }
@@ -2127,7 +2675,7 @@ namespace OpenSim.Region.Framework.Scenes
2127 if ((MovementFlag & (uint)DCF) != 0) 2675 if ((MovementFlag & (uint)DCF) != 0)
2128 { 2676 {
2129 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with lack of {1}", Name, DCF); 2677 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with lack of {1}", Name, DCF);
2130 MovementFlag -= (uint)DCF; 2678 MovementFlag &= (uint)~DCF;
2131 update_movementflag = true; 2679 update_movementflag = true;
2132 2680
2133 /* 2681 /*
@@ -2180,11 +2728,11 @@ namespace OpenSim.Region.Framework.Scenes
2180 if (Flying && !ForceFly) 2728 if (Flying && !ForceFly)
2181 { 2729 {
2182 // Need to stop in mid air if user holds down AGENT_CONTROL_STOP 2730 // Need to stop in mid air if user holds down AGENT_CONTROL_STOP
2183 if (AgentControlStopActive) 2731 // if (AgentControlStopActive)
2184 { 2732 // {
2185 agent_control_v3 = Vector3.Zero; 2733 // agent_control_v3 = Vector3.Zero;
2186 } 2734 // }
2187 else 2735 // else
2188 { 2736 {
2189 // Landing detection code 2737 // Landing detection code
2190 2738
@@ -2192,38 +2740,44 @@ namespace OpenSim.Region.Framework.Scenes
2192 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || 2740 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
2193 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2741 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2194 2742
2195 //m_log.Debug("[CONTROL]: " +flags); 2743 //m_log.Debug("[CONTROL]: " +flags);
2196 // Applies a satisfying roll effect to the avatar when flying. 2744 // Applies a satisfying roll effect to the avatar when flying.
2197 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) != 0 && (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) 2745 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) != 0 && (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
2198 { 2746 {
2199 ApplyFlyingRoll( 2747 ApplyFlyingRoll(
2200 FLY_ROLL_RADIANS_PER_UPDATE, 2748 FLY_ROLL_RADIANS_PER_UPDATE,
2201 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0, 2749 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
2202 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0); 2750 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
2203 } 2751 }
2204 else if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) != 0 && 2752 else if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) != 0 &&
2205 (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) 2753 (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
2206 { 2754 {
2207 ApplyFlyingRoll( 2755 ApplyFlyingRoll(
2208 -FLY_ROLL_RADIANS_PER_UPDATE, 2756 -FLY_ROLL_RADIANS_PER_UPDATE,
2209 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0, 2757 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
2210 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0); 2758 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
2211 } 2759 }
2212 else 2760 else
2213 { 2761 {
2214 if (m_AngularVelocity.Z != 0) 2762 if (m_AngularVelocity.Z != 0)
2215 m_AngularVelocity.Z += CalculateFlyingRollResetToZero(FLY_ROLL_RESET_RADIANS_PER_UPDATE); 2763 m_AngularVelocity.Z += CalculateFlyingRollResetToZero(FLY_ROLL_RESET_RADIANS_PER_UPDATE);
2216 }
2217
2218 if (Flying && IsColliding && controlland)
2219 {
2220 // nesting this check because LengthSquared() is expensive and we don't
2221 // want to do it every step when flying.
2222 if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX))
2223 StopFlying();
2224 } 2764 }
2765
2766 /*
2767 if (Flying && IsColliding && controlland)
2768 {
2769 // nesting this check because LengthSquared() is expensive and we don't
2770 // want to do it every step when flying.
2771 if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX))
2772 StopFlying();
2773 }
2774 */
2225 } 2775 }
2226 } 2776 }
2777 else if (IsColliding && agent_control_v3.Z < 0f)
2778 agent_control_v3.Z = 0;
2779// else if(AgentControlStopActive %% Velocity.Z <0.01f)
2780
2227 2781
2228// m_log.DebugFormat("[SCENE PRESENCE]: MovementFlag {0} for {1}", MovementFlag, Name); 2782// m_log.DebugFormat("[SCENE PRESENCE]: MovementFlag {0} for {1}", MovementFlag, Name);
2229 2783
@@ -2236,32 +2790,23 @@ namespace OpenSim.Region.Framework.Scenes
2236 if (update_movementflag 2790 if (update_movementflag
2237 || (update_rotation && DCFlagKeyPressed && (!AgentControlStopActive || MovementFlag != 0))) 2791 || (update_rotation && DCFlagKeyPressed && (!AgentControlStopActive || MovementFlag != 0)))
2238 { 2792 {
2239// if (update_movementflag || !AgentControlStopActive || MovementFlag != 0)
2240// {
2241// m_log.DebugFormat(
2242// "[SCENE PRESENCE]: In {0} adding velocity of {1} to {2}, umf = {3}, mf = {4}, ur = {5}",
2243// m_scene.RegionInfo.RegionName, agent_control_v3, Name,
2244// update_movementflag, MovementFlag, update_rotation);
2245
2246 float speedModifier;
2247 2793
2248 if (AgentControlStopActive) 2794 if (AgentControlStopActive)
2249 speedModifier = AgentControlStopSlowWhilstMoving; 2795 {
2796 // if (MovementFlag == 0 && Animator.Falling)
2797 if (MovementFlag == 0 && Animator.currentControlState == ScenePresenceAnimator.motionControlStates.falling)
2798 {
2799 AddNewMovement(agent_control_v3, AgentControlStopSlowVel, true);
2800 }
2250 else 2801 else
2251 speedModifier = 1; 2802 AddNewMovement(agent_control_v3, AgentControlStopSlowVel);
2803 }
2804 else
2805 {
2806 AddNewMovement(agent_control_v3);
2807 }
2252 2808
2253 AddNewMovement(agent_control_v3, speedModifier);
2254// }
2255 } 2809 }
2256// else
2257// {
2258// if (!update_movementflag)
2259// {
2260// m_log.DebugFormat(
2261// "[SCENE PRESENCE]: In {0} ignoring requested update of {1} for {2} as update_movementflag = false",
2262// m_scene.RegionInfo.RegionName, agent_control_v3, Name);
2263// }
2264// }
2265 2810
2266 if (update_movementflag && ParentID == 0) 2811 if (update_movementflag && ParentID == 0)
2267 { 2812 {
@@ -2274,7 +2819,7 @@ namespace OpenSim.Region.Framework.Scenes
2274 2819
2275 // We need to send this back to the client in order to see the edit beams 2820 // We need to send this back to the client in order to see the edit beams
2276 if ((State & (uint)AgentState.Editing) != 0) 2821 if ((State & (uint)AgentState.Editing) != 0)
2277 ControllingClient.SendAgentTerseUpdate(this); 2822 SendAgentTerseUpdate(this);
2278 2823
2279 m_scene.EventManager.TriggerOnClientMovement(this); 2824 m_scene.EventManager.TriggerOnClientMovement(this);
2280 } 2825 }
@@ -2320,8 +2865,12 @@ namespace OpenSim.Region.Framework.Scenes
2320 // When we get to the point of re-computing neighbors everytime this 2865 // When we get to the point of re-computing neighbors everytime this
2321 // changes, then start using the agent's drawdistance rather than the 2866 // changes, then start using the agent's drawdistance rather than the
2322 // region's draw distance. 2867 // region's draw distance.
2868<<<<<<< HEAD
2323 DrawDistance = agentData.Far; 2869 DrawDistance = agentData.Far;
2324 // DrawDistance = Scene.DefaultDrawDistance; 2870 // DrawDistance = Scene.DefaultDrawDistance;
2871=======
2872 DrawDistance = Util.Clamp(agentData.Far, 32, m_scene.MaxDrawDistance);
2873>>>>>>> avn/ubitvar
2325 2874
2326 // Check if Client has camera in 'follow cam' or 'build' mode. 2875 // Check if Client has camera in 'follow cam' or 'build' mode.
2327 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation); 2876 Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
@@ -2358,11 +2907,13 @@ namespace OpenSim.Region.Framework.Scenes
2358 2907
2359 bool updated = false; 2908 bool updated = false;
2360 2909
2910 Vector3 LocalVectorToTarget3D = MoveToPositionTarget - AbsolutePosition;
2911
2361// m_log.DebugFormat( 2912// m_log.DebugFormat(
2362// "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}", 2913// "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}",
2363// allowUpdate, m_moveToPositionInProgress, m_autopilotMoving); 2914// allowUpdate, m_moveToPositionInProgress, m_autopilotMoving);
2364 2915
2365 double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget); 2916 double distanceToTarget = LocalVectorToTarget3D.Length();
2366 2917
2367// m_log.DebugFormat( 2918// m_log.DebugFormat(
2368// "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}", 2919// "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}",
@@ -2385,11 +2936,11 @@ namespace OpenSim.Region.Framework.Scenes
2385 // Theoretically we might need a more complex PID approach here if other 2936 // Theoretically we might need a more complex PID approach here if other
2386 // unknown forces are acting on the avatar and we need to adaptively respond 2937 // unknown forces are acting on the avatar and we need to adaptively respond
2387 // to such forces, but the following simple approach seems to works fine. 2938 // to such forces, but the following simple approach seems to works fine.
2388 Vector3 LocalVectorToTarget3D = 2939
2389 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords 2940 LocalVectorToTarget3D = LocalVectorToTarget3D * Quaternion.Inverse(Rotation); // change to avatar coords
2390 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords
2391 // Ignore z component of vector 2941 // Ignore z component of vector
2392// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 2942// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
2943
2393 LocalVectorToTarget3D.Normalize(); 2944 LocalVectorToTarget3D.Normalize();
2394 2945
2395 // update avatar movement flags. the avatar coordinate system is as follows: 2946 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -2413,28 +2964,37 @@ namespace OpenSim.Region.Framework.Scenes
2413 2964
2414 // based on the above avatar coordinate system, classify the movement into 2965 // based on the above avatar coordinate system, classify the movement into
2415 // one of left/right/back/forward. 2966 // one of left/right/back/forward.
2967
2968 const uint noMovFlagsMask = (uint)(~(Dir_ControlFlags.DIR_CONTROL_FLAG_BACK |
2969 Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD | Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT |
2970 Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT | Dir_ControlFlags.DIR_CONTROL_FLAG_UP |
2971 Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN));
2972
2973 MovementFlag &= noMovFlagsMask;
2974 AgentControlFlags &= noMovFlagsMask;
2975
2416 if (LocalVectorToTarget3D.X < 0) //MoveBack 2976 if (LocalVectorToTarget3D.X < 0) //MoveBack
2417 { 2977 {
2418 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; 2978 MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
2419 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; 2979 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
2420 updated = true; 2980 updated = true;
2421 } 2981 }
2422 else if (LocalVectorToTarget3D.X > 0) //Move Forward 2982 else if (LocalVectorToTarget3D.X > 0) //Move Forward
2423 { 2983 {
2424 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; 2984 MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
2425 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; 2985 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
2426 updated = true; 2986 updated = true;
2427 } 2987 }
2428 2988
2429 if (LocalVectorToTarget3D.Y > 0) //MoveLeft 2989 if (LocalVectorToTarget3D.Y > 0) //MoveLeft
2430 { 2990 {
2431 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; 2991 MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
2432 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; 2992 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
2433 updated = true; 2993 updated = true;
2434 } 2994 }
2435 else if (LocalVectorToTarget3D.Y < 0) //MoveRight 2995 else if (LocalVectorToTarget3D.Y < 0) //MoveRight
2436 { 2996 {
2437 MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; 2997 MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
2438 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; 2998 AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
2439 updated = true; 2999 updated = true;
2440 } 3000 }
@@ -2518,6 +3078,17 @@ namespace OpenSim.Region.Framework.Scenes
2518// } 3078// }
2519 3079
2520 // Get terrain height for sub-region in a megaregion if necessary 3080 // Get terrain height for sub-region in a megaregion if necessary
3081<<<<<<< HEAD
3082=======
3083 int X = (int)((m_scene.RegionInfo.WorldLocX) + pos.X);
3084 int Y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y);
3085 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y);
3086 // If X and Y is NaN, target_region will be null
3087 if (target_region == null)
3088 return;
3089 UUID target_regionID = target_region.RegionID;
3090 Scene targetScene = m_scene;
3091>>>>>>> avn/ubitvar
2521 3092
2522 //COMMENT: If its only nessesary in a megaregion, why do it on normal region's too? 3093 //COMMENT: If its only nessesary in a megaregion, why do it on normal region's too?
2523 3094
@@ -2527,6 +3098,7 @@ namespace OpenSim.Region.Framework.Scenes
2527 int y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y); 3098 int y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y);
2528 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y); 3099 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y);
2529 3100
3101<<<<<<< HEAD
2530 // If X and Y is NaN, target_region will be null 3102 // If X and Y is NaN, target_region will be null
2531 if (target_region == null) 3103 if (target_region == null)
2532 return; 3104 return;
@@ -2535,6 +3107,11 @@ namespace OpenSim.Region.Framework.Scenes
2535 } 3107 }
2536 3108
2537 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)]; 3109 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
3110=======
3111 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
3112 // dont try to land underground
3113 terrainHeight += Appearance.AvatarHeight / 2;
3114>>>>>>> avn/ubitvar
2538 pos.Z = Math.Max(terrainHeight, pos.Z); 3115 pos.Z = Math.Max(terrainHeight, pos.Z);
2539 3116
2540 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is 3117 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is
@@ -2543,9 +3120,17 @@ namespace OpenSim.Region.Framework.Scenes
2543 if (pos.Z - terrainHeight < 0.2) 3120 if (pos.Z - terrainHeight < 0.2)
2544 pos.Z = terrainHeight; 3121 pos.Z = terrainHeight;
2545 3122
3123<<<<<<< HEAD
3124=======
3125// m_log.DebugFormat(
3126// "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}",
3127// Name, pos, terrainHeight, m_scene.RegionInfo.RegionName);
3128
3129
3130>>>>>>> avn/ubitvar
2546 if (noFly) 3131 if (noFly)
2547 Flying = false; 3132 Flying = false;
2548 else if (pos.Z > terrainHeight) 3133 else if (pos.Z > terrainHeight + Appearance.AvatarHeight / 2 || Flying)
2549 Flying = true; 3134 Flying = true;
2550 3135
2551// m_log.DebugFormat( 3136// m_log.DebugFormat(
@@ -2629,29 +3214,41 @@ namespace OpenSim.Region.Framework.Scenes
2629 } 3214 }
2630 } 3215 }
2631 3216
3217<<<<<<< HEAD
3218=======
3219 part.ParentGroup.DeleteAvatar(UUID);
3220
3221 Quaternion standRotation = part.ParentGroup.RootPart.RotationOffset;
3222 Vector3 sitPartWorldPosition = part.ParentGroup.AbsolutePosition + m_pos * standRotation;
3223>>>>>>> avn/ubitvar
2632 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 3224 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
2633 3225
2634 ParentID = 0; 3226 ParentID = 0;
2635 ParentPart = null; 3227 ParentPart = null;
2636 3228
2637 Quaternion standRotation;
2638
2639 if (part.SitTargetAvatar == UUID) 3229 if (part.SitTargetAvatar == UUID)
2640 { 3230 standRotation = standRotation * part.SitTargetOrientation;
2641 standRotation = part.GetWorldRotation(); 3231 else
3232 standRotation = standRotation * m_bodyRot;
2642 3233
2643 if (!part.IsRoot) 3234 m_bodyRot = standRotation;
2644 standRotation = standRotation * part.SitTargetOrientation; 3235
2645// standRotation = part.RotationOffset * part.SitTargetOrientation; 3236 Quaternion standRotationZ = new Quaternion(0,0,standRotation.Z,standRotation.W);
2646// else
2647// standRotation = part.SitTargetOrientation;
2648 3237
3238 float t = standRotationZ.W * standRotationZ.W + standRotationZ.Z * standRotationZ.Z;
3239 if (t > 0)
3240 {
3241 t = 1.0f / (float)Math.Sqrt(t);
3242 standRotationZ.W *= t;
3243 standRotationZ.Z *= t;
2649 } 3244 }
2650 else 3245 else
2651 { 3246 {
2652 standRotation = Rotation; 3247 standRotationZ.W = 1.0f;
3248 standRotationZ.Z = 0f;
2653 } 3249 }
2654 3250
3251<<<<<<< HEAD
2655 //Vector3 standPos = ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 3252 //Vector3 standPos = ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2656 //Vector3 standPos = ParentPosition; 3253 //Vector3 standPos = ParentPosition;
2657 3254
@@ -2664,13 +3261,13 @@ namespace OpenSim.Region.Framework.Scenes
2664 Vector3 adjustmentForSitPose = new Vector3(0.74f, 0f, 0f) * standRotation; 3261 Vector3 adjustmentForSitPose = new Vector3(0.74f, 0f, 0f) * standRotation;
2665 3262
2666 Vector3 standPos = part.ParentGroup.AbsolutePosition + adjustmentForSitPosition + adjustmentForSitPose; 3263 Vector3 standPos = part.ParentGroup.AbsolutePosition + adjustmentForSitPosition + adjustmentForSitPose;
3264=======
3265 Vector3 adjustmentForSitPose = new Vector3(0.75f, 0, m_sitAvatarHeight + .3f) * standRotationZ;
2667 3266
2668// m_log.DebugFormat( 3267 Vector3 standPos = sitPartWorldPosition + adjustmentForSitPose;
2669// "[SCENE PRESENCE]: Setting stand to pos {0}, (adjustmentForSitPosition {1}, adjustmentForSitPose {2}) rotation {3} for {4} in {5}", 3268>>>>>>> avn/ubitvar
2670// standPos, adjustmentForSitPosition, adjustmentForSitPose, standRotation, Name, Scene.Name);
2671 3269
2672 Rotation = standRotation; 3270 m_pos = standPos;
2673 AbsolutePosition = standPos;
2674 } 3271 }
2675 3272
2676 // We need to wait until we have calculated proper stand positions before sitting up the physical 3273 // We need to wait until we have calculated proper stand positions before sitting up the physical
@@ -2680,18 +3277,27 @@ namespace OpenSim.Region.Framework.Scenes
2680 3277
2681 if (satOnObject) 3278 if (satOnObject)
2682 { 3279 {
3280<<<<<<< HEAD
2683 SendAvatarDataToAllClients(); 3281 SendAvatarDataToAllClients();
2684 m_requestedSitTargetID = 0; 3282 m_requestedSitTargetID = 0;
2685 3283
2686 part.RemoveSittingAvatar(this); 3284 part.RemoveSittingAvatar(this);
2687 3285
3286=======
3287 m_requestedSitTargetID = 0;
3288 part.RemoveSittingAvatar(UUID);
3289>>>>>>> avn/ubitvar
2688 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 3290 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
3291
3292 SendAvatarDataToAllAgents();
2689 } 3293 }
2690 3294
2691 else if (PhysicsActor == null) 3295 // reset to default sitAnimation
2692 AddToPhysicalScene(false); 3296 sitAnimation = "SIT";
3297
3298// Animator.TrySetMovementAnimation("STAND");
3299 Animator.SetMovementAnimations("STAND");
2693 3300
2694 Animator.TrySetMovementAnimation("STAND");
2695 TriggerScenePresenceUpdated(); 3301 TriggerScenePresenceUpdated();
2696 } 3302 }
2697 3303
@@ -2739,6 +3345,7 @@ namespace OpenSim.Region.Framework.Scenes
2739 if (part == null) 3345 if (part == null)
2740 return; 3346 return;
2741 3347
3348
2742 if (PhysicsActor != null) 3349 if (PhysicsActor != null)
2743 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f; 3350 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2744 3351
@@ -2746,23 +3353,9 @@ namespace OpenSim.Region.Framework.Scenes
2746 3353
2747 if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) 3354 if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero)
2748 { 3355 {
2749// m_log.DebugFormat(
2750// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied",
2751// Name, part.Name, part.LocalId);
2752
2753 offset = part.SitTargetPosition; 3356 offset = part.SitTargetPosition;
2754 sitOrientation = part.SitTargetOrientation; 3357 sitOrientation = part.SitTargetOrientation;
2755 3358
2756 if (!part.IsRoot)
2757 {
2758 // m_log.DebugFormat("Old sit orient {0}", sitOrientation);
2759 sitOrientation = part.RotationOffset * sitOrientation;
2760 // m_log.DebugFormat("New sit orient {0}", sitOrientation);
2761// m_log.DebugFormat("Old sit offset {0}", offset);
2762 offset = offset * part.RotationOffset;
2763// m_log.DebugFormat("New sit offset {0}", offset);
2764 }
2765
2766 canSit = true; 3359 canSit = true;
2767 } 3360 }
2768 else 3361 else
@@ -2826,9 +3419,26 @@ namespace OpenSim.Region.Framework.Scenes
2826 3419
2827 forceMouselook = part.GetForceMouselook(); 3420 forceMouselook = part.GetForceMouselook();
2828 3421
2829 // An viewer expects to specify sit positions as offsets to the root prim, even if a child prim is 3422 if (!part.IsRoot)
2830 // being sat upon. 3423 {
2831 offset += part.OffsetPosition; 3424 sitOrientation = part.RotationOffset * sitOrientation;
3425 offset = offset * part.RotationOffset;
3426 offset += part.OffsetPosition;
3427
3428 if (CameraAtAxis == Vector3.Zero && cameraEyeOffset == Vector3.Zero)
3429 {
3430 CameraAtAxis = part.ParentGroup.RootPart.GetCameraAtOffset();
3431 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset();
3432 }
3433 else
3434 {
3435 cameraAtOffset = cameraAtOffset * part.RotationOffset;
3436 cameraAtOffset += part.OffsetPosition;
3437 cameraEyeOffset = cameraEyeOffset * part.RotationOffset;
3438 cameraEyeOffset += part.OffsetPosition;
3439 }
3440 }
3441
2832 3442
2833 ControllingClient.SendSitResponse( 3443 ControllingClient.SendSitResponse(
2834 part.ParentGroup.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 3444 part.ParentGroup.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
@@ -2875,9 +3485,6 @@ namespace OpenSim.Region.Framework.Scenes
2875 // returns false if does not suport so older sit can be tried 3485 // returns false if does not suport so older sit can be tried
2876 public bool PhysicsSit(SceneObjectPart part, Vector3 offset) 3486 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2877 { 3487 {
2878// TODO: Pull in these bits
2879 return false;
2880/*
2881 if (part == null || part.ParentGroup.IsAttachment) 3488 if (part == null || part.ParentGroup.IsAttachment)
2882 { 3489 {
2883 return true; 3490 return true;
@@ -2907,7 +3514,6 @@ namespace OpenSim.Region.Framework.Scenes
2907 return true; 3514 return true;
2908 3515
2909 return false; 3516 return false;
2910*/
2911 } 3517 }
2912 3518
2913 3519
@@ -2952,6 +3558,7 @@ namespace OpenSim.Region.Framework.Scenes
2952 ResetMoveToTarget(); 3558 ResetMoveToTarget();
2953 3559
2954 Velocity = Vector3.Zero; 3560 Velocity = Vector3.Zero;
3561 m_AngularVelocity = Vector3.Zero;
2955 3562
2956 part.AddSittingAvatar(this); 3563 part.AddSittingAvatar(this);
2957 3564
@@ -2959,23 +3566,58 @@ namespace OpenSim.Region.Framework.Scenes
2959 Vector3 cameraEyeOffset = part.GetCameraEyeOffset(); 3566 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2960 bool forceMouselook = part.GetForceMouselook(); 3567 bool forceMouselook = part.GetForceMouselook();
2961 3568
2962 ControllingClient.SendSitResponse( 3569 m_bodyRot = Orientation;
2963 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 3570
3571 if (!part.IsRoot)
3572 {
3573 Orientation = part.RotationOffset * Orientation;
3574 offset = offset * part.RotationOffset;
3575 offset += part.OffsetPosition;
3576
3577 if (CameraAtAxis == Vector3.Zero && cameraEyeOffset == Vector3.Zero)
3578 {
3579 CameraAtAxis = part.ParentGroup.RootPart.GetCameraAtOffset();
3580 cameraEyeOffset = part.ParentGroup.RootPart.GetCameraEyeOffset();
3581 }
3582 else
3583 {
3584 cameraAtOffset = cameraAtOffset * part.RotationOffset;
3585 cameraAtOffset += part.OffsetPosition;
3586 cameraEyeOffset = cameraEyeOffset * part.RotationOffset;
3587 cameraEyeOffset += part.OffsetPosition;
3588 }
2964 3589
2965 // not using autopilot 3590 }
2966 3591
2967 Rotation = Orientation;
2968 m_pos = offset; 3592 m_pos = offset;
2969 3593
3594 ControllingClient.SendSitResponse(
3595 part.ParentGroup.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
3596
3597
2970 m_requestedSitTargetID = 0; 3598 m_requestedSitTargetID = 0;
2971 3599
2972 ParentPart = part; 3600 ParentPart = part;
2973 ParentID = part.LocalId; 3601 ParentID = part.LocalId;
3602
3603 SendAvatarDataToAllAgents();
3604
3605/*
2974 if(status == 3) 3606 if(status == 3)
2975 Animator.TrySetMovementAnimation("SIT_GROUND"); 3607 Animator.TrySetMovementAnimation("SIT_GROUND");
2976 else 3608 else
2977 Animator.TrySetMovementAnimation("SIT"); 3609 Animator.TrySetMovementAnimation("SIT");
3610<<<<<<< HEAD
2978 SendAvatarDataToAllClients(); 3611 SendAvatarDataToAllClients();
3612=======
3613*/
3614 if (status == 3)
3615 sitAnimation = "SIT_GROUND";
3616 else
3617 sitAnimation = "SIT";
3618
3619 Animator.SetMovementAnimations("SIT");
3620>>>>>>> avn/ubitvar
2979 3621
2980 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 3622 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2981 } 3623 }
@@ -3084,13 +3726,20 @@ namespace OpenSim.Region.Framework.Scenes
3084 Velocity = Vector3.Zero; 3726 Velocity = Vector3.Zero;
3085 RemoveFromPhysicalScene(); 3727 RemoveFromPhysicalScene();
3086 3728
3087 String sitAnimation = "SIT"; 3729 SendAvatarDataToAllAgents();
3730
3731 sitAnimation = "SIT";
3088 if (!String.IsNullOrEmpty(part.SitAnimation)) 3732 if (!String.IsNullOrEmpty(part.SitAnimation))
3089 { 3733 {
3090 sitAnimation = part.SitAnimation; 3734 sitAnimation = part.SitAnimation;
3091 } 3735 }
3736<<<<<<< HEAD
3092 Animator.TrySetMovementAnimation(sitAnimation); 3737 Animator.TrySetMovementAnimation(sitAnimation);
3093 SendAvatarDataToAllClients(); 3738 SendAvatarDataToAllClients();
3739=======
3740// Animator.TrySetMovementAnimation(sitAnimation);
3741 Animator.SetMovementAnimations("SIT");
3742>>>>>>> avn/ubitvar
3094 TriggerScenePresenceUpdated(); 3743 TriggerScenePresenceUpdated();
3095 } 3744 }
3096 } 3745 }
@@ -3102,10 +3751,14 @@ namespace OpenSim.Region.Framework.Scenes
3102 3751
3103// m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.. 3752// m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick..
3104 m_AngularVelocity = Vector3.Zero; 3753 m_AngularVelocity = Vector3.Zero;
3105 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); 3754 sitAnimation = "SIT_GROUND_CONSTRAINED";
3106 TriggerScenePresenceUpdated(); 3755// Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
3756// TriggerScenePresenceUpdated();
3107 SitGround = true; 3757 SitGround = true;
3108 RemoveFromPhysicalScene(); 3758 RemoveFromPhysicalScene();
3759
3760 Animator.SetMovementAnimations("SITGROUND");
3761 TriggerScenePresenceUpdated();
3109 } 3762 }
3110 3763
3111 /// <summary> 3764 /// <summary>
@@ -3129,18 +3782,26 @@ namespace OpenSim.Region.Framework.Scenes
3129 TriggerScenePresenceUpdated(); 3782 TriggerScenePresenceUpdated();
3130 } 3783 }
3131 3784
3785 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
3786 {
3787 Animator.avnChangeAnim(animID, addRemove, sendPack);
3788 }
3789
3790
3791
3132 /// <summary> 3792 /// <summary>
3133 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 3793 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
3134 /// </summary> 3794 /// </summary>
3135 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 3795 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
3136 /// <param name="thisAddSpeedModifier"> 3796 /// <param name="thisAddSpeedModifier">
3137 /// Optional additional speed modifier for this particular add. Default is 1</param> 3797 /// Optional additional speed modifier for this particular add. Default is 1</param>
3138 public void AddNewMovement(Vector3 vec, float thisAddSpeedModifier = 1) 3798 public void AddNewMovement(Vector3 vec, float thisAddSpeedModifier = 1, bool breaking = false)
3139 { 3799 {
3140// m_log.DebugFormat( 3800 // m_log.DebugFormat(
3141// "[SCENE PRESENCE]: Adding new movement {0} with rotation {1}, thisAddSpeedModifier {2} for {3}", 3801 // "[SCENE PRESENCE]: Adding new movement {0} with rotation {1}, thisAddSpeedModifier {2} for {3}",
3142// vec, Rotation, thisAddSpeedModifier, Name); 3802 // vec, Rotation, thisAddSpeedModifier, Name);
3143 3803
3804<<<<<<< HEAD
3144 Quaternion rot = Rotation; 3805 Quaternion rot = Rotation;
3145 if (!Flying && PresenceType != PresenceType.Npc) 3806 if (!Flying && PresenceType != PresenceType.Npc)
3146 { 3807 {
@@ -3153,61 +3814,51 @@ namespace OpenSim.Region.Framework.Scenes
3153 } 3814 }
3154 3815
3155 Vector3 direc = vec * rot; 3816 Vector3 direc = vec * rot;
3817=======
3818 // rotate from avatar coord space to world
3819 // for now all controls assume this is only a rotation around Z
3820 // if not all checks below need to be done before this rotation
3821 Vector3 direc = vec * Rotation;
3822>>>>>>> avn/ubitvar
3156 direc.Normalize(); 3823 direc.Normalize();
3157 3824
3158 if (Flying != FlyingOld) // add for fly velocity control 3825 // mouse look situation ?
3159 {
3160 FlyingOld = Flying; // add for fly velocity control
3161 if (!Flying)
3162 WasFlying = true; // add for fly velocity control
3163 }
3164
3165 if (IsColliding)
3166 WasFlying = false; // add for fly velocity control
3167
3168 if ((vec.Z == 0f) && !Flying) 3826 if ((vec.Z == 0f) && !Flying)
3169 direc.Z = 0f; // Prevent camera WASD up. 3827 direc.Z = 0f; // Prevent camera WASD up.
3170 3828
3829 // odd rescalings
3171 direc *= 0.03f * 128f * SpeedModifier * thisAddSpeedModifier; 3830 direc *= 0.03f * 128f * SpeedModifier * thisAddSpeedModifier;
3172 3831
3173// m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name); 3832 // m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name);
3174 3833
3175 if (PhysicsActor != null) 3834 if (Animator.currentControlState == ScenePresenceAnimator.motionControlStates.falling)
3176 { 3835 {
3177 if (Flying) 3836 if (breaking)
3178 { 3837 direc.Z = -9999f; //hack to tell physics to stop on Z
3838 else
3839 direc = Vector3.Zero;
3840 }
3841 else if (Flying)
3842 {
3843 if (IsColliding && direc.Z < 0)
3844 // landing situation, prevent avatar moving or it may fail to land
3845 // animator will handle this condition and do the land
3846 direc = Vector3.Zero;
3847 else
3179 direc *= 4.0f; 3848 direc *= 4.0f;
3180 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 3849 }
3181 //if (controlland) 3850 else if (IsColliding)
3182 // m_log.Info("[AGENT]: landCommand"); 3851 {
3183 //if (IsColliding) 3852 if (direc.Z > 2.0f) // reinforce jumps
3184 // m_log.Info("[AGENT]: colliding");
3185 //if (Flying && IsColliding && controlland)
3186 //{
3187 // StopFlying();
3188 // m_log.Info("[AGENT]: Stop Flying");
3189 //}
3190 }
3191 if (Animator.Falling && WasFlying) // if falling from flying, disable motion add
3192 {
3193 direc *= 0.0f;
3194 }
3195 else if (!Flying && IsColliding)
3196 { 3853 {
3197 if (direc.Z > 2.0f) 3854 direc.Z *= 2.6f;
3198 {
3199 direc.Z *= 2.6f;
3200
3201 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
3202// Animator.TrySetMovementAnimation("PREJUMP");
3203// Animator.TrySetMovementAnimation("JUMP");
3204 }
3205 } 3855 }
3856 else if (direc.Z < 0) // on a surface moving down (pg down) only changes animation
3857 direc.Z = 0;
3206 } 3858 }
3207 3859
3208// m_log.DebugFormat("[SCENE PRESENCE]: Setting force to apply to {0} for {1}", direc, Name); 3860 // m_log.DebugFormat("[SCENE PRESENCE]: Setting force to apply to {0} for {1}", direc, Name);
3209 3861
3210 // TODO: Add the force instead of only setting it to support multiple forces per frame?
3211 m_forceToApply = direc; 3862 m_forceToApply = direc;
3212 Animator.UpdateMovementAnimations(); 3863 Animator.UpdateMovementAnimations();
3213 } 3864 }
@@ -3220,6 +3871,11 @@ namespace OpenSim.Region.Framework.Scenes
3220 { 3871 {
3221 if (IsChildAgent == false) 3872 if (IsChildAgent == false)
3222 { 3873 {
3874 CheckForBorderCrossing();
3875
3876 if (IsInTransit)
3877 return;
3878
3223 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 3879 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
3224 // grab the latest PhysicsActor velocity, whereas m_velocity is often 3880 // grab the latest PhysicsActor velocity, whereas m_velocity is often
3225 // storing a requested force instead of an actual traveling velocity 3881 // storing a requested force instead of an actual traveling velocity
@@ -3248,9 +3904,12 @@ namespace OpenSim.Region.Framework.Scenes
3248 m_lastVelocity = Velocity; 3904 m_lastVelocity = Velocity;
3249 } 3905 }
3250 3906
3907<<<<<<< HEAD
3251 if (Scene.AllowAvatarCrossing) 3908 if (Scene.AllowAvatarCrossing)
3252 CheckForBorderCrossing(); 3909 CheckForBorderCrossing();
3253 3910
3911=======
3912>>>>>>> avn/ubitvar
3254 CheckForSignificantMovement(); // sends update to the modules. 3913 CheckForSignificantMovement(); // sends update to the modules.
3255 } 3914 }
3256 } 3915 }
@@ -3259,8 +3918,41 @@ namespace OpenSim.Region.Framework.Scenes
3259 3918
3260 #region Update Client(s) 3919 #region Update Client(s)
3261 3920
3921<<<<<<< HEAD
3922=======
3923 public void SendUpdateToAgent(ScenePresence p)
3924 {
3925 IClientAPI remoteClient = p.ControllingClient;
3926
3927 if (remoteClient.IsActive)
3928 {
3929 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
3930 remoteClient.SendEntityUpdate(this, PrimUpdateFlags.FullUpdate);
3931 m_scene.StatsReporter.AddAgentUpdates(1);
3932 }
3933 }
3934
3935 public void SendFullUpdateToClient(IClientAPI remoteClient)
3936 {
3937 if (remoteClient.IsActive)
3938 {
3939 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
3940 remoteClient.SendEntityUpdate(this, PrimUpdateFlags.FullUpdate);
3941 m_scene.StatsReporter.AddAgentUpdates(1);
3942 }
3943 }
3944
3945 // this is diferente from SendTerseUpdateToClient
3946 // this sends bypassing entities updates
3947 public void SendAgentTerseUpdate(ISceneEntity p)
3948 {
3949 ControllingClient.SendAgentTerseUpdate(p);
3950 }
3951
3952>>>>>>> avn/ubitvar
3262 /// <summary> 3953 /// <summary>
3263 /// Sends a location update to the client connected to this scenePresence 3954 /// Sends a location update to the client connected to this scenePresence
3955 /// via entity updates
3264 /// </summary> 3956 /// </summary>
3265 /// <param name="remoteClient"></param> 3957 /// <param name="remoteClient"></param>
3266 public void SendTerseUpdateToClient(IClientAPI remoteClient) 3958 public void SendTerseUpdateToClient(IClientAPI remoteClient)
@@ -3293,7 +3985,6 @@ namespace OpenSim.Region.Framework.Scenes
3293 return; 3985 return;
3294 3986
3295 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity); 3987 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
3296
3297 remoteClient.SendEntityUpdate( 3988 remoteClient.SendEntityUpdate(
3298 this, 3989 this,
3299 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity 3990 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
@@ -3303,6 +3994,38 @@ namespace OpenSim.Region.Framework.Scenes
3303 } 3994 }
3304 } 3995 }
3305 3996
3997 public void SendTerseUpdateToAgent(ScenePresence p)
3998 {
3999 IClientAPI remoteClient = p.ControllingClient;
4000
4001 if (!remoteClient.IsActive)
4002 return;
4003
4004 if (ParcelHideThisAvatar && p.currentParcelUUID != currentParcelUUID && p.GodLevel < 200)
4005 return;
4006
4007 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
4008 remoteClient.SendEntityUpdate(
4009 this,
4010 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
4011 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity);
4012
4013 m_scene.StatsReporter.AddAgentUpdates(1);
4014 }
4015
4016 public void SendTerseUpdateToAgentNF(ScenePresence p)
4017 {
4018 IClientAPI remoteClient = p.ControllingClient;
4019 if (remoteClient.IsActive)
4020 {
4021 //m_log.DebugFormat("[SCENE PRESENCE]: " + Name + " sending TerseUpdate to " + remoteClient.Name + " : Pos={0} Rot={1} Vel={2}", m_pos, Rotation, m_velocity);
4022 remoteClient.SendEntityUpdate(this,
4023 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
4024 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity);
4025 m_scene.StatsReporter.AddAgentUpdates(1);
4026 }
4027 }
4028
3306 4029
3307 // vars to support reduced update frequency when velocity is unchanged 4030 // vars to support reduced update frequency when velocity is unchanged
3308 private Vector3 lastVelocitySentToAllClients = Vector3.Zero; 4031 private Vector3 lastVelocitySentToAllClients = Vector3.Zero;
@@ -3354,7 +4077,8 @@ namespace OpenSim.Region.Framework.Scenes
3354 m_terseUpdateCount++; 4077 m_terseUpdateCount++;
3355 4078
3356// Console.WriteLine("Scheduled update for {0} in {1}", Name, Scene.Name); 4079// Console.WriteLine("Scheduled update for {0} in {1}", Name, Scene.Name);
3357 m_scene.ForEachClient(SendTerseUpdateToClient); 4080// m_scene.ForEachClient(SendTerseUpdateToClient);
4081 m_scene.ForEachScenePresence(SendTerseUpdateToAgent);
3358 } 4082 }
3359 TriggerScenePresenceUpdated(); 4083 TriggerScenePresenceUpdated();
3360 } 4084 }
@@ -3393,22 +4117,40 @@ namespace OpenSim.Region.Framework.Scenes
3393 // we created a new ScenePresence (a new child agent) in a fresh region. 4117 // we created a new ScenePresence (a new child agent) in a fresh region.
3394 // Request info about all the (root) agents in this region 4118 // Request info about all the (root) agents in this region
3395 // Note: This won't send data *to* other clients in that region (children don't send) 4119 // Note: This won't send data *to* other clients in that region (children don't send)
4120<<<<<<< HEAD
3396 SendOtherAgentsAvatarDataToClient(); 4121 SendOtherAgentsAvatarDataToClient();
3397 SendOtherAgentsAppearanceToClient(); 4122 SendOtherAgentsAppearanceToClient();
4123=======
4124 if (m_teleportFlags <= 0)
4125 {
4126 ILandChannel landch = m_scene.LandChannel;
4127 if (landch != null)
4128 {
4129 landch.sendClientInitialLandInfo(ControllingClient);
4130 }
4131 }
4132>>>>>>> avn/ubitvar
3398 4133
4134 SendOtherAgentsAvatarFullToMe();
3399 EntityBase[] entities = Scene.Entities.GetEntities(); 4135 EntityBase[] entities = Scene.Entities.GetEntities();
3400 foreach (EntityBase e in entities) 4136 foreach (EntityBase e in entities)
3401 { 4137 {
3402 if (e != null && e is SceneObjectGroup) 4138 if (e != null && e is SceneObjectGroup && !((SceneObjectGroup)e).IsAttachment)
3403 ((SceneObjectGroup)e).SendFullUpdateToClient(ControllingClient); 4139 ((SceneObjectGroup)e).SendFullUpdateToClient(ControllingClient);
3404 } 4140 }
4141<<<<<<< HEAD
3405 }, null, string.Format("SendInitialDataToClient ({0} in {1})", Name, Scene.Name), false, true); 4142 }, null, string.Format("SendInitialDataToClient ({0} in {1})", Name, Scene.Name), false, true);
4143=======
4144 });
4145>>>>>>> avn/ubitvar
3406 } 4146 }
3407 4147
3408 /// <summary> 4148 /// <summary>
3409 /// Do everything required once a client completes its movement into a region and becomes 4149 /// Do everything required once a client completes its movement into a region and becomes
3410 /// a root agent. 4150 /// a root agent.
3411 /// </summary> 4151 /// </summary>
4152 ///
4153/* only called from on place, do done inline there
3412 private void ValidateAndSendAppearanceAndAgentData() 4154 private void ValidateAndSendAppearanceAndAgentData()
3413 { 4155 {
3414 //m_log.DebugFormat("[SCENE PRESENCE] SendInitialData: {0} ({1})", Name, UUID); 4156 //m_log.DebugFormat("[SCENE PRESENCE] SendInitialData: {0} ({1})", Name, UUID);
@@ -3422,14 +4164,14 @@ namespace OpenSim.Region.Framework.Scenes
3422 // to see if all the baked textures are already here. 4164 // to see if all the baked textures are already here.
3423 if (m_scene.AvatarFactory != null) 4165 if (m_scene.AvatarFactory != null)
3424 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(this); 4166 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(this);
3425 4167
3426 // If we aren't using a cached appearance, then clear out the baked textures 4168 // If we aren't using a cached appearance, then clear out the baked textures
3427 if (!cachedappearance) 4169 if (!cachedappearance)
3428 { 4170 {
3429 Appearance.ResetAppearance();
3430 if (m_scene.AvatarFactory != null) 4171 if (m_scene.AvatarFactory != null)
3431 m_scene.AvatarFactory.QueueAppearanceSave(UUID); 4172 m_scene.AvatarFactory.QueueAppearanceSave(UUID);
3432 } 4173 }
4174<<<<<<< HEAD
3433 4175
3434 // This agent just became root. We are going to tell everyone about it. The process of 4176 // This agent just became root. We are going to tell everyone about it. The process of
3435 // getting other avatars information was initiated elsewhere immediately after the child circuit connected... don't do it 4177 // getting other avatars information was initiated elsewhere immediately after the child circuit connected... don't do it
@@ -3439,17 +4181,66 @@ namespace OpenSim.Region.Framework.Scenes
3439 4181
3440 // This invocation always shows up in the viewer logs as an error. Is it needed? 4182 // This invocation always shows up in the viewer logs as an error. Is it needed?
3441 SendAppearanceToClient(this); 4183 SendAppearanceToClient(this);
4184=======
4185
4186 // send avatar object to all viewers so they cross it into region
4187 bool newhide = m_currentParcelHide;
4188 m_currentParcelHide = false;
4189
4190 SendAvatarDataToAllAgents();
4191
4192 // now hide
4193 if (newhide)
4194 {
4195 ParcelLoginCheck(m_currentParcelUUID);
4196 m_currentParcelHide = true;
4197 }
4198
4199 SendAppearanceToAgent(this);
4200>>>>>>> avn/ubitvar
4201
4202 m_inTransit = false;
3442 4203
3443 // If we are using the the cached appearance then send it out to everyone 4204 SendAppearanceToAllOtherAgents();
3444 if (cachedappearance) 4205
4206 if(Animator!= null)
4207 Animator.SendAnimPack();
4208 }
4209*/
4210 /// <summary>
4211 /// Send avatar full data appearance and animations for all other root agents to this agent, this agent
4212 /// can be either a child or root
4213 /// </summary>
4214 public void SendOtherAgentsAvatarFullToMe()
4215 {
4216 int count = 0;
4217 m_scene.ForEachRootScenePresence(delegate(ScenePresence p)
3445 { 4218 {
3446 m_log.DebugFormat("[SCENE PRESENCE]: Baked textures are in the cache for {0} in {1}", Name, m_scene.Name); 4219 // only send information about other root agents
4220 if (p.UUID == UUID)
4221 return;
3447 4222
4223<<<<<<< HEAD
3448 // If the avatars baked textures are all in the cache, then we have a 4224 // If the avatars baked textures are all in the cache, then we have a
3449 // complete appearance... send it out, if not, then we'll send it when 4225 // complete appearance... send it out, if not, then we'll send it when
3450 // the avatar finishes updating its appearance 4226 // the avatar finishes updating its appearance
3451 SendAppearanceToAllOtherClients(); 4227 SendAppearanceToAllOtherClients();
3452 } 4228 }
4229=======
4230 // get the avatar, then a kill if can't see it
4231 p.SendInitialAvatarDataToAgent(this);
4232
4233 if (p.ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && GodLevel < 200)
4234 return;
4235
4236 p.SendAppearanceToAgentNF(this);
4237 p.SendAnimPackToAgentNF(this);
4238 p.SendAttachmentsToAgentNF(this);
4239 count++;
4240 });
4241
4242 m_scene.StatsReporter.AddAgentUpdates(count);
4243>>>>>>> avn/ubitvar
3453 } 4244 }
3454 4245
3455 public void SendAvatarDataToAllClients() 4246 public void SendAvatarDataToAllClients()
@@ -3470,32 +4261,43 @@ namespace OpenSim.Region.Framework.Scenes
3470 m_log.WarnFormat( 4261 m_log.WarnFormat(
3471 "[SCENE PRESENCE]: Attempt to send avatar data from a child agent for {0} in {1}", 4262 "[SCENE PRESENCE]: Attempt to send avatar data from a child agent for {0} in {1}",
3472 Name, Scene.RegionInfo.RegionName); 4263 Name, Scene.RegionInfo.RegionName);
3473
3474 return; 4264 return;
3475 } 4265 }
3476 4266
3477 m_lastSize = Appearance.AvatarSize; 4267 m_lastSize = Appearance.AvatarSize;
3478
3479 int count = 0; 4268 int count = 0;
4269
3480 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 4270 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
3481 { 4271 {
4272<<<<<<< HEAD
3482 if (full) 4273 if (full)
3483 SendAvatarDataToClient(scenePresence); 4274 SendAvatarDataToClient(scenePresence);
3484 else 4275 else
3485 scenePresence.ControllingClient.SendAvatarDataImmediate(this); 4276 scenePresence.ControllingClient.SendAvatarDataImmediate(this);
4277=======
4278 SendAvatarDataToAgent(scenePresence);
4279>>>>>>> avn/ubitvar
3486 count++; 4280 count++;
3487 }); 4281 });
3488 4282
3489 m_scene.StatsReporter.AddAgentUpdates(count); 4283 m_scene.StatsReporter.AddAgentUpdates(count);
3490 } 4284 }
3491 4285
4286<<<<<<< HEAD
3492 /// <summary> 4287 /// <summary>
3493 /// Send avatar data for all other root agents to this agent, this agent 4288 /// Send avatar data for all other root agents to this agent, this agent
3494 /// can be either a child or root 4289 /// can be either a child or root
3495 /// </summary> 4290 /// </summary>
3496 public void SendOtherAgentsAvatarDataToClient() 4291 public void SendOtherAgentsAvatarDataToClient()
4292=======
4293 // sends avatar object to all clients so they cross it into region
4294 // then sends kills to hide
4295 public void SendInitialAvatarDataToAllAgents(List<ScenePresence> presences)
4296>>>>>>> avn/ubitvar
3497 { 4297 {
4298 m_lastSize = Appearance.AvatarSize;
3498 int count = 0; 4299 int count = 0;
4300<<<<<<< HEAD
3499 m_scene.ForEachRootScenePresence(delegate(ScenePresence scenePresence) 4301 m_scene.ForEachRootScenePresence(delegate(ScenePresence scenePresence)
3500 { 4302 {
3501 // only send information about other root agents 4303 // only send information about other root agents
@@ -3505,29 +4307,65 @@ namespace OpenSim.Region.Framework.Scenes
3505 scenePresence.SendAvatarDataToClient(this); 4307 scenePresence.SendAvatarDataToClient(this);
3506 count++; 4308 count++;
3507 }); 4309 });
4310=======
4311>>>>>>> avn/ubitvar
3508 4312
4313 foreach (ScenePresence p in presences)
4314 {
4315 p.ControllingClient.SendAvatarDataImmediate(this);
4316 if (p != this && ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
4317 // either just kill the object
4318 // p.ControllingClient.SendKillObject(new List<uint> {LocalId});
4319 // or also attachments viewer may still know about
4320 SendKillTo(p);
4321 count++;
4322 }
3509 m_scene.StatsReporter.AddAgentUpdates(count); 4323 m_scene.StatsReporter.AddAgentUpdates(count);
3510 } 4324 }
3511 4325
4326 public void SendInitialAvatarDataToAgent(ScenePresence p)
4327 {
4328 p.ControllingClient.SendAvatarDataImmediate(this);
4329 if (p != this && ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
4330 // either just kill the object
4331 // p.ControllingClient.SendKillObject(new List<uint> {LocalId});
4332 // or also attachments viewer may still know about
4333 SendKillTo(p);
4334 }
4335
3512 /// <summary> 4336 /// <summary>
3513 /// Send avatar data to an agent. 4337 /// Send avatar data to an agent.
3514 /// </summary> 4338 /// </summary>
3515 /// <param name="avatar"></param> 4339 /// <param name="avatar"></param>
3516 public void SendAvatarDataToClient(ScenePresence avatar) 4340 public void SendAvatarDataToClient(ScenePresence avatar)
3517 { 4341 {
4342<<<<<<< HEAD
3518 //m_log.DebugFormat("[SCENE PRESENCE] SendAvatarDataToClient from {0} ({1}) to {2} ({3})", Name, UUID, avatar.Name, avatar.UUID); 4343 //m_log.DebugFormat("[SCENE PRESENCE] SendAvatarDataToClient from {0} ({1}) to {2} ({3})", Name, UUID, avatar.Name, avatar.UUID);
3519 4344
4345=======
4346 //m_log.DebugFormat("[SCENE PRESENCE] SendAvatarDataToAgent from {0} ({1}) to {2} ({3})", Name, UUID, avatar.Name, avatar.UUID);
4347 if (ParcelHideThisAvatar && currentParcelUUID != avatar.currentParcelUUID && avatar.GodLevel < 200)
4348 return;
4349>>>>>>> avn/ubitvar
3520 avatar.ControllingClient.SendAvatarDataImmediate(this); 4350 avatar.ControllingClient.SendAvatarDataImmediate(this);
3521 Animator.SendAnimPackToClient(avatar.ControllingClient);
3522 } 4351 }
3523 4352
4353 public void SendAvatarDataToAgentNF(ScenePresence avatar)
4354 {
4355 avatar.ControllingClient.SendAvatarDataImmediate(this);
4356 }
4357
3524 /// <summary> 4358 /// <summary>
3525 /// Send this agent's appearance to all other root and child agents in the scene 4359 /// Send this agent's appearance to all other root and child agents in the scene
3526 /// This agent must be root. 4360 /// This agent must be root.
3527 /// </summary> 4361 /// </summary>
3528 public void SendAppearanceToAllOtherClients() 4362 public void SendAppearanceToAllOtherClients()
3529 { 4363 {
4364<<<<<<< HEAD
3530// m_log.DebugFormat("[SCENE PRESENCE] SendAppearanceToAllOtherClients: {0} {1}", Name, UUID); 4365// m_log.DebugFormat("[SCENE PRESENCE] SendAppearanceToAllOtherClients: {0} {1}", Name, UUID);
4366=======
4367 // m_log.DebugFormat("[SCENE PRESENCE] SendAppearanceToAllOtherAgents: {0} {1}", Name, UUID);
4368>>>>>>> avn/ubitvar
3531 4369
3532 // only send update from root agents to other clients; children are only "listening posts" 4370 // only send update from root agents to other clients; children are only "listening posts"
3533 if (IsChildAgent) 4371 if (IsChildAgent)
@@ -3538,7 +4376,7 @@ namespace OpenSim.Region.Framework.Scenes
3538 4376
3539 return; 4377 return;
3540 } 4378 }
3541 4379
3542 int count = 0; 4380 int count = 0;
3543 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 4381 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
3544 { 4382 {
@@ -3549,6 +4387,7 @@ namespace OpenSim.Region.Framework.Scenes
3549 SendAppearanceToClient(scenePresence); 4387 SendAppearanceToClient(scenePresence);
3550 count++; 4388 count++;
3551 }); 4389 });
4390<<<<<<< HEAD
3552 4391
3553 m_scene.StatsReporter.AddAgentUpdates(count); 4392 m_scene.StatsReporter.AddAgentUpdates(count);
3554 } 4393 }
@@ -3572,6 +4411,8 @@ namespace OpenSim.Region.Framework.Scenes
3572 count++; 4411 count++;
3573 }); 4412 });
3574 4413
4414=======
4415>>>>>>> avn/ubitvar
3575 m_scene.StatsReporter.AddAgentUpdates(count); 4416 m_scene.StatsReporter.AddAgentUpdates(count);
3576 } 4417 }
3577 4418
@@ -3583,11 +4424,62 @@ namespace OpenSim.Region.Framework.Scenes
3583 { 4424 {
3584// m_log.DebugFormat( 4425// m_log.DebugFormat(
3585// "[SCENE PRESENCE]: Sending appearance data from {0} {1} to {2} {3}", Name, m_uuid, avatar.Name, avatar.UUID); 4426// "[SCENE PRESENCE]: Sending appearance data from {0} {1} to {2} {3}", Name, m_uuid, avatar.Name, avatar.UUID);
4427 if (ParcelHideThisAvatar && currentParcelUUID != avatar.currentParcelUUID && avatar.GodLevel < 200)
4428 return;
4429 SendAppearanceToAgentNF(avatar);
4430 }
3586 4431
4432 public void SendAppearanceToAgentNF(ScenePresence avatar)
4433 {
3587 avatar.ControllingClient.SendAppearance( 4434 avatar.ControllingClient.SendAppearance(
3588 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 4435 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
4436 }
3589 4437
3590 4438 public void SendAnimPackToAgent(ScenePresence p)
4439 {
4440 if (IsChildAgent || Animator == null)
4441 return;
4442
4443 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
4444 return;
4445
4446 Animator.SendAnimPackToClient(p.ControllingClient);
4447 }
4448
4449 public void SendAnimPackToAgent(ScenePresence p, UUID[] animations, int[] seqs, UUID[] objectIDs)
4450 {
4451 if (IsChildAgent)
4452 return;
4453
4454 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
4455 return;
4456
4457 p.ControllingClient.SendAnimations(animations, seqs, ControllingClient.AgentId, objectIDs);
4458 }
4459
4460 public void SendAnimPackToAgentNF(ScenePresence p)
4461 {
4462 if (IsChildAgent || Animator == null)
4463 return;
4464 Animator.SendAnimPackToClient(p.ControllingClient);
4465 }
4466
4467 public void SendAnimPackToAgentNF(ScenePresence p, UUID[] animations, int[] seqs, UUID[] objectIDs)
4468 {
4469 p.ControllingClient.SendAnimations(animations, seqs, ControllingClient.AgentId, objectIDs);
4470 }
4471
4472 public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs)
4473 {
4474 if (IsChildAgent)
4475 return;
4476
4477 m_scene.ForEachScenePresence(delegate(ScenePresence p)
4478 {
4479 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
4480 return;
4481 p.ControllingClient.SendAnimations(animations, seqs, ControllingClient.AgentId, objectIDs);
4482 });
3591 } 4483 }
3592 4484
3593 #endregion 4485 #endregion
@@ -3611,6 +4503,7 @@ namespace OpenSim.Region.Framework.Scenes
3611 m_lastChildAgentUpdatePosition = AbsolutePosition; 4503 m_lastChildAgentUpdatePosition = AbsolutePosition;
3612// m_lastChildAgentUpdateCamPosition = CameraPosition; 4504// m_lastChildAgentUpdateCamPosition = CameraPosition;
3613 4505
4506/* cadu is not used
3614 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 4507 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
3615 cadu.ActiveGroupID = UUID.Zero.Guid; 4508 cadu.ActiveGroupID = UUID.Zero.Guid;
3616 cadu.AgentID = UUID.Guid; 4509 cadu.AgentID = UUID.Guid;
@@ -3624,6 +4517,7 @@ namespace OpenSim.Region.Framework.Scenes
3624 4517
3625 // Throttles 4518 // Throttles
3626 float multiplier = 1; 4519 float multiplier = 1;
4520
3627 int childRegions = KnownRegionCount; 4521 int childRegions = KnownRegionCount;
3628 if (childRegions != 0) 4522 if (childRegions != 0)
3629 multiplier = 1f / childRegions; 4523 multiplier = 1f / childRegions;
@@ -3634,9 +4528,22 @@ namespace OpenSim.Region.Framework.Scenes
3634 4528
3635 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); 4529 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier);
3636 cadu.Velocity = Velocity; 4530 cadu.Velocity = Velocity;
3637 4531*/
3638 AgentPosition agentpos = new AgentPosition(); 4532 AgentPosition agentpos = new AgentPosition();
3639 agentpos.CopyFrom(cadu, ControllingClient.SessionId); 4533// agentpos.CopyFrom(cadu, ControllingClient.SessionId);
4534
4535 agentpos.AgentID = new UUID(UUID.Guid);
4536 agentpos.SessionID = ControllingClient.SessionId;
4537
4538 agentpos.Size = Appearance.AvatarSize;
4539
4540 agentpos.Center = CameraPosition;
4541 agentpos.Far = DrawDistance;
4542 agentpos.Position = AbsolutePosition;
4543 agentpos.Velocity = Velocity;
4544 agentpos.RegionHandle = RegionHandle;
4545 agentpos.Throttles = ControllingClient.GetThrottlesPacked(1);
4546
3640 4547
3641 // Let's get this out of the update loop 4548 // Let's get this out of the update loop
3642 Util.FireAndForget( 4549 Util.FireAndForget(
@@ -3657,7 +4564,7 @@ namespace OpenSim.Region.Framework.Scenes
3657 protected void CheckForBorderCrossing() 4564 protected void CheckForBorderCrossing()
3658 { 4565 {
3659 // Check that we we are not a child 4566 // Check that we we are not a child
3660 if (IsChildAgent) 4567 if (IsChildAgent || IsInTransit)
3661 return; 4568 return;
3662 4569
3663 // If we don't have a PhysActor, we can't cross anyway 4570 // If we don't have a PhysActor, we can't cross anyway
@@ -3667,6 +4574,7 @@ namespace OpenSim.Region.Framework.Scenes
3667 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero) 4574 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
3668 return; 4575 return;
3669 4576
4577<<<<<<< HEAD
3670 if (IsInTransit) 4578 if (IsInTransit)
3671 return; 4579 return;
3672 4580
@@ -3740,6 +4648,70 @@ namespace OpenSim.Region.Framework.Scenes
3740 ret.Y = extentY - borderFudge; 4648 ret.Y = extentY - borderFudge;
3741 4649
3742 return ret; 4650 return ret;
4651=======
4652 Vector3 pos2 = AbsolutePosition;
4653 Vector3 vel = Velocity;
4654
4655 float timeStep = 0.1f;
4656 pos2.X += vel.X * timeStep;
4657 pos2.Y += vel.Y * timeStep;
4658 pos2.Z += vel.Z * timeStep;
4659
4660// m_log.DebugFormat(
4661// "[SCENE PRESENCE]: Testing border check for projected position {0} of {1} in {2}",
4662// pos2, Name, Scene.Name);
4663
4664 if (Scene.PositionIsInCurrentRegion(pos2))
4665 return;
4666
4667 if (!CrossToNewRegion() && m_requestedSitTargetUUID == UUID.Zero)
4668 {
4669 // we don't have entity transfer module
4670 Vector3 pos = AbsolutePosition;
4671 float px = pos.X;
4672 if (px < 0)
4673 pos.X += Velocity.X * 2;
4674 else if (px > m_scene.RegionInfo.RegionSizeX)
4675 pos.X -= Velocity.X * 2;
4676
4677 float py = pos.Y;
4678 if (py < 0)
4679 pos.Y += Velocity.Y * 2;
4680 else if (py > m_scene.RegionInfo.RegionSizeY)
4681 pos.Y -= Velocity.Y * 2;
4682
4683 Velocity = Vector3.Zero;
4684 AbsolutePosition = pos;
4685 }
4686 }
4687
4688 public void CrossToNewRegionFail()
4689 {
4690 if (m_requestedSitTargetUUID == UUID.Zero)
4691 {
4692 bool isFlying = Flying;
4693 RemoveFromPhysicalScene();
4694
4695 Vector3 pos = AbsolutePosition;
4696 float px = pos.X;
4697 if (px < 0)
4698 pos.X += Velocity.X * 2;
4699 else if (px > m_scene.RegionInfo.RegionSizeX)
4700 pos.X -= Velocity.X * 2;
4701
4702 float py = pos.Y;
4703 if (py < 0)
4704 pos.Y += Velocity.Y * 2;
4705 else if (py > m_scene.RegionInfo.RegionSizeY)
4706 pos.Y -= Velocity.Y * 2;
4707
4708 Velocity = Vector3.Zero;
4709 AbsolutePosition = pos;
4710
4711 AddToPhysicalScene(isFlying);
4712 }
4713
4714>>>>>>> avn/ubitvar
3743 } 4715 }
3744 4716
3745 /// <summary> 4717 /// <summary>
@@ -3750,16 +4722,25 @@ namespace OpenSim.Region.Framework.Scenes
3750 /// </summary> 4722 /// </summary>
3751 protected bool CrossToNewRegion() 4723 protected bool CrossToNewRegion()
3752 { 4724 {
4725 bool result = false;
4726// parcelRegionCross(false);
3753 try 4727 try
3754 { 4728 {
3755 return m_scene.CrossAgentToNewRegion(this, Flying); 4729 result = m_scene.CrossAgentToNewRegion(this, Flying);
3756 } 4730 }
3757 catch 4731 catch
3758 { 4732 {
3759 return m_scene.CrossAgentToNewRegion(this, false); 4733// result = m_scene.CrossAgentToNewRegion(this, false);
4734 return false;
3760 } 4735 }
4736 // if(!result)
4737 // parcelRegionCross(true);
4738
4739 return result;
4740
3761 } 4741 }
3762 4742
4743/* useless. Either use MakeChild or delete the presence
3763 public void Reset() 4744 public void Reset()
3764 { 4745 {
3765// m_log.DebugFormat("[SCENE PRESENCE]: Resetting {0} in {1}", Name, Scene.RegionInfo.RegionName); 4746// m_log.DebugFormat("[SCENE PRESENCE]: Resetting {0} in {1}", Name, Scene.RegionInfo.RegionName);
@@ -3770,7 +4751,7 @@ namespace OpenSim.Region.Framework.Scenes
3770 4751
3771 Animator.ResetAnimations(); 4752 Animator.ResetAnimations();
3772 } 4753 }
3773 4754*/
3774 /// <summary> 4755 /// <summary>
3775 /// Computes which child agents to close when the scene presence moves to another region. 4756 /// Computes which child agents to close when the scene presence moves to another region.
3776 /// Removes those regions from m_knownRegions. 4757 /// Removes those regions from m_knownRegions.
@@ -3778,8 +4759,9 @@ namespace OpenSim.Region.Framework.Scenes
3778 /// <param name="newRegionX">The new region's x on the map</param> 4759 /// <param name="newRegionX">The new region's x on the map</param>
3779 /// <param name="newRegionY">The new region's y on the map</param> 4760 /// <param name="newRegionY">The new region's y on the map</param>
3780 /// <returns></returns> 4761 /// <returns></returns>
3781 public void CloseChildAgents(uint newRegionX, uint newRegionY) 4762 public void CloseChildAgents(ulong newRegionHandle, int newRegionSizeX, int newRegionSizeY)
3782 { 4763 {
4764 uint newRegionX, newRegionY;
3783 List<ulong> byebyeRegions = new List<ulong>(); 4765 List<ulong> byebyeRegions = new List<ulong>();
3784 List<ulong> knownRegions = KnownRegionHandles; 4766 List<ulong> knownRegions = KnownRegionHandles;
3785 m_log.DebugFormat( 4767 m_log.DebugFormat(
@@ -3787,11 +4769,17 @@ namespace OpenSim.Region.Framework.Scenes
3787 knownRegions.Count, Scene.RegionInfo.RegionName); 4769 knownRegions.Count, Scene.RegionInfo.RegionName);
3788 //DumpKnownRegions(); 4770 //DumpKnownRegions();
3789 4771
4772 Util.RegionHandleToRegionLoc(newRegionHandle, out newRegionX, out newRegionY);
4773
4774 uint x, y;
4775 spRegionSizeInfo regInfo;
4776
3790 foreach (ulong handle in knownRegions) 4777 foreach (ulong handle in knownRegions)
3791 { 4778 {
3792 // Don't close the agent on this region yet 4779 // Don't close the agent on this region yet
3793 if (handle != Scene.RegionInfo.RegionHandle) 4780 if (handle != Scene.RegionInfo.RegionHandle)
3794 { 4781 {
4782<<<<<<< HEAD
3795 uint x, y; 4783 uint x, y;
3796 Util.RegionHandleToRegionLoc(handle, out x, out y); 4784 Util.RegionHandleToRegionLoc(handle, out x, out y);
3797 4785
@@ -3800,8 +4788,27 @@ namespace OpenSim.Region.Framework.Scenes
3800 float dist = (float)Math.Max(Scene.DefaultDrawDistance, 4788 float dist = (float)Math.Max(Scene.DefaultDrawDistance,
3801 (float)Math.Max(Scene.RegionInfo.RegionSizeX, Scene.RegionInfo.RegionSizeY)); 4789 (float)Math.Max(Scene.RegionInfo.RegionSizeX, Scene.RegionInfo.RegionSizeY));
3802 if (Util.IsOutsideView(dist, x, newRegionX, y, newRegionY)) 4790 if (Util.IsOutsideView(dist, x, newRegionX, y, newRegionY))
4791=======
4792 Util.RegionHandleToRegionLoc(handle, out x, out y);
4793 if (m_knownChildRegionsSizeInfo.TryGetValue(handle, out regInfo))
3803 { 4794 {
3804 byebyeRegions.Add(handle); 4795
4796 // m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
4797 // m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
4798 if (Util.IsOutsideView(DrawDistance, x, newRegionX, y, newRegionY,
4799 regInfo.sizeX, regInfo.sizeY, newRegionSizeX, newRegionSizeY))
4800 {
4801 byebyeRegions.Add(handle);
4802 }
4803 }
4804 else
4805>>>>>>> avn/ubitvar
4806 {
4807 if (Util.IsOutsideView(DrawDistance, x, newRegionX, y, newRegionY,
4808 (int)Constants.RegionSize, (int)Constants.RegionSize, newRegionSizeX, newRegionSizeY))
4809 {
4810 byebyeRegions.Add(handle);
4811 }
3805 } 4812 }
3806 } 4813 }
3807 } 4814 }
@@ -3820,6 +4827,7 @@ namespace OpenSim.Region.Framework.Scenes
3820 foreach (ulong handle in byebyeRegions) 4827 foreach (ulong handle in byebyeRegions)
3821 { 4828 {
3822 RemoveNeighbourRegion(handle); 4829 RemoveNeighbourRegion(handle);
4830 Scene.CapsModule.DropChildSeed(UUID, handle);
3823 } 4831 }
3824 } 4832 }
3825 4833
@@ -3831,6 +4839,8 @@ namespace OpenSim.Region.Framework.Scenes
3831 /// </summary> 4839 /// </summary>
3832 public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus) 4840 public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus)
3833 { 4841 {
4842 int oldgodlevel = GodLevel;
4843
3834 if (godStatus) 4844 if (godStatus)
3835 { 4845 {
3836 // For now, assign god level 200 to anyone 4846 // For now, assign god level 200 to anyone
@@ -3851,6 +4861,9 @@ namespace OpenSim.Region.Framework.Scenes
3851 } 4861 }
3852 4862
3853 ControllingClient.SendAdminResponse(token, (uint)GodLevel); 4863 ControllingClient.SendAdminResponse(token, (uint)GodLevel);
4864
4865 if(oldgodlevel != GodLevel)
4866 parcelGodCheck(m_currentParcelUUID, GodLevel >= 200);
3854 } 4867 }
3855 4868
3856 #region Child Agent Updates 4869 #region Child Agent Updates
@@ -3868,6 +4881,11 @@ namespace OpenSim.Region.Framework.Scenes
3868 4881
3869 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 4882 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3870 4883
4884 private void RaiseUpdateThrottles()
4885 {
4886 m_scene.EventManager.TriggerThrottleUpdate(this);
4887 }
4888
3871 /// <summary> 4889 /// <summary>
3872 /// This updates important decision making data about a child agent 4890 /// This updates important decision making data about a child agent
3873 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 4891 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3877,6 +4895,7 @@ namespace OpenSim.Region.Framework.Scenes
3877 if (!IsChildAgent) 4895 if (!IsChildAgent)
3878 return; 4896 return;
3879 4897
4898<<<<<<< HEAD
3880// m_log.DebugFormat( 4899// m_log.DebugFormat(
3881// "[SCENE PRESENCE]: ChildAgentPositionUpdate for {0} in {1}, tRegion {2},{3}, rRegion {4},{5}, pos {6}", 4900// "[SCENE PRESENCE]: ChildAgentPositionUpdate for {0} in {1}, tRegion {2},{3}, rRegion {4},{5}, pos {6}",
3882// Name, Scene.Name, tRegionX, tRegionY, rRegionX, rRegionY, cAgentData.Position); 4901// Name, Scene.Name, tRegionX, tRegionY, rRegionX, rRegionY, cAgentData.Position);
@@ -3886,6 +4905,13 @@ namespace OpenSim.Region.Framework.Scenes
3886 // uint 4905 // uint
3887 int shiftx = (int)(((int)rRegionX - (int)tRegionX) * Constants.RegionSize); 4906 int shiftx = (int)(((int)rRegionX - (int)tRegionX) * Constants.RegionSize);
3888 int shifty = (int)(((int)rRegionY - (int)tRegionY) * Constants.RegionSize); 4907 int shifty = (int)(((int)rRegionY - (int)tRegionY) * Constants.RegionSize);
4908=======
4909 RegionHandle = cAgentData.RegionHandle;
4910
4911 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY);
4912 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
4913 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
4914>>>>>>> avn/ubitvar
3889 4915
3890 Vector3 offset = new Vector3(shiftx, shifty, 0f); 4916 Vector3 offset = new Vector3(shiftx, shifty, 0f);
3891 4917
@@ -3893,7 +4919,11 @@ namespace OpenSim.Region.Framework.Scenes
3893 // changes, then start using the agent's drawdistance rather than the 4919 // changes, then start using the agent's drawdistance rather than the
3894 // region's draw distance. 4920 // region's draw distance.
3895 DrawDistance = cAgentData.Far; 4921 DrawDistance = cAgentData.Far;
4922<<<<<<< HEAD
3896 // DrawDistance = Scene.DefaultDrawDistance; 4923 // DrawDistance = Scene.DefaultDrawDistance;
4924=======
4925// DrawDistance = Scene.DefaultDrawDistance;
4926>>>>>>> avn/ubitvar
3897 4927
3898 if (cAgentData.Position != marker) // UGH!! 4928 if (cAgentData.Position != marker) // UGH!!
3899 m_pos = cAgentData.Position + offset; 4929 m_pos = cAgentData.Position + offset;
@@ -3907,10 +4937,36 @@ namespace OpenSim.Region.Framework.Scenes
3907 CameraPosition = cAgentData.Center + offset; 4937 CameraPosition = cAgentData.Center + offset;
3908 4938
3909 if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0) 4939 if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0)
3910 ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); 4940 {
4941 // some scaling factor
4942 float x = m_pos.X;
4943 if (x > m_scene.RegionInfo.RegionSizeX)
4944 x -= m_scene.RegionInfo.RegionSizeX;
4945 float y = m_pos.Y;
4946 if (y > m_scene.RegionInfo.RegionSizeY)
4947 y -= m_scene.RegionInfo.RegionSizeY;
4948
4949 x = x * x + y * y;
4950
4951 const float distScale = 0.4f / Constants.RegionSize / Constants.RegionSize;
4952 float factor = 1.0f - distScale * x;
4953 if (factor < 0.2f)
4954 factor = 0.2f;
4955
4956 ControllingClient.SetChildAgentThrottle(cAgentData.Throttles,factor);
4957 }
4958
4959 if(cAgentData.ChildrenCapSeeds != null && cAgentData.ChildrenCapSeeds.Count >0)
4960 {
4961 if (Scene.CapsModule != null)
4962 {
4963 Scene.CapsModule.SetChildrenSeed(UUID, cAgentData.ChildrenCapSeeds);
4964 }
4965
4966 KnownRegions = cAgentData.ChildrenCapSeeds;
4967 }
3911 4968
3912 //cAgentData.AVHeight; 4969 //cAgentData.AVHeight;
3913 RegionHandle = cAgentData.RegionHandle;
3914 //m_velocity = cAgentData.Velocity; 4970 //m_velocity = cAgentData.Velocity;
3915 } 4971 }
3916 4972
@@ -3932,16 +4988,7 @@ namespace OpenSim.Region.Framework.Scenes
3932 cAgent.Far = DrawDistance; 4988 cAgent.Far = DrawDistance;
3933 4989
3934 // Throttles 4990 // Throttles
3935 float multiplier = 1; 4991 cAgent.Throttles = ControllingClient.GetThrottlesPacked(1);
3936 int childRegions = KnownRegionCount;
3937 if (childRegions != 0)
3938 multiplier = 1f / childRegions;
3939
3940 // Minimum throttle for a child region is 1/4 of the root region throttle
3941 if (multiplier <= 0.25f)
3942 multiplier = 0.25f;
3943
3944 cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier);
3945 4992
3946 cAgent.HeadRotation = m_headrotation; 4993 cAgent.HeadRotation = m_headrotation;
3947 cAgent.BodyRotation = Rotation; 4994 cAgent.BodyRotation = Rotation;
@@ -3954,7 +5001,8 @@ namespace OpenSim.Region.Framework.Scenes
3954 5001
3955 cAgent.AlwaysRun = SetAlwaysRun; 5002 cAgent.AlwaysRun = SetAlwaysRun;
3956 5003
3957 cAgent.Appearance = new AvatarAppearance(Appearance); 5004 // make clear we want the all thing
5005 cAgent.Appearance = new AvatarAppearance(Appearance,true,true);
3958 5006
3959 cAgent.ParentPart = ParentUUID; 5007 cAgent.ParentPart = ParentUUID;
3960 cAgent.SitOffset = PrevSitOffset; 5008 cAgent.SitOffset = PrevSitOffset;
@@ -3980,12 +5028,20 @@ namespace OpenSim.Region.Framework.Scenes
3980 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation; 5028 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
3981 cAgent.AnimState = Animator.Animations.ImplicitDefaultAnimation; 5029 cAgent.AnimState = Animator.Animations.ImplicitDefaultAnimation;
3982 5030
5031 cAgent.MovementAnimationOverRides = Overrides.CloneAOPairs();
5032
5033 cAgent.MotionState = (byte)Animator.currentControlState;
5034
3983 if (Scene.AttachmentsModule != null) 5035 if (Scene.AttachmentsModule != null)
3984 Scene.AttachmentsModule.CopyAttachments(this, cAgent); 5036 Scene.AttachmentsModule.CopyAttachments(this, cAgent);
3985 } 5037 }
3986 5038
3987 private void CopyFrom(AgentData cAgent) 5039 private void CopyFrom(AgentData cAgent)
3988 { 5040 {
5041<<<<<<< HEAD
5042=======
5043
5044>>>>>>> avn/ubitvar
3989 m_callbackURI = cAgent.CallbackURI; 5045 m_callbackURI = cAgent.CallbackURI;
3990// m_log.DebugFormat( 5046// m_log.DebugFormat(
3991// "[SCENE PRESENCE]: Set callback for {0} in {1} to {2} in CopyFrom()", 5047// "[SCENE PRESENCE]: Set callback for {0} in {1} to {2} in CopyFrom()",
@@ -4004,7 +5060,20 @@ namespace OpenSim.Region.Framework.Scenes
4004 // changes, then start using the agent's drawdistance rather than the 5060 // changes, then start using the agent's drawdistance rather than the
4005 // region's draw distance. 5061 // region's draw distance.
4006 DrawDistance = cAgent.Far; 5062 DrawDistance = cAgent.Far;
5063<<<<<<< HEAD
4007 // DrawDistance = Scene.DefaultDrawDistance; 5064 // DrawDistance = Scene.DefaultDrawDistance;
5065=======
5066 //DrawDistance = Scene.DefaultDrawDistance;
5067
5068 if (cAgent.ChildrenCapSeeds != null && cAgent.ChildrenCapSeeds.Count > 0)
5069 {
5070 if (Scene.CapsModule != null)
5071 {
5072 Scene.CapsModule.SetChildrenSeed(UUID, cAgent.ChildrenCapSeeds);
5073 }
5074 KnownRegions = cAgent.ChildrenCapSeeds;
5075 }
5076>>>>>>> avn/ubitvar
4008 5077
4009 if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) 5078 if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0)
4010 ControllingClient.SetChildAgentThrottle(cAgent.Throttles); 5079 ControllingClient.SetChildAgentThrottle(cAgent.Throttles);
@@ -4017,14 +5086,17 @@ namespace OpenSim.Region.Framework.Scenes
4017 GodLevel = cAgent.GodLevel; 5086 GodLevel = cAgent.GodLevel;
4018 SetAlwaysRun = cAgent.AlwaysRun; 5087 SetAlwaysRun = cAgent.AlwaysRun;
4019 5088
5089
4020 Appearance = new AvatarAppearance(cAgent.Appearance); 5090 Appearance = new AvatarAppearance(cAgent.Appearance);
5091/*
5092 bool isFlying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
5093
4021 if (PhysicsActor != null) 5094 if (PhysicsActor != null)
4022 { 5095 {
4023 bool isFlying = Flying;
4024 RemoveFromPhysicalScene(); 5096 RemoveFromPhysicalScene();
4025 AddToPhysicalScene(isFlying); 5097 AddToPhysicalScene(isFlying);
4026 } 5098 }
4027 5099*/
4028 try 5100 try
4029 { 5101 {
4030 lock (scriptedcontrols) 5102 lock (scriptedcontrols)
@@ -4048,15 +5120,22 @@ namespace OpenSim.Region.Framework.Scenes
4048 } 5120 }
4049 catch { } 5121 catch { }
4050 5122
5123 Animator.ResetAnimations();
5124
5125 Overrides.CopyAOPairsFrom(cAgent.MovementAnimationOverRides);
5126
4051 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object? 5127 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object?
4052 if (cAgent.Anims != null)
4053 Animator.Animations.FromArray(cAgent.Anims);
4054 if (cAgent.DefaultAnim != null) 5128 if (cAgent.DefaultAnim != null)
4055 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero); 5129 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
4056 if (cAgent.AnimState != null) 5130 if (cAgent.AnimState != null)
4057 Animator.Animations.SetImplicitDefaultAnimation(cAgent.AnimState.AnimID, cAgent.AnimState.SequenceNum, UUID.Zero); 5131 Animator.Animations.SetImplicitDefaultAnimation(cAgent.AnimState.AnimID, cAgent.AnimState.SequenceNum, UUID.Zero);
5132 if (cAgent.Anims != null)
5133 Animator.Animations.FromArray(cAgent.Anims);
5134 if (cAgent.MotionState != 0)
5135 Animator.currentControlState = (ScenePresenceAnimator.motionControlStates) cAgent.MotionState;
4058 5136
4059 if (Scene.AttachmentsModule != null) 5137 if (Scene.AttachmentsModule != null)
5138<<<<<<< HEAD
4060 { 5139 {
4061 // If the JobEngine is running we can schedule this job now and continue rather than waiting for all 5140 // If the JobEngine is running we can schedule this job now and continue rather than waiting for all
4062 // attachments to copy, which might take a long time in the Hypergrid case as the entire inventory 5141 // attachments to copy, which might take a long time in the Hypergrid case as the entire inventory
@@ -4078,6 +5157,13 @@ namespace OpenSim.Region.Framework.Scenes
4078 // script attachments can outrace this thread. 5157 // script attachments can outrace this thread.
4079 lock (m_originRegionIDAccessLock) 5158 lock (m_originRegionIDAccessLock)
4080 m_originRegionID = cAgent.RegionID; 5159 m_originRegionID = cAgent.RegionID;
5160=======
5161 Scene.AttachmentsModule.CopyAttachments(cAgent, this);
5162
5163 lock (m_originRegionIDAccessLock)
5164 m_originRegionID = cAgent.RegionID;
5165
5166>>>>>>> avn/ubitvar
4081 } 5167 }
4082 5168
4083 public bool CopyAgent(out IAgentData agent) 5169 public bool CopyAgent(out IAgentData agent)
@@ -4094,6 +5180,8 @@ namespace OpenSim.Region.Framework.Scenes
4094 /// </summary> 5180 /// </summary>
4095 public void UpdateMovement() 5181 public void UpdateMovement()
4096 { 5182 {
5183 if (IsInTransit)
5184 return;
4097 if (m_forceToApply.HasValue) 5185 if (m_forceToApply.HasValue)
4098 { 5186 {
4099 Vector3 force = m_forceToApply.Value; 5187 Vector3 force = m_forceToApply.Value;
@@ -4131,9 +5219,15 @@ namespace OpenSim.Region.Framework.Scenes
4131 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying); 5219 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
4132*/ 5220*/
4133 5221
5222<<<<<<< HEAD
4134 PhysicsActor = m_scene.PhysicsScene.AddAvatar( 5223 PhysicsActor = m_scene.PhysicsScene.AddAvatar(
4135 LocalId, Firstname + "." + Lastname, AbsolutePosition, Velocity, 5224 LocalId, Firstname + "." + Lastname, AbsolutePosition, Velocity,
4136 Appearance.AvatarBoxSize, isFlying); 5225 Appearance.AvatarBoxSize, isFlying);
5226=======
5227 PhysicsActor = scene.AddAvatar(
5228 LocalId, Firstname + "." + Lastname, pVec,
5229 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
5230>>>>>>> avn/ubitvar
4137 5231
4138 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 5232 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
4139 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 5233 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
@@ -4168,7 +5262,9 @@ namespace OpenSim.Region.Framework.Scenes
4168 { 5262 {
4169 if (IsChildAgent || Animator == null) 5263 if (IsChildAgent || Animator == null)
4170 return; 5264 return;
4171 5265
5266 if(IsInTransit)
5267 return;
4172 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 5268 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
4173 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents( 5269 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents(
4174 // as of this comment the interval is set in AddToPhysicalScene 5270 // as of this comment the interval is set in AddToPhysicalScene
@@ -4192,7 +5288,49 @@ namespace OpenSim.Region.Framework.Scenes
4192// m_lastColCount = coldata.Count; 5288// m_lastColCount = coldata.Count;
4193// } 5289// }
4194 5290
4195 CollisionPlane = Vector4.UnitW; 5291 if (coldata.Count != 0)
5292 {
5293/*
5294 switch (Animator.CurrentMovementAnimation)
5295 {
5296 case "STAND":
5297 case "WALK":
5298 case "RUN":
5299 case "CROUCH":
5300 case "CROUCHWALK":
5301 {
5302 */
5303 ContactPoint lowest;
5304 lowest.SurfaceNormal = Vector3.Zero;
5305 lowest.Position = Vector3.Zero;
5306 lowest.Position.Z = float.MaxValue;
5307
5308 foreach (ContactPoint contact in coldata.Values)
5309 {
5310
5311 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
5312 {
5313 lowest = contact;
5314 }
5315 }
5316
5317 if (lowest.Position.Z != float.MaxValue)
5318 {
5319 lowest.SurfaceNormal = -lowest.SurfaceNormal;
5320 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
5321 }
5322 else
5323 CollisionPlane = Vector4.UnitW;
5324/*
5325 }
5326 break;
5327 }
5328*/
5329 }
5330 else
5331 CollisionPlane = Vector4.UnitW;
5332
5333 RaiseCollisionScriptEvents(coldata);
4196 5334
4197 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 5335 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
4198 if (Invulnerable || GodLevel > 0) 5336 if (Invulnerable || GodLevel > 0)
@@ -4311,6 +5449,10 @@ namespace OpenSim.Region.Framework.Scenes
4311 5449
4312 m_attachments.Add(gobj); 5450 m_attachments.Add(gobj);
4313 } 5451 }
5452
5453 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
5454 if (bakedModule != null)
5455 bakedModule.UpdateMeshAvatar(m_uuid);
4314 } 5456 }
4315 5457
4316 /// <summary> 5458 /// <summary>
@@ -4474,6 +5616,287 @@ namespace OpenSim.Region.Framework.Scenes
4474 return validated; 5616 return validated;
4475 } 5617 }
4476 5618
5619 public void SendAttachmentsToAllAgents()
5620 {
5621 lock (m_attachments)
5622 {
5623 foreach (SceneObjectGroup sog in m_attachments)
5624 {
5625 m_scene.ForEachScenePresence(delegate(ScenePresence p)
5626 {
5627 if (p != this && sog.HasPrivateAttachmentPoint)
5628 return;
5629
5630 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
5631 return;
5632
5633 SendTerseUpdateToAgentNF(p);
5634 SendAttachmentFullUpdateToAgentNF(sog, p);
5635 });
5636 }
5637 }
5638 }
5639
5640 // send attachments to a client without filters except for huds
5641 // for now they are checked in several places down the line...
5642 public void SendAttachmentsToAgentNF(ScenePresence p)
5643 {
5644 SendTerseUpdateToAgentNF(p);
5645 lock (m_attachments)
5646 {
5647 foreach (SceneObjectGroup sog in m_attachments)
5648 {
5649 SendAttachmentFullUpdateToAgentNF(sog, p);
5650 }
5651 }
5652 }
5653
5654 public void SendAttachmentFullUpdateToAgentNF(SceneObjectGroup sog, ScenePresence p)
5655 {
5656 if (p != this && sog.HasPrivateAttachmentPoint)
5657 return;
5658
5659 SceneObjectPart[] parts = sog.Parts;
5660 SceneObjectPart rootpart = sog.RootPart;
5661
5662 p.ControllingClient.SendEntityUpdate(rootpart, PrimUpdateFlags.FullUpdate);
5663
5664 for (int i = 0; i < parts.Length; i++)
5665 {
5666 SceneObjectPart part = parts[i];
5667 if (part == rootpart)
5668 continue;
5669 p.ControllingClient.SendEntityUpdate(part, PrimUpdateFlags.FullUpdate);
5670 }
5671 }
5672
5673 public void SendAttachmentScheduleUpdate(SceneObjectGroup sog)
5674 {
5675 if (IsChildAgent || IsInTransit)
5676 return;
5677
5678 SceneObjectPart[] origparts = sog.Parts;
5679 SceneObjectPart[] parts = new SceneObjectPart[origparts.Length];
5680 PrimUpdateFlags[] flags = new PrimUpdateFlags[origparts.Length];
5681
5682 SceneObjectPart rootpart = sog.RootPart;
5683 UpdateRequired rootreq = sog.RootPart.UpdateFlag;
5684
5685 int j = 0;
5686 bool allterse = true;
5687 for (int i = 0; i < origparts.Length; i++)
5688 {
5689 if (origparts[i] != rootpart)
5690 {
5691 switch (origparts[i].UpdateFlag)
5692 {
5693 case UpdateRequired.NONE:
5694 break;
5695
5696 case UpdateRequired.TERSE:
5697 flags[j] = PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
5698 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity;
5699 parts[j] = origparts[i];
5700 j++;
5701 break;
5702
5703 case UpdateRequired.FULL:
5704 flags[j] = PrimUpdateFlags.FullUpdate;
5705 allterse = false;
5706 parts[j] = origparts[i];
5707 j++;
5708 break;
5709 }
5710 }
5711 origparts[i].UpdateFlag = 0;
5712 }
5713
5714 if (j == 0 && rootreq == UpdateRequired.NONE)
5715 return;
5716
5717 PrimUpdateFlags rootflag = PrimUpdateFlags.FullUpdate;
5718
5719 if (rootreq != UpdateRequired.FULL && allterse)
5720 {
5721 rootflag = PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
5722 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity;
5723 }
5724
5725 int nparts = j;
5726
5727 ControllingClient.SendEntityUpdate(rootpart, rootflag);
5728
5729 for (int i = 0; i < nparts; i++)
5730 {
5731 ControllingClient.SendEntityUpdate(parts[i], flags[i]);
5732 }
5733
5734 if (sog.HasPrivateAttachmentPoint)
5735 return;
5736
5737 List<ScenePresence> allPresences = m_scene.GetScenePresences();
5738 foreach (ScenePresence p in allPresences)
5739 {
5740 if (p == this)
5741 continue;
5742
5743 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
5744 continue;
5745
5746 p.ControllingClient.SendEntityUpdate(rootpart, rootflag);
5747
5748 for (int i = 0; i < nparts; i++)
5749 {
5750 p.ControllingClient.SendEntityUpdate(parts[i], flags[i]);
5751 }
5752 }
5753 }
5754
5755 public void SendAttachmentUpdate(SceneObjectGroup sog, UpdateRequired UpdateFlag)
5756 {
5757 if (IsChildAgent || IsInTransit)
5758 return;
5759
5760 PrimUpdateFlags flag;
5761 switch (UpdateFlag)
5762 {
5763 case UpdateRequired.TERSE:
5764 flag = PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
5765 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity;
5766 break;
5767
5768 case UpdateRequired.FULL:
5769 flag = PrimUpdateFlags.FullUpdate;
5770 break;
5771
5772 default:
5773 return;
5774 }
5775
5776 SceneObjectPart[] parts = sog.Parts;
5777 SceneObjectPart rootpart = sog.RootPart;
5778
5779// rootpart.UpdateFlag = 0;
5780
5781 ControllingClient.SendEntityUpdate(rootpart, flag);
5782
5783 for (int i = 0; i < parts.Length; i++)
5784 {
5785 SceneObjectPart part = parts[i];
5786 if (part == rootpart)
5787 continue;
5788 ControllingClient.SendEntityUpdate(part, flag);
5789// part.UpdateFlag = 0;
5790 }
5791
5792 if (sog.HasPrivateAttachmentPoint)
5793 return;
5794
5795
5796 List<ScenePresence> allPresences = m_scene.GetScenePresences();
5797 foreach (ScenePresence p in allPresences)
5798 {
5799 if (p == this)
5800 continue;
5801
5802 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
5803 continue;
5804
5805 p.ControllingClient.SendEntityUpdate(rootpart, flag);
5806
5807 for (int i = 0; i < parts.Length; i++)
5808 {
5809 SceneObjectPart part = parts[i];
5810 if (part == rootpart)
5811 continue;
5812 p.ControllingClient.SendEntityUpdate(part, flag);
5813 }
5814 }
5815 }
5816
5817 public void SendAttachmentScheduleUpdate(SceneObjectPart part)
5818 {
5819 if (IsChildAgent || IsInTransit)
5820 return;
5821
5822
5823 PrimUpdateFlags flag;
5824 switch (part.UpdateFlag)
5825 {
5826 case UpdateRequired.TERSE:
5827 flag = PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
5828 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity;
5829 break;
5830
5831 case UpdateRequired.FULL:
5832 flag = PrimUpdateFlags.FullUpdate;
5833 break;
5834
5835 default:
5836 return;
5837 }
5838
5839 part.UpdateFlag = 0;
5840
5841 ControllingClient.SendEntityUpdate(part, flag);
5842
5843 if (part.ParentGroup.HasPrivateAttachmentPoint)
5844 return;
5845
5846 List<ScenePresence> allPresences = m_scene.GetScenePresences();
5847 foreach (ScenePresence p in allPresences)
5848 {
5849 if (p == this)
5850 continue;
5851
5852 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
5853 continue;
5854
5855 p.ControllingClient.SendEntityUpdate(part, flag);
5856 }
5857 }
5858
5859
5860 public void SendAttachmentUpdate(SceneObjectPart part, UpdateRequired UpdateFlag)
5861 {
5862 if (IsChildAgent || IsInTransit)
5863 return;
5864
5865 PrimUpdateFlags flag;
5866 switch (UpdateFlag)
5867 {
5868 case UpdateRequired.TERSE:
5869 flag = PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
5870 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity;
5871 break;
5872
5873 case UpdateRequired.FULL:
5874 flag = PrimUpdateFlags.FullUpdate;
5875 break;
5876
5877 default:
5878 return;
5879 }
5880
5881// part.UpdateFlag = 0;
5882
5883 ControllingClient.SendEntityUpdate(part, flag);
5884
5885 if (part.ParentGroup.HasPrivateAttachmentPoint)
5886 return;
5887
5888 List<ScenePresence> allPresences = m_scene.GetScenePresences();
5889 foreach (ScenePresence p in allPresences)
5890 {
5891 if (p == this)
5892 continue;
5893 if (ParcelHideThisAvatar && currentParcelUUID != p.currentParcelUUID && p.GodLevel < 200)
5894 continue;
5895
5896 p.ControllingClient.SendEntityUpdate(part, flag);
5897 }
5898 }
5899
4477 /// <summary> 5900 /// <summary>
4478 /// Send a script event to this scene presence's attachments 5901 /// Send a script event to this scene presence's attachments
4479 /// </summary> 5902 /// </summary>
@@ -4592,6 +6015,15 @@ namespace OpenSim.Region.Framework.Scenes
4592 ControllingClient.SendTakeControls(int.MaxValue, false, false); 6015 ControllingClient.SendTakeControls(int.MaxValue, false, false);
4593 } 6016 }
4594 6017
6018 public void ClearControls()
6019 {
6020 IgnoredControls = ScriptControlled.CONTROL_ZERO;
6021 lock (scriptedcontrols)
6022 {
6023 scriptedcontrols.Clear();
6024 }
6025 }
6026
4595 private void UnRegisterSeatControls(UUID obj) 6027 private void UnRegisterSeatControls(UUID obj)
4596 { 6028 {
4597 List<UUID> takers = new List<UUID>(); 6029 List<UUID> takers = new List<UUID>();
@@ -4833,11 +6265,8 @@ namespace OpenSim.Region.Framework.Scenes
4833 SpawnPoint[] spawnPoints = m_scene.RegionInfo.RegionSettings.SpawnPoints().ToArray(); 6265 SpawnPoint[] spawnPoints = m_scene.RegionInfo.RegionSettings.SpawnPoints().ToArray();
4834 if (spawnPoints.Length == 0) 6266 if (spawnPoints.Length == 0)
4835 { 6267 {
4836 if(m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)) 6268 pos.X = 128.0f;
4837 { 6269 pos.Y = 128.0f;
4838 pos.X = 128.0f;
4839 pos.Y = 128.0f;
4840 }
4841 return; 6270 return;
4842 } 6271 }
4843 6272
@@ -4982,8 +6411,8 @@ namespace OpenSim.Region.Framework.Scenes
4982 pos = land.LandData.UserLocation; 6411 pos = land.LandData.UserLocation;
4983 } 6412 }
4984 } 6413 }
4985 6414// this is now done in completeMovement for all cases and not just this
4986 land.SendLandUpdateToClient(ControllingClient); 6415// land.SendLandUpdateToClient(ControllingClient);
4987 } 6416 }
4988 } 6417 }
4989 6418
@@ -4998,6 +6427,7 @@ namespace OpenSim.Region.Framework.Scenes
4998 detobj.velVector = obj.Velocity; 6427 detobj.velVector = obj.Velocity;
4999 detobj.colliderType = 0; 6428 detobj.colliderType = 0;
5000 detobj.groupUUID = obj.GroupID; 6429 detobj.groupUUID = obj.GroupID;
6430 detobj.linkNumber = 0;
5001 6431
5002 return detobj; 6432 return detobj;
5003 } 6433 }
@@ -5013,6 +6443,7 @@ namespace OpenSim.Region.Framework.Scenes
5013 detobj.velVector = av.Velocity; 6443 detobj.velVector = av.Velocity;
5014 detobj.colliderType = 0; 6444 detobj.colliderType = 0;
5015 detobj.groupUUID = av.ControllingClient.ActiveGroupId; 6445 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
6446 detobj.linkNumber = 0;
5016 6447
5017 return detobj; 6448 return detobj;
5018 } 6449 }
@@ -5028,7 +6459,7 @@ namespace OpenSim.Region.Framework.Scenes
5028 detobj.velVector = Vector3.Zero; 6459 detobj.velVector = Vector3.Zero;
5029 detobj.colliderType = 0; 6460 detobj.colliderType = 0;
5030 detobj.groupUUID = UUID.Zero; 6461 detobj.groupUUID = UUID.Zero;
5031 6462 detobj.linkNumber = 0;
5032 return detobj; 6463 return detobj;
5033 } 6464 }
5034 6465
@@ -5095,6 +6526,95 @@ namespace OpenSim.Region.Framework.Scenes
5095 } 6526 }
5096 } 6527 }
5097 6528
6529 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
6530 {
6531 try
6532 {
6533 List<uint> thisHitColliders = new List<uint>();
6534 List<uint> endedColliders = new List<uint>();
6535 List<uint> startedColliders = new List<uint>();
6536 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
6537 CollisionForSoundInfo soundinfo;
6538 ContactPoint curcontact;
6539
6540 if (coldata.Count == 0)
6541 {
6542 if (m_lastColliders.Count == 0)
6543 return; // nothing to do
6544
6545 foreach (uint localID in m_lastColliders)
6546 {
6547 endedColliders.Add(localID);
6548 }
6549 m_lastColliders.Clear();
6550 }
6551
6552 else
6553 {
6554 bool candoparcelSound = ParcelAllowThisAvatarSounds;
6555
6556 foreach (uint id in coldata.Keys)
6557 {
6558 thisHitColliders.Add(id);
6559 if (!m_lastColliders.Contains(id))
6560 {
6561 startedColliders.Add(id);
6562 curcontact = coldata[id];
6563 if (candoparcelSound && Math.Abs(curcontact.RelativeSpeed) > 0.2)
6564 {
6565 soundinfo = new CollisionForSoundInfo();
6566 soundinfo.colliderID = id;
6567 soundinfo.position = curcontact.Position;
6568 soundinfo.relativeVel = curcontact.RelativeSpeed;
6569 soundinfolist.Add(soundinfo);
6570 }
6571 }
6572 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
6573 }
6574
6575 // calculate things that ended colliding
6576 foreach (uint localID in m_lastColliders)
6577 {
6578 if (!thisHitColliders.Contains(localID))
6579 {
6580 endedColliders.Add(localID);
6581 }
6582 }
6583 //add the items that started colliding this time to the last colliders list.
6584 foreach (uint localID in startedColliders)
6585 {
6586 m_lastColliders.Add(localID);
6587 }
6588 // remove things that ended colliding from the last colliders list
6589 foreach (uint localID in endedColliders)
6590 {
6591 m_lastColliders.Remove(localID);
6592 }
6593
6594 if (soundinfolist.Count > 0)
6595 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
6596 }
6597
6598 foreach (SceneObjectGroup att in GetAttachments())
6599 {
6600 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
6601 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
6602 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
6603
6604 if (startedColliders.Contains(0))
6605 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
6606 if (m_lastColliders.Contains(0))
6607 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
6608 if (endedColliders.Contains(0))
6609 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
6610 }
6611 }
6612 finally
6613 {
6614 m_collisionEventFlag = false;
6615 }
6616 }
6617
5098 private void TeleportFlagsDebug() { 6618 private void TeleportFlagsDebug() {
5099 6619
5100 // Some temporary debugging help to show all the TeleportFlags we have... 6620 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -5119,5 +6639,282 @@ namespace OpenSim.Region.Framework.Scenes
5119 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 6639 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
5120 6640
5121 } 6641 }
6642
6643 private void parcelGodCheck(UUID currentParcelID, bool isGod)
6644 {
6645 List<ScenePresence> allpresences = m_scene.GetScenePresences();
6646
6647 foreach (ScenePresence p in allpresences)
6648 {
6649 if (p.IsDeleted || p.IsChildAgent || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6650 continue;
6651
6652 if (p.ParcelHideThisAvatar && p.currentParcelUUID != currentParcelID)
6653 {
6654 if (isGod)
6655 p.SendViewTo(this);
6656 else
6657 p.SendKillTo(this);
6658 }
6659 }
6660 }
6661
6662 private void ParcelCrossCheck(UUID currentParcelID,UUID previusParcelID,
6663 bool currentParcelHide, bool previusParcelHide, bool oldhide,bool check)
6664 {
6665 List<ScenePresence> killsToSendto = new List<ScenePresence>();
6666 List<ScenePresence> killsToSendme = new List<ScenePresence>();
6667 List<ScenePresence> viewsToSendto = new List<ScenePresence>();
6668 List<ScenePresence> viewsToSendme = new List<ScenePresence>();
6669 List<ScenePresence> allpresences = null;
6670
6671 if (IsInTransit || IsChildAgent)
6672 return;
6673
6674 if (check)
6675 {
6676 // check is relative to current parcel only
6677 if (currentParcelUUID == null || oldhide == currentParcelHide)
6678 return;
6679
6680 allpresences = m_scene.GetScenePresences();
6681
6682 if (oldhide)
6683 { // where private
6684 foreach (ScenePresence p in allpresences)
6685 {
6686 if (p.IsDeleted || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6687 continue;
6688
6689 // those on not on parcel see me
6690 if (currentParcelID != p.currentParcelUUID)
6691 {
6692 viewsToSendto.Add(p); // they see me
6693 }
6694 }
6695 } // where private end
6696
6697 else
6698 { // where public
6699 foreach (ScenePresence p in allpresences)
6700 {
6701 if (p.IsDeleted || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6702 continue;
6703
6704 // those not on parcel dont see me
6705 if (currentParcelID != p.currentParcelUUID && p.GodLevel < 200)
6706 {
6707 killsToSendto.Add(p); // they dont see me
6708 }
6709 }
6710 } // where public end
6711
6712 allpresences.Clear();
6713 }
6714 else
6715 {
6716 if (currentParcelHide)
6717 {
6718 // now on a private parcel
6719 allpresences = m_scene.GetScenePresences();
6720
6721 if (previusParcelHide && previusParcelID != UUID.Zero)
6722 {
6723 foreach (ScenePresence p in allpresences)
6724 {
6725 if (p.IsDeleted || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6726 continue;
6727
6728 // only those on previus parcel need receive kills
6729 if (previusParcelID == p.currentParcelUUID)
6730 {
6731 if(p.GodLevel < 200)
6732 killsToSendto.Add(p); // they dont see me
6733 if(GodLevel < 200)
6734 killsToSendme.Add(p); // i dont see them
6735 }
6736 // only those on new parcel need see
6737 if (currentParcelID == p.currentParcelUUID)
6738 {
6739 viewsToSendto.Add(p); // they see me
6740 viewsToSendme.Add(p); // i see them
6741 }
6742 }
6743 }
6744 else
6745 {
6746 //was on a public area
6747 allpresences = m_scene.GetScenePresences();
6748
6749 foreach (ScenePresence p in allpresences)
6750 {
6751 if (p.IsDeleted || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6752 continue;
6753
6754 // those not on new parcel dont see me
6755 if (currentParcelID != p.currentParcelUUID && p.GodLevel < 200)
6756 {
6757 killsToSendto.Add(p); // they dont see me
6758 }
6759 else
6760 {
6761 viewsToSendme.Add(p); // i see those on it
6762 }
6763 }
6764 }
6765 allpresences.Clear();
6766 } // now on a private parcel end
6767
6768 else
6769 {
6770 // now on public parcel
6771 if (previusParcelHide && previusParcelID != UUID.Zero)
6772 {
6773 // was on private area
6774 allpresences = m_scene.GetScenePresences();
6775
6776 foreach (ScenePresence p in allpresences)
6777 {
6778 if (p.IsDeleted || p == this || p.ControllingClient == null || !p.ControllingClient.IsActive)
6779 continue;
6780 // only those old parcel need kills
6781 if (previusParcelID == p.currentParcelUUID && GodLevel < 200)
6782 {
6783 killsToSendme.Add(p); // i dont see them
6784 }
6785 else
6786 {
6787 viewsToSendto.Add(p); // they see me
6788 }
6789 }
6790 }
6791 else
6792 return; // was on a public area also
6793 } // now on public parcel end
6794 }
6795
6796 // send the things
6797
6798 if (killsToSendto.Count > 0)
6799 {
6800 foreach (ScenePresence p in killsToSendto)
6801 {
6802 m_log.Debug("[AVATAR]: killTo: " + Lastname + " " + p.Lastname);
6803 SendKillTo(p);
6804 }
6805 }
6806
6807 if (killsToSendme.Count > 0)
6808 {
6809 foreach (ScenePresence p in killsToSendme)
6810 {
6811 m_log.Debug("[AVATAR]: killToMe: " + Lastname + " " + p.Lastname);
6812 p.SendKillTo(this);
6813 }
6814 }
6815
6816 if (viewsToSendto.Count > 0)
6817 {
6818 foreach (ScenePresence p in viewsToSendto)
6819 {
6820 SendViewTo(p);
6821 }
6822 }
6823
6824 if (viewsToSendme.Count > 0 )
6825 {
6826 foreach (ScenePresence p in viewsToSendme)
6827 {
6828 if (p.IsChildAgent)
6829 continue;
6830// m_log.Debug("[AVATAR]: viewMe: " + Lastname + "<-" + p.Lastname);
6831 p.SendViewTo(this);
6832 }
6833 }
6834 }
6835
6836 public void HasMovedAway(bool nearRegion)
6837 {
6838
6839 if (nearRegion)
6840 {
6841 if (Scene.AttachmentsModule != null)
6842 Scene.AttachmentsModule.DeleteAttachmentsFromScene(this, true);
6843
6844 if (!ParcelHideThisAvatar || GodLevel >= 200)
6845 return;
6846
6847 List<ScenePresence> allpresences = m_scene.GetScenePresences();
6848 foreach (ScenePresence p in allpresences)
6849 {
6850 if (p.IsDeleted || p == this || p.IsChildAgent || p.ControllingClient == null || !p.ControllingClient.IsActive)
6851 continue;
6852
6853 if (p.currentParcelUUID == m_currentParcelUUID)
6854 {
6855 p.SendKillTo(this);
6856 }
6857 }
6858 }
6859 else
6860 {
6861 List<ScenePresence> allpresences = m_scene.GetScenePresences();
6862 foreach (ScenePresence p in allpresences)
6863 {
6864 if (p == this)
6865 continue;
6866 SendKillTo(p);
6867 if (!p.IsChildAgent)
6868 p.SendKillTo(this);
6869 }
6870
6871 if (Scene.AttachmentsModule != null)
6872 Scene.AttachmentsModule.DeleteAttachmentsFromScene(this, true);
6873 }
6874 }
6875
6876
6877// kill with attachs root kills
6878 public void SendKillTo(ScenePresence p)
6879 {
6880 List<uint> ids = new List<uint>(m_attachments.Count + 1);
6881 foreach (SceneObjectGroup sog in m_attachments)
6882 {
6883 ids.Add(sog.RootPart.LocalId);
6884 }
6885
6886 ids.Add(LocalId);
6887 p.ControllingClient.SendKillObject(ids);
6888 }
6889
6890/*
6891// kill with hack
6892 public void SendKillTo(ScenePresence p)
6893 {
6894 foreach (SceneObjectGroup sog in m_attachments)
6895 p.ControllingClient.SendPartFullUpdate(sog.RootPart, LocalId + 1);
6896 p.ControllingClient.SendKillObject(new List<uint> { LocalId });
6897 }
6898*/
6899 public void SendViewTo(ScenePresence p)
6900 {
6901 SendAvatarDataToAgentNF(p);
6902 SendAppearanceToAgent(p);
6903 if (Animator != null)
6904 Animator.SendAnimPackToClient(p.ControllingClient);
6905 SendAttachmentsToAgentNF(p);
6906 }
6907
6908 public void SetAnimationOverride(string animState, UUID animID)
6909 {
6910 Overrides.SetOverride(animState, animID);
6911// Animator.SendAnimPack();
6912 Animator.ForceUpdateMovementAnimations();
6913 }
6914
6915 public UUID GetAnimationOverride(string animState)
6916 {
6917 return Overrides.GetOverriddenAnimation(animState);
6918 }
5122 } 6919 }
5123} 6920}
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index 4caa9cb..dc5de58 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -278,7 +278,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
278 // Script state may, or may not, exist. Not having any, is NOT 278 // Script state may, or may not, exist. Not having any, is NOT
279 // ever a problem. 279 // ever a problem.
280 sceneObject.LoadScriptState(doc); 280 sceneObject.LoadScriptState(doc);
281 281
282 return sceneObject; 282 return sceneObject;
283 } 283 }
284 catch (Exception e) 284 catch (Exception e)
@@ -307,14 +307,21 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
307 } 307 }
308 } 308 }
309 309
310<<<<<<< HEAD
310 311
312=======
313>>>>>>> avn/ubitvar
311 /// <summary> 314 /// <summary>
312 /// Modifies a SceneObjectGroup. 315 /// Modifies a SceneObjectGroup.
313 /// </summary> 316 /// </summary>
314 /// <param name="sog">The object</param> 317 /// <param name="sog">The object</param>
315 /// <returns>Whether the object was actually modified</returns> 318 /// <returns>Whether the object was actually modified</returns>
316 public delegate bool SceneObjectModifier(SceneObjectGroup sog); 319 public delegate bool SceneObjectModifier(SceneObjectGroup sog);
320<<<<<<< HEAD
317 321
322=======
323
324>>>>>>> avn/ubitvar
318 /// <summary> 325 /// <summary>
319 /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing. 326 /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing.
320 /// </summary> 327 /// </summary>
@@ -328,7 +335,11 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
328 CoalescedSceneObjects coa = null; 335 CoalescedSceneObjects coa = null;
329 336
330 string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data)); 337 string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data));
338<<<<<<< HEAD
331 339
340=======
341
342>>>>>>> avn/ubitvar
332 if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) 343 if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa))
333 { 344 {
334 // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); 345 // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
@@ -373,7 +384,10 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
373 384
374 return data; 385 return data;
375 } 386 }
387<<<<<<< HEAD
376 388
389=======
390>>>>>>> avn/ubitvar
377 391
378 #region manual serialization 392 #region manual serialization
379 393
@@ -450,11 +464,27 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
450 m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); 464 m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
451 m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); 465 m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
452 466
467 m_SOPXmlProcessors.Add("Buoyancy", ProcessBuoyancy);
468 m_SOPXmlProcessors.Add("Force", ProcessForce);
469 m_SOPXmlProcessors.Add("Torque", ProcessTorque);
470 m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
471
472
473 m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
474
453 m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType); 475 m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
454 m_SOPXmlProcessors.Add("Density", ProcessDensity); 476 m_SOPXmlProcessors.Add("Density", ProcessDensity);
455 m_SOPXmlProcessors.Add("Friction", ProcessFriction); 477 m_SOPXmlProcessors.Add("Friction", ProcessFriction);
456 m_SOPXmlProcessors.Add("Bounce", ProcessBounce); 478 m_SOPXmlProcessors.Add("Bounce", ProcessBounce);
457 m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier); 479 m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier);
480 m_SOPXmlProcessors.Add("CameraEyeOffset", ProcessCameraEyeOffset);
481 m_SOPXmlProcessors.Add("CameraAtOffset", ProcessCameraAtOffset);
482
483 m_SOPXmlProcessors.Add("SoundID", ProcessSoundID);
484 m_SOPXmlProcessors.Add("SoundGain", ProcessSoundGain);
485 m_SOPXmlProcessors.Add("SoundFlags", ProcessSoundFlags);
486 m_SOPXmlProcessors.Add("SoundRadius", ProcessSoundRadius);
487 m_SOPXmlProcessors.Add("SoundQueueing", ProcessSoundQueueing);
458 488
459 #endregion 489 #endregion
460 490
@@ -483,7 +513,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
483 m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask); 513 m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
484 m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType); 514 m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
485 m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged); 515 m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
486 516
487 #endregion 517 #endregion
488 518
489 #region ShapeXmlProcessors initialization 519 #region ShapeXmlProcessors initialization
@@ -709,7 +739,62 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
709 obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty); 739 obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty);
710 } 740 }
711 741
742<<<<<<< HEAD
712 private static void ProcessShape(SceneObjectPart obj, XmlReader reader) 743 private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
744=======
745 private static void ProcessCameraEyeOffset(SceneObjectPart obj, XmlTextReader reader)
746 {
747 obj.SetCameraEyeOffset(Util.ReadVector(reader, "CameraEyeOffset"));
748 }
749
750 private static void ProcessCameraAtOffset(SceneObjectPart obj, XmlTextReader reader)
751 {
752 obj.SetCameraAtOffset(Util.ReadVector(reader, "CameraAtOffset"));
753 }
754
755 private static void ProcessSoundID(SceneObjectPart obj, XmlTextReader reader)
756 {
757 obj.Sound = Util.ReadUUID(reader, "SoundID");
758 }
759
760 private static void ProcessSoundGain(SceneObjectPart obj, XmlTextReader reader)
761 {
762 obj.SoundGain = reader.ReadElementContentAsDouble("SoundGain", String.Empty);
763 }
764
765 private static void ProcessSoundFlags(SceneObjectPart obj, XmlTextReader reader)
766 {
767 obj.SoundFlags = (byte)reader.ReadElementContentAsInt("SoundFlags", String.Empty);
768 }
769
770 private static void ProcessSoundRadius(SceneObjectPart obj, XmlTextReader reader)
771 {
772 obj.SoundRadius = reader.ReadElementContentAsDouble("SoundRadius", String.Empty);
773 }
774
775 private static void ProcessSoundQueueing(SceneObjectPart obj, XmlTextReader reader)
776 {
777 obj.SoundQueueing = Util.ReadBoolean(reader);
778 }
779 private static void ProcessVehicle(SceneObjectPart obj, XmlTextReader reader)
780 {
781 SOPVehicle vehicle = SOPVehicle.FromXml2(reader);
782
783 if (vehicle == null)
784 {
785 obj.VehicleParams = null;
786 m_log.DebugFormat(
787 "[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
788 obj.Name, obj.UUID);
789 }
790 else
791 {
792 obj.VehicleParams = vehicle;
793 }
794 }
795
796 private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader)
797>>>>>>> avn/ubitvar
713 { 798 {
714 List<string> errorNodeNames; 799 List<string> errorNodeNames;
715 obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj); 800 obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj);
@@ -883,6 +968,25 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
883 obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty); 968 obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
884 } 969 }
885 970
971 private static void ProcessBuoyancy(SceneObjectPart obj, XmlTextReader reader)
972 {
973 obj.Buoyancy = (float)reader.ReadElementContentAsFloat("Buoyancy", String.Empty);
974 }
975
976 private static void ProcessForce(SceneObjectPart obj, XmlTextReader reader)
977 {
978 obj.Force = Util.ReadVector(reader, "Force");
979 }
980 private static void ProcessTorque(SceneObjectPart obj, XmlTextReader reader)
981 {
982 obj.Torque = Util.ReadVector(reader, "Torque");
983 }
984
985 private static void ProcessVolumeDetectActive(SceneObjectPart obj, XmlTextReader reader)
986 {
987 obj.VolumeDetectActive = Util.ReadBoolean(reader);
988 }
989
886 #endregion 990 #endregion
887 991
888 #region TaskInventoryXmlProcessors 992 #region TaskInventoryXmlProcessors
@@ -1271,12 +1375,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1271 1375
1272 if (sog.RootPart.KeyframeMotion != null) 1376 if (sog.RootPart.KeyframeMotion != null)
1273 { 1377 {
1274 Byte[] data = sog.RootPart.KeyframeMotion.Serialize(); 1378 Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
1275 1379
1276 writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty); 1380 writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
1277 writer.WriteBase64(data, 0, data.Length); 1381 writer.WriteBase64(data, 0, data.Length);
1278 writer.WriteEndElement(); 1382 writer.WriteEndElement();
1279 } 1383 }
1384
1280 1385
1281 writer.WriteEndElement(); 1386 writer.WriteEndElement();
1282 } 1387 }
@@ -1388,8 +1493,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1388 writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); 1493 writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
1389 writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString()); 1494 writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
1390 1495
1391 if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType()) 1496 writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString());
1392 writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower()); 1497
1498 WriteVector(writer, "Force", sop.Force);
1499 WriteVector(writer, "Torque", sop.Torque);
1500
1501 writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
1502
1503 if (sop.VehicleParams != null)
1504 sop.VehicleParams.ToXml2(writer);
1505
1506 writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
1393 if (sop.Density != 1000.0f) 1507 if (sop.Density != 1000.0f)
1394 writer.WriteElementString("Density", sop.Density.ToString().ToLower()); 1508 writer.WriteElementString("Density", sop.Density.ToString().ToLower());
1395 if (sop.Friction != 0.6f) 1509 if (sop.Friction != 0.6f)
@@ -1398,7 +1512,18 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1398 writer.WriteElementString("Bounce", sop.Restitution.ToString().ToLower()); 1512 writer.WriteElementString("Bounce", sop.Restitution.ToString().ToLower());
1399 if (sop.GravityModifier != 1.0f) 1513 if (sop.GravityModifier != 1.0f)
1400 writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower()); 1514 writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower());
1515 WriteVector(writer, "CameraEyeOffset", sop.GetCameraEyeOffset());
1516 WriteVector(writer, "CameraAtOffset", sop.GetCameraAtOffset());
1401 1517
1518 // if (sop.Sound != UUID.Zero) force it till sop crossing does clear it on child prim
1519 {
1520 WriteUUID(writer, "SoundID", sop.Sound, options);
1521 writer.WriteElementString("SoundGain", sop.SoundGain.ToString().ToLower());
1522 writer.WriteElementString("SoundFlags", sop.SoundFlags.ToString().ToLower());
1523 writer.WriteElementString("SoundRadius", sop.SoundRadius.ToString().ToLower());
1524 }
1525 writer.WriteElementString("SoundQueueing", sop.SoundQueueing.ToString().ToLower());
1526
1402 writer.WriteEndElement(); 1527 writer.WriteEndElement();
1403 } 1528 }
1404 1529
@@ -1625,12 +1750,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1625 { 1750 {
1626 TaskInventoryDictionary tinv = new TaskInventoryDictionary(); 1751 TaskInventoryDictionary tinv = new TaskInventoryDictionary();
1627 1752
1628 if (reader.IsEmptyElement)
1629 {
1630 reader.Read();
1631 return tinv;
1632 }
1633
1634 reader.ReadStartElement(name, String.Empty); 1753 reader.ReadStartElement(name, String.Empty);
1635 1754
1636 while (reader.Name == "TaskInventoryItem") 1755 while (reader.Name == "TaskInventoryItem")
diff --git a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
index 2174e51..52e3ff1 100755
--- a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
+++ b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
@@ -184,7 +184,11 @@ namespace OpenSim.Region.Framework.Scenes
184 184
185 // saved last reported value so there is something available for llGetRegionFPS 185 // saved last reported value so there is something available for llGetRegionFPS
186 private float lastReportedSimFPS; 186 private float lastReportedSimFPS;
187<<<<<<< HEAD
187 private float[] lastReportedSimStats = new float[m_statisticArraySize]; 188 private float[] lastReportedSimStats = new float[m_statisticArraySize];
189=======
190 private float[] lastReportedSimStats = new float[23];
191>>>>>>> avn/ubitvar
188 private float m_pfps; 192 private float m_pfps;
189 193
190 /// <summary> 194 /// <summary>
@@ -198,13 +202,20 @@ namespace OpenSim.Region.Framework.Scenes
198 private int m_objectUpdates; 202 private int m_objectUpdates;
199 203
200 private int m_frameMS; 204 private int m_frameMS;
201 private int m_spareMS; 205
202 private int m_netMS; 206 private int m_netMS;
203 private int m_agentMS; 207 private int m_agentMS;
204 private int m_physicsMS; 208 private int m_physicsMS;
205 private int m_imageMS; 209 private int m_imageMS;
206 private int m_otherMS; 210 private int m_otherMS;
211<<<<<<< HEAD
207 private int m_scriptMS; 212 private int m_scriptMS;
213=======
214 private int m_sleeptimeMS;
215
216//Ckrinke: (3-21-08) Comment out to remove a compiler warning. Bring back into play when needed.
217//Ckrinke private int m_scriptMS = 0;
218>>>>>>> avn/ubitvar
208 219
209 private int m_rootAgents; 220 private int m_rootAgents;
210 private int m_childAgents; 221 private int m_childAgents;
@@ -355,11 +366,15 @@ namespace OpenSim.Region.Framework.Scenes
355 if (!m_scene.Active) 366 if (!m_scene.Active)
356 return; 367 return;
357 368
369<<<<<<< HEAD
358 // Create arrays to hold the statistics for this current scene, 370 // Create arrays to hold the statistics for this current scene,
359 // these will be passed to the SimExtraStatsCollector, they are also 371 // these will be passed to the SimExtraStatsCollector, they are also
360 // sent to the SimStats class 372 // sent to the SimStats class
361 SimStatsPacket.StatBlock[] sb = new 373 SimStatsPacket.StatBlock[] sb = new
362 SimStatsPacket.StatBlock[m_statisticArraySize]; 374 SimStatsPacket.StatBlock[m_statisticArraySize];
375=======
376 SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[23];
377>>>>>>> avn/ubitvar
363 SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); 378 SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();
364 379
365 // Know what's not thread safe in Mono... modifying timers. 380 // Know what's not thread safe in Mono... modifying timers.
@@ -404,6 +419,35 @@ namespace OpenSim.Region.Framework.Scenes
404 physfps = 0; 419 physfps = 0;
405 420
406#endregion 421#endregion
422 float factor = 1 / m_statsUpdateFactor;
423
424 if (reportedFPS <= 0)
425 reportedFPS = 1;
426
427 float perframe = 1.0f / (float)reportedFPS;
428
429 float TotalFrameTime = m_frameMS * perframe;
430
431 float targetframetime = 1100.0f / (float)m_nominalReportedFps;
432
433 float sparetime;
434 float sleeptime;
435
436 if (TotalFrameTime > targetframetime)
437 {
438 sparetime = 0;
439 sleeptime = 0;
440 }
441 else
442 {
443 sparetime = m_frameMS - m_physicsMS - m_agentMS;
444 sparetime *= perframe;
445 if (sparetime < 0)
446 sparetime = 0;
447 else if (sparetime > TotalFrameTime)
448 sparetime = TotalFrameTime;
449 sleeptime = m_sleeptimeMS * perframe;
450 }
407 451
408 m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); 452 m_rootAgents = m_scene.SceneGraph.GetRootAgentCount();
409 m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); 453 m_childAgents = m_scene.SceneGraph.GetChildAgentCount();
@@ -417,16 +461,11 @@ namespace OpenSim.Region.Framework.Scenes
417 // so that stat numbers are always consistent. 461 // so that stat numbers are always consistent.
418 CheckStatSanity(); 462 CheckStatSanity();
419 463
420 //Our time dilation is 0.91 when we're running a full speed, 464 // other MS is actually simulation time
421 // therefore to make sure we get an appropriate range, 465 // m_otherMS = m_frameMS - m_physicsMS - m_imageMS - m_netMS - m_agentMS;
422 // we have to factor in our error. (0.10f * statsUpdateFactor) 466 // m_imageMS m_netMS are not included in m_frameMS
423 // multiplies the fix for the error times the amount of times it'll occur a second
424 // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
425 // Then we divide the whole amount by the amount of seconds pass in between stats updates.
426
427 // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change
428 // values to X-per-second values.
429 467
468<<<<<<< HEAD
430 uint thisFrame = m_scene.Frame; 469 uint thisFrame = m_scene.Frame;
431 uint numFrames = thisFrame - m_lastUpdateFrame; 470 uint numFrames = thisFrame - m_lastUpdateFrame;
432 float framesUpdated = (float)numFrames * m_reportedFpsCorrectionFactor; 471 float framesUpdated = (float)numFrames * m_reportedFpsCorrectionFactor;
@@ -437,6 +476,13 @@ namespace OpenSim.Region.Framework.Scenes
437 framesUpdated = 1; 476 framesUpdated = 1;
438 477
439 for (int i = 0; i < m_statisticArraySize; i++) 478 for (int i = 0; i < m_statisticArraySize; i++)
479=======
480 m_otherMS = m_frameMS - m_physicsMS - m_agentMS - m_sleeptimeMS;
481 if (m_otherMS < 0)
482 m_otherMS = 0;
483
484 for (int i = 0; i < 23; i++)
485>>>>>>> avn/ubitvar
440 { 486 {
441 sb[i] = new SimStatsPacket.StatBlock(); 487 sb[i] = new SimStatsPacket.StatBlock();
442 } 488 }
@@ -501,6 +547,7 @@ namespace OpenSim.Region.Framework.Scenes
501 // ORIGINAL code commented out until we have time to add our own 547 // ORIGINAL code commented out until we have time to add our own
502 // statistics to the statistics window 548 // statistics to the statistics window
503 sb[8].StatID = (uint)Stats.FrameMS; 549 sb[8].StatID = (uint)Stats.FrameMS;
550<<<<<<< HEAD
504 //sb[8].StatValue = m_frameMS / framesUpdated; 551 //sb[8].StatValue = m_frameMS / framesUpdated;
505 sb[8].StatValue = (float) totalSumFrameTime / m_numberFramesStored; 552 sb[8].StatValue = (float) totalSumFrameTime / m_numberFramesStored;
506 553
@@ -511,13 +558,26 @@ namespace OpenSim.Region.Framework.Scenes
511 sb[10].StatID = (uint)Stats.PhysicsMS; 558 sb[10].StatID = (uint)Stats.PhysicsMS;
512 //sb[10].StatValue = m_physicsMS / framesUpdated; 559 //sb[10].StatValue = m_physicsMS / framesUpdated;
513 sb[10].StatValue = (float) physicsSumFrameTime / m_numberFramesStored; 560 sb[10].StatValue = (float) physicsSumFrameTime / m_numberFramesStored;
561=======
562 sb[8].StatValue = TotalFrameTime;
563
564 sb[9].StatID = (uint)Stats.NetMS;
565 sb[9].StatValue = m_netMS * perframe;
566
567 sb[10].StatID = (uint)Stats.PhysicsMS;
568 sb[10].StatValue = m_physicsMS * perframe;
569>>>>>>> avn/ubitvar
514 570
515 sb[11].StatID = (uint)Stats.ImageMS ; 571 sb[11].StatID = (uint)Stats.ImageMS ;
516 sb[11].StatValue = m_imageMS / framesUpdated; 572 sb[11].StatValue = m_imageMS * perframe;
517 573
518 sb[12].StatID = (uint)Stats.OtherMS; 574 sb[12].StatID = (uint)Stats.OtherMS;
575<<<<<<< HEAD
519 //sb[12].StatValue = m_otherMS / framesUpdated; 576 //sb[12].StatValue = m_otherMS / framesUpdated;
520 sb[12].StatValue = (float) simulationSumFrameTime / m_numberFramesStored; 577 sb[12].StatValue = (float) simulationSumFrameTime / m_numberFramesStored;
578=======
579 sb[12].StatValue = m_otherMS * perframe;
580>>>>>>> avn/ubitvar
521 581
522 sb[13].StatID = (uint)Stats.InPacketsPerSecond; 582 sb[13].StatID = (uint)Stats.InPacketsPerSecond;
523 sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); 583 sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor);
@@ -529,7 +589,7 @@ namespace OpenSim.Region.Framework.Scenes
529 sb[15].StatValue = m_unAckedBytes; 589 sb[15].StatValue = m_unAckedBytes;
530 590
531 sb[16].StatID = (uint)Stats.AgentMS; 591 sb[16].StatID = (uint)Stats.AgentMS;
532 sb[16].StatValue = m_agentMS / framesUpdated; 592 sb[16].StatValue = m_agentMS * perframe;
533 593
534 sb[17].StatID = (uint)Stats.PendingDownloads; 594 sb[17].StatID = (uint)Stats.PendingDownloads;
535 sb[17].StatValue = m_pendingDownloads; 595 sb[17].StatValue = m_pendingDownloads;
@@ -544,7 +604,10 @@ namespace OpenSim.Region.Framework.Scenes
544 sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; 604 sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor;
545 605
546 sb[21].StatID = (uint)Stats.SimSpareMs; 606 sb[21].StatID = (uint)Stats.SimSpareMs;
547 sb[21].StatValue = m_spareMS / framesUpdated; 607 sb[21].StatValue = sparetime;
608
609 sb[22].StatID = (uint)Stats.SimSleepMs;
610 sb[22].StatValue = sleeptime;
548 611
549 // Current ratio between the sum of physics and sim rate, and the 612 // Current ratio between the sum of physics and sim rate, and the
550 // minimum time to run a scene's frame 613 // minimum time to run a scene's frame
@@ -587,28 +650,32 @@ namespace OpenSim.Region.Framework.Scenes
587 } 650 }
588 651
589 // Extra statistics that aren't currently sent to clients 652 // Extra statistics that aren't currently sent to clients
590 lock (m_lastReportedExtraSimStats) 653 if (m_scene.PhysicsScene != null)
591 { 654 {
592 m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor; 655 lock (m_lastReportedExtraSimStats)
593 m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value;
594
595 Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats();
596
597 if (physicsStats != null)
598 { 656 {
599 foreach (KeyValuePair<string, float> tuple in physicsStats) 657 m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor;
658 m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value;
659
660 Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats();
661
662 if (physicsStats != null)
600 { 663 {
601 // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second 664 foreach (KeyValuePair<string, float> tuple in physicsStats)
602 // Need to change things so that stats source can indicate whether they are per second or 665 {
603 // per frame. 666 // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
604 if (tuple.Key.EndsWith("MS")) 667 // Need to change things so that stats source can indicate whether they are per second or
605 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated; 668 // per frame.
606 else 669 if (tuple.Key.EndsWith("MS"))
607 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor; 670 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframe;
671 else
672 m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor;
673 }
608 } 674 }
609 } 675 }
610 } 676 }
611 677
678// LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor;
612 ResetValues(); 679 ResetValues();
613 } 680 }
614 } 681 }
@@ -635,8 +702,16 @@ namespace OpenSim.Region.Framework.Scenes
635 m_physicsMS = 0; 702 m_physicsMS = 0;
636 m_imageMS = 0; 703 m_imageMS = 0;
637 m_otherMS = 0; 704 m_otherMS = 0;
705<<<<<<< HEAD
638 m_scriptMS = 0; 706 m_scriptMS = 0;
639 m_spareMS = 0; 707 m_spareMS = 0;
708=======
709// m_spareMS = 0;
710 m_sleeptimeMS = 0;
711
712//Ckrinke This variable is not used, so comment to remove compiler warning until it is used.
713//Ckrinke m_scriptMS = 0;
714>>>>>>> avn/ubitvar
640 } 715 }
641 716
642 # region methods called from Scene 717 # region methods called from Scene
@@ -717,11 +792,6 @@ namespace OpenSim.Region.Framework.Scenes
717 SlowFramesStat.Value++; 792 SlowFramesStat.Value++;
718 } 793 }
719 794
720 public void AddSpareMS(int ms)
721 {
722 m_spareMS += ms;
723 }
724
725 public void addNetMS(int ms) 795 public void addNetMS(int ms)
726 { 796 {
727 m_netMS += ms; 797 m_netMS += ms;
@@ -747,6 +817,7 @@ namespace OpenSim.Region.Framework.Scenes
747 m_otherMS += ms; 817 m_otherMS += ms;
748 } 818 }
749 819
820<<<<<<< HEAD
750 public void AddScriptMS(int ms) 821 public void AddScriptMS(int ms)
751 { 822 {
752 m_scriptMS += ms; 823 m_scriptMS += ms;
@@ -776,6 +847,11 @@ namespace OpenSim.Region.Framework.Scenes
776 // first, the next location needs to loop back to the beginning of the 847 // first, the next location needs to loop back to the beginning of the
777 // list whenever it reaches the end 848 // list whenever it reaches the end
778 m_nextLocation = m_nextLocation % m_numberFramesStored; 849 m_nextLocation = m_nextLocation % m_numberFramesStored;
850=======
851 public void addSleepMS(int ms)
852 {
853 m_sleeptimeMS += ms;
854>>>>>>> avn/ubitvar
779 } 855 }
780 856
781 public void AddPendingDownloads(int count) 857 public void AddPendingDownloads(int count)
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index 3d563a6..6fd9096 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
@@ -49,6 +49,7 @@ namespace OpenSim.Region.Framework.Scenes
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[TERRAIN CHANNEL]"; 51 private static string LogHeader = "[TERRAIN CHANNEL]";
52<<<<<<< HEAD
52 53
53 protected TerrainData m_terrainData; 54 protected TerrainData m_terrainData;
54 55
@@ -57,6 +58,16 @@ namespace OpenSim.Region.Framework.Scenes
57 public int Height { get { return m_terrainData.SizeY; } } // Y dimension 58 public int Height { get { return m_terrainData.SizeY; } } // Y dimension
58 public int Altitude { get { return m_terrainData.SizeZ; } } // Y dimension 59 public int Altitude { get { return m_terrainData.SizeZ; } } // Y dimension
59 60
61=======
62
63 protected TerrainData m_terrainData;
64
65 public int Width { get { return m_terrainData.SizeX; } } // X dimension
66 // Unfortunately, for historical reasons, in this module 'Width' is X and 'Height' is Y
67 public int Height { get { return m_terrainData.SizeY; } } // Y dimension
68 public int Altitude { get { return m_terrainData.SizeZ; } } // Y dimension
69
70>>>>>>> avn/ubitvar
60 // Default, not-often-used builder 71 // Default, not-often-used builder
61 public TerrainChannel() 72 public TerrainChannel()
62 { 73 {
@@ -157,7 +168,15 @@ namespace OpenSim.Region.Framework.Scenes
157 { 168 {
158 if (Double.IsNaN(value) || Double.IsInfinity(value)) 169 if (Double.IsNaN(value) || Double.IsInfinity(value))
159 return; 170 return;
160 171<<<<<<< HEAD
172
173=======
174 if (value < 0)
175 value = 0;
176 else
177 if (value > 655.35)
178 value = 655.35;
179>>>>>>> avn/ubitvar
161 m_terrainData[x, y] = (float)value; 180 m_terrainData[x, y] = (float)value;
162 } 181 }
163 } 182 }
@@ -363,8 +382,13 @@ namespace OpenSim.Region.Framework.Scenes
363 public int SizeY; 382 public int SizeY;
364 public int SizeZ; 383 public int SizeZ;
365 public float CompressionFactor; 384 public float CompressionFactor;
385<<<<<<< HEAD
366 public int[] Map; 386 public int[] Map;
367 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, int[] pMap) 387 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, int[] pMap)
388=======
389 public float[] Map;
390 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, float[] pMap)
391>>>>>>> avn/ubitvar
368 { 392 {
369 Version = 1; 393 Version = 1;
370 SizeX = pX; 394 SizeX = pX;
@@ -395,10 +419,17 @@ namespace OpenSim.Region.Framework.Scenes
395 // Fill the heightmap with the center bump terrain 419 // Fill the heightmap with the center bump terrain
396 private void PinHeadIsland() 420 private void PinHeadIsland()
397 { 421 {
422<<<<<<< HEAD
423=======
424 float cx = m_terrainData.SizeX * 0.5f;
425 float cy = m_terrainData.SizeY * 0.5f;
426 float h;
427>>>>>>> avn/ubitvar
398 for (int x = 0; x < Width; x++) 428 for (int x = 0; x < Width; x++)
399 { 429 {
400 for (int y = 0; y < Height; y++) 430 for (int y = 0; y < Height; y++)
401 { 431 {
432<<<<<<< HEAD
402 m_terrainData[x, y] = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10; 433 m_terrainData[x, y] = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10;
403 float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 50) * 0.01d); 434 float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 50) * 0.01d);
404 float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 100) * 0.001d); 435 float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, m_terrainData.SizeX / 2.0, m_terrainData.SizeY / 2.0, 100) * 0.001d);
@@ -406,6 +437,17 @@ namespace OpenSim.Region.Framework.Scenes
406 m_terrainData[x, y]= spherFacA; 437 m_terrainData[x, y]= spherFacA;
407 if (m_terrainData[x, y]< spherFacB) 438 if (m_terrainData[x, y]< spherFacB)
408 m_terrainData[x, y] = spherFacB; 439 m_terrainData[x, y] = spherFacB;
440=======
441 // h = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10;
442 h = 1.0f;
443 float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 50) * 0.01d);
444 float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 100) * 0.001d);
445 if (h < spherFacA)
446 h = spherFacA;
447 if (h < spherFacB)
448 h = spherFacB;
449 m_terrainData[x, y] = h;
450>>>>>>> avn/ubitvar
409 } 451 }
410 } 452 }
411 } 453 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
index 558ba2c..b7e9499 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectDeRezTests.cs
@@ -82,8 +82,11 @@ namespace OpenSim.Region.Framework.Scenes.Tests
82 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); 82 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
83 83
84 TestScene scene = new SceneHelpers().SetupScene(); 84 TestScene scene = new SceneHelpers().SetupScene();
85 SceneHelpers.SetupSceneModules(scene, new PermissionsModule()); 85 IConfigSource configSource = new IniConfigSource();
86 TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, userId).ControllingClient; 86 IConfig config = configSource.AddConfig("Startup");
87 config.Set("serverside_object_permissions", true);
88 SceneHelpers.SetupSceneModules(scene, configSource, new object[] { new DefaultPermissionsModule() });
89 IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
87 90
88 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. 91 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
89 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter; 92 AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
@@ -105,9 +108,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
105 108
106 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId); 109 SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
107 Assert.That(retrievedPart2, Is.Null); 110 Assert.That(retrievedPart2, Is.Null);
108
109 Assert.That(client.ReceivedKills.Count, Is.EqualTo(1));
110 Assert.That(client.ReceivedKills[0], Is.EqualTo(soLocalId));
111 } 111 }
112 112
113 /// <summary> 113 /// <summary>
@@ -134,7 +134,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
134 SceneHelpers.SetupSceneModules(sceneB, config, etmB); 134 SceneHelpers.SetupSceneModules(sceneB, config, etmB);
135 135
136 // We need this for derez 136 // We need this for derez
137 SceneHelpers.SetupSceneModules(sceneA, new PermissionsModule()); 137 //SceneHelpers.SetupSceneModules(sceneA, new PermissionsModule());
138 138
139 UserAccount uaA = UserAccountHelpers.CreateUserWithInventory(sceneA, "Andy", "AAA", 0x1, ""); 139 UserAccount uaA = UserAccountHelpers.CreateUserWithInventory(sceneA, "Andy", "AAA", 0x1, "");
140 UserAccount uaB = UserAccountHelpers.CreateUserWithInventory(sceneA, "Brian", "BBB", 0x2, ""); 140 UserAccount uaB = UserAccountHelpers.CreateUserWithInventory(sceneA, "Brian", "BBB", 0x2, "");
@@ -154,12 +154,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
154 uint soLocalId = so.LocalId; 154 uint soLocalId = so.LocalId;
155 155
156 sceneA.DeleteSceneObject(so, false); 156 sceneA.DeleteSceneObject(so, false);
157
158 Assert.That(clientA.ReceivedKills.Count, Is.EqualTo(1));
159 Assert.That(clientA.ReceivedKills[0], Is.EqualTo(soLocalId));
160
161 Assert.That(childClientsB[0].ReceivedKills.Count, Is.EqualTo(1));
162 Assert.That(childClientsB[0].ReceivedKills[0], Is.EqualTo(soLocalId));
163 } 157 }
164 158
165 /// <summary> 159 /// <summary>
@@ -178,7 +172,10 @@ namespace OpenSim.Region.Framework.Scenes.Tests
178 UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001"); 172 UUID objectOwnerId = UUID.Parse("20000000-0000-0000-0000-000000000001");
179 173
180 TestScene scene = new SceneHelpers().SetupScene(); 174 TestScene scene = new SceneHelpers().SetupScene();
181 SceneHelpers.SetupSceneModules(scene, new PermissionsModule()); 175 IConfigSource configSource = new IniConfigSource();
176 IConfig config = configSource.AddConfig("Startup");
177 config.Set("serverside_object_permissions", true);
178 SceneHelpers.SetupSceneModules(scene, configSource, new object[] { new DefaultPermissionsModule() });
182 IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient; 179 IClientAPI client = SceneHelpers.AddScenePresence(scene, userId).ControllingClient;
183 180
184 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test. 181 // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
@@ -261,4 +258,4 @@ namespace OpenSim.Region.Framework.Scenes.Tests
261// Assert.That(retrievedPart, Is.Null); 258// Assert.That(retrievedPart, Is.Null);
262 } 259 }
263 } 260 }
264} \ No newline at end of file 261}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
index 11e9084..ce7fc0e 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs
@@ -61,6 +61,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
61 Assert.That(g1Post.RootPart.Scale.X, Is.EqualTo(2)); 61 Assert.That(g1Post.RootPart.Scale.X, Is.EqualTo(2));
62 Assert.That(g1Post.RootPart.Scale.Y, Is.EqualTo(3)); 62 Assert.That(g1Post.RootPart.Scale.Y, Is.EqualTo(3));
63 Assert.That(g1Post.RootPart.Scale.Z, Is.EqualTo(4)); 63 Assert.That(g1Post.RootPart.Scale.Z, Is.EqualTo(4));
64
65 Assert.That(g1Post.RootPart.UndoCount, Is.EqualTo(1));
64 } 66 }
65 67
66 /// <summary> 68 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
index fd49c88..32d6649 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectUserGroupTests.cs
@@ -43,7 +43,7 @@ using OpenSim.Tests.Common;
43namespace OpenSim.Region.Framework.Scenes.Tests 43namespace OpenSim.Region.Framework.Scenes.Tests
44{ 44{
45 [TestFixture] 45 [TestFixture]
46 public class SceneObjectUserGroupTests : OpenSimTestCase 46 public class SceneObjectUserGroupTests
47 { 47 {
48 /// <summary> 48 /// <summary>
49 /// Test share with group object functionality 49 /// Test share with group object functionality
@@ -53,6 +53,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
53 public void TestShareWithGroup() 53 public void TestShareWithGroup()
54 { 54 {
55 TestHelpers.InMethod(); 55 TestHelpers.InMethod();
56// log4net.Config.XmlConfigurator.Configure();
56 57
57 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001"); 58 UUID userId = UUID.Parse("10000000-0000-0000-0000-000000000001");
58 59
@@ -69,7 +70,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
69 70
70 SceneHelpers.SetupSceneModules( 71 SceneHelpers.SetupSceneModules(
71 scene, configSource, new object[] 72 scene, configSource, new object[]
72 { new PermissionsModule(), 73 { new DefaultPermissionsModule(),
73 new GroupsModule(), 74 new GroupsModule(),
74 new MockGroupsServicesConnector() }); 75 new MockGroupsServicesConnector() });
75 76
@@ -80,4 +81,4 @@ namespace OpenSim.Region.Framework.Scenes.Tests
80 groupsModule.CreateGroup(client, "group1", "To boldly go", true, UUID.Zero, 5, true, true, true); 81 groupsModule.CreateGroup(client, "group1", "To boldly go", true, UUID.Zero, 5, true, true, true);
81 } 82 }
82 } 83 }
83} \ No newline at end of file 84}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs
index cca30db..45bfbff 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs
@@ -74,14 +74,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
74 SceneHelpers.SetupSceneModules(scene, capsMod); 74 SceneHelpers.SetupSceneModules(scene, capsMod);
75 75
76 ScenePresence sp = SceneHelpers.AddChildScenePresence(scene, spUuid); 76 ScenePresence sp = SceneHelpers.AddChildScenePresence(scene, spUuid);
77 Assert.That(capsMod.GetCapsForUser(spUuid), Is.Not.Null); 77 //Assert.That(capsMod.GetCapsForUser(spUuid), Is.Not.Null);
78 78
79 // TODO: Need to add tests for other ICapabiltiesModule methods. 79 // TODO: Need to add tests for other ICapabiltiesModule methods.
80 80
81// scene.IncomingCloseAgent(sp.UUID, false);
82// //Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null);
81 scene.CloseAgent(sp.UUID, false); 83 scene.CloseAgent(sp.UUID, false);
82 Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null); 84// Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null);
83 85
84 // TODO: Need to add tests for other ICapabiltiesModule methods. 86 // TODO: Need to add tests for other ICapabiltiesModule methods.
85 } 87 }
86 } 88 }
87} \ No newline at end of file 89}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
index e14da8b..c193a97 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs
@@ -191,7 +191,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
191 // We need to set up the permisions module on scene B so that our later use of agent limit to deny 191 // We need to set up the permisions module on scene B so that our later use of agent limit to deny
192 // QueryAccess won't succeed anyway because administrators are always allowed in and the default 192 // QueryAccess won't succeed anyway because administrators are always allowed in and the default
193 // IsAdministrator if no permissions module is present is true. 193 // IsAdministrator if no permissions module is present is true.
194 SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB); 194// SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB);
195 195
196 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); 196 AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
197 TestClient tc = new TestClient(acd, sceneA); 197 TestClient tc = new TestClient(acd, sceneA);
@@ -245,4 +245,4 @@ namespace OpenSim.Region.Framework.Scenes.Tests
245 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); 245 Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
246 } 246 }
247 } 247 }
248} \ No newline at end of file 248}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
index da93d44..42276dd 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTeleportTests.cs
@@ -281,7 +281,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
281 // We need to set up the permisions module on scene B so that our later use of agent limit to deny 281 // We need to set up the permisions module on scene B so that our later use of agent limit to deny
282 // QueryAccess won't succeed anyway because administrators are always allowed in and the default 282 // QueryAccess won't succeed anyway because administrators are always allowed in and the default
283 // IsAdministrator if no permissions module is present is true. 283 // IsAdministrator if no permissions module is present is true.
284 SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB }); 284 SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new DefaultPermissionsModule(), etmB });
285 285
286 // Shared scene modules 286 // Shared scene modules
287 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); 287 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
@@ -446,7 +446,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
446 // We need to set up the permisions module on scene B so that our later use of agent limit to deny 446 // We need to set up the permisions module on scene B so that our later use of agent limit to deny
447 // QueryAccess won't succeed anyway because administrators are always allowed in and the default 447 // QueryAccess won't succeed anyway because administrators are always allowed in and the default
448 // IsAdministrator if no permissions module is present is true. 448 // IsAdministrator if no permissions module is present is true.
449 SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB }); 449 SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new DefaultPermissionsModule(), etmB });
450 450
451 // Shared scene modules 451 // Shared scene modules
452 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); 452 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
@@ -659,4 +659,4 @@ namespace OpenSim.Region.Framework.Scenes.Tests
659// TestHelpers.DisableLogging(); 659// TestHelpers.DisableLogging();
660 } 660 }
661 } 661 }
662} \ No newline at end of file 662}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
index 8ec6974..3caea8b 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/TaskInventoryTests.cs
@@ -96,7 +96,7 @@ namespace OpenSim.Region.Framework.Tests
96 Quaternion rezRot = new Quaternion(0.5f, 0.5f, 0.5f, 0.5f); 96 Quaternion rezRot = new Quaternion(0.5f, 0.5f, 0.5f, 0.5f);
97 Vector3 rezVel = new Vector3(2, 2, 2); 97 Vector3 rezVel = new Vector3(2, 2, 2);
98 98
99 scene.RezObject(sop1, taskSceneObjectItem, rezPos, rezRot, rezVel, 0); 99 scene.RezObject(sop1, taskSceneObjectItem, rezPos, rezRot, rezVel, 0,false);
100 100
101 SceneObjectGroup rezzedObject = scene.GetSceneObjectGroup("tso"); 101 SceneObjectGroup rezzedObject = scene.GetSceneObjectGroup("tso");
102 102
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs
index 860172c..7bbf1bd 100644
--- a/OpenSim/Region/Framework/Scenes/UndoState.cs
+++ b/OpenSim/Region/Framework/Scenes/UndoState.cs
@@ -27,202 +27,307 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using System.Collections.Generic;
30using log4net; 31using log4net;
31using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Framework;
32using OpenSim.Region.Framework.Interfaces; 34using OpenSim.Region.Framework.Interfaces;
33 35
34namespace OpenSim.Region.Framework.Scenes 36namespace OpenSim.Region.Framework.Scenes
35{ 37{
36 public class UndoState 38 public class UndoState
37 { 39 {
38// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 40 const int UNDOEXPIRESECONDS = 300; // undo expire time (nice to have it came from a ini later)
39
40 public Vector3 Position = Vector3.Zero;
41 public Vector3 Scale = Vector3.Zero;
42 public Quaternion Rotation = Quaternion.Identity;
43
44 /// <summary>
45 /// Is this undo state for an entire group?
46 /// </summary>
47 public bool ForGroup;
48 41
42 public ObjectChangeData data;
43 public DateTime creationtime;
49 /// <summary> 44 /// <summary>
50 /// Constructor. 45 /// Constructor.
51 /// </summary> 46 /// </summary>
52 /// <param name="part"></param> 47 /// <param name="part"></param>
53 /// <param name="forGroup">True if the undo is for an entire group</param> 48 /// <param name="change">bit field with what is changed</param>
54 public UndoState(SceneObjectPart part, bool forGroup) 49 ///
50 public UndoState(SceneObjectPart part, ObjectChangeType change)
55 { 51 {
56 if (part.ParentID == 0) 52 data = new ObjectChangeData();
57 { 53 data.change = change;
58 ForGroup = forGroup; 54 creationtime = DateTime.UtcNow;
59
60// if (ForGroup)
61 Position = part.ParentGroup.AbsolutePosition;
62// else
63// Position = part.OffsetPosition;
64
65// m_log.DebugFormat(
66// "[UNDO STATE]: Storing undo position {0} for root part", Position);
67 55
68 Rotation = part.RotationOffset; 56 if (part.ParentGroup.RootPart == part)
69 57 {
70// m_log.DebugFormat( 58 if ((change & ObjectChangeType.Position) != 0)
71// "[UNDO STATE]: Storing undo rotation {0} for root part", Rotation); 59 data.position = part.ParentGroup.AbsolutePosition;
72 60 if ((change & ObjectChangeType.Rotation) != 0)
73 Scale = part.Shape.Scale; 61 data.rotation = part.RotationOffset;
74 62 if ((change & ObjectChangeType.Scale) != 0)
75// m_log.DebugFormat( 63 data.scale = part.Shape.Scale;
76// "[UNDO STATE]: Storing undo scale {0} for root part", Scale);
77 } 64 }
78 else 65 else
79 { 66 {
80 Position = part.OffsetPosition; 67 if ((change & ObjectChangeType.Position) != 0)
81// m_log.DebugFormat( 68 data.position = part.OffsetPosition;
82// "[UNDO STATE]: Storing undo position {0} for child part", Position); 69 if ((change & ObjectChangeType.Rotation) != 0)
70 data.rotation = part.RotationOffset;
71 if ((change & ObjectChangeType.Scale) != 0)
72 data.scale = part.Shape.Scale;
73 }
74 }
75 /// <summary>
76 /// check if undo or redo is too old
77 /// </summary>
83 78
84 Rotation = part.RotationOffset; 79 public bool checkExpire()
85// m_log.DebugFormat( 80 {
86// "[UNDO STATE]: Storing undo rotation {0} for child part", Rotation); 81 TimeSpan t = DateTime.UtcNow - creationtime;
82 if (t.Seconds > UNDOEXPIRESECONDS)
83 return true;
84 return false;
85 }
87 86
88 Scale = part.Shape.Scale; 87 /// <summary>
89// m_log.DebugFormat( 88 /// updates undo or redo creation time to now
90// "[UNDO STATE]: Storing undo scale {0} for child part", Scale); 89 /// </summary>
91 } 90 public void updateExpire()
91 {
92 creationtime = DateTime.UtcNow;
92 } 93 }
93 94
94 /// <summary> 95 /// <summary>
95 /// Compare the relevant state in the given part to this state. 96 /// Compare the relevant state in the given part to this state.
96 /// </summary> 97 /// </summary>
97 /// <param name="part"></param> 98 /// <param name="part"></param>
98 /// <returns>true if both the part's position, rotation and scale match those in this undo state. False otherwise.</returns> 99 /// <returns>true what fiels and related data are equal, False otherwise.</returns>
99 public bool Compare(SceneObjectPart part) 100 ///
101 public bool Compare(SceneObjectPart part, ObjectChangeType change)
100 { 102 {
103 if (data.change != change) // if diferent targets, then they are diferent
104 return false;
105
101 if (part != null) 106 if (part != null)
102 { 107 {
103 if (part.ParentID == 0) 108 if (part.ParentID == 0)
104 return 109 {
105 Position == part.ParentGroup.AbsolutePosition 110 if ((change & ObjectChangeType.Position) != 0 && data.position != part.ParentGroup.AbsolutePosition)
106 && Rotation == part.RotationOffset 111 return false;
107 && Scale == part.Shape.Scale; 112 }
108 else 113 else
109 return 114 {
110 Position == part.OffsetPosition 115 if ((change & ObjectChangeType.Position) != 0 && data.position != part.OffsetPosition)
111 && Rotation == part.RotationOffset 116 return false;
112 && Scale == part.Shape.Scale; 117 }
113 } 118
119 if ((change & ObjectChangeType.Rotation) != 0 && data.rotation != part.RotationOffset)
120 return false;
121 if ((change & ObjectChangeType.Rotation) != 0 && data.scale == part.Shape.Scale)
122 return false;
123 return true;
114 124
125 }
115 return false; 126 return false;
116 } 127 }
117 128
118 public void PlaybackState(SceneObjectPart part) 129 /// <summary>
130 /// executes the undo or redo to a part or its group
131 /// </summary>
132 /// <param name="part"></param>
133 ///
134
135 public void PlayState(SceneObjectPart part)
119 { 136 {
120 part.Undoing = true; 137 part.Undoing = true;
121 138
122 if (part.ParentID == 0) 139 SceneObjectGroup grp = part.ParentGroup;
123 {
124// m_log.DebugFormat(
125// "[UNDO STATE]: Undoing position to {0} for root part {1} {2}",
126// Position, part.Name, part.LocalId);
127 140
128 if (Position != Vector3.Zero) 141 if (grp != null)
129 { 142 {
130 if (ForGroup) 143 grp.doChangeObject(part, data);
131 part.ParentGroup.AbsolutePosition = Position; 144 }
132 else 145 part.Undoing = false;
133 part.ParentGroup.UpdateRootPosition(Position); 146 }
134 } 147 }
135 148
136// m_log.DebugFormat( 149 public class UndoRedoState
137// "[UNDO STATE]: Undoing rotation {0} to {1} for root part {2} {3}", 150 {
138// part.RotationOffset, Rotation, part.Name, part.LocalId); 151 int size;
152 public LinkedList<UndoState> m_redo = new LinkedList<UndoState>();
153 public LinkedList<UndoState> m_undo = new LinkedList<UndoState>();
139 154
140 if (ForGroup) 155 /// <summary>
141 part.UpdateRotation(Rotation); 156 /// creates a new UndoRedoState with default states memory size
142 else 157 /// </summary>
143 part.ParentGroup.UpdateRootRotation(Rotation);
144 158
145 if (Scale != Vector3.Zero) 159 public UndoRedoState()
146 { 160 {
147// m_log.DebugFormat( 161 size = 5;
148// "[UNDO STATE]: Undoing scale {0} to {1} for root part {2} {3}", 162 }
149// part.Shape.Scale, Scale, part.Name, part.LocalId);
150 163
151 if (ForGroup) 164 /// <summary>
152 part.ParentGroup.GroupResize(Scale); 165 /// creates a new UndoRedoState with states memory having indicated size
153 else 166 /// </summary>
154 part.Resize(Scale); 167 /// <param name="size"></param>
155 }
156 168
157 part.ParentGroup.ScheduleGroupForTerseUpdate(); 169 public UndoRedoState(int _size)
158 } 170 {
171 if (_size < 3)
172 size = 3;
159 else 173 else
160 { 174 size = _size;
161 // Note: Updating these properties on sop automatically schedules an update if needed 175 }
162 if (Position != Vector3.Zero)
163 {
164// m_log.DebugFormat(
165// "[UNDO STATE]: Undoing position {0} to {1} for child part {2} {3}",
166// part.OffsetPosition, Position, part.Name, part.LocalId);
167 176
168 part.OffsetPosition = Position; 177 /// <summary>
169 } 178 /// returns number of undo entries in memory
179 /// </summary>
170 180
171// m_log.DebugFormat( 181 public int Count
172// "[UNDO STATE]: Undoing rotation {0} to {1} for child part {2} {3}", 182 {
173// part.RotationOffset, Rotation, part.Name, part.LocalId); 183 get { return m_undo.Count; }
184 }
174 185
175 part.UpdateRotation(Rotation); 186 /// <summary>
187 /// clears all undo and redo entries
188 /// </summary>
176 189
177 if (Scale != Vector3.Zero) 190 public void Clear()
191 {
192 m_undo.Clear();
193 m_redo.Clear();
194 }
195
196 /// <summary>
197 /// adds a new state undo to part or its group, with changes indicated by what bits
198 /// </summary>
199 /// <param name="part"></param>
200 /// <param name="change">bit field with what is changed</param>
201
202 public void StoreUndo(SceneObjectPart part, ObjectChangeType change)
203 {
204 lock (m_undo)
205 {
206 UndoState last;
207
208 if (m_redo.Count > 0) // last code seems to clear redo on every new undo
178 { 209 {
179// m_log.DebugFormat( 210 m_redo.Clear();
180// "[UNDO STATE]: Undoing scale {0} to {1} for child part {2} {3}", 211 }
181// part.Shape.Scale, Scale, part.Name, part.LocalId);
182 212
183 part.Resize(Scale); 213 if (m_undo.Count > 0)
214 {
215 // check expired entry
216 last = m_undo.First.Value;
217 if (last != null && last.checkExpire())
218 m_undo.Clear();
219 else
220 {
221 // see if we actually have a change
222 if (last != null)
223 {
224 if (last.Compare(part, change))
225 return;
226 }
227 }
184 } 228 }
185 }
186 229
187 part.Undoing = false; 230 // limite size
231 while (m_undo.Count >= size)
232 m_undo.RemoveLast();
233
234 UndoState nUndo = new UndoState(part, change);
235 m_undo.AddFirst(nUndo);
236 }
188 } 237 }
189 238
190 public void PlayfwdState(SceneObjectPart part) 239 /// <summary>
191 { 240 /// executes last state undo to part or its group
192 part.Undoing = true; 241 /// current state is pushed into redo
242 /// </summary>
243 /// <param name="part"></param>
193 244
194 if (part.ParentID == 0) 245 public void Undo(SceneObjectPart part)
246 {
247 lock (m_undo)
195 { 248 {
196 if (Position != Vector3.Zero) 249 UndoState nUndo;
197 part.ParentGroup.AbsolutePosition = Position;
198
199 if (Rotation != Quaternion.Identity)
200 part.UpdateRotation(Rotation);
201 250
202 if (Scale != Vector3.Zero) 251 // expire redo
252 if (m_redo.Count > 0)
203 { 253 {
204 if (ForGroup) 254 nUndo = m_redo.First.Value;
205 part.ParentGroup.GroupResize(Scale); 255 if (nUndo != null && nUndo.checkExpire())
206 else 256 m_redo.Clear();
207 part.Resize(Scale);
208 } 257 }
209 258
210 part.ParentGroup.ScheduleGroupForTerseUpdate(); 259 if (m_undo.Count > 0)
260 {
261 UndoState goback = m_undo.First.Value;
262 // check expired
263 if (goback != null && goback.checkExpire())
264 {
265 m_undo.Clear();
266 return;
267 }
268
269 if (goback != null)
270 {
271 m_undo.RemoveFirst();
272
273 // redo limite size
274 while (m_redo.Count >= size)
275 m_redo.RemoveLast();
276
277 nUndo = new UndoState(part, goback.data.change); // new value in part should it be full goback copy?
278 m_redo.AddFirst(nUndo);
279
280 goback.PlayState(part);
281 }
282 }
211 } 283 }
212 else 284 }
285
286 /// <summary>
287 /// executes last state redo to part or its group
288 /// current state is pushed into undo
289 /// </summary>
290 /// <param name="part"></param>
291
292 public void Redo(SceneObjectPart part)
293 {
294 lock (m_undo)
213 { 295 {
214 // Note: Updating these properties on sop automatically schedules an update if needed 296 UndoState nUndo;
215 if (Position != Vector3.Zero)
216 part.OffsetPosition = Position;
217 297
218 if (Rotation != Quaternion.Identity) 298 // expire undo
219 part.UpdateRotation(Rotation); 299 if (m_undo.Count > 0)
300 {
301 nUndo = m_undo.First.Value;
302 if (nUndo != null && nUndo.checkExpire())
303 m_undo.Clear();
304 }
220 305
221 if (Scale != Vector3.Zero) 306 if (m_redo.Count > 0)
222 part.Resize(Scale); 307 {
308 UndoState gofwd = m_redo.First.Value;
309 // check expired
310 if (gofwd != null && gofwd.checkExpire())
311 {
312 m_redo.Clear();
313 return;
314 }
315
316 if (gofwd != null)
317 {
318 m_redo.RemoveFirst();
319
320 // limite undo size
321 while (m_undo.Count >= size)
322 m_undo.RemoveLast();
323
324 nUndo = new UndoState(part, gofwd.data.change); // new value in part should it be full gofwd copy?
325 m_undo.AddFirst(nUndo);
326
327 gofwd.PlayState(part);
328 }
329 }
223 } 330 }
224
225 part.Undoing = false;
226 } 331 }
227 } 332 }
228 333
@@ -247,4 +352,4 @@ namespace OpenSim.Region.Framework.Scenes
247 m_terrainModule.UndoTerrain(m_terrainChannel); 352 m_terrainModule.UndoTerrain(m_terrainChannel);
248 } 353 }
249 } 354 }
250} \ No newline at end of file 355}
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index 9ec4e1d..25bbd3a 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -120,12 +120,52 @@ namespace OpenSim.Region.Framework.Scenes
120 /// <param name="uuid">UUID.</param> 120 /// <param name="uuid">UUID.</param>
121 public bool AddForInspection(UUID uuid) 121 public bool AddForInspection(UUID uuid)
122 { 122 {
123<<<<<<< HEAD
123 if (m_assetUuidsToInspect.Contains(uuid)) 124 if (m_assetUuidsToInspect.Contains(uuid))
124 return false; 125 return false;
125 126
126// m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid); 127// m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
127 128
128 m_assetUuidsToInspect.Enqueue(uuid); 129 m_assetUuidsToInspect.Enqueue(uuid);
130=======
131 try
132 {
133 assetUuids[assetUuid] = assetType;
134
135 if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType)
136 {
137 GetWearableAssetUuids(assetUuid, assetUuids);
138 }
139 else if ((sbyte)AssetType.Gesture == assetType)
140 {
141 GetGestureAssetUuids(assetUuid, assetUuids);
142 }
143 else if ((sbyte)AssetType.Notecard == assetType)
144 {
145 GetTextEmbeddedAssetUuids(assetUuid, assetUuids);
146 }
147 else if ((sbyte)AssetType.LSLText == assetType)
148 {
149 GetTextEmbeddedAssetUuids(assetUuid, assetUuids);
150 }
151 else if ((sbyte)OpenSimAssetType.Material == assetType)
152 {
153 GetMaterialAssetUuids(assetUuid, assetUuids);
154 }
155 else if ((sbyte)AssetType.Object == assetType)
156 {
157 GetSceneObjectAssetUuids(assetUuid, assetUuids);
158 }
159 }
160 catch (Exception)
161 {
162 m_log.ErrorFormat(
163 "[UUID GATHERER]: Failed to gather uuids for asset id {0}, type {1}",
164 assetUuid, assetType);
165 throw;
166 }
167 }
168>>>>>>> avn/ubitvar
129 169
130 return true; 170 return true;
131 } 171 }
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
index 6fe86b2..a34f6ee 100644
--- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
+++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
@@ -58,6 +58,8 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
58 58
59 public ISceneAgent SceneAgent { get; set; } 59 public ISceneAgent SceneAgent { get; set; }
60 60
61 public int PingTimeMS { get { return 0; } }
62
61 private string m_username; 63 private string m_username;
62 private string m_nick; 64 private string m_nick;
63 65
@@ -66,6 +68,8 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
66 68
67 private bool m_connected = true; 69 private bool m_connected = true;
68 70
71 public List<uint> SelectedObjects {get; private set;}
72
69 public IRCClientView(TcpClient client, Scene scene) 73 public IRCClientView(TcpClient client, Scene scene)
70 { 74 {
71 m_client = client; 75 m_client = client;
@@ -671,6 +675,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
671 public event ObjectDrop OnObjectDrop; 675 public event ObjectDrop OnObjectDrop;
672 public event StartAnim OnStartAnim; 676 public event StartAnim OnStartAnim;
673 public event StopAnim OnStopAnim; 677 public event StopAnim OnStopAnim;
678 public event ChangeAnim OnChangeAnim;
674 public event LinkObjects OnLinkObjects; 679 public event LinkObjects OnLinkObjects;
675 public event DelinkObjects OnDelinkObjects; 680 public event DelinkObjects OnDelinkObjects;
676 public event RequestMapBlocks OnRequestMapBlocks; 681 public event RequestMapBlocks OnRequestMapBlocks;
@@ -717,6 +722,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
717 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily; 722 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
718 public event UpdatePrimFlags OnUpdatePrimFlags; 723 public event UpdatePrimFlags OnUpdatePrimFlags;
719 public event UpdatePrimTexture OnUpdatePrimTexture; 724 public event UpdatePrimTexture OnUpdatePrimTexture;
725 public event ClientChangeObject onClientChangeObject;
720 public event UpdateVector OnUpdatePrimGroupPosition; 726 public event UpdateVector OnUpdatePrimGroupPosition;
721 public event UpdateVector OnUpdatePrimSinglePosition; 727 public event UpdateVector OnUpdatePrimSinglePosition;
722 public event UpdatePrimRotation OnUpdatePrimGroupRotation; 728 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
@@ -821,6 +827,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
821 public event ObjectOwner OnObjectOwner; 827 public event ObjectOwner OnObjectOwner;
822 public event DirPlacesQuery OnDirPlacesQuery; 828 public event DirPlacesQuery OnDirPlacesQuery;
823 public event DirFindQuery OnDirFindQuery; 829 public event DirFindQuery OnDirFindQuery;
830 public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
824 public event DirLandQuery OnDirLandQuery; 831 public event DirLandQuery OnDirLandQuery;
825 public event DirPopularQuery OnDirPopularQuery; 832 public event DirPopularQuery OnDirPopularQuery;
826 public event DirClassifiedQuery OnDirClassifiedQuery; 833 public event DirClassifiedQuery OnDirClassifiedQuery;
@@ -837,7 +844,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
837 public event ClassifiedInfoRequest OnClassifiedInfoRequest; 844 public event ClassifiedInfoRequest OnClassifiedInfoRequest;
838 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; 845 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
839 public event ClassifiedDelete OnClassifiedDelete; 846 public event ClassifiedDelete OnClassifiedDelete;
840 public event ClassifiedDelete OnClassifiedGodDelete; 847 public event ClassifiedGodDelete OnClassifiedGodDelete;
841 public event EventNotificationAddRequest OnEventNotificationAddRequest; 848 public event EventNotificationAddRequest OnEventNotificationAddRequest;
842 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; 849 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
843 public event EventGodDelete OnEventGodDelete; 850 public event EventGodDelete OnEventGodDelete;
@@ -867,10 +874,12 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
867 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; 874 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
868 public event SimWideDeletesDelegate OnSimWideDeletes; 875 public event SimWideDeletesDelegate OnSimWideDeletes;
869 public event SendPostcard OnSendPostcard; 876 public event SendPostcard OnSendPostcard;
877 public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
870 public event MuteListEntryUpdate OnUpdateMuteListEntry; 878 public event MuteListEntryUpdate OnUpdateMuteListEntry;
871 public event MuteListEntryRemove OnRemoveMuteListEntry; 879 public event MuteListEntryRemove OnRemoveMuteListEntry;
872 public event GodlikeMessage onGodlikeMessage; 880 public event GodlikeMessage onGodlikeMessage;
873 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 881 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
882 public event GenericCall2 OnUpdateThrottles;
874 883
875#pragma warning restore 67 884#pragma warning restore 67
876 885
@@ -888,10 +897,10 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
888 897
889 public void Close() 898 public void Close()
890 { 899 {
891 Close(false); 900 Close(true, false);
892 } 901 }
893 902
894 public void Close(bool force) 903 public void Close(bool sendStop, bool force)
895 { 904 {
896 Disconnect(); 905 Disconnect();
897 } 906 }
@@ -988,6 +997,11 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
988 997
989 } 998 }
990 999
1000 public virtual bool CanSendLayerData()
1001 {
1002 return false;
1003 }
1004
991 public void SendLayerData(float[] map) 1005 public void SendLayerData(float[] map)
992 { 1006 {
993 1007
@@ -1104,7 +1118,12 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1104 1118
1105 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId) 1119 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
1106 { 1120 {
1107 1121
1122 }
1123
1124 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
1125 {
1126
1108 } 1127 }
1109 1128
1110 public void SendRemoveInventoryItem(UUID itemID) 1129 public void SendRemoveInventoryItem(UUID itemID)
@@ -1127,7 +1146,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1127 1146
1128 } 1147 }
1129 1148
1130 public void SendXferPacket(ulong xferID, uint packet, byte[] data) 1149 public void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory)
1131 { 1150 {
1132 1151
1133 } 1152 }
@@ -1421,6 +1440,16 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1421 1440
1422 } 1441 }
1423 1442
1443 public virtual void SetChildAgentThrottle(byte[] throttle,float factor)
1444 {
1445
1446 }
1447
1448 public void SetAgentThrottleSilent(int throttle, int setting)
1449 {
1450
1451
1452 }
1424 public byte[] GetThrottlesPacked(float multiplier) 1453 public byte[] GetThrottlesPacked(float multiplier)
1425 { 1454 {
1426 return new byte[0]; 1455 return new byte[0];
@@ -1687,5 +1716,13 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1687 { 1716 {
1688 } 1717 }
1689 1718
1719 public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
1720 {
1721 }
1722
1723 public int GetAgentThrottleSilent(int throttle)
1724 {
1725 return 0;
1726 }
1690 } 1727 }
1691} 1728}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs
index 84211a9..5c45e4d 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs
@@ -42,6 +42,7 @@ using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.Framework.Scenes.Animation; 43using OpenSim.Region.Framework.Scenes.Animation;
44using OpenSim.Services.Interfaces; 44using OpenSim.Services.Interfaces;
45using AnimationSet = OpenSim.Region.Framework.Scenes.Animation.AnimationSet;
45 46
46namespace OpenSim.Region.OptionalModules.Avatar.Animations 47namespace OpenSim.Region.OptionalModules.Avatar.Animations
47{ 48{
@@ -197,4 +198,4 @@ namespace OpenSim.Region.OptionalModules.Avatar.Animations
197 sb.Append("\n"); 198 sb.Append("\n");
198 } 199 }
199 } 200 }
200} \ No newline at end of file 201}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs
index 535bf67..d56e39d 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs
@@ -184,7 +184,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments
184 hostPart.ParentGroup.RootPart.ScheduleFullUpdate(); 184 hostPart.ParentGroup.RootPart.ScheduleFullUpdate();
185 } 185 }
186 186
187 return attachmentsModule.AttachObject(target, hostPart.ParentGroup, (uint)attachmentPoint, false, false, true) ? 1 : 0; 187 return attachmentsModule.AttachObject(target, hostPart.ParentGroup, (uint)attachmentPoint, false, false, true, true) ? 1 : 0;
188 } 188 }
189 } 189 }
190} 190}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
index 4e84364..026ceca 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
@@ -107,7 +107,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
107 m_scene.AddCommand( 107 m_scene.AddCommand(
108 "Friends", this, "friends show", 108 "Friends", this, "friends show",
109 "friends show [--cache] <first-name> <last-name>", 109 "friends show [--cache] <first-name> <last-name>",
110 "Show the friends for the given user if they exist.\n", 110 "Show the friends for the given user if they exist.",
111 "The --cache option will show locally cached information for that user.", 111 "The --cache option will show locally cached information for that user.",
112 HandleFriendsShowCommand); 112 HandleFriendsShowCommand);
113 } 113 }
@@ -197,4 +197,4 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
197 } 197 }
198 } 198 }
199 } 199 }
200} \ No newline at end of file 200}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
index 45af212..3db0781 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
@@ -575,7 +575,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
575 575
576 public Hashtable FreeSwitchSLVoiceGetPreloginHTTPHandler(Hashtable request) 576 public Hashtable FreeSwitchSLVoiceGetPreloginHTTPHandler(Hashtable request)
577 { 577 {
578 m_log.Debug("[FreeSwitchVoice]: FreeSwitchSLVoiceGetPreloginHTTPHandler called"); 578// m_log.Debug("[FreeSwitchVoice] FreeSwitchSLVoiceGetPreloginHTTPHandler called");
579 579
580 Hashtable response = new Hashtable(); 580 Hashtable response = new Hashtable();
581 response["content_type"] = "text/xml"; 581 response["content_type"] = "text/xml";
@@ -726,7 +726,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
726 726
727 public Hashtable FreeSwitchSLVoiceSigninHTTPHandler(Hashtable request) 727 public Hashtable FreeSwitchSLVoiceSigninHTTPHandler(Hashtable request)
728 { 728 {
729 m_log.Debug("[FreeSwitchVoice]: FreeSwitchSLVoiceSigninHTTPHandler called"); 729 //m_log.Debug("[FreeSwitchVoice] FreeSwitchSLVoiceSigninHTTPHandler called");
730// string requestbody = (string)request["body"]; 730// string requestbody = (string)request["body"];
731// string uri = (string)request["uri"]; 731// string uri = (string)request["uri"];
732// string contenttype = (string)request["content-type"]; 732// string contenttype = (string)request["content-type"];
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
index dd44564..f51527e 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs
@@ -121,6 +121,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
121 121
122 public void Initialise(IConfigSource config) 122 public void Initialise(IConfigSource config)
123 { 123 {
124 MainConsole.Instance.Commands.AddCommand("vivox", false, "vivox debug", "vivox debug <on>|<off>", "Set vivox debugging", HandleDebug);
124 125
125 m_config = config.Configs["VivoxVoice"]; 126 m_config = config.Configs["VivoxVoice"];
126 127
@@ -196,7 +197,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
196 break; 197 break;
197 } 198 }
198 199
199 m_vivoxVoiceAccountApi = String.Format("http://{0}/api2", m_vivoxServer); 200 m_vivoxVoiceAccountApi = String.Format("https://{0}/api2", m_vivoxServer);
200 201
201 // Admin interface required values 202 // Admin interface required values
202 if (String.IsNullOrEmpty(m_vivoxServer) || 203 if (String.IsNullOrEmpty(m_vivoxServer) ||
@@ -475,8 +476,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
475 avatarName = avatar.Name; 476 avatarName = avatar.Name;
476 477
477 m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: scene = {0}, agentID = {1}", scene, agentID); 478 m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: scene = {0}, agentID = {1}", scene, agentID);
478 m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 479// m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
479 request, path, param); 480// request, path, param);
480 481
481 XmlElement resp; 482 XmlElement resp;
482 bool retry = false; 483 bool retry = false;
@@ -583,7 +584,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
583 584
584 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 585 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
585 586
586 m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: avatar \"{0}\": {1}", avatarName, r); 587// m_log.DebugFormat("[VivoxVoice][PROVISIONVOICE]: avatar \"{0}\": {1}", avatarName, r);
587 588
588 return r; 589 return r;
589 } 590 }
@@ -630,24 +631,28 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
630 // voice, if all do retrieve or obtain the parcel 631 // voice, if all do retrieve or obtain the parcel
631 // voice channel 632 // voice channel
632 LandData land = scene.GetLandData(avatar.AbsolutePosition); 633 LandData land = scene.GetLandData(avatar.AbsolutePosition);
634 if (land == null)
635 {
636 return "<llsd><undef /></llsd>";
637 }
633 638
634 m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}", 639// m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}",
635 scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, request, path, param); 640// scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, request, path, param);
636 // m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: avatar \"{0}\": location: {1} {2} {3}", 641 // m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: avatar \"{0}\": location: {1} {2} {3}",
637 // avatarName, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z); 642 // avatarName, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
638 643
639 // TODO: EstateSettings don't seem to get propagated... 644 // TODO: EstateSettings don't seem to get propagated...
640 if (!scene.RegionInfo.EstateSettings.AllowVoice) 645 if (!scene.RegionInfo.EstateSettings.AllowVoice)
641 { 646 {
642 m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": voice not enabled in estate settings", 647 //m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": voice not enabled in estate settings",
643 scene.RegionInfo.RegionName); 648 // scene.RegionInfo.RegionName);
644 channel_uri = String.Empty; 649 channel_uri = String.Empty;
645 } 650 }
646 651
647 if ((land.Flags & (uint)ParcelFlags.AllowVoiceChat) == 0) 652 if ((land.Flags & (uint)ParcelFlags.AllowVoiceChat) == 0)
648 { 653 {
649 m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": voice not enabled for parcel", 654 //m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": voice not enabled for parcel",
650 scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName); 655 // scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName);
651 channel_uri = String.Empty; 656 channel_uri = String.Empty;
652 } 657 }
653 else 658 else
@@ -662,8 +667,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
662 parcelVoiceInfo = new LLSDParcelVoiceInfoResponse(scene.RegionInfo.RegionName, land.LocalID, creds); 667 parcelVoiceInfo = new LLSDParcelVoiceInfoResponse(scene.RegionInfo.RegionName, land.LocalID, creds);
663 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 668 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
664 669
665 m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": {4}", 670// m_log.DebugFormat("[VivoxVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": {4}",
666 scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, r); 671// scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, r);
667 return r; 672 return r;
668 } 673 }
669 catch (Exception e) 674 catch (Exception e)
@@ -690,11 +695,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
690 public string ChatSessionRequest(Scene scene, string request, string path, string param, 695 public string ChatSessionRequest(Scene scene, string request, string path, string param,
691 UUID agentID, Caps caps) 696 UUID agentID, Caps caps)
692 { 697 {
693 ScenePresence avatar = scene.GetScenePresence(agentID); 698// ScenePresence avatar = scene.GetScenePresence(agentID);
694 string avatarName = avatar.Name; 699// string avatarName = avatar.Name;
695 700
696 m_log.DebugFormat("[VivoxVoice][CHATSESSION]: avatar \"{0}\": request: {1}, path: {2}, param: {3}", 701// m_log.DebugFormat("[VivoxVoice][CHATSESSION]: avatar \"{0}\": request: {1}, path: {2}, param: {3}",
697 avatarName, request, path, param); 702// avatarName, request, path, param);
698 return "<llsd>true</llsd>"; 703 return "<llsd>true</llsd>";
699 } 704 }
700 705
@@ -744,7 +749,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
744 return channelUri; 749 return channelUri;
745 } 750 }
746 751
747 private static readonly string m_vivoxLoginPath = "http://{0}/api2/viv_signin.php?userid={1}&pwd={2}"; 752
753 private static readonly string m_vivoxLoginPath = "https://{0}/api2/viv_signin.php?userid={1}&pwd={2}";
748 754
749 /// <summary> 755 /// <summary>
750 /// Perform administrative login for Vivox. 756 /// Perform administrative login for Vivox.
@@ -756,7 +762,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
756 return VivoxCall(requrl, false); 762 return VivoxCall(requrl, false);
757 } 763 }
758 764
759 private static readonly string m_vivoxLogoutPath = "http://{0}/api2/viv_signout.php?auth_token={1}"; 765 private static readonly string m_vivoxLogoutPath = "https://{0}/api2/viv_signout.php?auth_token={1}";
760 766
761 /// <summary> 767 /// <summary>
762 /// Perform administrative logout for Vivox. 768 /// Perform administrative logout for Vivox.
@@ -767,7 +773,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
767 return VivoxCall(requrl, false); 773 return VivoxCall(requrl, false);
768 } 774 }
769 775
770 private static readonly string m_vivoxGetAccountPath = "http://{0}/api2/viv_get_acct.php?auth_token={1}&user_name={2}"; 776
777 private static readonly string m_vivoxGetAccountPath = "https://{0}/api2/viv_get_acct.php?auth_token={1}&user_name={2}";
771 778
772 /// <summary> 779 /// <summary>
773 /// Retrieve account information for the specified user. 780 /// Retrieve account information for the specified user.
@@ -779,7 +786,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
779 return VivoxCall(requrl, true); 786 return VivoxCall(requrl, true);
780 } 787 }
781 788
782 private static readonly string m_vivoxNewAccountPath = "http://{0}/api2/viv_adm_acct_new.php?username={1}&pwd={2}&auth_token={3}"; 789
790 private static readonly string m_vivoxNewAccountPath = "https://{0}/api2/viv_adm_acct_new.php?username={1}&pwd={2}&auth_token={3}";
783 791
784 /// <summary> 792 /// <summary>
785 /// Creates a new account. 793 /// Creates a new account.
@@ -793,7 +801,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
793 return VivoxCall(requrl, true); 801 return VivoxCall(requrl, true);
794 } 802 }
795 803
796 private static readonly string m_vivoxPasswordPath = "http://{0}/api2/viv_adm_password.php?user_name={1}&new_pwd={2}&auth_token={3}"; 804
805 private static readonly string m_vivoxPasswordPath = "https://{0}/api2/viv_adm_password.php?user_name={1}&new_pwd={2}&auth_token={3}";
797 806
798 /// <summary> 807 /// <summary>
799 /// Change the user's password. 808 /// Change the user's password.
@@ -804,7 +813,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
804 return VivoxCall(requrl, true); 813 return VivoxCall(requrl, true);
805 } 814 }
806 815
807 private static readonly string m_vivoxChannelPath = "http://{0}/api2/viv_chan_mod.php?mode={1}&chan_name={2}&auth_token={3}"; 816
817 private static readonly string m_vivoxChannelPath = "https://{0}/api2/viv_chan_mod.php?mode={1}&chan_name={2}&auth_token={3}";
808 818
809 /// <summary> 819 /// <summary>
810 /// Create a channel. 820 /// Create a channel.
@@ -876,7 +886,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
876 return false; 886 return false;
877 } 887 }
878 888
879 private static readonly string m_vivoxChannelSearchPath = "http://{0}/api2/viv_chan_search.php?cond_channame={1}&auth_token={2}"; 889 private static readonly string m_vivoxChannelSearchPath = "https://{0}/api2/viv_chan_search.php?cond_channame={1}&auth_token={2}";
880 890
881 /// <summary> 891 /// <summary>
882 /// Retrieve a channel. 892 /// Retrieve a channel.
@@ -1019,7 +1029,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1019 return false; 1029 return false;
1020 } 1030 }
1021 1031
1022 // private static readonly string m_vivoxChannelById = "http://{0}/api2/viv_chan_mod.php?mode={1}&chan_id={2}&auth_token={3}"; 1032 // private static readonly string m_vivoxChannelById = "https://{0}/api2/viv_chan_mod.php?mode={1}&chan_id={2}&auth_token={3}";
1023 1033
1024 // private XmlElement VivoxGetChannelById(string parent, string channelid) 1034 // private XmlElement VivoxGetChannelById(string parent, string channelid)
1025 // { 1035 // {
@@ -1031,7 +1041,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1031 // return VivoxCall(requrl, true); 1041 // return VivoxCall(requrl, true);
1032 // } 1042 // }
1033 1043
1034 private static readonly string m_vivoxChannelDel = "http://{0}/api2/viv_chan_mod.php?mode={1}&chan_id={2}&auth_token={3}"; 1044 private static readonly string m_vivoxChannelDel = "https://{0}/api2/viv_chan_mod.php?mode={1}&chan_id={2}&auth_token={3}";
1035 1045
1036 /// <summary> 1046 /// <summary>
1037 /// Delete a channel. 1047 /// Delete a channel.
@@ -1044,6 +1054,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1044 /// are required in a later phase. 1054 /// are required in a later phase.
1045 /// In this case the call handles parent and description as optional values. 1055 /// In this case the call handles parent and description as optional values.
1046 /// </summary> 1056 /// </summary>
1057
1047 private XmlElement VivoxDeleteChannel(string parent, string channelid) 1058 private XmlElement VivoxDeleteChannel(string parent, string channelid)
1048 { 1059 {
1049 string requrl = String.Format(m_vivoxChannelDel, m_vivoxServer, "delete", channelid, m_authToken); 1060 string requrl = String.Format(m_vivoxChannelDel, m_vivoxServer, "delete", channelid, m_authToken);
@@ -1054,11 +1065,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1054 return VivoxCall(requrl, true); 1065 return VivoxCall(requrl, true);
1055 } 1066 }
1056 1067
1057 private static readonly string m_vivoxChannelSearch = "http://{0}/api2/viv_chan_search.php?&cond_chanparent={1}&auth_token={2}"; 1068 private static readonly string m_vivoxChannelSearch = "https://{0}/api2/viv_chan_search.php?&cond_chanparent={1}&auth_token={2}";
1058 1069
1059 /// <summary> 1070 /// <summary>
1060 /// Return information on channels in the given directory 1071 /// Return information on channels in the given directory
1061 /// </summary> 1072 /// </summary>
1073
1062 private XmlElement VivoxListChildren(string channelid) 1074 private XmlElement VivoxListChildren(string channelid)
1063 { 1075 {
1064 string requrl = String.Format(m_vivoxChannelSearch, m_vivoxServer, channelid, m_authToken); 1076 string requrl = String.Format(m_vivoxChannelSearch, m_vivoxServer, channelid, m_authToken);
@@ -1124,7 +1136,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1124 try 1136 try
1125 { 1137 {
1126 // Otherwise prepare the request 1138 // Otherwise prepare the request
1127 m_log.DebugFormat("[VivoxVoice] Sending request <{0}>", requrl); 1139 //m_log.DebugFormat("[VivoxVoice] Sending request <{0}>", requrl);
1128 1140
1129 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requrl); 1141 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requrl);
1130 1142
@@ -1324,5 +1336,21 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
1324 result = String.Empty; 1336 result = String.Empty;
1325 return false; 1337 return false;
1326 } 1338 }
1339
1340 private void HandleDebug(string module, string[] cmd)
1341 {
1342 if (cmd.Length < 3)
1343 {
1344 MainConsole.Instance.Output("Error: missing on/off flag");
1345 return;
1346 }
1347
1348 if (cmd[2] == "on")
1349 m_dumpXml = true;
1350 else if (cmd[2] == "off")
1351 m_dumpXml = false;
1352 else
1353 MainConsole.Instance.Output("Error: only on and off are supported");
1354 }
1327 } 1355 }
1328} 1356}
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
index dff3f78..0512e48 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
@@ -206,6 +206,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
206 } 206 }
207 207
208 scene.EventManager.OnNewClient += OnNewClient; 208 scene.EventManager.OnNewClient += OnNewClient;
209 scene.EventManager.OnMakeRootAgent += OnMakeRoot;
210 scene.EventManager.OnMakeChildAgent += OnMakeChild;
209 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; 211 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
210 // The InstantMessageModule itself doesn't do this, 212 // The InstantMessageModule itself doesn't do this,
211 // so lets see if things explode if we don't do it 213 // so lets see if things explode if we don't do it
@@ -256,19 +258,34 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
256 #endregion 258 #endregion
257 259
258 #region EventHandlers 260 #region EventHandlers
261
262 private void OnMakeRoot(ScenePresence sp)
263 {
264 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
265
266 sp.ControllingClient.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
267 // Used for Notices and Group Invites/Accept/Reject
268 sp.ControllingClient.OnInstantMessage += OnInstantMessage;
269 // Send client their groups information.
270// SendAgentGroupDataUpdate(sp.ControllingClient, sp.UUID);
271 // only send data viwer will ask rest later
272 OnAgentDataUpdateRequest(sp.ControllingClient, sp.UUID, sp.UUID);
273 }
274
275 private void OnMakeChild(ScenePresence sp)
276 {
277 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
278
279 sp.ControllingClient.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
280 sp.ControllingClient.OnInstantMessage -= OnInstantMessage;
281 }
282
259 private void OnNewClient(IClientAPI client) 283 private void OnNewClient(IClientAPI client)
260 { 284 {
261 if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); 285 if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
262 286
263 client.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
264 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest; 287 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
265 client.OnRequestAvatarProperties += OnRequestAvatarProperties; 288 client.OnRequestAvatarProperties += OnRequestAvatarProperties;
266
267 // Used for Notices and Group Invites/Accept/Reject
268 client.OnInstantMessage += OnInstantMessage;
269
270 // Send client their groups information.
271 SendAgentGroupDataUpdate(client, client.AgentId);
272 } 289 }
273 290
274 private void OnRequestAvatarProperties(IClientAPI remoteClient, UUID avatarID) 291 private void OnRequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
@@ -984,7 +1001,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
984 msg.toAgentID = agentID.Guid; 1001 msg.toAgentID = agentID.Guid;
985 msg.dialog = dialog; 1002 msg.dialog = dialog;
986 msg.fromGroup = true; 1003 msg.fromGroup = true;
987 msg.offline = (byte)0; 1004 msg.offline = (byte)1; // Allow this message to be stored for offline use
988 msg.ParentEstateID = 0; 1005 msg.ParentEstateID = 0;
989 msg.Position = Vector3.Zero; 1006 msg.Position = Vector3.Zero;
990 msg.RegionID = UUID.Zero.Guid; 1007 msg.RegionID = UUID.Zero.Guid;
diff --git a/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
index 395bbf1..d3c46c9 100644
--- a/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
+++ b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs
@@ -135,31 +135,50 @@ namespace OpenSim.Region.OptionalModules
135 135
136 private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene) 136 private bool CanObjectEnter(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
137 { 137 {
138 if (newPoint.X < -1f || newPoint.X > (scene.RegionInfo.RegionSizeX + 1) ||
139 newPoint.Y < -1f || newPoint.Y > (scene.RegionInfo.RegionSizeY) )
140 return true;
141
138 SceneObjectPart obj = scene.GetSceneObjectPart(objectID); 142 SceneObjectPart obj = scene.GetSceneObjectPart(objectID);
139 Vector3 oldPoint = obj.GroupPosition; 143
140 int objectCount = obj.ParentGroup.PrimCount; 144 if (obj == null)
141 ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y); 145 return false;
146
147 // Prim counts are determined by the location of the root prim. if we're
148 // moving a child prim, just let it pass
149 if (!obj.IsRoot)
150 {
151 return true;
152 }
153
142 ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y); 154 ILandObject newParcel = scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
143 155
156<<<<<<< HEAD
144 // newParcel will be null only if it outside of our current region. If this is the case, then the 157 // newParcel will be null only if it outside of our current region. If this is the case, then the
145 // receiving permissions will perform the check. 158 // receiving permissions will perform the check.
146 if (newParcel == null) 159 if (newParcel == null)
147 return true; 160 return true;
148 161
149 // The prim hasn't crossed a region boundary so we don't need to worry 162 // The prim hasn't crossed a region boundary so we don't need to worry
150 // about prim counts here 163=======
151 if(oldParcel.Equals(newParcel)) 164 if (newParcel == null)
152 {
153 return true; 165 return true;
154 }
155 166
156 // Prim counts are determined by the location of the root prim. if we're 167 Vector3 oldPoint = obj.GroupPosition;
157 // moving a child prim, just let it pass 168 ILandObject oldParcel = scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
158 if(!obj.IsRoot) 169
170 // The prim hasn't crossed a region boundry so we don't need to worry
171>>>>>>> avn/ubitvar
172 // about prim counts here
173 if(oldParcel != null && oldParcel.Equals(newParcel))
159 { 174 {
160 return true; 175 return true;
161 } 176 }
162 177
178 int objectCount = obj.ParentGroup.PrimCount;
179 int usedPrims = newParcel.PrimCounts.Total;
180 int simulatorCapacity = newParcel.GetSimulatorMaxPrimCount();
181
163 // TODO: Add Special Case here for temporary prims 182 // TODO: Add Special Case here for temporary prims
164 183
165 string response = DoCommonChecks(objectCount, obj.OwnerID, newParcel, scene); 184 string response = DoCommonChecks(objectCount, obj.OwnerID, newParcel, scene);
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
index 709d389..97133c0 100644
--- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
@@ -179,7 +179,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule
179 { 179 {
180 if(!m_Channels.ContainsKey(itemID)) 180 if(!m_Channels.ContainsKey(itemID))
181 { 181 {
182 m_log.InfoFormat("[XMLRPC GRID ROUTER]: Attempted to unregister non-existing Item: {0}", itemID.ToString()); 182 //m_log.InfoFormat("[XMLRPC GRID ROUTER]: Attempted to unregister non-existing Item: {0}", itemID.ToString());
183 return false; 183 return false;
184 } 184 }
185 185
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
index 943675e..32549d6 100644
--- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
@@ -98,7 +98,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule
98 98
99 public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) 99 public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri)
100 { 100 {
101 scriptEngine.PostScriptEvent(itemID, "xmlrpc_uri", new Object[] {uri}); 101 if (m_Enabled)
102 {
103 scriptEngine.PostScriptEvent(itemID, "xmlrpc_uri", new Object[] { uri });
104 }
102 } 105 }
103 106
104 public void UnRegisterReceiver(string channelID, UUID itemID) 107 public void UnRegisterReceiver(string channelID, UUID itemID)
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs
index d37369c..fcf5e91 100644
--- a/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs
+++ b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs
@@ -1,29 +1,8 @@
1/* 1// ******************************************************************
2 * Copyright (c) Contributors, http://opensimulator.org/ 2// Copyright (c) 2008, 2009 Melanie Thielker
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3//
4 * 4// All rights reserved
5 * Redistribution and use in source and binary forms, with or without 5//
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 6
28using System; 7using System;
29using System.IO; 8using System.IO;
@@ -131,8 +110,11 @@ namespace OpenSim.Region.OptionalModules.ViewerSupport
131 { 110 {
132 foreach (MenuItemData d in m_menuItems[UUID.Zero]) 111 foreach (MenuItemData d in m_menuItems[UUID.Zero])
133 { 112 {
134 if (d.Mode == UserMode.God && (!m_scene.Permissions.IsGod(agentID))) 113 if (!m_scene.Permissions.IsGod(agentID))
135 continue; 114 {
115 if (d.Mode == UserMode.RegionManager && (!m_scene.Permissions.IsAdministrator(agentID)))
116 continue;
117 }
136 118
137 OSDMap loc = null; 119 OSDMap loc = null;
138 switch (d.Location) 120 switch (d.Location)
diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs
index 4cd5676..8565f5a 100644
--- a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs
+++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs
@@ -205,8 +205,9 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule
205 { 205 {
206 } 206 }
207 207
208 public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount) 208 public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount, UUID txn, out string result)
209 { 209 {
210 result = String.Empty;
210 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID)); 211 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
211 212
212 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description); 213 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
@@ -842,6 +843,10 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule
842 if (module != null) 843 if (module != null)
843 module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice); 844 module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice);
844 } 845 }
846
847 public void MoveMoney(UUID fromAgentID, UUID toAgentID, int amount, string text)
848 {
849 }
845 } 850 }
846 851
847 public enum TransactionType : int 852 public enum TransactionType : int
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index fb644b7..dc1ea95 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -61,10 +61,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC
61 private readonly string m_firstname; 61 private readonly string m_firstname;
62 private readonly string m_lastname; 62 private readonly string m_lastname;
63 private readonly Vector3 m_startPos; 63 private readonly Vector3 m_startPos;
64<<<<<<< HEAD
64 private readonly UUID m_uuid; 65 private readonly UUID m_uuid;
66=======
67 private UUID m_uuid = UUID.Random();
68>>>>>>> avn/ubitvar
65 private readonly Scene m_scene; 69 private readonly Scene m_scene;
66 private readonly UUID m_ownerID; 70 private readonly UUID m_ownerID;
67 71
72 public List<uint> SelectedObjects {get; private set;}
73
68 public NPCAvatar( 74 public NPCAvatar(
69 string firstname, string lastname, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene) 75 string firstname, string lastname, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene)
70 { 76 {
@@ -94,6 +100,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
94 get { return m_scene; } 100 get { return m_scene; }
95 } 101 }
96 102
103 public int PingTimeMS { get { return 0; } }
104
97 public UUID OwnerID 105 public UUID OwnerID
98 { 106 {
99 get { return m_ownerID; } 107 get { return m_ownerID; }
@@ -248,7 +256,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
248#pragma warning disable 67 256#pragma warning disable 67
249 public event Action<IClientAPI> OnLogout; 257 public event Action<IClientAPI> OnLogout;
250 public event ObjectPermissions OnObjectPermissions; 258 public event ObjectPermissions OnObjectPermissions;
251 259 public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
252 public event MoneyTransferRequest OnMoneyTransferRequest; 260 public event MoneyTransferRequest OnMoneyTransferRequest;
253 public event ParcelBuy OnParcelBuy; 261 public event ParcelBuy OnParcelBuy;
254 public event Action<IClientAPI> OnConnectionClosed; 262 public event Action<IClientAPI> OnConnectionClosed;
@@ -268,6 +276,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
268 public event ObjectDrop OnObjectDrop; 276 public event ObjectDrop OnObjectDrop;
269 public event StartAnim OnStartAnim; 277 public event StartAnim OnStartAnim;
270 public event StopAnim OnStopAnim; 278 public event StopAnim OnStopAnim;
279 public event ChangeAnim OnChangeAnim;
271 public event LinkObjects OnLinkObjects; 280 public event LinkObjects OnLinkObjects;
272 public event DelinkObjects OnDelinkObjects; 281 public event DelinkObjects OnDelinkObjects;
273 public event RequestMapBlocks OnRequestMapBlocks; 282 public event RequestMapBlocks OnRequestMapBlocks;
@@ -318,6 +327,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
318 public event UpdatePrimTexture OnUpdatePrimTexture; 327 public event UpdatePrimTexture OnUpdatePrimTexture;
319 public event UpdateVector OnUpdatePrimGroupPosition; 328 public event UpdateVector OnUpdatePrimGroupPosition;
320 public event UpdateVector OnUpdatePrimSinglePosition; 329 public event UpdateVector OnUpdatePrimSinglePosition;
330 public event ClientChangeObject onClientChangeObject;
321 public event UpdatePrimRotation OnUpdatePrimGroupRotation; 331 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
322 public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition; 332 public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
323 public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation; 333 public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
@@ -456,7 +466,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
456 public event ClassifiedInfoRequest OnClassifiedInfoRequest; 466 public event ClassifiedInfoRequest OnClassifiedInfoRequest;
457 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; 467 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
458 public event ClassifiedDelete OnClassifiedDelete; 468 public event ClassifiedDelete OnClassifiedDelete;
459 public event ClassifiedDelete OnClassifiedGodDelete; 469 public event ClassifiedGodDelete OnClassifiedGodDelete;
460 470
461 public event EventNotificationAddRequest OnEventNotificationAddRequest; 471 public event EventNotificationAddRequest OnEventNotificationAddRequest;
462 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; 472 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
@@ -495,11 +505,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC
495 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; 505 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
496 public event SimWideDeletesDelegate OnSimWideDeletes; 506 public event SimWideDeletesDelegate OnSimWideDeletes;
497 public event SendPostcard OnSendPostcard; 507 public event SendPostcard OnSendPostcard;
508 public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
498 public event MuteListEntryUpdate OnUpdateMuteListEntry; 509 public event MuteListEntryUpdate OnUpdateMuteListEntry;
499 public event MuteListEntryRemove OnRemoveMuteListEntry; 510 public event MuteListEntryRemove OnRemoveMuteListEntry;
500 public event GodlikeMessage onGodlikeMessage; 511 public event GodlikeMessage onGodlikeMessage;
501 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 512 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
502 513 public event GenericCall2 OnUpdateThrottles;
503#pragma warning restore 67 514#pragma warning restore 67
504 515
505 #endregion 516 #endregion
@@ -522,6 +533,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
522 public virtual UUID AgentId 533 public virtual UUID AgentId
523 { 534 {
524 get { return m_uuid; } 535 get { return m_uuid; }
536 set { m_uuid = value; }
525 } 537 }
526 538
527 public UUID SessionId 539 public UUID SessionId
@@ -627,6 +639,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC
627 public virtual void SetChildAgentThrottle(byte[] throttle) 639 public virtual void SetChildAgentThrottle(byte[] throttle)
628 { 640 {
629 } 641 }
642
643 public virtual void SetChildAgentThrottle(byte[] throttle, float factor)
644 {
645
646 }
647
648 public void SetAgentThrottleSilent(int throttle, int setting)
649 {
650
651
652 }
630 public byte[] GetThrottlesPacked(float multiplier) 653 public byte[] GetThrottlesPacked(float multiplier)
631 { 654 {
632 return new byte[0]; 655 return new byte[0];
@@ -665,6 +688,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
665 688
666 } 689 }
667 690
691 public virtual bool CanSendLayerData()
692 {
693 return false;
694 }
695
668 public virtual void SendLayerData(float[] map) 696 public virtual void SendLayerData(float[] map)
669 { 697 {
670 } 698 }
@@ -772,6 +800,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
772 { 800 {
773 } 801 }
774 802
803 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
804 {
805 }
806
775 public virtual void SendRemoveInventoryItem(UUID itemID) 807 public virtual void SendRemoveInventoryItem(UUID itemID)
776 { 808 {
777 } 809 }
@@ -788,7 +820,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
788 { 820 {
789 } 821 }
790 822
791 public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data) 823 public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory)
792 { 824 {
793 } 825 }
794 public virtual void SendAbortXferPacket(ulong xferID) 826 public virtual void SendAbortXferPacket(ulong xferID)
@@ -933,10 +965,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
933 965
934 public void Close() 966 public void Close()
935 { 967 {
936 Close(false); 968 Close(true, false);
937 } 969 }
938 970
939 public void Close(bool force) 971 public void Close(bool sendStop, bool force)
940 { 972 {
941 // Remove ourselves from the scene 973 // Remove ourselves from the scene
942 m_scene.RemoveClient(AgentId, false); 974 m_scene.RemoveClient(AgentId, false);
@@ -1269,5 +1301,14 @@ namespace OpenSim.Region.OptionalModules.World.NPC
1269 { 1301 {
1270 } 1302 }
1271 1303
1304 public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
1305 {
1306 }
1307
1308 public int GetAgentThrottleSilent(int throttle)
1309 {
1310 return 0;
1311 }
1312
1272 } 1313 }
1273} 1314}
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 9232db9..2977195 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -167,10 +167,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
167 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, 167 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
168 int.MaxValue); 168 int.MaxValue);
169 169
170 m_log.DebugFormat( 170// m_log.DebugFormat(
171 "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", 171// "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
172 firstname, lastname, npcAvatar.AgentId, owner, 172// firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName);
173 senseAsAgent, position, scene.RegionInfo.RegionName);
174 173
175 AgentCircuitData acd = new AgentCircuitData(); 174 AgentCircuitData acd = new AgentCircuitData();
176 acd.AgentID = npcAvatar.AgentId; 175 acd.AgentID = npcAvatar.AgentId;
@@ -192,36 +191,31 @@ namespace OpenSim.Region.OptionalModules.World.NPC
192 } 191 }
193 */ 192 */
194 193
195 lock (m_avatars) 194// ManualResetEvent ev = new ManualResetEvent(false);
196 {
197 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
198 acd);
199 scene.AddNewAgent(npcAvatar, PresenceType.Npc);
200 195
201 ScenePresence sp; 196// Util.FireAndForget(delegate(object x) {
202 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 197 lock (m_avatars)
203 { 198 {
204 /* 199 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
205 m_log.DebugFormat( 200 scene.AddNewAgent(npcAvatar, PresenceType.Npc);
206 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
207 sp.Name, sp.UUID);
208 */
209 201
210 sp.CompleteMovement(npcAvatar, false); 202 ScenePresence sp;
211 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 203 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
212 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); 204 {
213 205
214 return npcAvatar.AgentId; 206 sp.CompleteMovement(npcAvatar, false);
207 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
208// m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
209 }
215 } 210 }
216 else 211// ev.Set();
217 { 212// });
218 m_log.WarnFormat(
219 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
220 sp.Name, sp.UUID);
221 213
222 return UUID.Zero; 214// ev.WaitOne();
223 } 215
224 } 216// m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);
217
218 return npcAvatar.AgentId;
225 } 219 }
226 220
227 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, 221 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
@@ -436,9 +430,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC
436 { 430 {
437 NPCAvatar av; 431 NPCAvatar av;
438 if (m_avatars.TryGetValue(npcID, out av)) 432 if (m_avatars.TryGetValue(npcID, out av))
433 {
434 if (npcID == callerID)
435 return true;
439 return CheckPermissions(av, callerID); 436 return CheckPermissions(av, callerID);
437 }
440 else 438 else
439 {
441 return false; 440 return false;
441 }
442 } 442 }
443 } 443 }
444 444
@@ -457,8 +457,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC
457 /// <returns>true if they do, false if they don't.</returns> 457 /// <returns>true if they do, false if they don't.</returns>
458 private bool CheckPermissions(NPCAvatar av, UUID callerID) 458 private bool CheckPermissions(NPCAvatar av, UUID callerID)
459 { 459 {
460<<<<<<< HEAD
460 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || 461 return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
461 av.OwnerID == callerID || av.AgentId == callerID; 462 av.OwnerID == callerID || av.AgentId == callerID;
463=======
464 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID || av.AgentId == callerID;
465>>>>>>> avn/ubitvar
462 } 466 }
463 } 467 }
464} 468}
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 0bebb58..2345e38 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -113,7 +113,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
113 // ScenePresence.SendInitialData() to reset our entire appearance. 113 // ScenePresence.SendInitialData() to reset our entire appearance.
114 m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); 114 m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));
115 115
116 m_afMod.SetAppearance(sp, originalTe, null, null); 116 m_afMod.SetAppearance(sp, originalTe, null, new WearableCacheItem[0] );
117 117
118 UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); 118 UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance);
119 119
@@ -484,4 +484,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
484 Assert.That(npc.ParentID, Is.EqualTo(0)); 484 Assert.That(npc.ParentID, Is.EqualTo(0));
485 } 485 }
486 } 486 }
487} \ No newline at end of file 487}
diff --git a/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs
index 0927c4f..a26d145 100644
--- a/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs
+++ b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs
@@ -334,4 +334,4 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments
334 } 334 }
335 } 335 }
336 } 336 }
337} \ No newline at end of file 337}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 86d86cb..03a9ddc 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -555,7 +555,9 @@ public class BSShapeMesh : BSShape
555 { 555 {
556 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, 556 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
557 false, // say it is not physical so a bounding box is not built 557 false, // say it is not physical so a bounding box is not built
558 false // do not cache the mesh and do not use previously built versions 558 false, // do not cache the mesh and do not use previously built versions
559 false,
560 false
559 ); 561 );
560 } 562 }
561 563
@@ -712,7 +714,7 @@ public class BSShapeHull : BSShape
712 lock (physicsScene.mesher) 714 lock (physicsScene.mesher)
713 { 715 {
714 // Pass true for physicalness as this prevents the creation of bounding box which is not needed 716 // Pass true for physicalness as this prevents the creation of bounding box which is not needed
715 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */); 717 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */, false, false);
716 718
717 // If we should use the asset's hull info, fetch it out of the locked mesher 719 // If we should use the asset's hull info, fetch it out of the locked mesher
718 if (meshData != null && BSParam.ShouldUseAssetHulls) 720 if (meshData != null && BSParam.ShouldUseAssetHulls)
diff --git a/OpenSim/Region/Physics/ChOdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/ChOdePlugin/AssemblyInfo.cs
new file mode 100644
index 0000000..d65929a
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/AssemblyInfo.cs
@@ -0,0 +1,58 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Reflection;
29using System.Runtime.InteropServices;
30
31// Information about this assembly is defined by the following
32// attributes.
33//
34// change them to the information which is associated with the assembly
35// you compile.
36
37[assembly : AssemblyTitle("OdePlugin")]
38[assembly : AssemblyDescription("")]
39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("OdePlugin")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")]
43[assembly : AssemblyTrademark("")]
44[assembly : AssemblyCulture("")]
45
46// This sets the default COM visibility of types in the assembly to invisible.
47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
48
49[assembly : ComVisible(false)]
50
51// The assembly version has following format :
52//
53// Major.Minor.Build.Revision
54//
55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default):
57
58[assembly : AssemblyVersion("0.6.5.*")]
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/ChOdePlugin/ODECharacter.cs
new file mode 100644
index 0000000..ec717d7
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/ODECharacter.cs
@@ -0,0 +1,1467 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using OpenMetaverse;
32using Ode.NET;
33using OpenSim.Framework;
34using OpenSim.Region.Physics.Manager;
35using log4net;
36
37namespace OpenSim.Region.Physics.OdePlugin
38{
39 /// <summary>
40 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
41 /// </summary>
42
43 public enum dParam : int
44 {
45 LowStop = 0,
46 HiStop = 1,
47 Vel = 2,
48 FMax = 3,
49 FudgeFactor = 4,
50 Bounce = 5,
51 CFM = 6,
52 StopERP = 7,
53 StopCFM = 8,
54 LoStop2 = 256,
55 HiStop2 = 257,
56 Vel2 = 258,
57 FMax2 = 259,
58 StopERP2 = 7 + 256,
59 StopCFM2 = 8 + 256,
60 LoStop3 = 512,
61 HiStop3 = 513,
62 Vel3 = 514,
63 FMax3 = 515,
64 StopERP3 = 7 + 512,
65 StopCFM3 = 8 + 512
66 }
67 public class OdeCharacter : PhysicsActor
68 {
69 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
70
71 private Vector3 _position;
72 private d.Vector3 _zeroPosition;
73 // private d.Matrix3 m_StandUpRotation;
74 private bool _zeroFlag = false;
75 private bool m_lastUpdateSent = false;
76 private Vector3 _velocity;
77 private Vector3 _target_velocity;
78 private Vector3 _acceleration;
79 private Vector3 m_rotationalVelocity;
80 private float m_mass = 80f;
81 public float m_density = 60f;
82 private bool m_pidControllerActive = true;
83 public float PID_D = 800.0f;
84 public float PID_P = 900.0f;
85 //private static float POSTURE_SERVO = 10000.0f;
86 public float CAPSULE_RADIUS = 0.37f;
87 public float CAPSULE_LENGTH = 2.140599f;
88 public float m_tensor = 3800000f;
89 public float heightFudgeFactor = 0.52f;
90 public float walkDivisor = 1.3f;
91 public float runDivisor = 0.8f;
92 private bool flying = false;
93 private bool jumping = false; // add for jumping
94 private bool m_iscolliding = false;
95 private bool m_iscollidingGround = false;
96 private bool m_wascolliding = false;
97 private bool m_wascollidingGround = false;
98 private bool m_iscollidingObj = false;
99 private bool m_alwaysRun = false;
100 private bool m_hackSentFall = false;
101 private bool m_hackSentFly = false;
102 private int m_requestedUpdateFrequency = 0;
103 private Vector3 m_taintPosition = Vector3.Zero;
104 public uint m_localID = 0;
105 public bool m_returnCollisions = false;
106 // taints and their non-tainted counterparts
107 public bool m_isPhysical = false; // the current physical status
108 public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing)
109 public float MinimumGroundFlightOffset = 3f;
110
111 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
112 private float m_tiltMagnitudeWhenProjectedOnXYPlane = 0.1131371f; // used to introduce a fixed tilt because a straight-up capsule falls through terrain, probably a bug in terrain collider
113
114
115 private float m_buoyancy = 0f;
116
117 // private CollisionLocker ode;
118
119 private string m_name = String.Empty;
120
121 private bool[] m_colliderarr = new bool[11];
122 private bool[] m_colliderGroundarr = new bool[11];
123
124 // Default we're a Character
125 private CollisionCategories m_collisionCategories = (CollisionCategories.Character);
126
127 // Default, Collide with Other Geometries, spaces, bodies and characters.
128 private CollisionCategories m_collisionFlags = (CollisionCategories.Geom
129 | CollisionCategories.Space
130 | CollisionCategories.Body
131 | CollisionCategories.Character
132 | CollisionCategories.Land);
133 public IntPtr Body = IntPtr.Zero;
134 private OdeScene _parent_scene;
135 public IntPtr Shell = IntPtr.Zero;
136 public IntPtr Amotor = IntPtr.Zero;
137 public d.Mass ShellMass;
138 public bool collidelock = false;
139
140 public int m_eventsubscription = 0;
141 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
142
143 private Vector3 m_taintMomentum = Vector3.Zero;
144 private bool m_haveTaintMomentum = false;
145
146
147 // unique UUID of this character object
148 public UUID m_uuid;
149 public bool bad = false;
150 private Object m_syncRoot = new Object();
151
152 public OdeCharacter(String avName, OdeScene parent_scene, Vector3 pos, CollisionLocker dode, Vector3 size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
153 {
154 m_uuid = UUID.Random();
155
156 if (pos.IsFinite())
157 {
158 if (pos.Z > 9999999f)
159 {
160 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
161 }
162 if (pos.Z < -90000f)
163 {
164 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
165 }
166 _position = pos;
167 m_taintPosition.X = pos.X;
168 m_taintPosition.Y = pos.Y;
169 m_taintPosition.Z = pos.Z;
170 }
171 else
172 {
173 _position = new Vector3(((float)_parent_scene.WorldExtents.X * 0.5f), ((float)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f);
174 m_taintPosition.X = _position.X;
175 m_taintPosition.Y = _position.Y;
176 m_taintPosition.Z = _position.Z;
177 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
178 }
179
180 _parent_scene = parent_scene;
181
182 PID_D = pid_d;
183 PID_P = pid_p;
184 CAPSULE_RADIUS = capsule_radius;
185 m_tensor = tensor;
186 m_density = density;
187 heightFudgeFactor = height_fudge_factor;
188 walkDivisor = walk_divisor;
189 runDivisor = rundivisor;
190
191 // m_StandUpRotation =
192 // new d.Matrix3(0.5f, 0.7071068f, 0.5f, -0.7071068f, 0f, 0.7071068f, 0.5f, -0.7071068f,
193 // 0.5f);
194
195 for (int i = 0; i < 11; i++)
196 {
197 m_colliderarr[i] = false;
198 }
199 CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
200 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
201 m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
202
203 m_isPhysical = false; // current status: no ODE information exists
204 m_tainted_isPhysical = true; // new tainted status: need to create ODE information
205
206 _parent_scene.AddPhysicsActorTaint(this);
207
208 m_name = avName;
209 }
210
211 public override int PhysicsActorType
212 {
213 get { return (int) ActorTypes.Agent; }
214 set { return; }
215 }
216
217 /// <summary>
218 /// If this is set, the avatar will move faster
219 /// </summary>
220 public override bool SetAlwaysRun
221 {
222 get { return m_alwaysRun; }
223 set { m_alwaysRun = value; }
224 }
225
226 public override uint LocalID
227 {
228 set { m_localID = value; }
229 }
230
231 public override bool Grabbed
232 {
233 set { return; }
234 }
235
236 public override bool Selected
237 {
238// set { return; }
239 set { jumping = value; } // add for jumping flag
240 }
241
242 public override float Buoyancy
243 {
244 get { return m_buoyancy; }
245 set { m_buoyancy = value; }
246 }
247
248 public override bool FloatOnWater
249 {
250 set { return; }
251 }
252
253 public override bool IsPhysical
254 {
255 get { return false; }
256 set { return; }
257 }
258
259 public override bool ThrottleUpdates
260 {
261 get { return false; }
262 set { return; }
263 }
264
265 public override bool Flying
266 {
267 get { return flying; }
268 set { flying = value; }
269 }
270
271 /// <summary>
272 /// Returns if the avatar is colliding in general.
273 /// This includes the ground and objects and avatar.
274 /// </summary>
275 public override bool IsColliding
276 {
277//#@ get { return m_iscolliding; }
278 get { //##
279//Console.WriteLine(">>>>>>>>>>>> IC get = {0}", m_iscolliding); //##
280 return m_iscolliding; } //##
281 set
282 {
283 int i;
284 int truecount = 0;
285 int falsecount = 0;
286
287 if (m_colliderarr.Length >= 10)
288 {
289 for (i = 0; i < 10; i++)
290 {
291 m_colliderarr[i] = m_colliderarr[i + 1];
292 }
293 }
294 m_colliderarr[10] = value;
295
296 for (i = 0; i < 11; i++)
297 {
298 if (m_colliderarr[i])
299 {
300 truecount++;
301 }
302 else
303 {
304 falsecount++;
305 }
306 }
307
308 // Equal truecounts and false counts means we're colliding with something.
309
310 if (falsecount > 1.2*truecount)
311 {
312 m_iscolliding = false;
313 }
314 else
315 {
316 m_iscolliding = true;
317 }
318// ## Console.WriteLine("IC SET = {0} t{1} f{2} i {3}", value, truecount, falsecount, m_iscolliding);
319 if (m_wascolliding != m_iscolliding)
320 {
321 //base.SendCollisionUpdate(new CollisionEventUpdate());
322 }
323 m_wascolliding = m_iscolliding;
324 }
325 }
326
327 /// <summary>
328 /// Returns if an avatar is colliding with the ground
329 /// </summary>
330 public override bool CollidingGround
331 {
332 get { return m_iscollidingGround; }
333 set
334 {
335 // Collisions against the ground are not really reliable
336 // So, to get a consistant value we have to average the current result over time
337 // Currently we use 1 second = 10 calls to this.
338 int i;
339 int truecount = 0;
340 int falsecount = 0;
341
342 if (m_colliderGroundarr.Length >= 10)
343 {
344 for (i = 0; i < 10; i++)
345 {
346 m_colliderGroundarr[i] = m_colliderGroundarr[i + 1];
347 }
348 }
349 m_colliderGroundarr[10] = value;
350
351 for (i = 0; i < 11; i++)
352 {
353 if (m_colliderGroundarr[i])
354 {
355 truecount++;
356 }
357 else
358 {
359 falsecount++;
360 }
361 }
362
363 // Equal truecounts and false counts means we're colliding with something.
364
365 if (falsecount > 1.2*truecount)
366 {
367 m_iscollidingGround = false;
368 }
369 else
370 {
371 m_iscollidingGround = true;
372 }
373 if (m_wascollidingGround != m_iscollidingGround)
374 {
375 //base.SendCollisionUpdate(new CollisionEventUpdate());
376 }
377 m_wascollidingGround = m_iscollidingGround;
378 }
379 }
380
381 /// <summary>
382 /// Returns if the avatar is colliding with an object
383 /// </summary>
384 public override bool CollidingObj
385 {
386 get { return m_iscollidingObj; }
387 set
388 {
389 m_iscollidingObj = value;
390 if (value)
391 m_pidControllerActive = false;
392 else
393 m_pidControllerActive = true;
394 }
395 }
396
397 /// <summary>
398 /// turn the PID controller on or off.
399 /// The PID Controller will turn on all by itself in many situations
400 /// </summary>
401 /// <param name="status"></param>
402 public void SetPidStatus(bool status)
403 {
404 m_pidControllerActive = status;
405 }
406
407 public override bool Stopped
408 {
409 get { return _zeroFlag; }
410 }
411
412 /// <summary>
413 /// This 'puts' an avatar somewhere in the physics space.
414 /// Not really a good choice unless you 'know' it's a good
415 /// spot otherwise you're likely to orbit the avatar.
416 /// </summary>
417 public override Vector3 Position
418 {
419 get { return _position; }
420 set
421 {
422 if (Body == IntPtr.Zero || Shell == IntPtr.Zero)
423 {
424 if (value.IsFinite())
425 {
426 if (value.Z > 9999999f)
427 {
428 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
429 }
430 if (value.Z < -90000f)
431 {
432 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
433 }
434
435 _position.X = value.X;
436 _position.Y = value.Y;
437 _position.Z = value.Z;
438
439 m_taintPosition.X = value.X;
440 m_taintPosition.Y = value.Y;
441 m_taintPosition.Z = value.Z;
442 _parent_scene.AddPhysicsActorTaint(this);
443 }
444 else
445 {
446 m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character");
447 }
448 }
449 }
450 }
451
452 public override Vector3 RotationalVelocity
453 {
454 get { return m_rotationalVelocity; }
455 set { m_rotationalVelocity = value; }
456 }
457
458 /// <summary>
459 /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
460 /// and use it to offset landings properly
461 /// </summary>
462 public override Vector3 Size
463 {
464 get { return new Vector3(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); }
465 set
466 {
467 if (value.IsFinite())
468 {
469 m_pidControllerActive = true;
470
471 Vector3 SetSize = value;
472 m_tainted_CAPSULE_LENGTH = (SetSize.Z*1.15f) - CAPSULE_RADIUS*2.0f;
473 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
474
475 Velocity = Vector3.Zero;
476 m_taintPosition = _position; // update the stale taint position
477 _parent_scene.AddPhysicsActorTaint(this);
478 }
479 else
480 {
481 m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
482 }
483 }
484 }
485
486 private void AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3 movementVector)
487 {
488 movementVector.Z = 0f;
489 float magnitude = (float)Math.Sqrt((double)(movementVector.X * movementVector.X + movementVector.Y * movementVector.Y));
490 if (magnitude < 0.1f) return;
491
492 // normalize the velocity vector
493 float invMagnitude = 1.0f / magnitude;
494 movementVector.X *= invMagnitude;
495 movementVector.Y *= invMagnitude;
496
497 // if we change the capsule heading too often, the capsule can fall down
498 // therefore we snap movement vector to just 1 of 4 predefined directions (ne, nw, se, sw),
499 // meaning only 4 possible capsule tilt orientations
500 if (movementVector.X > 0)
501 {
502 // east
503 if (movementVector.Y > 0)
504 {
505 // northeast
506 movementVector.X = (float)Math.Sqrt(2.0);
507 movementVector.Y = (float)Math.Sqrt(2.0);
508 }
509 else
510 {
511 // southeast
512 movementVector.X = (float)Math.Sqrt(2.0);
513 movementVector.Y = -(float)Math.Sqrt(2.0);
514 }
515 }
516 else
517 {
518 // west
519 if (movementVector.Y > 0)
520 {
521 // northwest
522 movementVector.X = -(float)Math.Sqrt(2.0);
523 movementVector.Y = (float)Math.Sqrt(2.0);
524 }
525 else
526 {
527 // southwest
528 movementVector.X = -(float)Math.Sqrt(2.0);
529 movementVector.Y = -(float)Math.Sqrt(2.0);
530 }
531 }
532
533
534 // movementVector.Z is zero
535
536 // calculate tilt components based on desired amount of tilt and current (snapped) heading.
537 // the "-" sign is to force the tilt to be OPPOSITE the direction of movement.
538 float xTiltComponent = -movementVector.X * m_tiltMagnitudeWhenProjectedOnXYPlane;
539 float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane;
540
541 //m_log.Debug("[PHYSICS] changing avatar tilt");
542 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent);
543 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced
544 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
545 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
546 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
547 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
548 }
549
550 /// <summary>
551 /// This creates the Avatar's physical Surrogate at the position supplied
552 /// </summary>
553 /// <param name="npositionX"></param>
554 /// <param name="npositionY"></param>
555 /// <param name="npositionZ"></param>
556
557 // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access
558 // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only
559 // place that is safe to call this routine AvatarGeomAndBodyCreation.
560 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ, float tensor)
561 {
562 //CAPSULE_LENGTH = -5;
563 //CAPSULE_RADIUS = -5;
564 int dAMotorEuler = 1;
565 _parent_scene.waitForSpaceUnlock(_parent_scene.space);
566 if (CAPSULE_LENGTH <= 0)
567 {
568 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
569 CAPSULE_LENGTH = 0.01f;
570
571 }
572
573 if (CAPSULE_RADIUS <= 0)
574 {
575 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
576 CAPSULE_RADIUS = 0.01f;
577
578 }
579
580 if(Shell != IntPtr.Zero)
581 {
582 try
583 {
584 d.GeomDestroy(Shell);
585 }
586 catch (System.AccessViolationException)
587 {
588 m_log.Error("[PHYSICS]: PrimGeom dead");
589 }
590 // Remove any old entries
591//string tShell;
592//_parent_scene.geom_name_map.TryGetValue(Shell, out tShell);
593//Console.WriteLine("**** Remove {0}", tShell);
594 if(_parent_scene.geom_name_map.ContainsKey(Shell)) _parent_scene.geom_name_map.Remove(Shell);
595 if(_parent_scene.actor_name_map.ContainsKey(Shell)) _parent_scene.actor_name_map.Remove(Shell);
596 }
597
598 Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
599 _parent_scene.geom_name_map[Shell] = m_name;
600 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
601//Console.WriteLine("**** Create {2} Dicts: actor={0} name={1} height={3} rad={4}", _parent_scene.actor_name_map.Count, _parent_scene.geom_name_map.Count, m_name, CAPSULE_LENGTH, CAPSULE_RADIUS);
602
603 d.GeomSetCategoryBits(Shell, (int)m_collisionCategories);
604 d.GeomSetCollideBits(Shell, (int)m_collisionFlags);
605
606 d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH);
607 Body = d.BodyCreate(_parent_scene.world);
608 d.BodySetPosition(Body, npositionX, npositionY, npositionZ);
609
610 _position.X = npositionX;
611 _position.Y = npositionY;
612 _position.Z = npositionZ;
613
614
615 m_taintPosition.X = npositionX;
616 m_taintPosition.Y = npositionY;
617 m_taintPosition.Z = npositionZ;
618
619 d.BodySetMass(Body, ref ShellMass);
620 d.Matrix3 m_caprot;
621 // 90 Stand up on the cap of the capped cyllinder
622 if (_parent_scene.IsAvCapsuleTilted)
623 {
624 d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2));
625 }
626 else
627 {
628 d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2));
629 }
630
631
632 d.GeomSetRotation(Shell, ref m_caprot);
633 d.BodySetRotation(Body, ref m_caprot);
634
635 d.GeomSetBody(Shell, Body);
636
637
638 // The purpose of the AMotor here is to keep the avatar's physical
639 // surrogate from rotating while moving
640 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
641 d.JointAttach(Amotor, Body, IntPtr.Zero);
642 d.JointSetAMotorMode(Amotor, dAMotorEuler);
643 d.JointSetAMotorNumAxes(Amotor, 3);
644 d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
645 d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
646 d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
647 d.JointSetAMotorAngle(Amotor, 0, 0);
648 d.JointSetAMotorAngle(Amotor, 1, 0);
649 d.JointSetAMotorAngle(Amotor, 2, 0);
650
651 // These lowstops and high stops are effectively (no wiggle room)
652 if (_parent_scene.IsAvCapsuleTilted)
653 {
654 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f);
655 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f);
656 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f);
657 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f);
658 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f);
659 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f);
660 }
661 else
662 {
663 #region Documentation of capsule motor LowStop and HighStop parameters
664 // Intentionally introduce some tilt into the capsule by setting
665 // the motor stops to small epsilon values. This small tilt prevents
666 // the capsule from falling into the terrain; a straight-up capsule
667 // (with -0..0 motor stops) falls into the terrain for reasons yet
668 // to be comprehended in their entirety.
669 #endregion
670 AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero);
671 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
672 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
673 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
674 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
675 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
676 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
677 }
678
679 // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the
680 // capped cyllinder will fall over
681 d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
682 d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor);
683
684 //d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
685 //d.QfromR(
686 //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068,
687 //
688 //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22);
689 //standupStraight();
690 }
691
692 //
693 /// <summary>
694 /// Uses the capped cyllinder volume formula to calculate the avatar's mass.
695 /// This may be used in calculations in the scene/scenepresence
696 /// </summary>
697 public override float Mass
698 {
699 get
700 {
701 float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
702 return m_density*AVvolume;
703 }
704 }
705 public override void link(PhysicsActor obj)
706 {
707
708 }
709
710 public override void delink()
711 {
712
713 }
714
715 public override void LockAngularMotion(Vector3 axis)
716 {
717
718 }
719
720// This code is very useful. Written by DanX0r. We're just not using it right now.
721// Commented out to prevent a warning.
722//
723// private void standupStraight()
724// {
725// // The purpose of this routine here is to quickly stabilize the Body while it's popped up in the air.
726// // The amotor needs a few seconds to stabilize so without it, the avatar shoots up sky high when you
727// // change appearance and when you enter the simulator
728// // After this routine is done, the amotor stabilizes much quicker
729// d.Vector3 feet;
730// d.Vector3 head;
731// d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet);
732// d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head);
733// float posture = head.Z - feet.Z;
734
735// // restoring force proportional to lack of posture:
736// float servo = (2.5f - posture) * POSTURE_SERVO;
737// d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f);
738// d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f);
739// //d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
740// //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22);
741// }
742
743 public override Vector3 Force
744 {
745 get { return _target_velocity; }
746 set { return; }
747 }
748
749 public override int VehicleType
750 {
751 get { return 0; }
752 set { return; }
753 }
754
755 public override void VehicleFloatParam(int param, float value)
756 {
757
758 }
759
760 public override void VehicleVectorParam(int param, Vector3 value)
761 {
762
763 }
764
765 public override void VehicleRotationParam(int param, Quaternion rotation)
766 {
767
768 }
769
770 public override void VehicleFlags(int flags, bool remove)
771 {
772 }
773
774 public override void SetVolumeDetect(int param)
775 {
776
777 }
778
779 public override Vector3 CenterOfMass
780 {
781 get { return Vector3.Zero; }
782 }
783
784 public override Vector3 GeometricCenter
785 {
786 get { return Vector3.Zero; }
787 }
788
789 public override PrimitiveBaseShape Shape
790 {
791 set { return; }
792 }
793
794 public override Vector3 Velocity
795 {
796 get {
797 // There's a problem with Vector3.Zero! Don't Use it Here!
798 if (_zeroFlag)
799 return Vector3.Zero;
800 m_lastUpdateSent = false;
801 return _velocity;
802 }
803 set
804 {
805 if (value.IsFinite())
806 {
807 _target_velocity = value;
808 m_pidControllerActive = true;
809 }
810 else
811 {
812 m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
813 }
814 }
815 }
816
817 public override Vector3 Torque
818 {
819 get { return Vector3.Zero; }
820 set { return; }
821 }
822
823 public override float CollisionScore
824 {
825 get { return 0f; }
826 set { }
827 }
828
829 public override bool Kinematic
830 {
831 get { return false; }
832 set { }
833 }
834
835 public override Quaternion Orientation
836 {
837 get { return Quaternion.Identity; }
838 set {
839 //Matrix3 or = Orientation.ToRotationMatrix();
840 //d.Matrix3 ord = new d.Matrix3(or.m00, or.m10, or.m20, or.m01, or.m11, or.m21, or.m02, or.m12, or.m22);
841 //d.BodySetRotation(Body, ref ord);
842 }
843 }
844
845 public override Vector3 Acceleration
846 {
847 get { return _acceleration; }
848 set { _acceleration = value; }
849 }
850
851 public void SetAcceleration(Vector3 accel)
852 {
853 m_pidControllerActive = true;
854 _acceleration = accel;
855 }
856
857 /// <summary>
858 /// Adds the force supplied to the Target Velocity
859 /// The PID controller takes this target velocity and tries to make it a reality
860 /// </summary>
861 /// <param name="force"></param>
862 public override void AddForce(Vector3 force, bool pushforce)
863 {
864 if (force.IsFinite())
865 {
866 if (pushforce)
867 {
868 m_pidControllerActive = false;
869 force *= 100f;
870//Console.WriteLine("DF 1"); // ##
871 if (!force.ApproxEquals(Vector3.Zero, 0.01f))
872 doForce(force);
873 // If uncommented, things get pushed off world
874 //
875 // m_log.Debug("Push!");
876 // _target_velocity.X += force.X;
877 // _target_velocity.Y += force.Y;
878 // _target_velocity.Z += force.Z;
879 }
880 else
881 {
882 m_pidControllerActive = true;
883 _target_velocity.X += force.X;
884 _target_velocity.Y += force.Y;
885 _target_velocity.Z += force.Z;
886 }
887 }
888 else
889 {
890 m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
891 }
892 //m_lastUpdateSent = false;
893 }
894
895 public override void AddAngularForce(Vector3 force, bool pushforce)
896 {
897
898 }
899
900 /// <summary>
901 /// After all of the forces add up with 'add force' we apply them with doForce
902 /// </summary>
903 /// <param name="force"></param>
904 public void doForce(Vector3 force)
905 {
906 if (!collidelock)
907 {
908 d.BodyAddForce(Body, force.X, force.Y, force.Z);
909 //d.BodySetRotation(Body, ref m_StandUpRotation);
910 //standupStraight();
911 d.Vector3 vel = d.BodyGetLinearVel(Body); //##
912//Console.WriteLine("AvVel <{0},{1},{2}>", vel.X, vel.Y, vel.Z); //##
913 }
914 }
915
916 public override void SetMomentum(Vector3 momentum)
917 {
918 if (momentum.IsFinite())
919 {
920 m_taintMomentum = momentum;
921 m_haveTaintMomentum = true;
922 _parent_scene.AddPhysicsActorTaint(this);
923 }
924 else
925 m_log.Warn("[PHYSICS] !isFinite momentum");
926 }
927
928
929 /// <summary>
930 /// Called from Simulate
931 /// This is the avatar's movement control + PID Controller
932 /// </summary>
933 /// <param name="timeStep"></param>
934 public void Move(float timeStep, List<OdeCharacter> defects)
935 {
936 // no lock; for now it's only called from within Simulate()
937
938 // If the PID Controller isn't active then we set our force
939 // calculating base velocity to the current position
940
941 if (Body == IntPtr.Zero)
942 return;
943
944 if (m_pidControllerActive == false)
945 {
946 _zeroPosition = d.BodyGetPosition(Body);
947 }
948 //PidStatus = true;
949
950 d.Vector3 localpos = d.BodyGetPosition(Body);
951 Vector3 localPos = new Vector3(localpos.X, localpos.Y, localpos.Z);
952
953 if (!localPos.IsFinite())
954 {
955
956 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
957 defects.Add(this);
958 // _parent_scene.RemoveCharacter(this);
959
960 // destroy avatar capsule and related ODE data
961 if (Amotor != IntPtr.Zero)
962 {
963 // Kill the Amotor
964 d.JointDestroy(Amotor);
965 Amotor = IntPtr.Zero;
966 }
967
968 //kill the Geometry
969 _parent_scene.waitForSpaceUnlock(_parent_scene.space);
970
971 if (Body != IntPtr.Zero)
972 {
973 //kill the body
974 d.BodyDestroy(Body);
975
976 Body = IntPtr.Zero;
977 }
978
979 if(Shell != IntPtr.Zero)
980 {
981 try
982 {
983 d.GeomDestroy(Shell);
984 }
985 catch (System.AccessViolationException)
986 {
987 m_log.Error("[PHYSICS]: PrimGeom dead");
988 }
989 // Remove any old entries
990//string tShell;
991//_parent_scene.geom_name_map.TryGetValue(Shell, out tShell);
992//Console.WriteLine("**** Remove {0}", tShell);
993
994 if(_parent_scene.geom_name_map.ContainsKey(Shell)) _parent_scene.geom_name_map.Remove(Shell);
995 if(_parent_scene.actor_name_map.ContainsKey(Shell)) _parent_scene.actor_name_map.Remove(Shell);
996 Shell = IntPtr.Zero;
997 }
998
999 return;
1000 }
1001
1002 Vector3 vec = Vector3.Zero;
1003 d.Vector3 vel = d.BodyGetLinearVel(Body);
1004
1005 float movementdivisor = 1f;
1006
1007 if (!m_alwaysRun)
1008 {
1009 movementdivisor = walkDivisor;
1010 }
1011 else
1012 {
1013 movementdivisor = runDivisor;
1014 }
1015
1016 // if velocity is zero, use position control; otherwise, velocity control
1017 if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f && m_iscolliding)
1018 {
1019 // keep track of where we stopped. No more slippin' & slidin'
1020 if (!_zeroFlag)
1021 {
1022 _zeroFlag = true;
1023 _zeroPosition = d.BodyGetPosition(Body);
1024 }
1025 if (m_pidControllerActive)
1026 {
1027 // We only want to deactivate the PID Controller if we think we want to have our surrogate
1028 // react to the physics scene by moving it's position.
1029 // Avatar to Avatar collisions
1030 // Prim to avatar collisions
1031
1032 d.Vector3 pos = d.BodyGetPosition(Body);
1033 float errX = _zeroPosition.X - pos.X;
1034 float errY = _zeroPosition.Y - pos.Y;
1035 if( (Math.Abs(errX) > 0.1f) || (Math.Abs(errY) > 0.1f) )
1036 {
1037 vec.X = (_target_velocity.X - vel.X) * (PID_D) + (errX) * (PID_P * 2);
1038 vec.Y = (_target_velocity.Y - vel.Y) * (PID_D) + (errY) * (PID_P * 2);
1039 }
1040 else
1041 { // close, jump to lateral destination
1042 d.BodySetPosition(Body, _zeroPosition.X, _zeroPosition.Y, pos.Z);
1043 }
1044// if (flying)
1045 if (flying || jumping) // add for jumping
1046 {
1047 vec.Z = (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
1048 }
1049 }
1050 //PidStatus = true;
1051 }
1052 else
1053 {
1054 m_pidControllerActive = true;
1055 _zeroFlag = false;
1056 if (m_iscolliding && !flying)
1057 {
1058 // We're standing on something
1059 vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * (PID_D);
1060 vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D);
1061 }
1062 else if (m_iscolliding && flying)
1063 {
1064 // We're flying and colliding with something
1065 vec.X = ((_target_velocity.X/movementdivisor) - vel.X)*(PID_D / 16);
1066 vec.Y = ((_target_velocity.Y/movementdivisor) - vel.Y)*(PID_D / 16);
1067 }
1068 else if (!m_iscolliding && flying)
1069 {
1070 // we're in mid air suspended
1071 vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * (PID_D/6);
1072 vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D/6);
1073 }
1074
1075 if (m_iscolliding && !flying && _target_velocity.Z > 0.0f)
1076 {
1077 // We're colliding with something and we're not flying but we're moving
1078 // This means we're walking or running.
1079 d.Vector3 pos = d.BodyGetPosition(Body);
1080 vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P;
1081 if (_target_velocity.X > 0)
1082 {
1083 vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
1084 }
1085 if (_target_velocity.Y > 0)
1086 {
1087 vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
1088 }
1089 }
1090 else if (!m_iscolliding && !flying)
1091 {
1092 // we're not colliding and we're not flying so that means we're falling!
1093 // m_iscolliding includes collisions with the ground.
1094
1095 // d.Vector3 pos = d.BodyGetPosition(Body);
1096 if (Math.Abs(_target_velocity.X) > 0)
1097 {
1098 vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
1099 }
1100 if (Math.Abs(_target_velocity.Y) > 0)
1101 {
1102 vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
1103 }
1104 }
1105
1106 if (flying)
1107 {
1108 vec.Z = (_target_velocity.Z - vel.Z) * (PID_D);
1109 }
1110 }
1111 if (flying)
1112 {
1113 vec.Z += ((-1 * _parent_scene.gravityz)*m_mass);
1114
1115 //Added for auto fly height. Kitto Flora
1116 //d.Vector3 pos = d.BodyGetPosition(Body);
1117 float target_altitude = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y) + MinimumGroundFlightOffset;
1118
1119 if (_position.Z < target_altitude)
1120 {
1121 vec.Z += (target_altitude - _position.Z) * PID_P * 5.0f;
1122 }
1123 // end add Kitto Flora
1124 }
1125
1126 if (vel.X * vel.X + vel.Y * vel.Y + vel.Z * vel.Z > 2500.0f) // 50ms apply breaks
1127 {
1128 float breakfactor = 0.16f * m_mass; // will give aprox 60m/s terminal velocity at free fall
1129 vec.X -= breakfactor * vel.X;
1130 vec.Y -= breakfactor * vel.Y;
1131 vec.Z -= breakfactor * vel.Z;
1132 }
1133
1134 if (vec.IsFinite())
1135 {
1136 if (vec.LengthSquared() > 0.0004f) // 0.01 allows 0.002 !!
1137 {
1138//Console.WriteLine("DF 2"); // ##
1139
1140 doForce(vec);
1141 if (!_zeroFlag)
1142 {
1143// AlignAvatarTiltWithCurrentDirectionOfMovement(vec);
1144 }
1145 }
1146 }
1147 else
1148 {
1149 m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()");
1150 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
1151 defects.Add(this);
1152 // _parent_scene.RemoveCharacter(this);
1153 // destroy avatar capsule and related ODE data
1154 if (Amotor != IntPtr.Zero)
1155 {
1156 // Kill the Amotor
1157 d.JointDestroy(Amotor);
1158 Amotor = IntPtr.Zero;
1159 }
1160 //kill the Geometry
1161 _parent_scene.waitForSpaceUnlock(_parent_scene.space);
1162
1163 if (Body != IntPtr.Zero)
1164 {
1165 //kill the body
1166 d.BodyDestroy(Body);
1167
1168 Body = IntPtr.Zero;
1169 }
1170
1171 if(Shell != IntPtr.Zero)
1172 {
1173 try
1174 {
1175 d.GeomDestroy(Shell);
1176 }
1177 catch (System.AccessViolationException)
1178 {
1179 m_log.Error("[PHYSICS]: PrimGeom dead");
1180 }
1181 // Remove any old entries
1182//string tShell;
1183//_parent_scene.geom_name_map.TryGetValue(Shell, out tShell);
1184//Console.WriteLine("**** Remove {0}", tShell);
1185
1186 if(_parent_scene.geom_name_map.ContainsKey(Shell)) _parent_scene.geom_name_map.Remove(Shell);
1187 if(_parent_scene.actor_name_map.ContainsKey(Shell)) _parent_scene.actor_name_map.Remove(Shell);
1188 Shell = IntPtr.Zero;
1189 }
1190 }
1191 }
1192
1193 /// <summary>
1194 /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence.
1195 /// </summary>
1196 public void UpdatePositionAndVelocity()
1197 {
1198 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
1199 d.Vector3 vec;
1200 try
1201 {
1202 vec = d.BodyGetPosition(Body);
1203 }
1204 catch (NullReferenceException)
1205 {
1206 bad = true;
1207 _parent_scene.BadCharacter(this);
1208 vec = new d.Vector3(_position.X, _position.Y, _position.Z);
1209 base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem!
1210 m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid);
1211 }
1212
1213
1214 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
1215 if (vec.X < 0.0f) vec.X = 0.0f;
1216 if (vec.Y < 0.0f) vec.Y = 0.0f;
1217 if (vec.X > (int)_parent_scene.WorldExtents.X - 0.05f) vec.X = (int)_parent_scene.WorldExtents.X - 0.05f;
1218 if (vec.Y > (int)_parent_scene.WorldExtents.Y - 0.05f) vec.Y = (int)_parent_scene.WorldExtents.Y - 0.05f;
1219
1220 _position.X = vec.X;
1221 _position.Y = vec.Y;
1222 _position.Z = vec.Z;
1223
1224 // Did we move last? = zeroflag
1225 // This helps keep us from sliding all over
1226
1227 if (_zeroFlag)
1228 {
1229 _velocity.X = 0.0f;
1230 _velocity.Y = 0.0f;
1231 _velocity.Z = 0.0f;
1232
1233 // Did we send out the 'stopped' message?
1234 if (!m_lastUpdateSent)
1235 {
1236 m_lastUpdateSent = true;
1237 //base.RequestPhysicsterseUpdate();
1238
1239 }
1240 }
1241 else
1242 {
1243 m_lastUpdateSent = false;
1244 try
1245 {
1246 vec = d.BodyGetLinearVel(Body);
1247 }
1248 catch (NullReferenceException)
1249 {
1250 vec.X = _velocity.X;
1251 vec.Y = _velocity.Y;
1252 vec.Z = _velocity.Z;
1253 }
1254 _velocity.X = (vec.X);
1255 _velocity.Y = (vec.Y);
1256
1257 _velocity.Z = (vec.Z);
1258
1259 if (_velocity.Z < -6 && !m_hackSentFall)
1260 {
1261 m_hackSentFall = true;
1262 m_pidControllerActive = false;
1263 }
1264 else if (flying && !m_hackSentFly)
1265 {
1266 //m_hackSentFly = true;
1267 //base.SendCollisionUpdate(new CollisionEventUpdate());
1268 }
1269 else
1270 {
1271 m_hackSentFly = false;
1272 m_hackSentFall = false;
1273 }
1274 }
1275 }
1276
1277 /// <summary>
1278 /// Cleanup the things we use in the scene.
1279 /// </summary>
1280 public void Destroy()
1281 {
1282 m_tainted_isPhysical = false;
1283 _parent_scene.AddPhysicsActorTaint(this);
1284 }
1285
1286 public override void CrossingFailure()
1287 {
1288 }
1289
1290 public override Vector3 PIDTarget { set { return; } }
1291 public override bool PIDActive { set { return; } }
1292 public override float PIDTau { set { return; } }
1293
1294 public override float PIDHoverHeight { set { return; } }
1295 public override bool PIDHoverActive { set { return; } }
1296 public override PIDHoverType PIDHoverType { set { return; } }
1297 public override float PIDHoverTau { set { return; } }
1298
1299 public override Quaternion APIDTarget{ set { return; } }
1300
1301 public override bool APIDActive{ set { return; } }
1302
1303 public override float APIDStrength{ set { return; } }
1304
1305 public override float APIDDamping{ set { return; } }
1306
1307
1308 public override void SubscribeEvents(int ms)
1309 {
1310 m_requestedUpdateFrequency = ms;
1311 m_eventsubscription = ms;
1312 _parent_scene.addCollisionEventReporting(this);
1313 }
1314 public override void UnSubscribeEvents()
1315 {
1316 _parent_scene.remCollisionEventReporting(this);
1317 m_requestedUpdateFrequency = 0;
1318 m_eventsubscription = 0;
1319 }
1320 public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1321 {
1322 if (m_eventsubscription > 0)
1323 {
1324 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1325 }
1326 }
1327
1328 public void SendCollisions()
1329 {
1330 if (m_eventsubscription > m_requestedUpdateFrequency)
1331 {
1332 if (CollisionEventsThisFrame != null)
1333 {
1334 base.SendCollisionUpdate(CollisionEventsThisFrame);
1335 }
1336 CollisionEventsThisFrame = new CollisionEventUpdate();
1337 m_eventsubscription = 0;
1338 }
1339 }
1340 public override bool SubscribedEvents()
1341 {
1342 if (m_eventsubscription > 0)
1343 return true;
1344 return false;
1345 }
1346
1347 public void ProcessTaints(float timestep)
1348 {
1349 lock (m_syncRoot)
1350 {
1351 if (m_tainted_isPhysical != m_isPhysical)
1352 {
1353 if (m_tainted_isPhysical)
1354 {
1355 // Create avatar capsule and related ODE data
1356 if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero))
1357 {
1358 m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - "
1359 + (Shell!=IntPtr.Zero ? "Shell ":"")
1360 + (Body!=IntPtr.Zero ? "Body ":"")
1361 + (Amotor!=IntPtr.Zero ? "Amotor ":""));
1362 }
1363 AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor);
1364 _parent_scene.AddCharacter(this);
1365 }
1366 else
1367 {
1368 _parent_scene.RemoveCharacter(this);
1369 // destroy avatar capsule and related ODE data
1370 if (Amotor != IntPtr.Zero)
1371 {
1372 // Kill the Amotor
1373 d.JointDestroy(Amotor);
1374 Amotor = IntPtr.Zero;
1375 }
1376 //kill the Geometry
1377 _parent_scene.waitForSpaceUnlock(_parent_scene.space);
1378
1379 if (Body != IntPtr.Zero)
1380 {
1381 //kill the body
1382 d.BodyDestroy(Body);
1383 Body = IntPtr.Zero;
1384 }
1385
1386 if(Shell != IntPtr.Zero)
1387 {
1388 try
1389 {
1390 d.GeomDestroy(Shell);
1391 }
1392 catch (Exception e)
1393 {
1394 m_log.ErrorFormat("[PHYSICS]: Failed to destroy character shell {0}",e.Message);
1395 }
1396 // Remove any old entries
1397 //string tShell;
1398 //_parent_scene.geom_name_map.TryGetValue(Shell, out tShell);
1399 //Console.WriteLine("**** Remove {0}", tShell);
1400
1401 if(_parent_scene.geom_name_map.ContainsKey(Shell)) _parent_scene.geom_name_map.Remove(Shell);
1402 if(_parent_scene.actor_name_map.ContainsKey(Shell)) _parent_scene.actor_name_map.Remove(Shell);
1403 Shell = IntPtr.Zero;
1404 }
1405 }
1406
1407 m_isPhysical = m_tainted_isPhysical;
1408 }
1409
1410 if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH)
1411 {
1412 if (Shell != IntPtr.Zero && Body != IntPtr.Zero && Amotor != IntPtr.Zero)
1413 {
1414
1415 m_pidControllerActive = true;
1416 // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate()
1417 d.JointDestroy(Amotor);
1418 float prevCapsule = CAPSULE_LENGTH;
1419 CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH;
1420 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
1421 d.BodyDestroy(Body);
1422 AvatarGeomAndBodyCreation(_position.X, _position.Y,
1423 _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor);
1424 Velocity = Vector3.Zero;
1425 }
1426 else
1427 {
1428 m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - "
1429 + (Shell==IntPtr.Zero ? "Shell ":"")
1430 + (Body==IntPtr.Zero ? "Body ":"")
1431 + (Amotor==IntPtr.Zero ? "Amotor ":""));
1432 }
1433 }
1434
1435 if (!m_taintPosition.ApproxEquals(_position, 0.05f))
1436 {
1437 if (Body != IntPtr.Zero)
1438 {
1439 d.BodySetPosition(Body, m_taintPosition.X, m_taintPosition.Y, m_taintPosition.Z);
1440
1441 }
1442 _position.X = m_taintPosition.X;
1443 _position.Y = m_taintPosition.Y;
1444 _position.Z = m_taintPosition.Z;
1445 }
1446
1447 if (m_haveTaintMomentum)
1448 {
1449 m_haveTaintMomentum = false;
1450 _velocity = m_taintMomentum;
1451 _target_velocity = m_taintMomentum;
1452 m_pidControllerActive = true;
1453 if (Body != IntPtr.Zero)
1454 d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z);
1455 }
1456 }
1457 }
1458
1459 internal void AddCollisionFrameTime(int p)
1460 {
1461 // protect it from overflow crashing
1462 if (m_eventsubscription + p >= int.MaxValue)
1463 m_eventsubscription = 0;
1464 m_eventsubscription += p;
1465 }
1466 }
1467}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs
new file mode 100644
index 0000000..ba24aa7
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs
@@ -0,0 +1,4124 @@
1/* Copyright (c) Contributors, http://opensimulator.org/
2 * See CONTRIBUTORS.TXT for a full list of copyright holders.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the OpenSimulator Project nor the
11 * names of its contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * Revised March 5th 2010 by Kitto Flora. ODEDynamics.cs
26 * Ubit 2012
27 * rolled into ODEPrim.cs
28 */
29
30using System;
31using System.IO;
32using System.Collections.Generic;
33using System.Reflection;
34using System.Runtime.InteropServices;
35using System.Threading;
36using log4net;
37using OpenMetaverse;
38using Ode.NET;
39using OpenSim.Framework;
40using OpenSim.Region.Physics.Manager;
41
42namespace OpenSim.Region.Physics.OdePlugin
43{
44 /// <summary>
45 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
46 /// </summary>
47
48 public class OdePrim : PhysicsActor
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 public class SerialControl
53 {
54 public object alock = new object();
55 public byte[] data = new byte[0];
56 }
57 private Vector3 _position;
58 private Vector3 _velocity;
59 private Vector3 _torque;
60 private Vector3 m_lastVelocity;
61 private Vector3 m_lastposition;
62 private Quaternion m_lastorientation = new Quaternion();
63 private Vector3 m_rotationalVelocity;
64 private Vector3 _size;
65 private Vector3 _acceleration;
66 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f);
67 private Quaternion _orientation;
68 private Vector3 m_taintposition;
69 private Vector3 m_taintsize;
70 private Vector3 m_taintVelocity;
71 private Vector3 m_taintTorque;
72 private Quaternion m_taintrot;
73 private Vector3 m_rotateEnable = Vector3.One; // Current setting
74 private Vector3 m_rotateEnableRequest = Vector3.One; // Request from LSL
75 private bool m_rotateEnableUpdate = false;
76 private Vector3 m_lockX;
77 private Vector3 m_lockY;
78 private Vector3 m_lockZ;
79 private IntPtr Amotor = IntPtr.Zero;
80 private IntPtr AmotorX = IntPtr.Zero;
81 private IntPtr AmotorY = IntPtr.Zero;
82 private IntPtr AmotorZ = IntPtr.Zero;
83
84 private Vector3 m_PIDTarget;
85 private float m_PIDTau;
86 private float PID_D = 35f;
87 private float PID_G = 25f;
88 private bool m_usePID = false;
89
90 private Quaternion m_APIDTarget = new Quaternion();
91 private float m_APIDStrength = 0.5f;
92 private float m_APIDDamping = 0.5f;
93 private bool m_useAPID = false;
94 private float m_APIDdamper = 1.0f;
95
96 // These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
97 // do not confuse with VEHICLE HOVER
98
99 private float m_PIDHoverHeight;
100 private float m_PIDHoverTau;
101 private bool m_useHoverPID;
102 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
103 private float m_targetHoverHeight;
104 private float m_groundHeight;
105 private float m_waterHeight;
106 private float m_buoyancy; //m_buoyancy set by llSetBuoyancy()
107
108 // private float m_tensor = 5f;
109 private int body_autodisable_frames = 20;
110
111
112 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
113 | CollisionCategories.Space
114 | CollisionCategories.Body
115 | CollisionCategories.Character
116 );
117 private bool m_taintshape;
118 private bool m_taintPhysics;
119 private bool m_collidesLand = true;
120 private bool m_collidesWater;
121 // public bool m_returnCollisions;
122
123 // Default we're a Geometry
124 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
125
126 // Default, Collide with Other Geometries, spaces and Bodies
127 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
128
129 public bool m_taintremove;
130 public bool m_taintdisable;
131 public bool m_disabled;
132 public bool m_taintadd;
133 public bool m_taintselected;
134 public bool m_taintphantom;
135 public bool m_taintCollidesWater;
136
137 public uint m_localID;
138
139 //public GCHandle gc;
140 private CollisionLocker ode;
141
142 private bool m_meshfailed = false;
143 private bool m_taintforce = false;
144 private bool m_taintaddangularforce = false;
145 private Vector3 m_force;
146 private List<Vector3> m_forcelist = new List<Vector3>();
147 private List<Vector3> m_angularforcelist = new List<Vector3>();
148
149 private IMesh _mesh;
150 private PrimitiveBaseShape _pbs;
151 private OdeScene _parent_scene;
152 public IntPtr m_targetSpace = IntPtr.Zero;
153 public IntPtr prim_geom;
154 // public IntPtr prev_geom;
155 public IntPtr _triMeshData;
156
157 private IntPtr _linkJointGroup = IntPtr.Zero;
158 private PhysicsActor _parent;
159 private PhysicsActor m_taintparent;
160
161 private List<OdePrim> childrenPrim = new List<OdePrim>();
162
163 private bool iscolliding;
164 private bool m_isphysical;
165 private bool m_isphantom;
166 private bool m_isSelected;
167
168 private bool m_NoColide; // for now only for internal use for bad meshs
169
170 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
171
172 private bool m_throttleUpdates;
173 private int throttleCounter;
174 public int m_interpenetrationcount;
175 public float m_collisionscore;
176 // public int m_roundsUnderMotionThreshold;
177 // private int m_crossingfailures;
178
179 public bool m_outofBounds;
180 private float m_density = 10.000006836f; // Aluminum g/cm3;
181
182 private float m_primMass = 10.000006836f; // Aluminum g/cm3;
183
184 private byte m_shapetype;
185 private byte m_taintshapetype;
186
187 public bool _zeroFlag; // if body has been stopped
188 private bool m_lastUpdateSent;
189
190 public IntPtr Body = IntPtr.Zero;
191 public String m_primName;
192 private Vector3 _target_velocity;
193 public d.Mass pMass;
194
195 public int m_eventsubscription;
196 private CollisionEventUpdate CollisionEventsThisFrame;
197
198 private IntPtr m_linkJoint = IntPtr.Zero;
199
200 public volatile bool childPrim;
201
202 internal int m_material = (int)Material.Wood;
203
204 private IntPtr m_body = IntPtr.Zero;
205
206 // Vehicle properties ============================================================================================
207 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
208 // private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
209 private VehicleFlag m_flags = (VehicleFlag)0; // Bit settings:
210 // HOVER_TERRAIN_ONLY
211 // HOVER_GLOBAL_HEIGHT
212 // NO_DEFLECTION_UP
213 // HOVER_WATER_ONLY
214 // HOVER_UP_ONLY
215 // LIMIT_MOTOR_UP
216 // LIMIT_ROLL_ONLY
217
218 // Linear properties
219 private Vector3 m_linearMotorDirection = Vector3.Zero; // (was m_linearMotorDirectionLASTSET) the (local) Velocity
220 //requested by LSL
221 private float m_linearMotorTimescale = 0; // Motor Attack rate set by LSL
222 private float m_linearMotorDecayTimescale = 0; // Motor Decay rate set by LSL
223 private Vector3 m_linearFrictionTimescale = Vector3.Zero; // General Friction set by LSL
224
225 private Vector3 m_lLinMotorDVel = Vector3.Zero; // decayed motor
226 private Vector3 m_lLinObjectVel = Vector3.Zero; // local frame object velocity
227 private Vector3 m_wLinObjectVel = Vector3.Zero; // world frame object velocity
228
229 //Angular properties
230 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
231
232 private float m_angularMotorTimescale = 0; // motor angular Attack rate set by LSL
233 private float m_angularMotorDecayTimescale = 0; // motor angular Decay rate set by LSL
234 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular Friction set by LSL
235
236 private Vector3 m_angularMotorDVel = Vector3.Zero; // decayed angular motor
237 // private Vector3 m_angObjectVel = Vector3.Zero; // current body angular velocity
238 private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body
239
240 //Deflection properties
241 // private float m_angularDeflectionEfficiency = 0;
242 // private float m_angularDeflectionTimescale = 0;
243 // private float m_linearDeflectionEfficiency = 0;
244 // private float m_linearDeflectionTimescale = 0;
245
246 //Banking properties
247 // private float m_bankingEfficiency = 0;
248 // private float m_bankingMix = 0;
249 // private float m_bankingTimescale = 0;
250
251 //Hover and Buoyancy properties
252 private float m_VhoverHeight = 0f;
253 // private float m_VhoverEfficiency = 0f;
254 private float m_VhoverTimescale = 0f;
255 private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
256 private float m_VehicleBuoyancy = 0f; // Set by VEHICLE_BUOYANCY, for a vehicle.
257 // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
258 // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
259 // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
260
261 //Attractor properties
262 private float m_verticalAttractionEfficiency = 1.0f; // damped
263 private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor.
264
265// SerialControl m_taintserial = null;
266 object m_taintvehicledata = null;
267
268 public void DoSetVehicle()
269 {
270 VehicleData vd = (VehicleData)m_taintvehicledata;
271
272 m_type = vd.m_type;
273 m_flags = vd.m_flags;
274
275 // Linear properties
276 m_linearMotorDirection = vd.m_linearMotorDirection;
277 m_linearFrictionTimescale = vd.m_linearFrictionTimescale;
278 m_linearMotorDecayTimescale = vd.m_linearMotorDecayTimescale;
279 m_linearMotorTimescale = vd.m_linearMotorTimescale;
280// m_linearMotorOffset = vd.m_linearMotorOffset;
281
282 //Angular properties
283 m_angularMotorDirection = vd.m_angularMotorDirection;
284 m_angularMotorTimescale = vd.m_angularMotorTimescale;
285 m_angularMotorDecayTimescale = vd.m_angularMotorDecayTimescale;
286 m_angularFrictionTimescale = vd.m_angularFrictionTimescale;
287
288 //Deflection properties
289// m_angularDeflectionEfficiency = vd.m_angularDeflectionEfficiency;
290// m_angularDeflectionTimescale = vd.m_angularDeflectionTimescale;
291// m_linearDeflectionEfficiency = vd.m_linearDeflectionEfficiency;
292// m_linearDeflectionTimescale = vd.m_linearDeflectionTimescale;
293
294 //Banking properties
295// m_bankingEfficiency = vd.m_bankingEfficiency;
296// m_bankingMix = vd.m_bankingMix;
297// m_bankingTimescale = vd.m_bankingTimescale;
298
299 //Hover and Buoyancy properties
300 m_VhoverHeight = vd.m_VhoverHeight;
301// m_VhoverEfficiency = vd.m_VhoverEfficiency;
302 m_VhoverTimescale = vd.m_VhoverTimescale;
303 m_VehicleBuoyancy = vd.m_VehicleBuoyancy;
304
305 //Attractor properties
306 m_verticalAttractionEfficiency = vd.m_verticalAttractionEfficiency;
307 m_verticalAttractionTimescale = vd.m_verticalAttractionTimescale;
308
309 // Axis
310// m_referenceFrame = vd.m_referenceFrame;
311
312
313 m_taintvehicledata = null;
314 }
315
316 public override void SetVehicle(object vdata)
317 {
318 m_taintvehicledata = vdata;
319 _parent_scene.AddPhysicsActorTaint(this);
320 }
321
322 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
323 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical,
324 bool pisPhantom,byte shapetype, CollisionLocker dode, uint localid)
325 {
326 m_localID = localid;
327 ode = dode;
328 if (!pos.IsFinite())
329 {
330 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
331 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
332 m_log.Warn("[PHYSICS]: Got nonFinite Object create Position");
333 }
334
335 _position = pos;
336 m_taintposition = pos;
337 PID_D = parent_scene.bodyPIDD;
338 PID_G = parent_scene.bodyPIDG;
339 m_density = parent_scene.geomDefaultDensity;
340 // m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
341 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
342
343 prim_geom = IntPtr.Zero;
344 // prev_geom = IntPtr.Zero;
345
346 if (!pos.IsFinite())
347 {
348 size = new Vector3(0.5f, 0.5f, 0.5f);
349 m_log.Warn("[PHYSICS]: Got nonFinite Object create Size");
350 }
351
352 if (size.X <= 0) size.X = 0.01f;
353 if (size.Y <= 0) size.Y = 0.01f;
354 if (size.Z <= 0) size.Z = 0.01f;
355
356 _size = size;
357 m_taintsize = _size;
358
359 if (!QuaternionIsFinite(rotation))
360 {
361 rotation = Quaternion.Identity;
362 m_log.Warn("[PHYSICS]: Got nonFinite Object create Rotation");
363 }
364
365 _orientation = rotation;
366 m_taintrot = _orientation;
367 _mesh = mesh;
368 _pbs = pbs;
369 m_shapetype = shapetype;
370 m_taintshapetype = shapetype;
371
372 _parent_scene = parent_scene;
373 m_targetSpace = (IntPtr)0;
374
375 // if (pos.Z < 0)
376 if (pos.Z < parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y))
377 m_isphysical = false;
378 else
379 {
380 m_isphysical = pisPhysical;
381 // If we're physical, we need to be in the master space for now.
382 // linksets *should* be in a space together.. but are not currently
383 if (m_isphysical)
384 m_targetSpace = _parent_scene.space;
385 }
386
387 m_isphantom = pisPhantom;
388 m_taintphantom = pisPhantom;
389
390 _triMeshData = IntPtr.Zero;
391 m_NoColide = false;
392
393// m_taintserial = null;
394 m_primName = primName;
395 m_taintadd = true;
396 _parent_scene.AddPhysicsActorTaint(this);
397 // don't do .add() here; old geoms get recycled with the same hash
398 }
399
400 public override int PhysicsActorType
401 {
402 get { return (int)ActorTypes.Prim; }
403 set { return; }
404 }
405
406 public override bool SetAlwaysRun
407 {
408 get { return false; }
409 set { return; }
410 }
411
412 public override uint LocalID
413 {
414 set
415 {
416 //m_log.Info("[PHYSICS]: Setting TrackerID: " + value);
417 m_localID = value;
418 }
419 }
420
421 public override bool Grabbed
422 {
423 set { return; }
424 }
425
426 public override bool Selected
427 {
428 set
429 {
430 //Console.WriteLine("Sel {0} {1} {2}", m_primName, value, m_isphysical);
431 // This only makes the object not collidable if the object
432 // is physical or the object is modified somehow *IN THE FUTURE*
433 // without this, if an avatar selects prim, they can walk right
434 // through it while it's selected
435 m_collisionscore = 0;
436 if ((m_isphysical && !_zeroFlag) || !value)
437 {
438 m_taintselected = value;
439 _parent_scene.AddPhysicsActorTaint(this);
440 }
441 else
442 {
443 m_taintselected = value;
444 m_isSelected = value;
445 }
446 if (m_isSelected) disableBodySoft();
447 }
448 }
449
450 public override bool IsPhysical
451 {
452 get { return m_isphysical; }
453 set
454 {
455 m_isphysical = value;
456 if (!m_isphysical)
457 { // Zero the remembered last velocity
458 m_lastVelocity = Vector3.Zero;
459 if (m_type != Vehicle.TYPE_NONE) Halt();
460 }
461 }
462 }
463
464 public override bool IsVolumeDtc
465 {
466 set { return; }
467 get { return m_isVolumeDetect; }
468
469 }
470
471 public override bool Phantom
472 {
473 get { return m_isphantom; }
474 set
475 {
476 m_isphantom = value;
477 }
478 }
479
480 public void setPrimForRemoval()
481 {
482 m_taintremove = true;
483 }
484
485 public override bool Flying
486 {
487 // no flying prims for you
488 get { return false; }
489 set { }
490 }
491
492 public override bool IsColliding
493 {
494 get { return iscolliding; }
495 set { iscolliding = value; }
496 }
497
498 public override bool CollidingGround
499 {
500 get { return false; }
501 set { return; }
502 }
503
504 public override bool CollidingObj
505 {
506 get { return false; }
507 set { return; }
508 }
509
510 public override bool ThrottleUpdates
511 {
512 get { return m_throttleUpdates; }
513 set { m_throttleUpdates = value; }
514 }
515
516 public override bool Stopped
517 {
518 get { return _zeroFlag; }
519 }
520
521 public override Vector3 Position
522 {
523 get { return _position; }
524
525 set
526 {
527 _position = value;
528 //m_log.Info("[PHYSICS]: " + _position.ToString());
529 }
530 }
531
532 public override Vector3 Size
533 {
534 get { return _size; }
535 set
536 {
537 if (value.IsFinite())
538 {
539 _size = value;
540 }
541 else
542 {
543 m_log.Warn("[PHYSICS]: Got NaN Size on object");
544 }
545 }
546 }
547
548 public override float Mass
549 {
550 get
551 {
552 CalculateMass();
553 return m_primMass;
554 }
555 }
556
557 public override Vector3 Force
558 {
559 //get { return Vector3.Zero; }
560 get { return m_force; }
561 set
562 {
563 if (value.IsFinite())
564 {
565 m_force = value;
566 }
567 else
568 {
569 m_log.Warn("[PHYSICS]: NaN in Force Applied to an Object");
570 }
571 }
572 }
573
574 public override int VehicleType
575 {
576 get { return (int)m_type; }
577 set { ProcessTypeChange((Vehicle)value); }
578 }
579
580 public override void VehicleFloatParam(int param, float value)
581 {
582 ProcessFloatVehicleParam((Vehicle)param, value);
583 }
584
585 public override void VehicleVectorParam(int param, Vector3 value)
586 {
587 ProcessVectorVehicleParam((Vehicle)param, value);
588 }
589
590 public override void VehicleRotationParam(int param, Quaternion rotation)
591 {
592 ProcessRotationVehicleParam((Vehicle)param, rotation);
593 }
594
595 public override void VehicleFlags(int param, bool remove)
596 {
597 ProcessVehicleFlags(param, remove);
598 }
599
600 public override void SetVolumeDetect(int param)
601 {
602 lock (_parent_scene.OdeLock)
603 {
604 m_isVolumeDetect = (param != 0);
605 }
606 }
607
608
609 public override Vector3 CenterOfMass
610 {
611 get { return Vector3.Zero; }
612 }
613
614 public override Vector3 GeometricCenter
615 {
616 get { return Vector3.Zero; }
617 }
618
619 public override PrimitiveBaseShape Shape
620 {
621 set
622 {
623 _pbs = value;
624 m_taintshape = true;
625 }
626 }
627
628 public override byte PhysicsShapeType
629 {
630 get
631 {
632 return m_shapetype;
633 }
634 set
635 {
636 m_taintshapetype = value;
637 _parent_scene.AddPhysicsActorTaint(this);
638 }
639 }
640
641 public override Vector3 Velocity
642 {
643 get
644 {
645 // Averate previous velocity with the new one so
646 // client object interpolation works a 'little' better
647 if (_zeroFlag)
648 return Vector3.Zero;
649
650 Vector3 returnVelocity = Vector3.Zero;
651 returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2;
652 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2;
653 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2;
654 return returnVelocity;
655 }
656 set
657 {
658 if (value.IsFinite())
659 {
660 _velocity = value;
661 if (_velocity.ApproxEquals(Vector3.Zero, 0.001f))
662 _acceleration = Vector3.Zero;
663
664 m_taintVelocity = value;
665 _parent_scene.AddPhysicsActorTaint(this);
666 }
667 else
668 {
669 m_log.Warn("[PHYSICS]: Got NaN Velocity in Object");
670 }
671
672 }
673 }
674
675 public override Vector3 Torque
676 {
677 get
678 {
679 if (!m_isphysical || Body == IntPtr.Zero)
680 return Vector3.Zero;
681
682 return _torque;
683 }
684
685 set
686 {
687 if (value.IsFinite())
688 {
689 m_taintTorque = value;
690 _parent_scene.AddPhysicsActorTaint(this);
691 }
692 else
693 {
694 m_log.Warn("[PHYSICS]: Got NaN Torque in Object");
695 }
696 }
697 }
698
699 public override float CollisionScore
700 {
701 get { return m_collisionscore; }
702 set { m_collisionscore = value; }
703 }
704
705 public override bool Kinematic
706 {
707 get { return false; }
708 set { }
709 }
710
711 public override Quaternion Orientation
712 {
713 get { return _orientation; }
714 set
715 {
716 if (QuaternionIsFinite(value))
717 {
718 _orientation = value;
719 }
720 else
721 m_log.Warn("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object");
722
723 }
724 }
725
726 public override bool FloatOnWater
727 {
728 set
729 {
730 m_taintCollidesWater = value;
731 _parent_scene.AddPhysicsActorTaint(this);
732 }
733 }
734
735 public override void SetMomentum(Vector3 momentum)
736 {
737 }
738
739 public override Vector3 PIDTarget
740 {
741 set
742 {
743 if (value.IsFinite())
744 {
745 m_PIDTarget = value;
746 }
747 else
748 m_log.Warn("[PHYSICS]: Got NaN PIDTarget from Scene on Object");
749 }
750 }
751 public override bool PIDActive { set { m_usePID = value; } }
752 public override float PIDTau { set { m_PIDTau = value; } }
753
754 // For RotLookAt
755 public override Quaternion APIDTarget { set { m_APIDTarget = value; } }
756 public override bool APIDActive { set { m_useAPID = value; } }
757 public override float APIDStrength { set { m_APIDStrength = value; } }
758 public override float APIDDamping { set { m_APIDDamping = value; } }
759
760 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
761 public override bool PIDHoverActive { set { m_useHoverPID = value; } }
762 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
763 public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
764
765 internal static bool QuaternionIsFinite(Quaternion q)
766 {
767 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
768 return false;
769 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
770 return false;
771 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
772 return false;
773 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
774 return false;
775 return true;
776 }
777
778 public override Vector3 Acceleration // client updates read data via here
779 {
780 get
781 {
782 if (_zeroFlag)
783 {
784 return Vector3.Zero;
785 }
786 return _acceleration;
787 }
788 set { _acceleration = value; }
789 }
790
791
792 public void SetAcceleration(Vector3 accel) // No one calls this, and it would not do anything.
793 {
794 _acceleration = accel;
795 }
796
797 public override void AddForce(Vector3 force, bool pushforce)
798 {
799 if (force.IsFinite())
800 {
801 lock (m_forcelist)
802 m_forcelist.Add(force);
803
804 m_taintforce = true;
805 }
806 else
807 {
808 m_log.Warn("[PHYSICS]: Got Invalid linear force vector from Scene in Object");
809 }
810 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
811 }
812
813 public override void AddAngularForce(Vector3 force, bool pushforce)
814 {
815 if (force.IsFinite())
816 {
817 m_angularforcelist.Add(force);
818 m_taintaddangularforce = true;
819 }
820 else
821 {
822 m_log.Warn("[PHYSICS]: Got Invalid Angular force vector from Scene in Object");
823 }
824 }
825
826 public override Vector3 RotationalVelocity
827 {
828 get
829 {
830 return m_rotationalVelocity;
831 }
832 set
833 {
834 if (value.IsFinite())
835 {
836 m_rotationalVelocity = value;
837 }
838 else
839 {
840 m_log.Warn("[PHYSICS]: Got NaN RotationalVelocity in Object");
841 }
842 }
843 }
844
845 public override void CrossingFailure()
846 {
847 if (m_outofBounds)
848 {
849 _position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
850 _position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
851 _position.Z = Util.Clip(_position.Z, -100f, 50000f);
852 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
853
854 m_lastposition = _position;
855
856 _velocity = Vector3.Zero;
857 m_lastVelocity = _velocity;
858
859
860 if (m_type != Vehicle.TYPE_NONE)
861 Halt();
862
863 d.BodySetLinearVel(Body, 0, 0, 0);
864 base.RequestPhysicsterseUpdate();
865 m_outofBounds = false;
866 }
867 /*
868 int tmp = Interlocked.Increment(ref m_crossingfailures);
869 if (tmp > _parent_scene.geomCrossingFailuresBeforeOutofbounds)
870 {
871 base.RaiseOutOfBounds(_position);
872 return;
873 }
874 else if (tmp == _parent_scene.geomCrossingFailuresBeforeOutofbounds)
875 {
876 m_log.Warn("[PHYSICS]: Too many crossing failures for: " + m_primName);
877 }
878 */
879 }
880
881 public override float Buoyancy
882 {
883 get { return m_buoyancy; }
884 set { m_buoyancy = value; }
885 }
886
887 public override void link(PhysicsActor obj)
888 {
889 m_taintparent = obj;
890 }
891
892 public override void delink()
893 {
894 m_taintparent = null;
895 }
896
897 public override void LockAngularMotion(Vector3 axis)
898 {
899 // This is actually ROTATION ENABLE, not a lock.
900 // default is <1,1,1> which is all enabled.
901 // The lock value is updated inside Move(), no point in using the taint system.
902 // OS 'm_taintAngularLock' etc change to m_rotateEnable.
903 if (axis.IsFinite())
904 {
905 axis.X = (axis.X > 0) ? 1f : 0f;
906 axis.Y = (axis.Y > 0) ? 1f : 0f;
907 axis.Z = (axis.Z > 0) ? 1f : 0f;
908 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
909 m_rotateEnableRequest = axis;
910 m_rotateEnableUpdate = true;
911 }
912 else
913 {
914 m_log.Warn("[PHYSICS]: Got NaN locking axis from Scene on Object");
915 }
916 }
917
918 public void SetGeom(IntPtr geom)
919 {
920 if (prim_geom != IntPtr.Zero)
921 {
922 // Remove any old entries
923 //string tPA;
924 //_parent_scene.geom_name_map.TryGetValue(prim_geom, out tPA);
925 //Console.WriteLine("**** Remove {0}", tPA);
926 if (_parent_scene.geom_name_map.ContainsKey(prim_geom)) _parent_scene.geom_name_map.Remove(prim_geom);
927 if (_parent_scene.actor_name_map.ContainsKey(prim_geom)) _parent_scene.actor_name_map.Remove(prim_geom);
928 d.GeomDestroy(prim_geom);
929 }
930
931 prim_geom = geom;
932 //Console.WriteLine("SetGeom to " + prim_geom + " for " + m_primName);
933 if (prim_geom != IntPtr.Zero)
934 {
935 _parent_scene.geom_name_map[prim_geom] = this.m_primName;
936 _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this;
937 //Console.WriteLine("**** Create {2} Dicts: actor={0} name={1}", _parent_scene.actor_name_map.Count, _parent_scene.geom_name_map.Count, this.m_primName);
938 if (m_NoColide)
939 {
940 d.GeomSetCategoryBits(prim_geom, 0);
941 if (m_isphysical && !m_isVolumeDetect)
942 {
943 d.GeomSetCollideBits(prim_geom, (int)CollisionCategories.Land);
944 }
945 else
946 {
947 d.GeomSetCollideBits(prim_geom, 0);
948 d.GeomDisable(prim_geom);
949 }
950 }
951 else
952 {
953 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
954 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
955 }
956 }
957
958 if (childPrim)
959 {
960 if (_parent != null && _parent is OdePrim)
961 {
962 OdePrim parent = (OdePrim)_parent;
963 //Console.WriteLine("SetGeom calls ChildSetGeom");
964 parent.ChildSetGeom(this);
965 }
966 }
967 //m_log.Warn("Setting Geom to: " + prim_geom);
968 }
969
970 public void enableBodySoft()
971 {
972 if (!childPrim)
973 {
974 if (m_isphysical && Body != IntPtr.Zero)
975 {
976 d.BodyEnable(Body);
977 if (m_type != Vehicle.TYPE_NONE)
978 Enable(Body, _parent_scene);
979 }
980
981 m_disabled = false;
982 }
983 }
984
985 public void disableBodySoft()
986 {
987 m_disabled = true;
988
989 if (m_isphysical && Body != IntPtr.Zero)
990 {
991 d.BodyDisable(Body);
992 Halt();
993 }
994 }
995
996 public void enableBody()
997 {
998 // Don't enable this body if we're a child prim
999 // this should be taken care of in the parent function not here
1000 if (!childPrim)
1001 {
1002 // Sets the geom to a body
1003 Body = d.BodyCreate(_parent_scene.world);
1004
1005 setMass();
1006 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
1007 d.Quaternion myrot = new d.Quaternion();
1008 myrot.X = _orientation.X;
1009 myrot.Y = _orientation.Y;
1010 myrot.Z = _orientation.Z;
1011 myrot.W = _orientation.W;
1012 d.BodySetQuaternion(Body, ref myrot);
1013 d.GeomSetBody(prim_geom, Body);
1014
1015 m_collisionCategories |= CollisionCategories.Body;
1016 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1017
1018 if (m_NoColide)
1019 {
1020 d.GeomSetCategoryBits(prim_geom, 0);
1021 d.GeomSetCollideBits(prim_geom, (int)CollisionCategories.Land);
1022 }
1023 else
1024 {
1025 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1026 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1027 }
1028
1029 d.BodySetAutoDisableFlag(Body, true);
1030 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1031
1032 // disconnect from world gravity so we can apply buoyancy
1033 d.BodySetGravityMode(Body, false);
1034
1035 m_interpenetrationcount = 0;
1036 m_collisionscore = 0;
1037 m_disabled = false;
1038
1039 if (m_type != Vehicle.TYPE_NONE)
1040 {
1041 Enable(Body, _parent_scene);
1042 }
1043
1044 _parent_scene.addActivePrim(this);
1045 }
1046 }
1047
1048 #region Mass Calculation
1049
1050 private float CalculateMass()
1051 {
1052 float volume = _size.X * _size.Y * _size.Z; // default
1053 float tmp;
1054
1055 float returnMass = 0;
1056 float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f;
1057 float hollowVolume = hollowAmount * hollowAmount;
1058
1059 switch (_pbs.ProfileShape)
1060 {
1061 case ProfileShape.Square:
1062 // default box
1063
1064 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1065 {
1066 if (hollowAmount > 0.0)
1067 {
1068 switch (_pbs.HollowShape)
1069 {
1070 case HollowShape.Square:
1071 case HollowShape.Same:
1072 break;
1073
1074 case HollowShape.Circle:
1075
1076 hollowVolume *= 0.78539816339f;
1077 break;
1078
1079 case HollowShape.Triangle:
1080
1081 hollowVolume *= (0.5f * .5f);
1082 break;
1083
1084 default:
1085 hollowVolume = 0;
1086 break;
1087 }
1088 volume *= (1.0f - hollowVolume);
1089 }
1090 }
1091
1092 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1093 {
1094 //a tube
1095
1096 volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX);
1097 tmp = 1.0f - 2.0e-2f * (float)(200 - _pbs.PathScaleY);
1098 volume -= volume * tmp * tmp;
1099
1100 if (hollowAmount > 0.0)
1101 {
1102 hollowVolume *= hollowAmount;
1103
1104 switch (_pbs.HollowShape)
1105 {
1106 case HollowShape.Square:
1107 case HollowShape.Same:
1108 break;
1109
1110 case HollowShape.Circle:
1111 hollowVolume *= 0.78539816339f; ;
1112 break;
1113
1114 case HollowShape.Triangle:
1115 hollowVolume *= 0.5f * 0.5f;
1116 break;
1117 default:
1118 hollowVolume = 0;
1119 break;
1120 }
1121 volume *= (1.0f - hollowVolume);
1122 }
1123 }
1124
1125 break;
1126
1127 case ProfileShape.Circle:
1128
1129 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1130 {
1131 volume *= 0.78539816339f; // elipse base
1132
1133 if (hollowAmount > 0.0)
1134 {
1135 switch (_pbs.HollowShape)
1136 {
1137 case HollowShape.Same:
1138 case HollowShape.Circle:
1139 break;
1140
1141 case HollowShape.Square:
1142 hollowVolume *= 0.5f * 2.5984480504799f;
1143 break;
1144
1145 case HollowShape.Triangle:
1146 hollowVolume *= .5f * 1.27323954473516f;
1147 break;
1148
1149 default:
1150 hollowVolume = 0;
1151 break;
1152 }
1153 volume *= (1.0f - hollowVolume);
1154 }
1155 }
1156
1157 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1158 {
1159 volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX);
1160 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1161 volume *= (1.0f - tmp * tmp);
1162
1163 if (hollowAmount > 0.0)
1164 {
1165
1166 // calculate the hollow volume by it's shape compared to the prim shape
1167 hollowVolume *= hollowAmount;
1168
1169 switch (_pbs.HollowShape)
1170 {
1171 case HollowShape.Same:
1172 case HollowShape.Circle:
1173 break;
1174
1175 case HollowShape.Square:
1176 hollowVolume *= 0.5f * 2.5984480504799f;
1177 break;
1178
1179 case HollowShape.Triangle:
1180 hollowVolume *= .5f * 1.27323954473516f;
1181 break;
1182
1183 default:
1184 hollowVolume = 0;
1185 break;
1186 }
1187 volume *= (1.0f - hollowVolume);
1188 }
1189 }
1190 break;
1191
1192 case ProfileShape.HalfCircle:
1193 if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1194 {
1195 volume *= 0.52359877559829887307710723054658f;
1196 }
1197 break;
1198
1199 case ProfileShape.EquilateralTriangle:
1200
1201 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1202 {
1203 volume *= 0.32475953f;
1204
1205 if (hollowAmount > 0.0)
1206 {
1207
1208 // calculate the hollow volume by it's shape compared to the prim shape
1209 switch (_pbs.HollowShape)
1210 {
1211 case HollowShape.Same:
1212 case HollowShape.Triangle:
1213 hollowVolume *= .25f;
1214 break;
1215
1216 case HollowShape.Square:
1217 hollowVolume *= 0.499849f * 3.07920140172638f;
1218 break;
1219
1220 case HollowShape.Circle:
1221 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1222 // Cyllinder hollow volume calculation
1223
1224 hollowVolume *= 0.1963495f * 3.07920140172638f;
1225 break;
1226
1227 default:
1228 hollowVolume = 0;
1229 break;
1230 }
1231 volume *= (1.0f - hollowVolume);
1232 }
1233 }
1234 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1235 {
1236 volume *= 0.32475953f;
1237 volume *= 0.01f * (float)(200 - _pbs.PathScaleX);
1238 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1239 volume *= (1.0f - tmp * tmp);
1240
1241 if (hollowAmount > 0.0)
1242 {
1243
1244 hollowVolume *= hollowAmount;
1245
1246 switch (_pbs.HollowShape)
1247 {
1248 case HollowShape.Same:
1249 case HollowShape.Triangle:
1250 hollowVolume *= .25f;
1251 break;
1252
1253 case HollowShape.Square:
1254 hollowVolume *= 0.499849f * 3.07920140172638f;
1255 break;
1256
1257 case HollowShape.Circle:
1258
1259 hollowVolume *= 0.1963495f * 3.07920140172638f;
1260 break;
1261
1262 default:
1263 hollowVolume = 0;
1264 break;
1265 }
1266 volume *= (1.0f - hollowVolume);
1267 }
1268 }
1269 break;
1270
1271 default:
1272 break;
1273 }
1274
1275
1276
1277 float taperX1;
1278 float taperY1;
1279 float taperX;
1280 float taperY;
1281 float pathBegin;
1282 float pathEnd;
1283 float profileBegin;
1284 float profileEnd;
1285
1286 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
1287 {
1288 taperX1 = _pbs.PathScaleX * 0.01f;
1289 if (taperX1 > 1.0f)
1290 taperX1 = 2.0f - taperX1;
1291 taperX = 1.0f - taperX1;
1292
1293 taperY1 = _pbs.PathScaleY * 0.01f;
1294 if (taperY1 > 1.0f)
1295 taperY1 = 2.0f - taperY1;
1296 taperY = 1.0f - taperY1;
1297 }
1298 else
1299 {
1300 taperX = _pbs.PathTaperX * 0.01f;
1301 if (taperX < 0.0f)
1302 taperX = -taperX;
1303 taperX1 = 1.0f - taperX;
1304
1305 taperY = _pbs.PathTaperY * 0.01f;
1306 if (taperY < 0.0f)
1307 taperY = -taperY;
1308 taperY1 = 1.0f - taperY;
1309
1310 }
1311
1312
1313 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
1314
1315 pathBegin = (float)_pbs.PathBegin * 2.0e-5f;
1316 pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f;
1317 volume *= (pathEnd - pathBegin);
1318
1319 // this is crude aproximation
1320 profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f;
1321 profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f;
1322 volume *= (profileEnd - profileBegin);
1323
1324 returnMass = m_density * volume;
1325
1326 if (returnMass <= 0)
1327 returnMass = 0.0001f;//ckrinke: Mass must be greater then zero.
1328 // else if (returnMass > _parent_scene.maximumMassObject)
1329 // returnMass = _parent_scene.maximumMassObject;
1330
1331
1332
1333 m_primMass = returnMass;
1334 if (m_primMass > _parent_scene.maximumMassObject)
1335 m_primMass = _parent_scene.maximumMassObject;
1336
1337 // Recursively calculate mass
1338 bool HasChildPrim = false;
1339 lock (childrenPrim)
1340 {
1341 if (childrenPrim.Count > 0)
1342 {
1343 HasChildPrim = true;
1344 }
1345
1346 }
1347 if (HasChildPrim)
1348 {
1349 OdePrim[] childPrimArr = new OdePrim[0];
1350
1351 lock (childrenPrim)
1352 childPrimArr = childrenPrim.ToArray();
1353
1354 for (int i = 0; i < childPrimArr.Length; i++)
1355 {
1356 if (childPrimArr[i] != null && !childPrimArr[i].m_taintremove)
1357 returnMass += childPrimArr[i].CalculateMass();
1358 // failsafe, this shouldn't happen but with OpenSim, you never know :)
1359 if (i > 256)
1360 break;
1361 }
1362 }
1363 if (returnMass > _parent_scene.maximumMassObject)
1364 returnMass = _parent_scene.maximumMassObject;
1365 return returnMass;
1366 }// end CalculateMass
1367
1368 #endregion
1369
1370 public void setMass()
1371 {
1372 if (Body != (IntPtr)0)
1373 {
1374 float newmass = CalculateMass();
1375
1376 //m_log.Info("[PHYSICS]: New Mass: " + newmass.ToString());
1377
1378 d.MassSetBoxTotal(out pMass, newmass, _size.X, _size.Y, _size.Z);
1379 d.BodySetMass(Body, ref pMass);
1380 }
1381 }
1382
1383
1384 private void UpdateDataFromGeom()
1385 {
1386 if (prim_geom != IntPtr.Zero)
1387 {
1388 d.Quaternion qtmp;
1389 d.GeomCopyQuaternion(prim_geom, out qtmp);
1390 _orientation.W = qtmp.W;
1391 _orientation.X = qtmp.X;
1392 _orientation.Y = qtmp.Y;
1393 _orientation.Z = qtmp.Z;
1394
1395 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
1396 _position.X = lpos.X;
1397 _position.Y = lpos.Y;
1398 _position.Z = lpos.Z;
1399 }
1400 }
1401
1402 public void disableBody()
1403 {
1404 //this kills the body so things like 'mesh' can re-create it.
1405 lock (this)
1406 {
1407 if (!childPrim)
1408 {
1409 if (Body != IntPtr.Zero)
1410 {
1411 _parent_scene.remActivePrim(this);
1412 m_collisionCategories &= ~CollisionCategories.Body;
1413 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1414
1415 if (prim_geom != IntPtr.Zero)
1416 {
1417 if (m_NoColide)
1418 {
1419 d.GeomSetCategoryBits(prim_geom, 0);
1420 d.GeomSetCollideBits(prim_geom, 0);
1421 d.GeomDisable(prim_geom);
1422 }
1423 else
1424 {
1425 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1426 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1427 }
1428 }
1429
1430 UpdateDataFromGeom();
1431
1432 lock (childrenPrim)
1433 {
1434 if (childrenPrim.Count > 0)
1435 {
1436 foreach (OdePrim prm in childrenPrim)
1437 {
1438 if (prm.prim_geom != IntPtr.Zero)
1439 {
1440 if (prm.m_NoColide)
1441 {
1442 d.GeomSetCategoryBits(prm.prim_geom, 0);
1443 d.GeomSetCollideBits(prm.prim_geom, 0);
1444 d.GeomDisable(prm.prim_geom);
1445
1446 }
1447 prm.UpdateDataFromGeom();
1448 }
1449 _parent_scene.remActivePrim(prm);
1450 prm.Body = IntPtr.Zero;
1451 }
1452 }
1453 }
1454 d.BodyDestroy(Body);
1455 Body = IntPtr.Zero;
1456 }
1457 }
1458 else
1459 {
1460 _parent_scene.remActivePrim(this);
1461
1462 m_collisionCategories &= ~CollisionCategories.Body;
1463 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1464
1465 if (prim_geom != IntPtr.Zero)
1466 {
1467 if (m_NoColide)
1468 {
1469 d.GeomSetCategoryBits(prim_geom, 0);
1470 d.GeomSetCollideBits(prim_geom, 0);
1471 d.GeomDisable(prim_geom);
1472 }
1473 else
1474 {
1475 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1476 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1477 }
1478 }
1479
1480 Body = IntPtr.Zero;
1481 }
1482 }
1483 m_disabled = true;
1484 m_collisionscore = 0;
1485 }
1486
1487// private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>();
1488
1489 public bool setMesh(OdeScene parent_scene, IMesh mesh)
1490 {
1491 //Kill Body so that mesh can re-make the geom
1492 if (IsPhysical && Body != IntPtr.Zero)
1493 {
1494 if (childPrim)
1495 {
1496 if (_parent != null)
1497 {
1498 OdePrim parent = (OdePrim)_parent;
1499 parent.ChildDelink(this);
1500 }
1501 }
1502 else
1503 {
1504 disableBody();
1505 }
1506 }
1507
1508 IntPtr vertices, indices;
1509 int vertexCount, indexCount;
1510 int vertexStride, triStride;
1511 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
1512 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
1513
1514 // warning this destroys the mesh for eventual future use. Only pinned float arrays stay valid
1515 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
1516
1517 if (vertexCount == 0 || indexCount == 0)
1518 {
1519 m_log.WarnFormat("[PHYSICS]: Got invalid mesh on prim {0} at <{1},{2},{3}>. mesh UUID {4}", Name, _position.X, _position.Y, _position.Z, _pbs.SculptTexture.ToString());
1520 return false;
1521 }
1522
1523 IntPtr geo = IntPtr.Zero;
1524 try
1525 {
1526 _triMeshData = d.GeomTriMeshDataCreate();
1527 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1528 d.GeomTriMeshDataPreprocess(_triMeshData);
1529
1530 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1531
1532 geo = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
1533 }
1534 catch (Exception e)
1535 {
1536 m_log.ErrorFormat("[PHYSICS]: Create trimesh failed on prim {0} : {1}",Name,e.Message);
1537
1538 if (_triMeshData != IntPtr.Zero)
1539 {
1540 d.GeomTriMeshDataDestroy(_triMeshData);
1541 _triMeshData = IntPtr.Zero;
1542 }
1543 return false;
1544 }
1545
1546 SetGeom(geo);
1547
1548 return true;
1549 }
1550
1551 public void ProcessTaints(float timestep) //=============================================================================
1552 {
1553 if (m_taintadd)
1554 {
1555 changeadd(timestep);
1556 }
1557
1558 if (m_taintremove)
1559 return;
1560
1561 if (prim_geom != IntPtr.Zero)
1562 {
1563 if (!_position.ApproxEquals(m_taintposition, 0f))
1564 {
1565 changemove(timestep);
1566 }
1567 if (m_taintrot != _orientation)
1568 {
1569 if (childPrim && IsPhysical) // For physical child prim...
1570 {
1571 rotate(timestep);
1572 // KF: ODE will also rotate the parent prim!
1573 // so rotate the root back to where it was
1574 OdePrim parent = (OdePrim)_parent;
1575 parent.rotate(timestep);
1576 }
1577 else
1578 {
1579 //Just rotate the prim
1580 rotate(timestep);
1581 }
1582 }
1583 //
1584 if (m_taintphantom != m_isphantom )
1585 {
1586 changePhantomStatus();
1587 }//
1588
1589 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent))
1590 {
1591 changePhysicsStatus(timestep);
1592 }//
1593
1594
1595 if (!_size.ApproxEquals(m_taintsize, 0f))
1596 changesize(timestep);
1597 //
1598
1599 if(m_taintshapetype != m_shapetype)
1600 {
1601 m_shapetype = m_taintshapetype;
1602 changeshape(timestep);
1603 }
1604
1605 if (m_taintshape)
1606 changeshape(timestep);
1607 //
1608
1609 if (m_taintforce)
1610 changeAddForce(timestep);
1611
1612 if (m_taintaddangularforce)
1613 changeAddAngularForce(timestep);
1614
1615 if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
1616 changeSetTorque(timestep);
1617
1618 if (m_taintdisable)
1619 changedisable(timestep);
1620
1621 if (m_taintselected != m_isSelected)
1622 changeSelectedStatus();
1623
1624 if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
1625 changevelocity(timestep);
1626
1627 if (m_taintparent != _parent)
1628 changelink(timestep);
1629
1630 if (m_taintCollidesWater != m_collidesWater)
1631 changefloatonwater(timestep);
1632
1633 if (m_taintvehicledata != null)
1634 DoSetVehicle();
1635
1636 /* obsolete
1637 if (!m_angularLock.ApproxEquals(m_taintAngularLock,0f))
1638 changeAngularLock(timestep);
1639 */
1640 }
1641
1642 else
1643 {
1644 m_log.Error("[PHYSICS]: prim {0} at <{1},{2},{3}> as invalid geom");
1645
1646 // not sure this will not flame...
1647 m_taintremove = true;
1648 _parent_scene.AddPhysicsActorTaint(this);
1649 }
1650
1651 }
1652
1653 private void changelink(float timestep)
1654 {
1655 // If the newly set parent is not null
1656 // create link
1657 if (_parent == null && m_taintparent != null)
1658 {
1659 if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim)
1660 {
1661 OdePrim obj = (OdePrim)m_taintparent;
1662 obj.ParentPrim(this);
1663 }
1664 }
1665 // If the newly set parent is null
1666 // destroy link
1667 else if (_parent != null && m_taintparent == null)
1668 {
1669 if (_parent is OdePrim)
1670 {
1671 OdePrim obj = (OdePrim)_parent;
1672 obj.ChildDelink(this);
1673 childPrim = false;
1674 }
1675 }
1676
1677 _parent = m_taintparent;
1678 m_taintPhysics = m_isphysical;
1679 }
1680
1681 // I'm the parent
1682 // prim is the child
1683 public void ParentPrim(OdePrim prim)
1684 {
1685 if (this.m_localID != prim.m_localID)
1686 {
1687 if (Body == IntPtr.Zero)
1688 {
1689 Body = d.BodyCreate(_parent_scene.world);
1690 // disconnect from world gravity so we can apply buoyancy
1691 d.BodySetGravityMode(Body, false);
1692
1693 setMass();
1694 }
1695 if (Body != IntPtr.Zero)
1696 {
1697 lock (childrenPrim)
1698 {
1699 if (!childrenPrim.Contains(prim))
1700 {
1701 childrenPrim.Add(prim);
1702
1703 foreach (OdePrim prm in childrenPrim)
1704 {
1705 d.Mass m2;
1706 d.MassSetZero(out m2);
1707 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1708
1709
1710 d.Quaternion quat = new d.Quaternion();
1711 quat.W = prm._orientation.W;
1712 quat.X = prm._orientation.X;
1713 quat.Y = prm._orientation.Y;
1714 quat.Z = prm._orientation.Z;
1715
1716 d.Matrix3 mat = new d.Matrix3();
1717 d.RfromQ(out mat, ref quat);
1718 d.MassRotate(ref m2, ref mat);
1719 d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
1720 d.MassAdd(ref pMass, ref m2);
1721 }
1722 foreach (OdePrim prm in childrenPrim)
1723 {
1724 if (m_isphantom && !prm.m_isVolumeDetect)
1725 {
1726 prm.m_collisionCategories = 0;
1727 prm.m_collisionFlags = CollisionCategories.Land;
1728 }
1729 else
1730 {
1731 prm.m_collisionCategories |= CollisionCategories.Body;
1732 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1733 }
1734 if (prm.prim_geom == IntPtr.Zero)
1735 {
1736 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements. No geom yet");
1737 continue;
1738 }
1739
1740 if (prm.m_NoColide)
1741 {
1742 d.GeomSetCategoryBits(prm.prim_geom, 0);
1743 d.GeomSetCollideBits(prm.prim_geom, (int)CollisionCategories.Land);
1744 }
1745 else
1746 {
1747 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1748 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1749 }
1750
1751 d.Quaternion quat = new d.Quaternion();
1752 quat.W = prm._orientation.W;
1753 quat.X = prm._orientation.X;
1754 quat.Y = prm._orientation.Y;
1755 quat.Z = prm._orientation.Z;
1756
1757 d.Matrix3 mat = new d.Matrix3();
1758 d.RfromQ(out mat, ref quat);
1759 if (Body != IntPtr.Zero)
1760 {
1761 d.GeomSetBody(prm.prim_geom, Body);
1762 prm.childPrim = true;
1763 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X, prm.Position.Y, prm.Position.Z);
1764 //d.GeomSetOffsetPosition(prim.prim_geom,
1765 // (Position.X - prm.Position.X) - pMass.c.X,
1766 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1767 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1768 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
1769 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
1770 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1771 d.BodySetMass(Body, ref pMass);
1772 }
1773 else
1774 {
1775 m_log.Debug("[PHYSICS]:I ain't got no boooooooooddy, no body");
1776 }
1777
1778 prm.m_interpenetrationcount = 0;
1779 prm.m_collisionscore = 0;
1780 prm.m_disabled = false;
1781
1782 prm.Body = Body;
1783
1784 _parent_scene.addActivePrim(prm);
1785 }
1786
1787 if (m_isphantom && !m_isVolumeDetect)
1788 {
1789 m_collisionCategories = 0;
1790 m_collisionFlags = CollisionCategories.Land;
1791 }
1792 else
1793 {
1794 m_collisionCategories |= CollisionCategories.Body;
1795 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1796 }
1797
1798 if (m_NoColide)
1799 {
1800 d.GeomSetCategoryBits(prim_geom, 0);
1801 d.GeomSetCollideBits(prim_geom, (int)CollisionCategories.Land);
1802 }
1803 else
1804 {
1805 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1806 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1807 }
1808
1809 d.Quaternion quat2 = new d.Quaternion();
1810 quat2.W = _orientation.W;
1811 quat2.X = _orientation.X;
1812 quat2.Y = _orientation.Y;
1813 quat2.Z = _orientation.Z;
1814
1815 d.Matrix3 mat2 = new d.Matrix3();
1816 d.RfromQ(out mat2, ref quat2);
1817 d.GeomSetBody(prim_geom, Body);
1818 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1819 //d.GeomSetOffsetPosition(prim.prim_geom,
1820 // (Position.X - prm.Position.X) - pMass.c.X,
1821 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1822 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1823 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1824 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1825 d.BodySetMass(Body, ref pMass);
1826
1827 d.BodySetAutoDisableFlag(Body, true);
1828 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1829
1830 m_interpenetrationcount = 0;
1831 m_collisionscore = 0;
1832 m_disabled = false;
1833
1834 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1835 if (m_type != Vehicle.TYPE_NONE) Enable(Body, _parent_scene);
1836
1837 _parent_scene.addActivePrim(this);
1838 }
1839 }
1840 }
1841 }
1842 }
1843
1844 private void ChildSetGeom(OdePrim odePrim)
1845 {
1846 lock (childrenPrim)
1847 {
1848 foreach (OdePrim prm in childrenPrim)
1849 {
1850 prm.disableBody();
1851 }
1852 }
1853 disableBody();
1854
1855 if (Body != IntPtr.Zero)
1856 {
1857 _parent_scene.remActivePrim(this);
1858 }
1859
1860 lock (childrenPrim)
1861 {
1862 foreach (OdePrim prm in childrenPrim)
1863 {
1864 ParentPrim(prm);
1865 }
1866 }
1867 }
1868
1869 private void ChildDelink(OdePrim odePrim)
1870 {
1871 // Okay, we have a delinked child.. need to rebuild the body.
1872 lock (childrenPrim)
1873 {
1874 foreach (OdePrim prm in childrenPrim)
1875 {
1876 prm.childPrim = true;
1877 prm.disableBody();
1878 }
1879 }
1880 disableBody();
1881
1882 lock (childrenPrim)
1883 {
1884 childrenPrim.Remove(odePrim);
1885 }
1886
1887 if (Body != IntPtr.Zero)
1888 {
1889 _parent_scene.remActivePrim(this);
1890 }
1891
1892 lock (childrenPrim)
1893 {
1894 foreach (OdePrim prm in childrenPrim)
1895 {
1896 ParentPrim(prm);
1897 }
1898 }
1899 }
1900
1901 private void changePhantomStatus()
1902 {
1903 m_taintphantom = m_isphantom;
1904 changeSelectedStatus();
1905 }
1906
1907/* not in use
1908 private void SetCollider()
1909 {
1910 SetCollider(m_isSelected, m_isphysical, m_isphantom, m_isSelected);
1911 }
1912
1913 private void SetCollider(bool sel, bool phys, bool phan, bool vdtc)
1914 {
1915 if (sel)
1916 {
1917 m_collisionCategories = CollisionCategories.Selected;
1918 m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space);
1919 }
1920 else
1921 {
1922 if (phan && !vdtc)
1923 {
1924 m_collisionCategories = 0;
1925 if (phys)
1926 m_collisionFlags = CollisionCategories.Land;
1927 else
1928 m_collisionFlags = 0; // this case should not happen non physical phantoms should not have physics
1929 }
1930 else
1931 {
1932 m_collisionCategories = CollisionCategories.Geom;
1933 if (phys)
1934 m_collisionCategories |= CollisionCategories.Body;
1935
1936 m_collisionFlags = m_default_collisionFlags;
1937
1938 if (m_collidesLand)
1939 m_collisionFlags |= CollisionCategories.Land;
1940 if (m_collidesWater)
1941 m_collisionFlags |= CollisionCategories.Water;
1942 }
1943 }
1944
1945 if (prim_geom != IntPtr.Zero)
1946 {
1947 if (m_NoColide)
1948 {
1949 d.GeomSetCategoryBits(prim_geom, 0);
1950 if (phys)
1951 d.GeomSetCollideBits(prim_geom, (int)CollisionCategories.Land);
1952 else
1953 {
1954 d.GeomSetCollideBits(prim_geom, 0);
1955 d.GeomDisable(prim_geom);
1956 }
1957 }
1958 else
1959 {
1960 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1961 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1962 }
1963 }
1964 }
1965*/
1966
1967 private void changeSelectedStatus()
1968 {
1969 if (m_taintselected)
1970 {
1971 m_collisionCategories = CollisionCategories.Selected;
1972 m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space);
1973
1974 // We do the body disable soft twice because 'in theory' a collision could have happened
1975 // in between the disabling and the collision properties setting
1976 // which would wake the physical body up from a soft disabling and potentially cause it to fall
1977 // through the ground.
1978
1979 // NOTE FOR JOINTS: this doesn't always work for jointed assemblies because if you select
1980 // just one part of the assembly, the rest of the assembly is non-selected and still simulating,
1981 // so that causes the selected part to wake up and continue moving.
1982
1983 // even if you select all parts of a jointed assembly, it is not guaranteed that the entire
1984 // assembly will stop simulating during the selection, because of the lack of atomicity
1985 // of select operations (their processing could be interrupted by a thread switch, causing
1986 // simulation to continue before all of the selected object notifications trickle down to
1987 // the physics engine).
1988
1989 // e.g. we select 100 prims that are connected by joints. non-atomically, the first 50 are
1990 // selected and disabled. then, due to a thread switch, the selection processing is
1991 // interrupted and the physics engine continues to simulate, so the last 50 items, whose
1992 // selection was not yet processed, continues to simulate. this wakes up ALL of the
1993 // first 50 again. then the last 50 are disabled. then the first 50, which were just woken
1994 // up, start simulating again, which in turn wakes up the last 50.
1995
1996 if (m_isphysical)
1997 {
1998 disableBodySoft();
1999 }
2000
2001 if (prim_geom != IntPtr.Zero)
2002 {
2003 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2004 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2005 if (m_NoColide)
2006 d.GeomDisable(prim_geom);
2007 }
2008
2009 if (m_isphysical)
2010 {
2011 disableBodySoft();
2012 }
2013 if (Body != IntPtr.Zero)
2014 {
2015 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2016 d.BodySetForce(Body, 0f, 0f, 0f);
2017 d.BodySetAngularVel(Body, 0.0f, 0.0f, 0.0f);
2018 d.BodySetTorque(Body, 0.0f, 0.0f, 0.0f);
2019 }
2020 }
2021 else
2022 {
2023 if (m_isphantom && !m_isVolumeDetect)
2024 {
2025 m_collisionCategories = 0;
2026 if (m_isphysical)
2027 m_collisionFlags = CollisionCategories.Land;
2028 else
2029 m_collisionFlags = 0; // this case should not happen non physical phantoms should not have physics
2030 }
2031 else
2032 {
2033 m_collisionCategories = CollisionCategories.Geom;
2034 if (m_isphysical)
2035 m_collisionCategories |= CollisionCategories.Body;
2036
2037 m_collisionFlags = m_default_collisionFlags;
2038
2039 if (m_collidesLand)
2040 m_collisionFlags |= CollisionCategories.Land;
2041 if (m_collidesWater)
2042 m_collisionFlags |= CollisionCategories.Water;
2043 }
2044
2045 if (prim_geom != IntPtr.Zero)
2046 {
2047 if (m_NoColide)
2048 {
2049 d.GeomSetCategoryBits(prim_geom, 0);
2050 if (m_isphysical)
2051 d.GeomSetCollideBits(prim_geom, (int)CollisionCategories.Land);
2052 else
2053 {
2054 d.GeomSetCollideBits(prim_geom, 0);
2055 d.GeomDisable(prim_geom);
2056 }
2057 }
2058 else
2059 {
2060 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2061 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2062 }
2063 }
2064 if (Body != IntPtr.Zero)
2065 {
2066 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2067 d.BodySetForce(Body, 0f, 0f, 0f);
2068 d.BodySetAngularVel(Body, 0.0f, 0.0f, 0.0f);
2069 d.BodySetTorque(Body, 0.0f, 0.0f, 0.0f);
2070 }
2071
2072 if (m_isphysical)
2073 {
2074 if (Body != IntPtr.Zero)
2075 {
2076 enableBodySoft();
2077 }
2078 }
2079 }
2080
2081 resetCollisionAccounting();
2082 m_isSelected = m_taintselected;
2083 }//end changeSelectedStatus
2084
2085 public void ResetTaints()
2086 {
2087 m_taintposition = _position;
2088 m_taintrot = _orientation;
2089 m_taintPhysics = m_isphysical;
2090 m_taintselected = m_isSelected;
2091 m_taintsize = _size;
2092 m_taintshape = false;
2093 m_taintforce = false;
2094 m_taintdisable = false;
2095 m_taintVelocity = Vector3.Zero;
2096 }
2097
2098 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
2099 {
2100 bool gottrimesh = false;
2101
2102 m_NoColide = false; // assume all will go well
2103
2104 if (_triMeshData != IntPtr.Zero)
2105 {
2106 d.GeomTriMeshDataDestroy(_triMeshData);
2107 _triMeshData = IntPtr.Zero;
2108 }
2109
2110 if (_mesh != null)
2111 {
2112 gottrimesh = setMesh(_parent_scene, _mesh);
2113 if (!gottrimesh)
2114 {
2115 // getting a mesh failed,
2116 // lets go on having a basic box or sphere, with prim size but not coliding
2117 // physical colides with land, non with nothing
2118
2119 m_NoColide = true;
2120 }
2121 }
2122
2123 if (!gottrimesh)
2124 { // we will have a basic box or sphere
2125 IntPtr geo = IntPtr.Zero;
2126
2127 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
2128 && _size.X == _size.Y && _size.X == _size.Z)
2129 {
2130 // its a sphere
2131 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2132 try
2133 {
2134 geo = d.CreateSphere(m_targetSpace, _size.X * 0.5f);
2135 }
2136 catch (Exception e)
2137 {
2138 m_log.WarnFormat("[PHYSICS]: Unable to create basic sphere for object {0}", e.Message);
2139 geo = IntPtr.Zero;
2140 ode.dunlock(_parent_scene.world);
2141 }
2142 }
2143 else // make it a box
2144 {
2145 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2146 try
2147 {
2148 geo = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
2149 }
2150 catch (Exception e)
2151 {
2152 m_log.WarnFormat("[PHYSICS]: Unable to create basic sphere for object {0}", e.Message);
2153 geo = IntPtr.Zero;
2154 ode.dunlock(_parent_scene.world);
2155 }
2156 }
2157
2158 if (geo == IntPtr.Zero) // if this happens it must be fixed
2159 {
2160 // if it does lets stop what we can
2161 // not sure this will not flame...
2162
2163 m_taintremove = true;
2164 _parent_scene.AddPhysicsActorTaint(this);
2165 return;
2166 }
2167
2168 SetGeom(geo); // this processes the m_NoColide
2169 }
2170 }
2171
2172 public void changeadd(float timestep)
2173 {
2174 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2175 IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
2176
2177 if (targetspace == IntPtr.Zero)
2178 targetspace = _parent_scene.createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
2179
2180 m_targetSpace = targetspace;
2181
2182 if (_mesh == null) // && m_meshfailed == false)
2183 {
2184 if (_parent_scene.needsMeshing(_pbs))
2185 {
2186 bool convex;
2187 if (m_shapetype == 2)
2188 convex = true;
2189 else
2190 convex = false;
2191 try
2192 {
2193 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, (int)LevelOfDetail.High, true,false,convex,false);
2194 }
2195 catch
2196 {
2197 //Don't continuously try to mesh prims when meshing has failed
2198 m_meshfailed = true;
2199 _mesh = null;
2200 m_log.WarnFormat("[PHYSICS]: changeAdd CreateMesh fail on prim {0} at <{1},{2},{3}>", Name, _position.X, _position.Y, _position.Z);
2201 }
2202 }
2203 }
2204
2205 lock (_parent_scene.OdeLock)
2206 {
2207 CreateGeom(m_targetSpace, _mesh);
2208
2209 if (prim_geom != IntPtr.Zero)
2210 {
2211 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2212 d.Quaternion myrot = new d.Quaternion();
2213 myrot.X = _orientation.X;
2214 myrot.Y = _orientation.Y;
2215 myrot.Z = _orientation.Z;
2216 myrot.W = _orientation.W;
2217 d.GeomSetQuaternion(prim_geom, ref myrot);
2218 }
2219
2220 if (m_isphysical && Body == IntPtr.Zero)
2221 {
2222 enableBody();
2223 }
2224 }
2225
2226 changeSelectedStatus();
2227
2228 m_taintadd = false;
2229 }
2230
2231 public void changemove(float timestep)
2232 {
2233 if (m_isphysical)
2234 {
2235 // if (!m_disabled && !m_taintremove && !childPrim) After one edit m_disabled is sometimes set, disabling further edits!
2236 if (!m_taintremove && !childPrim)
2237 {
2238 if (Body == IntPtr.Zero)
2239 enableBody();
2240 //Prim auto disable after 20 frames,
2241 //if you move it, re-enable the prim manually.
2242 if (_parent != null)
2243 {
2244 if (m_linkJoint != IntPtr.Zero)
2245 {
2246 d.JointDestroy(m_linkJoint);
2247 m_linkJoint = IntPtr.Zero;
2248 }
2249 }
2250 if (Body != IntPtr.Zero)
2251 {
2252 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
2253
2254 if (_parent != null)
2255 {
2256 OdePrim odParent = (OdePrim)_parent;
2257 if (Body != (IntPtr)0 && odParent.Body != (IntPtr)0 && Body != odParent.Body)
2258 {
2259 // KF: Fixed Joints were removed? Anyway - this Console.WriteLine does not show up, so routine is not used??
2260 Console.WriteLine("ODEPrim JointCreateFixed !!!");
2261 m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup);
2262 d.JointAttach(m_linkJoint, Body, odParent.Body);
2263 d.JointSetFixed(m_linkJoint);
2264 }
2265 }
2266 d.BodyEnable(Body);
2267 if (m_type != Vehicle.TYPE_NONE)
2268 {
2269 Enable(Body, _parent_scene);
2270 }
2271 }
2272 else
2273 {
2274 m_log.Warn("[PHYSICS]: Body Still null after enableBody(). This is a crash scenario.");
2275 }
2276 }
2277 //else
2278 // {
2279 //m_log.Debug("[BUG]: race!");
2280 //}
2281 }
2282 else
2283 {
2284 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2285 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2286 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2287
2288 IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
2289 m_targetSpace = tempspace;
2290
2291 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2292 if (prim_geom != IntPtr.Zero)
2293 {
2294 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2295
2296 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2297 d.SpaceAdd(m_targetSpace, prim_geom);
2298 }
2299 }
2300
2301 changeSelectedStatus();
2302
2303 resetCollisionAccounting();
2304 m_taintposition = _position;
2305 }
2306
2307 public void rotate(float timestep)
2308 {
2309 d.Quaternion myrot = new d.Quaternion();
2310 myrot.X = _orientation.X;
2311 myrot.Y = _orientation.Y;
2312 myrot.Z = _orientation.Z;
2313 myrot.W = _orientation.W;
2314 if (Body != IntPtr.Zero)
2315 {
2316 // KF: If this is a root prim do BodySet
2317 d.BodySetQuaternion(Body, ref myrot);
2318 }
2319 else
2320 {
2321 // daughter prim, do Geom set
2322 d.GeomSetQuaternion(prim_geom, ref myrot);
2323 }
2324
2325 resetCollisionAccounting();
2326 m_taintrot = _orientation;
2327 }
2328
2329 private void resetCollisionAccounting()
2330 {
2331 m_collisionscore = 0;
2332 m_interpenetrationcount = 0;
2333 m_disabled = false;
2334 }
2335
2336 public void changedisable(float timestep)
2337 {
2338 m_disabled = true;
2339 if (Body != IntPtr.Zero)
2340 {
2341 d.BodyDisable(Body);
2342 Body = IntPtr.Zero;
2343 }
2344
2345 m_taintdisable = false;
2346 }
2347
2348 public void changePhysicsStatus(float timestep)
2349 {
2350 if (m_isphysical == true)
2351 {
2352 if (Body == IntPtr.Zero)
2353 {
2354 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2355 {
2356 changeshape(2f);
2357 }
2358 else
2359 {
2360 enableBody();
2361 }
2362 }
2363 }
2364 else
2365 {
2366 if (Body != IntPtr.Zero)
2367 {
2368 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2369 {
2370 _mesh = null;
2371 changeadd(2f);
2372 }
2373 if (childPrim)
2374 {
2375 if (_parent != null)
2376 {
2377 OdePrim parent = (OdePrim)_parent;
2378 parent.ChildDelink(this);
2379 }
2380 }
2381 else
2382 {
2383 disableBody();
2384 }
2385 }
2386 }
2387
2388 changeSelectedStatus();
2389
2390 resetCollisionAccounting();
2391 m_taintPhysics = m_isphysical;
2392 }
2393
2394 public void changesize(float timestamp)
2395 {
2396
2397 string oldname = _parent_scene.geom_name_map[prim_geom];
2398
2399 if (_size.X <= 0) _size.X = 0.01f;
2400 if (_size.Y <= 0) _size.Y = 0.01f;
2401 if (_size.Z <= 0) _size.Z = 0.01f;
2402
2403 // Cleanup of old prim geometry
2404 if (_mesh != null)
2405 {
2406 // Cleanup meshing here
2407 }
2408 //kill body to rebuild
2409 if (IsPhysical && Body != IntPtr.Zero)
2410 {
2411 if (childPrim)
2412 {
2413 if (_parent != null)
2414 {
2415 OdePrim parent = (OdePrim)_parent;
2416 parent.ChildDelink(this);
2417 }
2418 }
2419 else
2420 {
2421 disableBody();
2422 }
2423 }
2424 if (d.SpaceQuery(m_targetSpace, prim_geom))
2425 {
2426 _parent_scene.waitForSpaceUnlock(m_targetSpace);
2427 d.SpaceRemove(m_targetSpace, prim_geom);
2428 }
2429 // we don't need to do space calculation because the client sends a position update also.
2430
2431 // Construction of new prim
2432 if (_parent_scene.needsMeshing(_pbs))// && m_meshfailed == false)
2433 {
2434 float meshlod = _parent_scene.meshSculptLOD;
2435
2436 if (IsPhysical)
2437 meshlod = _parent_scene.MeshSculptphysicalLOD;
2438 // Don't need to re-enable body.. it's done in SetMesh
2439
2440 IMesh mesh = null;
2441
2442 try
2443 {
2444 if (_parent_scene.needsMeshing(_pbs))
2445 mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, (int)LevelOfDetail.High, true);
2446 }
2447 catch
2448 {
2449 m_meshfailed = true;
2450 mesh = null;
2451 m_log.WarnFormat("[PHYSICS]: changeSize CreateMesh fail on prim {0} at <{1},{2},{3}>", Name, _position.X, _position.Y, _position.Z);
2452 }
2453
2454 //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
2455 CreateGeom(m_targetSpace, mesh);
2456 }
2457 else
2458 {
2459 _mesh = null;
2460 CreateGeom(m_targetSpace, _mesh);
2461 }
2462
2463 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2464 d.Quaternion myrot = new d.Quaternion();
2465 myrot.X = _orientation.X;
2466 myrot.Y = _orientation.Y;
2467 myrot.Z = _orientation.Z;
2468 myrot.W = _orientation.W;
2469 d.GeomSetQuaternion(prim_geom, ref myrot);
2470
2471 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
2472 if (IsPhysical && Body == IntPtr.Zero && !childPrim)
2473 {
2474 // Re creates body on size.
2475 // EnableBody also does setMass()
2476 enableBody();
2477 d.BodyEnable(Body);
2478 }
2479
2480 _parent_scene.geom_name_map[prim_geom] = oldname;
2481
2482 changeSelectedStatus();
2483 if (childPrim)
2484 {
2485 if (_parent is OdePrim)
2486 {
2487 OdePrim parent = (OdePrim)_parent;
2488 parent.ChildSetGeom(this);
2489 }
2490 }
2491 resetCollisionAccounting();
2492 m_taintsize = _size;
2493 }
2494
2495
2496
2497 public void changefloatonwater(float timestep)
2498 {
2499 m_collidesWater = m_taintCollidesWater;
2500
2501 if (prim_geom != IntPtr.Zero)
2502 {
2503 if (m_collidesWater)
2504 {
2505 m_collisionFlags |= CollisionCategories.Water;
2506 }
2507 else
2508 {
2509 m_collisionFlags &= ~CollisionCategories.Water;
2510 }
2511 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2512 }
2513 }
2514
2515 public void changeshape(float timestamp)
2516 {
2517 string oldname = _parent_scene.geom_name_map[prim_geom];
2518
2519 // Cleanup of old prim geometry and Bodies
2520 if (IsPhysical && Body != IntPtr.Zero)
2521 {
2522 if (childPrim)
2523 {
2524 if (_parent != null)
2525 {
2526 OdePrim parent = (OdePrim)_parent;
2527 parent.ChildDelink(this);
2528 }
2529 }
2530 else
2531 {
2532 disableBody();
2533 }
2534 }
2535
2536
2537 // we don't need to do space calculation because the client sends a position update also.
2538 if (_size.X <= 0) _size.X = 0.01f;
2539 if (_size.Y <= 0) _size.Y = 0.01f;
2540 if (_size.Z <= 0) _size.Z = 0.01f;
2541 // Construction of new prim
2542
2543 if (_parent_scene.needsMeshing(_pbs))// && m_meshfailed == false)
2544 {
2545 // Don't need to re-enable body.. it's done in SetMesh
2546 float meshlod = _parent_scene.meshSculptLOD;
2547 IMesh mesh;
2548
2549 if (IsPhysical)
2550 meshlod = _parent_scene.MeshSculptphysicalLOD;
2551
2552 bool convex;
2553 if (m_shapetype == 2)
2554 convex = true;
2555 else
2556 convex = false;
2557
2558 try
2559 {
2560 mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, (int)LevelOfDetail.High, true, false,convex,false);
2561 }
2562 catch
2563 {
2564 mesh = null;
2565 m_meshfailed = true;
2566 m_log.WarnFormat("[PHYSICS]: changeAdd CreateMesh fail on prim {0} at <{1},{2},{3}>", Name, _position.X, _position.Y, _position.Z);
2567 }
2568
2569 CreateGeom(m_targetSpace, mesh);
2570
2571 // createmesh returns null when it doesn't mesh.
2572 }
2573 else
2574 {
2575 _mesh = null;
2576 CreateGeom(m_targetSpace, null);
2577 }
2578
2579 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2580 d.Quaternion myrot = new d.Quaternion();
2581 //myrot.W = _orientation.w;
2582 myrot.W = _orientation.W;
2583 myrot.X = _orientation.X;
2584 myrot.Y = _orientation.Y;
2585 myrot.Z = _orientation.Z;
2586 d.GeomSetQuaternion(prim_geom, ref myrot);
2587
2588 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
2589 if (IsPhysical && Body == IntPtr.Zero)
2590 {
2591 // Re creates body on size.
2592 // EnableBody also does setMass()
2593 enableBody();
2594 if (Body != IntPtr.Zero)
2595 {
2596 d.BodyEnable(Body);
2597 }
2598 }
2599 _parent_scene.geom_name_map[prim_geom] = oldname;
2600
2601 changeSelectedStatus();
2602 if (childPrim)
2603 {
2604 if (_parent is OdePrim)
2605 {
2606 OdePrim parent = (OdePrim)_parent;
2607 parent.ChildSetGeom(this);
2608 }
2609 }
2610 resetCollisionAccounting();
2611 m_taintshape = false;
2612 }
2613
2614 public void changeAddForce(float timestamp)
2615 {
2616 if (!m_isSelected)
2617 {
2618 lock (m_forcelist)
2619 {
2620 //m_log.Info("[PHYSICS]: dequeing forcelist");
2621 if (IsPhysical)
2622 {
2623 Vector3 iforce = Vector3.Zero;
2624 int i = 0;
2625 try
2626 {
2627 for (i = 0; i < m_forcelist.Count; i++)
2628 {
2629
2630 iforce = iforce + (m_forcelist[i] * 100);
2631 }
2632 }
2633 catch (IndexOutOfRangeException)
2634 {
2635 m_forcelist = new List<Vector3>();
2636 m_collisionscore = 0;
2637 m_interpenetrationcount = 0;
2638 m_taintforce = false;
2639 return;
2640 }
2641 catch (ArgumentOutOfRangeException)
2642 {
2643 m_forcelist = new List<Vector3>();
2644 m_collisionscore = 0;
2645 m_interpenetrationcount = 0;
2646 m_taintforce = false;
2647 return;
2648 }
2649 d.BodyEnable(Body);
2650
2651 d.BodyAddForce(Body, iforce.X, iforce.Y, iforce.Z);
2652 }
2653 m_forcelist.Clear();
2654 }
2655
2656 m_collisionscore = 0;
2657 m_interpenetrationcount = 0;
2658 }
2659
2660 m_taintforce = false;
2661
2662 }
2663
2664
2665
2666 public void changeSetTorque(float timestamp)
2667 {
2668 if (!m_isSelected)
2669 {
2670 if (IsPhysical && Body != IntPtr.Zero)
2671 {
2672 d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
2673 }
2674 }
2675
2676 m_taintTorque = Vector3.Zero;
2677 }
2678
2679 public void changeAddAngularForce(float timestamp)
2680 {
2681 if (!m_isSelected)
2682 {
2683 lock (m_angularforcelist)
2684 {
2685 //m_log.Info("[PHYSICS]: dequeing forcelist");
2686 if (IsPhysical)
2687 {
2688 Vector3 iforce = Vector3.Zero;
2689 for (int i = 0; i < m_angularforcelist.Count; i++)
2690 {
2691 iforce = iforce + (m_angularforcelist[i] * 100);
2692 }
2693 d.BodyEnable(Body);
2694 d.BodyAddTorque(Body, iforce.X, iforce.Y, iforce.Z);
2695
2696 }
2697 m_angularforcelist.Clear();
2698 }
2699
2700 m_collisionscore = 0;
2701 m_interpenetrationcount = 0;
2702 }
2703
2704 m_taintaddangularforce = false;
2705 }
2706
2707 private void changevelocity(float timestep)
2708 {
2709 if (!m_isSelected)
2710 {
2711 Thread.Sleep(20);
2712 if (IsPhysical)
2713 {
2714 if (Body != IntPtr.Zero)
2715 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
2716 }
2717
2718 //resetCollisionAccounting();
2719 }
2720 m_taintVelocity = Vector3.Zero;
2721 }
2722
2723 public void UpdatePositionAndVelocity()
2724 {
2725 return; // moved to the Move () method
2726 }
2727
2728 public d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj)
2729 {
2730 obj.I.M00 = pMat[0, 0];
2731 obj.I.M01 = pMat[0, 1];
2732 obj.I.M02 = pMat[0, 2];
2733 obj.I.M10 = pMat[1, 0];
2734 obj.I.M11 = pMat[1, 1];
2735 obj.I.M12 = pMat[1, 2];
2736 obj.I.M20 = pMat[2, 0];
2737 obj.I.M21 = pMat[2, 1];
2738 obj.I.M22 = pMat[2, 2];
2739 return obj;
2740 }
2741
2742 public override void SubscribeEvents(int ms)
2743 {
2744 m_eventsubscription = ms;
2745 _parent_scene.addCollisionEventReporting(this);
2746 }
2747
2748 public override void UnSubscribeEvents()
2749 {
2750 _parent_scene.remCollisionEventReporting(this);
2751 m_eventsubscription = 0;
2752 }
2753
2754 public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
2755 {
2756 if (CollisionEventsThisFrame == null)
2757 CollisionEventsThisFrame = new CollisionEventUpdate();
2758 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
2759 }
2760
2761 public void SendCollisions()
2762 {
2763 if (CollisionEventsThisFrame == null)
2764 return;
2765
2766 base.SendCollisionUpdate(CollisionEventsThisFrame);
2767
2768 if (CollisionEventsThisFrame.m_objCollisionList.Count == 0)
2769 CollisionEventsThisFrame = null;
2770 else
2771 CollisionEventsThisFrame = new CollisionEventUpdate();
2772 }
2773
2774 public override bool SubscribedEvents()
2775 {
2776 if (m_eventsubscription > 0)
2777 return true;
2778 return false;
2779 }
2780
2781 public static Matrix4 Inverse(Matrix4 pMat)
2782 {
2783 if (determinant3x3(pMat) == 0)
2784 {
2785 return Matrix4.Identity; // should probably throw an error. singluar matrix inverse not possible
2786 }
2787
2788
2789
2790 return (Adjoint(pMat) / determinant3x3(pMat));
2791 }
2792
2793 public static Matrix4 Adjoint(Matrix4 pMat)
2794 {
2795 Matrix4 adjointMatrix = new Matrix4();
2796 for (int i = 0; i < 4; i++)
2797 {
2798 for (int j = 0; j < 4; j++)
2799 {
2800 Matrix4SetValue(ref adjointMatrix, i, j, (float)(Math.Pow(-1, i + j) * (determinant3x3(Minor(pMat, i, j)))));
2801 }
2802 }
2803
2804 adjointMatrix = Transpose(adjointMatrix);
2805 return adjointMatrix;
2806 }
2807
2808 public static Matrix4 Minor(Matrix4 matrix, int iRow, int iCol)
2809 {
2810 Matrix4 minor = new Matrix4();
2811 int m = 0, n = 0;
2812 for (int i = 0; i < 4; i++)
2813 {
2814 if (i == iRow)
2815 continue;
2816 n = 0;
2817 for (int j = 0; j < 4; j++)
2818 {
2819 if (j == iCol)
2820 continue;
2821 Matrix4SetValue(ref minor, m, n, matrix[i, j]);
2822 n++;
2823 }
2824 m++;
2825 }
2826 return minor;
2827 }
2828
2829 public static Matrix4 Transpose(Matrix4 pMat)
2830 {
2831 Matrix4 transposeMatrix = new Matrix4();
2832 for (int i = 0; i < 4; i++)
2833 for (int j = 0; j < 4; j++)
2834 Matrix4SetValue(ref transposeMatrix, i, j, pMat[j, i]);
2835 return transposeMatrix;
2836 }
2837
2838 public static void Matrix4SetValue(ref Matrix4 pMat, int r, int c, float val)
2839 {
2840 switch (r)
2841 {
2842 case 0:
2843 switch (c)
2844 {
2845 case 0:
2846 pMat.M11 = val;
2847 break;
2848 case 1:
2849 pMat.M12 = val;
2850 break;
2851 case 2:
2852 pMat.M13 = val;
2853 break;
2854 case 3:
2855 pMat.M14 = val;
2856 break;
2857 }
2858
2859 break;
2860 case 1:
2861 switch (c)
2862 {
2863 case 0:
2864 pMat.M21 = val;
2865 break;
2866 case 1:
2867 pMat.M22 = val;
2868 break;
2869 case 2:
2870 pMat.M23 = val;
2871 break;
2872 case 3:
2873 pMat.M24 = val;
2874 break;
2875 }
2876
2877 break;
2878 case 2:
2879 switch (c)
2880 {
2881 case 0:
2882 pMat.M31 = val;
2883 break;
2884 case 1:
2885 pMat.M32 = val;
2886 break;
2887 case 2:
2888 pMat.M33 = val;
2889 break;
2890 case 3:
2891 pMat.M34 = val;
2892 break;
2893 }
2894
2895 break;
2896 case 3:
2897 switch (c)
2898 {
2899 case 0:
2900 pMat.M41 = val;
2901 break;
2902 case 1:
2903 pMat.M42 = val;
2904 break;
2905 case 2:
2906 pMat.M43 = val;
2907 break;
2908 case 3:
2909 pMat.M44 = val;
2910 break;
2911 }
2912
2913 break;
2914 }
2915 }
2916 private static float determinant3x3(Matrix4 pMat)
2917 {
2918 float det = 0;
2919 float diag1 = pMat[0, 0] * pMat[1, 1] * pMat[2, 2];
2920 float diag2 = pMat[0, 1] * pMat[2, 1] * pMat[2, 0];
2921 float diag3 = pMat[0, 2] * pMat[1, 0] * pMat[2, 1];
2922 float diag4 = pMat[2, 0] * pMat[1, 1] * pMat[0, 2];
2923 float diag5 = pMat[2, 1] * pMat[1, 2] * pMat[0, 0];
2924 float diag6 = pMat[2, 2] * pMat[1, 0] * pMat[0, 1];
2925
2926 det = diag1 + diag2 + diag3 - (diag4 + diag5 + diag6);
2927 return det;
2928
2929 }
2930
2931 private static void DMassCopy(ref d.Mass src, ref d.Mass dst)
2932 {
2933 dst.c.W = src.c.W;
2934 dst.c.X = src.c.X;
2935 dst.c.Y = src.c.Y;
2936 dst.c.Z = src.c.Z;
2937 dst.mass = src.mass;
2938 dst.I.M00 = src.I.M00;
2939 dst.I.M01 = src.I.M01;
2940 dst.I.M02 = src.I.M02;
2941 dst.I.M10 = src.I.M10;
2942 dst.I.M11 = src.I.M11;
2943 dst.I.M12 = src.I.M12;
2944 dst.I.M20 = src.I.M20;
2945 dst.I.M21 = src.I.M21;
2946 dst.I.M22 = src.I.M22;
2947 }
2948
2949 public override void SetMaterial(int pMaterial)
2950 {
2951 m_material = pMaterial;
2952 }
2953
2954 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
2955 {
2956 switch (pParam)
2957 {
2958 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
2959 if (pValue < 0.01f) pValue = 0.01f;
2960 // m_angularDeflectionEfficiency = pValue;
2961 break;
2962 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
2963 if (pValue < 0.1f) pValue = 0.1f;
2964 // m_angularDeflectionTimescale = pValue;
2965 break;
2966 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
2967 if (pValue < 0.3f) pValue = 0.3f;
2968 m_angularMotorDecayTimescale = pValue;
2969 break;
2970 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
2971 if (pValue < 0.3f) pValue = 0.3f;
2972 m_angularMotorTimescale = pValue;
2973 break;
2974 case Vehicle.BANKING_EFFICIENCY:
2975 if (pValue < 0.01f) pValue = 0.01f;
2976 // m_bankingEfficiency = pValue;
2977 break;
2978 case Vehicle.BANKING_MIX:
2979 if (pValue < 0.01f) pValue = 0.01f;
2980 // m_bankingMix = pValue;
2981 break;
2982 case Vehicle.BANKING_TIMESCALE:
2983 if (pValue < 0.01f) pValue = 0.01f;
2984 // m_bankingTimescale = pValue;
2985 break;
2986 case Vehicle.BUOYANCY:
2987 if (pValue < -1f) pValue = -1f;
2988 if (pValue > 1f) pValue = 1f;
2989 m_VehicleBuoyancy = pValue;
2990 break;
2991 // case Vehicle.HOVER_EFFICIENCY:
2992 // if (pValue < 0f) pValue = 0f;
2993 // if (pValue > 1f) pValue = 1f;
2994 // m_VhoverEfficiency = pValue;
2995 // break;
2996 case Vehicle.HOVER_HEIGHT:
2997 m_VhoverHeight = pValue;
2998 break;
2999 case Vehicle.HOVER_TIMESCALE:
3000 if (pValue < 0.1f) pValue = 0.1f;
3001 m_VhoverTimescale = pValue;
3002 break;
3003 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
3004 if (pValue < 0.01f) pValue = 0.01f;
3005 // m_linearDeflectionEfficiency = pValue;
3006 break;
3007 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
3008 if (pValue < 0.01f) pValue = 0.01f;
3009 // m_linearDeflectionTimescale = pValue;
3010 break;
3011 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
3012 if (pValue < 0.3f) pValue = 0.3f;
3013 m_linearMotorDecayTimescale = pValue;
3014 break;
3015 case Vehicle.LINEAR_MOTOR_TIMESCALE:
3016 if (pValue < 0.1f) pValue = 0.1f;
3017 m_linearMotorTimescale = pValue;
3018 break;
3019 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
3020 if (pValue < 0.1f) pValue = 0.1f; // Less goes unstable
3021 if (pValue > 1.0f) pValue = 1.0f;
3022 m_verticalAttractionEfficiency = pValue;
3023 break;
3024 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
3025 if (pValue < 0.1f) pValue = 0.1f;
3026 m_verticalAttractionTimescale = pValue;
3027 break;
3028
3029 // These are vector properties but the engine lets you use a single float value to
3030 // set all of the components to the same value
3031 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
3032 if (pValue > 30f) pValue = 30f;
3033 if (pValue < 0.1f) pValue = 0.1f;
3034 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
3035 break;
3036 case Vehicle.ANGULAR_MOTOR_DIRECTION:
3037 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
3038 UpdateAngDecay();
3039 break;
3040 case Vehicle.LINEAR_FRICTION_TIMESCALE:
3041 if (pValue < 0.1f) pValue = 0.1f;
3042 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
3043 break;
3044 case Vehicle.LINEAR_MOTOR_DIRECTION:
3045 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
3046 UpdateLinDecay();
3047 break;
3048 case Vehicle.LINEAR_MOTOR_OFFSET:
3049 // m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
3050 break;
3051
3052 }
3053
3054 }//end ProcessFloatVehicleParam
3055
3056 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
3057 {
3058 switch (pParam)
3059 {
3060 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
3061 if (pValue.X > 30f) pValue.X = 30f;
3062 if (pValue.X < 0.1f) pValue.X = 0.1f;
3063 if (pValue.Y > 30f) pValue.Y = 30f;
3064 if (pValue.Y < 0.1f) pValue.Y = 0.1f;
3065 if (pValue.Z > 30f) pValue.Z = 30f;
3066 if (pValue.Z < 0.1f) pValue.Z = 0.1f;
3067 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
3068 break;
3069 case Vehicle.ANGULAR_MOTOR_DIRECTION:
3070 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
3071 // Limit requested angular speed to 2 rps= 4 pi rads/sec
3072 if (m_angularMotorDirection.X > 12.56f) m_angularMotorDirection.X = 12.56f;
3073 if (m_angularMotorDirection.X < -12.56f) m_angularMotorDirection.X = -12.56f;
3074 if (m_angularMotorDirection.Y > 12.56f) m_angularMotorDirection.Y = 12.56f;
3075 if (m_angularMotorDirection.Y < -12.56f) m_angularMotorDirection.Y = -12.56f;
3076 if (m_angularMotorDirection.Z > 12.56f) m_angularMotorDirection.Z = 12.56f;
3077 if (m_angularMotorDirection.Z < -12.56f) m_angularMotorDirection.Z = -12.56f;
3078 UpdateAngDecay();
3079 break;
3080 case Vehicle.LINEAR_FRICTION_TIMESCALE:
3081 if (pValue.X < 0.1f) pValue.X = 0.1f;
3082 if (pValue.Y < 0.1f) pValue.Y = 0.1f;
3083 if (pValue.Z < 0.1f) pValue.Z = 0.1f;
3084 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
3085 break;
3086 case Vehicle.LINEAR_MOTOR_DIRECTION:
3087 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); // velocity requested by LSL, for max limiting
3088 UpdateLinDecay();
3089 break;
3090 case Vehicle.LINEAR_MOTOR_OFFSET:
3091 // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
3092 break;
3093 }
3094
3095 }//end ProcessVectorVehicleParam
3096
3097 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
3098 {
3099 switch (pParam)
3100 {
3101 case Vehicle.REFERENCE_FRAME:
3102 // m_referenceFrame = pValue;
3103 break;
3104 }
3105
3106 }//end ProcessRotationVehicleParam
3107
3108 internal void ProcessVehicleFlags(int pParam, bool remove)
3109 {
3110 if (remove)
3111 {
3112 m_flags &= ~((VehicleFlag)pParam);
3113 }
3114 else
3115 {
3116 m_flags |= (VehicleFlag)pParam;
3117 }
3118 }
3119
3120 internal void ProcessTypeChange(Vehicle pType)
3121 {
3122 // Set Defaults For Type
3123 m_type = pType;
3124 switch (pType)
3125 {
3126 case Vehicle.TYPE_SLED:
3127 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
3128 m_angularFrictionTimescale = new Vector3(30, 30, 30);
3129 // m_lLinMotorVel = Vector3.Zero;
3130 m_linearMotorTimescale = 1000;
3131 m_linearMotorDecayTimescale = 120;
3132 m_angularMotorDirection = Vector3.Zero;
3133 m_angularMotorDVel = Vector3.Zero;
3134 m_angularMotorTimescale = 1000;
3135 m_angularMotorDecayTimescale = 120;
3136 m_VhoverHeight = 0;
3137 // m_VhoverEfficiency = 1;
3138 m_VhoverTimescale = 10;
3139 m_VehicleBuoyancy = 0;
3140 // m_linearDeflectionEfficiency = 1;
3141 // m_linearDeflectionTimescale = 1;
3142 // m_angularDeflectionEfficiency = 1;
3143 // m_angularDeflectionTimescale = 1000;
3144 // m_bankingEfficiency = 0;
3145 // m_bankingMix = 1;
3146 // m_bankingTimescale = 10;
3147 // m_referenceFrame = Quaternion.Identity;
3148 m_flags &=
3149 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
3150 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
3151 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
3152 break;
3153 case Vehicle.TYPE_CAR:
3154 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
3155 m_angularFrictionTimescale = new Vector3(30, 30, 30); // was 1000, but sl max frict time is 30.
3156 // m_lLinMotorVel = Vector3.Zero;
3157 m_linearMotorTimescale = 1;
3158 m_linearMotorDecayTimescale = 60;
3159 m_angularMotorDirection = Vector3.Zero;
3160 m_angularMotorDVel = Vector3.Zero;
3161 m_angularMotorTimescale = 1;
3162 m_angularMotorDecayTimescale = 0.8f;
3163 m_VhoverHeight = 0;
3164 // m_VhoverEfficiency = 0;
3165 m_VhoverTimescale = 1000;
3166 m_VehicleBuoyancy = 0;
3167 // // m_linearDeflectionEfficiency = 1;
3168 // // m_linearDeflectionTimescale = 2;
3169 // // m_angularDeflectionEfficiency = 0;
3170 // m_angularDeflectionTimescale = 10;
3171 m_verticalAttractionEfficiency = 1f;
3172 m_verticalAttractionTimescale = 10f;
3173 // m_bankingEfficiency = -0.2f;
3174 // m_bankingMix = 1;
3175 // m_bankingTimescale = 1;
3176 // m_referenceFrame = Quaternion.Identity;
3177 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
3178 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_UP_ONLY |
3179 VehicleFlag.LIMIT_MOTOR_UP);
3180 break;
3181 case Vehicle.TYPE_BOAT:
3182 m_linearFrictionTimescale = new Vector3(10, 3, 2);
3183 m_angularFrictionTimescale = new Vector3(10, 10, 10);
3184 // m_lLinMotorVel = Vector3.Zero;
3185 m_linearMotorTimescale = 5;
3186 m_linearMotorDecayTimescale = 60;
3187 m_angularMotorDirection = Vector3.Zero;
3188 m_angularMotorDVel = Vector3.Zero;
3189 m_angularMotorTimescale = 4;
3190 m_angularMotorDecayTimescale = 4;
3191 m_VhoverHeight = 0;
3192 // m_VhoverEfficiency = 0.5f;
3193 m_VhoverTimescale = 2;
3194 m_VehicleBuoyancy = 1;
3195 // m_linearDeflectionEfficiency = 0.5f;
3196 // m_linearDeflectionTimescale = 3;
3197 // m_angularDeflectionEfficiency = 0.5f;
3198 // m_angularDeflectionTimescale = 5;
3199 m_verticalAttractionEfficiency = 0.5f;
3200 m_verticalAttractionTimescale = 5f;
3201 // m_bankingEfficiency = -0.3f;
3202 // m_bankingMix = 0.8f;
3203 // m_bankingTimescale = 1;
3204 // m_referenceFrame = Quaternion.Identity;
3205 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.LIMIT_ROLL_ONLY |
3206 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
3207 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY |
3208 VehicleFlag.LIMIT_MOTOR_UP);
3209 break;
3210 case Vehicle.TYPE_AIRPLANE:
3211 m_linearFrictionTimescale = new Vector3(200, 10, 5);
3212 m_angularFrictionTimescale = new Vector3(20, 20, 20);
3213 // m_lLinMotorVel = Vector3.Zero;
3214 m_linearMotorTimescale = 2;
3215 m_linearMotorDecayTimescale = 60;
3216 m_angularMotorDirection = Vector3.Zero;
3217 m_angularMotorDVel = Vector3.Zero;
3218 m_angularMotorTimescale = 4;
3219 m_angularMotorDecayTimescale = 4;
3220 m_VhoverHeight = 0;
3221 // m_VhoverEfficiency = 0.5f;
3222 m_VhoverTimescale = 1000;
3223 m_VehicleBuoyancy = 0;
3224 // m_linearDeflectionEfficiency = 0.5f;
3225 // m_linearDeflectionTimescale = 3;
3226 // m_angularDeflectionEfficiency = 1;
3227 // m_angularDeflectionTimescale = 2;
3228 m_verticalAttractionEfficiency = 0.9f;
3229 m_verticalAttractionTimescale = 2f;
3230 // m_bankingEfficiency = 1;
3231 // m_bankingMix = 0.7f;
3232 // m_bankingTimescale = 2;
3233 // m_referenceFrame = Quaternion.Identity;
3234 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
3235 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
3236 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
3237 break;
3238 case Vehicle.TYPE_BALLOON:
3239 m_linearFrictionTimescale = new Vector3(5, 5, 5);
3240 m_angularFrictionTimescale = new Vector3(10, 10, 10);
3241 m_linearMotorTimescale = 5;
3242 m_linearMotorDecayTimescale = 60;
3243 m_angularMotorDirection = Vector3.Zero;
3244 m_angularMotorDVel = Vector3.Zero;
3245 m_angularMotorTimescale = 6;
3246 m_angularMotorDecayTimescale = 10;
3247 m_VhoverHeight = 5;
3248 // m_VhoverEfficiency = 0.8f;
3249 m_VhoverTimescale = 10;
3250 m_VehicleBuoyancy = 1;
3251 // m_linearDeflectionEfficiency = 0;
3252 // m_linearDeflectionTimescale = 5;
3253 // m_angularDeflectionEfficiency = 0;
3254 // m_angularDeflectionTimescale = 5;
3255 m_verticalAttractionEfficiency = 1f;
3256 m_verticalAttractionTimescale = 100f;
3257 // m_bankingEfficiency = 0;
3258 // m_bankingMix = 0.7f;
3259 // m_bankingTimescale = 5;
3260 // m_referenceFrame = Quaternion.Identity;
3261 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
3262 VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
3263 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
3264 break;
3265
3266 }
3267 }//end SetDefaultsForType
3268
3269 internal void Enable(IntPtr pBody, OdeScene pParentScene)
3270 {
3271 if (m_type == Vehicle.TYPE_NONE)
3272 return;
3273
3274 m_body = pBody;
3275 }
3276
3277
3278 internal void Halt()
3279 { // Kill all motions, when non-physical
3280 // m_linearMotorDirection = Vector3.Zero;
3281 m_lLinMotorDVel = Vector3.Zero;
3282 m_lLinObjectVel = Vector3.Zero;
3283 m_wLinObjectVel = Vector3.Zero;
3284 m_angularMotorDirection = Vector3.Zero;
3285 m_lastAngularVelocity = Vector3.Zero;
3286 m_angularMotorDVel = Vector3.Zero;
3287 _acceleration = Vector3.Zero;
3288 }
3289
3290 private void UpdateLinDecay()
3291 {
3292 m_lLinMotorDVel.X = m_linearMotorDirection.X;
3293 m_lLinMotorDVel.Y = m_linearMotorDirection.Y;
3294 m_lLinMotorDVel.Z = m_linearMotorDirection.Z;
3295 } // else let the motor decay on its own
3296
3297 private void UpdateAngDecay()
3298 {
3299 m_angularMotorDVel.X = m_angularMotorDirection.X;
3300 m_angularMotorDVel.Y = m_angularMotorDirection.Y;
3301 m_angularMotorDVel.Z = m_angularMotorDirection.Z;
3302 } // else let the motor decay on its own
3303
3304 public void Move(float timestep)
3305 {
3306 float fx = 0;
3307 float fy = 0;
3308 float fz = 0;
3309 Vector3 linvel; // velocity applied, including any reversal
3310
3311 // If geomCrossingFailuresBeforeOutofbounds is set to 0 in OpenSim.ini then phys objects bounce off region borders.
3312 // This is a temp patch until proper region crossing is developed.
3313
3314
3315 if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim && !m_outofBounds) // Only move root prims.
3316 {
3317 // Old public void UpdatePositionAndVelocity(), more accuratley calculated here
3318 bool lastZeroFlag = _zeroFlag; // was it stopped
3319
3320 d.Vector3 vec = d.BodyGetPosition(Body);
3321 Vector3 l_position = Vector3.Zero;
3322 l_position.X = vec.X;
3323 l_position.Y = vec.Y;
3324 l_position.Z = vec.Z;
3325 m_lastposition = _position;
3326 _position = l_position;
3327
3328 d.Quaternion ori = d.BodyGetQuaternion(Body);
3329 // Quaternion l_orientation = Quaternion.Identity;
3330 _orientation.X = ori.X;
3331 _orientation.Y = ori.Y;
3332 _orientation.Z = ori.Z;
3333 _orientation.W = ori.W;
3334 m_lastorientation = _orientation;
3335
3336 d.Vector3 vel = d.BodyGetLinearVel(Body);
3337 m_lastVelocity = _velocity;
3338 _velocity.X = vel.X;
3339 _velocity.Y = vel.Y;
3340 _velocity.Z = vel.Z;
3341 _acceleration = ((_velocity - m_lastVelocity) / timestep);
3342
3343 d.Vector3 torque = d.BodyGetTorque(Body);
3344 _torque = new Vector3(torque.X, torque.Y, torque.Z);
3345
3346
3347 if (_position.X < 0f || _position.X > _parent_scene.WorldExtents.X
3348 || _position.Y < 0f || _position.Y > _parent_scene.WorldExtents.Y
3349 )
3350 {
3351 // we are outside current region
3352 // clip position to a stop just outside region and stop it only internally
3353 // do it only once using m_crossingfailures as control
3354 _position.X = Util.Clip(l_position.X, -0.2f, _parent_scene.WorldExtents.X + .2f);
3355 _position.Y = Util.Clip(l_position.Y, -0.2f, _parent_scene.WorldExtents.Y + .2f);
3356 _position.Z = Util.Clip(l_position.Z, -100f, 50000f);
3357 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
3358 d.BodySetLinearVel(Body, 0, 0, 0);
3359 m_outofBounds = true;
3360 base.RequestPhysicsterseUpdate();
3361 return;
3362 }
3363
3364 base.RequestPhysicsterseUpdate();
3365
3366 if (l_position.Z < 0)
3367 {
3368 // This is so prim that get lost underground don't fall forever and suck up
3369 //
3370 // Sim resources and memory.
3371 // Disables the prim's movement physics....
3372 // It's a hack and will generate a console message if it fails.
3373
3374 //IsPhysical = false;
3375 if (_parent == null) base.RaiseOutOfBounds(_position);
3376
3377
3378 _acceleration.X = 0; // This stuff may stop client display but it has no
3379 _acceleration.Y = 0; // effect on the object in phys engine!
3380 _acceleration.Z = 0;
3381
3382 _velocity.X = 0;
3383 _velocity.Y = 0;
3384 _velocity.Z = 0;
3385 m_lastVelocity = Vector3.Zero;
3386 m_rotationalVelocity.X = 0;
3387 m_rotationalVelocity.Y = 0;
3388 m_rotationalVelocity.Z = 0;
3389
3390 if (_parent == null) base.RequestPhysicsterseUpdate();
3391
3392 m_throttleUpdates = false;
3393 throttleCounter = 0;
3394 _zeroFlag = true;
3395 //outofBounds = true;
3396 } // end neg Z check
3397
3398 // Is it moving?
3399 /* if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)
3400 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02)
3401 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) */
3402 if ((Vector3.Mag(_velocity) < 0.01) && // moving very slowly
3403 (Vector3.Mag(_velocity) < Vector3.Mag(m_lastVelocity)) && // decelerating
3404 (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, _orientation)) < 0.0001)) // spinning very slowly
3405 {
3406 _zeroFlag = true;
3407 m_throttleUpdates = false;
3408 }
3409 else
3410 {
3411 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
3412 _zeroFlag = false;
3413 m_lastUpdateSent = false;
3414 //m_throttleUpdates = false;
3415 }
3416
3417 if (_zeroFlag)
3418 { // Its stopped
3419 _velocity.X = 0.0f;
3420 _velocity.Y = 0.0f;
3421 // _velocity.Z = 0.0f;
3422
3423 _acceleration.X = 0;
3424 _acceleration.Y = 0;
3425 // _acceleration.Z = 0;
3426
3427 m_rotationalVelocity.X = 0;
3428 m_rotationalVelocity.Y = 0;
3429 m_rotationalVelocity.Z = 0;
3430 // Stop it in the phys engine
3431 d.BodySetLinearVel(Body, 0.0f, 0.0f, _velocity.Z);
3432 d.BodySetAngularVel(Body, 0.0f, 0.0f, 0.0f);
3433 d.BodySetForce(Body, 0f, 0f, 0f);
3434
3435 if (!m_lastUpdateSent)
3436 {
3437 m_throttleUpdates = false;
3438 throttleCounter = 0;
3439 if (_parent == null)
3440 {
3441 base.RequestPhysicsterseUpdate();
3442 }
3443
3444 m_lastUpdateSent = true;
3445 }
3446 }
3447 else
3448 { // Its moving
3449 if (lastZeroFlag != _zeroFlag)
3450 {
3451 if (_parent == null)
3452 {
3453 base.RequestPhysicsterseUpdate();
3454 }
3455 }
3456 m_lastUpdateSent = false;
3457 if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
3458 {
3459 if (_parent == null)
3460 {
3461 base.RequestPhysicsterseUpdate();
3462 }
3463 }
3464 else
3465 {
3466 throttleCounter++;
3467 }
3468 }
3469 m_lastposition = l_position;
3470
3471 /// End UpdatePositionAndVelocity insert
3472
3473
3474 // Rotation lock =====================================
3475 if (m_rotateEnableUpdate)
3476 {
3477 // Snapshot current angles, set up Amotor(s)
3478 m_rotateEnableUpdate = false;
3479 m_rotateEnable = m_rotateEnableRequest;
3480 //Console.WriteLine("RotEnable {0} = {1}",m_primName, m_rotateEnable);
3481
3482 if (Amotor != IntPtr.Zero)
3483 {
3484 d.JointDestroy(Amotor);
3485 Amotor = IntPtr.Zero;
3486 //Console.WriteLine("Old Amotor Destroyed");
3487 }
3488
3489 if (!m_rotateEnable.ApproxEquals(Vector3.One, 0.003f))
3490 { // not all are enabled
3491 d.Quaternion r = d.BodyGetQuaternion(Body);
3492 Quaternion locrot = new Quaternion(r.X, r.Y, r.Z, r.W);
3493 // extract the axes vectors
3494 Vector3 vX = new Vector3(1f, 0f, 0f);
3495 Vector3 vY = new Vector3(0f, 1f, 0f);
3496 Vector3 vZ = new Vector3(0f, 0f, 1f);
3497 vX = vX * locrot;
3498 vY = vY * locrot;
3499 vZ = vZ * locrot;
3500 // snapshot the current angle vectors
3501 m_lockX = vX;
3502 m_lockY = vY;
3503 m_lockZ = vZ;
3504 // m_lockRot = locrot;
3505 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
3506 d.JointAttach(Amotor, Body, IntPtr.Zero);
3507 d.JointSetAMotorMode(Amotor, 0); // User mode??
3508 //Console.WriteLine("New Amotor Created for {0}", m_primName);
3509
3510 float axisnum = 3; // how many to lock
3511 axisnum = (axisnum - (m_rotateEnable.X + m_rotateEnable.Y + m_rotateEnable.Z));
3512 d.JointSetAMotorNumAxes(Amotor, (int)axisnum);
3513 //Console.WriteLine("AxisNum={0}",(int)axisnum);
3514
3515 int i = 0;
3516
3517 if (m_rotateEnable.X == 0)
3518 {
3519 d.JointSetAMotorAxis(Amotor, i, 0, m_lockX.X, m_lockX.Y, m_lockX.Z);
3520 //Console.WriteLine("AxisX {0} set to {1}", i, m_lockX);
3521 i++;
3522 }
3523
3524 if (m_rotateEnable.Y == 0)
3525 {
3526 d.JointSetAMotorAxis(Amotor, i, 0, m_lockY.X, m_lockY.Y, m_lockY.Z);
3527 //Console.WriteLine("AxisY {0} set to {1}", i, m_lockY);
3528 i++;
3529 }
3530
3531 if (m_rotateEnable.Z == 0)
3532 {
3533 d.JointSetAMotorAxis(Amotor, i, 0, m_lockZ.X, m_lockZ.Y, m_lockZ.Z);
3534 //Console.WriteLine("AxisZ {0} set to {1}", i, m_lockZ);
3535 i++;
3536 }
3537
3538 // These lowstops and high stops are effectively (no wiggle room)
3539 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0f);
3540 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
3541 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0f);
3542 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0f);
3543 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f);
3544 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0f);
3545 d.JointSetAMotorParam(Amotor, (int)dParam.Vel, 0f);
3546 d.JointSetAMotorParam(Amotor, (int)dParam.Vel3, 0f);
3547 d.JointSetAMotorParam(Amotor, (int)dParam.Vel2, 0f);
3548 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0f);
3549 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0f);
3550 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0f);
3551 } // else none are locked
3552 } // end Rotation Update
3553
3554
3555 // VEHICLE processing ==========================================
3556 if (m_type != Vehicle.TYPE_NONE)
3557 {
3558 // get body attitude
3559 d.Quaternion rot = d.BodyGetQuaternion(Body);
3560 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
3561 Quaternion irotq = Quaternion.Inverse(rotq);
3562
3563 // VEHICLE Linear Motion
3564 d.Vector3 velnow = d.BodyGetLinearVel(Body); // this is in world frame
3565 Vector3 vel_now = new Vector3(velnow.X, velnow.Y, velnow.Z);
3566 m_lLinObjectVel = vel_now * irotq;
3567 if (m_linearMotorDecayTimescale < 300.0f) //setting of 300 or more disables decay rate
3568 {
3569 if (Vector3.Mag(m_lLinMotorDVel) < 1.0f)
3570 {
3571 float decayfactor = m_linearMotorDecayTimescale / timestep;
3572 Vector3 decayAmount = (m_lLinMotorDVel / decayfactor);
3573 m_lLinMotorDVel -= decayAmount;
3574 }
3575 else
3576 {
3577 float decayfactor = 3.0f - (0.57f * (float)Math.Log((double)(m_linearMotorDecayTimescale)));
3578 Vector3 decel = Vector3.Normalize(m_lLinMotorDVel) * decayfactor * timestep;
3579 m_lLinMotorDVel -= decel;
3580 }
3581 if (m_lLinMotorDVel.ApproxEquals(Vector3.Zero, 0.01f))
3582 {
3583 m_lLinMotorDVel = Vector3.Zero;
3584 }
3585
3586 /* else
3587 {
3588 if (Math.Abs(m_lLinMotorDVel.X) < Math.Abs(m_lLinObjectVel.X)) m_lLinObjectVel.X = m_lLinMotorDVel.X;
3589 if (Math.Abs(m_lLinMotorDVel.Y) < Math.Abs(m_lLinObjectVel.Y)) m_lLinObjectVel.Y = m_lLinMotorDVel.Y;
3590 if (Math.Abs(m_lLinMotorDVel.Z) < Math.Abs(m_lLinObjectVel.Z)) m_lLinObjectVel.Z = m_lLinMotorDVel.Z;
3591 } */
3592 } // end linear motor decay
3593
3594 if ((!m_lLinMotorDVel.ApproxEquals(Vector3.Zero, 0.01f)) || (!m_lLinObjectVel.ApproxEquals(Vector3.Zero, 0.01f)))
3595 {
3596 if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body);
3597 if (m_linearMotorTimescale < 300.0f)
3598 {
3599 Vector3 attack_error = m_lLinMotorDVel - m_lLinObjectVel;
3600 float linfactor = m_linearMotorTimescale / timestep;
3601 Vector3 attackAmount = (attack_error / linfactor) * 1.3f;
3602 m_lLinObjectVel += attackAmount;
3603 }
3604 if (m_linearFrictionTimescale.X < 300.0f)
3605 {
3606 float fricfactor = m_linearFrictionTimescale.X / timestep;
3607 float fricX = m_lLinObjectVel.X / fricfactor;
3608 m_lLinObjectVel.X -= fricX;
3609 }
3610 if (m_linearFrictionTimescale.Y < 300.0f)
3611 {
3612 float fricfactor = m_linearFrictionTimescale.Y / timestep;
3613 float fricY = m_lLinObjectVel.Y / fricfactor;
3614 m_lLinObjectVel.Y -= fricY;
3615 }
3616 if (m_linearFrictionTimescale.Z < 300.0f)
3617 {
3618 float fricfactor = m_linearFrictionTimescale.Z / timestep;
3619 float fricZ = m_lLinObjectVel.Z / fricfactor;
3620 m_lLinObjectVel.Z -= fricZ;
3621 }
3622 }
3623 m_wLinObjectVel = m_lLinObjectVel * rotq;
3624
3625 // Gravity and Buoyancy
3626 Vector3 grav = Vector3.Zero;
3627 if (m_VehicleBuoyancy < 1.0f)
3628 {
3629 // There is some gravity, make a gravity force vector
3630 // that is applied after object velocity.
3631 d.Mass objMass;
3632 d.BodyGetMass(Body, out objMass);
3633 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
3634 grav.Z = _parent_scene.gravityz * objMass.mass * (1f - m_VehicleBuoyancy); // Applied later as a force
3635 } // else its 1.0, no gravity.
3636
3637 // Hovering
3638 if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0)
3639 {
3640 // We should hover, get the target height
3641 d.Vector3 pos = d.BodyGetPosition(Body);
3642 if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) == VehicleFlag.HOVER_WATER_ONLY)
3643 {
3644 m_VhoverTargetHeight = _parent_scene.GetWaterLevel() + m_VhoverHeight;
3645 }
3646 else if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) == VehicleFlag.HOVER_TERRAIN_ONLY)
3647 {
3648 m_VhoverTargetHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y) + m_VhoverHeight;
3649 }
3650 else if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) == VehicleFlag.HOVER_GLOBAL_HEIGHT)
3651 {
3652 m_VhoverTargetHeight = m_VhoverHeight;
3653 }
3654
3655 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) == VehicleFlag.HOVER_UP_ONLY)
3656 {
3657 // If body is aready heigher, use its height as target height
3658 if (pos.Z > m_VhoverTargetHeight) m_VhoverTargetHeight = pos.Z;
3659 }
3660
3661 // m_VhoverEfficiency = 0f; // 0=boucy, 1=Crit.damped
3662 // m_VhoverTimescale = 0f; // time to acheive height
3663 // timestep is time since last frame,in secs
3664 float herr0 = pos.Z - m_VhoverTargetHeight;
3665 // Replace Vertical speed with correction figure if significant
3666 if (Math.Abs(herr0) > 0.01f)
3667 {
3668 //? d.Mass objMass;
3669 //? d.BodyGetMass(Body, out objMass);
3670 m_wLinObjectVel.Z = -((herr0 * timestep * 50.0f) / m_VhoverTimescale);
3671 //KF: m_VhoverEfficiency is not yet implemented
3672 }
3673 else
3674 {
3675 m_wLinObjectVel.Z = 0f;
3676 }
3677 }
3678 else
3679 { // not hovering
3680 if (m_wLinObjectVel.Z == 0f)
3681 { // Gravity rules
3682 m_wLinObjectVel.Z = vel_now.Z;
3683 } // else the motor has it
3684 }
3685 linvel = m_wLinObjectVel;
3686
3687 // Vehicle Linear Motion done =======================================
3688 // Apply velocity
3689 d.BodySetLinearVel(Body, linvel.X, linvel.Y, linvel.Z);
3690 // apply gravity force
3691 d.BodyAddForce(Body, grav.X, grav.Y, grav.Z);
3692 //if(frcount == 0) Console.WriteLine("Vel={0} Force={1}",linvel , grav);
3693 // end MoveLinear()
3694
3695
3696 // MoveAngular
3697 /*
3698 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
3699
3700 private float m_angularMotorTimescale = 0; // motor angular Attack rate set by LSL
3701 private float m_angularMotorDecayTimescale = 0; // motor angular Decay rate set by LSL
3702 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular Friction set by LSL
3703
3704 private Vector3 m_angularMotorDVel = Vector3.Zero; // decayed angular motor
3705 private Vector3 m_angObjectVel = Vector3.Zero; // what was last applied to body
3706 */
3707 //if(frcount == 0) Console.WriteLine("MoveAngular ");
3708
3709 d.Vector3 angularObjectVel = d.BodyGetAngularVel(Body);
3710 Vector3 angObjectVel = new Vector3(angularObjectVel.X, angularObjectVel.Y, angularObjectVel.Z);
3711 angObjectVel = angObjectVel * irotq; // ============ Converts to LOCAL rotation
3712
3713 //if(frcount == 0) Console.WriteLine("V0 = {0}", angObjectVel);
3714
3715 // Decay Angular Motor 1. In SL this also depends on attack rate! decay ~= 23/Attack.
3716 float atk_decayfactor = 23.0f / (m_angularMotorTimescale * timestep);
3717 m_angularMotorDVel -= m_angularMotorDVel / atk_decayfactor;
3718 // Decay Angular Motor 2.
3719 if (m_angularMotorDecayTimescale < 300.0f)
3720 {
3721 if (Vector3.Mag(m_angularMotorDVel) < 1.0f)
3722 {
3723 float decayfactor = (m_angularMotorDecayTimescale) / timestep;
3724 Vector3 decayAmount = (m_angularMotorDVel / decayfactor);
3725 m_angularMotorDVel -= decayAmount;
3726 }
3727 else
3728 {
3729 Vector3 decel = Vector3.Normalize(m_angularMotorDVel) * timestep / m_angularMotorDecayTimescale;
3730 m_angularMotorDVel -= decel;
3731 }
3732
3733 if (m_angularMotorDVel.ApproxEquals(Vector3.Zero, 0.01f))
3734 {
3735 m_angularMotorDVel = Vector3.Zero;
3736 }
3737 else
3738 {
3739 if (Math.Abs(m_angularMotorDVel.X) < Math.Abs(angObjectVel.X)) angObjectVel.X = m_angularMotorDVel.X;
3740 if (Math.Abs(m_angularMotorDVel.Y) < Math.Abs(angObjectVel.Y)) angObjectVel.Y = m_angularMotorDVel.Y;
3741 if (Math.Abs(m_angularMotorDVel.Z) < Math.Abs(angObjectVel.Z)) angObjectVel.Z = m_angularMotorDVel.Z;
3742 }
3743 } // end decay angular motor
3744 //if(frcount == 0) Console.WriteLine("MotorDvel {0} Obj {1}", m_angularMotorDVel, angObjectVel);
3745
3746 //if(frcount == 0) Console.WriteLine("VA = {0}", angObjectVel);
3747
3748 if ((!m_angularMotorDVel.ApproxEquals(Vector3.Zero, 0.01f)) || (!angObjectVel.ApproxEquals(Vector3.Zero, 0.01f)))
3749 { // if motor or object have motion
3750 if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body);
3751
3752 if (m_angularMotorTimescale < 300.0f)
3753 {
3754 Vector3 attack_error = m_angularMotorDVel - angObjectVel;
3755 float angfactor = m_angularMotorTimescale / timestep;
3756 Vector3 attackAmount = (attack_error / angfactor);
3757 angObjectVel += attackAmount;
3758 //if(frcount == 0) Console.WriteLine("Accel {0} Attk {1}",FrAaccel, attackAmount);
3759 //if(frcount == 0) Console.WriteLine("V2+= {0}", angObjectVel);
3760 }
3761
3762 angObjectVel.X -= angObjectVel.X / (m_angularFrictionTimescale.X * 0.7f / timestep);
3763 angObjectVel.Y -= angObjectVel.Y / (m_angularFrictionTimescale.Y * 0.7f / timestep);
3764 angObjectVel.Z -= angObjectVel.Z / (m_angularFrictionTimescale.Z * 0.7f / timestep);
3765 } // else no signif. motion
3766
3767 //if(frcount == 0) Console.WriteLine("Dmotor {0} Obj {1}", m_angularMotorDVel, angObjectVel);
3768 // Bank section tba
3769 // Deflection section tba
3770 //if(frcount == 0) Console.WriteLine("V3 = {0}", angObjectVel);
3771
3772
3773 /* // Rotation Axis Disables:
3774 if (!m_angularEnable.ApproxEquals(Vector3.One, 0.003f))
3775 {
3776 if (m_angularEnable.X == 0)
3777 angObjectVel.X = 0f;
3778 if (m_angularEnable.Y == 0)
3779 angObjectVel.Y = 0f;
3780 if (m_angularEnable.Z == 0)
3781 angObjectVel.Z = 0f;
3782 }
3783 */
3784 angObjectVel = angObjectVel * rotq; // ================ Converts to WORLD rotation
3785
3786 // Vertical attractor section
3787 Vector3 vertattr = Vector3.Zero;
3788
3789 if (m_verticalAttractionTimescale < 300)
3790 {
3791 float VAservo = 1.0f / (m_verticalAttractionTimescale * timestep);
3792 // make a vector pointing up
3793 Vector3 verterr = Vector3.Zero;
3794 verterr.Z = 1.0f;
3795 // rotate it to Body Angle
3796 verterr = verterr * rotq;
3797 // verterr.X and .Y are the World error ammounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1.
3798 // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go
3799 // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body.
3800
3801 if (verterr.Z < 0.0f)
3802 { // Deflection from vertical exceeds 90-degrees. This method will ensure stable return to
3803 // vertical, BUT for some reason a z-rotation is imparted to the object. TBI.
3804 //Console.WriteLine("InvertFlip");
3805 verterr.X = 2.0f - verterr.X;
3806 verterr.Y = 2.0f - verterr.Y;
3807 }
3808 verterr *= 0.5f;
3809 // verterror is 0 (no error) to +/- 1 (max error at 180-deg tilt)
3810 Vector3 xyav = angObjectVel;
3811 xyav.Z = 0.0f;
3812 if ((!xyav.ApproxEquals(Vector3.Zero, 0.001f)) || (verterr.Z < 0.49f))
3813 {
3814 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so
3815 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
3816 vertattr.X = verterr.Y;
3817 vertattr.Y = -verterr.X;
3818 vertattr.Z = 0f;
3819 //if(frcount == 0) Console.WriteLine("VAerr=" + verterr);
3820
3821 // scaling appears better usingsquare-law
3822 float damped = m_verticalAttractionEfficiency * m_verticalAttractionEfficiency;
3823 float bounce = 1.0f - damped;
3824 // 0 = crit damp, 1 = bouncy
3825 float oavz = angObjectVel.Z; // retain z velocity
3826 // time-scaled correction, which sums, therefore is bouncy:
3827 angObjectVel = (angObjectVel + (vertattr * VAservo * 0.0333f)) * bounce;
3828 // damped, good @ < 90:
3829 angObjectVel = angObjectVel + (vertattr * VAservo * 0.0667f * damped);
3830 angObjectVel.Z = oavz;
3831 //if(frcount == 0) Console.WriteLine("VA+");
3832 //Console.WriteLine("VAttr {0} OAvel {1}", vertattr, angObjectVel);
3833 }
3834 else
3835 {
3836 // else error is very small
3837 angObjectVel.X = 0f;
3838 angObjectVel.Y = 0f;
3839 //if(frcount == 0) Console.WriteLine("VA0");
3840 }
3841 } // else vertical attractor is off
3842 //if(frcount == 0) Console.WriteLine("V1 = {0}", angObjectVel);
3843
3844
3845 m_lastAngularVelocity = angObjectVel;
3846 // apply Angular Velocity to body
3847 d.BodySetAngularVel(Body, m_lastAngularVelocity.X, m_lastAngularVelocity.Y, m_lastAngularVelocity.Z);
3848 //if(frcount == 0) Console.WriteLine("V4 = {0}", m_lastAngularVelocity);
3849
3850 } // end VEHICLES
3851 else
3852 {
3853 // Dyamics (NON-'VEHICLES') are dealt with here ================================================================
3854
3855 if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009
3856
3857 /// Dynamics Buoyancy
3858 //KF: m_buoyancy is set by llSetBuoyancy() and is for non-vehicle.
3859 // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up
3860 // NB Prims in ODE are no subject to global gravity
3861 // This should only affect gravity operations
3862
3863 float m_mass = CalculateMass();
3864 // calculate z-force due togravity on object.
3865 fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; // force = acceleration * mass
3866 if ((m_usePID) && (m_PIDTau > 0.0f)) // Dynamics llMoveToTarget.
3867 {
3868 fz = 0; // llMoveToTarget ignores gravity.
3869 // it also ignores mass of object, and any physical resting on it.
3870 // Vector3 m_PIDTarget is where we are going
3871 // float m_PIDTau is time to get there
3872 fx = 0;
3873 fy = 0;
3874 d.Vector3 pos = d.BodyGetPosition(Body);
3875 Vector3 error = new Vector3(
3876 (m_PIDTarget.X - pos.X),
3877 (m_PIDTarget.Y - pos.Y),
3878 (m_PIDTarget.Z - pos.Z));
3879 if (error.ApproxEquals(Vector3.Zero, 0.01f))
3880 { // Very close, Jump there and quit move
3881
3882 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
3883 _target_velocity = Vector3.Zero;
3884 d.BodySetLinearVel(Body, _target_velocity.X, _target_velocity.Y, _target_velocity.Z);
3885 d.BodySetForce(Body, 0f, 0f, 0f);
3886 }
3887 else
3888 {
3889 float scale = 50.0f * timestep / m_PIDTau;
3890 if ((error.ApproxEquals(Vector3.Zero, 0.5f)) && (_target_velocity != Vector3.Zero))
3891 {
3892 // Nearby, quit update of velocity
3893 }
3894 else
3895 { // Far, calc damped velocity
3896 _target_velocity = error * scale;
3897 }
3898 d.BodySetLinearVel(Body, _target_velocity.X, _target_velocity.Y, _target_velocity.Z);
3899 }
3900 } // end PID MoveToTarget
3901
3902
3903 /// Dynamics Hover ===================================================================================
3904 // Hover PID Controller can only run if the PIDcontroller is not in use.
3905 if (m_useHoverPID && !m_usePID)
3906 {
3907 //Console.WriteLine("Hover " + m_primName);
3908
3909 // If we're using the PID controller, then we have no gravity
3910 fz = (-1 * _parent_scene.gravityz) * m_mass;
3911
3912 // no lock; for now it's only called from within Simulate()
3913
3914 // If the PID Controller isn't active then we set our force
3915 // calculating base velocity to the current position
3916
3917 if ((m_PIDTau < 1))
3918 {
3919 PID_G = PID_G / m_PIDTau;
3920 }
3921
3922 if ((PID_G - m_PIDTau) <= 0)
3923 {
3924 PID_G = m_PIDTau + 1;
3925 }
3926
3927
3928 // Where are we, and where are we headed?
3929 d.Vector3 pos = d.BodyGetPosition(Body);
3930 // d.Vector3 vel = d.BodyGetLinearVel(Body);
3931
3932
3933 // Non-Vehicles have a limited set of Hover options.
3934 // determine what our target height really is based on HoverType
3935 switch (m_PIDHoverType)
3936 {
3937 case PIDHoverType.Ground:
3938 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
3939 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3940 break;
3941 case PIDHoverType.GroundAndWater:
3942 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
3943 m_waterHeight = _parent_scene.GetWaterLevel();
3944 if (m_groundHeight > m_waterHeight)
3945 {
3946 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3947 }
3948 else
3949 {
3950 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
3951 }
3952 break;
3953
3954 } // end switch (m_PIDHoverType)
3955
3956
3957 _target_velocity =
3958 new Vector3(0.0f, 0.0f,
3959 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
3960 );
3961
3962 // if velocity is zero, use position control; otherwise, velocity control
3963
3964 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
3965 {
3966 // keep track of where we stopped. No more slippin' & slidin'
3967
3968 // We only want to deactivate the PID Controller if we think we want to have our surrogate
3969 // react to the physics scene by moving it's position.
3970 // Avatar to Avatar collisions
3971 // Prim to avatar collisions
3972 d.Vector3 dlinvel = vel;
3973 d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
3974 d.BodySetLinearVel(Body, dlinvel.X, dlinvel.Y, dlinvel.Z);
3975 d.BodyAddForce(Body, 0, 0, fz);
3976 //KF this prevents furthur motions return;
3977 }
3978 else
3979 {
3980 _zeroFlag = false;
3981
3982 // We're flying and colliding with something
3983 fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
3984 }
3985 } // end m_useHoverPID && !m_usePID
3986
3987
3988 /// Dynamics Apply Forces ===================================================================================
3989 fx *= m_mass;
3990 fy *= m_mass;
3991 //fz *= m_mass;
3992 fx += m_force.X;
3993 fy += m_force.Y;
3994 fz += m_force.Z;
3995
3996 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
3997 if (fx != 0 || fy != 0 || fz != 0)
3998 {
3999 //m_taintdisable = true;
4000 //base.RaiseOutOfBounds(Position);
4001 //d.BodySetLinearVel(Body, fx, fy, 0f);
4002 if (!d.BodyIsEnabled(Body))
4003 {
4004 // A physical body at rest on a surface will auto-disable after a while,
4005 // this appears to re-enable it incase the surface it is upon vanishes,
4006 // and the body should fall again.
4007 d.BodySetLinearVel(Body, 0f, 0f, 0f);
4008 d.BodySetForce(Body, 0f, 0f, 0f);
4009 enableBodySoft();
4010 }
4011
4012 // 35x10 = 350n times the mass per second applied maximum.
4013 float nmax = 35f * m_mass;
4014 float nmin = -35f * m_mass;
4015
4016
4017 if (fx > nmax)
4018 fx = nmax;
4019 if (fx < nmin)
4020 fx = nmin;
4021 if (fy > nmax)
4022 fy = nmax;
4023 if (fy < nmin)
4024 fy = nmin;
4025 d.BodyAddForce(Body, fx, fy, fz);
4026 } // end apply forces
4027 } // end Vehicle/Dynamics
4028
4029 /// RotLookAt / LookAt =================================================================================
4030 if (m_useAPID)
4031 {
4032 // RotLookAt, apparently overrides all other rotation sources. Inputs:
4033 // Quaternion m_APIDTarget
4034 // float m_APIDStrength // From SL experiments, this is the time to get there
4035 // float m_APIDDamping // From SL experiments, this is damping, 1.0 = damped, 0.1 = wobbly
4036 // Also in SL the mass of the object has no effect on time to get there.
4037 // Factors:
4038 // get present body rotation
4039 float limit = 1.0f;
4040 float rscaler = 50f; // adjusts rotation damping time
4041 float lscaler = 10f; // adjusts linear damping time in llLookAt
4042 float RLAservo = 0f;
4043 Vector3 diff_axis;
4044 float diff_angle;
4045 d.Quaternion rot = d.BodyGetQuaternion(Body); // prim present rotation
4046 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W);
4047 Quaternion rtarget = new Quaternion();
4048
4049 if (m_APIDTarget.W == -99.9f)
4050 {
4051 // this is really a llLookAt(), x,y,z is the target vector
4052 Vector3 target = new Vector3(m_APIDTarget.X, m_APIDTarget.Y, m_APIDTarget.Z);
4053 Vector3 ospin = new Vector3(1.0f, 0.0f, 0.0f) * rotq;
4054 Vector3 error = new Vector3(0.0f, 0.0f, 0.0f);
4055 float twopi = 2.0f * (float)Math.PI;
4056 Vector3 dir = target - _position;
4057 dir.Normalize();
4058 float tzrot = (float)Math.Atan2(dir.Y, dir.X);
4059 float txy = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
4060 float terot = (float)Math.Atan2(dir.Z, txy);
4061 float ozrot = (float)Math.Atan2(ospin.Y, ospin.X);
4062 float oxy = (float)Math.Sqrt((ospin.X * ospin.X) + (ospin.Y * ospin.Y));
4063 float oerot = (float)Math.Atan2(ospin.Z, oxy);
4064 float ra = 2.0f * ((rotq.W * rotq.X) + (rotq.Y * rotq.Z));
4065 float rb = 1.0f - 2.0f * ((rotq.Y * rotq.Y) + (rotq.X * rotq.X));
4066 float roll = (float)Math.Atan2(ra, rb);
4067 float errorz = tzrot - ozrot;
4068 if (errorz > (float)Math.PI) errorz -= twopi;
4069 else if (errorz < -(float)Math.PI) errorz += twopi;
4070 float errory = oerot - terot;
4071 if (errory > (float)Math.PI) errory -= twopi;
4072 else if (errory < -(float)Math.PI) errory += twopi;
4073 diff_angle = Math.Abs(errorz) + Math.Abs(errory) + Math.Abs(roll);
4074 if (diff_angle > 0.01f * m_APIDdamper)
4075 {
4076 m_APIDdamper = 1.0f;
4077 RLAservo = timestep / m_APIDStrength * rscaler;
4078 errorz *= RLAservo;
4079 errory *= RLAservo;
4080 error.X = -roll * 8.0f;
4081 error.Y = errory;
4082 error.Z = errorz;
4083 error *= rotq;
4084 d.BodySetAngularVel(Body, error.X, error.Y, error.Z);
4085 }
4086 else
4087 {
4088 d.BodySetAngularVel(Body, 0.0f, 0.0f, 0.0f);
4089 m_APIDdamper = 2.0f;
4090 }
4091 }
4092 else
4093 {
4094 // this is a llRotLookAt()
4095 rtarget = m_APIDTarget;
4096
4097 Quaternion rot_diff = Quaternion.Inverse(rotq) * rtarget; // difference to desired rot
4098 rot_diff.GetAxisAngle(out diff_axis, out diff_angle); // convert to axis to point at & error angle
4099 //if(frcount == 0) Console.WriteLine("axis {0} angle {1}",diff_axis * 57.3f, diff_angle);
4100
4101 // diff_axis.Normalize(); it already is!
4102 if (diff_angle > 0.01f * m_APIDdamper) // diff_angle is always +ve // if there is enough error
4103 {
4104 m_APIDdamper = 1.0f;
4105 Vector3 rotforce = new Vector3(diff_axis.X, diff_axis.Y, diff_axis.Z);
4106 rotforce = rotforce * rotq;
4107 if (diff_angle > limit) diff_angle = limit; // cap the rotate rate
4108 RLAservo = timestep / m_APIDStrength * lscaler;
4109 rotforce = rotforce * RLAservo * diff_angle;
4110 d.BodySetAngularVel(Body, rotforce.X, rotforce.Y, rotforce.Z);
4111 //Console.WriteLine("axis= " + diff_axis + " angle= " + diff_angle + "servo= " + RLAservo);
4112 }
4113 else
4114 { // close enough
4115 d.BodySetAngularVel(Body, 0.0f, 0.0f, 0.0f);
4116 m_APIDdamper = 2.0f;
4117 }
4118 } // end llLookAt/llRotLookAt
4119 //if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + " angle= " + diff_angle);
4120 } // end m_useAPID
4121 } // end root prims
4122 } // end Move()
4123 } // end class
4124}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/ChOdePlugin/ODERayCastRequestManager.cs
new file mode 100644
index 0000000..712029e
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/ODERayCastRequestManager.cs
@@ -0,0 +1,384 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Runtime.InteropServices;
32using System.Text;
33using OpenMetaverse;
34using OpenSim.Region.Physics.Manager;
35using Ode.NET;
36using log4net;
37
38namespace OpenSim.Region.Physics.OdePlugin
39{
40 /// <summary>
41 /// Processes raycast requests as ODE is in a state to be able to do them.
42 /// This ensures that it's thread safe and there will be no conflicts.
43 /// Requests get returned by a different thread then they were requested by.
44 /// </summary>
45 public class ODERayCastRequestManager
46 {
47 /// <summary>
48 /// Pending Raycast Requests
49 /// </summary>
50 protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>();
51
52 /// <summary>
53 /// Scene that created this object.
54 /// </summary>
55 private OdeScene m_scene;
56
57 /// <summary>
58 /// ODE contact array to be filled by the collision testing
59 /// </summary>
60 d.ContactGeom[] contacts = new d.ContactGeom[5];
61
62 /// <summary>
63 /// ODE near callback delegate
64 /// </summary>
65 private d.NearCallback nearCallback;
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 private List<ContactResult> m_contactResults = new List<ContactResult>();
68
69
70 public ODERayCastRequestManager(OdeScene pScene)
71 {
72 m_scene = pScene;
73 nearCallback = near;
74
75 }
76
77 /// <summary>
78 /// Queues a raycast
79 /// </summary>
80 /// <param name="position">Origin of Ray</param>
81 /// <param name="direction">Ray normal</param>
82 /// <param name="length">Ray length</param>
83 /// <param name="retMethod">Return method to send the results</param>
84 public void QueueRequest(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
85 {
86 lock (m_PendingRequests)
87 {
88 ODERayCastRequest req = new ODERayCastRequest();
89 req.callbackMethod = retMethod;
90 req.length = length;
91 req.Normal = direction;
92 req.Origin = position;
93
94 m_PendingRequests.Add(req);
95 }
96 }
97
98 /// <summary>
99 /// Process all queued raycast requests
100 /// </summary>
101 /// <returns>Time in MS the raycasts took to process.</returns>
102 public int ProcessQueuedRequests()
103 {
104 int time = System.Environment.TickCount;
105 lock (m_PendingRequests)
106 {
107 if (m_PendingRequests.Count > 0)
108 {
109 ODERayCastRequest[] reqs = m_PendingRequests.ToArray();
110 for (int i = 0; i < reqs.Length; i++)
111 {
112 try
113 {
114 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
115 RayCast(reqs[i]); // if there isn't anyone to send results
116 }
117 catch
118 {
119 //Fail silently
120 //This can genuinely happen because raycast requests are queued, and the actor may have
121 //been removed from the scene since it was queued
122 }
123 }
124 /*
125 foreach (ODERayCastRequest req in m_PendingRequests)
126 {
127 if (req.callbackMethod != null) // quick optimization here, don't raycast
128 RayCast(req); // if there isn't anyone to send results to
129
130 }
131 */
132 m_PendingRequests.Clear();
133 }
134 }
135
136 lock (m_contactResults)
137 m_contactResults.Clear();
138
139 return System.Environment.TickCount - time;
140 }
141
142 /// <summary>
143 /// Method that actually initiates the raycast
144 /// </summary>
145 /// <param name="req"></param>
146 private void RayCast(ODERayCastRequest req)
147 {
148 // Create the ray
149 IntPtr ray = d.CreateRay(m_scene.space, req.length);
150 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
151
152 // Collide test
153 d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
154
155 // Remove Ray
156 d.GeomDestroy(ray);
157
158
159 // Define default results
160 bool hitYN = false;
161 uint hitConsumerID = 0;
162 float distance = 999999999999f;
163 Vector3 closestcontact = new Vector3(99999f, 99999f, 99999f);
164 Vector3 snormal = Vector3.Zero;
165
166 // Find closest contact and object.
167 lock (m_contactResults)
168 {
169 foreach (ContactResult cResult in m_contactResults)
170 {
171 if (Vector3.Distance(req.Origin, cResult.Pos) < Vector3.Distance(req.Origin, closestcontact))
172 {
173 closestcontact = cResult.Pos;
174 hitConsumerID = cResult.ConsumerID;
175 distance = cResult.Depth;
176 hitYN = true;
177 snormal = cResult.Normal;
178 }
179 }
180
181 m_contactResults.Clear();
182 }
183
184 // Return results
185 if (req.callbackMethod != null)
186 req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal);
187 }
188
189 // This is the standard Near. Uses space AABBs to speed up detection.
190 private void near(IntPtr space, IntPtr g1, IntPtr g2)
191 {
192
193 //Don't test against heightfield Geom, or you'll be sorry!
194
195 /*
196 terminate called after throwing an instance of 'std::bad_alloc'
197 what(): std::bad_alloc
198 Stacktrace:
199
200 at (wrapper managed-to-native) Ode.NET.d.Collide (intptr,intptr,int,Ode.NET.d/ContactGeom[],int) <0x00004>
201 at (wrapper managed-to-native) Ode.NET.d.Collide (intptr,intptr,int,Ode.NET.d/ContactGeom[],int) <0xffffffff>
202 at OpenSim.Region.Physics.OdePlugin.ODERayCastRequestManager.near (intptr,intptr,intptr) <0x00280>
203 at (wrapper native-to-managed) OpenSim.Region.Physics.OdePlugin.ODERayCastRequestManager.near (intptr,intptr,intptr) <0xfff
204 fffff>
205 at (wrapper managed-to-native) Ode.NET.d.SpaceCollide2 (intptr,intptr,intptr,Ode.NET.d/NearCallback) <0x00004>
206 at (wrapper managed-to-native) Ode.NET.d.SpaceCollide2 (intptr,intptr,intptr,Ode.NET.d/NearCallback) <0xffffffff>
207 at OpenSim.Region.Physics.OdePlugin.ODERayCastRequestManager.RayCast (OpenSim.Region.Physics.OdePlugin.ODERayCastRequest) <
208 0x00114>
209 at OpenSim.Region.Physics.OdePlugin.ODERayCastRequestManager.ProcessQueuedRequests () <0x000eb>
210 at OpenSim.Region.Physics.OdePlugin.OdeScene.Simulate (single) <0x017e6>
211 at OpenSim.Region.Framework.Scenes.SceneGraph.UpdatePhysics (double) <0x00042>
212 at OpenSim.Region.Framework.Scenes.Scene.Update () <0x0039e>
213 at OpenSim.Region.Framework.Scenes.Scene.Heartbeat (object) <0x00019>
214 at (wrapper runtime-invoke) object.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>
215
216 Native stacktrace:
217
218 mono [0x80d2a42]
219 [0xb7f5840c]
220 /lib/i686/cmov/libc.so.6(abort+0x188) [0xb7d1a018]
221 /usr/lib/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x158) [0xb45fc988]
222 /usr/lib/libstdc++.so.6 [0xb45fa865]
223 /usr/lib/libstdc++.so.6 [0xb45fa8a2]
224 /usr/lib/libstdc++.so.6 [0xb45fa9da]
225 /usr/lib/libstdc++.so.6(_Znwj+0x83) [0xb45fb033]
226 /usr/lib/libstdc++.so.6(_Znaj+0x1d) [0xb45fb11d]
227 libode.so(_ZN13dxHeightfield23dCollideHeightfieldZoneEiiiiP6dxGeomiiP12dContactGeomi+0xd04) [0xb46678e4]
228 libode.so(_Z19dCollideHeightfieldP6dxGeomS0_iP12dContactGeomi+0x54b) [0xb466832b]
229 libode.so(dCollide+0x102) [0xb46571b2]
230 [0x95cfdec9]
231 [0x8ea07fe1]
232 [0xab260146]
233 libode.so [0xb465a5c4]
234 libode.so(_ZN11dxHashSpace8collide2EPvP6dxGeomPFvS0_S2_S2_E+0x75) [0xb465bcf5]
235 libode.so(dSpaceCollide2+0x177) [0xb465ac67]
236 [0x95cf978e]
237 [0x8ea07945]
238 [0x95cf2bbc]
239 [0xab2787e7]
240 [0xab419fb3]
241 [0xab416657]
242 [0xab415bda]
243 [0xb609b08e]
244 mono(mono_runtime_delegate_invoke+0x34) [0x8192534]
245 mono [0x81a2f0f]
246 mono [0x81d28b6]
247 mono [0x81ea2c6]
248 /lib/i686/cmov/libpthread.so.0 [0xb7e744c0]
249 /lib/i686/cmov/libc.so.6(clone+0x5e) [0xb7dcd6de]
250 */
251
252 // Exclude heightfield geom
253
254 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
255 return;
256 if (d.GeomGetClass(g1) == d.GeomClassID.HeightfieldClass || d.GeomGetClass(g2) == d.GeomClassID.HeightfieldClass)
257 return;
258
259 // Raytest against AABBs of spaces first, then dig into the spaces it hits for actual geoms.
260 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2))
261 {
262 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
263 return;
264
265 // Separating static prim geometry spaces.
266 // We'll be calling near recursivly if one
267 // of them is a space to find all of the
268 // contact points in the space
269 try
270 {
271 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
272 }
273 catch (AccessViolationException)
274 {
275 m_log.Warn("[PHYSICS]: Unable to collide test a space");
276 return;
277 }
278 //Colliding a space or a geom with a space or a geom. so drill down
279
280 //Collide all geoms in each space..
281 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback);
282 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback);
283 return;
284 }
285
286 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
287 return;
288
289 int count = 0;
290 try
291 {
292
293 if (g1 == g2)
294 return; // Can't collide with yourself
295
296 lock (contacts)
297 {
298 count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf);
299 }
300 }
301 catch (SEHException)
302 {
303 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
304 }
305 catch (Exception e)
306 {
307 m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message);
308 return;
309 }
310
311 PhysicsActor p1 = null;
312 PhysicsActor p2 = null;
313
314 if (g1 != IntPtr.Zero)
315 m_scene.actor_name_map.TryGetValue(g1, out p1);
316
317 if (g2 != IntPtr.Zero)
318 m_scene.actor_name_map.TryGetValue(g1, out p2);
319
320 // Loop over contacts, build results.
321 for (int i = 0; i < count; i++)
322 {
323 if (p1 != null) {
324 if (p1 is OdePrim)
325 {
326 ContactResult collisionresult = new ContactResult();
327
328 collisionresult.ConsumerID = ((OdePrim)p1).m_localID;
329 collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z);
330 collisionresult.Depth = contacts[i].depth;
331 collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y,
332 contacts[i].normal.Z);
333 lock (m_contactResults)
334 m_contactResults.Add(collisionresult);
335 }
336 }
337
338 if (p2 != null)
339 {
340 if (p2 is OdePrim)
341 {
342 ContactResult collisionresult = new ContactResult();
343
344 collisionresult.ConsumerID = ((OdePrim)p2).m_localID;
345 collisionresult.Pos = new Vector3(contacts[i].pos.X, contacts[i].pos.Y, contacts[i].pos.Z);
346 collisionresult.Depth = contacts[i].depth;
347 collisionresult.Normal = new Vector3(contacts[i].normal.X, contacts[i].normal.Y,
348 contacts[i].normal.Z);
349
350 lock (m_contactResults)
351 m_contactResults.Add(collisionresult);
352 }
353 }
354
355
356 }
357
358 }
359
360 /// <summary>
361 /// Dereference the creator scene so that it can be garbage collected if needed.
362 /// </summary>
363 internal void Dispose()
364 {
365 m_scene = null;
366 }
367 }
368
369 public struct ODERayCastRequest
370 {
371 public Vector3 Origin;
372 public Vector3 Normal;
373 public float length;
374 public RaycastCallback callbackMethod;
375 }
376
377 public struct ContactResult
378 {
379 public Vector3 Pos;
380 public float Depth;
381 public uint ConsumerID;
382 public Vector3 Normal;
383 }
384}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdePhysicsJoint.cs b/OpenSim/Region/Physics/ChOdePlugin/OdePhysicsJoint.cs
new file mode 100644
index 0000000..b4a3c48
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/OdePhysicsJoint.cs
@@ -0,0 +1,48 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using OpenMetaverse;
30using Ode.NET;
31using OpenSim.Framework;
32using OpenSim.Region.Physics.Manager;
33using OpenSim.Region.Physics.OdePlugin;
34
35namespace OpenSim.Region.Physics.OdePlugin
36{
37 class OdePhysicsJoint : PhysicsJoint
38 {
39 public override bool IsInPhysicsEngine
40 {
41 get
42 {
43 return (jointID != IntPtr.Zero);
44 }
45 }
46 public IntPtr jointID;
47 }
48}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
new file mode 100644
index 0000000..00f5122
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
@@ -0,0 +1,3887 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28//#define USE_DRAWSTUFF
29
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using System.Runtime.InteropServices;
34using System.Threading;
35using System.IO;
36using System.Diagnostics;
37using log4net;
38using Nini.Config;
39using Ode.NET;
40#if USE_DRAWSTUFF
41using Drawstuff.NET;
42#endif
43using OpenSim.Framework;
44using OpenSim.Region.Physics.Manager;
45using OpenMetaverse;
46
47//using OpenSim.Region.Physics.OdePlugin.Meshing;
48
49namespace OpenSim.Region.Physics.OdePlugin
50{
51 /// <summary>
52 /// ODE plugin
53 /// </summary>
54 public class OdePlugin : IPhysicsPlugin
55 {
56 //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
57
58 private CollisionLocker ode;
59 private OdeScene _mScene;
60
61 public OdePlugin()
62 {
63 ode = new CollisionLocker();
64 }
65
66 public bool Init()
67 {
68 return true;
69 }
70
71 public PhysicsScene GetScene(String sceneIdentifier)
72 {
73 if (_mScene == null)
74 {
75 if (Util.IsWindows())
76 Util.LoadArchSpecificWindowsDll("ode.dll");
77
78 // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
79 // http://opensimulator.org/mantis/view.php?id=2750).
80 d.InitODE();
81
82 _mScene = new OdeScene(ode, sceneIdentifier);
83 }
84 return (_mScene);
85 }
86
87 public string GetName()
88 {
89 return ("ChODE");
90 }
91
92 public void Dispose()
93 {
94 }
95 }
96
97 public enum StatusIndicators : int
98 {
99 Generic = 0,
100 Start = 1,
101 End = 2
102 }
103
104 public struct sCollisionData
105 {
106 public uint ColliderLocalId;
107 public uint CollidedWithLocalId;
108 public int NumberOfCollisions;
109 public int CollisionType;
110 public int StatusIndicator;
111 public int lastframe;
112 }
113
114 [Flags]
115 public enum CollisionCategories : int
116 {
117 Disabled = 0,
118 Geom = 0x00000001,
119 Body = 0x00000002,
120 Space = 0x00000004,
121 Character = 0x00000008,
122 Land = 0x00000010,
123 Water = 0x00000020,
124 Wind = 0x00000040,
125 Sensor = 0x00000080,
126 Selected = 0x00000100
127 }
128
129 /// <summary>
130 /// Material type for a primitive
131 /// </summary>
132 public enum Material : int
133 {
134 /// <summary></summary>
135 Stone = 0,
136 /// <summary></summary>
137 Metal = 1,
138 /// <summary></summary>
139 Glass = 2,
140 /// <summary></summary>
141 Wood = 3,
142 /// <summary></summary>
143 Flesh = 4,
144 /// <summary></summary>
145 Plastic = 5,
146 /// <summary></summary>
147 Rubber = 6
148
149 }
150
151 public sealed class OdeScene : PhysicsScene
152 {
153 private readonly ILog m_log;
154 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
155
156 CollisionLocker ode;
157
158 private Random fluidRandomizer = new Random(Environment.TickCount);
159
160 private const uint m_regionWidth = Constants.RegionSize;
161 private const uint m_regionHeight = Constants.RegionSize;
162
163 private float ODE_STEPSIZE = 0.020f;
164 private float metersInSpace = 29.9f;
165 private float m_timeDilation = 1.0f;
166
167 public float gravityx = 0f;
168 public float gravityy = 0f;
169 public float gravityz = -9.8f;
170
171 private float contactsurfacelayer = 0.001f;
172
173 private int worldHashspaceLow = -4;
174 private int worldHashspaceHigh = 128;
175
176 private int smallHashspaceLow = -4;
177 private int smallHashspaceHigh = 66;
178
179 private float waterlevel = 0f;
180 private int framecount = 0;
181 //private int m_returncollisions = 10;
182
183 private readonly IntPtr contactgroup;
184
185 internal IntPtr LandGeom;
186 internal IntPtr WaterGeom;
187
188 private float nmTerrainContactFriction = 255.0f;
189 private float nmTerrainContactBounce = 0.1f;
190 private float nmTerrainContactERP = 0.1025f;
191
192 private float mTerrainContactFriction = 75f;
193 private float mTerrainContactBounce = 0.1f;
194 private float mTerrainContactERP = 0.05025f;
195
196 private float nmAvatarObjectContactFriction = 250f;
197 private float nmAvatarObjectContactBounce = 0.1f;
198
199 private float mAvatarObjectContactFriction = 75f;
200 private float mAvatarObjectContactBounce = 0.1f;
201
202 private float avPIDD = 3200f;
203 private float avPIDP = 1400f;
204 private float avCapRadius = 0.37f;
205 private float avStandupTensor = 2000000f;
206 private bool avCapsuleTilted = true; // true = old compatibility mode with leaning capsule; false = new corrected mode
207 public bool IsAvCapsuleTilted { get { return avCapsuleTilted; } set { avCapsuleTilted = value; } }
208 private float avDensity = 80f;
209 private float avHeightFudgeFactor = 0.52f;
210 private float avMovementDivisorWalk = 1.3f;
211 private float avMovementDivisorRun = 0.8f;
212 private float minimumGroundFlightOffset = 3f;
213 public float maximumMassObject = 10000.01f;
214
215 public bool meshSculptedPrim = true;
216 public bool forceSimplePrimMeshing = false;
217
218 public float meshSculptLOD = 32;
219 public float MeshSculptphysicalLOD = 16;
220
221 public float geomDefaultDensity = 10.000006836f;
222
223 public int geomContactPointsStartthrottle = 3;
224 public int geomUpdatesPerThrottledUpdate = 15;
225
226 public float bodyPIDD = 35f;
227 public float bodyPIDG = 25;
228
229 public int geomCrossingFailuresBeforeOutofbounds = 5;
230 public float geomRegionFence = 0.0f;
231
232 public float bodyMotorJointMaxforceTensor = 2;
233
234 public int bodyFramesAutoDisable = 20;
235
236 private DateTime m_lastframe = DateTime.UtcNow;
237
238 private float[] _watermap;
239 private bool m_filterCollisions = true;
240
241 private d.NearCallback nearCallback;
242 public d.TriCallback triCallback;
243 public d.TriArrayCallback triArrayCallback;
244 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
245 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
246 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
247 private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>();
248 private readonly Object _taintedPrimLock = new Object();
249 private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>();
250 private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>();
251 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>();
252 private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
253 private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
254 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
255 public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
256 private bool m_NINJA_physics_joints_enabled = false;
257 //private Dictionary<String, IntPtr> jointpart_name_map = new Dictionary<String,IntPtr>();
258 private readonly Dictionary<String, List<PhysicsJoint>> joints_connecting_actor = new Dictionary<String, List<PhysicsJoint>>();
259 private d.ContactGeom[] contacts;
260 private readonly List<PhysicsJoint> requestedJointsToBeCreated = new List<PhysicsJoint>(); // lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active
261 private readonly List<PhysicsJoint> pendingJoints = new List<PhysicsJoint>(); // can lock for longer. accessed only by OdeScene.
262 private readonly List<PhysicsJoint> activeJoints = new List<PhysicsJoint>(); // can lock for longer. accessed only by OdeScene.
263 private readonly List<string> requestedJointsToBeDeleted = new List<string>(); // lock only briefly. accessed by external code (to request deletion of joints) and by OdeScene.Simulate() to move those joints out of pending/active
264 private Object externalJointRequestsLock = new Object();
265 private readonly Dictionary<String, PhysicsJoint> SOPName_to_activeJoint = new Dictionary<String, PhysicsJoint>();
266 private readonly Dictionary<String, PhysicsJoint> SOPName_to_pendingJoint = new Dictionary<String, PhysicsJoint>();
267 private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>();
268 private readonly Dictionary<IntPtr,float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>();
269
270 private d.Contact ContactCopy; // local copy that can be modified
271 private d.Contact TerrainContact;
272 private d.Contact AvatarStaticprimContact; // was 'contact'
273 private d.Contact AvatarMovementprimContact;
274 private d.Contact AvatarMovementTerrainContact;
275 private d.Contact WaterContact;
276 private d.Contact[,] m_materialContacts;
277
278//Ckrinke: Comment out until used. We declare it, initialize it, but do not use it
279//Ckrinke private int m_randomizeWater = 200;
280 private int m_physicsiterations = 10;
281 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
282 private readonly PhysicsActor PANull = new NullPhysicsActor();
283 private float step_time = 0.0f;
284//Ckrinke: Comment out until used. We declare it, initialize it, but do not use it
285//Ckrinke private int ms = 0;
286 public IntPtr world;
287 //private bool returncollisions = false;
288 // private uint obj1LocalID = 0;
289 private uint obj2LocalID = 0;
290 //private int ctype = 0;
291 private OdeCharacter cc1;
292 private OdePrim cp1;
293 private OdeCharacter cc2;
294 private OdePrim cp2;
295 //private int cStartStop = 0;
296 //private string cDictKey = "";
297
298 public IntPtr space;
299
300 //private IntPtr tmpSpace;
301 // split static geometry collision handling into spaces of 30 meters
302 public IntPtr[,] staticPrimspace;
303
304 public Object OdeLock;
305
306 public IMesher mesher;
307
308 private IConfigSource m_config;
309
310 public bool physics_logging = false;
311 public int physics_logging_interval = 0;
312 public bool physics_logging_append_existing_logfile = false;
313
314 public d.Vector3 xyz = new d.Vector3(128.1640f, 128.3079f, 25.7600f);
315 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f);
316
317 // TODO: unused: private uint heightmapWidth = m_regionWidth + 1;
318 // TODO: unused: private uint heightmapHeight = m_regionHeight + 1;
319 // TODO: unused: private uint heightmapWidthSamples;
320 // TODO: unused: private uint heightmapHeightSamples;
321
322 private volatile int m_global_contactcount = 0;
323
324 private Vector3 m_worldOffset = Vector3.Zero;
325 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
326 private PhysicsScene m_parentScene = null;
327
328 private ODERayCastRequestManager m_rayCastManager;
329
330 /// <summary>
331 /// Initiailizes the scene
332 /// Sets many properties that ODE requires to be stable
333 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
334 /// </summary>
335 public OdeScene(CollisionLocker dode, string sceneIdentifier)
336 {
337 m_log
338 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + sceneIdentifier);
339
340 OdeLock = new Object();
341 ode = dode;
342 nearCallback = near;
343 triCallback = TriCallback;
344 triArrayCallback = TriArrayCallback;
345 m_rayCastManager = new ODERayCastRequestManager(this);
346 lock (OdeLock)
347 {
348 // Create the world and the first space
349 world = d.WorldCreate();
350 space = d.HashSpaceCreate(IntPtr.Zero);
351
352
353 contactgroup = d.JointGroupCreate(0);
354 //contactgroup
355
356 d.WorldSetAutoDisableFlag(world, false);
357 #if USE_DRAWSTUFF
358
359 Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization));
360 viewthread.Start();
361 #endif
362 }
363
364
365 _watermap = new float[258 * 258];
366
367 // Zero out the prim spaces array (we split our space into smaller spaces so
368 // we can hit test less.
369 }
370
371#if USE_DRAWSTUFF
372 public void startvisualization(object o)
373 {
374 ds.Functions fn;
375 fn.version = ds.VERSION;
376 fn.start = new ds.CallbackFunction(start);
377 fn.step = new ds.CallbackFunction(step);
378 fn.command = new ds.CallbackFunction(command);
379 fn.stop = null;
380 fn.path_to_textures = "./textures";
381 string[] args = new string[0];
382 ds.SimulationLoop(args.Length, args, 352, 288, ref fn);
383 }
384#endif
385
386 // Initialize the mesh plugin
387 public override void Initialise(IMesher meshmerizer, IConfigSource config)
388 {
389 mesher = meshmerizer;
390 m_config = config;
391 // Defaults
392
393 if (Environment.OSVersion.Platform == PlatformID.Unix)
394 {
395 avPIDD = 3200.0f;
396 avPIDP = 1400.0f;
397 avStandupTensor = 2000000f;
398 }
399 else
400 {
401 avPIDD = 2200.0f;
402 avPIDP = 900.0f;
403 avStandupTensor = 550000f;
404 }
405
406 int contactsPerCollision = 80;
407
408 if (m_config != null)
409 {
410 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"];
411 if (physicsconfig != null)
412 {
413 gravityx = physicsconfig.GetFloat("world_gravityx", 0f);
414 gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
415 gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
416
417 worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4);
418 worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128);
419
420 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f);
421 smallHashspaceLow = physicsconfig.GetInt("small_hashspace_size_low", -4);
422 smallHashspaceHigh = physicsconfig.GetInt("small_hashspace_size_high", 66);
423
424 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", 0.001f);
425
426 nmTerrainContactFriction = physicsconfig.GetFloat("nm_terraincontact_friction", 255.0f);
427 nmTerrainContactBounce = physicsconfig.GetFloat("nm_terraincontact_bounce", 0.1f);
428 nmTerrainContactERP = physicsconfig.GetFloat("nm_terraincontact_erp", 0.1025f);
429
430 mTerrainContactFriction = physicsconfig.GetFloat("m_terraincontact_friction", 75f);
431 mTerrainContactBounce = physicsconfig.GetFloat("m_terraincontact_bounce", 0.05f);
432 mTerrainContactERP = physicsconfig.GetFloat("m_terraincontact_erp", 0.05025f);
433
434 nmAvatarObjectContactFriction = physicsconfig.GetFloat("objectcontact_friction", 250f);
435 nmAvatarObjectContactBounce = physicsconfig.GetFloat("objectcontact_bounce", 0.2f);
436
437 mAvatarObjectContactFriction = physicsconfig.GetFloat("m_avatarobjectcontact_friction", 75f);
438 mAvatarObjectContactBounce = physicsconfig.GetFloat("m_avatarobjectcontact_bounce", 0.1f);
439
440 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", 0.020f);
441 m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", 10);
442
443 avDensity = physicsconfig.GetFloat("av_density", 80f);
444 avHeightFudgeFactor = physicsconfig.GetFloat("av_height_fudge_factor", 0.52f);
445 avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", 1.3f);
446 avMovementDivisorRun = physicsconfig.GetFloat("av_movement_divisor_run", 0.8f);
447 avCapRadius = physicsconfig.GetFloat("av_capsule_radius", 0.37f);
448 avCapsuleTilted = physicsconfig.GetBoolean("av_capsule_tilted", false);
449
450 contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", 80);
451
452 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3);
453 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15);
454 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5);
455 geomRegionFence = physicsconfig.GetFloat("region_border_fence", 0.0f);
456
457 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f);
458 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20);
459
460 bodyPIDD = physicsconfig.GetFloat("body_pid_derivative", 35f);
461 bodyPIDG = physicsconfig.GetFloat("body_pid_gain", 25f);
462
463 forceSimplePrimMeshing = physicsconfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing);
464 meshSculptedPrim = physicsconfig.GetBoolean("mesh_sculpted_prim", true);
465 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f);
466 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f);
467 m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false);
468
469 if (Environment.OSVersion.Platform == PlatformID.Unix)
470 {
471 avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", 2200.0f);
472 avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", 900.0f);
473 avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_linux", 550000f);
474 bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_linux", 5f);
475 }
476 else
477 {
478 avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", 2200.0f);
479 avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", 900.0f);
480 avStandupTensor = physicsconfig.GetFloat("av_capsule_standup_tensor_win", 550000f);
481 bodyMotorJointMaxforceTensor = physicsconfig.GetFloat("body_motor_joint_maxforce_tensor_win", 5f);
482 }
483
484 physics_logging = physicsconfig.GetBoolean("physics_logging", false);
485 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0);
486 physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false);
487
488 m_NINJA_physics_joints_enabled = physicsconfig.GetBoolean("use_NINJA_physics_joints", false);
489 minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", 3f);
490 maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", 10000.01f);
491 }
492 }
493
494 contacts = new d.ContactGeom[contactsPerCollision];
495
496 staticPrimspace = new IntPtr[(int)(300 / metersInSpace), (int)(300 / metersInSpace)];
497
498 // Avatar static on a Prim parameters
499 AvatarStaticprimContact.surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
500 AvatarStaticprimContact.surface.mu = 255.0f;
501 AvatarStaticprimContact.surface.bounce = 0.0f;
502 AvatarStaticprimContact.surface.soft_cfm = 0.0f;
503 AvatarStaticprimContact.surface.soft_erp = 0.30f; // If this is too small static Av will fall through a sloping prim. 1.0 prevents fall-thru
504
505 // Avatar moving on a Prim parameters
506 AvatarMovementprimContact.surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
507 AvatarMovementprimContact.surface.mu = 255.0f;
508 AvatarMovementprimContact.surface.bounce = 0.0f;
509 AvatarMovementprimContact.surface.soft_cfm = 0.0f; // if this is 0.01 then prims become phantom to Avs!
510 AvatarMovementprimContact.surface.soft_erp = 0.3f;
511
512 // Static Avatar on Terrain parameters
513 // Keeps Avatar in place better
514 TerrainContact.surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
515 TerrainContact.surface.mu = 255.0f;
516 TerrainContact.surface.bounce = 0.0f;
517 TerrainContact.surface.soft_cfm = 0.0f;
518 TerrainContact.surface.soft_erp = 0.05f;
519
520 // Moving Avatar on Terrain parameters
521 AvatarMovementTerrainContact.surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
522 AvatarMovementTerrainContact.surface.mu = 75f;
523 AvatarMovementTerrainContact.surface.bounce = 0.0f;
524 AvatarMovementTerrainContact.surface.soft_cfm = 0.0f;
525 AvatarMovementTerrainContact.surface.soft_erp = 0.05f;
526
527 // Avatar or prim the the water, this may not be used, possibly water is same as air?
528 WaterContact.surface.mode |= (d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM);
529 WaterContact.surface.mu = 0.0f; // No friction
530 WaterContact.surface.bounce = 0.0f; // No bounce
531 WaterContact.surface.soft_cfm = 0.010f;
532 WaterContact.surface.soft_erp = 0.010f;
533
534
535 // Prim static or moving on a prim, depends on material type
536 m_materialContacts = new d.Contact[7,2];
537 // V 1 = Sliding; 0 = static or fell onto
538 m_materialContacts[(int)Material.Stone, 0] = new d.Contact();
539 m_materialContacts[(int)Material.Stone, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
540 m_materialContacts[(int)Material.Stone, 0].surface.mu = 60f; // friction, 1 = slippery, 255 = no slip
541 m_materialContacts[(int)Material.Stone, 0].surface.bounce = 0.0f;
542 m_materialContacts[(int)Material.Stone, 0].surface.soft_cfm = 0.0f;
543 m_materialContacts[(int)Material.Stone, 0].surface.soft_erp = 0.50f; // erp also changes friction, more erp=less friction
544
545 m_materialContacts[(int)Material.Stone, 1] = new d.Contact();
546 m_materialContacts[(int)Material.Stone, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
547 m_materialContacts[(int)Material.Stone, 1].surface.mu = 40f;
548 m_materialContacts[(int)Material.Stone, 1].surface.bounce = 0.0f;
549 m_materialContacts[(int)Material.Stone, 1].surface.soft_cfm = 0.0f;
550 m_materialContacts[(int)Material.Stone, 1].surface.soft_erp = 0.50f;
551
552 m_materialContacts[(int)Material.Metal, 0] = new d.Contact();
553 m_materialContacts[(int)Material.Metal, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
554 m_materialContacts[(int)Material.Metal, 0].surface.mu = 15f;
555 m_materialContacts[(int)Material.Metal, 0].surface.bounce = 0.2f;
556 m_materialContacts[(int)Material.Metal, 0].surface.soft_cfm = 0.0f;
557 m_materialContacts[(int)Material.Metal, 0].surface.soft_erp = 0.50f;
558
559 m_materialContacts[(int)Material.Metal, 1] = new d.Contact();
560 m_materialContacts[(int)Material.Metal, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
561 m_materialContacts[(int)Material.Metal, 1].surface.mu = 10f;
562 m_materialContacts[(int)Material.Metal, 1].surface.bounce = 0.2f;
563 m_materialContacts[(int)Material.Metal, 1].surface.soft_cfm = 0.0f;
564 m_materialContacts[(int)Material.Metal, 1].surface.soft_erp = 0.50f;
565
566 m_materialContacts[(int)Material.Glass, 0] = new d.Contact();
567 m_materialContacts[(int)Material.Glass, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
568 m_materialContacts[(int)Material.Glass, 0].surface.mu = 7.5f;
569 m_materialContacts[(int)Material.Glass, 0].surface.bounce = 0.0f;
570 m_materialContacts[(int)Material.Glass, 0].surface.soft_cfm = 0.0f;
571 m_materialContacts[(int)Material.Glass, 0].surface.soft_erp = 0.50f;
572
573 m_materialContacts[(int)Material.Glass, 1] = new d.Contact();
574 m_materialContacts[(int)Material.Glass, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
575 m_materialContacts[(int)Material.Glass, 1].surface.mu = 5f;
576 m_materialContacts[(int)Material.Glass, 1].surface.bounce = 0.0f;
577 m_materialContacts[(int)Material.Glass, 1].surface.soft_cfm = 0.0f;
578 m_materialContacts[(int)Material.Glass, 1].surface.soft_erp = 0.50f;
579
580 m_materialContacts[(int)Material.Wood, 0] = new d.Contact();
581 m_materialContacts[(int)Material.Wood, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
582 m_materialContacts[(int)Material.Wood, 0].surface.mu = 45f;
583 m_materialContacts[(int)Material.Wood, 0].surface.bounce = 0.1f;
584 m_materialContacts[(int)Material.Wood, 0].surface.soft_cfm = 0.0f;
585 m_materialContacts[(int)Material.Wood, 0].surface.soft_erp = 0.50f;
586
587 m_materialContacts[(int)Material.Wood, 1] = new d.Contact();
588 m_materialContacts[(int)Material.Wood, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
589 m_materialContacts[(int)Material.Wood, 1].surface.mu = 30f;
590 m_materialContacts[(int)Material.Wood, 1].surface.bounce = 0.1f;
591 m_materialContacts[(int)Material.Wood, 1].surface.soft_cfm = 0.0f;
592 m_materialContacts[(int)Material.Wood, 1].surface.soft_erp = 0.50f;
593
594 m_materialContacts[(int)Material.Flesh, 0] = new d.Contact();
595 m_materialContacts[(int)Material.Flesh, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
596 m_materialContacts[(int)Material.Flesh, 0].surface.mu = 150f;
597 m_materialContacts[(int)Material.Flesh, 0].surface.bounce = 0.0f;
598 m_materialContacts[(int)Material.Flesh, 0].surface.soft_cfm = 0.0f;
599 m_materialContacts[(int)Material.Flesh, 0].surface.soft_erp = 0.50f;
600
601 m_materialContacts[(int)Material.Flesh, 1] = new d.Contact();
602 m_materialContacts[(int)Material.Flesh, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
603 m_materialContacts[(int)Material.Flesh, 1].surface.mu = 100f;
604 m_materialContacts[(int)Material.Flesh, 1].surface.bounce = 0.0f;
605 m_materialContacts[(int)Material.Flesh, 1].surface.soft_cfm = 0.0f;
606 m_materialContacts[(int)Material.Flesh, 1].surface.soft_erp = 0.50f;
607
608 m_materialContacts[(int)Material.Plastic, 0] = new d.Contact();
609 m_materialContacts[(int)Material.Plastic, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
610 m_materialContacts[(int)Material.Plastic, 0].surface.mu = 30f;
611 m_materialContacts[(int)Material.Plastic, 0].surface.bounce = 0.2f;
612 m_materialContacts[(int)Material.Plastic, 0].surface.soft_cfm = 0.0f;
613 m_materialContacts[(int)Material.Plastic, 0].surface.soft_erp = 0.50f;
614
615 m_materialContacts[(int)Material.Plastic, 1] = new d.Contact();
616 m_materialContacts[(int)Material.Plastic, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
617 m_materialContacts[(int)Material.Plastic, 1].surface.mu = 20f;
618 m_materialContacts[(int)Material.Plastic, 1].surface.bounce = 0.2f;
619 m_materialContacts[(int)Material.Plastic, 1].surface.soft_cfm = 0.0f;
620 m_materialContacts[(int)Material.Plastic, 1].surface.soft_erp = 0.50f;
621
622 m_materialContacts[(int)Material.Rubber, 0] = new d.Contact();
623 m_materialContacts[(int)Material.Rubber, 0].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
624 m_materialContacts[(int)Material.Rubber, 0].surface.mu = 150f;
625 m_materialContacts[(int)Material.Rubber, 0].surface.bounce = 0.7f;
626 m_materialContacts[(int)Material.Rubber, 0].surface.soft_cfm = 0.0f;
627 m_materialContacts[(int)Material.Rubber, 0].surface.soft_erp = 0.50f;
628
629 m_materialContacts[(int)Material.Rubber, 1] = new d.Contact();
630 m_materialContacts[(int)Material.Rubber, 1].surface.mode = d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP | d.ContactFlags.Bounce;
631 m_materialContacts[(int)Material.Rubber, 1].surface.mu = 100f;
632 m_materialContacts[(int)Material.Rubber, 1].surface.bounce = 0.7f;
633 m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.0f;
634 m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.50f;
635
636 d.HashSpaceSetLevels(space, worldHashspaceLow, worldHashspaceHigh);
637
638 // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
639
640 d.WorldSetGravity(world, gravityx, gravityy, gravityz);
641 d.WorldSetContactSurfaceLayer(world, contactsurfacelayer);
642
643
644 d.WorldSetLinearDampingThreshold(world, 256f);
645 d.WorldSetLinearDamping(world, 256f);
646// d.WorldSetLinearDampingThreshold(world, 0.01f);
647// d.WorldSetLinearDamping(world, 0.1f);
648 d.WorldSetAngularDampingThreshold(world, 256f);
649 d.WorldSetAngularDamping(world, 256f);
650 d.WorldSetMaxAngularSpeed(world, 256f);
651
652 // Set how many steps we go without running collision testing
653 // This is in addition to the step size.
654 // Essentially Steps * m_physicsiterations
655 d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
656 //d.WorldSetContactMaxCorrectingVel(world, 1000.0f);
657
658
659
660 for (int i = 0; i < staticPrimspace.GetLength(0); i++)
661 {
662 for (int j = 0; j < staticPrimspace.GetLength(1); j++)
663 {
664 staticPrimspace[i, j] = IntPtr.Zero;
665 }
666 }
667 }
668
669 internal void waitForSpaceUnlock(IntPtr space)
670 {
671 //if (space != IntPtr.Zero)
672 //while (d.SpaceLockQuery(space)) { } // Wait and do nothing
673 }
674
675 /// <summary>
676 /// Debug space message for printing the space that a prim/avatar is in.
677 /// </summary>
678 /// <param name="pos"></param>
679 /// <returns>Returns which split up space the given position is in.</returns>
680 public string whichspaceamIin(Vector3 pos)
681 {
682 return calculateSpaceForGeom(pos).ToString();
683 }
684
685 #region Collision Detection
686
687 /// <summary>
688 /// This is our near callback. A geometry is near a body
689 /// </summary>
690 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
691 /// <param name="g1">a geometry or space</param>
692 /// <param name="g2">another geometry or space</param>
693 private void near(IntPtr space, IntPtr g1, IntPtr g2)
694 {
695 // no lock here! It's invoked from within Simulate(), which is thread-locked
696
697 // Test if we're colliding a geom with a space.
698 // If so we have to drill down into the space recursively
699//Console.WriteLine("near -----------"); //##
700 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2))
701 {
702 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
703 return;
704
705 // Separating static prim geometry spaces.
706 // We'll be calling near recursivly if one
707 // of them is a space to find all of the
708 // contact points in the space
709 try
710 {
711 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
712 }
713 catch (AccessViolationException)
714 {
715 m_log.Warn("[PHYSICS]: Unable to collide test a space");
716 return;
717 }
718 //Colliding a space or a geom with a space or a geom. so drill down
719
720 //Collide all geoms in each space..
721 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback);
722 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback);
723 return;
724 }
725
726 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
727 return;
728
729 IntPtr b1 = d.GeomGetBody(g1);
730 IntPtr b2 = d.GeomGetBody(g2);
731
732 // d.GeomClassID id = d.GeomGetClass(g1);
733
734 String name1 = null;
735 String name2 = null;
736
737 if (!geom_name_map.TryGetValue(g1, out name1))
738 {
739 name1 = "null";
740 }
741 if (!geom_name_map.TryGetValue(g2, out name2))
742 {
743 name2 = "null";
744 }
745
746 //if (id == d.GeomClassId.TriMeshClass)
747 //{
748 // m_log.InfoFormat("near: A collision was detected between {1} and {2}", 0, name1, name2);
749 //m_log.Debug("near: A collision was detected between {1} and {2}", 0, name1, name2);
750 //}
751
752 // Figure out how many contact points we have
753 int count = 0;
754 try
755 {
756 // Colliding Geom To Geom
757 // This portion of the function 'was' blatantly ripped off from BoxStack.cs
758
759 if (g1 == g2)
760 return; // Can't collide with yourself
761
762 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
763 return;
764
765 lock (contacts)
766 {
767 count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf);
768 if (count > contacts.Length)
769 m_log.Error("[PHYSICS]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length);
770 }
771 }
772 catch (SEHException)
773 {
774 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
775 ode.drelease(world);
776 base.TriggerPhysicsBasedRestart();
777 }
778 catch (Exception e)
779 {
780 m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message);
781 return;
782 }
783
784 PhysicsActor p1;
785 PhysicsActor p2;
786
787 if (!actor_name_map.TryGetValue(g1, out p1))
788 {
789 p1 = PANull;
790 }
791
792 if (!actor_name_map.TryGetValue(g2, out p2))
793 {
794 p2 = PANull;
795 }
796
797 ContactPoint maxDepthContact = new ContactPoint();
798 if (p1.CollisionScore + count >= float.MaxValue)
799 p1.CollisionScore = 0;
800 p1.CollisionScore += count;
801
802 if (p2.CollisionScore + count >= float.MaxValue)
803 p2.CollisionScore = 0;
804 p2.CollisionScore += count;
805 for (int i = 0; i < count; i++)
806 {
807 d.ContactGeom curContact = contacts[i];
808
809 if (curContact.depth > maxDepthContact.PenetrationDepth)
810 {
811 maxDepthContact = new ContactPoint(
812 new Vector3(curContact.pos.X, curContact.pos.Y, curContact.pos.Z),
813 new Vector3(curContact.normal.X, curContact.normal.Y, curContact.normal.Z),
814 curContact.depth
815 );
816 }
817
818 //m_log.Warn("[CCOUNT]: " + count);
819 IntPtr joint;
820 // If we're colliding with terrain, use 'TerrainContact' instead of AvatarStaticprimContact.
821 // allows us to have different settings
822
823 // We only need to test p2 for 'jump crouch purposes'
824 if (p2 is OdeCharacter && p1.PhysicsActorType == (int)ActorTypes.Prim)
825 {
826 // Testing if the collision is at the feet of the avatar
827
828 //m_log.DebugFormat("[PHYSICS]: {0} - {1} - {2} - {3}", curContact.pos.Z, p2.Position.Z, (p2.Position.Z - curContact.pos.Z), (p2.Size.Z * 0.6f));
829//#@ if ((p2.Position.Z - curContact.pos.Z) > (p2.Size.Z * 0.6f))
830//#@ p2.IsColliding = true;
831 if ((p2.Position.Z - curContact.pos.Z) > (p2.Size.Z * 0.6f)){ //##
832 p2.IsColliding = true; //##
833 }else{
834
835 } //##
836 }
837 else
838 {
839 p2.IsColliding = true;
840 }
841
842 //if ((framecount % m_returncollisions) == 0)
843
844 switch (p1.PhysicsActorType)
845 {
846 case (int)ActorTypes.Agent:
847 p2.CollidingObj = true;
848 break;
849 case (int)ActorTypes.Prim:
850 if (p2.Velocity.LengthSquared() > 0.0f)
851 p2.CollidingObj = true;
852 break;
853 case (int)ActorTypes.Unknown:
854 p2.CollidingGround = true;
855 break;
856 default:
857 p2.CollidingGround = true;
858 break;
859 }
860
861 // we don't want prim or avatar to explode
862
863 #region InterPenetration Handling - Unintended physics explosions
864# region disabled code1
865
866 if (curContact.depth >= 0.08f)
867 {
868 //This is disabled at the moment only because it needs more tweaking
869 //It will eventually be uncommented
870 /*
871 if (AvatarStaticprimContact.depth >= 1.00f)
872 {
873 //m_log.Debug("[PHYSICS]: " + AvatarStaticprimContact.depth.ToString());
874 }
875
876 //If you interpenetrate a prim with an agent
877 if ((p2.PhysicsActorType == (int) ActorTypes.Agent &&
878 p1.PhysicsActorType == (int) ActorTypes.Prim) ||
879 (p1.PhysicsActorType == (int) ActorTypes.Agent &&
880 p2.PhysicsActorType == (int) ActorTypes.Prim))
881 {
882
883 //AvatarStaticprimContact.depth = AvatarStaticprimContact.depth * 4.15f;
884 /*
885 if (p2.PhysicsActorType == (int) ActorTypes.Agent)
886 {
887 p2.CollidingObj = true;
888 AvatarStaticprimContact.depth = 0.003f;
889 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f);
890 OdeCharacter character = (OdeCharacter) p2;
891 character.SetPidStatus(true);
892 AvatarStaticprimContact.pos = new d.Vector3(AvatarStaticprimContact.pos.X + (p1.Size.X / 2), AvatarStaticprimContact.pos.Y + (p1.Size.Y / 2), AvatarStaticprimContact.pos.Z + (p1.Size.Z / 2));
893
894 }
895 else
896 {
897
898 //AvatarStaticprimContact.depth = 0.0000000f;
899 }
900 if (p1.PhysicsActorType == (int) ActorTypes.Agent)
901 {
902
903 p1.CollidingObj = true;
904 AvatarStaticprimContact.depth = 0.003f;
905 p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f);
906 AvatarStaticprimContact.pos = new d.Vector3(AvatarStaticprimContact.pos.X + (p2.Size.X / 2), AvatarStaticprimContact.pos.Y + (p2.Size.Y / 2), AvatarStaticprimContact.pos.Z + (p2.Size.Z / 2));
907 OdeCharacter character = (OdeCharacter)p1;
908 character.SetPidStatus(true);
909 }
910 else
911 {
912
913 //AvatarStaticprimContact.depth = 0.0000000f;
914 }
915
916
917
918 }
919*/
920 // If you interpenetrate a prim with another prim
921 /*
922 if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim)
923 {
924 #region disabledcode2
925 //OdePrim op1 = (OdePrim)p1;
926 //OdePrim op2 = (OdePrim)p2;
927 //op1.m_collisionscore++;
928 //op2.m_collisionscore++;
929
930 //if (op1.m_collisionscore > 8000 || op2.m_collisionscore > 8000)
931 //{
932 //op1.m_taintdisable = true;
933 //AddPhysicsActorTaint(p1);
934 //op2.m_taintdisable = true;
935 //AddPhysicsActorTaint(p2);
936 //}
937
938 //if (AvatarStaticprimContact.depth >= 0.25f)
939 //{
940 // Don't collide, one or both prim will expld.
941
942 //op1.m_interpenetrationcount++;
943 //op2.m_interpenetrationcount++;
944 //interpenetrations_before_disable = 200;
945 //if (op1.m_interpenetrationcount >= interpenetrations_before_disable)
946 //{
947 //op1.m_taintdisable = true;
948 //AddPhysicsActorTaint(p1);
949 //}
950 //if (op2.m_interpenetrationcount >= interpenetrations_before_disable)
951 //{
952 // op2.m_taintdisable = true;
953 //AddPhysicsActorTaint(p2);
954 //}
955
956 //AvatarStaticprimContact.depth = AvatarStaticprimContact.depth / 8f;
957 //AvatarStaticprimContact.normal = new d.Vector3(0, 0, 1);
958 //}
959 //if (op1.m_disabled || op2.m_disabled)
960 //{
961 //Manually disabled objects stay disabled
962 //AvatarStaticprimContact.depth = 0f;
963 //}
964 #endregion
965 }
966 */
967#endregion
968 if (curContact.depth >= 1.00f)
969 {
970 //m_log.Info("[P]: " + AvatarStaticprimContact.depth.ToString());
971 if ((p2.PhysicsActorType == (int) ActorTypes.Agent &&
972 p1.PhysicsActorType == (int) ActorTypes.Unknown) ||
973 (p1.PhysicsActorType == (int) ActorTypes.Agent &&
974 p2.PhysicsActorType == (int) ActorTypes.Unknown))
975 {
976 if (p2.PhysicsActorType == (int) ActorTypes.Agent)
977 {
978 if (p2 is OdeCharacter)
979 {
980 OdeCharacter character = (OdeCharacter) p2;
981
982 //p2.CollidingObj = true;
983 curContact.depth = 0.00000003f;
984 p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f);
985 curContact.pos =
986 new d.Vector3(curContact.pos.X + (p1.Size.X/2),
987 curContact.pos.Y + (p1.Size.Y/2),
988 curContact.pos.Z + (p1.Size.Z/2));
989 character.SetPidStatus(true);
990 }
991 }
992
993
994 if (p1.PhysicsActorType == (int) ActorTypes.Agent)
995 {
996 if (p1 is OdeCharacter)
997 {
998 OdeCharacter character = (OdeCharacter) p1;
999
1000 //p2.CollidingObj = true;
1001 curContact.depth = 0.00000003f;
1002 p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f);
1003 curContact.pos =
1004 new d.Vector3(curContact.pos.X + (p1.Size.X/2),
1005 curContact.pos.Y + (p1.Size.Y/2),
1006 curContact.pos.Z + (p1.Size.Z/2));
1007 character.SetPidStatus(true);
1008 }
1009 }
1010 }
1011 }
1012 }
1013
1014 #endregion
1015
1016 // Logic for collision handling
1017 // Note, that if *all* contacts are skipped (VolumeDetect)
1018 // The prim still detects (and forwards) collision events but
1019 // appears to be phantom for the world
1020 Boolean skipThisContact = false;
1021
1022 if ((p1 is OdePrim) && (((OdePrim)p1).m_isVolumeDetect))
1023 skipThisContact = true; // No collision on volume detect prims
1024
1025 if (!skipThisContact && (p2 is OdePrim) && (((OdePrim)p2).m_isVolumeDetect))
1026 skipThisContact = true; // No collision on volume detect prims
1027
1028 if (!skipThisContact && curContact.depth < 0f)
1029 skipThisContact = true;
1030
1031 if (!skipThisContact && checkDupe(curContact, p2.PhysicsActorType))
1032 skipThisContact = true;
1033
1034 const int maxContactsbeforedeath = 4000;
1035 joint = IntPtr.Zero;
1036
1037 if (!skipThisContact)
1038 {
1039 // Add contact joints with materials params----------------------------------
1040 // p1 is what is being hit, p2 is the physical object doing the hitting
1041 int material = (int) Material.Wood;
1042 int movintYN = 0; // 1 = Sliding; 0 = static or fell onto
1043 if (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f) movintYN = 1;
1044
1045 // If we're colliding against terrain
1046 if (name1 == "Terrain" || name2 == "Terrain")
1047 {
1048 // If we're moving
1049 if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && (movintYN == 1))
1050 {
1051 //$ Av walk/run on terrain (not falling) Use the Avatar movement terrain contact
1052 AvatarMovementTerrainContact.geom = curContact;
1053 _perloopContact.Add(curContact);
1054 if (m_global_contactcount < maxContactsbeforedeath)
1055 {
1056 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact);
1057 m_global_contactcount++;
1058 }
1059 }
1060 else
1061 {
1062 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
1063 {
1064 //$ Av standing on terrain, Use the non moving Avata terrain contact
1065 TerrainContact.geom = curContact;
1066 _perloopContact.Add(curContact);
1067 if (m_global_contactcount < maxContactsbeforedeath)
1068 {
1069 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact);
1070 m_global_contactcount++;
1071 }
1072 }
1073 else
1074 {
1075 if (p2.PhysicsActorType == (int)ActorTypes.Prim && p1.PhysicsActorType == (int)ActorTypes.Prim)
1076 {
1077 //& THIS NEVER HAPPENS? prim prim contact In terrain contact?
1078 // int pj294950 = 0;
1079 // prim terrain contact
1080
1081 if (p2 is OdePrim)
1082 material = ((OdePrim)p2).m_material;
1083 //m_log.DebugFormat("Material: {0}", material);
1084 m_materialContacts[material, movintYN].geom = curContact;
1085 _perloopContact.Add(curContact);
1086
1087 if (m_global_contactcount < maxContactsbeforedeath)
1088 {
1089 joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
1090 m_global_contactcount++;
1091
1092 }
1093
1094 }
1095 else
1096 {
1097 //$ prim on terrain contact
1098 if (p2 is OdePrim)
1099 material = ((OdePrim)p2).m_material;
1100 //m_log.DebugFormat("Material: {0}", material);
1101 m_materialContacts[material, movintYN].geom = curContact;
1102 _perloopContact.Add(curContact);
1103
1104 ContactCopy = m_materialContacts[material, movintYN];
1105 if(movintYN == 1)
1106 {
1107 // prevent excessive slide on terrain
1108 ContactCopy.surface.mu = m_materialContacts[material, movintYN].surface.mu * 30.0f;
1109 }
1110
1111 if (m_global_contactcount < maxContactsbeforedeath)
1112 {
1113 joint = d.JointCreateContact(world, contactgroup, ref ContactCopy);
1114 m_global_contactcount++;
1115 }
1116 }
1117 }
1118 }
1119 }
1120 else if (name1 == "Water" || name2 == "Water")
1121 {
1122 //$ This never happens! Perhaps water is treated like air?
1123 /*
1124 if ((p2.PhysicsActorType == (int) ActorTypes.Prim))
1125 {
1126 }
1127 else
1128 {
1129 }
1130 */
1131 //WaterContact.surface.soft_cfm = 0.0000f;
1132 //WaterContact.surface.soft_erp = 0.00000f;
1133 if (curContact.depth > 0.1f)
1134 {
1135 curContact.depth *= 52;
1136 //AvatarStaticprimContact.normal = new d.Vector3(0, 0, 1);
1137 //AvatarStaticprimContact.pos = new d.Vector3(0, 0, contact.pos.Z - 5f);
1138 }
1139 WaterContact.geom = curContact;
1140 _perloopContact.Add(curContact);
1141 if (m_global_contactcount < maxContactsbeforedeath)
1142 {
1143 joint = d.JointCreateContact(world, contactgroup, ref WaterContact);
1144 m_global_contactcount++;
1145 }
1146 //m_log.Info("[PHYSICS]: Prim Water Contact" + AvatarStaticprimContact.depth);
1147 }
1148 else
1149 {
1150
1151 // no terrain and no water, we're colliding with prim or avatar
1152 // check if we're moving
1153 if ((p2.PhysicsActorType == (int)ActorTypes.Agent))
1154 {
1155 //$ Avatar on Prim or other Avatar
1156 if (movintYN == 1)
1157 {
1158 // Use the AV Movement / prim contact
1159 AvatarMovementprimContact.geom = curContact;
1160 _perloopContact.Add(curContact);
1161 if (m_global_contactcount < maxContactsbeforedeath)
1162 {
1163 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact);
1164 m_global_contactcount++;
1165 }
1166 }
1167 else
1168 {
1169 // Use the Av non movement / prim contact
1170 AvatarStaticprimContact.geom = curContact;
1171 _perloopContact.Add(curContact);
1172 ContactCopy = AvatarStaticprimContact; // local copy so we can change locally
1173
1174 if (m_global_contactcount < maxContactsbeforedeath)
1175 {
1176 if (curContact.depth > 0.2)
1177 { // embedded, eject slowly
1178 ContactCopy.surface.soft_erp = 0.1f;
1179 ContactCopy.surface.soft_cfm = 0.1f;
1180 }
1181 else
1182 { // keep on the surface
1183 ContactCopy.surface.soft_erp = 0.3f;
1184 ContactCopy.surface.soft_cfm = 0.0f;
1185 }
1186 joint = d.JointCreateContact(world, contactgroup, ref ContactCopy);
1187 m_global_contactcount++;
1188 }
1189 }
1190 }
1191 else if (p2.PhysicsActorType == (int)ActorTypes.Prim)
1192 {
1193 //$ Prim on Prim
1194 //p1.PhysicsActorType
1195
1196 if (p2 is OdePrim) material = ((OdePrim)p2).m_material;
1197 //m_log.DebugFormat("Material: {0}", material);
1198
1199 m_materialContacts[material, movintYN].geom = curContact;
1200 _perloopContact.Add(curContact);
1201
1202 if (m_global_contactcount < maxContactsbeforedeath)
1203 {
1204 joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
1205 m_global_contactcount++;
1206 }
1207 }
1208 }
1209
1210 if (m_global_contactcount < maxContactsbeforedeath && joint != IntPtr.Zero) // stack collide!
1211 {
1212 d.JointAttach(joint, b1, b2);
1213 m_global_contactcount++;
1214 }
1215
1216 }
1217 collision_accounting_events(p1, p2, maxDepthContact);
1218 if (count > geomContactPointsStartthrottle)
1219 {
1220 // If there are more then 3 contact points, it's likely
1221 // that we've got a pile of objects, so ...
1222 // We don't want to send out hundreds of terse updates over and over again
1223 // so lets throttle them and send them again after it's somewhat sorted out.
1224 p2.ThrottleUpdates = true;
1225 }
1226 //m_log.Debug(count.ToString());
1227 //m_log.Debug("near: A collision was detected between {1} and {2}", 0, name1, name2);
1228 } // end for i.. loop
1229 } // end near
1230
1231 private bool checkDupe(d.ContactGeom contactGeom, int atype)
1232 {
1233 bool result = false;
1234 //return result;
1235 if (!m_filterCollisions)
1236 return false;
1237
1238 ActorTypes at = (ActorTypes)atype;
1239 lock (_perloopContact)
1240 {
1241 foreach (d.ContactGeom contact in _perloopContact)
1242 {
1243 //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2))
1244 //{
1245 // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2)
1246 if (at == ActorTypes.Agent)
1247 {
1248 if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom)
1249 {
1250
1251 if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f)
1252 {
1253 //contactGeom.depth *= .00005f;
1254 //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
1255 // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z));
1256 result = true;
1257 break;
1258 }
1259 else
1260 {
1261 //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
1262 }
1263 }
1264 else
1265 {
1266 //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z));
1267 //int i = 0;
1268 }
1269 }
1270 else if (at == ActorTypes.Prim)
1271 {
1272 //d.AABB aabb1 = new d.AABB();
1273 //d.AABB aabb2 = new d.AABB();
1274
1275 //d.GeomGetAABB(contactGeom.g2, out aabb2);
1276 //d.GeomGetAABB(contactGeom.g1, out aabb1);
1277 //aabb1.
1278 if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom)
1279 {
1280 if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z)
1281 {
1282 if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f)
1283 {
1284 result = true;
1285 break;
1286 }
1287 }
1288 //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
1289 //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z));
1290 }
1291
1292 }
1293
1294 //}
1295
1296 }
1297 }
1298 return result;
1299 }
1300
1301 private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact)
1302 {
1303 // obj1LocalID = 0;
1304 //returncollisions = false;
1305 obj2LocalID = 0;
1306 //ctype = 0;
1307 //cStartStop = 0;
1308 if (!p2.SubscribedEvents() && !p1.SubscribedEvents())
1309 return;
1310
1311 switch ((ActorTypes)p2.PhysicsActorType)
1312 {
1313 case ActorTypes.Agent:
1314 cc2 = (OdeCharacter)p2;
1315
1316 // obj1LocalID = cc2.m_localID;
1317 switch ((ActorTypes)p1.PhysicsActorType)
1318 {
1319 case ActorTypes.Agent:
1320 cc1 = (OdeCharacter)p1;
1321 obj2LocalID = cc1.m_localID;
1322 cc1.AddCollisionEvent(cc2.m_localID, contact);
1323 //ctype = (int)CollisionCategories.Character;
1324
1325 //if (cc1.CollidingObj)
1326 //cStartStop = (int)StatusIndicators.Generic;
1327 //else
1328 //cStartStop = (int)StatusIndicators.Start;
1329
1330 //returncollisions = true;
1331 break;
1332 case ActorTypes.Prim:
1333 if (p1 is OdePrim)
1334 {
1335 cp1 = (OdePrim) p1;
1336 obj2LocalID = cp1.m_localID;
1337 cp1.AddCollisionEvent(cc2.m_localID, contact);
1338 }
1339 //ctype = (int)CollisionCategories.Geom;
1340
1341 //if (cp1.CollidingObj)
1342 //cStartStop = (int)StatusIndicators.Generic;
1343 //else
1344 //cStartStop = (int)StatusIndicators.Start;
1345
1346 //returncollisions = true;
1347 break;
1348
1349 case ActorTypes.Ground:
1350 case ActorTypes.Unknown:
1351 obj2LocalID = 0;
1352 //ctype = (int)CollisionCategories.Land;
1353 //returncollisions = true;
1354 break;
1355 }
1356
1357 cc2.AddCollisionEvent(obj2LocalID, contact);
1358 break;
1359 case ActorTypes.Prim:
1360
1361 if (p2 is OdePrim)
1362 {
1363 cp2 = (OdePrim) p2;
1364
1365 // obj1LocalID = cp2.m_localID;
1366 switch ((ActorTypes) p1.PhysicsActorType)
1367 {
1368 case ActorTypes.Agent:
1369 if (p1 is OdeCharacter)
1370 {
1371 cc1 = (OdeCharacter) p1;
1372 obj2LocalID = cc1.m_localID;
1373 cc1.AddCollisionEvent(cp2.m_localID, contact);
1374 //ctype = (int)CollisionCategories.Character;
1375
1376 //if (cc1.CollidingObj)
1377 //cStartStop = (int)StatusIndicators.Generic;
1378 //else
1379 //cStartStop = (int)StatusIndicators.Start;
1380 //returncollisions = true;
1381 }
1382 break;
1383 case ActorTypes.Prim:
1384
1385 if (p1 is OdePrim)
1386 {
1387 cp1 = (OdePrim) p1;
1388 obj2LocalID = cp1.m_localID;
1389 cp1.AddCollisionEvent(cp2.m_localID, contact);
1390 //ctype = (int)CollisionCategories.Geom;
1391
1392 //if (cp1.CollidingObj)
1393 //cStartStop = (int)StatusIndicators.Generic;
1394 //else
1395 //cStartStop = (int)StatusIndicators.Start;
1396
1397 //returncollisions = true;
1398 }
1399 break;
1400
1401 case ActorTypes.Ground:
1402 case ActorTypes.Unknown:
1403 obj2LocalID = 0;
1404 //ctype = (int)CollisionCategories.Land;
1405
1406 //returncollisions = true;
1407 break;
1408 }
1409
1410 cp2.AddCollisionEvent(obj2LocalID, contact);
1411 }
1412 break;
1413 }
1414 //if (returncollisions)
1415 //{
1416
1417 //lock (m_storedCollisions)
1418 //{
1419 //cDictKey = obj1LocalID.ToString() + obj2LocalID.ToString() + cStartStop.ToString() + ctype.ToString();
1420 //if (m_storedCollisions.ContainsKey(cDictKey))
1421 //{
1422 //sCollisionData objd = m_storedCollisions[cDictKey];
1423 //objd.NumberOfCollisions += 1;
1424 //objd.lastframe = framecount;
1425 //m_storedCollisions[cDictKey] = objd;
1426 //}
1427 //else
1428 //{
1429 //sCollisionData objd = new sCollisionData();
1430 //objd.ColliderLocalId = obj1LocalID;
1431 //objd.CollidedWithLocalId = obj2LocalID;
1432 //objd.CollisionType = ctype;
1433 //objd.NumberOfCollisions = 1;
1434 //objd.lastframe = framecount;
1435 //objd.StatusIndicator = cStartStop;
1436 //m_storedCollisions.Add(cDictKey, objd);
1437 //}
1438 //}
1439 // }
1440 }
1441
1442 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
1443 {
1444 /* String name1 = null;
1445 String name2 = null;
1446
1447 if (!geom_name_map.TryGetValue(trimesh, out name1))
1448 {
1449 name1 = "null";
1450 }
1451 if (!geom_name_map.TryGetValue(refObject, out name2))
1452 {
1453 name2 = "null";
1454 }
1455
1456 m_log.InfoFormat("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2);
1457 */
1458 return 1;
1459 }
1460
1461 public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
1462 {
1463 String name1 = null;
1464 String name2 = null;
1465
1466 if (!geom_name_map.TryGetValue(trimesh, out name1))
1467 {
1468 name1 = "null";
1469 }
1470
1471 if (!geom_name_map.TryGetValue(refObject, out name2))
1472 {
1473 name2 = "null";
1474 }
1475
1476 // m_log.InfoFormat("TriCallback: A collision was detected between {1} and {2}. Index was {3}", 0, name1, name2, triangleIndex);
1477
1478 d.Vector3 v0 = new d.Vector3();
1479 d.Vector3 v1 = new d.Vector3();
1480 d.Vector3 v2 = new d.Vector3();
1481
1482 d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2);
1483 // m_log.DebugFormat("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
1484
1485 return 1;
1486 }
1487
1488 /// <summary>
1489 /// This is our collision testing routine in ODE
1490 /// </summary>
1491 /// <param name="timeStep"></param>
1492 private void collision_optimized(float timeStep)
1493 {
1494 _perloopContact.Clear();
1495
1496 lock (_characters)
1497 {
1498 foreach (OdeCharacter chr in _characters)
1499 {
1500 // Reset the collision values to false
1501 // since we don't know if we're colliding yet
1502
1503 // For some reason this can happen. Don't ask...
1504 //
1505 if (chr == null)
1506 continue;
1507
1508 if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero)
1509 continue;
1510
1511 chr.IsColliding = false;
1512 chr.CollidingGround = false;
1513 chr.CollidingObj = false;
1514
1515 // test the avatar's geometry for collision with the space
1516 // This will return near and the space that they are the closest to
1517 // And we'll run this again against the avatar and the space segment
1518 // This will return with a bunch of possible objects in the space segment
1519 // and we'll run it again on all of them.
1520 try
1521 {
1522 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
1523 }
1524 catch (AccessViolationException)
1525 {
1526 m_log.Warn("[PHYSICS]: Unable to space collide");
1527 }
1528 //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y);
1529 //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10)
1530 //{
1531 //chr.Position.Z = terrainheight + 10.0f;
1532 //forcedZ = true;
1533 //}
1534 }
1535 }
1536
1537 lock (_activeprims)
1538 {
1539 List<OdePrim> removeprims = null;
1540 foreach (OdePrim chr in _activeprims)
1541 {
1542 if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled) && !chr.m_outofBounds)
1543 {
1544 try
1545 {
1546 lock (chr)
1547 {
1548 if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false)
1549 {
1550 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback);
1551 }
1552 else
1553 {
1554 if (removeprims == null)
1555 {
1556 removeprims = new List<OdePrim>();
1557 }
1558 removeprims.Add(chr);
1559 /// Commented this because it triggers on every bullet
1560 //m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!");
1561 }
1562 }
1563 }
1564 catch (AccessViolationException)
1565 {
1566 m_log.Warn("[PHYSICS]: Unable to space collide");
1567 }
1568 }
1569 }
1570 if (removeprims != null)
1571 {
1572 foreach (OdePrim chr in removeprims)
1573 {
1574 _activeprims.Remove(chr);
1575 }
1576 }
1577 }
1578
1579 _perloopContact.Clear();
1580 }
1581
1582 #endregion
1583
1584 public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
1585 {
1586 m_worldOffset = offset;
1587 WorldExtents = new Vector2(extents.X, extents.Y);
1588 m_parentScene = pScene;
1589
1590 }
1591
1592 // Recovered for use by fly height. Kitto Flora
1593 public float GetTerrainHeightAtXY(float x, float y)
1594 {
1595
1596 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1597 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1598
1599 IntPtr heightFieldGeom = IntPtr.Zero;
1600
1601 if (RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom))
1602 {
1603 if (heightFieldGeom != IntPtr.Zero)
1604 {
1605 if (TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
1606 {
1607
1608 int index;
1609
1610
1611 if ((int)x > WorldExtents.X || (int)y > WorldExtents.Y ||
1612 (int)x < 0.001f || (int)y < 0.001f)
1613 return 0;
1614
1615 x = x - offsetX;
1616 y = y - offsetY;
1617
1618 index = (int)((int)x * ((int)Constants.RegionSize + 2) + (int)y);
1619
1620 if (index < TerrainHeightFieldHeights[heightFieldGeom].Length)
1621 {
1622 //m_log.DebugFormat("x{0} y{1} = {2}", x, y, (float)TerrainHeightFieldHeights[heightFieldGeom][index]);
1623 return (float)TerrainHeightFieldHeights[heightFieldGeom][index];
1624 }
1625
1626 else
1627 return 0f;
1628 }
1629 else
1630 {
1631 return 0f;
1632 }
1633
1634 }
1635 else
1636 {
1637 return 0f;
1638 }
1639
1640 }
1641 else
1642 {
1643 return 0f;
1644 }
1645
1646
1647 }
1648// End recovered. Kitto Flora
1649
1650 public void addCollisionEventReporting(PhysicsActor obj)
1651 {
1652 lock (_collisionEventPrim)
1653 {
1654 if (!_collisionEventPrim.Contains(obj))
1655 _collisionEventPrim.Add(obj);
1656 }
1657 }
1658
1659 public void remCollisionEventReporting(PhysicsActor obj)
1660 {
1661 lock (_collisionEventPrim)
1662 {
1663 if (!_collisionEventPrim.Contains(obj))
1664 _collisionEventPrim.Remove(obj);
1665 }
1666 }
1667
1668 #region Add/Remove Entities
1669
1670 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
1671 {
1672 Vector3 pos;
1673 pos.X = position.X;
1674 pos.Y = position.Y;
1675 pos.Z = position.Z;
1676 OdeCharacter newAv = new OdeCharacter(avName, this, pos, ode, size, avPIDD, avPIDP, avCapRadius, avStandupTensor, avDensity, avHeightFudgeFactor, avMovementDivisorWalk, avMovementDivisorRun);
1677 newAv.Flying = isFlying;
1678 newAv.MinimumGroundFlightOffset = minimumGroundFlightOffset;
1679
1680 return newAv;
1681 }
1682
1683 public void AddCharacter(OdeCharacter chr)
1684 {
1685 lock (_characters)
1686 {
1687 if (!_characters.Contains(chr))
1688 {
1689 _characters.Add(chr);
1690 if (chr.bad)
1691 m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid);
1692 }
1693 }
1694 }
1695
1696 public void RemoveCharacter(OdeCharacter chr)
1697 {
1698 lock (_characters)
1699 {
1700 if (_characters.Contains(chr))
1701 {
1702 _characters.Remove(chr);
1703 }
1704 }
1705 }
1706 public void BadCharacter(OdeCharacter chr)
1707 {
1708 lock (_badCharacter)
1709 {
1710 if (!_badCharacter.Contains(chr))
1711 _badCharacter.Add(chr);
1712 }
1713 }
1714
1715 public override void RemoveAvatar(PhysicsActor actor)
1716 {
1717 //m_log.Debug("[PHYSICS]:ODELOCK");
1718 ((OdeCharacter) actor).Destroy();
1719
1720 }
1721
1722 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1723 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical, bool isphantom, byte shapetype, uint localid)
1724 {
1725
1726 Vector3 pos = position;
1727 Vector3 siz = size;
1728 Quaternion rot = rotation;
1729
1730 OdePrim newPrim;
1731 lock (OdeLock)
1732 {
1733 newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, isphantom, shapetype, ode, localid);
1734
1735 lock (_prims)
1736 _prims.Add(newPrim);
1737 }
1738
1739 return newPrim;
1740 }
1741
1742
1743 public void addActivePrim(OdePrim activatePrim)
1744 {
1745 // adds active prim.. (ones that should be iterated over in collisions_optimized
1746 lock (_activeprims)
1747 {
1748 if (!_activeprims.Contains(activatePrim))
1749 _activeprims.Add(activatePrim);
1750 //else
1751 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
1752 }
1753 }
1754
1755 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1756 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
1757 {
1758 PhysicsActor result;
1759 IMesh mesh = null;
1760
1761 if (needsMeshing(pbs))
1762 mesh = mesher.CreateMesh(primName, pbs, size, (int)LevelOfDetail.High, true);
1763
1764 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical,false,0, localid);
1765
1766 return result;
1767 }
1768
1769 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1770 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, uint localid)
1771 {
1772 PhysicsActor result;
1773 IMesh mesh = null;
1774
1775 if (needsMeshing(pbs))
1776 mesh = mesher.CreateMesh(primName, pbs, size, (int)LevelOfDetail.High, true);
1777
1778 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, isPhantom,0, localid);
1779
1780 return result;
1781 }
1782
1783 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1784 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid)
1785 {
1786 PhysicsActor result;
1787 IMesh mesh = null;
1788
1789 if (needsMeshing(pbs))
1790 mesh = mesher.CreateMesh(primName, pbs, size, (int)LevelOfDetail.High, true);
1791
1792 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, isPhantom, shapetype, localid);
1793
1794 return result;
1795 }
1796
1797 public override float TimeDilation
1798 {
1799 get { return m_timeDilation; }
1800 }
1801
1802 public override bool SupportsNINJAJoints
1803 {
1804 get { return m_NINJA_physics_joints_enabled; }
1805 }
1806
1807 // internal utility function: must be called within a lock (OdeLock)
1808 private void InternalAddActiveJoint(PhysicsJoint joint)
1809 {
1810 activeJoints.Add(joint);
1811 SOPName_to_activeJoint.Add(joint.ObjectNameInScene, joint);
1812 }
1813
1814 // internal utility function: must be called within a lock (OdeLock)
1815 private void InternalAddPendingJoint(OdePhysicsJoint joint)
1816 {
1817 pendingJoints.Add(joint);
1818 SOPName_to_pendingJoint.Add(joint.ObjectNameInScene, joint);
1819 }
1820
1821 // internal utility function: must be called within a lock (OdeLock)
1822 private void InternalRemovePendingJoint(PhysicsJoint joint)
1823 {
1824 pendingJoints.Remove(joint);
1825 SOPName_to_pendingJoint.Remove(joint.ObjectNameInScene);
1826 }
1827
1828 // internal utility function: must be called within a lock (OdeLock)
1829 private void InternalRemoveActiveJoint(PhysicsJoint joint)
1830 {
1831 activeJoints.Remove(joint);
1832 SOPName_to_activeJoint.Remove(joint.ObjectNameInScene);
1833 }
1834
1835 public override void DumpJointInfo()
1836 {
1837 string hdr = "[NINJA] JOINTINFO: ";
1838 foreach (PhysicsJoint j in pendingJoints)
1839 {
1840 m_log.Debug(hdr + " pending joint, Name: " + j.ObjectNameInScene + " raw parms:" + j.RawParams);
1841 }
1842 m_log.Debug(hdr + pendingJoints.Count + " total pending joints");
1843 foreach (string jointName in SOPName_to_pendingJoint.Keys)
1844 {
1845 m_log.Debug(hdr + " pending joints dict contains Name: " + jointName);
1846 }
1847 m_log.Debug(hdr + SOPName_to_pendingJoint.Keys.Count + " total pending joints dict entries");
1848 foreach (PhysicsJoint j in activeJoints)
1849 {
1850 m_log.Debug(hdr + " active joint, Name: " + j.ObjectNameInScene + " raw parms:" + j.RawParams);
1851 }
1852 m_log.Debug(hdr + activeJoints.Count + " total active joints");
1853 foreach (string jointName in SOPName_to_activeJoint.Keys)
1854 {
1855 m_log.Debug(hdr + " active joints dict contains Name: " + jointName);
1856 }
1857 m_log.Debug(hdr + SOPName_to_activeJoint.Keys.Count + " total active joints dict entries");
1858
1859 m_log.Debug(hdr + " Per-body joint connectivity information follows.");
1860 m_log.Debug(hdr + joints_connecting_actor.Keys.Count + " bodies are connected by joints.");
1861 foreach (string actorName in joints_connecting_actor.Keys)
1862 {
1863 m_log.Debug(hdr + " Actor " + actorName + " has the following joints connecting it");
1864 foreach (PhysicsJoint j in joints_connecting_actor[actorName])
1865 {
1866 m_log.Debug(hdr + " * joint Name: " + j.ObjectNameInScene + " raw parms:" + j.RawParams);
1867 }
1868 m_log.Debug(hdr + joints_connecting_actor[actorName].Count + " connecting joints total for this actor");
1869 }
1870 }
1871
1872 public override void RequestJointDeletion(string ObjectNameInScene)
1873 {
1874 lock (externalJointRequestsLock)
1875 {
1876 if (!requestedJointsToBeDeleted.Contains(ObjectNameInScene)) // forbid same deletion request from entering twice to prevent spurious deletions processed asynchronously
1877 {
1878 requestedJointsToBeDeleted.Add(ObjectNameInScene);
1879 }
1880 }
1881 }
1882
1883 private void DeleteRequestedJoints()
1884 {
1885 List<string> myRequestedJointsToBeDeleted;
1886 lock (externalJointRequestsLock)
1887 {
1888 // make a local copy of the shared list for processing (threading issues)
1889 myRequestedJointsToBeDeleted = new List<string>(requestedJointsToBeDeleted);
1890 }
1891
1892 foreach (string jointName in myRequestedJointsToBeDeleted)
1893 {
1894 lock (OdeLock)
1895 {
1896 //m_log.Debug("[NINJA] trying to deleting requested joint " + jointName);
1897 if (SOPName_to_activeJoint.ContainsKey(jointName) || SOPName_to_pendingJoint.ContainsKey(jointName))
1898 {
1899 OdePhysicsJoint joint = null;
1900 if (SOPName_to_activeJoint.ContainsKey(jointName))
1901 {
1902 joint = SOPName_to_activeJoint[jointName] as OdePhysicsJoint;
1903 InternalRemoveActiveJoint(joint);
1904 }
1905 else if (SOPName_to_pendingJoint.ContainsKey(jointName))
1906 {
1907 joint = SOPName_to_pendingJoint[jointName] as OdePhysicsJoint;
1908 InternalRemovePendingJoint(joint);
1909 }
1910
1911 if (joint != null)
1912 {
1913 //m_log.Debug("joint.BodyNames.Count is " + joint.BodyNames.Count + " and contents " + joint.BodyNames);
1914 for (int iBodyName = 0; iBodyName < 2; iBodyName++)
1915 {
1916 string bodyName = joint.BodyNames[iBodyName];
1917 if (bodyName != "NULL")
1918 {
1919 joints_connecting_actor[bodyName].Remove(joint);
1920 if (joints_connecting_actor[bodyName].Count == 0)
1921 {
1922 joints_connecting_actor.Remove(bodyName);
1923 }
1924 }
1925 }
1926
1927 DoJointDeactivated(joint);
1928 if (joint.jointID != IntPtr.Zero)
1929 {
1930 d.JointDestroy(joint.jointID);
1931 joint.jointID = IntPtr.Zero;
1932 //DoJointErrorMessage(joint, "successfully destroyed joint " + jointName);
1933 }
1934 else
1935 {
1936 //m_log.Warn("[NINJA] Ignoring re-request to destroy joint " + jointName);
1937 }
1938 }
1939 else
1940 {
1941 // DoJointErrorMessage(joint, "coult not find joint to destroy based on name " + jointName);
1942 }
1943 }
1944 else
1945 {
1946 // DoJointErrorMessage(joint, "WARNING - joint removal failed, joint " + jointName);
1947 }
1948 }
1949 }
1950
1951 // remove processed joints from the shared list
1952 lock (externalJointRequestsLock)
1953 {
1954 foreach (string jointName in myRequestedJointsToBeDeleted)
1955 {
1956 requestedJointsToBeDeleted.Remove(jointName);
1957 }
1958 }
1959 }
1960
1961 // for pending joints we don't know if their associated bodies exist yet or not.
1962 // the joint is actually created during processing of the taints
1963 private void CreateRequestedJoints()
1964 {
1965 List<PhysicsJoint> myRequestedJointsToBeCreated;
1966 lock (externalJointRequestsLock)
1967 {
1968 // make a local copy of the shared list for processing (threading issues)
1969 myRequestedJointsToBeCreated = new List<PhysicsJoint>(requestedJointsToBeCreated);
1970 }
1971
1972 foreach (PhysicsJoint joint in myRequestedJointsToBeCreated)
1973 {
1974 lock (OdeLock)
1975 {
1976 if (SOPName_to_pendingJoint.ContainsKey(joint.ObjectNameInScene) && SOPName_to_pendingJoint[joint.ObjectNameInScene] != null)
1977 {
1978 DoJointErrorMessage(joint, "WARNING: ignoring request to re-add already pending joint Name:" + joint.ObjectNameInScene + " type:" + joint.Type + " parms: " + joint.RawParams + " pos: " + joint.Position + " rot:" + joint.Rotation);
1979 continue;
1980 }
1981 if (SOPName_to_activeJoint.ContainsKey(joint.ObjectNameInScene) && SOPName_to_activeJoint[joint.ObjectNameInScene] != null)
1982 {
1983 DoJointErrorMessage(joint, "WARNING: ignoring request to re-add already active joint Name:" + joint.ObjectNameInScene + " type:" + joint.Type + " parms: " + joint.RawParams + " pos: " + joint.Position + " rot:" + joint.Rotation);
1984 continue;
1985 }
1986
1987 InternalAddPendingJoint(joint as OdePhysicsJoint);
1988
1989 if (joint.BodyNames.Count >= 2)
1990 {
1991 for (int iBodyName = 0; iBodyName < 2; iBodyName++)
1992 {
1993 string bodyName = joint.BodyNames[iBodyName];
1994 if (bodyName != "NULL")
1995 {
1996 if (!joints_connecting_actor.ContainsKey(bodyName))
1997 {
1998 joints_connecting_actor.Add(bodyName, new List<PhysicsJoint>());
1999 }
2000 joints_connecting_actor[bodyName].Add(joint);
2001 }
2002 }
2003 }
2004 }
2005 }
2006
2007 // remove processed joints from shared list
2008 lock (externalJointRequestsLock)
2009 {
2010 foreach (PhysicsJoint joint in myRequestedJointsToBeCreated)
2011 {
2012 requestedJointsToBeCreated.Remove(joint);
2013 }
2014 }
2015
2016 }
2017
2018 // public function to add an request for joint creation
2019 // this joint will just be added to a waiting list that is NOT processed during the main
2020 // Simulate() loop (to avoid deadlocks). After Simulate() is finished, we handle unprocessed joint requests.
2021
2022 public override PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position,
2023 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation)
2024
2025 {
2026
2027 OdePhysicsJoint joint = new OdePhysicsJoint();
2028 joint.ObjectNameInScene = objectNameInScene;
2029 joint.Type = jointType;
2030 joint.Position = position;
2031 joint.Rotation = rotation;
2032 joint.RawParams = parms;
2033 joint.BodyNames = new List<string>(bodyNames);
2034 joint.TrackedBodyName = trackedBodyName;
2035 joint.LocalRotation = localRotation;
2036 joint.jointID = IntPtr.Zero;
2037 joint.ErrorMessageCount = 0;
2038
2039 lock (externalJointRequestsLock)
2040 {
2041 if (!requestedJointsToBeCreated.Contains(joint)) // forbid same creation request from entering twice
2042 {
2043 requestedJointsToBeCreated.Add(joint);
2044 }
2045 }
2046 return joint;
2047 }
2048
2049 private void RemoveAllJointsConnectedToActor(PhysicsActor actor)
2050 {
2051 //m_log.Debug("RemoveAllJointsConnectedToActor: start");
2052 if (actor.SOPName != null && joints_connecting_actor.ContainsKey(actor.SOPName) && joints_connecting_actor[actor.SOPName] != null)
2053 {
2054
2055 List<PhysicsJoint> jointsToRemove = new List<PhysicsJoint>();
2056 //TODO: merge these 2 loops (originally it was needed to avoid altering a list being iterated over, but it is no longer needed due to the joint request queue mechanism)
2057 foreach (PhysicsJoint j in joints_connecting_actor[actor.SOPName])
2058 {
2059 jointsToRemove.Add(j);
2060 }
2061 foreach (PhysicsJoint j in jointsToRemove)
2062 {
2063 //m_log.Debug("RemoveAllJointsConnectedToActor: about to request deletion of " + j.ObjectNameInScene);
2064 RequestJointDeletion(j.ObjectNameInScene);
2065 //m_log.Debug("RemoveAllJointsConnectedToActor: done request deletion of " + j.ObjectNameInScene);
2066 j.TrackedBodyName = null; // *IMMEDIATELY* prevent any further movement of this joint (else a deleted actor might cause spurious tracking motion of the joint for a few frames, leading to the joint proxy object disappearing)
2067 }
2068 }
2069 }
2070
2071 public override void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor)
2072 {
2073 //m_log.Debug("RemoveAllJointsConnectedToActorThreadLocked: start");
2074 lock (OdeLock)
2075 {
2076 //m_log.Debug("RemoveAllJointsConnectedToActorThreadLocked: got lock");
2077 RemoveAllJointsConnectedToActor(actor);
2078 }
2079 }
2080
2081 // normally called from within OnJointMoved, which is called from within a lock (OdeLock)
2082 public override Vector3 GetJointAnchor(PhysicsJoint joint)
2083 {
2084 Debug.Assert(joint.IsInPhysicsEngine);
2085 d.Vector3 pos = new d.Vector3();
2086
2087 if (!(joint is OdePhysicsJoint))
2088 {
2089 DoJointErrorMessage(joint, "warning: non-ODE joint requesting anchor: " + joint.ObjectNameInScene);
2090 }
2091 else
2092 {
2093 OdePhysicsJoint odeJoint = (OdePhysicsJoint)joint;
2094 switch (odeJoint.Type)
2095 {
2096 case PhysicsJointType.Ball:
2097 d.JointGetBallAnchor(odeJoint.jointID, out pos);
2098 break;
2099 case PhysicsJointType.Hinge:
2100 d.JointGetHingeAnchor(odeJoint.jointID, out pos);
2101 break;
2102 }
2103 }
2104 return new Vector3(pos.X, pos.Y, pos.Z);
2105 }
2106
2107 // normally called from within OnJointMoved, which is called from within a lock (OdeLock)
2108 // WARNING: ODE sometimes returns <0,0,0> as the joint axis! Therefore this function
2109 // appears to be unreliable. Fortunately we can compute the joint axis ourselves by
2110 // keeping track of the joint's original orientation relative to one of the involved bodies.
2111 public override Vector3 GetJointAxis(PhysicsJoint joint)
2112 {
2113 Debug.Assert(joint.IsInPhysicsEngine);
2114 d.Vector3 axis = new d.Vector3();
2115
2116 if (!(joint is OdePhysicsJoint))
2117 {
2118 DoJointErrorMessage(joint, "warning: non-ODE joint requesting anchor: " + joint.ObjectNameInScene);
2119 }
2120 else
2121 {
2122 OdePhysicsJoint odeJoint = (OdePhysicsJoint)joint;
2123 switch (odeJoint.Type)
2124 {
2125 case PhysicsJointType.Ball:
2126 DoJointErrorMessage(joint, "warning - axis requested for ball joint: " + joint.ObjectNameInScene);
2127 break;
2128 case PhysicsJointType.Hinge:
2129 d.JointGetHingeAxis(odeJoint.jointID, out axis);
2130 break;
2131 }
2132 }
2133 return new Vector3(axis.X, axis.Y, axis.Z);
2134 }
2135
2136
2137 public void remActivePrim(OdePrim deactivatePrim)
2138 {
2139 lock (_activeprims)
2140 {
2141 _activeprims.Remove(deactivatePrim);
2142 }
2143 }
2144
2145 public override void RemovePrim(PhysicsActor prim)
2146 {
2147 if (prim is OdePrim)
2148 {
2149 lock (OdeLock)
2150 {
2151 OdePrim p = (OdePrim) prim;
2152
2153 p.setPrimForRemoval();
2154 AddPhysicsActorTaint(prim);
2155 //RemovePrimThreadLocked(p);
2156 }
2157 }
2158 }
2159
2160 /// <summary>
2161 /// This is called from within simulate but outside the locked portion
2162 /// We need to do our own locking here
2163 /// Essentially, we need to remove the prim from our space segment, whatever segment it's in.
2164 ///
2165 /// If there are no more prim in the segment, we need to empty (spacedestroy)the segment and reclaim memory
2166 /// that the space was using.
2167 /// </summary>
2168 /// <param name="prim"></param>
2169 public void RemovePrimThreadLocked(OdePrim prim)
2170 {
2171//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
2172 lock (prim)
2173 {
2174 remCollisionEventReporting(prim);
2175 lock (ode)
2176 {
2177 if (prim.prim_geom != IntPtr.Zero)
2178 {
2179 prim.ResetTaints();
2180
2181 try
2182 {
2183 if (prim._triMeshData != IntPtr.Zero)
2184 {
2185 d.GeomTriMeshDataDestroy(prim._triMeshData);
2186 prim._triMeshData = IntPtr.Zero;
2187 }
2188 }
2189 catch { };
2190
2191 if (prim.IsPhysical)
2192 {
2193 prim.disableBody();
2194 if (prim.childPrim)
2195 {
2196 prim.childPrim = false;
2197 prim.Body = IntPtr.Zero;
2198 prim.m_disabled = true;
2199 prim.IsPhysical = false;
2200 }
2201
2202 }
2203 // we don't want to remove the main space
2204
2205 // If the geometry is in the targetspace, remove it from the target space
2206 //m_log.Warn(prim.m_targetSpace);
2207
2208 //if (prim.m_targetSpace != IntPtr.Zero)
2209 //{
2210 //if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
2211 //{
2212
2213 //if (d.GeomIsSpace(prim.m_targetSpace))
2214 //{
2215 //waitForSpaceUnlock(prim.m_targetSpace);
2216 //d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
2217 prim.m_targetSpace = IntPtr.Zero;
2218 //}
2219 //else
2220 //{
2221 // m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
2222 //((OdePrim)prim).m_targetSpace.ToString());
2223 //}
2224
2225 //}
2226 //}
2227 //m_log.Warn(prim.prim_geom);
2228 try
2229 {
2230 if (prim.prim_geom != IntPtr.Zero)
2231 {
2232
2233//string tPA;
2234//geom_name_map.TryGetValue(prim.prim_geom, out tPA);
2235//Console.WriteLine("**** Remove {0}", tPA);
2236 if(geom_name_map.ContainsKey(prim.prim_geom)) geom_name_map.Remove(prim.prim_geom);
2237 if(actor_name_map.ContainsKey(prim.prim_geom)) actor_name_map.Remove(prim.prim_geom);
2238 d.GeomDestroy(prim.prim_geom);
2239 prim.prim_geom = IntPtr.Zero;
2240 }
2241 else
2242 {
2243 m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene");
2244 }
2245 }
2246 catch (AccessViolationException)
2247 {
2248 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed.");
2249 }
2250 lock (_prims)
2251 _prims.Remove(prim);
2252
2253 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
2254 //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
2255 //{
2256 //if (prim.m_targetSpace != null)
2257 //{
2258 //if (d.GeomIsSpace(prim.m_targetSpace))
2259 //{
2260 //waitForSpaceUnlock(prim.m_targetSpace);
2261 //d.SpaceRemove(space, prim.m_targetSpace);
2262 // free up memory used by the space.
2263 //d.SpaceDestroy(prim.m_targetSpace);
2264 //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
2265 //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
2266 //}
2267 //else
2268 //{
2269 //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
2270 //((OdePrim) prim).m_targetSpace.ToString());
2271 //}
2272 //}
2273 //}
2274
2275 if (SupportsNINJAJoints)
2276 {
2277 RemoveAllJointsConnectedToActorThreadLocked(prim);
2278 }
2279 }
2280 }
2281 }
2282 }
2283
2284 #endregion
2285
2286 #region Space Separation Calculation
2287
2288 /// <summary>
2289 /// Takes a space pointer and zeros out the array we're using to hold the spaces
2290 /// </summary>
2291 /// <param name="pSpace"></param>
2292 public void resetSpaceArrayItemToZero(IntPtr pSpace)
2293 {
2294 for (int x = 0; x < staticPrimspace.GetLength(0); x++)
2295 {
2296 for (int y = 0; y < staticPrimspace.GetLength(1); y++)
2297 {
2298 if (staticPrimspace[x, y] == pSpace)
2299 staticPrimspace[x, y] = IntPtr.Zero;
2300 }
2301 }
2302 }
2303
2304 public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY)
2305 {
2306 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
2307 }
2308
2309 /// <summary>
2310 /// Called when a static prim moves. Allocates a space for the prim based on its position
2311 /// </summary>
2312 /// <param name="geom">the pointer to the geom that moved</param>
2313 /// <param name="pos">the position that the geom moved to</param>
2314 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
2315 /// <returns>a pointer to the new space it's in</returns>
2316 public IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace)
2317 {
2318 // Called from setting the Position and Size of an ODEPrim so
2319 // it's already in locked space.
2320
2321 // we don't want to remove the main space
2322 // we don't need to test physical here because this function should
2323 // never be called if the prim is physical(active)
2324
2325 // All physical prim end up in the root space
2326 //Thread.Sleep(20);
2327 if (currentspace != space)
2328 {
2329 //m_log.Info("[SPACE]: C:" + currentspace.ToString() + " g:" + geom.ToString());
2330 //if (currentspace == IntPtr.Zero)
2331 //{
2332 //int adfadf = 0;
2333 //}
2334 if (d.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero)
2335 {
2336 if (d.GeomIsSpace(currentspace))
2337 {
2338 waitForSpaceUnlock(currentspace);
2339 d.SpaceRemove(currentspace, geom);
2340 }
2341 else
2342 {
2343 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + currentspace +
2344 " Geom:" + geom);
2345 }
2346 }
2347 else
2348 {
2349 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
2350 if (sGeomIsIn != IntPtr.Zero)
2351 {
2352 if (d.GeomIsSpace(currentspace))
2353 {
2354 waitForSpaceUnlock(sGeomIsIn);
2355 d.SpaceRemove(sGeomIsIn, geom);
2356 }
2357 else
2358 {
2359 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
2360 sGeomIsIn + " Geom:" + geom);
2361 }
2362 }
2363 }
2364
2365 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
2366 if (d.SpaceGetNumGeoms(currentspace) == 0)
2367 {
2368 if (currentspace != IntPtr.Zero)
2369 {
2370 if (d.GeomIsSpace(currentspace))
2371 {
2372 waitForSpaceUnlock(currentspace);
2373 waitForSpaceUnlock(space);
2374 d.SpaceRemove(space, currentspace);
2375 // free up memory used by the space.
2376
2377 //d.SpaceDestroy(currentspace);
2378 resetSpaceArrayItemToZero(currentspace);
2379 }
2380 else
2381 {
2382 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
2383 currentspace + " Geom:" + geom);
2384 }
2385 }
2386 }
2387 }
2388 else
2389 {
2390 // this is a physical object that got disabled. ;.;
2391 if (currentspace != IntPtr.Zero && geom != IntPtr.Zero)
2392 {
2393 if (d.SpaceQuery(currentspace, geom))
2394 {
2395 if (d.GeomIsSpace(currentspace))
2396 {
2397 waitForSpaceUnlock(currentspace);
2398 d.SpaceRemove(currentspace, geom);
2399 }
2400 else
2401 {
2402 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
2403 currentspace + " Geom:" + geom);
2404 }
2405 }
2406 else
2407 {
2408 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
2409 if (sGeomIsIn != IntPtr.Zero)
2410 {
2411 if (d.GeomIsSpace(sGeomIsIn))
2412 {
2413 waitForSpaceUnlock(sGeomIsIn);
2414 d.SpaceRemove(sGeomIsIn, geom);
2415 }
2416 else
2417 {
2418 m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" +
2419 sGeomIsIn + " Geom:" + geom);
2420 }
2421 }
2422 }
2423 }
2424 }
2425
2426 // The routines in the Position and Size sections do the 'inserting' into the space,
2427 // so all we have to do is make sure that the space that we're putting the prim into
2428 // is in the 'main' space.
2429 int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos);
2430 IntPtr newspace = calculateSpaceForGeom(pos);
2431
2432 if (newspace == IntPtr.Zero)
2433 {
2434 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
2435 d.HashSpaceSetLevels(newspace, smallHashspaceLow, smallHashspaceHigh);
2436 }
2437
2438 return newspace;
2439 }
2440
2441 /// <summary>
2442 /// Creates a new space at X Y
2443 /// </summary>
2444 /// <param name="iprimspaceArrItemX"></param>
2445 /// <param name="iprimspaceArrItemY"></param>
2446 /// <returns>A pointer to the created space</returns>
2447 public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
2448 {
2449 // creating a new space for prim and inserting it into main space.
2450 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero);
2451 d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space);
2452 waitForSpaceUnlock(space);
2453 d.SpaceSetSublevel(space, 1);
2454 d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]);
2455 return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY];
2456 }
2457
2458 /// <summary>
2459 /// Calculates the space the prim should be in by its position
2460 /// </summary>
2461 /// <param name="pos"></param>
2462 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
2463 public IntPtr calculateSpaceForGeom(Vector3 pos)
2464 {
2465 int[] xyspace = calculateSpaceArrayItemFromPos(pos);
2466 //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString());
2467 return staticPrimspace[xyspace[0], xyspace[1]];
2468 }
2469
2470 /// <summary>
2471 /// Holds the space allocation logic
2472 /// </summary>
2473 /// <param name="pos"></param>
2474 /// <returns>an array item based on the position</returns>
2475 public int[] calculateSpaceArrayItemFromPos(Vector3 pos)
2476 {
2477 int[] returnint = new int[2];
2478
2479 returnint[0] = (int) (pos.X/metersInSpace);
2480
2481 if (returnint[0] > ((int) (259f/metersInSpace)))
2482 returnint[0] = ((int) (259f/metersInSpace));
2483 if (returnint[0] < 0)
2484 returnint[0] = 0;
2485
2486 returnint[1] = (int) (pos.Y/metersInSpace);
2487 if (returnint[1] > ((int) (259f/metersInSpace)))
2488 returnint[1] = ((int) (259f/metersInSpace));
2489 if (returnint[1] < 0)
2490 returnint[1] = 0;
2491
2492 return returnint;
2493 }
2494
2495 #endregion
2496
2497 /// <summary>
2498 /// Routine to figure out if we need to mesh this prim with our mesher
2499 /// </summary>
2500 /// <param name="pbs"></param>
2501 /// <returns></returns>
2502 public bool needsMeshing(PrimitiveBaseShape pbs)
2503 {
2504 // most of this is redundant now as the mesher will return null if it cant mesh a prim
2505 // but we still need to check for sculptie meshing being enabled so this is the most
2506 // convenient place to do it for now...
2507
2508 // //if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle && pbs.ProfileCurve == (byte)Primitive.ProfileCurve.Circle && pbs.PathScaleY <= 0.75f)
2509 // //m_log.Debug("needsMeshing: " + " pathCurve: " + pbs.PathCurve.ToString() + " profileCurve: " + pbs.ProfileCurve.ToString() + " pathScaleY: " + Primitive.UnpackPathScale(pbs.PathScaleY).ToString());
2510 int iPropertiesNotSupportedDefault = 0;
2511
2512 if (pbs.SculptEntry && !meshSculptedPrim)
2513 {
2514#if SPAM
2515 m_log.Warn("NonMesh");
2516#endif
2517 return false;
2518 }
2519
2520 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim
2521 if (!forceSimplePrimMeshing && !pbs.SculptEntry)
2522 {
2523 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
2524 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
2525 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
2526 {
2527
2528 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
2529 && pbs.ProfileHollow == 0
2530 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
2531 && pbs.PathBegin == 0 && pbs.PathEnd == 0
2532 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
2533 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
2534 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
2535 {
2536#if SPAM
2537 m_log.Warn("NonMesh");
2538#endif
2539 return false;
2540 }
2541 }
2542 }
2543
2544 if (forceSimplePrimMeshing)
2545 return true;
2546
2547 if (pbs.ProfileHollow != 0)
2548 iPropertiesNotSupportedDefault++;
2549
2550 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0))
2551 iPropertiesNotSupportedDefault++;
2552
2553 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
2554 iPropertiesNotSupportedDefault++;
2555
2556 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
2557 iPropertiesNotSupportedDefault++;
2558
2559 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
2560 iPropertiesNotSupportedDefault++;
2561
2562 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
2563 iPropertiesNotSupportedDefault++;
2564
2565 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
2566 iPropertiesNotSupportedDefault++;
2567
2568 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte) Extrusion.Curve1)
2569 iPropertiesNotSupportedDefault++;
2570
2571 // test for torus
2572 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
2573 {
2574 if (pbs.PathCurve == (byte)Extrusion.Curve1)
2575 {
2576 iPropertiesNotSupportedDefault++;
2577 }
2578 }
2579 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
2580 {
2581 if (pbs.PathCurve == (byte)Extrusion.Straight)
2582 {
2583 iPropertiesNotSupportedDefault++;
2584 }
2585
2586 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
2587 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
2588 {
2589 iPropertiesNotSupportedDefault++;
2590 }
2591 }
2592 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
2593 {
2594 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
2595 {
2596 iPropertiesNotSupportedDefault++;
2597 }
2598 }
2599 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
2600 {
2601 if (pbs.PathCurve == (byte)Extrusion.Straight)
2602 {
2603 iPropertiesNotSupportedDefault++;
2604 }
2605 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
2606 {
2607 iPropertiesNotSupportedDefault++;
2608 }
2609 }
2610
2611 if (pbs.SculptEntry && meshSculptedPrim)
2612 iPropertiesNotSupportedDefault++;
2613
2614 if (iPropertiesNotSupportedDefault == 0)
2615 {
2616#if SPAM
2617 m_log.Warn("NonMesh");
2618#endif
2619 return false;
2620 }
2621#if SPAM
2622 m_log.Debug("Mesh");
2623#endif
2624 return true;
2625 }
2626
2627 /// <summary>
2628 /// Called after our prim properties are set Scale, position etc.
2629 /// We use this event queue like method to keep changes to the physical scene occuring in the threadlocked mutex
2630 /// This assures us that we have no race conditions
2631 /// </summary>
2632 /// <param name="prim"></param>
2633 public override void AddPhysicsActorTaint(PhysicsActor prim)
2634 {
2635
2636 if (prim is OdePrim)
2637 {
2638 OdePrim taintedprim = ((OdePrim) prim);
2639 lock (_taintedPrimLock)
2640 {
2641 if (!(_taintedPrimH.Contains(taintedprim)))
2642 {
2643//Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.m_primName);
2644 _taintedPrimH.Add(taintedprim); // HashSet for searching
2645 _taintedPrimL.Add(taintedprim); // List for ordered readout
2646 }
2647 }
2648 return;
2649 }
2650 else if (prim is OdeCharacter)
2651 {
2652 OdeCharacter taintedchar = ((OdeCharacter)prim);
2653 lock (_taintedActors)
2654 {
2655 if (!(_taintedActors.Contains(taintedchar)))
2656 {
2657 _taintedActors.Add(taintedchar);
2658 if (taintedchar.bad)
2659 m_log.DebugFormat("[PHYSICS]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid);
2660 }
2661 }
2662 }
2663 }
2664
2665 /// <summary>
2666 /// This is our main simulate loop
2667 /// It's thread locked by a Mutex in the scene.
2668 /// It holds Collisions, it instructs ODE to step through the physical reactions
2669 /// It moves the objects around in memory
2670 /// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
2671 /// </summary>
2672 /// <param name="timeStep"></param>
2673 /// <returns></returns>
2674 public override float Simulate(float timeStep)
2675 {
2676 if (framecount >= int.MaxValue)
2677 framecount = 0;
2678 //if (m_worldOffset != Vector3.Zero)
2679 // return 0;
2680
2681 framecount++;
2682
2683 DateTime now = DateTime.UtcNow;
2684 TimeSpan SinceLastFrame = now - m_lastframe;
2685 m_lastframe = now;
2686 float realtime = (float)SinceLastFrame.TotalSeconds;
2687// Console.WriteLine("ts={0} rt={1}", timeStep, realtime);
2688 timeStep = realtime;
2689
2690 // float fps = 1.0f / realtime;
2691 float fps = 0.0f; // number of ODE steps in this Simulate step
2692 //m_log.Info(timeStep.ToString());
2693 step_time += timeStep;
2694
2695 // If We're loaded down by something else,
2696 // or debugging with the Visual Studio project on pause
2697 // skip a few frames to catch up gracefully.
2698 // without shooting the physicsactors all over the place
2699
2700 if (step_time >= m_SkipFramesAtms)
2701 {
2702 // Instead of trying to catch up, it'll do 5 physics frames only
2703 step_time = ODE_STEPSIZE;
2704 m_physicsiterations = 5;
2705 }
2706 else
2707 {
2708 m_physicsiterations = 10;
2709 }
2710
2711 if (SupportsNINJAJoints)
2712 {
2713 DeleteRequestedJoints(); // this must be outside of the lock (OdeLock) to avoid deadlocks
2714 CreateRequestedJoints(); // this must be outside of the lock (OdeLock) to avoid deadlocks
2715 }
2716
2717 lock (OdeLock)
2718 {
2719 // Process 10 frames if the sim is running normal..
2720 // process 5 frames if the sim is running slow
2721 //try
2722 //{
2723 //d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
2724 //}
2725 //catch (StackOverflowException)
2726 //{
2727 // m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim.");
2728 // ode.drelease(world);
2729 //base.TriggerPhysicsBasedRestart();
2730 //}
2731
2732 int i = 0;
2733
2734 // Figure out the Frames Per Second we're going at.
2735 //(step_time == 0.004f, there's 250 of those per second. Times the step time/step size
2736
2737 // fps = (step_time / ODE_STEPSIZE) * 1000;
2738 // HACK: Using a time dilation of 1.0 to debug rubberbanding issues
2739 //m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f);
2740
2741 // step_time = 0.09375f;
2742
2743 while (step_time > 0.0f)
2744 {
2745 //lock (ode)
2746 //{
2747 //if (!ode.lockquery())
2748 //{
2749 // ode.dlock(world);
2750 try
2751 {
2752 // Insert, remove Characters
2753 bool processedtaints = false;
2754
2755 lock (_taintedActors)
2756 {
2757 if (_taintedActors.Count > 0)
2758 {
2759 foreach (OdeCharacter character in _taintedActors)
2760 {
2761
2762 character.ProcessTaints(ODE_STEPSIZE);
2763
2764 processedtaints = true;
2765 //character.m_collisionscore = 0;
2766 }
2767
2768 if (processedtaints)
2769 _taintedActors.Clear();
2770 }
2771 } // end lock _taintedActors
2772
2773 // Modify other objects in the scene.
2774 processedtaints = false;
2775
2776 lock (_taintedPrimLock)
2777 {
2778 foreach (OdePrim prim in _taintedPrimL)
2779 {
2780 if (prim.m_taintremove)
2781 {
2782 //Console.WriteLine("Simulate calls RemovePrimThreadLocked");
2783 RemovePrimThreadLocked(prim);
2784 }
2785 else
2786 {
2787 //Console.WriteLine("Simulate calls ProcessTaints");
2788 prim.ProcessTaints(ODE_STEPSIZE);
2789 }
2790 processedtaints = true;
2791 prim.m_collisionscore = 0;
2792
2793 // This loop can block up the Heartbeat for a very long time on large regions.
2794 // We need to let the Watchdog know that the Heartbeat is not dead
2795 // NOTE: This is currently commented out, but if things like OAR loading are
2796 // timing the heartbeat out we will need to uncomment it
2797 //Watchdog.UpdateThread();
2798 }
2799
2800 if (SupportsNINJAJoints)
2801 {
2802 // Create pending joints, if possible
2803
2804 // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating
2805 // a joint requires specifying the body id of both involved bodies
2806 if (pendingJoints.Count > 0)
2807 {
2808 List<PhysicsJoint> successfullyProcessedPendingJoints = new List<PhysicsJoint>();
2809 //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints");
2810 foreach (PhysicsJoint joint in pendingJoints)
2811 {
2812 //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams);
2813 string[] jointParams = joint.RawParams.Split(" ".ToCharArray(),
2814 System.StringSplitOptions.RemoveEmptyEntries);
2815 List<IntPtr> jointBodies = new List<IntPtr>();
2816 bool allJointBodiesAreReady = true;
2817 foreach (string jointParam in jointParams)
2818 {
2819 if (jointParam == "NULL")
2820 {
2821 //DoJointErrorMessage(joint, "attaching NULL joint to world");
2822 jointBodies.Add(IntPtr.Zero);
2823 }
2824 else
2825 {
2826 //DoJointErrorMessage(joint, "looking for prim name: " + jointParam);
2827 bool foundPrim = false;
2828 lock (_prims)
2829 {
2830 foreach (OdePrim prim in _prims) // FIXME: inefficient
2831 {
2832 if (prim.SOPName == jointParam)
2833 {
2834 //DoJointErrorMessage(joint, "found for prim name: " + jointParam);
2835 if (prim.IsPhysical && prim.Body != IntPtr.Zero)
2836 {
2837 jointBodies.Add(prim.Body);
2838 foundPrim = true;
2839 break;
2840 }
2841 else
2842 {
2843 DoJointErrorMessage(joint, "prim name " + jointParam +
2844 " exists but is not (yet) physical; deferring joint creation. " +
2845 "IsPhysical property is " + prim.IsPhysical +
2846 " and body is " + prim.Body);
2847 foundPrim = false;
2848 break;
2849 }
2850 }
2851 }
2852 }
2853 if (foundPrim)
2854 {
2855 // all is fine
2856 }
2857 else
2858 {
2859 allJointBodiesAreReady = false;
2860 break;
2861 }
2862 }
2863 }
2864 if (allJointBodiesAreReady)
2865 {
2866 //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams);
2867 if (jointBodies[0] == jointBodies[1])
2868 {
2869 DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams);
2870 }
2871 else
2872 {
2873 switch (joint.Type)
2874 {
2875 case PhysicsJointType.Ball:
2876 {
2877 IntPtr odeJoint;
2878 //DoJointErrorMessage(joint, "ODE creating ball joint ");
2879 odeJoint = d.JointCreateBall(world, IntPtr.Zero);
2880 //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
2881 d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
2882 //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position);
2883 d.JointSetBallAnchor(odeJoint,
2884 joint.Position.X,
2885 joint.Position.Y,
2886 joint.Position.Z);
2887 //DoJointErrorMessage(joint, "ODE joint setting OK");
2888 //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: ");
2889 //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment"));
2890 //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: ");
2891 //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment"));
2892
2893 if (joint is OdePhysicsJoint)
2894 {
2895 ((OdePhysicsJoint)joint).jointID = odeJoint;
2896 }
2897 else
2898 {
2899 DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!");
2900 }
2901 }
2902 break;
2903 case PhysicsJointType.Hinge:
2904 {
2905 IntPtr odeJoint;
2906 //DoJointErrorMessage(joint, "ODE creating hinge joint ");
2907 odeJoint = d.JointCreateHinge(world, IntPtr.Zero);
2908 //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
2909 d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
2910 //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position);
2911 d.JointSetHingeAnchor(odeJoint,
2912 joint.Position.X,
2913 joint.Position.Y,
2914 joint.Position.Z);
2915 // We use the orientation of the x-axis of the joint's coordinate frame
2916 // as the axis for the hinge.
2917
2918 // Therefore, we must get the joint's coordinate frame based on the
2919 // joint.Rotation field, which originates from the orientation of the
2920 // joint's proxy object in the scene.
2921
2922 // The joint's coordinate frame is defined as the transformation matrix
2923 // that converts a vector from joint-local coordinates into world coordinates.
2924 // World coordinates are defined as the XYZ coordinate system of the sim,
2925 // as shown in the top status-bar of the viewer.
2926
2927 // Once we have the joint's coordinate frame, we extract its X axis (AtAxis)
2928 // and use that as the hinge axis.
2929
2930 //joint.Rotation.Normalize();
2931 Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation);
2932
2933 // Now extract the X axis of the joint's coordinate frame.
2934
2935 // Do not try to use proxyFrame.AtAxis or you will become mired in the
2936 // tar pit of transposed, inverted, and generally messed-up orientations.
2937 // (In other words, Matrix4.AtAxis() is borked.)
2938 // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness
2939
2940 // Instead, compute the X axis of the coordinate frame by transforming
2941 // the (1,0,0) vector. At least that works.
2942
2943 //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame);
2944 Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame);
2945 //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis);
2946 //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis);
2947 d.JointSetHingeAxis(odeJoint,
2948 jointAxis.X,
2949 jointAxis.Y,
2950 jointAxis.Z);
2951 //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f);
2952 if (joint is OdePhysicsJoint)
2953 {
2954 ((OdePhysicsJoint)joint).jointID = odeJoint;
2955 }
2956 else
2957 {
2958 DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!");
2959 }
2960 }
2961 break;
2962 }
2963 successfullyProcessedPendingJoints.Add(joint);
2964 }
2965 }
2966 else
2967 {
2968 DoJointErrorMessage(joint, "joint could not yet be created; still pending");
2969 }
2970 }
2971 foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints)
2972 {
2973 //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams);
2974 //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending");
2975 InternalRemovePendingJoint(successfullyProcessedJoint);
2976 //DoJointErrorMessage(successfullyProcessedJoint, "adding to active");
2977 InternalAddActiveJoint(successfullyProcessedJoint);
2978 //DoJointErrorMessage(successfullyProcessedJoint, "done");
2979 }
2980 }
2981 } // end SupportsNINJAJoints
2982
2983 if (processedtaints)
2984//Console.WriteLine("Simulate calls Clear of _taintedPrim list");
2985 _taintedPrimH.Clear(); // ??? if this only ???
2986 _taintedPrimL.Clear();
2987 } // end lock _taintedPrimLock
2988
2989 // Move characters
2990 lock (_characters)
2991 {
2992 List<OdeCharacter> defects = new List<OdeCharacter>();
2993 foreach (OdeCharacter actor in _characters)
2994 {
2995 if (actor != null)
2996 actor.Move(ODE_STEPSIZE, defects);
2997 }
2998 if (0 != defects.Count)
2999 {
3000 foreach (OdeCharacter defect in defects)
3001 {
3002 RemoveCharacter(defect);
3003 }
3004 }
3005 } // end lock _characters
3006
3007 // Move other active objects
3008 lock (_activeprims)
3009 {
3010 foreach (OdePrim prim in _activeprims)
3011 {
3012 prim.m_collisionscore = 0;
3013 prim.Move(ODE_STEPSIZE);
3014 }
3015 } // end lock _activeprims
3016
3017 //if ((framecount % m_randomizeWater) == 0)
3018 // randomizeWater(waterlevel);
3019
3020 //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests();
3021 m_rayCastManager.ProcessQueuedRequests();
3022
3023 collision_optimized(ODE_STEPSIZE);
3024
3025 lock (_collisionEventPrim)
3026 {
3027 foreach (PhysicsActor obj in _collisionEventPrim)
3028 {
3029 if (obj == null)
3030 continue;
3031
3032 switch ((ActorTypes)obj.PhysicsActorType)
3033 {
3034 case ActorTypes.Agent:
3035 OdeCharacter cobj = (OdeCharacter)obj;
3036 cobj.AddCollisionFrameTime(100);
3037 cobj.SendCollisions();
3038 break;
3039 case ActorTypes.Prim:
3040 OdePrim pobj = (OdePrim)obj;
3041 pobj.SendCollisions();
3042 break;
3043 }
3044 }
3045 } // end lock _collisionEventPrim
3046
3047 //if (m_global_contactcount > 5)
3048 //{
3049 // m_log.DebugFormat("[PHYSICS]: Contacts:{0}", m_global_contactcount);
3050 //}
3051
3052 m_global_contactcount = 0;
3053
3054 d.WorldQuickStep(world, ODE_STEPSIZE);
3055 d.JointGroupEmpty(contactgroup);
3056 fps++;
3057 //ode.dunlock(world);
3058 } // end try
3059 catch (Exception e)
3060 {
3061 m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e);
3062 ode.dunlock(world);
3063 }
3064
3065 step_time -= ODE_STEPSIZE;
3066 i++;
3067 //}
3068 //else
3069 //{
3070 //fps = 0;
3071 //}
3072 //}
3073 } // end while (step_time > 0.0f)
3074
3075 lock (_characters)
3076 {
3077 foreach (OdeCharacter actor in _characters)
3078 {
3079 if (actor != null)
3080 {
3081 if (actor.bad)
3082 m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid);
3083 actor.UpdatePositionAndVelocity();
3084 }
3085 }
3086 }
3087
3088 lock (_badCharacter)
3089 {
3090 if (_badCharacter.Count > 0)
3091 {
3092 foreach (OdeCharacter chr in _badCharacter)
3093 {
3094 RemoveCharacter(chr);
3095 }
3096 _badCharacter.Clear();
3097 }
3098 }
3099
3100 lock (_activeprims)
3101 {
3102 //if (timeStep < 0.2f)
3103 {
3104 foreach (OdePrim actor in _activeprims)
3105 {
3106 if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag))
3107 {
3108 actor.UpdatePositionAndVelocity();
3109
3110 if (SupportsNINJAJoints)
3111 {
3112 // If an actor moved, move its joint proxy objects as well.
3113 // There seems to be an event PhysicsActor.OnPositionUpdate that could be used
3114 // for this purpose but it is never called! So we just do the joint
3115 // movement code here.
3116
3117 if (actor.SOPName != null &&
3118 joints_connecting_actor.ContainsKey(actor.SOPName) &&
3119 joints_connecting_actor[actor.SOPName] != null &&
3120 joints_connecting_actor[actor.SOPName].Count > 0)
3121 {
3122 foreach (PhysicsJoint affectedJoint in joints_connecting_actor[actor.SOPName])
3123 {
3124 if (affectedJoint.IsInPhysicsEngine)
3125 {
3126 DoJointMoved(affectedJoint);
3127 }
3128 else
3129 {
3130 DoJointErrorMessage(affectedJoint, "a body connected to a joint was moved, but the joint doesn't exist yet! this will lead to joint error. joint was: " + affectedJoint.ObjectNameInScene + " parms:" + affectedJoint.RawParams);
3131 }
3132 }
3133 }
3134 }
3135 }
3136 }
3137 }
3138 } // end lock _activeprims
3139
3140 //DumpJointInfo();
3141
3142 // Finished with all sim stepping. If requested, dump world state to file for debugging.
3143 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
3144 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
3145 if (physics_logging && (physics_logging_interval>0) && (framecount % physics_logging_interval == 0))
3146 {
3147 string fname = "state-" + world.ToString() + ".DIF"; // give each physics world a separate filename
3148 string prefix = "world" + world.ToString(); // prefix for variable names in exported .DIF file
3149
3150 if (physics_logging_append_existing_logfile)
3151 {
3152 string header = "-------------- START OF PHYSICS FRAME " + framecount.ToString() + " --------------";
3153 TextWriter fwriter = File.AppendText(fname);
3154 fwriter.WriteLine(header);
3155 fwriter.Close();
3156 }
3157 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
3158 }
3159 } // end lock OdeLock
3160
3161 return fps * 1000.0f; //NB This is a FRAME COUNT, not a time! AND is divide by 1000 in SimStatusReporter!
3162 } // end Simulate
3163
3164 public override void GetResults()
3165 {
3166 }
3167
3168 public override bool IsThreaded
3169 {
3170 // for now we won't be multithreaded
3171 get { return (false); }
3172 }
3173
3174 #region ODE Specific Terrain Fixes
3175 public float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
3176 {
3177 float[] returnarr = new float[262144];
3178 float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y];
3179
3180 // Filling out the array into its multi-dimensional components
3181 for (int y = 0; y < WorldExtents.Y; y++)
3182 {
3183 for (int x = 0; x < WorldExtents.X; x++)
3184 {
3185 resultarr[y, x] = heightMap[y * (int)WorldExtents.Y + x];
3186 }
3187 }
3188
3189 // Resize using Nearest Neighbour
3190
3191 // This particular way is quick but it only works on a multiple of the original
3192
3193 // The idea behind this method can be described with the following diagrams
3194 // second pass and third pass happen in the same loop really.. just separated
3195 // them to show what this does.
3196
3197 // First Pass
3198 // ResultArr:
3199 // 1,1,1,1,1,1
3200 // 1,1,1,1,1,1
3201 // 1,1,1,1,1,1
3202 // 1,1,1,1,1,1
3203 // 1,1,1,1,1,1
3204 // 1,1,1,1,1,1
3205
3206 // Second Pass
3207 // ResultArr2:
3208 // 1,,1,,1,,1,,1,,1,
3209 // ,,,,,,,,,,
3210 // 1,,1,,1,,1,,1,,1,
3211 // ,,,,,,,,,,
3212 // 1,,1,,1,,1,,1,,1,
3213 // ,,,,,,,,,,
3214 // 1,,1,,1,,1,,1,,1,
3215 // ,,,,,,,,,,
3216 // 1,,1,,1,,1,,1,,1,
3217 // ,,,,,,,,,,
3218 // 1,,1,,1,,1,,1,,1,
3219
3220 // Third pass fills in the blanks
3221 // ResultArr2:
3222 // 1,1,1,1,1,1,1,1,1,1,1,1
3223 // 1,1,1,1,1,1,1,1,1,1,1,1
3224 // 1,1,1,1,1,1,1,1,1,1,1,1
3225 // 1,1,1,1,1,1,1,1,1,1,1,1
3226 // 1,1,1,1,1,1,1,1,1,1,1,1
3227 // 1,1,1,1,1,1,1,1,1,1,1,1
3228 // 1,1,1,1,1,1,1,1,1,1,1,1
3229 // 1,1,1,1,1,1,1,1,1,1,1,1
3230 // 1,1,1,1,1,1,1,1,1,1,1,1
3231 // 1,1,1,1,1,1,1,1,1,1,1,1
3232 // 1,1,1,1,1,1,1,1,1,1,1,1
3233
3234 // X,Y = .
3235 // X+1,y = ^
3236 // X,Y+1 = *
3237 // X+1,Y+1 = #
3238
3239 // Filling in like this;
3240 // .*
3241 // ^#
3242 // 1st .
3243 // 2nd *
3244 // 3rd ^
3245 // 4th #
3246 // on single loop.
3247
3248 float[,] resultarr2 = new float[512, 512];
3249 for (int y = 0; y < WorldExtents.Y; y++)
3250 {
3251 for (int x = 0; x < WorldExtents.X; x++)
3252 {
3253 resultarr2[y * 2, x * 2] = resultarr[y, x];
3254
3255 if (y < WorldExtents.Y)
3256 {
3257 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x];
3258 }
3259 if (x < WorldExtents.X)
3260 {
3261 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x];
3262 }
3263 if (x < WorldExtents.X && y < WorldExtents.Y)
3264 {
3265 resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x];
3266 }
3267 }
3268 }
3269
3270 //Flatten out the array
3271 int i = 0;
3272 for (int y = 0; y < 512; y++)
3273 {
3274 for (int x = 0; x < 512; x++)
3275 {
3276 if (resultarr2[y, x] <= 0)
3277 returnarr[i] = 0.0000001f;
3278 else
3279 returnarr[i] = resultarr2[y, x];
3280
3281 i++;
3282 }
3283 }
3284
3285 return returnarr;
3286 }
3287
3288 public float[] ResizeTerrain512Interpolation(float[] heightMap)
3289 {
3290 float[] returnarr = new float[262144];
3291 float[,] resultarr = new float[512,512];
3292
3293 // Filling out the array into its multi-dimensional components
3294 for (int y = 0; y < 256; y++)
3295 {
3296 for (int x = 0; x < 256; x++)
3297 {
3298 resultarr[y, x] = heightMap[y * 256 + x];
3299 }
3300 }
3301
3302 // Resize using interpolation
3303
3304 // This particular way is quick but it only works on a multiple of the original
3305
3306 // The idea behind this method can be described with the following diagrams
3307 // second pass and third pass happen in the same loop really.. just separated
3308 // them to show what this does.
3309
3310 // First Pass
3311 // ResultArr:
3312 // 1,1,1,1,1,1
3313 // 1,1,1,1,1,1
3314 // 1,1,1,1,1,1
3315 // 1,1,1,1,1,1
3316 // 1,1,1,1,1,1
3317 // 1,1,1,1,1,1
3318
3319 // Second Pass
3320 // ResultArr2:
3321 // 1,,1,,1,,1,,1,,1,
3322 // ,,,,,,,,,,
3323 // 1,,1,,1,,1,,1,,1,
3324 // ,,,,,,,,,,
3325 // 1,,1,,1,,1,,1,,1,
3326 // ,,,,,,,,,,
3327 // 1,,1,,1,,1,,1,,1,
3328 // ,,,,,,,,,,
3329 // 1,,1,,1,,1,,1,,1,
3330 // ,,,,,,,,,,
3331 // 1,,1,,1,,1,,1,,1,
3332
3333 // Third pass fills in the blanks
3334 // ResultArr2:
3335 // 1,1,1,1,1,1,1,1,1,1,1,1
3336 // 1,1,1,1,1,1,1,1,1,1,1,1
3337 // 1,1,1,1,1,1,1,1,1,1,1,1
3338 // 1,1,1,1,1,1,1,1,1,1,1,1
3339 // 1,1,1,1,1,1,1,1,1,1,1,1
3340 // 1,1,1,1,1,1,1,1,1,1,1,1
3341 // 1,1,1,1,1,1,1,1,1,1,1,1
3342 // 1,1,1,1,1,1,1,1,1,1,1,1
3343 // 1,1,1,1,1,1,1,1,1,1,1,1
3344 // 1,1,1,1,1,1,1,1,1,1,1,1
3345 // 1,1,1,1,1,1,1,1,1,1,1,1
3346
3347 // X,Y = .
3348 // X+1,y = ^
3349 // X,Y+1 = *
3350 // X+1,Y+1 = #
3351
3352 // Filling in like this;
3353 // .*
3354 // ^#
3355 // 1st .
3356 // 2nd *
3357 // 3rd ^
3358 // 4th #
3359 // on single loop.
3360
3361 float[,] resultarr2 = new float[512,512];
3362 for (int y = 0; y < (int)Constants.RegionSize; y++)
3363 {
3364 for (int x = 0; x < (int)Constants.RegionSize; x++)
3365 {
3366 resultarr2[y*2, x*2] = resultarr[y, x];
3367
3368 if (y < (int)Constants.RegionSize)
3369 {
3370 if (y + 1 < (int)Constants.RegionSize)
3371 {
3372 if (x + 1 < (int)Constants.RegionSize)
3373 {
3374 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] +
3375 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
3376 }
3377 else
3378 {
3379 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2);
3380 }
3381 }
3382 else
3383 {
3384 resultarr2[(y*2) + 1, x*2] = resultarr[y, x];
3385 }
3386 }
3387 if (x < (int)Constants.RegionSize)
3388 {
3389 if (x + 1 < (int)Constants.RegionSize)
3390 {
3391 if (y + 1 < (int)Constants.RegionSize)
3392 {
3393 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
3394 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
3395 }
3396 else
3397 {
3398 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2);
3399 }
3400 }
3401 else
3402 {
3403 resultarr2[y*2, (x*2) + 1] = resultarr[y, x];
3404 }
3405 }
3406 if (x < (int)Constants.RegionSize && y < (int)Constants.RegionSize)
3407 {
3408 if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize))
3409 {
3410 resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
3411 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
3412 }
3413 else
3414 {
3415 resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x];
3416 }
3417 }
3418 }
3419 }
3420 //Flatten out the array
3421 int i = 0;
3422 for (int y = 0; y < 512; y++)
3423 {
3424 for (int x = 0; x < 512; x++)
3425 {
3426 if (Single.IsNaN(resultarr2[y, x]) || Single.IsInfinity(resultarr2[y, x]))
3427 {
3428 m_log.Warn("[PHYSICS]: Non finite heightfield element detected. Setting it to 0");
3429 resultarr2[y, x] = 0;
3430 }
3431 returnarr[i] = resultarr2[y, x];
3432 i++;
3433 }
3434 }
3435
3436 return returnarr;
3437 }
3438
3439 #endregion
3440
3441 public override void SetTerrain(float[] heightMap)
3442 {
3443 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
3444 {
3445 if (m_parentScene is OdeScene)
3446 {
3447 ((OdeScene)m_parentScene).SetTerrain(heightMap, m_worldOffset);
3448 }
3449 }
3450 else
3451 {
3452 SetTerrain(heightMap, m_worldOffset);
3453 }
3454 }
3455
3456 public void SetTerrain(float[] heightMap, Vector3 pOffset)
3457 {
3458
3459 int regionsize = (int) Constants.RegionSize; // visible region size eg. 256(M)
3460
3461 int heightmapWidth = regionsize + 2; // ODE map size 257 x 257 (Meters) (1 extra
3462 int heightmapHeight = regionsize + 2;
3463
3464 int heightmapWidthSamples = (int)regionsize + 2; // Sample file size, 258 x 258 samples
3465 int heightmapHeightSamples = (int)regionsize + 2;
3466
3467 // Array of height samples for ODE
3468 float[] _heightmap;
3469 _heightmap = new float[(heightmapWidthSamples * heightmapHeightSamples)]; // loaded samples 258 x 258
3470
3471 // Other ODE parameters
3472 const float scale = 1.0f;
3473 const float offset = 0.0f;
3474 const float thickness = 2.0f; // Was 0.2f, Larger appears to prevent Av fall-through
3475 const int wrap = 0;
3476
3477 float hfmin = 2000f;
3478 float hfmax = -2000f;
3479 float minele = 0.0f; // Dont allow -ve heights
3480
3481 int x = 0;
3482 int y = 0;
3483 int xx = 0;
3484 int yy = 0;
3485
3486 // load the height samples array from the heightMap
3487 for ( x = 0; x < heightmapWidthSamples; x++) // 0 to 257
3488 {
3489 for ( y = 0; y < heightmapHeightSamples; y++) // 0 to 257
3490 {
3491 xx = x - 1;
3492 if (xx < 0) xx = 0;
3493 if (xx > (regionsize - 1)) xx = regionsize - 1;
3494
3495 yy = y - 1;
3496 if (yy < 0) yy = 0;
3497 if (yy > (regionsize - 1)) yy = regionsize - 1;
3498 // Input xx = 0 0 1 2 ..... 254 255 255 256 total in
3499 // Output x = 0 1 2 3 ..... 255 256 257 258 total out
3500 float val= heightMap[(yy * regionsize) + xx]; // input from heightMap, <0-255 * 256> <0-255>
3501 if (val < minele) val = minele;
3502 _heightmap[x * (regionsize + 2) + y] = val; // samples output to _heightmap, <0-257 * 258> <0-257>
3503 hfmin = (val < hfmin) ? val : hfmin;
3504 hfmax = (val > hfmax) ? val : hfmax;
3505 }
3506 }
3507
3508 lock (OdeLock)
3509 {
3510 IntPtr GroundGeom = IntPtr.Zero;
3511 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
3512 {
3513 RegionTerrain.Remove(pOffset);
3514 if (GroundGeom != IntPtr.Zero)
3515 {
3516 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
3517 {
3518 TerrainHeightFieldHeights.Remove(GroundGeom);
3519 }
3520 d.SpaceRemove(space, GroundGeom);
3521 d.GeomDestroy(GroundGeom);
3522 }
3523 }
3524 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3525 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0,
3526 heightmapWidth, heightmapHeight, (int)heightmapWidthSamples,
3527 (int)heightmapHeightSamples, scale, offset, thickness, wrap);
3528 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
3529 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1);
3530 if (GroundGeom != IntPtr.Zero)
3531 {
3532 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
3533 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
3534 }
3535 geom_name_map[GroundGeom] = "Terrain";
3536
3537 d.Matrix3 R = new d.Matrix3();
3538
3539 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
3540 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
3541 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
3542
3543 q1 = q1 * q2;
3544 //q1 = q1 * q3;
3545 Vector3 v3;
3546 float angle;
3547 q1.GetAxisAngle(out v3, out angle);
3548
3549 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3550 d.GeomSetRotation(GroundGeom, ref R);
3551 d.GeomSetPosition(GroundGeom, (pOffset.X + (regionsize * 0.5f)) - 0.5f, (pOffset.Y + (regionsize * 0.5f)) - 0.5f, 0);
3552 IntPtr testGround = IntPtr.Zero;
3553 if (RegionTerrain.TryGetValue(pOffset, out testGround))
3554 {
3555 RegionTerrain.Remove(pOffset);
3556 }
3557 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
3558 TerrainHeightFieldHeights.Add(GroundGeom,_heightmap);
3559 }
3560 }
3561
3562 public override void DeleteTerrain()
3563 {
3564 }
3565
3566 public float GetWaterLevel()
3567 {
3568 return waterlevel;
3569 }
3570
3571 public override bool SupportsCombining()
3572 {
3573 return true;
3574 }
3575
3576 public override void UnCombine(PhysicsScene pScene)
3577 {
3578 IntPtr localGround = IntPtr.Zero;
3579// float[] localHeightfield;
3580 bool proceed = false;
3581 List<IntPtr> geomDestroyList = new List<IntPtr>();
3582
3583 lock (OdeLock)
3584 {
3585 if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround))
3586 {
3587 foreach (IntPtr geom in TerrainHeightFieldHeights.Keys)
3588 {
3589 if (geom == localGround)
3590 {
3591// localHeightfield = TerrainHeightFieldHeights[geom];
3592 proceed = true;
3593 }
3594 else
3595 {
3596 geomDestroyList.Add(geom);
3597 }
3598 }
3599
3600 if (proceed)
3601 {
3602 m_worldOffset = Vector3.Zero;
3603 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
3604 m_parentScene = null;
3605
3606 foreach (IntPtr g in geomDestroyList)
3607 {
3608 // removingHeightField needs to be done or the garbage collector will
3609 // collect the terrain data before we tell ODE to destroy it causing
3610 // memory corruption
3611 if (TerrainHeightFieldHeights.ContainsKey(g))
3612 {
3613// float[] removingHeightField = TerrainHeightFieldHeights[g];
3614 TerrainHeightFieldHeights.Remove(g);
3615
3616 if (RegionTerrain.ContainsKey(g))
3617 {
3618 RegionTerrain.Remove(g);
3619 }
3620
3621 d.GeomDestroy(g);
3622 //removingHeightField = new float[0];
3623 }
3624 }
3625
3626 }
3627 else
3628 {
3629 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
3630
3631 }
3632 }
3633 }
3634 }
3635
3636 public override void SetWaterLevel(float baseheight)
3637 {
3638 waterlevel = baseheight;
3639 randomizeWater(waterlevel);
3640 }
3641
3642 public void randomizeWater(float baseheight)
3643 {
3644 const uint heightmapWidth = m_regionWidth + 2;
3645 const uint heightmapHeight = m_regionHeight + 2;
3646 const uint heightmapWidthSamples = m_regionWidth + 2;
3647 const uint heightmapHeightSamples = m_regionHeight + 2;
3648 const float scale = 1.0f;
3649 const float offset = 0.0f;
3650 const float thickness = 2.9f;
3651 const int wrap = 0;
3652
3653 for (int i = 0; i < (258 * 258); i++)
3654 {
3655 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
3656 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
3657 }
3658
3659 lock (OdeLock)
3660 {
3661 if (WaterGeom != IntPtr.Zero)
3662 {
3663 d.SpaceRemove(space, WaterGeom);
3664 }
3665 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3666 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
3667 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
3668 offset, thickness, wrap);
3669 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
3670 WaterGeom = d.CreateHeightfield(space, HeightmapData, 1);
3671 if (WaterGeom != IntPtr.Zero)
3672 {
3673 d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water));
3674 d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space));
3675
3676 }
3677 geom_name_map[WaterGeom] = "Water";
3678
3679 d.Matrix3 R = new d.Matrix3();
3680
3681 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
3682 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
3683 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
3684
3685 q1 = q1 * q2;
3686 //q1 = q1 * q3;
3687 Vector3 v3;
3688 float angle;
3689 q1.GetAxisAngle(out v3, out angle);
3690
3691 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3692 d.GeomSetRotation(WaterGeom, ref R);
3693 d.GeomSetPosition(WaterGeom, 128, 128, 0);
3694
3695 }
3696
3697 }
3698
3699 public override void Dispose()
3700 {
3701 m_rayCastManager.Dispose();
3702 m_rayCastManager = null;
3703
3704 lock (OdeLock)
3705 {
3706 lock (_prims)
3707 {
3708 foreach (OdePrim prm in _prims)
3709 {
3710 RemovePrim(prm);
3711 }
3712 }
3713
3714 //foreach (OdeCharacter act in _characters)
3715 //{
3716 //RemoveAvatar(act);
3717 //}
3718 d.WorldDestroy(world);
3719 //d.CloseODE();
3720 }
3721 }
3722 public override Dictionary<uint, float> GetTopColliders()
3723 {
3724 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
3725 int cnt = 0;
3726 lock (_prims)
3727 {
3728 foreach (OdePrim prm in _prims)
3729 {
3730 if (prm.CollisionScore > 0)
3731 {
3732 returncolliders.Add(prm.m_localID, prm.CollisionScore);
3733 cnt++;
3734 prm.CollisionScore = 0f;
3735 if (cnt > 25)
3736 {
3737 break;
3738 }
3739 }
3740 }
3741 }
3742 return returncolliders;
3743 }
3744
3745 public override bool SupportsRayCast()
3746 {
3747 return true;
3748 }
3749
3750 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
3751 {
3752 if (retMethod != null)
3753 {
3754 m_rayCastManager.QueueRequest(position, direction, length, retMethod);
3755 }
3756 }
3757
3758#if USE_DRAWSTUFF
3759 // Keyboard callback
3760 public void command(int cmd)
3761 {
3762 IntPtr geom;
3763 d.Mass mass;
3764 d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f);
3765
3766
3767
3768 Char ch = Char.ToLower((Char)cmd);
3769 switch ((Char)ch)
3770 {
3771 case 'w':
3772 try
3773 {
3774 Vector3 rotate = (new Vector3(1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
3775
3776 xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z;
3777 ds.SetViewpoint(ref xyz, ref hpr);
3778 }
3779 catch (ArgumentException)
3780 { hpr.X = 0; }
3781 break;
3782
3783 case 'a':
3784 hpr.X++;
3785 ds.SetViewpoint(ref xyz, ref hpr);
3786 break;
3787
3788 case 's':
3789 try
3790 {
3791 Vector3 rotate2 = (new Vector3(-1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
3792
3793 xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z;
3794 ds.SetViewpoint(ref xyz, ref hpr);
3795 }
3796 catch (ArgumentException)
3797 { hpr.X = 0; }
3798 break;
3799 case 'd':
3800 hpr.X--;
3801 ds.SetViewpoint(ref xyz, ref hpr);
3802 break;
3803 case 'r':
3804 xyz.Z++;
3805 ds.SetViewpoint(ref xyz, ref hpr);
3806 break;
3807 case 'f':
3808 xyz.Z--;
3809 ds.SetViewpoint(ref xyz, ref hpr);
3810 break;
3811 case 'e':
3812 xyz.Y++;
3813 ds.SetViewpoint(ref xyz, ref hpr);
3814 break;
3815 case 'q':
3816 xyz.Y--;
3817 ds.SetViewpoint(ref xyz, ref hpr);
3818 break;
3819 }
3820 }
3821
3822 public void step(int pause)
3823 {
3824
3825 ds.SetColor(1.0f, 1.0f, 0.0f);
3826 ds.SetTexture(ds.Texture.Wood);
3827 lock (_prims)
3828 {
3829 foreach (OdePrim prm in _prims)
3830 {
3831 //IntPtr body = d.GeomGetBody(prm.prim_geom);
3832 if (prm.prim_geom != IntPtr.Zero)
3833 {
3834 d.Vector3 pos;
3835 d.GeomCopyPosition(prm.prim_geom, out pos);
3836 //d.BodyCopyPosition(body, out pos);
3837
3838 d.Matrix3 R;
3839 d.GeomCopyRotation(prm.prim_geom, out R);
3840 //d.BodyCopyRotation(body, out R);
3841
3842
3843 d.Vector3 sides = new d.Vector3();
3844 sides.X = prm.Size.X;
3845 sides.Y = prm.Size.Y;
3846 sides.Z = prm.Size.Z;
3847
3848 ds.DrawBox(ref pos, ref R, ref sides);
3849 }
3850 }
3851 }
3852 ds.SetColor(1.0f, 0.0f, 0.0f);
3853 lock (_characters)
3854 {
3855 foreach (OdeCharacter chr in _characters)
3856 {
3857 if (chr.Shell != IntPtr.Zero)
3858 {
3859 IntPtr body = d.GeomGetBody(chr.Shell);
3860
3861 d.Vector3 pos;
3862 d.GeomCopyPosition(chr.Shell, out pos);
3863 //d.BodyCopyPosition(body, out pos);
3864
3865 d.Matrix3 R;
3866 d.GeomCopyRotation(chr.Shell, out R);
3867 //d.BodyCopyRotation(body, out R);
3868
3869 ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f);
3870 d.Vector3 sides = new d.Vector3();
3871 sides.X = 0.5f;
3872 sides.Y = 0.5f;
3873 sides.Z = 0.5f;
3874
3875 ds.DrawBox(ref pos, ref R, ref sides);
3876 }
3877 }
3878 }
3879 }
3880
3881 public void start(int unused)
3882 {
3883 ds.SetViewpoint(ref xyz, ref hpr);
3884 }
3885#endif
3886 }
3887}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
new file mode 100644
index 0000000..e7e7bb3
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs
@@ -0,0 +1,353 @@
1/* Ubit 2012
2 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
3 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
6 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
8 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
10 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
11 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12*/
13
14// no endian conversion. So can't be use to pass information around diferent cpus with diferent endian
15
16using System;
17using System.IO;
18using OpenMetaverse;
19
20namespace OpenSim.Region.Physics.OdePlugin
21{
22
23 unsafe public class wstreamer
24 {
25 byte[] buf;
26 int index;
27 byte* src;
28
29 public wstreamer()
30 {
31 buf = new byte[1024];
32 index = 0;
33 }
34 public wstreamer(int size)
35 {
36 buf = new byte[size];
37 index = 0;
38 }
39
40 public byte[] close()
41 {
42 byte[] data = new byte[index];
43 Buffer.BlockCopy(buf, 0, data, 0, index);
44 return data;
45 }
46
47 public void Seek(int pos)
48 {
49 index = pos;
50 }
51
52 public void Seekrel(int pos)
53 {
54 index += pos;
55 }
56
57 public void Wbyte(byte value)
58 {
59 buf[index++] = value;
60 }
61 public void Wshort(short value)
62 {
63 src = (byte*)&value;
64 buf[index++] = *src++;
65 buf[index++] = *src;
66 }
67 public void Wushort(ushort value)
68 {
69 src = (byte*)&value;
70 buf[index++] = *src++;
71 buf[index++] = *src;
72 }
73 public void Wint(int value)
74 {
75 src = (byte*)&value;
76 buf[index++] = *src++;
77 buf[index++] = *src++;
78 buf[index++] = *src++;
79 buf[index++] = *src;
80 }
81 public void Wuint(uint value)
82 {
83 src = (byte*)&value;
84 buf[index++] = *src++;
85 buf[index++] = *src++;
86 buf[index++] = *src++;
87 buf[index++] = *src;
88 }
89 public void Wlong(long value)
90 {
91 src = (byte*)&value;
92 buf[index++] = *src++;
93 buf[index++] = *src++;
94 buf[index++] = *src++;
95 buf[index++] = *src++;
96 buf[index++] = *src++;
97 buf[index++] = *src++;
98 buf[index++] = *src++;
99 buf[index++] = *src;
100 }
101 public void Wulong(ulong value)
102 {
103 src = (byte*)&value;
104 buf[index++] = *src++;
105 buf[index++] = *src++;
106 buf[index++] = *src++;
107 buf[index++] = *src++;
108 buf[index++] = *src++;
109 buf[index++] = *src++;
110 buf[index++] = *src++;
111 buf[index++] = *src;
112 }
113
114 public void Wfloat(float value)
115 {
116 src = (byte*)&value;
117 buf[index++] = *src++;
118 buf[index++] = *src++;
119 buf[index++] = *src++;
120 buf[index++] = *src;
121 }
122
123 public void Wdouble(double value)
124 {
125 src = (byte*)&value;
126 buf[index++] = *src++;
127 buf[index++] = *src++;
128 buf[index++] = *src++;
129 buf[index++] = *src++;
130 buf[index++] = *src++;
131 buf[index++] = *src++;
132 buf[index++] = *src++;
133 buf[index++] = *src;
134 }
135
136 public void Wvector3(Vector3 value)
137 {
138 src = (byte*)&value.X;
139 buf[index++] = *src++;
140 buf[index++] = *src++;
141 buf[index++] = *src++;
142 buf[index++] = *src;
143 src = (byte*)&value.Y; // it may have padding ??
144 buf[index++] = *src++;
145 buf[index++] = *src++;
146 buf[index++] = *src++;
147 buf[index++] = *src;
148 src = (byte*)&value.Z;
149 buf[index++] = *src++;
150 buf[index++] = *src++;
151 buf[index++] = *src++;
152 buf[index++] = *src;
153 }
154 public void Wquat(Quaternion value)
155 {
156 src = (byte*)&value.X;
157 buf[index++] = *src++;
158 buf[index++] = *src++;
159 buf[index++] = *src++;
160 buf[index++] = *src;
161 src = (byte*)&value.Y; // it may have padding ??
162 buf[index++] = *src++;
163 buf[index++] = *src++;
164 buf[index++] = *src++;
165 buf[index++] = *src;
166 src = (byte*)&value.Z;
167 buf[index++] = *src++;
168 buf[index++] = *src++;
169 buf[index++] = *src++;
170 buf[index++] = *src;
171 src = (byte*)&value.W;
172 buf[index++] = *src++;
173 buf[index++] = *src++;
174 buf[index++] = *src++;
175 buf[index++] = *src;
176 }
177 }
178
179 unsafe public class rstreamer
180 {
181 private byte[] rbuf;
182 private int ptr;
183 private byte* dst;
184
185 public rstreamer(byte[] data)
186 {
187 rbuf = data;
188 ptr = 0;
189 }
190
191 public void close()
192 {
193 }
194
195 public void Seek(int pos)
196 {
197 ptr = pos;
198 }
199
200 public void Seekrel(int pos)
201 {
202 ptr += pos;
203 }
204
205 public byte Rbyte()
206 {
207 return (byte)rbuf[ptr++];
208 }
209
210 public short Rshort()
211 {
212 short v;
213 dst = (byte*)&v;
214 *dst++ = rbuf[ptr++];
215 *dst = rbuf[ptr++];
216 return v;
217 }
218 public ushort Rushort()
219 {
220 ushort v;
221 dst = (byte*)&v;
222 *dst++ = rbuf[ptr++];
223 *dst = rbuf[ptr++];
224 return v;
225 }
226 public int Rint()
227 {
228 int v;
229 dst = (byte*)&v;
230 *dst++ = rbuf[ptr++];
231 *dst++ = rbuf[ptr++];
232 *dst++ = rbuf[ptr++];
233 *dst = rbuf[ptr++];
234 return v;
235 }
236 public uint Ruint()
237 {
238 uint v;
239 dst = (byte*)&v;
240 *dst++ = rbuf[ptr++];
241 *dst++ = rbuf[ptr++];
242 *dst++ = rbuf[ptr++];
243 *dst = rbuf[ptr++];
244 return v;
245 }
246 public long Rlong()
247 {
248 long v;
249 dst = (byte*)&v;
250 *dst++ = rbuf[ptr++];
251 *dst++ = rbuf[ptr++];
252 *dst++ = rbuf[ptr++];
253 *dst++ = rbuf[ptr++];
254 *dst++ = rbuf[ptr++];
255 *dst++ = rbuf[ptr++];
256 *dst++ = rbuf[ptr++];
257 *dst = rbuf[ptr++];
258 return v;
259 }
260 public ulong Rulong()
261 {
262 ulong v;
263 dst = (byte*)&v;
264 *dst++ = rbuf[ptr++];
265 *dst++ = rbuf[ptr++];
266 *dst++ = rbuf[ptr++];
267 *dst++ = rbuf[ptr++];
268 *dst++ = rbuf[ptr++];
269 *dst++ = rbuf[ptr++];
270 *dst++ = rbuf[ptr++];
271 *dst = rbuf[ptr++];
272 return v;
273 }
274 public float Rfloat()
275 {
276 float v;
277 dst = (byte*)&v;
278 *dst++ = rbuf[ptr++];
279 *dst++ = rbuf[ptr++];
280 *dst++ = rbuf[ptr++];
281 *dst = rbuf[ptr++];
282 return v;
283 }
284
285 public double Rdouble()
286 {
287 double v;
288 dst = (byte*)&v;
289 *dst++ = rbuf[ptr++];
290 *dst++ = rbuf[ptr++];
291 *dst++ = rbuf[ptr++];
292 *dst++ = rbuf[ptr++];
293 *dst++ = rbuf[ptr++];
294 *dst++ = rbuf[ptr++];
295 *dst++ = rbuf[ptr++];
296 *dst = rbuf[ptr++];
297 return v;
298 }
299
300 public Vector3 Rvector3()
301 {
302 Vector3 v;
303 dst = (byte*)&v.X;
304 *dst++ = rbuf[ptr++];
305 *dst++ = rbuf[ptr++];
306 *dst++ = rbuf[ptr++];
307 *dst = rbuf[ptr++];
308
309 dst = (byte*)&v.Y;
310 *dst++ = rbuf[ptr++];
311 *dst++ = rbuf[ptr++];
312 *dst++ = rbuf[ptr++];
313 *dst = rbuf[ptr++];
314
315 dst = (byte*)&v.Z;
316 *dst++ = rbuf[ptr++];
317 *dst++ = rbuf[ptr++];
318 *dst++ = rbuf[ptr++];
319 *dst = rbuf[ptr++];
320 return v;
321 }
322
323 public Quaternion Rquat()
324 {
325 Quaternion v;
326 dst = (byte*)&v.X;
327 *dst++ = rbuf[ptr++];
328 *dst++ = rbuf[ptr++];
329 *dst++ = rbuf[ptr++];
330 *dst = rbuf[ptr++];
331
332 dst = (byte*)&v.Y;
333 *dst++ = rbuf[ptr++];
334 *dst++ = rbuf[ptr++];
335 *dst++ = rbuf[ptr++];
336 *dst = rbuf[ptr++];
337
338 dst = (byte*)&v.Z;
339 *dst++ = rbuf[ptr++];
340 *dst++ = rbuf[ptr++];
341 *dst++ = rbuf[ptr++];
342 *dst = rbuf[ptr++];
343
344 dst = (byte*)&v.W;
345 *dst++ = rbuf[ptr++];
346 *dst++ = rbuf[ptr++];
347 *dst++ = rbuf[ptr++];
348 *dst = rbuf[ptr++];
349
350 return v;
351 }
352 }
353}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/ChOdePlugin/Tests/ODETestClass.cs
new file mode 100644
index 0000000..69e2d03
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/Tests/ODETestClass.cs
@@ -0,0 +1,122 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using NUnit.Framework;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Physics.Manager;
34using log4net;
35using System.Reflection;
36
37namespace OpenSim.Region.Physics.OdePlugin
38{
39 [TestFixture]
40 public class ODETestClass
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private OdePlugin cbt;
45 private PhysicsScene ps;
46 private IMeshingPlugin imp;
47
48 [SetUp]
49 public void Initialize()
50 {
51 // Loading ODEPlugin
52 cbt = new OdePlugin();
53 // Loading Zero Mesher
54 imp = new ZeroMesherPlugin();
55 // Getting Physics Scene
56 ps = cbt.GetScene("test");
57 // Initializing Physics Scene.
58 ps.Initialise(imp.GetMesher(),null);
59 float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize];
60 for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++)
61 {
62 _heightmap[i] = 21f;
63 }
64 ps.SetTerrain(_heightmap);
65 }
66
67 [TearDown]
68 public void Terminate()
69 {
70 ps.DeleteTerrain();
71 ps.Dispose();
72
73 }
74
75 [Test]
76 public void CreateAndDropPhysicalCube()
77 {
78 PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
79 Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
80 Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
81 Quaternion rot = Quaternion.Identity;
82 PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true);
83 OdePrim oprim = (OdePrim)prim;
84 OdeScene pscene = (OdeScene) ps;
85
86 Assert.That(oprim.m_taintadd);
87
88 prim.LocalID = 5;
89
90 for (int i = 0; i < 58; i++)
91 {
92 ps.Simulate(0.133f);
93
94 Assert.That(oprim.prim_geom != (IntPtr)0);
95
96 Assert.That(oprim.m_targetSpace != (IntPtr)0);
97
98 //Assert.That(oprim.m_targetSpace == pscene.space);
99 m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);
100
101 Assert.That(!oprim.m_taintadd);
102 m_log.Info("Prim Position (" + oprim.m_localID + "): " + prim.Position.ToString());
103
104 // Make sure we're above the ground
105 //Assert.That(prim.Position.Z > 20f);
106 //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);
107
108 // Make sure we've got a Body
109 Assert.That(oprim.Body != (IntPtr)0);
110 //m_log.Info(
111 }
112
113 // Make sure we're not somewhere above the ground
114 Assert.That(prim.Position.Z < 21.5f);
115
116 ps.RemovePrim(prim);
117 Assert.That(oprim.m_taintremove);
118 ps.Simulate(0.133f);
119 Assert.That(oprim.Body == (IntPtr)0);
120 }
121 }
122}
diff --git a/OpenSim/Region/Physics/ChOdePlugin/drawstuff.cs b/OpenSim/Region/Physics/ChOdePlugin/drawstuff.cs
new file mode 100644
index 0000000..87ca446
--- /dev/null
+++ b/OpenSim/Region/Physics/ChOdePlugin/drawstuff.cs
@@ -0,0 +1,98 @@
1/*
2 * Copyright ODE
3 * Ode.NET - .NET bindings for ODE
4 * Jason Perkins (starkos@industriousone.com)
5 * Licensed under the New BSD
6 * Part of the OpenDynamicsEngine
7Open Dynamics Engine
8Copyright (c) 2001-2007, Russell L. Smith.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
15Redistributions of source code must retain the above copyright notice,
16this list of conditions and the following disclaimer.
17
18Redistributions in binary form must reproduce the above copyright notice,
19this list of conditions and the following disclaimer in the documentation
20and/or other materials provided with the distribution.
21
22Neither the names of ODE's copyright owner nor the names of its
23contributors may be used to endorse or promote products derived from
24this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 *
39 */
40
41using System;
42using System.Runtime.InteropServices;
43using Ode.NET;
44
45namespace Drawstuff.NET
46{
47#if dDOUBLE
48 using dReal = System.Double;
49#else
50 using dReal = System.Single;
51#endif
52
53 public static class ds
54 {
55 public const int VERSION = 2;
56
57 public enum Texture
58 {
59 None,
60 Wood
61 }
62
63 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64 public delegate void CallbackFunction(int arg);
65
66 [StructLayout(LayoutKind.Sequential)]
67 public struct Functions
68 {
69 public int version;
70 public CallbackFunction start;
71 public CallbackFunction step;
72 public CallbackFunction command;
73 public CallbackFunction stop;
74 public string path_to_textures;
75 }
76
77 [DllImport("drawstuff", EntryPoint = "dsDrawBox")]
78 public static extern void DrawBox(ref d.Vector3 pos, ref d.Matrix3 R, ref d.Vector3 sides);
79
80 [DllImport("drawstuff", EntryPoint = "dsDrawCapsule")]
81 public static extern void DrawCapsule(ref d.Vector3 pos, ref d.Matrix3 R, dReal length, dReal radius);
82
83 [DllImport("drawstuff", EntryPoint = "dsDrawConvex")]
84 public static extern void DrawConvex(ref d.Vector3 pos, ref d.Matrix3 R, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
85
86 [DllImport("drawstuff", EntryPoint = "dsSetColor")]
87 public static extern void SetColor(float red, float green, float blue);
88
89 [DllImport("drawstuff", EntryPoint = "dsSetTexture")]
90 public static extern void SetTexture(Texture texture);
91
92 [DllImport("drawstuff", EntryPoint = "dsSetViewpoint")]
93 public static extern void SetViewpoint(ref d.Vector3 xyz, ref d.Vector3 hpr);
94
95 [DllImport("drawstuff", EntryPoint = "dsSimulationLoop")]
96 public static extern void SimulationLoop(int argc, string[] argv, int window_width, int window_height, ref Functions fn);
97 }
98}
diff --git a/OpenSim/Region/Physics/Manager/IMesher.cs b/OpenSim/Region/Physics/Manager/IMesher.cs
index 2e7bb5d..e290dc9 100644
--- a/OpenSim/Region/Physics/Manager/IMesher.cs
+++ b/OpenSim/Region/Physics/Manager/IMesher.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Runtime.InteropServices;
30using OpenSim.Framework; 31using OpenSim.Framework;
31using OpenMetaverse; 32using OpenMetaverse;
32 33
@@ -36,7 +37,12 @@ namespace OpenSim.Region.Physics.Manager
36 { 37 {
37 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod); 38 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod);
38 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical); 39 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical);
39 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache); 40 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde);
41 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde);
42 IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex);
43 void ReleaseMesh(IMesh mesh);
44 void ExpireReleaseMeshs();
45 void ExpireFileCache();
40 } 46 }
41 47
42 // Values for level of detail to be passed to the mesher. 48 // Values for level of detail to be passed to the mesher.
@@ -54,6 +60,25 @@ namespace OpenSim.Region.Physics.Manager
54 { 60 {
55 } 61 }
56 62
63 [Serializable()]
64 [StructLayout(LayoutKind.Explicit)]
65 public struct AMeshKey
66 {
67 [FieldOffset(0)]
68 public UUID uuid;
69 [FieldOffset(0)]
70 public ulong hashA;
71 [FieldOffset(8)]
72 public ulong hashB;
73 [FieldOffset(16)]
74 public ulong hashC;
75
76 public override string ToString()
77 {
78 return uuid.ToString() + "-" + hashC.ToString("x") ;
79 }
80 }
81
57 public interface IMesh 82 public interface IMesh
58 { 83 {
59 List<Vector3> getVertexList(); 84 List<Vector3> getVertexList();
@@ -67,5 +92,7 @@ namespace OpenSim.Region.Physics.Manager
67 void releasePinned(); 92 void releasePinned();
68 void Append(IMesh newMesh); 93 void Append(IMesh newMesh);
69 void TransformLinear(float[,] matrix, float[] offset); 94 void TransformLinear(float[,] matrix, float[] offset);
95 Vector3 GetCentroid();
96 Vector3 GetOBB();
70 } 97 }
71} 98}
diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
index 6bc6e23..60f6480 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
@@ -43,7 +43,8 @@ namespace OpenSim.Region.Physics.Manager
43 Unknown = 0, 43 Unknown = 0,
44 Agent = 1, 44 Agent = 1,
45 Prim = 2, 45 Prim = 2,
46 Ground = 3 46 Ground = 3,
47 Water = 4
47 } 48 }
48 49
49 public enum PIDHoverType 50 public enum PIDHoverType
@@ -59,15 +60,41 @@ namespace OpenSim.Region.Physics.Manager
59 public Vector3 Position; 60 public Vector3 Position;
60 public Vector3 SurfaceNormal; 61 public Vector3 SurfaceNormal;
61 public float PenetrationDepth; 62 public float PenetrationDepth;
63 public float RelativeSpeed;
64 public bool CharacterFeet;
62 65
63 public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth) 66 public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth)
64 { 67 {
65 Position = position; 68 Position = position;
66 SurfaceNormal = surfaceNormal; 69 SurfaceNormal = surfaceNormal;
67 PenetrationDepth = penetrationDepth; 70 PenetrationDepth = penetrationDepth;
71 RelativeSpeed = 0f; // for now let this one be set explicity
72 CharacterFeet = true; // keep other plugins work as before
73 }
74
75 public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth, bool feet)
76 {
77 Position = position;
78 SurfaceNormal = surfaceNormal;
79 PenetrationDepth = penetrationDepth;
80 RelativeSpeed = 0f; // for now let this one be set explicity
81 CharacterFeet = feet; // keep other plugins work as before
68 } 82 }
69 } 83 }
70 84
85 public struct ContactData
86 {
87 public float mu;
88 public float bounce;
89 public bool softcolide;
90
91 public ContactData(float _mu, float _bounce, bool _softcolide)
92 {
93 mu = _mu;
94 bounce = _bounce;
95 softcolide = _softcolide;
96 }
97 }
71 /// <summary> 98 /// <summary>
72 /// Used to pass collision information to OnCollisionUpdate listeners. 99 /// Used to pass collision information to OnCollisionUpdate listeners.
73 /// </summary> 100 /// </summary>
@@ -99,7 +126,7 @@ namespace OpenSim.Region.Physics.Manager
99 m_objCollisionList.Add(localID, contact); 126 m_objCollisionList.Add(localID, contact);
100 } 127 }
101 else 128 else
102 { 129 {
103 if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth) 130 if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth)
104 m_objCollisionList[localID] = contact; 131 m_objCollisionList[localID] = contact;
105 } 132 }
@@ -135,6 +162,8 @@ namespace OpenSim.Region.Physics.Manager
135 /// </summary> 162 /// </summary>
136 public event CollisionUpdate OnCollisionUpdate; 163 public event CollisionUpdate OnCollisionUpdate;
137 164
165 public virtual void SetVehicle(object vdata) { }
166
138 public event OutOfBounds OnOutOfBounds; 167 public event OutOfBounds OnOutOfBounds;
139#pragma warning restore 67 168#pragma warning restore 67
140 169
@@ -142,11 +171,32 @@ namespace OpenSim.Region.Physics.Manager
142 { 171 {
143 get { return new NullPhysicsActor(); } 172 get { return new NullPhysicsActor(); }
144 } 173 }
174
175 public virtual bool Building { get; set; }
176
177 public virtual void getContactData(ref ContactData cdata)
178 {
179 cdata.mu = 0;
180 cdata.bounce = 0;
181 }
145 182
146 public abstract bool Stopped { get; } 183 public abstract bool Stopped { get; }
147 184
148 public abstract Vector3 Size { get; set; } 185 public abstract Vector3 Size { get; set; }
149 186
187 public virtual void setAvatarSize(Vector3 size, float feetOffset)
188 {
189 Size = size;
190 }
191
192 public virtual bool Phantom { get; set; }
193
194 public virtual bool IsVolumeDtc
195 {
196 get { return false; }
197 set { return; }
198 }
199
150 public virtual byte PhysicsShapeType { get; set; } 200 public virtual byte PhysicsShapeType { get; set; }
151 201
152 public abstract PrimitiveBaseShape Shape { set; } 202 public abstract PrimitiveBaseShape Shape { set; }
@@ -169,7 +219,7 @@ namespace OpenSim.Region.Physics.Manager
169 /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or 219 /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or
170 /// water. This is not a problem due to the formatting of names given by prims and avatars. 220 /// water. This is not a problem due to the formatting of names given by prims and avatars.
171 /// </remarks> 221 /// </remarks>
172 public string Name { get; protected set; } 222 public string Name { get; set; }
173 223
174 /// <summary> 224 /// <summary>
175 /// This is being used by ODE joint code. 225 /// This is being used by ODE joint code.
@@ -253,6 +303,51 @@ namespace OpenSim.Region.Physics.Manager
253 public abstract Vector3 GeometricCenter { get; } 303 public abstract Vector3 GeometricCenter { get; }
254 public abstract Vector3 CenterOfMass { get; } 304 public abstract Vector3 CenterOfMass { get; }
255 305
306 public virtual Vector3 OOBsize
307 {
308 get
309 {
310 Vector3 s=Size;
311 s.X *=0.5f;
312 s.Y *=0.5f;
313 s.Z *=0.5f;
314 return s;
315 }
316 }
317
318 public virtual Vector3 OOBoffset
319 {
320 get
321 {
322 return Vector3.Zero;
323 }
324 }
325
326 public virtual float OOBRadiusSQ
327 {
328 get
329 {
330 return Size.LengthSquared() * 0.25f; // ((0.5^2)
331 }
332 }
333
334
335 public virtual float PhysicsCost
336 {
337 get
338 {
339 return 0.1f;
340 }
341 }
342
343 public virtual float StreamCost
344 {
345 get
346 {
347 return 1.0f;
348 }
349 }
350
256 /// <summary> 351 /// <summary>
257 /// The desired velocity of this actor. 352 /// The desired velocity of this actor.
258 /// </summary> 353 /// </summary>
@@ -314,6 +409,12 @@ namespace OpenSim.Region.Physics.Manager
314 public abstract void UnSubscribeEvents(); 409 public abstract void UnSubscribeEvents();
315 public abstract bool SubscribedEvents(); 410 public abstract bool SubscribedEvents();
316 411
412 public virtual void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { }
413
414 // Warning in a parent part it returns itself, not null
415 public virtual PhysicsActor ParentActor { get { return this; } }
416
417
317 // Extendable interface for new, physics engine specific operations 418 // Extendable interface for new, physics engine specific operations
318 public virtual object Extension(string pFunct, params object[] pParams) 419 public virtual object Extension(string pFunct, params object[] pParams)
319 { 420 {
@@ -324,9 +425,11 @@ namespace OpenSim.Region.Physics.Manager
324 425
325 public class NullPhysicsActor : PhysicsActor 426 public class NullPhysicsActor : PhysicsActor
326 { 427 {
428 private ActorTypes m_actorType = ActorTypes.Unknown;
429
327 public override bool Stopped 430 public override bool Stopped
328 { 431 {
329 get{ return false; } 432 get{ return true; }
330 } 433 }
331 434
332 public override Vector3 Position 435 public override Vector3 Position
@@ -343,6 +446,7 @@ namespace OpenSim.Region.Physics.Manager
343 446
344 public override uint LocalID 447 public override uint LocalID
345 { 448 {
449 get { return 0; }
346 set { return; } 450 set { return; }
347 } 451 }
348 452
@@ -402,50 +506,17 @@ namespace OpenSim.Region.Physics.Manager
402 set { return; } 506 set { return; }
403 } 507 }
404 508
405 public override void VehicleFloatParam(int param, float value) 509 public override void VehicleFloatParam(int param, float value) {}
406 { 510 public override void VehicleVectorParam(int param, Vector3 value) { }
511 public override void VehicleRotationParam(int param, Quaternion rotation) { }
512 public override void VehicleFlags(int param, bool remove) { }
513 public override void SetVolumeDetect(int param) {}
514 public override void SetMaterial(int material) {}
515 public override Vector3 CenterOfMass { get { return Vector3.Zero; }}
407 516
408 } 517 public override Vector3 GeometricCenter { get { return Vector3.Zero; }}
409 518
410 public override void VehicleVectorParam(int param, Vector3 value) 519 public override PrimitiveBaseShape Shape { set { return; }}
411 {
412
413 }
414
415 public override void VehicleRotationParam(int param, Quaternion rotation)
416 {
417
418 }
419
420 public override void VehicleFlags(int param, bool remove)
421 {
422
423 }
424
425 public override void SetVolumeDetect(int param)
426 {
427
428 }
429
430 public override void SetMaterial(int material)
431 {
432
433 }
434
435 public override Vector3 CenterOfMass
436 {
437 get { return Vector3.Zero; }
438 }
439
440 public override Vector3 GeometricCenter
441 {
442 get { return Vector3.Zero; }
443 }
444
445 public override PrimitiveBaseShape Shape
446 {
447 set { return; }
448 }
449 520
450 public override Vector3 Velocity 521 public override Vector3 Velocity
451 { 522 {
@@ -465,9 +536,7 @@ namespace OpenSim.Region.Physics.Manager
465 set { } 536 set { }
466 } 537 }
467 538
468 public override void CrossingFailure() 539 public override void CrossingFailure() {}
469 {
470 }
471 540
472 public override Quaternion Orientation 541 public override Quaternion Orientation
473 { 542 {
@@ -507,8 +576,20 @@ namespace OpenSim.Region.Physics.Manager
507 576
508 public override int PhysicsActorType 577 public override int PhysicsActorType
509 { 578 {
510 get { return (int) ActorTypes.Unknown; } 579 get { return (int)m_actorType; }
511 set { return; } 580 set {
581 ActorTypes type = (ActorTypes)value;
582 switch (type)
583 {
584 case ActorTypes.Ground:
585 case ActorTypes.Water:
586 m_actorType = type;
587 break;
588 default:
589 m_actorType = ActorTypes.Unknown;
590 break;
591 }
592 }
512 } 593 }
513 594
514 public override bool Kinematic 595 public override bool Kinematic
@@ -517,26 +598,11 @@ namespace OpenSim.Region.Physics.Manager
517 set { return; } 598 set { return; }
518 } 599 }
519 600
520 public override void link(PhysicsActor obj) 601 public override void link(PhysicsActor obj) { }
521 { 602 public override void delink() { }
522 } 603 public override void LockAngularMotion(Vector3 axis) { }
523 604 public override void AddForce(Vector3 force, bool pushforce) { }
524 public override void delink() 605 public override void AddAngularForce(Vector3 force, bool pushforce) { }
525 {
526 }
527
528 public override void LockAngularMotion(Vector3 axis)
529 {
530 }
531
532 public override void AddForce(Vector3 force, bool pushforce)
533 {
534 }
535
536 public override void AddAngularForce(Vector3 force, bool pushforce)
537 {
538
539 }
540 606
541 public override Vector3 RotationalVelocity 607 public override Vector3 RotationalVelocity
542 { 608 {
@@ -564,21 +630,10 @@ namespace OpenSim.Region.Physics.Manager
564 public override float APIDStrength { set { return; } } 630 public override float APIDStrength { set { return; } }
565 public override float APIDDamping { set { return; } } 631 public override float APIDDamping { set { return; } }
566 632
567 public override void SetMomentum(Vector3 momentum) 633 public override void SetMomentum(Vector3 momentum) { }
568 {
569 }
570
571 public override void SubscribeEvents(int ms)
572 {
573
574 }
575 public override void UnSubscribeEvents()
576 {
577 634
578 } 635 public override void SubscribeEvents(int ms) { }
579 public override bool SubscribedEvents() 636 public override void UnSubscribeEvents() { }
580 { 637 public override bool SubscribedEvents() { return false; }
581 return false;
582 }
583 } 638 }
584} 639}
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index d8279b7..ddbe80b 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -60,6 +60,14 @@ namespace OpenSim.Region.Physics.Manager
60 m_log.Info("[PHYSICS]: Added meshing engine: " + plugHard.GetName()); 60 m_log.Info("[PHYSICS]: Added meshing engine: " + plugHard.GetName());
61 } 61 }
62 62
63 // Legacy method for simulators before extent was passed
64 public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName,
65 IConfigSource config, string regionName)
66 {
67 Vector3 extent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
68 return GetPhysicsScene(physEngineName, meshEngineName, config, regionName, extent);
69 }
70
63 /// <summary> 71 /// <summary>
64 /// Get a physics scene for the given physics engine and mesher. 72 /// Get a physics scene for the given physics engine and mesher.
65 /// </summary> 73 /// </summary>
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 9cdedbf..96ef0a6 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -41,6 +41,10 @@ namespace OpenSim.Region.Physics.Manager
41 41
42 public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal); 42 public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal);
43 public delegate void RayCallback(List<ContactResult> list); 43 public delegate void RayCallback(List<ContactResult> list);
44 public delegate void ProbeBoxCallback(List<ContactResult> list);
45 public delegate void ProbeSphereCallback(List<ContactResult> list);
46 public delegate void ProbePlaneCallback(List<ContactResult> list);
47 public delegate void SitAvatarCallback(int status, uint partID, Vector3 offset, Quaternion Orientation);
44 48
45 public delegate void JointMoved(PhysicsJoint joint); 49 public delegate void JointMoved(PhysicsJoint joint);
46 public delegate void JointDeactivated(PhysicsJoint joint); 50 public delegate void JointDeactivated(PhysicsJoint joint);
@@ -89,6 +93,8 @@ namespace OpenSim.Region.Physics.Manager
89 public Vector3 Normal; 93 public Vector3 Normal;
90 } 94 }
91 95
96
97
92 public abstract class PhysicsScene 98 public abstract class PhysicsScene
93 { 99 {
94// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 100// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -146,9 +152,16 @@ namespace OpenSim.Region.Physics.Manager
146 /// <param name="size"></param> 152 /// <param name="size"></param>
147 /// <param name="isFlying"></param> 153 /// <param name="isFlying"></param>
148 /// <returns></returns> 154 /// <returns></returns>
155<<<<<<< HEAD
149 public abstract PhysicsActor AddAvatar( 156 public abstract PhysicsActor AddAvatar(
150 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying); 157 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying);
151 158
159=======
160 public virtual PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
161 {
162 return null;
163 }
164>>>>>>> avn/ubitvar
152 /// <summary> 165 /// <summary>
153 /// Add an avatar 166 /// Add an avatar
154 /// </summary> 167 /// </summary>
@@ -170,6 +183,12 @@ namespace OpenSim.Region.Physics.Manager
170 return ret; 183 return ret;
171 } 184 }
172 185
186 public virtual PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, float feetOffset, bool isFlying)
187 {
188 PhysicsActor ret = AddAvatar(localID, avName, position, size, isFlying);
189 return ret;
190 }
191
173 /// <summary> 192 /// <summary>
174 /// Remove an avatar. 193 /// Remove an avatar.
175 /// </summary> 194 /// </summary>
@@ -185,6 +204,19 @@ namespace OpenSim.Region.Physics.Manager
185 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 204 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
186 Vector3 size, Quaternion rotation, bool isPhysical, uint localid); 205 Vector3 size, Quaternion rotation, bool isPhysical, uint localid);
187 206
207 public virtual PhysicsActor AddPrimShape(string primName, PhysicsActor parent, PrimitiveBaseShape pbs, Vector3 position,
208 uint localid, byte[] sdata)
209 {
210 return null;
211 }
212
213 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
214 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, uint localid)
215 {
216 return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid);
217 }
218
219
188 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 220 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
189 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid) 221 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid)
190 { 222 {
@@ -258,6 +290,9 @@ namespace OpenSim.Region.Physics.Manager
258 290
259 public abstract void AddPhysicsActorTaint(PhysicsActor prim); 291 public abstract void AddPhysicsActorTaint(PhysicsActor prim);
260 292
293
294 public virtual void PrepareSimulation() { }
295
261 /// <summary> 296 /// <summary>
262 /// Perform a simulation of the current physics scene over the given timestep. 297 /// Perform a simulation of the current physics scene over the given timestep.
263 /// </summary> 298 /// </summary>
@@ -302,7 +337,7 @@ namespace OpenSim.Region.Physics.Manager
302 } 337 }
303 338
304 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} 339 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
305 340 public virtual void CombineTerrain(float[] heightMap, Vector3 pOffset) {}
306 public virtual void UnCombine(PhysicsScene pScene) {} 341 public virtual void UnCombine(PhysicsScene pScene) {}
307 342
308 /// <summary> 343 /// <summary>
@@ -351,6 +386,31 @@ namespace OpenSim.Region.Physics.Manager
351 return false; 386 return false;
352 } 387 }
353 388
389 public virtual List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags flags)
390 {
391 return new List<ContactResult>();
392 }
393
394 public virtual List<ContactResult> BoxProbe(Vector3 position, Vector3 size, Quaternion orientation, int Count, RayFilterFlags flags)
395 {
396 return new List<ContactResult>();
397 }
398
399 public virtual List<ContactResult> SphereProbe(Vector3 position, float radius, int Count, RayFilterFlags flags)
400 {
401 return new List<ContactResult>();
402 }
403
404 public virtual List<ContactResult> PlaneProbe(PhysicsActor actor, Vector4 plane, int Count, RayFilterFlags flags)
405 {
406 return new List<ContactResult>();
407 }
408
409 public virtual int SitAvatar(PhysicsActor actor, Vector3 AbsolutePosition, Vector3 CameraPosition, Vector3 offset, Vector3 AvatarSize, SitAvatarCallback PhysicsSitResponse)
410 {
411 return 0;
412 }
413
354 // Extendable interface for new, physics engine specific operations 414 // Extendable interface for new, physics engine specific operations
355 public virtual object Extension(string pFunct, params object[] pParams) 415 public virtual object Extension(string pFunct, params object[] pParams)
356 { 416 {
diff --git a/OpenSim/Region/Physics/Manager/VehicleConstants.cs b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
index f0775c1..8e24b4c 100644
--- a/OpenSim/Region/Physics/Manager/VehicleConstants.cs
+++ b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using OpenMetaverse;
29 30
30namespace OpenSim.Region.Physics.Manager 31namespace OpenSim.Region.Physics.Manager
31{ 32{
@@ -117,5 +118,47 @@ namespace OpenSim.Region.Physics.Manager
117 NO_DEFLECTION = 16392, 118 NO_DEFLECTION = 16392,
118 LOCK_ROTATION = 32784 119 LOCK_ROTATION = 32784
119 } 120 }
120 121
122 public struct VehicleData
123 {
124 public Vehicle m_type;
125 public VehicleFlag m_flags;
126
127 // Linear properties
128 public Vector3 m_linearMotorDirection;
129 public Vector3 m_linearFrictionTimescale;
130 public float m_linearMotorDecayTimescale;
131 public float m_linearMotorTimescale;
132 public Vector3 m_linearMotorOffset;
133
134 //Angular properties
135 public Vector3 m_angularMotorDirection;
136 public float m_angularMotorTimescale;
137 public float m_angularMotorDecayTimescale;
138 public Vector3 m_angularFrictionTimescale;
139
140 //Deflection properties
141 public float m_angularDeflectionEfficiency;
142 public float m_angularDeflectionTimescale;
143 public float m_linearDeflectionEfficiency;
144 public float m_linearDeflectionTimescale;
145
146 //Banking properties
147 public float m_bankingEfficiency;
148 public float m_bankingMix;
149 public float m_bankingTimescale;
150
151 //Hover and Buoyancy properties
152 public float m_VhoverHeight;
153 public float m_VhoverEfficiency;
154 public float m_VhoverTimescale;
155 public float m_VehicleBuoyancy;
156
157 //Attractor properties
158 public float m_verticalAttractionEfficiency;
159 public float m_verticalAttractionTimescale;
160
161 // Axis
162 public Quaternion m_referenceFrame;
163 }
121} 164}
diff --git a/OpenSim/Region/Physics/Manager/ZeroMesher.cs b/OpenSim/Region/Physics/Manager/ZeroMesher.cs
index 270d2ec..890951f 100644
--- a/OpenSim/Region/Physics/Manager/ZeroMesher.cs
+++ b/OpenSim/Region/Physics/Manager/ZeroMesher.cs
@@ -64,20 +64,34 @@ namespace OpenSim.Region.Physics.Manager
64 { 64 {
65 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) 65 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
66 { 66 {
67 return CreateMesh(primName, primShape, size, lod, false, false); 67 return CreateMesh(primName, primShape, size, lod, false);
68 } 68 }
69 69
70 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) 70 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde)
71 { 71 {
72 return CreateMesh(primName, primShape, size, lod, false, false); 72 return CreateMesh(primName, primShape, size, lod, false);
73 } 73 }
74 74
75 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache) 75 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex,bool forOde)
76 {
77 return CreateMesh(primName, primShape, size, lod, false);
78 }
79
80 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical)
76 { 81 {
77 // Remove the reference to the encoded JPEG2000 data so it can be GCed 82 // Remove the reference to the encoded JPEG2000 data so it can be GCed
78 primShape.SculptData = OpenMetaverse.Utils.EmptyBytes; 83 primShape.SculptData = OpenMetaverse.Utils.EmptyBytes;
79 84
80 return null; 85 return null;
81 } 86 }
87
88 public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex)
89 {
90 return null;
91 }
92
93 public void ReleaseMesh(IMesh mesh) { }
94 public void ExpireReleaseMeshs() { }
95 public void ExpireFileCache() { }
82 } 96 }
83} 97}
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs
index bd8e306..e6b32e7 100644
--- a/OpenSim/Region/Physics/Meshing/Mesh.cs
+++ b/OpenSim/Region/Physics/Meshing/Mesh.cs
@@ -46,11 +46,36 @@ namespace OpenSim.Region.Physics.Meshing
46 IntPtr m_indicesPtr = IntPtr.Zero; 46 IntPtr m_indicesPtr = IntPtr.Zero;
47 int m_indexCount = 0; 47 int m_indexCount = 0;
48 public float[] m_normals; 48 public float[] m_normals;
49 Vector3 _centroid;
50 int _centroidDiv;
51
52 private class vertexcomp : IEqualityComparer<Vertex>
53 {
54 public bool Equals(Vertex v1, Vertex v2)
55 {
56 if (v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z)
57 return true;
58 else
59 return false;
60 }
61 public int GetHashCode(Vertex v)
62 {
63 int a = v.X.GetHashCode();
64 int b = v.Y.GetHashCode();
65 int c = v.Z.GetHashCode();
66 return (a << 16) ^ (b << 8) ^ c;
67 }
68
69 }
49 70
50 public Mesh() 71 public Mesh()
51 { 72 {
52 m_vertices = new Dictionary<Vertex, int>(); 73 vertexcomp vcomp = new vertexcomp();
74
75 m_vertices = new Dictionary<Vertex, int>(vcomp);
53 m_triangles = new List<Triangle>(); 76 m_triangles = new List<Triangle>();
77 _centroid = Vector3.Zero;
78 _centroidDiv = 0;
54 } 79 }
55 80
56 public Mesh Clone() 81 public Mesh Clone()
@@ -61,7 +86,8 @@ namespace OpenSim.Region.Physics.Meshing
61 { 86 {
62 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone())); 87 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone()));
63 } 88 }
64 89 result._centroid = _centroid;
90 result._centroidDiv = _centroidDiv;
65 return result; 91 return result;
66 } 92 }
67 93
@@ -71,15 +97,63 @@ namespace OpenSim.Region.Physics.Meshing
71 throw new NotSupportedException("Attempt to Add to a pinned Mesh"); 97 throw new NotSupportedException("Attempt to Add to a pinned Mesh");
72 // If a vertex of the triangle is not yet in the vertices list, 98 // If a vertex of the triangle is not yet in the vertices list,
73 // add it and set its index to the current index count 99 // add it and set its index to the current index count
100 // vertex == seems broken
101 // skip colapsed triangles
102 if ((triangle.v1.X == triangle.v2.X && triangle.v1.Y == triangle.v2.Y && triangle.v1.Z == triangle.v2.Z)
103 || (triangle.v1.X == triangle.v3.X && triangle.v1.Y == triangle.v3.Y && triangle.v1.Z == triangle.v3.Z)
104 || (triangle.v2.X == triangle.v3.X && triangle.v2.Y == triangle.v3.Y && triangle.v2.Z == triangle.v3.Z)
105 )
106 {
107 return;
108 }
109
110 if (m_vertices.Count == 0)
111 {
112 _centroidDiv = 0;
113 _centroid = Vector3.Zero;
114 }
115
74 if (!m_vertices.ContainsKey(triangle.v1)) 116 if (!m_vertices.ContainsKey(triangle.v1))
117 {
75 m_vertices[triangle.v1] = m_vertices.Count; 118 m_vertices[triangle.v1] = m_vertices.Count;
119 _centroid.X += triangle.v1.X;
120 _centroid.Y += triangle.v1.Y;
121 _centroid.Z += triangle.v1.Z;
122 _centroidDiv++;
123 }
76 if (!m_vertices.ContainsKey(triangle.v2)) 124 if (!m_vertices.ContainsKey(triangle.v2))
125 {
77 m_vertices[triangle.v2] = m_vertices.Count; 126 m_vertices[triangle.v2] = m_vertices.Count;
127 _centroid.X += triangle.v2.X;
128 _centroid.Y += triangle.v2.Y;
129 _centroid.Z += triangle.v2.Z;
130 _centroidDiv++;
131 }
78 if (!m_vertices.ContainsKey(triangle.v3)) 132 if (!m_vertices.ContainsKey(triangle.v3))
133 {
79 m_vertices[triangle.v3] = m_vertices.Count; 134 m_vertices[triangle.v3] = m_vertices.Count;
135 _centroid.X += triangle.v3.X;
136 _centroid.Y += triangle.v3.Y;
137 _centroid.Z += triangle.v3.Z;
138 _centroidDiv++;
139 }
80 m_triangles.Add(triangle); 140 m_triangles.Add(triangle);
81 } 141 }
82 142
143 public Vector3 GetCentroid()
144 {
145 if (_centroidDiv > 0)
146 return new Vector3(_centroid.X / _centroidDiv, _centroid.Y / _centroidDiv, _centroid.Z / _centroidDiv);
147 else
148 return Vector3.Zero;
149 }
150
151 // not functional
152 public Vector3 GetOBB()
153 {
154 return new Vector3(0.5f, 0.5f, 0.5f);
155 }
156
83 public void CalcNormals() 157 public void CalcNormals()
84 { 158 {
85 int iTriangles = m_triangles.Count; 159 int iTriangles = m_triangles.Count;
@@ -185,6 +259,7 @@ namespace OpenSim.Region.Physics.Meshing
185 public void getVertexListAsPtrToFloatArray(out IntPtr vertices, out int vertexStride, out int vertexCount) 259 public void getVertexListAsPtrToFloatArray(out IntPtr vertices, out int vertexStride, out int vertexCount)
186 { 260 {
187 // A vertex is 3 floats 261 // A vertex is 3 floats
262
188 vertexStride = 3 * sizeof(float); 263 vertexStride = 3 * sizeof(float);
189 264
190 // If there isn't an unmanaged array allocated yet, do it now 265 // If there isn't an unmanaged array allocated yet, do it now
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 42231b5..ef6482a 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -909,11 +909,21 @@ namespace OpenSim.Region.Physics.Meshing
909 return CreateMesh(primName, primShape, size, lod, false, true); 909 return CreateMesh(primName, primShape, size, lod, false, true);
910 } 910 }
911 911
912 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde)
913 {
914 return CreateMesh(primName, primShape, size, lod, false);
915 }
916
912 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) 917 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical)
913 { 918 {
914 return CreateMesh(primName, primShape, size, lod, isPhysical, true); 919 return CreateMesh(primName, primShape, size, lod, isPhysical, true);
915 } 920 }
916 921
922 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde)
923 {
924 return CreateMesh(primName, primShape, size, lod, isPhysical, true);
925 }
926
917 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache) 927 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache)
918 { 928 {
919#if SPAM 929#if SPAM
@@ -967,5 +977,13 @@ namespace OpenSim.Region.Physics.Meshing
967 977
968 return mesh; 978 return mesh;
969 } 979 }
980 public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex)
981 {
982 return null;
983 }
984
985 public void ReleaseMesh(IMesh imesh) { }
986 public void ExpireReleaseMeshs() { }
987 public void ExpireFileCache() { }
970 } 988 }
971} 989}
diff --git a/OpenSim/Region/Physics/Meshing/SculptMap.cs b/OpenSim/Region/Physics/Meshing/SculptMap.cs
index 740424e..b3d9cb6 100644
--- a/OpenSim/Region/Physics/Meshing/SculptMap.cs
+++ b/OpenSim/Region/Physics/Meshing/SculptMap.cs
@@ -58,28 +58,24 @@ namespace PrimMesher
58 if (bmW == 0 || bmH == 0) 58 if (bmW == 0 || bmH == 0)
59 throw new Exception("SculptMap: bitmap has no data"); 59 throw new Exception("SculptMap: bitmap has no data");
60 60
61 int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image 61 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
62 62
63 bool smallMap = bmW * bmH <= numLodPixels;
63 bool needsScaling = false; 64 bool needsScaling = false;
64 65
65 bool smallMap = bmW * bmH <= lod * lod;
66
67 width = bmW; 66 width = bmW;
68 height = bmH; 67 height = bmH;
69 while (width * height > numLodPixels) 68 while (width * height > numLodPixels * 4)
70 { 69 {
71 width >>= 1; 70 width >>= 1;
72 height >>= 1; 71 height >>= 1;
73 needsScaling = true; 72 needsScaling = true;
74 } 73 }
75 74
76
77
78 try 75 try
79 { 76 {
80 if (needsScaling) 77 if (needsScaling)
81 bm = ScaleImage(bm, width, height, 78 bm = ScaleImage(bm, width, height);
82 System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor);
83 } 79 }
84 80
85 catch (Exception e) 81 catch (Exception e)
@@ -87,7 +83,7 @@ namespace PrimMesher
87 throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); 83 throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
88 } 84 }
89 85
90 if (width * height > lod * lod) 86 if (width * height > numLodPixels)
91 { 87 {
92 width >>= 1; 88 width >>= 1;
93 height >>= 1; 89 height >>= 1;
@@ -144,15 +140,17 @@ namespace PrimMesher
144 int rowNdx, colNdx; 140 int rowNdx, colNdx;
145 int smNdx = 0; 141 int smNdx = 0;
146 142
143
147 for (rowNdx = 0; rowNdx < numRows; rowNdx++) 144 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
148 { 145 {
149 List<Coord> row = new List<Coord>(numCols); 146 List<Coord> row = new List<Coord>(numCols);
150 for (colNdx = 0; colNdx < numCols; colNdx++) 147 for (colNdx = 0; colNdx < numCols; colNdx++)
151 { 148 {
149
152 if (mirror) 150 if (mirror)
153 row.Add(new Coord(-(redBytes[smNdx] * pixScale - 0.5f), (greenBytes[smNdx] * pixScale - 0.5f), blueBytes[smNdx] * pixScale - 0.5f)); 151 row.Add(new Coord(-((float)redBytes[smNdx] * pixScale - 0.5f), ((float)greenBytes[smNdx] * pixScale - 0.5f), (float)blueBytes[smNdx] * pixScale - 0.5f));
154 else 152 else
155 row.Add(new Coord(redBytes[smNdx] * pixScale - 0.5f, greenBytes[smNdx] * pixScale - 0.5f, blueBytes[smNdx] * pixScale - 0.5f)); 153 row.Add(new Coord((float)redBytes[smNdx] * pixScale - 0.5f, (float)greenBytes[smNdx] * pixScale - 0.5f, (float)blueBytes[smNdx] * pixScale - 0.5f));
156 154
157 ++smNdx; 155 ++smNdx;
158 } 156 }
@@ -161,23 +159,39 @@ namespace PrimMesher
161 return rows; 159 return rows;
162 } 160 }
163 161
164 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight, 162 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight)
165 System.Drawing.Drawing2D.InterpolationMode interpMode)
166 { 163 {
167 Bitmap scaledImage = new Bitmap(srcImage, destWidth, destHeight);
168 scaledImage.SetResolution(96.0f, 96.0f);
169
170 Graphics grPhoto = Graphics.FromImage(scaledImage);
171 grPhoto.InterpolationMode = interpMode;
172 164
173 grPhoto.DrawImage(srcImage, 165 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
174 new Rectangle(0, 0, destWidth, destHeight), 166
175 new Rectangle(0, 0, srcImage.Width, srcImage.Height), 167 Color c;
176 GraphicsUnit.Pixel); 168 float xscale = srcImage.Width / destWidth;
169 float yscale = srcImage.Height / destHeight;
170
171 float sy = 0.5f;
172 for (int y = 0; y < destHeight; y++)
173 {
174 float sx = 0.5f;
175 for (int x = 0; x < destWidth; x++)
176 {
177 try
178 {
179 c = srcImage.GetPixel((int)(sx), (int)(sy));
180 scaledImage.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B));
181 }
182 catch (IndexOutOfRangeException)
183 {
184 }
177 185
178 grPhoto.Dispose(); 186 sx += xscale;
187 }
188 sy += yscale;
189 }
190 srcImage.Dispose();
179 return scaledImage; 191 return scaledImage;
180 } 192 }
193
194 }
195
181 } 196 }
182}
183#endif 197#endif
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 05eaf2a..9203169 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1251,7 +1251,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1251 public override Vector3 PIDTarget { set { return; } } 1251 public override Vector3 PIDTarget { set { return; } }
1252 public override bool PIDActive 1252 public override bool PIDActive
1253 { 1253 {
1254<<<<<<< HEAD
1254 get { return false; } 1255 get { return false; }
1256=======
1257 // os version
1258 // get { return false; }
1259>>>>>>> avn/ubitvar
1255 set { return; } 1260 set { return; }
1256 } 1261 }
1257 public override float PIDTau { set { return; } } 1262 public override float PIDTau { set { return; } }
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index f934b8a..6363422 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -2955,7 +2955,14 @@ Console.WriteLine(" JointCreateFixed");
2955 m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name); 2955 m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name);
2956 } 2956 }
2957 } 2957 }
2958<<<<<<< HEAD
2958 public override bool PIDActive { get; set; } 2959 public override bool PIDActive { get; set; }
2960=======
2961 // os version
2962 //public override bool PIDActive {get { return m_usePID; } set { m_usePID = value; } }
2963 public override bool PIDActive { set { m_usePID = value; } }
2964
2965>>>>>>> avn/ubitvar
2959 public override float PIDTau { set { m_PIDTau = value; } } 2966 public override float PIDTau { set { m_PIDTau = value; } }
2960 2967
2961 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } 2968 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
@@ -3352,7 +3359,14 @@ Console.WriteLine(" JointCreateFixed");
3352 RequestAssetDelegate assetProvider = _parent_scene.RequestAssetMethod; 3359 RequestAssetDelegate assetProvider = _parent_scene.RequestAssetMethod;
3353 if (assetProvider != null) 3360 if (assetProvider != null)
3354 assetProvider(_pbs.SculptTexture, MeshAssetReceived); 3361 assetProvider(_pbs.SculptTexture, MeshAssetReceived);
3362<<<<<<< HEAD
3355 }, null, "ODEPrim.CheckMeshAsset"); 3363 }, null, "ODEPrim.CheckMeshAsset");
3364=======
3365 // os version
3366 //}, null, "ODEPrim.CheckMeshAsset");
3367 // avn
3368 });
3369>>>>>>> avn/ubitvar
3356 } 3370 }
3357 } 3371 }
3358 3372
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
index 8d7d3b3..fa2ed3e 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
@@ -172,8 +172,13 @@ namespace OpenSim.Region.Physics.OdePlugin
172 /// <param name="req"></param> 172 /// <param name="req"></param>
173 private void RayCast(ODERayCastRequest req) 173 private void RayCast(ODERayCastRequest req)
174 { 174 {
175 // limit ray lenght or collisions will take all avaiable stack space
176 float len = req.length;
177 if (len > 250f)
178 len = 250f;
179
175 // Create the ray 180 // Create the ray
176 IntPtr ray = d.CreateRay(m_scene.space, req.length); 181 IntPtr ray = d.CreateRay(m_scene.space, len);
177 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); 182 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
178 183
179 // Collide test 184 // Collide test
@@ -218,8 +223,13 @@ namespace OpenSim.Region.Physics.OdePlugin
218 /// <param name="req"></param> 223 /// <param name="req"></param>
219 private void RayCast(ODERayRequest req) 224 private void RayCast(ODERayRequest req)
220 { 225 {
226 // limit ray lenght or collisions will take all avaiable stack space
227 float len = req.length;
228 if (len > 250f)
229 len = 250f;
230
221 // Create the ray 231 // Create the ray
222 IntPtr ray = d.CreateRay(m_scene.space, req.length); 232 IntPtr ray = d.CreateRay(m_scene.space, len);
223 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); 233 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
224 234
225 // Collide test 235 // Collide test
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 5953557..7f4a809 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -25,6 +25,14 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// Ubit changes for varsize regions
29// using a large Heightfield geometry for terrain
30// ODE ode should handle it fine
31// EXCEPT raycasts, those need to have limited range
32// (even in normal regions)
33// or aplication stack will just blowup
34
35
28//#define USE_DRAWSTUFF 36//#define USE_DRAWSTUFF
29//#define SPAM 37//#define SPAM
30 38
@@ -263,8 +271,10 @@ namespace OpenSim.Region.Physics.OdePlugin
263 271
264 private Random fluidRandomizer = new Random(Environment.TickCount); 272 private Random fluidRandomizer = new Random(Environment.TickCount);
265 273
266 private const uint m_regionWidth = Constants.RegionSize; 274 public bool m_suportCombine = true;
267 private const uint m_regionHeight = Constants.RegionSize; 275
276 private uint m_regionWidth = Constants.RegionSize;
277 private uint m_regionHeight = Constants.RegionSize;
268 278
269 private float ODE_STEPSIZE = 0.0178f; 279 private float ODE_STEPSIZE = 0.0178f;
270 private float metersInSpace = 29.9f; 280 private float metersInSpace = 29.9f;
@@ -290,7 +300,7 @@ namespace OpenSim.Region.Physics.OdePlugin
290 300
291 private readonly IntPtr contactgroup; 301 private readonly IntPtr contactgroup;
292 302
293 internal IntPtr WaterGeom; 303// internal IntPtr WaterGeom;
294 304
295 private float nmTerrainContactFriction = 255.0f; 305 private float nmTerrainContactFriction = 255.0f;
296 private float nmTerrainContactBounce = 0.1f; 306 private float nmTerrainContactBounce = 0.1f;
@@ -507,17 +517,17 @@ namespace OpenSim.Region.Physics.OdePlugin
507 public d.Vector3 xyz = new d.Vector3(128.1640f, 128.3079f, 25.7600f); 517 public d.Vector3 xyz = new d.Vector3(128.1640f, 128.3079f, 25.7600f);
508 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f); 518 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f);
509 519
510 // TODO: unused: private uint heightmapWidth = m_regionWidth + 1;
511 // TODO: unused: private uint heightmapHeight = m_regionHeight + 1;
512 // TODO: unused: private uint heightmapWidthSamples;
513 // TODO: unused: private uint heightmapHeightSamples;
514
515 private volatile int m_global_contactcount = 0; 520 private volatile int m_global_contactcount = 0;
516 521
517 private Vector3 m_worldOffset = Vector3.Zero; 522 private Vector3 m_worldOffset = Vector3.Zero;
518 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); 523 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
519 private PhysicsScene m_parentScene = null; 524 private PhysicsScene m_parentScene = null;
520 525
526 float spacesPerMeterX;
527 float spacesPerMeterY;
528 int spaceGridMaxX;
529 int spaceGridMaxY;
530
521 private ODERayCastRequestManager m_rayCastManager; 531 private ODERayCastRequestManager m_rayCastManager;
522 532
523 /// <summary> 533 /// <summary>
@@ -551,7 +561,7 @@ namespace OpenSim.Region.Physics.OdePlugin
551 viewthread.Start(); 561 viewthread.Start();
552 #endif 562 #endif
553 563
554 _watermap = new float[258 * 258]; 564 // _watermap = new float[258 * 258];
555 565
556 // Zero out the prim spaces array (we split our space into smaller spaces so 566 // Zero out the prim spaces array (we split our space into smaller spaces so
557 // we can hit test less. 567 // we can hit test less.
@@ -572,6 +582,16 @@ namespace OpenSim.Region.Physics.OdePlugin
572 } 582 }
573#endif 583#endif
574 584
585 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
586 {
587 WorldExtents.X = regionExtent.X;
588 m_regionWidth = (uint)regionExtent.X;
589 WorldExtents.Y = regionExtent.Y;
590 m_regionHeight = (uint)regionExtent.Y;
591 m_suportCombine = false;
592 Initialise(meshmerizer, config);
593 }
594
575 // Initialize the mesh plugin 595 // Initialize the mesh plugin
576 public override void Initialise(IMesher meshmerizer, IConfigSource config) 596 public override void Initialise(IMesher meshmerizer, IConfigSource config)
577 { 597 {
@@ -699,7 +719,31 @@ namespace OpenSim.Region.Physics.OdePlugin
699 719
700 contacts = new d.ContactGeom[contactsPerCollision]; 720 contacts = new d.ContactGeom[contactsPerCollision];
701 721
702 staticPrimspace = new IntPtr[(int)(300 / metersInSpace), (int)(300 / metersInSpace)]; 722 spacesPerMeterX = 1.0f / metersInSpace;
723 spacesPerMeterY = 1.0f / metersInSpace;
724
725 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX);
726 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY);
727
728 // ubit: limit number of spaces
729 if (spaceGridMaxX > 40)
730 {
731 spaceGridMaxX = 40;
732 spacesPerMeterX = WorldExtents.X / spaceGridMaxX;
733 }
734 if (spaceGridMaxY > 40)
735 {
736 spaceGridMaxY = 40;
737 spacesPerMeterY = WorldExtents.X / spaceGridMaxY;
738 }
739
740 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
741
742 // make this index limits
743 spaceGridMaxX--;
744 spaceGridMaxY--;
745
746
703 747
704 // Centeral contact friction and bounce 748 // Centeral contact friction and bounce
705 // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why 749 // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why
@@ -1883,6 +1927,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1883 1927
1884 public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) 1928 public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
1885 { 1929 {
1930 if (!m_suportCombine)
1931 return;
1886 m_worldOffset = offset; 1932 m_worldOffset = offset;
1887 WorldExtents = new Vector2(extents.X, extents.Y); 1933 WorldExtents = new Vector2(extents.X, extents.Y);
1888 m_parentScene = pScene; 1934 m_parentScene = pScene;
@@ -1891,12 +1937,17 @@ namespace OpenSim.Region.Physics.OdePlugin
1891 // Recovered for use by fly height. Kitto Flora 1937 // Recovered for use by fly height. Kitto Flora
1892 internal float GetTerrainHeightAtXY(float x, float y) 1938 internal float GetTerrainHeightAtXY(float x, float y)
1893 { 1939 {
1894 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1895 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1896
1897 IntPtr heightFieldGeom = IntPtr.Zero; 1940 IntPtr heightFieldGeom = IntPtr.Zero;
1941 int offsetX = 0;
1942 int offsetY = 0;
1943
1944 if (m_suportCombine)
1945 {
1946 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1947 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1948 }
1898 1949
1899 if (RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom)) 1950 if(RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom))
1900 { 1951 {
1901 if (heightFieldGeom != IntPtr.Zero) 1952 if (heightFieldGeom != IntPtr.Zero)
1902 { 1953 {
@@ -1910,8 +1961,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1910 (int)x < 0.001f || (int)y < 0.001f) 1961 (int)x < 0.001f || (int)y < 0.001f)
1911 return 0; 1962 return 0;
1912 1963
1913 x = x - offsetX; 1964 x = x - offsetX + 1f;
1914 y = y - offsetY; 1965 y = y - offsetY + 1f;
1915 1966
1916 index = (int)((int)x * ((int)Constants.RegionSize + 2) + (int)y); 1967 index = (int)((int)x * ((int)Constants.RegionSize + 2) + (int)y);
1917 1968
@@ -1969,11 +2020,35 @@ namespace OpenSim.Region.Physics.OdePlugin
1969 2020
1970 #region Add/Remove Entities 2021 #region Add/Remove Entities
1971 2022
2023<<<<<<< HEAD
1972 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) 2024 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
1973 { 2025 {
1974 OdeCharacter newAv 2026 OdeCharacter newAv
1975 = new OdeCharacter( 2027 = new OdeCharacter(
1976 avName, this, position, velocity, size, avPIDD, avPIDP, 2028 avName, this, position, velocity, size, avPIDD, avPIDP,
2029=======
2030/* core version
2031 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
2032 {
2033 OdeCharacter newAv
2034 = new OdeCharacter(
2035 avName, this, position, velocity, size, avPIDD, avPIDP,
2036 avCapRadius, avStandupTensor, avDensity,
2037 avMovementDivisorWalk, avMovementDivisorRun);
2038
2039 newAv.Flying = isFlying;
2040 newAv.MinimumGroundFlightOffset = minimumGroundFlightOffset;
2041 newAv.m_avatarplanted = avplanted;
2042
2043 return newAv;
2044 }
2045*/
2046 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
2047 {
2048 OdeCharacter newAv
2049 = new OdeCharacter(
2050 avName, this, position, Vector3.Zero, size, avPIDD, avPIDP,
2051>>>>>>> avn/ubitvar
1977 avCapRadius, avStandupTensor, avDensity, 2052 avCapRadius, avStandupTensor, avDensity,
1978 avMovementDivisorWalk, avMovementDivisorRun); 2053 avMovementDivisorWalk, avMovementDivisorRun);
1979 2054
@@ -2747,16 +2822,16 @@ namespace OpenSim.Region.Physics.OdePlugin
2747 { 2822 {
2748 int[] returnint = new int[2]; 2823 int[] returnint = new int[2];
2749 2824
2750 returnint[0] = (int) (pos.X/metersInSpace); 2825 returnint[0] = (int) (pos.X * spacesPerMeterX);
2751 2826
2752 if (returnint[0] > ((int) (259f/metersInSpace))) 2827 if (returnint[0] > spaceGridMaxX)
2753 returnint[0] = ((int) (259f/metersInSpace)); 2828 returnint[0] = spaceGridMaxX;
2754 if (returnint[0] < 0) 2829 if (returnint[0] < 0)
2755 returnint[0] = 0; 2830 returnint[0] = 0;
2756 2831
2757 returnint[1] = (int) (pos.Y/metersInSpace); 2832 returnint[1] = (int)(pos.Y * spacesPerMeterY);
2758 if (returnint[1] > ((int) (259f/metersInSpace))) 2833 if (returnint[1] > spaceGridMaxY)
2759 returnint[1] = ((int) (259f/metersInSpace)); 2834 returnint[1] = spaceGridMaxY;
2760 if (returnint[1] < 0) 2835 if (returnint[1] < 0)
2761 returnint[1] = 0; 2836 returnint[1] = 0;
2762 2837
@@ -3510,6 +3585,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3510 get { return false; } 3585 get { return false; }
3511 } 3586 }
3512 3587
3588/* godd try.. but not a fix
3513 #region ODE Specific Terrain Fixes 3589 #region ODE Specific Terrain Fixes
3514 private float[] ResizeTerrain512NearestNeighbour(float[] heightMap) 3590 private float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
3515 { 3591 {
@@ -3776,7 +3852,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3776 } 3852 }
3777 3853
3778 #endregion 3854 #endregion
3779 3855*/
3780 public override void SetTerrain(float[] heightMap) 3856 public override void SetTerrain(float[] heightMap)
3781 { 3857 {
3782 if (m_worldOffset != Vector3.Zero && m_parentScene != null) 3858 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
@@ -3797,71 +3873,63 @@ namespace OpenSim.Region.Physics.OdePlugin
3797 int startTime = Util.EnvironmentTickCount(); 3873 int startTime = Util.EnvironmentTickCount();
3798 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", Name, pOffset); 3874 m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0} with offset {1}", Name, pOffset);
3799 3875
3800 // this._heightmap[i] = (double)heightMap[i]; 3876
3801 // dbm (danx0r) -- creating a buffer zone of one extra sample all around
3802 //_origheightmap = heightMap;
3803
3804 float[] _heightmap; 3877 float[] _heightmap;
3805 3878
3806 // zero out a heightmap array float array (single dimension [flattened])) 3879 // ok im lasy this are just a aliases
3807 //if ((int)Constants.RegionSize == 256) 3880 uint regionsizeX = m_regionWidth;
3808 // _heightmap = new float[514 * 514]; 3881 uint regionsizeY = m_regionHeight;
3809 //else
3810
3811 _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))];
3812 3882
3813 uint heightmapWidth = Constants.RegionSize + 1; 3883 // map is rotated
3814 uint heightmapHeight = Constants.RegionSize + 1; 3884 uint heightmapWidth = regionsizeY + 2;
3885 uint heightmapHeight = regionsizeX + 2;
3815 3886
3816 uint heightmapWidthSamples; 3887 uint heightmapWidthSamples = heightmapWidth + 1;
3888 uint heightmapHeightSamples = heightmapHeight + 1;
3817 3889
3818 uint heightmapHeightSamples; 3890 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples];
3819
3820 //if (((int)Constants.RegionSize) == 256)
3821 //{
3822 // heightmapWidthSamples = 2 * (uint)Constants.RegionSize + 2;
3823 // heightmapHeightSamples = 2 * (uint)Constants.RegionSize + 2;
3824 // heightmapWidth++;
3825 // heightmapHeight++;
3826 //}
3827 //else
3828 //{
3829
3830 heightmapWidthSamples = (uint)Constants.RegionSize + 1;
3831 heightmapHeightSamples = (uint)Constants.RegionSize + 1;
3832 //}
3833 3891
3834 const float scale = 1.0f; 3892 const float scale = 1.0f;
3835 const float offset = 0.0f; 3893 const float offset = 0.0f;
3836 const float thickness = 0.2f; 3894 const float thickness = 10f;
3837 const int wrap = 0; 3895 const int wrap = 0;
3838 3896
3839 int regionsize = (int) Constants.RegionSize + 2;
3840 //Double resolution
3841 //if (((int)Constants.RegionSize) == 256)
3842 // heightMap = ResizeTerrain512Interpolation(heightMap);
3843 3897
3898 float hfmin = float.MaxValue;
3899 float hfmax = float.MinValue;
3900 float val;
3901 uint xx;
3902 uint yy;
3844 3903
3845 // if (((int)Constants.RegionSize) == 256 && (int)Constants.RegionSize == 256) 3904 uint maxXX = regionsizeX - 1;
3846 // regionsize = 512; 3905 uint maxYY = regionsizeY - 1;
3847 3906
3848 float hfmin = 2000; 3907 // flipping map adding one margin all around so things don't fall in edges
3849 float hfmax = -2000; 3908
3850 3909 uint xt = 0;
3851 for (int x = 0; x < heightmapWidthSamples; x++) 3910 xx = 0;
3911
3912 for (uint x = 0; x < heightmapWidthSamples; x++)
3852 { 3913 {
3853 for (int y = 0; y < heightmapHeightSamples; y++) 3914 if (x > 1 && xx < maxXX)
3915 xx++;
3916 yy = 0;
3917 for (uint y = 0; y < heightmapHeightSamples; y++)
3854 { 3918 {
3855 int xx = Util.Clip(x - 1, 0, regionsize - 1); 3919 if (y > 1 && y < maxYY)
3856 int yy = Util.Clip(y - 1, 0, regionsize - 1); 3920 yy += regionsizeX;
3857 3921
3858 3922 val = heightMap[yy + xx];
3859 float val= heightMap[yy * (int)Constants.RegionSize + xx]; 3923 if (val < 0.0f)
3860 _heightmap[x * ((int)Constants.RegionSize + 2) + y] = val; 3924 val = 0.0f;
3861 3925 _heightmap[xt + y] = val;
3862 hfmin = (val < hfmin) ? val : hfmin; 3926
3863 hfmax = (val > hfmax) ? val : hfmax; 3927 if (hfmin > val)
3928 hfmin = val;
3929 if (hfmax < val)
3930 hfmax = val;
3864 } 3931 }
3932 xt += heightmapHeightSamples;
3865 } 3933 }
3866 3934
3867 lock (OdeLock) 3935 lock (OdeLock)
@@ -3882,9 +3950,10 @@ namespace OpenSim.Region.Physics.OdePlugin
3882 3950
3883 } 3951 }
3884 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 3952 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3885 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, heightmapWidth + 1, heightmapHeight + 1, 3953 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight,
3886 (int)heightmapWidthSamples + 1, (int)heightmapHeightSamples + 1, scale, 3954 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
3887 offset, thickness, wrap); 3955 offset, thickness, wrap);
3956
3888 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 3957 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
3889 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); 3958 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1);
3890 if (GroundGeom != IntPtr.Zero) 3959 if (GroundGeom != IntPtr.Zero)
@@ -3899,17 +3968,15 @@ namespace OpenSim.Region.Physics.OdePlugin
3899 3968
3900 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f); 3969 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
3901 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f); 3970 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
3902 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
3903 3971
3904 q1 = q1 * q2; 3972 q1 = q1 * q2;
3905 //q1 = q1 * q3;
3906 Vector3 v3; 3973 Vector3 v3;
3907 float angle; 3974 float angle;
3908 q1.GetAxisAngle(out v3, out angle); 3975 q1.GetAxisAngle(out v3, out angle);
3909 3976
3910 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3977 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3911 d.GeomSetRotation(GroundGeom, ref R); 3978 d.GeomSetRotation(GroundGeom, ref R);
3912 d.GeomSetPosition(GroundGeom, (pOffset.X + ((int)Constants.RegionSize * 0.5f)), (pOffset.Y + ((int)Constants.RegionSize * 0.5f)), 0); 3979 d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0);
3913 IntPtr testGround = IntPtr.Zero; 3980 IntPtr testGround = IntPtr.Zero;
3914 if (RegionTerrain.TryGetValue(pOffset, out testGround)) 3981 if (RegionTerrain.TryGetValue(pOffset, out testGround))
3915 { 3982 {
@@ -3934,89 +4001,31 @@ namespace OpenSim.Region.Physics.OdePlugin
3934 4001
3935 public override bool SupportsCombining() 4002 public override bool SupportsCombining()
3936 { 4003 {
3937 return true; 4004 return m_suportCombine;
3938 } 4005 }
3939 4006
3940// public override void UnCombine(PhysicsScene pScene)
3941// {
3942// IntPtr localGround = IntPtr.Zero;
3943//// float[] localHeightfield;
3944// bool proceed = false;
3945// List<IntPtr> geomDestroyList = new List<IntPtr>();
3946//
3947// lock (OdeLock)
3948// {
3949// if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround))
3950// {
3951// foreach (IntPtr geom in TerrainHeightFieldHeights.Keys)
3952// {
3953// if (geom == localGround)
3954// {
3955//// localHeightfield = TerrainHeightFieldHeights[geom];
3956// proceed = true;
3957// }
3958// else
3959// {
3960// geomDestroyList.Add(geom);
3961// }
3962// }
3963//
3964// if (proceed)
3965// {
3966// m_worldOffset = Vector3.Zero;
3967// WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
3968// m_parentScene = null;
3969//
3970// foreach (IntPtr g in geomDestroyList)
3971// {
3972// // removingHeightField needs to be done or the garbage collector will
3973// // collect the terrain data before we tell ODE to destroy it causing
3974// // memory corruption
3975// if (TerrainHeightFieldHeights.ContainsKey(g))
3976// {
3977//// float[] removingHeightField = TerrainHeightFieldHeights[g];
3978// TerrainHeightFieldHeights.Remove(g);
3979//
3980// if (RegionTerrain.ContainsKey(g))
3981// {
3982// RegionTerrain.Remove(g);
3983// }
3984//
3985// d.GeomDestroy(g);
3986// //removingHeightField = new float[0];
3987// }
3988// }
3989//
3990// }
3991// else
3992// {
3993// m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
3994// }
3995// }
3996// }
3997// }
3998
3999 public override void SetWaterLevel(float baseheight) 4007 public override void SetWaterLevel(float baseheight)
4000 { 4008 {
4001 waterlevel = baseheight; 4009 waterlevel = baseheight;
4002 randomizeWater(waterlevel); 4010// randomizeWater(waterlevel);
4003 } 4011 }
4004 4012
4013/*
4005 private void randomizeWater(float baseheight) 4014 private void randomizeWater(float baseheight)
4006 { 4015 {
4007 const uint heightmapWidth = m_regionWidth + 2; 4016 uint heightmapWidth = m_regionWidth + 2;
4008 const uint heightmapHeight = m_regionHeight + 2; 4017 uint heightmapHeight = m_regionHeight + 2;
4009 const uint heightmapWidthSamples = m_regionWidth + 2; 4018 uint heightmapWidthSamples = m_regionWidth + 2;
4010 const uint heightmapHeightSamples = m_regionHeight + 2; 4019 uint heightmapHeightSamples = m_regionHeight + 2;
4011 const float scale = 1.0f; 4020 float scale = 1.0f;
4012 const float offset = 0.0f; 4021 float offset = 0.0f;
4013 const float thickness = 2.9f; 4022 float thickness = 2.9f;
4014 const int wrap = 0; 4023 int wrap = 0;
4015 4024
4016 for (int i = 0; i < (258 * 258); i++) 4025 for (int i = 0; i < (258 * 258); i++)
4017 { 4026 {
4018 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f); 4027 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
4019 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f)); 4028 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
4020 } 4029 }
4021 4030
4022 lock (OdeLock) 4031 lock (OdeLock)
@@ -4027,8 +4036,8 @@ namespace OpenSim.Region.Physics.OdePlugin
4027 } 4036 }
4028 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 4037 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
4029 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight, 4038 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
4030 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale, 4039 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
4031 offset, thickness, wrap); 4040 offset, thickness, wrap);
4032 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); 4041 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
4033 WaterGeom = d.CreateHeightfield(space, HeightmapData, 1); 4042 WaterGeom = d.CreateHeightfield(space, HeightmapData, 1);
4034 if (WaterGeom != IntPtr.Zero) 4043 if (WaterGeom != IntPtr.Zero)
@@ -4056,7 +4065,7 @@ namespace OpenSim.Region.Physics.OdePlugin
4056 d.GeomSetPosition(WaterGeom, 128, 128, 0); 4065 d.GeomSetPosition(WaterGeom, 128, 128, 0);
4057 } 4066 }
4058 } 4067 }
4059 4068*/
4060 public override void Dispose() 4069 public override void Dispose()
4061 { 4070 {
4062 _worldInitialized = false; 4071 _worldInitialized = false;
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPrim.cs b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs
index 7c1e915..782ba82 100644
--- a/OpenSim/Region/Physics/POSPlugin/POSPrim.cs
+++ b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs
@@ -298,7 +298,7 @@ namespace OpenSim.Region.Physics.POSPlugin
298 { 298 {
299 set { return; } 299 set { return; }
300 } 300 }
301 301
302 public override Quaternion APIDTarget 302 public override Quaternion APIDTarget
303 { 303 {
304 set { return; } 304 set { return; }
diff --git a/OpenSim/Region/Physics/UbitMeshing/HelperTypes.cs b/OpenSim/Region/Physics/UbitMeshing/HelperTypes.cs
new file mode 100644
index 0000000..5dc1e78
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/HelperTypes.cs
@@ -0,0 +1,340 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Diagnostics;
31using System.Globalization;
32using OpenMetaverse;
33using OpenSim.Region.Physics.Manager;
34using OpenSim.Region.Physics.Meshing;
35
36public class Vertex : IComparable<Vertex>
37{
38 Vector3 vector;
39
40 public float X
41 {
42 get { return vector.X; }
43 set { vector.X = value; }
44 }
45
46 public float Y
47 {
48 get { return vector.Y; }
49 set { vector.Y = value; }
50 }
51
52 public float Z
53 {
54 get { return vector.Z; }
55 set { vector.Z = value; }
56 }
57
58 public Vertex(float x, float y, float z)
59 {
60 vector.X = x;
61 vector.Y = y;
62 vector.Z = z;
63 }
64
65 public Vertex normalize()
66 {
67 float tlength = vector.Length();
68 if (tlength != 0f)
69 {
70 float mul = 1.0f / tlength;
71 return new Vertex(vector.X * mul, vector.Y * mul, vector.Z * mul);
72 }
73 else
74 {
75 return new Vertex(0f, 0f, 0f);
76 }
77 }
78
79 public Vertex cross(Vertex v)
80 {
81 return new Vertex(vector.Y * v.Z - vector.Z * v.Y, vector.Z * v.X - vector.X * v.Z, vector.X * v.Y - vector.Y * v.X);
82 }
83
84 // disable warning: mono compiler moans about overloading
85 // operators hiding base operator but should not according to C#
86 // language spec
87#pragma warning disable 0108
88 public static Vertex operator *(Vertex v, Quaternion q)
89 {
90 // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/
91
92 Vertex v2 = new Vertex(0f, 0f, 0f);
93
94 v2.X = q.W * q.W * v.X +
95 2f * q.Y * q.W * v.Z -
96 2f * q.Z * q.W * v.Y +
97 q.X * q.X * v.X +
98 2f * q.Y * q.X * v.Y +
99 2f * q.Z * q.X * v.Z -
100 q.Z * q.Z * v.X -
101 q.Y * q.Y * v.X;
102
103 v2.Y =
104 2f * q.X * q.Y * v.X +
105 q.Y * q.Y * v.Y +
106 2f * q.Z * q.Y * v.Z +
107 2f * q.W * q.Z * v.X -
108 q.Z * q.Z * v.Y +
109 q.W * q.W * v.Y -
110 2f * q.X * q.W * v.Z -
111 q.X * q.X * v.Y;
112
113 v2.Z =
114 2f * q.X * q.Z * v.X +
115 2f * q.Y * q.Z * v.Y +
116 q.Z * q.Z * v.Z -
117 2f * q.W * q.Y * v.X -
118 q.Y * q.Y * v.Z +
119 2f * q.W * q.X * v.Y -
120 q.X * q.X * v.Z +
121 q.W * q.W * v.Z;
122
123 return v2;
124 }
125
126 public static Vertex operator +(Vertex v1, Vertex v2)
127 {
128 return new Vertex(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
129 }
130
131 public static Vertex operator -(Vertex v1, Vertex v2)
132 {
133 return new Vertex(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
134 }
135
136 public static Vertex operator *(Vertex v1, Vertex v2)
137 {
138 return new Vertex(v1.X * v2.X, v1.Y * v2.Y, v1.Z * v2.Z);
139 }
140
141 public static Vertex operator +(Vertex v1, float am)
142 {
143 v1.X += am;
144 v1.Y += am;
145 v1.Z += am;
146 return v1;
147 }
148
149 public static Vertex operator -(Vertex v1, float am)
150 {
151 v1.X -= am;
152 v1.Y -= am;
153 v1.Z -= am;
154 return v1;
155 }
156
157 public static Vertex operator *(Vertex v1, float am)
158 {
159 v1.X *= am;
160 v1.Y *= am;
161 v1.Z *= am;
162 return v1;
163 }
164
165 public static Vertex operator /(Vertex v1, float am)
166 {
167 if (am == 0f)
168 {
169 return new Vertex(0f,0f,0f);
170 }
171 float mul = 1.0f / am;
172 v1.X *= mul;
173 v1.Y *= mul;
174 v1.Z *= mul;
175 return v1;
176 }
177#pragma warning restore 0108
178
179
180 public float dot(Vertex v)
181 {
182 return X * v.X + Y * v.Y + Z * v.Z;
183 }
184
185 public Vertex(Vector3 v)
186 {
187 vector = v;
188 }
189
190 public Vertex Clone()
191 {
192 return new Vertex(X, Y, Z);
193 }
194
195 public static Vertex FromAngle(double angle)
196 {
197 return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f);
198 }
199
200 public float Length()
201 {
202 return vector.Length();
203 }
204
205 public virtual bool Equals(Vertex v, float tolerance)
206 {
207 Vertex diff = this - v;
208 float d = diff.Length();
209 if (d < tolerance)
210 return true;
211
212 return false;
213 }
214
215
216 public int CompareTo(Vertex other)
217 {
218 if (X < other.X)
219 return -1;
220
221 if (X > other.X)
222 return 1;
223
224 if (Y < other.Y)
225 return -1;
226
227 if (Y > other.Y)
228 return 1;
229
230 if (Z < other.Z)
231 return -1;
232
233 if (Z > other.Z)
234 return 1;
235
236 return 0;
237 }
238
239 public static bool operator >(Vertex me, Vertex other)
240 {
241 return me.CompareTo(other) > 0;
242 }
243
244 public static bool operator <(Vertex me, Vertex other)
245 {
246 return me.CompareTo(other) < 0;
247 }
248
249 public String ToRaw()
250 {
251 // Why this stuff with the number formatter?
252 // Well, the raw format uses the english/US notation of numbers
253 // where the "," separates groups of 1000 while the "." marks the border between 1 and 10E-1.
254 // The german notation uses these characters exactly vice versa!
255 // The Float.ToString() routine is a localized one, giving different results depending on the country
256 // settings your machine works with. Unusable for a machine readable file format :-(
257 NumberFormatInfo nfi = new NumberFormatInfo();
258 nfi.NumberDecimalSeparator = ".";
259 nfi.NumberDecimalDigits = 6;
260
261 String s1 = X.ToString(nfi) + " " + Y.ToString(nfi) + " " + Z.ToString(nfi);
262
263 return s1;
264 }
265}
266
267public class Triangle
268{
269 public Vertex v1;
270 public Vertex v2;
271 public Vertex v3;
272
273 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
274 {
275 v1 = _v1;
276 v2 = _v2;
277 v3 = _v3;
278 }
279
280 public Triangle(float _v1x,float _v1y,float _v1z,
281 float _v2x,float _v2y,float _v2z,
282 float _v3x,float _v3y,float _v3z)
283 {
284 v1 = new Vertex(_v1x, _v1y, _v1z);
285 v2 = new Vertex(_v2x, _v2y, _v2z);
286 v3 = new Vertex(_v3x, _v3y, _v3z);
287 }
288
289 public override String ToString()
290 {
291 NumberFormatInfo nfi = new NumberFormatInfo();
292 nfi.CurrencyDecimalDigits = 2;
293 nfi.CurrencyDecimalSeparator = ".";
294
295 String s1 = "<" + v1.X.ToString(nfi) + "," + v1.Y.ToString(nfi) + "," + v1.Z.ToString(nfi) + ">";
296 String s2 = "<" + v2.X.ToString(nfi) + "," + v2.Y.ToString(nfi) + "," + v2.Z.ToString(nfi) + ">";
297 String s3 = "<" + v3.X.ToString(nfi) + "," + v3.Y.ToString(nfi) + "," + v3.Z.ToString(nfi) + ">";
298
299 return s1 + ";" + s2 + ";" + s3;
300 }
301
302 public Vector3 getNormal()
303 {
304 // Vertices
305
306 // Vectors for edges
307 Vector3 e1;
308 Vector3 e2;
309
310 e1 = new Vector3(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
311 e2 = new Vector3(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z);
312
313 // Cross product for normal
314 Vector3 n = Vector3.Cross(e1, e2);
315
316 // Length
317 float l = n.Length();
318
319 // Normalized "normal"
320 n = n/l;
321
322 return n;
323 }
324
325 public void invertNormal()
326 {
327 Vertex vt;
328 vt = v1;
329 v1 = v2;
330 v2 = vt;
331 }
332
333 // Dumps a triangle in the "raw faces" format, blender can import. This is for visualisation and
334 // debugging purposes
335 public String ToStringRaw()
336 {
337 String output = v1.ToRaw() + " " + v2.ToRaw() + " " + v3.ToRaw();
338 return output;
339 }
340}
diff --git a/OpenSim/Region/Physics/UbitMeshing/Mesh.cs b/OpenSim/Region/Physics/UbitMeshing/Mesh.cs
new file mode 100644
index 0000000..0418893
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/Mesh.cs
@@ -0,0 +1,601 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Runtime.InteropServices;
32using OpenSim.Region.Physics.Manager;
33using PrimMesher;
34using OpenMetaverse;
35using System.Runtime.Serialization;
36using System.Runtime.Serialization.Formatters.Binary;
37
38namespace OpenSim.Region.Physics.Meshing
39{
40 public class MeshBuildingData
41 {
42 public Dictionary<Vertex, int> m_vertices;
43 public List<Triangle> m_triangles;
44 public float m_obbXmin;
45 public float m_obbXmax;
46 public float m_obbYmin;
47 public float m_obbYmax;
48 public float m_obbZmin;
49 public float m_obbZmax;
50 public Vector3 m_centroid;
51 public int m_centroidDiv;
52 }
53
54 [Serializable()]
55 public class Mesh : IMesh
56 {
57 float[] vertices;
58 int[] indexes;
59 Vector3 m_obb;
60 Vector3 m_obboffset;
61 [NonSerialized()]
62 MeshBuildingData m_bdata;
63 [NonSerialized()]
64 GCHandle vhandler;
65 [NonSerialized()]
66 GCHandle ihandler;
67 [NonSerialized()]
68 IntPtr m_verticesPtr = IntPtr.Zero;
69 [NonSerialized()]
70 IntPtr m_indicesPtr = IntPtr.Zero;
71 [NonSerialized()]
72 int m_vertexCount = 0;
73 [NonSerialized()]
74 int m_indexCount = 0;
75
76 public int RefCount { get; set; }
77 public AMeshKey Key { get; set; }
78
79 private class vertexcomp : IEqualityComparer<Vertex>
80 {
81 public bool Equals(Vertex v1, Vertex v2)
82 {
83 if (v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z)
84 return true;
85 else
86 return false;
87 }
88 public int GetHashCode(Vertex v)
89 {
90 int a = v.X.GetHashCode();
91 int b = v.Y.GetHashCode();
92 int c = v.Z.GetHashCode();
93 return (a << 16) ^ (b << 8) ^ c;
94 }
95 }
96
97 public Mesh()
98 {
99 vertexcomp vcomp = new vertexcomp();
100
101 m_bdata = new MeshBuildingData();
102 m_bdata.m_vertices = new Dictionary<Vertex, int>(vcomp);
103 m_bdata.m_triangles = new List<Triangle>();
104 m_bdata.m_centroid = Vector3.Zero;
105 m_bdata.m_centroidDiv = 0;
106 m_bdata.m_obbXmin = float.MaxValue;
107 m_bdata.m_obbXmax = float.MinValue;
108 m_bdata.m_obbYmin = float.MaxValue;
109 m_bdata.m_obbYmax = float.MinValue;
110 m_bdata.m_obbZmin = float.MaxValue;
111 m_bdata.m_obbZmax = float.MinValue;
112 m_obb = new Vector3(0.5f, 0.5f, 0.5f);
113 m_obboffset = Vector3.Zero;
114 }
115
116
117 public Mesh Scale(Vector3 scale)
118 {
119 if (m_verticesPtr == null || m_indicesPtr == null)
120 return null;
121
122 Mesh result = new Mesh();
123
124 float x = scale.X;
125 float y = scale.Y;
126 float z = scale.Z;
127
128 result.m_obb.X = m_obb.X * x;
129 result.m_obb.Y = m_obb.Y * y;
130 result.m_obb.Z = m_obb.Z * z;
131 result.m_obboffset.X = m_obboffset.X * x;
132 result.m_obboffset.Y = m_obboffset.Y * y;
133 result.m_obboffset.Z = m_obboffset.Z * z;
134
135 result.vertices = new float[vertices.Length];
136 int j = 0;
137 for (int i = 0; i < m_vertexCount; i++)
138 {
139 result.vertices[j] = vertices[j] * x;
140 j++;
141 result.vertices[j] = vertices[j] * y;
142 j++;
143 result.vertices[j] = vertices[j] * z;
144 j++;
145 }
146
147 result.indexes = new int[indexes.Length];
148 indexes.CopyTo(result.indexes,0);
149
150 result.pinMemory();
151
152 return result;
153 }
154
155 public Mesh Clone()
156 {
157 Mesh result = new Mesh();
158
159 if (m_bdata != null)
160 {
161 result.m_bdata = new MeshBuildingData();
162 foreach (Triangle t in m_bdata.m_triangles)
163 {
164 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone()));
165 }
166 result.m_bdata.m_centroid = m_bdata.m_centroid;
167 result.m_bdata.m_centroidDiv = m_bdata.m_centroidDiv;
168 result.m_bdata.m_obbXmin = m_bdata.m_obbXmin;
169 result.m_bdata.m_obbXmax = m_bdata.m_obbXmax;
170 result.m_bdata.m_obbYmin = m_bdata.m_obbYmin;
171 result.m_bdata.m_obbYmax = m_bdata.m_obbYmax;
172 result.m_bdata.m_obbZmin = m_bdata.m_obbZmin;
173 result.m_bdata.m_obbZmax = m_bdata.m_obbZmax;
174 }
175 result.m_obb = m_obb;
176 result.m_obboffset = m_obboffset;
177 return result;
178 }
179
180 public void addVertexLStats(Vertex v)
181 {
182 float x = v.X;
183 float y = v.Y;
184 float z = v.Z;
185
186 m_bdata.m_centroid.X += x;
187 m_bdata.m_centroid.Y += y;
188 m_bdata.m_centroid.Z += z;
189 m_bdata.m_centroidDiv++;
190
191 if (x > m_bdata.m_obbXmax)
192 m_bdata.m_obbXmax = x;
193 else if (x < m_bdata.m_obbXmin)
194 m_bdata.m_obbXmin = x;
195
196 if (y > m_bdata.m_obbYmax)
197 m_bdata.m_obbYmax = y;
198 else if (y < m_bdata.m_obbYmin)
199 m_bdata.m_obbYmin = y;
200
201 if (z > m_bdata.m_obbZmax)
202 m_bdata.m_obbZmax = z;
203 else if (z < m_bdata.m_obbZmin)
204 m_bdata.m_obbZmin = z;
205
206 }
207
208 public void Add(Triangle triangle)
209 {
210 if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
211 throw new NotSupportedException("Attempt to Add to a pinned Mesh");
212
213
214 triangle.v1.X = (float)Math.Round(triangle.v1.X, 6);
215 triangle.v1.Y = (float)Math.Round(triangle.v1.Y, 6);
216 triangle.v1.Z = (float)Math.Round(triangle.v1.Z, 6);
217 triangle.v2.X = (float)Math.Round(triangle.v2.X, 6);
218 triangle.v2.Y = (float)Math.Round(triangle.v2.Y, 6);
219 triangle.v2.Z = (float)Math.Round(triangle.v2.Z, 6);
220 triangle.v3.X = (float)Math.Round(triangle.v3.X, 6);
221 triangle.v3.Y = (float)Math.Round(triangle.v3.Y, 6);
222 triangle.v3.Z = (float)Math.Round(triangle.v3.Z, 6);
223
224 if ((triangle.v1.X == triangle.v2.X && triangle.v1.Y == triangle.v2.Y && triangle.v1.Z == triangle.v2.Z)
225 || (triangle.v1.X == triangle.v3.X && triangle.v1.Y == triangle.v3.Y && triangle.v1.Z == triangle.v3.Z)
226 || (triangle.v2.X == triangle.v3.X && triangle.v2.Y == triangle.v3.Y && triangle.v2.Z == triangle.v3.Z)
227 )
228 {
229 return;
230 }
231
232 if (m_bdata.m_vertices.Count == 0)
233 {
234 m_bdata.m_centroidDiv = 0;
235 m_bdata.m_centroid = Vector3.Zero;
236 }
237
238 if (!m_bdata.m_vertices.ContainsKey(triangle.v1))
239 {
240 m_bdata.m_vertices[triangle.v1] = m_bdata.m_vertices.Count;
241 addVertexLStats(triangle.v1);
242 }
243 if (!m_bdata.m_vertices.ContainsKey(triangle.v2))
244 {
245 m_bdata.m_vertices[triangle.v2] = m_bdata.m_vertices.Count;
246 addVertexLStats(triangle.v2);
247 }
248 if (!m_bdata.m_vertices.ContainsKey(triangle.v3))
249 {
250 m_bdata.m_vertices[triangle.v3] = m_bdata.m_vertices.Count;
251 addVertexLStats(triangle.v3);
252 }
253 m_bdata.m_triangles.Add(triangle);
254 }
255
256 public Vector3 GetCentroid()
257 {
258 return m_obboffset;
259
260 }
261
262 public Vector3 GetOBB()
263 {
264 return m_obb;
265 float x, y, z;
266 if (m_bdata.m_centroidDiv > 0)
267 {
268 x = (m_bdata.m_obbXmax - m_bdata.m_obbXmin) * 0.5f;
269 y = (m_bdata.m_obbYmax - m_bdata.m_obbYmin) * 0.5f;
270 z = (m_bdata.m_obbZmax - m_bdata.m_obbZmin) * 0.5f;
271 }
272 else // ??
273 {
274 x = 0.5f;
275 y = 0.5f;
276 z = 0.5f;
277 }
278 return new Vector3(x, y, z);
279 }
280
281 public List<Vector3> getVertexList()
282 {
283 List<Vector3> result = new List<Vector3>();
284 foreach (Vertex v in m_bdata.m_vertices.Keys)
285 {
286 result.Add(new Vector3(v.X, v.Y, v.Z));
287 }
288 return result;
289 }
290
291 public float[] getVertexListAsFloat()
292 {
293 if (m_bdata.m_vertices == null)
294 throw new NotSupportedException();
295 float[] result = new float[m_bdata.m_vertices.Count * 3];
296 foreach (KeyValuePair<Vertex, int> kvp in m_bdata.m_vertices)
297 {
298 Vertex v = kvp.Key;
299 int i = kvp.Value;
300 result[3 * i + 0] = v.X;
301 result[3 * i + 1] = v.Y;
302 result[3 * i + 2] = v.Z;
303 }
304 return result;
305 }
306
307 public float[] getVertexListAsFloatLocked()
308 {
309 return null;
310 }
311
312 public void getVertexListAsPtrToFloatArray(out IntPtr _vertices, out int vertexStride, out int vertexCount)
313 {
314 // A vertex is 3 floats
315 vertexStride = 3 * sizeof(float);
316
317 // If there isn't an unmanaged array allocated yet, do it now
318 if (m_verticesPtr == IntPtr.Zero && m_bdata != null)
319 {
320 vertices = getVertexListAsFloat();
321 // Each vertex is 3 elements (floats)
322 m_vertexCount = vertices.Length / 3;
323 vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
324 m_verticesPtr = vhandler.AddrOfPinnedObject();
325 GC.AddMemoryPressure(Buffer.ByteLength(vertices));
326 }
327 _vertices = m_verticesPtr;
328 vertexCount = m_vertexCount;
329 }
330
331 public int[] getIndexListAsInt()
332 {
333 if (m_bdata.m_triangles == null)
334 throw new NotSupportedException();
335 int[] result = new int[m_bdata.m_triangles.Count * 3];
336 for (int i = 0; i < m_bdata.m_triangles.Count; i++)
337 {
338 Triangle t = m_bdata.m_triangles[i];
339 result[3 * i + 0] = m_bdata.m_vertices[t.v1];
340 result[3 * i + 1] = m_bdata.m_vertices[t.v2];
341 result[3 * i + 2] = m_bdata.m_vertices[t.v3];
342 }
343 return result;
344 }
345
346 /// <summary>
347 /// creates a list of index values that defines triangle faces. THIS METHOD FREES ALL NON-PINNED MESH DATA
348 /// </summary>
349 /// <returns></returns>
350 public int[] getIndexListAsIntLocked()
351 {
352 return null;
353 }
354
355 public void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount)
356 {
357 // If there isn't an unmanaged array allocated yet, do it now
358 if (m_indicesPtr == IntPtr.Zero && m_bdata != null)
359 {
360 indexes = getIndexListAsInt();
361 m_indexCount = indexes.Length;
362 ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
363 m_indicesPtr = ihandler.AddrOfPinnedObject();
364 GC.AddMemoryPressure(Buffer.ByteLength(indexes));
365 }
366 // A triangle is 3 ints (indices)
367 triStride = 3 * sizeof(int);
368 indices = m_indicesPtr;
369 indexCount = m_indexCount;
370 }
371
372 public void releasePinned()
373 {
374 if (m_verticesPtr != IntPtr.Zero)
375 {
376 vhandler.Free();
377 vertices = null;
378 m_verticesPtr = IntPtr.Zero;
379 }
380 if (m_indicesPtr != IntPtr.Zero)
381 {
382 ihandler.Free();
383 indexes = null;
384 m_indicesPtr = IntPtr.Zero;
385 }
386 }
387
388 /// <summary>
389 /// frees up the source mesh data to minimize memory - call this method after calling get*Locked() functions
390 /// </summary>
391 public void releaseSourceMeshData()
392 {
393 if (m_bdata != null)
394 {
395 m_bdata.m_triangles = null;
396 m_bdata.m_vertices = null;
397 }
398 }
399
400 public void releaseBuildingMeshData()
401 {
402 if (m_bdata != null)
403 {
404 m_bdata.m_triangles = null;
405 m_bdata.m_vertices = null;
406 m_bdata = null;
407 }
408 }
409
410 public void Append(IMesh newMesh)
411 {
412 if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
413 throw new NotSupportedException("Attempt to Append to a pinned Mesh");
414
415 if (!(newMesh is Mesh))
416 return;
417
418 foreach (Triangle t in ((Mesh)newMesh).m_bdata.m_triangles)
419 Add(t);
420 }
421
422 // Do a linear transformation of mesh.
423 public void TransformLinear(float[,] matrix, float[] offset)
424 {
425 if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
426 throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh");
427
428 foreach (Vertex v in m_bdata.m_vertices.Keys)
429 {
430 if (v == null)
431 continue;
432 float x, y, z;
433 x = v.X*matrix[0, 0] + v.Y*matrix[1, 0] + v.Z*matrix[2, 0];
434 y = v.X*matrix[0, 1] + v.Y*matrix[1, 1] + v.Z*matrix[2, 1];
435 z = v.X*matrix[0, 2] + v.Y*matrix[1, 2] + v.Z*matrix[2, 2];
436 v.X = x + offset[0];
437 v.Y = y + offset[1];
438 v.Z = z + offset[2];
439 }
440 }
441
442 public void DumpRaw(String path, String name, String title)
443 {
444 if (path == null)
445 return;
446 if (m_bdata == null)
447 return;
448 String fileName = name + "_" + title + ".raw";
449 String completePath = System.IO.Path.Combine(path, fileName);
450 StreamWriter sw = new StreamWriter(completePath);
451 foreach (Triangle t in m_bdata.m_triangles)
452 {
453 String s = t.ToStringRaw();
454 sw.WriteLine(s);
455 }
456 sw.Close();
457 }
458
459 public void TrimExcess()
460 {
461 m_bdata.m_triangles.TrimExcess();
462 }
463
464 public void pinMemory()
465 {
466 m_vertexCount = vertices.Length / 3;
467 vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
468 m_verticesPtr = vhandler.AddrOfPinnedObject();
469 GC.AddMemoryPressure(Buffer.ByteLength(vertices));
470
471 m_indexCount = indexes.Length;
472 ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
473 m_indicesPtr = ihandler.AddrOfPinnedObject();
474 GC.AddMemoryPressure(Buffer.ByteLength(indexes));
475 }
476
477 public void PrepForOde()
478 {
479 // If there isn't an unmanaged array allocated yet, do it now
480 if (m_verticesPtr == IntPtr.Zero)
481 vertices = getVertexListAsFloat();
482
483 // If there isn't an unmanaged array allocated yet, do it now
484 if (m_indicesPtr == IntPtr.Zero)
485 indexes = getIndexListAsInt();
486
487 pinMemory();
488
489 float x, y, z;
490
491 if (m_bdata.m_centroidDiv > 0)
492 {
493 m_obboffset = new Vector3(m_bdata.m_centroid.X / m_bdata.m_centroidDiv, m_bdata.m_centroid.Y / m_bdata.m_centroidDiv, m_bdata.m_centroid.Z / m_bdata.m_centroidDiv);
494 x = (m_bdata.m_obbXmax - m_bdata.m_obbXmin) * 0.5f;
495 y = (m_bdata.m_obbYmax - m_bdata.m_obbYmin) * 0.5f;
496 z = (m_bdata.m_obbZmax - m_bdata.m_obbZmin) * 0.5f;
497 }
498
499 else
500 {
501 m_obboffset = Vector3.Zero;
502 x = 0.5f;
503 y = 0.5f;
504 z = 0.5f;
505 }
506 m_obb = new Vector3(x, y, z);
507
508 releaseBuildingMeshData();
509 }
510 public bool ToStream(Stream st)
511 {
512 if (m_indicesPtr == IntPtr.Zero || m_verticesPtr == IntPtr.Zero)
513 return false;
514
515 BinaryWriter bw = new BinaryWriter(st);
516 bool ok = true;
517
518 try
519 {
520
521 bw.Write(m_vertexCount);
522 bw.Write(m_indexCount);
523
524 for (int i = 0; i < 3 * m_vertexCount; i++)
525 bw.Write(vertices[i]);
526 for (int i = 0; i < m_indexCount; i++)
527 bw.Write(indexes[i]);
528 bw.Write(m_obb.X);
529 bw.Write(m_obb.Y);
530 bw.Write(m_obb.Z);
531 bw.Write(m_obboffset.X);
532 bw.Write(m_obboffset.Y);
533 bw.Write(m_obboffset.Z);
534 }
535 catch
536 {
537 ok = false;
538 }
539
540 if (bw != null)
541 {
542 bw.Flush();
543 bw.Close();
544 }
545
546 return ok;
547 }
548
549 public static Mesh FromStream(Stream st, AMeshKey key)
550 {
551 Mesh mesh = new Mesh();
552 mesh.releaseBuildingMeshData();
553
554 BinaryReader br = new BinaryReader(st);
555
556 bool ok = true;
557 try
558 {
559 mesh.m_vertexCount = br.ReadInt32();
560 mesh.m_indexCount = br.ReadInt32();
561
562 int n = 3 * mesh.m_vertexCount;
563 mesh.vertices = new float[n];
564 for (int i = 0; i < n; i++)
565 mesh.vertices[i] = br.ReadSingle();
566
567 mesh.indexes = new int[mesh.m_indexCount];
568 for (int i = 0; i < mesh.m_indexCount; i++)
569 mesh.indexes[i] = br.ReadInt32();
570
571 mesh.m_obb.X = br.ReadSingle();
572 mesh.m_obb.Y = br.ReadSingle();
573 mesh.m_obb.Z = br.ReadSingle();
574
575 mesh.m_obboffset.X = br.ReadSingle();
576 mesh.m_obboffset.Y = br.ReadSingle();
577 mesh.m_obboffset.Z = br.ReadSingle();
578 }
579 catch
580 {
581 ok = false;
582 }
583
584 br.Close();
585
586 if (ok)
587 {
588 mesh.pinMemory();
589
590 mesh.Key = key;
591 mesh.RefCount = 1;
592
593 return mesh;
594 }
595
596 mesh.vertices = null;
597 mesh.indexes = null;
598 return null;
599 }
600 }
601}
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
new file mode 100644
index 0000000..c131c6f
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
@@ -0,0 +1,1424 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27//#define SPAM
28
29using System;
30using System.Collections.Generic;
31using OpenSim.Framework;
32using OpenSim.Region.Physics.Manager;
33using OpenMetaverse;
34using OpenMetaverse.StructuredData;
35using System.Drawing;
36using System.Drawing.Imaging;
37using System.IO.Compression;
38using PrimMesher;
39using log4net;
40using Nini.Config;
41using System.Reflection;
42using System.IO;
43using ComponentAce.Compression.Libs.zlib;
44using OpenSim.Region.Physics.ConvexDecompositionDotNet;
45using System.Runtime.Serialization;
46using System.Runtime.Serialization.Formatters.Binary;
47
48namespace OpenSim.Region.Physics.Meshing
49{
50 public class MeshmerizerPlugin : IMeshingPlugin
51 {
52 public MeshmerizerPlugin()
53 {
54 }
55
56 public string GetName()
57 {
58 return "UbitMeshmerizer";
59 }
60
61 public IMesher GetMesher(IConfigSource config)
62 {
63 return new Meshmerizer(config);
64 }
65 }
66
67 public class Meshmerizer : IMesher
68 {
69 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
70
71 // Setting baseDir to a path will enable the dumping of raw files
72 // raw files can be imported by blender so a visual inspection of the results can be done
73
74 public object diskLock = new object();
75
76 public bool doMeshFileCache = true;
77
78 public string cachePath = "MeshCache";
79 public TimeSpan CacheExpire;
80 public bool doCacheExpire = true;
81
82// const string baseDir = "rawFiles";
83 private const string baseDir = null; //"rawFiles";
84
85 private bool useMeshiesPhysicsMesh = false;
86
87 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh
88
89 private Dictionary<AMeshKey, Mesh> m_uniqueMeshes = new Dictionary<AMeshKey, Mesh>();
90 private Dictionary<AMeshKey, Mesh> m_uniqueReleasedMeshes = new Dictionary<AMeshKey, Mesh>();
91
92 public Meshmerizer(IConfigSource config)
93 {
94 IConfig start_config = config.Configs["Startup"];
95 IConfig mesh_config = config.Configs["Mesh"];
96
97
98 float fcache = 48.0f;
99// float fcache = 0.02f;
100
101 if(mesh_config != null)
102 {
103 useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh);
104 if (useMeshiesPhysicsMesh)
105 {
106 doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache);
107 cachePath = mesh_config.GetString("MeshFileCachePath", cachePath);
108 fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache);
109 doCacheExpire = mesh_config.GetBoolean("MeshFileCacheDoExpire", doCacheExpire);
110 }
111 else
112 {
113 doMeshFileCache = false;
114 doCacheExpire = false;
115 }
116 }
117
118 CacheExpire = TimeSpan.FromHours(fcache);
119
120 }
121
122 /// <summary>
123 /// creates a simple box mesh of the specified size. This mesh is of very low vertex count and may
124 /// be useful as a backup proxy when level of detail is not needed or when more complex meshes fail
125 /// for some reason
126 /// </summary>
127 /// <param name="minX"></param>
128 /// <param name="maxX"></param>
129 /// <param name="minY"></param>
130 /// <param name="maxY"></param>
131 /// <param name="minZ"></param>
132 /// <param name="maxZ"></param>
133 /// <returns></returns>
134 private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
135 {
136 Mesh box = new Mesh();
137 List<Vertex> vertices = new List<Vertex>();
138 // bottom
139
140 vertices.Add(new Vertex(minX, maxY, minZ));
141 vertices.Add(new Vertex(maxX, maxY, minZ));
142 vertices.Add(new Vertex(maxX, minY, minZ));
143 vertices.Add(new Vertex(minX, minY, minZ));
144
145 box.Add(new Triangle(vertices[0], vertices[1], vertices[2]));
146 box.Add(new Triangle(vertices[0], vertices[2], vertices[3]));
147
148 // top
149
150 vertices.Add(new Vertex(maxX, maxY, maxZ));
151 vertices.Add(new Vertex(minX, maxY, maxZ));
152 vertices.Add(new Vertex(minX, minY, maxZ));
153 vertices.Add(new Vertex(maxX, minY, maxZ));
154
155 box.Add(new Triangle(vertices[4], vertices[5], vertices[6]));
156 box.Add(new Triangle(vertices[4], vertices[6], vertices[7]));
157
158 // sides
159
160 box.Add(new Triangle(vertices[5], vertices[0], vertices[3]));
161 box.Add(new Triangle(vertices[5], vertices[3], vertices[6]));
162
163 box.Add(new Triangle(vertices[1], vertices[0], vertices[5]));
164 box.Add(new Triangle(vertices[1], vertices[5], vertices[4]));
165
166 box.Add(new Triangle(vertices[7], vertices[1], vertices[4]));
167 box.Add(new Triangle(vertices[7], vertices[2], vertices[1]));
168
169 box.Add(new Triangle(vertices[3], vertices[2], vertices[7]));
170 box.Add(new Triangle(vertices[3], vertices[7], vertices[6]));
171
172 return box;
173 }
174
175 /// <summary>
176 /// Creates a simple bounding box mesh for a complex input mesh
177 /// </summary>
178 /// <param name="meshIn"></param>
179 /// <returns></returns>
180 private static Mesh CreateBoundingBoxMesh(Mesh meshIn)
181 {
182 float minX = float.MaxValue;
183 float maxX = float.MinValue;
184 float minY = float.MaxValue;
185 float maxY = float.MinValue;
186 float minZ = float.MaxValue;
187 float maxZ = float.MinValue;
188
189 foreach (Vector3 v in meshIn.getVertexList())
190 {
191 if (v.X < minX) minX = v.X;
192 if (v.Y < minY) minY = v.Y;
193 if (v.Z < minZ) minZ = v.Z;
194
195 if (v.X > maxX) maxX = v.X;
196 if (v.Y > maxY) maxY = v.Y;
197 if (v.Z > maxZ) maxZ = v.Z;
198 }
199
200 return CreateSimpleBoxMesh(minX, maxX, minY, maxY, minZ, maxZ);
201 }
202
203 private void ReportPrimError(string message, string primName, PrimMesh primMesh)
204 {
205 m_log.Error(message);
206 m_log.Error("\nPrim Name: " + primName);
207 m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString());
208 }
209
210 /// <summary>
211 /// Add a submesh to an existing list of coords and faces.
212 /// </summary>
213 /// <param name="subMeshData"></param>
214 /// <param name="size">Size of entire object</param>
215 /// <param name="coords"></param>
216 /// <param name="faces"></param>
217 private void AddSubMesh(OSDMap subMeshData, List<Coord> coords, List<Face> faces)
218 {
219 // Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap));
220
221 // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level
222 // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no
223 // geometry for this submesh.
224 if (subMeshData.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshData["NoGeometry"]))
225 return;
226
227 OpenMetaverse.Vector3 posMax;
228 OpenMetaverse.Vector3 posMin;
229 if (subMeshData.ContainsKey("PositionDomain"))
230 {
231 posMax = ((OSDMap)subMeshData["PositionDomain"])["Max"].AsVector3();
232 posMin = ((OSDMap)subMeshData["PositionDomain"])["Min"].AsVector3();
233 }
234 else
235 {
236 posMax = new Vector3(0.5f, 0.5f, 0.5f);
237 posMin = new Vector3(-0.5f, -0.5f, -0.5f);
238 }
239
240 ushort faceIndexOffset = (ushort)coords.Count;
241
242 byte[] posBytes = subMeshData["Position"].AsBinary();
243 for (int i = 0; i < posBytes.Length; i += 6)
244 {
245 ushort uX = Utils.BytesToUInt16(posBytes, i);
246 ushort uY = Utils.BytesToUInt16(posBytes, i + 2);
247 ushort uZ = Utils.BytesToUInt16(posBytes, i + 4);
248
249 Coord c = new Coord(
250 Utils.UInt16ToFloat(uX, posMin.X, posMax.X),
251 Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y),
252 Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z));
253
254 coords.Add(c);
255 }
256
257 byte[] triangleBytes = subMeshData["TriangleList"].AsBinary();
258 for (int i = 0; i < triangleBytes.Length; i += 6)
259 {
260 ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset);
261 ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset);
262 ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset);
263 Face f = new Face(v1, v2, v3);
264 faces.Add(f);
265 }
266 }
267
268 /// <summary>
269 /// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type.
270 /// </summary>
271 /// <param name="primName"></param>
272 /// <param name="primShape"></param>
273 /// <param name="size"></param>
274 /// <param name="lod"></param>
275 /// <returns></returns>
276 private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, float lod, bool convex)
277 {
278// m_log.DebugFormat(
279// "[MESH]: Creating physics proxy for {0}, shape {1}",
280// primName, (OpenMetaverse.SculptType)primShape.SculptType);
281
282 List<Coord> coords;
283 List<Face> faces;
284
285 if (primShape.SculptEntry)
286 {
287 if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh)
288 {
289 if (!useMeshiesPhysicsMesh)
290 return null;
291
292 if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, out coords, out faces, convex))
293 return null;
294 }
295 else
296 {
297 if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, lod, out coords, out faces))
298 return null;
299 }
300 }
301 else
302 {
303 if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, lod, out coords, out faces))
304 return null;
305 }
306
307 primShape.SculptData = Utils.EmptyBytes;
308
309 int numCoords = coords.Count;
310 int numFaces = faces.Count;
311
312 Mesh mesh = new Mesh();
313 // Add the corresponding triangles to the mesh
314 for (int i = 0; i < numFaces; i++)
315 {
316 Face f = faces[i];
317 mesh.Add(new Triangle(coords[f.v1].X, coords[f.v1].Y, coords[f.v1].Z,
318 coords[f.v2].X, coords[f.v2].Y, coords[f.v2].Z,
319 coords[f.v3].X, coords[f.v3].Y, coords[f.v3].Z));
320 }
321
322 coords.Clear();
323 faces.Clear();
324
325 return mesh;
326 }
327
328 /// <summary>
329 /// Generate the co-ords and faces necessary to construct a mesh from the mesh data the accompanies a prim.
330 /// </summary>
331 /// <param name="primName"></param>
332 /// <param name="primShape"></param>
333 /// <param name="size"></param>
334 /// <param name="coords">Coords are added to this list by the method.</param>
335 /// <param name="faces">Faces are added to this list by the method.</param>
336 /// <returns>true if coords and faces were successfully generated, false if not</returns>
337 private bool GenerateCoordsAndFacesFromPrimMeshData(
338 string primName, PrimitiveBaseShape primShape, out List<Coord> coords, out List<Face> faces, bool convex)
339 {
340// m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
341
342 bool usemesh = false;
343
344 coords = new List<Coord>();
345 faces = new List<Face>();
346 OSD meshOsd = null;
347
348 if (primShape.SculptData.Length <= 0)
349 {
350// m_log.InfoFormat("[MESH]: asset data for {0} is zero length", primName);
351 return false;
352 }
353
354 long start = 0;
355 using (MemoryStream data = new MemoryStream(primShape.SculptData))
356 {
357 try
358 {
359 OSD osd = OSDParser.DeserializeLLSDBinary(data);
360 if (osd is OSDMap)
361 meshOsd = (OSDMap)osd;
362 else
363 {
364 m_log.Warn("[Mesh}: unable to cast mesh asset to OSDMap");
365 return false;
366 }
367 }
368 catch (Exception e)
369 {
370 m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString());
371 }
372
373 start = data.Position;
374 }
375
376 if (meshOsd is OSDMap)
377 {
378 OSDMap physicsParms = null;
379 OSDMap map = (OSDMap)meshOsd;
380
381 if (!convex)
382 {
383 if (map.ContainsKey("physics_shape"))
384 physicsParms = (OSDMap)map["physics_shape"]; // old asset format
385 else if (map.ContainsKey("physics_mesh"))
386 physicsParms = (OSDMap)map["physics_mesh"]; // new asset format
387
388 if (physicsParms != null)
389 usemesh = true;
390 }
391
392 if(!usemesh && (map.ContainsKey("physics_convex")))
393 physicsParms = (OSDMap)map["physics_convex"];
394
395
396 if (physicsParms == null)
397 {
398 m_log.Warn("[MESH]: unknown mesh type");
399 return false;
400 }
401
402 int physOffset = physicsParms["offset"].AsInteger() + (int)start;
403 int physSize = physicsParms["size"].AsInteger();
404
405 if (physOffset < 0 || physSize == 0)
406 return false; // no mesh data in asset
407
408 OSD decodedMeshOsd = new OSD();
409 byte[] meshBytes = new byte[physSize];
410 System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize);
411
412 try
413 {
414 using (MemoryStream inMs = new MemoryStream(meshBytes))
415 {
416 using (MemoryStream outMs = new MemoryStream())
417 {
418 using (ZOutputStream zOut = new ZOutputStream(outMs))
419 {
420 byte[] readBuffer = new byte[2048];
421 int readLen = 0;
422 while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
423 {
424 zOut.Write(readBuffer, 0, readLen);
425 }
426 zOut.Flush();
427 outMs.Seek(0, SeekOrigin.Begin);
428
429 byte[] decompressedBuf = outMs.GetBuffer();
430
431 decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
432 }
433 }
434 }
435 }
436 catch (Exception e)
437 {
438 m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString());
439 return false;
440 }
441
442 if (usemesh)
443 {
444 OSDArray decodedMeshOsdArray = null;
445
446 // physics_shape is an array of OSDMaps, one for each submesh
447 if (decodedMeshOsd is OSDArray)
448 {
449// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd));
450
451 decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
452 foreach (OSD subMeshOsd in decodedMeshOsdArray)
453 {
454 if (subMeshOsd is OSDMap)
455 AddSubMesh(subMeshOsd as OSDMap, coords, faces);
456 }
457 }
458 }
459 else
460 {
461 OSDMap cmap = (OSDMap)decodedMeshOsd;
462 if (cmap == null)
463 return false;
464
465 byte[] data;
466
467 List<float3> vs = new List<float3>();
468 PHullResult hullr = new PHullResult();
469 float3 f3;
470 Coord c;
471 Face f;
472 Vector3 range;
473 Vector3 min;
474
475 const float invMaxU16 = 1.0f / 65535f;
476 int t1;
477 int t2;
478 int t3;
479 int i;
480 int nverts;
481 int nindexs;
482
483 if (cmap.ContainsKey("Max"))
484 range = cmap["Max"].AsVector3();
485 else
486 range = new Vector3(0.5f, 0.5f, 0.5f);
487
488 if (cmap.ContainsKey("Min"))
489 min = cmap["Min"].AsVector3();
490 else
491 min = new Vector3(-0.5f, -0.5f, -0.5f);
492
493 range = range - min;
494 range *= invMaxU16;
495
496 if (!convex && cmap.ContainsKey("HullList") && cmap.ContainsKey("Positions"))
497 {
498 List<int> hsizes = new List<int>();
499 int totalpoints = 0;
500 data = cmap["HullList"].AsBinary();
501 for (i = 0; i < data.Length; i++)
502 {
503 t1 = data[i];
504 if (t1 == 0)
505 t1 = 256;
506 totalpoints += t1;
507 hsizes.Add(t1);
508 }
509
510 data = cmap["Positions"].AsBinary();
511 int ptr = 0;
512 int vertsoffset = 0;
513
514 if (totalpoints == data.Length / 6) // 2 bytes per coord, 3 coords per point
515 {
516 foreach (int hullsize in hsizes)
517 {
518 for (i = 0; i < hullsize; i++ )
519 {
520 t1 = data[ptr++];
521 t1 += data[ptr++] << 8;
522 t2 = data[ptr++];
523 t2 += data[ptr++] << 8;
524 t3 = data[ptr++];
525 t3 += data[ptr++] << 8;
526
527 f3 = new float3((t1 * range.X + min.X),
528 (t2 * range.Y + min.Y),
529 (t3 * range.Z + min.Z));
530 vs.Add(f3);
531 }
532
533 if(hullsize <3)
534 {
535 vs.Clear();
536 continue;
537 }
538
539 if (hullsize <5)
540 {
541 foreach (float3 point in vs)
542 {
543 c.X = point.x;
544 c.Y = point.y;
545 c.Z = point.z;
546 coords.Add(c);
547 }
548 f = new Face(vertsoffset, vertsoffset + 1, vertsoffset + 2);
549 faces.Add(f);
550
551 if (hullsize == 4)
552 {
553 // not sure about orientation..
554 f = new Face(vertsoffset, vertsoffset + 2, vertsoffset + 3);
555 faces.Add(f);
556 f = new Face(vertsoffset, vertsoffset + 3, vertsoffset + 1);
557 faces.Add(f);
558 f = new Face(vertsoffset + 3, vertsoffset + 2, vertsoffset + 1);
559 faces.Add(f);
560 }
561 vertsoffset += vs.Count;
562 vs.Clear();
563 continue;
564 }
565
566 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
567 {
568 vs.Clear();
569 continue;
570 }
571
572 nverts = hullr.Vertices.Count;
573 nindexs = hullr.Indices.Count;
574
575 if (nindexs % 3 != 0)
576 {
577 vs.Clear();
578 continue;
579 }
580
581 for (i = 0; i < nverts; i++)
582 {
583 c.X = hullr.Vertices[i].x;
584 c.Y = hullr.Vertices[i].y;
585 c.Z = hullr.Vertices[i].z;
586 coords.Add(c);
587 }
588
589 for (i = 0; i < nindexs; i += 3)
590 {
591 t1 = hullr.Indices[i];
592 if (t1 > nverts)
593 break;
594 t2 = hullr.Indices[i + 1];
595 if (t2 > nverts)
596 break;
597 t3 = hullr.Indices[i + 2];
598 if (t3 > nverts)
599 break;
600 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
601 faces.Add(f);
602 }
603 vertsoffset += nverts;
604 vs.Clear();
605 }
606 }
607 if (coords.Count > 0 && faces.Count > 0)
608 return true;
609 }
610
611 vs.Clear();
612
613 if (cmap.ContainsKey("BoundingVerts"))
614 {
615 data = cmap["BoundingVerts"].AsBinary();
616
617 for (i = 0; i < data.Length; )
618 {
619 t1 = data[i++];
620 t1 += data[i++] << 8;
621 t2 = data[i++];
622 t2 += data[i++] << 8;
623 t3 = data[i++];
624 t3 += data[i++] << 8;
625
626 f3 = new float3((t1 * range.X + min.X),
627 (t2 * range.Y + min.Y),
628 (t3 * range.Z + min.Z));
629 vs.Add(f3);
630 }
631
632 if (vs.Count < 3)
633 {
634 vs.Clear();
635 return false;
636 }
637
638 if (vs.Count < 5)
639 {
640 foreach (float3 point in vs)
641 {
642 c.X = point.x;
643 c.Y = point.y;
644 c.Z = point.z;
645 coords.Add(c);
646 }
647 f = new Face(0, 1, 2);
648 faces.Add(f);
649
650 if (vs.Count == 4)
651 {
652 f = new Face(0, 2, 3);
653 faces.Add(f);
654 f = new Face(0, 3, 1);
655 faces.Add(f);
656 f = new Face( 3, 2, 1);
657 faces.Add(f);
658 }
659 vs.Clear();
660 return true;
661 }
662
663 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
664 return false;
665
666 nverts = hullr.Vertices.Count;
667 nindexs = hullr.Indices.Count;
668
669 if (nindexs % 3 != 0)
670 return false;
671
672 for (i = 0; i < nverts; i++)
673 {
674 c.X = hullr.Vertices[i].x;
675 c.Y = hullr.Vertices[i].y;
676 c.Z = hullr.Vertices[i].z;
677 coords.Add(c);
678 }
679 for (i = 0; i < nindexs; i += 3)
680 {
681 t1 = hullr.Indices[i];
682 if (t1 > nverts)
683 break;
684 t2 = hullr.Indices[i + 1];
685 if (t2 > nverts)
686 break;
687 t3 = hullr.Indices[i + 2];
688 if (t3 > nverts)
689 break;
690 f = new Face(t1, t2, t3);
691 faces.Add(f);
692 }
693
694 if (coords.Count > 0 && faces.Count > 0)
695 return true;
696 }
697 else
698 return false;
699 }
700 }
701
702 return true;
703 }
704
705 /// <summary>
706 /// Generate the co-ords and faces necessary to construct a mesh from the sculpt data the accompanies a prim.
707 /// </summary>
708 /// <param name="primName"></param>
709 /// <param name="primShape"></param>
710 /// <param name="size"></param>
711 /// <param name="lod"></param>
712 /// <param name="coords">Coords are added to this list by the method.</param>
713 /// <param name="faces">Faces are added to this list by the method.</param>
714 /// <returns>true if coords and faces were successfully generated, false if not</returns>
715 private bool GenerateCoordsAndFacesFromPrimSculptData(
716 string primName, PrimitiveBaseShape primShape, float lod, out List<Coord> coords, out List<Face> faces)
717 {
718 coords = new List<Coord>();
719 faces = new List<Face>();
720 PrimMesher.SculptMesh sculptMesh;
721 Image idata = null;
722
723 if (primShape.SculptData == null || primShape.SculptData.Length == 0)
724 return false;
725
726 try
727 {
728 OpenMetaverse.Imaging.ManagedImage unusedData;
729 OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(primShape.SculptData, out unusedData, out idata);
730
731 unusedData = null;
732
733 if (idata == null)
734 {
735 // In some cases it seems that the decode can return a null bitmap without throwing
736 // an exception
737 m_log.WarnFormat("[PHYSICS]: OpenJPEG decoded sculpt data for {0} to a null bitmap. Ignoring.", primName);
738 return false;
739 }
740 }
741 catch (DllNotFoundException)
742 {
743 m_log.Error("[PHYSICS]: OpenJpeg is not installed correctly on this system. Physics Proxy generation failed. Often times this is because of an old version of GLIBC. You must have version 2.4 or above!");
744 return false;
745 }
746 catch (IndexOutOfRangeException)
747 {
748 m_log.Error("[PHYSICS]: OpenJpeg was unable to decode this. Physics Proxy generation failed");
749 return false;
750 }
751 catch (Exception ex)
752 {
753 m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed: " + ex.Message);
754 return false;
755 }
756
757 PrimMesher.SculptMesh.SculptType sculptType;
758 // remove mirror and invert bits
759 OpenMetaverse.SculptType pbsSculptType = ((OpenMetaverse.SculptType)(primShape.SculptType & 0x3f));
760 switch (pbsSculptType)
761 {
762 case OpenMetaverse.SculptType.Cylinder:
763 sculptType = PrimMesher.SculptMesh.SculptType.cylinder;
764 break;
765 case OpenMetaverse.SculptType.Plane:
766 sculptType = PrimMesher.SculptMesh.SculptType.plane;
767 break;
768 case OpenMetaverse.SculptType.Torus:
769 sculptType = PrimMesher.SculptMesh.SculptType.torus;
770 break;
771 case OpenMetaverse.SculptType.Sphere:
772 sculptType = PrimMesher.SculptMesh.SculptType.sphere;
773 break;
774 default:
775 sculptType = PrimMesher.SculptMesh.SculptType.plane;
776 break;
777 }
778
779 bool mirror = ((primShape.SculptType & 128) != 0);
780 bool invert = ((primShape.SculptType & 64) != 0);
781
782 sculptMesh = new PrimMesher.SculptMesh((Bitmap)idata, sculptType, (int)lod, mirror, invert);
783
784 idata.Dispose();
785
786// sculptMesh.DumpRaw(baseDir, primName, "primMesh");
787
788 coords = sculptMesh.coords;
789 faces = sculptMesh.faces;
790
791 return true;
792 }
793
794 /// <summary>
795 /// Generate the co-ords and faces necessary to construct a mesh from the shape data the accompanies a prim.
796 /// </summary>
797 /// <param name="primName"></param>
798 /// <param name="primShape"></param>
799 /// <param name="size"></param>
800 /// <param name="coords">Coords are added to this list by the method.</param>
801 /// <param name="faces">Faces are added to this list by the method.</param>
802 /// <returns>true if coords and faces were successfully generated, false if not</returns>
803 private bool GenerateCoordsAndFacesFromPrimShapeData(
804 string primName, PrimitiveBaseShape primShape, float lod, out List<Coord> coords, out List<Face> faces)
805 {
806 PrimMesh primMesh;
807 coords = new List<Coord>();
808 faces = new List<Face>();
809
810 float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f;
811 float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f;
812 float pathBegin = (float)primShape.PathBegin * 2.0e-5f;
813 float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f;
814 float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f;
815 float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f;
816
817 float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f;
818 float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f;
819
820 if (profileBegin < 0.0f)
821 profileBegin = 0.0f;
822
823 if (profileEnd < 0.02f)
824 profileEnd = 0.02f;
825 else if (profileEnd > 1.0f)
826 profileEnd = 1.0f;
827
828 if (profileBegin >= profileEnd)
829 profileBegin = profileEnd - 0.02f;
830
831 float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f;
832 if (profileHollow > 0.95f)
833 profileHollow = 0.95f;
834
835 int sides = 4;
836 LevelOfDetail iLOD = (LevelOfDetail)lod;
837 byte profshape = (byte)(primShape.ProfileCurve & 0x07);
838
839 if (profshape == (byte)ProfileShape.EquilateralTriangle
840 || profshape == (byte)ProfileShape.IsometricTriangle
841 || profshape == (byte)ProfileShape.RightTriangle)
842 sides = 3;
843 else if (profshape == (byte)ProfileShape.Circle)
844 {
845 switch (iLOD)
846 {
847 case LevelOfDetail.High: sides = 24; break;
848 case LevelOfDetail.Medium: sides = 12; break;
849 case LevelOfDetail.Low: sides = 6; break;
850 case LevelOfDetail.VeryLow: sides = 3; break;
851 default: sides = 24; break;
852 }
853 }
854 else if (profshape == (byte)ProfileShape.HalfCircle)
855 { // half circle, prim is a sphere
856 switch (iLOD)
857 {
858 case LevelOfDetail.High: sides = 24; break;
859 case LevelOfDetail.Medium: sides = 12; break;
860 case LevelOfDetail.Low: sides = 6; break;
861 case LevelOfDetail.VeryLow: sides = 3; break;
862 default: sides = 24; break;
863 }
864
865 profileBegin = 0.5f * profileBegin + 0.5f;
866 profileEnd = 0.5f * profileEnd + 0.5f;
867 }
868
869 int hollowSides = sides;
870 if (primShape.HollowShape == HollowShape.Circle)
871 {
872 switch (iLOD)
873 {
874 case LevelOfDetail.High: hollowSides = 24; break;
875 case LevelOfDetail.Medium: hollowSides = 12; break;
876 case LevelOfDetail.Low: hollowSides = 6; break;
877 case LevelOfDetail.VeryLow: hollowSides = 3; break;
878 default: hollowSides = 24; break;
879 }
880 }
881 else if (primShape.HollowShape == HollowShape.Square)
882 hollowSides = 4;
883 else if (primShape.HollowShape == HollowShape.Triangle)
884 {
885 if (profshape == (byte)ProfileShape.HalfCircle)
886 hollowSides = 6;
887 else
888 hollowSides = 3;
889 }
890
891 primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides);
892
893 if (primMesh.errorMessage != null)
894 if (primMesh.errorMessage.Length > 0)
895 m_log.Error("[ERROR] " + primMesh.errorMessage);
896
897 primMesh.topShearX = pathShearX;
898 primMesh.topShearY = pathShearY;
899 primMesh.pathCutBegin = pathBegin;
900 primMesh.pathCutEnd = pathEnd;
901
902 if (primShape.PathCurve == (byte)Extrusion.Straight || primShape.PathCurve == (byte) Extrusion.Flexible)
903 {
904 primMesh.twistBegin = (primShape.PathTwistBegin * 18) / 10;
905 primMesh.twistEnd = (primShape.PathTwist * 18) / 10;
906 primMesh.taperX = pathScaleX;
907 primMesh.taperY = pathScaleY;
908
909#if SPAM
910 m_log.Debug("****** PrimMesh Parameters (Linear) ******\n" + primMesh.ParamsToDisplayString());
911#endif
912 try
913 {
914 primMesh.ExtrudeLinear();
915 }
916 catch (Exception ex)
917 {
918 ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh);
919 return false;
920 }
921 }
922 else
923 {
924 primMesh.holeSizeX = (200 - primShape.PathScaleX) * 0.01f;
925 primMesh.holeSizeY = (200 - primShape.PathScaleY) * 0.01f;
926 primMesh.radius = 0.01f * primShape.PathRadiusOffset;
927 primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions;
928 primMesh.skew = 0.01f * primShape.PathSkew;
929 primMesh.twistBegin = (primShape.PathTwistBegin * 36) / 10;
930 primMesh.twistEnd = (primShape.PathTwist * 36) / 10;
931 primMesh.taperX = primShape.PathTaperX * 0.01f;
932 primMesh.taperY = primShape.PathTaperY * 0.01f;
933
934#if SPAM
935 m_log.Debug("****** PrimMesh Parameters (Circular) ******\n" + primMesh.ParamsToDisplayString());
936#endif
937 try
938 {
939 primMesh.ExtrudeCircular();
940 }
941 catch (Exception ex)
942 {
943 ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh);
944 return false;
945 }
946 }
947
948// primMesh.DumpRaw(baseDir, primName, "primMesh");
949
950 coords = primMesh.coords;
951 faces = primMesh.faces;
952
953 return true;
954 }
955
956 public AMeshKey GetMeshUniqueKey(PrimitiveBaseShape primShape, Vector3 size, byte lod, bool convex)
957 {
958 AMeshKey key = new AMeshKey();
959 Byte[] someBytes;
960
961 key.hashB = 5181;
962 key.hashC = 5181;
963 ulong hash = 5381;
964
965 if (primShape.SculptEntry)
966 {
967 key.uuid = primShape.SculptTexture;
968 key.hashC = mdjb2(key.hashC, primShape.SculptType);
969 key.hashC = mdjb2(key.hashC, primShape.PCode);
970 }
971 else
972 {
973 hash = mdjb2(hash, primShape.PathCurve);
974 hash = mdjb2(hash, (byte)primShape.HollowShape);
975 hash = mdjb2(hash, (byte)primShape.ProfileShape);
976 hash = mdjb2(hash, primShape.PathBegin);
977 hash = mdjb2(hash, primShape.PathEnd);
978 hash = mdjb2(hash, primShape.PathScaleX);
979 hash = mdjb2(hash, primShape.PathScaleY);
980 hash = mdjb2(hash, primShape.PathShearX);
981 key.hashA = hash;
982 hash = key.hashB;
983 hash = mdjb2(hash, primShape.PathShearY);
984 hash = mdjb2(hash, (byte)primShape.PathTwist);
985 hash = mdjb2(hash, (byte)primShape.PathTwistBegin);
986 hash = mdjb2(hash, (byte)primShape.PathRadiusOffset);
987 hash = mdjb2(hash, (byte)primShape.PathTaperX);
988 hash = mdjb2(hash, (byte)primShape.PathTaperY);
989 hash = mdjb2(hash, primShape.PathRevolutions);
990 hash = mdjb2(hash, (byte)primShape.PathSkew);
991 hash = mdjb2(hash, primShape.ProfileBegin);
992 hash = mdjb2(hash, primShape.ProfileEnd);
993 hash = mdjb2(hash, primShape.ProfileHollow);
994 hash = mdjb2(hash, primShape.PCode);
995 key.hashB = hash;
996 }
997
998 hash = key.hashC;
999
1000 hash = mdjb2(hash, lod);
1001
1002 if (size == m_MeshUnitSize)
1003 {
1004 hash = hash << 8;
1005 hash |= 8;
1006 }
1007 else
1008 {
1009 someBytes = size.GetBytes();
1010 for (int i = 0; i < someBytes.Length; i++)
1011 hash = mdjb2(hash, someBytes[i]);
1012 hash = hash << 8;
1013 }
1014
1015 if (convex)
1016 hash |= 4;
1017
1018 if (primShape.SculptEntry)
1019 {
1020 hash |= 1;
1021 if (primShape.SculptType == (byte)SculptType.Mesh)
1022 hash |= 2;
1023 }
1024
1025 key.hashC = hash;
1026
1027 return key;
1028 }
1029
1030 private ulong mdjb2(ulong hash, byte c)
1031 {
1032 return ((hash << 5) + hash) + (ulong)c;
1033 }
1034
1035 private ulong mdjb2(ulong hash, ushort c)
1036 {
1037 hash = ((hash << 5) + hash) + (ulong)((byte)c);
1038 return ((hash << 5) + hash) + (ulong)(c >> 8);
1039 }
1040
1041 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
1042 {
1043 return CreateMesh(primName, primShape, size, lod, false,false,false);
1044 }
1045
1046 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical)
1047 {
1048 return CreateMesh(primName, primShape, size, lod, false,false,false);
1049 }
1050
1051 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde)
1052 {
1053 return CreateMesh(primName, primShape, size, lod, false, false, false);
1054 }
1055
1056 public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex)
1057 {
1058 Mesh mesh = null;
1059
1060 if (size.X < 0.01f) size.X = 0.01f;
1061 if (size.Y < 0.01f) size.Y = 0.01f;
1062 if (size.Z < 0.01f) size.Z = 0.01f;
1063
1064 AMeshKey key = GetMeshUniqueKey(primShape, size, (byte)lod, convex);
1065 lock (m_uniqueMeshes)
1066 {
1067 m_uniqueMeshes.TryGetValue(key, out mesh);
1068
1069 if (mesh != null)
1070 {
1071 mesh.RefCount++;
1072 return mesh;
1073 }
1074
1075 // try to find a identical mesh on meshs recently released
1076 lock (m_uniqueReleasedMeshes)
1077 {
1078 m_uniqueReleasedMeshes.TryGetValue(key, out mesh);
1079 if (mesh != null)
1080 {
1081 m_uniqueReleasedMeshes.Remove(key);
1082 try
1083 {
1084 m_uniqueMeshes.Add(key, mesh);
1085 }
1086 catch { }
1087 mesh.RefCount = 1;
1088 return mesh;
1089 }
1090 }
1091 }
1092 return null;
1093 }
1094
1095 private static Vector3 m_MeshUnitSize = new Vector3(1.0f, 1.0f, 1.0f);
1096
1097 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde)
1098 {
1099#if SPAM
1100 m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName);
1101#endif
1102
1103 Mesh mesh = null;
1104
1105 if (size.X < 0.01f) size.X = 0.01f;
1106 if (size.Y < 0.01f) size.Y = 0.01f;
1107 if (size.Z < 0.01f) size.Z = 0.01f;
1108
1109 // try to find a identical mesh on meshs in use
1110
1111 AMeshKey key = GetMeshUniqueKey(primShape,size,(byte)lod, convex);
1112
1113 lock (m_uniqueMeshes)
1114 {
1115 m_uniqueMeshes.TryGetValue(key, out mesh);
1116
1117 if (mesh != null)
1118 {
1119 mesh.RefCount++;
1120 return mesh;
1121 }
1122
1123 // try to find a identical mesh on meshs recently released
1124 lock (m_uniqueReleasedMeshes)
1125 {
1126 m_uniqueReleasedMeshes.TryGetValue(key, out mesh);
1127 if (mesh != null)
1128 {
1129 m_uniqueReleasedMeshes.Remove(key);
1130 try
1131 {
1132 m_uniqueMeshes.Add(key, mesh);
1133 }
1134 catch { }
1135 mesh.RefCount = 1;
1136 return mesh;
1137 }
1138 }
1139 }
1140
1141 Mesh UnitMesh = null;
1142 AMeshKey unitKey = GetMeshUniqueKey(primShape, m_MeshUnitSize, (byte)lod, convex);
1143
1144 lock (m_uniqueReleasedMeshes)
1145 {
1146 m_uniqueReleasedMeshes.TryGetValue(unitKey, out UnitMesh);
1147 if (UnitMesh != null)
1148 {
1149 UnitMesh.RefCount = 1;
1150 }
1151 }
1152
1153 if (UnitMesh == null && primShape.SculptEntry && doMeshFileCache)
1154 UnitMesh = GetFromFileCache(unitKey);
1155
1156 if (UnitMesh == null)
1157 {
1158 UnitMesh = CreateMeshFromPrimMesher(primName, primShape, lod, convex);
1159
1160 if (UnitMesh == null)
1161 return null;
1162
1163 UnitMesh.DumpRaw(baseDir, unitKey.ToString(), "Z");
1164
1165 if (forOde)
1166 {
1167 // force pinned mem allocation
1168 UnitMesh.PrepForOde();
1169 }
1170 else
1171 UnitMesh.TrimExcess();
1172
1173 UnitMesh.Key = unitKey;
1174 UnitMesh.RefCount = 1;
1175
1176 if (doMeshFileCache && primShape.SculptEntry)
1177 StoreToFileCache(unitKey, UnitMesh);
1178
1179 lock (m_uniqueReleasedMeshes)
1180 {
1181 try
1182 {
1183 m_uniqueReleasedMeshes.Add(unitKey, UnitMesh);
1184 }
1185 catch { }
1186 }
1187 }
1188
1189 mesh = UnitMesh.Scale(size);
1190 mesh.Key = key;
1191 mesh.RefCount = 1;
1192 lock (m_uniqueMeshes)
1193 {
1194 try
1195 {
1196 m_uniqueMeshes.Add(key, mesh);
1197 }
1198 catch { }
1199 }
1200
1201 return mesh;
1202 }
1203
1204 public void ReleaseMesh(IMesh imesh)
1205 {
1206 if (imesh == null)
1207 return;
1208
1209 Mesh mesh = (Mesh)imesh;
1210
1211 lock (m_uniqueMeshes)
1212 {
1213 int curRefCount = mesh.RefCount;
1214 curRefCount--;
1215
1216 if (curRefCount > 0)
1217 {
1218 mesh.RefCount = curRefCount;
1219 return;
1220 }
1221
1222 mesh.RefCount = 0;
1223 m_uniqueMeshes.Remove(mesh.Key);
1224 lock (m_uniqueReleasedMeshes)
1225 {
1226 try
1227 {
1228 m_uniqueReleasedMeshes.Add(mesh.Key, mesh);
1229 }
1230 catch { }
1231 }
1232 }
1233 }
1234
1235 public void ExpireReleaseMeshs()
1236 {
1237 if (m_uniqueReleasedMeshes.Count == 0)
1238 return;
1239
1240 List<Mesh> meshstodelete = new List<Mesh>();
1241 int refcntr;
1242
1243 lock (m_uniqueReleasedMeshes)
1244 {
1245 foreach (Mesh m in m_uniqueReleasedMeshes.Values)
1246 {
1247 refcntr = m.RefCount;
1248 refcntr--;
1249 if (refcntr > -6)
1250 m.RefCount = refcntr;
1251 else
1252 meshstodelete.Add(m);
1253 }
1254
1255 foreach (Mesh m in meshstodelete)
1256 {
1257 m_uniqueReleasedMeshes.Remove(m.Key);
1258 m.releaseBuildingMeshData();
1259 m.releasePinned();
1260 }
1261 }
1262 }
1263
1264 public void FileNames(AMeshKey key, out string dir,out string fullFileName)
1265 {
1266 string id = key.ToString();
1267 string init = id.Substring(0, 1);
1268 dir = System.IO.Path.Combine(cachePath, init);
1269 fullFileName = System.IO.Path.Combine(dir, id);
1270 }
1271
1272 public string FullFileName(AMeshKey key)
1273 {
1274 string id = key.ToString();
1275 string init = id.Substring(0,1);
1276 id = System.IO.Path.Combine(init, id);
1277 id = System.IO.Path.Combine(cachePath, id);
1278 return id;
1279 }
1280
1281 private Mesh GetFromFileCache(AMeshKey key)
1282 {
1283 Mesh mesh = null;
1284 string filename = FullFileName(key);
1285 bool ok = true;
1286
1287 lock (diskLock)
1288 {
1289 if (File.Exists(filename))
1290 {
1291 FileStream stream = null;
1292 try
1293 {
1294 stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
1295 BinaryFormatter bformatter = new BinaryFormatter();
1296
1297 mesh = Mesh.FromStream(stream, key);
1298
1299 }
1300 catch (Exception e)
1301 {
1302 ok = false;
1303 m_log.ErrorFormat(
1304 "[MESH CACHE]: Failed to get file {0}. Exception {1} {2}",
1305 filename, e.Message, e.StackTrace);
1306 }
1307
1308 if (stream != null)
1309 stream.Close();
1310
1311 if (mesh == null || !ok)
1312 File.Delete(filename);
1313 else
1314 File.SetLastAccessTimeUtc(filename, DateTime.UtcNow);
1315 }
1316 }
1317
1318 return mesh;
1319 }
1320
1321 private void StoreToFileCache(AMeshKey key, Mesh mesh)
1322 {
1323 Stream stream = null;
1324 bool ok = false;
1325
1326 // Make sure the target cache directory exists
1327 string dir = String.Empty;
1328 string filename = String.Empty;
1329
1330 FileNames(key, out dir, out filename);
1331
1332 lock (diskLock)
1333 {
1334 try
1335 {
1336 if (!Directory.Exists(dir))
1337 {
1338 Directory.CreateDirectory(dir);
1339 }
1340
1341 stream = File.Open(filename, FileMode.Create);
1342 ok = mesh.ToStream(stream);
1343 }
1344 catch (IOException e)
1345 {
1346 m_log.ErrorFormat(
1347 "[MESH CACHE]: Failed to write file {0}. Exception {1} {2}.",
1348 filename, e.Message, e.StackTrace);
1349 ok = false;
1350 }
1351
1352 if (stream != null)
1353 stream.Close();
1354
1355 if (File.Exists(filename))
1356 {
1357 if (ok)
1358 File.SetLastAccessTimeUtc(filename, DateTime.UtcNow);
1359 else
1360 File.Delete(filename);
1361 }
1362 }
1363 }
1364
1365 public void ExpireFileCache()
1366 {
1367 if (!doCacheExpire)
1368 return;
1369
1370 string controlfile = System.IO.Path.Combine(cachePath, "cntr");
1371
1372 lock (diskLock)
1373 {
1374 try
1375 {
1376 if (File.Exists(controlfile))
1377 {
1378 int ndeleted = 0;
1379 int totalfiles = 0;
1380 int ndirs = 0;
1381 DateTime OlderTime = File.GetLastAccessTimeUtc(controlfile) - CacheExpire;
1382 File.SetLastAccessTimeUtc(controlfile, DateTime.UtcNow);
1383
1384 foreach (string dir in Directory.GetDirectories(cachePath))
1385 {
1386 try
1387 {
1388 foreach (string file in Directory.GetFiles(dir))
1389 {
1390 try
1391 {
1392 if (File.GetLastAccessTimeUtc(file) < OlderTime)
1393 {
1394 File.Delete(file);
1395 ndeleted++;
1396 }
1397 }
1398 catch { }
1399 totalfiles++;
1400 }
1401 }
1402 catch { }
1403 ndirs++;
1404 }
1405
1406 if (ndeleted == 0)
1407 m_log.InfoFormat("[MESH CACHE]: {0} Files in {1} cache folders, no expires",
1408 totalfiles,ndirs);
1409 else
1410 m_log.InfoFormat("[MESH CACHE]: {0} Files in {1} cache folders, expired {2} files accessed before {3}",
1411 totalfiles,ndirs, ndeleted, OlderTime.ToString());
1412 }
1413 else
1414 {
1415 m_log.Info("[MESH CACHE]: Expire delayed to next startup");
1416 FileStream fs = File.Create(controlfile,4096,FileOptions.WriteThrough);
1417 fs.Close();
1418 }
1419 }
1420 catch { }
1421 }
1422 }
1423 }
1424}
diff --git a/OpenSim/Region/Physics/UbitMeshing/PrimMesher.cs b/OpenSim/Region/Physics/UbitMeshing/PrimMesher.cs
new file mode 100644
index 0000000..8eb136b
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/PrimMesher.cs
@@ -0,0 +1,1708 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.IO;
32
33namespace PrimMesher
34{
35 public struct Quat
36 {
37 /// <summary>X value</summary>
38 public float X;
39 /// <summary>Y value</summary>
40 public float Y;
41 /// <summary>Z value</summary>
42 public float Z;
43 /// <summary>W value</summary>
44 public float W;
45
46 public Quat(float x, float y, float z, float w)
47 {
48 X = x;
49 Y = y;
50 Z = z;
51 W = w;
52 }
53
54 public Quat(Coord axis, float angle)
55 {
56 axis = axis.Normalize();
57
58 angle *= 0.5f;
59 float c = (float)Math.Cos(angle);
60 float s = (float)Math.Sin(angle);
61
62 X = axis.X * s;
63 Y = axis.Y * s;
64 Z = axis.Z * s;
65 W = c;
66
67 Normalize();
68 }
69
70 public float Length()
71 {
72 return (float)Math.Sqrt(X * X + Y * Y + Z * Z + W * W);
73 }
74
75 public Quat Normalize()
76 {
77 const float MAG_THRESHOLD = 0.0000001f;
78 float mag = Length();
79
80 // Catch very small rounding errors when normalizing
81 if (mag > MAG_THRESHOLD)
82 {
83 float oomag = 1f / mag;
84 X *= oomag;
85 Y *= oomag;
86 Z *= oomag;
87 W *= oomag;
88 }
89 else
90 {
91 X = 0f;
92 Y = 0f;
93 Z = 0f;
94 W = 1f;
95 }
96
97 return this;
98 }
99
100 public static Quat operator *(Quat q1, Quat q2)
101 {
102 float x = q1.W * q2.X + q1.X * q2.W + q1.Y * q2.Z - q1.Z * q2.Y;
103 float y = q1.W * q2.Y - q1.X * q2.Z + q1.Y * q2.W + q1.Z * q2.X;
104 float z = q1.W * q2.Z + q1.X * q2.Y - q1.Y * q2.X + q1.Z * q2.W;
105 float w = q1.W * q2.W - q1.X * q2.X - q1.Y * q2.Y - q1.Z * q2.Z;
106 return new Quat(x, y, z, w);
107 }
108
109 public override string ToString()
110 {
111 return "< X: " + this.X.ToString() + ", Y: " + this.Y.ToString() + ", Z: " + this.Z.ToString() + ", W: " + this.W.ToString() + ">";
112 }
113 }
114
115 public struct Coord
116 {
117 public float X;
118 public float Y;
119 public float Z;
120
121 public Coord(float x, float y, float z)
122 {
123 this.X = x;
124 this.Y = y;
125 this.Z = z;
126 }
127
128 public float Length()
129 {
130 return (float)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
131 }
132
133 public Coord Invert()
134 {
135 this.X = -this.X;
136 this.Y = -this.Y;
137 this.Z = -this.Z;
138
139 return this;
140 }
141
142 public Coord Normalize()
143 {
144 const float MAG_THRESHOLD = 0.0000001f;
145 float mag = Length();
146
147 // Catch very small rounding errors when normalizing
148 if (mag > MAG_THRESHOLD)
149 {
150 float oomag = 1.0f / mag;
151 this.X *= oomag;
152 this.Y *= oomag;
153 this.Z *= oomag;
154 }
155 else
156 {
157 this.X = 0.0f;
158 this.Y = 0.0f;
159 this.Z = 0.0f;
160 }
161
162 return this;
163 }
164
165 public override string ToString()
166 {
167 return this.X.ToString() + " " + this.Y.ToString() + " " + this.Z.ToString();
168 }
169
170 public static Coord Cross(Coord c1, Coord c2)
171 {
172 return new Coord(
173 c1.Y * c2.Z - c2.Y * c1.Z,
174 c1.Z * c2.X - c2.Z * c1.X,
175 c1.X * c2.Y - c2.X * c1.Y
176 );
177 }
178
179 public static Coord operator +(Coord v, Coord a)
180 {
181 return new Coord(v.X + a.X, v.Y + a.Y, v.Z + a.Z);
182 }
183
184 public static Coord operator *(Coord v, Coord m)
185 {
186 return new Coord(v.X * m.X, v.Y * m.Y, v.Z * m.Z);
187 }
188
189 public static Coord operator *(Coord v, Quat q)
190 {
191 // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/
192
193 Coord c2 = new Coord(0.0f, 0.0f, 0.0f);
194
195 c2.X = q.W * q.W * v.X +
196 2f * q.Y * q.W * v.Z -
197 2f * q.Z * q.W * v.Y +
198 q.X * q.X * v.X +
199 2f * q.Y * q.X * v.Y +
200 2f * q.Z * q.X * v.Z -
201 q.Z * q.Z * v.X -
202 q.Y * q.Y * v.X;
203
204 c2.Y =
205 2f * q.X * q.Y * v.X +
206 q.Y * q.Y * v.Y +
207 2f * q.Z * q.Y * v.Z +
208 2f * q.W * q.Z * v.X -
209 q.Z * q.Z * v.Y +
210 q.W * q.W * v.Y -
211 2f * q.X * q.W * v.Z -
212 q.X * q.X * v.Y;
213
214 c2.Z =
215 2f * q.X * q.Z * v.X +
216 2f * q.Y * q.Z * v.Y +
217 q.Z * q.Z * v.Z -
218 2f * q.W * q.Y * v.X -
219 q.Y * q.Y * v.Z +
220 2f * q.W * q.X * v.Y -
221 q.X * q.X * v.Z +
222 q.W * q.W * v.Z;
223
224 return c2;
225 }
226 }
227
228 public struct Face
229 {
230 public int primFace;
231
232 // vertices
233 public int v1;
234 public int v2;
235 public int v3;
236
237 public Face(int v1, int v2, int v3)
238 {
239 primFace = 0;
240
241 this.v1 = v1;
242 this.v2 = v2;
243 this.v3 = v3;
244
245 }
246
247 public Coord SurfaceNormal(List<Coord> coordList)
248 {
249 Coord c1 = coordList[this.v1];
250 Coord c2 = coordList[this.v2];
251 Coord c3 = coordList[this.v3];
252
253 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z);
254 Coord edge2 = new Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z);
255
256 return Coord.Cross(edge1, edge2).Normalize();
257 }
258 }
259
260 internal struct Angle
261 {
262 internal float angle;
263 internal float X;
264 internal float Y;
265
266 internal Angle(float angle, float x, float y)
267 {
268 this.angle = angle;
269 this.X = x;
270 this.Y = y;
271 }
272 }
273
274 internal class AngleList
275 {
276 private float iX, iY; // intersection point
277
278 private static Angle[] angles3 =
279 {
280 new Angle(0.0f, 1.0f, 0.0f),
281 new Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f),
282 new Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f),
283 new Angle(1.0f, 1.0f, 0.0f)
284 };
285
286 private static Angle[] angles4 =
287 {
288 new Angle(0.0f, 1.0f, 0.0f),
289 new Angle(0.25f, 0.0f, 1.0f),
290 new Angle(0.5f, -1.0f, 0.0f),
291 new Angle(0.75f, 0.0f, -1.0f),
292 new Angle(1.0f, 1.0f, 0.0f)
293 };
294
295 private static Angle[] angles6 =
296 {
297 new Angle(0.0f, 1.0f, 0.0f),
298 new Angle(0.16666666666666667f, 0.5f, 0.8660254037844386f),
299 new Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f),
300 new Angle(0.5f, -1.0f, 0.0f),
301 new Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f),
302 new Angle(0.83333333333333326f, 0.5f, -0.86602540378443904f),
303 new Angle(1.0f, 1.0f, 0.0f)
304 };
305
306 private static Angle[] angles12 =
307 {
308 new Angle(0.0f, 1.0f, 0.0f),
309 new Angle(0.083333333333333329f, 0.86602540378443871f, 0.5f),
310 new Angle(0.16666666666666667f, 0.5f, 0.8660254037844386f),
311 new Angle(0.25f, 0.0f, 1.0f),
312 new Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f),
313 new Angle(0.41666666666666663f, -0.86602540378443849f, 0.5f),
314 new Angle(0.5f, -1.0f, 0.0f),
315 new Angle(0.58333333333333326f, -0.86602540378443882f, -0.5f),
316 new Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f),
317 new Angle(0.75f, 0.0f, -1.0f),
318 new Angle(0.83333333333333326f, 0.5f, -0.86602540378443904f),
319 new Angle(0.91666666666666663f, 0.86602540378443837f, -0.5f),
320 new Angle(1.0f, 1.0f, 0.0f)
321 };
322
323 private static Angle[] angles24 =
324 {
325 new Angle(0.0f, 1.0f, 0.0f),
326 new Angle(0.041666666666666664f, 0.96592582628906831f, 0.25881904510252074f),
327 new Angle(0.083333333333333329f, 0.86602540378443871f, 0.5f),
328 new Angle(0.125f, 0.70710678118654757f, 0.70710678118654746f),
329 new Angle(0.16666666666666667f, 0.5f, 0.8660254037844386f),
330 new Angle(0.20833333333333331f, 0.25881904510252096f, 0.9659258262890682f),
331 new Angle(0.25f, 0.0f, 1.0f),
332 new Angle(0.29166666666666663f, -0.25881904510252063f, 0.96592582628906831f),
333 new Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f),
334 new Angle(0.375f, -0.70710678118654746f, 0.70710678118654757f),
335 new Angle(0.41666666666666663f, -0.86602540378443849f, 0.5f),
336 new Angle(0.45833333333333331f, -0.9659258262890682f, 0.25881904510252102f),
337 new Angle(0.5f, -1.0f, 0.0f),
338 new Angle(0.54166666666666663f, -0.96592582628906842f, -0.25881904510252035f),
339 new Angle(0.58333333333333326f, -0.86602540378443882f, -0.5f),
340 new Angle(0.62499999999999989f, -0.70710678118654791f, -0.70710678118654713f),
341 new Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f),
342 new Angle(0.70833333333333326f, -0.25881904510252152f, -0.96592582628906809f),
343 new Angle(0.75f, 0.0f, -1.0f),
344 new Angle(0.79166666666666663f, 0.2588190451025203f, -0.96592582628906842f),
345 new Angle(0.83333333333333326f, 0.5f, -0.86602540378443904f),
346 new Angle(0.875f, 0.70710678118654735f, -0.70710678118654768f),
347 new Angle(0.91666666666666663f, 0.86602540378443837f, -0.5f),
348 new Angle(0.95833333333333326f, 0.96592582628906809f, -0.25881904510252157f),
349 new Angle(1.0f, 1.0f, 0.0f)
350 };
351
352 private Angle interpolatePoints(float newPoint, Angle p1, Angle p2)
353 {
354 float m = (newPoint - p1.angle) / (p2.angle - p1.angle);
355 return new Angle(newPoint, p1.X + m * (p2.X - p1.X), p1.Y + m * (p2.Y - p1.Y));
356 }
357
358 private void intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
359 { // ref: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
360 double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
361 double uaNumerator = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
362
363 if (denom != 0.0)
364 {
365 double ua = uaNumerator / denom;
366 iX = (float)(x1 + ua * (x2 - x1));
367 iY = (float)(y1 + ua * (y2 - y1));
368 }
369 }
370
371 internal List<Angle> angles;
372
373 internal void makeAngles(int sides, float startAngle, float stopAngle, bool hasCut)
374 {
375 angles = new List<Angle>();
376
377 const double twoPi = System.Math.PI * 2.0;
378 const float twoPiInv = (float)(1.0d / twoPi);
379
380 if (sides < 1)
381 throw new Exception("number of sides not greater than zero");
382 if (stopAngle <= startAngle)
383 throw new Exception("stopAngle not greater than startAngle");
384
385 if ((sides == 3 || sides == 4 || sides == 6 || sides == 12 || sides == 24))
386 {
387 startAngle *= twoPiInv;
388 stopAngle *= twoPiInv;
389
390 Angle[] sourceAngles;
391 switch (sides)
392 {
393 case 3:
394 sourceAngles = angles3;
395 break;
396 case 4:
397 sourceAngles = angles4;
398 break;
399 case 6:
400 sourceAngles = angles6;
401 break;
402 case 12:
403 sourceAngles = angles12;
404 break;
405 default:
406 sourceAngles = angles24;
407 break;
408 }
409
410 int startAngleIndex = (int)(startAngle * sides);
411 int endAngleIndex = sourceAngles.Length - 1;
412
413 if (hasCut)
414 {
415 if (stopAngle < 1.0f)
416 endAngleIndex = (int)(stopAngle * sides) + 1;
417 if (endAngleIndex == startAngleIndex)
418 endAngleIndex++;
419
420 for (int angleIndex = startAngleIndex; angleIndex < endAngleIndex + 1; angleIndex++)
421 {
422 angles.Add(sourceAngles[angleIndex]);
423 }
424
425 if (startAngle > 0.0f)
426 angles[0] = interpolatePoints(startAngle, angles[0], angles[1]);
427
428 if (stopAngle < 1.0f)
429 {
430 int lastAngleIndex = angles.Count - 1;
431 angles[lastAngleIndex] = interpolatePoints(stopAngle, angles[lastAngleIndex - 1], angles[lastAngleIndex]);
432 }
433 }
434 else
435 {
436 for (int angleIndex = startAngleIndex; angleIndex < endAngleIndex; angleIndex++)
437 angles.Add(sourceAngles[angleIndex]);
438 }
439 }
440 else
441 {
442 double stepSize = twoPi / sides;
443
444 int startStep = (int)(startAngle / stepSize);
445 double angle = stepSize * startStep;
446 int step = startStep;
447 double stopAngleTest = stopAngle;
448 if (stopAngle < twoPi)
449 {
450 stopAngleTest = stepSize * ((int)(stopAngle / stepSize) + 1);
451 if (stopAngleTest < stopAngle)
452 stopAngleTest += stepSize;
453 if (stopAngleTest > twoPi)
454 stopAngleTest = twoPi;
455 }
456
457 while (angle <= stopAngleTest)
458 {
459 Angle newAngle;
460 newAngle.angle = (float)angle;
461 newAngle.X = (float)System.Math.Cos(angle);
462 newAngle.Y = (float)System.Math.Sin(angle);
463 angles.Add(newAngle);
464 step += 1;
465 angle = stepSize * step;
466 }
467
468 if (startAngle > angles[0].angle)
469 {
470 Angle newAngle;
471 intersection(angles[0].X, angles[0].Y, angles[1].X, angles[1].Y, 0.0f, 0.0f, (float)Math.Cos(startAngle), (float)Math.Sin(startAngle));
472 newAngle.angle = startAngle;
473 newAngle.X = iX;
474 newAngle.Y = iY;
475 angles[0] = newAngle;
476 }
477
478 int index = angles.Count - 1;
479 if (stopAngle < angles[index].angle)
480 {
481 Angle newAngle;
482 intersection(angles[index - 1].X, angles[index - 1].Y, angles[index].X, angles[index].Y, 0.0f, 0.0f, (float)Math.Cos(stopAngle), (float)Math.Sin(stopAngle));
483 newAngle.angle = stopAngle;
484 newAngle.X = iX;
485 newAngle.Y = iY;
486 angles[index] = newAngle;
487 }
488 }
489 }
490 }
491
492 /// <summary>
493 /// generates a profile for extrusion
494 /// </summary>
495 public class Profile
496 {
497 private const float twoPi = 2.0f * (float)Math.PI;
498
499 public string errorMessage = null;
500
501 public List<Coord> coords;
502 public List<Face> faces;
503
504 // use these for making individual meshes for each prim face
505 public List<int> outerCoordIndices = null;
506 public List<int> hollowCoordIndices = null;
507
508 public int numOuterVerts = 0;
509 public int numHollowVerts = 0;
510
511 public int outerFaceNumber = -1;
512 public int hollowFaceNumber = -1;
513
514 public int bottomFaceNumber = 0;
515 public int numPrimFaces = 0;
516
517 public Profile()
518 {
519 this.coords = new List<Coord>();
520 this.faces = new List<Face>();
521 }
522
523 public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool hasProfileCut, bool createFaces)
524 {
525 const float halfSqr2 = 0.7071067811866f;
526
527 this.coords = new List<Coord>();
528 this.faces = new List<Face>();
529
530 List<Coord> hollowCoords = new List<Coord>();
531
532 bool hasHollow = (hollow > 0.0f);
533
534 AngleList angles = new AngleList();
535 AngleList hollowAngles = new AngleList();
536
537 float xScale = 0.5f;
538 float yScale = 0.5f;
539 if (sides == 4) // corners of a square are sqrt(2) from center
540 {
541 xScale = halfSqr2;
542 yScale = halfSqr2;
543 }
544
545 float startAngle = profileStart * twoPi;
546 float stopAngle = profileEnd * twoPi;
547
548 try { angles.makeAngles(sides, startAngle, stopAngle,hasProfileCut); }
549 catch (Exception ex)
550 {
551
552 errorMessage = "makeAngles failed: Exception: " + ex.ToString()
553 + "\nsides: " + sides.ToString() + " startAngle: " + startAngle.ToString() + " stopAngle: " + stopAngle.ToString();
554
555 return;
556 }
557
558 this.numOuterVerts = angles.angles.Count;
559
560 Angle angle;
561 Coord newVert = new Coord();
562
563 // flag to create as few triangles as possible for 3 or 4 side profile
564 bool simpleFace = (sides < 5 && !hasHollow && !hasProfileCut);
565
566 if (hasHollow)
567 {
568 if (sides == hollowSides)
569 hollowAngles = angles;
570 else
571 {
572 try { hollowAngles.makeAngles(hollowSides, startAngle, stopAngle, hasProfileCut); }
573 catch (Exception ex)
574 {
575 errorMessage = "makeAngles failed: Exception: " + ex.ToString()
576 + "\nsides: " + sides.ToString() + " startAngle: " + startAngle.ToString() + " stopAngle: " + stopAngle.ToString();
577
578 return;
579 }
580
581 int numHollowAngles = hollowAngles.angles.Count;
582 for (int i = 0; i < numHollowAngles; i++)
583 {
584 angle = hollowAngles.angles[i];
585 newVert.X = hollow * xScale * angle.X;
586 newVert.Y = hollow * yScale * angle.Y;
587 newVert.Z = 0.0f;
588
589 hollowCoords.Add(newVert);
590 }
591 }
592 this.numHollowVerts = hollowAngles.angles.Count;
593 }
594 else if (!simpleFace)
595 {
596 Coord center = new Coord(0.0f, 0.0f, 0.0f);
597 this.coords.Add(center);
598 }
599
600 int numAngles = angles.angles.Count;
601 bool hollowsame = (hasHollow && hollowSides == sides);
602
603 for (int i = 0; i < numAngles; i++)
604 {
605 angle = angles.angles[i];
606 newVert.X = angle.X * xScale;
607 newVert.Y = angle.Y * yScale;
608 newVert.Z = 0.0f;
609 this.coords.Add(newVert);
610 if (hollowsame)
611 {
612 newVert.X *= hollow;
613 newVert.Y *= hollow;
614 hollowCoords.Add(newVert);
615 }
616 }
617
618 if (hasHollow)
619 {
620 hollowCoords.Reverse();
621 this.coords.AddRange(hollowCoords);
622
623 if (createFaces)
624 {
625 int numTotalVerts = this.numOuterVerts + this.numHollowVerts;
626
627 if (this.numOuterVerts == this.numHollowVerts)
628 {
629 Face newFace = new Face();
630
631 for (int coordIndex = 0; coordIndex < this.numOuterVerts - 1; coordIndex++)
632 {
633 newFace.v1 = coordIndex;
634 newFace.v2 = coordIndex + 1;
635 newFace.v3 = numTotalVerts - coordIndex - 1;
636 this.faces.Add(newFace);
637
638 newFace.v1 = coordIndex + 1;
639 newFace.v2 = numTotalVerts - coordIndex - 2;
640 newFace.v3 = numTotalVerts - coordIndex - 1;
641 this.faces.Add(newFace);
642 }
643 if (!hasProfileCut)
644 {
645 newFace.v1 = this.numOuterVerts - 1;
646 newFace.v2 = 0;
647 newFace.v3 = this.numOuterVerts;
648 this.faces.Add(newFace);
649
650 newFace.v1 = 0;
651 newFace.v2 = numTotalVerts - 1;
652 newFace.v3 = this.numOuterVerts;
653 this.faces.Add(newFace);
654 }
655 }
656 else if (this.numOuterVerts < this.numHollowVerts)
657 {
658 Face newFace = new Face();
659 int j = 0; // j is the index for outer vertices
660 int i;
661 int maxJ = this.numOuterVerts - 1;
662 float curHollowAngle = 0;
663 for (i = 0; i < this.numHollowVerts; i++) // i is the index for inner vertices
664 {
665 curHollowAngle = hollowAngles.angles[i].angle;
666 if (j < maxJ)
667 {
668 if (angles.angles[j + 1].angle - curHollowAngle < curHollowAngle - angles.angles[j].angle + 0.000001f)
669 {
670 newFace.v1 = numTotalVerts - i - 1;
671 newFace.v2 = j;
672 newFace.v3 = j + 1;
673 this.faces.Add(newFace);
674 j++;
675 }
676 }
677 else
678 {
679 if (1.0f - curHollowAngle < curHollowAngle - angles.angles[j].angle + 0.000001f)
680 break;
681 }
682
683 newFace.v1 = j;
684 newFace.v2 = numTotalVerts - i - 2;
685 newFace.v3 = numTotalVerts - i - 1;
686
687 this.faces.Add(newFace);
688 }
689
690 if (!hasProfileCut)
691 {
692 if (i == this.numHollowVerts)
693 {
694 newFace.v1 = numTotalVerts - this.numHollowVerts;
695 newFace.v2 = maxJ;
696 newFace.v3 = 0;
697
698 this.faces.Add(newFace);
699 }
700 else
701 {
702 if (1.0f - curHollowAngle < curHollowAngle - angles.angles[maxJ].angle + 0.000001f)
703 {
704 newFace.v1 = numTotalVerts - i - 1;
705 newFace.v2 = maxJ;
706 newFace.v3 = 0;
707
708 this.faces.Add(newFace);
709 }
710
711 for (; i < this.numHollowVerts - 1; i++)
712 {
713 newFace.v1 = 0;
714 newFace.v2 = numTotalVerts - i - 2;
715 newFace.v3 = numTotalVerts - i - 1;
716
717 this.faces.Add(newFace);
718 }
719 }
720
721 newFace.v1 = 0;
722 newFace.v2 = numTotalVerts - this.numHollowVerts;
723 newFace.v3 = numTotalVerts - 1;
724 this.faces.Add(newFace);
725 }
726 }
727 else // numHollowVerts < numOuterVerts
728 {
729 Face newFace = new Face();
730 int j = 0; // j is the index for inner vertices
731 int maxJ = this.numHollowVerts - 1;
732 for (int i = 0; i < this.numOuterVerts; i++)
733 {
734 if (j < maxJ)
735 if (hollowAngles.angles[j + 1].angle - angles.angles[i].angle < angles.angles[i].angle - hollowAngles.angles[j].angle + 0.000001f)
736 {
737 newFace.v1 = i;
738 newFace.v2 = numTotalVerts - j - 2;
739 newFace.v3 = numTotalVerts - j - 1;
740
741 this.faces.Add(newFace);
742 j += 1;
743 }
744
745 newFace.v1 = numTotalVerts - j - 1;
746 newFace.v2 = i;
747 newFace.v3 = i + 1;
748
749 this.faces.Add(newFace);
750 }
751
752 if (!hasProfileCut)
753 {
754 int i = this.numOuterVerts - 1;
755
756 if (hollowAngles.angles[0].angle - angles.angles[i].angle < angles.angles[i].angle - hollowAngles.angles[maxJ].angle + 0.000001f)
757 {
758 newFace.v1 = 0;
759 newFace.v2 = numTotalVerts - maxJ - 1;
760 newFace.v3 = numTotalVerts - 1;
761
762 this.faces.Add(newFace);
763 }
764
765 newFace.v1 = numTotalVerts - maxJ - 1;
766 newFace.v2 = i;
767 newFace.v3 = 0;
768
769 this.faces.Add(newFace);
770 }
771 }
772 }
773
774 }
775
776 else if (createFaces)
777 {
778 if (simpleFace)
779 {
780 if (sides == 3)
781 this.faces.Add(new Face(0, 1, 2));
782 else if (sides == 4)
783 {
784 this.faces.Add(new Face(0, 1, 2));
785 this.faces.Add(new Face(0, 2, 3));
786 }
787 }
788 else
789 {
790 for (int i = 1; i < numAngles ; i++)
791 {
792 Face newFace = new Face();
793 newFace.v1 = 0;
794 newFace.v2 = i;
795 newFace.v3 = i + 1;
796 this.faces.Add(newFace);
797 }
798 if (!hasProfileCut)
799 {
800 Face newFace = new Face();
801 newFace.v1 = 0;
802 newFace.v2 = numAngles;
803 newFace.v3 = 1;
804 this.faces.Add(newFace);
805 }
806 }
807 }
808
809
810 hollowCoords = null;
811 }
812
813
814 public Profile Copy()
815 {
816 return this.Copy(true);
817 }
818
819 public Profile Copy(bool needFaces)
820 {
821 Profile copy = new Profile();
822
823 copy.coords.AddRange(this.coords);
824
825 if (needFaces)
826 copy.faces.AddRange(this.faces);
827
828 copy.numOuterVerts = this.numOuterVerts;
829 copy.numHollowVerts = this.numHollowVerts;
830
831 return copy;
832 }
833
834 public void AddPos(Coord v)
835 {
836 this.AddPos(v.X, v.Y, v.Z);
837 }
838
839 public void AddPos(float x, float y, float z)
840 {
841 int i;
842 int numVerts = this.coords.Count;
843 Coord vert;
844
845 for (i = 0; i < numVerts; i++)
846 {
847 vert = this.coords[i];
848 vert.X += x;
849 vert.Y += y;
850 vert.Z += z;
851 this.coords[i] = vert;
852 }
853 }
854
855 public void AddRot(Quat q)
856 {
857 int i;
858 int numVerts = this.coords.Count;
859
860 for (i = 0; i < numVerts; i++)
861 this.coords[i] *= q;
862 }
863
864 public void Scale(float x, float y)
865 {
866 int i;
867 int numVerts = this.coords.Count;
868 Coord vert;
869
870 for (i = 0; i < numVerts; i++)
871 {
872 vert = this.coords[i];
873 vert.X *= x;
874 vert.Y *= y;
875 this.coords[i] = vert;
876 }
877 }
878
879 /// <summary>
880 /// Changes order of the vertex indices and negates the center vertex normal. Does not alter vertex normals of radial vertices
881 /// </summary>
882 public void FlipNormals()
883 {
884 int i;
885 int numFaces = this.faces.Count;
886 Face tmpFace;
887 int tmp;
888
889 for (i = 0; i < numFaces; i++)
890 {
891 tmpFace = this.faces[i];
892 tmp = tmpFace.v3;
893 tmpFace.v3 = tmpFace.v1;
894 tmpFace.v1 = tmp;
895 this.faces[i] = tmpFace;
896 }
897 }
898
899 public void AddValue2FaceVertexIndices(int num)
900 {
901 int numFaces = this.faces.Count;
902 Face tmpFace;
903 for (int i = 0; i < numFaces; i++)
904 {
905 tmpFace = this.faces[i];
906 tmpFace.v1 += num;
907 tmpFace.v2 += num;
908 tmpFace.v3 += num;
909
910 this.faces[i] = tmpFace;
911 }
912 }
913
914 public void DumpRaw(String path, String name, String title)
915 {
916 if (path == null)
917 return;
918 String fileName = name + "_" + title + ".raw";
919 String completePath = System.IO.Path.Combine(path, fileName);
920 StreamWriter sw = new StreamWriter(completePath);
921
922 for (int i = 0; i < this.faces.Count; i++)
923 {
924 string s = this.coords[this.faces[i].v1].ToString();
925 s += " " + this.coords[this.faces[i].v2].ToString();
926 s += " " + this.coords[this.faces[i].v3].ToString();
927
928 sw.WriteLine(s);
929 }
930
931 sw.Close();
932 }
933 }
934
935 public struct PathNode
936 {
937 public Coord position;
938 public Quat rotation;
939 public float xScale;
940 public float yScale;
941 public float percentOfPath;
942 }
943
944 public enum PathType { Linear = 0, Circular = 1, Flexible = 2 }
945
946 public class Path
947 {
948 public List<PathNode> pathNodes = new List<PathNode>();
949
950 public float twistBegin = 0.0f;
951 public float twistEnd = 0.0f;
952 public float topShearX = 0.0f;
953 public float topShearY = 0.0f;
954 public float pathCutBegin = 0.0f;
955 public float pathCutEnd = 1.0f;
956 public float dimpleBegin = 0.0f;
957 public float dimpleEnd = 1.0f;
958 public float skew = 0.0f;
959 public float holeSizeX = 1.0f; // called pathScaleX in pbs
960 public float holeSizeY = 0.25f;
961 public float taperX = 0.0f;
962 public float taperY = 0.0f;
963 public float radius = 0.0f;
964 public float revolutions = 1.0f;
965 public int stepsPerRevolution = 24;
966
967 private const float twoPi = 2.0f * (float)Math.PI;
968
969 public void Create(PathType pathType, int steps)
970 {
971 if (this.taperX > 0.999f)
972 this.taperX = 0.999f;
973 if (this.taperX < -0.999f)
974 this.taperX = -0.999f;
975 if (this.taperY > 0.999f)
976 this.taperY = 0.999f;
977 if (this.taperY < -0.999f)
978 this.taperY = -0.999f;
979
980 if (pathType == PathType.Linear || pathType == PathType.Flexible)
981 {
982 int step = 0;
983
984 float length = this.pathCutEnd - this.pathCutBegin;
985 float twistTotal = twistEnd - twistBegin;
986 float twistTotalAbs = Math.Abs(twistTotal);
987 if (twistTotalAbs > 0.01f)
988 steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number
989
990 float start = -0.5f;
991 float stepSize = length / (float)steps;
992 float percentOfPathMultiplier = stepSize * 0.999999f;
993 float xOffset = this.topShearX * this.pathCutBegin;
994 float yOffset = this.topShearY * this.pathCutBegin;
995 float zOffset = start;
996 float xOffsetStepIncrement = this.topShearX * length / steps;
997 float yOffsetStepIncrement = this.topShearY * length / steps;
998
999 float percentOfPath = this.pathCutBegin;
1000 zOffset += percentOfPath;
1001
1002 // sanity checks
1003
1004 bool done = false;
1005
1006 while (!done)
1007 {
1008 PathNode newNode = new PathNode();
1009
1010 newNode.xScale = 1.0f;
1011 if (this.taperX == 0.0f)
1012 newNode.xScale = 1.0f;
1013 else if (this.taperX > 0.0f)
1014 newNode.xScale = 1.0f - percentOfPath * this.taperX;
1015 else newNode.xScale = 1.0f + (1.0f - percentOfPath) * this.taperX;
1016
1017 newNode.yScale = 1.0f;
1018 if (this.taperY == 0.0f)
1019 newNode.yScale = 1.0f;
1020 else if (this.taperY > 0.0f)
1021 newNode.yScale = 1.0f - percentOfPath * this.taperY;
1022 else newNode.yScale = 1.0f + (1.0f - percentOfPath) * this.taperY;
1023
1024 float twist = twistBegin + twistTotal * percentOfPath;
1025
1026 newNode.rotation = new Quat(new Coord(0.0f, 0.0f, 1.0f), twist);
1027 newNode.position = new Coord(xOffset, yOffset, zOffset);
1028 newNode.percentOfPath = percentOfPath;
1029
1030 pathNodes.Add(newNode);
1031
1032 if (step < steps)
1033 {
1034 step += 1;
1035 percentOfPath += percentOfPathMultiplier;
1036 xOffset += xOffsetStepIncrement;
1037 yOffset += yOffsetStepIncrement;
1038 zOffset += stepSize;
1039 if (percentOfPath > this.pathCutEnd)
1040 done = true;
1041 }
1042 else done = true;
1043 }
1044 } // end of linear path code
1045
1046 else // pathType == Circular
1047 {
1048 float twistTotal = twistEnd - twistBegin;
1049
1050 // if the profile has a lot of twist, add more layers otherwise the layers may overlap
1051 // and the resulting mesh may be quite inaccurate. This method is arbitrary and doesn't
1052 // accurately match the viewer
1053 float twistTotalAbs = Math.Abs(twistTotal);
1054 if (twistTotalAbs > 0.01f)
1055 {
1056 if (twistTotalAbs > Math.PI * 1.5f)
1057 steps *= 2;
1058 if (twistTotalAbs > Math.PI * 3.0f)
1059 steps *= 2;
1060 }
1061
1062 float yPathScale = this.holeSizeY * 0.5f;
1063 float pathLength = this.pathCutEnd - this.pathCutBegin;
1064 float totalSkew = this.skew * 2.0f * pathLength;
1065 float skewStart = this.pathCutBegin * 2.0f * this.skew - this.skew;
1066 float xOffsetTopShearXFactor = this.topShearX * (0.25f + 0.5f * (0.5f - this.holeSizeY));
1067 float yShearCompensation = 1.0f + Math.Abs(this.topShearY) * 0.25f;
1068
1069 // It's not quite clear what pushY (Y top shear) does, but subtracting it from the start and end
1070 // angles appears to approximate it's effects on path cut. Likewise, adding it to the angle used
1071 // to calculate the sine for generating the path radius appears to approximate it's effects there
1072 // too, but there are some subtle differences in the radius which are noticeable as the prim size
1073 // increases and it may affect megaprims quite a bit. The effect of the Y top shear parameter on
1074 // the meshes generated with this technique appear nearly identical in shape to the same prims when
1075 // displayed by the viewer.
1076
1077 float startAngle = (twoPi * this.pathCutBegin * this.revolutions) - this.topShearY * 0.9f;
1078 float endAngle = (twoPi * this.pathCutEnd * this.revolutions) - this.topShearY * 0.9f;
1079 float stepSize = twoPi / this.stepsPerRevolution;
1080
1081 int step = (int)(startAngle / stepSize);
1082 float angle = startAngle;
1083
1084 bool done = false;
1085 while (!done) // loop through the length of the path and add the layers
1086 {
1087 PathNode newNode = new PathNode();
1088
1089 float xProfileScale = (1.0f - Math.Abs(this.skew)) * this.holeSizeX;
1090 float yProfileScale = this.holeSizeY;
1091
1092 float percentOfPath = angle / (twoPi * this.revolutions);
1093 float percentOfAngles = (angle - startAngle) / (endAngle - startAngle);
1094
1095 if (this.taperX > 0.01f)
1096 xProfileScale *= 1.0f - percentOfPath * this.taperX;
1097 else if (this.taperX < -0.01f)
1098 xProfileScale *= 1.0f + (1.0f - percentOfPath) * this.taperX;
1099
1100 if (this.taperY > 0.01f)
1101 yProfileScale *= 1.0f - percentOfPath * this.taperY;
1102 else if (this.taperY < -0.01f)
1103 yProfileScale *= 1.0f + (1.0f - percentOfPath) * this.taperY;
1104
1105 newNode.xScale = xProfileScale;
1106 newNode.yScale = yProfileScale;
1107
1108 float radiusScale = 1.0f;
1109 if (this.radius > 0.001f)
1110 radiusScale = 1.0f - this.radius * percentOfPath;
1111 else if (this.radius < 0.001f)
1112 radiusScale = 1.0f + this.radius * (1.0f - percentOfPath);
1113
1114 float twist = twistBegin + twistTotal * percentOfPath;
1115
1116 float xOffset = 0.5f * (skewStart + totalSkew * percentOfAngles);
1117 xOffset += (float)Math.Sin(angle) * xOffsetTopShearXFactor;
1118
1119 float yOffset = yShearCompensation * (float)Math.Cos(angle) * (0.5f - yPathScale) * radiusScale;
1120
1121 float zOffset = (float)Math.Sin(angle + this.topShearY) * (0.5f - yPathScale) * radiusScale;
1122
1123 newNode.position = new Coord(xOffset, yOffset, zOffset);
1124
1125 // now orient the rotation of the profile layer relative to it's position on the path
1126 // adding taperY to the angle used to generate the quat appears to approximate the viewer
1127
1128 newNode.rotation = new Quat(new Coord(1.0f, 0.0f, 0.0f), angle + this.topShearY);
1129
1130 // next apply twist rotation to the profile layer
1131 if (twistTotal != 0.0f || twistBegin != 0.0f)
1132 newNode.rotation *= new Quat(new Coord(0.0f, 0.0f, 1.0f), twist);
1133
1134 newNode.percentOfPath = percentOfPath;
1135
1136 pathNodes.Add(newNode);
1137
1138 // calculate terms for next iteration
1139 // calculate the angle for the next iteration of the loop
1140
1141 if (angle >= endAngle - 0.01)
1142 done = true;
1143 else
1144 {
1145 step += 1;
1146 angle = stepSize * step;
1147 if (angle > endAngle)
1148 angle = endAngle;
1149 }
1150 }
1151 }
1152 }
1153 }
1154
1155 public class PrimMesh
1156 {
1157 public string errorMessage = "";
1158 private const float twoPi = 2.0f * (float)Math.PI;
1159
1160 public List<Coord> coords;
1161// public List<Coord> normals;
1162 public List<Face> faces;
1163
1164 private int sides = 4;
1165 private int hollowSides = 4;
1166 private float profileStart = 0.0f;
1167 private float profileEnd = 1.0f;
1168 private float hollow = 0.0f;
1169 public int twistBegin = 0;
1170 public int twistEnd = 0;
1171 public float topShearX = 0.0f;
1172 public float topShearY = 0.0f;
1173 public float pathCutBegin = 0.0f;
1174 public float pathCutEnd = 1.0f;
1175 public float dimpleBegin = 0.0f;
1176 public float dimpleEnd = 1.0f;
1177 public float skew = 0.0f;
1178 public float holeSizeX = 1.0f; // called pathScaleX in pbs
1179 public float holeSizeY = 0.25f;
1180 public float taperX = 0.0f;
1181 public float taperY = 0.0f;
1182 public float radius = 0.0f;
1183 public float revolutions = 1.0f;
1184 public int stepsPerRevolution = 24;
1185
1186 private bool hasProfileCut = false;
1187 private bool hasHollow = false;
1188
1189 public int numPrimFaces = 0;
1190
1191 /// <summary>
1192 /// Human readable string representation of the parameters used to create a mesh.
1193 /// </summary>
1194 /// <returns></returns>
1195 public string ParamsToDisplayString()
1196 {
1197 string s = "";
1198 s += "sides..................: " + this.sides.ToString();
1199 s += "\nhollowSides..........: " + this.hollowSides.ToString();
1200 s += "\nprofileStart.........: " + this.profileStart.ToString();
1201 s += "\nprofileEnd...........: " + this.profileEnd.ToString();
1202 s += "\nhollow...............: " + this.hollow.ToString();
1203 s += "\ntwistBegin...........: " + this.twistBegin.ToString();
1204 s += "\ntwistEnd.............: " + this.twistEnd.ToString();
1205 s += "\ntopShearX............: " + this.topShearX.ToString();
1206 s += "\ntopShearY............: " + this.topShearY.ToString();
1207 s += "\npathCutBegin.........: " + this.pathCutBegin.ToString();
1208 s += "\npathCutEnd...........: " + this.pathCutEnd.ToString();
1209 s += "\ndimpleBegin..........: " + this.dimpleBegin.ToString();
1210 s += "\ndimpleEnd............: " + this.dimpleEnd.ToString();
1211 s += "\nskew.................: " + this.skew.ToString();
1212 s += "\nholeSizeX............: " + this.holeSizeX.ToString();
1213 s += "\nholeSizeY............: " + this.holeSizeY.ToString();
1214 s += "\ntaperX...............: " + this.taperX.ToString();
1215 s += "\ntaperY...............: " + this.taperY.ToString();
1216 s += "\nradius...............: " + this.radius.ToString();
1217 s += "\nrevolutions..........: " + this.revolutions.ToString();
1218 s += "\nstepsPerRevolution...: " + this.stepsPerRevolution.ToString();
1219 s += "\nhasProfileCut........: " + this.hasProfileCut.ToString();
1220 s += "\nhasHollow............: " + this.hasHollow.ToString();
1221
1222 return s;
1223 }
1224
1225 public bool HasProfileCut
1226 {
1227 get { return hasProfileCut; }
1228 set { hasProfileCut = value; }
1229 }
1230
1231 public bool HasHollow
1232 {
1233 get { return hasHollow; }
1234 }
1235
1236
1237 /// <summary>
1238 /// Constructs a PrimMesh object and creates the profile for extrusion.
1239 /// </summary>
1240 /// <param name="sides"></param>
1241 /// <param name="profileStart"></param>
1242 /// <param name="profileEnd"></param>
1243 /// <param name="hollow"></param>
1244 /// <param name="hollowSides"></param>
1245 /// <param name="sphereMode"></param>
1246 public PrimMesh(int sides, float profileStart, float profileEnd, float hollow, int hollowSides)
1247 {
1248 this.coords = new List<Coord>();
1249 this.faces = new List<Face>();
1250
1251 this.sides = sides;
1252 this.profileStart = profileStart;
1253 this.profileEnd = profileEnd;
1254 this.hollow = hollow;
1255 this.hollowSides = hollowSides;
1256
1257 if (sides < 3)
1258 this.sides = 3;
1259 if (hollowSides < 3)
1260 this.hollowSides = 3;
1261 if (profileStart < 0.0f)
1262 this.profileStart = 0.0f;
1263 if (profileEnd > 1.0f)
1264 this.profileEnd = 1.0f;
1265 if (profileEnd < 0.02f)
1266 this.profileEnd = 0.02f;
1267 if (profileStart >= profileEnd)
1268 this.profileStart = profileEnd - 0.02f;
1269 if (hollow > 0.99f)
1270 this.hollow = 0.99f;
1271 if (hollow < 0.0f)
1272 this.hollow = 0.0f;
1273 }
1274
1275 /// <summary>
1276 /// Extrudes a profile along a path.
1277 /// </summary>
1278 public void Extrude(PathType pathType)
1279 {
1280 bool needEndFaces = false;
1281
1282 this.coords = new List<Coord>();
1283 this.faces = new List<Face>();
1284
1285 int steps = 1;
1286
1287 float length = this.pathCutEnd - this.pathCutBegin;
1288
1289 this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f;
1290
1291 this.hasHollow = (this.hollow > 0.001f);
1292
1293 float twistBegin = this.twistBegin / 360.0f * twoPi;
1294 float twistEnd = this.twistEnd / 360.0f * twoPi;
1295 float twistTotal = twistEnd - twistBegin;
1296 float twistTotalAbs = Math.Abs(twistTotal);
1297 if (twistTotalAbs > 0.01f)
1298 steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number
1299
1300 float hollow = this.hollow;
1301
1302 if (pathType == PathType.Circular)
1303 {
1304 needEndFaces = false;
1305 if (this.pathCutBegin != 0.0f || this.pathCutEnd != 1.0f)
1306 needEndFaces = true;
1307 else if (this.taperX != 0.0f || this.taperY != 0.0f)
1308 needEndFaces = true;
1309 else if (this.skew != 0.0f)
1310 needEndFaces = true;
1311 else if (twistTotal != 0.0f)
1312 needEndFaces = true;
1313 else if (this.radius != 0.0f)
1314 needEndFaces = true;
1315 }
1316 else needEndFaces = true;
1317
1318 // sanity checks
1319 float initialProfileRot = 0.0f;
1320 if (pathType == PathType.Circular)
1321 {
1322 if (this.sides == 3)
1323 {
1324 initialProfileRot = (float)Math.PI;
1325 if (this.hollowSides == 4)
1326 {
1327 if (hollow > 0.7f)
1328 hollow = 0.7f;
1329 hollow *= 0.707f;
1330 }
1331 else hollow *= 0.5f;
1332 }
1333 else if (this.sides == 4)
1334 {
1335 initialProfileRot = 0.25f * (float)Math.PI;
1336 if (this.hollowSides != 4)
1337 hollow *= 0.707f;
1338 }
1339 else if (this.sides > 4)
1340 {
1341 initialProfileRot = (float)Math.PI;
1342 if (this.hollowSides == 4)
1343 {
1344 if (hollow > 0.7f)
1345 hollow = 0.7f;
1346 hollow /= 0.7f;
1347 }
1348 }
1349 }
1350 else
1351 {
1352 if (this.sides == 3)
1353 {
1354 if (this.hollowSides == 4)
1355 {
1356 if (hollow > 0.7f)
1357 hollow = 0.7f;
1358 hollow *= 0.707f;
1359 }
1360 else hollow *= 0.5f;
1361 }
1362 else if (this.sides == 4)
1363 {
1364 initialProfileRot = 1.25f * (float)Math.PI;
1365 if (this.hollowSides != 4)
1366 hollow *= 0.707f;
1367 }
1368 else if (this.sides == 24 && this.hollowSides == 4)
1369 hollow *= 1.414f;
1370 }
1371
1372 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, this.hasProfileCut,true);
1373 this.errorMessage = profile.errorMessage;
1374
1375 this.numPrimFaces = profile.numPrimFaces;
1376
1377 if (initialProfileRot != 0.0f)
1378 {
1379 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot));
1380 }
1381
1382 float thisV = 0.0f;
1383 float lastV = 0.0f;
1384
1385 Path path = new Path();
1386 path.twistBegin = twistBegin;
1387 path.twistEnd = twistEnd;
1388 path.topShearX = topShearX;
1389 path.topShearY = topShearY;
1390 path.pathCutBegin = pathCutBegin;
1391 path.pathCutEnd = pathCutEnd;
1392 path.dimpleBegin = dimpleBegin;
1393 path.dimpleEnd = dimpleEnd;
1394 path.skew = skew;
1395 path.holeSizeX = holeSizeX;
1396 path.holeSizeY = holeSizeY;
1397 path.taperX = taperX;
1398 path.taperY = taperY;
1399 path.radius = radius;
1400 path.revolutions = revolutions;
1401 path.stepsPerRevolution = stepsPerRevolution;
1402
1403 path.Create(pathType, steps);
1404
1405 int lastNode = path.pathNodes.Count -1;
1406
1407 for (int nodeIndex = 0; nodeIndex < path.pathNodes.Count; nodeIndex++)
1408 {
1409 PathNode node = path.pathNodes[nodeIndex];
1410 Profile newLayer = profile.Copy();
1411
1412 newLayer.Scale(node.xScale, node.yScale);
1413 newLayer.AddRot(node.rotation);
1414 newLayer.AddPos(node.position);
1415
1416 if (needEndFaces && nodeIndex == 0)
1417 {
1418 newLayer.FlipNormals();
1419 } // if (nodeIndex == 0)
1420
1421 // append this layer
1422
1423 int coordsLen = this.coords.Count;
1424 newLayer.AddValue2FaceVertexIndices(coordsLen);
1425
1426 this.coords.AddRange(newLayer.coords);
1427
1428 if (needEndFaces)
1429 {
1430 if (nodeIndex == 0)
1431 this.faces.AddRange(newLayer.faces);
1432 else if (nodeIndex == lastNode)
1433 {
1434 if (node.xScale > 1e-6 && node.yScale > 1e-6)
1435 this.faces.AddRange(newLayer.faces);
1436 }
1437 }
1438
1439 // fill faces between layers
1440
1441 int numVerts = newLayer.coords.Count;
1442 Face newFace1 = new Face();
1443 Face newFace2 = new Face();
1444
1445 thisV = 1.0f - node.percentOfPath;
1446
1447 if (nodeIndex > 0)
1448 {
1449 int startVert = coordsLen;
1450 int endVert = this.coords.Count;
1451 if (!this.hasProfileCut)
1452 {
1453 int i = startVert;
1454 for (int l = 0; l < profile.numOuterVerts - 1; l++)
1455 {
1456 newFace1.v1 = i;
1457 newFace1.v2 = i - numVerts;
1458 newFace1.v3 = i + 1;
1459 this.faces.Add(newFace1);
1460
1461 newFace2.v1 = i + 1;
1462 newFace2.v2 = i - numVerts;
1463 newFace2.v3 = i + 1 - numVerts;
1464 this.faces.Add(newFace2);
1465 i++;
1466 }
1467
1468 newFace1.v1 = i;
1469 newFace1.v2 = i - numVerts;
1470 newFace1.v3 = startVert;
1471 this.faces.Add(newFace1);
1472
1473 newFace2.v1 = startVert;
1474 newFace2.v2 = i - numVerts;
1475 newFace2.v3 = startVert - numVerts;
1476 this.faces.Add(newFace2);
1477
1478 if (this.hasHollow)
1479 {
1480 startVert = ++i;
1481 for (int l = 0; l < profile.numHollowVerts - 1; l++)
1482 {
1483 newFace1.v1 = i;
1484 newFace1.v2 = i - numVerts;
1485 newFace1.v3 = i + 1;
1486 this.faces.Add(newFace1);
1487
1488 newFace2.v1 = i + 1;
1489 newFace2.v2 = i - numVerts;
1490 newFace2.v3 = i + 1 - numVerts;
1491 this.faces.Add(newFace2);
1492 i++;
1493 }
1494
1495 newFace1.v1 = i;
1496 newFace1.v2 = i - numVerts;
1497 newFace1.v3 = startVert;
1498 this.faces.Add(newFace1);
1499
1500 newFace2.v1 = startVert;
1501 newFace2.v2 = i - numVerts;
1502 newFace2.v3 = startVert - numVerts;
1503 this.faces.Add(newFace2);
1504 }
1505
1506
1507 }
1508 else
1509 {
1510 for (int i = startVert; i < endVert; i++)
1511 {
1512 int iNext = i + 1;
1513 if (i == endVert - 1)
1514 iNext = startVert;
1515
1516 newFace1.v1 = i;
1517 newFace1.v2 = i - numVerts;
1518 newFace1.v3 = iNext;
1519 this.faces.Add(newFace1);
1520
1521 newFace2.v1 = iNext;
1522 newFace2.v2 = i - numVerts;
1523 newFace2.v3 = iNext - numVerts;
1524 this.faces.Add(newFace2);
1525
1526 }
1527 }
1528 }
1529
1530 lastV = thisV;
1531
1532 } // for (int nodeIndex = 0; nodeIndex < path.pathNodes.Count; nodeIndex++)
1533
1534 }
1535
1536
1537 /// <summary>
1538 /// DEPRICATED - use Extrude(PathType.Linear) instead
1539 /// Extrudes a profile along a straight line path. Used for prim types box, cylinder, and prism.
1540 /// </summary>
1541 ///
1542 public void ExtrudeLinear()
1543 {
1544 this.Extrude(PathType.Linear);
1545 }
1546
1547
1548 /// <summary>
1549 /// DEPRICATED - use Extrude(PathType.Circular) instead
1550 /// Extrude a profile into a circular path prim mesh. Used for prim types torus, tube, and ring.
1551 /// </summary>
1552 ///
1553 public void ExtrudeCircular()
1554 {
1555 this.Extrude(PathType.Circular);
1556 }
1557
1558
1559 private Coord SurfaceNormal(Coord c1, Coord c2, Coord c3)
1560 {
1561 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z);
1562 Coord edge2 = new Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z);
1563
1564 Coord normal = Coord.Cross(edge1, edge2);
1565
1566 normal.Normalize();
1567
1568 return normal;
1569 }
1570
1571 private Coord SurfaceNormal(Face face)
1572 {
1573 return SurfaceNormal(this.coords[face.v1], this.coords[face.v2], this.coords[face.v3]);
1574 }
1575
1576 /// <summary>
1577 /// Calculate the surface normal for a face in the list of faces
1578 /// </summary>
1579 /// <param name="faceIndex"></param>
1580 /// <returns></returns>
1581 public Coord SurfaceNormal(int faceIndex)
1582 {
1583 int numFaces = this.faces.Count;
1584 if (faceIndex < 0 || faceIndex >= numFaces)
1585 throw new Exception("faceIndex out of range");
1586
1587 return SurfaceNormal(this.faces[faceIndex]);
1588 }
1589
1590 /// <summary>
1591 /// Duplicates a PrimMesh object. All object properties are copied by value, including lists.
1592 /// </summary>
1593 /// <returns></returns>
1594 public PrimMesh Copy()
1595 {
1596 PrimMesh copy = new PrimMesh(this.sides, this.profileStart, this.profileEnd, this.hollow, this.hollowSides);
1597 copy.twistBegin = this.twistBegin;
1598 copy.twistEnd = this.twistEnd;
1599 copy.topShearX = this.topShearX;
1600 copy.topShearY = this.topShearY;
1601 copy.pathCutBegin = this.pathCutBegin;
1602 copy.pathCutEnd = this.pathCutEnd;
1603 copy.dimpleBegin = this.dimpleBegin;
1604 copy.dimpleEnd = this.dimpleEnd;
1605 copy.skew = this.skew;
1606 copy.holeSizeX = this.holeSizeX;
1607 copy.holeSizeY = this.holeSizeY;
1608 copy.taperX = this.taperX;
1609 copy.taperY = this.taperY;
1610 copy.radius = this.radius;
1611 copy.revolutions = this.revolutions;
1612 copy.stepsPerRevolution = this.stepsPerRevolution;
1613
1614 copy.numPrimFaces = this.numPrimFaces;
1615 copy.errorMessage = this.errorMessage;
1616
1617 copy.coords = new List<Coord>(this.coords);
1618 copy.faces = new List<Face>(this.faces);
1619
1620 return copy;
1621 }
1622
1623 /// <summary>
1624 /// Adds a value to each XYZ vertex coordinate in the mesh
1625 /// </summary>
1626 /// <param name="x"></param>
1627 /// <param name="y"></param>
1628 /// <param name="z"></param>
1629 public void AddPos(float x, float y, float z)
1630 {
1631 int i;
1632 int numVerts = this.coords.Count;
1633 Coord vert;
1634
1635 for (i = 0; i < numVerts; i++)
1636 {
1637 vert = this.coords[i];
1638 vert.X += x;
1639 vert.Y += y;
1640 vert.Z += z;
1641 this.coords[i] = vert;
1642 }
1643 }
1644
1645 /// <summary>
1646 /// Rotates the mesh
1647 /// </summary>
1648 /// <param name="q"></param>
1649 public void AddRot(Quat q)
1650 {
1651 int i;
1652 int numVerts = this.coords.Count;
1653
1654 for (i = 0; i < numVerts; i++)
1655 this.coords[i] *= q;
1656 }
1657
1658#if VERTEX_INDEXER
1659 public VertexIndexer GetVertexIndexer()
1660 {
1661 return null;
1662 }
1663#endif
1664
1665 /// <summary>
1666 /// Scales the mesh
1667 /// </summary>
1668 /// <param name="x"></param>
1669 /// <param name="y"></param>
1670 /// <param name="z"></param>
1671 public void Scale(float x, float y, float z)
1672 {
1673 int i;
1674 int numVerts = this.coords.Count;
1675 //Coord vert;
1676
1677 Coord m = new Coord(x, y, z);
1678 for (i = 0; i < numVerts; i++)
1679 this.coords[i] *= m;
1680 }
1681
1682 /// <summary>
1683 /// Dumps the mesh to a Blender compatible "Raw" format file
1684 /// </summary>
1685 /// <param name="path"></param>
1686 /// <param name="name"></param>
1687 /// <param name="title"></param>
1688 public void DumpRaw(String path, String name, String title)
1689 {
1690 if (path == null)
1691 return;
1692 String fileName = name + "_" + title + ".raw";
1693 String completePath = System.IO.Path.Combine(path, fileName);
1694 StreamWriter sw = new StreamWriter(completePath);
1695
1696 for (int i = 0; i < this.faces.Count; i++)
1697 {
1698 string s = this.coords[this.faces[i].v1].ToString();
1699 s += " " + this.coords[this.faces[i].v2].ToString();
1700 s += " " + this.coords[this.faces[i].v3].ToString();
1701
1702 sw.WriteLine(s);
1703 }
1704
1705 sw.Close();
1706 }
1707 }
1708}
diff --git a/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
new file mode 100644
index 0000000..1c75db6
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
@@ -0,0 +1,244 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32using System.Drawing;
33using System.Drawing.Imaging;
34
35namespace PrimMesher
36{
37 public class SculptMap
38 {
39 public int width;
40 public int height;
41 public byte[] redBytes;
42 public byte[] greenBytes;
43 public byte[] blueBytes;
44
45 public SculptMap()
46 {
47 }
48
49 public SculptMap(Bitmap bm, int lod)
50 {
51 int bmW = bm.Width;
52 int bmH = bm.Height;
53
54 if (bmW == 0 || bmH == 0)
55 throw new Exception("SculptMap: bitmap has no data");
56
57 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
58
59 bool needsScaling = false;
60 bool smallMap = false;
61
62 width = bmW;
63 height = bmH;
64
65 while (width * height > numLodPixels * 4)
66 {
67 width >>= 1;
68 height >>= 1;
69 needsScaling = true;
70 }
71
72 try
73 {
74 if (needsScaling)
75 bm = ScaleImage(bm, width, height);
76 }
77
78 catch (Exception e)
79 {
80 throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
81 }
82
83 if (width * height > numLodPixels)
84 {
85 smallMap = false;
86 width >>= 1;
87 height >>= 1;
88 }
89 else
90 smallMap = true;
91
92 int numBytes = (width + 1) * (height + 1);
93 redBytes = new byte[numBytes];
94 greenBytes = new byte[numBytes];
95 blueBytes = new byte[numBytes];
96
97 int byteNdx = 0;
98 Color c;
99
100 try
101 {
102 for (int y = 0; y <= height; y++)
103 {
104 for (int x = 0; x < width; x++)
105 {
106 if (smallMap)
107 c = bm.GetPixel(x, y < height ? y : y - 1);
108 else
109 c = bm.GetPixel(x * 2, y < height ? y * 2 : y * 2 - 1);
110
111 redBytes[byteNdx] = c.R;
112 greenBytes[byteNdx] = c.G;
113 blueBytes[byteNdx] = c.B;
114
115 ++byteNdx;
116 }
117
118 if (smallMap)
119 c = bm.GetPixel(width - 1, y < height ? y : y - 1);
120 else
121 c = bm.GetPixel(width * 2 - 1, y < height ? y * 2 : y * 2 - 1);
122
123 redBytes[byteNdx] = c.R;
124 greenBytes[byteNdx] = c.G;
125 blueBytes[byteNdx] = c.B;
126
127 ++byteNdx;
128 }
129 }
130 catch (Exception e)
131 {
132 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
133 }
134
135 width++;
136 height++;
137 }
138
139 public List<List<Coord>> ToRows(bool mirror)
140 {
141 int numRows = height;
142 int numCols = width;
143
144 List<List<Coord>> rows = new List<List<Coord>>(numRows);
145
146 float pixScale = 1.0f / 255;
147
148 int rowNdx, colNdx;
149 int smNdx = 0;
150
151 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
152 {
153 List<Coord> row = new List<Coord>(numCols);
154 for (colNdx = 0; colNdx < numCols; colNdx++)
155 {
156
157 if (mirror)
158 row.Add(new Coord(-((float)redBytes[smNdx] * pixScale - 0.5f), ((float)greenBytes[smNdx] * pixScale - 0.5f), (float)blueBytes[smNdx] * pixScale - 0.5f));
159 else
160 row.Add(new Coord((float)redBytes[smNdx] * pixScale - 0.5f, (float)greenBytes[smNdx] * pixScale - 0.5f, (float)blueBytes[smNdx] * pixScale - 0.5f));
161
162 ++smNdx;
163 }
164 rows.Add(row);
165 }
166 return rows;
167 }
168
169 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight)
170 {
171
172 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
173
174 Color c;
175
176
177 // will let last step to be eventually diferent, as seems to be in sl
178
179 float xscale = (float)srcImage.Width / (float)destWidth;
180 float yscale = (float)srcImage.Height / (float)destHeight;
181
182 int lastsx = srcImage.Width - 1;
183 int lastsy = srcImage.Height - 1;
184 int lastdx = destWidth - 1;
185 int lastdy = destHeight - 1;
186
187 float sy = 0.5f;
188 float sx;
189
190 for (int y = 0; y < lastdy; y++)
191 {
192 sx = 0.5f;
193 for (int x = 0; x < lastdx; x++)
194 {
195 try
196 {
197 c = srcImage.GetPixel((int)(sx), (int)(sy));
198 scaledImage.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B));
199 }
200 catch (IndexOutOfRangeException)
201 {
202 }
203 sx += xscale;
204 }
205 try
206 {
207 c = srcImage.GetPixel(lastsx, (int)(sy));
208 scaledImage.SetPixel(lastdx, y, Color.FromArgb(c.R, c.G, c.B));
209 }
210 catch (IndexOutOfRangeException)
211 {
212 }
213
214 sy += yscale;
215 }
216
217 sx = 0.5f;
218 for (int x = 0; x < lastdx; x++)
219 {
220 try
221 {
222 c = srcImage.GetPixel((int)(sx), lastsy);
223 scaledImage.SetPixel(x, lastdy, Color.FromArgb(c.R, c.G, c.B));
224 }
225 catch (IndexOutOfRangeException)
226 {
227 }
228
229 sx += xscale;
230 }
231 try
232 {
233 c = srcImage.GetPixel(lastsx, lastsy);
234 scaledImage.SetPixel(lastdx, lastdy, Color.FromArgb(c.R, c.G, c.B));
235 }
236 catch (IndexOutOfRangeException)
237 {
238 }
239
240 srcImage.Dispose();
241 return scaledImage;
242 }
243 }
244} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs b/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs
new file mode 100644
index 0000000..bc1375b
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs
@@ -0,0 +1,220 @@
1/*
2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.IO;
32
33using System.Drawing;
34using System.Drawing.Imaging;
35
36namespace PrimMesher
37{
38
39 public class SculptMesh
40 {
41 public List<Coord> coords;
42 public List<Face> faces;
43
44 public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 };
45
46
47 public SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool mirror, bool invert)
48 {
49 if (mirror)
50 invert = !invert;
51
52 SculptMap smap = new SculptMap(sculptBitmap, lod);
53
54 List<List<Coord>> rows = smap.ToRows(mirror);
55
56 _SculptMesh(rows, sculptType, invert);
57 }
58
59 private void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool invert)
60 {
61 coords = new List<Coord>();
62 faces = new List<Face>();
63
64 sculptType = (SculptType)(((int)sculptType) & 0x07);
65
66 int width = rows[0].Count;
67
68 int p1, p2, p3, p4;
69
70 int imageX, imageY;
71
72 if (sculptType != SculptType.plane)
73 {
74 if (rows.Count % 2 == 0)
75 {
76 for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++)
77 rows[rowNdx].Add(rows[rowNdx][0]);
78 }
79 else
80 {
81 int lastIndex = rows[0].Count - 1;
82
83 for (int i = 0; i < rows.Count; i++)
84 rows[i][0] = rows[i][lastIndex];
85 }
86 }
87
88 Coord topPole = rows[0][width / 2];
89 Coord bottomPole = rows[rows.Count - 1][width / 2];
90
91 if (sculptType == SculptType.sphere)
92 {
93 if (rows.Count % 2 == 0)
94 {
95 int count = rows[0].Count;
96 List<Coord> topPoleRow = new List<Coord>(count);
97 List<Coord> bottomPoleRow = new List<Coord>(count);
98
99 for (int i = 0; i < count; i++)
100 {
101 topPoleRow.Add(topPole);
102 bottomPoleRow.Add(bottomPole);
103 }
104 rows.Insert(0, topPoleRow);
105 rows.Add(bottomPoleRow);
106 }
107 else
108 {
109 int count = rows[0].Count;
110
111 List<Coord> topPoleRow = rows[0];
112 List<Coord> bottomPoleRow = rows[rows.Count - 1];
113
114 for (int i = 0; i < count; i++)
115 {
116 topPoleRow[i] = topPole;
117 bottomPoleRow[i] = bottomPole;
118 }
119 }
120 }
121
122 if (sculptType == SculptType.torus)
123 rows.Add(rows[0]);
124
125 int coordsDown = rows.Count;
126 int coordsAcross = rows[0].Count;
127
128 float widthUnit = 1.0f / (coordsAcross - 1);
129 float heightUnit = 1.0f / (coordsDown - 1);
130
131 for (imageY = 0; imageY < coordsDown; imageY++)
132 {
133 int rowOffset = imageY * coordsAcross;
134
135 for (imageX = 0; imageX < coordsAcross; imageX++)
136 {
137 /*
138 * p1-----p2
139 * | \ f2 |
140 * | \ |
141 * | f1 \|
142 * p3-----p4
143 */
144
145 p4 = rowOffset + imageX;
146 p3 = p4 - 1;
147
148 p2 = p4 - coordsAcross;
149 p1 = p3 - coordsAcross;
150
151 this.coords.Add(rows[imageY][imageX]);
152
153 if (imageY > 0 && imageX > 0)
154 {
155 Face f1, f2;
156
157 if (invert)
158 {
159 f1 = new Face(p1, p4, p3);
160 f2 = new Face(p1, p2, p4);
161 }
162 else
163 {
164 f1 = new Face(p1, p3, p4);
165 f2 = new Face(p1, p4, p2);
166 }
167
168 this.faces.Add(f1);
169 this.faces.Add(f2);
170 }
171 }
172 }
173 }
174
175 /// <summary>
176 /// Duplicates a SculptMesh object. All object properties are copied by value, including lists.
177 /// </summary>
178 /// <returns></returns>
179 public SculptMesh Copy()
180 {
181 return new SculptMesh(this);
182 }
183
184 public SculptMesh(SculptMesh sm)
185 {
186 coords = new List<Coord>(sm.coords);
187 faces = new List<Face>(sm.faces);
188 }
189
190 public void Scale(float x, float y, float z)
191 {
192 int i;
193 int numVerts = this.coords.Count;
194
195 Coord m = new Coord(x, y, z);
196 for (i = 0; i < numVerts; i++)
197 this.coords[i] *= m;
198 }
199
200 public void DumpRaw(String path, String name, String title)
201 {
202 if (path == null)
203 return;
204 String fileName = name + "_" + title + ".raw";
205 String completePath = System.IO.Path.Combine(path, fileName);
206 StreamWriter sw = new StreamWriter(completePath);
207
208 for (int i = 0; i < this.faces.Count; i++)
209 {
210 string s = this.coords[this.faces[i].v1].ToString();
211 s += " " + this.coords[this.faces[i].v2].ToString();
212 s += " " + this.coords[this.faces[i].v3].ToString();
213
214 sw.WriteLine(s);
215 }
216
217 sw.Close();
218 }
219 }
220}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs
new file mode 100644
index 0000000..d46341b
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs
@@ -0,0 +1,58 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Reflection;
29using System.Runtime.InteropServices;
30
31// Information about this assembly is defined by the following
32// attributes.
33//
34// change them to the information which is associated with the assembly
35// you compile.
36
37[assembly : AssemblyTitle("OdePlugin")]
38[assembly : AssemblyDescription("Ubit Variation")]
39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("OdePlugin")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")]
43[assembly : AssemblyTrademark("")]
44[assembly : AssemblyCulture("")]
45
46// This sets the default COM visibility of types in the assembly to invisible.
47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
48
49[assembly : ComVisible(false)]
50
51// The assembly version has following format :
52//
53// Major.Minor.Build.Revision
54//
55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default):
57
58[assembly : AssemblyVersion("0.6.5.*")]
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
new file mode 100644
index 0000000..1c38246
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
@@ -0,0 +1,1847 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29// Revision by Ubit 2011/12
30
31using System;
32using System.Collections.Generic;
33using System.Reflection;
34using OpenMetaverse;
35using OdeAPI;
36using OpenSim.Framework;
37using OpenSim.Region.Physics.Manager;
38using log4net;
39
40namespace OpenSim.Region.Physics.OdePlugin
41{
42 /// <summary>
43 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
44 /// </summary>
45
46 public enum dParam : int
47 {
48 LowStop = 0,
49 HiStop = 1,
50 Vel = 2,
51 FMax = 3,
52 FudgeFactor = 4,
53 Bounce = 5,
54 CFM = 6,
55 StopERP = 7,
56 StopCFM = 8,
57 LoStop2 = 256,
58 HiStop2 = 257,
59 Vel2 = 258,
60 FMax2 = 259,
61 StopERP2 = 7 + 256,
62 StopCFM2 = 8 + 256,
63 LoStop3 = 512,
64 HiStop3 = 513,
65 Vel3 = 514,
66 FMax3 = 515,
67 StopERP3 = 7 + 512,
68 StopCFM3 = 8 + 512
69 }
70
71 public class OdeCharacter : PhysicsActor
72 {
73 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74
75 private Vector3 _position;
76 private Vector3 _zeroPosition;
77 private Vector3 _velocity;
78 private Vector3 _target_velocity;
79 private Vector3 _acceleration;
80 private Vector3 m_rotationalVelocity;
81 private Vector3 m_size;
82 private Vector3 m_collideNormal;
83 private Quaternion m_orientation;
84 private Quaternion m_orientation2D;
85 private float m_mass = 80f;
86 public float m_density = 60f;
87 private bool m_pidControllerActive = true;
88
89 const float basePID_D = 0.55f; // scaled for unit mass unit time (2200 /(50*80))
90 const float basePID_P = 0.225f; // scaled for unit mass unit time (900 /(50*80))
91 public float PID_D;
92 public float PID_P;
93
94 private float timeStep;
95 private float invtimeStep;
96
97 private float m_feetOffset = 0;
98 private float feetOff = 0;
99 private float boneOff = 0;
100 private float AvaAvaSizeXsq = 0.3f;
101 private float AvaAvaSizeYsq = 0.2f;
102
103 public float walkDivisor = 1.3f;
104 public float runDivisor = 0.8f;
105 private bool flying = false;
106 private bool m_iscolliding = false;
107 private bool m_iscollidingGround = false;
108 private bool m_iscollidingObj = false;
109 private bool m_alwaysRun = false;
110
111 private bool _zeroFlag = false;
112
113
114 private uint m_localID = 0;
115 public bool m_returnCollisions = false;
116 // taints and their non-tainted counterparts
117 public bool m_isPhysical = false; // the current physical status
118 public float MinimumGroundFlightOffset = 3f;
119
120 private float m_buoyancy = 0f;
121
122 private bool m_freemove = false;
123 // private CollisionLocker ode;
124
125// private string m_name = String.Empty;
126 // other filter control
127 int m_colliderfilter = 0;
128 int m_colliderGroundfilter = 0;
129 int m_colliderObjectfilter = 0;
130
131 // Default we're a Character
132 private CollisionCategories m_collisionCategories = (CollisionCategories.Character);
133
134 // Default, Collide with Other Geometries, spaces, bodies and characters.
135 private CollisionCategories m_collisionFlags = (CollisionCategories.Character
136 | CollisionCategories.Geom
137 | CollisionCategories.VolumeDtc
138 );
139 // we do land collisions not ode | CollisionCategories.Land);
140 public IntPtr Body = IntPtr.Zero;
141 private OdeScene _parent_scene;
142 private IntPtr capsule = IntPtr.Zero;
143 public IntPtr collider = IntPtr.Zero;
144
145 public IntPtr Amotor = IntPtr.Zero;
146
147 public d.Mass ShellMass;
148
149 public int m_eventsubscription = 0;
150 private int m_cureventsubscription = 0;
151 private CollisionEventUpdate CollisionEventsThisFrame = null;
152 private bool SentEmptyCollisionsEvent;
153
154 // unique UUID of this character object
155 public UUID m_uuid;
156 public bool bad = false;
157
158 float mu;
159
160 public OdeCharacter(uint localID, String avName, OdeScene parent_scene, Vector3 pos, Vector3 pSize, float pfeetOffset, float density, float walk_divisor, float rundivisor)
161 {
162 m_uuid = UUID.Random();
163 m_localID = localID;
164
165 timeStep = parent_scene.ODE_STEPSIZE;
166 invtimeStep = 1 / timeStep;
167
168 if (pos.IsFinite())
169 {
170 if (pos.Z > 99999f)
171 {
172 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
173 }
174 if (pos.Z < -100f) // shouldn't this be 0 ?
175 {
176 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
177 }
178 _position = pos;
179 }
180 else
181 {
182 _position = new Vector3(((float)_parent_scene.WorldExtents.X * 0.5f), ((float)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f);
183 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
184 }
185
186 _parent_scene = parent_scene;
187
188
189 m_size.X = pSize.X;
190 m_size.Y = pSize.Y;
191 m_size.Z = pSize.Z;
192
193 if(m_size.X <0.01f)
194 m_size.X = 0.01f;
195 if(m_size.Y <0.01f)
196 m_size.Y = 0.01f;
197 if(m_size.Z <0.01f)
198 m_size.Z = 0.01f;
199
200 m_feetOffset = pfeetOffset;
201 m_orientation = Quaternion.Identity;
202 m_orientation2D = Quaternion.Identity;
203 m_density = density;
204
205 // force lower density for testing
206 m_density = 3.0f;
207
208 mu = parent_scene.AvatarFriction;
209
210 walkDivisor = walk_divisor;
211 runDivisor = rundivisor;
212
213 m_mass = m_density * m_size.X * m_size.Y * m_size.Z; ; // sure we have a default
214
215 PID_D = basePID_D * m_mass * invtimeStep;
216 PID_P = basePID_P * m_mass * invtimeStep;
217
218 m_isPhysical = false; // current status: no ODE information exists
219
220 Name = avName;
221
222 AddChange(changes.Add, null);
223 }
224
225 public override int PhysicsActorType
226 {
227 get { return (int)ActorTypes.Agent; }
228 set { return; }
229 }
230
231 public override void getContactData(ref ContactData cdata)
232 {
233 cdata.mu = mu;
234 cdata.bounce = 0;
235 cdata.softcolide = false;
236 }
237
238 public override bool Building { get; set; }
239
240 /// <summary>
241 /// If this is set, the avatar will move faster
242 /// </summary>
243 public override bool SetAlwaysRun
244 {
245 get { return m_alwaysRun; }
246 set { m_alwaysRun = value; }
247 }
248
249 public override uint LocalID
250 {
251 get { return m_localID; }
252 set { m_localID = value; }
253 }
254
255 public override PhysicsActor ParentActor
256 {
257 get { return (PhysicsActor)this; }
258 }
259
260 public override bool Grabbed
261 {
262 set { return; }
263 }
264
265 public override bool Selected
266 {
267 set { return; }
268 }
269
270 public override float Buoyancy
271 {
272 get { return m_buoyancy; }
273 set { m_buoyancy = value; }
274 }
275
276 public override bool FloatOnWater
277 {
278 set { return; }
279 }
280
281 public override bool IsPhysical
282 {
283 get { return m_isPhysical; }
284 set { return; }
285 }
286
287 public override bool ThrottleUpdates
288 {
289 get { return false; }
290 set { return; }
291 }
292
293 public override bool Flying
294 {
295 get { return flying; }
296 set
297 {
298 flying = value;
299// m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying);
300 }
301 }
302
303 /// <summary>
304 /// Returns if the avatar is colliding in general.
305 /// This includes the ground and objects and avatar.
306 /// </summary>
307 public override bool IsColliding
308 {
309 get { return (m_iscolliding || m_iscollidingGround); }
310 set
311 {
312 if (value)
313 {
314 m_colliderfilter += 3;
315 if (m_colliderfilter > 3)
316 m_colliderfilter = 3;
317 }
318 else
319 {
320 m_colliderfilter--;
321 if (m_colliderfilter < 0)
322 m_colliderfilter = 0;
323 }
324
325 if (m_colliderfilter == 0)
326 m_iscolliding = false;
327 else
328 {
329 m_pidControllerActive = true;
330 m_iscolliding = true;
331 m_freemove = false;
332 }
333 }
334 }
335
336 /// <summary>
337 /// Returns if an avatar is colliding with the ground
338 /// </summary>
339 public override bool CollidingGround
340 {
341 get { return m_iscollidingGround; }
342 set
343 {
344/* we now control this
345 if (value)
346 {
347 m_colliderGroundfilter += 2;
348 if (m_colliderGroundfilter > 2)
349 m_colliderGroundfilter = 2;
350 }
351 else
352 {
353 m_colliderGroundfilter--;
354 if (m_colliderGroundfilter < 0)
355 m_colliderGroundfilter = 0;
356 }
357
358 if (m_colliderGroundfilter == 0)
359 m_iscollidingGround = false;
360 else
361 m_iscollidingGround = true;
362 */
363 }
364
365 }
366
367 /// <summary>
368 /// Returns if the avatar is colliding with an object
369 /// </summary>
370 public override bool CollidingObj
371 {
372 get { return m_iscollidingObj; }
373 set
374 {
375 // Ubit filter this also
376 if (value)
377 {
378 m_colliderObjectfilter += 2;
379 if (m_colliderObjectfilter > 2)
380 m_colliderObjectfilter = 2;
381 }
382 else
383 {
384 m_colliderObjectfilter--;
385 if (m_colliderObjectfilter < 0)
386 m_colliderObjectfilter = 0;
387 }
388
389 if (m_colliderObjectfilter == 0)
390 m_iscollidingObj = false;
391 else
392 m_iscollidingObj = true;
393
394// m_iscollidingObj = value;
395
396 if (m_iscollidingObj)
397 m_pidControllerActive = false;
398 else
399 m_pidControllerActive = true;
400 }
401 }
402
403 /// <summary>
404 /// turn the PID controller on or off.
405 /// The PID Controller will turn on all by itself in many situations
406 /// </summary>
407 /// <param name="status"></param>
408 public void SetPidStatus(bool status)
409 {
410 m_pidControllerActive = status;
411 }
412
413 public override bool Stopped
414 {
415 get { return _zeroFlag; }
416 }
417
418 /// <summary>
419 /// This 'puts' an avatar somewhere in the physics space.
420 /// Not really a good choice unless you 'know' it's a good
421 /// spot otherwise you're likely to orbit the avatar.
422 /// </summary>
423 public override Vector3 Position
424 {
425 get { return _position; }
426 set
427 {
428 if (value.IsFinite())
429 {
430 if (value.Z > 9999999f)
431 {
432 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
433 }
434 if (value.Z < -100f)
435 {
436 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
437 }
438 AddChange(changes.Position, value);
439 }
440 else
441 {
442 m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character");
443 }
444 }
445 }
446
447 public override Vector3 RotationalVelocity
448 {
449 get { return m_rotationalVelocity; }
450 set { m_rotationalVelocity = value; }
451 }
452
453 /// <summary>
454 /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
455 /// and use it to offset landings properly
456 /// </summary>
457 public override Vector3 Size
458 {
459 get
460 {
461 return m_size;
462 }
463 set
464 {
465 if (value.IsFinite())
466 {
467 if(value.X <0.01f)
468 value.X = 0.01f;
469 if(value.Y <0.01f)
470 value.Y = 0.01f;
471 if(value.Z <0.01f)
472 value.Z = 0.01f;
473
474 AddChange(changes.Size, value);
475 }
476 else
477 {
478 m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
479 }
480 }
481 }
482
483 public override void setAvatarSize(Vector3 size, float feetOffset)
484 {
485 if (size.IsFinite())
486 {
487 if (size.X < 0.01f)
488 size.X = 0.01f;
489 if (size.Y < 0.01f)
490 size.Y = 0.01f;
491 if (size.Z < 0.01f)
492 size.Z = 0.01f;
493
494 strAvatarSize st = new strAvatarSize();
495 st.size = size;
496 st.offset = feetOffset;
497 AddChange(changes.AvatarSize, st);
498 }
499 else
500 {
501 m_log.Warn("[PHYSICS]: Got a NaN AvatarSize from Scene on a Character");
502 }
503
504 }
505 /// <summary>
506 /// This creates the Avatar's physical Surrogate at the position supplied
507 /// </summary>
508 /// <param name="npositionX"></param>
509 /// <param name="npositionY"></param>
510 /// <param name="npositionZ"></param>
511
512 //
513 /// <summary>
514 /// Uses the capped cyllinder volume formula to calculate the avatar's mass.
515 /// This may be used in calculations in the scene/scenepresence
516 /// </summary>
517 public override float Mass
518 {
519 get
520 {
521 return m_mass;
522 }
523 }
524 public override void link(PhysicsActor obj)
525 {
526
527 }
528
529 public override void delink()
530 {
531
532 }
533
534 public override void LockAngularMotion(Vector3 axis)
535 {
536
537 }
538
539
540 public override Vector3 Force
541 {
542 get { return _target_velocity; }
543 set { return; }
544 }
545
546 public override int VehicleType
547 {
548 get { return 0; }
549 set { return; }
550 }
551
552 public override void VehicleFloatParam(int param, float value)
553 {
554
555 }
556
557 public override void VehicleVectorParam(int param, Vector3 value)
558 {
559
560 }
561
562 public override void VehicleRotationParam(int param, Quaternion rotation)
563 {
564
565 }
566
567 public override void VehicleFlags(int param, bool remove)
568 {
569
570 }
571
572 public override void SetVolumeDetect(int param)
573 {
574
575 }
576
577 public override Vector3 CenterOfMass
578 {
579 get
580 {
581 Vector3 pos = _position;
582 return pos;
583 }
584 }
585
586 public override Vector3 GeometricCenter
587 {
588 get
589 {
590 Vector3 pos = _position;
591 return pos;
592 }
593 }
594
595 public override PrimitiveBaseShape Shape
596 {
597 set { return; }
598 }
599
600 public override Vector3 Velocity
601 {
602 get
603 {
604 return _velocity;
605 }
606 set
607 {
608 if (value.IsFinite())
609 {
610 AddChange(changes.Velocity, value);
611 }
612 else
613 {
614 m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
615 }
616 }
617 }
618
619 public override Vector3 Torque
620 {
621 get { return Vector3.Zero; }
622 set { return; }
623 }
624
625 public override float CollisionScore
626 {
627 get { return 0f; }
628 set { }
629 }
630
631 public override bool Kinematic
632 {
633 get { return false; }
634 set { }
635 }
636
637 public override Quaternion Orientation
638 {
639 get { return m_orientation; }
640 set
641 {
642// fakeori = value;
643// givefakeori++;
644 value.Normalize();
645 AddChange(changes.Orientation, value);
646 }
647 }
648
649 public override Vector3 Acceleration
650 {
651 get { return _acceleration; }
652 set { }
653 }
654
655 public void SetAcceleration(Vector3 accel)
656 {
657 m_pidControllerActive = true;
658 _acceleration = accel;
659 }
660
661 /// <summary>
662 /// Adds the force supplied to the Target Velocity
663 /// The PID controller takes this target velocity and tries to make it a reality
664 /// </summary>
665 /// <param name="force"></param>
666 public override void AddForce(Vector3 force, bool pushforce)
667 {
668 if (force.IsFinite())
669 {
670 if (pushforce)
671 {
672 AddChange(changes.Force, force * m_density / (_parent_scene.ODE_STEPSIZE * 28f));
673 }
674 else
675 {
676 AddChange(changes.Velocity, force);
677 }
678 }
679 else
680 {
681 m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
682 }
683 //m_lastUpdateSent = false;
684 }
685
686 public override void AddAngularForce(Vector3 force, bool pushforce)
687 {
688
689 }
690
691 public override void SetMomentum(Vector3 momentum)
692 {
693 if (momentum.IsFinite())
694 AddChange(changes.Momentum, momentum);
695 }
696
697
698 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ)
699 {
700 // sizes one day should came from visual parameters
701 float sx = m_size.X;
702 float sy = m_size.Y;
703 float sz = m_size.Z;
704
705 float bot = -sz * 0.5f + m_feetOffset;
706 boneOff = bot + 0.3f;
707
708 float feetsz = sz * 0.45f;
709 if (feetsz > 0.6f)
710 feetsz = 0.6f;
711
712 feetOff = bot + feetsz;
713
714 AvaAvaSizeXsq = 0.4f * sx;
715 AvaAvaSizeXsq *= AvaAvaSizeXsq;
716 AvaAvaSizeYsq = 0.5f * sy;
717 AvaAvaSizeYsq *= AvaAvaSizeYsq;
718
719 _parent_scene.waitForSpaceUnlock(_parent_scene.CharsSpace);
720
721 collider = d.HashSpaceCreate(_parent_scene.CharsSpace);
722 d.HashSpaceSetLevels(collider, -4, 3);
723 d.SpaceSetSublevel(collider, 3);
724 d.SpaceSetCleanup(collider, false);
725 d.GeomSetCategoryBits(collider, (uint)m_collisionCategories);
726 d.GeomSetCollideBits(collider, (uint)m_collisionFlags);
727
728 float r = m_size.X;
729 if (m_size.Y > r)
730 r = m_size.Y;
731 float l = m_size.Z - r;
732 r *= 0.5f;
733
734 capsule = d.CreateCapsule(collider, r, l);
735
736 m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass
737
738 d.MassSetBoxTotal(out ShellMass, m_mass, m_size.X, m_size.Y, m_size.Z);
739
740 PID_D = basePID_D * m_mass / _parent_scene.ODE_STEPSIZE;
741 PID_P = basePID_P * m_mass / _parent_scene.ODE_STEPSIZE;
742
743 Body = d.BodyCreate(_parent_scene.world);
744
745 _zeroFlag = false;
746 m_pidControllerActive = true;
747 m_freemove = false;
748
749 _velocity = Vector3.Zero;
750
751 d.BodySetAutoDisableFlag(Body, false);
752 d.BodySetPosition(Body, npositionX, npositionY, npositionZ);
753
754 _position.X = npositionX;
755 _position.Y = npositionY;
756 _position.Z = npositionZ;
757
758 d.BodySetMass(Body, ref ShellMass);
759 d.GeomSetBody(capsule, Body);
760
761 // The purpose of the AMotor here is to keep the avatar's physical
762 // surrogate from rotating while moving
763 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
764 d.JointAttach(Amotor, Body, IntPtr.Zero);
765
766 d.JointSetAMotorMode(Amotor, 0);
767 d.JointSetAMotorNumAxes(Amotor, 3);
768 d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
769 d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
770 d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
771
772 d.JointSetAMotorAngle(Amotor, 0, 0);
773 d.JointSetAMotorAngle(Amotor, 1, 0);
774 d.JointSetAMotorAngle(Amotor, 2, 0);
775
776 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0f); // make it HARD
777 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0f);
778 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0f);
779 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f);
780 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f);
781 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f);
782
783 // These lowstops and high stops are effectively (no wiggle room)
784 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -1e-5f);
785 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 1e-5f);
786 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -1e-5f);
787 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 1e-5f);
788 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -1e-5f);
789 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 1e-5f);
790
791 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0);
792 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel2, 0);
793 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel3, 0);
794
795 d.JointSetAMotorParam(Amotor, (int)dParam.FMax, 5e8f);
796 d.JointSetAMotorParam(Amotor, (int)dParam.FMax2, 5e8f);
797 d.JointSetAMotorParam(Amotor, (int)dParam.FMax3, 5e8f);
798 }
799
800 /// <summary>
801 /// Destroys the avatar body and geom
802
803 private void AvatarGeomAndBodyDestroy()
804 {
805 // Kill the Amotor
806 if (Amotor != IntPtr.Zero)
807 {
808 d.JointDestroy(Amotor);
809 Amotor = IntPtr.Zero;
810 }
811
812 if (Body != IntPtr.Zero)
813 {
814 //kill the body
815 d.BodyDestroy(Body);
816 Body = IntPtr.Zero;
817 }
818
819 //kill the Geoms
820 if (capsule != IntPtr.Zero)
821 {
822 _parent_scene.actor_name_map.Remove(capsule);
823 _parent_scene.waitForSpaceUnlock(collider);
824 d.GeomDestroy(capsule);
825 capsule = IntPtr.Zero;
826 }
827
828 if (collider != IntPtr.Zero)
829 {
830 d.SpaceDestroy(collider);
831 collider = IntPtr.Zero;
832 }
833
834 }
835
836 //in place 2D rotation around Z assuming rot is normalised and is a rotation around Z
837 public void RotateXYonZ(ref float x, ref float y, ref Quaternion rot)
838 {
839 float sin = 2.0f * rot.Z * rot.W;
840 float cos = rot.W * rot.W - rot.Z * rot.Z;
841 float tx = x;
842
843 x = tx * cos - y * sin;
844 y = tx * sin + y * cos;
845 }
846 public void RotateXYonZ(ref float x, ref float y, ref float sin, ref float cos)
847 {
848 float tx = x;
849 x = tx * cos - y * sin;
850 y = tx * sin + y * cos;
851 }
852 public void invRotateXYonZ(ref float x, ref float y, ref float sin, ref float cos)
853 {
854 float tx = x;
855 x = tx * cos + y * sin;
856 y = -tx * sin + y * cos;
857 }
858
859 public void invRotateXYonZ(ref float x, ref float y, ref Quaternion rot)
860 {
861 float sin = - 2.0f * rot.Z * rot.W;
862 float cos = rot.W * rot.W - rot.Z * rot.Z;
863 float tx = x;
864
865 x = tx * cos - y * sin;
866 y = tx * sin + y * cos;
867 }
868
869 public bool Collide(IntPtr me, IntPtr other, bool reverse, ref d.ContactGeom contact,
870 ref d.ContactGeom altContact , ref bool useAltcontact, ref bool feetcollision)
871 {
872 feetcollision = false;
873 useAltcontact = false;
874
875 if (me == capsule)
876 {
877 Vector3 offset;
878
879 float h = contact.pos.Z - _position.Z;
880 offset.Z = h - feetOff;
881
882 offset.X = contact.pos.X - _position.X;
883 offset.Y = contact.pos.Y - _position.Y;
884
885 d.GeomClassID gtype = d.GeomGetClass(other);
886 if (gtype == d.GeomClassID.CapsuleClass)
887 {
888 Vector3 roff = offset * Quaternion.Inverse(m_orientation2D);
889 float r = roff.X *roff.X / AvaAvaSizeXsq;
890 r += (roff.Y * roff.Y) / AvaAvaSizeYsq;
891 if (r > 1.0f)
892 return false;
893
894 float dp = 1.0f -(float)Math.Sqrt((double)r);
895 if (dp > 0.05f)
896 dp = 0.05f;
897
898 contact.depth = dp;
899
900 if (offset.Z < 0)
901 {
902 feetcollision = true;
903 if (h < boneOff)
904 {
905 m_collideNormal.X = contact.normal.X;
906 m_collideNormal.Y = contact.normal.Y;
907 m_collideNormal.Z = contact.normal.Z;
908 IsColliding = true;
909 }
910 }
911 return true;
912 }
913/*
914 d.AABB aabb;
915 d.GeomGetAABB(other,out aabb);
916 float othertop = aabb.MaxZ - _position.Z;
917*/
918// if (offset.Z > 0 || othertop > -feetOff || contact.normal.Z > 0.35f)
919 if (offset.Z > 0 || contact.normal.Z > 0.35f)
920 {
921 if (offset.Z <= 0)
922 {
923 feetcollision = true;
924 if (h < boneOff)
925 {
926 m_collideNormal.X = contact.normal.X;
927 m_collideNormal.Y = contact.normal.Y;
928 m_collideNormal.Z = contact.normal.Z;
929 IsColliding = true;
930 }
931 }
932 return true;
933 }
934
935 altContact = contact;
936 useAltcontact = true;
937
938 offset.Z -= 0.2f;
939
940 offset.Normalize();
941
942 if (contact.depth > 0.1f)
943 contact.depth = 0.1f;
944
945 if (reverse)
946 {
947 altContact.normal.X = offset.X;
948 altContact.normal.Y = offset.Y;
949 altContact.normal.Z = offset.Z;
950 }
951 else
952 {
953 altContact.normal.X = -offset.X;
954 altContact.normal.Y = -offset.Y;
955 altContact.normal.Z = -offset.Z;
956 }
957
958 feetcollision = true;
959 if (h < boneOff)
960 {
961 m_collideNormal.X = contact.normal.X;
962 m_collideNormal.Y = contact.normal.Y;
963 m_collideNormal.Z = contact.normal.Z;
964 IsColliding = true;
965 }
966 return true;
967 }
968 return false;
969 }
970
971 /// <summary>
972 /// Called from Simulate
973 /// This is the avatar's movement control + PID Controller
974 /// </summary>
975 /// <param name="timeStep"></param>
976 public void Move(List<OdeCharacter> defects)
977 {
978 if (Body == IntPtr.Zero)
979 return;
980
981 d.Vector3 dtmp = d.BodyGetPosition(Body);
982 Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
983
984 // the Amotor still lets avatar rotation to drift during colisions
985 // so force it back to identity
986
987 d.Quaternion qtmp;
988 qtmp.W = m_orientation2D.W;
989 qtmp.X = m_orientation2D.X;
990 qtmp.Y = m_orientation2D.Y;
991 qtmp.Z = m_orientation2D.Z;
992 d.BodySetQuaternion(Body, ref qtmp);
993
994 if (m_pidControllerActive == false)
995 {
996 _zeroPosition = localpos;
997 }
998
999 if (!localpos.IsFinite())
1000 {
1001 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
1002 defects.Add(this);
1003 // _parent_scene.RemoveCharacter(this);
1004
1005 // destroy avatar capsule and related ODE data
1006 AvatarGeomAndBodyDestroy();
1007 return;
1008 }
1009
1010 // check outbounds forcing to be in world
1011 bool fixbody = false;
1012 if (localpos.X < 0.0f)
1013 {
1014 fixbody = true;
1015 localpos.X = 0.1f;
1016 }
1017 else if (localpos.X > _parent_scene.WorldExtents.X - 0.1f)
1018 {
1019 fixbody = true;
1020 localpos.X = _parent_scene.WorldExtents.X - 0.1f;
1021 }
1022 if (localpos.Y < 0.0f)
1023 {
1024 fixbody = true;
1025 localpos.Y = 0.1f;
1026 }
1027 else if (localpos.Y > _parent_scene.WorldExtents.Y - 0.1)
1028 {
1029 fixbody = true;
1030 localpos.Y = _parent_scene.WorldExtents.Y - 0.1f;
1031 }
1032 if (fixbody)
1033 {
1034 m_freemove = false;
1035 d.BodySetPosition(Body, localpos.X, localpos.Y, localpos.Z);
1036 }
1037
1038 float breakfactor;
1039
1040 Vector3 vec = Vector3.Zero;
1041 dtmp = d.BodyGetLinearVel(Body);
1042 Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
1043 float velLengthSquared = vel.LengthSquared();
1044
1045
1046 Vector3 ctz = _target_velocity;
1047
1048 float movementdivisor = 1f;
1049 //Ubit change divisions into multiplications below
1050 if (!m_alwaysRun)
1051 movementdivisor = 1 / walkDivisor;
1052 else
1053 movementdivisor = 1 / runDivisor;
1054
1055 ctz.X *= movementdivisor;
1056 ctz.Y *= movementdivisor;
1057
1058 //******************************************
1059 // colide with land
1060
1061 d.AABB aabb;
1062// d.GeomGetAABB(feetbox, out aabb);
1063 d.GeomGetAABB(capsule, out aabb);
1064 float chrminZ = aabb.MinZ; // move up a bit
1065 Vector3 posch = localpos;
1066
1067 float ftmp;
1068
1069 if (flying)
1070 {
1071 ftmp = timeStep;
1072 posch.X += vel.X * ftmp;
1073 posch.Y += vel.Y * ftmp;
1074 }
1075
1076 float terrainheight = _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y);
1077 if (chrminZ < terrainheight)
1078 {
1079 if (ctz.Z < 0)
1080 ctz.Z = 0;
1081
1082 Vector3 n = _parent_scene.GetTerrainNormalAtXY(posch.X, posch.Y);
1083 float depth = terrainheight - chrminZ;
1084
1085 vec.Z = depth * PID_P * 50;
1086
1087 if (!flying)
1088 vec.Z += -vel.Z * PID_D;
1089
1090 if (depth < 0.2f)
1091 {
1092 m_colliderGroundfilter++;
1093 if (m_colliderGroundfilter > 2)
1094 {
1095 m_iscolliding = true;
1096 m_colliderfilter = 2;
1097
1098 if (m_colliderGroundfilter > 10)
1099 {
1100 m_colliderGroundfilter = 10;
1101 m_freemove = false;
1102 }
1103
1104 m_collideNormal.X = n.X;
1105 m_collideNormal.Y = n.Y;
1106 m_collideNormal.Z = n.Z;
1107
1108 m_iscollidingGround = true;
1109
1110
1111 ContactPoint contact = new ContactPoint();
1112 contact.PenetrationDepth = depth;
1113 contact.Position.X = localpos.X;
1114 contact.Position.Y = localpos.Y;
1115 contact.Position.Z = terrainheight;
1116 contact.SurfaceNormal.X = -n.X;
1117 contact.SurfaceNormal.Y = -n.Y;
1118 contact.SurfaceNormal.Z = -n.Z;
1119 contact.RelativeSpeed = -vel.Z;
1120 contact.CharacterFeet = true;
1121 AddCollisionEvent(0, contact);
1122
1123// vec.Z *= 0.5f;
1124 }
1125 }
1126
1127 else
1128 {
1129 m_colliderGroundfilter -= 5;
1130 if (m_colliderGroundfilter <= 0)
1131 {
1132 m_colliderGroundfilter = 0;
1133 m_iscollidingGround = false;
1134 }
1135 }
1136 }
1137 else
1138 {
1139 m_colliderGroundfilter -= 5;
1140 if (m_colliderGroundfilter <= 0)
1141 {
1142 m_colliderGroundfilter = 0;
1143 m_iscollidingGround = false;
1144 }
1145 }
1146
1147
1148 //******************************************
1149 if (!m_iscolliding)
1150 m_collideNormal.Z = 0;
1151
1152 bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f);
1153
1154
1155
1156 if (!tviszero)
1157 {
1158 m_freemove = false;
1159
1160 // movement relative to surface if moving on it
1161 // dont disturbe vertical movement, ie jumps
1162 if (m_iscolliding && !flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
1163 {
1164 float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y;
1165 ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
1166 ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
1167 ctz.Z -= p;
1168 if (ctz.Z < 0)
1169 ctz.Z *= 2;
1170
1171 }
1172
1173 }
1174
1175
1176 if (!m_freemove)
1177 {
1178
1179 // if velocity is zero, use position control; otherwise, velocity control
1180 if (tviszero && m_iscolliding && !flying)
1181 {
1182 // keep track of where we stopped. No more slippin' & slidin'
1183 if (!_zeroFlag)
1184 {
1185 _zeroFlag = true;
1186 _zeroPosition = localpos;
1187 }
1188 if (m_pidControllerActive)
1189 {
1190 // We only want to deactivate the PID Controller if we think we want to have our surrogate
1191 // react to the physics scene by moving it's position.
1192 // Avatar to Avatar collisions
1193 // Prim to avatar collisions
1194
1195 vec.X = -vel.X * PID_D * 2f + (_zeroPosition.X - localpos.X) * (PID_P * 5);
1196 vec.Y = -vel.Y * PID_D * 2f + (_zeroPosition.Y - localpos.Y) * (PID_P * 5);
1197 if(vel.Z > 0)
1198 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
1199 else
1200 vec.Z += (-vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P) * 0.2f;
1201/*
1202 if (flying)
1203 {
1204 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
1205 }
1206*/
1207 }
1208 //PidStatus = true;
1209 }
1210 else
1211 {
1212 m_pidControllerActive = true;
1213 _zeroFlag = false;
1214
1215 if (m_iscolliding)
1216 {
1217 if (!flying)
1218 {
1219 // we are on a surface
1220 if (ctz.Z > 0f)
1221 {
1222 // moving up or JUMPING
1223 vec.Z += (ctz.Z - vel.Z) * PID_D * 2f;
1224 vec.X += (ctz.X - vel.X) * (PID_D);
1225 vec.Y += (ctz.Y - vel.Y) * (PID_D);
1226 }
1227 else
1228 {
1229 // we are moving down on a surface
1230 if (ctz.Z == 0)
1231 {
1232 if (vel.Z > 0)
1233 vec.Z -= vel.Z * PID_D * 2f;
1234 vec.X += (ctz.X - vel.X) * (PID_D);
1235 vec.Y += (ctz.Y - vel.Y) * (PID_D);
1236 }
1237 // intencionally going down
1238 else
1239 {
1240 if (ctz.Z < vel.Z)
1241 vec.Z += (ctz.Z - vel.Z) * PID_D;
1242 else
1243 {
1244 }
1245
1246 if (Math.Abs(ctz.X) > Math.Abs(vel.X))
1247 vec.X += (ctz.X - vel.X) * (PID_D);
1248 if (Math.Abs(ctz.Y) > Math.Abs(vel.Y))
1249 vec.Y += (ctz.Y - vel.Y) * (PID_D);
1250 }
1251 }
1252
1253 // We're standing on something
1254 }
1255 else
1256 {
1257 // We're flying and colliding with something
1258 vec.X += (ctz.X - vel.X) * (PID_D * 0.0625f);
1259 vec.Y += (ctz.Y - vel.Y) * (PID_D * 0.0625f);
1260 vec.Z += (ctz.Z - vel.Z) * (PID_D * 0.0625f);
1261 }
1262 }
1263 else // ie not colliding
1264 {
1265 if (flying) //(!m_iscolliding && flying)
1266 {
1267 // we're in mid air suspended
1268 vec.X += (ctz.X - vel.X) * (PID_D);
1269 vec.Y += (ctz.Y - vel.Y) * (PID_D);
1270 vec.Z += (ctz.Z - vel.Z) * (PID_D);
1271 }
1272
1273 else
1274 {
1275 // we're not colliding and we're not flying so that means we're falling!
1276 // m_iscolliding includes collisions with the ground.
1277
1278 // d.Vector3 pos = d.BodyGetPosition(Body);
1279 vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
1280 vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
1281 // hack for breaking on fall
1282 if (ctz.Z == -9999f)
1283 vec.Z += -vel.Z * PID_D - _parent_scene.gravityz * m_mass;
1284 }
1285 }
1286 }
1287
1288 if (velLengthSquared > 2500.0f) // 50m/s apply breaks
1289 {
1290 breakfactor = 0.16f * m_mass;
1291 vec.X -= breakfactor * vel.X;
1292 vec.Y -= breakfactor * vel.Y;
1293 vec.Z -= breakfactor * vel.Z;
1294 }
1295 }
1296 else
1297 {
1298 breakfactor = m_mass;
1299 vec.X -= breakfactor * vel.X;
1300 vec.Y -= breakfactor * vel.Y;
1301 if (flying)
1302 vec.Z -= 0.5f * breakfactor * vel.Z;
1303 else
1304 vec.Z -= .16f* m_mass * vel.Z;
1305 }
1306
1307 if (flying)
1308 {
1309 vec.Z -= _parent_scene.gravityz * m_mass;
1310
1311 //Added for auto fly height. Kitto Flora
1312 float target_altitude = _parent_scene.GetTerrainHeightAtXY(localpos.X, localpos.Y) + MinimumGroundFlightOffset;
1313
1314 if (localpos.Z < target_altitude)
1315 {
1316 vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f;
1317 }
1318 // end add Kitto Flora
1319 }
1320
1321 if (vec.IsFinite())
1322 {
1323 if (vec.X != 0 || vec.Y !=0 || vec.Z !=0)
1324 d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
1325 }
1326 else
1327 {
1328 m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()");
1329 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
1330 defects.Add(this);
1331 // _parent_scene.RemoveCharacter(this);
1332 // destroy avatar capsule and related ODE data
1333 AvatarGeomAndBodyDestroy();
1334 return;
1335 }
1336
1337 // update our local ideia of position velocity and aceleration
1338 // _position = localpos;
1339 _position = localpos;
1340
1341 if (_zeroFlag)
1342 {
1343 _velocity = Vector3.Zero;
1344 _acceleration = Vector3.Zero;
1345 m_rotationalVelocity = Vector3.Zero;
1346 }
1347 else
1348 {
1349 Vector3 a =_velocity; // previus velocity
1350 SetSmooth(ref _velocity, ref vel, 2);
1351 a = (_velocity - a) * invtimeStep;
1352 SetSmooth(ref _acceleration, ref a, 2);
1353
1354 dtmp = d.BodyGetAngularVel(Body);
1355 m_rotationalVelocity.X = 0f;
1356 m_rotationalVelocity.Y = 0f;
1357 m_rotationalVelocity.Z = dtmp.Z;
1358 Math.Round(m_rotationalVelocity.Z,3);
1359 }
1360 }
1361
1362 public void round(ref Vector3 v, int digits)
1363 {
1364 v.X = (float)Math.Round(v.X, digits);
1365 v.Y = (float)Math.Round(v.Y, digits);
1366 v.Z = (float)Math.Round(v.Z, digits);
1367 }
1368
1369 public void SetSmooth(ref Vector3 dst, ref Vector3 value)
1370 {
1371 dst.X = 0.1f * dst.X + 0.9f * value.X;
1372 dst.Y = 0.1f * dst.Y + 0.9f * value.Y;
1373 dst.Z = 0.1f * dst.Z + 0.9f * value.Z;
1374 }
1375
1376 public void SetSmooth(ref Vector3 dst, ref Vector3 value, int rounddigits)
1377 {
1378 dst.X = 0.4f * dst.X + 0.6f * value.X;
1379 dst.X = (float)Math.Round(dst.X, rounddigits);
1380
1381 dst.Y = 0.4f * dst.Y + 0.6f * value.Y;
1382 dst.Y = (float)Math.Round(dst.Y, rounddigits);
1383
1384 dst.Z = 0.4f * dst.Z + 0.6f * value.Z;
1385 dst.Z = (float)Math.Round(dst.Z, rounddigits);
1386 }
1387
1388
1389 /// <summary>
1390 /// Updates the reported position and velocity.
1391 /// Used to copy variables from unmanaged space at heartbeat rate and also trigger scene updates acording
1392 /// also outbounds checking
1393 /// copy and outbounds now done in move(..) at ode rate
1394 ///
1395 /// </summary>
1396 public void UpdatePositionAndVelocity()
1397 {
1398 return;
1399
1400// if (Body == IntPtr.Zero)
1401// return;
1402
1403 }
1404
1405 /// <summary>
1406 /// Cleanup the things we use in the scene.
1407 /// </summary>
1408 public void Destroy()
1409 {
1410 AddChange(changes.Remove, null);
1411 }
1412
1413 public override void CrossingFailure()
1414 {
1415 }
1416
1417 public override Vector3 PIDTarget { set { return; } }
1418 public override bool PIDActive { set { return; } }
1419 public override float PIDTau { set { return; } }
1420
1421 public override float PIDHoverHeight { set { return; } }
1422 public override bool PIDHoverActive { set { return; } }
1423 public override PIDHoverType PIDHoverType { set { return; } }
1424 public override float PIDHoverTau { set { return; } }
1425
1426 public override Quaternion APIDTarget { set { return; } }
1427
1428 public override bool APIDActive { set { return; } }
1429
1430 public override float APIDStrength { set { return; } }
1431
1432 public override float APIDDamping { set { return; } }
1433
1434
1435 public override void SubscribeEvents(int ms)
1436 {
1437 m_eventsubscription = ms;
1438 m_cureventsubscription = 0;
1439 if (CollisionEventsThisFrame == null)
1440 CollisionEventsThisFrame = new CollisionEventUpdate();
1441 SentEmptyCollisionsEvent = false;
1442 }
1443
1444 public override void UnSubscribeEvents()
1445 {
1446 if (CollisionEventsThisFrame != null)
1447 {
1448 lock (CollisionEventsThisFrame)
1449 {
1450 CollisionEventsThisFrame.Clear();
1451 CollisionEventsThisFrame = null;
1452 }
1453 }
1454 m_eventsubscription = 0;
1455 }
1456
1457 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1458 {
1459 if (CollisionEventsThisFrame == null)
1460 CollisionEventsThisFrame = new CollisionEventUpdate();
1461 lock (CollisionEventsThisFrame)
1462 {
1463 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1464 _parent_scene.AddCollisionEventReporting(this);
1465 }
1466 }
1467
1468 public void SendCollisions()
1469 {
1470 if (CollisionEventsThisFrame == null)
1471 return;
1472
1473 lock (CollisionEventsThisFrame)
1474 {
1475 if (m_cureventsubscription < m_eventsubscription)
1476 return;
1477
1478 m_cureventsubscription = 0;
1479
1480 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
1481
1482 if (!SentEmptyCollisionsEvent || ncolisions > 0)
1483 {
1484 base.SendCollisionUpdate(CollisionEventsThisFrame);
1485
1486 if (ncolisions == 0)
1487 {
1488 SentEmptyCollisionsEvent = true;
1489 _parent_scene.RemoveCollisionEventReporting(this);
1490 }
1491 else
1492 {
1493 SentEmptyCollisionsEvent = false;
1494 CollisionEventsThisFrame.Clear();
1495 }
1496 }
1497 }
1498 }
1499
1500 internal void AddCollisionFrameTime(int t)
1501 {
1502 // protect it from overflow crashing
1503 if (m_cureventsubscription < 50000)
1504 m_cureventsubscription += t;
1505 }
1506
1507 public override bool SubscribedEvents()
1508 {
1509 if (m_eventsubscription > 0)
1510 return true;
1511 return false;
1512 }
1513
1514 private void changePhysicsStatus(bool NewStatus)
1515 {
1516 if (NewStatus != m_isPhysical)
1517 {
1518 if (NewStatus)
1519 {
1520 AvatarGeomAndBodyDestroy();
1521
1522 AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z);
1523
1524 _parent_scene.actor_name_map[collider] = (PhysicsActor)this;
1525 _parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
1526 _parent_scene.AddCharacter(this);
1527 }
1528 else
1529 {
1530 _parent_scene.RemoveCollisionEventReporting(this);
1531 _parent_scene.RemoveCharacter(this);
1532 // destroy avatar capsule and related ODE data
1533 AvatarGeomAndBodyDestroy();
1534 }
1535 m_freemove = false;
1536 m_isPhysical = NewStatus;
1537 }
1538 }
1539
1540 private void changeAdd()
1541 {
1542 changePhysicsStatus(true);
1543 }
1544
1545 private void changeRemove()
1546 {
1547 changePhysicsStatus(false);
1548 }
1549
1550 private void changeShape(PrimitiveBaseShape arg)
1551 {
1552 }
1553
1554 private void changeAvatarSize(strAvatarSize st)
1555 {
1556 m_feetOffset = st.offset;
1557 changeSize(st.size);
1558 }
1559
1560 private void changeSize(Vector3 pSize)
1561 {
1562 if (pSize.IsFinite())
1563 {
1564 // for now only look to Z changes since viewers also don't change X and Y
1565 if (pSize.Z != m_size.Z)
1566 {
1567 AvatarGeomAndBodyDestroy();
1568
1569
1570 float oldsz = m_size.Z;
1571 m_size = pSize;
1572
1573
1574 AvatarGeomAndBodyCreation(_position.X, _position.Y,
1575 _position.Z + (m_size.Z - oldsz) * 0.5f);
1576
1577 Velocity = Vector3.Zero;
1578
1579
1580 _parent_scene.actor_name_map[collider] = (PhysicsActor)this;
1581 _parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
1582 }
1583 m_freemove = false;
1584 m_pidControllerActive = true;
1585 }
1586 else
1587 {
1588 m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
1589 }
1590 }
1591
1592 private void changePosition( Vector3 newPos)
1593 {
1594 if (Body != IntPtr.Zero)
1595 d.BodySetPosition(Body, newPos.X, newPos.Y, newPos.Z);
1596 _position = newPos;
1597 m_freemove = false;
1598 m_pidControllerActive = true;
1599 }
1600
1601 private void changeOrientation(Quaternion newOri)
1602 {
1603 if (m_orientation != newOri)
1604 {
1605 m_orientation = newOri; // keep a copy for core use
1606 // but only use rotations around Z
1607
1608 m_orientation2D.W = newOri.W;
1609 m_orientation2D.Z = newOri.Z;
1610
1611 float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
1612 if (t > 0)
1613 {
1614 t = 1.0f / (float)Math.Sqrt(t);
1615 m_orientation2D.W *= t;
1616 m_orientation2D.Z *= t;
1617 }
1618 else
1619 {
1620 m_orientation2D.W = 1.0f;
1621 m_orientation2D.Z = 0f;
1622 }
1623 m_orientation2D.Y = 0f;
1624 m_orientation2D.X = 0f;
1625
1626 d.Quaternion myrot = new d.Quaternion();
1627 myrot.X = m_orientation2D.X;
1628 myrot.Y = m_orientation2D.Y;
1629 myrot.Z = m_orientation2D.Z;
1630 myrot.W = m_orientation2D.W;
1631 d.BodySetQuaternion(Body, ref myrot);
1632 }
1633 }
1634
1635 private void changeVelocity(Vector3 newVel)
1636 {
1637 m_pidControllerActive = true;
1638 m_freemove = false;
1639 _target_velocity = newVel;
1640 }
1641
1642 private void changeSetTorque(Vector3 newTorque)
1643 {
1644 }
1645
1646 private void changeAddForce(Vector3 newForce)
1647 {
1648 }
1649
1650 private void changeAddAngularForce(Vector3 arg)
1651 {
1652 }
1653
1654 private void changeAngularLock(Vector3 arg)
1655 {
1656 }
1657
1658 private void changeFloatOnWater(bool arg)
1659 {
1660 }
1661
1662 private void changeVolumedetetion(bool arg)
1663 {
1664 }
1665
1666 private void changeSelectedStatus(bool arg)
1667 {
1668 }
1669
1670 private void changeDisable(bool arg)
1671 {
1672 }
1673
1674 private void changeBuilding(bool arg)
1675 {
1676 }
1677
1678 private void setFreeMove()
1679 {
1680 m_pidControllerActive = true;
1681 _zeroFlag = false;
1682 _target_velocity = Vector3.Zero;
1683 m_freemove = true;
1684 m_colliderfilter = -1;
1685 m_colliderObjectfilter = -1;
1686 m_colliderGroundfilter = -1;
1687
1688 m_iscolliding = false;
1689 m_iscollidingGround = false;
1690 m_iscollidingObj = false;
1691
1692 CollisionEventsThisFrame.Clear();
1693 }
1694
1695 private void changeForce(Vector3 newForce)
1696 {
1697 setFreeMove();
1698
1699 if (Body != IntPtr.Zero)
1700 {
1701 if (newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0)
1702 d.BodyAddForce(Body, newForce.X, newForce.Y, newForce.Z);
1703 }
1704 }
1705
1706 // for now momentum is actually velocity
1707 private void changeMomentum(Vector3 newmomentum)
1708 {
1709 _velocity = newmomentum;
1710 setFreeMove();
1711
1712 if (Body != IntPtr.Zero)
1713 d.BodySetLinearVel(Body, newmomentum.X, newmomentum.Y, newmomentum.Z);
1714 }
1715
1716 private void donullchange()
1717 {
1718 }
1719
1720 public bool DoAChange(changes what, object arg)
1721 {
1722 if (collider == IntPtr.Zero && what != changes.Add && what != changes.Remove)
1723 {
1724 return false;
1725 }
1726
1727 // nasty switch
1728 switch (what)
1729 {
1730 case changes.Add:
1731 changeAdd();
1732 break;
1733 case changes.Remove:
1734 changeRemove();
1735 break;
1736
1737 case changes.Position:
1738 changePosition((Vector3)arg);
1739 break;
1740
1741 case changes.Orientation:
1742 changeOrientation((Quaternion)arg);
1743 break;
1744
1745 case changes.PosOffset:
1746 donullchange();
1747 break;
1748
1749 case changes.OriOffset:
1750 donullchange();
1751 break;
1752
1753 case changes.Velocity:
1754 changeVelocity((Vector3)arg);
1755 break;
1756
1757 // case changes.Acceleration:
1758 // changeacceleration((Vector3)arg);
1759 // break;
1760 // case changes.AngVelocity:
1761 // changeangvelocity((Vector3)arg);
1762 // break;
1763
1764 case changes.Force:
1765 changeForce((Vector3)arg);
1766 break;
1767
1768 case changes.Torque:
1769 changeSetTorque((Vector3)arg);
1770 break;
1771
1772 case changes.AddForce:
1773 changeAddForce((Vector3)arg);
1774 break;
1775
1776 case changes.AddAngForce:
1777 changeAddAngularForce((Vector3)arg);
1778 break;
1779
1780 case changes.AngLock:
1781 changeAngularLock((Vector3)arg);
1782 break;
1783
1784 case changes.Size:
1785 changeSize((Vector3)arg);
1786 break;
1787
1788 case changes.AvatarSize:
1789 changeAvatarSize((strAvatarSize)arg);
1790 break;
1791
1792 case changes.Momentum:
1793 changeMomentum((Vector3)arg);
1794 break;
1795/* not in use for now
1796 case changes.Shape:
1797 changeShape((PrimitiveBaseShape)arg);
1798 break;
1799
1800 case changes.CollidesWater:
1801 changeFloatOnWater((bool)arg);
1802 break;
1803
1804 case changes.VolumeDtc:
1805 changeVolumedetetion((bool)arg);
1806 break;
1807
1808 case changes.Physical:
1809 changePhysicsStatus((bool)arg);
1810 break;
1811
1812 case changes.Selected:
1813 changeSelectedStatus((bool)arg);
1814 break;
1815
1816 case changes.disabled:
1817 changeDisable((bool)arg);
1818 break;
1819
1820 case changes.building:
1821 changeBuilding((bool)arg);
1822 break;
1823*/
1824 case changes.Null:
1825 donullchange();
1826 break;
1827
1828 default:
1829 donullchange();
1830 break;
1831 }
1832 return false;
1833 }
1834
1835 public void AddChange(changes what, object arg)
1836 {
1837 _parent_scene.AddChange((PhysicsActor)this, what, arg);
1838 }
1839
1840 private struct strAvatarSize
1841 {
1842 public Vector3 size;
1843 public float offset;
1844 }
1845
1846 }
1847}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
new file mode 100644
index 0000000..3c952ae
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
@@ -0,0 +1,1096 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces
29 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
30 * ODEPrim.cs contains methods dealing with Prim editing, Prim
31 * characteristics and Kinetic motion.
32 * ODEDynamics.cs contains methods dealing with Prim Physical motion
33 * (dynamics) and the associated settings. Old Linear and angular
34 * motors for dynamic motion have been replace with MoveLinear()
35 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
36 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
37 * switch between 'VEHICLE' parameter use and general dynamics
38 * settings use.
39 */
40
41// Extensive change Ubit 2012
42
43using System;
44using System.Collections.Generic;
45using System.Reflection;
46using System.Runtime.InteropServices;
47using log4net;
48using OpenMetaverse;
49using OdeAPI;
50using OpenSim.Framework;
51using OpenSim.Region.Physics.Manager;
52
53namespace OpenSim.Region.Physics.OdePlugin
54{
55 public class ODEDynamics
56 {
57 public Vehicle Type
58 {
59 get { return m_type; }
60 }
61
62 private OdePrim rootPrim;
63 private OdeScene _pParentScene;
64
65 // Vehicle properties
66 // WARNING this are working copies for internel use
67 // their values may not be the corresponding parameter
68
69 private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
70 private Quaternion m_RollreferenceFrame = Quaternion.Identity; // what hell is this ?
71
72 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
73
74 private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings:
75 // HOVER_TERRAIN_ONLY
76 // HOVER_GLOBAL_HEIGHT
77 // NO_DEFLECTION_UP
78 // HOVER_WATER_ONLY
79 // HOVER_UP_ONLY
80 // LIMIT_MOTOR_UP
81 // LIMIT_ROLL_ONLY
82 private Vector3 m_BlockingEndPoint = Vector3.Zero; // not sl
83
84 // Linear properties
85 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
86 private Vector3 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
87 private float m_linearMotorDecayTimescale = 120;
88 private float m_linearMotorTimescale = 1000;
89 private Vector3 m_linearMotorOffset = Vector3.Zero;
90
91 //Angular properties
92 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
93 private float m_angularMotorTimescale = 1000; // motor angular velocity ramp up rate
94 private float m_angularMotorDecayTimescale = 120; // motor angular velocity decay rate
95 private Vector3 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); // body angular velocity decay rate
96
97 //Deflection properties
98 private float m_angularDeflectionEfficiency = 0;
99 private float m_angularDeflectionTimescale = 1000;
100 private float m_linearDeflectionEfficiency = 0;
101 private float m_linearDeflectionTimescale = 1000;
102
103 //Banking properties
104 private float m_bankingEfficiency = 0;
105 private float m_bankingMix = 0;
106 private float m_bankingTimescale = 1000;
107
108 //Hover and Buoyancy properties
109 private float m_VhoverHeight = 0f;
110 private float m_VhoverEfficiency = 0f;
111 private float m_VhoverTimescale = 1000f;
112 private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
113 // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
114 // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
115 // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
116
117 //Attractor properties
118 private float m_verticalAttractionEfficiency = 1.0f; // damped
119 private float m_verticalAttractionTimescale = 1000f; // Timescale > 300 means no vert attractor.
120
121
122 // auxiliar
123 private float m_lmEfect = 0f; // current linear motor eficiency
124 private float m_lmDecay = 0f; // current linear decay
125
126 private float m_amEfect = 0; // current angular motor eficiency
127 private float m_amDecay = 0f; // current linear decay
128
129 private float m_ffactor = 1.0f;
130
131 private float m_timestep = 0.02f;
132 private float m_invtimestep = 50;
133
134
135 float m_ampwr;
136 float m_amdampX;
137 float m_amdampY;
138 float m_amdampZ;
139
140 float m_gravmod;
141
142 public float FrictionFactor
143 {
144 get
145 {
146 return m_ffactor;
147 }
148 }
149
150 public float GravMod
151 {
152 set
153 {
154 m_gravmod = value;
155 }
156 }
157
158
159 public ODEDynamics(OdePrim rootp)
160 {
161 rootPrim = rootp;
162 _pParentScene = rootPrim._parent_scene;
163 m_timestep = _pParentScene.ODE_STEPSIZE;
164 m_invtimestep = 1.0f / m_timestep;
165 m_gravmod = rootPrim.GravModifier;
166 }
167
168 public void DoSetVehicle(VehicleData vd)
169 {
170 m_type = vd.m_type;
171 m_flags = vd.m_flags;
172
173
174 // Linear properties
175 m_linearMotorDirection = vd.m_linearMotorDirection;
176
177 m_linearFrictionTimescale = vd.m_linearFrictionTimescale;
178 if (m_linearFrictionTimescale.X < m_timestep) m_linearFrictionTimescale.X = m_timestep;
179 if (m_linearFrictionTimescale.Y < m_timestep) m_linearFrictionTimescale.Y = m_timestep;
180 if (m_linearFrictionTimescale.Z < m_timestep) m_linearFrictionTimescale.Z = m_timestep;
181
182 m_linearMotorDecayTimescale = vd.m_linearMotorDecayTimescale;
183 if (m_linearMotorDecayTimescale < m_timestep) m_linearMotorDecayTimescale = m_timestep;
184 m_linearMotorDecayTimescale += 0.2f;
185 m_linearMotorDecayTimescale *= m_invtimestep;
186
187 m_linearMotorTimescale = vd.m_linearMotorTimescale;
188 if (m_linearMotorTimescale < m_timestep) m_linearMotorTimescale = m_timestep;
189
190 m_linearMotorOffset = vd.m_linearMotorOffset;
191
192 //Angular properties
193 m_angularMotorDirection = vd.m_angularMotorDirection;
194 m_angularMotorTimescale = vd.m_angularMotorTimescale;
195 if (m_angularMotorTimescale < m_timestep) m_angularMotorTimescale = m_timestep;
196
197 m_angularMotorDecayTimescale = vd.m_angularMotorDecayTimescale;
198 if (m_angularMotorDecayTimescale < m_timestep) m_angularMotorDecayTimescale = m_timestep;
199 m_angularMotorDecayTimescale *= m_invtimestep;
200
201 m_angularFrictionTimescale = vd.m_angularFrictionTimescale;
202 if (m_angularFrictionTimescale.X < m_timestep) m_angularFrictionTimescale.X = m_timestep;
203 if (m_angularFrictionTimescale.Y < m_timestep) m_angularFrictionTimescale.Y = m_timestep;
204 if (m_angularFrictionTimescale.Z < m_timestep) m_angularFrictionTimescale.Z = m_timestep;
205
206 //Deflection properties
207 m_angularDeflectionEfficiency = vd.m_angularDeflectionEfficiency;
208 m_angularDeflectionTimescale = vd.m_angularDeflectionTimescale;
209 if (m_angularDeflectionTimescale < m_timestep) m_angularDeflectionTimescale = m_timestep;
210
211 m_linearDeflectionEfficiency = vd.m_linearDeflectionEfficiency;
212 m_linearDeflectionTimescale = vd.m_linearDeflectionTimescale;
213 if (m_linearDeflectionTimescale < m_timestep) m_linearDeflectionTimescale = m_timestep;
214
215 //Banking properties
216 m_bankingEfficiency = vd.m_bankingEfficiency;
217 m_bankingMix = vd.m_bankingMix;
218 m_bankingTimescale = vd.m_bankingTimescale;
219 if (m_bankingTimescale < m_timestep) m_bankingTimescale = m_timestep;
220
221 //Hover and Buoyancy properties
222 m_VhoverHeight = vd.m_VhoverHeight;
223 m_VhoverEfficiency = vd.m_VhoverEfficiency;
224 m_VhoverTimescale = vd.m_VhoverTimescale;
225 if (m_VhoverTimescale < m_timestep) m_VhoverTimescale = m_timestep;
226
227 m_VehicleBuoyancy = vd.m_VehicleBuoyancy;
228
229 //Attractor properties
230 m_verticalAttractionEfficiency = vd.m_verticalAttractionEfficiency;
231 m_verticalAttractionTimescale = vd.m_verticalAttractionTimescale;
232 if (m_verticalAttractionTimescale < m_timestep) m_verticalAttractionTimescale = m_timestep;
233
234 // Axis
235 m_referenceFrame = vd.m_referenceFrame;
236
237 m_lmEfect = 0;
238 m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale);
239 m_amEfect = 0;
240 m_ffactor = 1.0f;
241 }
242
243 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
244 {
245 float len;
246
247 switch (pParam)
248 {
249 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
250 if (pValue < 0f) pValue = 0f;
251 if (pValue > 1f) pValue = 1f;
252 m_angularDeflectionEfficiency = pValue;
253 break;
254 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
255 if (pValue < m_timestep) pValue = m_timestep;
256 m_angularDeflectionTimescale = pValue;
257 break;
258 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
259 if (pValue < m_timestep) pValue = m_timestep;
260 else if (pValue > 120) pValue = 120;
261 m_angularMotorDecayTimescale = pValue * m_invtimestep;
262 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
263 break;
264 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
265 if (pValue < m_timestep) pValue = m_timestep;
266 m_angularMotorTimescale = pValue;
267 break;
268 case Vehicle.BANKING_EFFICIENCY:
269 if (pValue < -1f) pValue = -1f;
270 if (pValue > 1f) pValue = 1f;
271 m_bankingEfficiency = pValue;
272 break;
273 case Vehicle.BANKING_MIX:
274 if (pValue < 0f) pValue = 0f;
275 if (pValue > 1f) pValue = 1f;
276 m_bankingMix = pValue;
277 break;
278 case Vehicle.BANKING_TIMESCALE:
279 if (pValue < m_timestep) pValue = m_timestep;
280 m_bankingTimescale = pValue;
281 break;
282 case Vehicle.BUOYANCY:
283 if (pValue < -1f) pValue = -1f;
284 if (pValue > 1f) pValue = 1f;
285 m_VehicleBuoyancy = pValue;
286 break;
287 case Vehicle.HOVER_EFFICIENCY:
288 if (pValue < 0f) pValue = 0f;
289 if (pValue > 1f) pValue = 1f;
290 m_VhoverEfficiency = pValue;
291 break;
292 case Vehicle.HOVER_HEIGHT:
293 m_VhoverHeight = pValue;
294 break;
295 case Vehicle.HOVER_TIMESCALE:
296 if (pValue < m_timestep) pValue = m_timestep;
297 m_VhoverTimescale = pValue;
298 break;
299 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
300 if (pValue < 0f) pValue = 0f;
301 if (pValue > 1f) pValue = 1f;
302 m_linearDeflectionEfficiency = pValue;
303 break;
304 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
305 if (pValue < m_timestep) pValue = m_timestep;
306 m_linearDeflectionTimescale = pValue;
307 break;
308 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
309 if (pValue < m_timestep) pValue = m_timestep;
310 else if (pValue > 120) pValue = 120;
311 m_linearMotorDecayTimescale = (0.2f +pValue) * m_invtimestep;
312 m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale);
313 break;
314 case Vehicle.LINEAR_MOTOR_TIMESCALE:
315 if (pValue < m_timestep) pValue = m_timestep;
316 m_linearMotorTimescale = pValue;
317 break;
318 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
319 if (pValue < 0f) pValue = 0f;
320 if (pValue > 1f) pValue = 1f;
321 m_verticalAttractionEfficiency = pValue;
322 break;
323 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
324 if (pValue < m_timestep) pValue = m_timestep;
325 m_verticalAttractionTimescale = pValue;
326 break;
327
328 // These are vector properties but the engine lets you use a single float value to
329 // set all of the components to the same value
330 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
331 if (pValue < m_timestep) pValue = m_timestep;
332 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
333 break;
334 case Vehicle.ANGULAR_MOTOR_DIRECTION:
335 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
336 len = m_angularMotorDirection.Length();
337 if (len > 12.566f)
338 m_angularMotorDirection *= (12.566f / len);
339
340 m_amEfect = 1.0f ; // turn it on
341 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
342
343 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
344 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
345 d.BodyEnable(rootPrim.Body);
346 break;
347 case Vehicle.LINEAR_FRICTION_TIMESCALE:
348 if (pValue < m_timestep) pValue = m_timestep;
349 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
350 break;
351 case Vehicle.LINEAR_MOTOR_DIRECTION:
352 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
353 len = m_linearMotorDirection.Length();
354 if (len > 100.0f)
355 m_linearMotorDirection *= (100.0f / len);
356
357 m_lmDecay = 1.0f - 1.0f / m_linearMotorDecayTimescale;
358 m_lmEfect = 1.0f; // turn it on
359
360 m_ffactor = 0.0f;
361 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
362 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
363 d.BodyEnable(rootPrim.Body);
364 break;
365 case Vehicle.LINEAR_MOTOR_OFFSET:
366 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
367 len = m_linearMotorOffset.Length();
368 if (len > 100.0f)
369 m_linearMotorOffset *= (100.0f / len);
370 break;
371 }
372 }//end ProcessFloatVehicleParam
373
374 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
375 {
376 float len;
377
378 switch (pParam)
379 {
380 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
381 if (pValue.X < m_timestep) pValue.X = m_timestep;
382 if (pValue.Y < m_timestep) pValue.Y = m_timestep;
383 if (pValue.Z < m_timestep) pValue.Z = m_timestep;
384
385 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
386 break;
387 case Vehicle.ANGULAR_MOTOR_DIRECTION:
388 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
389 // Limit requested angular speed to 2 rps= 4 pi rads/sec
390 len = m_angularMotorDirection.Length();
391 if (len > 12.566f)
392 m_angularMotorDirection *= (12.566f / len);
393
394 m_amEfect = 1.0f; // turn it on
395 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
396
397 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
398 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
399 d.BodyEnable(rootPrim.Body);
400 break;
401 case Vehicle.LINEAR_FRICTION_TIMESCALE:
402 if (pValue.X < m_timestep) pValue.X = m_timestep;
403 if (pValue.Y < m_timestep) pValue.Y = m_timestep;
404 if (pValue.Z < m_timestep) pValue.Z = m_timestep;
405 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
406 break;
407 case Vehicle.LINEAR_MOTOR_DIRECTION:
408 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
409 len = m_linearMotorDirection.Length();
410 if (len > 100.0f)
411 m_linearMotorDirection *= (100.0f / len);
412
413 m_lmEfect = 1.0f; // turn it on
414 m_lmDecay = 1.0f - 1.0f / m_linearMotorDecayTimescale;
415
416 m_ffactor = 0.0f;
417 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
418 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
419 d.BodyEnable(rootPrim.Body);
420 break;
421 case Vehicle.LINEAR_MOTOR_OFFSET:
422 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
423 len = m_linearMotorOffset.Length();
424 if (len > 100.0f)
425 m_linearMotorOffset *= (100.0f / len);
426 break;
427 case Vehicle.BLOCK_EXIT:
428 m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z);
429 break;
430 }
431 }//end ProcessVectorVehicleParam
432
433 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
434 {
435 switch (pParam)
436 {
437 case Vehicle.REFERENCE_FRAME:
438 // m_referenceFrame = Quaternion.Inverse(pValue);
439 m_referenceFrame = pValue;
440 break;
441 case Vehicle.ROLL_FRAME:
442 m_RollreferenceFrame = pValue;
443 break;
444 }
445 }//end ProcessRotationVehicleParam
446
447 internal void ProcessVehicleFlags(int pParam, bool remove)
448 {
449 if (remove)
450 {
451 m_flags &= ~((VehicleFlag)pParam);
452 }
453 else
454 {
455 m_flags |= (VehicleFlag)pParam;
456 }
457 }//end ProcessVehicleFlags
458
459 internal void ProcessTypeChange(Vehicle pType)
460 {
461 m_lmEfect = 0;
462
463 m_amEfect = 0;
464 m_ffactor = 1f;
465
466 m_linearMotorDirection = Vector3.Zero;
467 m_angularMotorDirection = Vector3.Zero;
468
469 m_BlockingEndPoint = Vector3.Zero;
470 m_RollreferenceFrame = Quaternion.Identity;
471 m_linearMotorOffset = Vector3.Zero;
472
473 m_referenceFrame = Quaternion.Identity;
474
475 // Set Defaults For Type
476 m_type = pType;
477 switch (pType)
478 {
479 case Vehicle.TYPE_NONE:
480 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
481 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
482 m_linearMotorTimescale = 1000;
483 m_linearMotorDecayTimescale = 120 * m_invtimestep;
484 m_angularMotorTimescale = 1000;
485 m_angularMotorDecayTimescale = 1000 * m_invtimestep;
486 m_VhoverHeight = 0;
487 m_VhoverEfficiency = 1;
488 m_VhoverTimescale = 1000;
489 m_VehicleBuoyancy = 0;
490 m_linearDeflectionEfficiency = 0;
491 m_linearDeflectionTimescale = 1000;
492 m_angularDeflectionEfficiency = 0;
493 m_angularDeflectionTimescale = 1000;
494 m_bankingEfficiency = 0;
495 m_bankingMix = 1;
496 m_bankingTimescale = 1000;
497 m_verticalAttractionEfficiency = 0;
498 m_verticalAttractionTimescale = 1000;
499
500 m_flags = (VehicleFlag)0;
501 break;
502
503 case Vehicle.TYPE_SLED:
504 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
505 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
506 m_linearMotorTimescale = 1000;
507 m_linearMotorDecayTimescale = 120 * m_invtimestep;
508 m_angularMotorTimescale = 1000;
509 m_angularMotorDecayTimescale = 120 * m_invtimestep;
510 m_VhoverHeight = 0;
511 m_VhoverEfficiency = 1;
512 m_VhoverTimescale = 10;
513 m_VehicleBuoyancy = 0;
514 m_linearDeflectionEfficiency = 1;
515 m_linearDeflectionTimescale = 1;
516 m_angularDeflectionEfficiency = 0;
517 m_angularDeflectionTimescale = 10;
518 m_verticalAttractionEfficiency = 1;
519 m_verticalAttractionTimescale = 1000;
520 m_bankingEfficiency = 0;
521 m_bankingMix = 1;
522 m_bankingTimescale = 10;
523 m_flags &=
524 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
525 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
526 m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
527 VehicleFlag.LIMIT_ROLL_ONLY |
528 VehicleFlag.LIMIT_MOTOR_UP);
529 break;
530
531 case Vehicle.TYPE_CAR:
532 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
533 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
534 m_linearMotorTimescale = 1;
535 m_linearMotorDecayTimescale = 60 * m_invtimestep;
536 m_angularMotorTimescale = 1;
537 m_angularMotorDecayTimescale = 0.8f * m_invtimestep;
538 m_VhoverHeight = 0;
539 m_VhoverEfficiency = 0;
540 m_VhoverTimescale = 1000;
541 m_VehicleBuoyancy = 0;
542 m_linearDeflectionEfficiency = 1;
543 m_linearDeflectionTimescale = 2;
544 m_angularDeflectionEfficiency = 0;
545 m_angularDeflectionTimescale = 10;
546 m_verticalAttractionEfficiency = 1f;
547 m_verticalAttractionTimescale = 10f;
548 m_bankingEfficiency = -0.2f;
549 m_bankingMix = 1;
550 m_bankingTimescale = 1;
551 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
552 VehicleFlag.HOVER_TERRAIN_ONLY |
553 VehicleFlag.HOVER_GLOBAL_HEIGHT);
554 m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
555 VehicleFlag.LIMIT_ROLL_ONLY |
556 VehicleFlag.LIMIT_MOTOR_UP |
557 VehicleFlag.HOVER_UP_ONLY);
558 break;
559 case Vehicle.TYPE_BOAT:
560 m_linearFrictionTimescale = new Vector3(10, 3, 2);
561 m_angularFrictionTimescale = new Vector3(10, 10, 10);
562 m_linearMotorTimescale = 5;
563 m_linearMotorDecayTimescale = 60 * m_invtimestep;
564 m_angularMotorTimescale = 4;
565 m_angularMotorDecayTimescale = 4 * m_invtimestep;
566 m_VhoverHeight = 0;
567 m_VhoverEfficiency = 0.5f;
568 m_VhoverTimescale = 2;
569 m_VehicleBuoyancy = 1;
570 m_linearDeflectionEfficiency = 0.5f;
571 m_linearDeflectionTimescale = 3;
572 m_angularDeflectionEfficiency = 0.5f;
573 m_angularDeflectionTimescale = 5;
574 m_verticalAttractionEfficiency = 0.5f;
575 m_verticalAttractionTimescale = 5f;
576 m_bankingEfficiency = -0.3f;
577 m_bankingMix = 0.8f;
578 m_bankingTimescale = 1;
579 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
580 VehicleFlag.HOVER_GLOBAL_HEIGHT |
581 VehicleFlag.HOVER_UP_ONLY); // |
582// VehicleFlag.LIMIT_ROLL_ONLY);
583 m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
584 VehicleFlag.LIMIT_MOTOR_UP |
585 VehicleFlag.HOVER_UP_ONLY | // new sl
586 VehicleFlag.HOVER_WATER_ONLY);
587 break;
588
589 case Vehicle.TYPE_AIRPLANE:
590 m_linearFrictionTimescale = new Vector3(200, 10, 5);
591 m_angularFrictionTimescale = new Vector3(20, 20, 20);
592 m_linearMotorTimescale = 2;
593 m_linearMotorDecayTimescale = 60 * m_invtimestep;
594 m_angularMotorTimescale = 4;
595 m_angularMotorDecayTimescale = 8 * m_invtimestep;
596 m_VhoverHeight = 0;
597 m_VhoverEfficiency = 0.5f;
598 m_VhoverTimescale = 1000;
599 m_VehicleBuoyancy = 0;
600 m_linearDeflectionEfficiency = 0.5f;
601 m_linearDeflectionTimescale = 0.5f;
602 m_angularDeflectionEfficiency = 1;
603 m_angularDeflectionTimescale = 2;
604 m_verticalAttractionEfficiency = 0.9f;
605 m_verticalAttractionTimescale = 2f;
606 m_bankingEfficiency = 1;
607 m_bankingMix = 0.7f;
608 m_bankingTimescale = 2;
609 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
610 VehicleFlag.HOVER_TERRAIN_ONLY |
611 VehicleFlag.HOVER_GLOBAL_HEIGHT |
612 VehicleFlag.HOVER_UP_ONLY |
613 VehicleFlag.NO_DEFLECTION_UP |
614 VehicleFlag.LIMIT_MOTOR_UP);
615 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
616 break;
617
618 case Vehicle.TYPE_BALLOON:
619 m_linearFrictionTimescale = new Vector3(5, 5, 5);
620 m_angularFrictionTimescale = new Vector3(10, 10, 10);
621 m_linearMotorTimescale = 5;
622 m_linearMotorDecayTimescale = 60 * m_invtimestep;
623 m_angularMotorTimescale = 6;
624 m_angularMotorDecayTimescale = 10 * m_invtimestep;
625 m_VhoverHeight = 5;
626 m_VhoverEfficiency = 0.8f;
627 m_VhoverTimescale = 10;
628 m_VehicleBuoyancy = 1;
629 m_linearDeflectionEfficiency = 0;
630 m_linearDeflectionTimescale = 5 * m_invtimestep;
631 m_angularDeflectionEfficiency = 0;
632 m_angularDeflectionTimescale = 5;
633 m_verticalAttractionEfficiency = 1f;
634 m_verticalAttractionTimescale = 1000f;
635 m_bankingEfficiency = 0;
636 m_bankingMix = 0.7f;
637 m_bankingTimescale = 5;
638 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
639 VehicleFlag.HOVER_TERRAIN_ONLY |
640 VehicleFlag.HOVER_UP_ONLY |
641 VehicleFlag.NO_DEFLECTION_UP |
642 VehicleFlag.LIMIT_MOTOR_UP | //);
643 VehicleFlag.LIMIT_ROLL_ONLY | // new sl
644 VehicleFlag.HOVER_GLOBAL_HEIGHT); // new sl
645
646// m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY |
647// VehicleFlag.HOVER_GLOBAL_HEIGHT);
648 break;
649
650 }
651
652 m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale);
653 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
654
655 }//end SetDefaultsForType
656
657 internal void Stop()
658 {
659 m_lmEfect = 0;
660 m_lmDecay = 0f;
661 m_amEfect = 0;
662 m_amDecay = 0;
663 m_ffactor = 1f;
664 }
665
666 public static Vector3 Xrot(Quaternion rot)
667 {
668 Vector3 vec;
669 rot.Normalize(); // just in case
670 vec.X = 2 * (rot.X * rot.X + rot.W * rot.W) - 1;
671 vec.Y = 2 * (rot.X * rot.Y + rot.Z * rot.W);
672 vec.Z = 2 * (rot.X * rot.Z - rot.Y * rot.W);
673 return vec;
674 }
675
676 public static Vector3 Zrot(Quaternion rot)
677 {
678 Vector3 vec;
679 rot.Normalize(); // just in case
680 vec.X = 2 * (rot.X * rot.Z + rot.Y * rot.W);
681 vec.Y = 2 * (rot.Y * rot.Z - rot.X * rot.W);
682 vec.Z = 2 * (rot.Z * rot.Z + rot.W * rot.W) - 1;
683
684 return vec;
685 }
686
687 private const float pi = (float)Math.PI;
688 private const float halfpi = 0.5f * (float)Math.PI;
689 private const float twopi = 2.0f * pi;
690
691 public static Vector3 ubitRot2Euler(Quaternion rot)
692 {
693 // returns roll in X
694 // pitch in Y
695 // yaw in Z
696 Vector3 vec;
697
698 // assuming rot is normalised
699 // rot.Normalize();
700
701 float zX = rot.X * rot.Z + rot.Y * rot.W;
702
703 if (zX < -0.49999f)
704 {
705 vec.X = 0;
706 vec.Y = -halfpi;
707 vec.Z = (float)(-2d * Math.Atan(rot.X / rot.W));
708 }
709 else if (zX > 0.49999f)
710 {
711 vec.X = 0;
712 vec.Y = halfpi;
713 vec.Z = (float)(2d * Math.Atan(rot.X / rot.W));
714 }
715 else
716 {
717 vec.Y = (float)Math.Asin(2 * zX);
718
719 float sqw = rot.W * rot.W;
720
721 float minuszY = rot.X * rot.W - rot.Y * rot.Z;
722 float zZ = rot.Z * rot.Z + sqw - 0.5f;
723
724 vec.X = (float)Math.Atan2(minuszY, zZ);
725
726 float yX = rot.Z * rot.W - rot.X * rot.Y; //( have negative ?)
727 float yY = rot.X * rot.X + sqw - 0.5f;
728 vec.Z = (float)Math.Atan2(yX, yY);
729 }
730 return vec;
731 }
732
733 public static void GetRollPitch(Quaternion rot, out float roll, out float pitch)
734 {
735 // assuming rot is normalised
736 // rot.Normalize();
737
738 float zX = rot.X * rot.Z + rot.Y * rot.W;
739
740 if (zX < -0.49999f)
741 {
742 roll = 0;
743 pitch = -halfpi;
744 }
745 else if (zX > 0.49999f)
746 {
747 roll = 0;
748 pitch = halfpi;
749 }
750 else
751 {
752 pitch = (float)Math.Asin(2 * zX);
753
754 float minuszY = rot.X * rot.W - rot.Y * rot.Z;
755 float zZ = rot.Z * rot.Z + rot.W * rot.W - 0.5f;
756
757 roll = (float)Math.Atan2(minuszY, zZ);
758 }
759 return ;
760 }
761
762 internal void Step()
763 {
764 IntPtr Body = rootPrim.Body;
765
766 d.Mass dmass;
767 d.BodyGetMass(Body, out dmass);
768
769 d.Quaternion rot = d.BodyGetQuaternion(Body);
770 Quaternion objrotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
771 Quaternion rotq = objrotq; // rotq = rotation of object
772 rotq *= m_referenceFrame; // rotq is now rotation in vehicle reference frame
773 Quaternion irotq = Quaternion.Inverse(rotq);
774
775 d.Vector3 dvtmp;
776 Vector3 tmpV;
777 Vector3 curVel; // velocity in world
778 Vector3 curAngVel; // angular velocity in world
779 Vector3 force = Vector3.Zero; // actually linear aceleration until mult by mass in world frame
780 Vector3 torque = Vector3.Zero;// actually angular aceleration until mult by Inertia in vehicle frame
781 d.Vector3 dtorque = new d.Vector3();
782
783 dvtmp = d.BodyGetLinearVel(Body);
784 curVel.X = dvtmp.X;
785 curVel.Y = dvtmp.Y;
786 curVel.Z = dvtmp.Z;
787 Vector3 curLocalVel = curVel * irotq; // current velocity in local
788
789 dvtmp = d.BodyGetAngularVel(Body);
790 curAngVel.X = dvtmp.X;
791 curAngVel.Y = dvtmp.Y;
792 curAngVel.Z = dvtmp.Z;
793 Vector3 curLocalAngVel = curAngVel * irotq; // current angular velocity in local
794
795 float ldampZ = 0;
796
797 // linear motor
798 if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000)
799 {
800 tmpV = m_linearMotorDirection - curLocalVel; // velocity error
801 tmpV *= m_lmEfect / m_linearMotorTimescale; // error to correct in this timestep
802 tmpV *= rotq; // to world
803
804 if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0)
805 tmpV.Z = 0;
806
807 if (m_linearMotorOffset.X != 0 || m_linearMotorOffset.Y != 0 || m_linearMotorOffset.Z != 0)
808 {
809 // have offset, do it now
810 tmpV *= dmass.mass;
811 d.BodyAddForceAtRelPos(Body, tmpV.X, tmpV.Y, tmpV.Z, m_linearMotorOffset.X, m_linearMotorOffset.Y, m_linearMotorOffset.Z);
812 }
813 else
814 {
815 force.X += tmpV.X;
816 force.Y += tmpV.Y;
817 force.Z += tmpV.Z;
818 }
819
820 m_lmEfect *= m_lmDecay;
821// m_ffactor = 0.01f + 1e-4f * curVel.LengthSquared();
822 m_ffactor = 0.0f;
823 }
824 else
825 {
826 m_lmEfect = 0;
827 m_ffactor = 1f;
828 }
829
830 // hover
831 if (m_VhoverTimescale < 300 && rootPrim.prim_geom != IntPtr.Zero)
832 {
833 // d.Vector3 pos = d.BodyGetPosition(Body);
834 d.Vector3 pos = d.GeomGetPosition(rootPrim.prim_geom);
835 pos.Z -= 0.21f; // minor offset that seems to be always there in sl
836
837 float t = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y);
838 float perr;
839
840 // default to global but don't go underground
841 perr = m_VhoverHeight - pos.Z;
842
843 if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) == 0)
844 {
845 if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0)
846 {
847 perr += _pParentScene.GetWaterLevel();
848 }
849 else if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
850 {
851 perr += t;
852 }
853 else
854 {
855 float w = _pParentScene.GetWaterLevel();
856 if (t > w)
857 perr += t;
858 else
859 perr += w;
860 }
861 }
862 else if (t > m_VhoverHeight)
863 perr = t - pos.Z; ;
864
865 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) == 0 || perr > -0.1)
866 {
867 ldampZ = m_VhoverEfficiency * m_invtimestep;
868
869 perr *= (1.0f + ldampZ) / m_VhoverTimescale;
870
871 // force.Z += perr - curVel.Z * tmp;
872 force.Z += perr;
873 ldampZ *= -curVel.Z;
874
875 force.Z += _pParentScene.gravityz * m_gravmod * (1f - m_VehicleBuoyancy);
876 }
877 else // no buoyancy
878 force.Z += _pParentScene.gravityz;
879 }
880 else
881 {
882 // default gravity and Buoyancy
883 force.Z += _pParentScene.gravityz * m_gravmod * (1f - m_VehicleBuoyancy);
884 }
885
886 // linear deflection
887 if (m_linearDeflectionEfficiency > 0)
888 {
889 float len = curVel.Length();
890 if (len > 0.01) // if moving
891 {
892 Vector3 atAxis;
893 atAxis = Xrot(rotq); // where are we pointing to
894 atAxis *= len; // make it same size as world velocity vector
895
896 tmpV = -atAxis; // oposite direction
897 atAxis -= curVel; // error to one direction
898 len = atAxis.LengthSquared();
899
900 tmpV -= curVel; // error to oposite
901 float lens = tmpV.LengthSquared();
902
903 if (len > 0.01 || lens > 0.01) // do nothing if close enougth
904 {
905 if (len < lens)
906 tmpV = atAxis;
907
908 tmpV *= (m_linearDeflectionEfficiency / m_linearDeflectionTimescale); // error to correct in this timestep
909 force.X += tmpV.X;
910 force.Y += tmpV.Y;
911 if ((m_flags & VehicleFlag.NO_DEFLECTION_UP) == 0)
912 force.Z += tmpV.Z;
913 }
914 }
915 }
916
917 // linear friction/damping
918 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0)
919 {
920 tmpV.X = -curLocalVel.X / m_linearFrictionTimescale.X;
921 tmpV.Y = -curLocalVel.Y / m_linearFrictionTimescale.Y;
922 tmpV.Z = -curLocalVel.Z / m_linearFrictionTimescale.Z;
923 tmpV *= rotq; // to world
924
925 if(ldampZ != 0 && Math.Abs(ldampZ) > Math.Abs(tmpV.Z))
926 tmpV.Z = ldampZ;
927 force.X += tmpV.X;
928 force.Y += tmpV.Y;
929 force.Z += tmpV.Z;
930 }
931
932 // vertical atractor
933 if (m_verticalAttractionTimescale < 300)
934 {
935 float roll;
936 float pitch;
937
938
939
940 float ftmp = m_invtimestep / m_verticalAttractionTimescale / m_verticalAttractionTimescale;
941
942 float ftmp2;
943 ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
944 m_amdampX = ftmp2;
945
946 m_ampwr = 1.0f - 0.8f * m_verticalAttractionEfficiency;
947
948 GetRollPitch(irotq, out roll, out pitch);
949
950 if (roll > halfpi)
951 roll = pi - roll;
952 else if (roll < -halfpi)
953 roll = -pi - roll;
954
955 float effroll = pitch / halfpi;
956 effroll *= effroll;
957 effroll = 1 - effroll;
958 effroll *= roll;
959
960
961 torque.X += effroll * ftmp;
962
963 if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)
964 {
965 float effpitch = roll / halfpi;
966 effpitch *= effpitch;
967 effpitch = 1 - effpitch;
968 effpitch *= pitch;
969
970 torque.Y += effpitch * ftmp;
971 }
972
973 if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
974 {
975
976 float broll = effroll;
977 /*
978 if (broll > halfpi)
979 broll = pi - broll;
980 else if (broll < -halfpi)
981 broll = -pi - broll;
982 */
983 broll *= m_bankingEfficiency;
984 if (m_bankingMix != 0)
985 {
986 float vfact = Math.Abs(curLocalVel.X) / 10.0f;
987 if (vfact > 1.0f) vfact = 1.0f;
988
989 if (curLocalVel.X >= 0)
990 broll *= (1 + (vfact - 1) * m_bankingMix);
991 else
992 broll *= -(1 + (vfact - 1) * m_bankingMix);
993 }
994 // make z rot be in world Z not local as seems to be in sl
995
996 broll = broll / m_bankingTimescale;
997
998
999 tmpV = Zrot(irotq);
1000 tmpV *= broll;
1001
1002 torque.X += tmpV.X;
1003 torque.Y += tmpV.Y;
1004 torque.Z += tmpV.Z;
1005
1006 m_amdampZ = Math.Abs(m_bankingEfficiency) / m_bankingTimescale;
1007 m_amdampY = m_amdampZ;
1008
1009 }
1010 else
1011 {
1012 m_amdampZ = 1 / m_angularFrictionTimescale.Z;
1013 m_amdampY = m_amdampX;
1014 }
1015 }
1016 else
1017 {
1018 m_ampwr = 1.0f;
1019 m_amdampX = 1 / m_angularFrictionTimescale.X;
1020 m_amdampY = 1 / m_angularFrictionTimescale.Y;
1021 m_amdampZ = 1 / m_angularFrictionTimescale.Z;
1022 }
1023
1024 // angular motor
1025 if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
1026 {
1027 tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error
1028 tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep
1029 torque.X += tmpV.X * m_ampwr;
1030 torque.Y += tmpV.Y * m_ampwr;
1031 torque.Z += tmpV.Z;
1032
1033 m_amEfect *= m_amDecay;
1034 }
1035 else
1036 m_amEfect = 0;
1037
1038 // angular deflection
1039 if (m_angularDeflectionEfficiency > 0)
1040 {
1041 Vector3 dirv;
1042
1043 if (curLocalVel.X > 0.01f)
1044 dirv = curLocalVel;
1045 else if (curLocalVel.X < -0.01f)
1046 // use oposite
1047 dirv = -curLocalVel;
1048 else
1049 {
1050 // make it fall into small positive x case
1051 dirv.X = 0.01f;
1052 dirv.Y = curLocalVel.Y;
1053 dirv.Z = curLocalVel.Z;
1054 }
1055
1056 float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
1057
1058 if (Math.Abs(dirv.Z) > 0.01)
1059 {
1060 torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
1061 }
1062
1063 if (Math.Abs(dirv.Y) > 0.01)
1064 {
1065 torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
1066 }
1067 }
1068
1069 // angular friction
1070 if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
1071 {
1072 torque.X -= curLocalAngVel.X * m_amdampX;
1073 torque.Y -= curLocalAngVel.Y * m_amdampY;
1074 torque.Z -= curLocalAngVel.Z * m_amdampZ;
1075 }
1076
1077
1078 if (force.X != 0 || force.Y != 0 || force.Z != 0)
1079 {
1080 force *= dmass.mass;
1081 d.BodyAddForce(Body, force.X, force.Y, force.Z);
1082 }
1083
1084 if (torque.X != 0 || torque.Y != 0 || torque.Z != 0)
1085 {
1086 torque *= m_referenceFrame; // to object frame
1087 dtorque.X = torque.X ;
1088 dtorque.Y = torque.Y;
1089 dtorque.Z = torque.Z;
1090
1091 d.MultiplyM3V3(out dvtmp, ref dmass.I, ref dtorque);
1092 d.BodyAddRelTorque(Body, dvtmp.X, dvtmp.Y, dvtmp.Z); // add torque in object frame
1093 }
1094 }
1095 }
1096}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
new file mode 100644
index 0000000..a6bdaa0
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
@@ -0,0 +1,933 @@
1/*
2 * AJLDuarte 2012
3 */
4
5using System;
6using System.Threading;
7using System.Collections.Generic;
8using System.IO;
9using System.Reflection;
10using System.Runtime.InteropServices;
11using System.Text;
12using OpenSim.Framework;
13using OpenSim.Region.Physics.Manager;
14using OdeAPI;
15using log4net;
16using Nini.Config;
17using OpenMetaverse;
18
19namespace OpenSim.Region.Physics.OdePlugin
20{
21 public enum MeshState : byte
22 {
23 noNeed = 0,
24
25 loadingAsset = 1,
26
27 AssetOK = 0x0f, // 00001111
28
29 NeedMask = 0x30, // 00110000
30 needMesh = 0x10, // 00010000
31 needAsset = 0x20, // 00100000
32
33 FailMask = 0xC0, // 11000000
34 AssetFailed = 0x40, // 01000000
35 MeshFailed = 0x80, // 10000000
36
37 MeshNoColide = FailMask | needAsset
38 }
39
40 public enum meshWorkerCmnds : byte
41 {
42 nop = 0,
43 addnew,
44 changefull,
45 changesize,
46 changeshapetype,
47 getmesh,
48 }
49
50 public class ODEPhysRepData
51 {
52 public PhysicsActor actor;
53 public PrimitiveBaseShape pbs;
54 public IMesh mesh;
55
56 public Vector3 size;
57 public Vector3 OBB;
58 public Vector3 OBBOffset;
59
60 public float volume;
61
62 public byte shapetype;
63 public bool hasOBB;
64 public bool hasMeshVolume;
65 public MeshState meshState;
66 public UUID? assetID;
67 public meshWorkerCmnds comand;
68 }
69
70 public class ODEMeshWorker
71 {
72
73 private ILog m_log;
74 private OdeScene m_scene;
75 private IMesher m_mesher;
76
77 public bool meshSculptedPrim = true;
78 public bool forceSimplePrimMeshing = false;
79 public float meshSculptLOD = 32;
80 public float MeshSculptphysicalLOD = 32;
81
82
83 private OpenSim.Framework.BlockingQueue<ODEPhysRepData> createqueue = new OpenSim.Framework.BlockingQueue<ODEPhysRepData>();
84 private bool m_running;
85
86 private Thread m_thread;
87
88 public ODEMeshWorker(OdeScene pScene, ILog pLog, IMesher pMesher, IConfig pConfig)
89 {
90 m_scene = pScene;
91 m_log = pLog;
92 m_mesher = pMesher;
93
94 if (pConfig != null)
95 {
96 forceSimplePrimMeshing = pConfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing);
97 meshSculptedPrim = pConfig.GetBoolean("mesh_sculpted_prim", meshSculptedPrim);
98 meshSculptLOD = pConfig.GetFloat("mesh_lod", meshSculptLOD);
99 MeshSculptphysicalLOD = pConfig.GetFloat("mesh_physical_lod", MeshSculptphysicalLOD);
100 }
101 m_running = true;
102 m_thread = new Thread(DoWork);
103 m_thread.Name = "OdeMeshWorker";
104 m_thread.Start();
105 }
106
107 private void DoWork()
108 {
109 m_mesher.ExpireFileCache();
110
111 while(m_running)
112 {
113 ODEPhysRepData nextRep = createqueue.Dequeue();
114 if(!m_running)
115 return;
116 if (nextRep == null)
117 continue;
118 if (m_scene.haveActor(nextRep.actor))
119 {
120 switch (nextRep.comand)
121 {
122 case meshWorkerCmnds.changefull:
123 case meshWorkerCmnds.changeshapetype:
124 case meshWorkerCmnds.changesize:
125 GetMesh(nextRep);
126 if (CreateActorPhysRep(nextRep) && m_scene.haveActor(nextRep.actor))
127 m_scene.AddChange(nextRep.actor, changes.PhysRepData, nextRep);
128 break;
129 case meshWorkerCmnds.getmesh:
130 DoRepDataGetMesh(nextRep);
131 break;
132 }
133 }
134 }
135 }
136
137 public void Stop()
138 {
139 try
140 {
141 m_thread.Abort();
142 createqueue.Clear();
143 }
144 catch
145 {
146 }
147 }
148
149 public void ChangeActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
150 Vector3 size, byte shapetype)
151 {
152 ODEPhysRepData repData = new ODEPhysRepData();
153 repData.actor = actor;
154 repData.pbs = pbs;
155 repData.size = size;
156 repData.shapetype = shapetype;
157
158 CheckMesh(repData);
159 CalcVolumeData(repData);
160 m_scene.AddChange(actor, changes.PhysRepData, repData);
161 return;
162 }
163
164 public ODEPhysRepData NewActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
165 Vector3 size, byte shapetype)
166 {
167 ODEPhysRepData repData = new ODEPhysRepData();
168 repData.actor = actor;
169 repData.pbs = pbs;
170 repData.size = size;
171 repData.shapetype = shapetype;
172
173 CheckMesh(repData);
174 CalcVolumeData(repData);
175 m_scene.AddChange(actor, changes.AddPhysRep, repData);
176 return repData;
177 }
178
179 public void RequestMesh(ODEPhysRepData repData)
180 {
181 repData.mesh = null;
182
183 if (repData.meshState == MeshState.needAsset)
184 {
185 PrimitiveBaseShape pbs = repData.pbs;
186
187 // check if we got outdated
188
189 if (!pbs.SculptEntry || pbs.SculptTexture == UUID.Zero)
190 {
191 repData.meshState = MeshState.noNeed;
192 return;
193 }
194
195 repData.assetID = pbs.SculptTexture;
196 repData.meshState = MeshState.loadingAsset;
197
198 repData.comand = meshWorkerCmnds.getmesh;
199 createqueue.Enqueue(repData);
200 }
201 }
202
203 // creates and prepares a mesh to use and calls parameters estimation
204 public bool CreateActorPhysRep(ODEPhysRepData repData)
205 {
206 IMesh mesh = repData.mesh;
207
208 if (mesh != null)
209 {
210 IntPtr vertices, indices;
211 int vertexCount, indexCount;
212 int vertexStride, triStride;
213
214 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount);
215 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount);
216
217 if (vertexCount == 0 || indexCount == 0)
218 {
219 m_log.WarnFormat("[PHYSICS]: Invalid mesh data on prim {0} mesh UUID {1}",
220 repData.actor.Name, repData.pbs.SculptTexture.ToString());
221 repData.meshState = MeshState.MeshFailed;
222 repData.hasOBB = false;
223 repData.mesh = null;
224 m_scene.mesher.ReleaseMesh(mesh);
225 }
226 else
227 {
228 repData.OBBOffset = mesh.GetCentroid();
229 repData.OBB = mesh.GetOBB();
230 repData.hasOBB = true;
231 mesh.releaseSourceMeshData();
232 }
233 }
234 CalcVolumeData(repData);
235 return true;
236 }
237
238 public void AssetLoaded(ODEPhysRepData repData)
239 {
240 if (m_scene.haveActor(repData.actor))
241 {
242 if (needsMeshing(repData.pbs)) // no need for pbs now?
243 {
244 repData.comand = meshWorkerCmnds.changefull;
245 createqueue.Enqueue(repData);
246 }
247 }
248 else
249 repData.pbs.SculptData = Utils.EmptyBytes;
250 }
251
252 public void DoRepDataGetMesh(ODEPhysRepData repData)
253 {
254 if (!repData.pbs.SculptEntry)
255 return;
256
257 if (repData.meshState != MeshState.loadingAsset)
258 return;
259
260 if (repData.assetID == null || repData.assetID == UUID.Zero)
261 return;
262
263 if (repData.assetID != repData.pbs.SculptTexture)
264 return;
265
266 // check if it is in cache
267 GetMesh(repData);
268 if (repData.meshState != MeshState.needAsset)
269 {
270 CreateActorPhysRep(repData);
271 m_scene.AddChange(repData.actor, changes.PhysRepData, repData);
272 return;
273 }
274
275 RequestAssetDelegate assetProvider = m_scene.RequestAssetMethod;
276 if (assetProvider == null)
277 return;
278 ODEAssetRequest asr = new ODEAssetRequest(this, assetProvider, repData, m_log);
279 }
280
281
282 /// <summary>
283 /// Routine to figure out if we need to mesh this prim with our mesher
284 /// </summary>
285 /// <param name="pbs"></param>
286 /// <returns></returns>
287 public bool needsMeshing(PrimitiveBaseShape pbs)
288 {
289 // check sculpts or meshs
290 if (pbs.SculptEntry)
291 {
292 if (meshSculptedPrim)
293 return true;
294
295 if (pbs.SculptType == (byte)SculptType.Mesh) // always do meshs
296 return true;
297
298 return false;
299 }
300
301 if (forceSimplePrimMeshing)
302 return true;
303
304 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim
305
306 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
307 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
308 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
309 {
310
311 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
312 && pbs.ProfileHollow == 0
313 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
314 && pbs.PathBegin == 0 && pbs.PathEnd == 0
315 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
316 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
317 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
318 {
319 return false;
320 }
321 }
322
323 // following code doesn't give meshs to boxes and spheres ever
324 // and it's odd.. so for now just return true if asked to force meshs
325 // hopefully mesher will fail if doesn't suport so things still get basic boxes
326
327 int iPropertiesNotSupportedDefault = 0;
328
329 if (pbs.ProfileHollow != 0)
330 iPropertiesNotSupportedDefault++;
331
332 if ((pbs.PathBegin != 0) || pbs.PathEnd != 0)
333 iPropertiesNotSupportedDefault++;
334
335 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0))
336 iPropertiesNotSupportedDefault++;
337
338 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
339 iPropertiesNotSupportedDefault++;
340
341 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
342 iPropertiesNotSupportedDefault++;
343
344 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
345 iPropertiesNotSupportedDefault++;
346
347 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
348 iPropertiesNotSupportedDefault++;
349
350 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
351 iPropertiesNotSupportedDefault++;
352
353 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1)
354 iPropertiesNotSupportedDefault++;
355
356 // test for torus
357 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
358 {
359 if (pbs.PathCurve == (byte)Extrusion.Curve1)
360 {
361 iPropertiesNotSupportedDefault++;
362 }
363 }
364 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
365 {
366 if (pbs.PathCurve == (byte)Extrusion.Straight)
367 {
368 iPropertiesNotSupportedDefault++;
369 }
370
371 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
372 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
373 {
374 iPropertiesNotSupportedDefault++;
375 }
376 }
377 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
378 {
379 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
380 {
381 iPropertiesNotSupportedDefault++;
382 }
383 }
384 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
385 {
386 if (pbs.PathCurve == (byte)Extrusion.Straight)
387 {
388 iPropertiesNotSupportedDefault++;
389 }
390 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
391 {
392 iPropertiesNotSupportedDefault++;
393 }
394 }
395
396 if (iPropertiesNotSupportedDefault == 0)
397 {
398 return false;
399 }
400 return true;
401 }
402
403 // see if we need a mesh and if so if we have a cached one
404 // called with a new repData
405 public void CheckMesh(ODEPhysRepData repData)
406 {
407 PhysicsActor actor = repData.actor;
408 PrimitiveBaseShape pbs = repData.pbs;
409
410 if (!needsMeshing(pbs))
411 {
412 repData.meshState = MeshState.noNeed;
413 return;
414 }
415
416 IMesh mesh = null;
417
418 Vector3 size = repData.size;
419 byte shapetype = repData.shapetype;
420
421 bool convex;
422
423 int clod = (int)LevelOfDetail.High;
424 if (shapetype == 0)
425 convex = false;
426 else
427 {
428 convex = true;
429 if (pbs.SculptType != (byte)SculptType.Mesh)
430 clod = (int)LevelOfDetail.Low;
431 }
432
433 mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
434
435 if (mesh == null)
436 {
437 if (pbs.SculptEntry)
438 {
439 if (pbs.SculptTexture != null && pbs.SculptTexture != UUID.Zero)
440 {
441 repData.assetID = pbs.SculptTexture;
442 repData.meshState = MeshState.needAsset;
443 }
444 else
445 repData.meshState = MeshState.MeshFailed;
446
447 return;
448 }
449 else
450 {
451 repData.meshState = MeshState.needMesh;
452 mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true);
453 if (mesh == null)
454 {
455 repData.meshState = MeshState.MeshFailed;
456 return;
457 }
458 }
459 }
460
461 repData.meshState = MeshState.AssetOK;
462 repData.mesh = mesh;
463
464 if (pbs.SculptEntry)
465 {
466 repData.assetID = pbs.SculptTexture;
467 }
468
469 pbs.SculptData = Utils.EmptyBytes;
470 return ;
471 }
472
473 public void GetMesh(ODEPhysRepData repData)
474 {
475 PhysicsActor actor = repData.actor;
476
477 PrimitiveBaseShape pbs = repData.pbs;
478
479 repData.mesh = null;
480 repData.hasOBB = false;
481
482 if (!needsMeshing(pbs))
483 {
484 repData.meshState = MeshState.noNeed;
485 return;
486 }
487
488 if (repData.meshState == MeshState.MeshFailed)
489 return;
490
491 if (pbs.SculptEntry)
492 {
493 if (repData.meshState == MeshState.AssetFailed)
494 {
495 if (pbs.SculptTexture == repData.assetID)
496 return;
497 }
498 }
499
500 repData.meshState = MeshState.noNeed;
501
502 IMesh mesh = null;
503 Vector3 size = repData.size;
504 byte shapetype = repData.shapetype;
505
506 bool convex;
507 int clod = (int)LevelOfDetail.High;
508 if (shapetype == 0)
509 convex = false;
510 else
511 {
512 convex = true;
513 if (pbs.SculptType != (byte)SculptType.Mesh)
514 clod = (int)LevelOfDetail.Low;
515 }
516
517 mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true);
518
519 if (mesh == null)
520 {
521 if (pbs.SculptEntry)
522 {
523 if (pbs.SculptTexture == UUID.Zero)
524 return;
525
526 repData.assetID = pbs.SculptTexture;
527
528 if (pbs.SculptData == null || pbs.SculptData.Length == 0)
529 {
530 repData.meshState = MeshState.needAsset;
531 return;
532 }
533 }
534 }
535
536 repData.mesh = mesh;
537 repData.pbs.SculptData = Utils.EmptyBytes;
538
539 if (mesh == null)
540 {
541 if (pbs.SculptEntry)
542 repData.meshState = MeshState.AssetFailed;
543 else
544 repData.meshState = MeshState.MeshFailed;
545
546 return;
547 }
548
549 repData.meshState = MeshState.AssetOK;
550
551 return;
552 }
553
554 private void CalculateBasicPrimVolume(ODEPhysRepData repData)
555 {
556 PrimitiveBaseShape _pbs = repData.pbs;
557 Vector3 _size = repData.size;
558
559 float volume = _size.X * _size.Y * _size.Z; // default
560 float tmp;
561
562 float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f;
563 float hollowVolume = hollowAmount * hollowAmount;
564
565 switch (_pbs.ProfileShape)
566 {
567 case ProfileShape.Square:
568 // default box
569
570 if (_pbs.PathCurve == (byte)Extrusion.Straight)
571 {
572 if (hollowAmount > 0.0)
573 {
574 switch (_pbs.HollowShape)
575 {
576 case HollowShape.Square:
577 case HollowShape.Same:
578 break;
579
580 case HollowShape.Circle:
581
582 hollowVolume *= 0.78539816339f;
583 break;
584
585 case HollowShape.Triangle:
586
587 hollowVolume *= (0.5f * .5f);
588 break;
589
590 default:
591 hollowVolume = 0;
592 break;
593 }
594 volume *= (1.0f - hollowVolume);
595 }
596 }
597
598 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
599 {
600 //a tube
601
602 volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX);
603 tmp = 1.0f - 2.0e-2f * (float)(200 - _pbs.PathScaleY);
604 volume -= volume * tmp * tmp;
605
606 if (hollowAmount > 0.0)
607 {
608 hollowVolume *= hollowAmount;
609
610 switch (_pbs.HollowShape)
611 {
612 case HollowShape.Square:
613 case HollowShape.Same:
614 break;
615
616 case HollowShape.Circle:
617 hollowVolume *= 0.78539816339f;
618 break;
619
620 case HollowShape.Triangle:
621 hollowVolume *= 0.5f * 0.5f;
622 break;
623 default:
624 hollowVolume = 0;
625 break;
626 }
627 volume *= (1.0f - hollowVolume);
628 }
629 }
630
631 break;
632
633 case ProfileShape.Circle:
634
635 if (_pbs.PathCurve == (byte)Extrusion.Straight)
636 {
637 volume *= 0.78539816339f; // elipse base
638
639 if (hollowAmount > 0.0)
640 {
641 switch (_pbs.HollowShape)
642 {
643 case HollowShape.Same:
644 case HollowShape.Circle:
645 break;
646
647 case HollowShape.Square:
648 hollowVolume *= 0.5f * 2.5984480504799f;
649 break;
650
651 case HollowShape.Triangle:
652 hollowVolume *= .5f * 1.27323954473516f;
653 break;
654
655 default:
656 hollowVolume = 0;
657 break;
658 }
659 volume *= (1.0f - hollowVolume);
660 }
661 }
662
663 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
664 {
665 volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX);
666 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
667 volume *= (1.0f - tmp * tmp);
668
669 if (hollowAmount > 0.0)
670 {
671
672 // calculate the hollow volume by it's shape compared to the prim shape
673 hollowVolume *= hollowAmount;
674
675 switch (_pbs.HollowShape)
676 {
677 case HollowShape.Same:
678 case HollowShape.Circle:
679 break;
680
681 case HollowShape.Square:
682 hollowVolume *= 0.5f * 2.5984480504799f;
683 break;
684
685 case HollowShape.Triangle:
686 hollowVolume *= .5f * 1.27323954473516f;
687 break;
688
689 default:
690 hollowVolume = 0;
691 break;
692 }
693 volume *= (1.0f - hollowVolume);
694 }
695 }
696 break;
697
698 case ProfileShape.HalfCircle:
699 if (_pbs.PathCurve == (byte)Extrusion.Curve1)
700 {
701 volume *= 0.5236f;
702
703 if (hollowAmount > 0.0)
704 {
705 hollowVolume *= hollowAmount;
706
707 switch (_pbs.HollowShape)
708 {
709 case HollowShape.Circle:
710 case HollowShape.Triangle: // diference in sl is minor and odd
711 case HollowShape.Same:
712 break;
713
714 case HollowShape.Square:
715 hollowVolume *= 0.909f;
716 break;
717
718 // case HollowShape.Triangle:
719 // hollowVolume *= .827f;
720 // break;
721 default:
722 hollowVolume = 0;
723 break;
724 }
725 volume *= (1.0f - hollowVolume);
726 }
727
728 }
729 break;
730
731 case ProfileShape.EquilateralTriangle:
732
733 if (_pbs.PathCurve == (byte)Extrusion.Straight)
734 {
735 volume *= 0.32475953f;
736
737 if (hollowAmount > 0.0)
738 {
739
740 // calculate the hollow volume by it's shape compared to the prim shape
741 switch (_pbs.HollowShape)
742 {
743 case HollowShape.Same:
744 case HollowShape.Triangle:
745 hollowVolume *= .25f;
746 break;
747
748 case HollowShape.Square:
749 hollowVolume *= 0.499849f * 3.07920140172638f;
750 break;
751
752 case HollowShape.Circle:
753 // Hollow shape is a perfect cyllinder in respect to the cube's scale
754 // Cyllinder hollow volume calculation
755
756 hollowVolume *= 0.1963495f * 3.07920140172638f;
757 break;
758
759 default:
760 hollowVolume = 0;
761 break;
762 }
763 volume *= (1.0f - hollowVolume);
764 }
765 }
766 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
767 {
768 volume *= 0.32475953f;
769 volume *= 0.01f * (float)(200 - _pbs.PathScaleX);
770 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
771 volume *= (1.0f - tmp * tmp);
772
773 if (hollowAmount > 0.0)
774 {
775
776 hollowVolume *= hollowAmount;
777
778 switch (_pbs.HollowShape)
779 {
780 case HollowShape.Same:
781 case HollowShape.Triangle:
782 hollowVolume *= .25f;
783 break;
784
785 case HollowShape.Square:
786 hollowVolume *= 0.499849f * 3.07920140172638f;
787 break;
788
789 case HollowShape.Circle:
790
791 hollowVolume *= 0.1963495f * 3.07920140172638f;
792 break;
793
794 default:
795 hollowVolume = 0;
796 break;
797 }
798 volume *= (1.0f - hollowVolume);
799 }
800 }
801 break;
802
803 default:
804 break;
805 }
806
807 float taperX1;
808 float taperY1;
809 float taperX;
810 float taperY;
811 float pathBegin;
812 float pathEnd;
813 float profileBegin;
814 float profileEnd;
815
816 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
817 {
818 taperX1 = _pbs.PathScaleX * 0.01f;
819 if (taperX1 > 1.0f)
820 taperX1 = 2.0f - taperX1;
821 taperX = 1.0f - taperX1;
822
823 taperY1 = _pbs.PathScaleY * 0.01f;
824 if (taperY1 > 1.0f)
825 taperY1 = 2.0f - taperY1;
826 taperY = 1.0f - taperY1;
827 }
828 else
829 {
830 taperX = _pbs.PathTaperX * 0.01f;
831 if (taperX < 0.0f)
832 taperX = -taperX;
833 taperX1 = 1.0f - taperX;
834
835 taperY = _pbs.PathTaperY * 0.01f;
836 if (taperY < 0.0f)
837 taperY = -taperY;
838 taperY1 = 1.0f - taperY;
839 }
840
841 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
842
843 pathBegin = (float)_pbs.PathBegin * 2.0e-5f;
844 pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f;
845 volume *= (pathEnd - pathBegin);
846
847 // this is crude aproximation
848 profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f;
849 profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f;
850 volume *= (profileEnd - profileBegin);
851
852 repData.volume = volume;
853 }
854
855 private void CalcVolumeData(ODEPhysRepData repData)
856 {
857 if (repData.hasOBB)
858 {
859 Vector3 OBB = repData.OBB;
860 }
861 else
862 {
863 Vector3 OBB = repData.size;
864 OBB.X *= 0.5f;
865 OBB.Y *= 0.5f;
866 OBB.Z *= 0.5f;
867
868 repData.OBB = OBB;
869 repData.OBBOffset = Vector3.Zero;
870 }
871
872 CalculateBasicPrimVolume(repData);
873 }
874 }
875
876 public class ODEAssetRequest
877 {
878 ODEMeshWorker m_worker;
879 private ILog m_log;
880 ODEPhysRepData repData;
881
882 public ODEAssetRequest(ODEMeshWorker pWorker, RequestAssetDelegate provider,
883 ODEPhysRepData pRepData, ILog plog)
884 {
885 m_worker = pWorker;
886 m_log = plog;
887 repData = pRepData;
888
889 repData.meshState = MeshState.AssetFailed;
890 if (provider == null)
891 return;
892
893 if (repData.assetID == null)
894 return;
895
896 UUID assetID = (UUID) repData.assetID;
897 if (assetID == UUID.Zero)
898 return;
899
900 repData.meshState = MeshState.loadingAsset;
901 provider(assetID, ODEassetReceived);
902 }
903
904 void ODEassetReceived(AssetBase asset)
905 {
906 repData.meshState = MeshState.AssetFailed;
907 if (asset != null)
908 {
909 if (asset.Data != null && asset.Data.Length > 0)
910 {
911 repData.meshState = MeshState.noNeed;
912
913 if (!repData.pbs.SculptEntry)
914 return;
915 if (repData.pbs.SculptTexture != repData.assetID)
916 return;
917
918// repData.pbs.SculptData = new byte[asset.Data.Length];
919// asset.Data.CopyTo(repData.pbs.SculptData,0);
920 repData.pbs.SculptData = asset.Data;
921 repData.meshState = MeshState.AssetOK;
922 m_worker.AssetLoaded(repData);
923 }
924 else
925 m_log.WarnFormat("[PHYSICS]: asset provider returned invalid mesh data for prim {0} asset UUID {1}.",
926 repData.actor.Name, asset.ID.ToString());
927 }
928 else
929 m_log.WarnFormat("[PHYSICS]: asset provider returned null asset fo mesh of prim {0}.",
930 repData.actor.Name);
931 }
932 }
933} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
new file mode 100644
index 0000000..b13f601
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -0,0 +1,3897 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Revision 2011/12/13 by Ubit Umarov
29 *
30 *
31 */
32
33/*
34 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
35 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
36 * ODEPrim.cs contains methods dealing with Prim editing, Prim
37 * characteristics and Kinetic motion.
38 * ODEDynamics.cs contains methods dealing with Prim Physical motion
39 * (dynamics) and the associated settings. Old Linear and angular
40 * motors for dynamic motion have been replace with MoveLinear()
41 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
42 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
43 * switch between 'VEHICLE' parameter use and general dynamics
44 * settings use.
45 */
46
47//#define SPAM
48
49using System;
50using System.Collections.Generic;
51using System.Reflection;
52using System.Runtime.InteropServices;
53using System.Threading;
54using log4net;
55using OpenMetaverse;
56using OdeAPI;
57using OpenSim.Framework;
58using OpenSim.Region.Physics.Manager;
59
60namespace OpenSim.Region.Physics.OdePlugin
61{
62 public class OdePrim : PhysicsActor
63 {
64 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
65
66 private bool m_isphysical;
67 private bool m_fakeisphysical;
68 private bool m_isphantom;
69 private bool m_fakeisphantom;
70 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
71 private bool m_fakeisVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
72
73 protected bool m_building;
74 protected bool m_forcePosOrRotation;
75 private bool m_iscolliding;
76
77 internal bool m_isSelected;
78 private bool m_delaySelect;
79 private bool m_lastdoneSelected;
80 internal bool m_outbounds;
81
82 private Quaternion m_lastorientation;
83 private Quaternion _orientation;
84
85 private Vector3 _position;
86 private Vector3 _velocity;
87 private Vector3 m_torque;
88 private Vector3 m_lastVelocity;
89 private Vector3 m_lastposition;
90 private Vector3 m_rotationalVelocity;
91 private Vector3 _size;
92 private Vector3 _acceleration;
93 private Vector3 m_angularlock = Vector3.One;
94 private IntPtr Amotor;
95
96 private Vector3 m_force;
97 private Vector3 m_forceacc;
98 private Vector3 m_angularForceacc;
99
100 private float m_invTimeStep;
101 private float m_timeStep;
102
103 private Vector3 m_PIDTarget;
104 private float m_PIDTau;
105 private bool m_usePID;
106
107 private float m_PIDHoverHeight;
108 private float m_PIDHoverTau;
109 private bool m_useHoverPID;
110 private PIDHoverType m_PIDHoverType;
111 private float m_targetHoverHeight;
112 private float m_groundHeight;
113 private float m_waterHeight;
114 private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
115
116 private int body_autodisable_frames;
117 public int bodydisablecontrol;
118 private float m_gravmod = 1.0f;
119
120 // Default we're a Geometry
121 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
122 // Default colide nonphysical don't try to colide with anything
123 private const CollisionCategories m_default_collisionFlagsNotPhysical = 0;
124
125 private const CollisionCategories m_default_collisionFlagsPhysical = (CollisionCategories.Geom |
126 CollisionCategories.Character |
127 CollisionCategories.Land |
128 CollisionCategories.VolumeDtc);
129
130// private bool m_collidesLand = true;
131 private bool m_collidesWater;
132// public bool m_returnCollisions;
133
134 private bool m_NoColide; // for now only for internal use for bad meshs
135
136
137 // Default, Collide with Other Geometries, spaces and Bodies
138 private CollisionCategories m_collisionFlags = m_default_collisionFlagsNotPhysical;
139
140 public bool m_disabled;
141
142 private uint m_localID;
143
144 private IMesh m_mesh;
145 private object m_meshlock = new object();
146 private PrimitiveBaseShape _pbs;
147
148 private UUID? m_assetID;
149 private MeshState m_meshState;
150
151 public OdeScene _parent_scene;
152
153 /// <summary>
154 /// The physics space which contains prim geometry
155 /// </summary>
156 public IntPtr m_targetSpace;
157
158 public IntPtr prim_geom;
159 public IntPtr _triMeshData;
160
161 private PhysicsActor _parent;
162
163 private List<OdePrim> childrenPrim = new List<OdePrim>();
164
165 public float m_collisionscore;
166 private int m_colliderfilter = 0;
167
168 public IntPtr collide_geom; // for objects: geom if single prim space it linkset
169
170 private float m_density;
171 private byte m_shapetype;
172 public bool _zeroFlag;
173 private bool m_lastUpdateSent;
174
175 public IntPtr Body;
176
177 private Vector3 _target_velocity;
178
179 public Vector3 m_OBBOffset;
180 public Vector3 m_OBB;
181 public float primOOBradiusSQ;
182
183 private bool m_hasOBB = true;
184
185 private float m_physCost;
186 private float m_streamCost;
187
188 public d.Mass primdMass; // prim inertia information on it's own referencial
189 float primMass; // prim own mass
190 float primVolume; // prim own volume;
191 float _mass; // object mass acording to case
192
193 public int givefakepos;
194 private Vector3 fakepos;
195 public int givefakeori;
196 private Quaternion fakeori;
197
198 private int m_eventsubscription;
199 private int m_cureventsubscription;
200 private CollisionEventUpdate CollisionEventsThisFrame = null;
201 private bool SentEmptyCollisionsEvent;
202
203 public volatile bool childPrim;
204
205 public ODEDynamics m_vehicle;
206
207 internal int m_material = (int)Material.Wood;
208 private float mu;
209 private float bounce;
210
211 /// <summary>
212 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
213 /// </summary>
214 public override bool IsPhysical // this is not reliable for internal use
215 {
216 get { return m_fakeisphysical; }
217 set
218 {
219 m_fakeisphysical = value; // we show imediatly to outside that we changed physical
220 // and also to stop imediatly some updates
221 // but real change will only happen in taintprocessing
222
223 if (!value) // Zero the remembered last velocity
224 m_lastVelocity = Vector3.Zero;
225 AddChange(changes.Physical, value);
226 }
227 }
228
229 public override bool IsVolumeDtc
230 {
231 get { return m_fakeisVolumeDetect; }
232 set
233 {
234 m_fakeisVolumeDetect = value;
235 AddChange(changes.VolumeDtc, value);
236 }
237 }
238
239 public override bool Phantom // this is not reliable for internal use
240 {
241 get { return m_fakeisphantom; }
242 set
243 {
244 m_fakeisphantom = value;
245 AddChange(changes.Phantom, value);
246 }
247 }
248
249 public override bool Building // this is not reliable for internal use
250 {
251 get { return m_building; }
252 set
253 {
254// if (value)
255// m_building = true;
256 AddChange(changes.building, value);
257 }
258 }
259
260 public override void getContactData(ref ContactData cdata)
261 {
262 cdata.mu = mu;
263 cdata.bounce = bounce;
264
265 // cdata.softcolide = m_softcolide;
266 cdata.softcolide = false;
267
268 if (m_isphysical)
269 {
270 ODEDynamics veh;
271 if (_parent != null)
272 veh = ((OdePrim)_parent).m_vehicle;
273 else
274 veh = m_vehicle;
275
276 if (veh != null && veh.Type != Vehicle.TYPE_NONE)
277 cdata.mu *= veh.FrictionFactor;
278// cdata.mu *= 0;
279 }
280 }
281
282 public override float PhysicsCost
283 {
284 get
285 {
286 return m_physCost;
287 }
288 }
289
290 public override float StreamCost
291 {
292 get
293 {
294 return m_streamCost;
295 }
296 }
297
298 public override int PhysicsActorType
299 {
300 get { return (int)ActorTypes.Prim; }
301 set { return; }
302 }
303
304 public override bool SetAlwaysRun
305 {
306 get { return false; }
307 set { return; }
308 }
309
310 public override uint LocalID
311 {
312 get { return m_localID; }
313 set { m_localID = value; }
314 }
315
316 public override PhysicsActor ParentActor
317 {
318 get
319 {
320 if (childPrim)
321 return _parent;
322 else
323 return (PhysicsActor)this;
324 }
325 }
326
327 public override bool Grabbed
328 {
329 set { return; }
330 }
331
332 public override bool Selected
333 {
334 set
335 {
336 if (value)
337 m_isSelected = value; // if true set imediatly to stop moves etc
338 AddChange(changes.Selected, value);
339 }
340 }
341
342 public override bool Flying
343 {
344 // no flying prims for you
345 get { return false; }
346 set { }
347 }
348
349 public override bool IsColliding
350 {
351 get { return m_iscolliding; }
352 set
353 {
354 if (value)
355 {
356 m_colliderfilter += 2;
357 if (m_colliderfilter > 2)
358 m_colliderfilter = 2;
359 }
360 else
361 {
362 m_colliderfilter--;
363 if (m_colliderfilter < 0)
364 m_colliderfilter = 0;
365 }
366
367 if (m_colliderfilter == 0)
368 m_iscolliding = false;
369 else
370 m_iscolliding = true;
371 }
372 }
373
374 public override bool CollidingGround
375 {
376 get { return false; }
377 set { return; }
378 }
379
380 public override bool CollidingObj
381 {
382 get { return false; }
383 set { return; }
384 }
385
386
387 public override bool ThrottleUpdates {get;set;}
388
389 public override bool Stopped
390 {
391 get { return _zeroFlag; }
392 }
393
394 public override Vector3 Position
395 {
396 get
397 {
398 if (givefakepos > 0)
399 return fakepos;
400 else
401 return _position;
402 }
403
404 set
405 {
406 fakepos = value;
407 givefakepos++;
408 AddChange(changes.Position, value);
409 }
410 }
411
412 public override Vector3 Size
413 {
414 get { return _size; }
415 set
416 {
417 if (value.IsFinite())
418 {
419 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, _pbs, value, m_shapetype);
420 }
421 else
422 {
423 m_log.WarnFormat("[PHYSICS]: Got NaN Size on object {0}", Name);
424 }
425 }
426 }
427
428 public override float Mass
429 {
430 get { return primMass; }
431 }
432
433 public override Vector3 Force
434 {
435 get { return m_force; }
436 set
437 {
438 if (value.IsFinite())
439 {
440 AddChange(changes.Force, value);
441 }
442 else
443 {
444 m_log.WarnFormat("[PHYSICS]: NaN in Force Applied to an Object {0}", Name);
445 }
446 }
447 }
448
449 public override void SetVolumeDetect(int param)
450 {
451 m_fakeisVolumeDetect = (param != 0);
452 AddChange(changes.VolumeDtc, m_fakeisVolumeDetect);
453 }
454
455 public override Vector3 GeometricCenter
456 {
457 // this is not real geometric center but a average of positions relative to root prim acording to
458 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
459 // ignoring tortured prims details since sl also seems to ignore
460 // so no real use in doing it on physics
461 get
462 {
463 return Vector3.Zero;
464 }
465 }
466
467 public override Vector3 CenterOfMass
468 {
469 get
470 {
471 lock (_parent_scene.OdeLock)
472 {
473 d.Vector3 dtmp;
474 if (!childPrim && Body != IntPtr.Zero)
475 {
476 dtmp = d.BodyGetPosition(Body);
477 return new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
478 }
479 else if (prim_geom != IntPtr.Zero)
480 {
481 d.Quaternion dq;
482 d.GeomCopyQuaternion(prim_geom, out dq);
483 Quaternion q;
484 q.X = dq.X;
485 q.Y = dq.Y;
486 q.Z = dq.Z;
487 q.W = dq.W;
488
489 Vector3 Ptot = m_OBBOffset * q;
490 dtmp = d.GeomGetPosition(prim_geom);
491 Ptot.X += dtmp.X;
492 Ptot.Y += dtmp.Y;
493 Ptot.Z += dtmp.Z;
494
495 // if(childPrim) we only know about physical linksets
496 return Ptot;
497/*
498 float tmass = _mass;
499 Ptot *= tmass;
500
501 float m;
502
503 foreach (OdePrim prm in childrenPrim)
504 {
505 m = prm._mass;
506 Ptot += prm.CenterOfMass * m;
507 tmass += m;
508 }
509
510 if (tmass == 0)
511 tmass = 0;
512 else
513 tmass = 1.0f / tmass;
514
515 Ptot *= tmass;
516 return Ptot;
517*/
518 }
519 else
520 return _position;
521 }
522 }
523 }
524
525 public override Vector3 OOBsize
526 {
527 get
528 {
529 return m_OBB;
530 }
531 }
532
533 public override Vector3 OOBoffset
534 {
535 get
536 {
537 return m_OBBOffset;
538 }
539 }
540
541 public override float OOBRadiusSQ
542 {
543 get
544 {
545 return primOOBradiusSQ;
546 }
547 }
548
549 public override PrimitiveBaseShape Shape
550 {
551 set
552 {
553// AddChange(changes.Shape, value);
554 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, value, _size, m_shapetype);
555 }
556 }
557
558 public override byte PhysicsShapeType
559 {
560 get
561 {
562 return m_shapetype;
563 }
564 set
565 {
566 m_shapetype = value;
567 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, _pbs, _size, value);
568 }
569 }
570
571 public override Vector3 Velocity
572 {
573 get
574 {
575 if (_zeroFlag)
576 return Vector3.Zero;
577 return _velocity;
578 }
579 set
580 {
581 if (value.IsFinite())
582 {
583 AddChange(changes.Velocity, value);
584 }
585 else
586 {
587 m_log.WarnFormat("[PHYSICS]: Got NaN Velocity in Object {0}", Name);
588 }
589
590 }
591 }
592
593 public override Vector3 Torque
594 {
595 get
596 {
597 if (!IsPhysical || Body == IntPtr.Zero)
598 return Vector3.Zero;
599
600 return m_torque;
601 }
602
603 set
604 {
605 if (value.IsFinite())
606 {
607 AddChange(changes.Torque, value);
608 }
609 else
610 {
611 m_log.WarnFormat("[PHYSICS]: Got NaN Torque in Object {0}", Name);
612 }
613 }
614 }
615
616 public override float CollisionScore
617 {
618 get { return m_collisionscore; }
619 set { m_collisionscore = value; }
620 }
621
622 public override bool Kinematic
623 {
624 get { return false; }
625 set { }
626 }
627
628 public override Quaternion Orientation
629 {
630 get
631 {
632 if (givefakeori > 0)
633 return fakeori;
634 else
635
636 return _orientation;
637 }
638 set
639 {
640 if (QuaternionIsFinite(value))
641 {
642 fakeori = value;
643 givefakeori++;
644
645 value.Normalize();
646
647 AddChange(changes.Orientation, value);
648 }
649 else
650 m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name);
651
652 }
653 }
654
655 public override Vector3 Acceleration
656 {
657 get { return _acceleration; }
658 set { }
659 }
660
661 public override Vector3 RotationalVelocity
662 {
663 get
664 {
665 Vector3 pv = Vector3.Zero;
666 if (_zeroFlag)
667 return pv;
668
669 if (m_rotationalVelocity.ApproxEquals(pv, 0.0001f))
670 return pv;
671
672 return m_rotationalVelocity;
673 }
674 set
675 {
676 if (value.IsFinite())
677 {
678 AddChange(changes.AngVelocity, value);
679 }
680 else
681 {
682 m_log.WarnFormat("[PHYSICS]: Got NaN RotationalVelocity in Object {0}", Name);
683 }
684 }
685 }
686
687 public override float Buoyancy
688 {
689 get { return m_buoyancy; }
690 set
691 {
692 AddChange(changes.Buoyancy,value);
693 }
694 }
695
696 public override bool FloatOnWater
697 {
698 set
699 {
700 AddChange(changes.CollidesWater, value);
701 }
702 }
703
704 public override Vector3 PIDTarget
705 {
706 set
707 {
708 if (value.IsFinite())
709 {
710 AddChange(changes.PIDTarget,value);
711 }
712 else
713 m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name);
714 }
715 }
716
717 public override bool PIDActive
718 {
719 set
720 {
721 AddChange(changes.PIDActive,value);
722 }
723 }
724
725 public override float PIDTau
726 {
727 set
728 {
729 float tmp = 0;
730 if (value > 0)
731 {
732 float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
733 if (value < mint)
734 tmp = mint;
735 else
736 tmp = value;
737 }
738 AddChange(changes.PIDTau,tmp);
739 }
740 }
741
742 public override float PIDHoverHeight
743 {
744 set
745 {
746 AddChange(changes.PIDHoverHeight,value);
747 }
748 }
749 public override bool PIDHoverActive
750 {
751 set
752 {
753 AddChange(changes.PIDHoverActive, value);
754 }
755 }
756
757 public override PIDHoverType PIDHoverType
758 {
759 set
760 {
761 AddChange(changes.PIDHoverType,value);
762 }
763 }
764
765 public override float PIDHoverTau
766 {
767 set
768 {
769 float tmp =0;
770 if (value > 0)
771 {
772 float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
773 if (value < mint)
774 tmp = mint;
775 else
776 tmp = value;
777 }
778 AddChange(changes.PIDHoverTau, tmp);
779 }
780 }
781
782 public override Quaternion APIDTarget { set { return; } }
783
784 public override bool APIDActive { set { return; } }
785
786 public override float APIDStrength { set { return; } }
787
788 public override float APIDDamping { set { return; } }
789
790 public override int VehicleType
791 {
792 // we may need to put a fake on this
793 get
794 {
795 if (m_vehicle == null)
796 return (int)Vehicle.TYPE_NONE;
797 else
798 return (int)m_vehicle.Type;
799 }
800 set
801 {
802 AddChange(changes.VehicleType, value);
803 }
804 }
805
806 public override void VehicleFloatParam(int param, float value)
807 {
808 strVehicleFloatParam fp = new strVehicleFloatParam();
809 fp.param = param;
810 fp.value = value;
811 AddChange(changes.VehicleFloatParam, fp);
812 }
813
814 public override void VehicleVectorParam(int param, Vector3 value)
815 {
816 strVehicleVectorParam fp = new strVehicleVectorParam();
817 fp.param = param;
818 fp.value = value;
819 AddChange(changes.VehicleVectorParam, fp);
820 }
821
822 public override void VehicleRotationParam(int param, Quaternion value)
823 {
824 strVehicleQuatParam fp = new strVehicleQuatParam();
825 fp.param = param;
826 fp.value = value;
827 AddChange(changes.VehicleRotationParam, fp);
828 }
829
830 public override void VehicleFlags(int param, bool value)
831 {
832 strVehicleBoolParam bp = new strVehicleBoolParam();
833 bp.param = param;
834 bp.value = value;
835 AddChange(changes.VehicleFlags, bp);
836 }
837
838 public override void SetVehicle(object vdata)
839 {
840 AddChange(changes.SetVehicle, vdata);
841 }
842 public void SetAcceleration(Vector3 accel)
843 {
844 _acceleration = accel;
845 }
846
847 public override void AddForce(Vector3 force, bool pushforce)
848 {
849 if (force.IsFinite())
850 {
851 if(pushforce)
852 AddChange(changes.AddForce, force);
853 else // a impulse
854 AddChange(changes.AddForce, force * m_invTimeStep);
855 }
856 else
857 {
858 m_log.WarnFormat("[PHYSICS]: Got Invalid linear force vector from Scene in Object {0}", Name);
859 }
860 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
861 }
862
863 public override void AddAngularForce(Vector3 force, bool pushforce)
864 {
865 if (force.IsFinite())
866 {
867// if(pushforce) for now applyrotationimpulse seems more happy applied as a force
868 AddChange(changes.AddAngForce, force);
869// else // a impulse
870// AddChange(changes.AddAngForce, force * m_invTimeStep);
871 }
872 else
873 {
874 m_log.WarnFormat("[PHYSICS]: Got Invalid Angular force vector from Scene in Object {0}", Name);
875 }
876 }
877
878 public override void CrossingFailure()
879 {
880 if (m_outbounds)
881 {
882 _position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
883 _position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
884 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
885
886 m_lastposition = _position;
887 _velocity.X = 0;
888 _velocity.Y = 0;
889 _velocity.Z = 0;
890
891 m_lastVelocity = _velocity;
892 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
893 m_vehicle.Stop();
894
895 if(Body != IntPtr.Zero)
896 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
897 if (prim_geom != IntPtr.Zero)
898 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
899
900 m_outbounds = false;
901 changeDisable(false);
902 base.RequestPhysicsterseUpdate();
903 }
904 }
905
906 public override void SetMomentum(Vector3 momentum)
907 {
908 }
909
910 public override void SetMaterial(int pMaterial)
911 {
912 m_material = pMaterial;
913 mu = _parent_scene.m_materialContactsData[pMaterial].mu;
914 bounce = _parent_scene.m_materialContactsData[pMaterial].bounce;
915 }
916
917 public override float Density
918 {
919 get
920 {
921 return m_density * 100f;
922 }
923 set
924 {
925 m_density = value / 100f;
926 // for not prim mass is not updated since this implies full rebuild of body inertia TODO
927 }
928 }
929 public override float GravModifier
930 {
931 get
932 {
933 return m_gravmod;
934 }
935 set
936 {
937 m_gravmod = value;
938 if (m_vehicle != null)
939 m_vehicle.GravMod = m_gravmod;
940 }
941 }
942 public override float Friction
943 {
944 get
945 {
946 return mu;
947 }
948 set
949 {
950 mu = value;
951 }
952 }
953
954 public override float Restitution
955 {
956 get
957 {
958 return bounce;
959 }
960 set
961 {
962 bounce = value;
963 }
964 }
965
966 public void setPrimForRemoval()
967 {
968 AddChange(changes.Remove, null);
969 }
970
971 public override void link(PhysicsActor obj)
972 {
973 AddChange(changes.Link, obj);
974 }
975
976 public override void delink()
977 {
978 AddChange(changes.DeLink, null);
979 }
980
981 public override void LockAngularMotion(Vector3 axis)
982 {
983 // reverse the zero/non zero values for ODE.
984 if (axis.IsFinite())
985 {
986 axis.X = (axis.X > 0) ? 1f : 0f;
987 axis.Y = (axis.Y > 0) ? 1f : 0f;
988 axis.Z = (axis.Z > 0) ? 1f : 0f;
989// m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
990 AddChange(changes.AngLock, axis);
991 }
992 else
993 {
994 m_log.WarnFormat("[PHYSICS]: Got NaN locking axis from Scene on Object {0}", Name);
995 }
996 }
997
998 public override void SubscribeEvents(int ms)
999 {
1000 m_eventsubscription = ms;
1001 m_cureventsubscription = 0;
1002 if (CollisionEventsThisFrame == null)
1003 CollisionEventsThisFrame = new CollisionEventUpdate();
1004 SentEmptyCollisionsEvent = false;
1005 }
1006
1007 public override void UnSubscribeEvents()
1008 {
1009 if (CollisionEventsThisFrame != null)
1010 {
1011 CollisionEventsThisFrame.Clear();
1012 CollisionEventsThisFrame = null;
1013 }
1014 m_eventsubscription = 0;
1015 _parent_scene.RemoveCollisionEventReporting(this);
1016 }
1017
1018 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1019 {
1020 if (CollisionEventsThisFrame == null)
1021 CollisionEventsThisFrame = new CollisionEventUpdate();
1022// if(CollisionEventsThisFrame.Count < 32)
1023 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1024 }
1025
1026 public void SendCollisions()
1027 {
1028 if (CollisionEventsThisFrame == null)
1029 return;
1030
1031 if (m_cureventsubscription < m_eventsubscription)
1032 return;
1033
1034 m_cureventsubscription = 0;
1035
1036 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
1037
1038 if (!SentEmptyCollisionsEvent || ncolisions > 0)
1039 {
1040 base.SendCollisionUpdate(CollisionEventsThisFrame);
1041
1042 if (ncolisions == 0)
1043 {
1044 SentEmptyCollisionsEvent = true;
1045 _parent_scene.RemoveCollisionEventReporting(this);
1046 }
1047 else
1048 {
1049 SentEmptyCollisionsEvent = false;
1050 CollisionEventsThisFrame.Clear();
1051 }
1052 }
1053 }
1054
1055 internal void AddCollisionFrameTime(int t)
1056 {
1057 if (m_cureventsubscription < 50000)
1058 m_cureventsubscription += t;
1059 }
1060
1061 public override bool SubscribedEvents()
1062 {
1063 if (m_eventsubscription > 0)
1064 return true;
1065 return false;
1066 }
1067
1068 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
1069 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID)
1070 {
1071 Name = primName;
1072 LocalID = plocalID;
1073
1074 m_vehicle = null;
1075
1076 if (!pos.IsFinite())
1077 {
1078 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
1079 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
1080 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Position for {0}", Name);
1081 }
1082 _position = pos;
1083 givefakepos = 0;
1084
1085 m_timeStep = parent_scene.ODE_STEPSIZE;
1086 m_invTimeStep = 1f / m_timeStep;
1087
1088 m_density = parent_scene.geomDefaultDensity;
1089 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
1090
1091 prim_geom = IntPtr.Zero;
1092 collide_geom = IntPtr.Zero;
1093 Body = IntPtr.Zero;
1094
1095 if (!size.IsFinite())
1096 {
1097 size = new Vector3(0.5f, 0.5f, 0.5f);
1098 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Size for {0}", Name);
1099 }
1100
1101 if (size.X <= 0) size.X = 0.01f;
1102 if (size.Y <= 0) size.Y = 0.01f;
1103 if (size.Z <= 0) size.Z = 0.01f;
1104
1105 _size = size;
1106
1107 if (!QuaternionIsFinite(rotation))
1108 {
1109 rotation = Quaternion.Identity;
1110 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Rotation for {0}", Name);
1111 }
1112
1113 _orientation = rotation;
1114 givefakeori = 0;
1115
1116 _pbs = pbs;
1117
1118 _parent_scene = parent_scene;
1119 m_targetSpace = IntPtr.Zero;
1120
1121 if (pos.Z < 0)
1122 {
1123 m_isphysical = false;
1124 }
1125 else
1126 {
1127 m_isphysical = pisPhysical;
1128 }
1129 m_fakeisphysical = m_isphysical;
1130
1131 m_isVolumeDetect = false;
1132 m_fakeisVolumeDetect = false;
1133
1134 m_force = Vector3.Zero;
1135
1136 m_iscolliding = false;
1137 m_colliderfilter = 0;
1138 m_NoColide = false;
1139
1140 _triMeshData = IntPtr.Zero;
1141
1142 m_shapetype = _shapeType;
1143
1144 m_lastdoneSelected = false;
1145 m_isSelected = false;
1146 m_delaySelect = false;
1147
1148 m_isphantom = pisPhantom;
1149 m_fakeisphantom = pisPhantom;
1150
1151 mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu;
1152 bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce;
1153
1154 m_building = true; // control must set this to false when done
1155
1156 // get basic mass parameters
1157 ODEPhysRepData repData = _parent_scene.m_meshWorker.NewActorPhysRep(this, _pbs, _size, m_shapetype);
1158
1159 primVolume = repData.volume;
1160 m_OBB = repData.OBB;
1161 m_OBBOffset = repData.OBBOffset;
1162
1163 UpdatePrimBodyData();
1164 }
1165
1166 private void resetCollisionAccounting()
1167 {
1168 m_collisionscore = 0;
1169 }
1170
1171 private void UpdateCollisionCatFlags()
1172 {
1173 if(m_isphysical && m_disabled)
1174 {
1175 m_collisionCategories = 0;
1176 m_collisionFlags = 0;
1177 }
1178
1179 else if (m_isSelected)
1180 {
1181 m_collisionCategories = CollisionCategories.Selected;
1182 m_collisionFlags = 0;
1183 }
1184
1185 else if (m_isVolumeDetect)
1186 {
1187 m_collisionCategories = CollisionCategories.VolumeDtc;
1188 if (m_isphysical)
1189 m_collisionFlags = CollisionCategories.Geom | CollisionCategories.Character;
1190 else
1191 m_collisionFlags = 0;
1192 }
1193 else if (m_isphantom)
1194 {
1195 m_collisionCategories = CollisionCategories.Phantom;
1196 if (m_isphysical)
1197 m_collisionFlags = CollisionCategories.Land;
1198 else
1199 m_collisionFlags = 0;
1200 }
1201 else
1202 {
1203 m_collisionCategories = CollisionCategories.Geom;
1204 if (m_isphysical)
1205 m_collisionFlags = m_default_collisionFlagsPhysical;
1206 else
1207 m_collisionFlags = m_default_collisionFlagsNotPhysical;
1208 }
1209 }
1210
1211 private void ApplyCollisionCatFlags()
1212 {
1213 if (prim_geom != IntPtr.Zero)
1214 {
1215 if (!childPrim && childrenPrim.Count > 0)
1216 {
1217 foreach (OdePrim prm in childrenPrim)
1218 {
1219 if (m_isphysical && m_disabled)
1220 {
1221 prm.m_collisionCategories = 0;
1222 prm.m_collisionFlags = 0;
1223 }
1224 else
1225 {
1226 // preserve some
1227 if (prm.m_isSelected)
1228 {
1229 prm.m_collisionCategories = CollisionCategories.Selected;
1230 prm.m_collisionFlags = 0;
1231 }
1232 else if (prm.m_isVolumeDetect)
1233 {
1234 prm.m_collisionCategories = CollisionCategories.VolumeDtc;
1235 if (m_isphysical)
1236 prm.m_collisionFlags = CollisionCategories.Geom | CollisionCategories.Character;
1237 else
1238 prm.m_collisionFlags = 0;
1239 }
1240 else if (prm.m_isphantom)
1241 {
1242 prm.m_collisionCategories = CollisionCategories.Phantom;
1243 if (m_isphysical)
1244 prm.m_collisionFlags = CollisionCategories.Land;
1245 else
1246 prm.m_collisionFlags = 0;
1247 }
1248 else
1249 {
1250 prm.m_collisionCategories = m_collisionCategories;
1251 prm.m_collisionFlags = m_collisionFlags;
1252 }
1253 }
1254
1255 if (prm.prim_geom != IntPtr.Zero)
1256 {
1257 if (prm.m_NoColide)
1258 {
1259 d.GeomSetCategoryBits(prm.prim_geom, 0);
1260 if (m_isphysical)
1261 d.GeomSetCollideBits(prm.prim_geom, (int)CollisionCategories.Land);
1262 else
1263 d.GeomSetCollideBits(prm.prim_geom, 0);
1264 }
1265 else
1266 {
1267 d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
1268 d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
1269 }
1270 }
1271 }
1272 }
1273
1274 if (m_NoColide)
1275 {
1276 d.GeomSetCategoryBits(prim_geom, 0);
1277 d.GeomSetCollideBits(prim_geom, (uint)CollisionCategories.Land);
1278 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
1279 {
1280 d.GeomSetCategoryBits(collide_geom, 0);
1281 d.GeomSetCollideBits(collide_geom, (uint)CollisionCategories.Land);
1282 }
1283 }
1284 else
1285 {
1286 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1287 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1288 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
1289 {
1290 d.GeomSetCategoryBits(collide_geom, (uint)m_collisionCategories);
1291 d.GeomSetCollideBits(collide_geom, (uint)m_collisionFlags);
1292 }
1293 }
1294 }
1295 }
1296
1297 private void createAMotor(Vector3 axis)
1298 {
1299 if (Body == IntPtr.Zero)
1300 return;
1301
1302 if (Amotor != IntPtr.Zero)
1303 {
1304 d.JointDestroy(Amotor);
1305 Amotor = IntPtr.Zero;
1306 }
1307
1308 int axisnum = 3 - (int)(axis.X + axis.Y + axis.Z);
1309
1310 if (axisnum <= 0)
1311 return;
1312
1313 // stop it
1314 d.BodySetTorque(Body, 0, 0, 0);
1315 d.BodySetAngularVel(Body, 0, 0, 0);
1316
1317 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
1318 d.JointAttach(Amotor, Body, IntPtr.Zero);
1319
1320 d.JointSetAMotorMode(Amotor, 0);
1321
1322 d.JointSetAMotorNumAxes(Amotor, axisnum);
1323
1324 // get current orientation to lock
1325
1326 d.Quaternion dcur = d.BodyGetQuaternion(Body);
1327 Quaternion curr; // crap convertion between identical things
1328 curr.X = dcur.X;
1329 curr.Y = dcur.Y;
1330 curr.Z = dcur.Z;
1331 curr.W = dcur.W;
1332 Vector3 ax;
1333
1334 int i = 0;
1335 int j = 0;
1336 if (axis.X == 0)
1337 {
1338 ax = (new Vector3(1, 0, 0)) * curr; // rotate world X to current local X
1339 // ODE should do this with axis relative to body 1 but seems to fail
1340 d.JointSetAMotorAxis(Amotor, 0, 0, ax.X, ax.Y, ax.Z);
1341 d.JointSetAMotorAngle(Amotor, 0, 0);
1342 d.JointSetAMotorParam(Amotor, (int)d.JointParam.LoStop, 0f);
1343 d.JointSetAMotorParam(Amotor, (int)d.JointParam.HiStop, 0f);
1344 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0);
1345 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f);
1346 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f);
1347 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f);
1348 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopCFM, 0f);
1349 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopERP, 0.8f);
1350 i++;
1351 j = 256; // move to next axis set
1352 }
1353
1354 if (axis.Y == 0)
1355 {
1356 ax = (new Vector3(0, 1, 0)) * curr;
1357 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
1358 d.JointSetAMotorAngle(Amotor, i, 0);
1359 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f);
1360 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f);
1361 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
1362 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
1363 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
1364 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
1365 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
1366 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
1367 i++;
1368 j += 256;
1369 }
1370
1371 if (axis.Z == 0)
1372 {
1373 ax = (new Vector3(0, 0, 1)) * curr;
1374 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
1375 d.JointSetAMotorAngle(Amotor, i, 0);
1376 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f);
1377 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f);
1378 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
1379 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
1380 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
1381 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
1382 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
1383 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
1384 }
1385 }
1386
1387
1388 private void SetGeom(IntPtr geom)
1389 {
1390 prim_geom = geom;
1391 //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
1392 if (prim_geom != IntPtr.Zero)
1393 {
1394
1395 if (m_NoColide)
1396 {
1397 d.GeomSetCategoryBits(prim_geom, 0);
1398 if (m_isphysical)
1399 {
1400 d.GeomSetCollideBits(prim_geom, (uint)CollisionCategories.Land);
1401 }
1402 else
1403 {
1404 d.GeomSetCollideBits(prim_geom, 0);
1405 d.GeomDisable(prim_geom);
1406 }
1407 }
1408 else
1409 {
1410 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1411 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1412 }
1413
1414 UpdatePrimBodyData();
1415 _parent_scene.actor_name_map[prim_geom] = this;
1416
1417/*
1418// debug
1419 d.AABB aabb;
1420 d.GeomGetAABB(prim_geom, out aabb);
1421 float x = aabb.MaxX - aabb.MinX;
1422 float y = aabb.MaxY - aabb.MinY;
1423 float z = aabb.MaxZ - aabb.MinZ;
1424 if( x > 60.0f || y > 60.0f || z > 60.0f)
1425 m_log.WarnFormat("[PHYSICS]: large prim geo {0},size {1}, AABBsize <{2},{3},{4}, mesh {5} at {6}",
1426 Name, _size.ToString(), x, y, z, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh", _position.ToString());
1427 else if (x < 0.001f || y < 0.001f || z < 0.001f)
1428 m_log.WarnFormat("[PHYSICS]: small prim geo {0},size {1}, AABBsize <{2},{3},{4}, mesh {5} at {6}",
1429 Name, _size.ToString(), x, y, z, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh", _position.ToString());
1430
1431//
1432*/
1433
1434 }
1435 else
1436 m_log.Warn("Setting bad Geom");
1437 }
1438
1439 private bool GetMeshGeom()
1440 {
1441 IntPtr vertices, indices;
1442 int vertexCount, indexCount;
1443 int vertexStride, triStride;
1444
1445 IMesh mesh = m_mesh;
1446
1447 if (mesh == null)
1448 return false;
1449
1450 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount);
1451 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount);
1452
1453 if (vertexCount == 0 || indexCount == 0)
1454 {
1455 m_log.WarnFormat("[PHYSICS]: Invalid mesh data on OdePrim {0}, mesh {1} at {2}",
1456 Name, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh",_position.ToString());
1457
1458 m_hasOBB = false;
1459 m_OBBOffset = Vector3.Zero;
1460 m_OBB = _size * 0.5f;
1461
1462 m_physCost = 0.1f;
1463 m_streamCost = 1.0f;
1464
1465 _parent_scene.mesher.ReleaseMesh(mesh);
1466 m_meshState = MeshState.MeshFailed;
1467 m_mesh = null;
1468 return false;
1469 }
1470
1471 IntPtr geo = IntPtr.Zero;
1472
1473 try
1474 {
1475 _triMeshData = d.GeomTriMeshDataCreate();
1476
1477 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1478 d.GeomTriMeshDataPreprocess(_triMeshData);
1479
1480 geo = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
1481 }
1482
1483 catch (Exception e)
1484 {
1485 m_log.ErrorFormat("[PHYSICS]: SetGeom Mesh failed for {0} exception: {1}", Name, e);
1486 if (_triMeshData != IntPtr.Zero)
1487 {
1488 try
1489 {
1490 d.GeomTriMeshDataDestroy(_triMeshData);
1491 }
1492 catch
1493 {
1494 }
1495 }
1496 _triMeshData = IntPtr.Zero;
1497
1498 m_hasOBB = false;
1499 m_OBBOffset = Vector3.Zero;
1500 m_OBB = _size * 0.5f;
1501 m_physCost = 0.1f;
1502 m_streamCost = 1.0f;
1503
1504 _parent_scene.mesher.ReleaseMesh(mesh);
1505 m_meshState = MeshState.MeshFailed;
1506 m_mesh = null;
1507 return false;
1508 }
1509
1510 m_physCost = 0.0013f * (float)indexCount;
1511 // todo
1512 m_streamCost = 1.0f;
1513
1514 SetGeom(geo);
1515
1516 return true;
1517 }
1518
1519 private void CreateGeom()
1520 {
1521 bool hasMesh = false;
1522
1523 m_NoColide = false;
1524
1525 if ((m_meshState & MeshState.MeshNoColide) != 0)
1526 m_NoColide = true;
1527
1528 else if(m_mesh != null)
1529 {
1530 if (GetMeshGeom())
1531 hasMesh = true;
1532 else
1533 m_NoColide = true;
1534 }
1535
1536
1537 if (!hasMesh)
1538 {
1539 IntPtr geo = IntPtr.Zero;
1540
1541 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
1542 && _size.X == _size.Y && _size.Y == _size.Z)
1543 { // it's a sphere
1544 try
1545 {
1546 geo = d.CreateSphere(m_targetSpace, _size.X * 0.5f);
1547 }
1548 catch (Exception e)
1549 {
1550 m_log.WarnFormat("[PHYSICS]: Create sphere failed: {0}", e);
1551 return;
1552 }
1553 }
1554 else
1555 {// do it as a box
1556 try
1557 {
1558 geo = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1559 }
1560 catch (Exception e)
1561 {
1562 m_log.Warn("[PHYSICS]: Create box failed: {0}", e);
1563 return;
1564 }
1565 }
1566 m_physCost = 0.1f;
1567 m_streamCost = 1.0f;
1568 SetGeom(geo);
1569 }
1570 }
1571
1572 private void RemoveGeom()
1573 {
1574 if (prim_geom != IntPtr.Zero)
1575 {
1576 _parent_scene.actor_name_map.Remove(prim_geom);
1577
1578 try
1579 {
1580 d.GeomDestroy(prim_geom);
1581 if (_triMeshData != IntPtr.Zero)
1582 {
1583 d.GeomTriMeshDataDestroy(_triMeshData);
1584 _triMeshData = IntPtr.Zero;
1585 }
1586 }
1587 catch (Exception e)
1588 {
1589 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction failed for {0} exception {1}", Name, e);
1590 }
1591
1592 prim_geom = IntPtr.Zero;
1593 collide_geom = IntPtr.Zero;
1594 m_targetSpace = IntPtr.Zero;
1595 }
1596 else
1597 {
1598 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction BAD {0}", Name);
1599 }
1600
1601 lock (m_meshlock)
1602 {
1603 if (m_mesh != null)
1604 {
1605 _parent_scene.mesher.ReleaseMesh(m_mesh);
1606 m_mesh = null;
1607 }
1608 }
1609
1610 Body = IntPtr.Zero;
1611 m_hasOBB = false;
1612 }
1613
1614 //sets non physical prim m_targetSpace to right space in spaces grid for static prims
1615 // should only be called for non physical prims unless they are becoming non physical
1616 private void SetInStaticSpace(OdePrim prim)
1617 {
1618 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim._position, prim.m_targetSpace);
1619 prim.m_targetSpace = targetSpace;
1620 collide_geom = IntPtr.Zero;
1621 }
1622
1623 public void enableBodySoft()
1624 {
1625 m_disabled = false;
1626 if (!childPrim && !m_isSelected)
1627 {
1628 if (m_isphysical && Body != IntPtr.Zero)
1629 {
1630 UpdateCollisionCatFlags();
1631 ApplyCollisionCatFlags();
1632
1633 d.BodyEnable(Body);
1634 }
1635 }
1636 resetCollisionAccounting();
1637 }
1638
1639 private void disableBodySoft()
1640 {
1641 m_disabled = true;
1642 if (!childPrim)
1643 {
1644 if (m_isphysical && Body != IntPtr.Zero)
1645 {
1646 if (m_isSelected)
1647 m_collisionFlags = CollisionCategories.Selected;
1648 else
1649 m_collisionCategories = 0;
1650 m_collisionFlags = 0;
1651 ApplyCollisionCatFlags();
1652 d.BodyDisable(Body);
1653 }
1654 }
1655 }
1656
1657 private void MakeBody()
1658 {
1659 if (!m_isphysical) // only physical get bodies
1660 return;
1661
1662 if (childPrim) // child prims don't get bodies;
1663 return;
1664
1665 if (m_building)
1666 return;
1667
1668 if (prim_geom == IntPtr.Zero)
1669 {
1670 m_log.Warn("[PHYSICS]: Unable to link the linkset. Root has no geom yet");
1671 return;
1672 }
1673
1674 if (Body != IntPtr.Zero)
1675 {
1676 DestroyBody();
1677 m_log.Warn("[PHYSICS]: MakeBody called having a body");
1678 }
1679
1680 if (d.GeomGetBody(prim_geom) != IntPtr.Zero)
1681 {
1682 d.GeomSetBody(prim_geom, IntPtr.Zero);
1683 m_log.Warn("[PHYSICS]: MakeBody root geom already had a body");
1684 }
1685
1686 d.Matrix3 mymat = new d.Matrix3();
1687 d.Quaternion myrot = new d.Quaternion();
1688 d.Mass objdmass = new d.Mass { };
1689
1690 Body = d.BodyCreate(_parent_scene.world);
1691
1692 objdmass = primdMass;
1693
1694 // rotate inertia
1695 myrot.X = _orientation.X;
1696 myrot.Y = _orientation.Y;
1697 myrot.Z = _orientation.Z;
1698 myrot.W = _orientation.W;
1699
1700 d.RfromQ(out mymat, ref myrot);
1701 d.MassRotate(ref objdmass, ref mymat);
1702
1703 // set the body rotation
1704 d.BodySetRotation(Body, ref mymat);
1705
1706 // recompute full object inertia if needed
1707 if (childrenPrim.Count > 0)
1708 {
1709 d.Matrix3 mat = new d.Matrix3();
1710 d.Quaternion quat = new d.Quaternion();
1711 d.Mass tmpdmass = new d.Mass { };
1712 Vector3 rcm;
1713
1714 rcm.X = _position.X;
1715 rcm.Y = _position.Y;
1716 rcm.Z = _position.Z;
1717
1718 lock (childrenPrim)
1719 {
1720 foreach (OdePrim prm in childrenPrim)
1721 {
1722 if (prm.prim_geom == IntPtr.Zero)
1723 {
1724 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements, skipping it. No geom yet");
1725 continue;
1726 }
1727
1728 tmpdmass = prm.primdMass;
1729
1730 // apply prim current rotation to inertia
1731 quat.X = prm._orientation.X;
1732 quat.Y = prm._orientation.Y;
1733 quat.Z = prm._orientation.Z;
1734 quat.W = prm._orientation.W;
1735 d.RfromQ(out mat, ref quat);
1736 d.MassRotate(ref tmpdmass, ref mat);
1737
1738 Vector3 ppos = prm._position;
1739 ppos.X -= rcm.X;
1740 ppos.Y -= rcm.Y;
1741 ppos.Z -= rcm.Z;
1742 // refer inertia to root prim center of mass position
1743 d.MassTranslate(ref tmpdmass,
1744 ppos.X,
1745 ppos.Y,
1746 ppos.Z);
1747
1748 d.MassAdd(ref objdmass, ref tmpdmass); // add to total object inertia
1749 // fix prim colision cats
1750
1751 if (d.GeomGetBody(prm.prim_geom) != IntPtr.Zero)
1752 {
1753 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1754 m_log.Warn("[PHYSICS]: MakeBody child geom already had a body");
1755 }
1756
1757 d.GeomClearOffset(prm.prim_geom);
1758 d.GeomSetBody(prm.prim_geom, Body);
1759 prm.Body = Body;
1760 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); // set relative rotation
1761 }
1762 }
1763 }
1764
1765 d.GeomClearOffset(prim_geom); // make sure we don't have a hidden offset
1766 // associate root geom with body
1767 d.GeomSetBody(prim_geom, Body);
1768
1769 d.BodySetPosition(Body, _position.X + objdmass.c.X, _position.Y + objdmass.c.Y, _position.Z + objdmass.c.Z);
1770 d.GeomSetOffsetWorldPosition(prim_geom, _position.X, _position.Y, _position.Z);
1771
1772 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
1773 myrot.X = -myrot.X;
1774 myrot.Y = -myrot.Y;
1775 myrot.Z = -myrot.Z;
1776
1777 d.RfromQ(out mymat, ref myrot);
1778 d.MassRotate(ref objdmass, ref mymat);
1779
1780 d.BodySetMass(Body, ref objdmass);
1781 _mass = objdmass.mass;
1782
1783 // disconnect from world gravity so we can apply buoyancy
1784 d.BodySetGravityMode(Body, false);
1785
1786 d.BodySetAutoDisableFlag(Body, true);
1787 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1788 d.BodySetAutoDisableAngularThreshold(Body, 0.01f);
1789 d.BodySetAutoDisableLinearThreshold(Body, 0.01f);
1790 d.BodySetDamping(Body, .005f, .001f);
1791
1792 if (m_targetSpace != IntPtr.Zero)
1793 {
1794 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1795 if (d.SpaceQuery(m_targetSpace, prim_geom))
1796 d.SpaceRemove(m_targetSpace, prim_geom);
1797 }
1798
1799 if (childrenPrim.Count == 0)
1800 {
1801 collide_geom = prim_geom;
1802 m_targetSpace = _parent_scene.ActiveSpace;
1803 }
1804 else
1805 {
1806 m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace);
1807 d.HashSpaceSetLevels(m_targetSpace, -2, 8);
1808 d.SpaceSetSublevel(m_targetSpace, 3);
1809 d.SpaceSetCleanup(m_targetSpace, false);
1810
1811 d.GeomSetCategoryBits(m_targetSpace, (uint)(CollisionCategories.Space |
1812 CollisionCategories.Geom |
1813 CollisionCategories.Phantom |
1814 CollisionCategories.VolumeDtc
1815 ));
1816 d.GeomSetCollideBits(m_targetSpace, 0);
1817 collide_geom = m_targetSpace;
1818 }
1819
1820 d.SpaceAdd(m_targetSpace, prim_geom);
1821
1822 if (m_delaySelect)
1823 {
1824 m_isSelected = true;
1825 m_delaySelect = false;
1826 }
1827
1828 m_collisionscore = 0;
1829
1830 UpdateCollisionCatFlags();
1831 ApplyCollisionCatFlags();
1832
1833 _parent_scene.addActivePrim(this);
1834
1835 lock (childrenPrim)
1836 {
1837 foreach (OdePrim prm in childrenPrim)
1838 {
1839 if (prm.prim_geom == IntPtr.Zero)
1840 continue;
1841
1842 Vector3 ppos = prm._position;
1843 d.GeomSetOffsetWorldPosition(prm.prim_geom, ppos.X, ppos.Y, ppos.Z); // set relative position
1844
1845 if (prm.m_targetSpace != m_targetSpace)
1846 {
1847 if (prm.m_targetSpace != IntPtr.Zero)
1848 {
1849 _parent_scene.waitForSpaceUnlock(prm.m_targetSpace);
1850 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1851 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1852 }
1853 prm.m_targetSpace = m_targetSpace;
1854 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1855 }
1856
1857 prm.m_collisionscore = 0;
1858
1859 if(!m_disabled)
1860 prm.m_disabled = false;
1861
1862 _parent_scene.addActivePrim(prm);
1863 }
1864 }
1865
1866 // The body doesn't already have a finite rotation mode set here
1867 if ((!m_angularlock.ApproxEquals(Vector3.One, 0.0f)) && _parent == null)
1868 {
1869 createAMotor(m_angularlock);
1870 }
1871
1872
1873 if (m_isSelected || m_disabled)
1874 {
1875 d.BodyDisable(Body);
1876 }
1877 else
1878 {
1879 d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z);
1880 d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z);
1881 }
1882 _parent_scene.addActiveGroups(this);
1883 }
1884
1885 private void DestroyBody()
1886 {
1887 if (Body != IntPtr.Zero)
1888 {
1889 _parent_scene.remActivePrim(this);
1890
1891 collide_geom = IntPtr.Zero;
1892
1893 if (m_disabled)
1894 m_collisionCategories = 0;
1895 else if (m_isSelected)
1896 m_collisionCategories = CollisionCategories.Selected;
1897 else if (m_isVolumeDetect)
1898 m_collisionCategories = CollisionCategories.VolumeDtc;
1899 else if (m_isphantom)
1900 m_collisionCategories = CollisionCategories.Phantom;
1901 else
1902 m_collisionCategories = CollisionCategories.Geom;
1903
1904 m_collisionFlags = 0;
1905
1906 if (prim_geom != IntPtr.Zero)
1907 {
1908 if (m_NoColide)
1909 {
1910 d.GeomSetCategoryBits(prim_geom, 0);
1911 d.GeomSetCollideBits(prim_geom, 0);
1912 }
1913 else
1914 {
1915 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1916 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1917 }
1918 UpdateDataFromGeom();
1919 d.GeomSetBody(prim_geom, IntPtr.Zero);
1920 SetInStaticSpace(this);
1921 }
1922
1923 if (!childPrim)
1924 {
1925 lock (childrenPrim)
1926 {
1927 foreach (OdePrim prm in childrenPrim)
1928 {
1929 _parent_scene.remActivePrim(prm);
1930
1931 if (prm.m_isSelected)
1932 prm.m_collisionCategories = CollisionCategories.Selected;
1933 else if (prm.m_isVolumeDetect)
1934 prm.m_collisionCategories = CollisionCategories.VolumeDtc;
1935 else if (prm.m_isphantom)
1936 prm.m_collisionCategories = CollisionCategories.Phantom;
1937 else
1938 prm.m_collisionCategories = CollisionCategories.Geom;
1939
1940 prm.m_collisionFlags = 0;
1941
1942 if (prm.prim_geom != IntPtr.Zero)
1943 {
1944 if (prm.m_NoColide)
1945 {
1946 d.GeomSetCategoryBits(prm.prim_geom, 0);
1947 d.GeomSetCollideBits(prm.prim_geom, 0);
1948 }
1949 else
1950 {
1951 d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
1952 d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
1953 }
1954 prm.UpdateDataFromGeom();
1955 SetInStaticSpace(prm);
1956 }
1957 prm.Body = IntPtr.Zero;
1958 prm._mass = prm.primMass;
1959 prm.m_collisionscore = 0;
1960 }
1961 }
1962 if (Amotor != IntPtr.Zero)
1963 {
1964 d.JointDestroy(Amotor);
1965 Amotor = IntPtr.Zero;
1966 }
1967 _parent_scene.remActiveGroup(this);
1968 d.BodyDestroy(Body);
1969 }
1970 Body = IntPtr.Zero;
1971 }
1972 _mass = primMass;
1973 m_collisionscore = 0;
1974 }
1975
1976 private void FixInertia(Vector3 NewPos,Quaternion newrot)
1977 {
1978 d.Matrix3 mat = new d.Matrix3();
1979 d.Quaternion quat = new d.Quaternion();
1980
1981 d.Mass tmpdmass = new d.Mass { };
1982 d.Mass objdmass = new d.Mass { };
1983
1984 d.BodyGetMass(Body, out tmpdmass);
1985 objdmass = tmpdmass;
1986
1987 d.Vector3 dobjpos;
1988 d.Vector3 thispos;
1989
1990 // get current object position and rotation
1991 dobjpos = d.BodyGetPosition(Body);
1992
1993 // get prim own inertia in its local frame
1994 tmpdmass = primdMass;
1995
1996 // transform to object frame
1997 mat = d.GeomGetOffsetRotation(prim_geom);
1998 d.MassRotate(ref tmpdmass, ref mat);
1999
2000 thispos = d.GeomGetOffsetPosition(prim_geom);
2001 d.MassTranslate(ref tmpdmass,
2002 thispos.X,
2003 thispos.Y,
2004 thispos.Z);
2005
2006 // subtract current prim inertia from object
2007 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2008
2009 // back prim own inertia
2010 tmpdmass = primdMass;
2011
2012 // update to new position and orientation
2013 _position = NewPos;
2014 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2015 _orientation = newrot;
2016 quat.X = newrot.X;
2017 quat.Y = newrot.Y;
2018 quat.Z = newrot.Z;
2019 quat.W = newrot.W;
2020 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2021
2022 mat = d.GeomGetOffsetRotation(prim_geom);
2023 d.MassRotate(ref tmpdmass, ref mat);
2024
2025 thispos = d.GeomGetOffsetPosition(prim_geom);
2026 d.MassTranslate(ref tmpdmass,
2027 thispos.X,
2028 thispos.Y,
2029 thispos.Z);
2030
2031 d.MassAdd(ref objdmass, ref tmpdmass);
2032
2033 // fix all positions
2034 IntPtr g = d.BodyGetFirstGeom(Body);
2035 while (g != IntPtr.Zero)
2036 {
2037 thispos = d.GeomGetOffsetPosition(g);
2038 thispos.X -= objdmass.c.X;
2039 thispos.Y -= objdmass.c.Y;
2040 thispos.Z -= objdmass.c.Z;
2041 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2042 g = d.dBodyGetNextGeom(g);
2043 }
2044 d.BodyVectorToWorld(Body,objdmass.c.X, objdmass.c.Y, objdmass.c.Z,out thispos);
2045
2046 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2047 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2048 d.BodySetMass(Body, ref objdmass);
2049 _mass = objdmass.mass;
2050 }
2051
2052
2053
2054 private void FixInertia(Vector3 NewPos)
2055 {
2056 d.Matrix3 primmat = new d.Matrix3();
2057 d.Mass tmpdmass = new d.Mass { };
2058 d.Mass objdmass = new d.Mass { };
2059 d.Mass primmass = new d.Mass { };
2060
2061 d.Vector3 dobjpos;
2062 d.Vector3 thispos;
2063
2064 d.BodyGetMass(Body, out objdmass);
2065
2066 // get prim own inertia in its local frame
2067 primmass = primdMass;
2068 // transform to object frame
2069 primmat = d.GeomGetOffsetRotation(prim_geom);
2070 d.MassRotate(ref primmass, ref primmat);
2071
2072 tmpdmass = primmass;
2073
2074 thispos = d.GeomGetOffsetPosition(prim_geom);
2075 d.MassTranslate(ref tmpdmass,
2076 thispos.X,
2077 thispos.Y,
2078 thispos.Z);
2079
2080 // subtract current prim inertia from object
2081 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2082
2083 // update to new position
2084 _position = NewPos;
2085 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2086
2087 thispos = d.GeomGetOffsetPosition(prim_geom);
2088 d.MassTranslate(ref primmass,
2089 thispos.X,
2090 thispos.Y,
2091 thispos.Z);
2092
2093 d.MassAdd(ref objdmass, ref primmass);
2094
2095 // fix all positions
2096 IntPtr g = d.BodyGetFirstGeom(Body);
2097 while (g != IntPtr.Zero)
2098 {
2099 thispos = d.GeomGetOffsetPosition(g);
2100 thispos.X -= objdmass.c.X;
2101 thispos.Y -= objdmass.c.Y;
2102 thispos.Z -= objdmass.c.Z;
2103 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2104 g = d.dBodyGetNextGeom(g);
2105 }
2106
2107 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2108
2109 // get current object position and rotation
2110 dobjpos = d.BodyGetPosition(Body);
2111
2112 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2113 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2114 d.BodySetMass(Body, ref objdmass);
2115 _mass = objdmass.mass;
2116 }
2117
2118 private void FixInertia(Quaternion newrot)
2119 {
2120 d.Matrix3 mat = new d.Matrix3();
2121 d.Quaternion quat = new d.Quaternion();
2122
2123 d.Mass tmpdmass = new d.Mass { };
2124 d.Mass objdmass = new d.Mass { };
2125 d.Vector3 dobjpos;
2126 d.Vector3 thispos;
2127
2128 d.BodyGetMass(Body, out objdmass);
2129
2130 // get prim own inertia in its local frame
2131 tmpdmass = primdMass;
2132 mat = d.GeomGetOffsetRotation(prim_geom);
2133 d.MassRotate(ref tmpdmass, ref mat);
2134 // transform to object frame
2135 thispos = d.GeomGetOffsetPosition(prim_geom);
2136 d.MassTranslate(ref tmpdmass,
2137 thispos.X,
2138 thispos.Y,
2139 thispos.Z);
2140
2141 // subtract current prim inertia from object
2142 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2143
2144 // update to new orientation
2145 _orientation = newrot;
2146 quat.X = newrot.X;
2147 quat.Y = newrot.Y;
2148 quat.Z = newrot.Z;
2149 quat.W = newrot.W;
2150 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2151
2152 tmpdmass = primdMass;
2153 mat = d.GeomGetOffsetRotation(prim_geom);
2154 d.MassRotate(ref tmpdmass, ref mat);
2155 d.MassTranslate(ref tmpdmass,
2156 thispos.X,
2157 thispos.Y,
2158 thispos.Z);
2159
2160 d.MassAdd(ref objdmass, ref tmpdmass);
2161
2162 // fix all positions
2163 IntPtr g = d.BodyGetFirstGeom(Body);
2164 while (g != IntPtr.Zero)
2165 {
2166 thispos = d.GeomGetOffsetPosition(g);
2167 thispos.X -= objdmass.c.X;
2168 thispos.Y -= objdmass.c.Y;
2169 thispos.Z -= objdmass.c.Z;
2170 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2171 g = d.dBodyGetNextGeom(g);
2172 }
2173
2174 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2175 // get current object position and rotation
2176 dobjpos = d.BodyGetPosition(Body);
2177
2178 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2179 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2180 d.BodySetMass(Body, ref objdmass);
2181 _mass = objdmass.mass;
2182 }
2183
2184
2185 #region Mass Calculation
2186
2187 private void UpdatePrimBodyData()
2188 {
2189 primMass = m_density * primVolume;
2190
2191 if (primMass <= 0)
2192 primMass = 0.0001f;//ckrinke: Mass must be greater then zero.
2193 if (primMass > _parent_scene.maximumMassObject)
2194 primMass = _parent_scene.maximumMassObject;
2195
2196 _mass = primMass; // just in case
2197
2198 d.MassSetBoxTotal(out primdMass, primMass, 2.0f * m_OBB.X, 2.0f * m_OBB.Y, 2.0f * m_OBB.Z);
2199
2200 d.MassTranslate(ref primdMass,
2201 m_OBBOffset.X,
2202 m_OBBOffset.Y,
2203 m_OBBOffset.Z);
2204
2205 primOOBradiusSQ = m_OBB.LengthSquared();
2206
2207 if (_triMeshData != IntPtr.Zero)
2208 {
2209 float pc = m_physCost;
2210 float psf = primOOBradiusSQ;
2211 psf *= 1.33f * .2f;
2212 pc *= psf;
2213 if (pc < 0.1f)
2214 pc = 0.1f;
2215
2216 m_physCost = pc;
2217 }
2218 else
2219 m_physCost = 0.1f;
2220
2221 m_streamCost = 1.0f;
2222 }
2223
2224 #endregion
2225
2226
2227 /// <summary>
2228 /// Add a child prim to this parent prim.
2229 /// </summary>
2230 /// <param name="prim">Child prim</param>
2231 // I'm the parent
2232 // prim is the child
2233 public void ParentPrim(OdePrim prim)
2234 {
2235 //Console.WriteLine("ParentPrim " + m_primName);
2236 if (this.m_localID != prim.m_localID)
2237 {
2238 DestroyBody(); // for now we need to rebuil entire object on link change
2239
2240 lock (childrenPrim)
2241 {
2242 // adopt the prim
2243 if (!childrenPrim.Contains(prim))
2244 childrenPrim.Add(prim);
2245
2246 // see if this prim has kids and adopt them also
2247 // should not happen for now
2248 foreach (OdePrim prm in prim.childrenPrim)
2249 {
2250 if (!childrenPrim.Contains(prm))
2251 {
2252 if (prm.Body != IntPtr.Zero)
2253 {
2254 if (prm.prim_geom != IntPtr.Zero)
2255 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
2256 if (prm.Body != prim.Body)
2257 prm.DestroyBody(); // don't loose bodies around
2258 prm.Body = IntPtr.Zero;
2259 }
2260
2261 childrenPrim.Add(prm);
2262 prm._parent = this;
2263 }
2264 }
2265 }
2266 //Remove old children from the prim
2267 prim.childrenPrim.Clear();
2268
2269 if (prim.Body != IntPtr.Zero)
2270 {
2271 if (prim.prim_geom != IntPtr.Zero)
2272 d.GeomSetBody(prim.prim_geom, IntPtr.Zero);
2273 prim.DestroyBody(); // don't loose bodies around
2274 prim.Body = IntPtr.Zero;
2275 }
2276
2277 prim.childPrim = true;
2278 prim._parent = this;
2279
2280 MakeBody(); // full nasty reconstruction
2281 }
2282 }
2283
2284 private void UpdateChildsfromgeom()
2285 {
2286 if (childrenPrim.Count > 0)
2287 {
2288 foreach (OdePrim prm in childrenPrim)
2289 prm.UpdateDataFromGeom();
2290 }
2291 }
2292
2293 private void UpdateDataFromGeom()
2294 {
2295 if (prim_geom != IntPtr.Zero)
2296 {
2297 d.Quaternion qtmp;
2298 d.GeomCopyQuaternion(prim_geom, out qtmp);
2299 _orientation.X = qtmp.X;
2300 _orientation.Y = qtmp.Y;
2301 _orientation.Z = qtmp.Z;
2302 _orientation.W = qtmp.W;
2303/*
2304// Debug
2305 float qlen = _orientation.Length();
2306 if (qlen > 1.01f || qlen < 0.99)
2307 m_log.WarnFormat("[PHYSICS]: Got nonnorm quaternion from geom in Object {0} norm {1}", Name, qlen);
2308//
2309*/
2310 _orientation.Normalize();
2311
2312 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
2313 _position.X = lpos.X;
2314 _position.Y = lpos.Y;
2315 _position.Z = lpos.Z;
2316 }
2317 }
2318
2319 private void ChildDelink(OdePrim odePrim, bool remakebodies)
2320 {
2321 // Okay, we have a delinked child.. destroy all body and remake
2322 if (odePrim != this && !childrenPrim.Contains(odePrim))
2323 return;
2324
2325 DestroyBody();
2326
2327 if (odePrim == this) // delinking the root prim
2328 {
2329 OdePrim newroot = null;
2330 lock (childrenPrim)
2331 {
2332 if (childrenPrim.Count > 0)
2333 {
2334 newroot = childrenPrim[0];
2335 childrenPrim.RemoveAt(0);
2336 foreach (OdePrim prm in childrenPrim)
2337 {
2338 newroot.childrenPrim.Add(prm);
2339 }
2340 childrenPrim.Clear();
2341 }
2342 if (newroot != null)
2343 {
2344 newroot.childPrim = false;
2345 newroot._parent = null;
2346 if (remakebodies)
2347 newroot.MakeBody();
2348 }
2349 }
2350 }
2351
2352 else
2353 {
2354 lock (childrenPrim)
2355 {
2356 childrenPrim.Remove(odePrim);
2357 odePrim.childPrim = false;
2358 odePrim._parent = null;
2359 // odePrim.UpdateDataFromGeom();
2360 if (remakebodies)
2361 odePrim.MakeBody();
2362 }
2363 }
2364 if (remakebodies)
2365 MakeBody();
2366 }
2367
2368 protected void ChildRemove(OdePrim odePrim, bool reMakeBody)
2369 {
2370 // Okay, we have a delinked child.. destroy all body and remake
2371 if (odePrim != this && !childrenPrim.Contains(odePrim))
2372 return;
2373
2374 DestroyBody();
2375
2376 if (odePrim == this)
2377 {
2378 OdePrim newroot = null;
2379 lock (childrenPrim)
2380 {
2381 if (childrenPrim.Count > 0)
2382 {
2383 newroot = childrenPrim[0];
2384 childrenPrim.RemoveAt(0);
2385 foreach (OdePrim prm in childrenPrim)
2386 {
2387 newroot.childrenPrim.Add(prm);
2388 }
2389 childrenPrim.Clear();
2390 }
2391 if (newroot != null)
2392 {
2393 newroot.childPrim = false;
2394 newroot._parent = null;
2395 newroot.MakeBody();
2396 }
2397 }
2398 if (reMakeBody)
2399 MakeBody();
2400 return;
2401 }
2402 else
2403 {
2404 lock (childrenPrim)
2405 {
2406 childrenPrim.Remove(odePrim);
2407 odePrim.childPrim = false;
2408 odePrim._parent = null;
2409 if (reMakeBody)
2410 odePrim.MakeBody();
2411 }
2412 }
2413 MakeBody();
2414 }
2415
2416
2417 #region changes
2418
2419 private void changeadd()
2420 {
2421 }
2422
2423 private void changeAngularLock(Vector3 newLock)
2424 {
2425 // do we have a Physical object?
2426 if (Body != IntPtr.Zero)
2427 {
2428 //Check that we have a Parent
2429 //If we have a parent then we're not authorative here
2430 if (_parent == null)
2431 {
2432 if (!newLock.ApproxEquals(Vector3.One, 0f))
2433 {
2434 createAMotor(newLock);
2435 }
2436 else
2437 {
2438 if (Amotor != IntPtr.Zero)
2439 {
2440 d.JointDestroy(Amotor);
2441 Amotor = IntPtr.Zero;
2442 }
2443 }
2444 }
2445 }
2446 // Store this for later in case we get turned into a separate body
2447 m_angularlock = newLock;
2448 }
2449
2450 private void changeLink(OdePrim NewParent)
2451 {
2452 if (_parent == null && NewParent != null)
2453 {
2454 NewParent.ParentPrim(this);
2455 }
2456 else if (_parent != null)
2457 {
2458 if (_parent is OdePrim)
2459 {
2460 if (NewParent != _parent)
2461 {
2462 (_parent as OdePrim).ChildDelink(this, false); // for now...
2463 childPrim = false;
2464
2465 if (NewParent != null)
2466 {
2467 NewParent.ParentPrim(this);
2468 }
2469 }
2470 }
2471 }
2472 _parent = NewParent;
2473 }
2474
2475
2476 private void Stop()
2477 {
2478 if (!childPrim)
2479 {
2480// m_force = Vector3.Zero;
2481 m_forceacc = Vector3.Zero;
2482 m_angularForceacc = Vector3.Zero;
2483// m_torque = Vector3.Zero;
2484 _velocity = Vector3.Zero;
2485 _acceleration = Vector3.Zero;
2486 m_rotationalVelocity = Vector3.Zero;
2487 _target_velocity = Vector3.Zero;
2488 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2489 m_vehicle.Stop();
2490
2491 _zeroFlag = false;
2492 base.RequestPhysicsterseUpdate();
2493 }
2494
2495 if (Body != IntPtr.Zero)
2496 {
2497 d.BodySetForce(Body, 0f, 0f, 0f);
2498 d.BodySetTorque(Body, 0f, 0f, 0f);
2499 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2500 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2501 }
2502 }
2503
2504 private void changePhantomStatus(bool newval)
2505 {
2506 m_isphantom = newval;
2507
2508 UpdateCollisionCatFlags();
2509 ApplyCollisionCatFlags();
2510 }
2511
2512/* not in use
2513 internal void ChildSelectedChange(bool childSelect)
2514 {
2515 if(childPrim)
2516 return;
2517
2518 if (childSelect == m_isSelected)
2519 return;
2520
2521 if (childSelect)
2522 {
2523 DoSelectedStatus(true);
2524 }
2525
2526 else
2527 {
2528 foreach (OdePrim prm in childrenPrim)
2529 {
2530 if (prm.m_isSelected)
2531 return;
2532 }
2533 DoSelectedStatus(false);
2534 }
2535 }
2536*/
2537 private void changeSelectedStatus(bool newval)
2538 {
2539 if (m_lastdoneSelected == newval)
2540 return;
2541
2542 m_lastdoneSelected = newval;
2543 DoSelectedStatus(newval);
2544 }
2545
2546 private void CheckDelaySelect()
2547 {
2548 if (m_delaySelect)
2549 {
2550 DoSelectedStatus(m_isSelected);
2551 }
2552 }
2553
2554 private void DoSelectedStatus(bool newval)
2555 {
2556 m_isSelected = newval;
2557 Stop();
2558
2559 if (newval)
2560 {
2561 if (!childPrim && Body != IntPtr.Zero)
2562 d.BodyDisable(Body);
2563
2564 if (m_delaySelect || m_isphysical)
2565 {
2566 m_collisionCategories = CollisionCategories.Selected;
2567 m_collisionFlags = 0;
2568
2569 if (!childPrim)
2570 {
2571 foreach (OdePrim prm in childrenPrim)
2572 {
2573 prm.m_collisionCategories = m_collisionCategories;
2574 prm.m_collisionFlags = m_collisionFlags;
2575
2576 if (prm.prim_geom != IntPtr.Zero)
2577 {
2578
2579 if (prm.m_NoColide)
2580 {
2581 d.GeomSetCategoryBits(prm.prim_geom, 0);
2582 d.GeomSetCollideBits(prm.prim_geom, 0);
2583 }
2584 else
2585 {
2586 d.GeomSetCategoryBits(prm.prim_geom, (uint)m_collisionCategories);
2587 d.GeomSetCollideBits(prm.prim_geom, (uint)m_collisionFlags);
2588 }
2589 }
2590 prm.m_delaySelect = false;
2591 }
2592 }
2593// else if (_parent != null)
2594// ((OdePrim)_parent).ChildSelectedChange(true);
2595
2596
2597 if (prim_geom != IntPtr.Zero)
2598 {
2599 if (m_NoColide)
2600 {
2601 d.GeomSetCategoryBits(prim_geom, 0);
2602 d.GeomSetCollideBits(prim_geom, 0);
2603 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2604 {
2605 d.GeomSetCategoryBits(collide_geom, 0);
2606 d.GeomSetCollideBits(collide_geom, 0);
2607 }
2608
2609 }
2610 else
2611 {
2612 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
2613 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
2614 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2615 {
2616 d.GeomSetCategoryBits(collide_geom, (uint)m_collisionCategories);
2617 d.GeomSetCollideBits(collide_geom, (uint)m_collisionFlags);
2618 }
2619 }
2620 }
2621
2622 m_delaySelect = false;
2623 }
2624 else if(!m_isphysical)
2625 {
2626 m_delaySelect = true;
2627 }
2628 }
2629 else
2630 {
2631 if (!childPrim)
2632 {
2633 if (Body != IntPtr.Zero && !m_disabled)
2634 d.BodyEnable(Body);
2635 }
2636// else if (_parent != null)
2637// ((OdePrim)_parent).ChildSelectedChange(false);
2638
2639 UpdateCollisionCatFlags();
2640 ApplyCollisionCatFlags();
2641
2642 m_delaySelect = false;
2643 }
2644
2645 resetCollisionAccounting();
2646 }
2647
2648 private void changePosition(Vector3 newPos)
2649 {
2650 CheckDelaySelect();
2651 if (m_isphysical)
2652 {
2653 if (childPrim) // inertia is messed, must rebuild
2654 {
2655 if (m_building)
2656 {
2657 _position = newPos;
2658 }
2659
2660 else if (m_forcePosOrRotation && _position != newPos && Body != IntPtr.Zero)
2661 {
2662 FixInertia(newPos);
2663 if (!d.BodyIsEnabled(Body))
2664 d.BodyEnable(Body);
2665 }
2666 }
2667 else
2668 {
2669 if (_position != newPos)
2670 {
2671 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2672 _position = newPos;
2673 }
2674 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2675 d.BodyEnable(Body);
2676 }
2677 }
2678 else
2679 {
2680 if (prim_geom != IntPtr.Zero)
2681 {
2682 if (newPos != _position)
2683 {
2684 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2685 _position = newPos;
2686
2687 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2688 }
2689 }
2690 }
2691 givefakepos--;
2692 if (givefakepos < 0)
2693 givefakepos = 0;
2694// changeSelectedStatus();
2695 resetCollisionAccounting();
2696 }
2697
2698 private void changeOrientation(Quaternion newOri)
2699 {
2700 CheckDelaySelect();
2701 if (m_isphysical)
2702 {
2703 if (childPrim) // inertia is messed, must rebuild
2704 {
2705 if (m_building)
2706 {
2707 _orientation = newOri;
2708 }
2709/*
2710 else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero)
2711 {
2712 FixInertia(_position, newOri);
2713 if (!d.BodyIsEnabled(Body))
2714 d.BodyEnable(Body);
2715 }
2716*/
2717 }
2718 else
2719 {
2720 if (newOri != _orientation)
2721 {
2722 d.Quaternion myrot = new d.Quaternion();
2723 myrot.X = newOri.X;
2724 myrot.Y = newOri.Y;
2725 myrot.Z = newOri.Z;
2726 myrot.W = newOri.W;
2727 d.GeomSetQuaternion(prim_geom, ref myrot);
2728 _orientation = newOri;
2729 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2730 createAMotor(m_angularlock);
2731 }
2732 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2733 d.BodyEnable(Body);
2734 }
2735 }
2736 else
2737 {
2738 if (prim_geom != IntPtr.Zero)
2739 {
2740 if (newOri != _orientation)
2741 {
2742 d.Quaternion myrot = new d.Quaternion();
2743 myrot.X = newOri.X;
2744 myrot.Y = newOri.Y;
2745 myrot.Z = newOri.Z;
2746 myrot.W = newOri.W;
2747 d.GeomSetQuaternion(prim_geom, ref myrot);
2748 _orientation = newOri;
2749 }
2750 }
2751 }
2752 givefakeori--;
2753 if (givefakeori < 0)
2754 givefakeori = 0;
2755 resetCollisionAccounting();
2756 }
2757
2758 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2759 {
2760 CheckDelaySelect();
2761 if (m_isphysical)
2762 {
2763 if (childPrim && m_building) // inertia is messed, must rebuild
2764 {
2765 _position = newPos;
2766 _orientation = newOri;
2767 }
2768 else
2769 {
2770 if (newOri != _orientation)
2771 {
2772 d.Quaternion myrot = new d.Quaternion();
2773 myrot.X = newOri.X;
2774 myrot.Y = newOri.Y;
2775 myrot.Z = newOri.Z;
2776 myrot.W = newOri.W;
2777 d.GeomSetQuaternion(prim_geom, ref myrot);
2778 _orientation = newOri;
2779 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2780 createAMotor(m_angularlock);
2781 }
2782 if (_position != newPos)
2783 {
2784 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2785 _position = newPos;
2786 }
2787 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2788 d.BodyEnable(Body);
2789 }
2790 }
2791 else
2792 {
2793 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2794 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2795
2796 if (prim_geom != IntPtr.Zero)
2797 {
2798 if (newOri != _orientation)
2799 {
2800 d.Quaternion myrot = new d.Quaternion();
2801 myrot.X = newOri.X;
2802 myrot.Y = newOri.Y;
2803 myrot.Z = newOri.Z;
2804 myrot.W = newOri.W;
2805 d.GeomSetQuaternion(prim_geom, ref myrot);
2806 _orientation = newOri;
2807 }
2808
2809 if (newPos != _position)
2810 {
2811 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2812 _position = newPos;
2813
2814 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2815 }
2816 }
2817 }
2818 givefakepos--;
2819 if (givefakepos < 0)
2820 givefakepos = 0;
2821 givefakeori--;
2822 if (givefakeori < 0)
2823 givefakeori = 0;
2824 resetCollisionAccounting();
2825 }
2826
2827 private void changeDisable(bool disable)
2828 {
2829 if (disable)
2830 {
2831 if (!m_disabled)
2832 disableBodySoft();
2833 }
2834 else
2835 {
2836 if (m_disabled)
2837 enableBodySoft();
2838 }
2839 }
2840
2841 private void changePhysicsStatus(bool NewStatus)
2842 {
2843 CheckDelaySelect();
2844
2845 m_isphysical = NewStatus;
2846
2847 if (!childPrim)
2848 {
2849 if (NewStatus)
2850 {
2851 if (Body == IntPtr.Zero)
2852 MakeBody();
2853 }
2854 else
2855 {
2856 if (Body != IntPtr.Zero)
2857 {
2858 DestroyBody();
2859 }
2860 Stop();
2861 }
2862 }
2863
2864 resetCollisionAccounting();
2865 }
2866
2867 private void changeSize(Vector3 newSize)
2868 {
2869 }
2870
2871 private void changeShape(PrimitiveBaseShape newShape)
2872 {
2873 }
2874
2875 private void changeAddPhysRep(ODEPhysRepData repData)
2876 {
2877 _size = repData.size; //??
2878 _pbs = repData.pbs;
2879 m_shapetype = repData.shapetype;
2880
2881 m_mesh = repData.mesh;
2882
2883 m_assetID = repData.assetID;
2884 m_meshState = repData.meshState;
2885
2886 m_hasOBB = repData.hasOBB;
2887 m_OBBOffset = repData.OBBOffset;
2888 m_OBB = repData.OBB;
2889
2890 primVolume = repData.volume;
2891
2892 CreateGeom();
2893
2894 if (prim_geom != IntPtr.Zero)
2895 {
2896 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2897 d.Quaternion myrot = new d.Quaternion();
2898 myrot.X = _orientation.X;
2899 myrot.Y = _orientation.Y;
2900 myrot.Z = _orientation.Z;
2901 myrot.W = _orientation.W;
2902 d.GeomSetQuaternion(prim_geom, ref myrot);
2903 }
2904
2905 if (!m_isphysical)
2906 {
2907 SetInStaticSpace(this);
2908 UpdateCollisionCatFlags();
2909 ApplyCollisionCatFlags();
2910 }
2911 else
2912 MakeBody();
2913
2914 if ((m_meshState & MeshState.NeedMask) != 0)
2915 {
2916 repData.size = _size;
2917 repData.pbs = _pbs;
2918 repData.shapetype = m_shapetype;
2919 _parent_scene.m_meshWorker.RequestMesh(repData);
2920 }
2921 }
2922
2923 private void changePhysRepData(ODEPhysRepData repData)
2924 {
2925 CheckDelaySelect();
2926
2927 OdePrim parent = (OdePrim)_parent;
2928
2929 bool chp = childPrim;
2930
2931 if (chp)
2932 {
2933 if (parent != null)
2934 {
2935 parent.DestroyBody();
2936 }
2937 }
2938 else
2939 {
2940 DestroyBody();
2941 }
2942
2943 RemoveGeom();
2944
2945 _size = repData.size;
2946 _pbs = repData.pbs;
2947 m_shapetype = repData.shapetype;
2948
2949 m_mesh = repData.mesh;
2950
2951 m_assetID = repData.assetID;
2952 m_meshState = repData.meshState;
2953
2954 m_hasOBB = repData.hasOBB;
2955 m_OBBOffset = repData.OBBOffset;
2956 m_OBB = repData.OBB;
2957
2958 primVolume = repData.volume;
2959
2960 CreateGeom();
2961
2962 if (prim_geom != IntPtr.Zero)
2963 {
2964 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2965 d.Quaternion myrot = new d.Quaternion();
2966 myrot.X = _orientation.X;
2967 myrot.Y = _orientation.Y;
2968 myrot.Z = _orientation.Z;
2969 myrot.W = _orientation.W;
2970 d.GeomSetQuaternion(prim_geom, ref myrot);
2971 }
2972
2973 if (m_isphysical)
2974 {
2975 if (chp)
2976 {
2977 if (parent != null)
2978 {
2979 parent.MakeBody();
2980 }
2981 }
2982 else
2983 MakeBody();
2984 }
2985 else
2986 {
2987 SetInStaticSpace(this);
2988 UpdateCollisionCatFlags();
2989 ApplyCollisionCatFlags();
2990 }
2991
2992 resetCollisionAccounting();
2993
2994 if ((m_meshState & MeshState.NeedMask) != 0)
2995 {
2996 repData.size = _size;
2997 repData.pbs = _pbs;
2998 repData.shapetype = m_shapetype;
2999 _parent_scene.m_meshWorker.RequestMesh(repData);
3000 }
3001 }
3002
3003 private void changeFloatOnWater(bool newval)
3004 {
3005 m_collidesWater = newval;
3006
3007 UpdateCollisionCatFlags();
3008 ApplyCollisionCatFlags();
3009 }
3010
3011 private void changeSetTorque(Vector3 newtorque)
3012 {
3013 if (!m_isSelected)
3014 {
3015 if (m_isphysical && Body != IntPtr.Zero)
3016 {
3017 if (m_disabled)
3018 enableBodySoft();
3019 else if (!d.BodyIsEnabled(Body))
3020 d.BodyEnable(Body);
3021
3022 }
3023 m_torque = newtorque;
3024 }
3025 }
3026
3027 private void changeForce(Vector3 force)
3028 {
3029 m_force = force;
3030 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
3031 d.BodyEnable(Body);
3032 }
3033
3034 private void changeAddForce(Vector3 theforce)
3035 {
3036 m_forceacc += theforce;
3037 if (!m_isSelected)
3038 {
3039 lock (this)
3040 {
3041 //m_log.Info("[PHYSICS]: dequeing forcelist");
3042 if (m_isphysical && Body != IntPtr.Zero)
3043 {
3044 if (m_disabled)
3045 enableBodySoft();
3046 else if (!d.BodyIsEnabled(Body))
3047 d.BodyEnable(Body);
3048 }
3049 }
3050 m_collisionscore = 0;
3051 }
3052 }
3053
3054 // actually angular impulse
3055 private void changeAddAngularImpulse(Vector3 aimpulse)
3056 {
3057 m_angularForceacc += aimpulse * m_invTimeStep;
3058 if (!m_isSelected)
3059 {
3060 lock (this)
3061 {
3062 if (m_isphysical && Body != IntPtr.Zero)
3063 {
3064 if (m_disabled)
3065 enableBodySoft();
3066 else if (!d.BodyIsEnabled(Body))
3067 d.BodyEnable(Body);
3068 }
3069 }
3070 m_collisionscore = 0;
3071 }
3072 }
3073
3074 private void changevelocity(Vector3 newVel)
3075 {
3076 float len = newVel.LengthSquared();
3077 if (len > 100000.0f) // limit to 100m/s
3078 {
3079 len = 100.0f / (float)Math.Sqrt(len);
3080 newVel *= len;
3081 }
3082
3083 if (!m_isSelected)
3084 {
3085 if (Body != IntPtr.Zero)
3086 {
3087 if (m_disabled)
3088 enableBodySoft();
3089 else if (!d.BodyIsEnabled(Body))
3090 d.BodyEnable(Body);
3091
3092 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
3093 }
3094 //resetCollisionAccounting();
3095 }
3096 _velocity = newVel;
3097 }
3098
3099 private void changeangvelocity(Vector3 newAngVel)
3100 {
3101 float len = newAngVel.LengthSquared();
3102 if (len > 144.0f) // limit to 12rad/s
3103 {
3104 len = 12.0f / (float)Math.Sqrt(len);
3105 newAngVel *= len;
3106 }
3107
3108 if (!m_isSelected)
3109 {
3110 if (Body != IntPtr.Zero)
3111 {
3112 if (m_disabled)
3113 enableBodySoft();
3114 else if (!d.BodyIsEnabled(Body))
3115 d.BodyEnable(Body);
3116
3117
3118 d.BodySetAngularVel(Body, newAngVel.X, newAngVel.Y, newAngVel.Z);
3119 }
3120 //resetCollisionAccounting();
3121 }
3122 m_rotationalVelocity = newAngVel;
3123 }
3124
3125 private void changeVolumedetetion(bool newVolDtc)
3126 {
3127 m_isVolumeDetect = newVolDtc;
3128 m_fakeisVolumeDetect = newVolDtc;
3129 UpdateCollisionCatFlags();
3130 ApplyCollisionCatFlags();
3131 }
3132
3133 protected void changeBuilding(bool newbuilding)
3134 {
3135 // Check if we need to do anything
3136 if (newbuilding == m_building)
3137 return;
3138
3139 if ((bool)newbuilding)
3140 {
3141 m_building = true;
3142 if (!childPrim)
3143 DestroyBody();
3144 }
3145 else
3146 {
3147 m_building = false;
3148 CheckDelaySelect();
3149 if (!childPrim)
3150 MakeBody();
3151 }
3152 if (!childPrim && childrenPrim.Count > 0)
3153 {
3154 foreach (OdePrim prm in childrenPrim)
3155 prm.changeBuilding(m_building); // call directly
3156 }
3157 }
3158
3159 public void changeSetVehicle(VehicleData vdata)
3160 {
3161 if (m_vehicle == null)
3162 m_vehicle = new ODEDynamics(this);
3163 m_vehicle.DoSetVehicle(vdata);
3164 }
3165
3166 private void changeVehicleType(int value)
3167 {
3168 if (value == (int)Vehicle.TYPE_NONE)
3169 {
3170 if (m_vehicle != null)
3171 m_vehicle = null;
3172 }
3173 else
3174 {
3175 if (m_vehicle == null)
3176 m_vehicle = new ODEDynamics(this);
3177
3178 m_vehicle.ProcessTypeChange((Vehicle)value);
3179 }
3180 }
3181
3182 private void changeVehicleFloatParam(strVehicleFloatParam fp)
3183 {
3184 if (m_vehicle == null)
3185 return;
3186
3187 m_vehicle.ProcessFloatVehicleParam((Vehicle)fp.param, fp.value);
3188 }
3189
3190 private void changeVehicleVectorParam(strVehicleVectorParam vp)
3191 {
3192 if (m_vehicle == null)
3193 return;
3194 m_vehicle.ProcessVectorVehicleParam((Vehicle)vp.param, vp.value);
3195 }
3196
3197 private void changeVehicleRotationParam(strVehicleQuatParam qp)
3198 {
3199 if (m_vehicle == null)
3200 return;
3201 m_vehicle.ProcessRotationVehicleParam((Vehicle)qp.param, qp.value);
3202 }
3203
3204 private void changeVehicleFlags(strVehicleBoolParam bp)
3205 {
3206 if (m_vehicle == null)
3207 return;
3208 m_vehicle.ProcessVehicleFlags(bp.param, bp.value);
3209 }
3210
3211 private void changeBuoyancy(float b)
3212 {
3213 m_buoyancy = b;
3214 }
3215
3216 private void changePIDTarget(Vector3 trg)
3217 {
3218 m_PIDTarget = trg;
3219 }
3220
3221 private void changePIDTau(float tau)
3222 {
3223 m_PIDTau = tau;
3224 }
3225
3226 private void changePIDActive(bool val)
3227 {
3228 m_usePID = val;
3229 }
3230
3231 private void changePIDHoverHeight(float val)
3232 {
3233 m_PIDHoverHeight = val;
3234 if (val == 0)
3235 m_useHoverPID = false;
3236 }
3237
3238 private void changePIDHoverType(PIDHoverType type)
3239 {
3240 m_PIDHoverType = type;
3241 }
3242
3243 private void changePIDHoverTau(float tau)
3244 {
3245 m_PIDHoverTau = tau;
3246 }
3247
3248 private void changePIDHoverActive(bool active)
3249 {
3250 m_useHoverPID = active;
3251 }
3252
3253 #endregion
3254
3255 public void Move()
3256 {
3257 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
3258 !m_disabled && !m_isSelected && !m_building && !m_outbounds)
3259 {
3260 if (!d.BodyIsEnabled(Body))
3261 {
3262 // let vehicles sleep
3263 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3264 return;
3265
3266 if (++bodydisablecontrol < 20)
3267 return;
3268
3269 d.BodyEnable(Body);
3270 }
3271
3272 bodydisablecontrol = 0;
3273
3274 d.Vector3 lpos = d.GeomGetPosition(prim_geom); // root position that is seem by rest of simulator
3275
3276 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3277 {
3278 // 'VEHICLES' are dealt with in ODEDynamics.cs
3279 m_vehicle.Step();
3280 return;
3281 }
3282
3283 float fx = 0;
3284 float fy = 0;
3285 float fz = 0;
3286
3287 float m_mass = _mass;
3288
3289 if (m_usePID && m_PIDTau > 0)
3290 {
3291 // for now position error
3292 _target_velocity =
3293 new Vector3(
3294 (m_PIDTarget.X - lpos.X),
3295 (m_PIDTarget.Y - lpos.Y),
3296 (m_PIDTarget.Z - lpos.Z)
3297 );
3298
3299 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.02f))
3300 {
3301 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
3302 d.BodySetLinearVel(Body, 0, 0, 0);
3303 return;
3304 }
3305 else
3306 {
3307 _zeroFlag = false;
3308
3309 float tmp = 1 / m_PIDTau;
3310 _target_velocity *= tmp;
3311
3312 // apply limits
3313 tmp = _target_velocity.Length();
3314 if (tmp > 50.0f)
3315 {
3316 tmp = 50 / tmp;
3317 _target_velocity *= tmp;
3318 }
3319 else if (tmp < 0.05f)
3320 {
3321 tmp = 0.05f / tmp;
3322 _target_velocity *= tmp;
3323 }
3324
3325 d.Vector3 vel = d.BodyGetLinearVel(Body);
3326 fx = (_target_velocity.X - vel.X) * m_invTimeStep;
3327 fy = (_target_velocity.Y - vel.Y) * m_invTimeStep;
3328 fz = (_target_velocity.Z - vel.Z) * m_invTimeStep;
3329// d.BodySetLinearVel(Body, _target_velocity.X, _target_velocity.Y, _target_velocity.Z);
3330 }
3331 } // end if (m_usePID)
3332
3333 // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
3334 else if (m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
3335 {
3336
3337 // Non-Vehicles have a limited set of Hover options.
3338 // determine what our target height really is based on HoverType
3339
3340 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(lpos.X, lpos.Y);
3341
3342 switch (m_PIDHoverType)
3343 {
3344 case PIDHoverType.Ground:
3345 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3346 break;
3347
3348 case PIDHoverType.GroundAndWater:
3349 m_waterHeight = _parent_scene.GetWaterLevel();
3350 if (m_groundHeight > m_waterHeight)
3351 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3352 else
3353 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
3354 break;
3355 } // end switch (m_PIDHoverType)
3356
3357 // don't go underground unless volumedetector
3358
3359 if (m_targetHoverHeight > m_groundHeight || m_isVolumeDetect)
3360 {
3361 d.Vector3 vel = d.BodyGetLinearVel(Body);
3362
3363 fz = (m_targetHoverHeight - lpos.Z);
3364
3365 // if error is zero, use position control; otherwise, velocity control
3366 if (Math.Abs(fz) < 0.01f)
3367 {
3368 d.BodySetPosition(Body, lpos.X, lpos.Y, m_targetHoverHeight);
3369 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
3370 }
3371 else
3372 {
3373 _zeroFlag = false;
3374 fz /= m_PIDHoverTau;
3375
3376 float tmp = Math.Abs(fz);
3377 if (tmp > 50)
3378 fz = 50 * Math.Sign(fz);
3379 else if (tmp < 0.1)
3380 fz = 0.1f * Math.Sign(fz);
3381
3382 fz = ((fz - vel.Z) * m_invTimeStep);
3383 }
3384 }
3385 }
3386 else
3387 {
3388 float b = (1.0f - m_buoyancy) * m_gravmod;
3389 fx = _parent_scene.gravityx * b;
3390 fy = _parent_scene.gravityy * b;
3391 fz = _parent_scene.gravityz * b;
3392 }
3393
3394 fx *= m_mass;
3395 fy *= m_mass;
3396 fz *= m_mass;
3397
3398 // constant force
3399 fx += m_force.X;
3400 fy += m_force.Y;
3401 fz += m_force.Z;
3402
3403 fx += m_forceacc.X;
3404 fy += m_forceacc.Y;
3405 fz += m_forceacc.Z;
3406
3407 m_forceacc = Vector3.Zero;
3408
3409 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
3410 if (fx != 0 || fy != 0 || fz != 0)
3411 {
3412 d.BodyAddForce(Body, fx, fy, fz);
3413 //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
3414 }
3415
3416 Vector3 trq;
3417
3418 trq = m_torque;
3419 trq += m_angularForceacc;
3420 m_angularForceacc = Vector3.Zero;
3421 if (trq.X != 0 || trq.Y != 0 || trq.Z != 0)
3422 {
3423 d.BodyAddTorque(Body, trq.X, trq.Y, trq.Z);
3424 }
3425 }
3426 else
3427 { // is not physical, or is not a body or is selected
3428 // _zeroPosition = d.BodyGetPosition(Body);
3429 return;
3430 //Console.WriteLine("Nothing " + Name);
3431
3432 }
3433 }
3434
3435 public void UpdatePositionAndVelocity(int frame)
3436 {
3437 if (_parent == null && !m_disabled && !m_building && !m_outbounds && Body != IntPtr.Zero)
3438 {
3439 bool bodyenabled = d.BodyIsEnabled(Body);
3440 if (bodyenabled || !_zeroFlag)
3441 {
3442 bool lastZeroFlag = _zeroFlag;
3443
3444 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
3445
3446 // check outside region
3447 if (lpos.Z < -100 || lpos.Z > 100000f)
3448 {
3449 m_outbounds = true;
3450
3451 lpos.Z = Util.Clip(lpos.Z, -100f, 100000f);
3452 _acceleration.X = 0;
3453 _acceleration.Y = 0;
3454 _acceleration.Z = 0;
3455
3456 _velocity.X = 0;
3457 _velocity.Y = 0;
3458 _velocity.Z = 0;
3459 m_rotationalVelocity.X = 0;
3460 m_rotationalVelocity.Y = 0;
3461 m_rotationalVelocity.Z = 0;
3462
3463 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3464 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
3465 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
3466 m_lastposition = _position;
3467 m_lastorientation = _orientation;
3468
3469 base.RequestPhysicsterseUpdate();
3470
3471// throttleCounter = 0;
3472 _zeroFlag = true;
3473
3474 disableBodySoft(); // disable it and colisions
3475 base.RaiseOutOfBounds(_position);
3476 return;
3477 }
3478
3479 if (lpos.X < 0f)
3480 {
3481 _position.X = Util.Clip(lpos.X, -2f, -0.1f);
3482 m_outbounds = true;
3483 }
3484 else if (lpos.X > _parent_scene.WorldExtents.X)
3485 {
3486 _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
3487 m_outbounds = true;
3488 }
3489 if (lpos.Y < 0f)
3490 {
3491 _position.Y = Util.Clip(lpos.Y, -2f, -0.1f);
3492 m_outbounds = true;
3493 }
3494 else if (lpos.Y > _parent_scene.WorldExtents.Y)
3495 {
3496 _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
3497 m_outbounds = true;
3498 }
3499
3500 if (m_outbounds)
3501 {
3502 m_lastposition = _position;
3503 m_lastorientation = _orientation;
3504
3505 d.Vector3 dtmp = d.BodyGetAngularVel(Body);
3506 m_rotationalVelocity.X = dtmp.X;
3507 m_rotationalVelocity.Y = dtmp.Y;
3508 m_rotationalVelocity.Z = dtmp.Z;
3509
3510 dtmp = d.BodyGetLinearVel(Body);
3511 _velocity.X = dtmp.X;
3512 _velocity.Y = dtmp.Y;
3513 _velocity.Z = dtmp.Z;
3514
3515 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3516 d.BodySetAngularVel(Body, 0, 0, 0);
3517 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
3518 disableBodySoft(); // stop collisions
3519 UnSubscribeEvents();
3520
3521 base.RequestPhysicsterseUpdate();
3522 return;
3523 }
3524
3525 d.Quaternion ori;
3526 d.GeomCopyQuaternion(prim_geom, out ori);
3527
3528 // decide if moving
3529 // use positions since this are integrated quantities
3530 // tolerance values depende a lot on simulation noise...
3531 // use simple math.abs since we dont need to be exact
3532
3533 if (!bodyenabled ||
3534 (Math.Abs(_position.X - lpos.X) < 0.005f)
3535 && (Math.Abs(_position.Y - lpos.Y) < 0.005f)
3536 && (Math.Abs(_position.Z - lpos.Z) < 0.005f)
3537 && (Math.Abs(_orientation.X - ori.X) < 0.0005f)
3538 && (Math.Abs(_orientation.Y - ori.Y) < 0.0005f)
3539 && (Math.Abs(_orientation.Z - ori.Z) < 0.0005f) // ignore W
3540 )
3541 {
3542 _zeroFlag = true;
3543 }
3544 else
3545 _zeroFlag = false;
3546
3547 // update velocities and aceleration
3548 if (!(_zeroFlag && lastZeroFlag))
3549 {
3550 d.Vector3 vel = d.BodyGetLinearVel(Body);
3551
3552 _acceleration = _velocity;
3553
3554 if ((Math.Abs(vel.X) < 0.005f) &&
3555 (Math.Abs(vel.Y) < 0.005f) &&
3556 (Math.Abs(vel.Z) < 0.005f))
3557 {
3558 _velocity = Vector3.Zero;
3559 float t = -m_invTimeStep;
3560 _acceleration = _acceleration * t;
3561 }
3562 else
3563 {
3564 _velocity.X = vel.X;
3565 _velocity.Y = vel.Y;
3566 _velocity.Z = vel.Z;
3567 _acceleration = (_velocity - _acceleration) * m_invTimeStep;
3568 }
3569
3570 if ((Math.Abs(_acceleration.X) < 0.01f) &&
3571 (Math.Abs(_acceleration.Y) < 0.01f) &&
3572 (Math.Abs(_acceleration.Z) < 0.01f))
3573 {
3574 _acceleration = Vector3.Zero;
3575 }
3576
3577 if ((Math.Abs(_orientation.X - ori.X) < 0.0001) &&
3578 (Math.Abs(_orientation.Y - ori.Y) < 0.0001) &&
3579 (Math.Abs(_orientation.Z - ori.Z) < 0.0001)
3580 )
3581 {
3582 m_rotationalVelocity = Vector3.Zero;
3583 }
3584 else
3585 {
3586 vel = d.BodyGetAngularVel(Body);
3587 m_rotationalVelocity.X = vel.X;
3588 m_rotationalVelocity.Y = vel.Y;
3589 m_rotationalVelocity.Z = vel.Z;
3590 }
3591 // }
3592
3593 _position.X = lpos.X;
3594 _position.Y = lpos.Y;
3595 _position.Z = lpos.Z;
3596
3597 _orientation.X = ori.X;
3598 _orientation.Y = ori.Y;
3599 _orientation.Z = ori.Z;
3600 _orientation.W = ori.W;
3601 }
3602 if (_zeroFlag)
3603 {
3604 if (lastZeroFlag)
3605 {
3606 _velocity = Vector3.Zero;
3607 _acceleration = Vector3.Zero;
3608 m_rotationalVelocity = Vector3.Zero;
3609 }
3610
3611 if (!m_lastUpdateSent)
3612 {
3613 base.RequestPhysicsterseUpdate();
3614 if (lastZeroFlag)
3615 m_lastUpdateSent = true;
3616 }
3617 return;
3618 }
3619
3620 base.RequestPhysicsterseUpdate();
3621 m_lastUpdateSent = false;
3622 }
3623 }
3624 }
3625
3626 internal static bool QuaternionIsFinite(Quaternion q)
3627 {
3628 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
3629 return false;
3630 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
3631 return false;
3632 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
3633 return false;
3634 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
3635 return false;
3636 return true;
3637 }
3638
3639 internal static void DMassSubPartFromObj(ref d.Mass part, ref d.Mass theobj)
3640 {
3641 // assumes object center of mass is zero
3642 float smass = part.mass;
3643 theobj.mass -= smass;
3644
3645 smass *= 1.0f / (theobj.mass); ;
3646
3647 theobj.c.X -= part.c.X * smass;
3648 theobj.c.Y -= part.c.Y * smass;
3649 theobj.c.Z -= part.c.Z * smass;
3650
3651 theobj.I.M00 -= part.I.M00;
3652 theobj.I.M01 -= part.I.M01;
3653 theobj.I.M02 -= part.I.M02;
3654 theobj.I.M10 -= part.I.M10;
3655 theobj.I.M11 -= part.I.M11;
3656 theobj.I.M12 -= part.I.M12;
3657 theobj.I.M20 -= part.I.M20;
3658 theobj.I.M21 -= part.I.M21;
3659 theobj.I.M22 -= part.I.M22;
3660 }
3661
3662 private void donullchange()
3663 {
3664 }
3665
3666 public bool DoAChange(changes what, object arg)
3667 {
3668 if (prim_geom == IntPtr.Zero && what != changes.Add && what != changes.AddPhysRep && what != changes.Remove)
3669 {
3670 return false;
3671 }
3672
3673 // nasty switch
3674 switch (what)
3675 {
3676 case changes.Add:
3677 changeadd();
3678 break;
3679
3680 case changes.AddPhysRep:
3681 changeAddPhysRep((ODEPhysRepData)arg);
3682 break;
3683
3684 case changes.Remove:
3685 //If its being removed, we don't want to rebuild the physical rep at all, so ignore this stuff...
3686 //When we return true, it destroys all of the prims in the linkset anyway
3687 if (_parent != null)
3688 {
3689 OdePrim parent = (OdePrim)_parent;
3690 parent.ChildRemove(this, false);
3691 }
3692 else
3693 ChildRemove(this, false);
3694
3695 m_vehicle = null;
3696 RemoveGeom();
3697 m_targetSpace = IntPtr.Zero;
3698 UnSubscribeEvents();
3699 return true;
3700
3701 case changes.Link:
3702 OdePrim tmp = (OdePrim)arg;
3703 changeLink(tmp);
3704 break;
3705
3706 case changes.DeLink:
3707 changeLink(null);
3708 break;
3709
3710 case changes.Position:
3711 changePosition((Vector3)arg);
3712 break;
3713
3714 case changes.Orientation:
3715 changeOrientation((Quaternion)arg);
3716 break;
3717
3718 case changes.PosOffset:
3719 donullchange();
3720 break;
3721
3722 case changes.OriOffset:
3723 donullchange();
3724 break;
3725
3726 case changes.Velocity:
3727 changevelocity((Vector3)arg);
3728 break;
3729
3730// case changes.Acceleration:
3731// changeacceleration((Vector3)arg);
3732// break;
3733
3734 case changes.AngVelocity:
3735 changeangvelocity((Vector3)arg);
3736 break;
3737
3738 case changes.Force:
3739 changeForce((Vector3)arg);
3740 break;
3741
3742 case changes.Torque:
3743 changeSetTorque((Vector3)arg);
3744 break;
3745
3746 case changes.AddForce:
3747 changeAddForce((Vector3)arg);
3748 break;
3749
3750 case changes.AddAngForce:
3751 changeAddAngularImpulse((Vector3)arg);
3752 break;
3753
3754 case changes.AngLock:
3755 changeAngularLock((Vector3)arg);
3756 break;
3757
3758 case changes.Size:
3759 changeSize((Vector3)arg);
3760 break;
3761
3762 case changes.Shape:
3763 changeShape((PrimitiveBaseShape)arg);
3764 break;
3765
3766 case changes.PhysRepData:
3767 changePhysRepData((ODEPhysRepData) arg);
3768 break;
3769
3770 case changes.CollidesWater:
3771 changeFloatOnWater((bool)arg);
3772 break;
3773
3774 case changes.VolumeDtc:
3775 changeVolumedetetion((bool)arg);
3776 break;
3777
3778 case changes.Phantom:
3779 changePhantomStatus((bool)arg);
3780 break;
3781
3782 case changes.Physical:
3783 changePhysicsStatus((bool)arg);
3784 break;
3785
3786 case changes.Selected:
3787 changeSelectedStatus((bool)arg);
3788 break;
3789
3790 case changes.disabled:
3791 changeDisable((bool)arg);
3792 break;
3793
3794 case changes.building:
3795 changeBuilding((bool)arg);
3796 break;
3797
3798 case changes.VehicleType:
3799 changeVehicleType((int)arg);
3800 break;
3801
3802 case changes.VehicleFlags:
3803 changeVehicleFlags((strVehicleBoolParam) arg);
3804 break;
3805
3806 case changes.VehicleFloatParam:
3807 changeVehicleFloatParam((strVehicleFloatParam) arg);
3808 break;
3809
3810 case changes.VehicleVectorParam:
3811 changeVehicleVectorParam((strVehicleVectorParam) arg);
3812 break;
3813
3814 case changes.VehicleRotationParam:
3815 changeVehicleRotationParam((strVehicleQuatParam) arg);
3816 break;
3817
3818 case changes.SetVehicle:
3819 changeSetVehicle((VehicleData) arg);
3820 break;
3821
3822 case changes.Buoyancy:
3823 changeBuoyancy((float)arg);
3824 break;
3825
3826 case changes.PIDTarget:
3827 changePIDTarget((Vector3)arg);
3828 break;
3829
3830 case changes.PIDTau:
3831 changePIDTau((float)arg);
3832 break;
3833
3834 case changes.PIDActive:
3835 changePIDActive((bool)arg);
3836 break;
3837
3838 case changes.PIDHoverHeight:
3839 changePIDHoverHeight((float)arg);
3840 break;
3841
3842 case changes.PIDHoverType:
3843 changePIDHoverType((PIDHoverType)arg);
3844 break;
3845
3846 case changes.PIDHoverTau:
3847 changePIDHoverTau((float)arg);
3848 break;
3849
3850 case changes.PIDHoverActive:
3851 changePIDHoverActive((bool)arg);
3852 break;
3853
3854 case changes.Null:
3855 donullchange();
3856 break;
3857
3858
3859
3860 default:
3861 donullchange();
3862 break;
3863 }
3864 return false;
3865 }
3866
3867 public void AddChange(changes what, object arg)
3868 {
3869 _parent_scene.AddChange((PhysicsActor) this, what, arg);
3870 }
3871
3872
3873 private struct strVehicleBoolParam
3874 {
3875 public int param;
3876 public bool value;
3877 }
3878
3879 private struct strVehicleFloatParam
3880 {
3881 public int param;
3882 public float value;
3883 }
3884
3885 private struct strVehicleQuatParam
3886 {
3887 public int param;
3888 public Quaternion value;
3889 }
3890
3891 private struct strVehicleVectorParam
3892 {
3893 public int param;
3894 public Vector3 value;
3895 }
3896 }
3897}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
new file mode 100644
index 0000000..73ababa
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
@@ -0,0 +1,683 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Runtime.InteropServices;
32using System.Text;
33using OpenSim.Framework;
34using OpenSim.Region.Physics.Manager;
35using OdeAPI;
36using log4net;
37using OpenMetaverse;
38
39namespace OpenSim.Region.Physics.OdePlugin
40{
41 /// <summary>
42 /// Processes raycast requests as ODE is in a state to be able to do them.
43 /// This ensures that it's thread safe and there will be no conflicts.
44 /// Requests get returned by a different thread then they were requested by.
45 /// </summary>
46 public class ODERayCastRequestManager
47 {
48 /// <summary>
49 /// Pending ray requests
50 /// </summary>
51 protected OpenSim.Framework.LocklessQueue<ODERayRequest> m_PendingRequests = new OpenSim.Framework.LocklessQueue<ODERayRequest>();
52
53 /// <summary>
54 /// Scene that created this object.
55 /// </summary>
56 private OdeScene m_scene;
57
58 IntPtr ray; // the ray. we only need one for our lifetime
59 IntPtr Sphere;
60 IntPtr Box;
61 IntPtr Plane;
62
63 private int CollisionContactGeomsPerTest = 25;
64 private const int DefaultMaxCount = 25;
65 private const int MaxTimePerCallMS = 30;
66
67 /// <summary>
68 /// ODE near callback delegate
69 /// </summary>
70 private d.NearCallback nearCallback;
71 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
72 private List<ContactResult> m_contactResults = new List<ContactResult>();
73 private RayFilterFlags CurrentRayFilter;
74 private int CurrentMaxCount;
75
76 public ODERayCastRequestManager(OdeScene pScene)
77 {
78 m_scene = pScene;
79 nearCallback = near;
80 ray = d.CreateRay(IntPtr.Zero, 1.0f);
81 d.GeomSetCategoryBits(ray, 0);
82 Box = d.CreateBox(IntPtr.Zero, 1.0f, 1.0f, 1.0f);
83 d.GeomSetCategoryBits(Box, 0);
84 Sphere = d.CreateSphere(IntPtr.Zero,1.0f);
85 d.GeomSetCategoryBits(Sphere, 0);
86 Plane = d.CreatePlane(IntPtr.Zero, 0f,0f,1f,1f);
87 d.GeomSetCategoryBits(Sphere, 0);
88 }
89
90 public void QueueRequest(ODERayRequest req)
91 {
92 if (req.Count == 0)
93 req.Count = DefaultMaxCount;
94
95 m_PendingRequests.Enqueue(req);
96 }
97
98 /// <summary>
99 /// Process all queued raycast requests
100 /// </summary>
101 /// <returns>Time in MS the raycasts took to process.</returns>
102 public int ProcessQueuedRequests()
103 {
104
105 if (m_PendingRequests.Count <= 0)
106 return 0;
107
108 if (m_scene.ContactgeomsArray == IntPtr.Zero || ray == IntPtr.Zero)
109 // oops something got wrong or scene isn't ready still
110 {
111 m_PendingRequests.Clear();
112 return 0;
113 }
114
115 int time = Util.EnvironmentTickCount();
116
117 ODERayRequest req;
118 int closestHit;
119 int backfacecull;
120 CollisionCategories catflags;
121
122 while (m_PendingRequests.Dequeue(out req))
123 {
124 if (req.callbackMethod != null)
125 {
126 IntPtr geom = IntPtr.Zero;
127 if (req.actor != null)
128 {
129 if (m_scene.haveActor(req.actor))
130 {
131 if (req.actor is OdePrim)
132 geom = ((OdePrim)req.actor).prim_geom;
133 else if (req.actor is OdeCharacter)
134 geom = ((OdePrim)req.actor).prim_geom;
135 }
136 if (geom == IntPtr.Zero)
137 {
138 NoContacts(req);
139 continue;
140 }
141 }
142
143
144 CurrentRayFilter = req.filter;
145 CurrentMaxCount = req.Count;
146
147 CollisionContactGeomsPerTest = req.Count & 0xffff;
148
149 closestHit = ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0 ? 0 : 1);
150 backfacecull = ((CurrentRayFilter & RayFilterFlags.BackFaceCull) == 0 ? 0 : 1);
151
152 if (req.callbackMethod is ProbeBoxCallback)
153 {
154 if (CollisionContactGeomsPerTest > 80)
155 CollisionContactGeomsPerTest = 80;
156 d.GeomBoxSetLengths(Box, req.Normal.X, req.Normal.Y, req.Normal.Z);
157 d.GeomSetPosition(Box, req.Origin.X, req.Origin.Y, req.Origin.Z);
158 d.Quaternion qtmp;
159 qtmp.X = req.orientation.X;
160 qtmp.Y = req.orientation.Y;
161 qtmp.Z = req.orientation.Z;
162 qtmp.W = req.orientation.W;
163 d.GeomSetQuaternion(Box, ref qtmp);
164 }
165 else if (req.callbackMethod is ProbeSphereCallback)
166 {
167 if (CollisionContactGeomsPerTest > 80)
168 CollisionContactGeomsPerTest = 80;
169
170 d.GeomSphereSetRadius(Sphere, req.length);
171 d.GeomSetPosition(Sphere, req.Origin.X, req.Origin.Y, req.Origin.Z);
172 }
173 else if (req.callbackMethod is ProbePlaneCallback)
174 {
175 if (CollisionContactGeomsPerTest > 80)
176 CollisionContactGeomsPerTest = 80;
177
178 d.GeomPlaneSetParams(Plane, req.Normal.X, req.Normal.Y, req.Normal.Z, req.length);
179 }
180
181 else
182 {
183 if (CollisionContactGeomsPerTest > 25)
184 CollisionContactGeomsPerTest = 25;
185
186 d.GeomRaySetLength(ray, req.length);
187 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
188 d.GeomRaySetParams(ray, 0, backfacecull);
189 d.GeomRaySetClosestHit(ray, closestHit);
190
191 if (req.callbackMethod is RaycastCallback)
192 {
193 // if we only want one get only one per Collision pair saving memory
194 CurrentRayFilter |= RayFilterFlags.ClosestHit;
195 d.GeomRaySetClosestHit(ray, 1);
196 }
197 else
198 d.GeomRaySetClosestHit(ray, closestHit);
199 }
200
201 if ((CurrentRayFilter & RayFilterFlags.ContactsUnImportant) != 0)
202 unchecked
203 {
204 CollisionContactGeomsPerTest |= (int)d.CONTACTS_UNIMPORTANT;
205 }
206
207 if (geom == IntPtr.Zero)
208 {
209 // translate ray filter to Collision flags
210 catflags = 0;
211 if ((CurrentRayFilter & RayFilterFlags.volumedtc) != 0)
212 catflags |= CollisionCategories.VolumeDtc;
213 if ((CurrentRayFilter & RayFilterFlags.phantom) != 0)
214 catflags |= CollisionCategories.Phantom;
215 if ((CurrentRayFilter & RayFilterFlags.agent) != 0)
216 catflags |= CollisionCategories.Character;
217 if ((CurrentRayFilter & RayFilterFlags.PrimsNonPhantom) != 0)
218 catflags |= CollisionCategories.Geom;
219 if ((CurrentRayFilter & RayFilterFlags.land) != 0)
220 catflags |= CollisionCategories.Land;
221 if ((CurrentRayFilter & RayFilterFlags.water) != 0)
222 catflags |= CollisionCategories.Water;
223
224 if (catflags != 0)
225 {
226 if (req.callbackMethod is ProbeBoxCallback)
227 {
228 catflags |= CollisionCategories.Space;
229 d.GeomSetCollideBits(Box, (uint)catflags);
230 d.GeomSetCategoryBits(Box, (uint)catflags);
231 doProbe(req, Box);
232 }
233 else if (req.callbackMethod is ProbeSphereCallback)
234 {
235 catflags |= CollisionCategories.Space;
236 d.GeomSetCollideBits(Sphere, (uint)catflags);
237 d.GeomSetCategoryBits(Sphere, (uint)catflags);
238 doProbe(req, Sphere);
239 }
240 else if (req.callbackMethod is ProbePlaneCallback)
241 {
242 catflags |= CollisionCategories.Space;
243 d.GeomSetCollideBits(Plane, (uint)catflags);
244 d.GeomSetCategoryBits(Plane, (uint)catflags);
245 doPlane(req,IntPtr.Zero);
246 }
247 else
248 {
249 d.GeomSetCollideBits(ray, (uint)catflags);
250 doSpaceRay(req);
251 }
252 }
253 }
254 else
255 {
256 // if we select a geom don't use filters
257
258 if (req.callbackMethod is ProbePlaneCallback)
259 {
260 d.GeomSetCollideBits(Plane, (uint)CollisionCategories.All);
261 doPlane(req,geom);
262 }
263 else
264 {
265 d.GeomSetCollideBits(ray, (uint)CollisionCategories.All);
266 doGeomRay(req,geom);
267 }
268 }
269 }
270
271 if (Util.EnvironmentTickCountSubtract(time) > MaxTimePerCallMS)
272 break;
273 }
274
275 lock (m_contactResults)
276 m_contactResults.Clear();
277
278 return Util.EnvironmentTickCountSubtract(time);
279 }
280 /// <summary>
281 /// Method that actually initiates the raycast with spaces
282 /// </summary>
283 /// <param name="req"></param>
284 ///
285
286 private void NoContacts(ODERayRequest req)
287 {
288 if (req.callbackMethod is RaycastCallback)
289 {
290 ((RaycastCallback)req.callbackMethod)(false, Vector3.Zero, 0, 0, Vector3.Zero);
291 return;
292 }
293 List<ContactResult> cresult = new List<ContactResult>();
294
295 if (req.callbackMethod is RayCallback)
296 ((RayCallback)req.callbackMethod)(cresult);
297 else if (req.callbackMethod is ProbeBoxCallback)
298 ((ProbeBoxCallback)req.callbackMethod)(cresult);
299 else if (req.callbackMethod is ProbeSphereCallback)
300 ((ProbeSphereCallback)req.callbackMethod)(cresult);
301 }
302
303 private const RayFilterFlags FilterActiveSpace = RayFilterFlags.agent | RayFilterFlags.physical | RayFilterFlags.LSLPhantom;
304// private const RayFilterFlags FilterStaticSpace = RayFilterFlags.water | RayFilterFlags.land | RayFilterFlags.nonphysical | RayFilterFlags.LSLPhanton;
305 private const RayFilterFlags FilterStaticSpace = RayFilterFlags.water | RayFilterFlags.nonphysical | RayFilterFlags.LSLPhantom;
306
307 private void doSpaceRay(ODERayRequest req)
308 {
309 // Collide tests
310 if ((CurrentRayFilter & FilterActiveSpace) != 0)
311 {
312 d.SpaceCollide2(ray, m_scene.ActiveSpace, IntPtr.Zero, nearCallback);
313 d.SpaceCollide2(ray, m_scene.CharsSpace, IntPtr.Zero, nearCallback);
314 }
315 if ((CurrentRayFilter & FilterStaticSpace) != 0 && (m_contactResults.Count < CurrentMaxCount))
316 d.SpaceCollide2(ray, m_scene.StaticSpace, IntPtr.Zero, nearCallback);
317 if ((CurrentRayFilter & RayFilterFlags.land) != 0 && (m_contactResults.Count < CurrentMaxCount))
318 {
319 // current ode land to ray collisions is very bad
320 // so for now limit its range badly
321
322 if (req.length > 30.0f)
323 d.GeomRaySetLength(ray, 30.0f);
324
325 d.SpaceCollide2(ray, m_scene.GroundSpace, IntPtr.Zero, nearCallback);
326 }
327
328 if (req.callbackMethod is RaycastCallback)
329 {
330 // Define default results
331 bool hitYN = false;
332 uint hitConsumerID = 0;
333 float distance = float.MaxValue;
334 Vector3 closestcontact = Vector3.Zero;
335 Vector3 snormal = Vector3.Zero;
336
337 // Find closest contact and object.
338 lock (m_contactResults)
339 {
340 foreach (ContactResult cResult in m_contactResults)
341 {
342 if(cResult.Depth < distance)
343 {
344 closestcontact = cResult.Pos;
345 hitConsumerID = cResult.ConsumerID;
346 distance = cResult.Depth;
347 snormal = cResult.Normal;
348 }
349 }
350 m_contactResults.Clear();
351 }
352
353 if (distance > 0 && distance < float.MaxValue)
354 hitYN = true;
355 ((RaycastCallback)req.callbackMethod)(hitYN, closestcontact, hitConsumerID, distance, snormal);
356 }
357 else
358 {
359 List<ContactResult> cresult = new List<ContactResult>(m_contactResults.Count);
360 lock (m_PendingRequests)
361 {
362 cresult.AddRange(m_contactResults);
363 m_contactResults.Clear();
364 }
365 ((RayCallback)req.callbackMethod)(cresult);
366 }
367 }
368
369 private void doProbe(ODERayRequest req, IntPtr probe)
370 {
371 // Collide tests
372 if ((CurrentRayFilter & FilterActiveSpace) != 0)
373 {
374 d.SpaceCollide2(probe, m_scene.ActiveSpace, IntPtr.Zero, nearCallback);
375 d.SpaceCollide2(probe, m_scene.CharsSpace, IntPtr.Zero, nearCallback);
376 }
377 if ((CurrentRayFilter & FilterStaticSpace) != 0 && (m_contactResults.Count < CurrentMaxCount))
378 d.SpaceCollide2(probe, m_scene.StaticSpace, IntPtr.Zero, nearCallback);
379 if ((CurrentRayFilter & RayFilterFlags.land) != 0 && (m_contactResults.Count < CurrentMaxCount))
380 d.SpaceCollide2(probe, m_scene.GroundSpace, IntPtr.Zero, nearCallback);
381
382 List<ContactResult> cresult = new List<ContactResult>(m_contactResults.Count);
383 lock (m_PendingRequests)
384 {
385 cresult.AddRange(m_contactResults);
386 m_contactResults.Clear();
387 }
388 if (req.callbackMethod is ProbeBoxCallback)
389 ((ProbeBoxCallback)req.callbackMethod)(cresult);
390 else if (req.callbackMethod is ProbeSphereCallback)
391 ((ProbeSphereCallback)req.callbackMethod)(cresult);
392 }
393
394 private void doPlane(ODERayRequest req,IntPtr geom)
395 {
396 // Collide tests
397 if (geom == IntPtr.Zero)
398 {
399 if ((CurrentRayFilter & FilterActiveSpace) != 0)
400 {
401 d.SpaceCollide2(Plane, m_scene.ActiveSpace, IntPtr.Zero, nearCallback);
402 d.SpaceCollide2(Plane, m_scene.CharsSpace, IntPtr.Zero, nearCallback);
403 }
404 if ((CurrentRayFilter & FilterStaticSpace) != 0 && (m_contactResults.Count < CurrentMaxCount))
405 d.SpaceCollide2(Plane, m_scene.StaticSpace, IntPtr.Zero, nearCallback);
406 if ((CurrentRayFilter & RayFilterFlags.land) != 0 && (m_contactResults.Count < CurrentMaxCount))
407 d.SpaceCollide2(Plane, m_scene.GroundSpace, IntPtr.Zero, nearCallback);
408 }
409 else
410 {
411 d.SpaceCollide2(Plane, geom, IntPtr.Zero, nearCallback);
412 }
413
414 List<ContactResult> cresult = new List<ContactResult>(m_contactResults.Count);
415 lock (m_PendingRequests)
416 {
417 cresult.AddRange(m_contactResults);
418 m_contactResults.Clear();
419 }
420
421 ((ProbePlaneCallback)req.callbackMethod)(cresult);
422 }
423
424 /// <summary>
425 /// Method that actually initiates the raycast with a geom
426 /// </summary>
427 /// <param name="req"></param>
428 private void doGeomRay(ODERayRequest req, IntPtr geom)
429 {
430 // Collide test
431 d.SpaceCollide2(ray, geom, IntPtr.Zero, nearCallback); // still do this to have full AABB pre test
432
433 if (req.callbackMethod is RaycastCallback)
434 {
435 // Define default results
436 bool hitYN = false;
437 uint hitConsumerID = 0;
438 float distance = float.MaxValue;
439 Vector3 closestcontact = Vector3.Zero;
440 Vector3 snormal = Vector3.Zero;
441
442 // Find closest contact and object.
443 lock (m_contactResults)
444 {
445 foreach (ContactResult cResult in m_contactResults)
446 {
447 if(cResult.Depth < distance )
448 {
449 closestcontact = cResult.Pos;
450 hitConsumerID = cResult.ConsumerID;
451 distance = cResult.Depth;
452 snormal = cResult.Normal;
453 }
454 }
455 m_contactResults.Clear();
456 }
457
458 if (distance > 0 && distance < float.MaxValue)
459 hitYN = true;
460
461 ((RaycastCallback)req.callbackMethod)(hitYN, closestcontact, hitConsumerID, distance, snormal);
462 }
463 else
464 {
465 List<ContactResult> cresult = new List<ContactResult>(m_contactResults.Count);
466 lock (m_PendingRequests)
467 {
468 cresult.AddRange(m_contactResults);
469 m_contactResults.Clear();
470 }
471 ((RayCallback)req.callbackMethod)(cresult);
472 }
473 }
474
475 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom)
476 {
477 IntPtr ContactgeomsArray = m_scene.ContactgeomsArray;
478 if (ContactgeomsArray == IntPtr.Zero || index >= CollisionContactGeomsPerTest)
479 return false;
480
481 IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * d.ContactGeom.unmanagedSizeOf));
482 newcontactgeom = (d.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(d.ContactGeom));
483 return true;
484 }
485
486 // This is the standard Near. g1 is the ray
487 private void near(IntPtr space, IntPtr g1, IntPtr g2)
488 {
489 if (g2 == IntPtr.Zero || g1 == g2)
490 return;
491
492 if (m_contactResults.Count >= CurrentMaxCount)
493 return;
494
495 if (d.GeomIsSpace(g2))
496 {
497 try
498 {
499 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
500 }
501 catch (Exception e)
502 {
503 m_log.WarnFormat("[PHYSICS Ray]: Unable to Space collide test an object: {0}", e.Message);
504 }
505 return;
506 }
507
508 int count = 0;
509 try
510 {
511 count = d.CollidePtr(g1, g2, CollisionContactGeomsPerTest, m_scene.ContactgeomsArray, d.ContactGeom.unmanagedSizeOf);
512 }
513 catch (Exception e)
514 {
515 m_log.WarnFormat("[PHYSICS Ray]: Unable to collide test an object: {0}", e.Message);
516 return;
517 }
518
519 if (count == 0)
520 return;
521/*
522 uint cat1 = d.GeomGetCategoryBits(g1);
523 uint cat2 = d.GeomGetCategoryBits(g2);
524 uint col1 = d.GeomGetCollideBits(g1);
525 uint col2 = d.GeomGetCollideBits(g2);
526*/
527
528 uint ID = 0;
529 PhysicsActor p2 = null;
530
531 m_scene.actor_name_map.TryGetValue(g2, out p2);
532
533 if (p2 == null)
534 return;
535
536 switch (p2.PhysicsActorType)
537 {
538 case (int)ActorTypes.Prim:
539
540 RayFilterFlags thisFlags;
541
542 if (p2.IsPhysical)
543 thisFlags = RayFilterFlags.physical;
544 else
545 thisFlags = RayFilterFlags.nonphysical;
546
547 if (p2.Phantom)
548 thisFlags |= RayFilterFlags.phantom;
549
550 if (p2.IsVolumeDtc)
551 thisFlags |= RayFilterFlags.volumedtc;
552
553 if ((thisFlags & CurrentRayFilter) == 0)
554 return;
555
556 ID = ((OdePrim)p2).LocalID;
557 break;
558
559 case (int)ActorTypes.Agent:
560
561 if ((CurrentRayFilter & RayFilterFlags.agent) == 0)
562 return;
563 else
564 ID = ((OdeCharacter)p2).LocalID;
565 break;
566
567 case (int)ActorTypes.Ground:
568
569 if ((CurrentRayFilter & RayFilterFlags.land) == 0)
570 return;
571 break;
572
573 case (int)ActorTypes.Water:
574
575 if ((CurrentRayFilter & RayFilterFlags.water) == 0)
576 return;
577 break;
578
579 default:
580 break;
581 }
582
583 d.ContactGeom curcontact = new d.ContactGeom();
584
585 // closestHit for now only works for meshs, so must do it for others
586 if ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0)
587 {
588 // Loop all contacts, build results.
589 for (int i = 0; i < count; i++)
590 {
591 if (!GetCurContactGeom(i, ref curcontact))
592 break;
593
594 ContactResult collisionresult = new ContactResult();
595 collisionresult.ConsumerID = ID;
596 collisionresult.Pos.X = curcontact.pos.X;
597 collisionresult.Pos.Y = curcontact.pos.Y;
598 collisionresult.Pos.Z = curcontact.pos.Z;
599 collisionresult.Depth = curcontact.depth;
600 collisionresult.Normal.X = curcontact.normal.X;
601 collisionresult.Normal.Y = curcontact.normal.Y;
602 collisionresult.Normal.Z = curcontact.normal.Z;
603 lock (m_contactResults)
604 {
605 m_contactResults.Add(collisionresult);
606 if (m_contactResults.Count >= CurrentMaxCount)
607 return;
608 }
609 }
610 }
611 else
612 {
613 // keep only closest contact
614 ContactResult collisionresult = new ContactResult();
615 collisionresult.ConsumerID = ID;
616 collisionresult.Depth = float.MaxValue;
617
618 for (int i = 0; i < count; i++)
619 {
620 if (!GetCurContactGeom(i, ref curcontact))
621 break;
622
623 if (curcontact.depth < collisionresult.Depth)
624 {
625 collisionresult.Pos.X = curcontact.pos.X;
626 collisionresult.Pos.Y = curcontact.pos.Y;
627 collisionresult.Pos.Z = curcontact.pos.Z;
628 collisionresult.Depth = curcontact.depth;
629 collisionresult.Normal.X = curcontact.normal.X;
630 collisionresult.Normal.Y = curcontact.normal.Y;
631 collisionresult.Normal.Z = curcontact.normal.Z;
632 }
633 }
634
635 if (collisionresult.Depth != float.MaxValue)
636 {
637 lock (m_contactResults)
638 m_contactResults.Add(collisionresult);
639 }
640 }
641 }
642
643 /// <summary>
644 /// Dereference the creator scene so that it can be garbage collected if needed.
645 /// </summary>
646 internal void Dispose()
647 {
648 m_scene = null;
649 if (ray != IntPtr.Zero)
650 {
651 d.GeomDestroy(ray);
652 ray = IntPtr.Zero;
653 }
654 if (Box != IntPtr.Zero)
655 {
656 d.GeomDestroy(Box);
657 Box = IntPtr.Zero;
658 }
659 if (Sphere != IntPtr.Zero)
660 {
661 d.GeomDestroy(Sphere);
662 Sphere = IntPtr.Zero;
663 }
664 if (Plane != IntPtr.Zero)
665 {
666 d.GeomDestroy(Plane);
667 Plane = IntPtr.Zero;
668 }
669 }
670 }
671
672 public struct ODERayRequest
673 {
674 public PhysicsActor actor;
675 public Vector3 Origin;
676 public Vector3 Normal;
677 public int Count;
678 public float length;
679 public object callbackMethod;
680 public RayFilterFlags filter;
681 public Quaternion orientation;
682 }
683} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs
new file mode 100644
index 0000000..672212f
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs
@@ -0,0 +1,356 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27// Ubit 2012
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Runtime.InteropServices;
32using System.Text;
33using OpenSim.Framework;
34using OpenSim.Region.Physics.Manager;
35using OdeAPI;
36using log4net;
37using OpenMetaverse;
38
39namespace OpenSim.Region.Physics.OdePlugin
40{
41 /// <summary>
42 /// </summary>
43 public class ODESitAvatar
44 {
45 private OdeScene m_scene;
46 private ODERayCastRequestManager m_raymanager;
47
48 public ODESitAvatar(OdeScene pScene, ODERayCastRequestManager raymanager)
49 {
50 m_scene = pScene;
51 m_raymanager = raymanager;
52 }
53
54 private static Vector3 SitAjust = new Vector3(0, 0, 0.4f);
55 private const RayFilterFlags RaySitFlags = RayFilterFlags.AllPrims | RayFilterFlags.ClosestHit;
56
57 private void RotAroundZ(float x, float y, ref Quaternion ori)
58 {
59 double ang = Math.Atan2(y, x);
60 ang *= 0.5d;
61 float s = (float)Math.Sin(ang);
62 float c = (float)Math.Cos(ang);
63
64 ori.X = 0;
65 ori.Y = 0;
66 ori.Z = s;
67 ori.W = c;
68 }
69
70
71 public void Sit(PhysicsActor actor, Vector3 avPos, Vector3 avCameraPosition, Vector3 offset, Vector3 avOffset, SitAvatarCallback PhysicsSitResponse)
72 {
73 if (!m_scene.haveActor(actor) || !(actor is OdePrim) || ((OdePrim)actor).prim_geom == IntPtr.Zero)
74 {
75 PhysicsSitResponse(-1, actor.LocalID, offset, Quaternion.Identity);
76 return;
77 }
78
79 IntPtr geom = ((OdePrim)actor).prim_geom;
80
81 Vector3 geopos = d.GeomGetPositionOMV(geom);
82 Quaternion geomOri = d.GeomGetQuaternionOMV(geom);
83
84// Vector3 geopos = actor.Position;
85// Quaternion geomOri = actor.Orientation;
86
87 Quaternion geomInvOri = Quaternion.Conjugate(geomOri);
88
89 Quaternion ori = Quaternion.Identity;
90
91 Vector3 rayDir = geopos + offset - avCameraPosition;
92
93 float raylen = rayDir.Length();
94 if (raylen < 0.001f)
95 {
96 PhysicsSitResponse(-1, actor.LocalID, offset, Quaternion.Identity);
97 return;
98 }
99 float t = 1 / raylen;
100 rayDir.X *= t;
101 rayDir.Y *= t;
102 rayDir.Z *= t;
103
104 raylen += 30f; // focal point may be far
105 List<ContactResult> rayResults;
106
107 rayResults = m_scene.RaycastActor(actor, avCameraPosition, rayDir, raylen, 1, RaySitFlags);
108 if (rayResults.Count == 0)
109 {
110/* if this fundamental ray failed, then just fail so user can try another spot and not be sitted far on a big prim
111 d.AABB aabb;
112 d.GeomGetAABB(geom, out aabb);
113 offset = new Vector3(avOffset.X, 0, aabb.MaxZ + avOffset.Z - geopos.Z);
114 ori = geomInvOri;
115 offset *= geomInvOri;
116 PhysicsSitResponse(1, actor.LocalID, offset, ori);
117*/
118 PhysicsSitResponse(0, actor.LocalID, offset, ori);
119 return;
120 }
121
122 int status = 1;
123
124 offset = rayResults[0].Pos - geopos;
125
126 d.GeomClassID geoclass = d.GeomGetClass(geom);
127
128 if (geoclass == d.GeomClassID.SphereClass)
129 {
130 float r = d.GeomSphereGetRadius(geom);
131
132 offset.Normalize();
133 offset *= r;
134
135 RotAroundZ(offset.X, offset.Y, ref ori);
136
137 if (r < 0.4f)
138 {
139 offset = new Vector3(0, 0, r);
140 }
141 else
142 {
143 if (offset.Z < 0.4f)
144 {
145 t = offset.Z;
146 float rsq = r * r;
147
148 t = 1.0f / (rsq - t * t);
149 offset.X *= t;
150 offset.Y *= t;
151 offset.Z = 0.4f;
152 t = rsq - 0.16f;
153 offset.X *= t;
154 offset.Y *= t;
155 }
156 else if (r > 0.8f && offset.Z > 0.8f * r)
157 {
158 status = 3;
159 avOffset.X = -avOffset.X;
160 avOffset.Z *= 1.6f;
161 }
162 }
163
164 offset += avOffset * ori;
165
166 ori = geomInvOri * ori;
167 offset *= geomInvOri;
168
169 PhysicsSitResponse(status, actor.LocalID, offset, ori);
170 return;
171 }
172
173 Vector3 norm = rayResults[0].Normal;
174
175 if (norm.Z < -0.4f)
176 {
177 PhysicsSitResponse(0, actor.LocalID, offset, Quaternion.Identity);
178 return;
179 }
180
181
182 float SitNormX = -rayDir.X;
183 float SitNormY = -rayDir.Y;
184
185 Vector3 pivot = geopos + offset;
186
187 float edgeNormalX = norm.X;
188 float edgeNormalY = norm.Y;
189 float edgeDirX = -rayDir.X;
190 float edgeDirY = -rayDir.Y;
191 Vector3 edgePos = rayResults[0].Pos;
192 float edgeDist = float.MaxValue;
193
194 bool foundEdge = false;
195
196 if (norm.Z < 0.5f)
197 {
198 float rayDist = 4.0f;
199
200 for (int i = 0; i < 6; i++)
201 {
202 pivot.X -= 0.01f * norm.X;
203 pivot.Y -= 0.01f * norm.Y;
204 pivot.Z -= 0.01f * norm.Z;
205
206 rayDir.X = -norm.X * norm.Z;
207 rayDir.Y = -norm.Y * norm.Z;
208 rayDir.Z = 1.0f - norm.Z * norm.Z;
209 rayDir.Normalize();
210
211 rayResults = m_scene.RaycastActor(actor, pivot, rayDir, rayDist, 1, RayFilterFlags.AllPrims);
212 if (rayResults.Count == 0)
213 break;
214
215 if (Math.Abs(rayResults[0].Normal.Z) < 0.7f)
216 {
217 rayDist -= rayResults[0].Depth;
218 if (rayDist < 0f)
219 break;
220
221 pivot = rayResults[0].Pos;
222 norm = rayResults[0].Normal;
223 edgeNormalX = norm.X;
224 edgeNormalY = norm.Y;
225 edgeDirX = -rayDir.X;
226 edgeDirY = -rayDir.Y;
227 }
228 else
229 {
230 foundEdge = true;
231 edgePos = rayResults[0].Pos;
232 break;
233 }
234 }
235
236 if (!foundEdge)
237 {
238 PhysicsSitResponse(0, actor.LocalID, offset, ori);
239 return;
240 }
241 avOffset.X *= 0.5f;
242 }
243
244 else if (norm.Z > 0.866f)
245 {
246 float toCamBaseX = avCameraPosition.X - pivot.X;
247 float toCamBaseY = avCameraPosition.Y - pivot.Y;
248 float toCamX = toCamBaseX;
249 float toCamY = toCamBaseY;
250
251 for (int j = 0; j < 4; j++)
252 {
253 float rayDist = 1.0f;
254 float curEdgeDist = 0.0f;
255
256 for (int i = 0; i < 3; i++)
257 {
258 pivot.Z -= 0.01f;
259 rayDir.X = toCamX;
260 rayDir.Y = toCamY;
261 rayDir.Z = (-toCamX * norm.X - toCamY * norm.Y) / norm.Z;
262 rayDir.Normalize();
263
264 rayResults = m_scene.RaycastActor(actor, pivot, rayDir, rayDist, 1, RayFilterFlags.AllPrims);
265 if (rayResults.Count == 0)
266 break;
267
268 curEdgeDist += rayResults[0].Depth;
269
270 if (rayResults[0].Normal.Z > 0.5f)
271 {
272 rayDist -= rayResults[0].Depth;
273 if (rayDist < 0f)
274 break;
275
276 pivot = rayResults[0].Pos;
277 norm = rayResults[0].Normal;
278 }
279 else
280 {
281 foundEdge = true;
282 if (curEdgeDist < edgeDist)
283 {
284 edgeDist = curEdgeDist;
285 edgeNormalX = rayResults[0].Normal.X;
286 edgeNormalY = rayResults[0].Normal.Y;
287 edgeDirX = rayDir.X;
288 edgeDirY = rayDir.Y;
289 edgePos = rayResults[0].Pos;
290 }
291 break;
292 }
293 }
294 if (foundEdge && edgeDist < 0.2f)
295 break;
296
297 pivot = geopos + offset;
298
299 switch (j)
300 {
301 case 0:
302 toCamX = -toCamBaseY;
303 toCamY = toCamBaseX;
304 break;
305 case 1:
306 toCamX = toCamBaseY;
307 toCamY = -toCamBaseX;
308 break;
309 case 2:
310 toCamX = -toCamBaseX;
311 toCamY = -toCamBaseY;
312 break;
313 default:
314 break;
315 }
316 }
317
318 if (!foundEdge)
319 {
320 avOffset.X = -avOffset.X;
321 avOffset.Z *= 1.6f;
322
323 RotAroundZ(SitNormX, SitNormY, ref ori);
324
325 offset += avOffset * ori;
326
327 ori = geomInvOri * ori;
328 offset *= geomInvOri;
329
330 PhysicsSitResponse(3, actor.LocalID, offset, ori);
331 return;
332 }
333 avOffset.X *= 0.5f;
334 }
335
336 SitNormX = edgeNormalX;
337 SitNormY = edgeNormalY;
338 if (edgeDirX * SitNormX + edgeDirY * SitNormY < 0)
339 {
340 SitNormX = -SitNormX;
341 SitNormY = -SitNormY;
342 }
343
344 RotAroundZ(SitNormX, SitNormY, ref ori);
345
346 offset = edgePos + avOffset * ori;
347 offset -= geopos;
348
349 ori = geomInvOri * ori;
350 offset *= geomInvOri;
351
352 PhysicsSitResponse(1, actor.LocalID, offset, ori);
353 return;
354 }
355 }
356} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
new file mode 100644
index 0000000..10d7d50
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
@@ -0,0 +1,2025 @@
1/*
2 * based on:
3 * Ode.NET - .NET bindings for ODE
4 * Jason Perkins (starkos@industriousone.com)
5 * Licensed under the New BSD
6 * Part of the OpenDynamicsEngine
7Open Dynamics Engine
8Copyright (c) 2001-2007, Russell L. Smith.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
15Redistributions of source code must retain the above copyright notice,
16this list of conditions and the following disclaimer.
17
18Redistributions in binary form must reproduce the above copyright notice,
19this list of conditions and the following disclaimer in the documentation
20and/or other materials provided with the distribution.
21
22Neither the names of ODE's copyright owner nor the names of its
23contributors may be used to endorse or promote products derived from
24this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 * changes by opensim team;
39 * changes by Aurora team http://www.aurora-sim.org/
40
41 * Revision/fixs by Ubit Umarov
42 */
43
44using System;
45using System.Runtime.InteropServices;
46using System.Security;
47using OMV = OpenMetaverse;
48namespace OdeAPI
49{
50//#if dDOUBLE
51// don't see much use in double precision with time steps of 20ms and 10 iterations used on opensim
52// at least we save same memory and memory access time, FPU performance on intel usually is similar
53// using dReal = System.Double;
54//#else
55 using dReal = System.Single;
56//#endif
57
58 public static class d
59 {
60 public static dReal Infinity = dReal.MaxValue;
61 public static int NTotalBodies = 0;
62 public static int NTotalGeoms = 0;
63
64 public const uint CONTACTS_UNIMPORTANT = 0x80000000;
65
66 #region Flags and Enumerations
67
68 [Flags]
69 public enum AllocateODEDataFlags : uint
70 {
71 BasicData = 0,
72 CollisionData = 0x00000001,
73 All = ~0u
74 }
75
76 [Flags]
77 public enum IniteODEFlags : uint
78 {
79 dInitFlagManualThreadCleanup = 0x00000001
80 }
81
82 [Flags]
83 public enum ContactFlags : int
84 {
85 Mu2 = 0x001,
86 FDir1 = 0x002,
87 Bounce = 0x004,
88 SoftERP = 0x008,
89 SoftCFM = 0x010,
90 Motion1 = 0x020,
91 Motion2 = 0x040,
92 MotionN = 0x080,
93 Slip1 = 0x100,
94 Slip2 = 0x200,
95 Approx0 = 0x0000,
96 Approx1_1 = 0x1000,
97 Approx1_2 = 0x2000,
98 Approx1 = 0x3000
99 }
100
101 public enum GeomClassID : int
102 {
103 SphereClass,
104 BoxClass,
105 CapsuleClass,
106 CylinderClass,
107 PlaneClass,
108 RayClass,
109 ConvexClass,
110 GeomTransformClass,
111 TriMeshClass,
112 HeightfieldClass,
113 FirstSpaceClass,
114 SimpleSpaceClass = FirstSpaceClass,
115 HashSpaceClass,
116 QuadTreeSpaceClass,
117 LastSpaceClass = QuadTreeSpaceClass,
118 UbitTerrainClass,
119 FirstUserClass,
120 LastUserClass = FirstUserClass + MaxUserClasses - 1,
121 NumClasses,
122 MaxUserClasses = 5
123 }
124
125 public enum JointType : int
126 {
127 None,
128 Ball,
129 Hinge,
130 Slider,
131 Contact,
132 Universal,
133 Hinge2,
134 Fixed,
135 Null,
136 AMotor,
137 LMotor,
138 Plane2D
139 }
140
141 public enum JointParam : int
142 {
143 LoStop,
144 HiStop,
145 Vel,
146 FMax,
147 FudgeFactor,
148 Bounce,
149 CFM,
150 StopERP,
151 StopCFM,
152 SuspensionERP,
153 SuspensionCFM,
154 LoStop2 = 256,
155 HiStop2,
156 Vel2,
157 FMax2,
158 FudgeFactor2,
159 Bounce2,
160 CFM2,
161 StopERP2,
162 StopCFM2,
163 SuspensionERP2,
164 SuspensionCFM2,
165 LoStop3 = 512,
166 HiStop3,
167 Vel3,
168 FMax3,
169 FudgeFactor3,
170 Bounce3,
171 CFM3,
172 StopERP3,
173 StopCFM3,
174 SuspensionERP3,
175 SuspensionCFM3
176 }
177
178 public enum dSweepAndPruneAxis : int
179 {
180 XYZ = ((0)|(1<<2)|(2<<4)),
181 XZY = ((0)|(2<<2)|(1<<4)),
182 YXZ = ((1)|(0<<2)|(2<<4)),
183 YZX = ((1)|(2<<2)|(0<<4)),
184 ZXY = ((2)|(0<<2)|(1<<4)),
185 ZYX = ((2)|(1<<2)|(0<<4))
186 }
187
188 #endregion
189
190 #region Callbacks
191
192 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
193 public delegate int AABBTestFn(IntPtr o1, IntPtr o2, ref AABB aabb);
194
195 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
196 public delegate int ColliderFn(IntPtr o1, IntPtr o2, int flags, out ContactGeom contact, int skip);
197
198 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
199 public delegate void GetAABBFn(IntPtr geom, out AABB aabb);
200
201 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
202 public delegate ColliderFn GetColliderFnFn(int num);
203
204 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
205 public delegate void GeomDtorFn(IntPtr o);
206
207 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
208 public delegate dReal HeightfieldGetHeight(IntPtr p_user_data, int x, int z);
209
210 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
211 public delegate dReal UbitTerrainGetHeight(IntPtr p_user_data, int x, int z);
212
213 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
214 public delegate void NearCallback(IntPtr data, IntPtr geom1, IntPtr geom2);
215
216 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
217 public delegate int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex);
218
219 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
220 public delegate int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount);
221
222 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
223 public delegate int TriRayCallback(IntPtr trimesh, IntPtr ray, int triangleIndex, dReal u, dReal v);
224
225 #endregion
226
227 #region Structs
228
229 [StructLayout(LayoutKind.Sequential)]
230 public struct AABB
231 {
232 public dReal MinX, MaxX;
233 public dReal MinY, MaxY;
234 public dReal MinZ, MaxZ;
235 }
236
237
238 [StructLayout(LayoutKind.Sequential)]
239 public struct Contact
240 {
241 public SurfaceParameters surface;
242 public ContactGeom geom;
243 public Vector3 fdir1;
244 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(Contact));
245 }
246
247
248 [StructLayout(LayoutKind.Sequential)]
249 public struct ContactGeom
250 {
251
252 public Vector3 pos;
253 public Vector3 normal;
254 public dReal depth;
255 public IntPtr g1;
256 public IntPtr g2;
257 public int side1;
258 public int side2;
259 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(ContactGeom));
260 }
261
262 [StructLayout(LayoutKind.Sequential)]
263 public struct GeomClass
264 {
265 public int bytes;
266 public GetColliderFnFn collider;
267 public GetAABBFn aabb;
268 public AABBTestFn aabb_test;
269 public GeomDtorFn dtor;
270 }
271
272
273 [StructLayout(LayoutKind.Sequential)]
274 public struct JointFeedback
275 {
276 public Vector3 f1;
277 public Vector3 t1;
278 public Vector3 f2;
279 public Vector3 t2;
280 }
281
282
283 [StructLayout(LayoutKind.Sequential)]
284 public struct Mass
285 {
286 public dReal mass;
287 public Vector4 c;
288 public Matrix3 I;
289 }
290
291
292 [StructLayout(LayoutKind.Sequential)]
293 public struct Matrix3
294 {
295 public Matrix3(dReal m00, dReal m10, dReal m20, dReal m01, dReal m11, dReal m21, dReal m02, dReal m12, dReal m22)
296 {
297 M00 = m00; M10 = m10; M20 = m20; _m30 = 0.0f;
298 M01 = m01; M11 = m11; M21 = m21; _m31 = 0.0f;
299 M02 = m02; M12 = m12; M22 = m22; _m32 = 0.0f;
300 }
301 public dReal M00, M10, M20;
302 private dReal _m30;
303 public dReal M01, M11, M21;
304 private dReal _m31;
305 public dReal M02, M12, M22;
306 private dReal _m32;
307 }
308
309 [StructLayout(LayoutKind.Sequential)]
310 public struct Matrix4
311 {
312 public Matrix4(dReal m00, dReal m10, dReal m20, dReal m30,
313 dReal m01, dReal m11, dReal m21, dReal m31,
314 dReal m02, dReal m12, dReal m22, dReal m32,
315 dReal m03, dReal m13, dReal m23, dReal m33)
316 {
317 M00 = m00; M10 = m10; M20 = m20; M30 = m30;
318 M01 = m01; M11 = m11; M21 = m21; M31 = m31;
319 M02 = m02; M12 = m12; M22 = m22; M32 = m32;
320 M03 = m03; M13 = m13; M23 = m23; M33 = m33;
321 }
322 public dReal M00, M10, M20, M30;
323 public dReal M01, M11, M21, M31;
324 public dReal M02, M12, M22, M32;
325 public dReal M03, M13, M23, M33;
326 }
327
328 [StructLayout(LayoutKind.Sequential)]
329 public struct Quaternion
330 {
331 public dReal W, X, Y, Z;
332 }
333
334
335 [StructLayout(LayoutKind.Sequential)]
336 public struct SurfaceParameters
337 {
338 public ContactFlags mode;
339 public dReal mu;
340 public dReal mu2;
341 public dReal bounce;
342 public dReal bounce_vel;
343 public dReal soft_erp;
344 public dReal soft_cfm;
345 public dReal motion1;
346 public dReal motion2;
347 public dReal motionN;
348 public dReal slip1;
349 public dReal slip2;
350 }
351
352
353 [StructLayout(LayoutKind.Sequential)]
354 public struct Vector3
355 {
356 public Vector3(dReal x, dReal y, dReal z)
357 {
358 X = x; Y = y; Z = z; _w = 0.0f;
359 }
360 public dReal X, Y, Z;
361 private dReal _w;
362 }
363
364
365 [StructLayout(LayoutKind.Sequential)]
366 public struct Vector4
367 {
368 public Vector4(dReal x, dReal y, dReal z, dReal w)
369 {
370 X = x; Y = y; Z = z; W = w;
371 }
372 public dReal X, Y, Z, W;
373 }
374
375 #endregion
376
377 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAllocateODEDataForThread"), SuppressUnmanagedCodeSecurity]
378 public static extern int AllocateODEDataForThread(uint ODEInitFlags);
379
380 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnected"), SuppressUnmanagedCodeSecurity]
381 public static extern bool AreConnected(IntPtr b1, IntPtr b2);
382
383 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnectedExcluding"), SuppressUnmanagedCodeSecurity]
384 public static extern bool AreConnectedExcluding(IntPtr b1, IntPtr b2, JointType joint_type);
385
386 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForce"), SuppressUnmanagedCodeSecurity]
387 public static extern void BodyAddForce(IntPtr body, dReal fx, dReal fy, dReal fz);
388
389 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtPos"), SuppressUnmanagedCodeSecurity]
390 public static extern void BodyAddForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
391
392 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtRelPos"), SuppressUnmanagedCodeSecurity]
393 public static extern void BodyAddForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
394
395 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForce"), SuppressUnmanagedCodeSecurity]
396 public static extern void BodyAddRelForce(IntPtr body, dReal fx, dReal fy, dReal fz);
397
398 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtPos"), SuppressUnmanagedCodeSecurity]
399 public static extern void BodyAddRelForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
400
401 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtRelPos"), SuppressUnmanagedCodeSecurity]
402 public static extern void BodyAddRelForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
403
404 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelTorque"), SuppressUnmanagedCodeSecurity]
405 public static extern void BodyAddRelTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
406
407 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddTorque"), SuppressUnmanagedCodeSecurity]
408 public static extern void BodyAddTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
409
410 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
411 public static extern void BodyCopyPosition(IntPtr body, out Vector3 pos);
412
413 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
414 public static extern void BodyCopyPosition(IntPtr body, out dReal X);
415
416 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
417 public static extern void BodyCopyQuaternion(IntPtr body, out Quaternion quat);
418
419 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
420 public static extern void BodyCopyQuaternion(IntPtr body, out dReal X);
421
422 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
423 public static extern void BodyCopyRotation(IntPtr body, out Matrix3 R);
424
425 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
426 public static extern void BodyCopyRotation(IntPtr body, out dReal M00);
427
428 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCreate"), SuppressUnmanagedCodeSecurity]
429 public static extern IntPtr BodyiCreate(IntPtr world);
430 public static IntPtr BodyCreate(IntPtr world)
431 {
432 NTotalBodies++;
433 return BodyiCreate(world);
434 }
435
436 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDestroy"), SuppressUnmanagedCodeSecurity]
437 public static extern void BodyiDestroy(IntPtr body);
438 public static void BodyDestroy(IntPtr body)
439 {
440 NTotalBodies--;
441 BodyiDestroy(body);
442 }
443
444 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDisable"), SuppressUnmanagedCodeSecurity]
445 public static extern void BodyDisable(IntPtr body);
446
447 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyEnable"), SuppressUnmanagedCodeSecurity]
448 public static extern void BodyEnable(IntPtr body);
449
450 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
451 public static extern dReal BodyGetAutoDisableAngularThreshold(IntPtr body);
452
453 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
454 public static extern bool BodyGetAutoDisableFlag(IntPtr body);
455
456 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
457 public static extern void BodyGetAutoDisableDefaults(IntPtr body);
458
459 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
460 public static extern dReal BodyGetAutoDisableLinearThreshold(IntPtr body);
461
462 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
463 public static extern int BodyGetAutoDisableSteps(IntPtr body);
464
465 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
466 public static extern dReal BodyGetAutoDisableTime(IntPtr body);
467
468 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularVel"), SuppressUnmanagedCodeSecurity]
469 public extern unsafe static Vector3* BodyGetAngularVelUnsafe(IntPtr body);
470 public static Vector3 BodyGetAngularVel(IntPtr body)
471 {
472 unsafe { return *(BodyGetAngularVelUnsafe(body)); }
473 }
474
475 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetData"), SuppressUnmanagedCodeSecurity]
476 public static extern IntPtr BodyGetData(IntPtr body);
477
478 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
479 public static extern int BodyGetFiniteRotationMode(IntPtr body);
480
481 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
482 public static extern void BodyGetFiniteRotationAxis(IntPtr body, out Vector3 result);
483
484 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetForce"), SuppressUnmanagedCodeSecurity]
485 public extern unsafe static Vector3* BodyGetForceUnsafe(IntPtr body);
486 public static Vector3 BodyGetForce(IntPtr body)
487 {
488 unsafe { return *(BodyGetForceUnsafe(body)); }
489 }
490
491 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGravityMode"), SuppressUnmanagedCodeSecurity]
492 public static extern bool BodyGetGravityMode(IntPtr body);
493
494 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
495 public static extern int BodyGetGyroscopicMode(IntPtr body);
496
497 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetJoint"), SuppressUnmanagedCodeSecurity]
498 public static extern IntPtr BodyGetJoint(IntPtr body, int index);
499
500 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearVel"), SuppressUnmanagedCodeSecurity]
501 public extern unsafe static Vector3* BodyGetLinearVelUnsafe(IntPtr body);
502 public static Vector3 BodyGetLinearVel(IntPtr body)
503 {
504 unsafe { return *(BodyGetLinearVelUnsafe(body)); }
505 }
506
507 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetMass"), SuppressUnmanagedCodeSecurity]
508 public static extern void BodyGetMass(IntPtr body, out Mass mass);
509
510 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNumJoints"), SuppressUnmanagedCodeSecurity]
511 public static extern int BodyGetNumJoints(IntPtr body);
512
513 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPointVel"), SuppressUnmanagedCodeSecurity]
514 public static extern void BodyGetPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
515
516 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosition"), SuppressUnmanagedCodeSecurity]
517 public extern unsafe static Vector3* BodyGetPositionUnsafe(IntPtr body);
518 public static Vector3 BodyGetPosition(IntPtr body)
519 {
520 unsafe { return *(BodyGetPositionUnsafe(body)); }
521 }
522
523 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosRelPoint"), SuppressUnmanagedCodeSecurity]
524 public static extern void BodyGetPosRelPoint(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
525
526 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetQuaternion"), SuppressUnmanagedCodeSecurity]
527 public extern unsafe static Quaternion* BodyGetQuaternionUnsafe(IntPtr body);
528 public static Quaternion BodyGetQuaternion(IntPtr body)
529 {
530 unsafe { return *(BodyGetQuaternionUnsafe(body)); }
531 }
532
533 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointPos"), SuppressUnmanagedCodeSecurity]
534 public static extern void BodyGetRelPointPos(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
535
536 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointVel"), SuppressUnmanagedCodeSecurity]
537 public static extern void BodyGetRelPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
538
539 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRotation"), SuppressUnmanagedCodeSecurity]
540 public extern unsafe static Matrix3* BodyGetRotationUnsafe(IntPtr body);
541 public static Matrix3 BodyGetRotation(IntPtr body)
542 {
543 unsafe { return *(BodyGetRotationUnsafe(body)); }
544 }
545
546 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetTorque"), SuppressUnmanagedCodeSecurity]
547 public extern unsafe static Vector3* BodyGetTorqueUnsafe(IntPtr body);
548 public static Vector3 BodyGetTorque(IntPtr body)
549 {
550 unsafe { return *(BodyGetTorqueUnsafe(body)); }
551 }
552
553 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetWorld"), SuppressUnmanagedCodeSecurity]
554 public static extern IntPtr BodyGetWorld(IntPtr body);
555
556 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFirstGeom"), SuppressUnmanagedCodeSecurity]
557 public static extern IntPtr BodyGetFirstGeom(IntPtr body);
558
559 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNextGeom"), SuppressUnmanagedCodeSecurity]
560 public static extern IntPtr dBodyGetNextGeom(IntPtr Geom);
561
562
563 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyIsEnabled"), SuppressUnmanagedCodeSecurity]
564 public static extern bool BodyIsEnabled(IntPtr body);
565
566 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularVel"), SuppressUnmanagedCodeSecurity]
567 public static extern void BodySetAngularVel(IntPtr body, dReal x, dReal y, dReal z);
568
569 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
570 public static extern void BodySetAutoDisableAngularThreshold(IntPtr body, dReal angular_threshold);
571
572 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
573 public static extern void BodySetAutoDisableDefaults(IntPtr body);
574
575 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
576 public static extern void BodySetAutoDisableFlag(IntPtr body, bool do_auto_disable);
577
578 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
579 public static extern void BodySetAutoDisableLinearThreshold(IntPtr body, dReal linear_threshold);
580
581 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
582 public static extern void BodySetAutoDisableSteps(IntPtr body, int steps);
583
584 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
585 public static extern void BodySetAutoDisableTime(IntPtr body, dReal time);
586
587 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetData"), SuppressUnmanagedCodeSecurity]
588 public static extern void BodySetData(IntPtr body, IntPtr data);
589
590 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
591 public static extern void BodySetFiniteRotationMode(IntPtr body, int mode);
592
593 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
594 public static extern void BodySetFiniteRotationAxis(IntPtr body, dReal x, dReal y, dReal z);
595
596 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDamping"), SuppressUnmanagedCodeSecurity]
597 public static extern void BodySetLinearDamping(IntPtr body, dReal scale);
598
599 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
600 public static extern void BodySetAngularDamping(IntPtr body, dReal scale);
601
602 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDamping"), SuppressUnmanagedCodeSecurity]
603 public static extern dReal BodyGetLinearDamping(IntPtr body);
604
605 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDamping"), SuppressUnmanagedCodeSecurity]
606 public static extern dReal BodyGetAngularDamping(IntPtr body);
607
608 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
609 public static extern void BodySetDamping(IntPtr body, dReal linear_scale, dReal angular_scale);
610
611 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
612 public static extern void BodySetAngularDampingThreshold(IntPtr body, dReal threshold);
613
614 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
615 public static extern void BodySetLinearDampingThreshold(IntPtr body, dReal threshold);
616
617 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
618 public static extern dReal BodyGetLinearDampingThreshold(IntPtr body);
619
620 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
621 public static extern dReal BodyGetAngularDampingThreshold(IntPtr body);
622
623 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetForce"), SuppressUnmanagedCodeSecurity]
624 public static extern void BodySetForce(IntPtr body, dReal x, dReal y, dReal z);
625
626 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGravityMode"), SuppressUnmanagedCodeSecurity]
627 public static extern void BodySetGravityMode(IntPtr body, bool mode);
628
629 /// <summary>
630 /// Sets the Gyroscopic term status on the body specified.
631 /// </summary>
632 /// <param name="body">Pointer to body</param>
633 /// <param name="enabled">NonZero enabled, Zero disabled</param>
634 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
635 public static extern void dBodySetGyroscopicMode(IntPtr body, int enabled);
636
637 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearVel"), SuppressUnmanagedCodeSecurity]
638 public static extern void BodySetLinearVel(IntPtr body, dReal x, dReal y, dReal z);
639
640 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetMass"), SuppressUnmanagedCodeSecurity]
641 public static extern void BodySetMass(IntPtr body, ref Mass mass);
642
643 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetPosition"), SuppressUnmanagedCodeSecurity]
644 public static extern void BodySetPosition(IntPtr body, dReal x, dReal y, dReal z);
645
646 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
647 public static extern void BodySetQuaternion(IntPtr body, ref Quaternion q);
648
649 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
650 public static extern void BodySetQuaternion(IntPtr body, ref dReal w);
651
652 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
653 public static extern void BodySetRotation(IntPtr body, ref Matrix3 R);
654
655 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
656 public static extern void BodySetRotation(IntPtr body, ref dReal M00);
657
658 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetTorque"), SuppressUnmanagedCodeSecurity]
659 public static extern void BodySetTorque(IntPtr body, dReal x, dReal y, dReal z);
660
661 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorFromWorld"), SuppressUnmanagedCodeSecurity]
662 public static extern void BodyVectorFromWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
663
664 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorToWorld"), SuppressUnmanagedCodeSecurity]
665 public static extern void BodyVectorToWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
666
667 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxBox"), SuppressUnmanagedCodeSecurity]
668 public static extern void BoxBox(ref Vector3 p1, ref Matrix3 R1,
669 ref Vector3 side1, ref Vector3 p2,
670 ref Matrix3 R2, ref Vector3 side2,
671 ref Vector3 normal, out dReal depth, out int return_code,
672 int maxc, out ContactGeom contact, int skip);
673
674 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxTouchesBox"), SuppressUnmanagedCodeSecurity]
675 public static extern void BoxTouchesBox(ref Vector3 _p1, ref Matrix3 R1,
676 ref Vector3 side1, ref Vector3 _p2,
677 ref Matrix3 R2, ref Vector3 side2);
678
679 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCleanupODEAllDataForThread"), SuppressUnmanagedCodeSecurity]
680 public static extern void CleanupODEAllDataForThread();
681
682 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dClosestLineSegmentPoints"), SuppressUnmanagedCodeSecurity]
683 public static extern void ClosestLineSegmentPoints(ref Vector3 a1, ref Vector3 a2,
684 ref Vector3 b1, ref Vector3 b2,
685 ref Vector3 cp1, ref Vector3 cp2);
686
687 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCloseODE"), SuppressUnmanagedCodeSecurity]
688 public static extern void CloseODE();
689
690 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
691 public static extern int Collide(IntPtr o1, IntPtr o2, int flags, [In, Out] ContactGeom[] contact, int skip);
692 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
693 public static extern int CollidePtr(IntPtr o1, IntPtr o2, int flags, IntPtr contactgeomarray, int skip);
694
695 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dConnectingJoint"), SuppressUnmanagedCodeSecurity]
696 public static extern IntPtr ConnectingJoint(IntPtr j1, IntPtr j2);
697
698 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateBox"), SuppressUnmanagedCodeSecurity]
699 public static extern IntPtr CreateiBox(IntPtr space, dReal lx, dReal ly, dReal lz);
700 public static IntPtr CreateBox(IntPtr space, dReal lx, dReal ly, dReal lz)
701 {
702 NTotalGeoms++;
703 return CreateiBox(space, lx, ly, lz);
704 }
705
706 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCapsule"), SuppressUnmanagedCodeSecurity]
707 public static extern IntPtr CreateiCapsule(IntPtr space, dReal radius, dReal length);
708 public static IntPtr CreateCapsule(IntPtr space, dReal radius, dReal length)
709 {
710 NTotalGeoms++;
711 return CreateiCapsule(space, radius, length);
712 }
713
714 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateConvex"), SuppressUnmanagedCodeSecurity]
715 public static extern IntPtr CreateiConvex(IntPtr space, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
716 public static IntPtr CreateConvex(IntPtr space, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons)
717 {
718 NTotalGeoms++;
719 return CreateiConvex(space, planes, planeCount, points, pointCount, polygons);
720 }
721
722 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCylinder"), SuppressUnmanagedCodeSecurity]
723 public static extern IntPtr CreateiCylinder(IntPtr space, dReal radius, dReal length);
724 public static IntPtr CreateCylinder(IntPtr space, dReal radius, dReal length)
725 {
726 NTotalGeoms++;
727 return CreateiCylinder(space, radius, length);
728 }
729
730 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateHeightfield"), SuppressUnmanagedCodeSecurity]
731 public static extern IntPtr CreateiHeightfield(IntPtr space, IntPtr data, int bPlaceable);
732 public static IntPtr CreateHeightfield(IntPtr space, IntPtr data, int bPlaceable)
733 {
734 NTotalGeoms++;
735 return CreateiHeightfield(space, data, bPlaceable);
736 }
737
738 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateUbitTerrain"), SuppressUnmanagedCodeSecurity]
739 public static extern IntPtr CreateiUbitTerrain(IntPtr space, IntPtr data, int bPlaceable);
740 public static IntPtr CreateUbitTerrain(IntPtr space, IntPtr data, int bPlaceable)
741 {
742 NTotalGeoms++;
743 return CreateiUbitTerrain(space, data, bPlaceable);
744 }
745
746
747
748
749
750 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeom"), SuppressUnmanagedCodeSecurity]
751 public static extern IntPtr CreateiGeom(int classnum);
752 public static IntPtr CreateGeom(int classnum)
753 {
754 NTotalGeoms++;
755 return CreateiGeom(classnum);
756 }
757
758 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomClass"), SuppressUnmanagedCodeSecurity]
759 public static extern int CreateGeomClass(ref GeomClass classptr);
760
761 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomTransform"), SuppressUnmanagedCodeSecurity]
762 public static extern IntPtr CreateGeomTransform(IntPtr space);
763
764 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreatePlane"), SuppressUnmanagedCodeSecurity]
765 public static extern IntPtr CreateiPlane(IntPtr space, dReal a, dReal b, dReal c, dReal d);
766 public static IntPtr CreatePlane(IntPtr space, dReal a, dReal b, dReal c, dReal d)
767 {
768 NTotalGeoms++;
769 return CreateiPlane(space, a, b, c, d);
770 }
771
772 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateRay"), SuppressUnmanagedCodeSecurity]
773 public static extern IntPtr CreateiRay(IntPtr space, dReal length);
774 public static IntPtr CreateRay(IntPtr space, dReal length)
775 {
776 NTotalGeoms++;
777 return CreateiRay(space, length);
778 }
779
780 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateSphere"), SuppressUnmanagedCodeSecurity]
781 public static extern IntPtr CreateiSphere(IntPtr space, dReal radius);
782 public static IntPtr CreateSphere(IntPtr space, dReal radius)
783 {
784 NTotalGeoms++;
785 return CreateiSphere(space, radius);
786 }
787
788 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateTriMesh"), SuppressUnmanagedCodeSecurity]
789 public static extern IntPtr CreateiTriMesh(IntPtr space, IntPtr data,
790 TriCallback callback, TriArrayCallback arrayCallback, TriRayCallback rayCallback);
791 public static IntPtr CreateTriMesh(IntPtr space, IntPtr data,
792 TriCallback callback, TriArrayCallback arrayCallback, TriRayCallback rayCallback)
793 {
794 NTotalGeoms++;
795 return CreateiTriMesh(space, data, callback, arrayCallback, rayCallback);
796 }
797 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDot"), SuppressUnmanagedCodeSecurity]
798 public static extern dReal Dot(ref dReal X0, ref dReal X1, int n);
799
800 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDQfromW"), SuppressUnmanagedCodeSecurity]
801 public static extern void DQfromW(dReal[] dq, ref Vector3 w, ref Quaternion q);
802
803 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorCholesky"), SuppressUnmanagedCodeSecurity]
804 public static extern int FactorCholesky(ref dReal A00, int n);
805
806 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorLDLT"), SuppressUnmanagedCodeSecurity]
807 public static extern void FactorLDLT(ref dReal A, out dReal d, int n, int nskip);
808
809 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
810 public static extern void GeomBoxGetLengths(IntPtr geom, out Vector3 len);
811
812 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
813 public static extern void GeomBoxGetLengths(IntPtr geom, out dReal x);
814
815 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxPointDepth"), SuppressUnmanagedCodeSecurity]
816 public static extern dReal GeomBoxPointDepth(IntPtr geom, dReal x, dReal y, dReal z);
817
818 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxSetLengths"), SuppressUnmanagedCodeSecurity]
819 public static extern void GeomBoxSetLengths(IntPtr geom, dReal x, dReal y, dReal z);
820
821 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleGetParams"), SuppressUnmanagedCodeSecurity]
822 public static extern void GeomCapsuleGetParams(IntPtr geom, out dReal radius, out dReal length);
823
824 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsulePointDepth"), SuppressUnmanagedCodeSecurity]
825 public static extern dReal GeomCapsulePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
826
827 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleSetParams"), SuppressUnmanagedCodeSecurity]
828 public static extern void GeomCapsuleSetParams(IntPtr geom, dReal radius, dReal length);
829
830 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomClearOffset"), SuppressUnmanagedCodeSecurity]
831 public static extern void GeomClearOffset(IntPtr geom);
832
833 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
834 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref Vector3 pos);
835
836 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
837 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref dReal X);
838
839 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
840 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref Quaternion Q);
841
842 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
843 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref dReal X);
844
845 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
846 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref Matrix3 R);
847
848 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
849 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref dReal M00);
850
851 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
852 public static extern void GeomCopyPosition(IntPtr geom, out Vector3 pos);
853
854 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
855 public static extern void GeomCopyPosition(IntPtr geom, out dReal X);
856
857 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
858 public static extern void GeomCopyRotation(IntPtr geom, out Matrix3 R);
859
860 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
861 public static extern void GeomCopyRotation(IntPtr geom, out dReal M00);
862
863 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderGetParams"), SuppressUnmanagedCodeSecurity]
864 public static extern void GeomCylinderGetParams(IntPtr geom, out dReal radius, out dReal length);
865
866 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderSetParams"), SuppressUnmanagedCodeSecurity]
867 public static extern void GeomCylinderSetParams(IntPtr geom, dReal radius, dReal length);
868
869 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDestroy"), SuppressUnmanagedCodeSecurity]
870 public static extern void GeomiDestroy(IntPtr geom);
871 public static void GeomDestroy(IntPtr geom)
872 {
873 NTotalGeoms--;
874 GeomiDestroy(geom);
875 }
876
877
878 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDisable"), SuppressUnmanagedCodeSecurity]
879 public static extern void GeomDisable(IntPtr geom);
880
881 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomEnable"), SuppressUnmanagedCodeSecurity]
882 public static extern void GeomEnable(IntPtr geom);
883
884 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
885 public static extern void GeomGetAABB(IntPtr geom, out AABB aabb);
886
887 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
888 public static extern void GeomGetAABB(IntPtr geom, out dReal minX);
889
890 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetBody"), SuppressUnmanagedCodeSecurity]
891 public static extern IntPtr GeomGetBody(IntPtr geom);
892
893 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCategoryBits"), SuppressUnmanagedCodeSecurity]
894 public static extern uint GeomGetCategoryBits(IntPtr geom);
895
896 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClassData"), SuppressUnmanagedCodeSecurity]
897 public static extern IntPtr GeomGetClassData(IntPtr geom);
898
899 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCollideBits"), SuppressUnmanagedCodeSecurity]
900 public static extern uint GeomGetCollideBits(IntPtr geom);
901
902 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClass"), SuppressUnmanagedCodeSecurity]
903 public static extern GeomClassID GeomGetClass(IntPtr geom);
904
905 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetData"), SuppressUnmanagedCodeSecurity]
906 public static extern IntPtr GeomGetData(IntPtr geom);
907
908 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetPosition"), SuppressUnmanagedCodeSecurity]
909 public extern unsafe static Vector3* GeomGetOffsetPositionUnsafe(IntPtr geom);
910 public static Vector3 GeomGetOffsetPosition(IntPtr geom)
911 {
912 unsafe { return *(GeomGetOffsetPositionUnsafe(geom)); }
913 }
914
915 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetRotation"), SuppressUnmanagedCodeSecurity]
916 public extern unsafe static Matrix3* GeomGetOffsetRotationUnsafe(IntPtr geom);
917 public static Matrix3 GeomGetOffsetRotation(IntPtr geom)
918 {
919 unsafe { return *(GeomGetOffsetRotationUnsafe(geom)); }
920 }
921
922 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetPosition"), SuppressUnmanagedCodeSecurity]
923 public extern unsafe static Vector3* GeomGetPositionUnsafe(IntPtr geom);
924 public static Vector3 GeomGetPosition(IntPtr geom)
925 {
926 unsafe { return *(GeomGetPositionUnsafe(geom)); }
927 }
928 public static OMV.Vector3 GeomGetPositionOMV(IntPtr geom)
929 {
930 Vector3 vtmp = GeomGetPosition(geom);
931 return new OMV.Vector3(vtmp.X, vtmp.Y, vtmp.Z);
932 }
933
934 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
935 public static extern void GeomCopyQuaternion(IntPtr geom, out Quaternion q);
936 public static OMV.Quaternion GeomGetQuaternionOMV(IntPtr geom)
937 {
938 Quaternion qtmp;
939 GeomCopyQuaternion(geom, out qtmp);
940 return new OMV.Quaternion(qtmp.X, qtmp.Y, qtmp.Z, qtmp.W);
941 }
942
943 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
944 public static extern void GeomCopyQuaternion(IntPtr geom, out dReal X);
945
946 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetRotation"), SuppressUnmanagedCodeSecurity]
947 public extern unsafe static Matrix3* GeomGetRotationUnsafe(IntPtr geom);
948 public static Matrix3 GeomGetRotation(IntPtr geom)
949 {
950 unsafe { return *(GeomGetRotationUnsafe(geom)); }
951 }
952
953 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetSpace"), SuppressUnmanagedCodeSecurity]
954 public static extern IntPtr GeomGetSpace(IntPtr geom);
955
956 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
957 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, byte[] pHeightData, int bCopyHeightData,
958 dReal width, dReal depth, int widthSamples, int depthSamples,
959 dReal scale, dReal offset, dReal thickness, int bWrap);
960
961 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
962 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
963 dReal width, dReal depth, int widthSamples, int depthSamples,
964 dReal scale, dReal offset, dReal thickness, int bWrap);
965
966 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildCallback"), SuppressUnmanagedCodeSecurity]
967 public static extern void GeomHeightfieldDataBuildCallback(IntPtr d, IntPtr pUserData, HeightfieldGetHeight pCallback,
968 dReal width, dReal depth, int widthSamples, int depthSamples,
969 dReal scale, dReal offset, dReal thickness, int bWrap);
970
971 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
972 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, ushort[] pHeightData, int bCopyHeightData,
973 dReal width, dReal depth, int widthSamples, int depthSamples,
974 dReal scale, dReal offset, dReal thickness, int bWrap);
975
976 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
977 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, short[] pHeightData, int bCopyHeightData,
978 dReal width, dReal depth, int widthSamples, int depthSamples,
979 dReal scale, dReal offset, dReal thickness, int bWrap);
980
981 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
982 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
983 dReal width, dReal depth, int widthSamples, int depthSamples,
984 dReal scale, dReal offset, dReal thickness, int bWrap);
985
986 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
987 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, float[] pHeightData, int bCopyHeightData,
988 dReal width, dReal depth, int widthSamples, int depthSamples,
989 dReal scale, dReal offset, dReal thickness, int bWrap);
990
991 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
992 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
993 dReal width, dReal depth, int widthSamples, int depthSamples,
994 dReal scale, dReal offset, dReal thickness, int bWrap);
995
996
997
998 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
999 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, double[] pHeightData, int bCopyHeightData,
1000 dReal width, dReal depth, int widthSamples, int depthSamples,
1001 dReal scale, dReal offset, dReal thickness, int bWrap);
1002
1003 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1004 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
1005 dReal width, dReal depth, int widthSamples, int depthSamples,
1006 dReal scale, dReal offset, dReal thickness, int bWrap);
1007
1008 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataCreate"), SuppressUnmanagedCodeSecurity]
1009 public static extern IntPtr GeomHeightfieldDataCreate();
1010
1011 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataDestroy"), SuppressUnmanagedCodeSecurity]
1012 public static extern void GeomHeightfieldDataDestroy(IntPtr d);
1013
1014 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataSetBounds"), SuppressUnmanagedCodeSecurity]
1015 public static extern void GeomHeightfieldDataSetBounds(IntPtr d, dReal minHeight, dReal maxHeight);
1016
1017 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldGetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1018 public static extern IntPtr GeomHeightfieldGetHeightfieldData(IntPtr g);
1019
1020 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1021 public static extern void GeomHeightfieldSetHeightfieldData(IntPtr g, IntPtr d);
1022
1023
1024 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataBuild"), SuppressUnmanagedCodeSecurity]
1025 public static extern void GeomUbitTerrainDataBuild(IntPtr d, float[] pHeightData, int bCopyHeightData,
1026 dReal sampleSize, int widthSamples, int depthSamples,
1027 dReal offset, dReal thickness, int bWrap);
1028
1029 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataBuild"), SuppressUnmanagedCodeSecurity]
1030 public static extern void GeomUbitTerrainDataBuild(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
1031 dReal sampleSize, int widthSamples, int depthSamples,
1032 dReal thickness, int bWrap);
1033
1034 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataCreate"), SuppressUnmanagedCodeSecurity]
1035 public static extern IntPtr GeomUbitTerrainDataCreate();
1036
1037 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataDestroy"), SuppressUnmanagedCodeSecurity]
1038 public static extern void GeomUbitTerrainDataDestroy(IntPtr d);
1039
1040 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataSetBounds"), SuppressUnmanagedCodeSecurity]
1041 public static extern void GeomUbitTerrainDataSetBounds(IntPtr d, dReal minHeight, dReal maxHeight);
1042
1043 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainGetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1044 public static extern IntPtr GeomUbitTerrainGetHeightfieldData(IntPtr g);
1045
1046 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1047 public static extern void GeomUbitTerrainSetHeightfieldData(IntPtr g, IntPtr d);
1048
1049
1050 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsEnabled"), SuppressUnmanagedCodeSecurity]
1051 public static extern bool GeomIsEnabled(IntPtr geom);
1052
1053 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsOffset"), SuppressUnmanagedCodeSecurity]
1054 public static extern bool GeomIsOffset(IntPtr geom);
1055
1056 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsSpace"), SuppressUnmanagedCodeSecurity]
1057 public static extern bool GeomIsSpace(IntPtr geom);
1058
1059 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
1060 public static extern void GeomPlaneGetParams(IntPtr geom, ref Vector4 result);
1061
1062 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
1063 public static extern void GeomPlaneGetParams(IntPtr geom, ref dReal A);
1064
1065 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlanePointDepth"), SuppressUnmanagedCodeSecurity]
1066 public static extern dReal GeomPlanePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
1067
1068 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneSetParams"), SuppressUnmanagedCodeSecurity]
1069 public static extern void GeomPlaneSetParams(IntPtr plane, dReal a, dReal b, dReal c, dReal d);
1070
1071 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
1072 public static extern void GeomRayGet(IntPtr ray, ref Vector3 start, ref Vector3 dir);
1073
1074 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
1075 public static extern void GeomRayGet(IntPtr ray, ref dReal startX, ref dReal dirX);
1076
1077 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetClosestHit"), SuppressUnmanagedCodeSecurity]
1078 public static extern int GeomRayGetClosestHit(IntPtr ray);
1079
1080 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetLength"), SuppressUnmanagedCodeSecurity]
1081 public static extern dReal GeomRayGetLength(IntPtr ray);
1082
1083 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetParams"), SuppressUnmanagedCodeSecurity]
1084 public static extern dReal GeomRayGetParams(IntPtr g, out int firstContact, out int backfaceCull);
1085
1086 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySet"), SuppressUnmanagedCodeSecurity]
1087 public static extern void GeomRaySet(IntPtr ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
1088
1089 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetClosestHit"), SuppressUnmanagedCodeSecurity]
1090 public static extern void GeomRaySetClosestHit(IntPtr ray, int closestHit);
1091
1092 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetLength"), SuppressUnmanagedCodeSecurity]
1093 public static extern void GeomRaySetLength(IntPtr ray, dReal length);
1094
1095 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetParams"), SuppressUnmanagedCodeSecurity]
1096 public static extern void GeomRaySetParams(IntPtr ray, int firstContact, int backfaceCull);
1097
1098 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetBody"), SuppressUnmanagedCodeSecurity]
1099 public static extern void GeomSetBody(IntPtr geom, IntPtr body);
1100
1101 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCategoryBits"), SuppressUnmanagedCodeSecurity]
1102 public static extern void GeomSetCategoryBits(IntPtr geom, uint bits);
1103
1104 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCollideBits"), SuppressUnmanagedCodeSecurity]
1105 public static extern void GeomSetCollideBits(IntPtr geom, uint bits);
1106
1107 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetConvex"), SuppressUnmanagedCodeSecurity]
1108 public static extern IntPtr GeomSetConvex(IntPtr geom, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
1109
1110 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetData"), SuppressUnmanagedCodeSecurity]
1111 public static extern void GeomSetData(IntPtr geom, IntPtr data);
1112
1113 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetPosition"), SuppressUnmanagedCodeSecurity]
1114 public static extern void GeomSetOffsetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1115
1116 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1117 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref Quaternion Q);
1118
1119 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1120 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref dReal X);
1121
1122 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1123 public static extern void GeomSetOffsetRotation(IntPtr geom, ref Matrix3 R);
1124
1125 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1126 public static extern void GeomSetOffsetRotation(IntPtr geom, ref dReal M00);
1127
1128 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldPosition"), SuppressUnmanagedCodeSecurity]
1129 public static extern void GeomSetOffsetWorldPosition(IntPtr geom, dReal x, dReal y, dReal z);
1130
1131 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1132 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref Quaternion Q);
1133
1134 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1135 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref dReal X);
1136
1137 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1138 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref Matrix3 R);
1139
1140 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1141 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref dReal M00);
1142
1143 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetPosition"), SuppressUnmanagedCodeSecurity]
1144 public static extern void GeomSetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1145
1146 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1147 public static extern void GeomSetQuaternion(IntPtr geom, ref Quaternion quat);
1148
1149 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1150 public static extern void GeomSetQuaternion(IntPtr geom, ref dReal w);
1151
1152 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1153 public static extern void GeomSetRotation(IntPtr geom, ref Matrix3 R);
1154
1155 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1156 public static extern void GeomSetRotation(IntPtr geom, ref dReal M00);
1157
1158 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereGetRadius"), SuppressUnmanagedCodeSecurity]
1159 public static extern dReal GeomSphereGetRadius(IntPtr geom);
1160
1161 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSpherePointDepth"), SuppressUnmanagedCodeSecurity]
1162 public static extern dReal GeomSpherePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
1163
1164 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereSetRadius"), SuppressUnmanagedCodeSecurity]
1165 public static extern void GeomSphereSetRadius(IntPtr geom, dReal radius);
1166
1167 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetCleanup"), SuppressUnmanagedCodeSecurity]
1168 public static extern int GeomTransformGetCleanup(IntPtr geom);
1169
1170 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetGeom"), SuppressUnmanagedCodeSecurity]
1171 public static extern IntPtr GeomTransformGetGeom(IntPtr geom);
1172
1173 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetInfo"), SuppressUnmanagedCodeSecurity]
1174 public static extern int GeomTransformGetInfo(IntPtr geom);
1175
1176 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetCleanup"), SuppressUnmanagedCodeSecurity]
1177 public static extern void GeomTransformSetCleanup(IntPtr geom, int mode);
1178
1179 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetGeom"), SuppressUnmanagedCodeSecurity]
1180 public static extern void GeomTransformSetGeom(IntPtr geom, IntPtr obj);
1181
1182 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetInfo"), SuppressUnmanagedCodeSecurity]
1183 public static extern void GeomTransformSetInfo(IntPtr geom, int info);
1184
1185 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1186 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1187 double[] vertices, int vertexStride, int vertexCount,
1188 int[] indices, int indexCount, int triStride);
1189
1190 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1191 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1192 IntPtr vertices, int vertexStride, int vertexCount,
1193 IntPtr indices, int indexCount, int triStride);
1194
1195 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1196 public static extern void GeomTriMeshDataBuildDouble1(IntPtr d,
1197 double[] vertices, int vertexStride, int vertexCount,
1198 int[] indices, int indexCount, int triStride,
1199 double[] normals);
1200
1201 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1202 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1203 IntPtr vertices, int vertexStride, int vertexCount,
1204 IntPtr indices, int indexCount, int triStride,
1205 IntPtr normals);
1206
1207 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1208 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1209 dReal[] vertices, int vertexStride, int vertexCount,
1210 int[] indices, int indexCount, int triStride);
1211
1212 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1213 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1214 IntPtr vertices, int vertexStride, int vertexCount,
1215 IntPtr indices, int indexCount, int triStride);
1216
1217 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1218 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1219 dReal[] vertices, int vertexStride, int vertexCount,
1220 int[] indices, int indexCount, int triStride,
1221 dReal[] normals);
1222
1223 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1224 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1225 IntPtr vertices, int vertexStride, int vertexCount,
1226 IntPtr indices, int indexCount, int triStride,
1227 IntPtr normals);
1228
1229 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1230 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1231 float[] vertices, int vertexStride, int vertexCount,
1232 int[] indices, int indexCount, int triStride);
1233
1234 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1235 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1236 IntPtr vertices, int vertexStride, int vertexCount,
1237 IntPtr indices, int indexCount, int triStride);
1238
1239 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1240 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1241 float[] vertices, int vertexStride, int vertexCount,
1242 int[] indices, int indexCount, int triStride,
1243 float[] normals);
1244
1245 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1246 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1247 IntPtr vertices, int vertexStride, int vertexCount,
1248 IntPtr indices, int indexCount, int triStride,
1249 IntPtr normals);
1250
1251 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshClearTCCache"), SuppressUnmanagedCodeSecurity]
1252 public static extern void GeomTriMeshClearTCCache(IntPtr g);
1253
1254 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataCreate"), SuppressUnmanagedCodeSecurity]
1255 public static extern IntPtr GeomTriMeshDataCreate();
1256
1257 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataDestroy"), SuppressUnmanagedCodeSecurity]
1258 public static extern void GeomTriMeshDataDestroy(IntPtr d);
1259
1260 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataGet"), SuppressUnmanagedCodeSecurity]
1261 public static extern IntPtr GeomTriMeshDataGet(IntPtr d, int data_id);
1262
1263 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataPreprocess"), SuppressUnmanagedCodeSecurity]
1264 public static extern void GeomTriMeshDataPreprocess(IntPtr d);
1265
1266 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataSet"), SuppressUnmanagedCodeSecurity]
1267 public static extern void GeomTriMeshDataSet(IntPtr d, int data_id, IntPtr in_data);
1268
1269 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataUpdate"), SuppressUnmanagedCodeSecurity]
1270 public static extern void GeomTriMeshDataUpdate(IntPtr d);
1271
1272 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshEnableTC"), SuppressUnmanagedCodeSecurity]
1273 public static extern void GeomTriMeshEnableTC(IntPtr g, int geomClass, bool enable);
1274
1275 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetArrayCallback"), SuppressUnmanagedCodeSecurity]
1276 public static extern TriArrayCallback GeomTriMeshGetArrayCallback(IntPtr g);
1277
1278 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetCallback"), SuppressUnmanagedCodeSecurity]
1279 public static extern TriCallback GeomTriMeshGetCallback(IntPtr g);
1280
1281 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetData"), SuppressUnmanagedCodeSecurity]
1282 public static extern IntPtr GeomTriMeshGetData(IntPtr g);
1283
1284 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetLastTransform"), SuppressUnmanagedCodeSecurity]
1285 public extern unsafe static Matrix4* GeomTriMeshGetLastTransformUnsafe(IntPtr geom);
1286 public static Matrix4 GeomTriMeshGetLastTransform(IntPtr geom)
1287 {
1288 unsafe { return *(GeomTriMeshGetLastTransformUnsafe(geom)); }
1289 }
1290
1291 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetPoint"), SuppressUnmanagedCodeSecurity]
1292 public extern static void GeomTriMeshGetPoint(IntPtr g, int index, dReal u, dReal v, ref Vector3 outVec);
1293
1294 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetRayCallback"), SuppressUnmanagedCodeSecurity]
1295 public static extern TriRayCallback GeomTriMeshGetRayCallback(IntPtr g);
1296
1297 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangle"), SuppressUnmanagedCodeSecurity]
1298 public extern static void GeomTriMeshGetTriangle(IntPtr g, int index, ref Vector3 v0, ref Vector3 v1, ref Vector3 v2);
1299
1300 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangleCount"), SuppressUnmanagedCodeSecurity]
1301 public extern static int GeomTriMeshGetTriangleCount(IntPtr g);
1302
1303 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriMeshDataID"), SuppressUnmanagedCodeSecurity]
1304 public static extern IntPtr GeomTriMeshGetTriMeshDataID(IntPtr g);
1305
1306 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshIsTCEnabled"), SuppressUnmanagedCodeSecurity]
1307 public static extern bool GeomTriMeshIsTCEnabled(IntPtr g, int geomClass);
1308
1309 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetArrayCallback"), SuppressUnmanagedCodeSecurity]
1310 public static extern void GeomTriMeshSetArrayCallback(IntPtr g, TriArrayCallback arrayCallback);
1311
1312 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetCallback"), SuppressUnmanagedCodeSecurity]
1313 public static extern void GeomTriMeshSetCallback(IntPtr g, TriCallback callback);
1314
1315 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetData"), SuppressUnmanagedCodeSecurity]
1316 public static extern void GeomTriMeshSetData(IntPtr g, IntPtr data);
1317
1318 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1319 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref Matrix4 last_trans);
1320
1321 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1322 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref dReal M00);
1323
1324 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetRayCallback"), SuppressUnmanagedCodeSecurity]
1325 public static extern void GeomTriMeshSetRayCallback(IntPtr g, TriRayCallback callback);
1326
1327 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGetConfiguration"), SuppressUnmanagedCodeSecurity]
1328 public static extern IntPtr iGetConfiguration();
1329
1330 public static string GetConfiguration()
1331 {
1332 IntPtr ptr = iGetConfiguration();
1333 string s = Marshal.PtrToStringAnsi(ptr);
1334 return s;
1335 }
1336
1337 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceCreate"), SuppressUnmanagedCodeSecurity]
1338 public static extern IntPtr HashSpaceCreate(IntPtr space);
1339
1340 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceGetLevels"), SuppressUnmanagedCodeSecurity]
1341 public static extern void HashSpaceGetLevels(IntPtr space, out int minlevel, out int maxlevel);
1342
1343 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceSetLevels"), SuppressUnmanagedCodeSecurity]
1344 public static extern void HashSpaceSetLevels(IntPtr space, int minlevel, int maxlevel);
1345
1346 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInfiniteAABB"), SuppressUnmanagedCodeSecurity]
1347 public static extern void InfiniteAABB(IntPtr geom, out AABB aabb);
1348
1349 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE"), SuppressUnmanagedCodeSecurity]
1350 public static extern void InitODE();
1351
1352 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE2"), SuppressUnmanagedCodeSecurity]
1353 public static extern int InitODE2(uint ODEInitFlags);
1354
1355 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dIsPositiveDefinite"), SuppressUnmanagedCodeSecurity]
1356 public static extern int IsPositiveDefinite(ref dReal A, int n);
1357
1358 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInvertPDMatrix"), SuppressUnmanagedCodeSecurity]
1359 public static extern int InvertPDMatrix(ref dReal A, out dReal Ainv, int n);
1360
1361 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddAMotorTorques"), SuppressUnmanagedCodeSecurity]
1362 public static extern void JointAddAMotorTorques(IntPtr joint, dReal torque1, dReal torque2, dReal torque3);
1363
1364 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHingeTorque"), SuppressUnmanagedCodeSecurity]
1365 public static extern void JointAddHingeTorque(IntPtr joint, dReal torque);
1366
1367 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHinge2Torque"), SuppressUnmanagedCodeSecurity]
1368 public static extern void JointAddHinge2Torques(IntPtr joint, dReal torque1, dReal torque2);
1369
1370 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddPRTorque"), SuppressUnmanagedCodeSecurity]
1371 public static extern void JointAddPRTorque(IntPtr joint, dReal torque);
1372
1373 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddUniversalTorque"), SuppressUnmanagedCodeSecurity]
1374 public static extern void JointAddUniversalTorques(IntPtr joint, dReal torque1, dReal torque2);
1375
1376 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddSliderForce"), SuppressUnmanagedCodeSecurity]
1377 public static extern void JointAddSliderForce(IntPtr joint, dReal force);
1378
1379 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAttach"), SuppressUnmanagedCodeSecurity]
1380 public static extern void JointAttach(IntPtr joint, IntPtr body1, IntPtr body2);
1381
1382 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateAMotor"), SuppressUnmanagedCodeSecurity]
1383 public static extern IntPtr JointCreateAMotor(IntPtr world, IntPtr group);
1384
1385 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateBall"), SuppressUnmanagedCodeSecurity]
1386 public static extern IntPtr JointCreateBall(IntPtr world, IntPtr group);
1387
1388 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1389 public static extern IntPtr JointCreateContact(IntPtr world, IntPtr group, ref Contact contact);
1390 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1391 public static extern IntPtr JointCreateContactPtr(IntPtr world, IntPtr group, IntPtr contact);
1392
1393 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateFixed"), SuppressUnmanagedCodeSecurity]
1394 public static extern IntPtr JointCreateFixed(IntPtr world, IntPtr group);
1395
1396 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge"), SuppressUnmanagedCodeSecurity]
1397 public static extern IntPtr JointCreateHinge(IntPtr world, IntPtr group);
1398
1399 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge2"), SuppressUnmanagedCodeSecurity]
1400 public static extern IntPtr JointCreateHinge2(IntPtr world, IntPtr group);
1401
1402 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateLMotor"), SuppressUnmanagedCodeSecurity]
1403 public static extern IntPtr JointCreateLMotor(IntPtr world, IntPtr group);
1404
1405 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateNull"), SuppressUnmanagedCodeSecurity]
1406 public static extern IntPtr JointCreateNull(IntPtr world, IntPtr group);
1407
1408 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePR"), SuppressUnmanagedCodeSecurity]
1409 public static extern IntPtr JointCreatePR(IntPtr world, IntPtr group);
1410
1411 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePlane2D"), SuppressUnmanagedCodeSecurity]
1412 public static extern IntPtr JointCreatePlane2D(IntPtr world, IntPtr group);
1413
1414 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateSlider"), SuppressUnmanagedCodeSecurity]
1415 public static extern IntPtr JointCreateSlider(IntPtr world, IntPtr group);
1416
1417 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateUniversal"), SuppressUnmanagedCodeSecurity]
1418 public static extern IntPtr JointCreateUniversal(IntPtr world, IntPtr group);
1419
1420 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointDestroy"), SuppressUnmanagedCodeSecurity]
1421 public static extern void JointDestroy(IntPtr j);
1422
1423 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1424 public static extern dReal JointGetAMotorAngle(IntPtr j, int anum);
1425
1426 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngleRate"), SuppressUnmanagedCodeSecurity]
1427 public static extern dReal JointGetAMotorAngleRate(IntPtr j, int anum);
1428
1429 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1430 public static extern void JointGetAMotorAxis(IntPtr j, int anum, out Vector3 result);
1431
1432 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxisRel"), SuppressUnmanagedCodeSecurity]
1433 public static extern int JointGetAMotorAxisRel(IntPtr j, int anum);
1434
1435 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorMode"), SuppressUnmanagedCodeSecurity]
1436 public static extern int JointGetAMotorMode(IntPtr j);
1437
1438 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1439 public static extern int JointGetAMotorNumAxes(IntPtr j);
1440
1441 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorParam"), SuppressUnmanagedCodeSecurity]
1442 public static extern dReal JointGetAMotorParam(IntPtr j, int parameter);
1443
1444 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor"), SuppressUnmanagedCodeSecurity]
1445 public static extern void JointGetBallAnchor(IntPtr j, out Vector3 result);
1446
1447 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1448 public static extern void JointGetBallAnchor2(IntPtr j, out Vector3 result);
1449
1450 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBody"), SuppressUnmanagedCodeSecurity]
1451 public static extern IntPtr JointGetBody(IntPtr j);
1452
1453 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetData"), SuppressUnmanagedCodeSecurity]
1454 public static extern IntPtr JointGetData(IntPtr j);
1455
1456 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetFeedback"), SuppressUnmanagedCodeSecurity]
1457 public extern unsafe static JointFeedback* JointGetFeedbackUnsafe(IntPtr j);
1458 public static JointFeedback JointGetFeedback(IntPtr j)
1459 {
1460 unsafe { return *(JointGetFeedbackUnsafe(j)); }
1461 }
1462
1463 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1464 public static extern void JointGetHingeAnchor(IntPtr j, out Vector3 result);
1465
1466 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngle"), SuppressUnmanagedCodeSecurity]
1467 public static extern dReal JointGetHingeAngle(IntPtr j);
1468
1469 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngleRate"), SuppressUnmanagedCodeSecurity]
1470 public static extern dReal JointGetHingeAngleRate(IntPtr j);
1471
1472 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAxis"), SuppressUnmanagedCodeSecurity]
1473 public static extern void JointGetHingeAxis(IntPtr j, out Vector3 result);
1474
1475 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeParam"), SuppressUnmanagedCodeSecurity]
1476 public static extern dReal JointGetHingeParam(IntPtr j, int parameter);
1477
1478 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1"), SuppressUnmanagedCodeSecurity]
1479 public static extern dReal JointGetHinge2Angle1(IntPtr j);
1480
1481 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1Rate"), SuppressUnmanagedCodeSecurity]
1482 public static extern dReal JointGetHinge2Angle1Rate(IntPtr j);
1483
1484 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle2Rate"), SuppressUnmanagedCodeSecurity]
1485 public static extern dReal JointGetHinge2Angle2Rate(IntPtr j);
1486
1487 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor2"), SuppressUnmanagedCodeSecurity]
1488 public static extern void JointGetHingeAnchor2(IntPtr j, out Vector3 result);
1489
1490 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1491 public static extern void JointGetHinge2Anchor(IntPtr j, out Vector3 result);
1492
1493 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor2"), SuppressUnmanagedCodeSecurity]
1494 public static extern void JointGetHinge2Anchor2(IntPtr j, out Vector3 result);
1495
1496 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1497 public static extern void JointGetHinge2Axis1(IntPtr j, out Vector3 result);
1498
1499 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1500 public static extern void JointGetHinge2Axis2(IntPtr j, out Vector3 result);
1501
1502 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Param"), SuppressUnmanagedCodeSecurity]
1503 public static extern dReal JointGetHinge2Param(IntPtr j, int parameter);
1504
1505 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1506 public static extern void JointGetLMotorAxis(IntPtr j, int anum, out Vector3 result);
1507
1508 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1509 public static extern int JointGetLMotorNumAxes(IntPtr j);
1510
1511 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorParam"), SuppressUnmanagedCodeSecurity]
1512 public static extern dReal JointGetLMotorParam(IntPtr j, int parameter);
1513
1514 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAnchor"), SuppressUnmanagedCodeSecurity]
1515 public static extern void JointGetPRAnchor(IntPtr j, out Vector3 result);
1516
1517 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis1"), SuppressUnmanagedCodeSecurity]
1518 public static extern void JointGetPRAxis1(IntPtr j, out Vector3 result);
1519
1520 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis2"), SuppressUnmanagedCodeSecurity]
1521 public static extern void JointGetPRAxis2(IntPtr j, out Vector3 result);
1522
1523 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRParam"), SuppressUnmanagedCodeSecurity]
1524 public static extern dReal JointGetPRParam(IntPtr j, int parameter);
1525
1526 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPosition"), SuppressUnmanagedCodeSecurity]
1527 public static extern dReal JointGetPRPosition(IntPtr j);
1528
1529 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPositionRate"), SuppressUnmanagedCodeSecurity]
1530 public static extern dReal JointGetPRPositionRate(IntPtr j);
1531
1532 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderAxis"), SuppressUnmanagedCodeSecurity]
1533 public static extern void JointGetSliderAxis(IntPtr j, out Vector3 result);
1534
1535 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderParam"), SuppressUnmanagedCodeSecurity]
1536 public static extern dReal JointGetSliderParam(IntPtr j, int parameter);
1537
1538 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPosition"), SuppressUnmanagedCodeSecurity]
1539 public static extern dReal JointGetSliderPosition(IntPtr j);
1540
1541 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPositionRate"), SuppressUnmanagedCodeSecurity]
1542 public static extern dReal JointGetSliderPositionRate(IntPtr j);
1543
1544 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetType"), SuppressUnmanagedCodeSecurity]
1545 public static extern JointType JointGetType(IntPtr j);
1546
1547 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1548 public static extern void JointGetUniversalAnchor(IntPtr j, out Vector3 result);
1549
1550 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor2"), SuppressUnmanagedCodeSecurity]
1551 public static extern void JointGetUniversalAnchor2(IntPtr j, out Vector3 result);
1552
1553 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1"), SuppressUnmanagedCodeSecurity]
1554 public static extern dReal JointGetUniversalAngle1(IntPtr j);
1555
1556 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1Rate"), SuppressUnmanagedCodeSecurity]
1557 public static extern dReal JointGetUniversalAngle1Rate(IntPtr j);
1558
1559 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2"), SuppressUnmanagedCodeSecurity]
1560 public static extern dReal JointGetUniversalAngle2(IntPtr j);
1561
1562 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2Rate"), SuppressUnmanagedCodeSecurity]
1563 public static extern dReal JointGetUniversalAngle2Rate(IntPtr j);
1564
1565 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngles"), SuppressUnmanagedCodeSecurity]
1566 public static extern void JointGetUniversalAngles(IntPtr j, out dReal angle1, out dReal angle2);
1567
1568 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1569 public static extern void JointGetUniversalAxis1(IntPtr j, out Vector3 result);
1570
1571 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1572 public static extern void JointGetUniversalAxis2(IntPtr j, out Vector3 result);
1573
1574 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalParam"), SuppressUnmanagedCodeSecurity]
1575 public static extern dReal JointGetUniversalParam(IntPtr j, int parameter);
1576
1577 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupCreate"), SuppressUnmanagedCodeSecurity]
1578 public static extern IntPtr JointGroupCreate(int max_size);
1579
1580 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupDestroy"), SuppressUnmanagedCodeSecurity]
1581 public static extern void JointGroupDestroy(IntPtr group);
1582
1583 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupEmpty"), SuppressUnmanagedCodeSecurity]
1584 public static extern void JointGroupEmpty(IntPtr group);
1585
1586 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1587 public static extern void JointSetAMotorAngle(IntPtr j, int anum, dReal angle);
1588
1589 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1590 public static extern void JointSetAMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1591
1592 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorMode"), SuppressUnmanagedCodeSecurity]
1593 public static extern void JointSetAMotorMode(IntPtr j, int mode);
1594
1595 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1596 public static extern void JointSetAMotorNumAxes(IntPtr group, int num);
1597
1598 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorParam"), SuppressUnmanagedCodeSecurity]
1599 public static extern void JointSetAMotorParam(IntPtr group, int parameter, dReal value);
1600
1601 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor"), SuppressUnmanagedCodeSecurity]
1602 public static extern void JointSetBallAnchor(IntPtr j, dReal x, dReal y, dReal z);
1603
1604 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1605 public static extern void JointSetBallAnchor2(IntPtr j, dReal x, dReal y, dReal z);
1606
1607 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetData"), SuppressUnmanagedCodeSecurity]
1608 public static extern void JointSetData(IntPtr j, IntPtr data);
1609
1610 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFeedback"), SuppressUnmanagedCodeSecurity]
1611 public static extern void JointSetFeedback(IntPtr j, out JointFeedback feedback);
1612
1613 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFixed"), SuppressUnmanagedCodeSecurity]
1614 public static extern void JointSetFixed(IntPtr j);
1615
1616 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1617 public static extern void JointSetHingeAnchor(IntPtr j, dReal x, dReal y, dReal z);
1618
1619 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchorDelta"), SuppressUnmanagedCodeSecurity]
1620 public static extern void JointSetHingeAnchorDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1621
1622 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAxis"), SuppressUnmanagedCodeSecurity]
1623 public static extern void JointSetHingeAxis(IntPtr j, dReal x, dReal y, dReal z);
1624
1625 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeParam"), SuppressUnmanagedCodeSecurity]
1626 public static extern void JointSetHingeParam(IntPtr j, int parameter, dReal value);
1627
1628 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1629 public static extern void JointSetHinge2Anchor(IntPtr j, dReal x, dReal y, dReal z);
1630
1631 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1632 public static extern void JointSetHinge2Axis1(IntPtr j, dReal x, dReal y, dReal z);
1633
1634 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1635 public static extern void JointSetHinge2Axis2(IntPtr j, dReal x, dReal y, dReal z);
1636
1637 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Param"), SuppressUnmanagedCodeSecurity]
1638 public static extern void JointSetHinge2Param(IntPtr j, int parameter, dReal value);
1639
1640 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1641 public static extern void JointSetLMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1642
1643 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1644 public static extern void JointSetLMotorNumAxes(IntPtr j, int num);
1645
1646 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorParam"), SuppressUnmanagedCodeSecurity]
1647 public static extern void JointSetLMotorParam(IntPtr j, int parameter, dReal value);
1648
1649 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DAngleParam"), SuppressUnmanagedCodeSecurity]
1650 public static extern void JointSetPlane2DAngleParam(IntPtr j, int parameter, dReal value);
1651
1652 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DXParam"), SuppressUnmanagedCodeSecurity]
1653 public static extern void JointSetPlane2DXParam(IntPtr j, int parameter, dReal value);
1654
1655 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DYParam"), SuppressUnmanagedCodeSecurity]
1656 public static extern void JointSetPlane2DYParam(IntPtr j, int parameter, dReal value);
1657
1658 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAnchor"), SuppressUnmanagedCodeSecurity]
1659 public static extern void JointSetPRAnchor(IntPtr j, dReal x, dReal y, dReal z);
1660
1661 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis1"), SuppressUnmanagedCodeSecurity]
1662 public static extern void JointSetPRAxis1(IntPtr j, dReal x, dReal y, dReal z);
1663
1664 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis2"), SuppressUnmanagedCodeSecurity]
1665 public static extern void JointSetPRAxis2(IntPtr j, dReal x, dReal y, dReal z);
1666
1667 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRParam"), SuppressUnmanagedCodeSecurity]
1668 public static extern void JointSetPRParam(IntPtr j, int parameter, dReal value);
1669
1670 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxis"), SuppressUnmanagedCodeSecurity]
1671 public static extern void JointSetSliderAxis(IntPtr j, dReal x, dReal y, dReal z);
1672
1673 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxisDelta"), SuppressUnmanagedCodeSecurity]
1674 public static extern void JointSetSliderAxisDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1675
1676 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderParam"), SuppressUnmanagedCodeSecurity]
1677 public static extern void JointSetSliderParam(IntPtr j, int parameter, dReal value);
1678
1679 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1680 public static extern void JointSetUniversalAnchor(IntPtr j, dReal x, dReal y, dReal z);
1681
1682 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1683 public static extern void JointSetUniversalAxis1(IntPtr j, dReal x, dReal y, dReal z);
1684
1685 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1686 public static extern void JointSetUniversalAxis2(IntPtr j, dReal x, dReal y, dReal z);
1687
1688 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalParam"), SuppressUnmanagedCodeSecurity]
1689 public static extern void JointSetUniversalParam(IntPtr j, int parameter, dReal value);
1690
1691 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dLDLTAddTL"), SuppressUnmanagedCodeSecurity]
1692 public static extern void LDLTAddTL(ref dReal L, ref dReal d, ref dReal a, int n, int nskip);
1693
1694 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdd"), SuppressUnmanagedCodeSecurity]
1695 public static extern void MassAdd(ref Mass a, ref Mass b);
1696
1697 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdjust"), SuppressUnmanagedCodeSecurity]
1698 public static extern void MassAdjust(ref Mass m, dReal newmass);
1699
1700 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassCheck"), SuppressUnmanagedCodeSecurity]
1701 public static extern bool MassCheck(ref Mass m);
1702
1703 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1704 public static extern void MassRotate(ref Mass mass, ref Matrix3 R);
1705
1706 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1707 public static extern void MassRotate(ref Mass mass, ref dReal M00);
1708
1709 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBox"), SuppressUnmanagedCodeSecurity]
1710 public static extern void MassSetBox(out Mass mass, dReal density, dReal lx, dReal ly, dReal lz);
1711
1712 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBoxTotal"), SuppressUnmanagedCodeSecurity]
1713 public static extern void MassSetBoxTotal(out Mass mass, dReal total_mass, dReal lx, dReal ly, dReal lz);
1714
1715 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsule"), SuppressUnmanagedCodeSecurity]
1716 public static extern void MassSetCapsule(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1717
1718 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsuleTotal"), SuppressUnmanagedCodeSecurity]
1719 public static extern void MassSetCapsuleTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1720
1721 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinder"), SuppressUnmanagedCodeSecurity]
1722 public static extern void MassSetCylinder(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1723
1724 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinderTotal"), SuppressUnmanagedCodeSecurity]
1725 public static extern void MassSetCylinderTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1726
1727 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetParameters"), SuppressUnmanagedCodeSecurity]
1728 public static extern void MassSetParameters(out Mass mass, dReal themass,
1729 dReal cgx, dReal cgy, dReal cgz,
1730 dReal i11, dReal i22, dReal i33,
1731 dReal i12, dReal i13, dReal i23);
1732
1733 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphere"), SuppressUnmanagedCodeSecurity]
1734 public static extern void MassSetSphere(out Mass mass, dReal density, dReal radius);
1735
1736 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphereTotal"), SuppressUnmanagedCodeSecurity]
1737 public static extern void dMassSetSphereTotal(out Mass mass, dReal total_mass, dReal radius);
1738
1739 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetTrimesh"), SuppressUnmanagedCodeSecurity]
1740 public static extern void MassSetTrimesh(out Mass mass, dReal density, IntPtr g);
1741
1742 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetZero"), SuppressUnmanagedCodeSecurity]
1743 public static extern void MassSetZero(out Mass mass);
1744
1745 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassTranslate"), SuppressUnmanagedCodeSecurity]
1746 public static extern void MassTranslate(ref Mass mass, dReal x, dReal y, dReal z);
1747
1748 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1749 public static extern void Multiply0(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1750
1751 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1752 private static extern void MultiplyiM3V3(out Vector3 vout, ref Matrix3 matrix, ref Vector3 vect,int p, int q, int r);
1753 public static void MultiplyM3V3(out Vector3 outvector, ref Matrix3 matrix, ref Vector3 invector)
1754 {
1755 MultiplyiM3V3(out outvector, ref matrix, ref invector, 3, 3, 1);
1756 }
1757
1758 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply1"), SuppressUnmanagedCodeSecurity]
1759 public static extern void Multiply1(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1760
1761 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply2"), SuppressUnmanagedCodeSecurity]
1762 public static extern void Multiply2(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1763
1764 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1765 public static extern void QFromAxisAndAngle(out Quaternion q, dReal ax, dReal ay, dReal az, dReal angle);
1766
1767 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQfromR"), SuppressUnmanagedCodeSecurity]
1768 public static extern void QfromR(out Quaternion q, ref Matrix3 R);
1769
1770 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply0"), SuppressUnmanagedCodeSecurity]
1771 public static extern void QMultiply0(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1772
1773 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply1"), SuppressUnmanagedCodeSecurity]
1774 public static extern void QMultiply1(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1775
1776 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply2"), SuppressUnmanagedCodeSecurity]
1777 public static extern void QMultiply2(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1778
1779 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply3"), SuppressUnmanagedCodeSecurity]
1780 public static extern void QMultiply3(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1781
1782 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQSetIdentity"), SuppressUnmanagedCodeSecurity]
1783 public static extern void QSetIdentity(out Quaternion q);
1784
1785 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1786 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref Vector3 center, ref Vector3 extents, int depth);
1787
1788 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1789 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref dReal centerX, ref dReal extentsX, int depth);
1790
1791 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRandReal"), SuppressUnmanagedCodeSecurity]
1792 public static extern dReal RandReal();
1793
1794 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFrom2Axes"), SuppressUnmanagedCodeSecurity]
1795 public static extern void RFrom2Axes(out Matrix3 R, dReal ax, dReal ay, dReal az, dReal bx, dReal by, dReal bz);
1796
1797 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1798 public static extern void RFromAxisAndAngle(out Matrix3 R, dReal x, dReal y, dReal z, dReal angle);
1799
1800 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromEulerAngles"), SuppressUnmanagedCodeSecurity]
1801 public static extern void RFromEulerAngles(out Matrix3 R, dReal phi, dReal theta, dReal psi);
1802
1803 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRfromQ"), SuppressUnmanagedCodeSecurity]
1804 public static extern void RfromQ(out Matrix3 R, ref Quaternion q);
1805
1806 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromZAxis"), SuppressUnmanagedCodeSecurity]
1807 public static extern void RFromZAxis(out Matrix3 R, dReal ax, dReal ay, dReal az);
1808
1809 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRSetIdentity"), SuppressUnmanagedCodeSecurity]
1810 public static extern void RSetIdentity(out Matrix3 R);
1811
1812 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetValue"), SuppressUnmanagedCodeSecurity]
1813 public static extern void SetValue(out dReal a, int n);
1814
1815 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetZero"), SuppressUnmanagedCodeSecurity]
1816 public static extern void SetZero(out dReal a, int n);
1817
1818 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSimpleSpaceCreate"), SuppressUnmanagedCodeSecurity]
1819 public static extern IntPtr SimpleSpaceCreate(IntPtr space);
1820
1821 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveCholesky"), SuppressUnmanagedCodeSecurity]
1822 public static extern void SolveCholesky(ref dReal L, out dReal b, int n);
1823
1824 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1"), SuppressUnmanagedCodeSecurity]
1825 public static extern void SolveL1(ref dReal L, out dReal b, int n, int nskip);
1826
1827 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1T"), SuppressUnmanagedCodeSecurity]
1828 public static extern void SolveL1T(ref dReal L, out dReal b, int n, int nskip);
1829
1830 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveLDLT"), SuppressUnmanagedCodeSecurity]
1831 public static extern void SolveLDLT(ref dReal L, ref dReal d, out dReal b, int n, int nskip);
1832
1833 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceAdd"), SuppressUnmanagedCodeSecurity]
1834 public static extern void SpaceAdd(IntPtr space, IntPtr geom);
1835
1836 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceLockQuery"), SuppressUnmanagedCodeSecurity]
1837 public static extern bool SpaceLockQuery(IntPtr space);
1838
1839 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceClean"), SuppressUnmanagedCodeSecurity]
1840 public static extern void SpaceClean(IntPtr space);
1841
1842 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide"), SuppressUnmanagedCodeSecurity]
1843 public static extern void SpaceCollide(IntPtr space, IntPtr data, NearCallback callback);
1844
1845 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide2"), SuppressUnmanagedCodeSecurity]
1846 public static extern void SpaceCollide2(IntPtr space1, IntPtr space2, IntPtr data, NearCallback callback);
1847
1848 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceDestroy"), SuppressUnmanagedCodeSecurity]
1849 public static extern void SpaceDestroy(IntPtr space);
1850
1851 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetCleanup"), SuppressUnmanagedCodeSecurity]
1852 public static extern bool SpaceGetCleanup(IntPtr space);
1853
1854 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetNumGeoms"), SuppressUnmanagedCodeSecurity]
1855 public static extern int SpaceGetNumGeoms(IntPtr space);
1856
1857 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetGeom"), SuppressUnmanagedCodeSecurity]
1858 public static extern IntPtr SpaceGetGeom(IntPtr space, int i);
1859
1860 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetSublevel"), SuppressUnmanagedCodeSecurity]
1861 public static extern int SpaceGetSublevel(IntPtr space);
1862
1863 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceQuery"), SuppressUnmanagedCodeSecurity]
1864 public static extern bool SpaceQuery(IntPtr space, IntPtr geom);
1865
1866 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceRemove"), SuppressUnmanagedCodeSecurity]
1867 public static extern void SpaceRemove(IntPtr space, IntPtr geom);
1868
1869 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetCleanup"), SuppressUnmanagedCodeSecurity]
1870 public static extern void SpaceSetCleanup(IntPtr space, bool mode);
1871
1872 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetSublevel"), SuppressUnmanagedCodeSecurity]
1873 public static extern void SpaceSetSublevel(IntPtr space, int sublevel);
1874
1875 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSweepAndPruneSpaceCreate"), SuppressUnmanagedCodeSecurity]
1876 public static extern IntPtr SweepAndPruneSpaceCreate(IntPtr space, int AxisOrder);
1877
1878 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dVectorScale"), SuppressUnmanagedCodeSecurity]
1879 public static extern void VectorScale(out dReal a, ref dReal d, int n);
1880
1881 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldCreate"), SuppressUnmanagedCodeSecurity]
1882 public static extern IntPtr WorldCreate();
1883
1884 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldDestroy"), SuppressUnmanagedCodeSecurity]
1885 public static extern void WorldDestroy(IntPtr world);
1886
1887 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1888 public static extern int WorldGetAutoDisableAverageSamplesCount(IntPtr world);
1889
1890 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1891 public static extern dReal WorldGetAutoDisableAngularThreshold(IntPtr world);
1892
1893 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1894 public static extern bool WorldGetAutoDisableFlag(IntPtr world);
1895
1896 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1897 public static extern dReal WorldGetAutoDisableLinearThreshold(IntPtr world);
1898
1899 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1900 public static extern int WorldGetAutoDisableSteps(IntPtr world);
1901
1902 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1903 public static extern dReal WorldGetAutoDisableTime(IntPtr world);
1904
1905 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1906 public static extern int WorldGetAutoEnableDepthSF1(IntPtr world);
1907
1908 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetCFM"), SuppressUnmanagedCodeSecurity]
1909 public static extern dReal WorldGetCFM(IntPtr world);
1910
1911 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetERP"), SuppressUnmanagedCodeSecurity]
1912 public static extern dReal WorldGetERP(IntPtr world);
1913
1914 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1915 public static extern void WorldGetGravity(IntPtr world, out Vector3 gravity);
1916
1917 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1918 public static extern void WorldGetGravity(IntPtr world, out dReal X);
1919
1920 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1921 public static extern dReal WorldGetContactMaxCorrectingVel(IntPtr world);
1922
1923 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1924 public static extern dReal WorldGetContactSurfaceLayer(IntPtr world);
1925
1926 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDamping"), SuppressUnmanagedCodeSecurity]
1927 public static extern dReal WorldGetAngularDamping(IntPtr world);
1928
1929 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1930 public static extern dReal WorldGetAngularDampingThreshold(IntPtr world);
1931
1932 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDamping"), SuppressUnmanagedCodeSecurity]
1933 public static extern dReal WorldGetLinearDamping(IntPtr world);
1934
1935 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
1936 public static extern dReal WorldGetLinearDampingThreshold(IntPtr world);
1937
1938 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
1939 public static extern int WorldGetQuickStepNumIterations(IntPtr world);
1940
1941 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepW"), SuppressUnmanagedCodeSecurity]
1942 public static extern dReal WorldGetQuickStepW(IntPtr world);
1943
1944 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
1945 public static extern dReal WorldGetMaxAngularSpeed(IntPtr world);
1946
1947 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1948 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out Vector3 force);
1949
1950 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1951 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out dReal forceX);
1952
1953 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldQuickStep"), SuppressUnmanagedCodeSecurity]
1954 public static extern void WorldQuickStep(IntPtr world, dReal stepsize);
1955
1956 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDamping"), SuppressUnmanagedCodeSecurity]
1957 public static extern void WorldSetAngularDamping(IntPtr world, dReal scale);
1958
1959 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1960 public static extern void WorldSetAngularDampingThreshold(IntPtr world, dReal threshold);
1961
1962 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1963 public static extern void WorldSetAutoDisableAngularThreshold(IntPtr world, dReal angular_threshold);
1964
1965 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1966 public static extern void WorldSetAutoDisableAverageSamplesCount(IntPtr world, int average_samples_count);
1967
1968 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1969 public static extern void WorldSetAutoDisableFlag(IntPtr world, bool do_auto_disable);
1970
1971 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1972 public static extern void WorldSetAutoDisableLinearThreshold(IntPtr world, dReal linear_threshold);
1973
1974 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1975 public static extern void WorldSetAutoDisableSteps(IntPtr world, int steps);
1976
1977 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1978 public static extern void WorldSetAutoDisableTime(IntPtr world, dReal time);
1979
1980 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1981 public static extern void WorldSetAutoEnableDepthSF1(IntPtr world, int autoEnableDepth);
1982
1983 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetCFM"), SuppressUnmanagedCodeSecurity]
1984 public static extern void WorldSetCFM(IntPtr world, dReal cfm);
1985
1986 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1987 public static extern void WorldSetContactMaxCorrectingVel(IntPtr world, dReal vel);
1988
1989 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1990 public static extern void WorldSetContactSurfaceLayer(IntPtr world, dReal depth);
1991
1992 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetDamping"), SuppressUnmanagedCodeSecurity]
1993 public static extern void WorldSetDamping(IntPtr world, dReal linear_scale, dReal angular_scale);
1994
1995 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetERP"), SuppressUnmanagedCodeSecurity]
1996 public static extern void WorldSetERP(IntPtr world, dReal erp);
1997
1998 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetGravity"), SuppressUnmanagedCodeSecurity]
1999 public static extern void WorldSetGravity(IntPtr world, dReal x, dReal y, dReal z);
2000
2001 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDamping"), SuppressUnmanagedCodeSecurity]
2002 public static extern void WorldSetLinearDamping(IntPtr world, dReal scale);
2003
2004 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
2005 public static extern void WorldSetLinearDampingThreshold(IntPtr world, dReal threshold);
2006
2007 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
2008 public static extern void WorldSetQuickStepNumIterations(IntPtr world, int num);
2009
2010 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepW"), SuppressUnmanagedCodeSecurity]
2011 public static extern void WorldSetQuickStepW(IntPtr world, dReal over_relaxation);
2012
2013 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
2014 public static extern void WorldSetMaxAngularSpeed(IntPtr world, dReal max_speed);
2015
2016 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStep"), SuppressUnmanagedCodeSecurity]
2017 public static extern void WorldStep(IntPtr world, dReal stepsize);
2018
2019 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStepFast1"), SuppressUnmanagedCodeSecurity]
2020 public static extern void WorldStepFast1(IntPtr world, dReal stepsize, int maxiterations);
2021
2022 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldExportDIF"), SuppressUnmanagedCodeSecurity]
2023 public static extern void WorldExportDIF(IntPtr world, string filename, bool append, string prefix);
2024 }
2025}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs
new file mode 100644
index 0000000..d32188e
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs
@@ -0,0 +1,90 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Runtime.InteropServices;
32using System.Threading;
33using System.IO;
34using System.Diagnostics;
35using log4net;
36using Nini.Config;
37using OdeAPI;
38using OpenSim.Framework;
39using OpenSim.Region.Physics.Manager;
40using OpenMetaverse;
41
42namespace OpenSim.Region.Physics.OdePlugin
43{
44 /// <summary>
45 /// ODE plugin
46 /// </summary>
47 public class OdePlugin : IPhysicsPlugin
48 {
49 //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
50
51 private OdeScene m_scene;
52
53 public bool Init()
54 {
55 if (Util.IsWindows())
56 Util.LoadArchSpecificWindowsDll("ode.dll");
57
58 if (d.InitODE2(0) != 0)
59 {
60 if (d.AllocateODEDataForThread(~0U) == 0)
61 {
62 d.CloseODE();
63 return false;
64 }
65 return true;
66 }
67 return false;
68 }
69
70 public PhysicsScene GetScene(String sceneIdentifier)
71 {
72 if (m_scene == null)
73 {
74
75 m_scene = new OdeScene(sceneIdentifier);
76 }
77 return (m_scene);
78 }
79
80 public string GetName()
81 {
82 return ("UbitODE");
83 }
84
85 public void Dispose()
86 {
87 d.CloseODE();
88 }
89 }
90} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
new file mode 100644
index 0000000..dafd3a3
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -0,0 +1,2869 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// Revision 2011/12/13 by Ubit Umarov
29//#define SPAM
30
31using System;
32using System.Collections.Generic;
33using System.Reflection;
34using System.Runtime.InteropServices;
35using System.Threading;
36using System.IO;
37using System.Diagnostics;
38using log4net;
39using Nini.Config;
40using OdeAPI;
41using OpenSim.Framework;
42using OpenSim.Region.Physics.Manager;
43using OpenMetaverse;
44
45namespace OpenSim.Region.Physics.OdePlugin
46{
47 // colision flags of things others can colide with
48 // rays, sensors, probes removed since can't be colided with
49 // The top space where things are placed provided further selection
50 // ie physical are in active space nonphysical in static
51 // this should be exclusive as possible
52
53 [Flags]
54 public enum CollisionCategories : uint
55 {
56 Disabled = 0,
57 //by 'things' types
58 Space = 0x01,
59 Geom = 0x02, // aka prim/part
60 Character = 0x04,
61 Land = 0x08,
62 Water = 0x010,
63
64 // by state
65 Phantom = 0x01000,
66 VolumeDtc = 0x02000,
67 Selected = 0x04000,
68 NoShape = 0x08000,
69
70
71 All = 0xffffffff
72 }
73
74 /// <summary>
75 /// Material type for a primitive
76 /// </summary>
77 public enum Material : int
78 {
79 /// <summary></summary>
80 Stone = 0,
81 /// <summary></summary>
82 Metal = 1,
83 /// <summary></summary>
84 Glass = 2,
85 /// <summary></summary>
86 Wood = 3,
87 /// <summary></summary>
88 Flesh = 4,
89 /// <summary></summary>
90 Plastic = 5,
91 /// <summary></summary>
92 Rubber = 6,
93
94 light = 7 // compatibility with old viewers
95 }
96
97 public enum changes : int
98 {
99 Add = 0, // arg null. finishs the prim creation. should be used internally only ( to remove later ?)
100 Remove,
101 Link, // arg AuroraODEPrim new parent prim or null to delink. Makes the prim part of a object with prim parent as root
102 // or removes from a object if arg is null
103 DeLink,
104 Position, // arg Vector3 new position in world coords. Changes prim position. Prim must know if it is root or child
105 Orientation, // arg Quaternion new orientation in world coords. Changes prim position. Prim must know it it is root or child
106 PosOffset, // not in use
107 // arg Vector3 new position in local coords. Changes prim position in object
108 OriOffset, // not in use
109 // arg Vector3 new position in local coords. Changes prim position in object
110 Velocity,
111 AngVelocity,
112 Acceleration,
113 Force,
114 Torque,
115 Momentum,
116
117 AddForce,
118 AddAngForce,
119 AngLock,
120
121 Buoyancy,
122
123 PIDTarget,
124 PIDTau,
125 PIDActive,
126
127 PIDHoverHeight,
128 PIDHoverType,
129 PIDHoverTau,
130 PIDHoverActive,
131
132 Size,
133 AvatarSize,
134 Shape,
135 PhysRepData,
136 AddPhysRep,
137
138 CollidesWater,
139 VolumeDtc,
140
141 Physical,
142 Phantom,
143 Selected,
144 disabled,
145 building,
146
147 VehicleType,
148 VehicleFloatParam,
149 VehicleVectorParam,
150 VehicleRotationParam,
151 VehicleFlags,
152 SetVehicle,
153
154 Null //keep this last used do dim the methods array. does nothing but pulsing the prim
155 }
156
157 public struct ODEchangeitem
158 {
159 public PhysicsActor actor;
160 public OdeCharacter character;
161 public changes what;
162 public Object arg;
163 }
164
165
166
167 public class OdeScene : PhysicsScene
168 {
169 private readonly ILog m_log;
170 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
171
172 public bool OdeUbitLib = false;
173 public bool m_suportCombine = false; // mega suport not tested
174
175// private int threadid = 0;
176// private Random fluidRandomizer = new Random(Environment.TickCount);
177
178// const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce;
179
180 const d.ContactFlags comumContactFlags = d.ContactFlags.Bounce | d.ContactFlags.Approx1 | d.ContactFlags.Slip1 | d.ContactFlags.Slip2;
181 const float comumContactERP = 0.7f;
182 const float comumContactCFM = 0.0001f;
183 const float comumContactSLIP = 0f;
184
185 float frictionMovementMult = 0.8f;
186
187 float TerrainBounce = 0.1f;
188 float TerrainFriction = 0.3f;
189
190 public float AvatarFriction = 0;// 0.9f * 0.5f;
191
192 // this netx dimensions are only relevant for terrain partition (mega regions)
193 // WorldExtents below has the simulation dimensions
194 // they should be identical except on mega regions
195 private uint m_regionWidth = Constants.RegionSize;
196 private uint m_regionHeight = Constants.RegionSize;
197
198 public float ODE_STEPSIZE = 0.020f;
199 public float HalfOdeStep = 0.01f;
200 public int odetimestepMS = 20; // rounded
201 private float metersInSpace = 25.6f;
202 private float m_timeDilation = 1.0f;
203
204 private DateTime m_lastframe;
205 private DateTime m_lastMeshExpire;
206
207 public float gravityx = 0f;
208 public float gravityy = 0f;
209 public float gravityz = -9.8f;
210
211 private float waterlevel = 0f;
212 private int framecount = 0;
213
214// private int m_meshExpireCntr;
215
216 private float avDensity = 3f;
217 private float avMovementDivisorWalk = 1.3f;
218 private float avMovementDivisorRun = 0.8f;
219 private float minimumGroundFlightOffset = 3f;
220 public float maximumMassObject = 10000.01f;
221
222
223 public float geomDefaultDensity = 10.000006836f;
224
225 public float bodyPIDD = 35f;
226 public float bodyPIDG = 25;
227
228 public int bodyFramesAutoDisable = 5;
229
230 private d.NearCallback nearCallback;
231
232 private HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
233 private HashSet<OdePrim> _prims = new HashSet<OdePrim>();
234 private HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
235 private HashSet<OdePrim> _activegroups = new HashSet<OdePrim>();
236
237 public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>();
238
239 /// <summary>
240 /// A list of actors that should receive collision events.
241 /// </summary>
242 private List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
243 private List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>();
244
245 private HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
246// public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
247 public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
248
249 private float contactsurfacelayer = 0.001f;
250
251 private int contactsPerCollision = 80;
252 internal IntPtr ContactgeomsArray = IntPtr.Zero;
253 private IntPtr GlobalContactsArray = IntPtr.Zero;
254 private d.Contact SharedTmpcontact = new d.Contact();
255
256 const int maxContactsbeforedeath = 4000;
257 private volatile int m_global_contactcount = 0;
258
259 private IntPtr contactgroup;
260
261 public ContactData[] m_materialContactsData = new ContactData[8];
262
263 private Dictionary<Vector3, IntPtr> RegionTerrain = new Dictionary<Vector3, IntPtr>();
264 private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>();
265 private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>();
266
267 private int m_physicsiterations = 15;
268 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
269// private PhysicsActor PANull = new NullPhysicsActor();
270 private float step_time = 0.0f;
271
272 public IntPtr world;
273
274
275 // split the spaces acording to contents type
276 // ActiveSpace contains characters and active prims
277 // StaticSpace contains land and other that is mostly static in enviroment
278 // this can contain subspaces, like the grid in staticspace
279 // as now space only contains this 2 top spaces
280
281 public IntPtr TopSpace; // the global space
282 public IntPtr ActiveSpace; // space for active prims
283 public IntPtr CharsSpace; // space for active prims
284 public IntPtr StaticSpace; // space for the static things around
285 public IntPtr GroundSpace; // space for ground
286
287 // some speedup variables
288 private int spaceGridMaxX;
289 private int spaceGridMaxY;
290 private float spacesPerMeterX;
291 private float spacesPerMeterY;
292
293 // split static geometry collision into a grid as before
294 private IntPtr[,] staticPrimspace;
295 private IntPtr[] staticPrimspaceOffRegion;
296
297 public Object OdeLock;
298 public static Object SimulationLock;
299
300 public IMesher mesher;
301
302 private IConfigSource m_config;
303
304 public bool physics_logging = false;
305 public int physics_logging_interval = 0;
306 public bool physics_logging_append_existing_logfile = false;
307
308 private Vector3 m_worldOffset = Vector3.Zero;
309 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
310 private PhysicsScene m_parentScene = null;
311
312 private ODERayCastRequestManager m_rayCastManager;
313 public ODEMeshWorker m_meshWorker;
314
315/* maybe needed if ode uses tls
316 private void checkThread()
317 {
318
319 int th = Thread.CurrentThread.ManagedThreadId;
320 if(th != threadid)
321 {
322 threadid = th;
323 d.AllocateODEDataForThread(~0U);
324 }
325 }
326 */
327 /// <summary>
328 /// Initiailizes the scene
329 /// Sets many properties that ODE requires to be stable
330 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
331 /// </summary>
332 public OdeScene(string sceneIdentifier)
333 {
334 m_log
335 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + sceneIdentifier);
336
337// checkThread();
338 Name = sceneIdentifier;
339
340 OdeLock = new Object();
341 SimulationLock = new Object();
342
343 nearCallback = near;
344
345 m_rayCastManager = new ODERayCastRequestManager(this);
346
347 lock (OdeLock)
348 {
349 // Create the world and the first space
350 try
351 {
352 world = d.WorldCreate();
353 TopSpace = d.HashSpaceCreate(IntPtr.Zero);
354
355 // now the major subspaces
356 ActiveSpace = d.HashSpaceCreate(TopSpace);
357 CharsSpace = d.HashSpaceCreate(TopSpace);
358 StaticSpace = d.HashSpaceCreate(TopSpace);
359 GroundSpace = d.HashSpaceCreate(TopSpace);
360 }
361 catch
362 {
363 // i must RtC#FM
364 // i did!
365 }
366
367 d.HashSpaceSetLevels(TopSpace, -2, 8);
368 d.HashSpaceSetLevels(ActiveSpace, -2, 8);
369 d.HashSpaceSetLevels(CharsSpace, -4, 3);
370 d.HashSpaceSetLevels(StaticSpace, -2, 8);
371 d.HashSpaceSetLevels(GroundSpace, 0, 8);
372
373 // demote to second level
374 d.SpaceSetSublevel(ActiveSpace, 1);
375 d.SpaceSetSublevel(CharsSpace, 1);
376 d.SpaceSetSublevel(StaticSpace, 1);
377 d.SpaceSetSublevel(GroundSpace, 1);
378
379 d.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space |
380 CollisionCategories.Geom |
381 CollisionCategories.Character |
382 CollisionCategories.Phantom |
383 CollisionCategories.VolumeDtc
384 ));
385 d.GeomSetCollideBits(ActiveSpace, (uint)(CollisionCategories.Space |
386 CollisionCategories.Geom |
387 CollisionCategories.Character |
388 CollisionCategories.Phantom |
389 CollisionCategories.VolumeDtc
390 ));
391 d.GeomSetCategoryBits(CharsSpace, (uint)(CollisionCategories.Space |
392 CollisionCategories.Geom |
393 CollisionCategories.Character |
394 CollisionCategories.Phantom |
395 CollisionCategories.VolumeDtc
396 ));
397 d.GeomSetCollideBits(CharsSpace, 0);
398
399 d.GeomSetCategoryBits(StaticSpace, (uint)(CollisionCategories.Space |
400 CollisionCategories.Geom |
401// CollisionCategories.Land |
402// CollisionCategories.Water |
403 CollisionCategories.Phantom |
404 CollisionCategories.VolumeDtc
405 ));
406 d.GeomSetCollideBits(StaticSpace, 0);
407
408 d.GeomSetCategoryBits(GroundSpace, (uint)(CollisionCategories.Land));
409 d.GeomSetCollideBits(GroundSpace, 0);
410
411 contactgroup = d.JointGroupCreate(maxContactsbeforedeath + 1);
412 //contactgroup
413
414 d.WorldSetAutoDisableFlag(world, false);
415 }
416 }
417
418 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
419 {
420 WorldExtents.X = regionExtent.X;
421 m_regionWidth = (uint)regionExtent.X;
422 WorldExtents.Y = regionExtent.Y;
423 m_regionHeight = (uint)regionExtent.Y;
424
425 m_suportCombine = false;
426 Initialise(meshmerizer, config);
427 }
428
429
430 public override void Initialise(IMesher meshmerizer, IConfigSource config)
431 {
432// checkThread();
433 mesher = meshmerizer;
434 m_config = config;
435
436 string ode_config = d.GetConfiguration();
437 if (ode_config != null && ode_config != "")
438 {
439 m_log.WarnFormat("ODE configuration: {0}", ode_config);
440
441 if (ode_config.Contains("ODE_Ubit"))
442 {
443 OdeUbitLib = true;
444 }
445 }
446
447 // Defaults
448
449 int contactsPerCollision = 80;
450
451 IConfig physicsconfig = null;
452
453 if (m_config != null)
454 {
455 physicsconfig = m_config.Configs["ODEPhysicsSettings"];
456 if (physicsconfig != null)
457 {
458 gravityx = physicsconfig.GetFloat("world_gravityx", gravityx);
459 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy);
460 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz);
461
462 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace);
463
464// contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
465
466 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
467
468 avDensity = physicsconfig.GetFloat("av_density", avDensity);
469 avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", avMovementDivisorWalk);
470 avMovementDivisorRun = physicsconfig.GetFloat("av_movement_divisor_run", avMovementDivisorRun);
471
472 contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", contactsPerCollision);
473
474 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", geomDefaultDensity);
475 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", bodyFramesAutoDisable);
476
477 physics_logging = physicsconfig.GetBoolean("physics_logging", false);
478 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0);
479 physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false);
480
481 minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", minimumGroundFlightOffset);
482 maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", maximumMassObject);
483 }
484 }
485
486
487 d.WorldSetCFM(world, comumContactCFM);
488 d.WorldSetERP(world, comumContactERP);
489
490 d.WorldSetGravity(world, gravityx, gravityy, gravityz);
491
492 d.WorldSetLinearDamping(world, 0.002f);
493 d.WorldSetAngularDamping(world, 0.002f);
494 d.WorldSetAngularDampingThreshold(world, 0f);
495 d.WorldSetLinearDampingThreshold(world, 0f);
496 d.WorldSetMaxAngularSpeed(world, 100f);
497
498 d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
499
500 d.WorldSetContactSurfaceLayer(world, contactsurfacelayer);
501 d.WorldSetContactMaxCorrectingVel(world, 60.0f);
502
503 m_meshWorker = new ODEMeshWorker(this, m_log, meshmerizer, physicsconfig);
504
505 HalfOdeStep = ODE_STEPSIZE * 0.5f;
506 odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f);
507
508 ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
509 GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
510
511 SharedTmpcontact.geom.g1 = IntPtr.Zero;
512 SharedTmpcontact.geom.g2 = IntPtr.Zero;
513
514 SharedTmpcontact.geom.side1 = -1;
515 SharedTmpcontact.geom.side2 = -1;
516
517 SharedTmpcontact.surface.mode = comumContactFlags;
518 SharedTmpcontact.surface.mu = 0;
519 SharedTmpcontact.surface.bounce = 0;
520 SharedTmpcontact.surface.soft_cfm = comumContactCFM;
521 SharedTmpcontact.surface.soft_erp = comumContactERP;
522 SharedTmpcontact.surface.slip1 = comumContactSLIP;
523 SharedTmpcontact.surface.slip2 = comumContactSLIP;
524
525 m_materialContactsData[(int)Material.Stone].mu = 0.8f;
526 m_materialContactsData[(int)Material.Stone].bounce = 0.4f;
527
528 m_materialContactsData[(int)Material.Metal].mu = 0.3f;
529 m_materialContactsData[(int)Material.Metal].bounce = 0.4f;
530
531 m_materialContactsData[(int)Material.Glass].mu = 0.2f;
532 m_materialContactsData[(int)Material.Glass].bounce = 0.7f;
533
534 m_materialContactsData[(int)Material.Wood].mu = 0.6f;
535 m_materialContactsData[(int)Material.Wood].bounce = 0.5f;
536
537 m_materialContactsData[(int)Material.Flesh].mu = 0.9f;
538 m_materialContactsData[(int)Material.Flesh].bounce = 0.3f;
539
540 m_materialContactsData[(int)Material.Plastic].mu = 0.4f;
541 m_materialContactsData[(int)Material.Plastic].bounce = 0.7f;
542
543 m_materialContactsData[(int)Material.Rubber].mu = 0.9f;
544 m_materialContactsData[(int)Material.Rubber].bounce = 0.95f;
545
546 m_materialContactsData[(int)Material.light].mu = 0.0f;
547 m_materialContactsData[(int)Material.light].bounce = 0.0f;
548
549
550 spacesPerMeterX = 1.0f / metersInSpace;
551 spacesPerMeterY = spacesPerMeterX;
552 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeterX);
553 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeterY);
554
555 if (spaceGridMaxX > 40)
556 {
557 spaceGridMaxX = 40;
558 spacesPerMeterX = WorldExtents.X / spaceGridMaxX;
559 }
560
561 if (spaceGridMaxY > 40)
562 {
563 spaceGridMaxY = 40;
564 spacesPerMeterY = WorldExtents.Y / spaceGridMaxY;
565 }
566
567 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
568
569 // create all spaces now
570 int i, j;
571 IntPtr newspace;
572
573 for (i = 0; i < spaceGridMaxX; i++)
574 for (j = 0; j < spaceGridMaxY; j++)
575 {
576 newspace = d.HashSpaceCreate(StaticSpace);
577 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
578 waitForSpaceUnlock(newspace);
579 d.SpaceSetSublevel(newspace, 2);
580 d.HashSpaceSetLevels(newspace, -2, 8);
581 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
582 CollisionCategories.Geom |
583 CollisionCategories.Land |
584 CollisionCategories.Water |
585 CollisionCategories.Phantom |
586 CollisionCategories.VolumeDtc
587 ));
588 d.GeomSetCollideBits(newspace, 0);
589
590 staticPrimspace[i, j] = newspace;
591 }
592
593 // let this now be index limit
594 spaceGridMaxX--;
595 spaceGridMaxY--;
596
597 // create 4 off world spaces (x<0,x>max,y<0,y>max)
598 staticPrimspaceOffRegion = new IntPtr[4];
599
600 for (i = 0; i < 4; i++)
601 {
602 newspace = d.HashSpaceCreate(StaticSpace);
603 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
604 waitForSpaceUnlock(newspace);
605 d.SpaceSetSublevel(newspace, 2);
606 d.HashSpaceSetLevels(newspace, -2, 8);
607 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
608 CollisionCategories.Geom |
609 CollisionCategories.Land |
610 CollisionCategories.Water |
611 CollisionCategories.Phantom |
612 CollisionCategories.VolumeDtc
613 ));
614 d.GeomSetCollideBits(newspace, 0);
615
616 staticPrimspaceOffRegion[i] = newspace;
617 }
618
619 m_lastframe = DateTime.UtcNow;
620 m_lastMeshExpire = m_lastframe;
621 }
622
623 internal void waitForSpaceUnlock(IntPtr space)
624 {
625 //if (space != IntPtr.Zero)
626 //while (d.SpaceLockQuery(space)) { } // Wait and do nothing
627 }
628
629 #region Collision Detection
630
631 // sets a global contact for a joint for contactgeom , and base contact description)
632
633
634
635 private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom)
636 {
637 if (m_global_contactcount >= maxContactsbeforedeath)
638 return IntPtr.Zero;
639
640 m_global_contactcount++;
641
642 SharedTmpcontact.geom.depth = contactGeom.depth;
643 SharedTmpcontact.geom.pos = contactGeom.pos;
644 SharedTmpcontact.geom.normal = contactGeom.normal;
645
646 IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf));
647 Marshal.StructureToPtr(SharedTmpcontact, contact, true);
648 return d.JointCreateContactPtr(world, contactgroup, contact);
649 }
650
651 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom)
652 {
653 if (ContactgeomsArray == IntPtr.Zero || index >= contactsPerCollision)
654 return false;
655
656 IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * d.ContactGeom.unmanagedSizeOf));
657 newcontactgeom = (d.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(d.ContactGeom));
658 return true;
659 }
660
661 /// <summary>
662 /// This is our near callback. A geometry is near a body
663 /// </summary>
664 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
665 /// <param name="g1">a geometry or space</param>
666 /// <param name="g2">another geometry or space</param>
667 ///
668
669 private void near(IntPtr space, IntPtr g1, IntPtr g2)
670 {
671 // no lock here! It's invoked from within Simulate(), which is thread-locked
672
673 if (m_global_contactcount >= maxContactsbeforedeath)
674 return;
675
676 // Test if we're colliding a geom with a space.
677 // If so we have to drill down into the space recursively
678
679 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
680 return;
681
682 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2))
683 {
684 // We'll be calling near recursivly if one
685 // of them is a space to find all of the
686 // contact points in the space
687 try
688 {
689 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
690 }
691 catch (AccessViolationException)
692 {
693 m_log.Warn("[PHYSICS]: Unable to collide test a space");
694 return;
695 }
696 //here one should check collisions of geoms inside a space
697 // but on each space we only should have geoms that not colide amoung each other
698 // so we don't dig inside spaces
699 return;
700 }
701
702 // get geom bodies to check if we already a joint contact
703 // guess this shouldn't happen now
704 IntPtr b1 = d.GeomGetBody(g1);
705 IntPtr b2 = d.GeomGetBody(g2);
706
707 // d.GeomClassID id = d.GeomGetClass(g1);
708
709 // Figure out how many contact points we have
710 int count = 0;
711 try
712 {
713 // Colliding Geom To Geom
714 // This portion of the function 'was' blatantly ripped off from BoxStack.cs
715
716 if (g1 == g2)
717 return; // Can't collide with yourself
718
719 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
720 return;
721 /*
722 // debug
723 PhysicsActor dp2;
724 if (d.GeomGetClass(g1) == d.GeomClassID.HeightfieldClass)
725 {
726 d.AABB aabb;
727 d.GeomGetAABB(g2, out aabb);
728 float x = aabb.MaxX - aabb.MinX;
729 float y = aabb.MaxY - aabb.MinY;
730 float z = aabb.MaxZ - aabb.MinZ;
731 if (x > 60.0f || y > 60.0f || z > 60.0f)
732 {
733 if (!actor_name_map.TryGetValue(g2, out dp2))
734 m_log.WarnFormat("[PHYSICS]: failed actor mapping for geom 2");
735 else
736 m_log.WarnFormat("[PHYSICS]: land versus large prim geo {0},size {1}, AABBsize <{2},{3},{4}>, at {5} ori {6},({7})",
737 dp2.Name, dp2.Size, x, y, z,
738 dp2.Position.ToString(),
739 dp2.Orientation.ToString(),
740 dp2.Orientation.Length());
741 return;
742 }
743 }
744 //
745 */
746
747
748 if (d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc ||
749 d.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc)
750 {
751 int cflags;
752 unchecked
753 {
754 cflags = (int)(1 | d.CONTACTS_UNIMPORTANT);
755 }
756 count = d.CollidePtr(g1, g2, cflags, ContactgeomsArray, d.ContactGeom.unmanagedSizeOf);
757 }
758 else
759 count = d.CollidePtr(g1, g2, (contactsPerCollision & 0xffff), ContactgeomsArray, d.ContactGeom.unmanagedSizeOf);
760 }
761 catch (SEHException)
762 {
763 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
764 // ode.drelease(world);
765 base.TriggerPhysicsBasedRestart();
766 }
767 catch (Exception e)
768 {
769 m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message);
770 return;
771 }
772
773 // contacts done
774 if (count == 0)
775 return;
776
777 // try get physical actors
778 PhysicsActor p1;
779 PhysicsActor p2;
780
781 if (!actor_name_map.TryGetValue(g1, out p1))
782 {
783 m_log.WarnFormat("[PHYSICS]: failed actor mapping for geom 1");
784 return;
785 }
786
787 if (!actor_name_map.TryGetValue(g2, out p2))
788 {
789 m_log.WarnFormat("[PHYSICS]: failed actor mapping for geom 2");
790 return;
791 }
792
793 // update actors collision score
794 if (p1.CollisionScore >= float.MaxValue - count)
795 p1.CollisionScore = 0;
796 p1.CollisionScore += count;
797
798 if (p2.CollisionScore >= float.MaxValue - count)
799 p2.CollisionScore = 0;
800 p2.CollisionScore += count;
801
802 // get first contact
803 d.ContactGeom curContact = new d.ContactGeom();
804
805 if (!GetCurContactGeom(0, ref curContact))
806 return;
807
808 ContactPoint maxDepthContact = new ContactPoint();
809
810 // do volume detection case
811 if ((p1.IsVolumeDtc || p2.IsVolumeDtc))
812 {
813 maxDepthContact = new ContactPoint(
814 new Vector3(curContact.pos.X, curContact.pos.Y, curContact.pos.Z),
815 new Vector3(curContact.normal.X, curContact.normal.Y, curContact.normal.Z),
816 curContact.depth, false
817 );
818
819 collision_accounting_events(p1, p2, maxDepthContact);
820 return;
821 }
822
823 // big messy collision analises
824
825 float mu = 0;
826 float bounce = 0;
827// bool IgnoreNegSides = false;
828
829 ContactData contactdata1 = new ContactData(0, 0, false);
830 ContactData contactdata2 = new ContactData(0, 0, false);
831
832 bool dop1ava = false;
833 bool dop2ava = false;
834 bool ignore = false;
835
836 switch (p1.PhysicsActorType)
837 {
838 case (int)ActorTypes.Agent:
839 {
840 dop1ava = true;
841 switch (p2.PhysicsActorType)
842 {
843 case (int)ActorTypes.Agent:
844 case (int)ActorTypes.Prim:
845 break;
846
847 default:
848 ignore = true; // avatar to terrain and water ignored
849 break;
850 }
851 break;
852 }
853
854 case (int)ActorTypes.Prim:
855 {
856 switch (p2.PhysicsActorType)
857 {
858 case (int)ActorTypes.Agent:
859 dop2ava = true;
860 break;
861
862 case (int)ActorTypes.Prim:
863 Vector3 relV = p1.Velocity - p2.Velocity;
864 float relVlenSQ = relV.LengthSquared();
865 if (relVlenSQ > 0.0001f)
866 {
867 p1.CollidingObj = true;
868 p2.CollidingObj = true;
869 }
870 p1.getContactData(ref contactdata1);
871 p2.getContactData(ref contactdata2);
872 bounce = contactdata1.bounce * contactdata2.bounce;
873 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
874
875 if (relVlenSQ > 0.01f)
876 mu *= frictionMovementMult;
877
878 break;
879
880 case (int)ActorTypes.Ground:
881 p1.getContactData(ref contactdata1);
882 bounce = contactdata1.bounce * TerrainBounce;
883 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction);
884
885 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
886 mu *= frictionMovementMult;
887 p1.CollidingGround = true;
888 /*
889 if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
890 {
891 if (curContact.side1 > 0)
892 IgnoreNegSides = true;
893 }
894 */
895 break;
896
897 case (int)ActorTypes.Water:
898 default:
899 ignore = true;
900 break;
901 }
902 }
903 break;
904
905 case (int)ActorTypes.Ground:
906 if (p2.PhysicsActorType == (int)ActorTypes.Prim)
907 {
908 p2.CollidingGround = true;
909 p2.getContactData(ref contactdata2);
910 bounce = contactdata2.bounce * TerrainBounce;
911 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction);
912
913// if (curContact.side1 > 0) // should be 2 ?
914// IgnoreNegSides = true;
915
916 if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f)
917 mu *= frictionMovementMult;
918 }
919 else
920 ignore = true;
921 break;
922
923 case (int)ActorTypes.Water:
924 default:
925 break;
926 }
927
928 if (ignore)
929 return;
930
931 IntPtr Joint;
932 bool FeetCollision = false;
933 int ncontacts = 0;
934
935 int i = 0;
936
937 maxDepthContact = new ContactPoint();
938 maxDepthContact.PenetrationDepth = float.MinValue;
939 ContactPoint minDepthContact = new ContactPoint();
940 minDepthContact.PenetrationDepth = float.MaxValue;
941
942 SharedTmpcontact.geom.depth = 0;
943 SharedTmpcontact.surface.mu = mu;
944 SharedTmpcontact.surface.bounce = bounce;
945
946 d.ContactGeom altContact = new d.ContactGeom();
947 bool useAltcontact = false;
948 bool noskip = true;
949
950 while (true)
951 {
952// if (!(IgnoreNegSides && curContact.side1 < 0))
953 {
954 noskip = true;
955 useAltcontact = false;
956
957 if (dop1ava)
958 {
959 if ((((OdeCharacter)p1).Collide(g1, g2, false, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
960 {
961 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
962 {
963 p1.CollidingObj = true;
964 p2.CollidingObj = true;
965 }
966 else if (p2.Velocity.LengthSquared() > 0.0f)
967 p2.CollidingObj = true;
968 }
969 else
970 noskip = false;
971 }
972 else if (dop2ava)
973 {
974 if ((((OdeCharacter)p2).Collide(g2, g1, true, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
975 {
976 if (p1.PhysicsActorType == (int)ActorTypes.Agent)
977 {
978 p1.CollidingObj = true;
979 p2.CollidingObj = true;
980 }
981 else if (p2.Velocity.LengthSquared() > 0.0f)
982 p1.CollidingObj = true;
983 }
984 else
985 noskip = false;
986 }
987
988 if (noskip)
989 {
990 if(useAltcontact)
991 Joint = CreateContacJoint(ref altContact);
992 else
993 Joint = CreateContacJoint(ref curContact);
994
995 if (Joint == IntPtr.Zero)
996 break;
997
998 d.JointAttach(Joint, b1, b2);
999
1000 ncontacts++;
1001
1002 if (curContact.depth > maxDepthContact.PenetrationDepth)
1003 {
1004 maxDepthContact.Position.X = curContact.pos.X;
1005 maxDepthContact.Position.Y = curContact.pos.Y;
1006 maxDepthContact.Position.Z = curContact.pos.Z;
1007 maxDepthContact.PenetrationDepth = curContact.depth;
1008 maxDepthContact.CharacterFeet = FeetCollision;
1009 }
1010
1011 if (curContact.depth < minDepthContact.PenetrationDepth)
1012 {
1013 minDepthContact.PenetrationDepth = curContact.depth;
1014 minDepthContact.SurfaceNormal.X = curContact.normal.X;
1015 minDepthContact.SurfaceNormal.Y = curContact.normal.Y;
1016 minDepthContact.SurfaceNormal.Z = curContact.normal.Z;
1017 }
1018 }
1019 }
1020 if (++i >= count)
1021 break;
1022
1023 if (!GetCurContactGeom(i, ref curContact))
1024 break;
1025 }
1026
1027 if (ncontacts > 0)
1028 {
1029 maxDepthContact.SurfaceNormal.X = minDepthContact.SurfaceNormal.X;
1030 maxDepthContact.SurfaceNormal.Y = minDepthContact.SurfaceNormal.Y;
1031 maxDepthContact.SurfaceNormal.Z = minDepthContact.SurfaceNormal.Z;
1032
1033 collision_accounting_events(p1, p2, maxDepthContact);
1034 }
1035 }
1036
1037 private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact)
1038 {
1039 uint obj2LocalID = 0;
1040
1041 bool p1events = p1.SubscribedEvents();
1042 bool p2events = p2.SubscribedEvents();
1043
1044 if (p1.IsVolumeDtc)
1045 p2events = false;
1046 if (p2.IsVolumeDtc)
1047 p1events = false;
1048
1049 if (!p2events && !p1events)
1050 return;
1051
1052 Vector3 vel = Vector3.Zero;
1053 if (p2 != null && p2.IsPhysical)
1054 vel = p2.Velocity;
1055
1056 if (p1 != null && p1.IsPhysical)
1057 vel -= p1.Velocity;
1058
1059 contact.RelativeSpeed = Vector3.Dot(vel, contact.SurfaceNormal);
1060
1061 switch ((ActorTypes)p1.PhysicsActorType)
1062 {
1063 case ActorTypes.Agent:
1064 case ActorTypes.Prim:
1065 {
1066 switch ((ActorTypes)p2.PhysicsActorType)
1067 {
1068 case ActorTypes.Agent:
1069 case ActorTypes.Prim:
1070 if (p2events)
1071 {
1072 AddCollisionEventReporting(p2);
1073 p2.AddCollisionEvent(p1.ParentActor.LocalID, contact);
1074 }
1075 obj2LocalID = p2.ParentActor.LocalID;
1076 break;
1077
1078 case ActorTypes.Ground:
1079 case ActorTypes.Unknown:
1080 default:
1081 obj2LocalID = 0;
1082 break;
1083 }
1084 if (p1events)
1085 {
1086 contact.SurfaceNormal = -contact.SurfaceNormal;
1087 AddCollisionEventReporting(p1);
1088 p1.AddCollisionEvent(obj2LocalID, contact);
1089 }
1090 break;
1091 }
1092 case ActorTypes.Ground:
1093 case ActorTypes.Unknown:
1094 default:
1095 {
1096 if (p2events && !p2.IsVolumeDtc)
1097 {
1098 AddCollisionEventReporting(p2);
1099 p2.AddCollisionEvent(0, contact);
1100 }
1101 break;
1102 }
1103 }
1104 }
1105
1106 /// <summary>
1107 /// This is our collision testing routine in ODE
1108 /// </summary>
1109 /// <param name="timeStep"></param>
1110 private void collision_optimized()
1111 {
1112 lock (_characters)
1113 {
1114 try
1115 {
1116 foreach (OdeCharacter chr in _characters)
1117 {
1118 if (chr == null || chr.Body == IntPtr.Zero)
1119 continue;
1120
1121 chr.IsColliding = false;
1122 // chr.CollidingGround = false; not done here
1123 chr.CollidingObj = false;
1124 // do colisions with static space
1125 d.SpaceCollide2(chr.collider, StaticSpace, IntPtr.Zero, nearCallback);
1126
1127 // no coll with gnd
1128 }
1129 // chars with chars
1130 d.SpaceCollide(CharsSpace, IntPtr.Zero, nearCallback);
1131
1132 }
1133 catch (AccessViolationException)
1134 {
1135 m_log.Warn("[PHYSICS]: Unable to collide Character to static space");
1136 }
1137
1138 }
1139
1140 lock (_activeprims)
1141 {
1142 foreach (OdePrim aprim in _activeprims)
1143 {
1144 aprim.CollisionScore = 0;
1145 aprim.IsColliding = false;
1146 }
1147 }
1148
1149 // collide active prims with static enviroment
1150 lock (_activegroups)
1151 {
1152 try
1153 {
1154 foreach (OdePrim prm in _activegroups)
1155 {
1156 if (!prm.m_outbounds)
1157 {
1158 if (d.BodyIsEnabled(prm.Body))
1159 {
1160 d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback);
1161 d.SpaceCollide2(GroundSpace, prm.collide_geom, IntPtr.Zero, nearCallback);
1162 }
1163 }
1164 }
1165 }
1166 catch (AccessViolationException)
1167 {
1168 m_log.Warn("[PHYSICS]: Unable to collide Active prim to static space");
1169 }
1170 }
1171 // colide active amoung them
1172 try
1173 {
1174 d.SpaceCollide(ActiveSpace, IntPtr.Zero, nearCallback);
1175 }
1176 catch (AccessViolationException)
1177 {
1178 m_log.Warn("[PHYSICS]: Unable to collide Active with Characters space");
1179 }
1180 // and with chars
1181 try
1182 {
1183 d.SpaceCollide2(CharsSpace,ActiveSpace, IntPtr.Zero, nearCallback);
1184 }
1185 catch (AccessViolationException)
1186 {
1187 m_log.Warn("[PHYSICS]: Unable to collide in Active space");
1188 }
1189 // _perloopContact.Clear();
1190 }
1191
1192 #endregion
1193 /// <summary>
1194 /// Add actor to the list that should receive collision events in the simulate loop.
1195 /// </summary>
1196 /// <param name="obj"></param>
1197 public void AddCollisionEventReporting(PhysicsActor obj)
1198 {
1199 if (!_collisionEventPrim.Contains(obj))
1200 _collisionEventPrim.Add(obj);
1201 }
1202
1203 /// <summary>
1204 /// Remove actor from the list that should receive collision events in the simulate loop.
1205 /// </summary>
1206 /// <param name="obj"></param>
1207 public void RemoveCollisionEventReporting(PhysicsActor obj)
1208 {
1209 if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj))
1210 _collisionEventPrimRemove.Add(obj);
1211 }
1212
1213 public override float TimeDilation
1214 {
1215 get { return m_timeDilation; }
1216 }
1217
1218 public override bool SupportsNINJAJoints
1219 {
1220 get { return false; }
1221 }
1222
1223 #region Add/Remove Entities
1224
1225 public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, float feetOffset, bool isFlying)
1226 {
1227 Vector3 pos;
1228 pos.X = position.X;
1229 pos.Y = position.Y;
1230 pos.Z = position.Z;
1231 OdeCharacter newAv = new OdeCharacter(localID,avName, this, pos, size, feetOffset, avDensity, avMovementDivisorWalk, avMovementDivisorRun);
1232 newAv.Flying = isFlying;
1233 newAv.MinimumGroundFlightOffset = minimumGroundFlightOffset;
1234
1235 return newAv;
1236 }
1237
1238 public void AddCharacter(OdeCharacter chr)
1239 {
1240 lock (_characters)
1241 {
1242 if (!_characters.Contains(chr))
1243 {
1244 _characters.Add(chr);
1245 if (chr.bad)
1246 m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid);
1247 }
1248 }
1249 }
1250
1251 public void RemoveCharacter(OdeCharacter chr)
1252 {
1253 lock (_characters)
1254 {
1255 if (_characters.Contains(chr))
1256 {
1257 _characters.Remove(chr);
1258 }
1259 }
1260 }
1261
1262 public void BadCharacter(OdeCharacter chr)
1263 {
1264 lock (_badCharacter)
1265 {
1266 if (!_badCharacter.Contains(chr))
1267 _badCharacter.Add(chr);
1268 }
1269 }
1270
1271 public override void RemoveAvatar(PhysicsActor actor)
1272 {
1273 //m_log.Debug("[PHYSICS]:ODELOCK");
1274 ((OdeCharacter) actor).Destroy();
1275 }
1276
1277
1278 public void addActivePrim(OdePrim activatePrim)
1279 {
1280 // adds active prim..
1281 lock (_activeprims)
1282 {
1283 if (!_activeprims.Contains(activatePrim))
1284 _activeprims.Add(activatePrim);
1285 }
1286 }
1287
1288 public void addActiveGroups(OdePrim activatePrim)
1289 {
1290 lock (_activegroups)
1291 {
1292 if (!_activegroups.Contains(activatePrim))
1293 _activegroups.Add(activatePrim);
1294 }
1295 }
1296
1297 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1298 PrimitiveBaseShape pbs, bool isphysical, bool isPhantom, byte shapeType, uint localID)
1299 {
1300 OdePrim newPrim;
1301 lock (OdeLock)
1302 {
1303 newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID);
1304 lock (_prims)
1305 _prims.Add(newPrim);
1306 }
1307 return newPrim;
1308 }
1309
1310 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1311 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, uint localid)
1312 {
1313 return AddPrim(primName, position, size, rotation, pbs, isPhysical, isPhantom, 0 , localid);
1314 }
1315
1316
1317 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1318 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
1319 {
1320 return AddPrim(primName, position, size, rotation, pbs, isPhysical,false, 0, localid);
1321 }
1322
1323 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1324 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid)
1325 {
1326
1327 return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid);
1328 }
1329
1330 public void remActivePrim(OdePrim deactivatePrim)
1331 {
1332 lock (_activeprims)
1333 {
1334 _activeprims.Remove(deactivatePrim);
1335 }
1336 }
1337 public void remActiveGroup(OdePrim deactivatePrim)
1338 {
1339 lock (_activegroups)
1340 {
1341 _activegroups.Remove(deactivatePrim);
1342 }
1343 }
1344
1345 public override void RemovePrim(PhysicsActor prim)
1346 {
1347 // As with all ODE physics operations, we don't remove the prim immediately but signal that it should be
1348 // removed in the next physics simulate pass.
1349 if (prim is OdePrim)
1350 {
1351// lock (OdeLock)
1352 {
1353
1354 OdePrim p = (OdePrim)prim;
1355 p.setPrimForRemoval();
1356 }
1357 }
1358 }
1359
1360 public void RemovePrimThreadLocked(OdePrim prim)
1361 {
1362 //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
1363 lock (prim)
1364 {
1365// RemoveCollisionEventReporting(prim);
1366 lock (_prims)
1367 _prims.Remove(prim);
1368 }
1369
1370 }
1371
1372 public bool havePrim(OdePrim prm)
1373 {
1374 lock (_prims)
1375 return _prims.Contains(prm);
1376 }
1377
1378 public bool haveActor(PhysicsActor actor)
1379 {
1380 if (actor is OdePrim)
1381 {
1382 lock (_prims)
1383 return _prims.Contains((OdePrim)actor);
1384 }
1385 else if (actor is OdeCharacter)
1386 {
1387 lock (_characters)
1388 return _characters.Contains((OdeCharacter)actor);
1389 }
1390 return false;
1391 }
1392
1393 #endregion
1394
1395 #region Space Separation Calculation
1396
1397 /// <summary>
1398 /// Called when a static prim moves or becomes static
1399 /// Places the prim in a space one the static sub-spaces grid
1400 /// </summary>
1401 /// <param name="geom">the pointer to the geom that moved</param>
1402 /// <param name="pos">the position that the geom moved to</param>
1403 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
1404 /// <returns>a pointer to the new space it's in</returns>
1405 public IntPtr MoveGeomToStaticSpace(IntPtr geom, Vector3 pos, IntPtr currentspace)
1406 {
1407 // moves a prim into another static sub-space or from another space into a static sub-space
1408
1409 // Called ODEPrim so
1410 // it's already in locked space.
1411
1412 if (geom == IntPtr.Zero) // shouldn't happen
1413 return IntPtr.Zero;
1414
1415 // get the static sub-space for current position
1416 IntPtr newspace = calculateSpaceForGeom(pos);
1417
1418 if (newspace == currentspace) // if we are there all done
1419 return newspace;
1420
1421 // else remove it from its current space
1422 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom))
1423 {
1424 if (d.GeomIsSpace(currentspace))
1425 {
1426 waitForSpaceUnlock(currentspace);
1427 d.SpaceRemove(currentspace, geom);
1428
1429 if (d.SpaceGetSublevel(currentspace) > 2 && d.SpaceGetNumGeoms(currentspace) == 0)
1430 {
1431 d.SpaceDestroy(currentspace);
1432 }
1433 }
1434 else
1435 {
1436 m_log.Info("[Physics]: Invalid or empty Space passed to 'MoveGeomToStaticSpace':" + currentspace +
1437 " Geom:" + geom);
1438 }
1439 }
1440 else // odd currentspace is null or doesn't contain the geom? lets try the geom ideia of current space
1441 {
1442 currentspace = d.GeomGetSpace(geom);
1443 if (currentspace != IntPtr.Zero)
1444 {
1445 if (d.GeomIsSpace(currentspace))
1446 {
1447 waitForSpaceUnlock(currentspace);
1448 d.SpaceRemove(currentspace, geom);
1449
1450 if (d.SpaceGetSublevel(currentspace) > 2 && d.SpaceGetNumGeoms(currentspace) == 0)
1451 {
1452 d.SpaceDestroy(currentspace);
1453 }
1454
1455 }
1456 }
1457 }
1458
1459 // put the geom in the newspace
1460 waitForSpaceUnlock(newspace);
1461 d.SpaceAdd(newspace, geom);
1462
1463 // let caller know this newspace
1464 return newspace;
1465 }
1466
1467 /// <summary>
1468 /// Calculates the space the prim should be in by its position
1469 /// </summary>
1470 /// <param name="pos"></param>
1471 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
1472 public IntPtr calculateSpaceForGeom(Vector3 pos)
1473 {
1474 int x, y;
1475
1476 if (pos.X < 0)
1477 return staticPrimspaceOffRegion[0];
1478
1479 if (pos.Y < 0)
1480 return staticPrimspaceOffRegion[2];
1481
1482 x = (int)(pos.X * spacesPerMeterX);
1483 if (x > spaceGridMaxX)
1484 return staticPrimspaceOffRegion[1];
1485
1486 y = (int)(pos.Y * spacesPerMeterY);
1487 if (y > spaceGridMaxY)
1488 return staticPrimspaceOffRegion[3];
1489
1490 return staticPrimspace[x, y];
1491 }
1492
1493 #endregion
1494
1495
1496 /// <summary>
1497 /// Called to queue a change to a actor
1498 /// to use in place of old taint mechanism so changes do have a time sequence
1499 /// </summary>
1500
1501 public void AddChange(PhysicsActor actor, changes what, Object arg)
1502 {
1503 ODEchangeitem item = new ODEchangeitem();
1504 item.actor = actor;
1505 item.what = what;
1506 item.arg = arg;
1507 ChangesQueue.Enqueue(item);
1508 }
1509
1510 /// <summary>
1511 /// Called after our prim properties are set Scale, position etc.
1512 /// We use this event queue like method to keep changes to the physical scene occuring in the threadlocked mutex
1513 /// This assures us that we have no race conditions
1514 /// </summary>
1515 /// <param name="prim"></param>
1516 public override void AddPhysicsActorTaint(PhysicsActor prim)
1517 {
1518 }
1519
1520 // does all pending changes generated during region load process
1521 public override void PrepareSimulation()
1522 {
1523 lock (OdeLock)
1524 {
1525 if (world == IntPtr.Zero)
1526 {
1527 ChangesQueue.Clear();
1528 return;
1529 }
1530
1531 ODEchangeitem item;
1532
1533 int donechanges = 0;
1534 if (ChangesQueue.Count > 0)
1535 {
1536 m_log.InfoFormat("[ODE] start processing pending actor operations");
1537 int tstart = Util.EnvironmentTickCount();
1538
1539 while (ChangesQueue.Dequeue(out item))
1540 {
1541 if (item.actor != null)
1542 {
1543 try
1544 {
1545 if (item.actor is OdeCharacter)
1546 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1547 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1548 RemovePrimThreadLocked((OdePrim)item.actor);
1549 }
1550 catch
1551 {
1552 m_log.WarnFormat("[PHYSICS]: Operation failed for a actor {0} {1}",
1553 item.actor.Name, item.what.ToString());
1554 }
1555 }
1556 donechanges++;
1557 }
1558 int time = Util.EnvironmentTickCountSubtract(tstart);
1559 m_log.InfoFormat("[ODE] finished {0} operations in {1}ms", donechanges, time);
1560 }
1561 }
1562 }
1563
1564 /// <summary>
1565 /// This is our main simulate loop
1566 /// It's thread locked by a Mutex in the scene.
1567 /// It holds Collisions, it instructs ODE to step through the physical reactions
1568 /// It moves the objects around in memory
1569 /// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
1570 /// </summary>
1571 /// <param name="timeStep"></param>
1572 /// <returns></returns>
1573 public override float Simulate(float timeStep)
1574 {
1575 DateTime now = DateTime.UtcNow;
1576 TimeSpan timedif = now - m_lastframe;
1577 timeStep = (float)timedif.TotalSeconds;
1578 m_lastframe = now;
1579
1580 // acumulate time so we can reduce error
1581 step_time += timeStep;
1582
1583 if (step_time < HalfOdeStep)
1584 return 0;
1585
1586 if (framecount < 0)
1587 framecount = 0;
1588
1589 framecount++;
1590
1591// int curphysiteractions;
1592
1593 // if in trouble reduce step resolution
1594// if (step_time >= m_SkipFramesAtms)
1595// curphysiteractions = m_physicsiterations / 2;
1596// else
1597// curphysiteractions = m_physicsiterations;
1598
1599// checkThread();
1600 int nodeframes = 0;
1601
1602 lock (SimulationLock)
1603 lock(OdeLock)
1604 {
1605 if (world == IntPtr.Zero)
1606 {
1607 ChangesQueue.Clear();
1608 return 0;
1609 }
1610
1611 ODEchangeitem item;
1612
1613// d.WorldSetQuickStepNumIterations(world, curphysiteractions);
1614
1615 int loopstartMS = Util.EnvironmentTickCount();
1616 int looptimeMS = 0;
1617
1618
1619 while (step_time > HalfOdeStep)
1620 {
1621 try
1622 {
1623 // clear pointer/counter to contacts to pass into joints
1624 m_global_contactcount = 0;
1625
1626 if (ChangesQueue.Count > 0)
1627 {
1628 int changestartMS = Util.EnvironmentTickCount();
1629 int ttmp;
1630 while (ChangesQueue.Dequeue(out item))
1631 {
1632 if (item.actor != null)
1633 {
1634 try
1635 {
1636 if (item.actor is OdeCharacter)
1637 ((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
1638 else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
1639 RemovePrimThreadLocked((OdePrim)item.actor);
1640 }
1641 catch
1642 {
1643 m_log.WarnFormat("[PHYSICS]: doChange failed for a actor {0} {1}",
1644 item.actor.Name, item.what.ToString());
1645 }
1646 }
1647 ttmp = Util.EnvironmentTickCountSubtract(changestartMS);
1648 if (ttmp > 20)
1649 break;
1650 }
1651 }
1652
1653 // Move characters
1654 lock (_characters)
1655 {
1656 List<OdeCharacter> defects = new List<OdeCharacter>();
1657 foreach (OdeCharacter actor in _characters)
1658 {
1659 if (actor != null)
1660 actor.Move(defects);
1661 }
1662 if (defects.Count != 0)
1663 {
1664 foreach (OdeCharacter defect in defects)
1665 {
1666 RemoveCharacter(defect);
1667 }
1668 defects.Clear();
1669 }
1670 }
1671
1672 // Move other active objects
1673 lock (_activegroups)
1674 {
1675 foreach (OdePrim aprim in _activegroups)
1676 {
1677 aprim.Move();
1678 }
1679 }
1680
1681 m_rayCastManager.ProcessQueuedRequests();
1682
1683 collision_optimized();
1684
1685 foreach (PhysicsActor obj in _collisionEventPrim)
1686 {
1687 if (obj == null)
1688 continue;
1689
1690 switch ((ActorTypes)obj.PhysicsActorType)
1691 {
1692 case ActorTypes.Agent:
1693 OdeCharacter cobj = (OdeCharacter)obj;
1694 cobj.AddCollisionFrameTime((int)(odetimestepMS));
1695 cobj.SendCollisions();
1696 break;
1697
1698 case ActorTypes.Prim:
1699 OdePrim pobj = (OdePrim)obj;
1700 if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds))
1701 if (!pobj.m_outbounds)
1702 {
1703 pobj.AddCollisionFrameTime((int)(odetimestepMS));
1704 pobj.SendCollisions();
1705 }
1706 break;
1707 }
1708 }
1709
1710 foreach (PhysicsActor obj in _collisionEventPrimRemove)
1711 _collisionEventPrim.Remove(obj);
1712
1713 _collisionEventPrimRemove.Clear();
1714
1715 // do a ode simulation step
1716 d.WorldQuickStep(world, ODE_STEPSIZE);
1717// d.WorldStep(world, ODE_STEPSIZE);
1718 d.JointGroupEmpty(contactgroup);
1719
1720 // update managed ideia of physical data and do updates to core
1721 /*
1722 lock (_characters)
1723 {
1724 foreach (OdeCharacter actor in _characters)
1725 {
1726 if (actor != null)
1727 {
1728 if (actor.bad)
1729 m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid);
1730
1731 actor.UpdatePositionAndVelocity();
1732 }
1733 }
1734 }
1735 */
1736
1737 lock (_activegroups)
1738 {
1739 {
1740 foreach (OdePrim actor in _activegroups)
1741 {
1742 if (actor.IsPhysical)
1743 {
1744 actor.UpdatePositionAndVelocity(framecount);
1745 }
1746 }
1747 }
1748 }
1749 }
1750 catch (Exception e)
1751 {
1752 m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e);
1753// ode.dunlock(world);
1754 }
1755
1756 step_time -= ODE_STEPSIZE;
1757 nodeframes++;
1758
1759 looptimeMS = Util.EnvironmentTickCountSubtract(loopstartMS);
1760 if (looptimeMS > 100)
1761 break;
1762 }
1763
1764 lock (_badCharacter)
1765 {
1766 if (_badCharacter.Count > 0)
1767 {
1768 foreach (OdeCharacter chr in _badCharacter)
1769 {
1770 RemoveCharacter(chr);
1771 }
1772
1773 _badCharacter.Clear();
1774 }
1775 }
1776
1777 timedif = now - m_lastMeshExpire;
1778
1779 if (timedif.Seconds > 10)
1780 {
1781 mesher.ExpireReleaseMeshs();
1782 m_lastMeshExpire = now;
1783 }
1784
1785// information block running in debug only
1786/*
1787 int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
1788 int ntopstaticgeoms = d.SpaceGetNumGeoms(StaticSpace);
1789 int ngroundgeoms = d.SpaceGetNumGeoms(GroundSpace);
1790
1791 int nactivegeoms = 0;
1792 int nactivespaces = 0;
1793
1794 int nstaticgeoms = 0;
1795 int nstaticspaces = 0;
1796 IntPtr sp;
1797
1798 for (int i = 0; i < ntopactivegeoms; i++)
1799 {
1800 sp = d.SpaceGetGeom(ActiveSpace, i);
1801 if (d.GeomIsSpace(sp))
1802 {
1803 nactivespaces++;
1804 nactivegeoms += d.SpaceGetNumGeoms(sp);
1805 }
1806 else
1807 nactivegeoms++;
1808 }
1809
1810 for (int i = 0; i < ntopstaticgeoms; i++)
1811 {
1812 sp = d.SpaceGetGeom(StaticSpace, i);
1813 if (d.GeomIsSpace(sp))
1814 {
1815 nstaticspaces++;
1816 nstaticgeoms += d.SpaceGetNumGeoms(sp);
1817 }
1818 else
1819 nstaticgeoms++;
1820 }
1821
1822 int ntopgeoms = d.SpaceGetNumGeoms(TopSpace);
1823
1824 int totgeoms = nstaticgeoms + nactivegeoms + ngroundgeoms + 1; // one ray
1825 int nbodies = d.NTotalBodies;
1826 int ngeoms = d.NTotalGeoms;
1827*/
1828 // Finished with all sim stepping. If requested, dump world state to file for debugging.
1829 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
1830 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
1831 if (physics_logging && (physics_logging_interval > 0) && (framecount % physics_logging_interval == 0))
1832 {
1833 string fname = "state-" + world.ToString() + ".DIF"; // give each physics world a separate filename
1834 string prefix = "world" + world.ToString(); // prefix for variable names in exported .DIF file
1835
1836 if (physics_logging_append_existing_logfile)
1837 {
1838 string header = "-------------- START OF PHYSICS FRAME " + framecount.ToString() + " --------------";
1839 TextWriter fwriter = File.AppendText(fname);
1840 fwriter.WriteLine(header);
1841 fwriter.Close();
1842 }
1843
1844 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
1845 }
1846
1847 // think time dilation as to do with dinamic step size that we dont' have
1848 // even so tell something to world
1849 if (looptimeMS < 100) // we did the requested loops
1850 m_timeDilation = 1.0f;
1851 else if (step_time > 0)
1852 {
1853 m_timeDilation = timeStep / step_time;
1854 if (m_timeDilation > 1)
1855 m_timeDilation = 1;
1856 if (step_time > m_SkipFramesAtms)
1857 step_time = 0;
1858 m_lastframe = DateTime.UtcNow; // skip also the time lost
1859 }
1860 }
1861
1862// return nodeframes * ODE_STEPSIZE; // return real simulated time
1863 return 1000 * nodeframes; // return steps for now * 1000 to keep core happy
1864 }
1865
1866 /// <summary>
1867 public override void GetResults()
1868 {
1869 }
1870
1871 public override bool IsThreaded
1872 {
1873 // for now we won't be multithreaded
1874 get { return (false); }
1875 }
1876
1877 public float GetTerrainHeightAtXY(float x, float y)
1878 {
1879
1880 int offsetX = 0;
1881 int offsetY = 0;
1882
1883 if (m_suportCombine)
1884 {
1885 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1886 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1887 }
1888
1889 // get region map
1890 IntPtr heightFieldGeom = IntPtr.Zero;
1891 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom))
1892 return 0f;
1893
1894 if (heightFieldGeom == IntPtr.Zero)
1895 return 0f;
1896
1897 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
1898 return 0f;
1899
1900 // TerrainHeightField for ODE as offset 1m
1901 x += 1f - offsetX;
1902 y += 1f - offsetY;
1903
1904 // make position fit into array
1905 if (x < 0)
1906 x = 0;
1907 if (y < 0)
1908 y = 0;
1909
1910 // integer indexs
1911 int ix;
1912 int iy;
1913 // interpolators offset
1914 float dx;
1915 float dy;
1916
1917 int regsizeX = (int)m_regionWidth + 3; // map size see setterrain number of samples
1918 int regsizeY = (int)m_regionHeight + 3; // map size see setterrain number of samples
1919 int regsize = regsizeX;
1920
1921 if (OdeUbitLib)
1922 {
1923 if (x < regsizeX - 1)
1924 {
1925 ix = (int)x;
1926 dx = x - (float)ix;
1927 }
1928 else // out world use external height
1929 {
1930 ix = regsizeX - 2;
1931 dx = 0;
1932 }
1933 if (y < regsizeY - 1)
1934 {
1935 iy = (int)y;
1936 dy = y - (float)iy;
1937 }
1938 else
1939 {
1940 iy = regsizeY - 2;
1941 dy = 0;
1942 }
1943 }
1944 else
1945 {
1946 // we still have square fixed size regions
1947 // also flip x and y because of how map is done for ODE fliped axis
1948 // so ix,iy,dx and dy are inter exchanged
1949
1950 regsize = regsizeY;
1951
1952 if (x < regsizeX - 1)
1953 {
1954 iy = (int)x;
1955 dy = x - (float)iy;
1956 }
1957 else // out world use external height
1958 {
1959 iy = regsizeX - 2;
1960 dy = 0;
1961 }
1962 if (y < regsizeY - 1)
1963 {
1964 ix = (int)y;
1965 dx = y - (float)ix;
1966 }
1967 else
1968 {
1969 ix = regsizeY - 2;
1970 dx = 0;
1971 }
1972 }
1973
1974 float h0;
1975 float h1;
1976 float h2;
1977
1978 iy *= regsize;
1979 iy += ix; // all indexes have iy + ix
1980
1981 float[] heights = TerrainHeightFieldHeights[heightFieldGeom];
1982 /*
1983 if ((dx + dy) <= 1.0f)
1984 {
1985 h0 = ((float)heights[iy]); // 0,0 vertice
1986 h1 = (((float)heights[iy + 1]) - h0) * dx; // 1,0 vertice minus 0,0
1987 h2 = (((float)heights[iy + regsize]) - h0) * dy; // 0,1 vertice minus 0,0
1988 }
1989 else
1990 {
1991 h0 = ((float)heights[iy + regsize + 1]); // 1,1 vertice
1992 h1 = (((float)heights[iy + 1]) - h0) * (1 - dy); // 1,1 vertice minus 1,0
1993 h2 = (((float)heights[iy + regsize]) - h0) * (1 - dx); // 1,1 vertice minus 0,1
1994 }
1995 */
1996 h0 = ((float)heights[iy]); // 0,0 vertice
1997
1998 if (dy>dx)
1999 {
2000 iy += regsize;
2001 h2 = (float)heights[iy]; // 0,1 vertice
2002 h1 = (h2 - h0) * dy; // 0,1 vertice minus 0,0
2003 h2 = ((float)heights[iy + 1] - h2) * dx; // 1,1 vertice minus 0,1
2004 }
2005 else
2006 {
2007 iy++;
2008 h2 = (float)heights[iy]; // vertice 1,0
2009 h1 = (h2 - h0) * dx; // 1,0 vertice minus 0,0
2010 h2 = (((float)heights[iy + regsize]) - h2) * dy; // 1,1 vertice minus 1,0
2011 }
2012
2013 return h0 + h1 + h2;
2014 }
2015
2016 public Vector3 GetTerrainNormalAtXY(float x, float y)
2017 {
2018 int offsetX = 0;
2019 int offsetY = 0;
2020
2021 if (m_suportCombine)
2022 {
2023 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2024 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2025 }
2026
2027 // get region map
2028 IntPtr heightFieldGeom = IntPtr.Zero;
2029 Vector3 norm = new Vector3(0, 0, 1);
2030
2031 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom))
2032 return norm; ;
2033
2034 if (heightFieldGeom == IntPtr.Zero)
2035 return norm;
2036
2037 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
2038 return norm;
2039
2040 // TerrainHeightField for ODE as offset 1m
2041 x += 1f - offsetX;
2042 y += 1f - offsetY;
2043
2044 // make position fit into array
2045 if (x < 0)
2046 x = 0;
2047 if (y < 0)
2048 y = 0;
2049
2050 // integer indexs
2051 int ix;
2052 int iy;
2053 // interpolators offset
2054 float dx;
2055 float dy;
2056
2057 int regsizeX = (int)m_regionWidth + 3; // map size see setterrain number of samples
2058 int regsizeY = (int)m_regionHeight + 3; // map size see setterrain number of samples
2059 int regsize = regsizeX;
2060
2061 int xstep = 1;
2062 int ystep = regsizeX;
2063 bool firstTri = false;
2064
2065 if (OdeUbitLib)
2066 {
2067 if (x < regsizeX - 1)
2068 {
2069 ix = (int)x;
2070 dx = x - (float)ix;
2071 }
2072 else // out world use external height
2073 {
2074 ix = regsizeX - 2;
2075 dx = 0;
2076 }
2077 if (y < regsizeY - 1)
2078 {
2079 iy = (int)y;
2080 dy = y - (float)iy;
2081 }
2082 else
2083 {
2084 iy = regsizeY - 2;
2085 dy = 0;
2086 }
2087 firstTri = dy > dx;
2088 }
2089
2090 else
2091 {
2092 xstep = regsizeY;
2093 ystep = 1;
2094 regsize = regsizeY;
2095
2096 // we still have square fixed size regions
2097 // also flip x and y because of how map is done for ODE fliped axis
2098 // so ix,iy,dx and dy are inter exchanged
2099 if (x < regsizeX - 1)
2100 {
2101 iy = (int)x;
2102 dy = x - (float)iy;
2103 }
2104 else // out world use external height
2105 {
2106 iy = regsizeX - 2;
2107 dy = 0;
2108 }
2109 if (y < regsizeY - 1)
2110 {
2111 ix = (int)y;
2112 dx = y - (float)ix;
2113 }
2114 else
2115 {
2116 ix = regsizeY - 2;
2117 dx = 0;
2118 }
2119 firstTri = dx > dy;
2120 }
2121
2122 float h0;
2123 float h1;
2124 float h2;
2125
2126 iy *= regsize;
2127 iy += ix; // all indexes have iy + ix
2128
2129 float[] heights = TerrainHeightFieldHeights[heightFieldGeom];
2130
2131 if (firstTri)
2132 {
2133 h1 = ((float)heights[iy]); // 0,0 vertice
2134 iy += ystep;
2135 h0 = (float)heights[iy]; // 0,1
2136 h2 = (float)heights[iy+xstep]; // 1,1 vertice
2137 norm.X = h0 - h2;
2138 norm.Y = h1 - h0;
2139 }
2140 else
2141 {
2142 h2 = ((float)heights[iy]); // 0,0 vertice
2143 iy += xstep;
2144 h0 = ((float)heights[iy]); // 1,0 vertice
2145 h1 = (float)heights[iy+ystep]; // vertice 1,1
2146 norm.X = h2 - h0;
2147 norm.Y = h0 - h1;
2148 }
2149 norm.Z = 1;
2150 norm.Normalize();
2151 return norm;
2152 }
2153
2154 public override void SetTerrain(float[] heightMap)
2155 {
2156 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
2157 {
2158 if (m_parentScene is OdeScene)
2159 {
2160 ((OdeScene)m_parentScene).SetTerrain(heightMap, m_worldOffset);
2161 }
2162 }
2163 else
2164 {
2165 SetTerrain(heightMap, m_worldOffset);
2166 }
2167 }
2168
2169 public override void CombineTerrain(float[] heightMap, Vector3 pOffset)
2170 {
2171 if(m_suportCombine)
2172 SetTerrain(heightMap, pOffset);
2173 }
2174
2175 public void SetTerrain(float[] heightMap, Vector3 pOffset)
2176 {
2177 if (OdeUbitLib)
2178 UbitSetTerrain(heightMap, pOffset);
2179 else
2180 OriSetTerrain(heightMap, pOffset);
2181 }
2182
2183 public void OriSetTerrain(float[] heightMap, Vector3 pOffset)
2184 {
2185 // assumes 1m size grid and constante size square regions
2186 // needs to know about sims around in future
2187
2188 float[] _heightmap;
2189
2190 uint regionsizeX = m_regionWidth;
2191 uint regionsizeY = m_regionHeight;
2192
2193 // map is rotated
2194 uint heightmapWidth = regionsizeY + 2;
2195 uint heightmapHeight = regionsizeX + 2;
2196
2197 uint heightmapWidthSamples = heightmapWidth + 1;
2198 uint heightmapHeightSamples = heightmapHeight + 1;
2199
2200 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples];
2201
2202 const float scale = 1.0f;
2203 const float offset = 0.0f;
2204 const float thickness = 10f;
2205 const int wrap = 0;
2206
2207
2208 float hfmin = float.MaxValue;
2209 float hfmax = float.MinValue;
2210 float val;
2211 uint xx;
2212 uint yy;
2213
2214 uint maxXX = regionsizeX - 1;
2215 uint maxYY = regionsizeY - 1;
2216 // flipping map adding one margin all around so things don't fall in edges
2217
2218 uint xt = 0;
2219 xx = 0;
2220
2221 for (uint x = 0; x < heightmapWidthSamples; x++)
2222 {
2223 if (x > 1 && xx < maxXX)
2224 xx++;
2225 yy = 0;
2226 for (uint y = 0; y < heightmapHeightSamples; y++)
2227 {
2228 if (y > 1 && y < maxYY)
2229 yy += regionsizeX;
2230
2231 val = heightMap[yy + xx];
2232 if (val < 0.0f)
2233 val = 0.0f; // no neg terrain as in chode
2234 _heightmap[xt + y] = val;
2235
2236 if (hfmin > val)
2237 hfmin = val;
2238 if (hfmax < val)
2239 hfmax = val;
2240 }
2241 xt += heightmapHeightSamples;
2242 }
2243
2244 lock (OdeLock)
2245 {
2246 IntPtr GroundGeom = IntPtr.Zero;
2247 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2248 {
2249 RegionTerrain.Remove(pOffset);
2250 if (GroundGeom != IntPtr.Zero)
2251 {
2252 actor_name_map.Remove(GroundGeom);
2253 d.GeomDestroy(GroundGeom);
2254
2255 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2256 {
2257 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2258 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2259 TerrainHeightFieldHeights.Remove(GroundGeom);
2260 }
2261 }
2262 }
2263 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2264
2265 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2266
2267 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, heightmapWidth , heightmapHeight,
2268 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2269 offset, thickness, wrap);
2270
2271 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2272
2273 GroundGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1);
2274
2275 if (GroundGeom != IntPtr.Zero)
2276 {
2277 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
2278 d.GeomSetCollideBits(GroundGeom, 0);
2279
2280 PhysicsActor pa = new NullPhysicsActor();
2281 pa.Name = "Terrain";
2282 pa.PhysicsActorType = (int)ActorTypes.Ground;
2283 actor_name_map[GroundGeom] = pa;
2284
2285// geom_name_map[GroundGeom] = "Terrain";
2286
2287 d.Matrix3 R = new d.Matrix3();
2288
2289 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2290 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2291
2292
2293 q1 = q1 * q2;
2294
2295 Vector3 v3;
2296 float angle;
2297 q1.GetAxisAngle(out v3, out angle);
2298
2299 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2300 d.GeomSetRotation(GroundGeom, ref R);
2301 d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0);
2302 RegionTerrain.Add(pOffset, GroundGeom);
2303 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2304 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2305 }
2306 }
2307 }
2308
2309 public void UbitSetTerrain(float[] heightMap, Vector3 pOffset)
2310 {
2311 // assumes 1m size grid and constante size square regions
2312 // needs to know about sims around in future
2313
2314 float[] _heightmap;
2315
2316 uint regionsizeX = m_regionWidth;
2317 uint regionsizeY = m_regionHeight;
2318
2319 uint heightmapWidth = regionsizeX + 2;
2320 uint heightmapHeight = regionsizeY + 2;
2321
2322 uint heightmapWidthSamples = heightmapWidth + 1;
2323 uint heightmapHeightSamples = heightmapHeight + 1;
2324
2325 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples];
2326
2327
2328 float hfmin = float.MaxValue;
2329// float hfmax = float.MinValue;
2330 float val;
2331
2332
2333 uint maxXX = regionsizeX - 1;
2334 uint maxYY = regionsizeY - 1;
2335 // adding one margin all around so things don't fall in edges
2336
2337 uint xx;
2338 uint yy = 0;
2339 uint yt = 0;
2340
2341 for (uint y = 0; y < heightmapHeightSamples; y++)
2342 {
2343 if (y > 1 && y < maxYY)
2344 yy += regionsizeX;
2345 xx = 0;
2346 for (uint x = 0; x < heightmapWidthSamples; x++)
2347 {
2348 if (x > 1 && x < maxXX)
2349 xx++;
2350
2351 val = heightMap[yy + xx];
2352 if (val < 0.0f)
2353 val = 0.0f; // no neg terrain as in chode
2354 _heightmap[yt + x] = val;
2355
2356 if (hfmin > val)
2357 hfmin = val;
2358// if (hfmax < val)
2359// hfmax = val;
2360 }
2361 yt += heightmapWidthSamples;
2362 }
2363 lock (OdeLock)
2364 {
2365 IntPtr GroundGeom = IntPtr.Zero;
2366 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2367 {
2368 RegionTerrain.Remove(pOffset);
2369 if (GroundGeom != IntPtr.Zero)
2370 {
2371 actor_name_map.Remove(GroundGeom);
2372 d.GeomDestroy(GroundGeom);
2373
2374 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2375 {
2376 if (TerrainHeightFieldHeightsHandlers[GroundGeom].IsAllocated)
2377 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2378 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2379 TerrainHeightFieldHeights.Remove(GroundGeom);
2380 }
2381 }
2382 }
2383 IntPtr HeightmapData = d.GeomUbitTerrainDataCreate();
2384
2385 const int wrap = 0;
2386 float thickness = hfmin;
2387 if (thickness < 0)
2388 thickness = 1;
2389
2390 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2391
2392 d.GeomUbitTerrainDataBuild(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, 1.0f,
2393 (int)heightmapWidthSamples, (int)heightmapHeightSamples,
2394 thickness, wrap);
2395
2396// d.GeomUbitTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2397 GroundGeom = d.CreateUbitTerrain(GroundSpace, HeightmapData, 1);
2398 if (GroundGeom != IntPtr.Zero)
2399 {
2400 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
2401 d.GeomSetCollideBits(GroundGeom, 0);
2402
2403
2404 PhysicsActor pa = new NullPhysicsActor();
2405 pa.Name = "Terrain";
2406 pa.PhysicsActorType = (int)ActorTypes.Ground;
2407 actor_name_map[GroundGeom] = pa;
2408
2409// geom_name_map[GroundGeom] = "Terrain";
2410
2411 d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0);
2412 RegionTerrain.Add(pOffset, GroundGeom);
2413 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2414 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2415 }
2416 }
2417 }
2418
2419
2420 public override void DeleteTerrain()
2421 {
2422 }
2423
2424 public float GetWaterLevel()
2425 {
2426 return waterlevel;
2427 }
2428
2429 public override bool SupportsCombining()
2430 {
2431 return m_suportCombine;
2432 }
2433/*
2434 public override void UnCombine(PhysicsScene pScene)
2435 {
2436 IntPtr localGround = IntPtr.Zero;
2437// float[] localHeightfield;
2438 bool proceed = false;
2439 List<IntPtr> geomDestroyList = new List<IntPtr>();
2440
2441 lock (OdeLock)
2442 {
2443 if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround))
2444 {
2445 foreach (IntPtr geom in TerrainHeightFieldHeights.Keys)
2446 {
2447 if (geom == localGround)
2448 {
2449// localHeightfield = TerrainHeightFieldHeights[geom];
2450 proceed = true;
2451 }
2452 else
2453 {
2454 geomDestroyList.Add(geom);
2455 }
2456 }
2457
2458 if (proceed)
2459 {
2460 m_worldOffset = Vector3.Zero;
2461 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
2462 m_parentScene = null;
2463
2464 foreach (IntPtr g in geomDestroyList)
2465 {
2466 // removingHeightField needs to be done or the garbage collector will
2467 // collect the terrain data before we tell ODE to destroy it causing
2468 // memory corruption
2469 if (TerrainHeightFieldHeights.ContainsKey(g))
2470 {
2471// float[] removingHeightField = TerrainHeightFieldHeights[g];
2472 TerrainHeightFieldHeights.Remove(g);
2473
2474 if (RegionTerrain.ContainsKey(g))
2475 {
2476 RegionTerrain.Remove(g);
2477 }
2478
2479 d.GeomDestroy(g);
2480 //removingHeightField = new float[0];
2481 }
2482 }
2483
2484 }
2485 else
2486 {
2487 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
2488 }
2489 }
2490 }
2491 }
2492*/
2493 public override void SetWaterLevel(float baseheight)
2494 {
2495 waterlevel = baseheight;
2496 }
2497
2498 public override void Dispose()
2499 {
2500 if (m_meshWorker != null)
2501 m_meshWorker.Stop();
2502
2503 lock (OdeLock)
2504 {
2505 m_rayCastManager.Dispose();
2506 m_rayCastManager = null;
2507
2508 lock (_prims)
2509 {
2510 ChangesQueue.Clear();
2511 foreach (OdePrim prm in _prims)
2512 {
2513 prm.DoAChange(changes.Remove, null);
2514 _collisionEventPrim.Remove(prm);
2515 }
2516 _prims.Clear();
2517 }
2518
2519 OdeCharacter[] chtorem;
2520 lock (_characters)
2521 {
2522 chtorem = new OdeCharacter[_characters.Count];
2523 _characters.CopyTo(chtorem);
2524 }
2525
2526 ChangesQueue.Clear();
2527 foreach (OdeCharacter ch in chtorem)
2528 ch.DoAChange(changes.Remove, null);
2529
2530
2531 foreach (IntPtr GroundGeom in RegionTerrain.Values)
2532 {
2533 if (GroundGeom != IntPtr.Zero)
2534 d.GeomDestroy(GroundGeom);
2535 }
2536
2537
2538 RegionTerrain.Clear();
2539
2540 if (TerrainHeightFieldHeightsHandlers.Count > 0)
2541 {
2542 foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values)
2543 {
2544 if (gch.IsAllocated)
2545 gch.Free();
2546 }
2547 }
2548
2549 TerrainHeightFieldHeightsHandlers.Clear();
2550 TerrainHeightFieldHeights.Clear();
2551
2552 if (ContactgeomsArray != IntPtr.Zero)
2553 Marshal.FreeHGlobal(ContactgeomsArray);
2554 if (GlobalContactsArray != IntPtr.Zero)
2555 Marshal.FreeHGlobal(GlobalContactsArray);
2556
2557
2558 d.WorldDestroy(world);
2559 world = IntPtr.Zero;
2560 //d.CloseODE();
2561 }
2562 }
2563
2564 public override Dictionary<uint, float> GetTopColliders()
2565 {
2566 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
2567 int cnt = 0;
2568 lock (_prims)
2569 {
2570 foreach (OdePrim prm in _prims)
2571 {
2572 if (prm.CollisionScore > 0)
2573 {
2574 returncolliders.Add(prm.LocalID, prm.CollisionScore);
2575 cnt++;
2576 prm.CollisionScore = 0f;
2577 if (cnt > 25)
2578 {
2579 break;
2580 }
2581 }
2582 }
2583 }
2584 return returncolliders;
2585 }
2586
2587 public override bool SupportsRayCast()
2588 {
2589 return true;
2590 }
2591
2592 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2593 {
2594 if (retMethod != null)
2595 {
2596 ODERayRequest req = new ODERayRequest();
2597 req.actor = null;
2598 req.callbackMethod = retMethod;
2599 req.length = length;
2600 req.Normal = direction;
2601 req.Origin = position;
2602 req.Count = 0;
2603 req.filter = RayFilterFlags.AllPrims;
2604
2605 m_rayCastManager.QueueRequest(req);
2606 }
2607 }
2608
2609 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
2610 {
2611 if (retMethod != null)
2612 {
2613 ODERayRequest req = new ODERayRequest();
2614 req.actor = null;
2615 req.callbackMethod = retMethod;
2616 req.length = length;
2617 req.Normal = direction;
2618 req.Origin = position;
2619 req.Count = Count;
2620 req.filter = RayFilterFlags.AllPrims;
2621
2622 m_rayCastManager.QueueRequest(req);
2623 }
2624 }
2625
2626
2627 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
2628 {
2629 List<ContactResult> ourresults = new List<ContactResult>();
2630 object SyncObject = new object();
2631
2632 RayCallback retMethod = delegate(List<ContactResult> results)
2633 {
2634 lock (SyncObject)
2635 {
2636 ourresults = results;
2637 Monitor.PulseAll(SyncObject);
2638 }
2639 };
2640
2641 ODERayRequest req = new ODERayRequest();
2642 req.actor = null;
2643 req.callbackMethod = retMethod;
2644 req.length = length;
2645 req.Normal = direction;
2646 req.Origin = position;
2647 req.Count = Count;
2648 req.filter = RayFilterFlags.AllPrims;
2649
2650 lock (SyncObject)
2651 {
2652 m_rayCastManager.QueueRequest(req);
2653 if (!Monitor.Wait(SyncObject, 500))
2654 return null;
2655 else
2656 return ourresults;
2657 }
2658 }
2659
2660 public override bool SupportsRaycastWorldFiltered()
2661 {
2662 return true;
2663 }
2664
2665 public override object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2666 {
2667 object SyncObject = new object();
2668 List<ContactResult> ourresults = new List<ContactResult>();
2669
2670 RayCallback retMethod = delegate(List<ContactResult> results)
2671 {
2672 lock (SyncObject)
2673 {
2674 ourresults = results;
2675 Monitor.PulseAll(SyncObject);
2676 }
2677 };
2678
2679 ODERayRequest req = new ODERayRequest();
2680 req.actor = null;
2681 req.callbackMethod = retMethod;
2682 req.length = length;
2683 req.Normal = direction;
2684 req.Origin = position;
2685 req.Count = Count;
2686 req.filter = filter;
2687
2688 lock (SyncObject)
2689 {
2690 m_rayCastManager.QueueRequest(req);
2691 if (!Monitor.Wait(SyncObject, 500))
2692 return null;
2693 else
2694 return ourresults;
2695 }
2696 }
2697
2698 public override List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags flags)
2699 {
2700 if (actor == null)
2701 return new List<ContactResult>();
2702
2703 IntPtr geom;
2704 if (actor is OdePrim)
2705 geom = ((OdePrim)actor).prim_geom;
2706 else if (actor is OdeCharacter)
2707 geom = ((OdePrim)actor).prim_geom;
2708 else
2709 return new List<ContactResult>();
2710
2711 if (geom == IntPtr.Zero)
2712 return new List<ContactResult>();
2713
2714 List<ContactResult> ourResults = null;
2715 object SyncObject = new object();
2716
2717 RayCallback retMethod = delegate(List<ContactResult> results)
2718 {
2719 lock (SyncObject)
2720 {
2721 ourResults = results;
2722 Monitor.PulseAll(SyncObject);
2723 }
2724 };
2725
2726 ODERayRequest req = new ODERayRequest();
2727 req.actor = actor;
2728 req.callbackMethod = retMethod;
2729 req.length = length;
2730 req.Normal = direction;
2731 req.Origin = position;
2732 req.Count = Count;
2733 req.filter = flags;
2734
2735 lock (SyncObject)
2736 {
2737 m_rayCastManager.QueueRequest(req);
2738 if (!Monitor.Wait(SyncObject, 500))
2739 return new List<ContactResult>();
2740 }
2741
2742 if (ourResults == null)
2743 return new List<ContactResult>();
2744 return ourResults;
2745 }
2746
2747 public override List<ContactResult> BoxProbe(Vector3 position, Vector3 size, Quaternion orientation, int Count, RayFilterFlags flags)
2748 {
2749 List<ContactResult> ourResults = null;
2750 object SyncObject = new object();
2751
2752 ProbeBoxCallback retMethod = delegate(List<ContactResult> results)
2753 {
2754 lock (SyncObject)
2755 {
2756 ourResults = results;
2757 Monitor.PulseAll(SyncObject);
2758 }
2759 };
2760
2761 ODERayRequest req = new ODERayRequest();
2762 req.actor = null;
2763 req.callbackMethod = retMethod;
2764 req.Normal = size;
2765 req.Origin = position;
2766 req.orientation = orientation;
2767 req.Count = Count;
2768 req.filter = flags;
2769
2770 lock (SyncObject)
2771 {
2772 m_rayCastManager.QueueRequest(req);
2773 if (!Monitor.Wait(SyncObject, 500))
2774 return new List<ContactResult>();
2775 }
2776
2777 if (ourResults == null)
2778 return new List<ContactResult>();
2779 return ourResults;
2780 }
2781
2782 public override List<ContactResult> SphereProbe(Vector3 position, float radius, int Count, RayFilterFlags flags)
2783 {
2784 List<ContactResult> ourResults = null;
2785 object SyncObject = new object();
2786
2787 ProbeSphereCallback retMethod = delegate(List<ContactResult> results)
2788 {
2789 ourResults = results;
2790 Monitor.PulseAll(SyncObject);
2791 };
2792
2793 ODERayRequest req = new ODERayRequest();
2794 req.actor = null;
2795 req.callbackMethod = retMethod;
2796 req.length = radius;
2797 req.Origin = position;
2798 req.Count = Count;
2799 req.filter = flags;
2800
2801
2802 lock (SyncObject)
2803 {
2804 m_rayCastManager.QueueRequest(req);
2805 if (!Monitor.Wait(SyncObject, 500))
2806 return new List<ContactResult>();
2807 }
2808
2809 if (ourResults == null)
2810 return new List<ContactResult>();
2811 return ourResults;
2812 }
2813
2814 public override List<ContactResult> PlaneProbe(PhysicsActor actor, Vector4 plane, int Count, RayFilterFlags flags)
2815 {
2816 IntPtr geom = IntPtr.Zero;;
2817
2818 if (actor != null)
2819 {
2820 if (actor is OdePrim)
2821 geom = ((OdePrim)actor).prim_geom;
2822 else if (actor is OdeCharacter)
2823 geom = ((OdePrim)actor).prim_geom;
2824 }
2825
2826 List<ContactResult> ourResults = null;
2827 object SyncObject = new object();
2828
2829 ProbePlaneCallback retMethod = delegate(List<ContactResult> results)
2830 {
2831 ourResults = results;
2832 Monitor.PulseAll(SyncObject);
2833 };
2834
2835 ODERayRequest req = new ODERayRequest();
2836 req.actor = null;
2837 req.callbackMethod = retMethod;
2838 req.length = plane.W;
2839 req.Normal.X = plane.X;
2840 req.Normal.Y = plane.Y;
2841 req.Normal.Z = plane.Z;
2842 req.Count = Count;
2843 req.filter = flags;
2844
2845 lock (SyncObject)
2846 {
2847 m_rayCastManager.QueueRequest(req);
2848 if (!Monitor.Wait(SyncObject, 500))
2849 return new List<ContactResult>();
2850 }
2851
2852 if (ourResults == null)
2853 return new List<ContactResult>();
2854 return ourResults;
2855 }
2856
2857 public override int SitAvatar(PhysicsActor actor, Vector3 AbsolutePosition, Vector3 CameraPosition, Vector3 offset, Vector3 AvatarSize, SitAvatarCallback PhysicsSitResponse)
2858 {
2859 Util.FireAndForget( delegate
2860 {
2861 ODESitAvatar sitAvatar = new ODESitAvatar(this, m_rayCastManager);
2862 if(sitAvatar != null)
2863 sitAvatar.Sit(actor, AbsolutePosition, CameraPosition, offset, AvatarSize, PhysicsSitResponse);
2864 });
2865 return 1;
2866 }
2867
2868 }
2869}
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerLargeLandChannel.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerLargeLandChannel.cs
index 4bf2a82..e5e76e9 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerLargeLandChannel.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerLargeLandChannel.cs
@@ -196,6 +196,7 @@ namespace OpenSim.Region.RegionCombinerModule
196 RootRegionLandChannel.SetParcelOtherCleanTime(remoteClient, localID, otherCleanTime); 196 RootRegionLandChannel.SetParcelOtherCleanTime(remoteClient, localID, otherCleanTime);
197 } 197 }
198 198
199 public void sendClientInitialLandInfo(IClientAPI remoteClient) { }
199 #endregion 200 #endregion
200 } 201 }
201} \ No newline at end of file 202} \ No newline at end of file
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerPermissionModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerPermissionModule.cs
index 07dd68b..ddfe3e0 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerPermissionModule.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerPermissionModule.cs
@@ -105,9 +105,9 @@ namespace OpenSim.Region.RegionCombinerModule
105 return m_rootScene.Permissions.CanEditObject(objectid, editorid); 105 return m_rootScene.Permissions.CanEditObject(objectid, editorid);
106 } 106 }
107 107
108 public bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers g, Scene scene) 108 public bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers g, Scene scene, bool allowManager)
109 { 109 {
110 return m_rootScene.Permissions.CanEditParcelProperties(user, parcel, g); 110 return m_rootScene.Permissions.CanEditParcelProperties(user, parcel, g, allowManager);
111 } 111 }
112 112
113 public bool CanInstantMessage(UUID user, UUID target, Scene startscene) 113 public bool CanInstantMessage(UUID user, UUID target, Scene startscene)
diff --git a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
index 62a3a91..6bf1c4a 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionConnections.cs
@@ -91,4 +91,4 @@ namespace OpenSim.Region.RegionCombinerModule
91 YEnd = (uint)extents.Y; 91 YEnd = (uint)extents.Y;
92 } 92 }
93 } 93 }
94} \ No newline at end of file 94}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
index 036cb5d..df1bd8b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
@@ -28,9 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection;
32using System.Threading; 31using System.Threading;
33using log4net;
34using OpenMetaverse; 32using OpenMetaverse;
35using OpenSim.Framework; 33using OpenSim.Framework;
36using OpenSim.Framework.Monitoring; 34using OpenSim.Framework.Monitoring;
@@ -39,6 +37,8 @@ using OpenSim.Region.ScriptEngine.Interfaces;
39using OpenSim.Region.ScriptEngine.Shared; 37using OpenSim.Region.ScriptEngine.Shared;
40using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 38using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
41using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; 39using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer;
40using System.Reflection;
41using log4net;
42 42
43namespace OpenSim.Region.ScriptEngine.Shared.Api 43namespace OpenSim.Region.ScriptEngine.Shared.Api
44{ 44{
@@ -269,6 +269,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
269 /// <param name="itemID"></param> 269 /// <param name="itemID"></param>
270 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) 270 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
271 { 271 {
272 // Remove a specific script
272// m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); 273// m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID);
273 274
274 lock (staticLock) 275 lock (staticLock)
@@ -282,7 +283,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
282 // Remove from: HttpRequest 283 // Remove from: HttpRequest
283 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); 284 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>();
284 if (iHttpReq != null) 285 if (iHttpReq != null)
285 iHttpReq.StopHttpRequestsForScript(itemID); 286 iHttpReq.StopHttpRequest(localID, itemID);
286 287
287 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); 288 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
288 if (comms != null) 289 if (comms != null)
@@ -386,6 +387,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
386 } 387 }
387 } 388 }
388 389
390 public static void StateChange(IScriptEngine engine, uint localID, UUID itemID)
391 {
392 // Remove a specific script
393
394 // Remove dataserver events
395 m_Dataserver[engine].RemoveEvents(localID, itemID);
396
397 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
398 if (comms != null)
399 comms.DeleteListener(itemID);
400
401 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
402 if (xmlrpc != null)
403 {
404 xmlrpc.DeleteChannels(itemID);
405 xmlrpc.CancelSRDRequests(itemID);
406 }
407
408 // Remove Sensors
409 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
410
411 }
412
389 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 413 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
390 { 414 {
391 List<Object> data = new List<Object>(); 415 List<Object> data = new List<Object>();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
new file mode 100644
index 0000000..fce8ff8
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,117 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Threading;
30using System.Reflection;
31using System.Collections;
32using System.Collections.Generic;
33using System.Runtime.Remoting.Lifetime;
34using OpenMetaverse;
35using Nini.Config;
36using OpenSim;
37using OpenSim.Framework;
38using OpenSim.Region.CoreModules.World.LightShare;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.ScriptEngine.Shared;
42using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
43using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
44using OpenSim.Region.ScriptEngine.Interfaces;
45using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
46using OpenSim.Services.Interfaces;
47
48using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
49using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
50using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
51using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
52using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
53using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
54using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
55
56namespace OpenSim.Region.ScriptEngine.Shared.Api
57{
58 [Serializable]
59 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
60 {
61 internal IScriptEngine m_ScriptEngine;
62 internal SceneObjectPart m_host;
63 internal TaskInventoryItem m_item;
64 internal bool m_CMFunctionsEnabled = false;
65
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
67 {
68 m_ScriptEngine = ScriptEngine;
69 m_host = host;
70 m_item = item;
71
72 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
73 m_CMFunctionsEnabled = true;
74 }
75
76 public override Object InitializeLifetimeService()
77 {
78 ILease lease = (ILease)base.InitializeLifetimeService();
79
80 if (lease.CurrentState == LeaseState.Initial)
81 {
82 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
83 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
84 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
85 }
86 return lease;
87 }
88
89 public Scene World
90 {
91 get { return m_ScriptEngine.World; }
92 }
93
94 public string cmDetectedCountry(int number)
95 {
96 m_host.AddScriptLPS(1);
97 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
98 if (detectedParams == null)
99 return String.Empty;
100 return detectedParams.Country;
101 }
102
103 public string cmGetAgentCountry(LSL_Key key)
104 {
105 if (!World.Permissions.IsGod(m_host.OwnerID))
106 return String.Empty;
107
108 UUID uuid;
109
110 if (!UUID.TryParse(key, out uuid))
111 return String.Empty;
112
113 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
114 return account.UserCountry;
115 }
116 }
117}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 7719f07..f637a1d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -24,21 +24,30 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31<<<<<<< HEAD
31using System.Diagnostics; 32using System.Diagnostics;
32using System.Drawing; 33using System.Drawing;
33using System.Drawing.Imaging; 34using System.Drawing.Imaging;
35=======
36using System.Diagnostics; //for [DebuggerNonUserCode]
37>>>>>>> avn/ubitvar
34using System.Runtime.Remoting.Lifetime; 38using System.Runtime.Remoting.Lifetime;
35using System.Text; 39using System.Text;
36using System.Threading; 40using System.Threading;
37using System.Text.RegularExpressions; 41using System.Text.RegularExpressions;
42using System.Timers;
38using Nini.Config; 43using Nini.Config;
39using log4net; 44using log4net;
40using OpenMetaverse; 45using OpenMetaverse;
46<<<<<<< HEAD
41using OpenMetaverse.Assets; 47using OpenMetaverse.Assets;
48=======
49using OpenMetaverse.StructuredData;
50>>>>>>> avn/ubitvar
42using OpenMetaverse.Packets; 51using OpenMetaverse.Packets;
43using OpenMetaverse.Rendering; 52using OpenMetaverse.Rendering;
44using OpenSim; 53using OpenSim;
@@ -49,6 +58,7 @@ using OpenSim.Region.CoreModules.World.Land;
49using OpenSim.Region.CoreModules.World.Terrain; 58using OpenSim.Region.CoreModules.World.Terrain;
50using OpenSim.Region.Framework.Interfaces; 59using OpenSim.Region.Framework.Interfaces;
51using OpenSim.Region.Framework.Scenes; 60using OpenSim.Region.Framework.Scenes;
61using OpenSim.Region.Framework.Scenes.Serialization;
52using OpenSim.Region.Framework.Scenes.Animation; 62using OpenSim.Region.Framework.Scenes.Animation;
53using OpenSim.Region.Framework.Scenes.Scripting; 63using OpenSim.Region.Framework.Scenes.Scripting;
54using OpenSim.Region.Physics.Manager; 64using OpenSim.Region.Physics.Manager;
@@ -72,6 +82,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
72using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 82using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
73using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 83using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
74using System.Reflection; 84using System.Reflection;
85using Timer = System.Timers.Timer;
75using System.Linq; 86using System.Linq;
76using PermissionMask = OpenSim.Framework.PermissionMask; 87using PermissionMask = OpenSim.Framework.PermissionMask;
77 88
@@ -120,7 +131,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
120 protected int m_notecardLineReadCharsMax = 255; 131 protected int m_notecardLineReadCharsMax = 255;
121 protected int m_scriptConsoleChannel = 0; 132 protected int m_scriptConsoleChannel = 0;
122 protected bool m_scriptConsoleChannelEnabled = false; 133 protected bool m_scriptConsoleChannelEnabled = false;
134 protected bool m_debuggerSafe = false;
123 protected IUrlModule m_UrlModule = null; 135 protected IUrlModule m_UrlModule = null;
136<<<<<<< HEAD
124 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>(); 137 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
125 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. 138 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
126 protected int m_sleepMsOnSetTexture = 200; 139 protected int m_sleepMsOnSetTexture = 200;
@@ -241,6 +254,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
241 protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>(); 254 protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
242 protected bool m_useMeshCacheInCastRay = true; 255 protected bool m_useMeshCacheInCastRay = true;
243 protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>(); 256 protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
257=======
258 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
259 new Dictionary<UUID, UserInfoCacheEntry>();
260 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
261 protected ISoundModule m_SoundModule = null;
262
263// protected Timer m_ShoutSayTimer;
264 protected int m_SayShoutCount = 0;
265 DateTime m_lastSayShoutCheck;
266
267 private Dictionary<string, string> MovementAnimationsForLSL =
268 new Dictionary<string, string> {
269 {"CROUCH", "Crouching"},
270 {"CROUCHWALK", "CrouchWalking"},
271 {"FALLDOWN", "Falling Down"},
272 {"FLY", "Flying"},
273 {"FLYSLOW", "FlyingSlow"},
274 {"HOVER", "Hovering"},
275 {"HOVER_UP", "Hovering Up"},
276 {"HOVER_DOWN", "Hovering Down"},
277 {"JUMP", "Jumping"},
278 {"LAND", "Landing"},
279 {"PREJUMP", "PreJumping"},
280 {"RUN", "Running"},
281 {"SIT","Sitting"},
282 {"SITGROUND","Sitting on Ground"},
283 {"STAND", "Standing"},
284 {"STANDUP", "Standing Up"},
285 {"STRIDE","Striding"},
286 {"SOFT_LAND", "Soft Landing"},
287 {"TURNLEFT", "Turning Left"},
288 {"TURNRIGHT", "Turning Right"},
289 {"WALK", "Walking"}
290 };
291>>>>>>> avn/ubitvar
244 292
245 //An array of HTTP/1.1 headers that are not allowed to be used 293 //An array of HTTP/1.1 headers that are not allowed to be used
246 //as custom headers by llHTTPRequest. 294 //as custom headers by llHTTPRequest.
@@ -262,9 +310,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
262 public void Initialize( 310 public void Initialize(
263 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item) 311 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
264 { 312 {
313 m_lastSayShoutCheck = DateTime.UtcNow;
314
265 m_ScriptEngine = scriptEngine; 315 m_ScriptEngine = scriptEngine;
266 m_host = host; 316 m_host = host;
267 m_item = item; 317 m_item = item;
318<<<<<<< HEAD
319=======
320 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
321 m_coopSleepHandle = coopSleepHandle;
322>>>>>>> avn/ubitvar
268 323
269 LoadConfig(); 324 LoadConfig();
270 325
@@ -422,6 +477,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
422 get { return m_ScriptEngine.World; } 477 get { return m_ScriptEngine.World; }
423 } 478 }
424 479
480 [DebuggerNonUserCode]
425 public void state(string newState) 481 public void state(string newState)
426 { 482 {
427 m_ScriptEngine.SetState(m_item.ItemID, newState); 483 m_ScriptEngine.SetState(m_item.ItemID, newState);
@@ -431,6 +487,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
431 /// Reset the named script. The script must be present 487 /// Reset the named script. The script must be present
432 /// in the same prim. 488 /// in the same prim.
433 /// </summary> 489 /// </summary>
490 [DebuggerNonUserCode]
434 public void llResetScript() 491 public void llResetScript()
435 { 492 {
436 m_host.AddScriptLPS(1); 493 m_host.AddScriptLPS(1);
@@ -493,6 +550,57 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
493 } 550 }
494 } 551 }
495 552
553 public List<ScenePresence> GetLinkAvatars(int linkType)
554 {
555 List<ScenePresence> ret = new List<ScenePresence>();
556 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
557 return ret;
558
559 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
560
561 switch (linkType)
562 {
563 case ScriptBaseClass.LINK_SET:
564 return avs;
565
566 case ScriptBaseClass.LINK_ROOT:
567 return ret;
568
569 case ScriptBaseClass.LINK_ALL_OTHERS:
570 return avs;
571
572 case ScriptBaseClass.LINK_ALL_CHILDREN:
573 return avs;
574
575 case ScriptBaseClass.LINK_THIS:
576 return ret;
577
578 default:
579 if (linkType < 0)
580 return ret;
581
582 int partCount = m_host.ParentGroup.GetPartCount();
583
584 if (linkType <= partCount)
585 {
586 return ret;
587 }
588 else
589 {
590 linkType = linkType - partCount;
591 if (linkType > avs.Count)
592 {
593 return ret;
594 }
595 else
596 {
597 ret.Add(avs[linkType-1]);
598 return ret;
599 }
600 }
601 }
602 }
603
496 /// <summary> 604 /// <summary>
497 /// Get a given link entity from a linkset (linked objects and any sitting avatars). 605 /// Get a given link entity from a linkset (linked objects and any sitting avatars).
498 /// </summary> 606 /// </summary>
@@ -572,6 +680,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
572 public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType) 680 public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
573 { 681 {
574 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 682 List<SceneObjectPart> ret = new List<SceneObjectPart>();
683 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
684 return ret;
575 ret.Add(part); 685 ret.Add(part);
576 686
577 switch (linkType) 687 switch (linkType)
@@ -771,31 +881,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
771 881
772 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 882 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
773 883
774 /// <summary> 884 // Utility function for llRot2Euler
775 /// Convert an LSL rotation to a Euler vector. 885
776 /// </summary> 886 // normalize an angle between -PI and PI (-180 to +180 degrees)
777 /// <remarks> 887 protected double NormalizeAngle(double angle)
778 /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
779 /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
780 /// </remarks>
781 /// <param name="r"></param>
782 /// <returns></returns>
783 public LSL_Vector llRot2Euler(LSL_Rotation r)
784 { 888 {
785 m_host.AddScriptLPS(1); 889 if (angle > -Math.PI && angle < Math.PI)
890 return angle;
891
892 int numPis = (int)(Math.PI / angle);
893 double remainder = angle - Math.PI * numPis;
894 if (numPis % 2 == 1)
895 return Math.PI - angle;
896 return remainder;
897 }
786 898
787 LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r. 899 public LSL_Vector llRot2Euler(LSL_Rotation q1)
788 double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later. 900 {
789 if (m == 0.0) return new LSL_Vector(); 901 m_host.AddScriptLPS(1);
790 double x = Math.Atan2(-v.y, v.z); 902 LSL_Vector eul = new LSL_Vector();
791 double sin = v.x / m;
792 if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities.
793 double y = Math.Asin(sin);
794 // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
795 v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
796 double z = Math.Atan2(v.y, v.x);
797 903
798 return new LSL_Vector(x, y, z); 904 double sqw = q1.s*q1.s;
905 double sqx = q1.x*q1.x;
906 double sqy = q1.z*q1.z;
907 double sqz = q1.y*q1.y;
908 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
909 double test = q1.x*q1.z + q1.y*q1.s;
910 if (test > 0.4999*unit) { // singularity at north pole
911 eul.z = 2 * Math.Atan2(q1.x,q1.s);
912 eul.y = Math.PI/2;
913 eul.x = 0;
914 return eul;
915 }
916 if (test < -0.4999*unit) { // singularity at south pole
917 eul.z = -2 * Math.Atan2(q1.x,q1.s);
918 eul.y = -Math.PI/2;
919 eul.x = 0;
920 return eul;
921 }
922 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
923 eul.y = Math.Asin(2*test/unit);
924 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
925 return eul;
799 } 926 }
800 927
801 /* From wiki: 928 /* From wiki:
@@ -848,18 +975,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
848 m_host.AddScriptLPS(1); 975 m_host.AddScriptLPS(1);
849 976
850 double x,y,z,s; 977 double x,y,z,s;
851 978 v.x *= 0.5;
852 double c1 = Math.Cos(v.x * 0.5); 979 v.y *= 0.5;
853 double c2 = Math.Cos(v.y * 0.5); 980 v.z *= 0.5;
854 double c3 = Math.Cos(v.z * 0.5); 981 double c1 = Math.Cos(v.x);
855 double s1 = Math.Sin(v.x * 0.5); 982 double c2 = Math.Cos(v.y);
856 double s2 = Math.Sin(v.y * 0.5); 983 double c1c2 = c1 * c2;
857 double s3 = Math.Sin(v.z * 0.5); 984 double s1 = Math.Sin(v.x);
858 985 double s2 = Math.Sin(v.y);
859 x = s1 * c2 * c3 + c1 * s2 * s3; 986 double s1s2 = s1 * s2;
860 y = c1 * s2 * c3 - s1 * c2 * s3; 987 double c1s2 = c1 * s2;
861 z = s1 * s2 * c3 + c1 * c2 * s3; 988 double s1c2 = s1 * c2;
862 s = c1 * c2 * c3 - s1 * s2 * s3; 989 double c3 = Math.Cos(v.z);
990 double s3 = Math.Sin(v.z);
991
992 x = s1c2 * c3 + c1s2 * s3;
993 y = c1s2 * c3 - s1c2 * s3;
994 z = s1s2 * c3 + c1c2 * s3;
995 s = c1c2 * c3 - s1s2 * s3;
863 996
864 return new LSL_Rotation(x, y, z, s); 997 return new LSL_Rotation(x, y, z, s);
865 } 998 }
@@ -997,77 +1130,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
997 { 1130 {
998 //A and B should both be normalized 1131 //A and B should both be normalized
999 m_host.AddScriptLPS(1); 1132 m_host.AddScriptLPS(1);
1000 LSL_Rotation rotBetween; 1133 /* This method is more accurate than the SL one, and thus causes problems
1001 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 1134 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
1002 // continue calculation. 1135
1003 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 1136 double dotProduct = LSL_Vector.Dot(a, b);
1137 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
1138 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
1139 double angle = Math.Acos(dotProduct / magProduct);
1140 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
1141 double s = Math.Sin(angle / 2);
1142
1143 double x = axis.x * s;
1144 double y = axis.y * s;
1145 double z = axis.z * s;
1146 double w = Math.Cos(angle / 2);
1147
1148 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
1149 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
1150
1151 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
1152 */
1153
1154 // This method mimics the 180 errors found in SL
1155 // See www.euclideanspace.com... angleBetween
1156 LSL_Vector vec_a = a;
1157 LSL_Vector vec_b = b;
1158
1159 // Eliminate zero length
1160 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
1161 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
1162 if (vec_a_mag < 0.00001 ||
1163 vec_b_mag < 0.00001)
1004 { 1164 {
1005 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 1165 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
1006 } 1166 }
1007 else 1167
1168 // Normalize
1169 vec_a = llVecNorm(vec_a);
1170 vec_b = llVecNorm(vec_b);
1171
1172 // Calculate axis and rotation angle
1173 LSL_Vector axis = vec_a % vec_b;
1174 LSL_Float cos_theta = vec_a * vec_b;
1175
1176 // Check if parallel
1177 if (cos_theta > 0.99999)
1008 { 1178 {
1009 a = LSL_Vector.Norm(a); 1179 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
1010 b = LSL_Vector.Norm(b); 1180 }
1011 double dotProduct = LSL_Vector.Dot(a, b); 1181
1012 // There are two degenerate cases possible. These are for vectors 180 or 1182 // Check if anti-parallel
1013 // 0 degrees apart. These have to be detected and handled individually. 1183 else if (cos_theta < -0.99999)
1014 // 1184 {
1015 // Check for vectors 180 degrees apart. 1185 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
1016 // A dot product of -1 would mean the angle between vectors is 180 degrees. 1186 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
1017 if (dotProduct < -0.9999999f) 1187 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
1018 { 1188 }
1019 // First assume X axis is orthogonal to the vectors. 1189 else // other rotation
1020 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 1190 {
1021 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 1191 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
1022 // Check for near zero vector. A very small non-zero number here will create 1192 axis = llVecNorm(axis);
1023 // a rotation in an undesired direction. 1193 double x, y, z, s, t;
1024 if (LSL_Vector.Mag(orthoVector) > 0.0001) 1194 s = Math.Cos(theta);
1025 { 1195 t = Math.Sin(theta);
1026 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 1196 x = axis.x * t;
1027 } 1197 y = axis.y * t;
1028 // If the magnitude of the vector was near zero, then assume the X axis is not 1198 z = axis.z * t;
1029 // orthogonal and use the Z axis instead. 1199 return new LSL_Rotation(x,y,z,s);
1030 else
1031 {
1032 // Set 180 z rotation.
1033 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
1034 }
1035 }
1036 // Check for parallel vectors.
1037 // A dot product of 1 would mean the angle between vectors is 0 degrees.
1038 else if (dotProduct > 0.9999999f)
1039 {
1040 // Set zero rotation.
1041 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
1042 }
1043 else
1044 {
1045 // All special checks have been performed so get the axis of rotation.
1046 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
1047 // Quarternion s value is the length of the unit vector + dot product.
1048 double qs = 1.0 + dotProduct;
1049 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
1050 // Normalize the rotation.
1051 double mag = LSL_Rotation.Mag(rotBetween);
1052 // We shouldn't have to worry about a divide by zero here. The qs value will be
1053 // non-zero because we already know if we're here, then the dotProduct is not -1 so
1054 // qs will not be zero. Also, we've already handled the input vectors being zero so the
1055 // crossProduct vector should also not be zero.
1056 rotBetween.x = rotBetween.x / mag;
1057 rotBetween.y = rotBetween.y / mag;
1058 rotBetween.z = rotBetween.z / mag;
1059 rotBetween.s = rotBetween.s / mag;
1060 // Check for undefined values and set zero rotation if any found. This code might not actually be required
1061 // any longer since zero vectors are checked for at the top.
1062 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
1063 {
1064 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
1065 }
1066 }
1067 } 1200 }
1068 return rotBetween;
1069 } 1201 }
1070 1202
1071 public void llWhisper(int channelID, string text) 1203 public void llWhisper(int channelID, string text)
1072 { 1204 {
1073 m_host.AddScriptLPS(1); 1205 m_host.AddScriptLPS(1);
@@ -1083,10 +1215,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1083 wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text); 1215 wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
1084 } 1216 }
1085 1217
1218 private void CheckSayShoutTime()
1219 {
1220 DateTime now = DateTime.UtcNow;
1221 if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
1222 {
1223 m_lastSayShoutCheck = now;
1224 m_SayShoutCount = 0;
1225 }
1226 else
1227 m_SayShoutCount++;
1228 }
1229
1086 public void llSay(int channelID, string text) 1230 public void llSay(int channelID, string text)
1087 { 1231 {
1088 m_host.AddScriptLPS(1); 1232 m_host.AddScriptLPS(1);
1089 1233
1234 if (channelID == 0)
1235// m_SayShoutCount++;
1236 CheckSayShoutTime();
1237
1238 if (m_SayShoutCount >= 11)
1239 ScriptSleep(2000);
1240
1090 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) 1241 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
1091 { 1242 {
1092 Console.WriteLine(text); 1243 Console.WriteLine(text);
@@ -1109,6 +1260,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1109 { 1260 {
1110 m_host.AddScriptLPS(1); 1261 m_host.AddScriptLPS(1);
1111 1262
1263 if (channelID == 0)
1264// m_SayShoutCount++;
1265 CheckSayShoutTime();
1266
1267 if (m_SayShoutCount >= 11)
1268 ScriptSleep(2000);
1269
1112 if (text.Length > 1023) 1270 if (text.Length > 1023)
1113 text = text.Substring(0, 1023); 1271 text = text.Substring(0, 1023);
1114 1272
@@ -1143,16 +1301,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1143 1301
1144 public void llRegionSayTo(string target, int channel, string msg) 1302 public void llRegionSayTo(string target, int channel, string msg)
1145 { 1303 {
1304 string error = String.Empty;
1305
1146 if (msg.Length > 1023) 1306 if (msg.Length > 1023)
1147 msg = msg.Substring(0, 1023); 1307 msg = msg.Substring(0, 1023);
1148 1308
1149 m_host.AddScriptLPS(1); 1309 m_host.AddScriptLPS(1);
1150 1310
1151 if (channel == ScriptBaseClass.DEBUG_CHANNEL)
1152 {
1153 return;
1154 }
1155
1156 UUID TargetID; 1311 UUID TargetID;
1157 UUID.TryParse(target, out TargetID); 1312 UUID.TryParse(target, out TargetID);
1158 1313
@@ -1161,7 +1316,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1161 1316
1162 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 1317 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1163 if (wComm != null) 1318 if (wComm != null)
1164 wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg); 1319 if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error))
1320 LSLError(error);
1165 } 1321 }
1166 1322
1167 public LSL_Integer llListen(int channelID, string name, string ID, string msg) 1323 public LSL_Integer llListen(int channelID, string name, string ID, string msg)
@@ -1417,10 +1573,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1417 return detectedParams.TouchUV; 1573 return detectedParams.TouchUV;
1418 } 1574 }
1419 1575
1576 [DebuggerNonUserCode]
1420 public virtual void llDie() 1577 public virtual void llDie()
1421 { 1578 {
1422 m_host.AddScriptLPS(1); 1579 m_host.AddScriptLPS(1);
1423 throw new SelfDeleteException(); 1580 if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
1424 } 1581 }
1425 1582
1426 public LSL_Float llGround(LSL_Vector offset) 1583 public LSL_Float llGround(LSL_Vector offset)
@@ -1491,6 +1648,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1491 1648
1492 public void llSetStatus(int status, int value) 1649 public void llSetStatus(int status, int value)
1493 { 1650 {
1651 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1652 return;
1494 m_host.AddScriptLPS(1); 1653 m_host.AddScriptLPS(1);
1495 1654
1496 int statusrotationaxis = 0; 1655 int statusrotationaxis = 0;
@@ -1502,6 +1661,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1502 SceneObjectGroup group = m_host.ParentGroup; 1661 SceneObjectGroup group = m_host.ParentGroup;
1503 bool allow = true; 1662 bool allow = true;
1504 1663
1664 int maxprims = World.m_linksetPhysCapacity;
1665 bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
1666
1505 foreach (SceneObjectPart part in group.Parts) 1667 foreach (SceneObjectPart part in group.Parts)
1506 { 1668 {
1507 if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys) 1669 if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
@@ -1509,11 +1671,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1509 allow = false; 1671 allow = false;
1510 break; 1672 break;
1511 } 1673 }
1674 if (checkShape && part.PhysicsShapeType != (byte)PhysicsShapeType.None)
1675 {
1676 if (--maxprims < 0)
1677 {
1678 allow = false;
1679 break;
1680 }
1681 }
1512 } 1682 }
1513 1683
1514 if (!allow) 1684 if (!allow)
1515 return; 1685 return;
1516 1686
1687 if (m_host.ParentGroup.RootPart.PhysActor != null &&
1688 m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
1689 return;
1690
1517 m_host.ScriptSetPhysicsStatus(true); 1691 m_host.ScriptSetPhysicsStatus(true);
1518 } 1692 }
1519 else 1693 else
@@ -1712,12 +1886,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1712 { 1886 {
1713 m_host.AddScriptLPS(1); 1887 m_host.AddScriptLPS(1);
1714 1888
1889 SetColor(m_host, color, face);
1890 }
1891
1892 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1893 {
1894 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1895 return;
1896
1897 Primitive.TextureEntry tex = part.Shape.Textures;
1898 Color4 texcolor;
1899 if (face >= 0 && face < GetNumberOfSides(part))
1900 {
1901 texcolor = tex.CreateFace((uint)face).RGBA;
1902 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1903 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1904 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1905 tex.FaceTextures[face].RGBA = texcolor;
1906 part.UpdateTextureEntry(tex.GetBytes());
1907 return;
1908 }
1909 else if (face == ScriptBaseClass.ALL_SIDES)
1910 {
1911 for (uint i = 0; i < GetNumberOfSides(part); i++)
1912 {
1913 if (tex.FaceTextures[i] != null)
1914 {
1915 texcolor = tex.FaceTextures[i].RGBA;
1916 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1917 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1918 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1919 tex.FaceTextures[i].RGBA = texcolor;
1920 }
1921 texcolor = tex.DefaultTexture.RGBA;
1922 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1923 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1924 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1925 tex.DefaultTexture.RGBA = texcolor;
1926 }
1927 part.UpdateTextureEntry(tex.GetBytes());
1928 return;
1929 }
1930
1715 if (face == ScriptBaseClass.ALL_SIDES) 1931 if (face == ScriptBaseClass.ALL_SIDES)
1716 face = SceneObjectPart.ALL_SIDES; 1932 face = SceneObjectPart.ALL_SIDES;
1717 1933
1718 m_host.SetFaceColorAlpha(face, color, null); 1934 m_host.SetFaceColorAlpha(face, color, null);
1719 } 1935 }
1720 1936
1937 /*
1721 public void llSetContentType(LSL_Key id, LSL_Integer type) 1938 public void llSetContentType(LSL_Key id, LSL_Integer type)
1722 { 1939 {
1723 m_host.AddScriptLPS(1); 1940 m_host.AddScriptLPS(1);
@@ -1784,9 +2001,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1784 break; 2001 break;
1785 } 2002 }
1786 } 2003 }
2004 */
1787 2005
1788 public void SetTexGen(SceneObjectPart part, int face,int style) 2006 public void SetTexGen(SceneObjectPart part, int face,int style)
1789 { 2007 {
2008 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2009 return;
2010
1790 Primitive.TextureEntry tex = part.Shape.Textures; 2011 Primitive.TextureEntry tex = part.Shape.Textures;
1791 MappingType textype; 2012 MappingType textype;
1792 textype = MappingType.Default; 2013 textype = MappingType.Default;
@@ -1817,6 +2038,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1817 2038
1818 public void SetGlow(SceneObjectPart part, int face, float glow) 2039 public void SetGlow(SceneObjectPart part, int face, float glow)
1819 { 2040 {
2041 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2042 return;
2043
1820 Primitive.TextureEntry tex = part.Shape.Textures; 2044 Primitive.TextureEntry tex = part.Shape.Textures;
1821 if (face >= 0 && face < GetNumberOfSides(part)) 2045 if (face >= 0 && face < GetNumberOfSides(part))
1822 { 2046 {
@@ -1842,6 +2066,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1842 2066
1843 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 2067 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1844 { 2068 {
2069 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2070 return;
1845 2071
1846 Shininess sval = new Shininess(); 2072 Shininess sval = new Shininess();
1847 2073
@@ -1892,6 +2118,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1892 2118
1893 public void SetFullBright(SceneObjectPart part, int face, bool bright) 2119 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1894 { 2120 {
2121 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2122 return;
2123
1895 Primitive.TextureEntry tex = part.Shape.Textures; 2124 Primitive.TextureEntry tex = part.Shape.Textures;
1896 if (face >= 0 && face < GetNumberOfSides(part)) 2125 if (face >= 0 && face < GetNumberOfSides(part))
1897 { 2126 {
@@ -1952,13 +2181,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1952 m_host.AddScriptLPS(1); 2181 m_host.AddScriptLPS(1);
1953 2182
1954 List<SceneObjectPart> parts = GetLinkParts(linknumber); 2183 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1955 2184 if (parts.Count > 0)
1956 foreach (SceneObjectPart part in parts) 2185 {
1957 SetAlpha(part, alpha, face); 2186 try
2187 {
2188 foreach (SceneObjectPart part in parts)
2189 SetAlpha(part, alpha, face);
2190 }
2191 finally
2192 {
2193 }
2194 }
1958 } 2195 }
1959 2196
1960 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 2197 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1961 { 2198 {
2199 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2200 return;
2201
1962 Primitive.TextureEntry tex = part.Shape.Textures; 2202 Primitive.TextureEntry tex = part.Shape.Textures;
1963 Color4 texcolor; 2203 Color4 texcolor;
1964 if (face >= 0 && face < GetNumberOfSides(part)) 2204 if (face >= 0 && face < GetNumberOfSides(part))
@@ -2011,7 +2251,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2011 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 2251 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
2012 float wind, float tension, LSL_Vector Force) 2252 float wind, float tension, LSL_Vector Force)
2013 { 2253 {
2014 if (part == null) 2254 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2015 return; 2255 return;
2016 2256
2017 if (flexi) 2257 if (flexi)
@@ -2052,7 +2292,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2052 /// <param name="falloff"></param> 2292 /// <param name="falloff"></param>
2053 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 2293 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
2054 { 2294 {
2055 if (part == null) 2295 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2056 return; 2296 return;
2057 2297
2058 if (light) 2298 if (light)
@@ -2085,11 +2325,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2085 Primitive.TextureEntry tex = part.Shape.Textures; 2325 Primitive.TextureEntry tex = part.Shape.Textures;
2086 Color4 texcolor; 2326 Color4 texcolor;
2087 LSL_Vector rgb = new LSL_Vector(); 2327 LSL_Vector rgb = new LSL_Vector();
2328 int nsides = GetNumberOfSides(part);
2329
2088 if (face == ScriptBaseClass.ALL_SIDES) 2330 if (face == ScriptBaseClass.ALL_SIDES)
2089 { 2331 {
2090 int i; 2332 int i;
2091 2333 for (i = 0; i < nsides; i++)
2092 for (i = 0 ; i < GetNumberOfSides(part); i++)
2093 { 2334 {
2094 texcolor = tex.GetFace((uint)i).RGBA; 2335 texcolor = tex.GetFace((uint)i).RGBA;
2095 rgb.x += texcolor.R; 2336 rgb.x += texcolor.R;
@@ -2097,14 +2338,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2097 rgb.z += texcolor.B; 2338 rgb.z += texcolor.B;
2098 } 2339 }
2099 2340
2100 rgb.x /= (float)GetNumberOfSides(part); 2341 float invnsides = 1.0f / (float)nsides;
2101 rgb.y /= (float)GetNumberOfSides(part); 2342
2102 rgb.z /= (float)GetNumberOfSides(part); 2343 rgb.x *= invnsides;
2344 rgb.y *= invnsides;
2345 rgb.z *= invnsides;
2103 2346
2104 return rgb; 2347 return rgb;
2105 } 2348 }
2106 2349 if (face >= 0 && face < nsides)
2107 if (face >= 0 && face < GetNumberOfSides(part))
2108 { 2350 {
2109 texcolor = tex.GetFace((uint)face).RGBA; 2351 texcolor = tex.GetFace((uint)face).RGBA;
2110 rgb.x = texcolor.R; 2352 rgb.x = texcolor.R;
@@ -2131,15 +2373,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2131 m_host.AddScriptLPS(1); 2373 m_host.AddScriptLPS(1);
2132 2374
2133 List<SceneObjectPart> parts = GetLinkParts(linknumber); 2375 List<SceneObjectPart> parts = GetLinkParts(linknumber);
2376<<<<<<< HEAD
2134 2377
2135 foreach (SceneObjectPart part in parts) 2378 foreach (SceneObjectPart part in parts)
2136 SetTexture(part, texture, face); 2379 SetTexture(part, texture, face);
2137 2380
2138 ScriptSleep(m_sleepMsOnSetLinkTexture); 2381 ScriptSleep(m_sleepMsOnSetLinkTexture);
2382=======
2383 if (parts.Count > 0)
2384 {
2385 try
2386 {
2387 foreach (SceneObjectPart part in parts)
2388 SetTexture(part, texture, face);
2389 }
2390 finally
2391 {
2392 }
2393 }
2394 ScriptSleep(200);
2395>>>>>>> avn/ubitvar
2139 } 2396 }
2140 2397
2141 protected void SetTexture(SceneObjectPart part, string texture, int face) 2398 protected void SetTexture(SceneObjectPart part, string texture, int face)
2142 { 2399 {
2400 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2401 return;
2402
2143 UUID textureID = new UUID(); 2403 UUID textureID = new UUID();
2144 2404
2145 textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture); 2405 textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
@@ -2184,6 +2444,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2184 2444
2185 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 2445 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
2186 { 2446 {
2447 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2448 return;
2449
2187 Primitive.TextureEntry tex = part.Shape.Textures; 2450 Primitive.TextureEntry tex = part.Shape.Textures;
2188 if (face >= 0 && face < GetNumberOfSides(part)) 2451 if (face >= 0 && face < GetNumberOfSides(part))
2189 { 2452 {
@@ -2220,6 +2483,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2220 2483
2221 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2484 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
2222 { 2485 {
2486 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2487 return;
2488
2223 Primitive.TextureEntry tex = part.Shape.Textures; 2489 Primitive.TextureEntry tex = part.Shape.Textures;
2224 if (face >= 0 && face < GetNumberOfSides(part)) 2490 if (face >= 0 && face < GetNumberOfSides(part))
2225 { 2491 {
@@ -2256,6 +2522,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2256 2522
2257 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2523 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
2258 { 2524 {
2525 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2526 return;
2527
2259 Primitive.TextureEntry tex = part.Shape.Textures; 2528 Primitive.TextureEntry tex = part.Shape.Textures;
2260 if (face >= 0 && face < GetNumberOfSides(part)) 2529 if (face >= 0 && face < GetNumberOfSides(part))
2261 { 2530 {
@@ -2397,7 +2666,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2397 return end; 2666 return end;
2398 } 2667 }
2399 2668
2400 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos) 2669 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
2401 { 2670 {
2402 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 2671 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2403 return fromPos; 2672 return fromPos;
@@ -2413,9 +2682,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2413 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0) 2682 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
2414 targetPos.z = ground; 2683 targetPos.z = ground;
2415 } 2684 }
2416 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos); 2685 if (adjust)
2686 return SetPosAdjust(fromPos, targetPos);
2417 2687
2418 return real_vec; 2688 return targetPos;
2419 } 2689 }
2420 2690
2421 /// <summary> 2691 /// <summary>
@@ -2426,27 +2696,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2426 /// <param name="adjust">if TRUE, will cap the distance to 10m.</param> 2696 /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
2427 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust) 2697 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
2428 { 2698 {
2429 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2699 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2700 return;
2701
2430 LSL_Vector currentPos = GetPartLocalPos(part); 2702 LSL_Vector currentPos = GetPartLocalPos(part);
2703 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
2431 2704
2432 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
2433 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
2434 2705
2435 if (part.ParentGroup.RootPart == part) 2706 if (part.ParentGroup.RootPart == part)
2436 { 2707 {
2437 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
2438 targetPos.z = ground;
2439 SceneObjectGroup parent = part.ParentGroup; 2708 SceneObjectGroup parent = part.ParentGroup;
2440 parent.UpdateGroupPosition(!adjust ? targetPos : 2709 if (!World.Permissions.CanObjectEntry(parent.UUID, false, (Vector3)toPos))
2441 SetPosAdjust(currentPos, targetPos)); 2710 return;
2711 Util.FireAndForget(delegate(object x) {
2712 parent.UpdateGroupPosition((Vector3)toPos);
2713 });
2442 } 2714 }
2443 else 2715 else
2444 { 2716 {
2445 part.OffsetPosition = !adjust ? targetPos : 2717 part.OffsetPosition = (Vector3)toPos;
2446 SetPosAdjust(currentPos, targetPos); 2718// SceneObjectGroup parent = part.ParentGroup;
2447 SceneObjectGroup parent = part.ParentGroup; 2719// parent.HasGroupChanged = true;
2448 parent.HasGroupChanged = true; 2720// parent.ScheduleGroupForTerseUpdate();
2449 parent.ScheduleGroupForTerseUpdate(); 2721 part.ScheduleTerseUpdate();
2450 } 2722 }
2451 } 2723 }
2452 2724
@@ -2475,13 +2747,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2475 else 2747 else
2476 { 2748 {
2477 if (part.ParentGroup.IsAttachment) 2749 if (part.ParentGroup.IsAttachment)
2478 {
2479 pos = part.AttachedPos; 2750 pos = part.AttachedPos;
2480 }
2481 else 2751 else
2482 {
2483 pos = part.AbsolutePosition; 2752 pos = part.AbsolutePosition;
2484 }
2485 } 2753 }
2486 2754
2487// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos); 2755// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
@@ -2493,8 +2761,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2493 { 2761 {
2494 m_host.AddScriptLPS(1); 2762 m_host.AddScriptLPS(1);
2495 2763
2764
2765 // Teravus: if (m_host.ParentID == 0) is bug code because the ParentID for the Avatar will cause this to be nonzero for root prim attachments
2766 // which is then treated like a child prim rotation and it's offset gets cumulatively multiplied against.
2767 // to fix the scripted rotations we also have to check to see if the root part localid is the same as the host's localid.
2768 // RootPart != null should shortcircuit
2769
2496 // try to let this work as in SL... 2770 // try to let this work as in SL...
2497 if (m_host.ParentID == 0) 2771 if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
2498 { 2772 {
2499 // special case: If we are root, rotate complete SOG to new rotation 2773 // special case: If we are root, rotate complete SOG to new rotation
2500 SetRot(m_host, rot); 2774 SetRot(m_host, rot);
@@ -2521,25 +2795,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2521 2795
2522 protected void SetRot(SceneObjectPart part, Quaternion rot) 2796 protected void SetRot(SceneObjectPart part, Quaternion rot)
2523 { 2797 {
2524 part.UpdateRotation(rot); 2798 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2525 // Update rotation does not move the object in the physics scene if it's a linkset. 2799 return;
2526 2800
2527//KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type 2801 bool isroot = (part == part.ParentGroup.RootPart);
2528// part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition; 2802 bool isphys;
2529 2803
2530 // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
2531 // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
2532 // It's perfectly okay when the object is not an active physical body though.
2533 // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
2534 // but only if the object is not physial and active. This is important for rotating doors.
2535 // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
2536 // scene
2537 PhysicsActor pa = part.PhysActor; 2804 PhysicsActor pa = part.PhysActor;
2538 2805
2539 if (pa != null && !pa.IsPhysical) 2806 // keep using physactor ideia of isphysical
2807 // it should be SOP ideia of that
2808 // not much of a issue with ubitODE
2809 if (pa != null && pa.IsPhysical)
2810 isphys = true;
2811 else
2812 isphys = false;
2813
2814 // SL doesn't let scripts rotate root of physical linksets
2815 if (isroot && isphys)
2816 return;
2817
2818 part.UpdateRotation(rot);
2819
2820 // Update rotation does not move the object in the physics engine if it's a non physical linkset
2821 // so do a nasty update of parts positions if is a root part rotation
2822 if (isroot && pa != null) // with if above implies non physical root part
2540 { 2823 {
2541 part.ParentGroup.ResetChildPrimPhysicsPositions(); 2824 part.ParentGroup.ResetChildPrimPhysicsPositions();
2542 } 2825 }
2826 else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
2827 {
2828 List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
2829 if (sittingavas.Count > 0)
2830 {
2831 foreach (ScenePresence av in sittingavas)
2832 {
2833 if (isroot || part.LocalId == av.ParentID)
2834 av.SendTerseUpdateToAllClients();
2835 }
2836 }
2837 }
2543 } 2838 }
2544 2839
2545 /// <summary> 2840 /// <summary>
@@ -2556,6 +2851,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2556 2851
2557 m_host.AddScriptLPS(1); 2852 m_host.AddScriptLPS(1);
2558 Quaternion q = m_host.GetWorldRotation(); 2853 Quaternion q = m_host.GetWorldRotation();
2854
2855 if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
2856 {
2857 ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
2858 if (avatar != null)
2859 {
2860 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
2861 q = avatar.CameraRotation * q; // Mouselook
2862 else
2863 q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
2864 }
2865 }
2866
2559 return new LSL_Rotation(q.X, q.Y, q.Z, q.W); 2867 return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
2560 } 2868 }
2561 2869
@@ -2583,14 +2891,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2583 return new LSL_Rotation(q); 2891 return new LSL_Rotation(q);
2584 } 2892 }
2585 2893
2586 return new LSL_Rotation(part.GetWorldRotation()); 2894 q = part.GetWorldRotation();
2895 if (part.ParentGroup.AttachmentPoint != 0)
2896 {
2897 ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
2898 if (avatar != null)
2899 {
2900 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
2901 q = avatar.CameraRotation * q; // Mouselook
2902 else
2903 q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
2904 }
2905 }
2906
2907 return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
2587 } 2908 }
2588 2909
2589 public LSL_Rotation llGetLocalRot() 2910 public LSL_Rotation llGetLocalRot()
2590 { 2911 {
2591 m_host.AddScriptLPS(1); 2912 return GetPartLocalRot(m_host);
2913 }
2592 2914
2593 return new LSL_Rotation(m_host.RotationOffset); 2915 private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
2916 {
2917 m_host.AddScriptLPS(1);
2918 Quaternion rot = part.RotationOffset;
2919 return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
2594 } 2920 }
2595 2921
2596 public void llSetForce(LSL_Vector force, int local) 2922 public void llSetForce(LSL_Vector force, int local)
@@ -2620,32 +2946,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2620 return force; 2946 return force;
2621 } 2947 }
2622 2948
2623 public void llSetVelocity(LSL_Vector velocity, int local)
2624 {
2625 m_host.AddScriptLPS(1);
2626
2627 if (!m_host.ParentGroup.IsDeleted)
2628 {
2629 if (local != 0)
2630 velocity *= llGetRot();
2631
2632 m_host.ParentGroup.RootPart.Velocity = velocity;
2633 }
2634 }
2635
2636 public void llSetAngularVelocity(LSL_Vector angularVelocity, int local)
2637 {
2638 m_host.AddScriptLPS(1);
2639
2640 if (!m_host.ParentGroup.IsDeleted)
2641 {
2642 if (local != 0)
2643 angularVelocity *= llGetRot();
2644
2645 m_host.ParentGroup.RootPart.AngularVelocity = angularVelocity;
2646 }
2647 }
2648
2649 public LSL_Integer llTarget(LSL_Vector position, double range) 2949 public LSL_Integer llTarget(LSL_Vector position, double range)
2650 { 2950 {
2651 m_host.AddScriptLPS(1); 2951 m_host.AddScriptLPS(1);
@@ -2696,16 +2996,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2696 m_host.ApplyImpulse(v, local != 0); 2996 m_host.ApplyImpulse(v, local != 0);
2697 } 2997 }
2698 2998
2999
2699 public void llApplyRotationalImpulse(LSL_Vector force, int local) 3000 public void llApplyRotationalImpulse(LSL_Vector force, int local)
2700 { 3001 {
2701 m_host.AddScriptLPS(1); 3002 m_host.AddScriptLPS(1);
2702 m_host.ApplyAngularImpulse(force, local != 0); 3003 m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
2703 } 3004 }
2704 3005
2705 public void llSetTorque(LSL_Vector torque, int local) 3006 public void llSetTorque(LSL_Vector torque, int local)
2706 { 3007 {
2707 m_host.AddScriptLPS(1); 3008 m_host.AddScriptLPS(1);
2708 m_host.SetAngularImpulse(torque, local != 0); 3009 m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
2709 } 3010 }
2710 3011
2711 public LSL_Vector llGetTorque() 3012 public LSL_Vector llGetTorque()
@@ -2722,20 +3023,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2722 llSetTorque(torque, local); 3023 llSetTorque(torque, local);
2723 } 3024 }
2724 3025
3026 public void llSetVelocity(LSL_Vector vel, int local)
3027 {
3028 m_host.AddScriptLPS(1);
3029 m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
3030 }
3031
2725 public LSL_Vector llGetVel() 3032 public LSL_Vector llGetVel()
2726 { 3033 {
2727 m_host.AddScriptLPS(1); 3034 m_host.AddScriptLPS(1);
2728 3035
2729 Vector3 vel; 3036 Vector3 vel = Vector3.Zero;
2730 3037
2731 if (m_host.ParentGroup.IsAttachment) 3038 if (m_host.ParentGroup.IsAttachment)
2732 { 3039 {
2733 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar); 3040 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
3041<<<<<<< HEAD
2734 vel = avatar.GetWorldVelocity(); 3042 vel = avatar.GetWorldVelocity();
3043=======
3044 if (avatar != null)
3045 vel = avatar.Velocity;
3046>>>>>>> avn/ubitvar
2735 } 3047 }
2736 else 3048 else
2737 { 3049 {
2738 vel = m_host.Velocity; 3050 vel = m_host.ParentGroup.RootPart.Velocity;
2739 } 3051 }
2740 3052
2741 return new LSL_Vector(vel); 3053 return new LSL_Vector(vel);
@@ -2748,11 +3060,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2748 return new LSL_Vector(m_host.Acceleration); 3060 return new LSL_Vector(m_host.Acceleration);
2749 } 3061 }
2750 3062
2751 public LSL_Vector llGetOmega() 3063 public void llSetAngularVelocity(LSL_Vector avel, int local)
2752 { 3064 {
2753 m_host.AddScriptLPS(1); 3065 m_host.AddScriptLPS(1);
3066 m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
3067 }
2754 3068
2755 return new LSL_Vector(m_host.AngularVelocity); 3069 public LSL_Vector llGetOmega()
3070 {
3071 m_host.AddScriptLPS(1);
3072 Vector3 avel = m_host.AngularVelocity;
3073 return new LSL_Vector(avel.X, avel.Y, avel.Z);
2756 } 3074 }
2757 3075
2758 public LSL_Float llGetTimeOfDay() 3076 public LSL_Float llGetTimeOfDay()
@@ -2806,7 +3124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2806 m_SoundModule.SendSound( 3124 m_SoundModule.SendSound(
2807 m_host.UUID, 3125 m_host.UUID,
2808 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), 3126 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound),
2809 volume, false, m_host.SoundQueueing ? (byte)SoundFlags.Queue : (byte)SoundFlags.None, 3127 volume, false, 0,
2810 0, false, false); 3128 0, false, false);
2811 } 3129 }
2812 } 3130 }
@@ -2817,7 +3135,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2817 if (m_SoundModule != null) 3135 if (m_SoundModule != null)
2818 { 3136 {
2819 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 3137 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
2820 volume, 20, false); 3138 volume, 20, false,false);
2821 } 3139 }
2822 } 3140 }
2823 3141
@@ -2827,16 +3145,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2827 if (m_SoundModule != null) 3145 if (m_SoundModule != null)
2828 { 3146 {
2829 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 3147 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
2830 volume, 20, true); 3148 volume, 20, true, false);
2831 } 3149 }
2832 } 3150 }
2833 3151
2834 public void llLoopSoundSlave(string sound, double volume) 3152 public void llLoopSoundSlave(string sound, double volume)
2835 { 3153 {
2836 m_host.AddScriptLPS(1); 3154 m_host.AddScriptLPS(1);
2837 lock (m_host.ParentGroup.LoopSoundSlavePrims) 3155 if (m_SoundModule != null)
2838 { 3156 {
2839 m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host); 3157 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
3158 volume, 20, false, true);
2840 } 3159 }
2841 } 3160 }
2842 3161
@@ -3111,7 +3430,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3111 return src.ToLower(); 3430 return src.ToLower();
3112 } 3431 }
3113 3432
3114 public void llGiveMoney(string destination, int amount) 3433 public LSL_Integer llGiveMoney(string destination, int amount)
3115 { 3434 {
3116 Util.FireAndForget(x => 3435 Util.FireAndForget(x =>
3117 { 3436 {
@@ -3142,9 +3461,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3142 return; 3461 return;
3143 } 3462 }
3144 3463
3464 string reason;
3145 money.ObjectGiveMoney( 3465 money.ObjectGiveMoney(
3466<<<<<<< HEAD
3146 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); 3467 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
3147 }, null, "LSL_Api.llGiveMoney"); 3468 }, null, "LSL_Api.llGiveMoney");
3469=======
3470 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero, out reason);
3471 });
3472
3473 return 0;
3474>>>>>>> avn/ubitvar
3148 } 3475 }
3149 3476
3150 public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) 3477 public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
@@ -3177,6 +3504,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3177 3504
3178 public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) 3505 public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
3179 { 3506 {
3507 doObjectRez(inventory, pos, vel, rot, param, true);
3508 }
3509
3510 public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
3511 {
3180 m_host.AddScriptLPS(1); 3512 m_host.AddScriptLPS(1);
3181 3513
3182 Util.FireAndForget(x => 3514 Util.FireAndForget(x =>
@@ -3203,15 +3535,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3203 return; 3535 return;
3204 } 3536 }
3205 3537
3206 // need the magnitude later 3538 List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param, atRoot);
3207 // float velmag = (float)Util.GetMagnitude(llvel);
3208
3209 List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param);
3210 3539
3211 // If either of these are null, then there was an unknown error. 3540 // If either of these are null, then there was an unknown error.
3212 if (new_groups == null) 3541 if (new_groups == null)
3213 return; 3542 return;
3214 3543
3544 bool notAttachment = !m_host.ParentGroup.IsAttachment;
3545
3215 foreach (SceneObjectGroup group in new_groups) 3546 foreach (SceneObjectGroup group in new_groups)
3216 { 3547 {
3217 // objects rezzed with this method are die_at_edge by default. 3548 // objects rezzed with this method are die_at_edge by default.
@@ -3225,22 +3556,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3225 group.RootPart.UUID.ToString()) }, 3556 group.RootPart.UUID.ToString()) },
3226 new DetectParams[0])); 3557 new DetectParams[0]));
3227 3558
3228 float groupmass = group.GetMass(); 3559 if (notAttachment)
3560 {
3561 float groupmass = group.GetMass();
3229 3562
3230 PhysicsActor pa = group.RootPart.PhysActor; 3563 PhysicsActor pa = group.RootPart.PhysActor;
3231 3564
3232 //Recoil. 3565 //Recoil.
3233 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) 3566 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
3234 {
3235 Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
3236 if (recoil != Vector3.Zero)
3237 { 3567 {
3238 llApplyImpulse(recoil, 0); 3568 Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
3569 if (recoil != Vector3.Zero)
3570 {
3571 llApplyImpulse(recoil, 0);
3572 }
3239 } 3573 }
3240 } 3574 }
3241 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3575 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3242 } 3576 }
3577<<<<<<< HEAD
3243 }, null, "LSL_Api.llRezAtRoot"); 3578 }, null, "LSL_Api.llRezAtRoot");
3579=======
3580 return;
3581 });
3582>>>>>>> avn/ubitvar
3244 3583
3245 //ScriptSleep((int)((groupmass * velmag) / 10)); 3584 //ScriptSleep((int)((groupmass * velmag) / 10));
3246 ScriptSleep(m_sleepMsOnRezAtRoot); 3585 ScriptSleep(m_sleepMsOnRezAtRoot);
@@ -3248,15 +3587,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3248 3587
3249 public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) 3588 public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
3250 { 3589 {
3251 llRezAtRoot(inventory, pos, vel, rot, param); 3590 doObjectRez(inventory, pos, vel, rot, param, false);
3252 } 3591 }
3253 3592
3254 public void llLookAt(LSL_Vector target, double strength, double damping) 3593 public void llLookAt(LSL_Vector target, double strength, double damping)
3255 { 3594 {
3256 m_host.AddScriptLPS(1); 3595 m_host.AddScriptLPS(1);
3257 // Determine where we are looking from
3258 LSL_Vector from = llGetPos();
3259 3596
3597<<<<<<< HEAD
3260 // normalized direction to target 3598 // normalized direction to target
3261 LSL_Vector dir = llVecNorm(target - from); 3599 LSL_Vector dir = llVecNorm(target - from);
3262 // use vertical to help compute left axis 3600 // use vertical to help compute left axis
@@ -3274,12 +3612,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3274 PhysicsActor pa = m_host.PhysActor; 3612 PhysicsActor pa = m_host.PhysActor;
3275 3613
3276 if (m_host.ParentGroup.IsAttachment || strength == 0 || pa == null || !pa.IsPhysical) 3614 if (m_host.ParentGroup.IsAttachment || strength == 0 || pa == null || !pa.IsPhysical)
3615=======
3616 // Get the normalized vector to the target
3617 LSL_Vector d1 = llVecNorm(target - llGetPos());
3618
3619 // Get the bearing (yaw)
3620 LSL_Vector a1 = new LSL_Vector(0,0,0);
3621 a1.z = llAtan2(d1.y, d1.x);
3622
3623 // Get the elevation (pitch)
3624 LSL_Vector a2 = new LSL_Vector(0,0,0);
3625 a2.y= -llAtan2(d1.z, llSqrt((d1.x * d1.x) + (d1.y * d1.y)));
3626
3627 LSL_Rotation r1 = llEuler2Rot(a1);
3628 LSL_Rotation r2 = llEuler2Rot(a2);
3629 LSL_Rotation r3 = new LSL_Rotation(0.000000, 0.707107, 0.000000, 0.707107);
3630
3631 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
3632>>>>>>> avn/ubitvar
3277 { 3633 {
3278 llSetRot(rot); 3634 // Do nothing if either value is 0 (this has been checked in SL)
3635 if (strength <= 0.0 || damping <= 0.0)
3636 return;
3637
3638 llSetRot(r3 * r2 * r1);
3279 } 3639 }
3280 else 3640 else
3281 { 3641 {
3282 m_host.StartLookAt(rot, (float)strength, (float)damping); 3642 if (strength == 0)
3643 {
3644 llSetRot(r3 * r2 * r1);
3645 return;
3646 }
3647
3648 m_host.StartLookAt((Quaternion)(r3 * r2 * r1), (float)strength, (float)damping);
3283 } 3649 }
3284 } 3650 }
3285 3651
@@ -3325,22 +3691,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3325 } 3691 }
3326 else 3692 else
3327 { 3693 {
3328 if (m_host.IsRoot) 3694 // new SL always returns object mass
3329 { 3695// if (m_host.IsRoot)
3696// {
3330 return m_host.ParentGroup.GetMass(); 3697 return m_host.ParentGroup.GetMass();
3331 } 3698// }
3332 else 3699// else
3333 { 3700// {
3334 return m_host.GetMass(); 3701// return m_host.GetMass();
3335 } 3702// }
3336 } 3703 }
3337 } 3704 }
3338 3705
3706<<<<<<< HEAD
3339 public LSL_Float llGetMassMKS() 3707 public LSL_Float llGetMassMKS()
3340 { 3708 {
3341 // this is what the wiki says it does! 3709 // this is what the wiki says it does!
3342 // http://wiki.secondlife.com/wiki/LlGetMassMKS 3710 // http://wiki.secondlife.com/wiki/LlGetMassMKS
3343 return llGetMass() * 100.0; 3711 return llGetMass() * 100.0;
3712=======
3713
3714 public LSL_Float llGetMassMKS()
3715 {
3716 return 100f * llGetMass();
3717>>>>>>> avn/ubitvar
3344 } 3718 }
3345 3719
3346 public void llCollisionFilter(string name, string id, int accept) 3720 public void llCollisionFilter(string name, string id, int accept)
@@ -3390,8 +3764,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3390 { 3764 {
3391 // Unregister controls from Presence 3765 // Unregister controls from Presence
3392 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID); 3766 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3393 // Remove Take Control permission.
3394 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3395 } 3767 }
3396 } 3768 }
3397 } 3769 }
@@ -3419,7 +3791,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3419 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3791 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3420 3792
3421 if (attachmentsModule != null) 3793 if (attachmentsModule != null)
3422 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true); 3794 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, false, true);
3423 else 3795 else
3424 return false; 3796 return false;
3425 } 3797 }
@@ -3449,9 +3821,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3449 { 3821 {
3450 m_host.AddScriptLPS(1); 3822 m_host.AddScriptLPS(1);
3451 3823
3452// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
3453// return;
3454
3455 if (m_item.PermsGranter != m_host.OwnerID) 3824 if (m_item.PermsGranter != m_host.OwnerID)
3456 return; 3825 return;
3457 3826
@@ -3494,6 +3863,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3494 3863
3495 public void llInstantMessage(string user, string message) 3864 public void llInstantMessage(string user, string message)
3496 { 3865 {
3866 UUID result;
3867 if (!UUID.TryParse(user, out result) || result == UUID.Zero)
3868 {
3869 ShoutError("An invalid key was passed to llInstantMessage");
3870 ScriptSleep(2000);
3871 return;
3872 }
3873
3874
3497 m_host.AddScriptLPS(1); 3875 m_host.AddScriptLPS(1);
3498 3876
3499 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3877 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3505,14 +3883,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3505 3883
3506 // TODO: figure out values for client, fromSession, and imSessionID 3884 // TODO: figure out values for client, fromSession, and imSessionID
3507 // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch()); 3885 // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
3886<<<<<<< HEAD
3887
3888=======
3889 UUID friendTransactionID = UUID.Random();
3508 3890
3891 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3892
3893>>>>>>> avn/ubitvar
3509 GridInstantMessage msg = new GridInstantMessage(); 3894 GridInstantMessage msg = new GridInstantMessage();
3510 msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid; 3895 msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid;
3511 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3896 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3512 msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here 3897 msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here
3513// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3898// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3514// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3899// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3515 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3900// DateTime dt = DateTime.UtcNow;
3901//
3902// // Ticks from UtcNow, but make it look like local. Evil, huh?
3903// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3904//
3905// try
3906// {
3907// // Convert that to the PST timezone
3908// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3909// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3910// }
3911// catch
3912// {
3913// // No logging here, as it could be VERY spammy
3914// }
3915//
3916// // And make it look local again to fool the unix time util
3917// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3918
3919 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3920
3516 //if (client != null) 3921 //if (client != null)
3517 //{ 3922 //{
3518 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3923 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3526,10 +3931,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3526 msg.message = message.Substring(0, 1024); 3931 msg.message = message.Substring(0, 1024);
3527 else 3932 else
3528 msg.message = message; 3933 msg.message = message;
3529 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3934 msg.dialog = (byte)19; // MessageFromObject
3530 msg.fromGroup = false;// fromGroup; 3935 msg.fromGroup = false;// fromGroup;
3531 msg.offline = (byte)0; //offline; 3936 msg.offline = (byte)0; //offline;
3532 msg.ParentEstateID = 0; //ParentEstateID; 3937 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3533 msg.Position = new Vector3(m_host.AbsolutePosition); 3938 msg.Position = new Vector3(m_host.AbsolutePosition);
3534 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3939 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
3535 3940
@@ -3832,7 +4237,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3832 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 4237 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3833 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 4238 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3834 ScriptBaseClass.PERMISSION_TRACK_CAMERA | 4239 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
4240<<<<<<< HEAD
3835 ScriptBaseClass.PERMISSION_ATTACH; 4241 ScriptBaseClass.PERMISSION_ATTACH;
4242=======
4243 ScriptBaseClass.PERMISSION_ATTACH |
4244 ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
4245
4246>>>>>>> avn/ubitvar
3836 } 4247 }
3837 else 4248 else
3838 { 4249 {
@@ -3849,15 +4260,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3849 if (World.GetExtraSetting("auto_grant_attach_perms") == "true") 4260 if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
3850 implicitPerms = ScriptBaseClass.PERMISSION_ATTACH; 4261 implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
3851 } 4262 }
4263 if (World.GetExtraSetting("auto_grant_all_perms") == "true")
4264 {
4265 implicitPerms = perm;
4266 }
3852 } 4267 }
3853 4268
3854 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 4269 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3855 { 4270 {
3856 lock (m_host.TaskInventory) 4271 m_host.TaskInventory.LockItemsForWrite(true);
3857 { 4272 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3858 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 4273 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3859 m_host.TaskInventory[m_item.ItemID].PermsMask = perm; 4274 m_host.TaskInventory.LockItemsForWrite(false);
3860 }
3861 4275
3862 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( 4276 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3863 "run_time_permissions", new Object[] { 4277 "run_time_permissions", new Object[] {
@@ -3901,11 +4315,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3901 4315
3902 if (!m_waitingForScriptAnswer) 4316 if (!m_waitingForScriptAnswer)
3903 { 4317 {
3904 lock (m_host.TaskInventory) 4318 m_host.TaskInventory.LockItemsForWrite(true);
3905 { 4319 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3906 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 4320 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3907 m_host.TaskInventory[m_item.ItemID].PermsMask = 0; 4321 m_host.TaskInventory.LockItemsForWrite(false);
3908 }
3909 4322
3910 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 4323 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3911 m_waitingForScriptAnswer=true; 4324 m_waitingForScriptAnswer=true;
@@ -3934,14 +4347,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3934 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 4347 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3935 llReleaseControls(); 4348 llReleaseControls();
3936 4349
3937 lock (m_host.TaskInventory) 4350 m_host.TaskInventory.LockItemsForWrite(true);
3938 { 4351 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3939 m_host.TaskInventory[m_item.ItemID].PermsMask = answer; 4352 m_host.TaskInventory.LockItemsForWrite(false);
3940 } 4353
3941 4354 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3942 m_ScriptEngine.PostScriptEvent( 4355 "run_time_permissions", new Object[] {
3943 m_item.ItemID, 4356 new LSL_Integer(answer) },
3944 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0])); 4357 new DetectParams[0]));
3945 } 4358 }
3946 4359
3947 public LSL_String llGetPermissionsKey() 4360 public LSL_String llGetPermissionsKey()
@@ -3980,14 +4393,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3980 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 4393 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3981 { 4394 {
3982 List<SceneObjectPart> parts = GetLinkParts(linknumber); 4395 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3983 4396 if (parts.Count > 0)
3984 foreach (SceneObjectPart part in parts) 4397 {
3985 part.SetFaceColorAlpha(face, color, null); 4398 try
4399 {
4400 foreach (SceneObjectPart part in parts)
4401 part.SetFaceColorAlpha(face, color, null);
4402 }
4403 finally
4404 {
4405 }
4406 }
3986 } 4407 }
3987 4408
3988 public void llCreateLink(string target, int parent) 4409 public void llCreateLink(string target, int parent)
3989 { 4410 {
3990 m_host.AddScriptLPS(1); 4411 m_host.AddScriptLPS(1);
4412<<<<<<< HEAD
4413=======
4414
4415 UUID targetID;
4416
4417 if (!UUID.TryParse(target, out targetID))
4418 return;
4419>>>>>>> avn/ubitvar
3991 4420
3992 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4421 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3993 && !m_automaticLinkPermission) 4422 && !m_automaticLinkPermission)
@@ -4104,10 +4533,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4104 // Restructuring Multiple Prims. 4533 // Restructuring Multiple Prims.
4105 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 4534 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
4106 parts.Remove(parentPrim.RootPart); 4535 parts.Remove(parentPrim.RootPart);
4107 foreach (SceneObjectPart part in parts) 4536 if (parts.Count > 0)
4108 { 4537 {
4109 parentPrim.DelinkFromGroup(part.LocalId, true); 4538 try
4539 {
4540 foreach (SceneObjectPart part in parts)
4541 {
4542 parentPrim.DelinkFromGroup(part.LocalId, true);
4543 }
4544 }
4545 finally
4546 {
4547 }
4110 } 4548 }
4549
4111 parentPrim.HasGroupChanged = true; 4550 parentPrim.HasGroupChanged = true;
4112 parentPrim.ScheduleGroupForFullUpdate(); 4551 parentPrim.ScheduleGroupForFullUpdate();
4113 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 4552 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -4116,12 +4555,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4116 { 4555 {
4117 SceneObjectPart newRoot = parts[0]; 4556 SceneObjectPart newRoot = parts[0];
4118 parts.Remove(newRoot); 4557 parts.Remove(newRoot);
4119 foreach (SceneObjectPart part in parts) 4558
4559 try
4120 { 4560 {
4121 // Required for linking 4561 foreach (SceneObjectPart part in parts)
4122 part.ClearUpdateSchedule(); 4562 {
4123 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 4563 part.ClearUpdateSchedule();
4564 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
4565 }
4124 } 4566 }
4567 finally
4568 {
4569 }
4570
4571
4125 newRoot.ParentGroup.HasGroupChanged = true; 4572 newRoot.ParentGroup.HasGroupChanged = true;
4126 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4573 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
4127 } 4574 }
@@ -4142,6 +4589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4142 { 4589 {
4143 m_host.AddScriptLPS(1); 4590 m_host.AddScriptLPS(1);
4144 4591
4592<<<<<<< HEAD
4145 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4593 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4146 && !m_automaticLinkPermission) 4594 && !m_automaticLinkPermission)
4147 { 4595 {
@@ -4154,6 +4602,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4154 4602
4155 public void BreakAllLinks() 4603 public void BreakAllLinks()
4156 { 4604 {
4605=======
4606 TaskInventoryItem item = m_item;
4607
4608 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4609 && !m_automaticLinkPermission)
4610 {
4611 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4612 return;
4613 }
4614
4615>>>>>>> avn/ubitvar
4157 SceneObjectGroup parentPrim = m_host.ParentGroup; 4616 SceneObjectGroup parentPrim = m_host.ParentGroup;
4158 if (parentPrim.AttachmentPoint != 0) 4617 if (parentPrim.AttachmentPoint != 0)
4159 return; // Fail silently if attached 4618 return; // Fail silently if attached
@@ -4173,13 +4632,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4173 public LSL_String llGetLinkKey(int linknum) 4632 public LSL_String llGetLinkKey(int linknum)
4174 { 4633 {
4175 m_host.AddScriptLPS(1); 4634 m_host.AddScriptLPS(1);
4635 SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
4636 if (part != null)
4637 {
4638 return part.UUID.ToString();
4639 }
4640 else
4641 {
4642 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4643 {
4644 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4176 4645
4646<<<<<<< HEAD
4177 ISceneEntity entity = GetLinkEntity(m_host, linknum); 4647 ISceneEntity entity = GetLinkEntity(m_host, linknum);
4648=======
4649 if (linknum < 0)
4650 return UUID.Zero.ToString();
4651>>>>>>> avn/ubitvar
4178 4652
4179 if (entity != null) 4653 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4180 return entity.UUID.ToString(); 4654 if (avatars.Count > linknum)
4181 else 4655 {
4182 return ScriptBaseClass.NULL_KEY; 4656 return avatars[linknum].UUID.ToString();
4657 }
4658 }
4659 return UUID.Zero.ToString();
4660 }
4183 } 4661 }
4184 4662
4185 /// <summary> 4663 /// <summary>
@@ -4238,17 +4716,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4238 m_host.AddScriptLPS(1); 4716 m_host.AddScriptLPS(1);
4239 int count = 0; 4717 int count = 0;
4240 4718
4241 lock (m_host.TaskInventory) 4719 m_host.TaskInventory.LockItemsForRead(true);
4720 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4242 { 4721 {
4243 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4722 if (inv.Value.Type == type || type == -1)
4244 { 4723 {
4245 if (inv.Value.Type == type || type == -1) 4724 count = count + 1;
4246 {
4247 count = count + 1;
4248 }
4249 } 4725 }
4250 } 4726 }
4251 4727
4728 m_host.TaskInventory.LockItemsForRead(false);
4252 return count; 4729 return count;
4253 } 4730 }
4254 4731
@@ -4257,16 +4734,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4257 m_host.AddScriptLPS(1); 4734 m_host.AddScriptLPS(1);
4258 ArrayList keys = new ArrayList(); 4735 ArrayList keys = new ArrayList();
4259 4736
4260 lock (m_host.TaskInventory) 4737 m_host.TaskInventory.LockItemsForRead(true);
4738 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4261 { 4739 {
4262 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4740 if (inv.Value.Type == type || type == -1)
4263 { 4741 {
4264 if (inv.Value.Type == type || type == -1) 4742 keys.Add(inv.Value.Name);
4265 {
4266 keys.Add(inv.Value.Name);
4267 }
4268 } 4743 }
4269 } 4744 }
4745 m_host.TaskInventory.LockItemsForRead(false);
4270 4746
4271 if (keys.Count == 0) 4747 if (keys.Count == 0)
4272 { 4748 {
@@ -4303,8 +4779,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4303 4779
4304 if (item == null) 4780 if (item == null)
4305 { 4781 {
4782<<<<<<< HEAD
4306 Error("llGiveInventory", "Can't find inventory object '" + inventory + "'"); 4783 Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
4307 return; 4784 return;
4785=======
4786 llSay(0, String.Format("Could not find object '{0}'", inventory));
4787 return;
4788// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
4789>>>>>>> avn/ubitvar
4308 } 4790 }
4309 4791
4310 UUID objId = item.ItemID; 4792 UUID objId = item.ItemID;
@@ -4336,6 +4818,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4336 } 4818 }
4337 } 4819 }
4338 } 4820 }
4821
4339 // destination is an avatar 4822 // destination is an avatar
4340 string message; 4823 string message;
4341 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message); 4824 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
@@ -4346,27 +4829,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4346 return; 4829 return;
4347 } 4830 }
4348 4831
4349 if (m_TransferModule != null) 4832 byte[] bucket = new byte[1];
4350 { 4833 bucket[0] = (byte)item.Type;
4351 byte[] bucket = new byte[1]; 4834 //byte[] objBytes = agentItem.ID.GetBytes();
4352 bucket[0] = (byte)item.Type; 4835 //Array.Copy(objBytes, 0, bucket, 1, 16);
4353 4836
4354 GridInstantMessage msg = new GridInstantMessage(World, 4837 GridInstantMessage msg = new GridInstantMessage(World,
4355 m_host.OwnerID, m_host.Name, destId, 4838 m_host.OwnerID, m_host.Name, destId,
4356 (byte)InstantMessageDialog.TaskInventoryOffered, 4839 (byte)InstantMessageDialog.TaskInventoryOffered,
4357 false, item.Name+". "+m_host.Name+" is located at "+ 4840 false, item.Name+". "+m_host.Name+" is located at "+
4358 World.RegionInfo.RegionName+" "+ 4841 World.RegionInfo.RegionName+" "+
4359 m_host.AbsolutePosition.ToString(), 4842 m_host.AbsolutePosition.ToString(),
4360 agentItem.ID, true, m_host.AbsolutePosition, 4843 agentItem.ID, true, m_host.AbsolutePosition,
4361 bucket, true); 4844 bucket, true);
4362 4845
4363 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4846 ScenePresence sp;
4364 }
4365 4847
4848<<<<<<< HEAD
4366 ScriptSleep(m_sleepMsOnGiveInventory); 4849 ScriptSleep(m_sleepMsOnGiveInventory);
4850=======
4851 if (World.TryGetScenePresence(destId, out sp))
4852 {
4853 sp.ControllingClient.SendInstantMessage(msg);
4854 }
4855 else
4856 {
4857 if (m_TransferModule != null)
4858 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4859 }
4860
4861 //This delay should only occur when giving inventory to avatars.
4862 ScriptSleep(3000);
4863>>>>>>> avn/ubitvar
4367 } 4864 }
4368 } 4865 }
4369 4866
4867 [DebuggerNonUserCode]
4370 public void llRemoveInventory(string name) 4868 public void llRemoveInventory(string name)
4371 { 4869 {
4372 m_host.AddScriptLPS(1); 4870 m_host.AddScriptLPS(1);
@@ -4421,6 +4919,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4421 { 4919 {
4422 m_host.AddScriptLPS(1); 4920 m_host.AddScriptLPS(1);
4423 4921
4922<<<<<<< HEAD
4424 UUID uuid = (UUID)id; 4923 UUID uuid = (UUID)id;
4425 PresenceInfo pinfo = null; 4924 PresenceInfo pinfo = null;
4426 UserAccount account; 4925 UserAccount account;
@@ -4429,6 +4928,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4429 4928
4430 lock (m_userInfoCache) 4929 lock (m_userInfoCache)
4431 { 4930 {
4931=======
4932 UUID uuid;
4933 if (UUID.TryParse(id, out uuid))
4934 {
4935 PresenceInfo pinfo = null;
4936 UserAccount account;
4937
4938 UserInfoCacheEntry ce;
4939>>>>>>> avn/ubitvar
4432 if (!m_userInfoCache.TryGetValue(uuid, out ce)) 4940 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4433 { 4941 {
4434 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4942 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
@@ -4437,6 +4945,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4437 m_userInfoCache[uuid] = null; // Cache negative 4945 m_userInfoCache[uuid] = null; // Cache negative
4438 return UUID.Zero.ToString(); 4946 return UUID.Zero.ToString();
4439 } 4947 }
4948<<<<<<< HEAD
4949=======
4950
4951>>>>>>> avn/ubitvar
4440 4952
4441 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4953 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4442 if (pinfos != null && pinfos.Length > 0) 4954 if (pinfos != null && pinfos.Length > 0)
@@ -4449,6 +4961,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4449 } 4961 }
4450 } 4962 }
4451 } 4963 }
4964<<<<<<< HEAD
4452 4965
4453 ce = new UserInfoCacheEntry(); 4966 ce = new UserInfoCacheEntry();
4454 ce.time = Util.EnvironmentTickCount(); 4967 ce.time = Util.EnvironmentTickCount();
@@ -4481,6 +4994,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4481 else 4994 else
4482 { 4995 {
4483 pinfo = null; 4996 pinfo = null;
4997=======
4998
4999 ce = new UserInfoCacheEntry();
5000 ce.time = Util.EnvironmentTickCount();
5001 ce.account = account;
5002 ce.pinfo = pinfo;
5003 m_userInfoCache[uuid] = ce;
5004 }
5005 else
5006 {
5007 if (ce == null)
5008 return UUID.Zero.ToString();
5009
5010 account = ce.account;
5011 pinfo = ce.pinfo;
5012 }
5013
5014 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
5015 {
5016 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
5017 if (pinfos != null && pinfos.Length > 0)
5018 {
5019 foreach (PresenceInfo p in pinfos)
5020 {
5021 if (p.RegionID != UUID.Zero)
5022 {
5023 pinfo = p;
5024 }
5025>>>>>>> avn/ubitvar
4484 } 5026 }
4485 5027
4486 ce.time = Util.EnvironmentTickCount(); 5028 ce.time = Util.EnvironmentTickCount();
@@ -4490,11 +5032,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4490 { 5032 {
4491 pinfo = ce.pinfo; 5033 pinfo = ce.pinfo;
4492 } 5034 }
5035<<<<<<< HEAD
4493 } 5036 }
4494 } 5037 }
5038=======
5039 else
5040 pinfo = null;
4495 5041
4496 string reply = String.Empty; 5042 ce.time = Util.EnvironmentTickCount();
5043 ce.pinfo = pinfo;
5044 }
5045>>>>>>> avn/ubitvar
4497 5046
5047 string reply = String.Empty;
5048
5049<<<<<<< HEAD
4498 switch (data) 5050 switch (data)
4499 { 5051 {
4500 case ScriptBaseClass.DATA_ONLINE: 5052 case ScriptBaseClass.DATA_ONLINE:
@@ -4523,18 +5075,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4523 default: 5075 default:
4524 return UUID.Zero.ToString(); // Raise no event 5076 return UUID.Zero.ToString(); // Raise no event
4525 } 5077 }
5078=======
5079 switch (data)
5080 {
5081 case 1: // DATA_ONLINE (0|1)
5082 if (pinfo != null && pinfo.RegionID != UUID.Zero)
5083 reply = "1";
5084 else
5085 reply = "0";
5086 break;
5087 case 2: // DATA_NAME (First Last)
5088 reply = account.FirstName + " " + account.LastName;
5089 break;
5090 case 3: // DATA_BORN (YYYY-MM-DD)
5091 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
5092 born = born.AddSeconds(account.Created);
5093 reply = born.ToString("yyyy-MM-dd");
5094 break;
5095 case 4: // DATA_RATING (0,0,0,0,0,0)
5096 reply = "0,0,0,0,0,0";
5097 break;
5098 case 8: // DATA_PAYINFO (0|1|2|3)
5099 reply = "0";
5100 break;
5101 default:
5102 return UUID.Zero.ToString(); // Raise no event
5103 }
5104>>>>>>> avn/ubitvar
4526 5105
4527 UUID rq = UUID.Random(); 5106 UUID rq = UUID.Random();
4528 5107
4529 UUID tid = AsyncCommands. 5108 UUID tid = AsyncCommands.
4530 DataserverPlugin.RegisterRequest(m_host.LocalId, 5109 DataserverPlugin.RegisterRequest(m_host.LocalId,
4531 m_item.ItemID, rq.ToString()); 5110 m_item.ItemID, rq.ToString());
4532 5111
4533 AsyncCommands. 5112 AsyncCommands.
4534 DataserverPlugin.DataserverReply(rq.ToString(), reply); 5113 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4535 5114
5115<<<<<<< HEAD
4536 ScriptSleep(m_sleepMsOnRequestAgentData); 5116 ScriptSleep(m_sleepMsOnRequestAgentData);
4537 return tid.ToString(); 5117 return tid.ToString();
5118=======
5119 ScriptSleep(100);
5120 return tid.ToString();
5121 }
5122 else
5123 {
5124 ShoutError("Invalid UUID passed to llRequestAgentData.");
5125 }
5126 return "";
5127>>>>>>> avn/ubitvar
4538 } 5128 }
4539 5129
4540 public LSL_String llRequestInventoryData(string name) 5130 public LSL_String llRequestInventoryData(string name)
@@ -4588,12 +5178,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4588 if (UUID.TryParse(agent, out agentId)) 5178 if (UUID.TryParse(agent, out agentId))
4589 { 5179 {
4590 ScenePresence presence = World.GetScenePresence(agentId); 5180 ScenePresence presence = World.GetScenePresence(agentId);
4591 if (presence != null) 5181 if (presence != null && presence.PresenceType != PresenceType.Npc)
4592 { 5182 {
5183 // agent must not be a god
5184 if (presence.UserLevel >= 200) return;
5185
4593 // agent must be over the owners land 5186 // agent must be over the owners land
4594 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) 5187 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
4595 { 5188 {
4596 World.TeleportClientHome(agentId, presence.ControllingClient); 5189 if (!World.TeleportClientHome(agentId, presence.ControllingClient))
5190 {
5191 // They can't be teleported home for some reason
5192 GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
5193 if (regionInfo != null)
5194 {
5195 World.RequestTeleportLocation(
5196 presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
5197 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
5198 }
5199 }
4597 } 5200 }
4598 } 5201 }
4599 } 5202 }
@@ -4611,20 +5214,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4611 ScenePresence presence = World.GetScenePresence(agentId); 5214 ScenePresence presence = World.GetScenePresence(agentId);
4612 if (presence != null && presence.PresenceType != PresenceType.Npc) 5215 if (presence != null && presence.PresenceType != PresenceType.Npc)
4613 { 5216 {
4614 // agent must not be a god
4615 if (presence.GodLevel >= 200) return;
4616
4617 if (destination == String.Empty) 5217 if (destination == String.Empty)
4618 destination = World.RegionInfo.RegionName; 5218 destination = World.RegionInfo.RegionName;
4619 5219
4620 // agent must be over the owners land 5220 if (m_item.PermsGranter == agentId)
4621 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) 5221 {
5222 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
5223 {
5224 DoLLTeleport(presence, destination, targetPos, targetLookAt);
5225 }
5226 }
5227
5228 // agent must be wearing the object
5229 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
4622 { 5230 {
4623 DoLLTeleport(presence, destination, targetPos, targetLookAt); 5231 DoLLTeleport(presence, destination, targetPos, targetLookAt);
4624 } 5232 }
4625 else // or must be wearing the prim 5233 else
4626 { 5234 {
4627 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID) 5235 // agent must not be a god
5236 if (presence.GodLevel >= 200) return;
5237
5238 // agent must be over the owners land
5239 ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
5240 ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
5241 if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
4628 { 5242 {
4629 DoLLTeleport(presence, destination, targetPos, targetLookAt); 5243 DoLLTeleport(presence, destination, targetPos, targetLookAt);
4630 } 5244 }
@@ -4638,24 +5252,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4638 m_host.AddScriptLPS(1); 5252 m_host.AddScriptLPS(1);
4639 UUID agentId = new UUID(); 5253 UUID agentId = new UUID();
4640 5254
5255<<<<<<< HEAD
4641 ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y); 5256 ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
5257=======
5258 ulong regionHandle = Utils.UIntsToLong((uint)(global_coords.x / 256) * 256, (uint)(global_coords.y / 256) * 256);
5259>>>>>>> avn/ubitvar
4642 5260
4643 if (UUID.TryParse(agent, out agentId)) 5261 if (UUID.TryParse(agent, out agentId))
4644 { 5262 {
5263 // This function is owner only!
5264 if (m_host.OwnerID != agentId)
5265 return;
5266
4645 ScenePresence presence = World.GetScenePresence(agentId); 5267 ScenePresence presence = World.GetScenePresence(agentId);
5268
5269 // Can't TP sitting avatars
5270 if (presence.ParentID != 0) // Sitting
5271 return;
5272
4646 if (presence != null && presence.PresenceType != PresenceType.Npc) 5273 if (presence != null && presence.PresenceType != PresenceType.Npc)
4647 { 5274 {
4648 // agent must not be a god 5275 if (m_item.PermsGranter == agentId)
4649 if (presence.GodLevel >= 200) return;
4650
4651 // agent must be over the owners land
4652 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
4653 {
4654 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
4655 }
4656 else // or must be wearing the prim
4657 { 5276 {
4658 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID) 5277 // If attached using llAttachToAvatarTemp, cowardly refuse
5278 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
5279 return;
5280
5281 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
4659 { 5282 {
4660 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation); 5283 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
4661 } 5284 }
@@ -4732,9 +5355,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4732 { 5355 {
4733 m_host.AddScriptLPS(1); 5356 m_host.AddScriptLPS(1);
4734 5357
5358 if(impact_sound == "")
5359 {
5360 m_host.CollisionSoundVolume = (float)impact_volume;
5361 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
5362 m_host.CollisionSoundType = 0;
5363 return;
5364 }
4735 // TODO: Parameter check logic required. 5365 // TODO: Parameter check logic required.
4736 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); 5366 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4737 m_host.CollisionSoundVolume = (float)impact_volume; 5367 m_host.CollisionSoundVolume = (float)impact_volume;
5368 m_host.CollisionSoundType = 1;
4738 } 5369 }
4739 5370
4740 public LSL_String llGetAnimation(string id) 5371 public LSL_String llGetAnimation(string id)
@@ -4748,14 +5379,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4748 5379
4749 if (m_host.RegionHandle == presence.RegionHandle) 5380 if (m_host.RegionHandle == presence.RegionHandle)
4750 { 5381 {
4751 Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
4752
4753 if (presence != null) 5382 if (presence != null)
4754 { 5383 {
4755 AnimationSet currentAnims = presence.Animator.Animations; 5384// if (presence.SitGround)
4756 string currentAnimationState = String.Empty; 5385// return "Sitting on Ground";
4757 if (animationstateNames.TryGetValue(currentAnims.ImplicitDefaultAnimation.AnimID, out currentAnimationState)) 5386// if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
4758 return currentAnimationState; 5387// return "Sitting";
5388
5389 string movementAnimation = presence.Animator.CurrentMovementAnimation;
5390 string lslMovementAnimation;
5391
5392 if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
5393 return lslMovementAnimation;
4759 } 5394 }
4760 } 5395 }
4761 5396
@@ -4903,7 +5538,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4903 { 5538 {
4904 float distance = (PusheePos - m_host.AbsolutePosition).Length(); 5539 float distance = (PusheePos - m_host.AbsolutePosition).Length();
4905 float distance_term = distance * distance * distance; // Script Energy 5540 float distance_term = distance * distance * distance; // Script Energy
4906 float pusher_mass = m_host.GetMass(); 5541 // use total object mass and not part
5542 float pusher_mass = m_host.ParentGroup.GetMass();
4907 5543
4908 float PUSH_ATTENUATION_DISTANCE = 17f; 5544 float PUSH_ATTENUATION_DISTANCE = 17f;
4909 float PUSH_ATTENUATION_SCALE = 5f; 5545 float PUSH_ATTENUATION_SCALE = 5f;
@@ -4938,7 +5574,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4938 { 5574 {
4939 if (local != 0) 5575 if (local != 0)
4940 { 5576 {
4941 applied_linear_impulse *= m_host.GetWorldRotation(); 5577// applied_linear_impulse *= m_host.GetWorldRotation();
5578 applied_linear_impulse *= pusheeav.GetWorldRotation();
4942 } 5579 }
4943 5580
4944 pa.AddForce(applied_linear_impulse, true); 5581 pa.AddForce(applied_linear_impulse, true);
@@ -5292,14 +5929,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5292 { 5929 {
5293 m_host.AddScriptLPS(1); 5930 m_host.AddScriptLPS(1);
5294 5931
5295 if (src == null) 5932 return src.Length;
5296 {
5297 return 0;
5298 }
5299 else
5300 {
5301 return src.Length;
5302 }
5303 } 5933 }
5304 5934
5305 public LSL_Integer llList2Integer(LSL_List src, int index) 5935 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -5370,7 +6000,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5370 else if (src.Data[index] is LSL_Float) 6000 else if (src.Data[index] is LSL_Float)
5371 return Convert.ToDouble(((LSL_Float)src.Data[index]).value); 6001 return Convert.ToDouble(((LSL_Float)src.Data[index]).value);
5372 else if (src.Data[index] is LSL_String) 6002 else if (src.Data[index] is LSL_String)
5373 return Convert.ToDouble(((LSL_String)src.Data[index]).m_string); 6003 {
6004 string str = ((LSL_String) src.Data[index]).m_string;
6005 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
6006 if (m != Match.Empty)
6007 {
6008 str = m.Value;
6009 double d = 0.0;
6010 if (!Double.TryParse(str, out d))
6011 return 0.0;
6012
6013 return d;
6014 }
6015 return 0.0;
6016 }
5374 return Convert.ToDouble(src.Data[index]); 6017 return Convert.ToDouble(src.Data[index]);
5375 } 6018 }
5376 catch (FormatException) 6019 catch (FormatException)
@@ -5414,8 +6057,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5414 // NOTE: 3rd case is needed because a NULL_KEY comes through as 6057 // NOTE: 3rd case is needed because a NULL_KEY comes through as
5415 // type 'obj' and wrongly returns "" 6058 // type 'obj' and wrongly returns ""
5416 else if (!(src.Data[index] is LSL_String || 6059 else if (!(src.Data[index] is LSL_String ||
6060<<<<<<< HEAD
5417 src.Data[index] is LSL_Key || 6061 src.Data[index] is LSL_Key ||
5418 src.Data[index].ToString() == "00000000-0000-0000-0000-000000000000")) 6062 src.Data[index].ToString() == "00000000-0000-0000-0000-000000000000"))
6063=======
6064 src.Data[index] is LSL_Key ||
6065 src.Data[index] is String))
6066>>>>>>> avn/ubitvar
5419 { 6067 {
5420 return ""; 6068 return "";
5421 } 6069 }
@@ -5674,7 +6322,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5674 } 6322 }
5675 } 6323 }
5676 } 6324 }
5677 else { 6325 else
6326 {
5678 object[] array = new object[src.Length]; 6327 object[] array = new object[src.Length];
5679 Array.Copy(src.Data, 0, array, 0, src.Length); 6328 Array.Copy(src.Data, 0, array, 0, src.Length);
5680 result = new LSL_List(array); 6329 result = new LSL_List(array);
@@ -5781,13 +6430,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5781 public LSL_Integer llGetRegionAgentCount() 6430 public LSL_Integer llGetRegionAgentCount()
5782 { 6431 {
5783 m_host.AddScriptLPS(1); 6432 m_host.AddScriptLPS(1);
5784 return new LSL_Integer(World.GetRootAgentCount()); 6433
6434 int count = 0;
6435 World.ForEachRootScenePresence(delegate(ScenePresence sp) {
6436 count++;
6437 });
6438
6439 return new LSL_Integer(count);
5785 } 6440 }
5786 6441
5787 public LSL_Vector llGetRegionCorner() 6442 public LSL_Vector llGetRegionCorner()
5788 { 6443 {
5789 m_host.AddScriptLPS(1); 6444 m_host.AddScriptLPS(1);
5790 return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0); 6445 return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
6446<<<<<<< HEAD
5791 } 6447 }
5792 6448
5793 public LSL_String llGetEnv(LSL_String name) 6449 public LSL_String llGetEnv(LSL_String name)
@@ -5853,6 +6509,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5853 { 6509 {
5854 return ""; 6510 return "";
5855 } 6511 }
6512=======
6513>>>>>>> avn/ubitvar
5856 } 6514 }
5857 6515
5858 /// <summary> 6516 /// <summary>
@@ -5928,17 +6586,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5928 { 6586 {
5929 for (int i = 0; i < length; i++) 6587 for (int i = 0; i < length; i++)
5930 { 6588 {
6589 int needle = llGetListEntryType(test, 0).value;
6590 int haystack = llGetListEntryType(src, i).value;
6591
5931 // Why this piece of insanity? This is because most script constants are C# value types (e.g. int) 6592 // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
5932 // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code 6593 // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
5933 // and so the comparison fails even if the LSL_Integer conceptually has the same value. 6594 // and so the comparison fails even if the LSL_Integer conceptually has the same value.
5934 // Therefore, here we test Equals on both the source and destination objects. 6595 // Therefore, here we test Equals on both the source and destination objects.
5935 // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)). 6596 // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
5936 if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])) 6597 if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
5937 { 6598 {
5938 int j; 6599 int j;
5939 for (j = 1; j < test.Length; j++) 6600 for (j = 1; j < test.Length; j++)
5940 if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))) 6601 {
6602 needle = llGetListEntryType(test, j).value;
6603 haystack = llGetListEntryType(src, i+j).value;
6604
6605 if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
5941 break; 6606 break;
6607 }
5942 6608
5943 if (j == test.Length) 6609 if (j == test.Length)
5944 { 6610 {
@@ -6087,6 +6753,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6087 flags |= ScriptBaseClass.AGENT_AWAY; 6753 flags |= ScriptBaseClass.AGENT_AWAY;
6088 } 6754 }
6089 6755
6756 UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
6757 UUID[] anims = agent.Animator.GetAnimationArray();
6758 if (Array.Exists<UUID>(anims, a => { return a == busy; }))
6759 {
6760 flags |= ScriptBaseClass.AGENT_BUSY;
6761 }
6762
6090 // seems to get unset, even if in mouselook, when avatar is sitting on a prim??? 6763 // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
6091 if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) 6764 if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
6092 { 6765 {
@@ -6134,6 +6807,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6134 flags |= ScriptBaseClass.AGENT_SITTING; 6807 flags |= ScriptBaseClass.AGENT_SITTING;
6135 } 6808 }
6136 6809
6810 if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
6811 {
6812 flags |= ScriptBaseClass.AGENT_MALE;
6813 }
6814
6137 return flags; 6815 return flags;
6138 } 6816 }
6139 6817
@@ -6288,9 +6966,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6288 6966
6289 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6967 List<SceneObjectPart> parts = GetLinkParts(linknumber);
6290 6968
6291 foreach (SceneObjectPart part in parts) 6969 try
6970 {
6971 foreach (SceneObjectPart part in parts)
6972 {
6973 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6974 }
6975 }
6976 finally
6292 { 6977 {
6293 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6294 } 6978 }
6295 } 6979 }
6296 6980
@@ -6344,13 +7028,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6344 7028
6345 if (m_host.OwnerID == land.LandData.OwnerID) 7029 if (m_host.OwnerID == land.LandData.OwnerID)
6346 { 7030 {
6347 World.TeleportClientHome(agentID, presence.ControllingClient); 7031 Vector3 p = World.GetNearestAllowedPosition(presence, land);
7032 presence.TeleportWithMomentum(p, null);
7033 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6348 } 7034 }
6349 } 7035 }
6350 } 7036 }
6351 ScriptSleep(m_sleepMsOnEjectFromLand); 7037 ScriptSleep(m_sleepMsOnEjectFromLand);
6352 } 7038 }
6353 7039
7040 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
7041 {
7042 return ParseString2List(str, separators, in_spacers, false);
7043 }
7044
6354 public LSL_Integer llOverMyLand(string id) 7045 public LSL_Integer llOverMyLand(string id)
6355 { 7046 {
6356 m_host.AddScriptLPS(1); 7047 m_host.AddScriptLPS(1);
@@ -6403,26 +7094,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6403 } 7094 }
6404 else 7095 else
6405 { 7096 {
6406 agentSize = GetAgentSize(avatar); 7097// agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
7098 Vector3 s = avatar.Appearance.AvatarSize;
7099 agentSize = new LSL_Vector(s.X, s.Y, s.Z);
6407 } 7100 }
6408
6409 return agentSize; 7101 return agentSize;
6410 } 7102 }
6411 7103
6412 public LSL_Integer llSameGroup(string agent) 7104 public LSL_Integer llSameGroup(string id)
6413 { 7105 {
6414 m_host.AddScriptLPS(1); 7106 m_host.AddScriptLPS(1);
6415 UUID agentId = new UUID(); 7107 UUID uuid = new UUID();
6416 if (!UUID.TryParse(agent, out agentId)) 7108 if (!UUID.TryParse(id, out uuid))
6417 return new LSL_Integer(0);
6418 ScenePresence presence = World.GetScenePresence(agentId);
6419 if (presence == null || presence.IsChildAgent) // Return flase for child agents
6420 return new LSL_Integer(0); 7109 return new LSL_Integer(0);
6421 IClientAPI client = presence.ControllingClient; 7110
6422 if (m_host.GroupID == client.ActiveGroupId) 7111 // Check if it's a group key
7112 if (uuid == m_host.ParentGroup.RootPart.GroupID)
6423 return new LSL_Integer(1); 7113 return new LSL_Integer(1);
6424 else 7114
7115 // We got passed a UUID.Zero
7116 if (uuid == UUID.Zero)
7117 return new LSL_Integer(0);
7118
7119 // Handle the case where id names an avatar
7120 ScenePresence presence = World.GetScenePresence(uuid);
7121 if (presence != null)
7122 {
7123 if (presence.IsChildAgent)
7124 return new LSL_Integer(0);
7125
7126 IClientAPI client = presence.ControllingClient;
7127 if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
7128 return new LSL_Integer(1);
7129
7130 return new LSL_Integer(0);
7131 }
7132
7133 // Handle object case
7134 SceneObjectPart part = World.GetSceneObjectPart(uuid);
7135 if (part != null)
7136 {
7137 // This will handle both deed and non-deed and also the no
7138 // group case
7139 if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
7140 return new LSL_Integer(1);
7141
6425 return new LSL_Integer(0); 7142 return new LSL_Integer(0);
7143 }
7144
7145 return new LSL_Integer(0);
6426 } 7146 }
6427 7147
6428 public void llUnSit(string id) 7148 public void llUnSit(string id)
@@ -7236,6 +7956,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7236 7956
7237 protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot) 7957 protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
7238 { 7958 {
7959 // LSL quaternions can normalize to 0, normal Quaternions can't.
7960 if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
7961 rot.s = 1; // ZERO_ROTATION = 0,0,0,1
7962
7239 part.SitTargetPosition = offset; 7963 part.SitTargetPosition = offset;
7240 part.SitTargetOrientation = rot; 7964 part.SitTargetOrientation = rot;
7241 part.ParentGroup.HasGroupChanged = true; 7965 part.ParentGroup.HasGroupChanged = true;
@@ -7290,7 +8014,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7290 UUID key; 8014 UUID key;
7291 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 8015 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
7292 8016
7293 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) 8017 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
7294 { 8018 {
7295 int expires = 0; 8019 int expires = 0;
7296 if (hours != 0) 8020 if (hours != 0)
@@ -7428,11 +8152,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7428 UUID av = new UUID(); 8152 UUID av = new UUID();
7429 if (!UUID.TryParse(avatar,out av)) 8153 if (!UUID.TryParse(avatar,out av))
7430 { 8154 {
8155<<<<<<< HEAD
7431 Error("llDialog", "First parameter must be a key"); 8156 Error("llDialog", "First parameter must be a key");
8157=======
8158 //LSLError("First parameter to llDialog needs to be a key");
8159>>>>>>> avn/ubitvar
7432 return; 8160 return;
7433 } 8161 }
7434 if (buttons.Length < 1) 8162 if (buttons.Length < 1)
7435 { 8163 {
8164<<<<<<< HEAD
7436 Error("llDialog", "At least 1 button must be shown"); 8165 Error("llDialog", "At least 1 button must be shown");
7437 return; 8166 return;
7438 } 8167 }
@@ -7440,18 +8169,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7440 { 8169 {
7441 Error("llDialog", "No more than 12 buttons can be shown"); 8170 Error("llDialog", "No more than 12 buttons can be shown");
7442 return; 8171 return;
8172=======
8173 buttons.Add("OK");
7443 } 8174 }
7444 string[] buts = new string[buttons.Length]; 8175 if (buttons.Length > 12)
7445 for (int i = 0; i < buttons.Length; i++) 8176 {
8177 ShoutError("button list too long, must be 12 or fewer entries");
8178>>>>>>> avn/ubitvar
8179 }
8180 int length = buttons.Length;
8181 if (length > 12)
8182 length = 12;
8183
8184 string[] buts = new string[length];
8185 for (int i = 0; i < length; i++)
7446 { 8186 {
7447 if (buttons.Data[i].ToString() == String.Empty) 8187 if (buttons.Data[i].ToString() == String.Empty)
7448 { 8188 {
8189<<<<<<< HEAD
7449 Error("llDialog", "Button label cannot be blank"); 8190 Error("llDialog", "Button label cannot be blank");
8191=======
8192 ShoutError("button label cannot be blank");
8193>>>>>>> avn/ubitvar
7450 return; 8194 return;
7451 } 8195 }
7452 if (buttons.Data[i].ToString().Length > 24) 8196 if (buttons.Data[i].ToString().Length > 24)
7453 { 8197 {
8198<<<<<<< HEAD
7454 Error("llDialog", "Button label cannot be longer than 24 characters"); 8199 Error("llDialog", "Button label cannot be longer than 24 characters");
8200=======
8201 ShoutError("button label cannot be longer than 24 characters");
8202>>>>>>> avn/ubitvar
7455 return; 8203 return;
7456 } 8204 }
7457 buts[i] = buttons.Data[i].ToString(); 8205 buts[i] = buttons.Data[i].ToString();
@@ -7513,9 +8261,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7513 return; 8261 return;
7514 } 8262 }
7515 8263
7516 // the rest of the permission checks are done in RezScript, so check the pin there as well 8264 SceneObjectPart dest = World.GetSceneObjectPart(destId);
7517 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param); 8265 if (dest != null)
8266 {
8267 if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
8268 {
8269 // the rest of the permission checks are done in RezScript, so check the pin there as well
8270 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
7518 8271
8272 if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
8273 m_host.Inventory.RemoveInventoryItem(item.ItemID);
8274 }
8275 }
7519 // this will cause the delay even if the script pin or permissions were wrong - seems ok 8276 // this will cause the delay even if the script pin or permissions were wrong - seems ok
7520 ScriptSleep(m_sleepMsOnRemoteLoadScriptPin); 8277 ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
7521 } 8278 }
@@ -7589,19 +8346,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7589 public LSL_String llMD5String(string src, int nonce) 8346 public LSL_String llMD5String(string src, int nonce)
7590 { 8347 {
7591 m_host.AddScriptLPS(1); 8348 m_host.AddScriptLPS(1);
7592 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 8349 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
7593 } 8350 }
7594 8351
7595 public LSL_String llSHA1String(string src) 8352 public LSL_String llSHA1String(string src)
7596 { 8353 {
7597 m_host.AddScriptLPS(1); 8354 m_host.AddScriptLPS(1);
7598 return Util.SHA1Hash(src).ToLower(); 8355 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
7599 } 8356 }
7600 8357
7601 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) 8358 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
7602 { 8359 {
7603 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 8360 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
7604 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 8361 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
8362 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8363 return shapeBlock;
7605 8364
7606 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 8365 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
7607 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 8366 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -7706,6 +8465,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7706 // Prim type box, cylinder and prism. 8465 // Prim type box, cylinder and prism.
7707 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve) 8466 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve)
7708 { 8467 {
8468 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8469 return;
8470
7709 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 8471 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
7710 ObjectShapePacket.ObjectDataBlock shapeBlock; 8472 ObjectShapePacket.ObjectDataBlock shapeBlock;
7711 8473
@@ -7759,6 +8521,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7759 // Prim type sphere. 8521 // Prim type sphere.
7760 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) 8522 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
7761 { 8523 {
8524 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8525 return;
8526
7762 ObjectShapePacket.ObjectDataBlock shapeBlock; 8527 ObjectShapePacket.ObjectDataBlock shapeBlock;
7763 8528
7764 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); 8529 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
@@ -7805,6 +8570,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7805 // Prim type torus, tube and ring. 8570 // Prim type torus, tube and ring.
7806 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve) 8571 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve)
7807 { 8572 {
8573 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8574 return;
8575
7808 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 8576 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
7809 ObjectShapePacket.ObjectDataBlock shapeBlock; 8577 ObjectShapePacket.ObjectDataBlock shapeBlock;
7810 8578
@@ -7940,6 +8708,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7940 // Prim type sculpt. 8708 // Prim type sculpt.
7941 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) 8709 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
7942 { 8710 {
8711 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8712 return;
8713
7943 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 8714 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7944 UUID sculptId; 8715 UUID sculptId;
7945 8716
@@ -7962,7 +8733,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7962 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag)) 8733 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
7963 { 8734 {
7964 // default 8735 // default
7965 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 8736 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7966 } 8737 }
7967 8738
7968 part.Shape.SetSculptProperties((byte)type, sculptId); 8739 part.Shape.SetSculptProperties((byte)type, sculptId);
@@ -7979,6 +8750,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7979 ScriptSleep(m_sleepMsOnSetPrimitiveParams); 8750 ScriptSleep(m_sleepMsOnSetPrimitiveParams);
7980 } 8751 }
7981 8752
8753<<<<<<< HEAD
7982 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 8754 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7983 { 8755 {
7984 m_host.AddScriptLPS(1); 8756 m_host.AddScriptLPS(1);
@@ -7988,6 +8760,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7988 ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams); 8760 ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
7989 } 8761 }
7990 8762
8763=======
8764>>>>>>> avn/ubitvar
7991 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 8765 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
7992 { 8766 {
7993 m_host.AddScriptLPS(1); 8767 m_host.AddScriptLPS(1);
@@ -7995,16 +8769,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7995 SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast"); 8769 SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
7996 } 8770 }
7997 8771
8772<<<<<<< HEAD
7998 protected void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc) 8773 protected void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
7999 { 8774 {
8000 SetEntityParams(GetLinkEntities(linknumber), rules, originFunc); 8775 SetEntityParams(GetLinkEntities(linknumber), rules, originFunc);
8001 } 8776 }
8777=======
8778 private void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
8779 {
8780 List<object> parts = new List<object>();
8781 List<SceneObjectPart> prims = GetLinkParts(linknumber);
8782 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
8783 foreach (SceneObjectPart p in prims)
8784 parts.Add(p);
8785 foreach (ScenePresence p in avatars)
8786 parts.Add(p);
8787>>>>>>> avn/ubitvar
8002 8788
8003 protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc) 8789 protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc)
8004 { 8790 {
8005 LSL_List remaining = new LSL_List(); 8791 LSL_List remaining = new LSL_List();
8006 uint rulesParsed = 0; 8792 uint rulesParsed = 0;
8007 8793
8794<<<<<<< HEAD
8008 foreach (ISceneEntity entity in entities) 8795 foreach (ISceneEntity entity in entities)
8009 { 8796 {
8010 if (entity is SceneObjectPart) 8797 if (entity is SceneObjectPart)
@@ -8049,138 +8836,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8049 return; 8836 return;
8050 8837
8051 if (frames.Data.Length > 0) // We are getting a new motion 8838 if (frames.Data.Length > 0) // We are getting a new motion
8839=======
8840 if (parts.Count > 0)
8841>>>>>>> avn/ubitvar
8052 { 8842 {
8053 if (group.RootPart.KeyframeMotion != null) 8843 foreach (object part in parts)
8054 group.RootPart.KeyframeMotion.Delete();
8055 group.RootPart.KeyframeMotion = null;
8056
8057 int idx = 0;
8058
8059 KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
8060 KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
8061
8062 while (idx < options.Data.Length)
8063 { 8844 {
8064 int option = (int)options.GetLSLIntegerItem(idx++); 8845 if (part is SceneObjectPart)
8065 int remain = options.Data.Length - idx; 8846 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
8847 else
8848 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
8849 }
8066 8850
8067 switch (option) 8851 while ((object)remaining != null && remaining.Length > 2)
8852 {
8853 linknumber = remaining.GetLSLIntegerItem(0);
8854 rules = remaining.GetSublist(1, -1);
8855 parts.Clear();
8856 prims = GetLinkParts(linknumber);
8857 avatars = GetLinkAvatars(linknumber);
8858 foreach (SceneObjectPart p in prims)
8859 parts.Add(p);
8860 foreach (ScenePresence p in avatars)
8861 parts.Add(p);
8862
8863 remaining = null;
8864 foreach (object part in parts)
8068 { 8865 {
8069 case ScriptBaseClass.KFM_MODE: 8866 if (part is SceneObjectPart)
8070 if (remain < 1) 8867 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
8071 break; 8868 else
8072 int modeval = (int)options.GetLSLIntegerItem(idx++); 8869 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
8073 switch(modeval)
8074 {
8075 case ScriptBaseClass.KFM_FORWARD:
8076 mode = KeyframeMotion.PlayMode.Forward;
8077 break;
8078 case ScriptBaseClass.KFM_REVERSE:
8079 mode = KeyframeMotion.PlayMode.Reverse;
8080 break;
8081 case ScriptBaseClass.KFM_LOOP:
8082 mode = KeyframeMotion.PlayMode.Loop;
8083 break;
8084 case ScriptBaseClass.KFM_PING_PONG:
8085 mode = KeyframeMotion.PlayMode.PingPong;
8086 break;
8087 }
8088 break;
8089 case ScriptBaseClass.KFM_DATA:
8090 if (remain < 1)
8091 break;
8092 int dataval = (int)options.GetLSLIntegerItem(idx++);
8093 data = (KeyframeMotion.DataFormat)dataval;
8094 break;
8095 } 8870 }
8096 } 8871 }
8872 }
8873 }
8097 8874
8098 group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data); 8875 public LSL_List llGetPhysicsMaterial()
8876 {
8877 LSL_List result = new LSL_List();
8099 8878
8100 idx = 0; 8879 result.Add(new LSL_Float(m_host.GravityModifier));
8880 result.Add(new LSL_Float(m_host.Restitution));
8881 result.Add(new LSL_Float(m_host.Friction));
8882 result.Add(new LSL_Float(m_host.Density));
8101 8883
8102 int elemLength = 2; 8884 return result;
8103 if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation)) 8885 }
8104 elemLength = 3;
8105 8886
8106 List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>(); 8887 private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
8107 while (idx < frames.Data.Length) 8888 float material_density, float material_friction,
8108 { 8889 float material_restitution, float material_gravity_modifier)
8109 int remain = frames.Data.Length - idx; 8890 {
8891 ExtraPhysicsData physdata = new ExtraPhysicsData();
8892 physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
8893 physdata.Density = part.Density;
8894 physdata.Friction = part.Friction;
8895 physdata.Bounce = part.Restitution;
8896 physdata.GravitationModifier = part.GravityModifier;
8110 8897
8111 if (remain < elemLength) 8898 if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
8112 break; 8899 physdata.Density = material_density;
8900 if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
8901 physdata.Friction = material_friction;
8902 if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
8903 physdata.Bounce = material_restitution;
8904 if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
8905 physdata.GravitationModifier = material_gravity_modifier;
8113 8906
8114 KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe(); 8907 part.UpdateExtraPhysics(physdata);
8115 frame.Position = null; 8908 }
8116 frame.Rotation = null;
8117 8909
8118 if ((data & KeyframeMotion.DataFormat.Translation) != 0) 8910 public void llSetPhysicsMaterial(int material_bits,
8119 { 8911 float material_gravity_modifier, float material_restitution,
8120 LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++); 8912 float material_friction, float material_density)
8121 frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z); 8913 {
8122 } 8914 SetPhysicsMaterial(m_host, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
8123 if ((data & KeyframeMotion.DataFormat.Rotation) != 0) 8915 }
8124 {
8125 LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
8126 Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
8127 q.Normalize();
8128 frame.Rotation = q;
8129 }
8130 8916
8131 float tempf = (float)frames.GetLSLFloatItem(idx++); 8917 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
8132 frame.TimeMS = (int)(tempf * 1000.0f); 8918 {
8919 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
8920 llSetLinkPrimitiveParamsFast(linknumber, rules);
8921 ScriptSleep(200);
8922 }
8133 8923
8134 keyframes.Add(frame); 8924 // vector up using libomv (c&p from sop )
8135 } 8925 // vector up rotated by r
8926 private Vector3 Zrot(Quaternion r)
8927 {
8928 double x, y, z, m;
8136 8929
8137 group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray()); 8930 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
8138 group.RootPart.KeyframeMotion.Start(); 8931 if (Math.Abs(1.0 - m) > 0.000001)
8139 }
8140 else
8141 { 8932 {
8142 if (group.RootPart.KeyframeMotion == null) 8933 m = 1.0 / Math.Sqrt(m);
8143 return; 8934 r.X *= (float)m;
8144 8935 r.Y *= (float)m;
8145 if (options.Data.Length == 0) 8936 r.Z *= (float)m;
8146 { 8937 r.W *= (float)m;
8147 group.RootPart.KeyframeMotion.Stop(); 8938 }
8148 return;
8149 }
8150
8151 int idx = 0;
8152 8939
8153 while (idx < options.Data.Length) 8940 x = 2 * (r.X * r.Z + r.Y * r.W);
8154 { 8941 y = 2 * (-r.X * r.W + r.Y * r.Z);
8155 int option = (int)options.GetLSLIntegerItem(idx++); 8942 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
8156 8943
8157 switch (option) 8944 return new Vector3((float)x, (float)y, (float)z);
8158 {
8159 case ScriptBaseClass.KFM_COMMAND:
8160 int cmd = (int)options.GetLSLIntegerItem(idx++);
8161 switch (cmd)
8162 {
8163 case ScriptBaseClass.KFM_CMD_PLAY:
8164 group.RootPart.KeyframeMotion.Start();
8165 break;
8166 case ScriptBaseClass.KFM_CMD_STOP:
8167 group.RootPart.KeyframeMotion.Stop();
8168 break;
8169 case ScriptBaseClass.KFM_CMD_PAUSE:
8170 group.RootPart.KeyframeMotion.Pause();
8171 break;
8172 }
8173 break;
8174 }
8175 }
8176 }
8177 } 8945 }
8178 8946
8179 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed) 8947 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
8180 { 8948 {
8949 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8950 return null;
8951
8181 int idx = 0; 8952 int idx = 0;
8182 int idxStart = 0; 8953 int idxStart = 0;
8183 8954
8955 SceneObjectGroup parentgrp = part.ParentGroup;
8956
8184 bool positionChanged = false; 8957 bool positionChanged = false;
8185 LSL_Vector currentPosition = GetPartLocalPos(part); 8958 LSL_Vector currentPosition = GetPartLocalPos(part);
8186 8959
@@ -8204,6 +8977,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8204 if (remain < 1) 8977 if (remain < 1)
8205 return new LSL_List(); 8978 return new LSL_List();
8206 8979
8980<<<<<<< HEAD
8207 try 8981 try
8208 { 8982 {
8209 v = rules.GetVector3Item(idx++); 8983 v = rules.GetVector3Item(idx++);
@@ -8216,8 +8990,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8216 Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1)); 8990 Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
8217 return new LSL_List(); 8991 return new LSL_List();
8218 } 8992 }
8993=======
8994 v=rules.GetVector3Item(idx++);
8995 if (part.IsRoot && !part.ParentGroup.IsAttachment)
8996 currentPosition = GetSetPosTarget(part, v, currentPosition, true);
8997 else
8998 currentPosition = GetSetPosTarget(part, v, currentPosition, false);
8999>>>>>>> avn/ubitvar
8219 positionChanged = true; 9000 positionChanged = true;
8220 currentPosition = GetSetPosTarget(part, v, currentPosition);
8221 9001
8222 break; 9002 break;
8223 case ScriptBaseClass.PRIM_SIZE: 9003 case ScriptBaseClass.PRIM_SIZE:
@@ -8242,7 +9022,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8242 return new LSL_List(); 9022 return new LSL_List();
8243 } 9023 }
8244 // try to let this work as in SL... 9024 // try to let this work as in SL...
8245 if (part.ParentID == 0) 9025 if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
8246 { 9026 {
8247 // special case: If we are root, rotate complete SOG to new rotation 9027 // special case: If we are root, rotate complete SOG to new rotation
8248 SetRot(part, q); 9028 SetRot(part, q);
@@ -9243,7 +10023,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9243 10023
9244 break; 10024 break;
9245 10025
10026<<<<<<< HEAD
9246 case ScriptBaseClass.PRIM_TEMP_ON_REZ: 10027 case ScriptBaseClass.PRIM_TEMP_ON_REZ:
10028=======
10029 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
10030 if (remain < 5)
10031 return null;
10032
10033 int material_bits = rules.GetLSLIntegerItem(idx++);
10034 float material_density = (float)rules.GetLSLFloatItem(idx++);
10035 float material_friction = (float)rules.GetLSLFloatItem(idx++);
10036 float material_restitution = (float)rules.GetLSLFloatItem(idx++);
10037 float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
10038
10039 SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
10040
10041 break;
10042
10043 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
10044>>>>>>> avn/ubitvar
9247 if (remain < 1) 10045 if (remain < 1)
9248 return new LSL_List(); 10046 return new LSL_List();
9249 string temp = rules.Data[idx++].ToString(); 10047 string temp = rules.Data[idx++].ToString();
@@ -9437,14 +10235,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9437 if (part.ParentGroup.RootPart == part) 10235 if (part.ParentGroup.RootPart == part)
9438 { 10236 {
9439 SceneObjectGroup parent = part.ParentGroup; 10237 SceneObjectGroup parent = part.ParentGroup;
9440 parent.UpdateGroupPosition(currentPosition); 10238 Util.FireAndForget(delegate(object x) {
10239 parent.UpdateGroupPosition(currentPosition);
10240 });
9441 } 10241 }
9442 else 10242 else
9443 { 10243 {
9444 part.OffsetPosition = currentPosition; 10244 part.OffsetPosition = currentPosition;
9445 SceneObjectGroup parent = part.ParentGroup; 10245// SceneObjectGroup parent = part.ParentGroup;
9446 parent.HasGroupChanged = true; 10246// parent.HasGroupChanged = true;
9447 parent.ScheduleGroupForTerseUpdate(); 10247// parent.ScheduleGroupForTerseUpdate();
10248 part.ScheduleTerseUpdate();
9448 } 10249 }
9449 } 10250 }
9450 } 10251 }
@@ -9596,10 +10397,111 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9596 10397
9597 public LSL_String llXorBase64Strings(string str1, string str2) 10398 public LSL_String llXorBase64Strings(string str1, string str2)
9598 { 10399 {
10400<<<<<<< HEAD
9599 m_host.AddScriptLPS(1); 10401 m_host.AddScriptLPS(1);
9600 Deprecated("llXorBase64Strings", "Use llXorBase64 instead"); 10402 Deprecated("llXorBase64Strings", "Use llXorBase64 instead");
9601 ScriptSleep(m_sleepMsOnXorBase64Strings); 10403 ScriptSleep(m_sleepMsOnXorBase64Strings);
9602 return String.Empty; 10404 return String.Empty;
10405=======
10406 int padding = 0;
10407
10408 string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10409
10410 ScriptSleep(300);
10411 m_host.AddScriptLPS(1);
10412
10413 if (str1 == String.Empty)
10414 return String.Empty;
10415 if (str2 == String.Empty)
10416 return str1;
10417
10418 int len = str2.Length;
10419 if ((len % 4) != 0) // LL is EVIL!!!!
10420 {
10421 while (str2.EndsWith("="))
10422 str2 = str2.Substring(0, str2.Length - 1);
10423
10424 len = str2.Length;
10425 int mod = len % 4;
10426
10427 if (mod == 1)
10428 str2 = str2.Substring(0, str2.Length - 1);
10429 else if (mod == 2)
10430 str2 += "==";
10431 else if (mod == 3)
10432 str2 += "=";
10433 }
10434
10435 byte[] data1;
10436 byte[] data2;
10437 try
10438 {
10439 data1 = Convert.FromBase64String(str1);
10440 data2 = Convert.FromBase64String(str2);
10441 }
10442 catch (Exception)
10443 {
10444 return new LSL_String(String.Empty);
10445 }
10446
10447 // For cases where the decoded length of s2 is greater
10448 // than the decoded length of s1, simply perform a normal
10449 // decode and XOR
10450 //
10451 /*
10452 if (data2.Length >= data1.Length)
10453 {
10454 for (int pos = 0 ; pos < data1.Length ; pos++ )
10455 data1[pos] ^= data2[pos];
10456
10457 return Convert.ToBase64String(data1);
10458 }
10459 */
10460
10461 // Remove padding
10462 while (str1.EndsWith("="))
10463 {
10464 str1 = str1.Substring(0, str1.Length - 1);
10465 padding++;
10466 }
10467 while (str2.EndsWith("="))
10468 str2 = str2.Substring(0, str2.Length - 1);
10469
10470 byte[] d1 = new byte[str1.Length];
10471 byte[] d2 = new byte[str2.Length];
10472
10473 for (int i = 0 ; i < str1.Length ; i++)
10474 {
10475 int idx = b64.IndexOf(str1.Substring(i, 1));
10476 if (idx == -1)
10477 idx = 0;
10478 d1[i] = (byte)idx;
10479 }
10480
10481 for (int i = 0 ; i < str2.Length ; i++)
10482 {
10483 int idx = b64.IndexOf(str2.Substring(i, 1));
10484 if (idx == -1)
10485 idx = 0;
10486 d2[i] = (byte)idx;
10487 }
10488
10489 string output = String.Empty;
10490
10491 for (int pos = 0 ; pos < d1.Length ; pos++)
10492 output += b64[d1[pos] ^ d2[pos % d2.Length]];
10493
10494 // Here's a funny thing: LL blithely violate the base64
10495 // standard pretty much everywhere. Here, padding is
10496 // added only if the first input string had it, rather
10497 // than when the data actually needs it. This can result
10498 // in invalid base64 being returned. Go figure.
10499
10500 while (padding-- > 0)
10501 output += "=";
10502
10503 return output;
10504>>>>>>> avn/ubitvar
9603 } 10505 }
9604 10506
9605 public void llRemoteDataSetRegion() 10507 public void llRemoteDataSetRegion()
@@ -9724,8 +10626,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9724 public LSL_Integer llGetNumberOfPrims() 10626 public LSL_Integer llGetNumberOfPrims()
9725 { 10627 {
9726 m_host.AddScriptLPS(1); 10628 m_host.AddScriptLPS(1);
9727 10629 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
9728 return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount(); 10630
10631 return m_host.ParentGroup.PrimCount + avatarCount;
9729 } 10632 }
9730 10633
9731 /// <summary> 10634 /// <summary>
@@ -9770,10 +10673,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9770 10673
9771 // Initialize but break if no target 10674 // Initialize but break if no target
9772 LSL_List result = new LSL_List(); 10675 LSL_List result = new LSL_List();
10676<<<<<<< HEAD
9773 int groupCount = 0; 10677 int groupCount = 0;
9774 int partCount = 0; 10678 int partCount = 0;
9775 int vertexCount = 0; 10679 int vertexCount = 0;
9776 if (target == null && agent == null) 10680 if (target == null && agent == null)
10681=======
10682
10683 // If the ID is not valid, return null result
10684 if (!UUID.TryParse(obj, out objID))
10685>>>>>>> avn/ubitvar
9777 { 10686 {
9778 result.Add(new LSL_Vector()); 10687 result.Add(new LSL_Vector());
9779 result.Add(new LSL_Vector()); 10688 result.Add(new LSL_Vector());
@@ -9781,6 +10690,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9781 result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount)); 10690 result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount));
9782 return result; 10691 return result;
9783 } 10692 }
10693<<<<<<< HEAD
9784 Vector3 minPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); 10694 Vector3 minPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
9785 Vector3 maxPosition = new Vector3(float.MinValue, float.MinValue, float.MinValue); 10695 Vector3 maxPosition = new Vector3(float.MinValue, float.MinValue, float.MinValue);
9786 10696
@@ -9901,10 +10811,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9901 if (m_useSimpleBoxesInGetBoundingBox || primMesher == null) 10811 if (m_useSimpleBoxesInGetBoundingBox || primMesher == null)
9902 { 10812 {
9903 AddBoundingBoxOfSimpleBox(lower, upper, offset, sp.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount); 10813 AddBoundingBoxOfSimpleBox(lower, upper, offset, sp.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
10814=======
10815
10816 // Check if this is an attached prim. If so, replace
10817 // the UUID with the avatar UUID and report it's bounding box
10818 SceneObjectPart part = World.GetSceneObjectPart(objID);
10819 if (part != null && part.ParentGroup.IsAttachment)
10820 objID = part.ParentGroup.AttachedAvatar;
10821
10822 // Find out if this is an avatar ID. If so, return it's box
10823 ScenePresence presence = World.GetScenePresence(objID);
10824 if (presence != null)
10825 {
10826 // As per LSL Wiki, there is no difference between sitting
10827 // and standing avatar since server 1.36
10828 LSL_Vector lower;
10829 LSL_Vector upper;
10830
10831 Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
10832
10833 if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
10834 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
10835/*
10836 {
10837 // This is for ground sitting avatars
10838 float height = presence.Appearance.AvatarHeight / 2.66666667f;
10839 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
10840 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
10841 }
10842 else
10843 {
10844 // This is for standing/flying avatars
10845 float height = presence.Appearance.AvatarHeight / 2.0f;
10846 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
10847 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
10848 }
10849
10850 // Adjust to the documented error offsets (see LSL Wiki)
10851 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
10852 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
10853*/
10854 {
10855 // This is for ground sitting avatars TODO!
10856 lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
10857 upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
10858>>>>>>> avn/ubitvar
9904 } 10859 }
9905 // Do the full mounty 10860 // Do the full mounty
9906 else 10861 else
9907 { 10862 {
10863<<<<<<< HEAD
9908 // Prim shapes don't do center offsets, so add it here. 10864 // Prim shapes don't do center offsets, so add it here.
9909 offset = offset + (lower + upper) * 0.5f * sp.Rotation; 10865 offset = offset + (lower + upper) * 0.5f * sp.Rotation;
9910 Primitive omvPrim = MakeOpenMetaversePrim(upper - lower, offset, sp.Rotation, ScriptBaseClass.PRIM_TYPE_SPHERE); 10866 Primitive omvPrim = MakeOpenMetaversePrim(upper - lower, offset, sp.Rotation, ScriptBaseClass.PRIM_TYPE_SPHERE);
@@ -9960,6 +10916,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9960 { 10916 {
9961 lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height); 10917 lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
9962 upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height); 10918 upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
10919=======
10920 // This is for standing/flying avatars
10921 lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
10922 upper = new LSL_Vector(box.X, box.Y, box.Z);
10923 }
10924
10925 if (lower.x > upper.x)
10926 lower.x = upper.x;
10927 if (lower.y > upper.y)
10928 lower.y = upper.y;
10929 if (lower.z > upper.z)
10930 lower.z = upper.z;
10931
10932 result.Add(lower);
10933 result.Add(upper);
10934 return result;
10935 }
10936
10937 part = World.GetSceneObjectPart(objID);
10938 // Currently only works for single prims without a sitting avatar
10939 if (part != null)
10940 {
10941 float minX;
10942 float maxX;
10943 float minY;
10944 float maxY;
10945 float minZ;
10946 float maxZ;
10947
10948 // This BBox is in sim coordinates, with the offset being
10949 // a contained point.
10950 Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
10951 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
10952
10953 minX -= offsets[0].X;
10954 maxX -= offsets[0].X;
10955 minY -= offsets[0].Y;
10956 maxY -= offsets[0].Y;
10957 minZ -= offsets[0].Z;
10958 maxZ -= offsets[0].Z;
10959
10960 LSL_Vector lower;
10961 LSL_Vector upper;
10962
10963 // Adjust to the documented error offsets (see LSL Wiki)
10964 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
10965 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
10966
10967 if (lower.x > upper.x)
10968 lower.x = upper.x;
10969 if (lower.y > upper.y)
10970 lower.y = upper.y;
10971 if (lower.z > upper.z)
10972 lower.z = upper.z;
10973
10974 result.Add(lower);
10975 result.Add(upper);
10976 return result;
10977>>>>>>> avn/ubitvar
9963 } 10978 }
9964 } 10979 }
9965 10980
@@ -10166,8 +11181,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10166 return new LSL_Vector(offset); 11181 return new LSL_Vector(offset);
10167 } 11182 }
10168 11183
10169 public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules) 11184 public LSL_List llGetPrimitiveParams(LSL_List rules)
10170 { 11185 {
11186<<<<<<< HEAD
10171 LSL_List result = new LSL_List(); 11187 LSL_List result = new LSL_List();
10172 LSL_List remaining; 11188 LSL_List remaining;
10173 11189
@@ -10179,57 +11195,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10179 11195
10180 if (entity == null) 11196 if (entity == null)
10181 return result; 11197 return result;
11198=======
11199 m_host.AddScriptLPS(1);
11200>>>>>>> avn/ubitvar
10182 11201
10183 if (entity is SceneObjectPart) 11202 LSL_List result = new LSL_List();
10184 remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
10185 else
10186 remaining = GetAgentParams((ScenePresence)entity, rules, ref result);
10187 11203
10188 if (remaining == null || remaining.Length < 2) 11204 LSL_List remaining = GetPrimParams(m_host, rules, ref result);
10189 return result;
10190 11205
11206 while ((object)remaining != null && remaining.Length > 2)
11207 {
10191 int linknumber = remaining.GetLSLIntegerItem(0); 11208 int linknumber = remaining.GetLSLIntegerItem(0);
10192 rules = remaining.GetSublist(1, -1); 11209 rules = remaining.GetSublist(1, -1);
11210<<<<<<< HEAD
10193 entity = GetLinkEntity(m_host, linknumber); 11211 entity = GetLinkEntity(m_host, linknumber);
10194 } 11212 }
10195 } 11213 }
11214=======
11215 List<SceneObjectPart> parts = GetLinkParts(linknumber);
11216>>>>>>> avn/ubitvar
10196 11217
10197 public LSL_List llGetPrimitiveParams(LSL_List rules) 11218 foreach (SceneObjectPart part in parts)
10198 { 11219 remaining = GetPrimParams(part, rules, ref result);
10199 m_host.AddScriptLPS(1); 11220 }
10200 11221
10201 return GetEntityParams(m_host, rules); 11222 return result;
10202 } 11223 }
10203 11224
10204 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules) 11225 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
10205 { 11226 {
10206 m_host.AddScriptLPS(1); 11227 m_host.AddScriptLPS(1);
10207 11228
11229<<<<<<< HEAD
10208 return GetEntityParams(GetLinkEntity(m_host, linknumber), rules); 11230 return GetEntityParams(GetLinkEntity(m_host, linknumber), rules);
10209 } 11231 }
11232=======
11233 // acording to SL wiki this must indicate a single link number or link_root or link_this.
11234 // keep other options as before
11235>>>>>>> avn/ubitvar
10210 11236
10211 public LSL_Vector GetAgentSize(ScenePresence sp) 11237 List<SceneObjectPart> parts;
10212 { 11238 List<ScenePresence> avatars;
10213 return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight); 11239
10214 } 11240 LSL_List res = new LSL_List();
11241 LSL_List remaining = null;
10215 11242
10216 /// <summary> 11243 while (rules.Length > 0)
10217 /// Gets params for a seated avatar in a linkset.
10218 /// </summary>
10219 /// <returns></returns>
10220 /// <param name='sp'></param>
10221 /// <param name='rules'></param>
10222 /// <param name='res'></param>
10223 public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
10224 {
10225 int idx = 0;
10226 while (idx < rules.Length)
10227 { 11244 {
10228 int code = (int)rules.GetLSLIntegerItem(idx++); 11245 parts = GetLinkParts(linknumber);
10229 int remain = rules.Length-idx; 11246 avatars = GetLinkAvatars(linknumber);
10230 11247
10231 switch (code) 11248 remaining = null;
11249 foreach (SceneObjectPart part in parts)
10232 { 11250 {
11251<<<<<<< HEAD
10233 case (int)ScriptBaseClass.PRIM_MATERIAL: 11252 case (int)ScriptBaseClass.PRIM_MATERIAL:
10234 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH)); 11253 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
10235 break; 11254 break;
@@ -10376,17 +11395,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10376 case (int)ScriptBaseClass.PRIM_LINK_TARGET: 11395 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
10377 if(remain < 3) 11396 if(remain < 3)
10378 return new LSL_List(); 11397 return new LSL_List();
11398=======
11399 remaining = GetPrimParams(part, rules, ref res);
11400 }
11401 foreach (ScenePresence avatar in avatars)
11402 {
11403 remaining = GetPrimParams(avatar, rules, ref res);
11404 }
11405>>>>>>> avn/ubitvar
10379 11406
10380 return rules.GetSublist(idx, -1); 11407 if ((object)remaining != null && remaining.Length > 0)
11408 {
11409 linknumber = remaining.GetLSLIntegerItem(0);
11410 rules = remaining.GetSublist(1, -1);
10381 } 11411 }
11412 else
11413 break;
10382 } 11414 }
10383 11415
11416<<<<<<< HEAD
10384 return new LSL_List(); 11417 return new LSL_List();
11418=======
11419 return res;
11420>>>>>>> avn/ubitvar
10385 } 11421 }
10386 11422
10387 public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res) 11423 public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
10388 { 11424 {
10389 int idx = 0; 11425 int idx=0;
10390 while (idx < rules.Length) 11426 while (idx < rules.Length)
10391 { 11427 {
10392 int code = (int)rules.GetLSLIntegerItem(idx++); 11428 int code = (int)rules.GetLSLIntegerItem(idx++);
@@ -10420,19 +11456,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10420 break; 11456 break;
10421 11457
10422 case (int)ScriptBaseClass.PRIM_POSITION: 11458 case (int)ScriptBaseClass.PRIM_POSITION:
10423 LSL_Vector v = new LSL_Vector(part.AbsolutePosition); 11459 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
10424 11460 part.AbsolutePosition.Y,
10425 // For some reason, the part.AbsolutePosition.* values do not change if the 11461 part.AbsolutePosition.Z);
10426 // linkset is rotated; they always reflect the child prim's world position
10427 // as though the linkset is unrotated. This is incompatible behavior with SL's
10428 // implementation, so will break scripts imported from there (not to mention it
10429 // makes it more difficult to determine a child prim's actual inworld position).
10430 if (!part.IsRoot)
10431 {
10432 LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
10433 v = ((v - rootPos) * llGetRootRotation()) + rootPos;
10434 }
10435
10436 res.Add(v); 11462 res.Add(v);
10437 break; 11463 break;
10438 11464
@@ -10606,30 +11632,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10606 if (remain < 1) 11632 if (remain < 1)
10607 return new LSL_List(); 11633 return new LSL_List();
10608 11634
10609 face=(int)rules.GetLSLIntegerItem(idx++); 11635 face = (int)rules.GetLSLIntegerItem(idx++);
10610 11636
10611 tex = part.Shape.Textures; 11637 tex = part.Shape.Textures;
11638 int shiny;
10612 if (face == ScriptBaseClass.ALL_SIDES) 11639 if (face == ScriptBaseClass.ALL_SIDES)
10613 { 11640 {
10614 for (face = 0; face < GetNumberOfSides(part); face++) 11641 for (face = 0; face < GetNumberOfSides(part); face++)
10615 { 11642 {
10616 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 11643 Shininess shinyness = tex.GetFace((uint)face).Shiny;
10617 // Convert Shininess to PRIM_SHINY_* 11644 if (shinyness == Shininess.High)
10618 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 11645 {
10619 // PRIM_BUMP_* 11646 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
10620 res.Add(new LSL_Integer((int)texface.Bump)); 11647 }
11648 else if (shinyness == Shininess.Medium)
11649 {
11650 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
11651 }
11652 else if (shinyness == Shininess.Low)
11653 {
11654 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
11655 }
11656 else
11657 {
11658 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
11659 }
11660 res.Add(new LSL_Integer(shiny));
11661 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
10621 } 11662 }
10622 } 11663 }
10623 else 11664 else
10624 { 11665 {
10625 if (face >= 0 && face < GetNumberOfSides(part)) 11666 Shininess shinyness = tex.GetFace((uint)face).Shiny;
11667 if (shinyness == Shininess.High)
10626 { 11668 {
10627 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 11669 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
10628 // Convert Shininess to PRIM_SHINY_*
10629 res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
10630 // PRIM_BUMP_*
10631 res.Add(new LSL_Integer((int)texface.Bump));
10632 } 11670 }
11671 else if (shinyness == Shininess.Medium)
11672 {
11673 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
11674 }
11675 else if (shinyness == Shininess.Low)
11676 {
11677 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
11678 }
11679 else
11680 {
11681 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
11682 }
11683 res.Add(new LSL_Integer(shiny));
11684 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
10633 } 11685 }
10634 break; 11686 break;
10635 11687
@@ -10640,21 +11692,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10640 face = (int)rules.GetLSLIntegerItem(idx++); 11692 face = (int)rules.GetLSLIntegerItem(idx++);
10641 11693
10642 tex = part.Shape.Textures; 11694 tex = part.Shape.Textures;
11695 int fullbright;
10643 if (face == ScriptBaseClass.ALL_SIDES) 11696 if (face == ScriptBaseClass.ALL_SIDES)
10644 { 11697 {
10645 for (face = 0; face < GetNumberOfSides(part); face++) 11698 for (face = 0; face < GetNumberOfSides(part); face++)
10646 { 11699 {
10647 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 11700 if (tex.GetFace((uint)face).Fullbright == true)
10648 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 11701 {
11702 fullbright = ScriptBaseClass.TRUE;
11703 }
11704 else
11705 {
11706 fullbright = ScriptBaseClass.FALSE;
11707 }
11708 res.Add(new LSL_Integer(fullbright));
10649 } 11709 }
10650 } 11710 }
10651 else 11711 else
10652 { 11712 {
10653 if (face >= 0 && face < GetNumberOfSides(part)) 11713 if (tex.GetFace((uint)face).Fullbright == true)
10654 { 11714 {
10655 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 11715 fullbright = ScriptBaseClass.TRUE;
10656 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 11716 }
11717 else
11718 {
11719 fullbright = ScriptBaseClass.FALSE;
10657 } 11720 }
11721 res.Add(new LSL_Integer(fullbright));
10658 } 11722 }
10659 break; 11723 break;
10660 11724
@@ -10676,27 +11740,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10676 break; 11740 break;
10677 11741
10678 case (int)ScriptBaseClass.PRIM_TEXGEN: 11742 case (int)ScriptBaseClass.PRIM_TEXGEN:
11743 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
10679 if (remain < 1) 11744 if (remain < 1)
10680 return new LSL_List(); 11745 return new LSL_List();
10681 11746
10682 face=(int)rules.GetLSLIntegerItem(idx++); 11747 face = (int)rules.GetLSLIntegerItem(idx++);
10683 11748
10684 tex = part.Shape.Textures; 11749 tex = part.Shape.Textures;
10685 if (face == ScriptBaseClass.ALL_SIDES) 11750 if (face == ScriptBaseClass.ALL_SIDES)
10686 { 11751 {
10687 for (face = 0; face < GetNumberOfSides(part); face++) 11752 for (face = 0; face < GetNumberOfSides(part); face++)
10688 { 11753 {
10689 MappingType texgen = tex.GetFace((uint)face).TexMapType; 11754 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
10690 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 11755 {
10691 res.Add(new LSL_Integer((uint)texgen >> 1)); 11756 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
11757 }
11758 else
11759 {
11760 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
11761 }
10692 } 11762 }
10693 } 11763 }
10694 else 11764 else
10695 { 11765 {
10696 if (face >= 0 && face < GetNumberOfSides(part)) 11766 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
10697 { 11767 {
10698 MappingType texgen = tex.GetFace((uint)face).TexMapType; 11768 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
10699 res.Add(new LSL_Integer((uint)texgen >> 1)); 11769 }
11770 else
11771 {
11772 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
10700 } 11773 }
10701 } 11774 }
10702 break; 11775 break;
@@ -10720,24 +11793,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10720 if (remain < 1) 11793 if (remain < 1)
10721 return new LSL_List(); 11794 return new LSL_List();
10722 11795
10723 face=(int)rules.GetLSLIntegerItem(idx++); 11796 face = (int)rules.GetLSLIntegerItem(idx++);
10724 11797
10725 tex = part.Shape.Textures; 11798 tex = part.Shape.Textures;
11799 float primglow;
10726 if (face == ScriptBaseClass.ALL_SIDES) 11800 if (face == ScriptBaseClass.ALL_SIDES)
10727 { 11801 {
10728 for (face = 0; face < GetNumberOfSides(part); face++) 11802 for (face = 0; face < GetNumberOfSides(part); face++)
10729 { 11803 {
10730 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 11804 primglow = tex.GetFace((uint)face).Glow;
10731 res.Add(new LSL_Float(texface.Glow)); 11805 res.Add(new LSL_Float(primglow));
10732 } 11806 }
10733 } 11807 }
10734 else 11808 else
10735 { 11809 {
10736 if (face >= 0 && face < GetNumberOfSides(part)) 11810 primglow = tex.GetFace((uint)face).Glow;
10737 { 11811 res.Add(new LSL_Float(primglow));
10738 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
10739 res.Add(new LSL_Float(texface.Glow));
10740 }
10741 } 11812 }
10742 break; 11813 break;
10743 11814
@@ -10749,15 +11820,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10749 textColor.B)); 11820 textColor.B));
10750 res.Add(new LSL_Float(1.0 - textColor.A)); 11821 res.Add(new LSL_Float(1.0 - textColor.A));
10751 break; 11822 break;
11823
10752 case (int)ScriptBaseClass.PRIM_NAME: 11824 case (int)ScriptBaseClass.PRIM_NAME:
10753 res.Add(new LSL_String(part.Name)); 11825 res.Add(new LSL_String(part.Name));
10754 break; 11826 break;
11827
10755 case (int)ScriptBaseClass.PRIM_DESC: 11828 case (int)ScriptBaseClass.PRIM_DESC:
10756 res.Add(new LSL_String(part.Description)); 11829 res.Add(new LSL_String(part.Description));
10757 break; 11830 break;
10758 case (int)ScriptBaseClass.PRIM_ROT_LOCAL: 11831 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
10759 res.Add(new LSL_Rotation(part.RotationOffset)); 11832 res.Add(new LSL_Rotation(part.RotationOffset));
10760 break; 11833 break;
11834
10761 case (int)ScriptBaseClass.PRIM_POS_LOCAL: 11835 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
10762 res.Add(new LSL_Vector(GetPartLocalPos(part))); 11836 res.Add(new LSL_Vector(GetPartLocalPos(part)));
10763 break; 11837 break;
@@ -11370,8 +12444,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11370 // The function returns an ordered list 12444 // The function returns an ordered list
11371 // representing the tokens found in the supplied 12445 // representing the tokens found in the supplied
11372 // sources string. If two successive tokenizers 12446 // sources string. If two successive tokenizers
11373 // are encountered, then a NULL entry is added 12447 // are encountered, then a null-string entry is
11374 // to the list. 12448 // added to the list.
11375 // 12449 //
11376 // It is a precondition that the source and 12450 // It is a precondition that the source and
11377 // toekizer lisst are non-null. If they are null, 12451 // toekizer lisst are non-null. If they are null,
@@ -11379,7 +12453,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11379 // while their lengths are being determined. 12453 // while their lengths are being determined.
11380 // 12454 //
11381 // A small amount of working memoryis required 12455 // A small amount of working memoryis required
11382 // of approximately 8*#tokenizers. 12456 // of approximately 8*#tokenizers + 8*srcstrlen.
11383 // 12457 //
11384 // There are many ways in which this function 12458 // There are many ways in which this function
11385 // can be implemented, this implementation is 12459 // can be implemented, this implementation is
@@ -11395,155 +12469,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11395 // and eliminates redundant tokenizers as soon 12469 // and eliminates redundant tokenizers as soon
11396 // as is possible. 12470 // as is possible.
11397 // 12471 //
11398 // The implementation tries to avoid any copying 12472 // The implementation tries to minimize temporary
11399 // of arrays or other objects. 12473 // garbage generation.
11400 // </remarks> 12474 // </remarks>
11401 12475
11402 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 12476 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
11403 { 12477 {
11404 int beginning = 0; 12478 return ParseString2List(src, separators, spacers, true);
11405 int srclen = src.Length; 12479 }
11406 int seplen = separators.Length;
11407 object[] separray = separators.Data;
11408 int spclen = spacers.Length;
11409 object[] spcarray = spacers.Data;
11410 int mlen = seplen+spclen;
11411
11412 int[] offset = new int[mlen+1];
11413 bool[] active = new bool[mlen];
11414
11415 int best;
11416 int j;
11417
11418 // Initial capacity reduces resize cost
11419 12480
11420 LSL_List tokens = new LSL_List(); 12481 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
12482 {
12483 int srclen = src.Length;
12484 int seplen = separators.Length;
12485 object[] separray = separators.Data;
12486 int spclen = spacers.Length;
12487 object[] spcarray = spacers.Data;
12488 int dellen = 0;
12489 string[] delarray = new string[seplen+spclen];
11421 12490
11422 // All entries are initially valid 12491 int outlen = 0;
12492 string[] outarray = new string[srclen*2+1];
11423 12493
11424 for (int i = 0; i < mlen; i++) 12494 int i, j;
11425 active[i] = true; 12495 string d;
11426 12496
11427 offset[mlen] = srclen; 12497 m_host.AddScriptLPS(1);
11428 12498
11429 while (beginning < srclen) 12499 /*
12500 * Convert separator and spacer lists to C# strings.
12501 * Also filter out null strings so we don't hang.
12502 */
12503 for (i = 0; i < seplen; i ++)
11430 { 12504 {
12505 d = separray[i].ToString();
12506 if (d.Length > 0)
12507 {
12508 delarray[dellen++] = d;
12509 }
12510 }
12511 seplen = dellen;
11431 12512
11432 best = mlen; // as bad as it gets 12513 for (i = 0; i < spclen; i ++)
12514 {
12515 d = spcarray[i].ToString();
12516 if (d.Length > 0)
12517 {
12518 delarray[dellen++] = d;
12519 }
12520 }
11433 12521
11434 // Scan for separators 12522 /*
12523 * Scan through source string from beginning to end.
12524 */
12525 for (i = 0;;)
12526 {
11435 12527
11436 for (j = 0; j < seplen; j++) 12528 /*
12529 * Find earliest delimeter in src starting at i (if any).
12530 */
12531 int earliestDel = -1;
12532 int earliestSrc = srclen;
12533 string earliestStr = null;
12534 for (j = 0; j < dellen; j ++)
11437 { 12535 {
11438 if (separray[j].ToString() == String.Empty) 12536 d = delarray[j];
11439 active[j] = false; 12537 if (d != null)
11440
11441 if (active[j])
11442 { 12538 {
11443 // scan all of the markers 12539 int index = src.IndexOf(d, i);
11444 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 12540 if (index < 0)
11445 { 12541 {
11446 // not present at all 12542 delarray[j] = null; // delim nowhere in src, don't check it anymore
11447 active[j] = false;
11448 } 12543 }
11449 else 12544 else if (index < earliestSrc)
11450 { 12545 {
11451 // present and correct 12546 earliestSrc = index; // where delimeter starts in source string
11452 if (offset[j] < offset[best]) 12547 earliestDel = j; // where delimeter is in delarray[]
11453 { 12548 earliestStr = d; // the delimeter string from delarray[]
11454 // closest so far 12549 if (index == i) break; // can't do any better than found at beg of string
11455 best = j;
11456 if (offset[best] == beginning)
11457 break;
11458 }
11459 } 12550 }
11460 } 12551 }
11461 } 12552 }
11462 12553
11463 // Scan for spacers 12554 /*
11464 12555 * Output source string starting at i through start of earliest delimeter.
11465 if (offset[best] != beginning) 12556 */
12557 if (keepNulls || (earliestSrc > i))
11466 { 12558 {
11467 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 12559 outarray[outlen++] = src.Substring(i, earliestSrc - i);
11468 {
11469 if (spcarray[j-seplen].ToString() == String.Empty)
11470 active[j] = false;
11471
11472 if (active[j])
11473 {
11474 // scan all of the markers
11475 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
11476 {
11477 // not present at all
11478 active[j] = false;
11479 }
11480 else
11481 {
11482 // present and correct
11483 if (offset[j] < offset[best])
11484 {
11485 // closest so far
11486 best = j;
11487 }
11488 }
11489 }
11490 }
11491 } 12560 }
11492 12561
11493 // This is the normal exit from the scanning loop 12562 /*
12563 * If no delimeter found at or after i, we're done scanning.
12564 */
12565 if (earliestDel < 0) break;
11494 12566
11495 if (best == mlen) 12567 /*
12568 * If delimeter was a spacer, output the spacer.
12569 */
12570 if (earliestDel >= seplen)
11496 { 12571 {
11497 // no markers were found on this pass 12572 outarray[outlen++] = earliestStr;
11498 // so we're pretty much done
11499 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
11500 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
11501 break;
11502 } 12573 }
11503 12574
11504 // Otherwise we just add the newly delimited token 12575 /*
11505 // and recalculate where the search should continue. 12576 * Look at rest of src string following delimeter.
11506 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 12577 */
11507 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 12578 i = earliestSrc + earliestStr.Length;
11508
11509 if (best < seplen)
11510 {
11511 beginning = offset[best] + (separray[best].ToString()).Length;
11512 }
11513 else
11514 {
11515 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
11516 string str = spcarray[best - seplen].ToString();
11517 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
11518 tokens.Add(new LSL_String(str));
11519 }
11520 } 12579 }
11521 12580
11522 // This an awkward an not very intuitive boundary case. If the 12581 /*
11523 // last substring is a tokenizer, then there is an implied trailing 12582 * Make up an exact-sized output array suitable for an LSL_List object.
11524 // null list entry. Hopefully the single comparison will not be too 12583 */
11525 // arduous. Alternatively the 'break' could be replced with a return 12584 object[] outlist = new object[outlen];
11526 // but that's shabby programming. 12585 for (i = 0; i < outlen; i ++)
11527
11528 if ((beginning == srclen) && (keepNulls))
11529 { 12586 {
11530 if (srclen != 0) 12587 outlist[i] = new LSL_String(outarray[i]);
11531 tokens.Add(new LSL_String(""));
11532 } 12588 }
11533 12589 return new LSL_List(outlist);
11534 return tokens;
11535 }
11536
11537 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
11538 {
11539 m_host.AddScriptLPS(1);
11540 return this.ParseString(src, separators, spacers, false);
11541 }
11542
11543 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
11544 {
11545 m_host.AddScriptLPS(1);
11546 return this.ParseString(src, separators, spacers, true);
11547 } 12590 }
11548 12591
11549 public LSL_Integer llGetObjectPermMask(int mask) 12592 public LSL_Integer llGetObjectPermMask(int mask)
@@ -11841,31 +12884,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11841 UUID key = new UUID(); 12884 UUID key = new UUID();
11842 if (UUID.TryParse(id, out key)) 12885 if (UUID.TryParse(id, out key))
11843 { 12886 {
11844 try 12887 // return total object mass
11845 { 12888 SceneObjectPart part = World.GetSceneObjectPart(key);
11846 SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId); 12889 if (part != null)
11847 if (obj != null) 12890 return part.ParentGroup.GetMass();
11848 return (double)obj.GetMass(); 12891
11849 // the object is null so the key is for an avatar 12892 // the object is null so the key is for an avatar
11850 ScenePresence avatar = World.GetScenePresence(key); 12893 ScenePresence avatar = World.GetScenePresence(key);
11851 if (avatar != null) 12894 if (avatar != null)
11852 if (avatar.IsChildAgent)
11853 // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
11854 // child agents have a mass of 1.0
11855 return 1;
11856 else
11857 return (double)avatar.GetMass();
11858 }
11859 catch (KeyNotFoundException)
11860 { 12895 {
11861 return 0; // The Object/Agent not in the region so just return zero 12896 if (avatar.IsChildAgent)
12897 {
12898 // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
12899 // child agents have a mass of 1.0
12900 return 1;
12901 }
12902 else
12903 {
12904 return (double)avatar.GetMass();
12905 }
11862 } 12906 }
11863 } 12907 }
11864 return 0; 12908 return 0;
11865 } 12909 }
11866 12910
11867 /// <summary> 12911 /// <summary>
11868 /// illListReplaceList removes the sub-list defined by the inclusive indices 12912 /// llListReplaceList removes the sub-list defined by the inclusive indices
11869 /// start and end and inserts the src list in its place. The inclusive 12913 /// start and end and inserts the src list in its place. The inclusive
11870 /// nature of the indices means that at least one element must be deleted 12914 /// nature of the indices means that at least one element must be deleted
11871 /// if the indices are within the bounds of the existing list. I.e. 2,2 12915 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -11922,16 +12966,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11922 // based upon end. Note that if end exceeds the upper 12966 // based upon end. Note that if end exceeds the upper
11923 // bound in this case, the entire destination list 12967 // bound in this case, the entire destination list
11924 // is removed. 12968 // is removed.
11925 else 12969 else if (start == 0)
11926 { 12970 {
11927 if (end + 1 < dest.Length) 12971 if (end + 1 < dest.Length)
11928 {
11929 return src + dest.GetSublist(end + 1, -1); 12972 return src + dest.GetSublist(end + 1, -1);
11930 }
11931 else 12973 else
11932 {
11933 return src; 12974 return src;
11934 } 12975 }
12976 else // Start < 0
12977 {
12978 if (end + 1 < dest.Length)
12979 return dest.GetSublist(end + 1, -1);
12980 else
12981 return new LSL_List();
11935 } 12982 }
11936 } 12983 }
11937 // Finally, if start > end, we strip away a prefix and 12984 // Finally, if start > end, we strip away a prefix and
@@ -11968,7 +13015,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11968 // according to the docs, this command only works if script owner and land owner are the same 13015 // according to the docs, this command only works if script owner and land owner are the same
11969 // lets add estate owners and gods, too, and use the generic permission check. 13016 // lets add estate owners and gods, too, and use the generic permission check.
11970 ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 13017 ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
11971 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return; 13018 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
11972 13019
11973 bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)? 13020 bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
11974 byte loop = 0; 13021 byte loop = 0;
@@ -11982,17 +13029,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11982 int width = 0; 13029 int width = 0;
11983 int height = 0; 13030 int height = 0;
11984 13031
11985 ParcelMediaCommandEnum? commandToSend = null; 13032 uint commandToSend = 0;
11986 float time = 0.0f; // default is from start 13033 float time = 0.0f; // default is from start
11987 13034
11988 ScenePresence presence = null; 13035 ScenePresence presence = null;
11989 13036
11990 for (int i = 0; i < commandList.Data.Length; i++) 13037 for (int i = 0; i < commandList.Data.Length; i++)
11991 { 13038 {
11992 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 13039 uint command = (uint)(commandList.GetLSLIntegerItem(i));
11993 switch (command) 13040 switch (command)
11994 { 13041 {
11995 case ParcelMediaCommandEnum.Agent: 13042 case (uint)ParcelMediaCommandEnum.Agent:
11996 // we send only to one agent 13043 // we send only to one agent
11997 if ((i + 1) < commandList.Length) 13044 if ((i + 1) < commandList.Length)
11998 { 13045 {
@@ -12009,25 +13056,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12009 } 13056 }
12010 break; 13057 break;
12011 13058
12012 case ParcelMediaCommandEnum.Loop: 13059 case (uint)ParcelMediaCommandEnum.Loop:
12013 loop = 1; 13060 loop = 1;
12014 commandToSend = command; 13061 commandToSend = command;
12015 update = true; //need to send the media update packet to set looping 13062 update = true; //need to send the media update packet to set looping
12016 break; 13063 break;
12017 13064
12018 case ParcelMediaCommandEnum.Play: 13065 case (uint)ParcelMediaCommandEnum.Play:
12019 loop = 0; 13066 loop = 0;
12020 commandToSend = command; 13067 commandToSend = command;
12021 update = true; //need to send the media update packet to make sure it doesn't loop 13068 update = true; //need to send the media update packet to make sure it doesn't loop
12022 break; 13069 break;
12023 13070
12024 case ParcelMediaCommandEnum.Pause: 13071 case (uint)ParcelMediaCommandEnum.Pause:
12025 case ParcelMediaCommandEnum.Stop: 13072 case (uint)ParcelMediaCommandEnum.Stop:
12026 case ParcelMediaCommandEnum.Unload: 13073 case (uint)ParcelMediaCommandEnum.Unload:
12027 commandToSend = command; 13074 commandToSend = command;
12028 break; 13075 break;
12029 13076
12030 case ParcelMediaCommandEnum.Url: 13077 case (uint)ParcelMediaCommandEnum.Url:
12031 if ((i + 1) < commandList.Length) 13078 if ((i + 1) < commandList.Length)
12032 { 13079 {
12033 if (commandList.Data[i + 1] is LSL_String) 13080 if (commandList.Data[i + 1] is LSL_String)
@@ -12040,7 +13087,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12040 } 13087 }
12041 break; 13088 break;
12042 13089
12043 case ParcelMediaCommandEnum.Texture: 13090 case (uint)ParcelMediaCommandEnum.Texture:
12044 if ((i + 1) < commandList.Length) 13091 if ((i + 1) < commandList.Length)
12045 { 13092 {
12046 if (commandList.Data[i + 1] is LSL_String) 13093 if (commandList.Data[i + 1] is LSL_String)
@@ -12053,7 +13100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12053 } 13100 }
12054 break; 13101 break;
12055 13102
12056 case ParcelMediaCommandEnum.Time: 13103 case (uint)ParcelMediaCommandEnum.Time:
12057 if ((i + 1) < commandList.Length) 13104 if ((i + 1) < commandList.Length)
12058 { 13105 {
12059 if (commandList.Data[i + 1] is LSL_Float) 13106 if (commandList.Data[i + 1] is LSL_Float)
@@ -12065,7 +13112,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12065 } 13112 }
12066 break; 13113 break;
12067 13114
12068 case ParcelMediaCommandEnum.AutoAlign: 13115 case (uint)ParcelMediaCommandEnum.AutoAlign:
12069 if ((i + 1) < commandList.Length) 13116 if ((i + 1) < commandList.Length)
12070 { 13117 {
12071 if (commandList.Data[i + 1] is LSL_Integer) 13118 if (commandList.Data[i + 1] is LSL_Integer)
@@ -12079,7 +13126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12079 } 13126 }
12080 break; 13127 break;
12081 13128
12082 case ParcelMediaCommandEnum.Type: 13129 case (uint)ParcelMediaCommandEnum.Type:
12083 if ((i + 1) < commandList.Length) 13130 if ((i + 1) < commandList.Length)
12084 { 13131 {
12085 if (commandList.Data[i + 1] is LSL_String) 13132 if (commandList.Data[i + 1] is LSL_String)
@@ -12092,7 +13139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12092 } 13139 }
12093 break; 13140 break;
12094 13141
12095 case ParcelMediaCommandEnum.Desc: 13142 case (uint)ParcelMediaCommandEnum.Desc:
12096 if ((i + 1) < commandList.Length) 13143 if ((i + 1) < commandList.Length)
12097 { 13144 {
12098 if (commandList.Data[i + 1] is LSL_String) 13145 if (commandList.Data[i + 1] is LSL_String)
@@ -12105,7 +13152,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12105 } 13152 }
12106 break; 13153 break;
12107 13154
12108 case ParcelMediaCommandEnum.Size: 13155 case (uint)ParcelMediaCommandEnum.Size:
12109 if ((i + 2) < commandList.Length) 13156 if ((i + 2) < commandList.Length)
12110 { 13157 {
12111 if (commandList.Data[i + 1] is LSL_Integer) 13158 if (commandList.Data[i + 1] is LSL_Integer)
@@ -12175,7 +13222,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12175 } 13222 }
12176 } 13223 }
12177 13224
12178 if (commandToSend != null) 13225 if (commandToSend != 0)
12179 { 13226 {
12180 // the commandList contained a start/stop/... command, too 13227 // the commandList contained a start/stop/... command, too
12181 if (presence == null) 13228 if (presence == null)
@@ -12212,7 +13259,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12212 13259
12213 if (aList.Data[i] != null) 13260 if (aList.Data[i] != null)
12214 { 13261 {
12215 switch ((ParcelMediaCommandEnum) aList.Data[i]) 13262 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
12216 { 13263 {
12217 case ParcelMediaCommandEnum.Url: 13264 case ParcelMediaCommandEnum.Url:
12218 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL)); 13265 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
@@ -12269,15 +13316,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12269 13316
12270 if (quick_pay_buttons.Data.Length < 4) 13317 if (quick_pay_buttons.Data.Length < 4)
12271 { 13318 {
13319<<<<<<< HEAD
12272 Error("llSetPayPrice", "List must have at least 4 elements"); 13320 Error("llSetPayPrice", "List must have at least 4 elements");
12273 return; 13321 return;
12274 } 13322=======
12275 m_host.ParentGroup.RootPart.PayPrice[0]=price; 13323 int x;
12276 13324 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
12277 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 13325 {
12278 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 13326 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
12279 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 13327 }
12280 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 13328>>>>>>> avn/ubitvar
13329 }
13330 int[] nPrice = new int[5];
13331 nPrice[0] = price;
13332 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
13333 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
13334 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
13335 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
13336 m_host.ParentGroup.RootPart.PayPrice = nPrice;
12281 m_host.ParentGroup.HasGroupChanged = true; 13337 m_host.ParentGroup.HasGroupChanged = true;
12282 } 13338 }
12283 13339
@@ -12294,7 +13350,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12294 return Vector3.Zero; 13350 return Vector3.Zero;
12295 } 13351 }
12296 13352
12297 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 13353// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
13354 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
12298 if (presence != null) 13355 if (presence != null)
12299 { 13356 {
12300 LSL_Vector pos = new LSL_Vector(presence.CameraPosition); 13357 LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
@@ -12317,7 +13374,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12317 return Quaternion.Identity; 13374 return Quaternion.Identity;
12318 } 13375 }
12319 13376
12320 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 13377// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
13378 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
12321 if (presence != null) 13379 if (presence != null)
12322 { 13380 {
12323 return new LSL_Rotation(presence.CameraRotation); 13381 return new LSL_Rotation(presence.CameraRotation);
@@ -12370,15 +13428,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12370 { 13428 {
12371 m_host.AddScriptLPS(1); 13429 m_host.AddScriptLPS(1);
12372 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0); 13430 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
12373 if (detectedParams == null) return; // only works on the first detected avatar 13431 if (detectedParams == null)
12374 13432 {
13433 if (m_host.ParentGroup.IsAttachment == true)
13434 {
13435 detectedParams = new DetectParams();
13436 detectedParams.Key = m_host.OwnerID;
13437 }
13438 else
13439 {
13440 return;
13441 }
13442 }
13443
12375 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 13444 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
12376 if (avatar != null) 13445 if (avatar != null)
12377 { 13446 {
12378 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, 13447 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
12379 simname, pos, lookAt); 13448 simname, pos, lookAt);
12380 } 13449 }
13450<<<<<<< HEAD
12381 ScriptSleep(m_sleepMsOnMapDestination); 13451 ScriptSleep(m_sleepMsOnMapDestination);
13452=======
13453
13454 ScriptSleep(1000);
13455>>>>>>> avn/ubitvar
12382 } 13456 }
12383 13457
12384 public void llAddToLandBanList(string avatar, double hours) 13458 public void llAddToLandBanList(string avatar, double hours)
@@ -12386,7 +13460,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12386 m_host.AddScriptLPS(1); 13460 m_host.AddScriptLPS(1);
12387 UUID key; 13461 UUID key;
12388 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 13462 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
12389 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) 13463 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
12390 { 13464 {
12391 int expires = 0; 13465 int expires = 0;
12392 if (hours != 0) 13466 if (hours != 0)
@@ -12427,7 +13501,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12427 m_host.AddScriptLPS(1); 13501 m_host.AddScriptLPS(1);
12428 UUID key; 13502 UUID key;
12429 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 13503 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
12430 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed)) 13504 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed, false))
12431 { 13505 {
12432 if (UUID.TryParse(avatar, out key)) 13506 if (UUID.TryParse(avatar, out key))
12433 { 13507 {
@@ -12454,7 +13528,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12454 m_host.AddScriptLPS(1); 13528 m_host.AddScriptLPS(1);
12455 UUID key; 13529 UUID key;
12456 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 13530 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
12457 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) 13531 if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
12458 { 13532 {
12459 if (UUID.TryParse(avatar, out key)) 13533 if (UUID.TryParse(avatar, out key))
12460 { 13534 {
@@ -12503,6 +13577,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12503 object[] data = rules.Data; 13577 object[] data = rules.Data;
12504 for (int i = 0; i < data.Length; ++i) 13578 for (int i = 0; i < data.Length; ++i)
12505 { 13579 {
13580<<<<<<< HEAD
12506 int type; 13581 int type;
12507 try 13582 try
12508 { 13583 {
@@ -12513,6 +13588,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12513 Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1])); 13588 Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
12514 return; 13589 return;
12515 } 13590 }
13591=======
13592 int type = Convert.ToInt32(data[i++].ToString());
13593>>>>>>> avn/ubitvar
12516 if (i >= data.Length) break; // odd number of entries => ignore the last 13594 if (i >= data.Length) break; // odd number of entries => ignore the last
12517 13595
12518 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 13596 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
@@ -12686,19 +13764,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12686 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 13764 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
12687 { 13765 {
12688 m_host.AddScriptLPS(1); 13766 m_host.AddScriptLPS(1);
12689 string ret = String.Empty; 13767
12690 string src1 = llBase64ToString(str1); 13768 if (str1 == String.Empty)
12691 string src2 = llBase64ToString(str2); 13769 return String.Empty;
12692 int c = 0; 13770 if (str2 == String.Empty)
12693 for (int i = 0; i < src1.Length; i++) 13771 return str1;
13772
13773 int len = str2.Length;
13774 if ((len % 4) != 0) // LL is EVIL!!!!
13775 {
13776 while (str2.EndsWith("="))
13777 str2 = str2.Substring(0, str2.Length - 1);
13778
13779 len = str2.Length;
13780 int mod = len % 4;
13781
13782 if (mod == 1)
13783 str2 = str2.Substring(0, str2.Length - 1);
13784 else if (mod == 2)
13785 str2 += "==";
13786 else if (mod == 3)
13787 str2 += "=";
13788 }
13789
13790 byte[] data1;
13791 byte[] data2;
13792 try
13793 {
13794 data1 = Convert.FromBase64String(str1);
13795 data2 = Convert.FromBase64String(str2);
13796 }
13797 catch (Exception)
13798 {
13799 return new LSL_String(String.Empty);
13800 }
13801
13802 byte[] d2 = new Byte[data1.Length];
13803 int pos = 0;
13804
13805 if (data1.Length <= data2.Length)
12694 { 13806 {
12695 ret += (char) (src1[i] ^ src2[c]); 13807 Array.Copy(data2, 0, d2, 0, data1.Length);
13808 }
13809 else
13810 {
13811 while (pos < data1.Length)
13812 {
13813 len = data1.Length - pos;
13814 if (len > data2.Length)
13815 len = data2.Length;
12696 13816
12697 c++; 13817 Array.Copy(data2, 0, d2, pos, len);
12698 if (c >= src2.Length) 13818 pos += len;
12699 c = 0; 13819 }
12700 } 13820 }
12701 return llStringToBase64(ret); 13821
13822 for (pos = 0 ; pos < data1.Length ; pos++ )
13823 data1[pos] ^= d2[pos];
13824
13825 return Convert.ToBase64String(data1);
12702 } 13826 }
12703 13827
12704 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 13828 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -12802,16 +13926,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12802 if (userAgent != null) 13926 if (userAgent != null)
12803 httpHeaders["User-Agent"] = userAgent; 13927 httpHeaders["User-Agent"] = userAgent;
12804 13928
13929 // See if the URL contains any header hacks
13930 string[] urlParts = url.Split(new char[] {'\n'});
13931 if (urlParts.Length > 1)
13932 {
13933 // Iterate the passed headers and parse them
13934 for (int i = 1 ; i < urlParts.Length ; i++ )
13935 {
13936 // The rest of those would be added to the body in SL.
13937 // Let's not do that.
13938 if (urlParts[i] == String.Empty)
13939 break;
13940
13941 // See if this could be a valid header
13942 string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
13943 if (headerParts.Length != 2)
13944 continue;
13945
13946 string headerName = headerParts[0].Trim();
13947 string headerValue = headerParts[1].Trim();
13948
13949 // Filter out headers that could be used to abuse
13950 // another system or cloak the request
13951 if (headerName.ToLower() == "x-secondlife-shard" ||
13952 headerName.ToLower() == "x-secondlife-object-name" ||
13953 headerName.ToLower() == "x-secondlife-object-key" ||
13954 headerName.ToLower() == "x-secondlife-region" ||
13955 headerName.ToLower() == "x-secondlife-local-position" ||
13956 headerName.ToLower() == "x-secondlife-local-velocity" ||
13957 headerName.ToLower() == "x-secondlife-local-rotation" ||
13958 headerName.ToLower() == "x-secondlife-owner-name" ||
13959 headerName.ToLower() == "x-secondlife-owner-key" ||
13960 headerName.ToLower() == "connection" ||
13961 headerName.ToLower() == "content-length" ||
13962 headerName.ToLower() == "from" ||
13963 headerName.ToLower() == "host" ||
13964 headerName.ToLower() == "proxy-authorization" ||
13965 headerName.ToLower() == "referer" ||
13966 headerName.ToLower() == "trailer" ||
13967 headerName.ToLower() == "transfer-encoding" ||
13968 headerName.ToLower() == "via" ||
13969 headerName.ToLower() == "authorization")
13970 continue;
13971
13972 httpHeaders[headerName] = headerValue;
13973 }
13974
13975 // Finally, strip any protocol specifier from the URL
13976 url = urlParts[0].Trim();
13977 int idx = url.IndexOf(" HTTP/");
13978 if (idx != -1)
13979 url = url.Substring(0, idx);
13980 }
13981
12805 string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$"; 13982 string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
12806 Regex r = new Regex(authregex); 13983 Regex r = new Regex(authregex);
12807 int[] gnums = r.GetGroupNumbers(); 13984 int[] gnums = r.GetGroupNumbers();
12808 Match m = r.Match(url); 13985 Match m = r.Match(url);
12809 if (m.Success) { 13986 if (m.Success)
12810 for (int i = 1; i < gnums.Length; i++) { 13987 {
13988 for (int i = 1; i < gnums.Length; i++)
13989 {
12811 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 13990 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
12812 //CaptureCollection cc = g.Captures; 13991 //CaptureCollection cc = g.Captures;
12813 } 13992 }
12814 if (m.Groups.Count == 5) { 13993 if (m.Groups.Count == 5)
13994 {
12815 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 13995 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
12816 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 13996 url = m.Groups[1].ToString() + m.Groups[4].ToString();
12817 } 13997 }
@@ -13018,6 +14198,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13018 14198
13019 LSL_List ret = new LSL_List(); 14199 LSL_List ret = new LSL_List();
13020 UUID key = new UUID(); 14200 UUID key = new UUID();
14201
14202
13021 if (UUID.TryParse(id, out key)) 14203 if (UUID.TryParse(id, out key))
13022 { 14204 {
13023 ScenePresence av = World.GetScenePresence(key); 14205 ScenePresence av = World.GetScenePresence(key);
@@ -13035,13 +14217,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13035 ret.Add(new LSL_String("")); 14217 ret.Add(new LSL_String(""));
13036 break; 14218 break;
13037 case ScriptBaseClass.OBJECT_POS: 14219 case ScriptBaseClass.OBJECT_POS:
13038 ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z)); 14220 Vector3 avpos;
14221
14222 if (av.ParentID != 0 && av.ParentPart != null)
14223 {
14224 avpos = av.OffsetPosition;
14225
14226 Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
14227 avpos -= sitOffset;
14228
14229 avpos = av.ParentPart.GetWorldPosition() + avpos * av.ParentPart.GetWorldRotation();
14230 }
14231 else
14232 avpos = av.AbsolutePosition;
14233
14234 ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
13039 break; 14235 break;
13040 case ScriptBaseClass.OBJECT_ROT: 14236 case ScriptBaseClass.OBJECT_ROT:
13041 ret.Add(new LSL_Rotation(av.GetWorldRotation())); 14237 Quaternion avrot = av.Rotation;
14238 if (av.ParentID != 0 && av.ParentPart != null)
14239 {
14240 avrot = av.ParentPart.GetWorldRotation() * avrot;
14241 }
14242 ret.Add(new LSL_Rotation((double)avrot.X, (double)avrot.Y, (double)avrot.Z, (double)avrot.W));
13042 break; 14243 break;
13043 case ScriptBaseClass.OBJECT_VELOCITY: 14244 case ScriptBaseClass.OBJECT_VELOCITY:
14245<<<<<<< HEAD
13044 ret.Add(new LSL_Vector(av.GetWorldVelocity())); 14246 ret.Add(new LSL_Vector(av.GetWorldVelocity()));
14247=======
14248 Vector3 avvel = av.Velocity;
14249 ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
14250>>>>>>> avn/ubitvar
13045 break; 14251 break;
13046 case ScriptBaseClass.OBJECT_OWNER: 14252 case ScriptBaseClass.OBJECT_OWNER:
13047 ret.Add(new LSL_String(id)); 14253 ret.Add(new LSL_String(id));
@@ -13143,11 +14349,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13143 case ScriptBaseClass.OBJECT_NAME: 14349 case ScriptBaseClass.OBJECT_NAME:
13144 ret.Add(new LSL_String(obj.Name)); 14350 ret.Add(new LSL_String(obj.Name));
13145 break; 14351 break;
13146 case ScriptBaseClass.OBJECT_DESC: 14352 case ScriptBaseClass.OBJECT_DESC:
13147 ret.Add(new LSL_String(obj.Description)); 14353 ret.Add(new LSL_String(obj.Description));
13148 break; 14354 break;
13149 case ScriptBaseClass.OBJECT_POS: 14355 case ScriptBaseClass.OBJECT_POS:
13150 ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z)); 14356 Vector3 opos = obj.AbsolutePosition;
14357 ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
13151 break; 14358 break;
13152 case ScriptBaseClass.OBJECT_ROT: 14359 case ScriptBaseClass.OBJECT_ROT:
13153 Quaternion rot = Quaternion.Identity; 14360 Quaternion rot = Quaternion.Identity;
@@ -13220,9 +14427,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13220 // The value returned in SL for normal prims is prim count 14427 // The value returned in SL for normal prims is prim count
13221 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount)); 14428 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
13222 break; 14429 break;
13223 // The following 3 costs I have intentionaly coded to return zero. They are part of 14430
13224 // "Land Impact" calculations. These calculations are probably not applicable 14431 // costs below may need to be diferent for root parts, need to check
13225 // to OpenSim and are not yet complete in SL
13226 case ScriptBaseClass.OBJECT_SERVER_COST: 14432 case ScriptBaseClass.OBJECT_SERVER_COST:
13227 // The linden calculation is here 14433 // The linden calculation is here
13228 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight 14434 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
@@ -13230,16 +14436,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13230 ret.Add(new LSL_Float(0)); 14436 ret.Add(new LSL_Float(0));
13231 break; 14437 break;
13232 case ScriptBaseClass.OBJECT_STREAMING_COST: 14438 case ScriptBaseClass.OBJECT_STREAMING_COST:
13233 // The linden calculation is here 14439 // The value returned in SL for normal prims is prim count * 0.06
13234 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost 14440 ret.Add(new LSL_Float(obj.StreamingCost));
13235 // The value returned in SL for normal prims looks like the prim count * 0.06
13236 ret.Add(new LSL_Float(0));
13237 break; 14441 break;
13238 case ScriptBaseClass.OBJECT_PHYSICS_COST: 14442 case ScriptBaseClass.OBJECT_PHYSICS_COST:
13239 // The linden calculation is here 14443 // The value returned in SL for normal prims is prim count
13240 // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics 14444 ret.Add(new LSL_Float(obj.PhysicsCost));
13241 // The value returned in SL for normal prims looks like the prim count
13242 ret.Add(new LSL_Float(0));
13243 break; 14445 break;
13244 case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding 14446 case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
13245 ret.Add(new LSL_Float(0)); 14447 ret.Add(new LSL_Float(0));
@@ -13530,15 +14732,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13530 return new LSL_List(); 14732 return new LSL_List();
13531 } 14733 }
13532 14734
13533 public void print(string str) 14735 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
13534 { 14736 {
13535 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 14737 List<SceneObjectPart> parts = GetLinkParts(link);
13536 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL"); 14738 if (parts.Count < 1)
13537 if (ossl != null) 14739 return 0;
13538 { 14740
13539 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 14741 return GetNumberOfSides(parts[0]);
13540 m_log.Info("LSL print():" + str);
13541 }
13542 } 14742 }
13543 14743
13544 private string Name2Username(string name) 14744 private string Name2Username(string name)
@@ -13583,7 +14783,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13583 14783
13584 return rq.ToString(); 14784 return rq.ToString();
13585 } 14785 }
13586 14786/*
14787 private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
14788 {
14789 m_SayShoutCount = 0;
14790 }
14791*/
13587 private struct Tri 14792 private struct Tri
13588 { 14793 {
13589 public Vector3 p1; 14794 public Vector3 p1;
@@ -13732,9 +14937,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13732 14937
13733 ContactResult result = new ContactResult (); 14938 ContactResult result = new ContactResult ();
13734 result.ConsumerID = group.LocalId; 14939 result.ConsumerID = group.LocalId;
13735 result.Depth = intersection.distance; 14940// result.Depth = intersection.distance;
13736 result.Normal = intersection.normal; 14941 result.Normal = intersection.normal;
13737 result.Pos = intersection.ipoint; 14942 result.Pos = intersection.ipoint;
14943 result.Depth = Vector3.Mag(rayStart - result.Pos);
13738 14944
13739 contacts.Add(result); 14945 contacts.Add(result);
13740 }); 14946 });
@@ -13867,6 +15073,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13867 15073
13868 return contacts[0]; 15074 return contacts[0];
13869 } 15075 }
15076/*
15077 // not done:
15078 private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
15079 {
15080 ContactResult[] contacts = null;
15081 World.ForEachSOG(delegate(SceneObjectGroup group)
15082 {
15083 if (m_host.ParentGroup == group)
15084 return;
15085
15086 if (group.IsAttachment)
15087 return;
15088
15089 if(group.RootPart.PhysActor != null)
15090 return;
15091
15092 contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
15093 });
15094 return contacts;
15095 }
15096*/
13870 15097
13871 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) 15098 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
13872 { 15099 {
@@ -13994,18 +15221,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13994 } 15221 }
13995 } 15222 }
13996 15223
15224 // Double check this
13997 if (checkTerrain) 15225 if (checkTerrain)
13998 { 15226 {
13999 ContactResult? groundContact = GroundIntersection(rayStart, rayEnd); 15227 bool skipGroundCheck = false;
14000 if (groundContact != null) 15228
14001 results.Add((ContactResult)groundContact); 15229 foreach (ContactResult c in results)
15230 {
15231 if (c.ConsumerID == 0) // Physics gave us a ground collision
15232 skipGroundCheck = true;
15233 }
15234
15235 if (!skipGroundCheck)
15236 {
15237 ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
15238 if (groundContact != null)
15239 results.Add((ContactResult)groundContact);
15240 }
14002 } 15241 }
14003 15242
14004 results.Sort(delegate(ContactResult a, ContactResult b) 15243 results.Sort(delegate(ContactResult a, ContactResult b)
14005 { 15244 {
14006 return a.Depth.CompareTo(b.Depth); 15245 return a.Depth.CompareTo(b.Depth);
14007 }); 15246 });
14008 15247
14009 int values = 0; 15248 int values = 0;
14010 SceneObjectGroup thisgrp = m_host.ParentGroup; 15249 SceneObjectGroup thisgrp = m_host.ParentGroup;
14011 15250
@@ -14964,7 +16203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
14964 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD: 16203 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
14965 if (!isAccount) return 0; 16204 if (!isAccount) return 0;
14966 if (estate.HasAccess(id)) return 1; 16205 if (estate.HasAccess(id)) return 1;
14967 if (estate.IsBanned(id)) 16206 if (estate.IsBanned(id, World.GetUserFlags(id)))
14968 estate.RemoveBan(id); 16207 estate.RemoveBan(id);
14969 estate.AddEstateUser(id); 16208 estate.AddEstateUser(id);
14970 break; 16209 break;
@@ -14983,14 +16222,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
14983 break; 16222 break;
14984 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: 16223 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
14985 if (!isAccount) return 0; 16224 if (!isAccount) return 0;
14986 if (estate.IsBanned(id)) return 1; 16225 if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
14987 EstateBan ban = new EstateBan(); 16226 EstateBan ban = new EstateBan();
14988 ban.EstateID = estate.EstateID; 16227 ban.EstateID = estate.EstateID;
14989 ban.BannedUserID = id; 16228 ban.BannedUserID = id;
14990 estate.AddBan(ban); 16229 estate.AddBan(ban);
14991 break; 16230 break;
14992 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: 16231 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
14993 if (!isAccount || !estate.IsBanned(id)) return 0; 16232 if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
14994 estate.RemoveBan(id); 16233 estate.RemoveBan(id);
14995 break; 16234 break;
14996 default: return 0; 16235 default: return 0;
@@ -15049,13 +16288,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
15049 public void llCollisionSprite(string impact_sprite) 16288 public void llCollisionSprite(string impact_sprite)
15050 { 16289 {
15051 m_host.AddScriptLPS(1); 16290 m_host.AddScriptLPS(1);
15052 NotImplemented("llCollisionSprite"); 16291 // Viewer 2.0 broke this and it's likely LL has no intention
16292 // of fixing it. Therefore, letting this be a NOP seems appropriate.
15053 } 16293 }
15054 16294
15055 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 16295 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
15056 { 16296 {
15057 m_host.AddScriptLPS(1); 16297 m_host.AddScriptLPS(1);
15058 NotImplemented("llGodLikeRezObject"); 16298
16299 if (!World.Permissions.IsGod(m_host.OwnerID))
16300 NotImplemented("llGodLikeRezObject");
16301
16302 AssetBase rezAsset = World.AssetService.Get(inventory);
16303 if (rezAsset == null)
16304 {
16305 llSay(0, "Asset not found");
16306 return;
16307 }
16308
16309 SceneObjectGroup group = null;
16310
16311 try
16312 {
16313 string xmlData = Utils.BytesToString(rezAsset.Data);
16314 group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
16315 }
16316 catch
16317 {
16318 llSay(0, "Asset not found");
16319 return;
16320 }
16321
16322 if (group == null)
16323 {
16324 llSay(0, "Asset not found");
16325 return;
16326 }
16327
16328 group.RootPart.AttachPoint = group.RootPart.Shape.State;
16329 group.RootPart.AttachedPos = group.AbsolutePosition;
16330
16331 group.ResetIDs();
16332
16333 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
16334 World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
16335 group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
16336 group.ScheduleGroupForFullUpdate();
16337
16338 // objects rezzed with this method are die_at_edge by default.
16339 group.RootPart.SetDieAtEdge(true);
16340
16341 group.ResumeScripts();
16342
16343 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
16344 "object_rez", new Object[] {
16345 new LSL_String(
16346 group.RootPart.UUID.ToString()) },
16347 new DetectParams[0]));
15059 } 16348 }
15060 16349
15061 public LSL_String llTransferLindenDollars(string destination, int amount) 16350 public LSL_String llTransferLindenDollars(string destination, int amount)
@@ -15106,8 +16395,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
15106 return; 16395 return;
15107 } 16396 }
15108 16397
16398 string reason;
15109 bool result = money.ObjectGiveMoney( 16399 bool result = money.ObjectGiveMoney(
15110 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); 16400 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn, out reason);
15111 16401
15112 if (result) 16402 if (result)
15113 { 16403 {
@@ -15115,7 +16405,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
15115 return; 16405 return;
15116 } 16406 }
15117 16407
15118 replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS"; 16408 replydata = reason;
15119 } 16409 }
15120 finally 16410 finally
15121 { 16411 {
@@ -15132,6 +16422,964 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
15132 } 16422 }
15133 16423
15134 #endregion 16424 #endregion
16425
16426 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
16427 {
16428 SceneObjectGroup group = m_host.ParentGroup;
16429
16430 if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
16431 return;
16432 if (group.IsAttachment)
16433 return;
16434
16435 if (frames.Data.Length > 0) // We are getting a new motion
16436 {
16437 if (group.RootPart.KeyframeMotion != null)
16438 group.RootPart.KeyframeMotion.Delete();
16439 group.RootPart.KeyframeMotion = null;
16440
16441 int idx = 0;
16442
16443 KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
16444 KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
16445
16446 while (idx < options.Data.Length)
16447 {
16448 int option = (int)options.GetLSLIntegerItem(idx++);
16449 int remain = options.Data.Length - idx;
16450
16451 switch (option)
16452 {
16453 case ScriptBaseClass.KFM_MODE:
16454 if (remain < 1)
16455 break;
16456 int modeval = (int)options.GetLSLIntegerItem(idx++);
16457 switch(modeval)
16458 {
16459 case ScriptBaseClass.KFM_FORWARD:
16460 mode = KeyframeMotion.PlayMode.Forward;
16461 break;
16462 case ScriptBaseClass.KFM_REVERSE:
16463 mode = KeyframeMotion.PlayMode.Reverse;
16464 break;
16465 case ScriptBaseClass.KFM_LOOP:
16466 mode = KeyframeMotion.PlayMode.Loop;
16467 break;
16468 case ScriptBaseClass.KFM_PING_PONG:
16469 mode = KeyframeMotion.PlayMode.PingPong;
16470 break;
16471 }
16472 break;
16473 case ScriptBaseClass.KFM_DATA:
16474 if (remain < 1)
16475 break;
16476 int dataval = (int)options.GetLSLIntegerItem(idx++);
16477 data = (KeyframeMotion.DataFormat)dataval;
16478 break;
16479 }
16480 }
16481
16482 group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
16483
16484 idx = 0;
16485
16486 int elemLength = 2;
16487 if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
16488 elemLength = 3;
16489
16490 List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
16491 while (idx < frames.Data.Length)
16492 {
16493 int remain = frames.Data.Length - idx;
16494
16495 if (remain < elemLength)
16496 break;
16497
16498 KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
16499 frame.Position = null;
16500 frame.Rotation = null;
16501
16502 if ((data & KeyframeMotion.DataFormat.Translation) != 0)
16503 {
16504 LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
16505 frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
16506 }
16507 if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
16508 {
16509 LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
16510 Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
16511 q.Normalize();
16512 frame.Rotation = q;
16513 }
16514
16515 float tempf = (float)frames.GetLSLFloatItem(idx++);
16516 frame.TimeMS = (int)(tempf * 1000.0f);
16517
16518 keyframes.Add(frame);
16519 }
16520
16521 group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
16522 group.RootPart.KeyframeMotion.Start();
16523 }
16524 else
16525 {
16526 if (group.RootPart.KeyframeMotion == null)
16527 return;
16528
16529 if (options.Data.Length == 0)
16530 {
16531 group.RootPart.KeyframeMotion.Stop();
16532 return;
16533 }
16534
16535 int code = (int)options.GetLSLIntegerItem(0);
16536
16537 int idx = 0;
16538
16539 while (idx < options.Data.Length)
16540 {
16541 int option = (int)options.GetLSLIntegerItem(idx++);
16542 int remain = options.Data.Length - idx;
16543
16544 switch (option)
16545 {
16546 case ScriptBaseClass.KFM_COMMAND:
16547 int cmd = (int)options.GetLSLIntegerItem(idx++);
16548 switch (cmd)
16549 {
16550 case ScriptBaseClass.KFM_CMD_PLAY:
16551 group.RootPart.KeyframeMotion.Start();
16552 break;
16553 case ScriptBaseClass.KFM_CMD_STOP:
16554 group.RootPart.KeyframeMotion.Stop();
16555 break;
16556 case ScriptBaseClass.KFM_CMD_PAUSE:
16557 group.RootPart.KeyframeMotion.Pause();
16558 break;
16559 }
16560 break;
16561 }
16562 }
16563 }
16564 }
16565
16566 protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
16567 {
16568 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
16569
16570 int idx = 0;
16571 int idxStart = 0;
16572
16573 bool positionChanged = false;
16574 Vector3 finalPos = Vector3.Zero;
16575
16576 try
16577 {
16578 while (idx < rules.Length)
16579 {
16580 ++rulesParsed;
16581 int code = rules.GetLSLIntegerItem(idx++);
16582
16583 int remain = rules.Length - idx;
16584 idxStart = idx;
16585
16586 switch (code)
16587 {
16588 case (int)ScriptBaseClass.PRIM_POSITION:
16589 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
16590 {
16591 if (remain < 1)
16592 return null;
16593
16594 LSL_Vector v;
16595 v = rules.GetVector3Item(idx++);
16596
16597 LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
16598
16599 v = v + 2 * sitOffset;
16600
16601 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
16602 av.SendAvatarDataToAllAgents();
16603
16604 }
16605 break;
16606
16607 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
16608 case (int)ScriptBaseClass.PRIM_ROTATION:
16609 {
16610 if (remain < 1)
16611 return null;
16612
16613 LSL_Rotation r;
16614 r = rules.GetQuaternionItem(idx++);
16615
16616 av.Rotation = r * llGetRootRotation();
16617 av.SendAvatarDataToAllAgents();
16618 }
16619 break;
16620
16621 // parse rest doing nothing but number of parameters error check
16622 case (int)ScriptBaseClass.PRIM_SIZE:
16623 case (int)ScriptBaseClass.PRIM_MATERIAL:
16624 case (int)ScriptBaseClass.PRIM_PHANTOM:
16625 case (int)ScriptBaseClass.PRIM_PHYSICS:
16626 case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
16627 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
16628 case (int)ScriptBaseClass.PRIM_NAME:
16629 case (int)ScriptBaseClass.PRIM_DESC:
16630 if (remain < 1)
16631 return null;
16632 idx++;
16633 break;
16634
16635 case (int)ScriptBaseClass.PRIM_GLOW:
16636 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
16637 case (int)ScriptBaseClass.PRIM_TEXGEN:
16638 if (remain < 2)
16639 return null;
16640 idx += 2;
16641 break;
16642
16643 case (int)ScriptBaseClass.PRIM_TYPE:
16644 if (remain < 3)
16645 return null;
16646 code = (int)rules.GetLSLIntegerItem(idx++);
16647 remain = rules.Length - idx;
16648 switch (code)
16649 {
16650 case (int)ScriptBaseClass.PRIM_TYPE_BOX:
16651 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
16652 case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
16653 if (remain < 6)
16654 return null;
16655 idx += 6;
16656 break;
16657
16658 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
16659 if (remain < 5)
16660 return null;
16661 idx += 5;
16662 break;
16663
16664 case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
16665 case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
16666 case (int)ScriptBaseClass.PRIM_TYPE_RING:
16667 if (remain < 11)
16668 return null;
16669 idx += 11;
16670 break;
16671
16672 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
16673 if (remain < 2)
16674 return null;
16675 idx += 2;
16676 break;
16677 }
16678 break;
16679
16680 case (int)ScriptBaseClass.PRIM_COLOR:
16681 case (int)ScriptBaseClass.PRIM_TEXT:
16682 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
16683 case (int)ScriptBaseClass.PRIM_OMEGA:
16684 if (remain < 3)
16685 return null;
16686 idx += 3;
16687 break;
16688
16689 case (int)ScriptBaseClass.PRIM_TEXTURE:
16690 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
16691 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
16692 if (remain < 5)
16693 return null;
16694 idx += 5;
16695 break;
16696
16697 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
16698 if (remain < 7)
16699 return null;
16700
16701 idx += 7;
16702 break;
16703
16704 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
16705 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
16706 return null;
16707
16708 return rules.GetSublist(idx, -1);
16709 }
16710 }
16711 }
16712 catch (InvalidCastException e)
16713 {
16714 ShoutError(string.Format(
16715 "{0} error running rule #{1}: arg #{2} ",
16716 originFunc, rulesParsed, idx - idxStart) + e.Message);
16717 }
16718 finally
16719 {
16720 if (positionChanged)
16721 {
16722 av.OffsetPosition = finalPos;
16723// av.SendAvatarDataToAllAgents();
16724 av.SendTerseUpdateToAllClients();
16725 positionChanged = false;
16726 }
16727 }
16728 return null;
16729 }
16730
16731 public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
16732 {
16733 // avatars case
16734 // replies as SL wiki
16735
16736// SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
16737 SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
16738
16739 int idx = 0;
16740 while (idx < rules.Length)
16741 {
16742 int code = (int)rules.GetLSLIntegerItem(idx++);
16743 int remain = rules.Length - idx;
16744
16745 switch (code)
16746 {
16747 case (int)ScriptBaseClass.PRIM_MATERIAL:
16748 res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
16749 break;
16750
16751 case (int)ScriptBaseClass.PRIM_PHYSICS:
16752 res.Add(new LSL_Integer(0));
16753 break;
16754
16755 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
16756 res.Add(new LSL_Integer(0));
16757 break;
16758
16759 case (int)ScriptBaseClass.PRIM_PHANTOM:
16760 res.Add(new LSL_Integer(0));
16761 break;
16762
16763 case (int)ScriptBaseClass.PRIM_POSITION:
16764
16765 Vector3 pos = avatar.OffsetPosition;
16766
16767 Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
16768 pos -= sitOffset;
16769
16770 res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
16771 break;
16772
16773 case (int)ScriptBaseClass.PRIM_SIZE:
16774 Vector3 s = avatar.Appearance.AvatarSize;
16775 res.Add(new LSL_Vector(s.X, s.Y, s.Z));
16776
16777 break;
16778
16779 case (int)ScriptBaseClass.PRIM_ROTATION:
16780 LSL_Rotation rot = new LSL_Rotation(avatar.Rotation.X, avatar.Rotation.Y, avatar.Rotation.Z, avatar.Rotation.W) / llGetRootRotation();
16781
16782 res.Add(rot);
16783 break;
16784
16785 case (int)ScriptBaseClass.PRIM_TYPE:
16786 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
16787 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
16788 res.Add(new LSL_Vector(0f,1.0f,0f));
16789 res.Add(new LSL_Float(0.0f));
16790 res.Add(new LSL_Vector(0, 0, 0));
16791 res.Add(new LSL_Vector(1.0f,1.0f,0f));
16792 res.Add(new LSL_Vector(0, 0, 0));
16793 break;
16794
16795 case (int)ScriptBaseClass.PRIM_TEXTURE:
16796 if (remain < 1)
16797 return null;
16798
16799 int face = (int)rules.GetLSLIntegerItem(idx++);
16800 if (face == ScriptBaseClass.ALL_SIDES)
16801 {
16802 for (face = 0; face < 21; face++)
16803 {
16804 res.Add(new LSL_String(""));
16805 res.Add(new LSL_Vector(0,0,0));
16806 res.Add(new LSL_Vector(0,0,0));
16807 res.Add(new LSL_Float(0.0));
16808 }
16809 }
16810 else
16811 {
16812 if (face >= 0 && face < 21)
16813 {
16814 res.Add(new LSL_String(""));
16815 res.Add(new LSL_Vector(0,0,0));
16816 res.Add(new LSL_Vector(0,0,0));
16817 res.Add(new LSL_Float(0.0));
16818 }
16819 }
16820 break;
16821
16822 case (int)ScriptBaseClass.PRIM_COLOR:
16823 if (remain < 1)
16824 return null;
16825
16826 face = (int)rules.GetLSLIntegerItem(idx++);
16827
16828 if (face == ScriptBaseClass.ALL_SIDES)
16829 {
16830 for (face = 0; face < 21; face++)
16831 {
16832 res.Add(new LSL_Vector(0,0,0));
16833 res.Add(new LSL_Float(0));
16834 }
16835 }
16836 else
16837 {
16838 res.Add(new LSL_Vector(0,0,0));
16839 res.Add(new LSL_Float(0));
16840 }
16841 break;
16842
16843 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
16844 if (remain < 1)
16845 return null;
16846 face = (int)rules.GetLSLIntegerItem(idx++);
16847
16848 if (face == ScriptBaseClass.ALL_SIDES)
16849 {
16850 for (face = 0; face < 21; face++)
16851 {
16852 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
16853 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
16854 }
16855 }
16856 else
16857 {
16858 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
16859 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
16860 }
16861 break;
16862
16863 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
16864 if (remain < 1)
16865 return null;
16866 face = (int)rules.GetLSLIntegerItem(idx++);
16867
16868 if (face == ScriptBaseClass.ALL_SIDES)
16869 {
16870 for (face = 0; face < 21; face++)
16871 {
16872 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
16873 }
16874 }
16875 else
16876 {
16877 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
16878 }
16879 break;
16880
16881 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
16882 res.Add(new LSL_Integer(0));
16883 res.Add(new LSL_Integer(0));// softness
16884 res.Add(new LSL_Float(0.0f)); // gravity
16885 res.Add(new LSL_Float(0.0f)); // friction
16886 res.Add(new LSL_Float(0.0f)); // wind
16887 res.Add(new LSL_Float(0.0f)); // tension
16888 res.Add(new LSL_Vector(0f,0f,0f));
16889 break;
16890
16891 case (int)ScriptBaseClass.PRIM_TEXGEN:
16892 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
16893 if (remain < 1)
16894 return null;
16895 face = (int)rules.GetLSLIntegerItem(idx++);
16896
16897 if (face == ScriptBaseClass.ALL_SIDES)
16898 {
16899 for (face = 0; face < 21; face++)
16900 {
16901 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
16902 }
16903 }
16904 else
16905 {
16906 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
16907 }
16908 break;
16909
16910 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
16911 res.Add(new LSL_Integer(0));
16912 res.Add(new LSL_Vector(0f,0f,0f));
16913 res.Add(new LSL_Float(0f)); // intensity
16914 res.Add(new LSL_Float(0f)); // radius
16915 res.Add(new LSL_Float(0f)); // falloff
16916 break;
16917
16918 case (int)ScriptBaseClass.PRIM_GLOW:
16919 if (remain < 1)
16920 return null;
16921 face = (int)rules.GetLSLIntegerItem(idx++);
16922
16923 if (face == ScriptBaseClass.ALL_SIDES)
16924 {
16925 for (face = 0; face < 21; face++)
16926 {
16927 res.Add(new LSL_Float(0f));
16928 }
16929 }
16930 else
16931 {
16932 res.Add(new LSL_Float(0f));
16933 }
16934 break;
16935
16936 case (int)ScriptBaseClass.PRIM_TEXT:
16937 res.Add(new LSL_String(""));
16938 res.Add(new LSL_Vector(0f,0f,0f));
16939 res.Add(new LSL_Float(1.0f));
16940 break;
16941
16942 case (int)ScriptBaseClass.PRIM_NAME:
16943 res.Add(new LSL_String(avatar.Name));
16944 break;
16945
16946 case (int)ScriptBaseClass.PRIM_DESC:
16947 res.Add(new LSL_String(""));
16948 break;
16949
16950 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
16951 Quaternion lrot = avatar.Rotation;
16952
16953 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
16954 {
16955 lrot = sitPart.RotationOffset * lrot; // apply sit part rotation offset
16956 }
16957 res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
16958 break;
16959
16960 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
16961 Vector3 lpos = avatar.OffsetPosition; // pos relative to sit part
16962 Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
16963 lpos -= lsitOffset;
16964
16965 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
16966 {
16967 lpos = sitPart.OffsetPosition + (lpos * sitPart.RotationOffset); // make it relative to root prim
16968 }
16969 res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
16970 break;
16971
16972 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
16973 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
16974 return null;
16975
16976 return rules.GetSublist(idx, -1);
16977 }
16978 }
16979
16980 return null;
16981 }
16982
16983 public void llSetContentType(LSL_Key id, LSL_Integer content_type)
16984 {
16985 if (m_UrlModule != null)
16986 {
16987 string type = "text.plain";
16988 if (content_type == (int)ScriptBaseClass.CONTENT_TYPE_HTML)
16989 type = "text/html";
16990
16991 m_UrlModule.HttpContentType(new UUID(id),type);
16992 }
16993 }
16994
16995 public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
16996 {
16997 string state = String.Empty;
16998
16999 foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
17000 {
17001 if (kvp.Value.ToLower() == ((string)animState).ToLower())
17002 {
17003 state = kvp.Key;
17004 break;
17005 }
17006 }
17007
17008 if (state == String.Empty)
17009 {
17010 llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
17011 return;
17012 }
17013
17014 if (m_item.PermsGranter == UUID.Zero)
17015 {
17016 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17017 return;
17018 }
17019
17020 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
17021 {
17022 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17023 return;
17024 }
17025
17026 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
17027
17028 if (presence == null)
17029 return;
17030
17031 UUID animID;
17032
17033 animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
17034
17035 if (animID == UUID.Zero)
17036 {
17037 String animupper = ((string)anim).ToUpperInvariant();
17038 DefaultAvatarAnimations.AnimsUUID.TryGetValue(animupper, out animID);
17039 }
17040
17041 if (animID == UUID.Zero)
17042 {
17043 llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
17044 return;
17045 }
17046
17047 presence.SetAnimationOverride(state, animID);
17048 }
17049
17050 public void llResetAnimationOverride(LSL_String animState)
17051 {
17052 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
17053 if (presence == null)
17054 return;
17055
17056 if (m_item.PermsGranter == UUID.Zero)
17057 {
17058 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17059 return;
17060 }
17061
17062 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
17063 {
17064 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17065 return;
17066 }
17067
17068 if (animState == "ALL")
17069 {
17070 presence.SetAnimationOverride("ALL", UUID.Zero);
17071 return;
17072 }
17073
17074 string state = String.Empty;
17075
17076 foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
17077 {
17078 if (kvp.Value.ToLower() == ((string)animState).ToLower())
17079 {
17080 state = kvp.Key;
17081 break;
17082 }
17083 }
17084
17085 if (state == String.Empty)
17086 {
17087 return;
17088 }
17089
17090 presence.SetAnimationOverride(state, UUID.Zero);
17091 }
17092
17093 public LSL_String llGetAnimationOverride(LSL_String animState)
17094 {
17095 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
17096 if (presence == null)
17097 return String.Empty;
17098
17099 if (m_item.PermsGranter == UUID.Zero)
17100 {
17101 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17102 return String.Empty;
17103 }
17104
17105 if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
17106 {
17107 llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
17108 return String.Empty;
17109 }
17110
17111 string state = String.Empty;
17112
17113 foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
17114 {
17115 if (kvp.Value.ToLower() == ((string)animState).ToLower())
17116 {
17117 state = kvp.Key;
17118 break;
17119 }
17120 }
17121
17122 if (state == String.Empty)
17123 {
17124 return String.Empty;
17125 }
17126
17127 UUID animID = presence.GetAnimationOverride(state);
17128 if (animID == UUID.Zero)
17129 return animState;
17130
17131 foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUID)
17132 {
17133 if (kvp.Value == animID)
17134 return kvp.Key.ToLower();
17135 }
17136
17137 foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
17138 {
17139 if (item.AssetID == animID)
17140 return item.Name;
17141 }
17142
17143 return String.Empty;
17144 }
17145
17146 public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
17147 {
17148 OSD o = OSDParser.DeserializeJson(json);
17149 OSD specVal = JsonGetSpecific(o, specifiers, 0);
17150
17151 return specVal.AsString();
17152 }
17153
17154 public LSL_List llJson2List(LSL_String json)
17155 {
17156 try
17157 {
17158 OSD o = OSDParser.DeserializeJson(json);
17159 return (LSL_List)ParseJsonNode(o);
17160 }
17161 catch (Exception)
17162 {
17163 return new LSL_List(ScriptBaseClass.JSON_INVALID);
17164 }
17165 }
17166
17167 private object ParseJsonNode(OSD node)
17168 {
17169 if (node.Type == OSDType.Integer)
17170 return new LSL_Integer(node.AsInteger());
17171 if (node.Type == OSDType.Boolean)
17172 return new LSL_Integer(node.AsBoolean() ? 1 : 0);
17173 if (node.Type == OSDType.Real)
17174 return new LSL_Float(node.AsReal());
17175 if (node.Type == OSDType.UUID || node.Type == OSDType.String)
17176 return new LSL_String(node.AsString());
17177 if (node.Type == OSDType.Array)
17178 {
17179 LSL_List resp = new LSL_List();
17180 OSDArray ar = node as OSDArray;
17181 foreach (OSD o in ar)
17182 resp.Add(ParseJsonNode(o));
17183 return resp;
17184 }
17185 if (node.Type == OSDType.Map)
17186 {
17187 LSL_List resp = new LSL_List();
17188 OSDMap ar = node as OSDMap;
17189 foreach (KeyValuePair<string, OSD> o in ar)
17190 {
17191 resp.Add(new LSL_String(o.Key));
17192 resp.Add(ParseJsonNode(o.Value));
17193 }
17194 return resp;
17195 }
17196 throw new Exception(ScriptBaseClass.JSON_INVALID);
17197 }
17198
17199 public LSL_String llList2Json(LSL_String type, LSL_List values)
17200 {
17201 try
17202 {
17203 if (type == ScriptBaseClass.JSON_ARRAY)
17204 {
17205 OSDArray array = new OSDArray();
17206 foreach (object o in values.Data)
17207 {
17208 array.Add(ListToJson(o));
17209 }
17210 return OSDParser.SerializeJsonString(array);
17211 }
17212 else if (type == ScriptBaseClass.JSON_OBJECT)
17213 {
17214 OSDMap map = new OSDMap();
17215 for (int i = 0; i < values.Data.Length; i += 2)
17216 {
17217 if (!(values.Data[i] is LSL_String))
17218 return ScriptBaseClass.JSON_INVALID;
17219 map.Add(((LSL_String)values.Data[i]).m_string, ListToJson(values.Data[i + 1]));
17220 }
17221 return OSDParser.SerializeJsonString(map);
17222 }
17223 return ScriptBaseClass.JSON_INVALID;
17224 }
17225 catch (Exception ex)
17226 {
17227 return ex.Message;
17228 }
17229 }
17230
17231 private OSD ListToJson(object o)
17232 {
17233 if (o is LSL_Float)
17234 return OSD.FromReal(((LSL_Float)o).value);
17235 if (o is LSL_Integer)
17236 {
17237 int i = ((LSL_Integer)o).value;
17238 if (i == 0)
17239 return OSD.FromBoolean(false);
17240 else if (i == 1)
17241 return OSD.FromBoolean(true);
17242 return OSD.FromInteger(i);
17243 }
17244 if (o is LSL_Rotation)
17245 return OSD.FromString(((LSL_Rotation)o).ToString());
17246 if (o is LSL_Vector)
17247 return OSD.FromString(((LSL_Vector)o).ToString());
17248 if (o is LSL_String)
17249 {
17250 string str = ((LSL_String)o).m_string;
17251 if (str == ScriptBaseClass.JSON_NULL)
17252 return new OSD();
17253 return OSD.FromString(str);
17254 }
17255 throw new Exception(ScriptBaseClass.JSON_INVALID);
17256 }
17257
17258 private OSD JsonGetSpecific(OSD o, LSL_List specifiers, int i)
17259 {
17260 object spec = specifiers.Data[i];
17261 OSD nextVal = null;
17262 if (o is OSDArray)
17263 {
17264 if (spec is LSL_Integer)
17265 nextVal = ((OSDArray)o)[((LSL_Integer)spec).value];
17266 }
17267 if (o is OSDMap)
17268 {
17269 if (spec is LSL_String)
17270 nextVal = ((OSDMap)o)[((LSL_String)spec).m_string];
17271 }
17272 if (nextVal != null)
17273 {
17274 if (specifiers.Data.Length - 1 > i)
17275 return JsonGetSpecific(nextVal, specifiers, i + 1);
17276 }
17277 return nextVal;
17278 }
17279
17280 public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
17281 {
17282 try
17283 {
17284 OSD o = OSDParser.DeserializeJson(json);
17285 JsonSetSpecific(o, specifiers, 0, value);
17286 return OSDParser.SerializeJsonString(o);
17287 }
17288 catch (Exception)
17289 {
17290 }
17291 return ScriptBaseClass.JSON_INVALID;
17292 }
17293
17294 private void JsonSetSpecific(OSD o, LSL_List specifiers, int i, LSL_String val)
17295 {
17296 object spec = specifiers.Data[i];
17297 // 20131224 not used object specNext = i+1 == specifiers.Data.Length ? null : specifiers.Data[i+1];
17298 OSD nextVal = null;
17299 if (o is OSDArray)
17300 {
17301 OSDArray array = ((OSDArray)o);
17302 if (spec is LSL_Integer)
17303 {
17304 int v = ((LSL_Integer)spec).value;
17305 if (v >= array.Count)
17306 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
17307 else
17308 nextVal = ((OSDArray)o)[v];
17309 }
17310 else if (spec is LSL_String && ((LSL_String)spec) == ScriptBaseClass.JSON_APPEND)
17311 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
17312 }
17313 if (o is OSDMap)
17314 {
17315 if (spec is LSL_String)
17316 {
17317 OSDMap map = ((OSDMap)o);
17318 if (map.ContainsKey(((LSL_String)spec).m_string))
17319 nextVal = map[((LSL_String)spec).m_string];
17320 else
17321 map.Add(((LSL_String)spec).m_string, JsonBuildRestOfSpec(specifiers, i + 1, val));
17322 }
17323 }
17324 if (nextVal != null)
17325 {
17326 if (specifiers.Data.Length - 1 > i)
17327 {
17328 JsonSetSpecific(nextVal, specifiers, i + 1, val);
17329 return;
17330 }
17331 }
17332 }
17333
17334 private OSD JsonBuildRestOfSpec(LSL_List specifiers, int i, LSL_String val)
17335 {
17336 object spec = i >= specifiers.Data.Length ? null : specifiers.Data[i];
17337 // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
17338
17339 if (spec == null)
17340 return OSD.FromString(val);
17341
17342 if (spec is LSL_Integer ||
17343 (spec is LSL_String && ((LSL_String)spec) == ScriptBaseClass.JSON_APPEND))
17344 {
17345 OSDArray array = new OSDArray();
17346 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
17347 return array;
17348 }
17349 else if (spec is LSL_String)
17350 {
17351 OSDMap map = new OSDMap();
17352 map.Add((LSL_String)spec, JsonBuildRestOfSpec(specifiers, i + 1, val));
17353 return map;
17354 }
17355 return new OSD();
17356 }
17357
17358 public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
17359 {
17360 OSD o = OSDParser.DeserializeJson(json);
17361 OSD specVal = JsonGetSpecific(o, specifiers, 0);
17362 if (specVal == null)
17363 return ScriptBaseClass.JSON_INVALID;
17364 switch (specVal.Type)
17365 {
17366 case OSDType.Array:
17367 return ScriptBaseClass.JSON_ARRAY;
17368 case OSDType.Boolean:
17369 return specVal.AsBoolean() ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
17370 case OSDType.Integer:
17371 case OSDType.Real:
17372 return ScriptBaseClass.JSON_NUMBER;
17373 case OSDType.Map:
17374 return ScriptBaseClass.JSON_OBJECT;
17375 case OSDType.String:
17376 case OSDType.UUID:
17377 return ScriptBaseClass.JSON_STRING;
17378 case OSDType.Unknown:
17379 return ScriptBaseClass.JSON_NULL;
17380 }
17381 return ScriptBaseClass.JSON_INVALID;
17382 }
15135 } 17383 }
15136 17384
15137 public class NotecardCache 17385 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 1458c95..7bd4fa7 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -136,7 +136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
136// ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); 136// ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType);
137 137
138 Type returntype = m_comms.LookupReturnType(fname); 138 Type returntype = m_comms.LookupReturnType(fname);
139 if (returntype != typeof(string)) 139 if (returntype != typeof(void))
140 MODError(String.Format("return type mismatch for {0}",fname)); 140 MODError(String.Format("return type mismatch for {0}",fname));
141 141
142 modInvoke(fname,parms); 142 modInvoke(fname,parms);
@@ -329,6 +329,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
329 if (result != null) 329 if (result != null)
330 return result; 330 return result;
331 331
332 Type returntype = m_comms.LookupReturnType(fname);
333 if (returntype == typeof(void))
334 return null;
335
332 MODError(String.Format("Invocation of {0} failed; null return value",fname)); 336 MODError(String.Format("Invocation of {0} failed; null return value",fname));
333 } 337 }
334 catch (Exception e) 338 catch (Exception e)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e799714..5d8f0f6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -140,6 +140,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
140 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 140 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
141 internal float m_ScriptDelayFactor = 1.0f; 141 internal float m_ScriptDelayFactor = 1.0f;
142 internal float m_ScriptDistanceFactor = 1.0f; 142 internal float m_ScriptDistanceFactor = 1.0f;
143 internal bool m_debuggerSafe = false;
143 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 144 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
144 145
145 protected IUrlModule m_UrlModule = null; 146 protected IUrlModule m_UrlModule = null;
@@ -150,6 +151,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
150 m_ScriptEngine = scriptEngine; 151 m_ScriptEngine = scriptEngine;
151 m_host = host; 152 m_host = host;
152 m_item = item; 153 m_item = item;
154 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
153 155
154 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 156 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
155 157
@@ -216,7 +218,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
216 218
217 internal void OSSLError(string msg) 219 internal void OSSLError(string msg)
218 { 220 {
219 throw new ScriptException("OSSL Runtime Error: " + msg); 221 if (m_debuggerSafe)
222 {
223 OSSLShoutError(msg);
224 }
225 else
226 {
227 throw new ScriptException("OSSL Runtime Error: " + msg);
228 }
220 } 229 }
221 230
222 /// <summary> 231 /// <summary>
@@ -820,7 +829,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
820 private void TeleportAgent(string agent, int regionX, int regionY, 829 private void TeleportAgent(string agent, int regionX, int regionY,
821 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 830 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
822 { 831 {
832<<<<<<< HEAD
823 // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); 833 // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
834=======
835>>>>>>> avn/ubitvar
824 ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY); 836 ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
825 837
826 m_host.AddScriptLPS(1); 838 m_host.AddScriptLPS(1);
@@ -993,18 +1005,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
993 if (target != null) 1005 if (target != null)
994 { 1006 {
995 UUID animID=UUID.Zero; 1007 UUID animID=UUID.Zero;
996 lock (m_host.TaskInventory) 1008 m_host.TaskInventory.LockItemsForRead(true);
1009 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
997 { 1010 {
998 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 1011 if (inv.Value.Name == animation)
999 { 1012 {
1000 if (inv.Value.Name == animation) 1013 if (inv.Value.Type == (int)AssetType.Animation)
1001 { 1014 animID = inv.Value.AssetID;
1002 if (inv.Value.Type == (int)AssetType.Animation) 1015 continue;
1003 animID = inv.Value.AssetID;
1004 continue;
1005 }
1006 } 1016 }
1007 } 1017 }
1018 m_host.TaskInventory.LockItemsForRead(false);
1008 if (animID == UUID.Zero) 1019 if (animID == UUID.Zero)
1009 target.Animator.AddAnimation(animation, m_host.UUID); 1020 target.Animator.AddAnimation(animation, m_host.UUID);
1010 else 1021 else
@@ -1046,6 +1057,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1046 animID = UUID.Zero; 1057 animID = UUID.Zero;
1047 } 1058 }
1048 1059
1060
1049 if (animID == UUID.Zero) 1061 if (animID == UUID.Zero)
1050 target.Animator.RemoveAnimation(animation); 1062 target.Animator.RemoveAnimation(animation);
1051 else 1063 else
@@ -1487,7 +1499,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1487 return; 1499 return;
1488 } 1500 }
1489 1501
1490 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions)) 1502 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
1491 { 1503 {
1492 OSSLShoutError("You do not have permission to modify the parcel"); 1504 OSSLShoutError("You do not have permission to modify the parcel");
1493 return; 1505 return;
@@ -1722,7 +1734,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1722 } 1734 }
1723 } 1735 }
1724 1736
1725 public Object osParseJSONNew(string JSON) 1737 private Object osParseJSONNew(string JSON)
1726 { 1738 {
1727 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew"); 1739 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1728 1740
@@ -1934,15 +1946,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1934 { 1946 {
1935 UUID assetID = UUID.Zero; 1947 UUID assetID = UUID.Zero;
1936 1948
1937 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1949 bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
1950
1951 if (!notecardNameIsUUID)
1938 { 1952 {
1939 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1953 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1940 {
1941 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1942 {
1943 assetID = item.AssetID;
1944 }
1945 }
1946 } 1954 }
1947 1955
1948 if (assetID == UUID.Zero) 1956 if (assetID == UUID.Zero)
@@ -1953,13 +1961,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1953 AssetBase a = World.AssetService.Get(assetID.ToString()); 1961 AssetBase a = World.AssetService.Get(assetID.ToString());
1954 1962
1955 if (a == null) 1963 if (a == null)
1956 return UUID.Zero; 1964 {
1965 // Whoops, it's still possible here that the notecard name was properly
1966 // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
1967 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1968 if (assetID == UUID.Zero)
1969 return UUID.Zero;
1970
1971 if (!NotecardCache.IsCached(assetID))
1972 {
1973 a = World.AssetService.Get(assetID.ToString());
1974
1975 if (a == null)
1976 {
1977 return UUID.Zero;
1978 }
1979 }
1980 }
1957 1981
1958 NotecardCache.Cache(assetID, a.Data); 1982 NotecardCache.Cache(assetID, a.Data);
1959 }; 1983 };
1960 1984
1961 return assetID; 1985 return assetID;
1962 } 1986 }
1987 protected UUID SearchTaskInventoryForAssetId(string name)
1988 {
1989 UUID assetId = UUID.Zero;
1990 m_host.TaskInventory.LockItemsForRead(true);
1991 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1992 {
1993 if (item.Type == 7 && item.Name == name)
1994 {
1995 assetId = item.AssetID;
1996 }
1997 }
1998 m_host.TaskInventory.LockItemsForRead(false);
1999 return assetId;
2000 }
1963 2001
1964 /// <summary> 2002 /// <summary>
1965 /// Directly get an entire notecard at once. 2003 /// Directly get an entire notecard at once.
@@ -2544,7 +2582,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2544 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 2582 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2545 m_host.AddScriptLPS(1); 2583 m_host.AddScriptLPS(1);
2546 2584
2547 return NpcCreate(firstname, lastname, position, notecard, false, false); 2585 return NpcCreate(firstname, lastname, position, notecard, true, false);
2548 } 2586 }
2549 2587
2550 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) 2588 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
@@ -2555,24 +2593,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 return NpcCreate( 2593 return NpcCreate(
2556 firstname, lastname, position, notecard, 2594 firstname, lastname, position, notecard,
2557 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, 2595 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2558 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); 2596 false);
2597// (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
2559 } 2598 }
2560 2599
2561 private LSL_Key NpcCreate( 2600 private LSL_Key NpcCreate(
2562 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) 2601 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
2563 { 2602 {
2603 if (!owned)
2604 OSSLError("Unowned NPCs are unsupported");
2605
2606 string groupTitle = String.Empty;
2607
2608 if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2609 return new LSL_Key(UUID.Zero.ToString());
2610
2611 if (firstname != String.Empty || lastname != String.Empty)
2612 {
2613 if (firstname != "Shown outfit:")
2614 groupTitle = "- NPC -";
2615 }
2616
2564 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2617 INPCModule module = World.RequestModuleInterface<INPCModule>();
2565 if (module != null) 2618 if (module != null)
2566 { 2619 {
2567 AvatarAppearance appearance = null; 2620 AvatarAppearance appearance = null;
2568 2621
2569 UUID id; 2622// UUID id;
2570 if (UUID.TryParse(notecard, out id)) 2623// if (UUID.TryParse(notecard, out id))
2571 { 2624// {
2572 ScenePresence clonePresence = World.GetScenePresence(id); 2625// ScenePresence clonePresence = World.GetScenePresence(id);
2573 if (clonePresence != null) 2626// if (clonePresence != null)
2574 appearance = clonePresence.Appearance; 2627// appearance = clonePresence.Appearance;
2575 } 2628// }
2576 2629
2577 if (appearance == null) 2630 if (appearance == null)
2578 { 2631 {
@@ -2580,9 +2633,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2580 2633
2581 if (appearanceSerialized != null) 2634 if (appearanceSerialized != null)
2582 { 2635 {
2583 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2636 try
2584 appearance = new AvatarAppearance(); 2637 {
2585 appearance.Unpack(appearanceOsd); 2638 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2639 appearance = new AvatarAppearance();
2640 appearance.Unpack(appearanceOsd);
2641 }
2642 catch
2643 {
2644 return UUID.Zero.ToString();
2645 }
2586 } 2646 }
2587 else 2647 else
2588 { 2648 {
@@ -2601,6 +2661,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2601 World, 2661 World,
2602 appearance); 2662 appearance);
2603 2663
2664 ScenePresence sp;
2665 if (World.TryGetScenePresence(x, out sp))
2666 {
2667 sp.Grouptitle = groupTitle;
2668 sp.SendAvatarDataToAllAgents();
2669 }
2604 return new LSL_Key(x.ToString()); 2670 return new LSL_Key(x.ToString());
2605 } 2671 }
2606 2672
@@ -2898,16 +2964,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2898 CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); 2964 CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
2899 m_host.AddScriptLPS(1); 2965 m_host.AddScriptLPS(1);
2900 2966
2901 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2967 ManualResetEvent ev = new ManualResetEvent(false);
2902 if (module != null)
2903 {
2904 UUID npcId = new UUID(npc.m_string);
2905 2968
2906 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2969 Util.FireAndForget(delegate(object x) {
2907 return; 2970 try
2971 {
2972 INPCModule module = World.RequestModuleInterface<INPCModule>();
2973 if (module != null)
2974 {
2975 UUID npcId = new UUID(npc.m_string);
2908 2976
2909 module.DeleteNPC(npcId, World); 2977 ILandObject l = World.LandChannel.GetLandObject(m_host.GroupPosition.X, m_host.GroupPosition.Y);
2910 } 2978 if (l == null || m_host.OwnerID != l.LandData.OwnerID)
2979 {
2980 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2981 return;
2982 }
2983
2984 module.DeleteNPC(npcId, World);
2985 }
2986 }
2987 finally
2988 {
2989 ev.Set();
2990 }
2991 });
2992 ev.WaitOne();
2911 } 2993 }
2912 2994
2913 public void osNpcPlayAnimation(LSL_Key npc, string animation) 2995 public void osNpcPlayAnimation(LSL_Key npc, string animation)
@@ -3183,9 +3265,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3183 } 3265 }
3184 else 3266 else
3185 { 3267 {
3268<<<<<<< HEAD
3186 Scene scene = m_ScriptEngine.World; 3269 Scene scene = m_ScriptEngine.World;
3187 GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID); 3270 GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
3188 return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeX, Constants.RegionHeight); 3271 return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeX, Constants.RegionHeight);
3272=======
3273 return new LSL_Vector((float)World.RegionInfo.RegionSizeX,
3274 (float)World.RegionInfo.RegionSizeY,
3275 (float)World.RegionInfo.RegionSizeZ );
3276>>>>>>> avn/ubitvar
3189 } 3277 }
3190 } 3278 }
3191 3279
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 64dc2e2..7bfe27b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -93,7 +93,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
93 private const int AGENT = 1; 93 private const int AGENT = 1;
94 private const int AGENT_BY_USERNAME = 0x10; 94 private const int AGENT_BY_USERNAME = 0x10;
95 private const int NPC = 0x20; 95 private const int NPC = 0x20;
96 private const int OS_NPC = 0x01000000;
97 private const int ACTIVE = 2; 96 private const int ACTIVE = 2;
98 private const int PASSIVE = 4; 97 private const int PASSIVE = 4;
99 private const int SCRIPTED = 8; 98 private const int SCRIPTED = 8;
@@ -240,7 +239,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
240 List<SensedEntity> sensedEntities = new List<SensedEntity>(); 239 List<SensedEntity> sensedEntities = new List<SensedEntity>();
241 240
242 // Is the sensor type is AGENT and not SCRIPTED then include agents 241 // Is the sensor type is AGENT and not SCRIPTED then include agents
243 if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC | OS_NPC)) != 0 && (ts.type & SCRIPTED) == 0) 242 if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0)
244 { 243 {
245 sensedEntities.AddRange(doAgentSensor(ts)); 244 sensedEntities.AddRange(doAgentSensor(ts));
246 } 245 }
@@ -339,7 +338,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
339 float dy; 338 float dy;
340 float dz; 339 float dz;
341 340
342 Quaternion q = SensePoint.GetWorldRotation(); 341// Quaternion q = SensePoint.RotationOffset;
342 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
343 if (SensePoint.ParentGroup.IsAttachment) 343 if (SensePoint.ParentGroup.IsAttachment)
344 { 344 {
345 // In attachments, rotate the sensor cone with the 345 // In attachments, rotate the sensor cone with the
@@ -358,7 +358,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
358 if (avatar == null) 358 if (avatar == null)
359 return sensedEntities; 359 return sensedEntities;
360 360
361 q = avatar.GetWorldRotation() * q; 361 fromRegionPos = avatar.AbsolutePosition;
362 q = avatar.Rotation;
362 } 363 }
363 364
364 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); 365 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
@@ -402,7 +403,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
402 objtype = 0; 403 objtype = 0;
403 404
404 part = ((SceneObjectGroup)ent).RootPart; 405 part = ((SceneObjectGroup)ent).RootPart;
405 if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore 406 if (part.ParentGroup.RootPart.Shape.PCode != (byte)PCode.Tree &&
407 part.ParentGroup.RootPart.Shape.PCode != (byte)PCode.NewTree &&
408 part.ParentGroup.AttachmentPoint != 0) // Attached so ignore
406 continue; 409 continue;
407 410
408 if (part.Inventory.ContainsScripts()) 411 if (part.Inventory.ContainsScripts())
@@ -489,8 +492,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
489 // Don't proceed if the avatar for this attachment has since been removed from the scene. 492 // Don't proceed if the avatar for this attachment has since been removed from the scene.
490 if (avatar == null) 493 if (avatar == null)
491 return sensedEntities; 494 return sensedEntities;
492 495 fromRegionPos = avatar.AbsolutePosition;
493 q = avatar.GetWorldRotation() * q; 496 q = avatar.Rotation;
494 } 497 }
495 498
496 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); 499 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
@@ -506,7 +509,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
506// "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}", 509// "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
507// presence.Name, presence.PresenceType, ts.name, ts.type); 510// presence.Name, presence.PresenceType, ts.name, ts.type);
508 511
509 if ((ts.type & NPC) == 0 && (ts.type & OS_NPC) == 0 && presence.PresenceType == PresenceType.Npc) 512 if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc)
510 { 513 {
511 INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene); 514 INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
512 if (npcData == null || !npcData.SenseAsAgent) 515 if (npcData == null || !npcData.SenseAsAgent)
@@ -546,7 +549,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
546 return; 549 return;
547 550
548 toRegionPos = presence.AbsolutePosition; 551 toRegionPos = presence.AbsolutePosition;
549 dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); 552 dis = Util.GetDistanceTo(toRegionPos, fromRegionPos);
553 if (presence.IsSatOnObject && presence.ParentPart != null &&
554 presence.ParentPart.ParentGroup != null &&
555 presence.ParentPart.ParentGroup.RootPart != null)
556 {
557 Vector3 rpos = presence.ParentPart.ParentGroup.RootPart.AbsolutePosition;
558 double dis2 = Util.GetDistanceTo(rpos, fromRegionPos);
559 if (dis > dis2)
560 dis = dis2;
561 }
550 562
551 // Disabled for now since all osNpc* methods check for appropriate ownership permission. 563 // Disabled for now since all osNpc* methods check for appropriate ownership permission.
552 // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not 564 // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
@@ -706,4 +718,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
706 return retList; 718 return retList;
707 } 719 }
708 } 720 }
709} \ No newline at end of file 721}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index 0b14565..5b1fdc0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -123,25 +123,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
123 if (Timers.Count == 0) 123 if (Timers.Count == 0)
124 return; 124 return;
125 125
126 Dictionary<string, TimerInfo> tvals;
126 lock (TimerListLock) 127 lock (TimerListLock)
127 { 128 {
128 // Go through all timers 129 // Go through all timers
129 Dictionary<string, TimerInfo>.ValueCollection tvals = Timers.Values; 130 tvals = new Dictionary<string, TimerInfo>(Timers);
130 foreach (TimerInfo ts in tvals) 131 }
132
133 foreach (TimerInfo ts in tvals.Values)
134 {
135 // Time has passed?
136 if (ts.next < DateTime.Now.Ticks)
131 { 137 {
132 // Time has passed? 138 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
133 if (ts.next < DateTime.Now.Ticks) 139 // Add it to queue
134 { 140 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
135 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); 141 new EventParams("timer", new Object[0],
136 // Add it to queue 142 new DetectParams[0]));
137 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, 143 // set next interval
138 new EventParams("timer", new Object[0], 144
139 new DetectParams[0])); 145 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
140 // set next interval 146 ts.next = DateTime.Now.Ticks + ts.interval;
141
142 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
143 ts.next = DateTime.Now.Ticks + ts.interval;
144 }
145 } 147 }
146 } 148 }
147 } 149 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
new file mode 100644
index 0000000..ab215f3
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections;
29using OpenSim.Region.ScriptEngine.Interfaces;
30
31using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
32using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
33using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
34using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
35using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
36using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
37using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
38
39namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{
41 public interface ICM_Api
42 {
43 string cmDetectedCountry(int num);
44 string cmGetAgentCountry(key key);
45 }
46}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 3d58573..a3bb7d6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -127,6 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
127 LSL_String llGetEnv(LSL_String name); 127 LSL_String llGetEnv(LSL_String name);
128 LSL_Vector llGetForce(); 128 LSL_Vector llGetForce();
129 LSL_Integer llGetFreeMemory(); 129 LSL_Integer llGetFreeMemory();
130 LSL_Integer llGetUsedMemory();
130 LSL_Integer llGetFreeURLs(); 131 LSL_Integer llGetFreeURLs();
131 LSL_Vector llGetGeometricCenter(); 132 LSL_Vector llGetGeometricCenter();
132 LSL_Float llGetGMTclock(); 133 LSL_Float llGetGMTclock();
@@ -204,12 +205,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
204 LSL_String llGetTimestamp(); 205 LSL_String llGetTimestamp();
205 LSL_Vector llGetTorque(); 206 LSL_Vector llGetTorque();
206 LSL_Integer llGetUnixTime(); 207 LSL_Integer llGetUnixTime();
207 LSL_Integer llGetUsedMemory();
208 LSL_Vector llGetVel(); 208 LSL_Vector llGetVel();
209 LSL_Float llGetWallclock(); 209 LSL_Float llGetWallclock();
210 void llGiveInventory(string destination, string inventory); 210 void llGiveInventory(string destination, string inventory);
211 void llGiveInventoryList(string destination, string category, LSL_List inventory); 211 void llGiveInventoryList(string destination, string category, LSL_List inventory);
212 void llGiveMoney(string destination, int amount); 212 LSL_Integer llGiveMoney(string destination, int amount);
213 LSL_String llTransferLindenDollars(string destination, int amount); 213 LSL_String llTransferLindenDollars(string destination, int amount);
214 void llGodLikeRezObject(string inventory, LSL_Vector pos); 214 void llGodLikeRezObject(string inventory, LSL_Vector pos);
215 LSL_Float llGround(LSL_Vector offset); 215 LSL_Float llGround(LSL_Vector offset);
@@ -344,7 +344,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
344 void llSetDamage(double damage); 344 void llSetDamage(double damage);
345 void llSetForce(LSL_Vector force, int local); 345 void llSetForce(LSL_Vector force, int local);
346 void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local); 346 void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local);
347 void llSetVelocity(LSL_Vector velocity, int local);
348 void llSetAngularVelocity(LSL_Vector angularVelocity, int local); 347 void llSetAngularVelocity(LSL_Vector angularVelocity, int local);
349 void llSetHoverHeight(double height, int water, double tau); 348 void llSetHoverHeight(double height, int water, double tau);
350 void llSetInventoryPermMask(string item, int mask, int value); 349 void llSetInventoryPermMask(string item, int mask, int value);
@@ -362,11 +361,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
362 void llSetParcelMusicURL(string url); 361 void llSetParcelMusicURL(string url);
363 void llSetPayPrice(int price, LSL_List quick_pay_buttons); 362 void llSetPayPrice(int price, LSL_List quick_pay_buttons);
364 void llSetPos(LSL_Vector pos); 363 void llSetPos(LSL_Vector pos);
364 LSL_Integer llSetRegionPos(LSL_Vector pos);
365 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules); 365 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules);
366 void llSetPrimitiveParams(LSL_List rules); 366 void llSetPrimitiveParams(LSL_List rules);
367 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules); 367 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules);
368 void llSetPrimURL(string url); 368 void llSetPrimURL(string url);
369 LSL_Integer llSetRegionPos(LSL_Vector pos);
370 void llSetRemoteScriptAccessPin(int pin); 369 void llSetRemoteScriptAccessPin(int pin);
371 void llSetRot(LSL_Rotation rot); 370 void llSetRot(LSL_Rotation rot);
372 void llSetScale(LSL_Vector scale); 371 void llSetScale(LSL_Vector scale);
@@ -429,10 +428,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
429 LSL_Vector llWind(LSL_Vector offset); 428 LSL_Vector llWind(LSL_Vector offset);
430 LSL_String llXorBase64Strings(string str1, string str2); 429 LSL_String llXorBase64Strings(string str1, string str2);
431 LSL_String llXorBase64StringsCorrect(string str1, string str2); 430 LSL_String llXorBase64StringsCorrect(string str1, string str2);
432 void print(string str); 431 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
432 void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density);
433 433
434 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc); 434 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc);
435 void llSetKeyframedMotion(LSL_List frames, LSL_List options); 435 void llSetKeyframedMotion(LSL_List frames, LSL_List options);
436 LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 436 LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
437 LSL_List llGetPhysicsMaterial();
438 void llSetAnimationOverride(LSL_String animState, LSL_String anim);
439 void llResetAnimationOverride(LSL_String anim_state);
440 LSL_String llGetAnimationOverride(LSL_String anim_state);
441 LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers);
442 LSL_List llJson2List(LSL_String json);
443 LSL_String llList2Json(LSL_String type, LSL_List values);
444 LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value);
445 LSL_String llJsonValueType(LSL_String json, LSL_List specifiers);
437 } 446 }
438} 447}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 6259b76..ddd7630 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -144,7 +144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
144 // Avatar Info Commands 144 // Avatar Info Commands
145 string osGetAgentIP(string agent); 145 string osGetAgentIP(string agent);
146 LSL_List osGetAgents(); 146 LSL_List osGetAgents();
147 147
148 // Teleport commands 148 // Teleport commands
149 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 149 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
150 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 150 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
@@ -261,7 +261,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
261 string osGetSimulatorVersion(); 261 string osGetSimulatorVersion();
262 LSL_Integer osCheckODE(); 262 LSL_Integer osCheckODE();
263 string osGetPhysicsEngineType(); 263 string osGetPhysicsEngineType();
264 Object osParseJSONNew(string JSON);
265 Hashtable osParseJSON(string JSON); 264 Hashtable osParseJSON(string JSON);
266 265
267 void osMessageObject(key objectUUID,string message); 266 void osMessageObject(key objectUUID,string message);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
new file mode 100644
index 0000000..4132dfa
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Runtime.Remoting.Lifetime;
30using System.Threading;
31using System.Reflection;
32using System.Collections;
33using System.Collections.Generic;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
38using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
46
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{
49 public partial class ScriptBaseClass : MarshalByRefObject
50 {
51 public ICM_Api m_CM_Functions;
52
53 public void ApiTypeCM(IScriptApi api)
54 {
55 if (!(api is ICM_Api))
56 return;
57
58 m_CM_Functions = (ICM_Api)api;
59 }
60
61 public string cmDetectedCountry(int num)
62 {
63 return m_CM_Functions.cmDetectedCountry(num);
64 }
65
66 public string cmGetAgentCountry(key key)
67 {
68 return m_CM_Functions.cmGetAgentCountry(key);
69 }
70 }
71}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
index ce17ed0..1cc2cfb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics; //for [DebuggerNonUserCode]
30using System.Reflection; 31using System.Reflection;
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using OpenSim.Region.ScriptEngine.Shared; 33using OpenSim.Region.ScriptEngine.Shared;
@@ -133,6 +134,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
133 return (eventFlags); 134 return (eventFlags);
134 } 135 }
135 136
137 [DebuggerNonUserCode]
136 public void ExecuteEvent(string state, string FunctionName, object[] args) 138 public void ExecuteEvent(string state, string FunctionName, object[] args)
137 { 139 {
138 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. 140 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 9aecea2..158acc6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -57,7 +57,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
57 public const int ACTIVE = 2; 57 public const int ACTIVE = 2;
58 public const int PASSIVE = 4; 58 public const int PASSIVE = 4;
59 public const int SCRIPTED = 8; 59 public const int SCRIPTED = 8;
60 public const int OS_NPC = 0x01000000;
61 60
62 public const int CONTROL_FWD = 1; 61 public const int CONTROL_FWD = 1;
63 public const int CONTROL_BACK = 2; 62 public const int CONTROL_BACK = 2;
@@ -82,6 +81,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
82 public const int PERMISSION_CHANGE_PERMISSIONS = 512; 81 public const int PERMISSION_CHANGE_PERMISSIONS = 512;
83 public const int PERMISSION_TRACK_CAMERA = 1024; 82 public const int PERMISSION_TRACK_CAMERA = 1024;
84 public const int PERMISSION_CONTROL_CAMERA = 2048; 83 public const int PERMISSION_CONTROL_CAMERA = 2048;
84 public const int PERMISSION_TELEPORT = 4096;
85 public const int PERMISSION_OVERRIDE_ANIMATIONS = 0x8000;
85 86
86 public const int AGENT_FLYING = 1; 87 public const int AGENT_FLYING = 1;
87 public const int AGENT_ATTACHMENTS = 2; 88 public const int AGENT_ATTACHMENTS = 2;
@@ -96,6 +97,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
96 public const int AGENT_CROUCHING = 1024; 97 public const int AGENT_CROUCHING = 1024;
97 public const int AGENT_BUSY = 2048; 98 public const int AGENT_BUSY = 2048;
98 public const int AGENT_ALWAYS_RUN = 4096; 99 public const int AGENT_ALWAYS_RUN = 4096;
100 public const int AGENT_MALE = 8192;
99 101
100 //Particle Systems 102 //Particle Systems
101 public const int PSYS_PART_INTERP_COLOR_MASK = 1; 103 public const int PSYS_PART_INTERP_COLOR_MASK = 1;
@@ -353,6 +355,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
353 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 355 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
354 public const int CHANGED_MEDIA = 2048; 356 public const int CHANGED_MEDIA = 2048;
355 public const int CHANGED_ANIMATION = 16384; 357 public const int CHANGED_ANIMATION = 16384;
358 public const int CHANGED_POSITION = 32768;
356 public const int TYPE_INVALID = 0; 359 public const int TYPE_INVALID = 0;
357 public const int TYPE_INTEGER = 1; 360 public const int TYPE_INTEGER = 1;
358 public const int TYPE_FLOAT = 2; 361 public const int TYPE_FLOAT = 2;
@@ -708,7 +711,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
708 public const int FRICTION = 2; 711 public const int FRICTION = 2;
709 public const int RESTITUTION = 4; 712 public const int RESTITUTION = 4;
710 public const int GRAVITY_MULTIPLIER = 8; 713 public const int GRAVITY_MULTIPLIER = 8;
711 714
712 // extra constants for llSetPrimMediaParams 715 // extra constants for llSetPrimMediaParams
713 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); 716 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0);
714 public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); 717 public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000);
@@ -795,6 +798,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
795 public const int KFM_CMD_STOP = 1; 798 public const int KFM_CMD_STOP = 1;
796 public const int KFM_CMD_PAUSE = 2; 799 public const int KFM_CMD_PAUSE = 2;
797 800
801 public const string JSON_ARRAY = "JSON_ARRAY";
802 public const string JSON_OBJECT = "JSON_OBJECT";
803 public const string JSON_INVALID = "JSON_INVALID";
804 public const string JSON_NUMBER = "JSON_NUMBER";
805 public const string JSON_STRING = "JSON_STRING";
806 public const string JSON_TRUE = "JSON_TRUE";
807 public const string JSON_FALSE = "JSON_FALSE";
808 public const string JSON_NULL = "JSON_NULL";
809 public const string JSON_APPEND = "JSON_APPEND";
810
798 /// <summary> 811 /// <summary>
799 /// process name parameter as regex 812 /// process name parameter as regex
800 /// </summary> 813 /// </summary>
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 35aaf01..2745637 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Diagnostics; //for [DebuggerNonUserCode]
29using System.Runtime.Remoting.Lifetime; 30using System.Runtime.Remoting.Lifetime;
30using System.Threading; 31using System.Threading;
31using System.Reflection; 32using System.Reflection;
@@ -314,6 +315,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
314 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); 315 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel);
315 } 316 }
316 317
318 [DebuggerNonUserCode]
317 public void llDie() 319 public void llDie()
318 { 320 {
319 m_LSL_Functions.llDie(); 321 m_LSL_Functions.llDie();
@@ -479,6 +481,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
479 return m_LSL_Functions.llGetFreeMemory(); 481 return m_LSL_Functions.llGetFreeMemory();
480 } 482 }
481 483
484 public LSL_Integer llGetUsedMemory()
485 {
486 return m_LSL_Functions.llGetUsedMemory();
487 }
488
482 public LSL_Integer llGetFreeURLs() 489 public LSL_Integer llGetFreeURLs()
483 { 490 {
484 return m_LSL_Functions.llGetFreeURLs(); 491 return m_LSL_Functions.llGetFreeURLs();
@@ -559,11 +566,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
559 return m_LSL_Functions.llGetLinkNumberOfSides(link); 566 return m_LSL_Functions.llGetLinkNumberOfSides(link);
560 } 567 }
561 568
562 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
563 {
564 m_LSL_Functions.llSetKeyframedMotion(frames, options);
565 }
566
567 public LSL_Integer llGetListEntryType(LSL_List src, int index) 569 public LSL_Integer llGetListEntryType(LSL_List src, int index)
568 { 570 {
569 return m_LSL_Functions.llGetListEntryType(src, index); 571 return m_LSL_Functions.llGetListEntryType(src, index);
@@ -859,11 +861,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
859 return m_LSL_Functions.llGetUnixTime(); 861 return m_LSL_Functions.llGetUnixTime();
860 } 862 }
861 863
862 public LSL_Integer llGetUsedMemory()
863 {
864 return m_LSL_Functions.llGetUsedMemory();
865 }
866
867 public LSL_Vector llGetVel() 864 public LSL_Vector llGetVel()
868 { 865 {
869 return m_LSL_Functions.llGetVel(); 866 return m_LSL_Functions.llGetVel();
@@ -884,9 +881,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
884 m_LSL_Functions.llGiveInventoryList(destination, category, inventory); 881 m_LSL_Functions.llGiveInventoryList(destination, category, inventory);
885 } 882 }
886 883
887 public void llGiveMoney(string destination, int amount) 884 public LSL_Integer llGiveMoney(string destination, int amount)
888 { 885 {
889 m_LSL_Functions.llGiveMoney(destination, amount); 886 return m_LSL_Functions.llGiveMoney(destination, amount);
890 } 887 }
891 888
892 public LSL_String llTransferLindenDollars(string destination, int amount) 889 public LSL_String llTransferLindenDollars(string destination, int amount)
@@ -1558,11 +1555,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1558 m_LSL_Functions.llSetForceAndTorque(force, torque, local); 1555 m_LSL_Functions.llSetForceAndTorque(force, torque, local);
1559 } 1556 }
1560 1557
1561 public void llSetVelocity(LSL_Vector force, int local)
1562 {
1563 m_LSL_Functions.llSetVelocity(force, local);
1564 }
1565
1566 public void llSetAngularVelocity(LSL_Vector force, int local) 1558 public void llSetAngularVelocity(LSL_Vector force, int local)
1567 { 1559 {
1568 m_LSL_Functions.llSetAngularVelocity(force, local); 1560 m_LSL_Functions.llSetAngularVelocity(force, local);
@@ -1643,6 +1635,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1643 m_LSL_Functions.llSetPos(pos); 1635 m_LSL_Functions.llSetPos(pos);
1644 } 1636 }
1645 1637
1638 public LSL_Integer llSetRegionPos(LSL_Vector pos)
1639 {
1640 return m_LSL_Functions.llSetRegionPos(pos);
1641 }
1642
1646 public void llSetPrimitiveParams(LSL_List rules) 1643 public void llSetPrimitiveParams(LSL_List rules)
1647 { 1644 {
1648 m_LSL_Functions.llSetPrimitiveParams(rules); 1645 m_LSL_Functions.llSetPrimitiveParams(rules);
@@ -1658,11 +1655,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1658 m_LSL_Functions.llSetPrimURL(url); 1655 m_LSL_Functions.llSetPrimURL(url);
1659 } 1656 }
1660 1657
1661 public LSL_Integer llSetRegionPos(LSL_Vector pos)
1662 {
1663 return m_LSL_Functions.llSetRegionPos(pos);
1664 }
1665
1666 public void llSetRemoteScriptAccessPin(int pin) 1658 public void llSetRemoteScriptAccessPin(int pin)
1667 { 1659 {
1668 m_LSL_Functions.llSetRemoteScriptAccessPin(pin); 1660 m_LSL_Functions.llSetRemoteScriptAccessPin(pin);
@@ -2008,9 +2000,64 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
2008 return m_LSL_Functions.llClearLinkMedia(link, face); 2000 return m_LSL_Functions.llClearLinkMedia(link, face);
2009 } 2001 }
2010 2002
2011 public void print(string str) 2003 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
2004 {
2005 return m_LSL_Functions.llGetLinkNumberOfSides(link);
2006 }
2007
2008 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
2009 {
2010 m_LSL_Functions.llSetKeyframedMotion(frames, options);
2011 }
2012
2013 public void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density)
2014 {
2015 m_LSL_Functions.llSetPhysicsMaterial(material_bits, material_gravity_modifier, material_restitution, material_friction, material_density);
2016 }
2017
2018 public LSL_List llGetPhysicsMaterial()
2019 {
2020 return m_LSL_Functions.llGetPhysicsMaterial();
2021 }
2022
2023 public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
2024 {
2025 m_LSL_Functions.llSetAnimationOverride(animState, anim);
2026 }
2027
2028 public void llResetAnimationOverride(LSL_String anim_state)
2029 {
2030 m_LSL_Functions.llResetAnimationOverride(anim_state);
2031 }
2032
2033 public LSL_String llGetAnimationOverride(LSL_String anim_state)
2034 {
2035 return m_LSL_Functions.llGetAnimationOverride(anim_state);
2036 }
2037
2038 public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
2039 {
2040 return m_LSL_Functions.llJsonGetValue(json, specifiers);
2041 }
2042
2043 public LSL_List llJson2List(LSL_String json)
2044 {
2045 return m_LSL_Functions.llJson2List(json);
2046 }
2047
2048 public LSL_String llList2Json(LSL_String type, LSL_List values)
2049 {
2050 return m_LSL_Functions.llList2Json(type, values);
2051 }
2052
2053 public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
2054 {
2055 return m_LSL_Functions.llJsonSetValue(json, specifiers, value);
2056 }
2057
2058 public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
2012 { 2059 {
2013 m_LSL_Functions.print(str); 2060 return m_LSL_Functions.llJsonValueType(json, specifiers);
2014 } 2061 }
2015 } 2062 }
2016} 2063}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
index 143b497..2e27f16 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
@@ -72,9 +72,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
72 { 72 {
73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); 73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
74 } 74 }
75
75 public void lsClearWindlightScene() 76 public void lsClearWindlightScene()
76 { 77 {
77 m_LS_Functions.lsClearWindlightScene(); 78 m_LS_Functions.lsClearWindlightScene();
78 } 79 }
80
81 public LSL_List cmGetWindlightScene(LSL_List rules)
82 {
83 return m_LS_Functions.lsGetWindlightScene(rules);
84 }
85
86 public int cmSetWindlightScene(LSL_List rules)
87 {
88 return m_LS_Functions.lsSetWindlightScene(rules);
89 }
90
91 public int cmSetWindlightSceneTargeted(LSL_List rules, key target)
92 {
93 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
94 }
95
96 public void cmClearWindlightScene()
97 {
98 m_LS_Functions.lsClearWindlightScene();
99 }
79 } 100 }
80} 101}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index a60f381..5fdbf9d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -440,11 +440,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
440 return m_OSSL_Functions.osParseJSON(JSON); 440 return m_OSSL_Functions.osParseJSON(JSON);
441 } 441 }
442 442
443 public Object osParseJSONNew(string JSON)
444 {
445 return m_OSSL_Functions.osParseJSONNew(JSON);
446 }
447
448 public void osMessageObject(key objectUUID,string message) 443 public void osMessageObject(key objectUUID,string message)
449 { 444 {
450 m_OSSL_Functions.osMessageObject(objectUUID,message); 445 m_OSSL_Functions.osMessageObject(objectUUID,message);
@@ -744,14 +739,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
744 if (Position.y > ((int)Constants.RegionSize - 1)) 739 if (Position.y > ((int)Constants.RegionSize - 1))
745 Position.y = ((int)Constants.RegionSize - 1); 740 Position.y = ((int)Constants.RegionSize - 1);
746 */ 741 */
742<<<<<<< HEAD
747 if (Position.z > Constants.RegionHeight) 743 if (Position.z > Constants.RegionHeight)
748 Position.z = Constants.RegionHeight; 744 Position.z = Constants.RegionHeight;
745=======
746>>>>>>> avn/ubitvar
749 if (Position.x < 0) 747 if (Position.x < 0)
750 Position.x = 0; 748 Position.x = 0;
751 if (Position.y < 0) 749 if (Position.y < 0)
752 Position.y = 0; 750 Position.y = 0;
753 if (Position.z < 0) 751 if (Position.z < 0)
754 Position.z = 0; 752 Position.z = 0;
753 if (Position.z > Constants.RegionHeight)
754 Position.z = Constants.RegionHeight;
755 prim.OSSL.llSetPos(Position); 755 prim.OSSL.llSetPos(Position);
756 } 756 }
757 757
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index edbbc2a..b138da3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -33,6 +33,7 @@ using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using System.Collections; 34using System.Collections;
35using System.Collections.Generic; 35using System.Collections.Generic;
36using System.Diagnostics; //for [DebuggerNonUserCode]
36using OpenSim.Region.ScriptEngine.Interfaces; 37using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared; 38using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; 39using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
@@ -90,6 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
90 return (int)m_Executor.GetStateEventFlags(state); 91 return (int)m_Executor.GetStateEventFlags(state);
91 } 92 }
92 93
94 [DebuggerNonUserCode]
93 public void ExecuteEvent(string state, string FunctionName, object[] args) 95 public void ExecuteEvent(string state, string FunctionName, object[] args)
94 { 96 {
95 m_Executor.ExecuteEvent(state, FunctionName, args); 97 m_Executor.ExecuteEvent(state, FunctionName, args);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index e02d35e..e44a106 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -35,6 +35,7 @@ using OpenMetaverse;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.CoreModules; 36using OpenSim.Region.CoreModules;
37using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
38using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
39 40
40namespace OpenSim.Region.ScriptEngine.Shared 41namespace OpenSim.Region.ScriptEngine.Shared
@@ -120,6 +121,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
120 Type = 0; 121 Type = 0;
121 Velocity = new LSL_Types.Vector3(); 122 Velocity = new LSL_Types.Vector3();
122 initializeSurfaceTouch(); 123 initializeSurfaceTouch();
124 Country = String.Empty;
123 } 125 }
124 126
125 public UUID Key; 127 public UUID Key;
@@ -151,6 +153,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
151 private int touchFace; 153 private int touchFace;
152 public int TouchFace { get { return touchFace; } } 154 public int TouchFace { get { return touchFace; } }
153 155
156 public string Country;
157
154 // This can be done in two places including the constructor 158 // This can be done in two places including the constructor
155 // so be carefull what gets added here 159 // so be carefull what gets added here
156 private void initializeSurfaceTouch() 160 private void initializeSurfaceTouch()
@@ -198,6 +202,10 @@ namespace OpenSim.Region.ScriptEngine.Shared
198 return; 202 return;
199 203
200 Name = presence.Firstname + " " + presence.Lastname; 204 Name = presence.Firstname + " " + presence.Lastname;
205 UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key);
206 if (account != null)
207 Country = account.UserCountry;
208
201 Owner = Key; 209 Owner = Key;
202 Position = new LSL_Types.Vector3(presence.AbsolutePosition); 210 Position = new LSL_Types.Vector3(presence.AbsolutePosition);
203 Rotation = new LSL_Types.Quaternion( 211 Rotation = new LSL_Types.Quaternion(
@@ -207,22 +215,27 @@ namespace OpenSim.Region.ScriptEngine.Shared
207 presence.Rotation.W); 215 presence.Rotation.W);
208 Velocity = new LSL_Types.Vector3(presence.Velocity); 216 Velocity = new LSL_Types.Vector3(presence.Velocity);
209 217
210 if (presence.PresenceType != PresenceType.Npc) 218 Type = 0x01; // Avatar
211 { 219 if (presence.PresenceType == PresenceType.Npc)
212 Type = AGENT; 220 Type = 0x20;
213 } 221
214 else 222 // Cope Impl. We don't use OS_NPC.
215 { 223 //if (presence.PresenceType != PresenceType.Npc)
216 Type = OS_NPC; 224 //{
217 225 // Type = AGENT;
218 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 226 //}
219 INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene); 227 //else
220 228 //{
221 if (npcData.SenseAsAgent) 229 // Type = OS_NPC;
222 { 230
223 Type |= AGENT; 231 // INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
224 } 232 // INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene);
225 } 233
234 // if (npcData.SenseAsAgent)
235 // {
236 // Type |= AGENT;
237 // }
238 //}
226 239
227 if (presence.Velocity != Vector3.Zero) 240 if (presence.Velocity != Vector3.Zero)
228 Type |= ACTIVE; 241 Type |= ACTIVE;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index fa6e6fc..49df5e7 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Globalization; 31using System.Globalization;
32using System.IO; 32using System.IO;
33using System.Diagnostics; //for [DebuggerNonUserCode]
33using System.Reflection; 34using System.Reflection;
34using System.Runtime.Remoting; 35using System.Runtime.Remoting;
35using System.Runtime.Remoting.Lifetime; 36using System.Runtime.Remoting.Lifetime;
@@ -186,13 +187,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
186 187
187 public UUID ItemID { get; private set; } 188 public UUID ItemID { get; private set; }
188 189
189 public UUID ObjectID { get { return Part.UUID; } } 190 public UUID ObjectID { get; private set; }
190 191
191 public uint LocalID { get { return Part.LocalId; } } 192 public uint LocalID { get; private set; }
192 193
193 public UUID RootObjectID { get { return Part.ParentGroup.UUID; } } 194 public UUID RootObjectID { get; private set; }
194 195
195 public uint RootLocalID { get { return Part.ParentGroup.LocalId; } } 196 public uint RootLocalID { get; private set; }
196 197
197 public UUID AssetID { get; private set; } 198 public UUID AssetID { get; private set; }
198 199
@@ -251,13 +252,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
251 ItemID = ScriptTask.ItemID; 252 ItemID = ScriptTask.ItemID;
252 AssetID = ScriptTask.AssetID; 253 AssetID = ScriptTask.AssetID;
253 } 254 }
255 LocalID = part.LocalId;
254 256
255 PrimName = part.ParentGroup.Name; 257 PrimName = part.ParentGroup.Name;
256 StartParam = startParam; 258 StartParam = startParam;
257 m_MaxScriptQueue = maxScriptQueue; 259 m_MaxScriptQueue = maxScriptQueue;
258 m_postOnRez = postOnRez; 260 m_postOnRez = postOnRez;
259 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 261 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
260 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 262 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
261 263
262 m_SaveState = StatePersistedHere; 264 m_SaveState = StatePersistedHere;
263 265
@@ -456,27 +458,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
456 PostEvent(new EventParams("attach", 458 PostEvent(new EventParams("attach",
457 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 459 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
458 } 460 }
461
459 } 462 }
460 } 463 }
461 464
462 private void ReleaseControls() 465 private void ReleaseControls()
463 { 466 {
464 int permsMask; 467 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
465 UUID permsGranter; 468
466 lock (Part.TaskInventory) 469 if (part != null)
467 { 470 {
468 if (!Part.TaskInventory.ContainsKey(ItemID)) 471 int permsMask;
472 UUID permsGranter;
473 part.TaskInventory.LockItemsForRead(true);
474 if (!part.TaskInventory.ContainsKey(ItemID))
475 {
476 part.TaskInventory.LockItemsForRead(false);
469 return; 477 return;
478 }
479 permsGranter = part.TaskInventory[ItemID].PermsGranter;
480 permsMask = part.TaskInventory[ItemID].PermsMask;
481 part.TaskInventory.LockItemsForRead(false);
470 482
471 permsGranter = Part.TaskInventory[ItemID].PermsGranter; 483 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
472 permsMask = Part.TaskInventory[ItemID].PermsMask; 484 {
473 } 485 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
474 486 if (presence != null)
475 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 487 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
476 { 488 }
477 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
478 if (presence != null)
479 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
480 } 489 }
481 } 490 }
482 491
@@ -639,11 +648,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
639 return true; 648 return true;
640 } 649 }
641 650
651 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
642 public void SetState(string state) 652 public void SetState(string state)
643 { 653 {
644 if (state == State) 654 if (state == State)
645 return; 655 return;
646 656
657<<<<<<< HEAD
647 EventParams lastTimerEv = null; 658 EventParams lastTimerEv = null;
648 659
649 lock (EventQueue) 660 lock (EventQueue)
@@ -671,6 +682,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
671 m_StateChangeInProgress = true; 682 m_StateChangeInProgress = true;
672 } 683 }
673 684
685=======
686 PostEvent(new EventParams("state_exit", new Object[0],
687 new DetectParams[0]));
688 PostEvent(new EventParams("state", new Object[] { state },
689 new DetectParams[0]));
690 PostEvent(new EventParams("state_entry", new Object[0],
691 new DetectParams[0]));
692
693>>>>>>> avn/ubitvar
674 throw new EventAbortException(); 694 throw new EventAbortException();
675 } 695 }
676 696
@@ -764,14 +784,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
764 /// <returns></returns> 784 /// <returns></returns>
765 public object EventProcessor() 785 public object EventProcessor()
766 { 786 {
787 EventParams data = null;
767 // We check here as the thread stopping this instance from running may itself hold the m_Script lock. 788 // We check here as the thread stopping this instance from running may itself hold the m_Script lock.
768 if (!Running) 789 if (!Running)
769 return 0; 790 return 0;
770 791
771 lock (m_Script)
772 {
773// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); 792// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName);
774 793
794<<<<<<< HEAD
775 if (Suspended) 795 if (Suspended)
776 return 0; 796 return 0;
777 797
@@ -797,6 +817,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
797 lock (EventQueue) 817 lock (EventQueue)
798 { 818 {
799 data = (EventParams)EventQueue.Dequeue(); 819 data = (EventParams)EventQueue.Dequeue();
820=======
821 if (Suspended)
822 return 0;
823
824 lock (EventQueue)
825 {
826 data = (EventParams) EventQueue.Dequeue();
827>>>>>>> avn/ubitvar
800 if (data == null) // Shouldn't happen 828 if (data == null) // Shouldn't happen
801 { 829 {
802 if (EventQueue.Count > 0 && Running && !ShuttingDown) 830 if (EventQueue.Count > 0 && Running && !ShuttingDown)
@@ -821,6 +849,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
821 m_CollisionInQueue = false; 849 m_CollisionInQueue = false;
822 } 850 }
823 851
852<<<<<<< HEAD
824 if (DebugLevel >= 2) 853 if (DebugLevel >= 2)
825 m_log.DebugFormat( 854 m_log.DebugFormat(
826 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 855 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
@@ -850,6 +879,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
850 Part.ParentGroup.UUID, 879 Part.ParentGroup.UUID,
851 Part.AbsolutePosition, 880 Part.AbsolutePosition,
852 Part.ParentGroup.Scene.Name); 881 Part.ParentGroup.Scene.Name);
882=======
883 lock(m_Script)
884 {
885
886// m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this);
887 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
888
889 if (DebugLevel >= 2)
890 m_log.DebugFormat(
891 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
892 data.EventName,
893 ScriptName,
894 part.Name,
895 part.LocalId,
896 part.ParentGroup.Name,
897 part.ParentGroup.UUID,
898 part.AbsolutePosition,
899 part.ParentGroup.Scene.Name);
900>>>>>>> avn/ubitvar
853 901
854 AsyncCommandManager.StateChange(Engine, 902 AsyncCommandManager.StateChange(Engine,
855 LocalID, ItemID); 903 LocalID, ItemID);
@@ -867,7 +915,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
867 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", 915 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
868 // PrimName, ScriptName, data.EventName, State); 916 // PrimName, ScriptName, data.EventName, State);
869 917
918<<<<<<< HEAD
870 try 919 try
920=======
921 if (DebugLevel >= 1)
922 m_log.DebugFormat(
923 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
924 State,
925 ScriptName,
926 part.Name,
927 part.LocalId,
928 part.ParentGroup.Name,
929 part.ParentGroup.UUID,
930 part.AbsolutePosition,
931 part.ParentGroup.Scene.Name);
932
933 AsyncCommandManager.RemoveScript(Engine,
934 LocalID, ItemID);
935
936 if (part != null)
937 {
938 part.SetScriptEvents(ItemID,
939 (int)m_Script.GetStateEventFlags(State));
940 }
941 }
942 else
943 {
944 if (Engine.World.PipeEventsForScript(LocalID) ||
945 data.EventName == "control") // Don't freeze avies!
946>>>>>>> avn/ubitvar
871 { 947 {
872 m_CurrentEvent = data.EventName; 948 m_CurrentEvent = data.EventName;
873 m_EventStart = DateTime.Now; 949 m_EventStart = DateTime.Now;
@@ -905,6 +981,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
905 && !(e.InnerException is ScriptCoopStopException))) 981 && !(e.InnerException is ScriptCoopStopException)))
906 && !(e is ThreadAbortException)) 982 && !(e is ThreadAbortException))
907 { 983 {
984<<<<<<< HEAD
908 try 985 try
909 { 986 {
910 // DISPLAY ERROR INWORLD 987 // DISPLAY ERROR INWORLD
@@ -927,9 +1004,78 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
927 Part.AbsolutePosition, 1004 Part.AbsolutePosition,
928 Part.ParentGroup.Scene.Name), 1005 Part.ParentGroup.Scene.Name),
929 e); 1006 e);
1007=======
1008// m_log.DebugFormat(
1009// "[SCRIPT] Exception in script {0} {1}: {2}{3}",
1010// ScriptName, ItemID, e.Message, e.StackTrace);
1011
1012 m_InEvent = false;
1013 m_CurrentEvent = String.Empty;
1014
1015 if ((!(e is TargetInvocationException)
1016 || (!(e.InnerException is SelfDeleteException)
1017 && !(e.InnerException is ScriptDeleteException)
1018 && !(e.InnerException is ScriptCoopStopException)))
1019 && !(e is ThreadAbortException))
1020 {
1021 try
1022 {
1023 // DISPLAY ERROR INWORLD
1024 string text = FormatException(e);
1025
1026 if (text.Length > 1000)
1027 text = text.Substring(0, 1000);
1028 Engine.World.SimChat(Utils.StringToBytes(text),
1029 ChatTypeEnum.DebugChannel, 2147483647,
1030 part.AbsolutePosition,
1031 part.Name, part.UUID, false);
1032
1033
1034 m_log.DebugFormat(
1035 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
1036 ScriptName,
1037 PrimName,
1038 part.UUID,
1039 part.AbsolutePosition,
1040 part.ParentGroup.Scene.Name,
1041 text.Replace("\n", "\\n"),
1042 e.InnerException);
1043 }
1044 catch (Exception)
1045 {
1046 }
1047 // catch (Exception e2) // LEGIT: User Scripting
1048 // {
1049 // m_log.Error("[SCRIPT]: "+
1050 // "Error displaying error in-world: " +
1051 // e2.ToString());
1052 // m_log.Error("[SCRIPT]: " +
1053 // "Errormessage: Error compiling script:\r\n" +
1054 // e.ToString());
1055 // }
1056 }
1057 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
1058 {
1059 m_InSelfDelete = true;
1060 if (part != null)
1061 Engine.World.DeleteSceneObject(part.ParentGroup, false);
1062>>>>>>> avn/ubitvar
930 } 1063 }
931 catch (Exception) 1064 catch (Exception)
932 { 1065 {
1066<<<<<<< HEAD
1067=======
1068 m_InSelfDelete = true;
1069 if (part != null)
1070 part.Inventory.RemoveInventoryItem(ItemID);
1071 }
1072 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
1073 {
1074 if (DebugLevel >= 1)
1075 m_log.DebugFormat(
1076 "[SCRIPT INSTANCE]: Script {0}.{1} in event {2}, state {3} stopped co-operatively.",
1077 PrimName, ScriptName, data.EventName, State);
1078>>>>>>> avn/ubitvar
933 } 1079 }
934 // catch (Exception e2) // LEGIT: User Scripting 1080 // catch (Exception e2) // LEGIT: User Scripting
935 // { 1081 // {
@@ -1012,15 +1158,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1012 ReleaseControls(); 1158 ReleaseControls();
1013 1159
1014 Stop(timeout); 1160 Stop(timeout);
1015 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 1161 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
1016 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 1162 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1163 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1164 part.CollisionSound = UUID.Zero;
1017 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1165 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
1018 EventQueue.Clear(); 1166 EventQueue.Clear();
1019 m_Script.ResetVars(); 1167 m_Script.ResetVars();
1020 StartParam = 0; 1168 StartParam = 0;
1021 State = "default"; 1169 State = "default";
1022 1170
1023 Part.SetScriptEvents(ItemID, 1171 part.SetScriptEvents(ItemID,
1024 (int)m_Script.GetStateEventFlags(State)); 1172 (int)m_Script.GetStateEventFlags(State));
1025 if (running) 1173 if (running)
1026 Start(); 1174 Start();
@@ -1031,6 +1179,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1031 new Object[0], new DetectParams[0])); 1179 new Object[0], new DetectParams[0]));
1032 } 1180 }
1033 1181
1182 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
1034 public void ApiResetScript() 1183 public void ApiResetScript()
1035 { 1184 {
1036 // bool running = Running; 1185 // bool running = Running;
@@ -1039,8 +1188,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1039 ReleaseControls(); 1188 ReleaseControls();
1040 1189
1041 m_Script.ResetVars(); 1190 m_Script.ResetVars();
1042 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 1191 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
1043 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 1192 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1193 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1194 part.CollisionSound = UUID.Zero;
1044 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1195 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
1045 1196
1046 EventQueue.Clear(); 1197 EventQueue.Clear();
@@ -1049,7 +1200,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1049 StartParam = 0; 1200 StartParam = 0;
1050 State = "default"; 1201 State = "default";
1051 1202
1052 Part.SetScriptEvents(ItemID, 1203 part.SetScriptEvents(ItemID,
1053 (int)m_Script.GetStateEventFlags(State)); 1204 (int)m_Script.GetStateEventFlags(State));
1054 1205
1055 if (m_CurrentEvent != "state_entry" || oldState != "default") 1206 if (m_CurrentEvent != "state_entry" || oldState != "default")
@@ -1063,10 +1214,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1063 1214
1064 public Dictionary<string, object> GetVars() 1215 public Dictionary<string, object> GetVars()
1065 { 1216 {
1066 if (m_Script != null) 1217 return m_Script.GetVars();
1067 return m_Script.GetVars();
1068 else
1069 return new Dictionary<string, object>();
1070 } 1218 }
1071 1219
1072 public void SetVars(Dictionary<string, object> vars) 1220 public void SetVars(Dictionary<string, object> vars)
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 0ca5ff3..885559a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -102,19 +102,31 @@ namespace OpenSim.Region.ScriptEngine.Shared
102 102
103 public override string ToString() 103 public override string ToString()
104 { 104 {
105<<<<<<< HEAD
105 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); 106 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z);
107=======
108 string s = String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}>", x, y, z);
109>>>>>>> avn/ubitvar
106 return s; 110 return s;
107 } 111 }
108 112
109 public static explicit operator LSLString(Vector3 vec) 113 public static explicit operator LSLString(Vector3 vec)
110 { 114 {
115<<<<<<< HEAD
111 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 116 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z);
117=======
118 string s = String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
119>>>>>>> avn/ubitvar
112 return new LSLString(s); 120 return new LSLString(s);
113 } 121 }
114 122
115 public static explicit operator string(Vector3 vec) 123 public static explicit operator string(Vector3 vec)
116 { 124 {
125<<<<<<< HEAD
117 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 126 string s=String.Format(Culture.FormatProvider,"<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z);
127=======
128 string s = String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
129>>>>>>> avn/ubitvar
118 return s; 130 return s;
119 } 131 }
120 132
@@ -414,19 +426,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
414 426
415 public override string ToString() 427 public override string ToString()
416 { 428 {
417 string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); 429 string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s);
418 return st; 430 return st;
419 } 431 }
420 432
421 public static explicit operator string(Quaternion r) 433 public static explicit operator string(Quaternion r)
422 { 434 {
423 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 435 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
424 return s; 436 return s;
425 } 437 }
426 438
427 public static explicit operator LSLString(Quaternion r) 439 public static explicit operator LSLString(Quaternion r)
428 { 440 {
429 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 441 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
430 return new LSLString(s); 442 return new LSLString(s);
431 } 443 }
432 444
@@ -537,7 +549,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
537 else if (o is LSL_Types.LSLFloat) 549 else if (o is LSL_Types.LSLFloat)
538 size += 8; 550 size += 8;
539 else if (o is LSL_Types.LSLString) 551 else if (o is LSL_Types.LSLString)
540 size += ((LSL_Types.LSLString)o).m_string.Length; 552 size += ((LSL_Types.LSLString)o).m_string == null ? 0 : ((LSL_Types.LSLString)o).m_string.Length;
541 else if (o is LSL_Types.key) 553 else if (o is LSL_Types.key)
542 size += ((LSL_Types.key)o).value.Length; 554 size += ((LSL_Types.key)o).value.Length;
543 else if (o is LSL_Types.Vector3) 555 else if (o is LSL_Types.Vector3)
@@ -546,6 +558,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
546 size += 64; 558 size += 64;
547 else if (o is int) 559 else if (o is int)
548 size += 4; 560 size += 4;
561 else if (o is uint)
562 size += 4;
549 else if (o is string) 563 else if (o is string)
550 size += ((string)o).Length; 564 size += ((string)o).Length;
551 else if (o is float) 565 else if (o is float)
@@ -713,10 +727,17 @@ namespace OpenSim.Region.ScriptEngine.Shared
713 private void ExtendAndAdd(object o) 727 private void ExtendAndAdd(object o)
714 { 728 {
715 object[] tmp; 729 object[] tmp;
730<<<<<<< HEAD
716 tmp = new object[Data.Length + 1]; 731 tmp = new object[Data.Length + 1];
717 Data.CopyTo(tmp, 0); 732 Data.CopyTo(tmp, 0);
718 tmp.SetValue(o, tmp.Length - 1); 733 tmp.SetValue(o, tmp.Length - 1);
719 Data = tmp; 734 Data = tmp;
735=======
736 tmp = new object[m_data.Length + 1];
737 m_data.CopyTo(tmp, 0);
738 tmp.SetValue(o, tmp.Length - 1);
739 m_data = tmp;
740>>>>>>> avn/ubitvar
720 } 741 }
721 742
722 public static list operator +(list a, LSLString s) 743 public static list operator +(list a, LSLString s)
@@ -739,24 +760,16 @@ namespace OpenSim.Region.ScriptEngine.Shared
739 760
740 public static bool operator ==(list a, list b) 761 public static bool operator ==(list a, list b)
741 { 762 {
742 int la = -1; 763 int la = a.Length;
743 int lb = -1; 764 int lb = b.Length;
744 try { la = a.Length; }
745 catch (NullReferenceException) { }
746 try { lb = b.Length; }
747 catch (NullReferenceException) { }
748 765
749 return la == lb; 766 return la == lb;
750 } 767 }
751 768
752 public static bool operator !=(list a, list b) 769 public static bool operator !=(list a, list b)
753 { 770 {
754 int la = -1; 771 int la = a.Length;
755 int lb = -1; 772 int lb = b.Length;
756 try { la = a.Length; }
757 catch (NullReferenceException) { }
758 try {lb = b.Length;}
759 catch (NullReferenceException) { }
760 773
761 return la != lb; 774 return la != lb;
762 } 775 }
@@ -990,7 +1003,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
990 ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r)); 1003 ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r));
991 } 1004 }
992 1005
993 if (ascending == 0) 1006 if (ascending != 1)
994 { 1007 {
995 ret = 0 - ret; 1008 ret = 0 - ret;
996 } 1009 }
@@ -1023,6 +1036,9 @@ namespace OpenSim.Region.ScriptEngine.Shared
1023 stride = 1; 1036 stride = 1;
1024 } 1037 }
1025 1038
1039 if ((Data.Length % stride) != 0)
1040 return new list(ret);
1041
1026 // we can optimize here in the case where stride == 1 and the list 1042 // we can optimize here in the case where stride == 1 and the list
1027 // consists of homogeneous types 1043 // consists of homogeneous types
1028 1044
@@ -1042,7 +1058,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1042 if (homogeneous) 1058 if (homogeneous)
1043 { 1059 {
1044 Array.Sort(ret, new HomogeneousComparer()); 1060 Array.Sort(ret, new HomogeneousComparer());
1045 if (ascending == 0) 1061 if (ascending != 1)
1046 { 1062 {
1047 Array.Reverse(ret); 1063 Array.Reverse(ret);
1048 } 1064 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
index 0ff2da3..ad775ff 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
@@ -245,6 +245,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
245 DetectParams d = new DetectParams(); 245 DetectParams d = new DetectParams();
246 d.Key =detobj.keyUUID; 246 d.Key =detobj.keyUUID;
247 d.Populate(myScriptEngine.World); 247 d.Populate(myScriptEngine.World);
248 d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
248 det.Add(d); 249 det.Add(d);
249 } 250 }
250 251
@@ -265,6 +266,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
265 DetectParams d = new DetectParams(); 266 DetectParams d = new DetectParams();
266 d.Key =detobj.keyUUID; 267 d.Key =detobj.keyUUID;
267 d.Populate(myScriptEngine.World); 268 d.Populate(myScriptEngine.World);
269 d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
268 det.Add(d); 270 det.Add(d);
269 } 271 }
270 272
@@ -284,6 +286,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
284 DetectParams d = new DetectParams(); 286 DetectParams d = new DetectParams();
285 d.Key =detobj.keyUUID; 287 d.Key =detobj.keyUUID;
286 d.Populate(myScriptEngine.World); 288 d.Populate(myScriptEngine.World);
289 d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
287 det.Add(d); 290 det.Add(d);
288 } 291 }
289 292
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 78d4ee9..466c190 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; //for [DebuggerNonUserCode]
31using System.Globalization; 32using System.Globalization;
32using System.IO; 33using System.IO;
33using System.Linq; 34using System.Linq;
@@ -161,6 +162,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
161 private Dictionary<UUID, IScriptInstance> m_Scripts = 162 private Dictionary<UUID, IScriptInstance> m_Scripts =
162 new Dictionary<UUID, IScriptInstance>(); 163 new Dictionary<UUID, IScriptInstance>();
163 164
165 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
166
164 // Maps the asset ID to the assembly 167 // Maps the asset ID to the assembly
165 168
166 private Dictionary<UUID, string> m_Assemblies = 169 private Dictionary<UUID, string> m_Assemblies =
@@ -183,6 +186,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
183 IWorkItemResult m_CurrentCompile = null; 186 IWorkItemResult m_CurrentCompile = null;
184 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 187 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
185 188
189 private void lockScriptsForRead(bool locked)
190 {
191 if (locked)
192 {
193 if (m_scriptsLock.RecursiveReadCount > 0)
194 {
195 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
196 m_scriptsLock.ExitReadLock();
197 }
198 if (m_scriptsLock.RecursiveWriteCount > 0)
199 {
200 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
201 m_scriptsLock.ExitWriteLock();
202 }
203
204 while (!m_scriptsLock.TryEnterReadLock(60000))
205 {
206 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
207 if (m_scriptsLock.IsWriteLockHeld)
208 {
209 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
210 }
211 }
212 }
213 else
214 {
215 if (m_scriptsLock.RecursiveReadCount > 0)
216 {
217 m_scriptsLock.ExitReadLock();
218 }
219 }
220 }
221 private void lockScriptsForWrite(bool locked)
222 {
223 if (locked)
224 {
225 if (m_scriptsLock.RecursiveReadCount > 0)
226 {
227 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
228 m_scriptsLock.ExitReadLock();
229 }
230 if (m_scriptsLock.RecursiveWriteCount > 0)
231 {
232 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
233 m_scriptsLock.ExitWriteLock();
234 }
235
236 while (!m_scriptsLock.TryEnterWriteLock(60000))
237 {
238 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
239 if (m_scriptsLock.IsWriteLockHeld)
240 {
241 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
242 }
243 }
244 }
245 else
246 {
247 if (m_scriptsLock.RecursiveWriteCount > 0)
248 {
249 m_scriptsLock.ExitWriteLock();
250 }
251 }
252 }
253
186 private ScriptEngineConsoleCommands m_consoleCommands; 254 private ScriptEngineConsoleCommands m_consoleCommands;
187 255
188 public string ScriptEngineName 256 public string ScriptEngineName
@@ -714,20 +782,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine
714 { 782 {
715 if (!m_Enabled) 783 if (!m_Enabled)
716 return; 784 return;
785 lockScriptsForRead(true);
717 786
718 lock (m_Scripts) 787 List<IScriptInstance> instancesToDel = new List<IScriptInstance>(m_Scripts.Values);
719 {
720 m_log.InfoFormat(
721 "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName);
722 788
723 foreach (IScriptInstance instance in m_Scripts.Values) 789// foreach (IScriptInstance instance in m_Scripts.Values)
790 foreach (IScriptInstance instance in instancesToDel)
791 {
792 // Force a final state save
793 //
794 if (m_Assemblies.ContainsKey(instance.AssetID))
724 { 795 {
796<<<<<<< HEAD
725 // Force a final state save 797 // Force a final state save
726 // 798 //
727 try 799 try
728 { 800 {
729 if (instance.StatePersistedHere) 801 if (instance.StatePersistedHere)
730 instance.SaveState(); 802 instance.SaveState();
803=======
804 string assembly = m_Assemblies[instance.AssetID];
805
806 try
807 {
808 instance.SaveState(assembly);
809>>>>>>> avn/ubitvar
731 } 810 }
732 catch (Exception e) 811 catch (Exception e)
733 { 812 {
@@ -737,36 +816,50 @@ namespace OpenSim.Region.ScriptEngine.XEngine
737 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name) 816 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
738 , e); 817 , e);
739 } 818 }
819 }
740 820
821<<<<<<< HEAD
741 // Clear the event queue and abort the instance thread 822 // Clear the event queue and abort the instance thread
742 // 823 //
743 instance.Stop(0, true); 824 instance.Stop(0, true);
825=======
826 // Clear the event queue and abort the instance thread
827 //
828 instance.ClearQueue();
829 instance.Stop(0);
830>>>>>>> avn/ubitvar
744 831
745 // Release events, timer, etc 832 // Release events, timer, etc
746 // 833 //
747 instance.DestroyScriptInstance(); 834 instance.DestroyScriptInstance();
748 835
749 // Unload scripts and app domains. 836 // Unload scripts and app domains
750 // Must be done explicitly because they have infinite 837 // Must be done explicitly because they have infinite
751 // lifetime. 838 // lifetime
752 // However, don't bother to do this if the simulator is shutting 839 //
753 // down since it takes a long time with many scripts. 840// if (!m_SimulatorShuttingDown)
754 if (!m_SimulatorShuttingDown) 841 {
842 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
843 if (m_DomainScripts[instance.AppDomain].Count == 0)
755 { 844 {
756 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 845 m_DomainScripts.Remove(instance.AppDomain);
757 if (m_DomainScripts[instance.AppDomain].Count == 0) 846 UnloadAppDomain(instance.AppDomain);
758 {
759 m_DomainScripts.Remove(instance.AppDomain);
760 UnloadAppDomain(instance.AppDomain);
761 }
762 } 847 }
763 } 848 }
764 849
765 m_Scripts.Clear(); 850// m_Scripts.Clear();
766 m_PrimObjects.Clear(); 851// m_PrimObjects.Clear();
767 m_Assemblies.Clear(); 852// m_Assemblies.Clear();
768 m_DomainScripts.Clear(); 853// m_DomainScripts.Clear();
769 } 854 }
855 lockScriptsForRead(false);
856 lockScriptsForWrite(true);
857 m_Scripts.Clear();
858 lockScriptsForWrite(false);
859 m_PrimObjects.Clear();
860 m_Assemblies.Clear();
861 m_DomainScripts.Clear();
862
770 lock (m_ScriptEngines) 863 lock (m_ScriptEngines)
771 { 864 {
772 m_ScriptEngines.Remove(this); 865 m_ScriptEngines.Remove(this);
@@ -835,6 +928,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
835 928
836 List<IScriptInstance> instances = new List<IScriptInstance>(); 929 List<IScriptInstance> instances = new List<IScriptInstance>();
837 930
931<<<<<<< HEAD
838 lock (m_Scripts) 932 lock (m_Scripts)
839 { 933 {
840 foreach (IScriptInstance instance in m_Scripts.Values) 934 foreach (IScriptInstance instance in m_Scripts.Values)
@@ -852,6 +946,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
852 946
853 foreach (IScriptInstance i in instances) 947 foreach (IScriptInstance i in instances)
854 { 948 {
949=======
950 lockScriptsForRead(true);
951 foreach (IScriptInstance instance in m_Scripts.Values)
952 instances.Add(instance);
953 lockScriptsForRead(false);
954
955 foreach (IScriptInstance i in instances)
956 {
957 string assembly = String.Empty;
958
959
960 if (!m_Assemblies.ContainsKey(i.AssetID))
961 continue;
962 assembly = m_Assemblies[i.AssetID];
963
964
965>>>>>>> avn/ubitvar
855 try 966 try
856 { 967 {
857 i.SaveState(); 968 i.SaveState();
@@ -1282,58 +1393,79 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1282 } 1393 }
1283 1394
1284 ScriptInstance instance = null; 1395 ScriptInstance instance = null;
1285 lock (m_Scripts) 1396 // Create the object record
1397 UUID appDomain = assetID;
1398
1399
1400
1401 lockScriptsForRead(true);
1402 if ((!m_Scripts.ContainsKey(itemID)) ||
1403 (m_Scripts[itemID].AssetID != assetID))
1286 { 1404 {
1287 // Create the object record 1405 lockScriptsForRead(false);
1288 if ((!m_Scripts.ContainsKey(itemID)) || 1406 instance = new ScriptInstance(this, part,
1289 (m_Scripts[itemID].AssetID != assetID)) 1407 item,
1290 { 1408 startParam, postOnRez,
1291 UUID appDomain = assetID; 1409 m_MaxScriptQueue);
1292 1410
1293 if (part.ParentGroup.IsAttachment) 1411 if (part.ParentGroup.IsAttachment)
1294 appDomain = part.ParentGroup.RootPart.UUID; 1412 appDomain = part.ParentGroup.RootPart.UUID;
1295 1413
1296 if (!m_AppDomains.ContainsKey(appDomain)) 1414 if (!m_AppDomains.ContainsKey(appDomain))
1415 {
1416 try
1297 { 1417 {
1298 try 1418 AppDomainSetup appSetup = new AppDomainSetup();
1299 { 1419 appSetup.PrivateBinPath = Path.Combine(
1300 AppDomainSetup appSetup = new AppDomainSetup(); 1420 m_ScriptEnginesPath,
1301 appSetup.PrivateBinPath = Path.Combine( 1421 m_Scene.RegionInfo.RegionID.ToString());
1302 m_ScriptEnginesPath,
1303 m_Scene.RegionInfo.RegionID.ToString());
1304 1422
1305 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 1423 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
1306 Evidence evidence = new Evidence(baseEvidence); 1424 Evidence evidence = new Evidence(baseEvidence);
1307 1425
1308 AppDomain sandbox; 1426 AppDomain sandbox;
1309 if (m_AppDomainLoading) 1427 if (m_AppDomainLoading)
1428 {
1429 sandbox = AppDomain.CreateDomain(
1430 m_Scene.RegionInfo.RegionID.ToString(),
1431 evidence, appSetup);
1432 if (m_AppDomains.ContainsKey(appDomain))
1310 { 1433 {
1311 sandbox = AppDomain.CreateDomain( 1434 m_AppDomains[appDomain].AssemblyResolve +=
1312 m_Scene.RegionInfo.RegionID.ToString(),
1313 evidence, appSetup);
1314 sandbox.AssemblyResolve +=
1315 new ResolveEventHandler( 1435 new ResolveEventHandler(
1316 AssemblyResolver.OnAssemblyResolve); 1436 AssemblyResolver.OnAssemblyResolve);
1437 if (m_DomainScripts.ContainsKey(appDomain))
1438 {
1439 m_DomainScripts[appDomain].Add(itemID);
1440 }
1441 else
1442 {
1443 m_DomainScripts.Add(appDomain, new List<UUID>());
1444 m_DomainScripts[appDomain].Add(itemID);
1445 }
1317 } 1446 }
1318 else 1447 else
1319 { 1448 {
1320 sandbox = AppDomain.CurrentDomain; 1449 m_AppDomains.Add(appDomain, sandbox);
1450 m_AppDomains[appDomain].AssemblyResolve +=
1451 new ResolveEventHandler(
1452 AssemblyResolver.OnAssemblyResolve);
1453 if (m_DomainScripts.ContainsKey(appDomain))
1454 {
1455 m_DomainScripts[appDomain].Add(itemID);
1456 }
1457 else
1458 {
1459 m_DomainScripts.Add(appDomain, new List<UUID>());
1460 m_DomainScripts[appDomain].Add(itemID);
1461 }
1462
1321 } 1463 }
1322
1323 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1324 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
1325 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
1326 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
1327 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
1328 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
1329 //sandbox.SetAppDomainPolicy(sandboxPolicy);
1330
1331 m_AppDomains[appDomain] = sandbox;
1332 1464
1333 m_DomainScripts[appDomain] = new List<UUID>();
1334 } 1465 }
1335 catch (Exception e) 1466 else
1336 { 1467 {
1468<<<<<<< HEAD
1337 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 1469 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
1338 m_ScriptErrorMessage += "Exception creating app domain:\n"; 1470 m_ScriptErrorMessage += "Exception creating app domain:\n";
1339 m_ScriptFailCount++; 1471 m_ScriptFailCount++;
@@ -1342,10 +1474,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1342 m_AddingAssemblies[assemblyPath]--; 1474 m_AddingAssemblies[assemblyPath]--;
1343 } 1475 }
1344 return false; 1476 return false;
1477=======
1478 sandbox = AppDomain.CurrentDomain;
1479>>>>>>> avn/ubitvar
1345 } 1480 }
1346 }
1347 m_DomainScripts[appDomain].Add(itemID);
1348 1481
1482<<<<<<< HEAD
1349 IScript scriptObj = null; 1483 IScript scriptObj = null;
1350 EventWaitHandle coopSleepHandle; 1484 EventWaitHandle coopSleepHandle;
1351 bool coopTerminationForThisScript; 1485 bool coopTerminationForThisScript;
@@ -1477,26 +1611,52 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1477 scriptObj, coopSleepHandle, assemblyPath, 1611 scriptObj, coopSleepHandle, assemblyPath,
1478 Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript)) 1612 Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript))
1479 return false; 1613 return false;
1614=======
1615// if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource))
1616// return false;
1617>>>>>>> avn/ubitvar
1480 1618
1481// if (DebugLevel >= 1) 1619 m_AppDomains[appDomain] = sandbox;
1482// m_log.DebugFormat(
1483// "[XEngine] Loaded script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}",
1484// part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID,
1485// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1486 1620
1487 if (presence != null) 1621 m_DomainScripts[appDomain] = new List<UUID>();
1622 }
1623 catch (Exception e)
1488 { 1624 {
1489 ShowScriptSaveResponse(item.OwnerID, 1625 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
1490 assetID, "Compile successful", true); 1626 m_ScriptErrorMessage += "Exception creating app domain:\n";
1627 m_ScriptFailCount++;
1628 lock (m_AddingAssemblies)
1629 {
1630 m_AddingAssemblies[assembly]--;
1631 }
1632 return false;
1491 } 1633 }
1634 }
1492 1635
1493 instance.AppDomain = appDomain;
1494 instance.LineMap = linemap;
1495 1636
1496 m_Scripts[itemID] = instance; 1637 if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource))
1638 return false;
1639// m_log.DebugFormat(
1640// "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
1641// part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
1642// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1643
1644 if (presence != null)
1645 {
1646 ShowScriptSaveResponse(item.OwnerID,
1647 assetID, "Compile successful", true);
1497 } 1648 }
1498 }
1499 1649
1650 instance.AppDomain = appDomain;
1651 instance.LineMap = linemap;
1652 lockScriptsForWrite(true);
1653 m_Scripts[itemID] = instance;
1654 lockScriptsForWrite(false);
1655 }
1656 else
1657 {
1658 lockScriptsForRead(false);
1659 }
1500 lock (m_PrimObjects) 1660 lock (m_PrimObjects)
1501 { 1661 {
1502 if (!m_PrimObjects.ContainsKey(localID)) 1662 if (!m_PrimObjects.ContainsKey(localID))
@@ -1514,7 +1674,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1514 m_AddingAssemblies[assemblyPath]--; 1674 m_AddingAssemblies[assemblyPath]--;
1515 } 1675 }
1516 1676
1517 if (instance != null) 1677 if (instance!=null)
1518 instance.Init(); 1678 instance.Init();
1519 1679
1520 bool runIt; 1680 bool runIt;
@@ -1537,19 +1697,28 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1537 m_CompileDict.Remove(itemID); 1697 m_CompileDict.Remove(itemID);
1538 } 1698 }
1539 1699
1540 IScriptInstance instance = null; 1700 lockScriptsForRead(true);
1541 1701 // Do we even have it?
1542 lock (m_Scripts) 1702 if (!m_Scripts.ContainsKey(itemID))
1543 { 1703 {
1544 // Do we even have it? 1704 lockScriptsForRead(false);
1545 if (!m_Scripts.ContainsKey(itemID)) 1705 return;
1546 return; 1706 }
1547
1548 instance = m_Scripts[itemID];
1549 m_Scripts.Remove(itemID);
1550 }
1551 1707
1708<<<<<<< HEAD
1552 instance.Stop(m_WaitForEventCompletionOnScriptStop, true); 1709 instance.Stop(m_WaitForEventCompletionOnScriptStop, true);
1710=======
1711 IScriptInstance instance=m_Scripts[itemID];
1712 lockScriptsForRead(false);
1713 lockScriptsForWrite(true);
1714 m_Scripts.Remove(itemID);
1715 lockScriptsForWrite(false);
1716 instance.ClearQueue();
1717
1718 instance.Stop(m_WaitForEventCompletionOnScriptStop);
1719
1720// bool objectRemoved = false;
1721>>>>>>> avn/ubitvar
1553 1722
1554 lock (m_PrimObjects) 1723 lock (m_PrimObjects)
1555 { 1724 {
@@ -1571,17 +1740,26 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1571 1740
1572 instance.DestroyScriptInstance(); 1741 instance.DestroyScriptInstance();
1573 1742
1574 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 1743 if (m_DomainScripts.ContainsKey(instance.AppDomain))
1575 if (m_DomainScripts[instance.AppDomain].Count == 0)
1576 { 1744 {
1577 m_DomainScripts.Remove(instance.AppDomain); 1745 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
1578 UnloadAppDomain(instance.AppDomain); 1746 if (m_DomainScripts[instance.AppDomain].Count == 0)
1747 {
1748 m_DomainScripts.Remove(instance.AppDomain);
1749 UnloadAppDomain(instance.AppDomain);
1750 }
1579 } 1751 }
1580 1752
1581 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 1753 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
1582 if (handlerObjectRemoved != null) 1754 if (handlerObjectRemoved != null)
1583 handlerObjectRemoved(instance.ObjectID); 1755 {
1756 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
1757 if (part != null)
1758 handlerObjectRemoved(part.UUID);
1759 }
1584 1760
1761 CleanAssemblies();
1762
1585 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 1763 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
1586 if (handlerScriptRemoved != null) 1764 if (handlerScriptRemoved != null)
1587 handlerScriptRemoved(itemID); 1765 handlerScriptRemoved(itemID);
@@ -1842,12 +2020,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1842 private IScriptInstance GetInstance(UUID itemID) 2020 private IScriptInstance GetInstance(UUID itemID)
1843 { 2021 {
1844 IScriptInstance instance; 2022 IScriptInstance instance;
1845 lock (m_Scripts) 2023 lockScriptsForRead(true);
2024 if (!m_Scripts.ContainsKey(itemID))
1846 { 2025 {
1847 if (!m_Scripts.ContainsKey(itemID)) 2026 lockScriptsForRead(false);
1848 return null; 2027 return null;
1849 instance = m_Scripts[itemID];
1850 } 2028 }
2029 instance = m_Scripts[itemID];
2030 lockScriptsForRead(false);
1851 return instance; 2031 return instance;
1852 } 2032 }
1853 2033
@@ -1869,6 +2049,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1869 return instance != null && instance.Running; 2049 return instance != null && instance.Running;
1870 } 2050 }
1871 2051
2052 [DebuggerNonUserCode]
1872 public void ApiResetScript(UUID itemID) 2053 public void ApiResetScript(UUID itemID)
1873 { 2054 {
1874 IScriptInstance instance = GetInstance(itemID); 2055 IScriptInstance instance = GetInstance(itemID);
@@ -1953,6 +2134,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1953 return instance != null ? instance.GetDetectID(idx) : UUID.Zero; 2134 return instance != null ? instance.GetDetectID(idx) : UUID.Zero;
1954 } 2135 }
1955 2136
2137 [DebuggerNonUserCode]
1956 public void SetState(UUID itemID, string newState) 2138 public void SetState(UUID itemID, string newState)
1957 { 2139 {
1958 IScriptInstance instance = GetInstance(itemID); 2140 IScriptInstance instance = GetInstance(itemID);
@@ -1973,11 +2155,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1973 2155
1974 List<IScriptInstance> instances = new List<IScriptInstance>(); 2156 List<IScriptInstance> instances = new List<IScriptInstance>();
1975 2157
1976 lock (m_Scripts) 2158 lockScriptsForRead(true);
1977 { 2159 foreach (IScriptInstance instance in m_Scripts.Values)
1978 foreach (IScriptInstance instance in m_Scripts.Values)
1979 instances.Add(instance); 2160 instances.Add(instance);
1980 } 2161 lockScriptsForRead(false);
1981 2162
1982 foreach (IScriptInstance i in instances) 2163 foreach (IScriptInstance i in instances)
1983 { 2164 {
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs
index 44ef124..a18cdc1 100644
--- a/OpenSim/Server/Base/HttpServerBase.cs
+++ b/OpenSim/Server/Base/HttpServerBase.cs
@@ -40,7 +40,7 @@ namespace OpenSim.Server.Base
40{ 40{
41 public class HttpServerBase : ServicesServerBase 41 public class HttpServerBase : ServicesServerBase
42 { 42 {
43// private static readonly ILog m_Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
45 private uint m_consolePort; 45 private uint m_consolePort;
46 46
@@ -70,6 +70,7 @@ namespace OpenSim.Server.Base
70 70
71 bool ssl_main = networkConfig.GetBoolean("https_main",false); 71 bool ssl_main = networkConfig.GetBoolean("https_main",false);
72 bool ssl_listener = networkConfig.GetBoolean("https_listener",false); 72 bool ssl_listener = networkConfig.GetBoolean("https_listener",false);
73 bool ssl_external = networkConfig.GetBoolean("https_external",false);
73 74
74 m_consolePort = (uint)networkConfig.GetInt("ConsolePort", 0); 75 m_consolePort = (uint)networkConfig.GetInt("ConsolePort", 0);
75 76
@@ -115,6 +116,7 @@ namespace OpenSim.Server.Base
115 { 116 {
116 uint https_port = (uint)networkConfig.GetInt("https_port", 0); 117 uint https_port = (uint)networkConfig.GetInt("https_port", 0);
117 118
119<<<<<<< HEAD
118 string cert_path = networkConfig.GetString("cert_path",String.Empty); 120 string cert_path = networkConfig.GetString("cert_path",String.Empty);
119 if (cert_path == String.Empty) 121 if (cert_path == String.Empty)
120 { 122 {
@@ -127,9 +129,31 @@ namespace OpenSim.Server.Base
127 { 129 {
128 System.Console.WriteLine("ERROR: Password for X509 certificate is missing, server can't start."); 130 System.Console.WriteLine("ERROR: Password for X509 certificate is missing, server can't start.");
129 Environment.Exit(1); 131 Environment.Exit(1);
132=======
133 m_log.WarnFormat("[SSL]: External flag is {0}", ssl_external);
134 if (!ssl_external)
135 {
136 string cert_path = networkConfig.GetString("cert_path",String.Empty);
137 if ( cert_path == String.Empty )
138 {
139 System.Console.WriteLine("Path to X509 certificate is missing, server can't start.");
140 Thread.CurrentThread.Abort();
141 }
142 string cert_pass = networkConfig.GetString("cert_pass",String.Empty);
143 if ( cert_pass == String.Empty )
144 {
145 System.Console.WriteLine("Password for X509 certificate is missing, server can't start.");
146 Thread.CurrentThread.Abort();
147 }
148
149 MainServer.AddHttpServer(new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass));
150 }
151 else
152 {
153 m_log.WarnFormat("[SSL]: SSL port is active but no SSL is used because external SSL was requested.");
154 MainServer.AddHttpServer(new BaseHttpServer(https_port));
155>>>>>>> avn/ubitvar
130 } 156 }
131
132 MainServer.AddHttpServer(new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass));
133 } 157 }
134 } 158 }
135 159
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
index e38543b..502cecf 100644
--- a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
@@ -45,12 +45,19 @@ namespace OpenSim.Server.Handlers.BakedTextures
45{ 45{
46 public class BakesServerPostHandler : BaseStreamHandler 46 public class BakesServerPostHandler : BaseStreamHandler
47 { 47 {
48<<<<<<< HEAD:OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 50
50 private IBakedTextureService m_BakesService; 51 private IBakedTextureService m_BakesService;
51 52
52 public BakesServerPostHandler(IBakedTextureService service, IServiceAuth auth) : 53 public BakesServerPostHandler(IBakedTextureService service, IServiceAuth auth) :
53 base("POST", "/bakes", auth) 54 base("POST", "/bakes", auth)
55=======
56 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57
58 public MSSQLAvatarData(string connectionString, string realm) :
59 base(connectionString, realm, "Avatar")
60>>>>>>> avn/ubitvar:OpenSim/Data/MSSQL/MSSQLAvatarData.cs
54 { 61 {
55 m_BakesService = service; 62 m_BakesService = service;
56 } 63 }
@@ -73,4 +80,4 @@ namespace OpenSim.Server.Handlers.BakedTextures
73 return new byte[0]; 80 return new byte[0];
74 } 81 }
75 } 82 }
76} \ No newline at end of file 83}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
index 9237c63..b63b594 100644
--- a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
@@ -185,6 +185,9 @@ namespace OpenSim.Server.Handlers.GridUser
185 185
186 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user); 186 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
187 187
188 if (guinfo == null)
189 return FailureResult();
190
188 Dictionary<string, object> result = new Dictionary<string, object>(); 191 Dictionary<string, object> result = new Dictionary<string, object>();
189 if (guinfo != null) 192 if (guinfo != null)
190 result["result"] = guinfo.ToKeyValuePairs(); 193 result["result"] = guinfo.ToKeyValuePairs();
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
index f2a5678..5d672c3 100644
--- a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
+++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
@@ -132,8 +132,13 @@ namespace OpenSim.Server.Handlers.Login
132 132
133 //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion); 133 //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
134 134
135
136 bool LibOMVclient = false;
137 if (request.Params.Count > 4 && (string)request.Params[4] == "gridproxy")
138 LibOMVclient = true;
139
135 LoginResponse reply = null; 140 LoginResponse reply = null;
136 reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient); 141 reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient, LibOMVclient);
137 142
138 XmlRpcResponse response = new XmlRpcResponse(); 143 XmlRpcResponse response = new XmlRpcResponse();
139 response.Value = reply.ToHashtable(); 144 response.Value = reply.ToHashtable();
@@ -216,7 +221,7 @@ namespace OpenSim.Server.Handlers.Login
216 221
217 LoginResponse reply = null; 222 LoginResponse reply = null;
218 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, 223 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
219 map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient); 224 map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient,false);
220 return reply.ToOSDMap(); 225 return reply.ToOSDMap();
221 226
222 } 227 }
@@ -259,7 +264,7 @@ namespace OpenSim.Server.Handlers.Login
259 (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint(); 264 (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint();
260 LoginResponse reply = null; 265 LoginResponse reply = null;
261 reply = m_LocalService.Login(first, last, passwd, start, scope, version, 266 reply = m_LocalService.Login(first, last, passwd, start, scope, version,
262 channel, mac, id0, endPoint); 267 channel, mac, id0, endPoint,false);
263 sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap())); 268 sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap()));
264 269
265 } 270 }
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
index 649a27e..083a628 100644
--- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
@@ -118,9 +118,19 @@ namespace OpenSim.Server.Handlers.MapImage
118 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; 118 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest;
119 return FailureResult("Bad request."); 119 return FailureResult("Bad request.");
120 } 120 }
121<<<<<<< HEAD
121 uint x = 0, y = 0; 122 uint x = 0, y = 0;
122 UInt32.TryParse(request["X"].ToString(), out x); 123 UInt32.TryParse(request["X"].ToString(), out x);
123 UInt32.TryParse(request["Y"].ToString(), out y); 124 UInt32.TryParse(request["Y"].ToString(), out y);
125=======
126 int x = 0, y = 0;
127// UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
128 UUID scopeID = UUID.Zero;
129 Int32.TryParse(request["X"].ToString(), out x);
130 Int32.TryParse(request["Y"].ToString(), out y);
131 if (request.ContainsKey("SCOPE"))
132 UUID.TryParse(request["SCOPE"].ToString(), out scopeID);
133>>>>>>> avn/ubitvar
124 134
125 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); 135 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y);
126 136
@@ -132,7 +142,11 @@ namespace OpenSim.Server.Handlers.MapImage
132 if (m_GridService != null) 142 if (m_GridService != null)
133 { 143 {
134 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); 144 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
145<<<<<<< HEAD
135 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y)); 146 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y));
147=======
148 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y));
149>>>>>>> avn/ubitvar
136 if (r != null) 150 if (r != null)
137 { 151 {
138 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) 152 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString())
@@ -153,7 +167,11 @@ namespace OpenSim.Server.Handlers.MapImage
153 byte[] data = Convert.FromBase64String(request["DATA"].ToString()); 167 byte[] data = Convert.FromBase64String(request["DATA"].ToString());
154 168
155 string reason = string.Empty; 169 string reason = string.Empty;
170<<<<<<< HEAD
156 bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason); 171 bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason);
172=======
173 bool result = m_MapService.AddMapTile(x, y, data, scopeID, out reason);
174>>>>>>> avn/ubitvar
157 175
158 if (result) 176 if (result)
159 return SuccessResult(); 177 return SuccessResult();
diff --git a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
index 7bb2f39..1ae669c 100644
--- a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using System.IO; 29using System.IO;
30using System.Net; 30using System.Net;
31using System.Reflection; 31using System.Reflection;
32using System.Threading;
32 33
33using Nini.Config; 34using Nini.Config;
34using log4net; 35using log4net;
@@ -37,6 +38,7 @@ using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Server.Handlers.Base; 40using OpenSim.Server.Handlers.Base;
41using OpenMetaverse;
40 42
41namespace OpenSim.Server.Handlers.MapImage 43namespace OpenSim.Server.Handlers.MapImage
42{ 44{
@@ -70,6 +72,8 @@ namespace OpenSim.Server.Handlers.MapImage
70 72
71 class MapServerGetHandler : BaseStreamHandler 73 class MapServerGetHandler : BaseStreamHandler
72 { 74 {
75 public static ManualResetEvent ev = new ManualResetEvent(true);
76
73// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74 78
75 private IMapImageService m_MapService; 79 private IMapImageService m_MapService;
@@ -82,10 +86,25 @@ namespace OpenSim.Server.Handlers.MapImage
82 86
83 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 87 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
84 { 88 {
85 byte[] result = new byte[0]; 89 ev.WaitOne();
90 lock (ev)
91 {
92 ev.Reset();
93 }
86 94
95 byte[] result = new byte[0];
87 string format = string.Empty; 96 string format = string.Empty;
88 result = m_MapService.GetMapTile(path.Trim('/'), out format); 97
98// UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
99 UUID scopeID = UUID.Zero;
100
101 string[] bits = path.Trim('/').Split(new char[] {'/'});
102 if (bits.Length > 1)
103 {
104 scopeID = new UUID(bits[0]);
105 path = bits[1];
106 }
107 result = m_MapService.GetMapTile(path.Trim('/'), scopeID, out format);
89 if (result.Length > 0) 108 if (result.Length > 0)
90 { 109 {
91 httpResponse.StatusCode = (int)HttpStatusCode.OK; 110 httpResponse.StatusCode = (int)HttpStatusCode.OK;
@@ -100,6 +119,11 @@ namespace OpenSim.Server.Handlers.MapImage
100 httpResponse.ContentType = "text/plain"; 119 httpResponse.ContentType = "text/plain";
101 } 120 }
102 121
122 lock (ev)
123 {
124 ev.Set();
125 }
126
103 return result; 127 return result;
104 } 128 }
105 129
diff --git a/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs b/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs
new file mode 100644
index 0000000..4f8f7e1
--- /dev/null
+++ b/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs
@@ -0,0 +1,253 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33
34using Nini.Config;
35using log4net;
36using OpenMetaverse;
37
38using OpenSim.Framework;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Server.Handlers.Base;
43
44using GridRegion = OpenSim.Services.Interfaces.GridRegion;
45
46namespace OpenSim.Server.Handlers.MapImage
47{
48 public class MapRemoveServiceConnector : ServiceConnector
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IMapImageService m_MapService;
53 private IGridService m_GridService;
54 private string m_ConfigName = "MapImageService";
55
56 public MapRemoveServiceConnector(IConfigSource config, IHttpServer server, string configName) :
57 base(config, server, configName)
58 {
59 IConfig serverConfig = config.Configs[m_ConfigName];
60 if (serverConfig == null)
61 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
62
63 string mapService = serverConfig.GetString("LocalServiceModule",
64 String.Empty);
65
66 if (mapService == String.Empty)
67 throw new Exception("No LocalServiceModule in config file");
68
69 Object[] args = new Object[] { config };
70 m_MapService = ServerUtils.LoadPlugin<IMapImageService>(mapService, args);
71
72 string gridService = serverConfig.GetString("GridService", String.Empty);
73 if (gridService != string.Empty)
74 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
75
76 if (m_GridService != null)
77 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is ON");
78 else
79 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF");
80
81 bool proxy = serverConfig.GetBoolean("HasProxy", false);
82 server.AddStreamHandler(new MapServerRemoveHandler(m_MapService, m_GridService, proxy));
83
84 }
85 }
86
87 class MapServerRemoveHandler : BaseStreamHandler
88 {
89 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
90 private IMapImageService m_MapService;
91 private IGridService m_GridService;
92 bool m_Proxy;
93
94 public MapServerRemoveHandler(IMapImageService service, IGridService grid, bool proxy) :
95 base("POST", "/removemap")
96 {
97 m_MapService = service;
98 m_GridService = grid;
99 m_Proxy = proxy;
100 }
101
102 public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
103 {
104// m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path);
105 StreamReader sr = new StreamReader(requestData);
106 string body = sr.ReadToEnd();
107 sr.Close();
108 body = body.Trim();
109
110 try
111 {
112 Dictionary<string, object> request = ServerUtils.ParseQueryString(body);
113
114 if (!request.ContainsKey("X") || !request.ContainsKey("Y"))
115 {
116 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest;
117 return FailureResult("Bad request.");
118 }
119 int x = 0, y = 0;
120 Int32.TryParse(request["X"].ToString(), out x);
121 Int32.TryParse(request["Y"].ToString(), out y);
122// UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
123 UUID scopeID = UUID.Zero;
124 if (request.ContainsKey("SCOPE"))
125 UUID.TryParse(request["SCOPE"].ToString(), out scopeID);
126
127 m_log.DebugFormat("[MAP REMOVE SERVER CONNECTOR]: Received position data for region at {0}-{1}", x, y);
128
129 if (m_GridService != null)
130 {
131 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
132 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y));
133 if (r != null)
134 {
135 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString())
136 {
137 m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address);
138 return FailureResult("IP address of caller does not match IP address of registered region");
139 }
140
141 }
142 else
143 {
144 m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}",
145 ipAddr, x, y);
146 return FailureResult("Region not found at given coordinates");
147 }
148 }
149
150 string reason = string.Empty;
151 bool result = m_MapService.RemoveMapTile(x, y, scopeID, out reason);
152
153 if (result)
154 return SuccessResult();
155 else
156 return FailureResult(reason);
157
158 }
159 catch (Exception e)
160 {
161 m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
162 }
163
164 return FailureResult("Unexpected server error");
165 }
166
167 private byte[] SuccessResult()
168 {
169 XmlDocument doc = new XmlDocument();
170
171 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
172 "", "");
173
174 doc.AppendChild(xmlnode);
175
176 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
177 "");
178
179 doc.AppendChild(rootElement);
180
181 XmlElement result = doc.CreateElement("", "Result", "");
182 result.AppendChild(doc.CreateTextNode("Success"));
183
184 rootElement.AppendChild(result);
185
186 return DocToBytes(doc);
187 }
188
189 private byte[] FailureResult(string msg)
190 {
191 XmlDocument doc = new XmlDocument();
192
193 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
194 "", "");
195
196 doc.AppendChild(xmlnode);
197
198 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
199 "");
200
201 doc.AppendChild(rootElement);
202
203 XmlElement result = doc.CreateElement("", "Result", "");
204 result.AppendChild(doc.CreateTextNode("Failure"));
205
206 rootElement.AppendChild(result);
207
208 XmlElement message = doc.CreateElement("", "Message", "");
209 message.AppendChild(doc.CreateTextNode(msg));
210
211 rootElement.AppendChild(message);
212
213 return DocToBytes(doc);
214 }
215
216 private byte[] DocToBytes(XmlDocument doc)
217 {
218 MemoryStream ms = new MemoryStream();
219 XmlTextWriter xw = new XmlTextWriter(ms, null);
220 xw.Formatting = Formatting.Indented;
221 doc.WriteTo(xw);
222 xw.Flush();
223
224 return ms.ToArray();
225 }
226
227 private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)
228 {
229 if (!m_Proxy)
230 return request.RemoteIPEndPoint.Address;
231
232 // We're behind a proxy
233 string xff = "X-Forwarded-For";
234 string xffValue = request.Headers[xff.ToLower()];
235 if (xffValue == null || (xffValue != null && xffValue == string.Empty))
236 xffValue = request.Headers[xff];
237
238 if (xffValue == null || (xffValue != null && xffValue == string.Empty))
239 {
240 m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header");
241 return request.RemoteIPEndPoint.Address;
242 }
243
244 System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue);
245 if (ep != null)
246 return ep.Address;
247
248 // Oops
249 return request.RemoteIPEndPoint.Address;
250 }
251
252 }
253}
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs
index 2dfb862..9afe953 100644
--- a/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs
+++ b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs
@@ -99,8 +99,6 @@ namespace OpenSim.Server.Handlers.Profiles
99 Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest); 99 Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest);
100 Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate); 100 Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate);
101 Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate); 101 Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate);
102 Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate);
103 Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest);
104 Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest); 102 Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest);
105 Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData); 103 Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData);
106 Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData); 104 Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData);
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs
index 49aa8ba..bc88184 100644
--- a/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs
+++ b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs
@@ -380,6 +380,7 @@ namespace OpenSim.Server.Handlers
380 } 380 }
381 #endregion Interests 381 #endregion Interests
382 382
383<<<<<<< HEAD
383 #region User Preferences 384 #region User Preferences
384 public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response) 385 public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response)
385 { 386 {
@@ -433,6 +434,8 @@ namespace OpenSim.Server.Handlers
433 } 434 }
434 #endregion User Preferences 435 #endregion User Preferences
435 436
437=======
438>>>>>>> avn/ubitvar
436 #region Utility 439 #region Utility
437 public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response) 440 public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response)
438 { 441 {
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index e7544b5..8780a49 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -149,6 +149,7 @@ namespace OpenSim.Server.Handlers.Simulation
149 if (args.ContainsKey("my_version")) 149 if (args.ContainsKey("my_version"))
150 theirVersion = args["my_version"].AsString(); 150 theirVersion = args["my_version"].AsString();
151 151
152<<<<<<< HEAD
152 List<UUID> features = new List<UUID>(); 153 List<UUID> features = new List<UUID>();
153 154
154 if (args.ContainsKey("features")) 155 if (args.ContainsKey("features"))
@@ -159,12 +160,18 @@ namespace OpenSim.Server.Handlers.Simulation
159 features.Add(new UUID(o.AsString())); 160 features.Add(new UUID(o.AsString()));
160 } 161 }
161 162
163=======
164>>>>>>> avn/ubitvar
162 GridRegion destination = new GridRegion(); 165 GridRegion destination = new GridRegion();
163 destination.RegionID = regionID; 166 destination.RegionID = regionID;
164 167
165 string reason; 168 string reason;
166 string version; 169 string version;
170<<<<<<< HEAD
167 bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, theirVersion, features, out version, out reason); 171 bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, theirVersion, features, out version, out reason);
172=======
173 bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, theirVersion, out version, out reason);
174>>>>>>> avn/ubitvar
168 175
169 responsedata["int_response_code"] = HttpStatusCode.OK; 176 responsedata["int_response_code"] = HttpStatusCode.OK;
170 177
@@ -262,7 +269,16 @@ namespace OpenSim.Server.Handlers.Simulation
262 httpResponse.KeepAlive = false; 269 httpResponse.KeepAlive = false;
263 Encoding encoding = Encoding.UTF8; 270 Encoding encoding = Encoding.UTF8;
264 271
272<<<<<<< HEAD
265 if (httpRequest.ContentType != "application/json") 273 if (httpRequest.ContentType != "application/json")
274=======
275 Stream inputStream = null;
276 if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
277 inputStream = new GZipStream(request, CompressionMode.Decompress);
278 else if (httpRequest.ContentType == "application/json")
279 inputStream = request;
280 else // no go
281>>>>>>> avn/ubitvar
266 { 282 {
267 httpResponse.StatusCode = 406; 283 httpResponse.StatusCode = 406;
268 return encoding.GetBytes("false"); 284 return encoding.GetBytes("false");
@@ -448,7 +464,30 @@ namespace OpenSim.Server.Handlers.Simulation
448 protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination, 464 protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination,
449 AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason) 465 AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
450 { 466 {
467<<<<<<< HEAD
451 return m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason); 468 return m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason);
469=======
470 reason = String.Empty;
471 if ((teleportFlags & (uint)TeleportFlags.ViaLogin) == 0)
472 {
473 Util.FireAndForget(x =>
474 {
475 string r;
476 m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out r);
477 m_log.DebugFormat("[AGENT HANDLER]: ASYNC CreateAgent {0}", r);
478 });
479
480 return true;
481 }
482 else
483 {
484
485 bool ret = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
486 m_log.DebugFormat("[AGENT HANDLER]: SYNC CreateAgent {0} {1}", ret.ToString(), reason);
487 return ret;
488 }
489
490>>>>>>> avn/ubitvar
452 } 491 }
453 } 492 }
454 493
diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs
index 65e9287..ed5a481 100644
--- a/OpenSim/Server/ServerMain.cs
+++ b/OpenSim/Server/ServerMain.cs
@@ -29,6 +29,7 @@ using Nini.Config;
29using log4net; 29using log4net;
30using System.Reflection; 30using System.Reflection;
31using System; 31using System;
32using System.Net;
32using System.Collections.Generic; 33using System.Collections.Generic;
33using OpenSim.Framework.Servers; 34using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer; 35using OpenSim.Framework.Servers.HttpServer;
@@ -53,6 +54,10 @@ namespace OpenSim.Server
53 54
54 public static int Main(string[] args) 55 public static int Main(string[] args)
55 { 56 {
57 // Make sure we don't get outbound connections queueing
58 ServicePointManager.DefaultConnectionLimit = 50;
59 ServicePointManager.UseNagleAlgorithm = false;
60
56 m_Server = new HttpServerBase("R.O.B.U.S.T.", args); 61 m_Server = new HttpServerBase("R.O.B.U.S.T.", args);
57 62
58 string registryLocation; 63 string registryLocation;
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs
index 0aefa16..c57db48 100644
--- a/OpenSim/Services/AssetService/AssetService.cs
+++ b/OpenSim/Services/AssetService/AssetService.cs
@@ -174,7 +174,10 @@ namespace OpenSim.Services.AssetService
174 { 174 {
175// m_log.DebugFormat( 175// m_log.DebugFormat(
176// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length); 176// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
177 m_Database.StoreAsset(asset); 177 if (!m_Database.StoreAsset(asset))
178 {
179 return UUID.Zero.ToString();
180 }
178 } 181 }
179// else 182// else
180// { 183// {
diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
index 229f557..e42f9a0 100644
--- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
+++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
@@ -30,10 +30,11 @@ using OpenMetaverse;
30using log4net; 30using log4net;
31using Nini.Config; 31using Nini.Config;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
33using OpenSim.Data; 35using OpenSim.Data;
34using OpenSim.Framework; 36using OpenSim.Framework;
35using OpenSim.Services.Base; 37using OpenSim.Services.Base;
36using OpenSim.Services.Interfaces;
37 38
38namespace OpenSim.Services.AuthenticationService 39namespace OpenSim.Services.AuthenticationService
39{ 40{
@@ -50,6 +51,12 @@ namespace OpenSim.Services.AuthenticationService
50 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
51 52
52 protected IAuthenticationData m_Database; 53 protected IAuthenticationData m_Database;
54 protected IUserAccountService m_UserAccountService = null;
55
56 public AuthenticationServiceBase(IConfigSource config, IUserAccountService acct) : this(config)
57 {
58 m_UserAccountService = acct;
59 }
53 60
54 public AuthenticationServiceBase(IConfigSource config) : base(config) 61 public AuthenticationServiceBase(IConfigSource config) : base(config)
55 { 62 {
diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs
index 5f1bde1..a069838 100644
--- a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs
+++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs
@@ -51,6 +51,12 @@ namespace OpenSim.Services.AuthenticationService
51 LogManager.GetLogger( 51 LogManager.GetLogger(
52 MethodBase.GetCurrentMethod().DeclaringType); 52 MethodBase.GetCurrentMethod().DeclaringType);
53 53
54 public PasswordAuthenticationService(IConfigSource config, IUserAccountService userService) :
55 base(config, userService)
56 {
57 m_log.Debug("[AUTH SERVICE]: Started with User Account access");
58 }
59
54 public PasswordAuthenticationService(IConfigSource config) : 60 public PasswordAuthenticationService(IConfigSource config) :
55 base(config) 61 base(config)
56 { 62 {
@@ -58,42 +64,90 @@ namespace OpenSim.Services.AuthenticationService
58 64
59 public string Authenticate(UUID principalID, string password, int lifetime) 65 public string Authenticate(UUID principalID, string password, int lifetime)
60 { 66 {
67 UUID realID;
68 return Authenticate(principalID, password, lifetime, out realID);
69 }
70
71 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
72 {
73 realID = UUID.Zero;
74
75 m_log.DebugFormat("[AUTH SERVICE]: Authenticating for {0}, user account service present: {1}", principalID, m_UserAccountService != null);
61 AuthenticationData data = m_Database.Get(principalID); 76 AuthenticationData data = m_Database.Get(principalID);
77 UserAccount user = null;
78 if (m_UserAccountService != null)
79 user = m_UserAccountService.GetUserAccount(UUID.Zero, principalID);
62 80
63 if (data == null) 81 if (data == null || data.Data == null)
64 { 82 {
65 m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} not found", principalID); 83 m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID);
66 return String.Empty; 84 return String.Empty;
67 } 85 }
68 else if (data.Data == null) 86
87 if (!data.Data.ContainsKey("passwordHash") ||
88 !data.Data.ContainsKey("passwordSalt"))
69 { 89 {
70 m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} data not found", principalID);
71 return String.Empty; 90 return String.Empty;
72 } 91 }
73 else if (!data.Data.ContainsKey("passwordHash") || !data.Data.ContainsKey("passwordSalt")) 92
93 string hashed = Util.Md5Hash(password + ":" +
94 data.Data["passwordSalt"].ToString());
95
96 m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString());
97
98 if (data.Data["passwordHash"].ToString() == hashed)
99 {
100 return GetToken(principalID, lifetime);
101 }
102
103 if (user == null)
74 { 104 {
75 m_log.DebugFormat( 105 m_log.DebugFormat("[PASS AUTH]: No user record for {0}", principalID);
76 "[AUTH SERVICE]: PrincipalID {0} data didn't contain either passwordHash or passwordSalt", principalID);
77 return String.Empty; 106 return String.Empty;
78 } 107 }
79 else 108
109 int impersonateFlag = 1 << 6;
110
111 if ((user.UserFlags & impersonateFlag) == 0)
112 return String.Empty;
113
114 m_log.DebugFormat("[PASS AUTH]: Attempting impersonation");
115
116 List<UserAccount> accounts = m_UserAccountService.GetUserAccountsWhere(UUID.Zero, "UserLevel >= 200");
117 if (accounts == null || accounts.Count == 0)
118 return String.Empty;
119
120 foreach (UserAccount a in accounts)
80 { 121 {
81 string hashed = Util.Md5Hash(password + ":" + data.Data["passwordSalt"].ToString()); 122 data = m_Database.Get(a.PrincipalID);
123 if (data == null || data.Data == null ||
124 !data.Data.ContainsKey("passwordHash") ||
125 !data.Data.ContainsKey("passwordSalt"))
126 {
127 continue;
128 }
129
130// m_log.DebugFormat("[PASS AUTH]: Trying {0}", data.PrincipalID);
82 131
83 m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); 132 hashed = Util.Md5Hash(password + ":" +
133 data.Data["passwordSalt"].ToString());
84 134
85 if (data.Data["passwordHash"].ToString() == hashed) 135 if (data.Data["passwordHash"].ToString() == hashed)
86 { 136 {
137 m_log.DebugFormat("[PASS AUTH]: {0} {1} impersonating {2}, proceeding with login", a.FirstName, a.LastName, principalID);
138 realID = a.PrincipalID;
87 return GetToken(principalID, lifetime); 139 return GetToken(principalID, lifetime);
88 } 140 }
89 else 141// else
90 { 142// {
91 m_log.DebugFormat( 143// m_log.DebugFormat(
92 "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.", 144// "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.",
93 hashed, data.Data["passwordHash"], principalID); 145// hashed, data.Data["passwordHash"], data.PrincipalID);
94 return String.Empty; 146// }
95 }
96 } 147 }
148
149 m_log.DebugFormat("[PASS AUTH]: Impersonation of {0} failed", principalID);
150 return String.Empty;
97 } 151 }
98 } 152 }
99} \ No newline at end of file 153}
diff --git a/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs b/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs
index 2344c0e..1510168 100644
--- a/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs
+++ b/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs
@@ -49,12 +49,23 @@ namespace OpenSim.Services.AuthenticationService
49 private static readonly ILog m_log = 49 private static readonly ILog m_log =
50 LogManager.GetLogger( 50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 public WebkeyAuthenticationService(IConfigSource config, IUserAccountService userService) :
54 base(config, userService)
55 {
56 }
52 57
53 public WebkeyAuthenticationService(IConfigSource config) : 58 public WebkeyAuthenticationService(IConfigSource config) :
54 base(config) 59 base(config)
55 { 60 {
56 } 61 }
57 62
63 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
64 {
65 realID = UUID.Zero;
66 return Authenticate(principalID, password, lifetime);
67 }
68
58 public string Authenticate(UUID principalID, string password, int lifetime) 69 public string Authenticate(UUID principalID, string password, int lifetime)
59 { 70 {
60 if (new UUID(password) == UUID.Zero) 71 if (new UUID(password) == UUID.Zero)
diff --git a/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs
index 2c6cebd..bbc8470 100644
--- a/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs
+++ b/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs
@@ -55,14 +55,22 @@ namespace OpenSim.Services.AuthenticationService
55 55
56 public string Authenticate(UUID principalID, string password, int lifetime) 56 public string Authenticate(UUID principalID, string password, int lifetime)
57 { 57 {
58 UUID realID;
59
60 return Authenticate(principalID, password, lifetime, out realID);
61 }
62
63 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
64 {
58 AuthenticationData data = m_Database.Get(principalID); 65 AuthenticationData data = m_Database.Get(principalID);
59 string result = String.Empty; 66 string result = String.Empty;
67 realID = UUID.Zero;
60 if (data != null && data.Data != null) 68 if (data != null && data.Data != null)
61 { 69 {
62 if (data.Data.ContainsKey("webLoginKey")) 70 if (data.Data.ContainsKey("webLoginKey"))
63 { 71 {
64 m_log.DebugFormat("[AUTH SERVICE]: Attempting web key authentication for PrincipalID {0}", principalID); 72 m_log.DebugFormat("[AUTH SERVICE]: Attempting web key authentication for PrincipalID {0}", principalID);
65 result = m_svcChecks["web_login_key"].Authenticate(principalID, password, lifetime); 73 result = m_svcChecks["web_login_key"].Authenticate(principalID, password, lifetime, out realID);
66 if (result == String.Empty) 74 if (result == String.Empty)
67 { 75 {
68 m_log.DebugFormat("[AUTH SERVICE]: Web Login failed for PrincipalID {0}", principalID); 76 m_log.DebugFormat("[AUTH SERVICE]: Web Login failed for PrincipalID {0}", principalID);
@@ -71,12 +79,15 @@ namespace OpenSim.Services.AuthenticationService
71 if (result == string.Empty && data.Data.ContainsKey("passwordHash") && data.Data.ContainsKey("passwordSalt")) 79 if (result == string.Empty && data.Data.ContainsKey("passwordHash") && data.Data.ContainsKey("passwordSalt"))
72 { 80 {
73 m_log.DebugFormat("[AUTH SERVICE]: Attempting password authentication for PrincipalID {0}", principalID); 81 m_log.DebugFormat("[AUTH SERVICE]: Attempting password authentication for PrincipalID {0}", principalID);
74 result = m_svcChecks["password"].Authenticate(principalID, password, lifetime); 82 result = m_svcChecks["password"].Authenticate(principalID, password, lifetime, out realID);
75 if (result == String.Empty) 83 if (result == String.Empty)
76 { 84 {
77 m_log.DebugFormat("[AUTH SERVICE]: Password login failed for PrincipalID {0}", principalID); 85 m_log.DebugFormat("[AUTH SERVICE]: Password login failed for PrincipalID {0}", principalID);
78 } 86 }
79 } 87 }
88
89
90
80 if (result == string.Empty) 91 if (result == string.Empty)
81 { 92 {
82 m_log.DebugFormat("[AUTH SERVICE]: Both password and webLoginKey-based authentication failed for PrincipalID {0}", principalID); 93 m_log.DebugFormat("[AUTH SERVICE]: Both password and webLoginKey-based authentication failed for PrincipalID {0}", principalID);
@@ -86,7 +97,9 @@ namespace OpenSim.Services.AuthenticationService
86 { 97 {
87 m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); 98 m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID);
88 } 99 }
100
101
89 return result; 102 return result;
90 } 103 }
91 } 104 }
92} \ No newline at end of file 105}
diff --git a/OpenSim/Services/Base/ServiceBase.cs b/OpenSim/Services/Base/ServiceBase.cs
index a7eb2be..09dcbef 100644
--- a/OpenSim/Services/Base/ServiceBase.cs
+++ b/OpenSim/Services/Base/ServiceBase.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.IO; 31using System.IO;
31using System.Reflection; 32using System.Reflection;
@@ -46,6 +47,7 @@ namespace OpenSim.Services.Base
46 47
47 public T LoadPlugin<T>(string dllName, Object[] args) where T:class 48 public T LoadPlugin<T>(string dllName, Object[] args) where T:class
48 { 49 {
50<<<<<<< HEAD
49 // The path:type separator : is unfortunate because it collides 51 // The path:type separator : is unfortunate because it collides
50 // with Windows paths like C:\... 52 // with Windows paths like C:\...
51 // When the path provided includes the drive, this fails. 53 // When the path provided includes the drive, this fails.
@@ -53,6 +55,11 @@ namespace OpenSim.Services.Base
53 string pathRoot = Path.GetPathRoot(dllName); 55 string pathRoot = Path.GetPathRoot(dllName);
54 string noRoot = dllName.Substring(pathRoot.Length); 56 string noRoot = dllName.Substring(pathRoot.Length);
55 string[] parts = noRoot.Split(new char[] {':'}); 57 string[] parts = noRoot.Split(new char[] {':'});
58=======
59 string pathRoot = Path.GetPathRoot(dllName);
60 string noRoot = dllName.Substring(pathRoot.Length);
61 string[] parts = noRoot.Split(new char[] { ':' });
62>>>>>>> avn/ubitvar
56 63
57 dllName = pathRoot + parts[0]; 64 dllName = pathRoot + parts[0];
58 65
diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
index badacb7..795ca2e 100644
--- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
@@ -27,9 +27,11 @@
27 27
28using log4net; 28using log4net;
29using System; 29using System;
30using System.Threading;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.IO; 32using System.IO;
32using System.Reflection; 33using System.Reflection;
34using System.Timers;
33using Nini.Config; 35using Nini.Config;
34using OpenSim.Framework; 36using OpenSim.Framework;
35using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
@@ -47,13 +49,22 @@ namespace OpenSim.Services.Connectors
47 49
48 private string m_ServerURI = String.Empty; 50 private string m_ServerURI = String.Empty;
49 private IImprovedAssetCache m_Cache = null; 51 private IImprovedAssetCache m_Cache = null;
52 private int m_retryCounter;
53 private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>();
54 private System.Timers.Timer m_retryTimer;
50 private int m_maxAssetRequestConcurrency = 30; 55 private int m_maxAssetRequestConcurrency = 30;
51 56
52 private delegate void AssetRetrievedEx(AssetBase asset); 57 private delegate void AssetRetrievedEx(AssetBase asset);
53 58
54 // Keeps track of concurrent requests for the same asset, so that it's only loaded once. 59 // Keeps track of concurrent requests for the same asset, so that it's only loaded once.
55 // Maps: Asset ID -> Handlers which will be called when the asset has been loaded 60 // Maps: Asset ID -> Handlers which will be called when the asset has been loaded
56 private Dictionary<string, AssetRetrievedEx> m_AssetHandlers = new Dictionary<string, AssetRetrievedEx>(); 61// private Dictionary<string, AssetRetrievedEx> m_AssetHandlers = new Dictionary<string, AssetRetrievedEx>();
62
63 private Dictionary<string, List<AssetRetrievedEx>> m_AssetHandlers = new Dictionary<string, List<AssetRetrievedEx>>();
64
65 private Dictionary<string, string> m_UriMap = new Dictionary<string, string>();
66
67 private Thread[] m_fetchThreads;
57 68
58 public int MaxAssetRequestConcurrency 69 public int MaxAssetRequestConcurrency
59 { 70 {
@@ -92,13 +103,108 @@ namespace OpenSim.Services.Connectors
92 string serviceURI = assetConfig.GetString("AssetServerURI", 103 string serviceURI = assetConfig.GetString("AssetServerURI",
93 String.Empty); 104 String.Empty);
94 105
106 m_ServerURI = serviceURI;
107
95 if (serviceURI == String.Empty) 108 if (serviceURI == String.Empty)
96 { 109 {
97 m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService"); 110 m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService");
98 throw new Exception("Asset connector init error"); 111 throw new Exception("Asset connector init error");
99 } 112 }
100 113
101 m_ServerURI = serviceURI; 114
115 m_retryTimer = new System.Timers.Timer();
116 m_retryTimer.Elapsed += new ElapsedEventHandler(retryCheck);
117 m_retryTimer.Interval = 60000;
118
119 Uri serverUri = new Uri(m_ServerURI);
120
121 string groupHost = serverUri.Host;
122
123 for (int i = 0 ; i < 256 ; i++)
124 {
125 string prefix = i.ToString("x2");
126 groupHost = assetConfig.GetString("AssetServerHost_"+prefix, groupHost);
127
128 m_UriMap[prefix] = groupHost;
129 //m_log.DebugFormat("[ASSET]: Using {0} for prefix {1}", groupHost, prefix);
130 }
131
132 m_fetchThreads = new Thread[2];
133
134 for (int i = 0 ; i < 2 ; i++)
135 {
136 m_fetchThreads[i] = new Thread(AssetRequestProcessor);
137 m_fetchThreads[i].Start();
138 }
139 }
140
141 private string MapServer(string id)
142 {
143 UriBuilder serverUri = new UriBuilder(m_ServerURI);
144
145 string prefix = id.Substring(0, 2).ToLower();
146
147 string host;
148
149 // HG URLs will not be valid UUIDS
150 if (m_UriMap.ContainsKey(prefix))
151 host = m_UriMap[prefix];
152 else
153 host = m_UriMap["00"];
154
155 serverUri.Host = host;
156
157 // m_log.DebugFormat("[ASSET]: Using {0} for host name for prefix {1}", host, prefix);
158
159 string ret = serverUri.Uri.AbsoluteUri;
160 if (ret.EndsWith("/"))
161 ret = ret.Substring(0, ret.Length - 1);
162 return ret;
163 }
164
165 protected void retryCheck(object source, ElapsedEventArgs e)
166 {
167 m_retryCounter++;
168 if (m_retryCounter > 60) m_retryCounter -= 60;
169 List<int> keys = new List<int>();
170 foreach (int a in m_retryQueue.Keys)
171 {
172 keys.Add(a);
173 }
174 foreach (int a in keys)
175 {
176 //We exponentially fall back on frequency until we reach one attempt per hour
177 //The net result is that we end up in the queue for roughly 24 hours..
178 //24 hours worth of assets could be a lot, so the hope is that the region admin
179 //will have gotten the asset connector back online quickly!
180
181 int timefactor = a ^ 2;
182 if (timefactor > 60)
183 {
184 timefactor = 60;
185 }
186
187 //First, find out if we care about this timefactor
188 if (timefactor % a == 0)
189 {
190 //Yes, we do!
191 List<AssetBase> retrylist = m_retryQueue[a];
192 m_retryQueue.Remove(a);
193
194 foreach(AssetBase ass in retrylist)
195 {
196 Store(ass); //Store my ass. This function will put it back in the dictionary if it fails
197 }
198 }
199 }
200
201 if (m_retryQueue.Count == 0)
202 {
203 //It might only be one tick per minute, but I have
204 //repented and abandoned my wasteful ways
205 m_retryCounter = 0;
206 m_retryTimer.Stop();
207 }
102 } 208 }
103 209
104 protected void SetCache(IImprovedAssetCache cache) 210 protected void SetCache(IImprovedAssetCache cache)
@@ -108,15 +214,13 @@ namespace OpenSim.Services.Connectors
108 214
109 public AssetBase Get(string id) 215 public AssetBase Get(string id)
110 { 216 {
111// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Synchronous get request for {0}", id); 217 string uri = MapServer(id) + "/assets/" + id;
112
113 string uri = m_ServerURI + "/assets/" + id;
114 218
115 AssetBase asset = null; 219 AssetBase asset = null;
116 if (m_Cache != null) 220 if (m_Cache != null)
117 asset = m_Cache.Get(id); 221 asset = m_Cache.Get(id);
118 222
119 if (asset == null) 223 if (asset == null || asset.Data == null || asset.Data.Length == 0)
120 { 224 {
121 // XXX: Commented out for now since this has either never been properly operational or not for some time 225 // XXX: Commented out for now since this has either never been properly operational or not for some time
122 // as m_maxAssetRequestConcurrency was being passed as the timeout, not a concurrency limiting option. 226 // as m_maxAssetRequestConcurrency was being passed as the timeout, not a concurrency limiting option.
@@ -155,7 +259,7 @@ namespace OpenSim.Services.Connectors
155 return fullAsset.Metadata; 259 return fullAsset.Metadata;
156 } 260 }
157 261
158 string uri = m_ServerURI + "/assets/" + id + "/metadata"; 262 string uri = MapServer(id) + "/assets/" + id + "/metadata";
159 263
160 AssetMetadata asset = SynchronousRestObjectRequester.MakeRequest<int, AssetMetadata>("GET", uri, 0, m_Auth); 264 AssetMetadata asset = SynchronousRestObjectRequester.MakeRequest<int, AssetMetadata>("GET", uri, 0, m_Auth);
161 return asset; 265 return asset;
@@ -171,11 +275,18 @@ namespace OpenSim.Services.Connectors
171 return fullAsset.Data; 275 return fullAsset.Data;
172 } 276 }
173 277
278<<<<<<< HEAD
174 using (RestClient rc = new RestClient(m_ServerURI)) 279 using (RestClient rc = new RestClient(m_ServerURI))
175 { 280 {
176 rc.AddResourcePath("assets"); 281 rc.AddResourcePath("assets");
177 rc.AddResourcePath(id); 282 rc.AddResourcePath(id);
178 rc.AddResourcePath("data"); 283 rc.AddResourcePath("data");
284=======
285 RestClient rc = new RestClient(MapServer(id));
286 rc.AddResourcePath("assets");
287 rc.AddResourcePath(id);
288 rc.AddResourcePath("data");
289>>>>>>> avn/ubitvar
179 290
180 rc.RequestMethod = "GET"; 291 rc.RequestMethod = "GET";
181 292
@@ -189,72 +300,147 @@ namespace OpenSim.Services.Connectors
189 byte[] ret = new byte[s.Length]; 300 byte[] ret = new byte[s.Length];
190 s.Read(ret, 0, (int)s.Length); 301 s.Read(ret, 0, (int)s.Length);
191 302
303<<<<<<< HEAD
192 return ret; 304 return ret;
193 } 305 }
194 306
195 return null; 307 return null;
196 } 308 }
309=======
310 s.Close();
311 return ret;
312 }
313
314 s.Close();
315 return null;
316>>>>>>> avn/ubitvar
197 } 317 }
198 318
199 public bool Get(string id, Object sender, AssetRetrieved handler) 319 private class QueuedAssetRequest
200 { 320 {
201// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Potentially asynchronous get request for {0}", id); 321 public string uri;
322 public string id;
323 }
202 324
203 string uri = m_ServerURI + "/assets/" + id; 325 private OpenMetaverse.BlockingQueue<QueuedAssetRequest> m_requestQueue =
326 new OpenMetaverse.BlockingQueue<QueuedAssetRequest>();
204 327
205 AssetBase asset = null; 328 private void AssetRequestProcessor()
206 if (m_Cache != null) 329 {
207 asset = m_Cache.Get(id); 330 QueuedAssetRequest r;
208 331
209 if (asset == null) 332 while (true)
210 { 333 {
211 lock (m_AssetHandlers) 334 r = m_requestQueue.Dequeue();
212 {
213 AssetRetrievedEx handlerEx = new AssetRetrievedEx(delegate(AssetBase _asset) { handler(id, sender, _asset); });
214 335
215 AssetRetrievedEx handlers; 336 string uri = r.uri;
216 if (m_AssetHandlers.TryGetValue(id, out handlers)) 337 string id = r.id;
217 {
218 // Someone else is already loading this asset. It will notify our handler when done.
219 handlers += handlerEx;
220 return true;
221 }
222
223 // Load the asset ourselves
224 handlers += handlerEx;
225 m_AssetHandlers.Add(id, handlers);
226 }
227 338
228 bool success = false; 339 bool success = false;
229 try 340 try
230 { 341 {
231 AsynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0, 342 AssetBase a = SynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0, 30);
232 delegate(AssetBase a) 343 if (a != null)
344 {
345 if (m_Cache != null)
346 m_Cache.Cache(a);
347
348 List<AssetRetrievedEx> handlers;
349 lock (m_AssetHandlers)
233 { 350 {
351<<<<<<< HEAD
234 if (a != null && m_Cache != null) 352 if (a != null && m_Cache != null)
235 m_Cache.Cache(a); 353 m_Cache.Cache(a);
354=======
355 handlers = m_AssetHandlers[id];
356 m_AssetHandlers.Remove(id);
357 }
358>>>>>>> avn/ubitvar
236 359
237 AssetRetrievedEx handlers; 360 Util.FireAndForget(x =>
238 lock (m_AssetHandlers)
239 { 361 {
362<<<<<<< HEAD
240 handlers = m_AssetHandlers[id]; 363 handlers = m_AssetHandlers[id];
241 m_AssetHandlers.Remove(id); 364 m_AssetHandlers.Remove(id);
242 } 365 }
243 handlers.Invoke(a); 366 handlers.Invoke(a);
244 }, m_maxAssetRequestConcurrency, m_Auth); 367 }, m_maxAssetRequestConcurrency, m_Auth);
368=======
369 foreach (AssetRetrievedEx h in handlers)
370 {
371 // Util.FireAndForget(x =>
372 // {
373 try { h.Invoke(a); }
374 catch { }
375 // });
376 }
377
378 if (handlers != null)
379 handlers.Clear();
380
381 });
382
383// if (handlers != null)
384// handlers.Clear();
385>>>>>>> avn/ubitvar
245 386
246 success = true; 387 success = true;
388 }
247 } 389 }
248 finally 390 finally
249 { 391 {
250 if (!success) 392 if (!success)
251 { 393 {
394 List<AssetRetrievedEx> handlers;
252 lock (m_AssetHandlers) 395 lock (m_AssetHandlers)
253 { 396 {
397 handlers = m_AssetHandlers[id];
254 m_AssetHandlers.Remove(id); 398 m_AssetHandlers.Remove(id);
255 } 399 }
400 if (handlers != null)
401 handlers.Clear();
402 }
403 }
404 }
405 }
406
407 public bool Get(string id, Object sender, AssetRetrieved handler)
408 {
409 string uri = MapServer(id) + "/assets/" + id;
410
411 AssetBase asset = null;
412 if (m_Cache != null)
413 asset = m_Cache.Get(id);
414
415 if (asset == null || asset.Data == null || asset.Data.Length == 0)
416 {
417 lock (m_AssetHandlers)
418 {
419 AssetRetrievedEx handlerEx = new AssetRetrievedEx(delegate(AssetBase _asset) { handler(id, sender, _asset); });
420
421// AssetRetrievedEx handlers;
422 List<AssetRetrievedEx> handlers;
423 if (m_AssetHandlers.TryGetValue(id, out handlers))
424 {
425 // Someone else is already loading this asset. It will notify our handler when done.
426// handlers += handlerEx;
427 handlers.Add(handlerEx);
428 return true;
256 } 429 }
430
431 // Load the asset ourselves
432// handlers += handlerEx;
433 handlers = new List<AssetRetrievedEx>();
434 handlers.Add(handlerEx);
435
436 m_AssetHandlers.Add(id, handlers);
257 } 437 }
438
439 QueuedAssetRequest request = new QueuedAssetRequest();
440 request.id = id;
441 request.uri = uri;
442
443 m_requestQueue.Enqueue(request);
258 } 444 }
259 else 445 else
260 { 446 {
@@ -287,19 +473,44 @@ namespace OpenSim.Services.Connectors
287 473
288 public string Store(AssetBase asset) 474 public string Store(AssetBase asset)
289 { 475 {
290 if (asset.Local) 476 // Have to assign the asset ID here. This isn't likely to
477 // trigger since current callers don't pass emtpy IDs
478 // We need the asset ID to route the request to the proper
479 // cluster member, so we can't have the server assign one.
480 if (asset.ID == string.Empty)
291 { 481 {
292 if (m_Cache != null) 482 if (asset.FullID == UUID.Zero)
293 m_Cache.Cache(asset); 483 {
484 asset.FullID = UUID.Random();
485 }
486 asset.ID = asset.FullID.ToString();
487 }
488 else if (asset.FullID == UUID.Zero)
489 {
490 UUID uuid = UUID.Zero;
491 if (UUID.TryParse(asset.ID, out uuid))
492 {
493 asset.FullID = uuid;
494 }
495 else
496 {
497 asset.FullID = UUID.Random();
498 }
499 }
294 500
501 if (m_Cache != null)
502 m_Cache.Cache(asset);
503 if (asset.Temporary || asset.Local)
504 {
295 return asset.ID; 505 return asset.ID;
296 } 506 }
297 507
298 string uri = m_ServerURI + "/assets/"; 508 string uri = MapServer(asset.FullID.ToString()) + "/assets/";
299 509
300 string newID; 510 string newID;
301 try 511 try
302 { 512 {
513<<<<<<< HEAD
303 newID = SynchronousRestObjectRequester.MakeRequest<AssetBase, string>("POST", uri, asset, m_Auth); 514 newID = SynchronousRestObjectRequester.MakeRequest<AssetBase, string>("POST", uri, asset, m_Auth);
304 } 515 }
305 catch (Exception e) 516 catch (Exception e)
@@ -324,6 +535,60 @@ namespace OpenSim.Services.Connectors
324 m_Cache.Cache(asset); 535 m_Cache.Cache(asset);
325 536
326 return newID; 537 return newID;
538=======
539 newID = SynchronousRestObjectRequester.
540 MakeRequest<AssetBase, string>("POST", uri, asset, 25);
541 if (newID == null || newID == "")
542 {
543 newID = UUID.Zero.ToString();
544 }
545 }
546 catch (Exception e)
547 {
548 newID = UUID.Zero.ToString();
549 }
550
551 if (newID == UUID.Zero.ToString())
552 {
553 //The asset upload failed, put it in a queue for later
554 asset.UploadAttempts++;
555 if (asset.UploadAttempts > 30)
556 {
557 //By this stage we've been in the queue for a good few hours;
558 //We're going to drop the asset.
559 m_log.ErrorFormat("[Assets] Dropping asset {0} - Upload has been in the queue for too long.", asset.ID.ToString());
560 }
561 else
562 {
563 if (!m_retryQueue.ContainsKey(asset.UploadAttempts))
564 {
565 m_retryQueue.Add(asset.UploadAttempts, new List<AssetBase>());
566 }
567 List<AssetBase> m_queue = m_retryQueue[asset.UploadAttempts];
568 m_queue.Add(asset);
569 m_log.WarnFormat("[Assets] Upload failed: {0} - Requeuing asset for another run.", asset.ID.ToString());
570 m_retryTimer.Start();
571 }
572 }
573 else
574 {
575 if (asset.UploadAttempts > 0)
576 {
577 m_log.InfoFormat("[Assets] Upload of {0} succeeded after {1} failed attempts", asset.ID.ToString(), asset.UploadAttempts.ToString());
578 }
579 if (newID != String.Empty)
580 {
581 // Placing this here, so that this work with old asset servers that don't send any reply back
582 // SynchronousRestObjectRequester returns somethins that is not an empty string
583 if (newID != null)
584 asset.ID = newID;
585
586 if (m_Cache != null)
587 m_Cache.Cache(asset);
588 }
589 }
590 return asset.ID;
591>>>>>>> avn/ubitvar
327 } 592 }
328 593
329 public bool UpdateContent(string id, byte[] data) 594 public bool UpdateContent(string id, byte[] data)
@@ -344,7 +609,7 @@ namespace OpenSim.Services.Connectors
344 } 609 }
345 asset.Data = data; 610 asset.Data = data;
346 611
347 string uri = m_ServerURI + "/assets/" + id; 612 string uri = MapServer(id) + "/assets/" + id;
348 613
349 if (SynchronousRestObjectRequester.MakeRequest<AssetBase, bool>("POST", uri, asset, m_Auth)) 614 if (SynchronousRestObjectRequester.MakeRequest<AssetBase, bool>("POST", uri, asset, m_Auth))
350 { 615 {
@@ -358,7 +623,7 @@ namespace OpenSim.Services.Connectors
358 623
359 public bool Delete(string id) 624 public bool Delete(string id)
360 { 625 {
361 string uri = m_ServerURI + "/assets/" + id; 626 string uri = MapServer(id) + "/assets/" + id;
362 627
363 if (SynchronousRestObjectRequester.MakeRequest<int, bool>("DELETE", uri, 0, m_Auth)) 628 if (SynchronousRestObjectRequester.MakeRequest<int, bool>("DELETE", uri, 0, m_Auth))
364 { 629 {
diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs
index c8a4912..0443f5a 100644
--- a/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs
@@ -84,6 +84,13 @@ namespace OpenSim.Services.Connectors
84 base.Initialise(source, "AuthenticationService"); 84 base.Initialise(source, "AuthenticationService");
85 } 85 }
86 86
87 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
88 {
89 realID = UUID.Zero;
90
91 return Authenticate(principalID, password, lifetime);
92 }
93
87 public string Authenticate(UUID principalID, string password, int lifetime) 94 public string Authenticate(UUID principalID, string password, int lifetime)
88 { 95 {
89 Dictionary<string, object> sendData = new Dictionary<string, object>(); 96 Dictionary<string, object> sendData = new Dictionary<string, object>();
diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
index 6d5ce4b..45f4514 100644
--- a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
+++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
@@ -144,44 +144,48 @@ namespace OpenSim.Services.Connectors.Friends
144 144
145 private bool Call(GridRegion region, Dictionary<string, object> sendData) 145 private bool Call(GridRegion region, Dictionary<string, object> sendData)
146 { 146 {
147 string reqString = ServerUtils.BuildQueryString(sendData); 147 Util.FireAndForget(x => {
148 //m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: queryString = {0}", reqString); 148 string reqString = ServerUtils.BuildQueryString(sendData);
149 if (region == null) 149 //m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: queryString = {0}", reqString);
150 return false; 150 if (region == null)
151 151 return;
152 string path = ServicePath(); 152
153 if (!region.ServerURI.EndsWith("/")) 153 string path = ServicePath();
154 path = "/" + path; 154 if (!region.ServerURI.EndsWith("/"))
155 string uri = region.ServerURI + path; 155 path = "/" + path;
156// m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: calling {0}", uri); 156 string uri = region.ServerURI + path;
157 157 // m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: calling {0}", uri);
158 try 158
159 { 159 try
160 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
161 if (reply != string.Empty)
162 { 160 {
163 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 161 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
164 162 if (reply != string.Empty)
165 if (replyData.ContainsKey("RESULT"))
166 { 163 {
167 if (replyData["RESULT"].ToString().ToLower() == "true") 164 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
168 return true; 165
166 if (replyData.ContainsKey("RESULT"))
167 {
168// if (replyData["RESULT"].ToString().ToLower() == "true")
169// return;
170// else
171 return;
172 }
169 else 173 else
170 return false; 174 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: reply data does not contain result field");
175
171 } 176 }
172 else 177 else
173 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: reply data does not contain result field"); 178 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: received empty reply");
174 179 }
180 catch (Exception e)
181 {
182 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: Exception when contacting remote sim at {0}: {1}", uri, e.Message);
175 } 183 }
176 else 184
177 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: received empty reply"); 185 return;
178 } 186 });
179 catch (Exception e) 187
180 { 188 return true;
181 m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: Exception when contacting remote sim at {0}: {1}", uri, e.Message);
182 }
183
184 return false;
185 } 189 }
186 } 190 }
187} 191}
diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs
index 9e55356..d208f1e 100644
--- a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs
@@ -49,6 +49,9 @@ namespace OpenSim.Services.Connectors
49 49
50 private string m_ServerURI = String.Empty; 50 private string m_ServerURI = String.Empty;
51 51
52 private ExpiringCache<ulong, GridRegion> m_regionCache =
53 new ExpiringCache<ulong, GridRegion>();
54
52 public GridServicesConnector() 55 public GridServicesConnector()
53 { 56 {
54 } 57 }
@@ -275,6 +278,11 @@ namespace OpenSim.Services.Connectors
275 278
276 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 279 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
277 { 280 {
281 ulong regionHandle = Util.UIntsToLong((uint)x, (uint)y);
282
283 if (m_regionCache.Contains(regionHandle))
284 return (GridRegion)m_regionCache[regionHandle];
285
278 Dictionary<string, object> sendData = new Dictionary<string, object>(); 286 Dictionary<string, object> sendData = new Dictionary<string, object>();
279 287
280 sendData["SCOPEID"] = scopeID.ToString(); 288 sendData["SCOPEID"] = scopeID.ToString();
@@ -316,6 +324,8 @@ namespace OpenSim.Services.Connectors
316 else 324 else
317 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); 325 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply");
318 326
327 m_regionCache.Add(regionHandle, rinfo, TimeSpan.FromSeconds(600));
328
319 return rinfo; 329 return rinfo;
320 } 330 }
321 331
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index b1663ee..2340998 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -161,6 +161,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
161 try 161 try
162 { 162 {
163 WebClient c = new WebClient(); 163 WebClient c = new WebClient();
164 //m_log.Debug("JPEG: " + imageURL);
164 string name = regionID.ToString(); 165 string name = regionID.ToString();
165 filename = Path.Combine(storagePath, name + ".jpg"); 166 filename = Path.Combine(storagePath, name + ".jpg");
166 m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename); 167 m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename);
@@ -189,11 +190,10 @@ namespace OpenSim.Services.Connectors.Hypergrid
189 190
190 ass.Data = imageData; 191 ass.Data = imageData;
191 192
192 mapTile = ass.FullID;
193
194 // finally
195 m_AssetService.Store(ass); 193 m_AssetService.Store(ass);
196 194
195 // finally
196 mapTile = ass.FullID;
197 } 197 }
198 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke 198 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
199 { 199 {
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index 8abd046..10b8d22 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -100,10 +100,14 @@ namespace OpenSim.Services.Connectors.Hypergrid
100 m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService"); 100 m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService");
101 throw new Exception("UserAgent connector init error"); 101 throw new Exception("UserAgent connector init error");
102 } 102 }
103<<<<<<< HEAD
103 104
104 m_ServerURL = m_ServerURLHost = serviceURI; 105 m_ServerURL = m_ServerURLHost = serviceURI;
105 if (!m_ServerURL.EndsWith("/")) 106 if (!m_ServerURL.EndsWith("/"))
106 m_ServerURL += "/"; 107 m_ServerURL += "/";
108=======
109 m_ServerURL = serviceURI;
110>>>>>>> avn/ubitvar
107 111
108 //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL); 112 //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL);
109 } 113 }
diff --git a/OpenSim/Services/Connectors/Land/LandServicesConnector.cs b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
index 644331a..3408f7a 100644
--- a/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs
@@ -130,4 +130,4 @@ namespace OpenSim.Services.Connectors
130 return landData; 130 return landData;
131 } 131 }
132 } 132 }
133} \ No newline at end of file 133}
diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
index 677825e..a0ac5f9 100644
--- a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
+++ b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs
@@ -149,13 +149,75 @@ namespace OpenSim.Services.Connectors
149 return false; 149 return false;
150 } 150 }
151 151
152 public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) 152 public bool RemoveMapTile(int x, int y, UUID scopeID, out string reason)
153 { 153 {
154 reason = string.Empty; 154 reason = string.Empty;
155 int tickstart = Util.EnvironmentTickCount(); 155 int tickstart = Util.EnvironmentTickCount();
156 Dictionary<string, object> sendData = new Dictionary<string, object>(); 156 Dictionary<string, object> sendData = new Dictionary<string, object>();
157 sendData["X"] = x.ToString(); 157 sendData["X"] = x.ToString();
158 sendData["Y"] = y.ToString(); 158 sendData["Y"] = y.ToString();
159 sendData["SCOPE"] = scopeID.ToString();
160
161 string reqString = ServerUtils.BuildQueryString(sendData);
162 string uri = m_ServerURI + "/removemap";
163
164 try
165 {
166 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
167 uri,
168 reqString);
169 if (reply != string.Empty)
170 {
171 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
172
173 if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success"))
174 {
175 return true;
176 }
177 else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure"))
178 {
179 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Delete failed: {0}", replyData["Message"].ToString());
180 reason = replyData["Message"].ToString();
181 return false;
182 }
183 else if (!replyData.ContainsKey("Result"))
184 {
185 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: reply data does not contain result field");
186 }
187 else
188 {
189 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData["Result"].ToString());
190 reason = "Unexpected result " + replyData["Result"].ToString();
191 }
192
193 }
194 else
195 {
196 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Map post received null reply");
197 }
198 }
199 catch (Exception e)
200 {
201 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message);
202 }
203 finally
204 {
205 // This just dumps a warning for any operation that takes more than 100 ms
206 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
207 m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile deleted in {0}ms", tickdiff);
208 }
209
210 return false;
211 }
212
213 public bool AddMapTile(int x, int y, byte[] jpgData, UUID scopeID, out string reason)
214 {
215 reason = string.Empty;
216 int tickstart = Util.EnvironmentTickCount();
217 Dictionary<string, object> sendData = new Dictionary<string, object>();
218 sendData["X"] = x.ToString();
219 sendData["Y"] = y.ToString();
220 sendData["SCOPE"] = scopeID.ToString();
159 sendData["TYPE"] = "image/jpeg"; 221 sendData["TYPE"] = "image/jpeg";
160 sendData["DATA"] = Convert.ToBase64String(jpgData); 222 sendData["DATA"] = Convert.ToBase64String(jpgData);
161 223
@@ -216,7 +278,7 @@ namespace OpenSim.Services.Connectors
216 278
217 } 279 }
218 280
219 public byte[] GetMapTile(string fileName, out string format) 281 public byte[] GetMapTile(string fileName, UUID scopeID, out string format)
220 { 282 {
221 format = string.Empty; 283 format = string.Empty;
222 new Exception("GetMapTile method not Implemented"); 284 new Exception("GetMapTile method not Implemented");
diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
index eecf096..e236ec3 100644
--- a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs
@@ -153,9 +153,15 @@ namespace OpenSim.Services.Connectors
153 } 153 }
154 catch (Exception e) 154 catch (Exception e)
155 { 155 {
156<<<<<<< HEAD
156 m_log.Warn(string.Format( 157 m_log.Warn(string.Format(
157 "[NEIGHBOUR SERVICES CONNECTOR]: Unable to send HelloNeighbour from {0} to {1} (uri {2}). Exception {3} ", 158 "[NEIGHBOUR SERVICES CONNECTOR]: Unable to send HelloNeighbour from {0} to {1} (uri {2}). Exception {3} ",
158 thisRegion.RegionName, region.RegionName, uri, e.Message), e); 159 thisRegion.RegionName, region.RegionName, uri, e.Message), e);
160=======
161// m_log.WarnFormat(
162// "[NEIGHBOUR SERVICE CONNCTOR]: Unable to send HelloNeighbour from {0} to {1}. Exception {2}{3}",
163// thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace);
164>>>>>>> avn/ubitvar
159 165
160 return false; 166 return false;
161 } 167 }
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
index 63f3f37..e474d41 100644
--- a/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
@@ -313,6 +313,17 @@ namespace OpenSim.Services.Connectors
313 { 313 {
314 pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]); 314 pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]);
315 } 315 }
316 else
317 {
318 if (replyData["result"].ToString() == "null")
319 return null;
320
321 m_log.DebugFormat("[PRESENCE CONNECTOR]: Invalid reply (result not dictionary) received from presence server when querying for sessionID {0}", sessionID.ToString());
322 }
323 }
324 else
325 {
326 m_log.DebugFormat("[PRESENCE CONNECTOR]: Invalid reply received from presence server when querying for sessionID {0}", sessionID.ToString());
316 } 327 }
317 328
318 return pinfo; 329 return pinfo;
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
index 3bd11d9..c402907 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
@@ -102,6 +102,12 @@ namespace OpenSim.Services.Connectors.SimianGrid
102 m_log.Info("[SIMIAN AUTH CONNECTOR]: No AuthenticationServerURI specified, disabling connector"); 102 m_log.Info("[SIMIAN AUTH CONNECTOR]: No AuthenticationServerURI specified, disabling connector");
103 } 103 }
104 104
105 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
106 {
107 realID = UUID.Zero;
108 return Authenticate(principalID, password, lifetime);
109 }
110
105 public string Authenticate(UUID principalID, string password, int lifetime) 111 public string Authenticate(UUID principalID, string password, int lifetime)
106 { 112 {
107 NameValueCollection requestArgs = new NameValueCollection 113 NameValueCollection requestArgs = new NameValueCollection
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
index b031f21..6043b70 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
@@ -28,6 +28,8 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Collections.Specialized; 30using System.Collections.Specialized;
31using System.Drawing;
32using System.Drawing.Imaging;
31using System.IO; 33using System.IO;
32using System.Net; 34using System.Net;
33using System.Reflection; 35using System.Reflection;
@@ -100,6 +102,15 @@ namespace OpenSim.Services.Connectors.SimianGrid
100 102
101 public string RegisterRegion(UUID scopeID, GridRegion regionInfo) 103 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
102 { 104 {
105 IPEndPoint ext = regionInfo.ExternalEndPoint;
106 if (ext == null) return "Region registration for " + regionInfo.RegionName + " failed: Could not resolve EndPoint";
107 // Generate and upload our map tile in PNG format to the SimianGrid AddMapTile service
108// Scene scene;
109// if (m_scenes.TryGetValue(regionInfo.RegionID, out scene))
110// UploadMapTile(scene);
111// else
112// m_log.Warn("Registering region " + regionInfo.RegionName + " (" + regionInfo.RegionID + ") that we are not tracking");
113
103 Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0); 114 Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0);
104 Vector3d maxPosition = minPosition + new Vector3d(regionInfo.RegionSizeX, regionInfo.RegionSizeY, Constants.RegionHeight); 115 Vector3d maxPosition = minPosition + new Vector3d(regionInfo.RegionSizeX, regionInfo.RegionSizeY, Constants.RegionHeight);
105 116
@@ -108,7 +119,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
108 { "ServerURI", OSD.FromString(regionInfo.ServerURI) }, 119 { "ServerURI", OSD.FromString(regionInfo.ServerURI) },
109 { "InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) }, 120 { "InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) },
110 { "InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) }, 121 { "InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) },
111 { "ExternalAddress", OSD.FromString(regionInfo.ExternalEndPoint.Address.ToString()) }, 122 { "ExternalAddress", OSD.FromString(ext.Address.ToString()) },
112 { "ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) }, 123 { "ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) },
113 { "MapTexture", OSD.FromUUID(regionInfo.TerrainImage) }, 124 { "MapTexture", OSD.FromUUID(regionInfo.TerrainImage) },
114 { "Access", OSD.FromInteger(regionInfo.Access) }, 125 { "Access", OSD.FromInteger(regionInfo.Access) },
@@ -412,6 +423,83 @@ namespace OpenSim.Services.Connectors.SimianGrid
412 423
413 #endregion IGridService 424 #endregion IGridService
414 425
426 private void UploadMapTile(IScene scene)
427 {
428 string errorMessage = null;
429
430 // Create a PNG map tile and upload it to the AddMapTile API
431 byte[] pngData = Utils.EmptyBytes;
432 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
433 if (tileGenerator == null)
434 {
435 m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator");
436 return;
437 }
438
439 using (Image mapTile = tileGenerator.CreateMapTile())
440 {
441 using (MemoryStream stream = new MemoryStream())
442 {
443 mapTile.Save(stream, ImageFormat.Png);
444 pngData = stream.ToArray();
445 }
446 }
447
448 List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
449 {
450 new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
451 new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
452 new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
453 };
454
455 // Make the remote storage request
456 try
457 {
458 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI);
459
460 HttpWebResponse response = MultipartForm.Post(request, postParameters);
461 using (Stream responseStream = response.GetResponseStream())
462 {
463 string responseStr = null;
464
465 try
466 {
467 responseStr = responseStream.GetStreamString();
468 OSD responseOSD = OSDParser.Deserialize(responseStr);
469 if (responseOSD.Type == OSDType.Map)
470 {
471 OSDMap responseMap = (OSDMap)responseOSD;
472 if (responseMap["Success"].AsBoolean())
473 m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile");
474 else
475 errorMessage = "Upload failed: " + responseMap["Message"].AsString();
476 }
477 else
478 {
479 errorMessage = "Response format was invalid:\n" + responseStr;
480 }
481 }
482 catch (Exception ex)
483 {
484 if (!String.IsNullOrEmpty(responseStr))
485 errorMessage = "Failed to parse the response:\n" + responseStr;
486 else
487 errorMessage = "Failed to retrieve the response: " + ex.Message;
488 }
489 }
490 }
491 catch (WebException ex)
492 {
493 errorMessage = ex.Message;
494 }
495
496 if (!String.IsNullOrEmpty(errorMessage))
497 {
498 m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}",
499 pngData.Length, scene.RegionInfo.RegionName, errorMessage.Replace('\n', ' '));
500 }
501 }
502
415 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) 503 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled)
416 { 504 {
417 NameValueCollection requestArgs = new NameValueCollection 505 NameValueCollection requestArgs = new NameValueCollection
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs
index 698c4c0..08c5c50 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianUserAccountServiceConnector.cs
@@ -191,9 +191,15 @@ namespace OpenSim.Services.Connectors.SimianGrid
191 return accounts; 191 return accounts;
192 } 192 }
193 193
194<<<<<<< HEAD
194 public void InvalidateCache(UUID userID) 195 public void InvalidateCache(UUID userID)
195 { 196 {
196 m_accountCache.Remove(userID); 197 m_accountCache.Remove(userID);
198=======
199 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
200 {
201 return null;
202>>>>>>> avn/ubitvar
197 } 203 }
198 204
199 public bool StoreUserAccount(UserAccount data) 205 public bool StoreUserAccount(UserAccount data)
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index 1eedbef..28b6de7 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -112,6 +112,7 @@ namespace OpenSim.Services.Connectors.Simulation
112 112
113 if (destination == null) 113 if (destination == null)
114 { 114 {
115 reason = "Destination not found";
115 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); 116 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
116 return false; 117 return false;
117 } 118 }
@@ -282,7 +283,13 @@ namespace OpenSim.Services.Connectors.Simulation
282 } 283 }
283 284
284 285
286<<<<<<< HEAD
285 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string myversion, List<UUID> featuresAvailable, out string version, out string reason) 287 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string myversion, List<UUID> featuresAvailable, out string version, out string reason)
288=======
289 /// <summary>
290 /// </summary>
291 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string myversion, out string version, out string reason)
292>>>>>>> avn/ubitvar
286 { 293 {
287 reason = "Failed to contact destination"; 294 reason = "Failed to contact destination";
288 version = "Unknown"; 295 version = "Unknown";
@@ -299,6 +306,7 @@ namespace OpenSim.Services.Connectors.Simulation
299 request.Add("viaTeleport", OSD.FromBoolean(viaTeleport)); 306 request.Add("viaTeleport", OSD.FromBoolean(viaTeleport));
300 request.Add("position", OSD.FromString(position.ToString())); 307 request.Add("position", OSD.FromString(position.ToString()));
301 request.Add("my_version", OSD.FromString(myversion)); 308 request.Add("my_version", OSD.FromString(myversion));
309<<<<<<< HEAD
302 310
303 OSDArray features = new OSDArray(); 311 OSDArray features = new OSDArray();
304 foreach (UUID feature in featuresAvailable) 312 foreach (UUID feature in featuresAvailable)
@@ -306,6 +314,8 @@ namespace OpenSim.Services.Connectors.Simulation
306 314
307 request.Add("features", features); 315 request.Add("features", features);
308 316
317=======
318>>>>>>> avn/ubitvar
309 if (agentHomeURI != null) 319 if (agentHomeURI != null)
310 request.Add("agent_home_uri", OSD.FromString(agentHomeURI)); 320 request.Add("agent_home_uri", OSD.FromString(agentHomeURI));
311 321
@@ -356,6 +366,7 @@ namespace OpenSim.Services.Connectors.Simulation
356 return false; 366 return false;
357 } 367 }
358 368
369<<<<<<< HEAD
359 370
360 featuresAvailable.Clear(); 371 featuresAvailable.Clear();
361 372
@@ -366,6 +377,11 @@ namespace OpenSim.Services.Connectors.Simulation
366 foreach (OSD o in array) 377 foreach (OSD o in array)
367 featuresAvailable.Add(new UUID(o.AsString())); 378 featuresAvailable.Add(new UUID(o.AsString()));
368 } 379 }
380=======
381 OSDMap resp = (OSDMap)result["_Result"];
382 success = resp["success"].AsBoolean();
383 reason = resp["reason"].AsString();
384>>>>>>> avn/ubitvar
369 385
370 return success; 386 return success;
371 } 387 }
@@ -451,12 +467,17 @@ namespace OpenSim.Services.Connectors.Simulation
451 args["destination_name"] = OSD.FromString(destination.RegionName); 467 args["destination_name"] = OSD.FromString(destination.RegionName);
452 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); 468 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
453 469
470<<<<<<< HEAD
454 OSDMap result = WebUtil.PostToService(uri, args, 40000, false); 471 OSDMap result = WebUtil.PostToService(uri, args, 40000, false);
455 472
456 if (result == null) 473 if (result == null)
457 return false; 474 return false;
458 bool success = result["success"].AsBoolean(); 475 bool success = result["success"].AsBoolean();
459 if (!success) 476 if (!success)
477=======
478 OSDMap response = WebUtil.PostToService(uri, args, 40000);
479 if (response["Success"] == "False")
480>>>>>>> avn/ubitvar
460 return false; 481 return false;
461 } 482 }
462 catch (Exception e) 483 catch (Exception e)
diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
index 560e6c4..e5fb5a8 100644
--- a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
+++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs
@@ -191,8 +191,14 @@ namespace OpenSim.Services.Connectors
191 return accounts; 191 return accounts;
192 } 192 }
193 193
194<<<<<<< HEAD
194 public void InvalidateCache(UUID userID) 195 public void InvalidateCache(UUID userID)
195 { 196 {
197=======
198 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where)
199 {
200 return null; // Not implemented for regions
201>>>>>>> avn/ubitvar
196 } 202 }
197 203
198 public virtual bool StoreUserAccount(UserAccount data) 204 public virtual bool StoreUserAccount(UserAccount data)
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 8807397..8293c18 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -57,9 +57,13 @@ namespace OpenSim.Services.GridService
57 protected bool m_AllowDuplicateNames = false; 57 protected bool m_AllowDuplicateNames = false;
58 protected bool m_AllowHypergridMapSearch = false; 58 protected bool m_AllowHypergridMapSearch = false;
59 59
60<<<<<<< HEAD
60 protected bool m_SuppressVarregionOverlapCheckOnRegistration = false; 61 protected bool m_SuppressVarregionOverlapCheckOnRegistration = false;
61 62
62 private static Dictionary<string,object> m_ExtraFeatures = new Dictionary<string, object>(); 63 private static Dictionary<string,object> m_ExtraFeatures = new Dictionary<string, object>();
64=======
65 private static Dictionary<string, object> m_ExtraFeatures = new Dictionary<string, object>();
66>>>>>>> avn/ubitvar
63 67
64 public GridService(IConfigSource config) 68 public GridService(IConfigSource config)
65 : base(config) 69 : base(config)
@@ -155,9 +159,15 @@ namespace OpenSim.Services.GridService
155 159
156 if (loginConfig == null || gridConfig == null) 160 if (loginConfig == null || gridConfig == null)
157 return; 161 return;
162<<<<<<< HEAD
158 163
159 string configVal; 164 string configVal;
160 165
166=======
167
168 string configVal;
169
170>>>>>>> avn/ubitvar
161 configVal = loginConfig.GetString("SearchURL", string.Empty); 171 configVal = loginConfig.GetString("SearchURL", string.Empty);
162 if (!string.IsNullOrEmpty(configVal)) 172 if (!string.IsNullOrEmpty(configVal))
163 m_ExtraFeatures["search-server-url"] = configVal; 173 m_ExtraFeatures["search-server-url"] = configVal;
@@ -201,6 +211,7 @@ namespace OpenSim.Services.GridService
201 if (regionInfos.RegionID == UUID.Zero) 211 if (regionInfos.RegionID == UUID.Zero)
202 return "Invalid RegionID - cannot be zero UUID"; 212 return "Invalid RegionID - cannot be zero UUID";
203 213
214<<<<<<< HEAD
204 String reason = "Region overlaps another region"; 215 String reason = "Region overlaps another region";
205 RegionData region = FindAnyConflictingRegion(regionInfos, scopeID, out reason); 216 RegionData region = FindAnyConflictingRegion(regionInfos, scopeID, out reason);
206 // If there is a conflicting region, if it has the same ID and same coordinates 217 // If there is a conflicting region, if it has the same ID and same coordinates
@@ -210,6 +221,12 @@ namespace OpenSim.Services.GridService
210 || (region.coordY != regionInfos.RegionCoordY) 221 || (region.coordY != regionInfos.RegionCoordY)
211 || (region.RegionID != regionInfos.RegionID) ) 222 || (region.RegionID != regionInfos.RegionID) )
212 ) 223 )
224=======
225 // we should not need to check for overlaps
226
227 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
228 if ((region != null) && (region.RegionID != regionInfos.RegionID))
229>>>>>>> avn/ubitvar
213 { 230 {
214 // If not same ID and same coordinates, this new region has conflicts and can't be registered. 231 // If not same ID and same coordinates, this new region has conflicts and can't be registered.
215 m_log.WarnFormat("{0} Register region conflict in scope {1}. {2}", LogHeader, scopeID, reason); 232 m_log.WarnFormat("{0} Register region conflict in scope {1}. {2}", LogHeader, scopeID, reason);
@@ -463,7 +480,7 @@ namespace OpenSim.Services.GridService
463 480
464 int flags = Convert.ToInt32(region.Data["flags"]); 481 int flags = Convert.ToInt32(region.Data["flags"]);
465 482
466 if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Framework.RegionFlags.Persistent) != 0) 483 if ((!m_DeleteOnUnregister) || ((flags & (int)OpenSim.Framework.RegionFlags.Persistent) != 0))
467 { 484 {
468 flags &= ~(int)OpenSim.Framework.RegionFlags.RegionOnline; 485 flags &= ~(int)OpenSim.Framework.RegionFlags.RegionOnline;
469 region.Data["flags"] = flags.ToString(); 486 region.Data["flags"] = flags.ToString();
@@ -478,7 +495,6 @@ namespace OpenSim.Services.GridService
478 } 495 }
479 496
480 return true; 497 return true;
481
482 } 498 }
483 499
484 return m_Database.Delete(regionID); 500 return m_Database.Delete(regionID);
@@ -492,10 +508,19 @@ namespace OpenSim.Services.GridService
492 if (region != null) 508 if (region != null)
493 { 509 {
494 // Not really? Maybe? 510 // Not really? Maybe?
511<<<<<<< HEAD
495 // The adjacent regions are presumed to be the same size as the current region 512 // The adjacent regions are presumed to be the same size as the current region
513=======
514/* this fails wiht var regions. My_sql db should now handle var regions
515>>>>>>> avn/ubitvar
496 List<RegionData> rdatas = m_Database.Get( 516 List<RegionData> rdatas = m_Database.Get(
497 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1, 517 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1,
498 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID); 518 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID);
519*/
520 // so send normal search area
521 List<RegionData> rdatas = m_Database.Get(
522 region.posX - 1, region.posY - 1,
523 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID);
499 524
500 foreach (RegionData rdata in rdatas) 525 foreach (RegionData rdata in rdatas)
501 { 526 {
@@ -537,6 +562,7 @@ namespace OpenSim.Services.GridService
537 // be the base coordinate of the region. 562 // be the base coordinate of the region.
538 // The snapping is technically unnecessary but is harmless because regions are always 563 // The snapping is technically unnecessary but is harmless because regions are always
539 // multiples of the legacy region size (256). 564 // multiples of the legacy region size (256).
565
540 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 566 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
541 { 567 {
542 uint regionX = Util.WorldToRegionLoc((uint)x); 568 uint regionX = Util.WorldToRegionLoc((uint)x);
@@ -872,7 +898,11 @@ namespace OpenSim.Services.GridService
872 return; 898 return;
873 } 899 }
874 900
901<<<<<<< HEAD
875 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y), UUID.Zero); 902 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y), UUID.Zero);
903=======
904 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y), UUID.Zero);
905>>>>>>> avn/ubitvar
876 if (region == null) 906 if (region == null)
877 { 907 {
878 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y); 908 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y);
@@ -889,7 +919,11 @@ namespace OpenSim.Services.GridService
889 ConsoleDisplayList dispList = new ConsoleDisplayList(); 919 ConsoleDisplayList dispList = new ConsoleDisplayList();
890 dispList.AddRow("Region Name", r.RegionName); 920 dispList.AddRow("Region Name", r.RegionName);
891 dispList.AddRow("Region ID", r.RegionID); 921 dispList.AddRow("Region ID", r.RegionID);
922<<<<<<< HEAD
892 dispList.AddRow("Position", string.Format("{0},{1}", r.coordX, r.coordY)); 923 dispList.AddRow("Position", string.Format("{0},{1}", r.coordX, r.coordY));
924=======
925 dispList.AddRow("Location", string.Format("{0},{1}", r.coordX, r.coordY));
926>>>>>>> avn/ubitvar
893 dispList.AddRow("Size", string.Format("{0}x{1}", r.sizeX, r.sizeY)); 927 dispList.AddRow("Size", string.Format("{0}x{1}", r.sizeX, r.sizeY));
894 dispList.AddRow("URI", r.Data["serverURI"]); 928 dispList.AddRow("URI", r.Data["serverURI"]);
895 dispList.AddRow("Owner ID", r.Data["owner_uuid"]); 929 dispList.AddRow("Owner ID", r.Data["owner_uuid"]);
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index 9d016fc..b4577b0 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -343,7 +343,11 @@ namespace OpenSim.Services.GridService
343 GridRegion region = m_GridService.GetRegionByPosition(regInfo.ScopeID, regInfo.RegionLocX, regInfo.RegionLocY); 343 GridRegion region = m_GridService.GetRegionByPosition(regInfo.ScopeID, regInfo.RegionLocX, regInfo.RegionLocY);
344 if (region != null) 344 if (region != null)
345 { 345 {
346<<<<<<< HEAD
346 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates <{0},{1}> are already occupied by region {2} with uuid {3}", 347 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates <{0},{1}> are already occupied by region {2} with uuid {3}",
348=======
349 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}",
350>>>>>>> avn/ubitvar
347 Util.WorldToRegionLoc((uint)regInfo.RegionLocX), Util.WorldToRegionLoc((uint)regInfo.RegionLocY), 351 Util.WorldToRegionLoc((uint)regInfo.RegionLocX), Util.WorldToRegionLoc((uint)regInfo.RegionLocY),
348 region.RegionName, region.RegionID); 352 region.RegionName, region.RegionID);
349 reason = "Coordinates are already in use"; 353 reason = "Coordinates are already in use";
@@ -379,8 +383,13 @@ namespace OpenSim.Services.GridService
379 region = m_GridService.GetRegionByUUID(scopeID, regionID); 383 region = m_GridService.GetRegionByUUID(scopeID, regionID);
380 if (region != null) 384 if (region != null)
381 { 385 {
386<<<<<<< HEAD
382 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates <{0},{1}>", 387 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates <{0},{1}>",
383 Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY)); 388 Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
389=======
390 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}",
391 Util.WorldToRegionLoc((uint)regInfo.RegionLocX), Util.WorldToRegionLoc((uint)regInfo.RegionLocY));
392>>>>>>> avn/ubitvar
384 regInfo = region; 393 regInfo = region;
385 return true; 394 return true;
386 } 395 }
@@ -536,6 +545,7 @@ namespace OpenSim.Services.GridService
536 MainConsole.Instance.Output(new string('-', 72)); 545 MainConsole.Instance.Output(new string('-', 72));
537 foreach (RegionData r in regions) 546 foreach (RegionData r in regions)
538 { 547 {
548<<<<<<< HEAD
539 MainConsole.Instance.Output( 549 MainConsole.Instance.Output(
540 String.Format("{0}\n{2,-32} {1}\n", 550 String.Format("{0}\n{2,-32} {1}\n",
541 r.RegionName, r.RegionID, 551 r.RegionName, r.RegionID,
@@ -544,6 +554,12 @@ namespace OpenSim.Services.GridService
544 ) 554 )
545 ) 555 )
546 ); 556 );
557=======
558 MainConsole.Instance.Output(String.Format("{0}\n{2,-32} {1}\n",
559 r.RegionName, r.RegionID,
560 String.Format("{0},{1} ({2},{3})", r.posX, r.posY,
561 Util.WorldToRegionLoc((uint)r.posX), Util.WorldToRegionLoc((uint)r.posY))) );
562>>>>>>> avn/ubitvar
547 } 563 }
548 return; 564 return;
549 } 565 }
@@ -645,8 +661,13 @@ namespace OpenSim.Services.GridService
645 string externalHostName; 661 string externalHostName;
646 try 662 try
647 { 663 {
664<<<<<<< HEAD
648 xloc = Convert.ToUInt32(cmdparams[0]); 665 xloc = Convert.ToUInt32(cmdparams[0]);
649 yloc = Convert.ToUInt32(cmdparams[1]); 666 yloc = Convert.ToUInt32(cmdparams[1]);
667=======
668 xloc = (uint)Convert.ToInt32(cmdparams[0]);
669 yloc = (uint)Convert.ToInt32(cmdparams[1]);
670>>>>>>> avn/ubitvar
650 externalPort = Convert.ToUInt32(cmdparams[3]); 671 externalPort = Convert.ToUInt32(cmdparams[3]);
651 externalHostName = cmdparams[2]; 672 externalHostName = cmdparams[2];
652 //internalPort = Convert.ToUInt32(cmdparams[4]); 673 //internalPort = Convert.ToUInt32(cmdparams[4]);
@@ -749,8 +770,13 @@ namespace OpenSim.Services.GridService
749 string externalHostName; 770 string externalHostName;
750 uint realXLoc, realYLoc; 771 uint realXLoc, realYLoc;
751 772
773<<<<<<< HEAD
752 xloc = Convert.ToUInt32(config.GetString("xloc", "0")); 774 xloc = Convert.ToUInt32(config.GetString("xloc", "0"));
753 yloc = Convert.ToUInt32(config.GetString("yloc", "0")); 775 yloc = Convert.ToUInt32(config.GetString("yloc", "0"));
776=======
777 xloc = (uint)Convert.ToInt32(config.GetString("xloc", "0"));
778 yloc = (uint)Convert.ToInt32(config.GetString("yloc", "0"));
779>>>>>>> avn/ubitvar
754 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); 780 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
755 externalHostName = config.GetString("externalHostName", ""); 781 externalHostName = config.GetString("externalHostName", "");
756 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); 782 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
@@ -758,8 +784,13 @@ namespace OpenSim.Services.GridService
758 784
759 if (m_enableAutoMapping) 785 if (m_enableAutoMapping)
760 { 786 {
787<<<<<<< HEAD
761 xloc = (xloc % 100) + m_autoMappingX; 788 xloc = (xloc % 100) + m_autoMappingX;
762 yloc = (yloc % 100) + m_autoMappingY; 789 yloc = (yloc % 100) + m_autoMappingY;
790=======
791 xloc = (uint)((xloc % 100) + m_autoMappingX);
792 yloc = (uint)((yloc % 100) + m_autoMappingY);
793>>>>>>> avn/ubitvar
763 } 794 }
764 795
765 if (((realXLoc == 0) && (realYLoc == 0)) || 796 if (((realXLoc == 0) && (realYLoc == 0)) ||
diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs
index fa7dd0b..6c3c655 100644
--- a/OpenSim/Services/HypergridService/UserAccountCache.cs
+++ b/OpenSim/Services/HypergridService/UserAccountCache.cs
@@ -90,6 +90,11 @@ namespace OpenSim.Services.HypergridService
90 return null; 90 return null;
91 } 91 }
92 92
93 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
94 {
95 return null;
96 }
97
93 public List<UserAccount> GetUserAccounts(UUID scopeID, string query) 98 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
94 { 99 {
95 return null; 100 return null;
diff --git a/OpenSim/Services/Interfaces/IAttachmentsService.cs b/OpenSim/Services/Interfaces/IAttachmentsService.cs
new file mode 100644
index 0000000..bdde369
--- /dev/null
+++ b/OpenSim/Services/Interfaces/IAttachmentsService.cs
@@ -0,0 +1,17 @@
1////////////////////////////////////////////////////////////////
2//
3// (c) 2009, 2010 Careminster Limited and Melanie Thielker
4//
5// All rights reserved
6//
7using System;
8using Nini.Config;
9
10namespace OpenSim.Services.Interfaces
11{
12 public interface IAttachmentsService
13 {
14 string Get(string id);
15 void Store(string id, string data);
16 }
17}
diff --git a/OpenSim/Services/Interfaces/IAuthenticationService.cs b/OpenSim/Services/Interfaces/IAuthenticationService.cs
index cee8bc0..cdcfad9 100644
--- a/OpenSim/Services/Interfaces/IAuthenticationService.cs
+++ b/OpenSim/Services/Interfaces/IAuthenticationService.cs
@@ -67,6 +67,7 @@ namespace OpenSim.Services.Interfaces
67 // various services. 67 // various services.
68 // 68 //
69 string Authenticate(UUID principalID, string password, int lifetime); 69 string Authenticate(UUID principalID, string password, int lifetime);
70 string Authenticate(UUID principalID, string password, int lifetime, out UUID realID);
70 71
71 ////////////////////////////////////////////////////// 72 //////////////////////////////////////////////////////
72 // Verification 73 // Verification
diff --git a/OpenSim/Services/Interfaces/IAvatarService.cs b/OpenSim/Services/Interfaces/IAvatarService.cs
index 6ca0b15..3663a7a 100644
--- a/OpenSim/Services/Interfaces/IAvatarService.cs
+++ b/OpenSim/Services/Interfaces/IAvatarService.cs
@@ -162,10 +162,16 @@ namespace OpenSim.Services.Interfaces
162 } 162 }
163 163
164 // Visual Params 164 // Visual Params
165 string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT]; 165 // string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT];
166 // byte[] binary = appearance.VisualParams;
167
168 // for (int i = 0 ; i < AvatarAppearance.VISUALPARAM_COUNT ; i++)
169
170
166 byte[] binary = appearance.VisualParams; 171 byte[] binary = appearance.VisualParams;
172 string[] vps = new string[binary.Length];
167 173
168 for (int i = 0 ; i < AvatarAppearance.VISUALPARAM_COUNT ; i++) 174 for (int i = 0; i < binary.Length; i++)
169 { 175 {
170 vps[i] = binary[i].ToString(); 176 vps[i] = binary[i].ToString();
171 } 177 }
@@ -202,7 +208,13 @@ namespace OpenSim.Services.Interfaces
202 appearance.Serial = Int32.Parse(Data["Serial"]); 208 appearance.Serial = Int32.Parse(Data["Serial"]);
203 209
204 if (Data.ContainsKey("AvatarHeight")) 210 if (Data.ContainsKey("AvatarHeight"))
205 appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]); 211 {
212 float h = float.Parse(Data["AvatarHeight"]);
213 if( h == 0f)
214 h = 1.9f;
215 appearance.SetSize(new Vector3(0.45f, 0.6f, h ));
216// appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]);
217 }
206 218
207 // Legacy Wearables 219 // Legacy Wearables
208 if (Data.ContainsKey("BodyItem")) 220 if (Data.ContainsKey("BodyItem"))
@@ -273,10 +285,14 @@ namespace OpenSim.Services.Interfaces
273 if (Data.ContainsKey("VisualParams")) 285 if (Data.ContainsKey("VisualParams"))
274 { 286 {
275 string[] vps = Data["VisualParams"].Split(new char[] {','}); 287 string[] vps = Data["VisualParams"].Split(new char[] {','});
276 byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT]; 288 // byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT];
289
290 // for (int i = 0 ; i < vps.Length && i < binary.Length ; i++)
291 byte[] binary = new byte[vps.Length];
277 292
278 for (int i = 0 ; i < vps.Length && i < binary.Length ; i++) 293 for (int i = 0; i < vps.Length; i++)
279 binary[i] = (byte)Convert.ToInt32(vps[i]); 294
295 binary[i] = (byte)Convert.ToInt32(vps[i]);
280 296
281 appearance.VisualParams = binary; 297 appearance.VisualParams = binary;
282 } 298 }
@@ -342,6 +358,7 @@ namespace OpenSim.Services.Interfaces
342 appearance.Wearables[AvatarWearable.EYES].Wear( 358 appearance.Wearables[AvatarWearable.EYES].Wear(
343 AvatarWearable.DefaultWearables[ 359 AvatarWearable.DefaultWearables[
344 AvatarWearable.EYES][0]); 360 AvatarWearable.EYES][0]);
361
345 } 362 }
346 catch 363 catch
347 { 364 {
diff --git a/OpenSim/Services/Interfaces/IBakedTextureService.cs b/OpenSim/Services/Interfaces/IBakedTextureService.cs
index 69df4a0..ab88695 100644
--- a/OpenSim/Services/Interfaces/IBakedTextureService.cs
+++ b/OpenSim/Services/Interfaces/IBakedTextureService.cs
@@ -1,3 +1,4 @@
1<<<<<<< HEAD
1/* 2/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 3 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 4 * See CONTRIBUTORS.TXT for a full list of copyright holders.
@@ -25,6 +26,14 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 27 */
27 28
29=======
30////////////////////////////////////////////////////////////////
31//
32// (c) 2009, 2010 Careminster Limited and Melanie Thielker
33//
34// All rights reserved
35//
36>>>>>>> avn/ubitvar
28using System; 37using System;
29using Nini.Config; 38using Nini.Config;
30 39
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index f5f1f75..7e5597b 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -159,7 +159,17 @@ namespace OpenSim.Services.Interfaces
159 } 159 }
160 } 160 }
161 set { 161 set {
162<<<<<<< HEAD
162 if (value.EndsWith("/")) { 163 if (value.EndsWith("/")) {
164=======
165 if ( value == null)
166 {
167 m_serverURI = String.Empty;
168 return;
169 }
170
171 if ( value.EndsWith("/") ) {
172>>>>>>> avn/ubitvar
163 m_serverURI = value; 173 m_serverURI = value;
164 } else { 174 } else {
165 m_serverURI = value + '/'; 175 m_serverURI = value + '/';
@@ -500,9 +510,13 @@ namespace OpenSim.Services.Interfaces
500 } 510 }
501 catch (SocketException e) 511 catch (SocketException e)
502 { 512 {
503 throw new Exception( 513 /*throw new Exception(
504 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + 514 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
505 e + "' attached to this exception", e); 515 e + "' attached to this exception", e);*/
516 // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
517 // Reason is, on systems such as OSgrid it has occured that known hostnames stop
518 // resolving and thus make surrounding regions crash out with this exception.
519 return null;
506 } 520 }
507 521
508 return new IPEndPoint(ia, m_internalEndPoint.Port); 522 return new IPEndPoint(ia, m_internalEndPoint.Port);
@@ -525,5 +539,110 @@ namespace OpenSim.Services.Interfaces
525 { 539 {
526 get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); } 540 get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); }
527 } 541 }
542<<<<<<< HEAD
543=======
544
545 public Dictionary<string, object> ToKeyValuePairs()
546 {
547 Dictionary<string, object> kvp = new Dictionary<string, object>();
548 kvp["uuid"] = RegionID.ToString();
549 kvp["locX"] = RegionLocX.ToString();
550 kvp["locY"] = RegionLocY.ToString();
551 kvp["sizeX"] = RegionSizeX.ToString();
552 kvp["sizeY"] = RegionSizeY.ToString();
553 kvp["regionName"] = RegionName;
554 kvp["serverIP"] = ExternalHostName; //ExternalEndPoint.Address.ToString();
555 kvp["serverHttpPort"] = HttpPort.ToString();
556 kvp["serverURI"] = ServerURI;
557 kvp["serverPort"] = InternalEndPoint.Port.ToString();
558 kvp["regionMapTexture"] = TerrainImage.ToString();
559 kvp["parcelMapTexture"] = ParcelImage.ToString();
560 kvp["access"] = Access.ToString();
561 kvp["regionSecret"] = RegionSecret;
562 kvp["owner_uuid"] = EstateOwner.ToString();
563 kvp["Token"] = Token.ToString();
564 // Maturity doesn't seem to exist in the DB
565 return kvp;
566 }
567
568 public GridRegion(Dictionary<string, object> kvp)
569 {
570 if (kvp.ContainsKey("uuid"))
571 RegionID = new UUID((string)kvp["uuid"]);
572
573 if (kvp.ContainsKey("locX"))
574 RegionLocX = Convert.ToInt32((string)kvp["locX"]);
575
576 if (kvp.ContainsKey("locY"))
577 RegionLocY = Convert.ToInt32((string)kvp["locY"]);
578
579 if (kvp.ContainsKey("sizeX"))
580 RegionSizeX = Convert.ToInt32((string)kvp["sizeX"]);
581 else
582 RegionSizeX = (int)Constants.RegionSize;
583
584 if (kvp.ContainsKey("sizeY"))
585 RegionSizeY = Convert.ToInt32((string)kvp["sizeY"]);
586 else
587 RegionSizeY = (int)Constants.RegionSize;
588
589 if (kvp.ContainsKey("regionName"))
590 RegionName = (string)kvp["regionName"];
591
592 if (kvp.ContainsKey("access"))
593 {
594 byte access = Convert.ToByte((string)kvp["access"]);
595 Maturity = (int)Util.ConvertAccessLevelToMaturity(access);
596 }
597
598 if (kvp.ContainsKey("serverIP"))
599 {
600 //int port = 0;
601 //Int32.TryParse((string)kvp["serverPort"], out port);
602 //IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["serverIP"]), port);
603 ExternalHostName = (string)kvp["serverIP"];
604 }
605 else
606 ExternalHostName = "127.0.0.1";
607
608 if (kvp.ContainsKey("serverPort"))
609 {
610 Int32 port = 0;
611 Int32.TryParse((string)kvp["serverPort"], out port);
612 InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
613 }
614
615 if (kvp.ContainsKey("serverHttpPort"))
616 {
617 UInt32 port = 0;
618 UInt32.TryParse((string)kvp["serverHttpPort"], out port);
619 HttpPort = port;
620 }
621
622 if (kvp.ContainsKey("serverURI"))
623 ServerURI = (string)kvp["serverURI"];
624
625 if (kvp.ContainsKey("regionMapTexture"))
626 UUID.TryParse((string)kvp["regionMapTexture"], out TerrainImage);
627
628 if (kvp.ContainsKey("parcelMapTexture"))
629 UUID.TryParse((string)kvp["parcelMapTexture"], out ParcelImage);
630
631 if (kvp.ContainsKey("access"))
632 Access = Byte.Parse((string)kvp["access"]);
633
634 if (kvp.ContainsKey("regionSecret"))
635 RegionSecret =(string)kvp["regionSecret"];
636
637 if (kvp.ContainsKey("owner_uuid"))
638 EstateOwner = new UUID(kvp["owner_uuid"].ToString());
639
640 if (kvp.ContainsKey("Token"))
641 Token = kvp["Token"].ToString();
642
643 // m_log.DebugFormat("{0} New GridRegion. id={1}, loc=<{2},{3}>, size=<{4},{5}>",
644 // LogHeader, RegionID, RegionLocX, RegionLocY, RegionSizeX, RegionSizeY);
645 }
646>>>>>>> avn/ubitvar
528 } 647 }
529} \ No newline at end of file 648}
diff --git a/OpenSim/Services/Interfaces/ILoginService.cs b/OpenSim/Services/Interfaces/ILoginService.cs
index ee9b0b1..7c44cd8 100644
--- a/OpenSim/Services/Interfaces/ILoginService.cs
+++ b/OpenSim/Services/Interfaces/ILoginService.cs
@@ -47,8 +47,8 @@ namespace OpenSim.Services.Interfaces
47 47
48 public interface ILoginService 48 public interface ILoginService
49 { 49 {
50 LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID, 50 LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID,
51 string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP); 51 string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP, bool LibOMVclient);
52 Hashtable SetLevel(string firstName, string lastName, string passwd, int level, IPEndPoint clientIP); 52 Hashtable SetLevel(string firstName, string lastName, string passwd, int level, IPEndPoint clientIP);
53 } 53 }
54 54
diff --git a/OpenSim/Services/Interfaces/IMapImageService.cs b/OpenSim/Services/Interfaces/IMapImageService.cs
index 78daa5f..0d1458e 100644
--- a/OpenSim/Services/Interfaces/IMapImageService.cs
+++ b/OpenSim/Services/Interfaces/IMapImageService.cs
@@ -34,8 +34,14 @@ namespace OpenSim.Services.Interfaces
34 public interface IMapImageService 34 public interface IMapImageService
35 { 35 {
36 //List<MapBlockData> GetMapBlocks(UUID scopeID, int minX, int minY, int maxX, int maxY); 36 //List<MapBlockData> GetMapBlocks(UUID scopeID, int minX, int minY, int maxX, int maxY);
37<<<<<<< HEAD
37 bool AddMapTile(int x, int y, byte[] imageData, out string reason); 38 bool AddMapTile(int x, int y, byte[] imageData, out string reason);
38 bool RemoveMapTile(int x, int y, out string reason); 39 bool RemoveMapTile(int x, int y, out string reason);
39 byte[] GetMapTile(string fileName, out string format); 40 byte[] GetMapTile(string fileName, out string format);
41=======
42 bool AddMapTile(int x, int y, byte[] imageData, UUID scopeID, out string reason);
43 bool RemoveMapTile(int x, int y, UUID scopeID, out string reason);
44 byte[] GetMapTile(string fileName, UUID scopeID, out string format);
45>>>>>>> avn/ubitvar
40 } 46 }
41} 47}
diff --git a/OpenSim/Services/Interfaces/ISimulationService.cs b/OpenSim/Services/Interfaces/ISimulationService.cs
index 42c414d..ee1e294 100644
--- a/OpenSim/Services/Interfaces/ISimulationService.cs
+++ b/OpenSim/Services/Interfaces/ISimulationService.cs
@@ -86,6 +86,7 @@ namespace OpenSim.Services.Interfaces
86 /// <param name="agentHomeURI">The visitor's Home URI. Will be missing (null) in older OpenSims.</param> 86 /// <param name="agentHomeURI">The visitor's Home URI. Will be missing (null) in older OpenSims.</param>
87 /// <param name="viaTeleport">True: via teleport; False: via cross (walking)</param> 87 /// <param name="viaTeleport">True: via teleport; False: via cross (walking)</param>
88 /// <param name="position">Position in the region</param> 88 /// <param name="position">Position in the region</param>
89<<<<<<< HEAD
89 /// <param name="sversion"> 90 /// <param name="sversion">
90 /// Version that the requesting simulator is runing. If null then no version check is carried out. 91 /// Version that the requesting simulator is runing. If null then no version check is carried out.
91 /// </param> 92 /// </param>
@@ -93,6 +94,13 @@ namespace OpenSim.Services.Interfaces
93 /// <param name="reason">[out] Optional error message</param> 94 /// <param name="reason">[out] Optional error message</param>
94 /// <returns>True: ok; False: not allowed</returns> 95 /// <returns>True: ok; False: not allowed</returns>
95 bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, List<UUID> features, out string version, out string reason); 96 bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, List<UUID> features, out string version, out string reason);
97=======
98 /// <param name="sversion">version that the requesting simulator is runing</param>
99 /// <param name="version">version that the target simulator is running</param>
100 /// <param name="reason">[out] Optional error message</param>
101 /// <returns>True: ok; False: not allowed</returns>
102 bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string sversion, out string version, out string reason);
103>>>>>>> avn/ubitvar
96 104
97 /// <summary> 105 /// <summary>
98 /// Message from receiving region to departing region, telling it got contacted by the client. 106 /// Message from receiving region to departing region, telling it got contacted by the client.
diff --git a/OpenSim/Services/Interfaces/IUserAccountService.cs b/OpenSim/Services/Interfaces/IUserAccountService.cs
index 2f7702c..1814699 100644
--- a/OpenSim/Services/Interfaces/IUserAccountService.cs
+++ b/OpenSim/Services/Interfaces/IUserAccountService.cs
@@ -91,6 +91,7 @@ namespace OpenSim.Services.Interfaces
91 public int UserLevel; 91 public int UserLevel;
92 public int UserFlags; 92 public int UserFlags;
93 public string UserTitle; 93 public string UserTitle;
94 public string UserCountry;
94 public Boolean LocalToGrid = true; 95 public Boolean LocalToGrid = true;
95 96
96 public Dictionary<string, object> ServiceURLs; 97 public Dictionary<string, object> ServiceURLs;
@@ -120,6 +121,8 @@ namespace OpenSim.Services.Interfaces
120 UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString()); 121 UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString());
121 if (kvp.ContainsKey("UserTitle")) 122 if (kvp.ContainsKey("UserTitle"))
122 UserTitle = kvp["UserTitle"].ToString(); 123 UserTitle = kvp["UserTitle"].ToString();
124 if (kvp.ContainsKey("UserCountry"))
125 UserCountry = kvp["UserCountry"].ToString();
123 if (kvp.ContainsKey("LocalToGrid")) 126 if (kvp.ContainsKey("LocalToGrid"))
124 Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid); 127 Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid);
125 128
@@ -155,6 +158,7 @@ namespace OpenSim.Services.Interfaces
155 result["UserLevel"] = UserLevel.ToString(); 158 result["UserLevel"] = UserLevel.ToString();
156 result["UserFlags"] = UserFlags.ToString(); 159 result["UserFlags"] = UserFlags.ToString();
157 result["UserTitle"] = UserTitle; 160 result["UserTitle"] = UserTitle;
161 result["UserCountry"] = UserCountry;
158 result["LocalToGrid"] = LocalToGrid.ToString(); 162 result["LocalToGrid"] = LocalToGrid.ToString();
159 163
160 string str = string.Empty; 164 string str = string.Empty;
@@ -182,6 +186,7 @@ namespace OpenSim.Services.Interfaces
182 /// <param name="query"></param> 186 /// <param name="query"></param>
183 /// <returns></returns> 187 /// <returns></returns>
184 List<UserAccount> GetUserAccounts(UUID scopeID, string query); 188 List<UserAccount> GetUserAccounts(UUID scopeID, string query);
189 List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where);
185 190
186 /// <summary> 191 /// <summary>
187 /// Store the data given, wich replaces the stored data, therefore must be complete. 192 /// Store the data given, wich replaces the stored data, therefore must be complete.
diff --git a/OpenSim/Services/Interfaces/IUserProfilesService.cs b/OpenSim/Services/Interfaces/IUserProfilesService.cs
index 121baa8..319d307 100644
--- a/OpenSim/Services/Interfaces/IUserProfilesService.cs
+++ b/OpenSim/Services/Interfaces/IUserProfilesService.cs
@@ -57,11 +57,6 @@ namespace OpenSim.Services.Interfaces
57 bool AvatarPropertiesRequest(ref UserProfileProperties prop, ref string result); 57 bool AvatarPropertiesRequest(ref UserProfileProperties prop, ref string result);
58 bool AvatarPropertiesUpdate(ref UserProfileProperties prop, ref string result); 58 bool AvatarPropertiesUpdate(ref UserProfileProperties prop, ref string result);
59 #endregion Profile Properties 59 #endregion Profile Properties
60
61 #region User Preferences
62 bool UserPreferencesRequest(ref UserPreferences pref, ref string result);
63 bool UserPreferencesUpdate(ref UserPreferences pref, ref string result);
64 #endregion User Preferences
65 60
66 #region Interests 61 #region Interests
67 bool AvatarInterestsUpdate(UserProfileProperties prop, ref string result); 62 bool AvatarInterestsUpdate(UserProfileProperties prop, ref string result);
diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
index c3756d0..92d93ee 100644
--- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -55,6 +55,7 @@ namespace OpenSim.Services.LLLoginService
55 public static LLFailedLoginResponse InventoryProblem; 55 public static LLFailedLoginResponse InventoryProblem;
56 public static LLFailedLoginResponse DeadRegionProblem; 56 public static LLFailedLoginResponse DeadRegionProblem;
57 public static LLFailedLoginResponse LoginBlockedProblem; 57 public static LLFailedLoginResponse LoginBlockedProblem;
58 public static LLFailedLoginResponse UnverifiedAccountProblem;
58 public static LLFailedLoginResponse AlreadyLoggedInProblem; 59 public static LLFailedLoginResponse AlreadyLoggedInProblem;
59 public static LLFailedLoginResponse InternalError; 60 public static LLFailedLoginResponse InternalError;
60 61
@@ -75,6 +76,10 @@ namespace OpenSim.Services.LLLoginService
75 LoginBlockedProblem = new LLFailedLoginResponse("presence", 76 LoginBlockedProblem = new LLFailedLoginResponse("presence",
76 "Logins are currently restricted. Please try again later.", 77 "Logins are currently restricted. Please try again later.",
77 "false"); 78 "false");
79 UnverifiedAccountProblem = new LLFailedLoginResponse("presence",
80 "Your account has not yet been verified. Please check " +
81 "your email and click the provided link.",
82 "false");
78 AlreadyLoggedInProblem = new LLFailedLoginResponse("presence", 83 AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
79 "You appear to be already logged in. " + 84 "You appear to be already logged in. " +
80 "If this is not the case please wait for your session to timeout. " + 85 "If this is not the case please wait for your session to timeout. " +
@@ -145,6 +150,7 @@ namespace OpenSim.Services.LLLoginService
145 private UUID agentID; 150 private UUID agentID;
146 private UUID sessionID; 151 private UUID sessionID;
147 private UUID secureSessionID; 152 private UUID secureSessionID;
153 private UUID realID;
148 154
149 // Login Flags 155 // Login Flags
150 private string dst; 156 private string dst;
@@ -228,8 +234,13 @@ namespace OpenSim.Services.LLLoginService
228 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo, 234 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo,
229 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService, 235 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
230 string where, string startlocation, Vector3 position, Vector3 lookAt, List<InventoryItemBase> gestures, string message, 236 string where, string startlocation, Vector3 position, Vector3 lookAt, List<InventoryItemBase> gestures, string message,
237<<<<<<< HEAD
231 GridRegion home, IPEndPoint clientIP, string mapTileURL, string searchURL, string currency, 238 GridRegion home, IPEndPoint clientIP, string mapTileURL, string searchURL, string currency,
232 string DSTZone, string destinationsURL, string avatarsURL, string classifiedFee, int maxAgentGroups) 239 string DSTZone, string destinationsURL, string avatarsURL, string classifiedFee, int maxAgentGroups)
240=======
241 GridRegion home, IPEndPoint clientIP, string mapTileURL, string profileURL, string openIDURL, string searchURL, string currency,
242 string DSTZone, string destinationsURL, string avatarsURL, UUID realID, string classifiedFee)
243>>>>>>> avn/ubitvar
233 : this() 244 : this()
234 { 245 {
235 FillOutInventoryData(invSkel, libService); 246 FillOutInventoryData(invSkel, libService);
@@ -242,6 +253,7 @@ namespace OpenSim.Services.LLLoginService
242 AgentID = account.PrincipalID; 253 AgentID = account.PrincipalID;
243 SessionID = aCircuit.SessionID; 254 SessionID = aCircuit.SessionID;
244 SecureSessionID = aCircuit.SecureSessionID; 255 SecureSessionID = aCircuit.SecureSessionID;
256 RealID = realID;
245 Message = message; 257 Message = message;
246 BuddList = ConvertFriendListItem(friendsList); 258 BuddList = ConvertFriendListItem(friendsList);
247 StartLocation = where; 259 StartLocation = where;
@@ -383,6 +395,7 @@ namespace OpenSim.Services.LLLoginService
383 private void FillOutRegionData(GridRegion destination) 395 private void FillOutRegionData(GridRegion destination)
384 { 396 {
385 IPEndPoint endPoint = destination.ExternalEndPoint; 397 IPEndPoint endPoint = destination.ExternalEndPoint;
398 if (endPoint == null) return;
386 SimAddress = endPoint.Address.ToString(); 399 SimAddress = endPoint.Address.ToString();
387 SimPort = (uint)endPoint.Port; 400 SimPort = (uint)endPoint.Port;
388 RegionX = (uint)destination.RegionLocX; 401 RegionX = (uint)destination.RegionLocX;
@@ -473,6 +486,7 @@ namespace OpenSim.Services.LLLoginService
473 SessionID = UUID.Random(); 486 SessionID = UUID.Random();
474 SecureSessionID = UUID.Random(); 487 SecureSessionID = UUID.Random();
475 AgentID = UUID.Random(); 488 AgentID = UUID.Random();
489 RealID = UUID.Zero;
476 490
477 Hashtable InitialOutfitHash = new Hashtable(); 491 Hashtable InitialOutfitHash = new Hashtable();
478 InitialOutfitHash["folder_name"] = "Nightclub Female"; 492 InitialOutfitHash["folder_name"] = "Nightclub Female";
@@ -518,6 +532,7 @@ namespace OpenSim.Services.LLLoginService
518 responseData["http_port"] = (Int32)SimHttpPort; 532 responseData["http_port"] = (Int32)SimHttpPort;
519 533
520 responseData["agent_id"] = AgentID.ToString(); 534 responseData["agent_id"] = AgentID.ToString();
535 responseData["real_id"] = RealID.ToString();
521 responseData["session_id"] = SessionID.ToString(); 536 responseData["session_id"] = SessionID.ToString();
522 responseData["secure_session_id"] = SecureSessionID.ToString(); 537 responseData["secure_session_id"] = SecureSessionID.ToString();
523 responseData["circuit_code"] = CircuitCode; 538 responseData["circuit_code"] = CircuitCode;
@@ -613,6 +628,7 @@ namespace OpenSim.Services.LLLoginService
613 map["sim_ip"] = OSD.FromString(SimAddress); 628 map["sim_ip"] = OSD.FromString(SimAddress);
614 629
615 map["agent_id"] = OSD.FromUUID(AgentID); 630 map["agent_id"] = OSD.FromUUID(AgentID);
631 map["real_id"] = OSD.FromUUID(RealID);
616 map["session_id"] = OSD.FromUUID(SessionID); 632 map["session_id"] = OSD.FromUUID(SessionID);
617 map["secure_session_id"] = OSD.FromUUID(SecureSessionID); 633 map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
618 map["circuit_code"] = OSD.FromInteger(CircuitCode); 634 map["circuit_code"] = OSD.FromInteger(CircuitCode);
@@ -924,6 +940,12 @@ namespace OpenSim.Services.LLLoginService
924 set { secureSessionID = value; } 940 set { secureSessionID = value; }
925 } 941 }
926 942
943 public UUID RealID
944 {
945 get { return realID; }
946 set { realID = value; }
947 }
948
927 public Int32 CircuitCode 949 public Int32 CircuitCode
928 { 950 {
929 get { return circuitCode; } 951 get { return circuitCode; }
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index d67bc4d..ba69e95 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -151,7 +151,8 @@ namespace OpenSim.Services.LLLoginService
151 Object[] args = new Object[] { config }; 151 Object[] args = new Object[] { config };
152 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); 152 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
153 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args); 153 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
154 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); 154 Object[] authArgs = new Object[] { config, m_UserAccountService };
155 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, authArgs);
155 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args); 156 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
156 157
157 if (gridService != string.Empty) 158 if (gridService != string.Empty)
@@ -257,14 +258,20 @@ namespace OpenSim.Services.LLLoginService
257 } 258 }
258 259
259 public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID, 260 public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID,
260 string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP) 261 string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP, bool LibOMVclient)
261 { 262 {
262 bool success = false; 263 bool success = false;
263 UUID session = UUID.Random(); 264 UUID session = UUID.Random();
265<<<<<<< HEAD
264 string processedMessage; 266 string processedMessage;
267=======
268 if (clientVersion.Contains("Radegast"))
269 LibOMVclient = false;
270>>>>>>> avn/ubitvar
265 271
266 m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}", 272
267 firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0); 273 m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}, Possible LibOMVGridProxy: {8} ",
274 firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0, LibOMVclient.ToString());
268 275
269 try 276 try
270 { 277 {
@@ -310,6 +317,12 @@ namespace OpenSim.Services.LLLoginService
310 return LLFailedLoginResponse.UserProblem; 317 return LLFailedLoginResponse.UserProblem;
311 } 318 }
312 319
320 if (account.UserLevel < 0)
321 {
322 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: Unverified account");
323 return LLFailedLoginResponse.UnverifiedAccountProblem;
324 }
325
313 if (account.UserLevel < m_MinLoginLevel) 326 if (account.UserLevel < m_MinLoginLevel)
314 { 327 {
315 m_log.InfoFormat( 328 m_log.InfoFormat(
@@ -341,7 +354,8 @@ namespace OpenSim.Services.LLLoginService
341 if (!passwd.StartsWith("$1$")) 354 if (!passwd.StartsWith("$1$"))
342 passwd = "$1$" + Util.Md5Hash(passwd); 355 passwd = "$1$" + Util.Md5Hash(passwd);
343 passwd = passwd.Remove(0, 3); //remove $1$ 356 passwd = passwd.Remove(0, 3); //remove $1$
344 string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); 357 UUID realID;
358 string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30, out realID);
345 UUID secureSession = UUID.Zero; 359 UUID secureSession = UUID.Zero;
346 if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) 360 if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
347 { 361 {
@@ -508,11 +522,19 @@ namespace OpenSim.Services.LLLoginService
508 processedMessage = processedMessage.Replace("\\n", "\n").Replace("<USERNAME>", firstName + " " + lastName); 522 processedMessage = processedMessage.Replace("\\n", "\n").Replace("<USERNAME>", firstName + " " + lastName);
509 523
510 LLLoginResponse response 524 LLLoginResponse response
525<<<<<<< HEAD
511 = new LLLoginResponse( 526 = new LLLoginResponse(
512 account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService, 527 account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
513 where, startLocation, position, lookAt, gestures, processedMessage, home, clientIP, 528 where, startLocation, position, lookAt, gestures, processedMessage, home, clientIP,
514 m_MapTileURL, m_SearchURL, m_Currency, m_DSTZone, 529 m_MapTileURL, m_SearchURL, m_Currency, m_DSTZone,
515 m_DestinationGuide, m_AvatarPicker, m_ClassifiedFee, m_MaxAgentGroups); 530 m_DestinationGuide, m_AvatarPicker, m_ClassifiedFee, m_MaxAgentGroups);
531=======
532 = new LLLoginResponse(
533 account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
534 where, startLocation, position, lookAt, gestures, m_WelcomeMessage, home, clientIP,
535 m_MapTileURL, m_ProfileURL, m_OpenIDURL, m_SearchURL, m_Currency, m_DSTZone,
536 m_DestinationGuide, m_AvatarPicker, realID, m_ClassifiedFee);
537>>>>>>> avn/ubitvar
516 538
517 m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}", firstName, lastName); 539 m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}", firstName, lastName);
518 540
diff --git a/OpenSim/Services/MapImageService/MapImageService.cs b/OpenSim/Services/MapImageService/MapImageService.cs
index a816411..fcace3a 100644
--- a/OpenSim/Services/MapImageService/MapImageService.cs
+++ b/OpenSim/Services/MapImageService/MapImageService.cs
@@ -69,6 +69,8 @@ namespace OpenSim.Services.MapImageService
69 private static bool m_Initialized = false; 69 private static bool m_Initialized = false;
70 private static string m_WaterTileFile = string.Empty; 70 private static string m_WaterTileFile = string.Empty;
71 private static Color m_Watercolor = Color.FromArgb(29, 71, 95); 71 private static Color m_Watercolor = Color.FromArgb(29, 71, 95);
72 private static Bitmap m_WaterBitmap = null;
73 private static byte[] m_WaterBytes = null;
72 74
73 public MapImageService(IConfigSource config) 75 public MapImageService(IConfigSource config)
74 { 76 {
@@ -91,6 +93,18 @@ namespace OpenSim.Services.MapImageService
91 Bitmap waterTile = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH); 93 Bitmap waterTile = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH);
92 FillImage(waterTile, m_Watercolor); 94 FillImage(waterTile, m_Watercolor);
93 waterTile.Save(m_WaterTileFile, ImageFormat.Jpeg); 95 waterTile.Save(m_WaterTileFile, ImageFormat.Jpeg);
96 m_WaterBitmap = waterTile;
97 }
98
99 if (File.Exists(m_WaterTileFile))
100 {
101 m_WaterBitmap = new Bitmap(m_WaterTileFile);
102 using (MemoryStream ms = new MemoryStream())
103 {
104 m_WaterBitmap.Save(ms,ImageFormat.Jpeg);
105 ms.Seek(0, SeekOrigin.Begin);
106 m_WaterBytes = ms.ToArray();
107 }
94 } 108 }
95 } 109 }
96 } 110 }
@@ -98,10 +112,10 @@ namespace OpenSim.Services.MapImageService
98 112
99 #region IMapImageService 113 #region IMapImageService
100 114
101 public bool AddMapTile(int x, int y, byte[] imageData, out string reason) 115 public bool AddMapTile(int x, int y, byte[] imageData, UUID scopeID, out string reason)
102 { 116 {
103 reason = string.Empty; 117 reason = string.Empty;
104 string fileName = GetFileName(1, x, y); 118 string fileName = GetFileName(1, x, y, scopeID);
105 119
106 lock (m_Sync) 120 lock (m_Sync)
107 { 121 {
@@ -117,6 +131,7 @@ namespace OpenSim.Services.MapImageService
117 return false; 131 return false;
118 } 132 }
119 } 133 }
134<<<<<<< HEAD
120 135
121 return UpdateMultiResolutionFilesAsync(x, y, out reason); 136 return UpdateMultiResolutionFilesAsync(x, y, out reason);
122 } 137 }
@@ -125,24 +140,49 @@ namespace OpenSim.Services.MapImageService
125 { 140 {
126 reason = String.Empty; 141 reason = String.Empty;
127 string fileName = GetFileName(1, x, y); 142 string fileName = GetFileName(1, x, y);
143=======
144
145 return UpdateMultiResolutionFiles(x, y, scopeID, out reason);
146 }
147
148 public bool RemoveMapTile(int x, int y, UUID scopeID, out string reason)
149 {
150 reason = String.Empty;
151 string fileName = GetFileName(1, x, y, scopeID);
152>>>>>>> avn/ubitvar
128 153
129 lock (m_Sync) 154 lock (m_Sync)
130 { 155 {
131 try 156 try
157<<<<<<< HEAD
132 { 158 {
133 File.Delete(fileName); 159 File.Delete(fileName);
134 } 160 }
135 catch (Exception e) 161 catch (Exception e)
136 { 162 {
163=======
164 {
165 File.Delete(fileName);
166 }
167 catch (Exception e)
168 {
169>>>>>>> avn/ubitvar
137 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to save delete file {0}: {1}", fileName, e); 170 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to save delete file {0}: {1}", fileName, e);
138 reason = e.Message; 171 reason = e.Message;
139 return false; 172 return false;
140 } 173 }
141 } 174 }
175<<<<<<< HEAD
142 176
143 return UpdateMultiResolutionFilesAsync(x, y, out reason); 177 return UpdateMultiResolutionFilesAsync(x, y, out reason);
144 } 178 }
145 179
180=======
181
182 return UpdateMultiResolutionFiles(x, y, scopeID, out reason);
183 }
184
185>>>>>>> avn/ubitvar
146 // When large varregions start up, they can send piles of new map tiles. This causes 186 // When large varregions start up, they can send piles of new map tiles. This causes
147 // this multi-resolution routine to be called a zillion times an causes much CPU 187 // this multi-resolution routine to be called a zillion times an causes much CPU
148 // time to be spent creating multi-resolution tiles that will be replaced when 188 // time to be spent creating multi-resolution tiles that will be replaced when
@@ -151,6 +191,7 @@ namespace OpenSim.Services.MapImageService
151 { 191 {
152 public int xx; 192 public int xx;
153 public int yy; 193 public int yy;
194<<<<<<< HEAD
154 public mapToMultiRez(int pX, int pY) 195 public mapToMultiRez(int pX, int pY)
155 { 196 {
156 xx = pX; 197 xx = pX;
@@ -168,6 +209,29 @@ namespace OpenSim.Services.MapImageService
168 if (multiRezToBuild.Count == 1) 209 if (multiRezToBuild.Count == 1)
169 Util.FireAndForget( 210 Util.FireAndForget(
170 DoUpdateMultiResolutionFilesAsync, null, "MapImageService.DoUpdateMultiResolutionFilesAsync"); 211 DoUpdateMultiResolutionFilesAsync, null, "MapImageService.DoUpdateMultiResolutionFilesAsync");
212=======
213 public UUID scopeID;
214 public mapToMultiRez(int pX, int pY, UUID pscopeID)
215 {
216 xx = pX;
217 yy = pY;
218 scopeID = pscopeID;
219 }
220 };
221 private Queue<mapToMultiRez> multiRezToBuild = new Queue<mapToMultiRez>();
222
223 private bool UpdateMultiResolutionFiles(int x, int y, UUID scopeID, out string reason)
224 {
225 reason = String.Empty;
226
227 lock (multiRezToBuild)
228 {
229 // m_log.DebugFormat("{0} UpdateMultiResolutionFilesAsync: scheduling update for <{1},{2}>", LogHeader, x, y);
230 multiRezToBuild.Enqueue(new mapToMultiRez(x, y, scopeID));
231 if (multiRezToBuild.Count == 1)
232 Util.FireAndForget(
233 DoUpdateMultiResolutionFilesAsync);
234>>>>>>> avn/ubitvar
171 } 235 }
172 236
173 return true; 237 return true;
@@ -175,10 +239,15 @@ namespace OpenSim.Services.MapImageService
175 239
176 private void DoUpdateMultiResolutionFilesAsync(object o) 240 private void DoUpdateMultiResolutionFilesAsync(object o)
177 { 241 {
242<<<<<<< HEAD
178 // This sleep causes the FireAndForget thread to be different than the invocation thread. 243 // This sleep causes the FireAndForget thread to be different than the invocation thread.
179 // It also allows other tiles to be uploaded so the multi-rez images are more likely 244 // It also allows other tiles to be uploaded so the multi-rez images are more likely
180 // to be correct. 245 // to be correct.
181 Thread.Sleep(1 * 1000); 246 Thread.Sleep(1 * 1000);
247=======
248 // let acumulate large region tiles
249 Thread.Sleep(60 * 1000); // large regions take time to upload tiles
250>>>>>>> avn/ubitvar
182 251
183 while (multiRezToBuild.Count > 0) 252 while (multiRezToBuild.Count > 0)
184 { 253 {
@@ -192,20 +261,35 @@ namespace OpenSim.Services.MapImageService
192 { 261 {
193 int x = toMultiRez.xx; 262 int x = toMultiRez.xx;
194 int y = toMultiRez.yy; 263 int y = toMultiRez.yy;
264<<<<<<< HEAD
265 // m_log.DebugFormat("{0} DoUpdateMultiResolutionFilesAsync: doing build for <{1},{2}>", LogHeader, x, y);
266
267=======
268 UUID scopeID = toMultiRez.scopeID;
195 // m_log.DebugFormat("{0} DoUpdateMultiResolutionFilesAsync: doing build for <{1},{2}>", LogHeader, x, y); 269 // m_log.DebugFormat("{0} DoUpdateMultiResolutionFilesAsync: doing build for <{1},{2}>", LogHeader, x, y);
196 270
271 int width = 1;
272>>>>>>> avn/ubitvar
197 // Stitch seven more aggregate tiles together 273 // Stitch seven more aggregate tiles together
198 for (uint zoomLevel = 2; zoomLevel <= ZOOM_LEVELS; zoomLevel++) 274 for (uint zoomLevel = 2; zoomLevel <= ZOOM_LEVELS; zoomLevel++)
199 { 275 {
200 // Calculate the width (in full resolution tiles) and bottom-left 276 // Calculate the width (in full resolution tiles) and bottom-left
201 // corner of the current zoom level 277 // corner of the current zoom level
278<<<<<<< HEAD
202 int width = (int)Math.Pow(2, (double)(zoomLevel - 1)); 279 int width = (int)Math.Pow(2, (double)(zoomLevel - 1));
280=======
281 width *= 2;
282>>>>>>> avn/ubitvar
203 int x1 = x - (x % width); 283 int x1 = x - (x % width);
204 int y1 = y - (y % width); 284 int y1 = y - (y % width);
205 285
206 lock (m_Sync) // must lock the reading and writing of the maptile files 286 lock (m_Sync) // must lock the reading and writing of the maptile files
207 { 287 {
288<<<<<<< HEAD
208 if (!CreateTile(zoomLevel, x1, y1)) 289 if (!CreateTile(zoomLevel, x1, y1))
290=======
291 if (!CreateTile(zoomLevel, x1, y1, scopeID))
292>>>>>>> avn/ubitvar
209 { 293 {
210 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to create tile for {0},{1} at zoom level {1}", x, y, zoomLevel); 294 m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to create tile for {0},{1} at zoom level {1}", x, y, zoomLevel);
211 return; 295 return;
@@ -214,25 +298,29 @@ namespace OpenSim.Services.MapImageService
214 } 298 }
215 } 299 }
216 } 300 }
301<<<<<<< HEAD
217 302
303=======
304>>>>>>> avn/ubitvar
218 return; 305 return;
219 } 306 }
220 307
221 public byte[] GetMapTile(string fileName, out string format) 308 public byte[] GetMapTile(string fileName, UUID scopeID, out string format)
222 { 309 {
223// m_log.DebugFormat("[MAP IMAGE SERVICE]: Getting map tile {0}", fileName); 310// m_log.DebugFormat("[MAP IMAGE SERVICE]: Getting map tile {0}", fileName);
224 311
225 format = ".jpg"; 312 format = ".jpg";
226 string fullName = Path.Combine(m_TilesStoragePath, fileName); 313 string fullName = Path.Combine(m_TilesStoragePath, scopeID.ToString());
314 fullName = Path.Combine(fullName, fileName);
227 if (File.Exists(fullName)) 315 if (File.Exists(fullName))
228 { 316 {
229 format = Path.GetExtension(fileName).ToLower(); 317 format = Path.GetExtension(fileName).ToLower();
230 //m_log.DebugFormat("[MAP IMAGE SERVICE]: Found file {0}, extension {1}", fileName, format); 318 //m_log.DebugFormat("[MAP IMAGE SERVICE]: Found file {0}, extension {1}", fileName, format);
231 return File.ReadAllBytes(fullName); 319 return File.ReadAllBytes(fullName);
232 } 320 }
233 else if (File.Exists(m_WaterTileFile)) 321 else if (m_WaterBytes != null)
234 { 322 {
235 return File.ReadAllBytes(m_WaterTileFile); 323 return (byte[])m_WaterBytes.Clone();
236 } 324 }
237 else 325 else
238 { 326 {
@@ -244,10 +332,12 @@ namespace OpenSim.Services.MapImageService
244 #endregion 332 #endregion
245 333
246 334
247 private string GetFileName(uint zoomLevel, int x, int y) 335 private string GetFileName(uint zoomLevel, int x, int y, UUID scopeID)
248 { 336 {
249 string extension = "jpg"; 337 string extension = "jpg";
250 return Path.Combine(m_TilesStoragePath, string.Format("map-{0}-{1}-{2}-objects.{3}", zoomLevel, x, y, extension)); 338 string path = Path.Combine(m_TilesStoragePath, scopeID.ToString());
339 Directory.CreateDirectory(path);
340 return Path.Combine(path, string.Format("map-{0}-{1}-{2}-objects.{3}", zoomLevel, x, y, extension));
251 } 341 }
252 342
253 private Bitmap GetInputTileImage(string fileName) 343 private Bitmap GetInputTileImage(string fileName)
@@ -276,7 +366,7 @@ namespace OpenSim.Services.MapImageService
276 { 366 {
277 // Create a new output tile with a transparent background 367 // Create a new output tile with a transparent background
278 Bitmap bm = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH, PixelFormat.Format24bppRgb); 368 Bitmap bm = new Bitmap(IMAGE_WIDTH, IMAGE_WIDTH, PixelFormat.Format24bppRgb);
279 bm.MakeTransparent(); 369 //bm.MakeTransparent(); // 24bpp does not have transparency, this whould make it 32bpp
280 return bm; 370 return bm;
281 } 371 }
282 } 372 }
@@ -288,7 +378,7 @@ namespace OpenSim.Services.MapImageService
288 return null; 378 return null;
289 } 379 }
290 380
291 private bool CreateTile(uint zoomLevel, int x, int y) 381 private bool CreateTile(uint zoomLevel, int x, int y, UUID scopeID)
292 { 382 {
293// m_log.DebugFormat("[MAP IMAGE SERVICE]: Create tile for {0} {1}, zoom {2}", x, y, zoomLevel); 383// m_log.DebugFormat("[MAP IMAGE SERVICE]: Create tile for {0} {1}, zoom {2}", x, y, zoomLevel);
294 int prevWidth = (int)Math.Pow(2, (double)zoomLevel - 2); 384 int prevWidth = (int)Math.Pow(2, (double)zoomLevel - 2);
@@ -303,55 +393,60 @@ namespace OpenSim.Services.MapImageService
303 int yOut = y - (y % thisWidth); 393 int yOut = y - (y % thisWidth);
304 394
305 // Try to open the four input tiles from the previous zoom level 395 // Try to open the four input tiles from the previous zoom level
306 Bitmap inputBL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn)); 396 Bitmap inputBL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn, scopeID));
307 Bitmap inputBR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn)); 397 Bitmap inputBR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn, scopeID));
308 Bitmap inputTL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn + prevWidth)); 398 Bitmap inputTL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn + prevWidth, scopeID));
309 Bitmap inputTR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn + prevWidth)); 399 Bitmap inputTR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn + prevWidth, scopeID));
310 400
311 // Open the output tile (current zoom level) 401 // Open the output tile (current zoom level)
312 string outputFile = GetFileName(zoomLevel, xOut, yOut); 402 string outputFile = GetFileName(zoomLevel, xOut, yOut, scopeID);
313 Bitmap output = GetOutputTileImage(outputFile); 403
314 if (output == null) 404 int ntiles = 0;
315 return false; 405 Bitmap output = (Bitmap)m_WaterBitmap.Clone();
316 FillImage(output, m_Watercolor);
317 406
318 if (inputBL != null) 407 if (inputBL != null)
319 { 408 {
320 ImageCopyResampled(output, inputBL, 0, HALF_WIDTH, 0, 0); 409 ImageCopyResampled(output, inputBL, 0, HALF_WIDTH, 0, 0);
321 inputBL.Dispose(); 410 inputBL.Dispose();
411 ntiles++;
322 } 412 }
323 if (inputBR != null) 413 if (inputBR != null)
324 { 414 {
325 ImageCopyResampled(output, inputBR, HALF_WIDTH, HALF_WIDTH, 0, 0); 415 ImageCopyResampled(output, inputBR, HALF_WIDTH, HALF_WIDTH, 0, 0);
326 inputBR.Dispose(); 416 inputBR.Dispose();
417 ntiles++;
327 } 418 }
328 if (inputTL != null) 419 if (inputTL != null)
329 { 420 {
330 ImageCopyResampled(output, inputTL, 0, 0, 0, 0); 421 ImageCopyResampled(output, inputTL, 0, 0, 0, 0);
331 inputTL.Dispose(); 422 inputTL.Dispose();
423 ntiles++;
332 } 424 }
333 if (inputTR != null) 425 if (inputTR != null)
334 { 426 {
335 ImageCopyResampled(output, inputTR, HALF_WIDTH, 0, 0, 0); 427 ImageCopyResampled(output, inputTR, HALF_WIDTH, 0, 0, 0);
336 inputTR.Dispose(); 428 inputTR.Dispose();
429 ntiles++;
337 } 430 }
338 431
339 // Write the modified output 432 // Write the modified output
340 try 433 if (ntiles == 0)
434 File.Delete(outputFile);
435
436 else
341 { 437 {
342 using (Bitmap final = new Bitmap(output)) 438
439 try
343 { 440 {
344 output.Dispose(); 441 output.Save(outputFile, ImageFormat.Jpeg);
345 final.Save(outputFile, ImageFormat.Jpeg);
346 } 442 }
347 } 443 catch (Exception e)
348 catch (Exception e) 444 {
349 { 445 m_log.WarnFormat("[MAP IMAGE SERVICE]: Oops on saving {0} {1}", outputFile, e);
350 m_log.WarnFormat("[MAP IMAGE SERVICE]: Oops on saving {0} {1}", outputFile, e); 446 }
351 } 447 } // Save also as png?
352
353 // Save also as png?
354 448
449 output.Dispose();
355 return true; 450 return true;
356 } 451 }
357 452
diff --git a/OpenSim/Services/SimulationService/SimulationDataService.cs b/OpenSim/Services/SimulationService/SimulationDataService.cs
index d9684c4..7a544fa 100644
--- a/OpenSim/Services/SimulationService/SimulationDataService.cs
+++ b/OpenSim/Services/SimulationService/SimulationDataService.cs
@@ -173,6 +173,11 @@ namespace OpenSim.Services.SimulationService
173 m_database.RemoveRegionEnvironmentSettings(regionUUID); 173 m_database.RemoveRegionEnvironmentSettings(regionUUID);
174 } 174 }
175 175
176 public UUID[] GetObjectIDs(UUID regionID)
177 {
178 return m_database.GetObjectIDs(regionID);
179 }
180
176 public void SaveExtra(UUID regionID, string name, string val) 181 public void SaveExtra(UUID regionID, string name, string val)
177 { 182 {
178 m_database.SaveExtra(regionID, name, val); 183 m_database.SaveExtra(regionID, name, val);
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs
index 2e19ece..987a07d 100644
--- a/OpenSim/Services/UserAccountService/UserAccountService.cs
+++ b/OpenSim/Services/UserAccountService/UserAccountService.cs
@@ -176,6 +176,10 @@ namespace OpenSim.Services.UserAccountService
176 Int32.TryParse(d.Data["UserLevel"], out u.UserLevel); 176 Int32.TryParse(d.Data["UserLevel"], out u.UserLevel);
177 if (d.Data.ContainsKey("UserFlags") && d.Data["UserFlags"] != null) 177 if (d.Data.ContainsKey("UserFlags") && d.Data["UserFlags"] != null)
178 Int32.TryParse(d.Data["UserFlags"], out u.UserFlags); 178 Int32.TryParse(d.Data["UserFlags"], out u.UserFlags);
179 if (d.Data.ContainsKey("UserCountry") && d.Data["UserCountry"] != null)
180 u.UserCountry = d.Data["UserCountry"].ToString();
181 else
182 u.UserTitle = string.Empty;
179 183
180 if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null) 184 if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null)
181 { 185 {
@@ -301,7 +305,22 @@ namespace OpenSim.Services.UserAccountService
301 305
302 public List<UserAccount> GetUserAccounts(UUID scopeID, string query) 306 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
303 { 307 {
304 UserAccountData[] d = m_Database.GetUsers(scopeID, query); 308 UserAccountData[] d = m_Database.GetUsers(scopeID, query.Trim());
309
310 if (d == null)
311 return new List<UserAccount>();
312
313 List<UserAccount> ret = new List<UserAccount>();
314
315 foreach (UserAccountData data in d)
316 ret.Add(MakeUserAccount(data));
317
318 return ret;
319 }
320
321 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where)
322 {
323 UserAccountData[] d = m_Database.GetUsersWhere(scopeID, where);
305 324
306 if (d == null) 325 if (d == null)
307 return new List<UserAccount>(); 326 return new List<UserAccount>();
diff --git a/OpenSim/Services/UserProfilesService/UserProfilesService.cs b/OpenSim/Services/UserProfilesService/UserProfilesService.cs
index 96c13c0..35fe31b 100644
--- a/OpenSim/Services/UserProfilesService/UserProfilesService.cs
+++ b/OpenSim/Services/UserProfilesService/UserProfilesService.cs
@@ -159,6 +159,7 @@ namespace OpenSim.Services.ProfilesService
159 } 159 }
160 #endregion Interests 160 #endregion Interests
161 161
162 /*
162 #region User Preferences 163 #region User Preferences
163 public bool UserPreferencesUpdate(ref UserPreferences pref, ref string result) 164 public bool UserPreferencesUpdate(ref UserPreferences pref, ref string result)
164 { 165 {
@@ -238,6 +239,7 @@ namespace OpenSim.Services.ProfilesService
238 return true; 239 return true;
239 } 240 }
240 #endregion User Preferences 241 #endregion User Preferences
242 */
241 243
242 #region Utility 244 #region Utility
243 public OSD AvatarImageAssetsRequest(UUID avatarId) 245 public OSD AvatarImageAssetsRequest(UUID avatarId)
diff --git a/OpenSim/Tests/Clients/Grid/GridClient.cs b/OpenSim/Tests/Clients/Grid/GridClient.cs
new file mode 100644
index 0000000..fed7a16
--- /dev/null
+++ b/OpenSim/Tests/Clients/Grid/GridClient.cs
@@ -0,0 +1,205 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.Reflection;
32
33using OpenMetaverse;
34using log4net;
35using log4net.Appender;
36using log4net.Layout;
37
38using OpenSim.Framework;
39using OpenSim.Services.Interfaces;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41using OpenSim.Services.Connectors;
42
43namespace OpenSim.Tests.Clients.GridClient
44{
45 public class GridClient
46 {
47// private static readonly ILog m_log =
48// LogManager.GetLogger(
49// MethodBase.GetCurrentMethod().DeclaringType);
50
51 public static void Main(string[] args)
52 {
53 ConsoleAppender consoleAppender = new ConsoleAppender();
54 consoleAppender.Layout =
55 new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
56 log4net.Config.BasicConfigurator.Configure(consoleAppender);
57
58 string serverURI = "http://127.0.0.1:8001";
59 GridServicesConnector m_Connector = new GridServicesConnector(serverURI);
60
61 GridRegion r1 = CreateRegion("Test Region 1", 1000, 1000);
62 GridRegion r2 = CreateRegion("Test Region 2", 1001, 1000);
63 GridRegion r3 = CreateRegion("Test Region 3", 1005, 1000);
64
65 Console.WriteLine("[GRID CLIENT]: *** Registering region 1");
66 string msg = m_Connector.RegisterRegion(UUID.Zero, r1);
67 if (msg == String.Empty)
68 Console.WriteLine("[GRID CLIENT]: Successfully registered region 1");
69 else
70 Console.WriteLine("[GRID CLIENT]: region 1 failed to register");
71
72 Console.WriteLine("[GRID CLIENT]: *** Registering region 2");
73 msg = m_Connector.RegisterRegion(UUID.Zero, r2);
74 if (msg == String.Empty)
75 Console.WriteLine("[GRID CLIENT]: Successfully registered region 2");
76 else
77 Console.WriteLine("[GRID CLIENT]: region 2 failed to register");
78
79 Console.WriteLine("[GRID CLIENT]: *** Registering region 3");
80 msg = m_Connector.RegisterRegion(UUID.Zero, r3);
81 if (msg == String.Empty)
82 Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
83 else
84 Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
85
86
87 bool success;
88 Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
89 success = m_Connector.DeregisterRegion(r3.RegionID);
90 if (success)
91 Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
92 else
93 Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
94 Console.WriteLine("[GRID CLIENT]: *** Registering region 3 again");
95 msg = m_Connector.RegisterRegion(UUID.Zero, r3);
96 if (msg == String.Empty)
97 Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
98 else
99 Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
100
101 Console.WriteLine("[GRID CLIENT]: *** GetNeighbours of region 1");
102 List<GridRegion> regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID);
103 if (regions == null)
104 Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 failed");
105 else if (regions.Count > 0)
106 {
107 if (regions.Count != 1)
108 Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned more neighbours than expected: " + regions.Count);
109 else
110 Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned the right neighbour " + regions[0].RegionName);
111 }
112 else
113 Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned 0 neighbours");
114
115
116 Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of region 2 (this should succeed)");
117 GridRegion region = m_Connector.GetRegionByUUID(UUID.Zero, r2.RegionID);
118 if (region == null)
119 Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
120 else
121 Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
122
123 Console.WriteLine("[GRID CLIENT]: *** GetRegionByUUID of non-existent region (this should fail)");
124 region = m_Connector.GetRegionByUUID(UUID.Zero, UUID.Random());
125 if (region == null)
126 Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned null");
127 else
128 Console.WriteLine("[GRID CLIENT]: GetRegionByUUID returned region " + region.RegionName);
129
130 Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of region 3 (this should succeed)");
131 region = m_Connector.GetRegionByName(UUID.Zero, r3.RegionName);
132 if (region == null)
133 Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
134 else
135 Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
136
137 Console.WriteLine("[GRID CLIENT]: *** GetRegionByName of non-existent region (this should fail)");
138 region = m_Connector.GetRegionByName(UUID.Zero, "Foo");
139 if (region == null)
140 Console.WriteLine("[GRID CLIENT]: GetRegionByName returned null");
141 else
142 Console.WriteLine("[GRID CLIENT]: GetRegionByName returned region " + region.RegionName);
143
144 Console.WriteLine("[GRID CLIENT]: *** GetRegionsByName (this should return 3 regions)");
145 regions = m_Connector.GetRegionsByName(UUID.Zero, "Test", 10);
146 if (regions == null)
147 Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned null");
148 else
149 Console.WriteLine("[GRID CLIENT]: GetRegionsByName returned " + regions.Count + " regions");
150
151 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 2 regions)");
152 regions = m_Connector.GetRegionRange(UUID.Zero,
153 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002),
154 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002) );
155 if (regions == null)
156 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
157 else
158 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
159 Console.WriteLine("[GRID CLIENT]: *** GetRegionRange (this should return 0 regions)");
160 regions = m_Connector.GetRegionRange(UUID.Zero,
161 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950),
162 (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950) );
163 if (regions == null)
164 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned null");
165 else
166 Console.WriteLine("[GRID CLIENT]: GetRegionRange returned " + regions.Count + " regions");
167
168 Console.Write("Proceed to deregister? Press enter...");
169 Console.ReadLine();
170
171 // Deregister them all
172 Console.WriteLine("[GRID CLIENT]: *** Deregistering region 1");
173 success = m_Connector.DeregisterRegion(r1.RegionID);
174 if (success)
175 Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 1");
176 else
177 Console.WriteLine("[GRID CLIENT]: region 1 failed to deregister");
178 Console.WriteLine("[GRID CLIENT]: *** Deregistering region 2");
179 success = m_Connector.DeregisterRegion(r2.RegionID);
180 if (success)
181 Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 2");
182 else
183 Console.WriteLine("[GRID CLIENT]: region 2 failed to deregister");
184 Console.WriteLine("[GRID CLIENT]: *** Deregistering region 3");
185 success = m_Connector.DeregisterRegion(r3.RegionID);
186 if (success)
187 Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
188 else
189 Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
190
191 }
192
193 private static GridRegion CreateRegion(string name, uint xcell, uint ycell)
194 {
195 GridRegion region = new GridRegion(xcell, ycell);
196 region.RegionName = name;
197 region.RegionID = UUID.Random();
198 region.ExternalHostName = "127.0.0.1";
199 region.HttpPort = 9000;
200 region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 9000);
201
202 return region;
203 }
204 }
205}
diff --git a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
index cf7583e..e6adcf7 100644
--- a/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/EntityTransferHelpers.cs
@@ -120,4 +120,4 @@ namespace OpenSim.Tests.Common
120 }; 120 };
121 } 121 }
122 } 122 }
123} \ No newline at end of file 123}
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
index 1fb1c5c..9ed3eae 100644
--- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -152,13 +152,22 @@ namespace OpenSim.Tests.Common
152 152
153 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); 153 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
154 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); 154 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
155<<<<<<< HEAD
155 Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ); 156 Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
156 PhysicsScene physicsScene 157 PhysicsScene physicsScene
158=======
159 Vector3 regionExtent = new Vector3(regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
160 PhysicsScene physicsScene
161>>>>>>> avn/ubitvar
157 = physicsPluginManager.GetPhysicsScene( 162 = physicsPluginManager.GetPhysicsScene(
158 "basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent); 163 "basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
159 164
160 TestScene testScene = new TestScene( 165 TestScene testScene = new TestScene(
166<<<<<<< HEAD
161 regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null); 167 regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null);
168=======
169 regInfo, m_acm, physicsScene, scs, m_simDataService, m_estateDataService, configSource, null);
170>>>>>>> avn/ubitvar
162 171
163 INonSharedRegionModule godsModule = new GodsModule(); 172 INonSharedRegionModule godsModule = new GodsModule();
164 godsModule.Initialise(new IniConfigSource()); 173 godsModule.Initialise(new IniConfigSource());
@@ -201,7 +210,11 @@ namespace OpenSim.Tests.Common
201 testScene.SetModuleInterfaces(); 210 testScene.SetModuleInterfaces();
202 211
203 testScene.LandChannel = new TestLandChannel(testScene); 212 testScene.LandChannel = new TestLandChannel(testScene);
213<<<<<<< HEAD
204 testScene.LoadWorldMap(); 214 testScene.LoadWorldMap();
215=======
216 testScene.LoadWorldMap();
217>>>>>>> avn/ubitvar
205 218
206 testScene.RegionInfo.EstateSettings = new EstateSettings(); 219 testScene.RegionInfo.EstateSettings = new EstateSettings();
207 testScene.LoginsEnabled = true; 220 testScene.LoginsEnabled = true;
diff --git a/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs b/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs
index dddf75d..aaf61e7 100644
--- a/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs
@@ -54,9 +54,10 @@ namespace OpenSim.Tests.Common
54 return assets.Find(x=>x.FullID == uuid); 54 return assets.Find(x=>x.FullID == uuid);
55 } 55 }
56 56
57 public void StoreAsset(AssetBase asset) 57 public bool StoreAsset(AssetBase asset)
58 { 58 {
59 assets.Add(asset); 59 assets.Add(asset);
60 return true;
60 } 61 }
61 62
62 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); } 63 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); }
diff --git a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
index 5df8e04..3ab9020 100644
--- a/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/MockRegionDataPlugin.cs
@@ -138,6 +138,11 @@ namespace OpenSim.Data.Null
138 m_store.RemoveRegionEnvironmentSettings(regionUUID); 138 m_store.RemoveRegionEnvironmentSettings(regionUUID);
139 } 139 }
140 140
141 public UUID[] GetObjectIDs(UUID regionID)
142 {
143 return new UUID[0];
144 }
145
141 public void SaveExtra(UUID regionID, string name, string value) 146 public void SaveExtra(UUID regionID, string name, string value)
142 { 147 {
143 } 148 }
@@ -355,6 +360,11 @@ namespace OpenSim.Data.Null
355 { 360 {
356 } 361 }
357 362
363 public UUID[] GetObjectIDs(UUID regionID)
364 {
365 return new UUID[0];
366 }
367
358 public void SaveExtra(UUID regionID, string name, string value) 368 public void SaveExtra(UUID regionID, string name, string value)
359 { 369 {
360 } 370 }
diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs
index 0e1bc8f..f034443 100644
--- a/OpenSim/Tests/Common/Mock/TestClient.cs
+++ b/OpenSim/Tests/Common/Mock/TestClient.cs
@@ -88,7 +88,7 @@ namespace OpenSim.Tests.Common
88 public event MoneyTransferRequest OnMoneyTransferRequest; 88 public event MoneyTransferRequest OnMoneyTransferRequest;
89 public event ParcelBuy OnParcelBuy; 89 public event ParcelBuy OnParcelBuy;
90 public event Action<IClientAPI> OnConnectionClosed; 90 public event Action<IClientAPI> OnConnectionClosed;
91 91 public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
92 public event ImprovedInstantMessage OnInstantMessage; 92 public event ImprovedInstantMessage OnInstantMessage;
93 public event ChatMessage OnChatFromClient; 93 public event ChatMessage OnChatFromClient;
94 public event TextureRequest OnRequestTexture; 94 public event TextureRequest OnRequestTexture;
@@ -105,6 +105,7 @@ namespace OpenSim.Tests.Common
105 public event ObjectDrop OnObjectDrop; 105 public event ObjectDrop OnObjectDrop;
106 public event StartAnim OnStartAnim; 106 public event StartAnim OnStartAnim;
107 public event StopAnim OnStopAnim; 107 public event StopAnim OnStopAnim;
108 public event ChangeAnim OnChangeAnim;
108 public event LinkObjects OnLinkObjects; 109 public event LinkObjects OnLinkObjects;
109 public event DelinkObjects OnDelinkObjects; 110 public event DelinkObjects OnDelinkObjects;
110 public event RequestMapBlocks OnRequestMapBlocks; 111 public event RequestMapBlocks OnRequestMapBlocks;
@@ -153,6 +154,7 @@ namespace OpenSim.Tests.Common
153 public event GenericCall7 OnObjectMaterial; 154 public event GenericCall7 OnObjectMaterial;
154 public event UpdatePrimFlags OnUpdatePrimFlags; 155 public event UpdatePrimFlags OnUpdatePrimFlags;
155 public event UpdatePrimTexture OnUpdatePrimTexture; 156 public event UpdatePrimTexture OnUpdatePrimTexture;
157 public event ClientChangeObject onClientChangeObject;
156 public event UpdateVector OnUpdatePrimGroupPosition; 158 public event UpdateVector OnUpdatePrimGroupPosition;
157 public event UpdateVector OnUpdatePrimSinglePosition; 159 public event UpdateVector OnUpdatePrimSinglePosition;
158 public event UpdatePrimRotation OnUpdatePrimGroupRotation; 160 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
@@ -295,7 +297,7 @@ namespace OpenSim.Tests.Common
295 public event ClassifiedInfoRequest OnClassifiedInfoRequest; 297 public event ClassifiedInfoRequest OnClassifiedInfoRequest;
296 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; 298 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
297 public event ClassifiedDelete OnClassifiedDelete; 299 public event ClassifiedDelete OnClassifiedDelete;
298 public event ClassifiedDelete OnClassifiedGodDelete; 300 public event ClassifiedGodDelete OnClassifiedGodDelete;
299 301
300 public event EventNotificationAddRequest OnEventNotificationAddRequest; 302 public event EventNotificationAddRequest OnEventNotificationAddRequest;
301 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; 303 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
@@ -334,11 +336,12 @@ namespace OpenSim.Tests.Common
334 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; 336 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
335 public event SimWideDeletesDelegate OnSimWideDeletes; 337 public event SimWideDeletesDelegate OnSimWideDeletes;
336 public event SendPostcard OnSendPostcard; 338 public event SendPostcard OnSendPostcard;
339 public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
337 public event MuteListEntryUpdate OnUpdateMuteListEntry; 340 public event MuteListEntryUpdate OnUpdateMuteListEntry;
338 public event MuteListEntryRemove OnRemoveMuteListEntry; 341 public event MuteListEntryRemove OnRemoveMuteListEntry;
339 public event GodlikeMessage onGodlikeMessage; 342 public event GodlikeMessage onGodlikeMessage;
340 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 343 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
341 344 public event GenericCall2 OnUpdateThrottles;
342#pragma warning restore 67 345#pragma warning restore 67
343 346
344 /// <value> 347 /// <value>
@@ -387,6 +390,8 @@ namespace OpenSim.Tests.Common
387 get { return FirstName + " " + LastName; } 390 get { return FirstName + " " + LastName; }
388 } 391 }
389 392
393 public int PingTimeMS { get { return 0; } }
394
390 public bool IsActive 395 public bool IsActive
391 { 396 {
392 get { return true; } 397 get { return true; }
@@ -448,6 +453,8 @@ namespace OpenSim.Tests.Common
448 get { return new IPEndPoint(IPAddress.Loopback, (ushort)m_circuitCode); } 453 get { return new IPEndPoint(IPAddress.Loopback, (ushort)m_circuitCode); }
449 } 454 }
450 455
456 public List<uint> SelectedObjects {get; private set;}
457
451 /// <summary> 458 /// <summary>
452 /// Constructor 459 /// Constructor
453 /// </summary> 460 /// </summary>
@@ -570,10 +577,27 @@ namespace OpenSim.Tests.Common
570 ReceivedKills.AddRange(localID); 577 ReceivedKills.AddRange(localID);
571 } 578 }
572 579
580 public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
581 {
582 }
583
573 public virtual void SetChildAgentThrottle(byte[] throttle) 584 public virtual void SetChildAgentThrottle(byte[] throttle)
574 { 585 {
575 } 586 }
576 587
588 public virtual void SetChildAgentThrottle(byte[] throttle, float factor)
589 {
590 }
591
592 public void SetAgentThrottleSilent(int throttle, int setting)
593 {
594 }
595
596 public int GetAgentThrottleSilent(int throttle)
597 {
598 return 0;
599 }
600
577 public byte[] GetThrottlesPacked(float multiplier) 601 public byte[] GetThrottlesPacked(float multiplier)
578 { 602 {
579 return new byte[0]; 603 return new byte[0];
@@ -608,6 +632,11 @@ namespace OpenSim.Tests.Common
608 632
609 } 633 }
610 634
635 public virtual bool CanSendLayerData()
636 {
637 return false;
638 }
639
611 public virtual void SendLayerData(float[] map) 640 public virtual void SendLayerData(float[] map)
612 { 641 {
613 } 642 }
@@ -755,6 +784,10 @@ namespace OpenSim.Tests.Common
755 { 784 {
756 } 785 }
757 786
787 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
788 {
789 }
790
758 public virtual void SendRemoveInventoryItem(UUID itemID) 791 public virtual void SendRemoveInventoryItem(UUID itemID)
759 { 792 {
760 } 793 }
@@ -771,7 +804,7 @@ namespace OpenSim.Tests.Common
771 { 804 {
772 } 805 }
773 806
774 public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data) 807 public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory)
775 { 808 {
776 } 809 }
777 810
@@ -966,10 +999,10 @@ namespace OpenSim.Tests.Common
966 999
967 public void Close() 1000 public void Close()
968 { 1001 {
969 Close(false); 1002 Close(true, false);
970 } 1003 }
971 1004
972 public void Close(bool force) 1005 public void Close(bool sendStop, bool force)
973 { 1006 {
974 // Fire the callback for this connection closing 1007 // Fire the callback for this connection closing
975 // This is necesary to get the presence detector to notice that a client has logged out. 1008 // This is necesary to get the presence detector to notice that a client has logged out.
@@ -1318,6 +1351,5 @@ namespace OpenSim.Tests.Common
1318 public void SendPartPhysicsProprieties(ISceneEntity entity) 1351 public void SendPartPhysicsProprieties(ISceneEntity entity)
1319 { 1352 {
1320 } 1353 }
1321
1322 } 1354 }
1323} 1355}
diff --git a/OpenSim/Tests/Common/Mock/TestLandChannel.cs b/OpenSim/Tests/Common/Mock/TestLandChannel.cs
index 89ebcd5..23258ad 100644
--- a/OpenSim/Tests/Common/Mock/TestLandChannel.cs
+++ b/OpenSim/Tests/Common/Mock/TestLandChannel.cs
@@ -111,5 +111,6 @@ namespace OpenSim.Tests.Common
111 111
112 public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id) {} 112 public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id) {}
113 public void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id) {} 113 public void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id) {}
114 public void sendClientInitialLandInfo(IClientAPI remoteClient) { }
114 } 115 }
115} \ No newline at end of file 116} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestScene.cs b/OpenSim/Tests/Common/Mock/TestScene.cs
index 45acf91..e559871 100644
--- a/OpenSim/Tests/Common/Mock/TestScene.cs
+++ b/OpenSim/Tests/Common/Mock/TestScene.cs
@@ -34,7 +34,10 @@ using OpenSim.Region.Framework;
34using OpenSim.Region.Framework.Interfaces; 34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.Physics.Manager; 36using OpenSim.Region.Physics.Manager;
37<<<<<<< HEAD
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
39=======
40>>>>>>> avn/ubitvar
38 41
39namespace OpenSim.Tests.Common 42namespace OpenSim.Tests.Common
40{ 43{
diff --git a/OpenSim/Tests/Performance/NPCPerformanceTests.cs b/OpenSim/Tests/Performance/NPCPerformanceTests.cs
index e222dc2..747c992 100644
--- a/OpenSim/Tests/Performance/NPCPerformanceTests.cs
+++ b/OpenSim/Tests/Performance/NPCPerformanceTests.cs
@@ -143,8 +143,7 @@ namespace OpenSim.Tests.Performance
143 // ScenePresence.SendInitialData() to reset our entire appearance. 143 // ScenePresence.SendInitialData() to reset our entire appearance.
144 scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); 144 scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));
145 145
146/* 146 afm.SetAppearance(sp, originalTe, null, new WearableCacheItem[0]);
147 afm.SetAppearance(sp, originalTe, null);
148 147
149 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 148 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
150 149
@@ -185,7 +184,6 @@ namespace OpenSim.Tests.Performance
185 endGcMemory / 1024 / 1024, 184 endGcMemory / 1024 / 1024,
186 startGcMemory / 1024 / 1024, 185 startGcMemory / 1024 / 1024,
187 (endGcMemory - startGcMemory) / 1024 / 1024); 186 (endGcMemory - startGcMemory) / 1024 / 1024);
188*/
189 } 187 }
190 } 188 }
191} 189}
diff --git a/bin/MsgPack.dll b/bin/MsgPack.dll
new file mode 100755
index 0000000..90e6b7b
--- /dev/null
+++ b/bin/MsgPack.dll
Binary files differ
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index 71e76db..8df81cf 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -142,10 +142,6 @@
142 ;; from the selected region_info_source. 142 ;; from the selected region_info_source.
143 ; allow_regionless = false 143 ; allow_regionless = false
144 144
145 ;# {MaxPrimUndos} {} {Maximum number of undos avialable for position, rotation and scale changes of each prim} {} 20
146 ;; Increasing the number of undos available number will increase memory usage.
147 MaxPrimUndos = 20
148
149 ;# {NonPhysicalPrimMin} {} {Minimum size of nonphysical prims?} {} 0.001 145 ;# {NonPhysicalPrimMin} {} {Minimum size of nonphysical prims?} {} 0.001
150 ;; Minimum size for non-physical prims. Affects resizing of existing 146 ;; Minimum size for non-physical prims. Affects resizing of existing
151 ;; prims. This can be overridden in the region config file (as 147 ;; prims. This can be overridden in the region config file (as
diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini
index c0c8134..05ea867 100644
--- a/bin/OpenSimDefaults.ini
+++ b/bin/OpenSimDefaults.ini
@@ -583,7 +583,7 @@
583 ; clients login by starting each connection more slowly. Disabled by 583 ; clients login by starting each connection more slowly. Disabled by
584 ; default 584 ; default
585 ; 585 ;
586 enable_adaptive_throttles = true 586 enable_adaptive_throttles = false
587 587
588 ; Per-client bytes per second rates for the various throttle categories. 588 ; Per-client bytes per second rates for the various throttle categories.
589 ; These are default values that will be overridden by clients. These 589 ; These are default values that will be overridden by clients. These
@@ -1928,7 +1928,7 @@
1928 GroupsCacheTimeout = 30 1928 GroupsCacheTimeout = 30
1929 1929
1930 ; Specify which messaging module to use for groups messaging and if it's enabled 1930 ; Specify which messaging module to use for groups messaging and if it's enabled
1931 MessagingModule = GroupsMessagingModule 1931 ;MessagingModule = GroupsMessagingModule
1932 ;MessagingEnabled = true 1932 ;MessagingEnabled = true
1933 1933
1934 ; Experimental option to only message cached online users rather than all users 1934 ; Experimental option to only message cached online users rather than all users
diff --git a/bin/OpenSimDefaults.ini.example b/bin/OpenSimDefaults.ini.example
new file mode 100644
index 0000000..ef8f73a
--- /dev/null
+++ b/bin/OpenSimDefaults.ini.example
@@ -0,0 +1,1325 @@
1[Startup]
2 ; Set this to true if you want to log crashes to disk
3 ; this can be useful when submitting bug reports.
4 save_crashes = false
5
6 ; Directory to save crashes to if above is enabled
7 ; (default is /opensimdir/crashes/*.txt or C:\opensim\crashes\*.txt)
8 crash_dir = "crashes"
9
10 ; Place to create a PID file
11 ; PIDFile = "/tmp/my.pid"
12
13 ; Http proxy support for llHTTPRequest and dynamic texture loading
14 ; Set HttpProxy to the URL for your proxy server if you would like
15 ; to proxy llHTTPRequests through a firewall
16 ; HttpProxy = "http://proxy.com"
17 ; Set HttpProxyExceptions to a list of regular expressions for
18 ; URLs that you don't want going through the proxy such as servers
19 ; inside your firewall, separate patterns with a ';'
20 ; HttpProxyExceptions = ".mydomain.com;localhost"
21
22 startup_console_commands_file = "startup_commands.txt"
23 shutdown_console_commands_file = "shutdown_commands.txt"
24
25 ; To run a script every few minutes, set the script filename here
26 ; timer_Script = "filename"
27
28 ; ##
29 ; ## SYSTEM
30 ; ##
31
32 ; Sets the method that OpenSim will use to fire asynchronous
33 ; events. Valid values are UnsafeQueueUserWorkItem,
34 ; QueueUserWorkItem, BeginInvoke, SmartThreadPool, and Thread.
35 ; SmartThreadPool is reported to work well on Mono/Linux, but
36 ; UnsafeQueueUserWorkItem has been benchmarked with better
37 ; performance on .NET/Windows
38 async_call_method = SmartThreadPool
39
40 ; Max threads to allocate on the FireAndForget thread pool
41 ; when running with the SmartThreadPool option above
42 MaxPoolThreads = 15
43
44 ; ##
45 ; ## CLIENTS
46 ; ##
47
48 ; Enables EventQueueGet Service.
49 EventQueue = true
50
51 ; Set this to the DLL containing the client stack to use.
52 clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll"
53
54 ; ##
55 ; ## REGIONS
56 ; ##
57
58 ; Determine where OpenSimulator looks for the files which tell it which regions to server
59 ; Defaults to "filesystem" if this setting isn't present
60 region_info_source = "filesystem"
61 ; region_info_source = "web"
62
63 ; Determines where the region XML files are stored if you are loading these from the filesystem.
64 ; Defaults to bin/Regions in your OpenSimulator installation directory
65 ; regionload_regionsdir="C:\somewhere\xmlfiles\"
66
67 ; Determines the page from which regions xml is retrieved if you are loading these from the web
68 ; The XML here has the same format as it does on the filesystem (including the <Root> tag),
69 ; except that everything is also enclosed in a <Regions> tag.
70 ; regionload_webserver_url = "http://example.com/regions.xml";
71
72 ; Draw objects on maptile. This step might take a long time if you've got a large number of
73 ; objects, so you can turn it off here if you'd like.
74 DrawPrimOnMapTile = true
75 ; Use terrain texture for maptiles if true, use shaded green if false
76 TextureOnMapTile = false
77
78 ; Maximum total size, and maximum size where a prim can be physical
79 NonPhysicalPrimMax = 256
80 PhysicalPrimMax = 10 ; (I think this was moved to the Regions.ini!)
81 ClampPrimSize = false
82
83 ; Allow scripts to cross region boundaries. These are recompiled on the new region.
84 AllowScriptCrossing = false
85
86 ; Allow compiled script binary code to cross region boundaries.
87 ; If you set this to "true", any region that can teleport to you can
88 ; inject ARBITRARY BINARY CODE into your system. Use at your own risk.
89 ; YOU HAVE BEEN WARNED!!!
90 TrustBinaries = false
91
92 ; Combine all contiguous regions into one large megaregion
93 ; Order your regions from South to North, West to East in your regions.ini and then set this to true
94 ; Warning! Don't use this with regions that have existing content!, This will likely break them
95 CombineContiguousRegions = false
96
97 ; If you have only one region in an instance, or to avoid the many bugs
98 ; that you can trigger in modules by restarting a region, set this to
99 ; true to make the entire instance exit instead of restarting the region.
100 ; This is meant to be used on systems where some external system like
101 ; Monit will restart any instance that exits, thereby making the shutdown
102 ; into a restart.
103 ;InworldRestartShutsDown = false
104
105 ; ##
106 ; ## PRIM STORAGE
107 ; ##
108
109 ; Persistence of changed objects happens during regular sweeps. The following control that behaviour to
110 ; prevent frequently changing objects from heavily loading the region data store.
111 ; If both of these values are set to zero then persistence of all changed objects will happen on every sweep.
112 ;
113 ; Objects will be considered for persistance in the next sweep when they have not changed for this number of seconds
114 MinimumTimeBeforePersistenceConsidered = 60
115 ; Objects will always be considered for persistance in the next sweep if the first change occurred this number of seconds ago
116 MaximumTimeBeforePersistenceConsidered = 600
117
118 ; Should avatars in neighbor sims see objects in this sim?
119 see_into_this_sim_from_neighbor = true
120
121 ; ##
122 ; ## PHYSICS
123 ; ##
124
125 ; if you would like to allow prims to be physical and move by physics with the physical checkbox in the client set this to true.
126 physical_prim = true
127
128 ; Select a mesher here.
129 ;
130 ; Meshmerizer properly handles complex prims by using triangle meshes.
131 ; Note that only the ODE physics engine currently deals with meshed prims in a satisfactory way
132 ;
133 ; ZeroMesher is faster but leaves the physics engine to model the mesh using the basic shapes that it supports
134 ; Usually this is only a box
135
136 meshing = Meshmerizer
137 ;meshing = ZeroMesher
138
139 ; Choose one of the physics engines below
140 ; OpenDynamicsEngine is by some distance the most developed physics engine
141 ; basicphysics effectively does not model physics at all, making all objects phantom
142
143 physics = OpenDynamicsEngine
144 ;physics = basicphysics
145 ;physics = POS
146 ;physics = modified_BulletX
147
148 ; ##
149 ; ## PERMISSIONS
150 ; ##
151
152 ;permissionmodules = "DefaultPermissionsModule"
153
154 ;If any of the specified permissions modules fail to load, quit?
155 SecurePermissionsLoading = true
156
157 ; If set to false, then, in theory, the server never carries out permission checks (allowing anybody to copy
158 ; any item, etc. This may not yet be implemented uniformally.
159 ; If set to true, then all permissions checks are carried out
160 ; Default is false
161 serverside_object_permissions = false
162
163 allow_grid_gods = false
164
165 ; This allows somne control over permissions
166 ; please note that this still doesn't duplicate SL, and is not intended to
167 ;region_owner_is_god = true
168 ;region_manager_is_god = false
169 ;parcel_owner_is_god = true
170
171 ; Control user types that are allowed to create new scripts
172 ; Only enforced if serviceside_object_permissions is true
173 ;
174 ; Current possible values are
175 ; all - anyone can create scripts (subject to normal permissions)
176 ; gods - only administrators can create scripts (as long as allow_grid_gods is true)
177 ; Default value is all
178 ; allowed_script_creators = all
179
180 ; Control user types that are allowed to edit (save) scripts
181 ; Only enforced if serviceside_object_permissions is true
182 ;
183 ; Current possible values are
184 ; all - anyone can edit scripts (subject to normal permissions)
185 ; gods - only administrators can edit scripts (as long as allow_grid_gods is true)
186 ; Default value is all
187 ; allowed_script_editors = all
188
189 ; ##
190 ; ## SCRIPT ENGINE
191 ; ##
192
193 DefaultScriptEngine = "XEngine"
194
195 ; ##
196 ; ## WORLD MAP
197 ; ##
198
199 ;WorldMapModule = "WorldMap"
200 ;MapImageModule = "MapImageModule"
201 ; Set to false to not generate any maptiles
202 ;GenerateMaptiles = "true"
203 ; Refresh (in seconds) the map tile periodically
204 ;MaptileRefresh = 0
205 ; If not generating maptiles, use this static texture asset ID
206 ;MaptileStaticUUID = "00000000-0000-0000-0000-000000000000"
207
208 ; ##
209 ; ## EMAIL MODULE
210 ; ##
211
212 ;emailmodule = DefaultEmailModule
213
214 ; ##
215 ; ## ANIMATIONS
216 ; ##
217
218 ; If enabled, enableFlySlow will change the primary fly state to
219 ; FLYSLOW, and the "always run" state will be the regular fly.
220
221 enableflyslow = false
222
223 ; PreJump is an additional animation state, but it probably
224 ; won't look right until the physics engine supports it
225 ; (i.e delays takeoff for a moment)
226
227 ; This is commented so it will come on automatically once it's
228 ; supported.
229
230 ; enableprejump = true
231
232 ; Simulator Stats URI
233 ; Enable JSON simulator data by setting a URI name (case sensitive)
234 ; Stats_URI = "jsonSimStats"
235
236 ; Make OpenSim start all regions woth logins disabled. They will need
237 ; to be enabled from the console if this is set
238 ; StartDisabled = false
239
240 ; Image decoding. Use CSJ2K for layer boundary decoding if true,
241 ; OpenJPEG if false
242 ; UseCSJ2K = true
243
244[SMTP]
245 enabled=false
246
247 ;enabled=true
248 ;internal_object_host=lsl.opensim.local
249 ;host_domain_header_from=127.0.0.1
250 ;SMTP_SERVER_HOSTNAME=127.0.0.1
251 ;SMTP_SERVER_PORT=25
252 ;SMTP_SERVER_LOGIN=foo
253 ;SMTP_SERVER_PASSWORD=bar
254
255[Network]
256 ConsoleUser = "Test"
257 ConsolePass = "secret"
258 http_listener_port = 9000
259 console_port = 0
260
261 ; ssl config: Experimental! The auto https config only really works definately on windows XP now
262 ; you need a Cert Request/Signed pair installed in the MY store with the CN specified below
263 ; you can use https on other platforms, but you'll need to configure the httpapi yourself for now
264 http_listener_ssl = false ; Also create a SSL server
265 http_listener_cn = "localhost" ; Use the cert with the common name
266 http_listener_sslport = 9001 ; Use this port for SSL connections
267 http_listener_ssl_cert = "" ; Currently unused, but will be used for OSHttpServer
268
269 ; Hostname to use in llRequestURL/llRequestSecureURL
270 ; if not defined - default machine name is being used
271 ; (on Windows this mean NETBIOS name - useably only inside local network)
272 ; ExternalHostNameForLSL=127.0.0.1
273
274 ; What is reported as the "X-Secondlife-Shard"
275 ; Defaults to the user server url if not set
276 ; The old default is "OpenSim", set here for compatibility
277 shard = "OpenSim"
278
279 ; What is reported as the "User-Agent" when using llHTTPRequest
280 ; Defaults to not sent if not set here. See the notes section in the wiki at
281 ; http://wiki.secondlife.com/wiki/LlHTTPRequest for comments on adding
282 ; " (Mozilla Compatible)" to the text where there are problems with a web server
283 ;user_agent = "OpenSim LSL (Mozilla Compatible)"
284
285[XMLRPC]
286 ; ##
287 ; ## Scripting XMLRPC mapper
288 ; ##
289
290 ; If enabled, this will post an event, "xmlrpc_uri(string)" to the
291 ; script concurrently with the first remote_data event.
292 ; This will contain the fully qualified URI an external site needs
293 ; to use to send XMLRPC requests to that script
294
295 ;XmlRpcRouterModule = "XmlRpcRouterModule"
296 ;XmlRpcPort = 20800
297
298[ClientStack.LindenUDP]
299 ; Set this to true to process incoming packets asynchronously. Networking is
300 ; already separated from packet handling with a queue, so this will only
301 ; affect whether networking internals such as packet decoding and
302 ; acknowledgement accounting are done synchronously or asynchronously
303 ;
304 ;async_packet_handling = false
305
306 ; The client socket receive buffer size determines how many
307 ; incoming requests we can process; the default on .NET is 8192
308 ; which is about 2 4k-sized UDP datagrams. On mono this is
309 ; whatever the underlying operating system has as default; for
310 ; example, ubuntu 8.04 or SLES11 have about 111k, which is about
311 ; 27 4k-sized UDP datagrams (on linux platforms you can [as root]
312 ; do "sysctl net.core.rmem_default" to find out what your system
313 ; uses a default socket receive buffer size.
314 ;
315 ; client_socket_rcvbuf_size allows you to specify the receive
316 ; buffer size LLUDPServer should use. NOTE: this will be limited
317 ; by the system's settings for the maximum client receive buffer
318 ; size (on linux systems you can set that with "sysctl -w
319 ; net.core.rmem_max=X")
320 ;
321 ;client_socket_rcvbuf_size = 8388608
322
323 ; Maximum outbound bytes per second for a single scene. This can be used to
324 ; throttle total outbound UDP traffic for a simulator. The default value is
325 ; 0, meaning no throttling at the scene level. The example given here is
326 ; 20 megabits
327 ;
328 ;scene_throttle_max_bps = 2621440
329
330 ; Maximum bits per second to send to any single client. This will override
331 ; the user's viewer preference settings. The default value is 0, meaning no
332 ; aggregate throttling on clients (only per-category throttling). The
333 ; example given here is 1.5 megabits
334 ;
335 ;client_throttle_max_bps = 196608
336
337 ; Per-client bytes per second rates for the various throttle categories.
338 ; These are default values that will be overriden by clients
339 ;
340 ;resend_default = 12500
341 ;land_default = 1000
342 ;wind_default = 1000
343 ;cloud_default = 1000
344 ;task_default = 1000
345 ;texture_default = 1000
346 ;asset_default = 1000
347 ;state_default = 1000
348
349 ; Per-client maximum burst rates in bytes per second for the various
350 ; throttle categories. These are default values that will be overriden by
351 ; clients
352 ;
353 ;resend_limit = 18750
354 ;land_limit = 29750
355 ;wind_limit = 18750
356 ;cloud_limit = 18750
357 ;task_limit = 18750
358 ;texture_limit = 55750
359 ;asset_limit = 27500
360 ;state_limit = 37000
361
362 ; Configures how ObjectUpdates are aggregated. These numbers
363 ; do not literally mean how many updates will be put in each
364 ; packet that goes over the wire, as packets are
365 ; automatically split on a 1400 byte boundary. These control
366 ; the balance between responsiveness of interest list updates
367 ; and total throughput. Higher numbers will ensure more full-
368 ; sized packets and faster sending of data, but more delay in
369 ; updating interest lists
370 ;
371 ;PrimTerseUpdatesPerPacket = 25
372 ;AvatarTerseUpdatesPerPacket = 10
373 ;PrimFullUpdatesPerPacket = 100
374
375 ; TextureSendLimit determines how many packets will be put on
376 ; the outgoing queue each cycle. Like the settings above, this
377 ; is a balance between responsiveness to priority updates and
378 ; total throughput. Higher numbers will give a better
379 ; throughput at the cost of reduced responsiveness to client
380 ; priority changes or transfer aborts
381 ;
382 ;TextureSendLimit = 20
383
384 ; Quash and remove any light properties from attachments not on the
385 ; hands. This allows flashlights and lanterns to function, but kills
386 ; silly vanity "Facelights" dead. Sorry, head mounted miner's lamps
387 ; will also be affected.
388 ;
389 ;DisableFacelights = "false"
390
391[Chat]
392 ; Controls whether the chat module is enabled. Default is true.
393 enabled = true;
394
395 ; Distance in meters that whispers should travel. Default is 10m
396 whisper_distance = 10
397
398 ; Distance in meters that ordinary chat should travel. Default is 30m
399 say_distance = 30
400
401 ; Distance in meters that shouts should travel. Default is 100m
402 shout_distance = 100
403
404 ; Append a prefix to the god avatar names appearing in chat whilst in god mode
405 ; admin_prefix = "@"
406
407
408[Messaging]
409 ; Control which region module is used for instant messaging.
410 ; Default is InstantMessageModule (this is the name of the core IM module as well as the setting)
411 InstantMessageModule = InstantMessageModule
412 ; MessageTransferModule = MessageTransferModule
413 ; OfflineMessageModule = OfflineMessageModule
414 ; OfflineMessageURL = http://yourserver/Offline.php
415 ; MuteListModule = MuteListModule
416 ; MuteListURL = http://yourserver/Mute.php
417
418 ; Control whether group messages are forwarded to offline users. Default is true.
419 ; ForwardOfflineGroupMessages = true
420
421
422[ODEPhysicsSettings]
423 ;##
424 ;## World Settings
425 ;##
426
427 ;Gravity. Feel like falling up? change world_gravityz to 9.8 instead of -9.8. m/s
428 world_gravityx = 0
429 world_gravityy = 0
430 world_gravityz = -9.8
431
432 ; World Step size. (warning these are dangerous. Changing these will probably cause your scene to explode dramatically)
433 ; reference: fps = (0.09375/ODE_STEPSIZE) * 1000;
434 world_stepsize = 0.020
435 world_internal_steps_without_collisions = 10
436
437 ;World Space settings. Affects memory consumption vs Collider CPU time for avatar and physical prim
438 world_hashspace_size_low = -4
439 world_hashSpace_size_high = 128
440
441 ;Dynamic space settings Affects memory consumption vs Collider CPU time for static prim
442 meters_in_small_space = 29.9
443 small_hashspace_size_low = -4
444 small_hashspace_size_high = 66
445
446 ; ##
447 ; ## Contact properties. (the stuff that happens when things come in contact with each other)
448 ; ##
449
450 ; surface layer around geometries other geometries can sink into before generating a contact
451 world_contact_surface_layer = 0.001
452
453 ; Filtering collisions helps keep things stable physics wise, but sometimes
454 ; it can be overzealous. If you notice bouncing, chances are it's that.
455 filter_collisions = false
456
457 ; Non Moving Terrain Contact (avatar isn't moving)
458 nm_terraincontact_friction = 255.0
459 nm_terraincontact_bounce = 0.1
460 nm_terraincontact_erp = 0.1025
461
462 ; Moving Terrain Contact (avatar is moving)
463 m_terraincontact_friction = 75.0
464 m_terraincontact_bounce = 0.05
465 m_terrainContact_erp = 0.05025
466
467 ; Moving Avatar to object Contact
468 m_avatarobjectcontact_friction = 75.0
469 m_avatarobjectcontact_bounce = 0.1
470
471 ; Object to Object Contact and Non-Moving Avatar to object
472 objectcontact_friction = 250.0
473 objectcontact_bounce = 0.2
474
475 ; ##
476 ; ## Avatar Control
477 ; ##
478
479 ; PID Controller Settings. These affect the math that causes the avatar to reach the
480 ; desired velocity
481 ; See http://en.wikipedia.org/wiki/PID_controller
482
483 av_pid_derivative_linux = 2200.0
484 av_pid_proportional_linux = 900.0;
485
486 av_pid_derivative_win = 2200.0
487 av_pid_proportional_win = 900.0;
488
489 ;girth of the avatar. Adds radius to the height also
490 av_capsule_radius = 0.37
491
492 ; Max force permissible to use to keep the avatar standing up straight
493 av_capsule_standup_tensor_win = 550000
494 av_capsule_standup_tensor_linux = 550000
495
496 ; specifies if the capsule should be tilted (=true; old compatibility mode)
497 ; or straight up-and-down (=false; better and more consistent physics behavior)
498 av_capsule_tilted = false
499
500 ; used to calculate mass of avatar.
501 ; float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
502 ; av_density * AVvolume;
503 av_density = 80
504
505 ; use this value to cut 52% of the height the sim gives us
506 av_height_fudge_factor = 0.52
507
508 ; Movement. Smaller is faster.
509
510 ; speed of movement with Always Run off
511 av_movement_divisor_walk = 1.3
512
513 ; speed of movement with Always Run on
514 av_movement_divisor_run = 0.8
515
516 ; When the avatar flies, it will be moved up by this amount off the ground (in meters)
517 minimum_ground_flight_offset = 3.0
518
519 ; ##
520 ; ## Object options
521 ; ##
522
523 ; used in the mass calculation.
524 geometry_default_density = 10.000006836
525
526 ; amount of ODE steps where object is non moving for ODE to automatically put it to sleep
527 body_frames_auto_disable = 20
528
529 ; used to control llMove2Target
530 body_pid_derivative = 35
531 body_pid_gain = 25
532
533 ; maximum number of contact points to generate per collision
534 contacts_per_collision = 80
535
536 ; amount of time a geom/body will try to cross a region border before it gets disabled
537 geom_crossing_failures_before_outofbounds = 5
538
539 ; start throttling the object updates if object comes in contact with 3 or more other objects
540 geom_contactpoints_start_throttling = 3
541
542 ; send 1 update for every x updates below when throttled
543 geom_updates_before_throttled_update = 15
544
545 ; Used for llSetStatus. How rigid the object rotation is held on the axis specified
546 body_motor_joint_maxforce_tensor_linux = 5
547 body_motor_joint_maxforce_tensor_win = 5
548
549 ; Maximum mass an object can be before it is clamped
550 maximum_mass_object = 10000.01
551
552 ; ##
553 ; ## Sculpted Prim settings
554 ; ##
555
556 ; Do we want to mesh sculpted prim to collide like they look?
557 mesh_sculpted_prim = true
558
559 ; number^2 non-physical level of detail of the sculpt texture. 32x32 - 1024 verticies
560 mesh_lod = 32
561
562 ; number^2 physical level of detail of the sculpt texture. 16x16 - 256 verticies
563 mesh_physical_lod = 16
564
565 ; ##
566 ; ## Physics logging settings - logfiles are saved to *.DIF files
567 ; ##
568
569 ; default is false
570 ;physics_logging = true
571 ;; every n simulation iterations, the physics snapshot file is updated
572 ;physics_logging_interval = 50
573 ;; append to existing physics logfile, or overwrite existing logfiles?
574 ;physics_logging_append_existing_logfile = true
575
576 ; ##
577 ; ## Joint support
578 ; ##
579
580 ; if you would like physics joints to be enabled through a special naming convention in the client, set this to true.
581 ; (see NINJA Physics documentation, http://opensimulator.org/wiki/NINJA_Physics)
582 ; default is false
583 ;use_NINJA_physics_joints = true
584
585 ; ##
586 ; ## additional meshing options
587 ; ##
588
589 ; physical collision mesh proxies are normally created for complex prim shapes, and collisions for simple boxes and
590 ; spheres are computed algorithmically. If you would rather have mesh proxies for simple prims, you can set this to
591 ; true. Note that this will increase memory usage and region startup time. Default is false.
592 ;force_simple_prim_meshing = true
593
594
595[RemoteAdmin]
596 enabled = false
597
598 ; Set this to a nonzero value to have remote admin use a different port
599 port = 0
600
601 ; This password is required to make any XMLRPC call (should be set as the "password" parameter)
602 access_password = unknown
603
604 ; set this variable to true if you want the create_region XmlRpc
605 ; call to unconditionally enable voice on all parcels for a newly
606 ; created region [default: false]
607 create_region_enable_voice = false
608
609 ; set this variable to false if you want the create_region XmlRpc
610 ; call to create all regions as private per default (can be
611 ; overridden in the XmlRpc call) [default: true]
612 create_region_public = false
613
614 ; the create_region XmlRpc call uses region_file_template to generate
615 ; the file name of newly create regions (if they are created
616 ; persistent). the parameter available are:
617 ; {0} - X location
618 ; {1} - Y location
619 ; {2} - region UUID
620 ; {3} - region port
621 ; {4} - region name with " ", ":", "/" mapped to "_"
622 region_file_template = "{0}x{1}-{2}.ini"
623
624 ; we can limit the number of regions that XmlRpcCreateRegion will
625 ; allow by setting this to a positive, non-0 number: as long as the
626 ; number of regions is below region_limits, XmlRpcCreateRegion will
627 ; succeed. setting region_limit to 0 disables the check.
628 ; default is 0
629 ;region_limit = 0
630
631 ; enable only those methods you deem to be appropriate using a | delimited whitelist
632 ; for example, enabled_methods = admin_broadcast|admin_region_query|admin_save_oar|admin_save_xml
633 ; if this parameter is not specified but enabled = true, all methods will be available
634 enabled_methods = all
635
636 ; specify the default appearance for an avatar created through the remote admin interface
637 ; This will only take effect is the file specified by the default_appearance setting below exists
638 ;default_male = Default Male
639 ;default_female = Default Female
640
641 ; update appearance copies inventory items and wearables of default avatars. if this value is false
642 ; (default), just worn assets are copied to the Clothes folder; if true, all Clothes and Bodyparts
643 ; subfolders are copied. the receiver will wear the same items the default avatar did wear.
644 ;copy_folders = false
645
646 ; path to default appearance XML file that specifies the look of the default avatars
647 ;default_appearance = default_appearance.xml
648
649[RestPlugins]
650 ; Change this to true to enable REST Plugins. This must be true if you wish to use
651 ; REST Region or REST Asset and Inventory Plugins
652 enabled = false
653 god_key = SECRET
654 prefix = /admin
655
656
657[RestRegionPlugin]
658 ; Change this to true to enable the REST Region Plugin
659 enabled = false
660
661
662[RestHandler]
663 ; Change this to true to enable the REST Asset and Inventory Plugin
664 enabled = false
665 authenticate = true
666 secured = true
667 extended-escape = true
668 realm = OpenSim REST
669 dump-asset = false
670 path-fill = true
671 dump-line-size = 32
672 flush-on-error = true
673
674
675; Uncomment the following for IRC bridge
676; experimental, so if it breaks... keep both parts... yada yada
677; also, not good error detection when it fails
678;[IRC]
679 ;enabled = true ; you need to set this otherwise it won't connect
680 ;server = name.of.irc.server.on.the.net
681 ;; user password - only use this if the server requires one
682 ;password = mypass
683 ;nick = OpenSimBotNameProbablyMakeThisShorter
684 ;channel = #the_irc_channel_you_want_to_connect_to
685 ;user = "USER OpenSimBot 8 * :I'm an OpenSim to IRC bot"
686 ;port = 6667
687 ;; channel to listen for configuration commands
688 ;commands_enabled = false
689 ;command_channel = 2777
690 ;report_clients = true
691 ;; relay private chat connections
692 ;; relay_private_channels = true: will relay IRC chat from/to private in-world channels
693 ;; relay_private_channel_out -- channel to send messages out to the IRC bridge
694 ;; relay_private_channel_in -- channel to receive message from the IRC bridge
695 ;; relay_chat = false: IRC bridge will not relay normal chat
696 ;; access_password -- simple security device
697 ;;
698 ;; so, to just relay chat from an IRC channel to in-world region and vice versa:
699 ;;
700 ;; relay_private_channels = false
701 ;; relay_chat = true
702 ;;
703 ;; to relay chat only to/from private in-world channels:
704 ;;
705 ;; relay_chat = false
706 ;; relay_private_channels = true
707 ;; relay_private_channel_in = 2226
708 ;; relay_private_channel_out = 2225
709 ;;
710 ;; in this example, all chat coming in from IRC will be send out via
711 ;; in-world channel 2226, and all chat from in-world channel 2225 will
712 ;; be relayed to the IRC channel.
713 ;;
714 ;relay_private_channels = false
715 ;relay_private_channel_in = 2226
716 ;relay_private_channel_out = 2225
717 ;relay_chat = true
718 ;access_password = foobar
719
720 ;;fallback_region = name of "default" region
721 ;;MSGformat fields : 0=botnick, 1=user, 2=region, 3=message
722 ;; must start with "PRIVMSG {0} : " or irc server will get upset
723 ;;for <bot>:<user in region> :<message>
724 ;;msgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"
725 ;;for <bot>:<message> - <user of region> :
726 ;msgformat = "PRIVMSG {0} : {3} - {1} of {2}"
727 ;;for <bot>:<message> - from <user> :
728 ;;msgformat = "PRIVMSG {0} : {3} - from {1}"
729
730 ;; exclude_list allows you to stop the IRC connector from announcing the
731 ;;arrival and departure of certain users. For example: admins, bots.
732
733 ;exclude_list=User 1,User 2,User 3
734
735
736;[CMS]
737 ;enabled = true
738 ;channel = 345
739
740
741; Uncomment the following to control the progression of daytime
742; in the Sim. The defaults are what is shown below
743;[Sun]
744 ; number of wall clock hours for an opensim day. 24.0 would mean realtime
745 ;day_length = 4
746 ; Year length in days
747 ;year_length = 60
748 ; Day to Night Ratio
749 ;day_night_offset = 0.45
750 ; send a Sun update every update_interval # of frames. A lower number will
751 ; make for smoother sun transition at the cost of network
752 ;update_interval = 100
753
754
755[Wind]
756 ; Enables the wind module. Default is true
757 enabled = true
758
759 ; How often should wind be updated, as a function of world frames. Approximately 50 frames a second
760 wind_update_rate = 150
761
762 ; The Default Wind Plugin to load
763 wind_plugin = SimpleRandomWind
764
765 ; These settings are specific to the ConfigurableWind plugin
766 ; To use ConfigurableWind as the default, simply change wind_plugin to ConfigurableWind and uncomment the following.
767 ; avg_strength = 5.0
768 ; avg_direction = 0.0
769 ; var_strength = 0.0
770 ; var_direction = 0.0
771 ; rate_change = 1.0
772
773 ; This setting is specific to the SimpleRandomWind plugin
774 ; Adjusts wind strength. 0.0 = no wind, 1.0 = normal wind. Default is 1.0
775 strength = 1.0
776
777
778[Cloud]
779 ; Enable this to generate classic particle clouds above the sim.
780 ; default is disabled - turn it on here
781 enabled = false
782
783 ; Density of cloud cover 0.0 to 1.0 Defult 0.5
784 density = 0.5
785
786 ; update interval for the cloud cover data returned by llCloud().
787 ; default is 1000
788 cloud_update_rate = 1000
789
790[LightShare]
791
792 ; This enables the transmission of Windlight scenes to supporting clients, such as the Meta7 viewer.
793 ; It has no ill effect on viewers which do not support server-side windlight settings.
794 ; Currently we only have support for MySQL databases.
795 enable_windlight = false;
796
797[Trees]
798 ; Enable this to allow the tree module to manage your sim trees, including growing, reproducing and dying
799 ; default is false
800 active_trees = false
801
802 ; Density of tree population
803 tree_density = 1000.0
804
805
806[VectorRender]
807
808 ; the font to use for rendering text (default: Arial)
809 ; font_name = "Arial"
810
811
812[LL-Functions]
813 ; Set the following to true to allow administrator owned scripts to execute console commands
814 ; currently unused
815 ; AllowosConsoleCommand=false
816
817 AllowGodFunctions = false
818
819 ; Maximum number of llListen events we allow per script
820 ; Set this to 0 to have no limit imposed.
821 max_listens_per_script = 64
822
823
824[DataSnapshot]
825 ; The following set of configs pertains to search.
826 ; Set index_sims to true to enable search engines to index your searchable data
827 ; If false, no data will be exposed, DataSnapshot module will be off, and you can ignore the rest of these search-related configs
828 ; default is false
829 index_sims = false
830
831 ; The variable data_exposure controls what the regions expose:
832 ; minimum: exposes only things explicitly marked for search
833 ; all: exposes everything
834 data_exposure = minimum
835
836 ; If search is on, change this to your grid name; will be ignored for standalones
837 gridname = "OSGrid"
838
839 ; Period between data snapshots, in seconds. 20 minutes, for starters, so that you see the initial changes fast.
840 ; Later, you may want to increase this to 3600 (1 hour) or more
841 default_snapshot_period = 1200
842
843 ; This will be created in bin, if it doesn't exist already. It will hold the data snapshots.
844 snapshot_cache_directory = "DataSnapshot"
845
846 ; This semicolon-separated string serves to notify specific data services about the existence
847 ; of this sim. Uncomment if you want to index your data with this and/or other search providers.
848 ;data_services="http://metaverseink.com/cgi-bin/register.py"
849
850
851[Economy]
852 ; These economy values get used in the BetaGridLikeMoneyModule. - This module is for demonstration only -
853
854 ; Enables selling things for $0
855 SellEnabled = "false"
856
857 ; 45000 is the highest value that the sim could possibly report because of protocol constraints
858 ObjectCapacity = 45000
859
860 ; Money Unit fee to upload textures, animations etc
861 PriceUpload = 0
862
863 ; Money Unit fee to create groups
864 PriceGroupCreate = 0
865
866 ; We don't really know what the rest of these values do. These get sent to the client
867 ; These taken from Agni at a Public Telehub. Change at your own risk.
868 ObjectCount = 0
869 PriceEnergyUnit = 100
870 PriceObjectClaim = 10
871 PricePublicObjectDecay = 4
872 PricePublicObjectDelete = 4
873 PriceParcelClaim = 1
874 PriceParcelClaimFactor = 1
875
876 PriceRentLight = 5
877 TeleportMinPrice = 2
878 TeleportPriceExponent = 2
879 EnergyEfficiency = 1
880 PriceObjectRent = 1
881 PriceObjectScaleFactor = 10
882 PriceParcelRent = 1
883
884[Git]
885Enabled = true
886RepoPath = "git"
887
888;How many seconds between the scheduled commits?
889CommitInterval = 21600
890
891;Disable all except the initial commit?
892DisableNonEssentialCommits = false
893
894;Should we automatically commit when necessary to avoid objects never making it into the repo?
895UseSafetyCommit = true
896
897
898[SVN]
899 Enabled = false
900 Directory = SVNmodule\repo
901 URL = "svn://your.repo.here/"
902 Username = "user"
903 Password = "password"
904 ImportOnStartup = false
905 Autosave = false
906 AutoSavePeriod = 15 ; Number of minutes between autosave backups
907
908
909[XEngine]
910 ; Enable this engine in this OpenSim instance
911 Enabled = true
912
913 ; How many threads to keep alive even if nothing is happening
914 MinThreads = 2
915
916 ; How many threads to start at maximum load
917 MaxThreads = 100
918
919 ; Time a thread must be idle (in seconds) before it dies
920 IdleTimeout = 60
921
922 ; Thread priority ("Lowest", "BelowNormal", "Normal", "AboveNormal", "Highest")
923 Priority = "BelowNormal"
924
925 ; Maximum number of events to queue for a script (excluding timers)
926 MaxScriptEventQueue = 300
927
928 ; Stack size per thread created
929 ThreadStackSize = 262144
930
931 ; Set this to true (the default) to load each script into a separate
932 ; AppDomain. Setting this to false will load all script assemblies into the
933 ; current AppDomain, which will reduce the per-script overhead at the
934 ; expense of reduced security and the inability to garbage collect the
935 ; script assemblies
936 AppDomainLoading = true
937
938 ; Rate to poll for asynchronous command replies (ms)
939 ; currently unused
940 ;AsyncLLCommandLoopms = 50
941
942 ; Save the source of all compiled scripts
943 WriteScriptSourceToDebugFile = false
944
945 ; Default language for scripts
946 DefaultCompileLanguage = lsl
947
948 ; List of allowed languages (lsl,vb,js,cs)
949 ; AllowedCompilers=lsl,cs,js,vb.
950 ; *warning*, non lsl languages have access to static methods such as System.IO.File. Enable at your own risk.
951 AllowedCompilers=lsl
952
953 ; Compile debug info (line numbers) into the script assemblies
954 CompileWithDebugInformation = true
955
956 ; Allow the user of mod* functions. This allows a script to pass messages
957 ; to a region module via the modSendCommand() function
958 ; Default is false
959 AllowMODFunctions = false
960
961 ; Allow the use of os* functions (some are dangerous)
962 AllowOSFunctions = false
963
964 ; Allow the user of LightShare functions
965 AllowLightShareFunctions = false
966
967 ; Threat level to allow, one of None, VeryLow, Low, Moderate, High, VeryHigh, Severe
968 OSFunctionThreatLevel = VeryLow
969
970 ; Interval (s) between background save of script states
971 SaveInterval = 120
972
973 ; Interval (s) between maintenance runs (0 = disable)
974 MaintenanceInterval = 10
975
976 ; Time a script can spend in an event handler before it is interrupted
977 EventLimit = 30
978
979 ; If a script overruns it's event limit, kill the script?
980 KillTimedOutScripts = false
981
982 ; Sets the multiplier for the scripting delays
983 ScriptDelayFactor = 1.0
984
985 ; The factor the 10 m distances llimits are multiplied by
986 ScriptDistanceLimitFactor = 1.0
987
988 ; Maximum length of notecard line read
989 ; Increasing this to large values potentially opens
990 ; up the system to malicious scripters
991 ; NotecardLineReadCharsMax = 255
992
993 ; Sensor settings
994 SensorMaxRange = 96.0
995 SensorMaxResults = 16
996
997 ; OS Functions enable/disable
998 ; For each function, you can add one line, as shown
999 ; The default for all functions allows them if below threat level
1000
1001 ; true allows the use of the function unconditionally
1002 ; Allow_osSetRegionWaterHeight = true
1003
1004 ; false disables the function completely
1005 ; Allow_osSetRegionWaterHeight = false
1006
1007 ; Comma separated list of UUIDS allows the function for that list of UUIDS
1008 ; Allow_osSetRegionWaterHeight = 888760cb-a3cf-43ac-8ea4-8732fd3ee2bb
1009
1010 ; You can also use script creators as the uuid
1011 ; Creators_osSetRegionWaterHeight = <uuid>, ...
1012
1013 ; If both Allow_ and Creators_ are given, effective permissions
1014 ; are the union of the two.
1015
1016 ; Allow for llCreateLink and llBreakLink to work without asking for permission
1017 ; only enable this in a trusted environment otherwise you may be subject to hijacking
1018 ; AutomaticLinkPermission = false
1019
1020 ; Disable underground movement of prims (default true); set to
1021 ; false to allow script controlled underground positioning of
1022 ; prims
1023 ; DisableUndergroundMovement = true
1024
1025
1026[OpenGridProtocol]
1027 ;These are the settings for the Open Grid Protocol.. the Agent Domain, Region Domain, you know..
1028 ;On/true or Off/false
1029 ogp_enabled=false
1030
1031 ;Name Prefix/suffix when using OGP
1032 ogp_firstname_prefix=""
1033 ogp_lastname_suffix="_EXTERNAL"
1034
1035
1036[Concierge]
1037 ; Enable concierge module
1038 ; Default is false
1039 enabled = false
1040
1041 ; name of the concierge
1042 whoami = "jeeves"
1043
1044 ; password for updating the welcome message templates via XmlRpc
1045 password = SECRET
1046
1047 ; regex specifying for which regions concierge service is desired; if
1048 ; empty, then for all
1049 regions = "^MeetingSpace-"
1050
1051 ; for each region that matches the regions regexp you can provide
1052 ; (optionally) a welcome template using format substitution:
1053 ; {0} is replaced with the name of the avatar entering the region
1054 ; {1} is replaced with the name of the region
1055 ; {2} is replaced with the name of the concierge (whoami variable above)
1056
1057 welcomes = /path/to/welcome/template/directory
1058
1059 ; Concierge can send attendee lists to an event broker whenever an
1060 ; avatar enters or leaves a concierged region. the URL is subject
1061 ; to format substitution:
1062 ; {0} is replaced with the region's name
1063 ; {1} is replaced with the region's UUID
1064 broker = "http://broker.place.com/{1}"
1065
1066
1067[RegionReady]
1068 ; Enable this module to get notified once all items and scripts in the region have been completely loaded and compiled
1069 ; default is false
1070 enabled = false
1071
1072 ; Channel on which to signal region readiness through a message
1073 ; formatted as follows: "{server_startup|oar_file_load},{0|1},n,[oar error]"
1074 ; - the first field indicating whether this is an initial server startup
1075 ; - the second field is a number indicating whether the OAR file loaded ok (1 == ok, 0 == error)
1076 ; - the third field is a number indicating how many scripts failed to compile
1077 ; - "oar error" if supplied, provides the error message from the OAR load
1078 channel_notify = -800
1079
1080
1081[MRM]
1082 ; Enables the Mini Region Modules Script Engine.
1083 ; default is false
1084 Enabled = false
1085
1086 ; Runs MRM in a Security Sandbox
1087 ; WARNING: DISABLING IS A SECURITY RISK.
1088 Sandboxed = true
1089
1090 ; The level sandbox to use, adjust at your OWN RISK.
1091 ; Valid values are:
1092 ; * FullTrust
1093 ; * SkipVerification
1094 ; * Execution
1095 ; * Nothing
1096 ; * LocalIntranet
1097 ; * Internet
1098 ; * Everything
1099 SandboxLevel = "Internet"
1100
1101 ; Only allow Region Owners to run MRMs
1102 ; May represent a security risk if you disable this.
1103 OwnerOnly = true
1104
1105[Hypergrid]
1106 ; Keep it false for now. Making it true requires the use of a special client in order to access inventory
1107 safemode = false
1108
1109[VivoxVoice]
1110 ; The VivoxVoice module will allow you to provide voice on your
1111 ; region(s). It uses the same voice technology as the LL grid and
1112 ; works with recent LL clients (we have tested 1.22.9.110075, so
1113 ; anything later ought to be fine as well).
1114 ;
1115 ; For this to work you need to obtain an admin account from Vivox
1116 ; that allows you to create voice accounts and region channels.
1117
1118 enabled = false
1119
1120 ; vivox voice server
1121 vivox_server = www.foobar.vivox.com
1122
1123 ; vivox SIP URI
1124 vivox_sip_uri = foobar.vivox.com
1125
1126 ; vivox admin user name
1127 vivox_admin_user = DeepThroat
1128
1129 ; vivox admin password
1130 vivox_admin_password = VoiceG4te
1131
1132 ; channel type: "channel" or "positional"
1133 ; - positional: spatial sound (default)
1134 ; - channel: normal "conference call", no spatial sound
1135 ;vivox_channel_type = positional
1136
1137 ; channel characteristics (unless you know what you are doing, i'd
1138 ; leave them as they are --- now you WILL muck around with them,
1139 ; huh? sigh)
1140
1141 ; channel distance model:
1142 ; 0 - no attenuation
1143 ; 1 - inverse distance attenuation
1144 ; 2 - linear attenuation (default)
1145 ; 3 - exponential attenuation
1146 ;vivox_channel_distance_model = 2
1147
1148 ; channel mode:
1149 ; - "open" (default)
1150 ; - "lecture"
1151 ; - "presentation"
1152 ; - "auditorium"
1153 ;vivox_channel_mode = "open"
1154
1155 ; channel roll off: rate of attenuation
1156 ; - a value between 1.0 and 4.0, default is 2.0
1157 ;vivox_channel_roll_off = 2.0
1158
1159 ; channel max range: distance at which channel is silent
1160 ; - a value between 0 and 160, default is 80
1161 ;vivox_channel_max_range = 80
1162
1163 ; channel clamping distance: distance before attenuation applies
1164 ; - a value between 0 and 160, default is 10
1165 ;vivox_channel_clamping_distance = 10
1166
1167[FreeSwitchVoice]
1168 ; In order for this to work you need a functioning FreeSWITCH PBX set up.
1169 ; Configuration details at http://opensimulator.org/wiki/Freeswitch_Module
1170 enabled = false
1171 ; FreeSWITCH server is going to contact us and ask us all sorts of things
1172 freeswitch_server_user = freeswitch
1173 freeswitch_server_pass = password
1174 freeswitch_api_prefix = /api
1175 ; external IP address of your OpenSim voice enabled region
1176 ; note: all regions running on same OpenSim.exe will be enabled
1177 freeswitch_service_server = ip.address.of.your.sim
1178 ; this should be the same port the region listens on
1179 freeswitch_service_port = 9000
1180 freeswitch_realm = ip.address.of.freeswitch.server
1181 freeswitch_sip_proxy = ip.address.of.freeswitch.server:5060
1182 ; STUN = Simple Traversal of UDP through NATs
1183 ; See http://wiki.freeswitch.org/wiki/NAT_Traversal
1184 ; stun.freeswitch.org is not guaranteed to be running so use it in production at your own risk
1185 freeswitch_attempt_stun = false
1186 freeswitch_stun_server = ip.address.of.stun.server
1187 freeswitch_echo_server = ip.address.of.freeswitch.server
1188 freeswitch_echo_port = 50505
1189 freeswitch_well_known_ip = ip.address.of.freeswitch.server
1190 ;
1191 ; Type the address of your http server here, hostname is allowed. This is provided so you can specify a hostname
1192 ; This is used by client for account verification. By default, it's the same as the freeswitch service server.
1193 ;
1194 ; opensim_well_known_http_address = Address_Of_Your_SIM_HTTP_Server_Hostname_Allowed
1195 ;
1196 freeswitch_default_timeout = 5000
1197 freeswitch_subscribe_retry = 120
1198 ; freeswitch_password_reset_url =
1199
1200[Groups]
1201 Enabled = false
1202
1203 ; This is the current groups stub in Region.CoreModules.Avatar.Groups. All the other settings below only really
1204 ; apply to the Flotsam/SimianGrid GroupsModule
1205 Module = Default
1206
1207 ; This module can use a PHP XmlRpc server from the Flotsam project at http://code.google.com/p/flotsam/
1208 ; or from the SimianGrid project at http://code.google.com/p/openmetaverse
1209 ;Module = GroupsModule
1210
1211 ; Enable Group Notices
1212 ;NoticesEnabled = true
1213
1214 ; This makes the Groups modules very chatty on the console.
1215 DebugEnabled = false
1216
1217 ; Specify which messaging module to use for groups messaging and if it's enabled
1218 ;MessagingModule = GroupsMessagingModule
1219 ;MessagingEnabled = true
1220
1221 ; Service connectors to the Groups Service. Select one depending on whether you're using a Flotsam XmlRpc backend or a SimianGrid backend
1222
1223 ; SimianGrid Service for Groups
1224 ;ServicesConnectorModule = SimianGroupsServicesConnector
1225 ;GroupsServerURI = http://mygridserver.com:82/Grid/
1226
1227 ; Flotsam XmlRpc Service for Groups
1228 ;ServicesConnectorModule = XmlRpcGroupsServicesConnector
1229 ;GroupsServerURI = http://yourxmlrpcserver.com/xmlrpc.php
1230
1231 ; XmlRpc Security settings. These must match those set on your backend groups service.
1232 ;XmlRpcServiceReadKey = 1234
1233 ;XmlRpcServiceWriteKey = 1234
1234
1235 ; Disables HTTP Keep-Alive for XmlRpcGroupsServicesConnector HTTP Requests,
1236 ; this is a work around fora problem discovered on some Windows based region servers.
1237 ; Only disable keep alive if you see a large number (dozens) of the following Exceptions:
1238 ; System.Net.WebException: The request was aborted: The request was canceled.
1239 ; XmlRpcDisableKeepAlive = false
1240
1241
1242[PacketPool]
1243 ; Enables the experimental packet pool. Yes, we've been here before.
1244 ;RecyclePackets = true;
1245 ;RecycleDataBlocks = true;
1246
1247
1248[InterestManagement]
1249 ; This section controls how state updates are prioritized for each client
1250 ; Valid values are Time, Distance, SimpleAngularDistance, and FrontBack
1251 UpdatePrioritizationScheme = FrontBack
1252 ReprioritizationEnabled = true
1253 ReprioritizationInterval = 2000.0
1254 RootReprioritizationDistance = 10.0
1255 ChildReprioritizationDistance = 20.0
1256
1257
1258[WebStats]
1259; View region statistics via a web page
1260; See http://opensimulator.org/wiki/FAQ#Region_Statistics_on_a_Web_Page
1261; Use a web browser and type in the "Login URI" + "/SStats/"
1262; For example- http://127.0.0.1:9000/SStats/
1263; enabled=false
1264
1265[LandManagement]
1266; DefaultAdministratorGroupUUID = "";
1267; DefaultAdministratorParcelName = "";
1268
1269[MediaOnAPrim]
1270 ; Enable media on a prim facilities
1271 Enabled = true;
1272
1273[MOTD]
1274Enabled = false
1275Message = "The MOTD module is working!"
1276
1277
1278;;
1279;; These are defaults that are overwritten below in [Architecture].
1280;; These defaults allow OpenSim to work out of the box with
1281;; zero configuration
1282;;
1283[AssetService]
1284 DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll"
1285 AssetLoaderArgs = "assets/AssetSets.xml"
1286
1287 ; Disable this to prevent the default asset set from being inserted into the
1288 ; asset store each time the region starts
1289 AssetLoaderEnabled = true
1290
1291[GridService]
1292 ;; default standalone, overridable in StandaloneCommon.ini
1293 StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"
1294
1295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1296 ;; The following is the configuration section for the new style services
1297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1298[Architecture]
1299 ; Choose exactly one and only one of the architectures below.
1300
1301 Include-Standalone = "config-include/Standalone.ini"
1302 ;Include-HGStandalone = "config-include/StandaloneHypergrid.ini"
1303 ;Include-Grid = "config-include/Grid.ini"
1304 ;Include-HGGrid = "config-include/GridHypergrid.ini"
1305 ;Include-SimianGrid = "config-include/SimianGrid.ini"
1306 ;Include-HyperSimianGrid = "config-include/HyperSimianGrid.ini"
1307
1308 ; Then choose
1309 ; config-include/StandaloneCommon.ini.example (if you're in standlone) OR
1310 ; config-include/GridCommon.ini.example (if you're connected to a grid)
1311 ; Copy to your own .ini there (without .example extension) and edit it
1312 ; to customize your data
1313
1314
1315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1316 ;; The below pulls in optional module config files
1317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1318[Modules]
1319 Include-modules = "addon-modules/*/config/*.ini"
1320
1321
1322;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1323;; ENSURE [Architecture] and [Modules] Sections with their "includes"
1324;; are last to allow for overrides
1325;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config b/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config
new file mode 100644
index 0000000..c72c281
--- /dev/null
+++ b/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config
@@ -0,0 +1,7 @@
1<configuration>
2 <dllmap os="osx" dll="ode" target="lib64/libode.dylib" />
3 <dllmap os="!windows,osx" cpu="x86-64,ia64" dll="ode" target="lib64/libode-x86_64" />
4 <dllmap os="!windows,osx" cpu="x86" dll="ode" target="lib32/libode" />
5 <dllmap os="!windows,osx" cpu="ppc64" dll="ode" target="lib64/libode-ppc64" />
6 <dllmap os="!windows,osx" cpu="s390x" dll="ode" target="lib64/libode-s390x" />
7</configuration>
diff --git a/bin/assets/TexturesAssetSet/defaultalpha.jp2 b/bin/assets/TexturesAssetSet/defaultalpha.jp2
new file mode 100644
index 0000000..af73c1e
--- /dev/null
+++ b/bin/assets/TexturesAssetSet/defaultalpha.jp2
Binary files differ
diff --git a/bin/enter_uuid.xml b/bin/enter_uuid.xml
new file mode 100644
index 0000000..84475ad
--- /dev/null
+++ b/bin/enter_uuid.xml
@@ -0,0 +1,7 @@
1<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2<floater can_close="true" can_drag_on_left="false" can_minimize="false" can_resize="false" height="100" name="enter_uuid" title="ID Required" width="390">
3 <text bottom="-30" left="10">Enter UUID</text>
4 <line_editor bottom="-60" left="10" width="370" name="new_owner" height="20"/>
5 <button bottom="-90" width="80" height="20" left="300" label="OK" name="ok" />
6 <button bottom="-90" width="80" height="20" left="210" label="Cancel" name="cancel" />
7</floater>
diff --git a/bin/lib32/libode.so b/bin/lib32/libode.so
index 6bb85fb..5b110ae 100644..100755
--- a/bin/lib32/libode.so
+++ b/bin/lib32/libode.so
Binary files differ
diff --git a/bin/lib32/ode.dll b/bin/lib32/ode.dll
index f310358..c3263ae 100755
--- a/bin/lib32/ode.dll
+++ b/bin/lib32/ode.dll
Binary files differ
diff --git a/bin/lib64/ode.dll b/bin/lib64/ode.dll
index df3a6c4..6f5b504 100755
--- a/bin/lib64/ode.dll
+++ b/bin/lib64/ode.dll
Binary files differ
diff --git a/bin/set_object_owner.xml b/bin/set_object_owner.xml
new file mode 100644
index 0000000..6d9bb8a
--- /dev/null
+++ b/bin/set_object_owner.xml
@@ -0,0 +1,8 @@
1<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2<floater can_close="true" can_drag_on_left="false" can_minimize="false" can_resize="false" height="100" name="set_owner_name" title="Set Owner Name" width="390">
3 <text bottom="-30" left="10">New Owner Name</text>
4 <line_editor enabled="false" bottom="-60" left="10" width="280" name="new_owner" height="20"/>
5 <button bottom_delta="0" left="300" height="20" width="80" label="Choose" name="picker"/>
6 <button bottom="-90" width="80" height="20" left="300" label="OK" name="ok" />
7 <button bottom="-90" width="80" height="20" left="210" label="Cancel" name="cancel" />
8</floater>
diff --git a/prebuild.xml b/prebuild.xml
index b5ebed1..2c43683 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -6,7 +6,7 @@
6 <CompilerDefines>TRACE;DEBUG</CompilerDefines> 6 <CompilerDefines>TRACE;DEBUG</CompilerDefines>
7 <OptimizeCode>false</OptimizeCode> 7 <OptimizeCode>false</OptimizeCode>
8 <CheckUnderflowOverflow>false</CheckUnderflowOverflow> 8 <CheckUnderflowOverflow>false</CheckUnderflowOverflow>
9 <AllowUnsafe>false</AllowUnsafe> 9 <AllowUnsafe>true</AllowUnsafe>
10 <WarningLevel>4</WarningLevel> 10 <WarningLevel>4</WarningLevel>
11 <WarningsAsErrors>false</WarningsAsErrors> 11 <WarningsAsErrors>false</WarningsAsErrors>
12 <SuppressWarnings/> 12 <SuppressWarnings/>
@@ -21,7 +21,7 @@
21 <CompilerDefines>TRACE</CompilerDefines> 21 <CompilerDefines>TRACE</CompilerDefines>
22 <OptimizeCode>true</OptimizeCode> 22 <OptimizeCode>true</OptimizeCode>
23 <CheckUnderflowOverflow>false</CheckUnderflowOverflow> 23 <CheckUnderflowOverflow>false</CheckUnderflowOverflow>
24 <AllowUnsafe>false</AllowUnsafe> 24 <AllowUnsafe>true</AllowUnsafe>
25 <WarningLevel>4</WarningLevel> 25 <WarningLevel>4</WarningLevel>
26 <WarningsAsErrors>false</WarningsAsErrors> 26 <WarningsAsErrors>false</WarningsAsErrors>
27 <SuppressWarnings/> 27 <SuppressWarnings/>
@@ -514,6 +514,93 @@
514 </Files> 514 </Files>
515 </Project> 515 </Project>
516 516
517 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.ConvexDecompositionDotNet" path="OpenSim/Region/Physics/ConvexDecompositionDotNet" type="Library">
518 <Configuration name="Debug">
519 <Options>
520 <OutputPath>../../../../bin/</OutputPath>
521 </Options>
522 </Configuration>
523 <Configuration name="Release">
524 <Options>
525 <OutputPath>../../../../bin/</OutputPath>
526 </Options>
527 </Configuration>
528
529 <ReferencePath>../../../../bin/</ReferencePath>
530 <Reference name="System"/>
531 <Reference name="System.Core"/>
532 <Reference name="System.Data"/>
533 <Reference name="System.Xml"/>
534
535 <Files>
536 <Match pattern="*.cs" recurse="true">
537 <Exclude name="Tests" pattern="Tests"/>
538 </Match>
539 </Files>
540 </Project>
541
542 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.ChOdePlugin" path="OpenSim/Region/Physics/ChOdePlugin" type="Library">
543 <Configuration name="Debug">
544 <Options>
545 <OutputPath>../../../../bin/Physics/</OutputPath>
546 </Options>
547 </Configuration>
548 <Configuration name="Release">
549 <Options>
550 <OutputPath>../../../../bin/Physics/</OutputPath>
551 </Options>
552 </Configuration>
553
554 <ReferencePath>../../../../bin/</ReferencePath>
555 <Reference name="System"/>
556 <Reference name="System.Core"/>
557 <Reference name="OpenMetaverseTypes.dll"/>
558 <Reference name="Nini.dll" />
559 <Reference name="OpenSim.Framework"/>
560 <Reference name="OpenSim.Framework.Console"/>
561 <Reference name="OpenSim.Region.Physics.Manager"/>
562 <Reference name="OpenSim.Region.Physics.ConvexDecompositionDotNet"/>
563 <Reference name="Ode.NET.dll" />
564 <Reference name="log4net.dll"/>
565
566 <Files>
567 <Match pattern="*.cs" recurse="true">
568 <Exclude name="Tests" pattern="Tests"/>
569 </Match>
570 </Files>
571 </Project>
572
573 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.UbitOdePlugin" path="OpenSim/Region/Physics/UbitOdePlugin" type="Library">
574 <Configuration name="Debug">
575 <Options>
576 <OutputPath>../../../../bin/Physics/</OutputPath>
577 </Options>
578 </Configuration>
579 <Configuration name="Release">
580 <Options>
581 <OutputPath>../../../../bin/Physics/</OutputPath>
582 </Options>
583 </Configuration>
584
585 <ReferencePath>../../../../bin/</ReferencePath>
586 <Reference name="System"/>
587 <Reference name="System.Core"/>
588 <Reference name="OpenMetaverseTypes" path="../../../../bin/"/>
589 <Reference name="Nini" path="../../../../bin/"/>
590
591 <Reference name="OpenSim.Framework"/>
592 <Reference name="OpenSim.Framework.Console"/>
593 <Reference name="OpenSim.Region.Physics.Manager"/>
594 <Reference name="OpenSim.Region.Physics.ConvexDecompositionDotNet"/>
595 <Reference name="log4net" path="../../../../bin/"/>
596
597 <Files>
598 <Match pattern="*.cs" recurse="true">
599 <Exclude name="Tests" pattern="Tests"/>
600 </Match>
601 </Files>
602 </Project>
603
517 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.Meshing" path="OpenSim/Region/Physics/Meshing" type="Library"> 604 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.Meshing" path="OpenSim/Region/Physics/Meshing" type="Library">
518 <Configuration name="Debug"> 605 <Configuration name="Debug">
519 <Options> 606 <Options>
@@ -544,6 +631,38 @@
544 </Files> 631 </Files>
545 </Project> 632 </Project>
546 633
634 <Project frameworkVersion="v4_0" name="OpenSim.Region.Physics.UbitMeshing" path="OpenSim/Region/Physics/UbitMeshing" type="Library">
635 <Configuration name="Debug">
636 <Options>
637 <OutputPath>../../../../bin/Physics/</OutputPath>
638 </Options>
639 </Configuration>
640 <Configuration name="Release">
641 <Options>
642 <OutputPath>../../../../bin/Physics/</OutputPath>
643 </Options>
644 </Configuration>
645
646 <ReferencePath>../../../../bin/</ReferencePath>
647 <Reference name="System"/>
648 <Reference name="System.Drawing"/>
649 <Reference name="CSJ2K" path="../../../../bin/"/>
650 <Reference name="OpenMetaverseTypes" path="../../../../bin/"/>
651 <Reference name="OpenMetaverse" path="../../../../bin/"/>
652 <Reference name="OpenMetaverse.StructuredData" path="../../../../bin/"/>
653 <Reference name="Nini" path="../../../../bin/"/>
654 <Reference name="OpenSim.Framework"/>
655 <Reference name="OpenSim.Framework.Console"/>
656 <Reference name="OpenSim.Region.Physics.Manager"/>
657 <Reference name="OpenSim.Region.Physics.ConvexDecompositionDotNet"/>
658 <Reference name="log4net" path="../../../../bin/"/>
659 <Reference name="zlib.net" path="../../../../bin/"/>
660
661 <Files>
662 <Match pattern="*.cs" recurse="true"/>
663 </Files>
664 </Project>
665
547 <Project frameworkVersion="v4_0" name="OpenSim.Capabilities" path="OpenSim/Capabilities" type="Library"> 666 <Project frameworkVersion="v4_0" name="OpenSim.Capabilities" path="OpenSim/Capabilities" type="Library">
548 <Configuration name="Debug"> 667 <Configuration name="Debug">
549 <Options> 668 <Options>
@@ -1026,6 +1145,7 @@
1026 <Reference name="OpenSim.Server.Base"/> 1145 <Reference name="OpenSim.Server.Base"/>
1027 <Reference name="OpenSim.Services.Interfaces"/> 1146 <Reference name="OpenSim.Services.Interfaces"/>
1028 <Reference name="OpenSim.Services.Base"/> 1147 <Reference name="OpenSim.Services.Base"/>
1148 <Reference name="OpenSim.Server.Base"/>
1029 <Reference name="OpenSim.Services.Connectors"/> 1149 <Reference name="OpenSim.Services.Connectors"/>
1030 <Reference name="OpenSim.Data"/> 1150 <Reference name="OpenSim.Data"/>
1031 <Reference name="Nini" path="../../../bin/"/> 1151 <Reference name="Nini" path="../../../bin/"/>
@@ -1583,9 +1703,10 @@
1583 <Reference name="System.Drawing"/> 1703 <Reference name="System.Drawing"/>
1584 <Reference name="System.Xml"/> 1704 <Reference name="System.Xml"/>
1585 <Reference name="System.Web"/> 1705 <Reference name="System.Web"/>
1706 <Reference name="OpenMetaverse" path="../../../../../bin/"/>
1586 <Reference name="OpenMetaverseTypes" path="../../../../../bin/"/> 1707 <Reference name="OpenMetaverseTypes" path="../../../../../bin/"/>
1587 <Reference name="OpenMetaverse.StructuredData" path="../../../../../bin/"/> 1708 <Reference name="OpenMetaverse.StructuredData" path="../../../../../bin/"/>
1588 <Reference name="OpenMetaverse" path="../../../../../bin/"/> 1709
1589 <Reference name="OpenSim.Region.Framework"/> 1710 <Reference name="OpenSim.Region.Framework"/>
1590 <Reference name="OpenSim.Capabilities"/> 1711 <Reference name="OpenSim.Capabilities"/>
1591 <Reference name="OpenSim.Capabilities.Handlers"/> 1712 <Reference name="OpenSim.Capabilities.Handlers"/>
@@ -1600,6 +1721,7 @@
1600 <Reference name="Nini" path="../../../../../bin/"/> 1721 <Reference name="Nini" path="../../../../../bin/"/>
1601 <Reference name="log4net" path="../../../../../bin/"/> 1722 <Reference name="log4net" path="../../../../../bin/"/>
1602 <Reference name="Nini" path="../../../../../bin/"/> 1723 <Reference name="Nini" path="../../../../../bin/"/>
1724 <Reference name="zlib.net" path="../../../../../bin/"/>
1603 1725
1604 <Files> 1726 <Files>
1605 <Match pattern="*.cs" recurse="true"> 1727 <Match pattern="*.cs" recurse="true">
@@ -1667,6 +1789,7 @@
1667 1789
1668 <!-- To allow regions to have mono addins --> 1790 <!-- To allow regions to have mono addins -->
1669 <Reference name="Mono.Addins" path="../../../bin/"/> 1791 <Reference name="Mono.Addins" path="../../../bin/"/>
1792 <Reference name="SmartThreadPool"/>
1670 1793
1671 <Files> 1794 <Files>
1672 <Match buildAction="EmbeddedResource" path="Resources" pattern="*.addin.xml" recurse="true"/> 1795 <Match buildAction="EmbeddedResource" path="Resources" pattern="*.addin.xml" recurse="true"/>
@@ -1748,6 +1871,8 @@
1748 <Reference name="OpenSim.Framework.Servers.HttpServer"/> 1871 <Reference name="OpenSim.Framework.Servers.HttpServer"/>
1749 <Reference name="OpenSim.Region.CoreModules"/> 1872 <Reference name="OpenSim.Region.CoreModules"/>
1750 <Reference name="OpenSim.Region.ClientStack.LindenUDP"/> 1873 <Reference name="OpenSim.Region.ClientStack.LindenUDP"/>
1874 <Reference name="OpenSim.Region.Framework.Interfaces"/>
1875 <Reference name="OpenSim.Region.Framework.Scenes"/>
1751 <Reference name="OpenSim.Region.Framework"/> 1876 <Reference name="OpenSim.Region.Framework"/>
1752 <Reference name="OpenSim.Region.Physics.Manager"/> 1877 <Reference name="OpenSim.Region.Physics.Manager"/>
1753 <Reference name="OpenSim.Server.Base"/> 1878 <Reference name="OpenSim.Server.Base"/>
@@ -3134,6 +3259,7 @@
3134 <Reference name="OpenSim.Framework.Servers.HttpServer"/> 3259 <Reference name="OpenSim.Framework.Servers.HttpServer"/>
3135 <Reference name="OpenSim.Region.ClientStack.LindenCaps"/> 3260 <Reference name="OpenSim.Region.ClientStack.LindenCaps"/>
3136 <Reference name="OpenSim.Region.Framework"/> 3261 <Reference name="OpenSim.Region.Framework"/>
3262 <Reference name="OpenSim.Region.Framework.Interfaces"/>
3137 <Reference name="OpenSim.Region.CoreModules"/> 3263 <Reference name="OpenSim.Region.CoreModules"/>
3138 <Reference name="OpenSim.Region.OptionalModules"/> 3264 <Reference name="OpenSim.Region.OptionalModules"/>
3139 <Reference name="OpenSim.Region.Physics.Manager"/> 3265 <Reference name="OpenSim.Region.Physics.Manager"/>