Refactor - rename KRDataBlock to mimir::Block

This commit is contained in:
2023-08-05 16:37:16 -07:00
parent 152f7a2d28
commit e485261e53
75 changed files with 339 additions and 268 deletions

View File

@@ -3,6 +3,7 @@ add_subdirectory(public)
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
# Private Implementation
add_sources(block.cpp)
add_sources(kraken.cpp)
add_sources(KRAmbientZone.cpp)
add_sources(KRAnimation.cpp)
@@ -41,7 +42,6 @@ IF(APPLE)
ENDIF()
ENDIF (APPLE)
add_sources(KRContextObject.cpp)
add_sources(KRDataBlock.cpp)
add_sources(KRDirectionalLight.cpp)
IF(APPLE)
add_sources(KRDSP_vDSP.cpp)

View File

@@ -35,6 +35,8 @@
#include "KRAnimationCurve.h"
#include "KREngine-common.h"
using namespace mimir;
KRAnimation::KRAnimation(KRContext& context, std::string name) : KRResource(context, name)
{
m_auto_play = false;
@@ -61,7 +63,7 @@ void KRAnimation::addLayer(KRAnimationLayer* layer)
m_layers[layer->getName()] = layer;
}
bool KRAnimation::save(KRDataBlock& data)
bool KRAnimation::save(Block& data)
{
tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* animation_node = doc.NewElement("animation");
@@ -82,7 +84,7 @@ bool KRAnimation::save(KRDataBlock& data)
return true;
}
KRAnimation* KRAnimation::Load(KRContext& context, const std::string& name, KRDataBlock* data)
KRAnimation* KRAnimation::Load(KRContext& context, const std::string& name, Block* data)
{
std::string xml_string = data->getString();

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
#include "KRAnimationLayer.h"
@@ -46,9 +46,9 @@ public:
virtual ~KRAnimation();
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
static KRAnimation* Load(KRContext& context, const std::string& name, KRDataBlock* data);
static KRAnimation* Load(KRContext& context, const std::string& name, mimir::Block* data);
void addLayer(KRAnimationLayer* layer);
unordered_map<std::string, KRAnimationLayer*>& getLayers();

View File

@@ -31,11 +31,13 @@
#include "KRContext.h"
#include "KRAnimationCurve.h"
#include "KRDataBlock.h"
#include "block.h"
using namespace mimir;
KRAnimationCurve::KRAnimationCurve(KRContext& context, const std::string& name) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_pData = new Block();
m_pData->expand(sizeof(animation_curve_header));
m_pData->lock();
animation_curve_header* header = (animation_curve_header*)m_pData->getStart();
@@ -51,7 +53,7 @@ KRAnimationCurve::~KRAnimationCurve()
m_pData->unload();
delete m_pData;
}
bool KRAnimationCurve::load(KRDataBlock* data)
bool KRAnimationCurve::load(Block* data)
{
m_pData->unload();
delete m_pData;
@@ -69,13 +71,13 @@ bool KRAnimationCurve::save(const std::string& path)
return m_pData->save(path);
}
bool KRAnimationCurve::save(KRDataBlock& data)
bool KRAnimationCurve::save(Block& data)
{
data.append(*m_pData);
return true;
}
KRAnimationCurve* KRAnimationCurve::Load(KRContext& context, const std::string& name, KRDataBlock* data)
KRAnimationCurve* KRAnimationCurve::Load(KRContext& context, const std::string& name, Block* data)
{
KRAnimationCurve* new_animation_curve = new KRAnimationCurve(context, name);
if (new_animation_curve->load(data)) {

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
class KRAnimationCurve : public KRResource
@@ -45,8 +45,8 @@ public:
virtual std::string getExtension();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool load(KRDataBlock* data);
virtual bool save(mimir::Block& data);
virtual bool load(mimir::Block* data);
float getFrameRate();
void setFrameRate(float frame_rate);
@@ -59,7 +59,7 @@ public:
void setValue(int frame_number, float value);
static KRAnimationCurve* Load(KRContext& context, const std::string& name, KRDataBlock* data);
static KRAnimationCurve* Load(KRContext& context, const std::string& name, mimir::Block* data);
bool valueChanges(float start_time, float duration);
bool valueChanges(int start_frame, int frame_count);
@@ -71,7 +71,7 @@ public:
void _unlockData();
private:
KRDataBlock* m_pData;
mimir::Block* m_pData;
typedef struct
{

View File

@@ -50,7 +50,7 @@ void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve* curve)
delete curve;
}
KRResource* KRAnimationCurveManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRAnimationCurveManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
{
if (extension.compare("kranimationcurve") == 0) {
return loadAnimationCurve(name, data);
@@ -65,7 +65,7 @@ KRResource* KRAnimationCurveManager::getResource(const std::string& name, const
return nullptr;
}
KRAnimationCurve* KRAnimationCurveManager::loadAnimationCurve(const std::string& name, KRDataBlock* data)
KRAnimationCurve* KRAnimationCurveManager::loadAnimationCurve(const std::string& name, mimir::Block* data)
{
KRAnimationCurve* pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data);
if (pAnimationCurve) {

View File

@@ -37,7 +37,7 @@
#include "KRAnimationCurve.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
using std::map;
@@ -47,10 +47,10 @@ public:
KRAnimationCurveManager(KRContext& context);
virtual ~KRAnimationCurveManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
KRAnimationCurve* loadAnimationCurve(const std::string& name, KRDataBlock* data);
KRAnimationCurve* loadAnimationCurve(const std::string& name, mimir::Block* data);
KRAnimationCurve* getAnimationCurve(const std::string& name);
void addAnimationCurve(KRAnimationCurve* new_animation_curve);
unordered_map<std::string, KRAnimationCurve*>& getAnimationCurves();

View File

@@ -82,7 +82,7 @@ void KRAnimationManager::endFrame(float deltaTime)
}
KRResource* KRAnimationManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRAnimationManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
{
if (extension.compare("kranimation") == 0) {
return loadAnimation(name.c_str(), data);
@@ -97,7 +97,7 @@ KRResource* KRAnimationManager::getResource(const std::string& name, const std::
return nullptr;
}
KRAnimation* KRAnimationManager::loadAnimation(const char* szName, KRDataBlock* data)
KRAnimation* KRAnimationManager::loadAnimation(const char* szName, mimir::Block* data)
{
KRAnimation* pAnimation = KRAnimation::Load(*m_pContext, szName, data);
addAnimation(pAnimation);

View File

@@ -37,7 +37,7 @@
#include "KRAnimation.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
@@ -47,10 +47,10 @@ public:
KRAnimationManager(KRContext& context);
virtual ~KRAnimationManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
KRAnimation* loadAnimation(const char* szName, KRDataBlock* data);
KRAnimation* loadAnimation(const char* szName, mimir::Block* data);
KRAnimation* getAnimation(const char* szName);
void addAnimation(KRAnimation* new_animation);
unordered_map<std::string, KRAnimation*>& getAnimations();

View File

@@ -32,7 +32,7 @@
#pragma once
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include "block.h"
class KRAudioManager;
class KRAudioSample;
@@ -56,7 +56,7 @@ private:
int m_frameCount;
int m_frameRate;
int m_bytesPerFrame;
KRDataBlock* m_pData;
mimir::Block* m_pData;
KRAudioSample* m_audioSample;
};

View File

@@ -32,12 +32,14 @@
#include "KRAudioManager.h"
#include "KRAudioSample.h"
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRAudioBuffer.h"
#include "KRContext.h"
#include "KRCollider.h"
#include "KRDSP.h"
using namespace mimir;
KRAudioManager::KRAudioManager(KRContext& context)
: KRResourceManager(context)
, m_initialized(false)
@@ -1199,7 +1201,7 @@ void KRAudioManager::destroy()
cleanupAudio();
for (std::vector<KRDataBlock*>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
for (std::vector<Block*>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
delete* itr;
}
m_bufferPoolIdle.clear();
@@ -1257,7 +1259,7 @@ void KRAudioManager::add(KRAudioSample* sound)
}
}
KRResource* KRAudioManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRAudioManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("mtl") == 0 ||
extension.compare("mp3") == 0 ||
@@ -1276,7 +1278,7 @@ KRResource* KRAudioManager::getResource(const std::string& name, const std::stri
return nullptr;
}
KRAudioSample* KRAudioManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
KRAudioSample* KRAudioManager::load(const std::string& name, const std::string& extension, Block* data)
{
KRAudioSample* Sound = new KRAudioSample(getContext(), name, extension, data);
if (Sound) add(Sound);
@@ -1290,23 +1292,23 @@ KRAudioSample* KRAudioManager::get(const std::string& name)
return m_sounds[lower_name];
}
KRDataBlock* KRAudioManager::getBufferData(int size)
Block* KRAudioManager::getBufferData(int size)
{
KRDataBlock* data;
Block* data;
// Note: We only store and recycle buffers with a size of CIRCA_AUDIO_MAX_BUFFER_SIZE
if (size == KRENGINE_AUDIO_MAX_BUFFER_SIZE && m_bufferPoolIdle.size() > 0) {
// Recycle a buffer from the pool
data = m_bufferPoolIdle.back();
m_bufferPoolIdle.pop_back();
} else {
data = new KRDataBlock();
data = new Block();
data->expand(size);
}
data->lock();
return data;
}
void KRAudioManager::recycleBufferData(KRDataBlock* data)
void KRAudioManager::recycleBufferData(Block* data)
{
if (data != NULL) {
data->unlock();

View File

@@ -36,7 +36,7 @@
#include "KRResourceManager.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRAudioSource.h"
#include "KRDSP.h"
@@ -100,14 +100,14 @@ public:
virtual ~KRAudioManager();
void destroy();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
unordered_map<std::string, KRAudioSample*>& getSounds();
void add(KRAudioSample* Sound);
KRAudioSample* load(const std::string& name, const std::string& extension, KRDataBlock* data);
KRAudioSample* load(const std::string& name, const std::string& extension, mimir::Block* data);
KRAudioSample* get(const std::string& name);
// Listener position and orientation
@@ -132,8 +132,8 @@ public:
void makeCurrentContext();
KRDataBlock* getBufferData(int size);
void recycleBufferData(KRDataBlock* data);
mimir::Block* getBufferData(int size);
void recycleBufferData(mimir::Block* data);
void activateAudioSource(KRAudioSource* audioSource);
void deactivateAudioSource(KRAudioSource* audioSource);
@@ -180,7 +180,7 @@ private:
unordered_map<std::string, KRAudioSample*> m_sounds;
std::vector<KRDataBlock*> m_bufferPoolIdle;
std::vector<mimir::Block*> m_bufferPoolIdle;
std::vector<KRAudioBuffer*> m_bufferCache;

View File

@@ -31,14 +31,16 @@
#include "KRAudioSample.h"
#include "KRAudioManager.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRAudioBuffer.h"
#include "KRContext.h"
#include "KRDSP.h"
using namespace mimir;
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_pData = new Block();
m_extension = extension;
#ifdef __APPLE__
@@ -54,7 +56,7 @@ KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string e
m_last_frame_used = 0;
}
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
{
m_pData = data;
m_extension = extension;
@@ -329,7 +331,7 @@ std::string KRAudioSample::getExtension()
return m_extension;
}
bool KRAudioSample::save(KRDataBlock& data)
bool KRAudioSample::save(Block& data)
{
data.append(*m_pData);
return true;

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
class KRAudioBuffer;
@@ -43,12 +43,12 @@ class KRAudioSample : public KRResource
public:
KRAudioSample(KRContext& context, std::string name, std::string extension);
KRAudioSample(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
KRAudioSample(KRContext& context, std::string name, std::string extension, mimir::Block* data);
virtual ~KRAudioSample();
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
float getDuration();
KRAudioBuffer* getBuffer(int index);
@@ -66,7 +66,7 @@ private:
__int64_t m_last_frame_used;
std::string m_extension;
KRDataBlock* m_pData;
mimir::Block* m_pData;
#ifdef __APPLE__
// Apple Audio Toolbox

View File

@@ -33,6 +33,8 @@
#include "KRContext.h"
#include "KREngine-common.h"
using namespace mimir;
const int KRENGINE_KRBUNDLE_HEADER_SIZE = 512;
typedef struct _tar_header
@@ -49,7 +51,7 @@ typedef struct _tar_header
} tar_header_type;
KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : KRResource(context, name)
KRBundle::KRBundle(KRContext& context, std::string name, Block* pData) : KRResource(context, name)
{
m_pData = pData;
@@ -61,7 +63,7 @@ KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : K
file_pos += 512; // Skip past the header to the file contents
if (file_header.file_name[0] != '\0' && file_header.file_name[0] != '.') {
// We ignore the last two records in the tar file, which are zero'ed out tar_header structures
KRDataBlock* pFileData = pData->getSubBlock((int)file_pos, (int)file_size);
Block* pFileData = pData->getSubBlock((int)file_pos, (int)file_size);
context.loadResource(file_header.file_name, pFileData);
}
file_pos += RoundUpSize(file_size);
@@ -71,7 +73,7 @@ KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : K
KRBundle::KRBundle(KRContext& context, std::string name) : KRResource(context, name)
{
// Create an empty krbundle (tar) file, initialized with two zero-ed out file headers, which terminate it.
m_pData = new KRDataBlock();
m_pData = new Block();
m_pData->expand(KRENGINE_KRBUNDLE_HEADER_SIZE * 2);
m_pData->lock();
memset(m_pData->getStart(), 0, m_pData->getSize());
@@ -106,7 +108,7 @@ bool KRBundle::save(const std::string& path)
return m_pData->save(path);
}
bool KRBundle::save(KRDataBlock& data)
bool KRBundle::save(Block& data)
{
if (m_pData->getSize() > KRENGINE_KRBUNDLE_HEADER_SIZE * 2) {
// Only output krbundles that contain files
@@ -115,10 +117,10 @@ bool KRBundle::save(KRDataBlock& data)
return true;
}
KRDataBlock* KRBundle::append(KRResource& resource)
Block* KRBundle::append(KRResource& resource)
{
// Serialize resource to binary representation
KRDataBlock resource_data;
Block resource_data;
resource.save(resource_data);
std::string file_name = resource.getName() + "." + resource.getExtension();
@@ -165,6 +167,6 @@ KRDataBlock* KRBundle::append(KRResource& resource)
m_pData->unlock();
KRDataBlock* pFileData = m_pData->getSubBlock((int)resource_data_start, (int)resource_data.getSize());
Block* pFileData = m_pData->getSubBlock((int)resource_data_start, (int)resource_data.getSize());
return pFileData;
}

View File

@@ -32,21 +32,21 @@
#include "KREngine-common.h"
#include "KRResource.h"
#include "KRDataBlock.h"
#include "block.h"
class KRBundle : public KRResource
{
public:
KRBundle(KRContext& context, std::string name, KRDataBlock* pData);
KRBundle(KRContext& context, std::string name, mimir::Block* pData);
KRBundle(KRContext& context, std::string name);
virtual ~KRBundle();
virtual std::string getExtension();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
KRDataBlock* append(KRResource& resource);
mimir::Block* append(KRResource& resource);
private:
KRDataBlock* m_pData;
mimir::Block* m_pData;
static size_t RoundUpSize(size_t s);
};

View File

@@ -46,7 +46,7 @@ KRBundleManager::~KRBundleManager()
m_bundles.clear();
}
KRResource* KRBundleManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRBundleManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
{
if (extension.compare("krbundle") == 0) {
return loadBundle(name.c_str(), data);
@@ -61,7 +61,7 @@ KRResource* KRBundleManager::getResource(const std::string& name, const std::str
return nullptr;
}
KRBundle* KRBundleManager::loadBundle(const char* szName, KRDataBlock* pData)
KRBundle* KRBundleManager::loadBundle(const char* szName, mimir::Block* pData)
{
KRBundle* pBundle = new KRBundle(*m_pContext, szName, pData);
m_bundles[szName] = pBundle;

View File

@@ -35,7 +35,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRContext;
class KRBundle;
@@ -46,10 +46,10 @@ public:
KRBundleManager(KRContext& context);
~KRBundleManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
KRBundle* loadBundle(const char* szName, KRDataBlock* pData);
KRBundle* loadBundle(const char* szName, mimir::Block* pData);
KRBundle* getBundle(const char* szName);
KRBundle* createBundle(const char* szName);

View File

@@ -35,6 +35,8 @@
#include "KRRenderPass.h"
#include "KRPipeline.h"
using namespace mimir;
/* static */
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
{
@@ -778,7 +780,7 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
} else {
if (m_debug_text_vertices.getSize() > 0) {
m_debug_text_vertices = KRDataBlock();
m_debug_text_vertices = Block();
}
}
}

View File

@@ -111,7 +111,7 @@ private:
float v;
} DebugTextVertexData;
KRDataBlock m_debug_text_vertices;
mimir::Block m_debug_text_vertices;
KRMeshManager::KRVBOData m_debug_text_vbo_data;
// std::string getDebugText();

View File

@@ -48,6 +48,8 @@
#include <windows.h>
#endif
using namespace mimir;
// TODO - Make values dynamic after Vulkan conversion:
int KRContext::KRENGINE_MAX_PIPELINE_HANDLES = 4000;
int KRContext::KRENGINE_GPU_MEM_MAX = 256000000;
@@ -325,7 +327,7 @@ std::vector<KRResource*> KRContext::getResources()
return resources;
}
KRResource* KRContext::loadResource(const std::string& file_name, KRDataBlock* data)
KRResource* KRContext::loadResource(const std::string& file_name, Block* data)
{
std::string name = KRResource::GetFileBase(file_name);
std::string extension = KRResource::GetFileExtension(file_name);
@@ -394,7 +396,7 @@ KrResult KRContext::loadResource(const KrLoadResourceInfo* loadResourceInfo)
if (loadResourceInfo->resourceHandle < 0 || loadResourceInfo->resourceHandle >= m_resourceMapSize) {
return KR_ERROR_OUT_OF_BOUNDS;
}
KRDataBlock* data = new KRDataBlock();
Block* data = new Block();
if (!data->load(loadResourceInfo->pResourcePath)) {
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KRContext::loadResource - Failed to open file: %s", loadResourceInfo->pResourcePath);
delete data;
@@ -457,7 +459,7 @@ KrResult KRContext::unmapResource(const KrUnmapResourceInfo* unmapResourceInfo)
KrResult KRContext::getResourceData(const KrGetResourceDataInfo* getResourceDataInfo, KrGetResourceDataCallback callback)
{
// TODO - This will be asynchronous... The function will always succeed, but the asynchronous result could report a failure
KRDataBlock data;
Block data;
KrGetResourceDataResult result = {};
KRResource* resource = nullptr;

View File

@@ -122,7 +122,7 @@ public:
}
// -=-=-=- End: Helper functions for Public API Entry Points
KRResource* loadResource(const std::string& file_name, KRDataBlock* data);
KRResource* loadResource(const std::string& file_name, mimir::Block* data);
KRBundleManager* getBundleManager();

View File

@@ -32,6 +32,8 @@
#include "KRDevice.h"
#include "KRDeviceManager.h"
using namespace mimir;
KRDevice::KRDevice(KRContext& context, const VkPhysicalDevice& device)
: KRContextObject(context)
, m_device(device)
@@ -713,14 +715,14 @@ void KRDevice::streamStart()
}
}
void KRDevice::streamUpload(KRDataBlock& data, VkBuffer destination)
void KRDevice::streamUpload(Block& data, VkBuffer destination)
{
data.lock();
streamUpload(data.getStart(), data.getSize(), destination);
data.unlock();
}
void KRDevice::graphicsUpload(VkCommandBuffer& commandBuffer, KRDataBlock& data, VkBuffer destination)
void KRDevice::graphicsUpload(VkCommandBuffer& commandBuffer, Block& data, VkBuffer destination)
{
data.lock();
graphicsUpload(commandBuffer, data.getStart(), data.getSize(), destination);
@@ -779,7 +781,7 @@ void KRDevice::streamUpload(void* data, size_t size, Vector3i dimensions, VkImag
streamUploadImpl(size, dimensions, destination, 0, 1);
}
void KRDevice::streamUpload(KRDataBlock& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount)
void KRDevice::streamUpload(Block& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount)
{
checkFlushStreamBuffer(size);

View File

@@ -34,7 +34,9 @@
#pragma once
class KRDataBlock;
namespace mimir {
class Block;
}
class KRDevice : public KRContextObject
{
@@ -69,13 +71,13 @@ public:
KrResult selectPresentMode(VkSurfaceKHR& surface, VkPresentModeKHR& selectedPresentMode) const;
void streamStart();
void streamUpload(KRDataBlock& data, VkBuffer destination);
void streamUpload(KRDataBlock& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount);
void streamUpload(mimir::Block& data, VkBuffer destination);
void streamUpload(mimir::Block& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount);
void streamUpload(void* data, size_t size, VkBuffer destination);
void streamUpload(void* data, size_t size, Vector3i dimensions, VkImage destination);
void streamEnd();
void graphicsUpload(VkCommandBuffer& commandBuffer, KRDataBlock& data, VkBuffer destination);
void graphicsUpload(VkCommandBuffer& commandBuffer, mimir::Block& data, VkBuffer destination);
void graphicsUpload(VkCommandBuffer& commandBuffer, void* data, size_t size, VkBuffer destination);
void createDescriptorSets(const std::vector<VkDescriptorSetLayout>& layouts, std::vector<VkDescriptorSet>& descriptorSets);

View File

@@ -36,6 +36,8 @@
#include "KRContext.h"
using namespace mimir;
KRMaterial::KRMaterial(KRContext& context, const char* szName) : KRResource(context, szName)
{
m_name = szName;
@@ -83,7 +85,7 @@ bool KRMaterial::needsVertexTangents()
return m_normalMap.size() > 0;
}
bool KRMaterial::save(KRDataBlock& data)
bool KRMaterial::save(Block& data)
{
std::stringstream stream;
stream.precision(std::numeric_limits<long double>::digits10);

View File

@@ -65,7 +65,7 @@ public:
virtual ~KRMaterial();
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
void setAmbientMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset);

View File

@@ -32,6 +32,8 @@
#include "KREngine-common.h"
#include "KRMaterialManager.h"
using namespace mimir;
KRMaterialManager::KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager) : KRResourceManager(context)
{
@@ -44,7 +46,7 @@ KRMaterialManager::~KRMaterialManager()
}
KRResource* KRMaterialManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRMaterialManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("mtl") == 0) {
return load(name.c_str(), data);
@@ -95,7 +97,7 @@ void KRMaterialManager::add(KRMaterial* new_material)
m_materials[lowerName] = new_material;
}
KRMaterial* KRMaterialManager::load(const char* szName, KRDataBlock* data)
KRMaterial* KRMaterialManager::load(const char* szName, Block* data)
{
KRMaterial* pMaterial = NULL;
char szSymbol[16][256];

View File

@@ -49,10 +49,10 @@ public:
KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager);
virtual ~KRMaterialManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
KRMaterial* load(const char* szName, KRDataBlock* data);
KRMaterial* load(const char* szName, mimir::Block* data);
void add(KRMaterial* new_material);
KRMaterial* getMaterial(const std::string& name);

View File

@@ -39,6 +39,8 @@
#include "KRContext.h"
#include "../3rdparty/forsyth/forsyth.h"
using namespace mimir;
KRMesh::KRMesh(KRContext& context, std::string name) : KRResource(context, name)
{
setName(name);
@@ -50,7 +52,7 @@ KRMesh::KRMesh(KRContext& context, std::string name) : KRResource(context, name)
m_constant = false;
}
KRMesh::KRMesh(KRContext& context, std::string name, KRDataBlock* data) : KRResource(context, name)
KRMesh::KRMesh(KRContext& context, std::string name, Block* data) : KRResource(context, name)
{
setName(name);
@@ -149,13 +151,13 @@ bool KRMesh::save(const std::string& path)
return m_pData->save(path);
}
bool KRMesh::save(KRDataBlock& data)
bool KRMesh::save(Block& data)
{
data.append(*m_pData);
return true;
}
void KRMesh::loadPack(KRDataBlock* data)
void KRMesh::loadPack(Block* data)
{
releaseData();
@@ -377,8 +379,8 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count);
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
KRDataBlock* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size);
KRDataBlock* index_data_block = m_pData->getSubBlock(index_data_offset + start_index_offset * 2, index_count * 2);
Block* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size);
Block* index_data_block = m_pData->getSubBlock(index_data_offset + start_index_offset * 2, index_count * 2);
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
#if KRENGINE_DEBUG_GPU_LABELS
, m_lodBaseName.c_str()
@@ -406,8 +408,8 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
int vertex_size = m_vertex_size;
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
KRDataBlock* index_data_block = NULL;
KRDataBlock* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes);
Block* index_data_block = NULL;
Block* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes);
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
#if KRENGINE_DEBUG_GPU_LABELS
, m_lodBaseName.c_str()
@@ -619,7 +621,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
size_t vertex_count = mi.vertices.size();
size_t bone_count = mi.bone_names.size();
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + KRALIGN(2 * index_count) + KRALIGN(8 * index_base_count) + vertex_size * vertex_count;
m_pData = new KRDataBlock();
m_pData = new Block();
m_pMetaData = m_pData;
m_pData->expand(new_file_size);
m_pData->lock();

View File

@@ -71,7 +71,7 @@ class KRMesh : public KRResource
public:
static void parseName(const std::string& name, std::string& lodBaseName, int& lodCoverage);
KRMesh(KRContext& context, std::string name, KRDataBlock* data);
KRMesh(KRContext& context, std::string name, mimir::Block* data);
KRMesh(KRContext& context, std::string name);
virtual ~KRMesh();
@@ -124,10 +124,10 @@ public:
virtual std::string getExtension();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
void LoadData(const mesh_info& mi, bool calculate_normals, bool calculate_tangents);
void loadPack(KRDataBlock* data);
void loadPack(mimir::Block* data);
void convertToIndexed();
void optimize();
@@ -160,8 +160,8 @@ public:
int start_vertex;
int vertex_count;
char szMaterialName[KRENGINE_MAX_NAME_LENGTH];
vector<KRDataBlock*> vertex_data_blocks;
vector<KRDataBlock*> index_data_blocks;
vector<mimir::Block*> vertex_data_blocks;
vector<mimir::Block*> index_data_blocks;
// KRMeshManager depends on the address of KRVBOData's being constant
// after allocation, enforced by deleted copy constructors.
// As std::vector requires copy constuctors, we wrap these in shared_ptr.
@@ -239,9 +239,9 @@ protected:
bool m_constant; // TRUE if this should be always loaded and should not be passed through the streamer
private:
KRDataBlock* m_pData;
KRDataBlock* m_pMetaData;
KRDataBlock* m_pIndexBaseData;
mimir::Block* m_pData;
mimir::Block* m_pMetaData;
mimir::Block* m_pIndexBaseData;
void getSubmeshes();
void getMaterials();

View File

@@ -38,6 +38,8 @@
#include "KRMeshQuad.h"
#include "KRMeshSphere.h"
using namespace mimir;
KRMeshManager::KRMeshManager(KRContext& context)
: KRResourceManager(context)
, m_currentVBO(NULL)
@@ -117,7 +119,7 @@ KRMeshManager::~KRMeshManager()
m_models.clear();
}
KRResource* KRMeshManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRMeshManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("krmesh") == 0) {
return loadModel(name.c_str(), data);
@@ -140,7 +142,7 @@ KRResource* KRMeshManager::getResource(const std::string& name, const std::strin
return nullptr;
}
KRMesh* KRMeshManager::loadModel(const char* szName, KRDataBlock* pData)
KRMesh* KRMeshManager::loadModel(const char* szName, Block* pData)
{
KRMesh* pModel = new KRMesh(*m_pContext, szName, pData);
addModel(pModel);
@@ -326,7 +328,7 @@ long KRMeshManager::getMemUsed()
long KRMeshManager::getMemActive()
{
long mem_active = 0;
for (unordered_map<KRDataBlock*, KRVBOData*>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
for (unordered_map<Block*, KRVBOData*>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
mem_active += (*itr).second->getSize();
}
return mem_active;
@@ -475,7 +477,7 @@ KRMeshManager::KRVBOData::KRVBOData()
memset(m_allocations, 0, sizeof(AllocationInfo) * KRENGINE_MAX_GPU_COUNT);
}
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, Block* data, Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
#if KRENGINE_DEBUG_GPU_LABELS
, const char* debug_label
#endif
@@ -492,7 +494,7 @@ KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, KRDataBlock* data, K
);
}
void KRMeshManager::KRVBOData::init(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
void KRMeshManager::KRVBOData::init(KRMeshManager* manager, Block* data, Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
#if KRENGINE_DEBUG_GPU_LABELS
, const char* debug_label
#endif

View File

@@ -35,7 +35,7 @@
#include "KRResourceManager.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRNode.h"
class KRContext;
@@ -51,13 +51,13 @@ public:
void init();
virtual ~KRMeshManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
void startFrame(float deltaTime);
void endFrame(float deltaTime);
KRMesh* loadModel(const char* szName, KRDataBlock* pData);
KRMesh* loadModel(const char* szName, mimir::Block* pData);
std::vector<KRMesh*> getModel(const char* szName);
KRMesh* getMaxLODModel(const char* szName);
void addModel(KRMesh* model);
@@ -84,12 +84,12 @@ public:
} vbo_type;
KRVBOData();
KRVBOData(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
KRVBOData(KRMeshManager* manager, mimir::Block* data, mimir::Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
#if KRENGINE_DEBUG_GPU_LABELS
, const char* debug_label
#endif
);
void init(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
void init(KRMeshManager* manager, mimir::Block* data, mimir::Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
#if KRENGINE_DEBUG_GPU_LABELS
, const char* debug_label
#endif
@@ -97,8 +97,8 @@ public:
~KRVBOData();
KRDataBlock* m_data;
KRDataBlock* m_index_data;
mimir::Block* m_data;
mimir::Block* m_index_data;
bool isVBOLoaded()
{
@@ -211,9 +211,9 @@ public:
void doStreaming(long& memoryRemaining, long& memoryRemainingThisFrame);
private:
KRDataBlock KRENGINE_VBO_3D_CUBE_VERTICES;
mimir::Block KRENGINE_VBO_3D_CUBE_VERTICES;
__int32_t KRENGINE_VBO_3D_CUBE_ATTRIBS;
KRDataBlock KRENGINE_VBO_2D_SQUARE_VERTICES;
mimir::Block KRENGINE_VBO_2D_SQUARE_VERTICES;
__int32_t KRENGINE_VBO_2D_SQUARE_ATTRIBS;
unordered_multimap<std::string, KRMesh*> m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model
@@ -221,12 +221,12 @@ private:
long m_vboMemUsed;
KRVBOData* m_currentVBO;
unordered_map<KRDataBlock*, KRVBOData*> m_vbosActive;
unordered_map<mimir::Block*, KRVBOData*> m_vbosActive;
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer;
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer_copy;
KRDataBlock m_randomParticleVertexData;
KRDataBlock m_volumetricLightingVertexData;
mimir::Block m_randomParticleVertexData;
mimir::Block m_volumetricLightingVertexData;
long m_memoryTransferredThisFrame;

View File

@@ -34,7 +34,7 @@
#include "KREngine-common.h"
#include "KRCamera.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRNode.h"
#include "KRSurface.h"
#include "KRMesh.h"

View File

@@ -35,12 +35,14 @@
#include "KRScene.h"
#include "KRResource+blend.h"
using namespace mimir;
KRScene* KRResource::LoadBlenderScene(KRContext& context, const std::string& path)
{
KRScene* pScene = new KRScene(context, KRResource::GetFileBase(path));
KRDataBlock data;
Block data;
if (data.load(path)) {
//KRBlendFile blend_file = KRBlendFile(pFile);

View File

@@ -34,6 +34,8 @@
#include "KRResource.h"
#include "KRMesh.h"
using namespace mimir;
KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
{
KRMesh* new_mesh = new KRMesh(context, KRResource::GetFileBase(path));
@@ -42,7 +44,7 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
std::vector<std::string> material_names_t;
KRDataBlock data;
Block data;
char szSymbol[500][256];

View File

@@ -34,6 +34,8 @@
#include "KRBundle.h"
#include "KRContext.h"
using namespace mimir;
KRResource::KRResource(KRContext& context, std::string name) : KRContextObject(context)
{
m_name = name;
@@ -89,7 +91,7 @@ std::string KRResource::GetFilePath(const std::string& name)
bool KRResource::save(const std::string& path)
{
KRDataBlock data;
Block data;
if (save(data)) {
return data.save(path);
} else {
@@ -99,11 +101,11 @@ bool KRResource::save(const std::string& path)
KrResult KRResource::moveToBundle(KRBundle* bundle)
{
KRDataBlock* data = bundle->append(*this);
Block* data = bundle->append(*this);
if (data == nullptr) {
return KR_ERROR_UNEXPECTED;
}
// TODO(kearwood) - We must re-attach the KRResource to the returned KRDataBlock
// TODO(kearwood) - We must re-attach the KRResource to the returned Block
delete data;
return KR_SUCCESS;
}

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRBundle;
class KRScene;
@@ -44,7 +44,7 @@ public:
std::string getName();
virtual std::string getExtension() = 0;
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data) = 0;
virtual bool save(mimir::Block& data) = 0;
KrResult moveToBundle(KRBundle* bundle);

View File

@@ -35,7 +35,7 @@
#include "KRResource.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRResourceManager : public KRContextObject
{
@@ -43,6 +43,6 @@ public:
KRResourceManager(KRContext& context);
virtual ~KRResourceManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) = 0;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) = 0;
virtual KRResource* getResource(const std::string& name, const std::string& extension) = 0;
};

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include "block.h"
using std::map;
using std::vector;

View File

@@ -40,6 +40,8 @@
#include "KRPointLight.h"
#include "KRAudioManager.h"
using namespace mimir;
const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10;
KRScene::KRScene(KRContext& context, std::string name) : KRResource(context, name)
@@ -383,7 +385,7 @@ KRNode* KRScene::getRootNode()
return m_pRootNode;
}
bool KRScene::save(KRDataBlock& data)
bool KRScene::save(Block& data)
{
tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* scene_node = doc.NewElement("scene");
@@ -397,7 +399,7 @@ bool KRScene::save(KRDataBlock& data)
return true;
}
KRScene* KRScene::Load(KRContext& context, const std::string& name, KRDataBlock* data)
KRScene* KRScene::Load(KRContext& context, const std::string& name, Block* data)
{
std::string xml_string = data->getString();
delete data;

View File

@@ -57,9 +57,9 @@ public:
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
static KRScene* Load(KRContext& context, const std::string& name, KRDataBlock* data);
static KRScene* Load(KRContext& context, const std::string& name, mimir::Block* data);
KRNode* getRootNode();
KRLight* getFirstLight();

View File

@@ -32,6 +32,8 @@
#include "KRSceneManager.h"
#include "KRScene.h"
using namespace mimir;
KRSceneManager::KRSceneManager(KRContext& context) : KRResourceManager(context)
{}
@@ -43,7 +45,7 @@ KRSceneManager::~KRSceneManager()
m_scenes.clear();
}
KRResource* KRSceneManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRSceneManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("krscene") == 0) {
return loadScene(name, data);
@@ -59,7 +61,7 @@ KRResource* KRSceneManager::getResource(const std::string& name, const std::stri
return nullptr;
}
KRScene* KRSceneManager::loadScene(const std::string& name, KRDataBlock* data)
KRScene* KRSceneManager::loadScene(const std::string& name, Block* data)
{
std::lock_guard<std::mutex> lock(m_mutex);
std::string lowerName = name;

View File

@@ -35,7 +35,7 @@
#include "KRResourceManager.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRScene;
@@ -45,13 +45,13 @@ public:
KRSceneManager(KRContext& context);
virtual ~KRSceneManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
KRScene* createScene(const std::string& name);
void add(KRScene* scene);
KRScene* loadScene(const std::string& name, KRDataBlock* data);
KRScene* loadScene(const std::string& name, mimir::Block* data);
KRScene* getScene(const std::string& name);
KRScene* getFirstScene();

View File

@@ -32,6 +32,8 @@
#include "KRShader.h"
#include "spirv_reflect.h"
using namespace mimir;
ShaderStage getShaderStageFromExtension(const char* extension)
{
if (strcmp(extension, "vert") == 0) {
@@ -104,7 +106,7 @@ VkShaderStageFlagBits getShaderStageFlagBitsFromShaderStage(ShaderStage stage)
KRShader::KRShader(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_pData = new Block();
m_extension = extension;
m_subExtension = KRResource::GetFileExtension(name);
m_stage = getShaderStageFromExtension(m_subExtension.c_str());
@@ -113,7 +115,7 @@ KRShader::KRShader(KRContext& context, std::string name, std::string extension)
getReflection();
}
KRShader::KRShader(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
KRShader::KRShader(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
{
m_pData = data;
m_extension = extension;
@@ -138,13 +140,13 @@ std::string& KRShader::getSubExtension()
return m_subExtension;
}
bool KRShader::save(KRDataBlock& data)
bool KRShader::save(Block& data)
{
data.append(*m_pData);
return true;
}
KRDataBlock* KRShader::getData()
Block* KRShader::getData()
{
return m_pData;
}

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
#include "spirv_reflect.h"
@@ -66,7 +66,7 @@ class KRShader : public KRResource
{
public:
KRShader(KRContext& context, std::string name, std::string extension);
KRShader(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
KRShader(KRContext& context, std::string name, std::string extension, mimir::Block* data);
virtual ~KRShader();
virtual std::string getExtension();
@@ -74,9 +74,9 @@ public:
bool createShaderModule(VkDevice& device, VkShaderModule& module);
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
KRDataBlock* getData();
mimir::Block* getData();
const SpvReflectShaderModule* getReflection();
ShaderStage getShaderStage() const;
VkShaderStageFlagBits getShaderStageFlagBits() const;
@@ -86,7 +86,7 @@ private:
std::string m_extension;
std::string m_subExtension;
KRDataBlock* m_pData;
mimir::Block* m_pData;
SpvReflectShaderModule m_reflection;
bool m_reflectionValid;

View File

@@ -36,6 +36,8 @@
#include "KRUnknownManager.h"
#include "KRUnknown.h"
using namespace mimir;
KRShaderManager::KRShaderManager(KRContext& context) : KRResourceManager(context)
, m_initializedGlslang(false)
, m_includer(&context)
@@ -55,7 +57,7 @@ KRShaderManager::~KRShaderManager()
}
}
KRResource* KRShaderManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRShaderManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("spv") == 0) {
return load(name, extension, data);
@@ -98,7 +100,7 @@ void KRShaderManager::add(KRShader* shader)
}
}
KRShader* KRShaderManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
KRShader* KRShaderManager::load(const std::string& name, const std::string& extension, Block* data)
{
KRShader* shader = new KRShader(getContext(), name, extension, data);
if (shader) add(shader);
@@ -347,7 +349,7 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
break;
}
if (!shader_name.empty()) {
KRDataBlock* data = new KRDataBlock();
Block* data = new Block();
data->append(static_cast<void*>(spirv.data()), spirv.size() * sizeof(unsigned int));
KRShader* shader = new KRShader(getContext(), shader_name, "spv", data);
add(shader);
@@ -393,7 +395,7 @@ glslang::TShader::Includer::IncludeResult* KRShaderManager::Includer::includeLoc
if (!source) {
return nullptr;
}
KRDataBlock* data = source->getData();
Block* data = source->getData();
data->lock();
const char* sourceString = static_cast<const char*>(data->getStart());
return new IncludeResult(std::string(headerName), sourceString, data->getSize(), static_cast<void*>(data));
@@ -401,6 +403,6 @@ glslang::TShader::Includer::IncludeResult* KRShaderManager::Includer::includeLoc
void KRShaderManager::Includer::releaseInclude(IncludeResult* includeResult)
{
KRDataBlock* data = static_cast<KRDataBlock*>(includeResult->userData);
Block* data = static_cast<Block*>(includeResult->userData);
data->unlock();
}

View File

@@ -37,7 +37,7 @@
#include "KRShader.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRUnknown;
@@ -47,12 +47,12 @@ public:
KRShaderManager(KRContext& context);
virtual ~KRShaderManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
void add(KRShader* shader);
KRShader* load(const std::string& name, const std::string& extension, KRDataBlock* data);
KRShader* load(const std::string& name, const std::string& extension, mimir::Block* data);
KRShader* get(const std::string& name, const std::string& extension);
bool compileAll(KRBundle* outputBundle, KRUnknown* logResource);

View File

@@ -31,13 +31,15 @@
#include "KRSource.h"
using namespace mimir;
KRSource::KRSource(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_pData = new Block();
m_extension = extension;
}
KRSource::KRSource(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
KRSource::KRSource(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
{
m_pData = data;
m_extension = extension;
@@ -53,13 +55,13 @@ std::string KRSource::getExtension()
return m_extension;
}
bool KRSource::save(KRDataBlock& data)
bool KRSource::save(Block& data)
{
data.append(*m_pData);
return true;
}
KRDataBlock* KRSource::getData()
Block* KRSource::getData()
{
return m_pData;
}

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
class KRSource : public KRResource
@@ -41,17 +41,17 @@ class KRSource : public KRResource
public:
KRSource(KRContext& context, std::string name, std::string extension);
KRSource(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
KRSource(KRContext& context, std::string name, std::string extension, mimir::Block* data);
virtual ~KRSource();
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
KRDataBlock* getData();
mimir::Block* getData();
private:
std::string m_extension;
KRDataBlock* m_pData;
mimir::Block* m_pData;
};

View File

@@ -33,6 +33,8 @@
#include "KREngine-common.h"
#include "KRShader.h"
using namespace mimir;
KRSourceManager::KRSourceManager(KRContext& context) : KRResourceManager(context)
{
@@ -75,7 +77,7 @@ void KRSourceManager::add(KRSource* source)
}
}
KRResource* KRSourceManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRSourceManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (getShaderStageFromExtension(extension.c_str()) != ShaderStage::Invalid ||
extension.compare("glsl") == 0 ||
@@ -95,7 +97,7 @@ KRResource* KRSourceManager::getResource(const std::string& name, const std::str
return nullptr;
}
KRSource* KRSourceManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
KRSource* KRSourceManager::load(const std::string& name, const std::string& extension, Block* data)
{
KRSource* source = new KRSource(getContext(), name, extension, data);
if (source) add(source);

View File

@@ -36,7 +36,7 @@
#include "KRResourceManager.h"
#include "KRSource.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRSourceManager : public KRResourceManager
{
@@ -44,12 +44,12 @@ public:
KRSourceManager(KRContext& context);
virtual ~KRSourceManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
void add(KRSource* source);
KRSource* load(const std::string& name, const std::string& extension, KRDataBlock* data);
KRSource* load(const std::string& name, const std::string& extension, mimir::Block* data);
KRSource* get(const std::string& name, const std::string& extension);
const unordered_map<std::string, KRSource*>& get(const std::string& extension);

View File

@@ -31,7 +31,7 @@
#include "KREngine-common.h"
#include "KRTexture.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRContext.h"
#include "KRTextureManager.h"

View File

@@ -35,7 +35,9 @@
#include "KRContextObject.h"
#include "KRResource.h"
class KRDataBlock;
namespace mimir {
class Block;
}
class KRCamera;
class KRDeviceManager;
class KRDevice;

View File

@@ -33,7 +33,9 @@
#include "KRTexture2D.h"
#include "KRTextureManager.h"
KRTexture2D::KRTexture2D(KRContext& context, KRDataBlock* data, std::string name) : KRTexture(context, name)
using namespace mimir;
KRTexture2D::KRTexture2D(KRContext& context, Block* data, std::string name) : KRTexture(context, name)
{
m_pData = data;
}
@@ -114,7 +116,7 @@ bool KRTexture2D::save(const std::string& path)
}
}
bool KRTexture2D::save(KRDataBlock& data)
bool KRTexture2D::save(Block& data)
{
if (m_pData) {
data.append(*m_pData);

View File

@@ -32,7 +32,7 @@
#pragma once
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include "block.h"
using std::list;
@@ -43,16 +43,16 @@ class KRDevice;
class KRTexture2D : public KRTexture
{
public:
KRTexture2D(KRContext& context, KRDataBlock* data, std::string name);
KRTexture2D(KRContext& context, mimir::Block* data, std::string name);
virtual ~KRTexture2D();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
virtual bool uploadTexture(KRDevice& device, VkImage& image, int lod_max_dim, int& current_lod_max_dim, bool premultiply_alpha = false) = 0;
virtual Vector2i getDimensions() const = 0;
protected:
KRDataBlock* m_pData;
mimir::Block* m_pData;
bool createGPUTexture(int lod_max_dim) override;
};

View File

@@ -143,7 +143,7 @@ bool KRTextureAnimated::save(const std::string& path)
return true; // Animated textures are just references; there are no files to output
}
bool KRTextureAnimated::save(KRDataBlock& data)
bool KRTextureAnimated::save(Block& data)
{
return true; // Animated textures are just references; there are no files to output
}

View File

@@ -34,6 +34,8 @@
#include "KRTexture.h"
#include "KRTexture2D.h"
using namespace mimir;
class KRTextureAnimated : public KRTexture
{
public:
@@ -41,7 +43,7 @@ public:
virtual ~KRTextureAnimated();
virtual std::string getExtension();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool save(Block& data);
virtual long getMemRequiredForSize(int max_dim);
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);

View File

@@ -33,6 +33,8 @@
#include "KRTexture2D.h"
#include "KRContext.h"
using namespace mimir;
KRTextureCube::KRTextureCube(KRContext& context, std::string name) : KRTexture(context, name)
{
@@ -163,7 +165,7 @@ bool KRTextureCube::save(const std::string& path)
return true; // Cube maps are just references; there are no files to output
}
bool KRTextureCube::save(KRDataBlock& data)
bool KRTextureCube::save(Block& data)
{
return true; // Cube maps are just references; there are no files to output
}

View File

@@ -42,7 +42,7 @@ public:
virtual ~KRTextureCube();
virtual std::string getExtension();
virtual bool save(const std::string& path);
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
virtual long getMemRequiredForSize(int max_dim);
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);

View File

@@ -38,7 +38,7 @@ __uint8_t _KTXFileIdentifier[12] = {
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
};
KRTextureKTX::KRTextureKTX(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
KRTextureKTX::KRTextureKTX(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
{
m_pData->copy(&m_header, 0, sizeof(KTXHeader));
if (memcmp(_KTXFileIdentifier, m_header.identifier, 12) != 0) {
@@ -84,7 +84,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, KRDataBlock* data, std::string na
m_min_lod_max_dim = KRMAX(width, height);
}
KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<KRDataBlock*>& blocks) : KRTexture2D(context, new KRDataBlock(), name)
KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<Block*>& blocks) : KRTexture2D(context, new Block(), name)
{
memcpy(m_header.identifier, _KTXFileIdentifier, 12);
m_header.endianness = 0x04030201;
@@ -103,7 +103,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int in
m_pData->append(&m_header, sizeof(m_header));
for (auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
KRDataBlock* source_block = *block_itr;
Block* source_block = *block_itr;
__uint32_t block_size = (__uint32_t)source_block->getSize();
m_pData->append(&block_size, 4);
m_pData->append(*source_block);
@@ -118,8 +118,8 @@ KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int in
KRTextureKTX::~KRTextureKTX()
{
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
delete block;
}
m_blocks.clear();
@@ -370,8 +370,8 @@ long KRTextureKTX::getMemRequiredForSize(int max_dim)
int height = m_header.pixelHeight;
long memoryRequired = 0;
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
if (width <= target_dim && height <= target_dim) {
memoryRequired += (long)block->getSize();
}
@@ -408,8 +408,8 @@ bool KRTextureKTX::uploadTexture(KRDevice& device, VkImage& image, int lod_max_d
// Upload texture data
int destination_level = 0;
int source_level = 0;
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
if (width <= target_dim && height <= target_dim) {
if (width > current_lod_max_dim) {

View File

@@ -33,11 +33,13 @@
#include "KRTexture2D.h"
using namespace mimir;
class KRTextureKTX : public KRTexture2D
{
public:
KRTextureKTX(KRContext& context, KRDataBlock* data, std::string name);
KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<KRDataBlock*>& blocks);
KRTextureKTX(KRContext& context, Block* data, std::string name);
KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<Block*>& blocks);
virtual ~KRTextureKTX();
virtual std::string getExtension();
@@ -50,7 +52,7 @@ public:
protected:
std::list<KRDataBlock*> m_blocks;
std::list<Block*> m_blocks;
typedef struct _KTXHeader
{

View File

@@ -34,11 +34,13 @@
#include "KREngine-common.h"
using namespace mimir;
__uint8_t _KTX2FileIdentifier[12] = {
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
};
KRTextureKTX2::KRTextureKTX2(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
KRTextureKTX2::KRTextureKTX2(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
{
m_pData->copy(&m_header, 0, sizeof(KTX2Header));
if (memcmp(_KTX2FileIdentifier, m_header.identifier, 12) != 0) {

View File

@@ -36,7 +36,7 @@
class KRTextureKTX2 : public KRTexture2D
{
public:
KRTextureKTX2(KRContext& context, KRDataBlock* data, std::string name);
KRTextureKTX2(KRContext& context, mimir::Block* data, std::string name);
virtual ~KRTextureKTX2();
virtual std::string getExtension();

View File

@@ -68,7 +68,7 @@ void KRTextureManager::setMaxAnisotropy(float max_anisotropy)
m_maxAnisotropy = max_anisotropy;
}
KRResource* KRTextureManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRTextureManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
if (extension.compare("pvr") == 0 ||
extension.compare("ktx") == 0 ||
@@ -95,7 +95,7 @@ KRResource* KRTextureManager::getResource(const std::string& name, const std::st
return nullptr;
}
KRTexture* KRTextureManager::loadTexture(const char* szName, const char* szExtension, KRDataBlock* data)
KRTexture* KRTextureManager::loadTexture(const char* szName, const char* szExtension, Block* data)
{
KRTexture* pTexture = NULL;

View File

@@ -38,7 +38,7 @@
#include "KRTexture.h"
#include "KRContextObject.h"
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRContext.h"
#include "KRStreamerThread.h"
@@ -49,12 +49,12 @@ public:
virtual ~KRTextureManager();
void destroy();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
bool selectTexture(unsigned int target, int iTextureUnit, int iTextureHandle);
KRTexture* loadTexture(const char* szName, const char* szExtension, KRDataBlock* data);
KRTexture* loadTexture(const char* szName, const char* szExtension, mimir::Block* data);
KRTexture* getTextureCube(const char* szName);
KRTexture* getTexture(const std::string& name);

View File

@@ -34,6 +34,8 @@
#include "KREngine-common.h"
using namespace mimir;
#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
@@ -62,7 +64,7 @@ typedef struct _PVRTexHeader
uint32_t numSurfs;
} PVRTexHeader;
KRTexturePVR::KRTexturePVR(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
KRTexturePVR::KRTexturePVR(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
{
#if TARGET_OS_IPHONE
@@ -139,8 +141,8 @@ KRTexturePVR::KRTexturePVR(KRContext& context, KRDataBlock* data, std::string na
KRTexturePVR::~KRTexturePVR()
{
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
delete block;
}
m_blocks.clear();
@@ -179,8 +181,8 @@ long KRTexturePVR::getMemRequiredForSize(int max_dim)
int height = m_iHeight;
long memoryRequired = 0;
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
if (width <= target_dim && height <= target_dim) {
memoryRequired += (long)block->getSize();
}
@@ -216,8 +218,8 @@ bool KRTexturePVR::uploadTexture(KRDevice& device, VkImage& image, int lod_max_d
// Upload texture data
int destination_level = 0;
int source_level = 0;
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
KRDataBlock* block = *itr;
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
Block* block = *itr;
if (width <= target_dim && height <= target_dim) {
if (width > current_lod_max_dim) {

View File

@@ -36,7 +36,7 @@
class KRTexturePVR : public KRTexture2D
{
public:
KRTexturePVR(KRContext& context, KRDataBlock* data, std::string name);
KRTexturePVR(KRContext& context, mimir::Block* data, std::string name);
virtual ~KRTexturePVR();
virtual std::string getExtension();
@@ -54,5 +54,5 @@ protected:
unsigned int m_internalFormat;
bool m_bHasAlpha;
std::list<KRDataBlock*> m_blocks;
std::list<mimir::Block*> m_blocks;
};

View File

@@ -70,7 +70,7 @@ typedef struct
#endif
KRTextureTGA::KRTextureTGA(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
KRTextureTGA::KRTextureTGA(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
{
data->lock();
TGA_HEADER* pHeader = (TGA_HEADER*)data->getStart();
@@ -329,7 +329,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
m_pData->lock();
std::list<KRDataBlock *> blocks;
std::list<Block *> blocks;
getContext().getTextureManager()->_setActiveTexture(0);
@@ -370,7 +370,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
while(lod_width > 1) {
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_WIDTH, &lod_width));
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size));
KRDataBlock *new_block = new KRDataBlock();
Block *new_block = new Block();
new_block->expand(compressed_size);
new_block->lock();
GLDEBUG(glGetCompressedTexImage(GL_TEXTURE_2D, lod_level, new_block->getStart()));
@@ -390,7 +390,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
m_pData->unlock();
for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
KRDataBlock *block = *block_itr;
Block *block = *block_itr;
delete block;
}

View File

@@ -33,10 +33,12 @@
#include "KRTexture2D.h"
using namespace mimir;
class KRTextureTGA : public KRTexture2D
{
public:
KRTextureTGA(KRContext& context, KRDataBlock* data, std::string name);
KRTextureTGA(KRContext& context, Block* data, std::string name);
virtual ~KRTextureTGA();
virtual std::string getExtension();

View File

@@ -31,13 +31,15 @@
#include "KRUnknown.h"
using namespace mimir;
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_pData = new Block();
m_extension = extension;
}
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
{
m_pData = data;
m_extension = extension;
@@ -53,13 +55,13 @@ std::string KRUnknown::getExtension()
return m_extension;
}
bool KRUnknown::save(KRDataBlock& data)
bool KRUnknown::save(Block& data)
{
data.append(*m_pData);
return true;
}
KRDataBlock* KRUnknown::getData()
Block* KRUnknown::getData()
{
return m_pData;
}

View File

@@ -33,7 +33,7 @@
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
#include "KRResource.h"
class KRUnknown : public KRResource
@@ -41,17 +41,17 @@ class KRUnknown : public KRResource
public:
KRUnknown(KRContext& context, std::string name, std::string extension);
KRUnknown(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
KRUnknown(KRContext& context, std::string name, std::string extension, mimir::Block* data);
virtual ~KRUnknown();
virtual std::string getExtension();
virtual bool save(KRDataBlock& data);
virtual bool save(mimir::Block& data);
KRDataBlock* getData();
mimir::Block* getData();
private:
std::string m_extension;
KRDataBlock* m_pData;
mimir::Block* m_pData;
};

View File

@@ -32,6 +32,8 @@
#include "KRUnknownManager.h"
#include "KREngine-common.h"
using namespace mimir;
KRUnknownManager::KRUnknownManager(KRContext& context) : KRResourceManager(context)
{
@@ -75,7 +77,7 @@ void KRUnknownManager::add(KRUnknown* unknown)
}
KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, Block* data)
{
// KRUnknown's can have any extension
return load(name, extension, data);
@@ -87,7 +89,7 @@ KRResource* KRUnknownManager::getResource(const std::string& name, const std::st
return get(name, extension);
}
KRUnknown* KRUnknownManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
KRUnknown* KRUnknownManager::load(const std::string& name, const std::string& extension, Block* data)
{
KRUnknown* unknown = new KRUnknown(getContext(), name, extension, data);
if (unknown) add(unknown);

View File

@@ -37,7 +37,7 @@
#include "KRUnknown.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "block.h"
class KRUnknownManager : public KRResourceManager
{
@@ -45,12 +45,12 @@ public:
KRUnknownManager(KRContext& context);
virtual ~KRUnknownManager();
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
void add(KRUnknown* unknown);
KRUnknown* load(const std::string& name, const std::string& extension, KRDataBlock* data);
KRUnknown* load(const std::string& name, const std::string& extension, mimir::Block* data);
KRUnknown* get(const std::string& name, const std::string& extension);

View File

@@ -1,5 +1,5 @@
//
// KRDataBlock.cpp
// block.cpp
// Kraken Engine
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
@@ -29,7 +29,7 @@
// or implied, of Kearwood Gilbert.
//
#include "KRDataBlock.h"
#include "block.h"
#include "KREngine-common.h"
#include "KRResource.h"
#include "KRContext.h"
@@ -40,6 +40,7 @@
#include <sys/mman.h>
#endif
#define KRENGINE_MIN_MMAP 32768
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1))
#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1)) + KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY)
@@ -47,7 +48,9 @@ int m_mapCount = 0;
size_t m_mapSize = 0;
size_t m_mapOverhead = 0;
KRDataBlock::KRDataBlock()
namespace mimir {
Block::Block()
{
m_data = NULL;
m_data_size = 0;
@@ -66,7 +69,7 @@ KRDataBlock::KRDataBlock()
m_bReadOnly = false;
}
KRDataBlock::KRDataBlock(void* data, size_t size)
Block::Block(void* data, size_t size)
{
m_data = NULL;
m_data_size = 0;
@@ -86,13 +89,13 @@ KRDataBlock::KRDataBlock(void* data, size_t size)
load(data, size);
}
KRDataBlock::~KRDataBlock()
Block::~Block()
{
unload();
}
// Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use
void KRDataBlock::unload()
void Block::unload()
{
assert(m_lockCount == 0);
@@ -130,7 +133,7 @@ void KRDataBlock::unload()
}
// Encapsulate a pointer. Note - The pointer will not be free'ed
bool KRDataBlock::load(void* data, size_t size)
bool Block::load(void* data, size_t size)
{
unload();
m_data = data;
@@ -141,7 +144,7 @@ bool KRDataBlock::load(void* data, size_t size)
}
// Load a file into memory using mmap. The data pointer will be protected as read-only until append() or expand() is called
bool KRDataBlock::load(const std::string& path)
bool Block::load(const std::string& path)
{
bool success = false;
unload();
@@ -180,10 +183,10 @@ bool KRDataBlock::load(const std::string& path)
return success;
}
// Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object.
KRDataBlock* KRDataBlock::getSubBlock(int start, int length)
// Create a Block encapsulating a sub-region of this block. The caller is responsible to free the object.
Block* Block::getSubBlock(int start, int length)
{
KRDataBlock* new_block = new KRDataBlock();
Block* new_block = new Block();
new_block->m_data_size = length;
#if defined(_WIN32) || defined(_WIN64)
@@ -206,27 +209,27 @@ KRDataBlock* KRDataBlock::getSubBlock(int start, int length)
}
// Return a pointer to the start of the data block
void* KRDataBlock::getStart()
void* Block::getStart()
{
assertLocked();
return m_data;
}
// Return a pointer to the byte after the end of the data block
void* KRDataBlock::getEnd()
void* Block::getEnd()
{
assertLocked();
return (unsigned char*)m_data + m_data_size;
}
// Return the size of the data block. Use append() or expand() to make the data block larger
size_t KRDataBlock::getSize() const
size_t Block::getSize() const
{
return m_data_size;
}
// Expand the data block, and switch it to read-write mode. Note - this may result in a mmap'ed file being copied to malloc'ed ram and then closed
void KRDataBlock::expand(size_t size)
void Block::expand(size_t size)
{
#if defined(_WIN32) || defined(_WIN64)
if (m_data == NULL && m_hPackFile == INVALID_HANDLE_VALUE) {
@@ -265,7 +268,7 @@ void KRDataBlock::expand(size_t size)
}
// Append data to the end of the block, increasing the size of the block and making it read-write.
void KRDataBlock::append(void* data, size_t size)
void Block::append(void* data, size_t size)
{
// Expand the data block
expand(size);
@@ -278,13 +281,13 @@ void KRDataBlock::append(void* data, size_t size)
// Copy the entire data block to the destination pointer
void KRDataBlock::copy(void* dest)
void Block::copy(void* dest)
{
copy(dest, 0, (int)m_data_size);
}
// Copy a range of data to the destination pointer
void KRDataBlock::copy(void* dest, int start, int count)
void Block::copy(void* dest, int start, int count)
{
#if defined(_WIN32) || defined(_WIN64)
if (m_lockCount == 0 && m_hPackFile != INVALID_HANDLE_VALUE) {
@@ -321,7 +324,7 @@ void KRDataBlock::copy(void* dest, int start, int count)
}
// Append data to the end of the block, increasing the size of the block and making it read-write.
void KRDataBlock::append(KRDataBlock & data)
void Block::append(Block & data)
{
data.lock();
append(data.getStart(), data.getSize());
@@ -329,7 +332,7 @@ void KRDataBlock::append(KRDataBlock & data)
}
// Append string to the end of the block, increasing the size of the block and making it read-write. The resulting datablock includes a terminating character
void KRDataBlock::append(const std::string & s)
void Block::append(const std::string & s)
{
const char* szText = s.c_str();
size_t text_length = strlen(szText);
@@ -349,7 +352,7 @@ void KRDataBlock::append(const std::string & s)
}
// Save the data to a file.
bool KRDataBlock::save(const std::string & path)
bool Block::save(const std::string & path)
{
#if defined(_WIN32) || defined(_WIN64)
bool success = true;
@@ -429,9 +432,9 @@ bool KRDataBlock::save(const std::string & path)
}
// Get contents as a string
std::string KRDataBlock::getString()
std::string Block::getString()
{
KRDataBlock b;
Block b;
b.append(*this);
b.append((void*)"\0", 1); // Ensure data is null terminated, to read as a string safely
b.lock();
@@ -471,7 +474,7 @@ void ReportWindowsLastError(LPCTSTR lpszFunction)
#endif
// Lock the memory, forcing it to be loaded into a contiguous block of address space
void KRDataBlock::lock()
void Block::lock()
{
if (m_lockCount == 0) {
@@ -503,7 +506,7 @@ void KRDataBlock::lock()
}
assert(m_mmapData != NULL);
#elif defined(__APPLE__) || defined(ANDROID)
//fprintf(stderr, "KRDataBlock::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
//fprintf(stderr, "Block::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
// Round m_data_offset down to the next memory page, as required by mmap
if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (caddr_t)-1) {
@@ -551,7 +554,7 @@ m_lockCount++;
}
// Unlock the memory, releasing the address space for use by other allocations
void KRDataBlock::unlock()
void Block::unlock()
{
// We expect that the data block was previously locked
assertLocked();
@@ -571,7 +574,7 @@ void KRDataBlock::unlock()
free(m_data);
m_data = NULL;
} else {
//fprintf(stderr, "KRDataBlock::unlock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
//fprintf(stderr, "Block::unlock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
#if defined(_WIN32) || defined(_WIN64)
if (m_mmapData != NULL) {
UnmapViewOfFile(m_mmapData);
@@ -599,7 +602,9 @@ m_lockCount--;
}
// Assert if not locked
void KRDataBlock::assertLocked()
void Block::assertLocked()
{
assert(m_lockCount > 0);
}
} // namespace mimir

View File

@@ -1,5 +1,5 @@
//
// KRDataBlock.h
// block.h
// Kraken Engine
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
@@ -31,20 +31,20 @@
#pragma once
#include <string>
#include "KREngine-common.h"
#if defined(_WIN32) || defined(_WIN64)
#include <Windows.h>
#endif
#define KRENGINE_MIN_MMAP 32768
class KRDataBlock
namespace mimir {
class Block
{
public:
KRDataBlock();
KRDataBlock(void* data, size_t size);
~KRDataBlock();
Block();
Block(void* data, size_t size);
~Block();
// Encapsulate a pointer. Note - The pointer will not be free'ed
bool load(void* data, size_t size);
@@ -55,14 +55,14 @@ public:
// Save the data to a file.
bool save(const std::string& path);
// Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object.
KRDataBlock* getSubBlock(int start, int length);
// Create a Block encapsulating a sub-region of this block. The caller is responsible to free the object.
Block* getSubBlock(int start, int length);
// Append data to the end of the block, increasing the size of the block and making it read-write.
void append(void* data, size_t size);
// Append data to the end of the block, increasing the size of the block and making it read-write.
void append(KRDataBlock& data);
void append(Block& data);
// Append string to the end of the block, increasing the size of the block and making it read-write. The null terminating character is included
void append(const std::string& s);
@@ -111,7 +111,7 @@ private:
#endif
std::string m_fileName;
KRDataBlock* m_fileOwnerDataBlock;
Block* m_fileOwnerDataBlock;
void* m_mmapData;
// For malloc'ed objects:
@@ -127,3 +127,5 @@ private:
void assertLocked();
};
} // namespace mimir