| 129 | } |
| 130 | |
| 131 | DS1::DS1(const std::string_view path) { |
| 132 | if (const auto lastSeparator = std::max(path.find_last_of('/'), path.find_last_of('\\')); lastSeparator != std::string_view::npos) { |
| 133 | name = std::string(path.substr(lastSeparator + 1)); |
| 134 | } else { |
| 135 | name = std::string(path); |
| 136 | } |
| 137 | |
| 138 | auto file = AbyssEngine::getInstance().loadFile(path); |
| 139 | Streams::StreamReader sr(file); |
| 140 | |
| 141 | version = sr.readInt32(); |
| 142 | if (version < 3) { |
| 143 | throw std::runtime_error("DS1 version is too old: " + std::to_string(version)); |
| 144 | } |
| 145 | |
| 146 | width = sr.readInt32() + 1; |
| 147 | height = sr.readInt32() + 1; |
| 148 | act = version >= 8 ? sr.readInt32() : 0; |
| 149 | substitutionType = version >= 10 ? sr.readInt32() : 0; |
| 150 | |
| 151 | const auto numberOfFiles = sr.readInt32(); |
| 152 | |
| 153 | for (int i = 0; i < numberOfFiles; ++i) { |
| 154 | files.push_back(sr.readString()); |
| 155 | } |
| 156 | |
| 157 | int numFloors = 1; |
| 158 | constexpr int numShadows = 1; |
| 159 | const int numSubstitutions = (substitutionType == 1 || substitutionType == 2) ? 1 : 0; |
| 160 | int numWalls = 0; |
| 161 | |
| 162 | if (version >= 9 && version <= 13) |
| 163 | sr.skip(1); |
| 164 | |
| 165 | if (version >= 4) |
| 166 | numWalls = sr.readInt32(); |
| 167 | |
| 168 | if (version >= 16) |
| 169 | numFloors = sr.readInt32(); |
| 170 | |
| 171 | layers.floor.resize(numFloors); |
| 172 | layers.wall.resize(numWalls); |
| 173 | layers.shadow.resize(numShadows); |
| 174 | layers.substitution.resize(numSubstitutions); |
| 175 | |
| 176 | resize(width, height); |
| 177 | loadLayerStreams(sr); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | void DS1::resize(const int width, const int height) { |
| 182 | const auto elements = width * height; |
nothing calls this directly
no test coverage detected