Annotation of /trunk/ModularRex/RexParts/RexPython/RexEventManager.cs
Parent Directory
|
Revision Log
Revision 12 - (view) (download)
| 1 : | mikkopa | 12 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | using System.Text; | ||
| 4 : | using OpenMetaverse; | ||
| 5 : | using OpenSim.Framework; | ||
| 6 : | using OpenSim.Region.Environment.Scenes; | ||
| 7 : | |||
| 8 : | namespace ModularRex.RexParts.RexPython | ||
| 9 : | { | ||
| 10 : | [Serializable] | ||
| 11 : | class RexEventManager | ||
| 12 : | { | ||
| 13 : | private RexScriptEngine myScriptEngine; | ||
| 14 : | |||
| 15 : | // tuco fixme, is there a better way to do this search??? | ||
| 16 : | private EntityBase GetEntityBase(uint vId) | ||
| 17 : | { | ||
| 18 : | SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(vId); | ||
| 19 : | if (part != null && (EntityBase)(part.ParentGroup) != null) | ||
| 20 : | return (EntityBase)(part.ParentGroup); | ||
| 21 : | else | ||
| 22 : | return null; | ||
| 23 : | } | ||
| 24 : | |||
| 25 : | public RexEventManager(RexScriptEngine vScriptEngine) | ||
| 26 : | { | ||
| 27 : | myScriptEngine = vScriptEngine; | ||
| 28 : | myScriptEngine.Log.InfoFormat("[RexScriptEngine]: Hooking up to server events"); | ||
| 29 : | myScriptEngine.World.EventManager.OnObjectGrab += touch_start; | ||
| 30 : | // myScriptEngine.World.EventManager.OnRezScript += OnRezScript; | ||
| 31 : | // myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript; | ||
| 32 : | // myScriptEngine.World.EventManager.OnFrame += OnFrame; | ||
| 33 : | //myScriptEngine.World.EventManager.OnNewClient += OnNewClient; | ||
| 34 : | myScriptEngine.World.EventManager.OnNewPresence += OnNewPresence; | ||
| 35 : | myScriptEngine.World.EventManager.OnRemovePresence += OnRemovePresence; | ||
| 36 : | myScriptEngine.World.EventManager.OnShutdown += OnShutDown; | ||
| 37 : | |||
| 38 : | ///TODO: | ||
| 39 : | ///These events were added to forked version. Some of them can be handled | ||
| 40 : | ///other way, some need changes to core and some need changes to physics engine. | ||
| 41 : | //myScriptEngine.World.EventManager.OnAddEntity += OnAddEntity; | ||
| 42 : | //myScriptEngine.World.EventManager.OnRemoveEntity += OnRemoveEntity; | ||
| 43 : | //myScriptEngine.World.EventManager.OnPythonScriptCommand += OnPythonScriptCommand; | ||
| 44 : | //myScriptEngine.World.EventManager.OnPythonClassChange += OnPythonClassChange; | ||
| 45 : | //myScriptEngine.World.EventManager.OnRexClientScriptCommand += OnRexClientScriptCommand; | ||
| 46 : | //myScriptEngine.World.EventManager.OnPrimVolumeCollision += OnPrimVolumeCollision; | ||
| 47 : | //myScriptEngine.World.EventManager.OnRexScriptListen += OnRexScriptListen; | ||
| 48 : | //myScriptEngine.World.EventManager.OnRexClientStartUp += OnRexClientStartUp; | ||
| 49 : | |||
| 50 : | } | ||
| 51 : | |||
| 52 : | |||
| 53 : | public void touch_start(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient)//(uint localID, Vector3 offsetPos, IClientAPI remoteClient) | ||
| 54 : | { | ||
| 55 : | string EventParams = "\"touch_start\"," + localID.ToString() + "," + "\"" + remoteClient.AgentId.ToString() + "\""; | ||
| 56 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 57 : | } | ||
| 58 : | |||
| 59 : | /* | ||
| 60 : | public void OnRezScript(uint localID, UUID itemID, string script) | ||
| 61 : | { | ||
| 62 : | |||
| 63 : | } | ||
| 64 : | public void OnRemoveScript(uint localID, UUID itemID) | ||
| 65 : | { | ||
| 66 : | |||
| 67 : | } | ||
| 68 : | |||
| 69 : | public void OnFrame() | ||
| 70 : | { | ||
| 71 : | |||
| 72 : | } | ||
| 73 : | |||
| 74 : | public void OnNewClient(IClientAPI vClient) | ||
| 75 : | { | ||
| 76 : | string EventParams = "\"new_client\"," + "\"" + vClient.AgentId.ToString() + "\""; | ||
| 77 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 78 : | } | ||
| 79 : | */ | ||
| 80 : | |||
| 81 : | public void OnNewPresence(ScenePresence vPresence) | ||
| 82 : | { | ||
| 83 : | try | ||
| 84 : | { | ||
| 85 : | if (vPresence.ControllingClient is IRexBot) | ||
| 86 : | { | ||
| 87 : | string EventParams = "\"add_bot\"," + vPresence.LocalId.ToString() + "," + "\"" + vPresence.UUID.ToString() + "\""; | ||
| 88 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 89 : | } | ||
| 90 : | else | ||
| 91 : | { | ||
| 92 : | string EventParams = "\"add_presence\"," + vPresence.LocalId.ToString() + "," + "\"" + vPresence.UUID.ToString() + "\""; | ||
| 93 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 94 : | } | ||
| 95 : | } | ||
| 96 : | catch (Exception e) | ||
| 97 : | { | ||
| 98 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnNewPresence: " + e.ToString()); | ||
| 99 : | } | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | public void OnRemovePresence(UUID uuid) | ||
| 103 : | { | ||
| 104 : | try | ||
| 105 : | { | ||
| 106 : | // python handles if this presence was bot or human | ||
| 107 : | string EventParams = "\"remove_presence\"," + "\"" + uuid.ToString() + "\""; | ||
| 108 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 109 : | } | ||
| 110 : | catch (Exception e) | ||
| 111 : | { | ||
| 112 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRemovePresence: " + e.ToString()); | ||
| 113 : | } | ||
| 114 : | } | ||
| 115 : | |||
| 116 : | public void OnShutDown() | ||
| 117 : | { | ||
| 118 : | Console.WriteLine("REX OnShutDown"); | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | public void OnAddEntity(uint localID) | ||
| 122 : | { | ||
| 123 : | try | ||
| 124 : | { | ||
| 125 : | string PythonClassName = "rxactor.Actor"; | ||
| 126 : | string PythonTag = ""; | ||
| 127 : | |||
| 128 : | RexObjects.RexObjectGroup tempobj = (RexObjects.RexObjectGroup)GetEntityBase(localID); | ||
| 129 : | //SceneObjectGroup tempobj = (SceneObjectGroup)GetEntityBase(localID); | ||
| 130 : | if (tempobj != null && tempobj.RootPart != null && tempobj.RootPart.RexClassName.Length > 0) | ||
| 131 : | PythonClassName = tempobj.RootPart.RexClassName; | ||
| 132 : | |||
| 133 : | // Create the actor directly without using an event. | ||
| 134 : | myScriptEngine.CreateActorToPython(localID.ToString(), PythonClassName, PythonTag); | ||
| 135 : | } | ||
| 136 : | catch (Exception e) | ||
| 137 : | { | ||
| 138 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnAddEntity: " + e.ToString()); | ||
| 139 : | } | ||
| 140 : | } | ||
| 141 : | |||
| 142 : | public void OnRemoveEntity(uint localID) | ||
| 143 : | { | ||
| 144 : | try | ||
| 145 : | { | ||
| 146 : | string EventParams = "\"remove_entity\"," + "\"" + localID.ToString() + "\""; | ||
| 147 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 148 : | } | ||
| 149 : | catch (Exception e) | ||
| 150 : | { | ||
| 151 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRemoveEntity: " + e.ToString()); | ||
| 152 : | } | ||
| 153 : | } | ||
| 154 : | |||
| 155 : | public void OnPythonScriptCommand(string vCommand) | ||
| 156 : | { | ||
| 157 : | try | ||
| 158 : | { | ||
| 159 : | if (vCommand.ToLower() == "restart") | ||
| 160 : | myScriptEngine.RestartPythonEngine(); | ||
| 161 : | else | ||
| 162 : | Console.WriteLine("Unknown PythonScriptEngine command:"+vCommand); | ||
| 163 : | } | ||
| 164 : | catch (Exception e) | ||
| 165 : | { | ||
| 166 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPythonScriptCommand: " + e.ToString()); | ||
| 167 : | } | ||
| 168 : | } | ||
| 169 : | |||
| 170 : | public void OnPythonClassChange(uint localID) | ||
| 171 : | { | ||
| 172 : | try | ||
| 173 : | { | ||
| 174 : | string PythonClassName = "rxactor.Actor"; | ||
| 175 : | string PythonTag = ""; | ||
| 176 : | |||
| 177 : | RexObjects.RexObjectGroup tempobj = (RexObjects.RexObjectGroup)GetEntityBase(localID); | ||
| 178 : | //SceneObjectGroup tempobj = (SceneObjectGroup)GetEntityBase(localID); | ||
| 179 : | if (tempobj != null && tempobj.RootPart != null && tempobj.RootPart.RexClassName.Length > 0) | ||
| 180 : | { | ||
| 181 : | int tagindex = tempobj.RootPart.RexClassName.IndexOf("?", 0); | ||
| 182 : | if (tagindex > -1) | ||
| 183 : | { | ||
| 184 : | PythonClassName = tempobj.RootPart.RexClassName.Substring(0, tagindex); | ||
| 185 : | PythonTag = tempobj.RootPart.RexClassName.Substring(tagindex + 1); | ||
| 186 : | } | ||
| 187 : | else | ||
| 188 : | PythonClassName = tempobj.RootPart.RexClassName; | ||
| 189 : | } | ||
| 190 : | if (myScriptEngine.IsEngineStarted) | ||
| 191 : | myScriptEngine.CreateActorToPython(localID.ToString(), PythonClassName, PythonTag); | ||
| 192 : | } | ||
| 193 : | catch (Exception e) | ||
| 194 : | { | ||
| 195 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPythonClassChange: " + e.ToString()); | ||
| 196 : | } | ||
| 197 : | } | ||
| 198 : | |||
| 199 : | public void OnRexClientScriptCommand(ScenePresence avatar, List<string> vCommands) | ||
| 200 : | { | ||
| 201 : | try | ||
| 202 : | { | ||
| 203 : | string Paramlist = ""; | ||
| 204 : | foreach (string s in vCommands) | ||
| 205 : | Paramlist = Paramlist + "," + "\"" + s + "\""; | ||
| 206 : | |||
| 207 : | string EventParams = "\"client_event\",\"" + avatar.UUID.ToString() + "\"" + Paramlist; | ||
| 208 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 209 : | } | ||
| 210 : | catch (Exception e) | ||
| 211 : | { | ||
| 212 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexClientScriptCommand: " + e.ToString()); | ||
| 213 : | } | ||
| 214 : | } | ||
| 215 : | |||
| 216 : | public void OnPrimVolumeCollision(uint ownID, uint colliderID) | ||
| 217 : | { | ||
| 218 : | try | ||
| 219 : | { | ||
| 220 : | string EventParams = "\"primvol_col\"," + ownID.ToString() + "," + "\"" + colliderID.ToString() + "\""; | ||
| 221 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 222 : | } | ||
| 223 : | catch (Exception e) | ||
| 224 : | { | ||
| 225 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPrimVolumeCollision: " + e.ToString()); | ||
| 226 : | } | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | public void OnRexScriptListen(uint vPrimLocalId, int vChannel, string vName, UUID vId, string vMessage) | ||
| 230 : | { | ||
| 231 : | try | ||
| 232 : | { | ||
| 233 : | SceneObjectPart source = null; | ||
| 234 : | ScenePresence avatar = null; | ||
| 235 : | string sid = "0"; | ||
| 236 : | |||
| 237 : | source = myScriptEngine.World.GetSceneObjectPart(vId); | ||
| 238 : | if (source != null) | ||
| 239 : | { | ||
| 240 : | if ((EntityBase)(source.ParentGroup) != null) | ||
| 241 : | sid = ((EntityBase)source.ParentGroup).LocalId.ToString(); | ||
| 242 : | } | ||
| 243 : | else | ||
| 244 : | { | ||
| 245 : | avatar = myScriptEngine.World.GetScenePresence(vId); | ||
| 246 : | if(avatar != null) | ||
| 247 : | sid = avatar.UUID.ToString(); | ||
| 248 : | } | ||
| 249 : | |||
| 250 : | string EventParams = "\"listen\"," + vPrimLocalId.ToString() + "," + vChannel.ToString() + "," + | ||
| 251 : | "\"" + vName + "\"" + "," + "\"" + sid + "\"" + "," + "\"" + vMessage.ToString() + "\""; | ||
| 252 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 253 : | } | ||
| 254 : | catch (Exception e) | ||
| 255 : | { | ||
| 256 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexScriptListen: " + e.ToString()); | ||
| 257 : | } | ||
| 258 : | } | ||
| 259 : | |||
| 260 : | public void OnRexClientStartUp(ScenePresence avatar, string vStatus) | ||
| 261 : | { | ||
| 262 : | try | ||
| 263 : | { | ||
| 264 : | string EventParams = "\"client_startup\",\"" + avatar.UUID.ToString() + "\",\"" + vStatus + "\""; | ||
| 265 : | myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); | ||
| 266 : | } | ||
| 267 : | catch (Exception e) | ||
| 268 : | { | ||
| 269 : | myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexClientStartUp: " + e.ToString()); | ||
| 270 : | } | ||
| 271 : | } | ||
| 272 : | |||
| 273 : | |||
| 274 : | |||
| 275 : | |||
| 276 : | // TODO: Replace placeholders below | ||
| 277 : | // These needs to be hooked up to OpenSim during init of this class. | ||
| 278 : | // When queued in EventQueueManager they need to be LSL compatible (name and params) | ||
| 279 : | |||
| 280 : | //public void state_entry() { } // | ||
| 281 : | public void state_exit() { } | ||
| 282 : | //public void touch_start() { } | ||
| 283 : | public void touch() { } | ||
| 284 : | public void touch_end() { } | ||
| 285 : | public void collision_start() { } | ||
| 286 : | public void collision() { } | ||
| 287 : | public void collision_end() { } | ||
| 288 : | public void land_collision_start() { } | ||
| 289 : | public void land_collision() { } | ||
| 290 : | public void land_collision_end() { } | ||
| 291 : | public void timer() { } | ||
| 292 : | public void listen() { } | ||
| 293 : | public void on_rez() { } | ||
| 294 : | public void sensor() { } | ||
| 295 : | public void no_sensor() { } | ||
| 296 : | public void control() { } | ||
| 297 : | public void money() { } | ||
| 298 : | public void email() { } | ||
| 299 : | public void at_target() { } | ||
| 300 : | public void not_at_target() { } | ||
| 301 : | public void at_rot_target() { } | ||
| 302 : | public void not_at_rot_target() { } | ||
| 303 : | public void run_time_permissions() { } | ||
| 304 : | public void changed() { } | ||
| 305 : | public void attach() { } | ||
| 306 : | public void dataserver() { } | ||
| 307 : | public void link_message() { } | ||
| 308 : | public void moving_start() { } | ||
| 309 : | public void moving_end() { } | ||
| 310 : | public void object_rez() { } | ||
| 311 : | public void remote_data() { } | ||
| 312 : | public void http_response() { } | ||
| 313 : | |||
| 314 : | } | ||
| 315 : | |||
| 316 : | |||
| 317 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

