123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * Bael'Zharon's Respite
- * Copyright (C) 2014 Daniel Skorupski
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- #include "resource/Environment.h"
- #include "resource/BSP.h"
- #include "BinReader.h"
- #include "TriangleFan.h"
- #include "Vertex.h"
- CellStruct::CellStruct()
- {}
- CellStruct::CellStruct(CellStruct&& other)
- {
- vertices = move(other.vertices);
- triangleFans = move(other.triangleFans);
- hitTriangleFans = move(other.hitTriangleFans);
- hitTree = move(other.hitTree);
- }
- CellStruct::~CellStruct()
- {}
- CellStruct& CellStruct::operator=(CellStruct&& other)
- {
- vertices = move(other.vertices);
- triangleFans = move(other.triangleFans);
- hitTriangleFans = move(other.hitTriangleFans);
- hitTree = move(other.hitTree);
- return *this;
- }
- static void read(BinReader& reader, CellStruct& part)
- {
- uint32_t numTriangleFans = reader.readInt();
- part.triangleFans.resize(numTriangleFans);
- uint32_t numHitTriangleFans = reader.readInt();
- part.hitTriangleFans.resize(numHitTriangleFans);
- uint32_t numPortals = reader.readInt();
- uint32_t unk5 = reader.readInt();
- assert(unk5 == 1);
- UNUSED(unk5);
- uint32_t numVertices = reader.readInt();
- part.vertices.resize(numVertices);
- for(uint32_t i = 0; i < numVertices; i++)
- {
- uint16_t vertexNum = reader.readShort();
- assert(vertexNum == i);
- UNUSED(vertexNum);
- read(reader, part.vertices[i]);
- }
- for(uint32_t i = 0; i < numTriangleFans; i++)
- {
- uint16_t triangleFanNum = reader.readShort();
- assert(triangleFanNum == i);
- UNUSED(triangleFanNum);
- read(reader, part.triangleFans[i]);
- }
- for(uint32_t i = 0; i < numPortals; i++)
- {
- reader.readShort();
- }
- reader.align();
- unique_ptr<BSPNode> cellBSP;
- read(reader, cellBSP, BSPTreeType::kCell);
- for(uint32_t i = 0; i < numHitTriangleFans; i++)
- {
- uint16_t triangleFanNum = reader.readShort();
- assert(triangleFanNum == i);
- UNUSED(triangleFanNum);
- read(reader, part.hitTriangleFans[i]);
- }
-
- unique_ptr<BSPNode> physicsBSP;
- read(reader, physicsBSP, BSPTreeType::kPhysics);
- uint32_t hasDrawingBSP = reader.readInt();
- assert(hasDrawingBSP == 0 || hasDrawingBSP == 1);
- if(hasDrawingBSP)
- {
- unique_ptr<BSPNode> drawingBSP;
- read(reader, drawingBSP, BSPTreeType::kDrawing);
- }
- reader.align();
- }
- Environment::Environment(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
- {
- BinReader reader(data, size);
- uint32_t resourceId = reader.readInt();
- assert(resourceId == id);
- UNUSED(resourceId);
- uint32_t numParts = reader.readInt();
- parts.resize(numParts);
- for(uint32_t i = 0; i < numParts; i++)
- {
- uint32_t partNum = reader.readInt();
- assert(partNum == i);
- UNUSED(partNum);
- read(reader, parts[i]);
- }
- assert(reader.remaining() == 0);
- }
|