Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cleanup] Advanced Screenshot now using C++11 threads #822

Merged
merged 1 commit into from Apr 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 3 additions & 35 deletions source/main/gfx/AdvancedScreen.h
Expand Up @@ -26,6 +26,8 @@ along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.

#include "RoRPrerequisites.h"

#include <thread>

#define SET_BIT(var, pos) ((var) |= (1<<(pos)))
#define CLEAR_BIT(var, pos) ((var) &= ~(1<<(pos)))
#define SET_LSB(var) ((var) |= 1)
Expand All @@ -42,34 +44,6 @@ void save(Ogre::uchar *data, Ogre::uchar *databuf, int mWidth, int mHeight, Ogre
OGRE_FREE(databuf, Ogre::MEMCATEGORY_RENDERSYS);
}

struct wrap {
Ogre::uchar *data;
Ogre::uchar *databuf;
int mWidth;
int mHeight;
Ogre::PixelFormat pf;
Ogre::String filename;

wrap(Ogre::uchar *data, Ogre::uchar *databuf, int mWidth, int mHeight, Ogre::PixelFormat pf, Ogre::String filename) :
data(data),
databuf(databuf),
mWidth(mWidth),
mHeight(mHeight),
pf(pf),
filename(filename)
{
}
};

void* save_img(void *arg)
{
std::auto_ptr< wrap > img(static_cast< wrap* >(arg));
save(img->data, img->databuf, img->mWidth, img->mHeight, img->pf, img->filename);

pthread_exit(NULL);
return NULL;
}

// this only works with lossless image compression (png)

class AdvancedScreen : public ZeroedMemoryAllocator
Expand Down Expand Up @@ -148,13 +122,7 @@ class AdvancedScreen : public ZeroedMemoryAllocator
//float used_per = ((float)(dsize * 8 + 40) / (float)isize) * 100.0f;
//LOG("used " + TOSTRING(used_per) + " %");

//save it
wrap* img = new wrap(data, databuf, mWidth, mHeight, pf, filename);
pthread_t pt;
pthread_create(&pt, NULL, save_img, img);

// C++11 alternative
//std::thread{save, data, databuf, mWidth, mHeight, pf, filename}.detach();
std::thread{save, data, databuf, mWidth, mHeight, pf, filename}.detach();
}

protected:
Expand Down