Rebekah Rowe 6c4b2e9186
Implement GPL3+ and Apache2.0 Dual License.
Commit is being made to allow additions of GPL3+ code previously
un-addable. With these changes, contributions back to cuberite are
possible with the backporting exemtion, as well as adding stuff in
minetest with minetest code properly being read through and implimented
to upgrade it to GPL3 from GPL2.

project still has Apache2.0 license and credits to all its contributers, but now has the freedom of GPL3+ and all the code that can be implimented and shared with it.
2023-03-20 11:49:56 -04:00

90 lines
2.1 KiB
C++

/*
* Copyright 2011-2022 Cuberite Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QObject>
#include <QCache>
#include <QMutex>
#include <memory>
// fwd:
class Region;
typedef std::shared_ptr<Region> RegionPtr;
class ChunkSource;
/** Caches regions' chunk data for reuse */
class RegionCache :
public QObject
{
typedef QObject super;
Q_OBJECT
public:
explicit RegionCache(QObject * parent = NULL);
/** Retrieves the specified region from the cache.
Only returns valid regions; if the region is invalid, queues it for rendering and returns an empty ptr. */
RegionPtr fetch(int a_RegionX, int a_RegionZ);
/** Replaces the chunk source used by the biome view to get the chunk biome data.
The cache is then invalidated. */
void setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource);
/** Returns true iff the chunk source has been initialized. */
bool hasData() const { return (m_ChunkSource.get() != nullptr); }
/** Reloads the current chunk source. */
void reload();
signals:
void regionAvailable(int a_RegionX, int a_RegionZ);
protected slots:
void gotRegion(int a_RegionX, int a_RegionZ);
protected:
/** The cache of the chunks */
QCache<quint32, RegionPtr> m_Cache;
/** Locks the cache against multithreaded access */
QMutex m_Mtx;
/** The source used to get the biome data. */
std::shared_ptr<ChunkSource> m_ChunkSource;
/** Returns the hash used by the chunk in the cache */
quint32 getRegionHash(int a_RegionX, int a_RegionZ);
/** Queues the specified region for rendering by m_RegionSource. */
void queueRegionRender(int a_RegionX, int a_RegionZ, RegionPtr & a_Region);
};