StarsAsset.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <StarsAsset.h>
  9. namespace AZ::Render
  10. {
  11. StarsAssetHandler::StarsAssetHandler()
  12. : AzFramework::GenericAssetHandler<StarsAsset>(StarsAsset::DisplayName, StarsAsset::Group, StarsAsset::Extension)
  13. {
  14. }
  15. AZ::Data::AssetHandler::LoadResult StarsAssetHandler::LoadAssetData(
  16. const AZ::Data::Asset<AZ::Data::AssetData>& asset,
  17. AZStd::shared_ptr<AZ::Data::AssetDataStream> stream,
  18. [[maybe_unused]] const AZ::Data::AssetFilterCB& assetLoadFilterCB)
  19. {
  20. StarsAsset* assetData = asset.GetAs<StarsAsset>();
  21. if(assetData && stream->GetLength() > 0)
  22. {
  23. assetData->m_data.resize(stream->GetLength());
  24. stream->Read(stream->GetLength(), assetData->m_data.data());
  25. // use a memory stream instead of AssetDataStream to validate the data,
  26. // AssetDataStream does not allow reverse seek
  27. AZ::IO::MemoryStream memStream(assetData->m_data.data(), assetData->m_data.size());
  28. constexpr uint32_t starsfileTag(0x52415453); // "STAR"
  29. uint32_t fileTag{0};
  30. if (!memStream.Read(sizeof(fileTag), &fileTag) || fileTag != starsfileTag)
  31. {
  32. return AZ::Data::AssetHandler::LoadResult::Error;
  33. }
  34. constexpr uint32_t starsfileVersion(0x00010001);
  35. uint32_t fileVersion{0};
  36. if (!memStream.Read(sizeof(fileVersion), &fileVersion) || fileVersion != starsfileVersion)
  37. {
  38. return AZ::Data::AssetHandler::LoadResult::Error;
  39. }
  40. uint32_t numStars{0};
  41. if(!memStream.Read(sizeof(numStars), &numStars))
  42. {
  43. return AZ::Data::AssetHandler::LoadResult::Error;
  44. }
  45. return AZ::Data::AssetHandler::LoadResult::LoadComplete;
  46. }
  47. return AZ::Data::AssetHandler::LoadResult::Error;
  48. }
  49. } // AZ::Render