Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

PhysicsScriptTable.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/PhysicsScriptTable.h"
  19. #include "BinReader.h"
  20. static void read(BinReader& reader, PhysicsScriptTableData& scripts)
  21. {
  22. uint32_t numScripts = reader.readInt();
  23. scripts.scripts.resize(numScripts);
  24. for(ScriptAndModData& script : scripts.scripts)
  25. {
  26. script.mod = reader.readFloat();
  27. script.scriptId = reader.readInt();
  28. assert((script.scriptId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kPhysicsScript));
  29. }
  30. }
  31. PhysicsScriptTable::PhysicsScriptTable(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  32. {
  33. BinReader reader(data, size);
  34. uint32_t resourceId = reader.readInt();
  35. assert(resourceId == id);
  36. UNUSED(resourceId);
  37. uint32_t scriptTableSize = reader.readInt();
  38. for(uint32_t i = 0; i < scriptTableSize; i++)
  39. {
  40. uint32_t scriptType = reader.readInt();
  41. read(reader, scriptTable[scriptType]);
  42. }
  43. assert(reader.remaining() == 0);
  44. }