2
0

simDatablock.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "sim/simBase.h"
  23. #include "console/consoleTypes.h"
  24. #include "sim/scriptObject.h"
  25. #include "sim/simDatablock.h"
  26. //-----------------------------------------------------------------------------
  27. IMPLEMENT_CO_DATABLOCK_V1(SimDataBlock);
  28. SimObjectId SimDataBlock::sNextObjectId = DataBlockObjectIdFirst;
  29. S32 SimDataBlock::sNextModifiedKey = 0;
  30. //---------------------------------------------------------------------------
  31. SimDataBlock::SimDataBlock()
  32. {
  33. setModDynamicFields(true);
  34. setModStaticFields(true);
  35. }
  36. bool SimDataBlock::onAdd()
  37. {
  38. Parent::onAdd();
  39. // This initialization is done here, and not in the constructor,
  40. // because some jokers like to construct and destruct objects
  41. // (without adding them to the manager) to check what class
  42. // they are.
  43. modifiedKey = ++sNextModifiedKey;
  44. AssertFatal(sNextObjectId <= DataBlockObjectIdLast,
  45. "Exceeded maximum number of data blocks");
  46. // add DataBlock to the DataBlockGroup unless it is client side ONLY DataBlock
  47. if (getId() >= DataBlockObjectIdFirst && getId() <= DataBlockObjectIdLast)
  48. if (SimGroup* grp = Sim::getDataBlockGroup())
  49. grp->addObject(this);
  50. return true;
  51. }
  52. void SimDataBlock::onRemove()
  53. {
  54. Parent::onRemove();
  55. }
  56. void SimDataBlock::assignId()
  57. {
  58. // We don't want the id assigned by the manager, but it may have
  59. // already been assigned a correct data block id.
  60. if (getId() < DataBlockObjectIdFirst || getId() > DataBlockObjectIdLast)
  61. setId(sNextObjectId++);
  62. }
  63. void SimDataBlock::onStaticModified(const char* slotName, const char* newValue)
  64. {
  65. modifiedKey = sNextModifiedKey++;
  66. }
  67. /*void SimDataBlock::setLastError(const char*)
  68. {
  69. } */
  70. void SimDataBlock::packData(BitStream*)
  71. {
  72. }
  73. void SimDataBlock::unpackData(BitStream*)
  74. {
  75. }
  76. bool SimDataBlock::preload(bool, char[256])
  77. {
  78. return true;
  79. }
  80. ConsoleFunction(deleteDataBlocks, void, 1, 1, "() Use the deleteDataBlocks function to cause a server to delete all datablocks that have thus far been loaded and defined.\n"
  81. "This is usually done in preparation of downloading a new set of datablocks, such as occurs on a mission change, but it's also good post-mission cleanup\n"
  82. "@return No return value.")
  83. {
  84. // delete from last to first:
  85. SimGroup *grp = Sim::getDataBlockGroup();
  86. for(S32 i = grp->size() - 1; i >= 0; i--)
  87. {
  88. SimObject *obj = (*grp)[i];
  89. obj->deleteObject();
  90. }
  91. SimDataBlock::sNextObjectId = DataBlockObjectIdFirst;
  92. SimDataBlock::sNextModifiedKey = 0;
  93. }