diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Sun/SunModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Sun/SunModule.cs | 225 |
1 files changed, 115 insertions, 110 deletions
diff --git a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs index a321c09..d0318eb 100644 --- a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs +++ b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs | |||
@@ -68,9 +68,6 @@ namespace OpenSim.Region.CoreModules | |||
68 | // updating those region settings in GenSunPos() | 68 | // updating those region settings in GenSunPos() |
69 | private bool receivedEstateToolsSunUpdate = false; | 69 | private bool receivedEstateToolsSunUpdate = false; |
70 | 70 | ||
71 | // Configurable values | ||
72 | private string m_RegionMode = "SL"; | ||
73 | |||
74 | // Sun's position information is updated and sent to clients every m_UpdateInterval frames | 71 | // Sun's position information is updated and sent to clients every m_UpdateInterval frames |
75 | private int m_UpdateInterval = 0; | 72 | private int m_UpdateInterval = 0; |
76 | 73 | ||
@@ -90,7 +87,6 @@ namespace OpenSim.Region.CoreModules | |||
90 | // private double m_longitude = 0; | 87 | // private double m_longitude = 0; |
91 | // private double m_latitude = 0; | 88 | // private double m_latitude = 0; |
92 | // Configurable defaults Defaults close to SL | 89 | // Configurable defaults Defaults close to SL |
93 | private string d_mode = "SL"; | ||
94 | private int d_frame_mod = 100; // Every 10 seconds (actually less) | 90 | private int d_frame_mod = 100; // Every 10 seconds (actually less) |
95 | private double d_day_length = 4; // A VW day is 4 RW hours long | 91 | private double d_day_length = 4; // A VW day is 4 RW hours long |
96 | private int d_year_length = 60; // There are 60 VW days in a VW year | 92 | private int d_year_length = 60; // There are 60 VW days in a VW year |
@@ -134,12 +130,15 @@ namespace OpenSim.Region.CoreModules | |||
134 | 130 | ||
135 | private const int TICKS_PER_SECOND = 10000000; | 131 | private const int TICKS_PER_SECOND = 10000000; |
136 | 132 | ||
133 | private ulong m_CurrentTimeOffset = 0; | ||
134 | |||
137 | // Current time in elapsed seconds since Jan 1st 1970 | 135 | // Current time in elapsed seconds since Jan 1st 1970 |
138 | private ulong CurrentTime | 136 | private ulong CurrentTime |
139 | { | 137 | { |
140 | get | 138 | get |
141 | { | 139 | { |
142 | return (ulong)(((DateTime.Now.Ticks) - TicksToEpoch + TicksUTCOffset) / TICKS_PER_SECOND); | 140 | ulong ctime = (ulong)(((DateTime.Now.Ticks) - TicksToEpoch + TicksUTCOffset) / TICKS_PER_SECOND); |
141 | return ctime + m_CurrentTimeOffset; | ||
143 | } | 142 | } |
144 | } | 143 | } |
145 | 144 | ||
@@ -252,21 +251,18 @@ namespace OpenSim.Region.CoreModules | |||
252 | } | 251 | } |
253 | 252 | ||
254 | // TODO: Decouple this, so we can get rid of Linden Hour info | 253 | // TODO: Decouple this, so we can get rid of Linden Hour info |
255 | // Update Region infor with new Sun Position and Hour | 254 | // Update Region with new Sun Vector |
256 | // set estate settings for region access to sun position | 255 | // set estate settings for region access to sun position |
257 | if (receivedEstateToolsSunUpdate) | 256 | if (receivedEstateToolsSunUpdate) |
258 | { | 257 | { |
259 | m_scene.RegionInfo.RegionSettings.SunVector = Position; | 258 | m_scene.RegionInfo.RegionSettings.SunVector = Position; |
260 | m_scene.RegionInfo.RegionSettings.SunPosition = GetCurrentTimeAsLindenSunHour(); | ||
261 | } | 259 | } |
262 | } | 260 | } |
263 | 261 | ||
264 | private float GetCurrentTimeAsLindenSunHour() | 262 | private float GetCurrentTimeAsLindenSunHour() |
265 | { | 263 | { |
266 | if (m_SunFixed) | 264 | float curtime = m_SunFixed ? m_SunFixedHour : GetCurrentSunHour(); |
267 | return m_SunFixedHour + 6; | 265 | return (curtime + 6.0f) % 24.0f; |
268 | |||
269 | return GetCurrentSunHour() + 6.0f; | ||
270 | } | 266 | } |
271 | 267 | ||
272 | #region INonSharedRegion Methods | 268 | #region INonSharedRegion Methods |
@@ -292,8 +288,6 @@ namespace OpenSim.Region.CoreModules | |||
292 | try | 288 | try |
293 | { | 289 | { |
294 | // Mode: determines how the sun is handled | 290 | // Mode: determines how the sun is handled |
295 | m_RegionMode = config.Configs["Sun"].GetString("mode", d_mode); | ||
296 | // Mode: determines how the sun is handled | ||
297 | // m_latitude = config.Configs["Sun"].GetDouble("latitude", d_latitude); | 291 | // m_latitude = config.Configs["Sun"].GetDouble("latitude", d_latitude); |
298 | // Mode: determines how the sun is handled | 292 | // Mode: determines how the sun is handled |
299 | // m_longitude = config.Configs["Sun"].GetDouble("longitude", d_longitude); | 293 | // m_longitude = config.Configs["Sun"].GetDouble("longitude", d_longitude); |
@@ -315,7 +309,6 @@ namespace OpenSim.Region.CoreModules | |||
315 | catch (Exception e) | 309 | catch (Exception e) |
316 | { | 310 | { |
317 | m_log.Debug("[SUN]: Configuration access failed, using defaults. Reason: " + e.Message); | 311 | m_log.Debug("[SUN]: Configuration access failed, using defaults. Reason: " + e.Message); |
318 | m_RegionMode = d_mode; | ||
319 | m_YearLengthDays = d_year_length; | 312 | m_YearLengthDays = d_year_length; |
320 | m_DayLengthHours = d_day_length; | 313 | m_DayLengthHours = d_day_length; |
321 | m_HorizonShift = d_day_night; | 314 | m_HorizonShift = d_day_night; |
@@ -326,40 +319,28 @@ namespace OpenSim.Region.CoreModules | |||
326 | // m_longitude = d_longitude; | 319 | // m_longitude = d_longitude; |
327 | } | 320 | } |
328 | 321 | ||
329 | switch (m_RegionMode) | 322 | SecondsPerSunCycle = (uint) (m_DayLengthHours * 60 * 60); |
330 | { | 323 | SecondsPerYear = (uint) (SecondsPerSunCycle*m_YearLengthDays); |
331 | case "T1": | ||
332 | default: | ||
333 | case "SL": | ||
334 | // Time taken to complete a cycle (day and season) | ||
335 | |||
336 | SecondsPerSunCycle = (uint) (m_DayLengthHours * 60 * 60); | ||
337 | SecondsPerYear = (uint) (SecondsPerSunCycle*m_YearLengthDays); | ||
338 | |||
339 | // Ration of real-to-virtual time | ||
340 | 324 | ||
341 | // VWTimeRatio = 24/m_day_length; | 325 | // Ration of real-to-virtual time |
342 | 326 | ||
343 | // Speed of rotation needed to complete a cycle in the | 327 | // VWTimeRatio = 24/m_day_length; |
344 | // designated period (day and season) | ||
345 | 328 | ||
346 | SunSpeed = m_SunCycle/SecondsPerSunCycle; | 329 | // Speed of rotation needed to complete a cycle in the |
347 | SeasonSpeed = m_SeasonalCycle/SecondsPerYear; | 330 | // designated period (day and season) |
348 | 331 | ||
349 | // Horizon translation | 332 | SunSpeed = m_SunCycle/SecondsPerSunCycle; |
333 | SeasonSpeed = m_SeasonalCycle/SecondsPerYear; | ||
350 | 334 | ||
351 | HorizonShift = m_HorizonShift; // Z axis translation | 335 | // Horizon translation |
352 | // HoursToRadians = (SunCycle/24)*VWTimeRatio; | ||
353 | 336 | ||
354 | m_log.Debug("[SUN]: Mode is " + m_RegionMode); | 337 | HorizonShift = m_HorizonShift; // Z axis translation |
355 | m_log.Debug("[SUN]: Initialization completed. Day is " + SecondsPerSunCycle + " seconds, and year is " + m_YearLengthDays + " days"); | 338 | // HoursToRadians = (SunCycle/24)*VWTimeRatio; |
356 | m_log.Debug("[SUN]: Axis offset is " + m_HorizonShift); | ||
357 | m_log.Debug("[SUN]: Percentage of time for daylight " + m_DayTimeSunHourScale); | ||
358 | m_log.Debug("[SUN]: Positional data updated every " + m_UpdateInterval + " frames"); | ||
359 | |||
360 | break; | ||
361 | } | ||
362 | 339 | ||
340 | m_log.Debug("[SUN]: Initialization completed. Day is " + SecondsPerSunCycle + " seconds, and year is " + m_YearLengthDays + " days"); | ||
341 | m_log.Debug("[SUN]: Axis offset is " + m_HorizonShift); | ||
342 | m_log.Debug("[SUN]: Percentage of time for daylight " + m_DayTimeSunHourScale); | ||
343 | m_log.Debug("[SUN]: Positional data updated every " + m_UpdateInterval + " frames"); | ||
363 | } | 344 | } |
364 | 345 | ||
365 | public Type ReplaceableInterface | 346 | public Type ReplaceableInterface |
@@ -386,7 +367,8 @@ namespace OpenSim.Region.CoreModules | |||
386 | string sunCommand = string.Format("sun {0}", kvp.Key); | 367 | string sunCommand = string.Format("sun {0}", kvp.Key); |
387 | m_scene.AddCommand("Regions", this, sunCommand, string.Format("{0} [<value>]", sunCommand), kvp.Value, "", HandleSunConsoleCommand); | 368 | m_scene.AddCommand("Regions", this, sunCommand, string.Format("{0} [<value>]", sunCommand), kvp.Value, "", HandleSunConsoleCommand); |
388 | } | 369 | } |
389 | 370 | m_scene.AddCommand("Regions", this, "sun help", "sun help", "list parameters that can be changed", "", HandleSunConsoleCommand); | |
371 | m_scene.AddCommand("Regions", this, "sun list", "sun list", "list parameters that can be changed", "", HandleSunConsoleCommand); | ||
390 | ready = true; | 372 | ready = true; |
391 | } | 373 | } |
392 | 374 | ||
@@ -395,7 +377,7 @@ namespace OpenSim.Region.CoreModules | |||
395 | ready = false; | 377 | ready = false; |
396 | 378 | ||
397 | // Remove our hooks | 379 | // Remove our hooks |
398 | m_scene.EventManager.OnFrame -= SunUpdate; | 380 | m_scene.EventManager.OnFrame -= SunUpdate; |
399 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; | 381 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; |
400 | m_scene.EventManager.OnEstateToolsSunUpdate -= EstateToolsSunUpdate; | 382 | m_scene.EventManager.OnEstateToolsSunUpdate -= EstateToolsSunUpdate; |
401 | m_scene.EventManager.OnGetCurrentTimeAsLindenSunHour -= GetCurrentTimeAsLindenSunHour; | 383 | m_scene.EventManager.OnGetCurrentTimeAsLindenSunHour -= GetCurrentTimeAsLindenSunHour; |
@@ -420,23 +402,22 @@ namespace OpenSim.Region.CoreModules | |||
420 | 402 | ||
421 | public void SunToClient(IClientAPI client) | 403 | public void SunToClient(IClientAPI client) |
422 | { | 404 | { |
423 | if (m_RegionMode != "T1") | 405 | if (ready) |
424 | { | 406 | { |
425 | if (ready) | 407 | if (m_SunFixed) |
426 | { | 408 | { |
427 | if (m_SunFixed) | 409 | // m_log.DebugFormat("[SUN]: Fixed SunHour {0}, Position {1}, PosTime {2}, OrbitalPosition : {3} ", |
428 | { | 410 | // m_SunFixedHour, Position.ToString(), PosTime.ToString(), OrbitalPosition.ToString()); |
429 | // m_log.DebugFormat("[SUN]: SunHour {0}, Position {1}, PosTime {2}, OrbitalPosition : {3} ", m_SunFixedHour, Position.ToString(), PosTime.ToString(), OrbitalPosition.ToString()); | 411 | client.SendSunPos(Position, Velocity, PosTime, SecondsPerSunCycle, SecondsPerYear, OrbitalPosition); |
430 | client.SendSunPos(Position, Velocity, PosTime, SecondsPerSunCycle, SecondsPerYear, OrbitalPosition); | 412 | } |
431 | } | 413 | else |
432 | else | 414 | { |
433 | { | 415 | // m_log.DebugFormat("[SUN]: SunHour {0}, Position {1}, PosTime {2}, OrbitalPosition : {3} ", |
434 | // m_log.DebugFormat("[SUN]: SunHour {0}, Position {1}, PosTime {2}, OrbitalPosition : {3} ", m_SunFixedHour, Position.ToString(), PosTime.ToString(), OrbitalPosition.ToString()); | 416 | // m_SunFixedHour, Position.ToString(), PosTime.ToString(), OrbitalPosition.ToString()); |
435 | client.SendSunPos(Position, Velocity, CurrentTime, SecondsPerSunCycle, SecondsPerYear, OrbitalPosition); | 417 | client.SendSunPos(Position, Velocity, CurrentTime, SecondsPerSunCycle, SecondsPerYear, OrbitalPosition); |
436 | } | ||
437 | } | 418 | } |
438 | } | 419 | } |
439 | } | 420 | } |
440 | 421 | ||
441 | public void SunUpdate() | 422 | public void SunUpdate() |
442 | { | 423 | { |
@@ -459,26 +440,33 @@ namespace OpenSim.Region.CoreModules | |||
459 | SunToClient(avatar.ControllingClient); | 440 | SunToClient(avatar.ControllingClient); |
460 | } | 441 | } |
461 | 442 | ||
462 | /// <summary> | 443 | public void EstateToolsSunUpdate(ulong regionHandle) |
463 | /// | ||
464 | /// </summary> | ||
465 | /// <param name="regionHandle"></param> | ||
466 | /// <param name="FixedTime">Is the sun's position fixed?</param> | ||
467 | /// <param name="useEstateTime">Use the Region or Estate Sun hour?</param> | ||
468 | /// <param name="FixedSunHour">What hour of the day is the Sun Fixed at?</param> | ||
469 | public void EstateToolsSunUpdate(ulong regionHandle, bool FixedSun, bool useEstateTime, float FixedSunHour) | ||
470 | { | 444 | { |
471 | if (m_scene.RegionInfo.RegionHandle == regionHandle) | 445 | if (m_scene.RegionInfo.RegionHandle == regionHandle) |
472 | { | 446 | { |
473 | // Must limit the Sun Hour to 0 ... 24 | 447 | float sunFixedHour; |
474 | while (FixedSunHour > 24.0f) | 448 | bool fixedSun; |
475 | FixedSunHour -= 24; | ||
476 | 449 | ||
477 | while (FixedSunHour < 0) | 450 | if (m_scene.RegionInfo.RegionSettings.UseEstateSun) |
478 | FixedSunHour += 24; | 451 | { |
452 | sunFixedHour = (float)m_scene.RegionInfo.EstateSettings.SunPosition; | ||
453 | fixedSun = m_scene.RegionInfo.EstateSettings.FixedSun; | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | sunFixedHour = (float)m_scene.RegionInfo.RegionSettings.SunPosition - 6.0f; | ||
458 | fixedSun = m_scene.RegionInfo.RegionSettings.FixedSun; | ||
459 | } | ||
460 | |||
461 | // Must limit the Sun Hour to 0 ... 24 | ||
462 | while (sunFixedHour > 24.0f) | ||
463 | sunFixedHour -= 24; | ||
479 | 464 | ||
480 | m_SunFixedHour = FixedSunHour; | 465 | while (sunFixedHour < 0) |
481 | m_SunFixed = FixedSun; | 466 | sunFixedHour += 24; |
467 | |||
468 | m_SunFixedHour = sunFixedHour; | ||
469 | m_SunFixed = fixedSun; | ||
482 | 470 | ||
483 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Fixed Sun? : {0}", m_SunFixed.ToString()); | 471 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Fixed Sun? : {0}", m_SunFixed.ToString()); |
484 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Sun Hour : {0}", m_SunFixedHour.ToString()); | 472 | // m_log.DebugFormat("[SUN]: Sun Settings Update: Sun Hour : {0}", m_SunFixedHour.ToString()); |
@@ -501,7 +489,7 @@ namespace OpenSim.Region.CoreModules | |||
501 | { | 489 | { |
502 | m_scene.ForEachRootClient(delegate(IClientAPI client) | 490 | m_scene.ForEachRootClient(delegate(IClientAPI client) |
503 | { | 491 | { |
504 | SunToClient(client); | 492 | SunToClient(client); |
505 | }); | 493 | }); |
506 | } | 494 | } |
507 | 495 | ||
@@ -526,6 +514,9 @@ namespace OpenSim.Region.CoreModules | |||
526 | case "update_interval": | 514 | case "update_interval": |
527 | return m_UpdateInterval; | 515 | return m_UpdateInterval; |
528 | 516 | ||
517 | case "current_time": | ||
518 | return GetCurrentTimeAsLindenSunHour(); | ||
519 | |||
529 | default: | 520 | default: |
530 | throw new Exception("Unknown sun parameter."); | 521 | throw new Exception("Unknown sun parameter."); |
531 | } | 522 | } |
@@ -533,7 +524,51 @@ namespace OpenSim.Region.CoreModules | |||
533 | 524 | ||
534 | public void SetSunParameter(string param, double value) | 525 | public void SetSunParameter(string param, double value) |
535 | { | 526 | { |
536 | HandleSunConsoleCommand("sun", new string[] {param, value.ToString() }); | 527 | switch (param) |
528 | { | ||
529 | case "year_length": | ||
530 | m_YearLengthDays = (int)value; | ||
531 | SecondsPerYear = (uint) (SecondsPerSunCycle*m_YearLengthDays); | ||
532 | SeasonSpeed = m_SeasonalCycle/SecondsPerYear; | ||
533 | break; | ||
534 | |||
535 | case "day_length": | ||
536 | m_DayLengthHours = value; | ||
537 | SecondsPerSunCycle = (uint) (m_DayLengthHours * 60 * 60); | ||
538 | SecondsPerYear = (uint) (SecondsPerSunCycle*m_YearLengthDays); | ||
539 | SunSpeed = m_SunCycle/SecondsPerSunCycle; | ||
540 | SeasonSpeed = m_SeasonalCycle/SecondsPerYear; | ||
541 | break; | ||
542 | |||
543 | case "day_night_offset": | ||
544 | m_HorizonShift = value; | ||
545 | HorizonShift = m_HorizonShift; | ||
546 | break; | ||
547 | |||
548 | case "day_time_sun_hour_scale": | ||
549 | m_DayTimeSunHourScale = value; | ||
550 | break; | ||
551 | |||
552 | case "update_interval": | ||
553 | m_UpdateInterval = (int)value; | ||
554 | break; | ||
555 | |||
556 | case "current_time": | ||
557 | value = (value + 18.0) % 24.0; | ||
558 | // set the current offset so that the effective sun time is the parameter | ||
559 | m_CurrentTimeOffset = 0; // clear this first so we use raw time | ||
560 | m_CurrentTimeOffset = (ulong)(SecondsPerSunCycle * value/ 24.0) - (CurrentTime % SecondsPerSunCycle); | ||
561 | break; | ||
562 | |||
563 | default: | ||
564 | throw new Exception("Unknown sun parameter."); | ||
565 | } | ||
566 | |||
567 | // Generate shared values | ||
568 | GenSunPos(); | ||
569 | |||
570 | // When sun settings are updated, we should update all clients with new settings. | ||
571 | SunUpdateToAllClients(); | ||
537 | } | 572 | } |
538 | 573 | ||
539 | public float GetCurrentSunHour() | 574 | public float GetCurrentSunHour() |
@@ -566,7 +601,7 @@ namespace OpenSim.Region.CoreModules | |||
566 | 601 | ||
567 | foreach (string output in ParseCmdParams(cmdparams)) | 602 | foreach (string output in ParseCmdParams(cmdparams)) |
568 | { | 603 | { |
569 | m_log.Info("[SUN] " + output); | 604 | MainConsole.Instance.Output(output); |
570 | } | 605 | } |
571 | } | 606 | } |
572 | 607 | ||
@@ -575,10 +610,11 @@ namespace OpenSim.Region.CoreModules | |||
575 | Dictionary<string, string> Params = new Dictionary<string, string>(); | 610 | Dictionary<string, string> Params = new Dictionary<string, string>(); |
576 | 611 | ||
577 | Params.Add("year_length", "number of days to a year"); | 612 | Params.Add("year_length", "number of days to a year"); |
578 | Params.Add("day_length", "number of seconds to a day"); | 613 | Params.Add("day_length", "number of hours to a day"); |
579 | Params.Add("day_night_offset", "induces a horizon shift"); | 614 | Params.Add("day_night_offset", "induces a horizon shift"); |
580 | Params.Add("update_interval", "how often to update the sun's position in frames"); | 615 | Params.Add("update_interval", "how often to update the sun's position in frames"); |
581 | Params.Add("day_time_sun_hour_scale", "scales day light vs nite hours to change day/night ratio"); | 616 | Params.Add("day_time_sun_hour_scale", "scales day light vs nite hours to change day/night ratio"); |
617 | Params.Add("current_time", "time in seconds of the simulator"); | ||
582 | 618 | ||
583 | return Params; | 619 | return Params; |
584 | } | 620 | } |
@@ -612,46 +648,15 @@ namespace OpenSim.Region.CoreModules | |||
612 | } | 648 | } |
613 | else if (args.Length == 3) | 649 | else if (args.Length == 3) |
614 | { | 650 | { |
615 | float value = 0.0f; | 651 | double value = 0.0; |
616 | if (!float.TryParse(args[2], out value)) | 652 | if (! double.TryParse(args[2], out value)) |
617 | { | 653 | { |
618 | Output.Add(String.Format("The parameter value {0} is not a valid number.", args[2])); | 654 | Output.Add(String.Format("The parameter value {0} is not a valid number.", args[2])); |
655 | return Output; | ||
619 | } | 656 | } |
620 | 657 | ||
621 | switch (args[1].ToLower()) | 658 | SetSunParameter(args[1].ToLower(), value); |
622 | { | ||
623 | case "year_length": | ||
624 | m_YearLengthDays = (int)value; | ||
625 | break; | ||
626 | |||
627 | case "day_length": | ||
628 | m_DayLengthHours = value; | ||
629 | break; | ||
630 | |||
631 | case "day_night_offset": | ||
632 | m_HorizonShift = value; | ||
633 | break; | ||
634 | |||
635 | case "day_time_sun_hour_scale": | ||
636 | m_DayTimeSunHourScale = value; | ||
637 | break; | ||
638 | |||
639 | case "update_interval": | ||
640 | m_UpdateInterval = (int)value; | ||
641 | break; | ||
642 | |||
643 | default: | ||
644 | Output.Add(String.Format("Unknown parameter {0}.", args[1])); | ||
645 | return Output; | ||
646 | } | ||
647 | |||
648 | Output.Add(String.Format("Parameter {0} set to {1}.", args[1], value.ToString())); | 659 | Output.Add(String.Format("Parameter {0} set to {1}.", args[1], value.ToString())); |
649 | |||
650 | // Generate shared values | ||
651 | GenSunPos(); | ||
652 | |||
653 | // When sun settings are updated, we should update all clients with new settings. | ||
654 | SunUpdateToAllClients(); | ||
655 | } | 660 | } |
656 | 661 | ||
657 | return Output; | 662 | return Output; |