2010-07-31 09:53:02 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
*
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
*
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
*
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Logging
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define BS_LOG_PREFIX "REGIONREGISTRY"
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Includes
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-07-29 19:55:28 +00:00
|
|
|
#include "sword25/kernel/outputpersistenceblock.h"
|
|
|
|
#include "sword25/kernel/inputpersistenceblock.h"
|
|
|
|
#include "sword25/math/regionregistry.h"
|
|
|
|
#include "sword25/math/region.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
namespace Sword25 {
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-08-18 12:57:47 +00:00
|
|
|
Common::SharedPtr<RegionRegistry> RegionRegistry::m_InstancePtr;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-08-18 12:57:47 +00:00
|
|
|
void RegionRegistry::LogErrorLn(const char *Message) const {
|
2010-07-29 19:53:02 +00:00
|
|
|
BS_LOG_ERRORLN(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-08-18 12:57:47 +00:00
|
|
|
void RegionRegistry::LogWarningLn(const char *Message) const {
|
2010-07-29 19:53:02 +00:00
|
|
|
BS_LOG_WARNINGLN(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
bool RegionRegistry::Persist(OutputPersistenceBlock &Writer) {
|
2010-07-29 19:53:02 +00:00
|
|
|
bool Result = true;
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Write out the next handle
|
2010-07-29 19:53:02 +00:00
|
|
|
Writer.Write(m_NextHandle);
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Number of regions to write
|
2010-07-29 19:53:02 +00:00
|
|
|
Writer.Write(m_Handle2PtrMap.size());
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Persist all the BS_Regions
|
2010-07-29 19:53:02 +00:00
|
|
|
HANDLE2PTR_MAP::const_iterator Iter = m_Handle2PtrMap.begin();
|
2010-08-01 08:31:50 +00:00
|
|
|
while (Iter != m_Handle2PtrMap.end()) {
|
|
|
|
// Handle persistence
|
2010-08-05 11:52:13 +00:00
|
|
|
Writer.Write(Iter->_key);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Persist object
|
2010-08-05 11:52:13 +00:00
|
|
|
Result &= Iter->_value->Persist(Writer);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
++Iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
bool RegionRegistry::Unpersist(InputPersistenceBlock &Reader) {
|
2010-07-29 19:53:02 +00:00
|
|
|
bool Result = true;
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Read in the next handle
|
2010-07-29 19:53:02 +00:00
|
|
|
Reader.Read(m_NextHandle);
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Destroy all existing BS_Regions
|
2010-08-05 11:52:13 +00:00
|
|
|
//FIXME: This doesn't seem right - the value is being deleted but not the actual hash node itself?
|
|
|
|
while (!m_Handle2PtrMap.empty()) delete m_Handle2PtrMap.begin()->_value;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Read in the number of BS_Regions
|
2010-09-02 12:14:04 +00:00
|
|
|
uint RegionCount;
|
2010-07-29 19:53:02 +00:00
|
|
|
Reader.Read(RegionCount);
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// Restore all the BS_Regions objects
|
2010-09-02 12:14:04 +00:00
|
|
|
for (uint i = 0; i < RegionCount; ++i) {
|
2010-08-01 08:31:50 +00:00
|
|
|
// Handle read
|
2010-09-02 12:14:04 +00:00
|
|
|
uint Handle;
|
2010-07-29 19:53:02 +00:00
|
|
|
Reader.Read(Handle);
|
|
|
|
|
2010-08-01 08:31:50 +00:00
|
|
|
// BS_Region restore
|
2010-08-18 12:57:47 +00:00
|
|
|
Result &= Region::Create(Reader, Handle) != 0;
|
2010-07-29 19:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Reader.IsGood() && Result;
|
|
|
|
}
|
2010-08-01 08:31:50 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword25
|