IdGenerater.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. namespace ETModel
  2. {
  3. public static class IdGenerater
  4. {
  5. public const int HeadPos = 50;
  6. private static long appId;
  7. public static long Head { get; private set; }
  8. public static long AppId
  9. {
  10. set
  11. {
  12. appId = value;
  13. Head = value << HeadPos;
  14. }
  15. get
  16. {
  17. return appId;
  18. }
  19. }
  20. public static long HeadMask = 0x0003ffffffffffff;
  21. private static ushort value;
  22. private static int sceneId = 100000;
  23. public static long GenerateSceneId()
  24. {
  25. return ++sceneId;
  26. }
  27. public static long GenerateSceneInstanceId(long id)
  28. {
  29. return IdGenerater.Head + id;
  30. }
  31. public static long GenerateId()
  32. {
  33. long time = TimeHelper.ClientNowSeconds();
  34. return Head + (time << 18) + ++value;
  35. }
  36. public static int GetProcessId(long v)
  37. {
  38. return (int)(v >> HeadPos);
  39. }
  40. }
  41. }