Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
- Changed std::atomic to volatile
  • Loading branch information
Matus Novak committed Oct 25, 2015
1 parent 1f6b023 commit 7e2f4b4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 49 deletions.
22 changes: 11 additions & 11 deletions release/defaults.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"bumps-or-normals": false,
"export-attachments": false,
"num-of-threads": -1,
"output-folder": "",
"starmade-folder": "",
"texture-format": -1,
"texture-size": -1,
"use-alpha": false,
"use-diffuse": false,
"use-emissive": false,
"uv-maps": 0
"bumps-or-normals": true,
"export-attachments": true,
"num-of-threads": 7,
"output-folder": "C:\\",
"starmade-folder": "E:\\Program Files (x86)\\StarMade\\StarMade",
"texture-format": 0,
"texture-size": 2,
"use-alpha": true,
"use-diffuse": true,
"use-emissive": true,
"uv-maps": 2
}
17 changes: 9 additions & 8 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sm2obj::window::window(){

///=============================================================================
sm2obj::window::~window(){
exportThreadStop.store(true);
exportThreadStop = true;
exportThread.join();
}

Expand Down Expand Up @@ -91,7 +91,7 @@ void sm2obj::window::setup(){
widgetFrames[6].push_back(radioMatNoBumps = this->addRadio(360, 160, 100, 20, L"None"));
widgetFrames[6].push_back(this->addLabel(10, 180, windowSize.x-20, 80,
L"Diffuse - The color of the material\nEmissive - Light generated from the material (self illuminated blocks)\nAlpha - The transparency of the material\nBumps/Normals - The detailness of the material"));

// Frame 07 - System options
widgetFrames[7].push_back(this->addLabel(windowSize.x/2-70, windowSize.y/2, 200, 20, L"How many threads to use?"));
widgetFrames[7].push_back(comboNumOfThreads = this->addCombo(windowSize.x/2-50, windowSize.y/2+20, 100, 20));
Expand Down Expand Up @@ -235,14 +235,14 @@ bool sm2obj::window::checkoutBlueprint(){
///=============================================================================
bool sm2obj::window::checkoutOutputFolder(){
outputFolder = ffw::wstrToAnsi(textInputOutputFolder->getValue());

std::fstream test(outputFolder + "\\delete_me.txt", std::ios::trunc | std::ios::out);
if(!test){
ffw::logError() << "Please, select correct output folder before continuing!";
ffw::showModalError(this, L"Error!", L"Please, select correct output folder before continuing!");
return false;
}

system(std::string("DEL \"" + outputFolder + "\\delete_me.txt\"").c_str());
return true;
}
Expand Down Expand Up @@ -364,7 +364,7 @@ void sm2obj::window::nextFrame(){
if(!checkoutSystemSettings())return;
buttonNext->disable();
}

if(currentFrame < FRAMES_TOTAL-1){
buttonPrev->enable();
for(const auto& w : widgetFrames[currentFrame]){
Expand All @@ -387,7 +387,7 @@ void sm2obj::window::prevFrame(){
if(currentFrame == frame::exportType){
buttonNext->enable();
}

if(currentFrame > 0){
buttonNext->enable();
for(const auto& w : widgetFrames[currentFrame]){
Expand Down Expand Up @@ -419,7 +419,7 @@ void sm2obj::window::hideAll(){

///=============================================================================
void sm2obj::window::windowCloseEvent(){
exportThreadStop.store(true);
exportThreadStop = true;
exportThread.join();

saveUserDefaults();
Expand Down Expand Up @@ -530,6 +530,7 @@ void sm2obj::window::widgetEvent(const ffw::uiWidget* Widget){
// Start export
if(Widget == buttonObjectPlusTextures || Widget == buttonTexturesOnly || Widget == buttonObjectOnly){
nextFrame();
exportThreadStop = false;
exportThread.start(NULL);
buttonPrev->disable();
buttonNext->disable();
Expand All @@ -541,7 +542,7 @@ void sm2obj::window::widgetEvent(const ffw::uiWidget* Widget){
this->shouldClose(true);
} else {
// Wait for thread
exportThreadStop.store(true);
exportThreadStop = true;
exportThread.join();
ffw::showModalWarning(this, L"Warning!", L"Export cancelled by user! The exported object/textures may be corrupted!");
this->shouldClose(true);
Expand Down
2 changes: 1 addition & 1 deletion source/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace sm2obj {
int currentFrame;

sm2obj::defaults userDefaults;
std::atomic_bool exportThreadStop;
volatile bool exportThreadStop;
ffw::thread exportThread;
ffw::mutex exportThreadMutex;
void* exportThreadFunc(void* Data);
Expand Down
62 changes: 33 additions & 29 deletions source/windowExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct progressStruct {

static bool recursiveMetaLoader(sm2obj::entityInfoStruct* Output, const std::string& BlueprintFolder, const std::string& BlueprintName, const std::string& SubFolder);
static void recursiveMetaDump(sm2obj::entityInfoStruct* Output, int Indent);
static bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& BlueprintFolder, const std::string& OutputTemp, int& FileIndex, progressStruct& Progress, std::atomic_bool& Cancel);
static void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& InputOutputTemp, std::vector<sm2obj::threadInfoStruct*>& Threads, progressStruct& Progress, const std::vector<sm2obj::blockInfoStruct>& BlockInfo, std::atomic_bool& Cancel);
static bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& BlueprintFolder, const std::string& OutputTemp, int& FileIndex, progressStruct& Progress, volatile bool& Cancel);
static void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& InputOutputTemp, std::vector<sm2obj::threadInfoStruct*>& Threads, progressStruct& Progress, const std::vector<sm2obj::blockInfoStruct>& BlockInfo, volatile bool& Cancel);
static void* processChunk(void* ThreadInfoPtr);
static void generateEntityQueue(sm2obj::entityInfoStruct* Input, std::vector<sm2obj::entityInfoStruct*>* Output);
static bool mergeVertices(sm2obj::entityInfoStruct* Input, const std::string& InputOutputTemp, ffw::file* Output, bool SplitTextures, bool ExportUvMaps);
Expand Down Expand Up @@ -158,11 +158,15 @@ void* sm2obj::window::exportThreadFunc(void* Data){
labelBlockConfig->setValue(L"Block config: 0/2");
progressBlockConfig->setValue(0);

std::cout << "checking... " << exportThreadStop << std::endl;

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

std::cout << "loading..." << std::endl;

// Load block types
if(!loadBlockTypes(blockTypes, blockTypesPath)){
ffw::showModalError(this, L"Error!", L"Failed to open block type properties: " + ffw::utf8ToWstr(blockTypesPath));
Expand All @@ -176,7 +180,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
progressBlockConfig->setValue(50);

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -189,7 +193,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -216,7 +220,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
progressReadingMeta->setValue(100);

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -241,7 +245,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -266,7 +270,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
threads.clear();

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand Down Expand Up @@ -313,7 +317,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
delete chunkRawBuffer;

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -339,7 +343,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
ffw::logSuccess() << "Creating material file...";

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -348,7 +352,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
ffw::logDebug() << "Exporting altas materials";
ffw::logDebug() << "Creating 3 materials...";
createMaterialAtlas(&mtlOutput, true, exportDiffuse, exportAlpha, exportNormals, exportEmissive, textureExtension);

} else if(exportMaterials){
ffw::logDebug() << "Exporting block materials";
std::vector<ffw::vec2i> materialList;
Expand Down Expand Up @@ -380,7 +384,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}
}
Expand Down Expand Up @@ -411,7 +415,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -425,7 +429,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -439,7 +443,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -450,7 +454,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){

guiProgress.status++;
guiProgress.setProgress("Exporting textures");

} else if(exportNormals){
exportNormalAtlas(textureFolder + "\\t000_NRM.png", textureSize, textureOutputFolder + "\\Atlas_0_bump." + textureExtension);
exportNormalAtlas(textureFolder + "\\t001_NRM.png", textureSize, textureOutputFolder + "\\Atlas_1_bump." + textureExtension);
Expand All @@ -468,7 +472,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

Expand All @@ -479,15 +483,15 @@ void* sm2obj::window::exportThreadFunc(void* Data){
}

// Check for cancelation
if(exportThreadStop.load()){
if(exportThreadStop){
return NULL;
}

if(exportNormals && useBumps){
exportTileBump(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension);
guiProgress.status++;
guiProgress.setProgress("Exporting textures");

} else if(exportNormals){
exportTileNormals(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension);
guiProgress.status++;
Expand Down Expand Up @@ -515,7 +519,7 @@ void* sm2obj::window::exportThreadFunc(void* Data){
///=============================================================================
bool recursiveMetaLoader(sm2obj::entityInfoStruct* Output, const std::string& BlueprintFolder, const std::string& BlueprintName, const std::string& SubFolder){
std::string path = BlueprintFolder + SubFolder + "\\meta.smbpm";

if(!loadMeta(Output, path, BlueprintName)){
ffw::logError() << "Failed to open meta file from: " << path;
return false;
Expand Down Expand Up @@ -557,7 +561,7 @@ int getTotalEntities(const sm2obj::entityInfoStruct* Input){
}

///=============================================================================
bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& BlueprintFolder, const std::string& OutputTemp, int& FileIndex, progressStruct& Progress, std::atomic_bool& Cancel){
bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& BlueprintFolder, const std::string& OutputTemp, int& FileIndex, progressStruct& Progress, volatile bool& Cancel){
std::vector<std::string> allFiles;

// Open target directory
Expand Down Expand Up @@ -672,8 +676,8 @@ bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& Bl
Progress.setProgress("Loading chunks");

for(auto& item : Input->attachments){
if(Cancel.load())return true;
if(Cancel)return true;

if(!recursiveChunkLoader(&item, BlueprintFolder, OutputTemp, FileIndex, Progress, Cancel))return false;
}

Expand All @@ -682,7 +686,7 @@ bool recursiveChunkLoader(sm2obj::entityInfoStruct* Input, const std::string& Bl


///=============================================================================
void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& InputOutputTemp, std::vector<sm2obj::threadInfoStruct*>& Threads, progressStruct& Progress, const std::vector<sm2obj::blockInfoStruct>& BlockInfo, std::atomic_bool& Cancel){
void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& InputOutputTemp, std::vector<sm2obj::threadInfoStruct*>& Threads, progressStruct& Progress, const std::vector<sm2obj::blockInfoStruct>& BlockInfo, volatile bool& Cancel){
ffw::logDebug() << "Exporting: " << Input->name << " from: " << Input->path;

// export chunks one by one
Expand Down Expand Up @@ -717,14 +721,14 @@ void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& In
found = true;
break;
}
if(Cancel.load())break;
if(Cancel)break;
}
if(Cancel.load())break;
if(Cancel)break;
// An empty thread was not found, wait and then try again
if(found)break;
ffw::usleep(100000);
}
if(Cancel.load())break;
if(Cancel)break;
}

ffw::logDebug() << "Waiting for threads...";
Expand All @@ -734,7 +738,7 @@ void recursiveChunkExport(sm2obj::entityInfoStruct* Input, const std::string& In
}

for(auto& item : Input->attachments){
if(Cancel.load())break;
if(Cancel)break;
recursiveChunkExport(&item, InputOutputTemp, Threads, Progress, BlockInfo, Cancel);
}
}
Expand Down Expand Up @@ -968,4 +972,4 @@ bool mergeVertices(sm2obj::entityInfoStruct* Input, const std::string& InputOutp
}

return true;
}
}

0 comments on commit 7e2f4b4

Please sign in to comment.