Asynchronous streaming and memory management improvements in progress.
--HG-- branch : async_streaming
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "KRDataBlock.h"
|
||||
#include "KREngine-common.h"
|
||||
#include "KRResource.h"
|
||||
|
||||
KRDataBlock::KRDataBlock() {
|
||||
m_data = NULL;
|
||||
@@ -97,7 +98,7 @@ bool KRDataBlock::load(const std::string &path)
|
||||
m_fdPackFile = open(path.c_str(), O_RDONLY);
|
||||
if(m_fdPackFile >= 0) {
|
||||
m_fileOwnerDataBlock = this;
|
||||
m_fileName = path;
|
||||
m_fileName = KRResource::GetFileBase(path);
|
||||
if(fstat(m_fdPackFile, &statbuf) >= 0) {
|
||||
m_data_size = statbuf.st_size;
|
||||
m_data_offset = 0;
|
||||
|
||||
@@ -45,6 +45,9 @@ float const D2R = PI * 2 / 360;
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/signals2/mutex.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "KRMeshCube.h"
|
||||
#include "KRMeshSphere.h"
|
||||
|
||||
KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) {
|
||||
KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context), m_streamer(context) {
|
||||
m_currentVBO.vbo_handle = -1;
|
||||
m_currentVBO.vbo_handle_indexes = -1;
|
||||
m_currentVBO.vao_handle = -1;
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
|
||||
#include "KRMeshStreamer.h"
|
||||
|
||||
class KRContext;
|
||||
class KRMesh;
|
||||
|
||||
@@ -135,6 +137,8 @@ private:
|
||||
std::vector<draw_call_info> m_draw_calls;
|
||||
bool m_draw_call_logging_enabled;
|
||||
bool m_draw_call_log_used;
|
||||
|
||||
KRMeshStreamer m_streamer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
33
KREngine/kraken/KRMeshStreamer.cpp
Normal file
33
KREngine/kraken/KRMeshStreamer.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// KRMeshStreamer.cpp
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 11/1/2013.
|
||||
// Copyright (c) 2013 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "KRMeshStreamer.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context)
|
||||
{
|
||||
m_stop = false;
|
||||
m_thread = std::thread(&KRMeshStreamer::run, this);
|
||||
}
|
||||
|
||||
KRMeshStreamer::~KRMeshStreamer()
|
||||
{
|
||||
m_stop = true;
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
void KRMeshStreamer::run()
|
||||
{
|
||||
std::chrono::microseconds sleep_duration( 100 );
|
||||
|
||||
while(!m_stop)
|
||||
{
|
||||
std::this_thread::sleep_for( sleep_duration );
|
||||
}
|
||||
}
|
||||
57
KREngine/kraken/KRMeshStreamer.h
Normal file
57
KREngine/kraken/KRMeshStreamer.h
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// KRMeshManager.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRMESHSTREAMER_H
|
||||
#define KRMESHSTREAMER_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
class KRContext;
|
||||
|
||||
class KRMeshStreamer
|
||||
{
|
||||
public:
|
||||
KRMeshStreamer(KRContext &context);
|
||||
~KRMeshStreamer();
|
||||
|
||||
private:
|
||||
KRContext &m_context;
|
||||
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_stop;
|
||||
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif /* defined(KRMESHSTREAMER_H) */
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "KRTextureAnimated.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
||||
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context), m_streamer(context) {
|
||||
m_textureMemUsed = 0;
|
||||
|
||||
for(int iTexture=0; iTexture<KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "KREngine-common.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRContext.h"
|
||||
#include "KRTextureStreamer.h"
|
||||
|
||||
class KRTextureManager : public KRContextObject {
|
||||
public:
|
||||
@@ -95,6 +96,8 @@ private:
|
||||
|
||||
void rotateBuffers();
|
||||
void balanceTextureMemory();
|
||||
|
||||
KRTextureStreamer m_streamer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
33
KREngine/kraken/KRTextureStreamer.cpp
Normal file
33
KREngine/kraken/KRTextureStreamer.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// KRTextureStreamer.cpp
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 11/1/2013.
|
||||
// Copyright (c) 2013 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "KRTextureStreamer.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context)
|
||||
{
|
||||
m_stop = false;
|
||||
m_thread = std::thread(&KRTextureStreamer::run, this);
|
||||
}
|
||||
|
||||
KRTextureStreamer::~KRTextureStreamer()
|
||||
{
|
||||
m_stop = true;
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
void KRTextureStreamer::run()
|
||||
{
|
||||
std::chrono::microseconds sleep_duration( 100 );
|
||||
|
||||
while(!m_stop)
|
||||
{
|
||||
std::this_thread::sleep_for( sleep_duration );
|
||||
}
|
||||
}
|
||||
57
KREngine/kraken/KRTextureStreamer.h
Normal file
57
KREngine/kraken/KRTextureStreamer.h
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// KRTextureManager.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRTEXTURESTREAMER_H
|
||||
#define KRTEXTURESTREAMER_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
class KRContext;
|
||||
|
||||
class KRTextureStreamer
|
||||
{
|
||||
public:
|
||||
KRTextureStreamer(KRContext &context);
|
||||
~KRTextureStreamer();
|
||||
|
||||
private:
|
||||
KRContext &m_context;
|
||||
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_stop;
|
||||
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif /* defined(KRTEXTURESTREAMER_H) */
|
||||
Reference in New Issue
Block a user