<commit_before>
#include "UnrealSandboxTerrainPrivatePCH.h"
#include "SandboxTerrainController.h"
#include "TerrainZoneComponent.h"
#include "TerrainRegionComponent.h"
#include "SandboxVoxeldata.h"
#include <cmath>
#include "DrawDebugHelpers.h"
#include "Async.h"

#include "SandboxTerrainMeshComponent.h"


class FLoadInitialZonesThread : public FRunnable {

private:
	 
	volatile int state = TH_STATE_NEW;

	FRunnableThread* thread;

public:

	FLoadInitialZonesThread() {
		thread = NULL;
	}

	~FLoadInitialZonesThread() {
		if (thread != NULL) {
			delete thread;
		}
	}

	TArray<FVector> zone_list;
	ASandboxTerrainController* Controller;

	bool IsFinished() {
		return state == TH_STATE_FINISHED;
	}

	virtual void Stop() { 
		if (state == TH_STATE_NEW || state == TH_STATE_RUNNING) {
			state = TH_STATE_STOP;
		}
	}

	virtual void WaitForFinish() {
		while (!IsFinished()) {

		}
	}

	void Start() {
		thread = FRunnableThread::Create(this, TEXT("THREAD_TEST"));
	}

	virtual uint32 Run() {
		state = TH_STATE_RUNNING;
		UE_LOG(LogTemp, Warning, TEXT("zone initial loader %d"), zone_list.Num());
		for (auto i = 0; i < zone_list.Num(); i++) {
			if (!Controller->IsValidLowLevel()) {
				// controller is not valid anymore
				state = TH_STATE_FINISHED;
				return 0;
			}

			if (state == TH_STATE_STOP) {
				state = TH_STATE_FINISHED;
				return 0;
			}

			FVector Index = zone_list[i];
			FVector Pos = FVector((float)(Index.X * 1000), (float)(Index.Y * 1000), (float)(Index.Z * 1000));

			//TODO maybe pass index?
			TVoxelData* NewVoxelData = Controller->CreateZoneVoxeldata(Pos);
			if (NewVoxelData->getDensityFillState() == TVoxelDataFillState::MIX) {
				UTerrainZoneComponent* Zone = Controller->GetZoneByVectorIndex(Index);
				if (Zone == NULL) {
					Controller->invokeLazyZoneAsync(Index);
				} else {
					Zone->SetVoxelData(NewVoxelData);
					std::shared_ptr<TMeshData> md_ptr = Zone->generateMesh();
					Zone->getVoxelData()->resetLastMeshRegenerationTime();
					Controller->invokeZoneMeshAsync(Zone, md_ptr);
				}
			}

			Controller->OnLoadZoneProgress(i, zone_list.Num());
		}

		Controller->OnLoadZoneListFinished();<commit_msg>code style renaming<commit_after>
#include "UnrealSandboxTerrainPrivatePCH.h"
#include "SandboxTerrainController.h"
#include "TerrainZoneComponent.h"
#include "TerrainRegionComponent.h"
#include "SandboxVoxeldata.h"
#include <cmath>
#include "DrawDebugHelpers.h"
#include "Async.h"

#include "SandboxTerrainMeshComponent.h"


class FLoadInitialZonesThread : public FRunnable {

private:
	 
	volatile int state = TH_STATE_NEW;

	FRunnableThread* thread;

public:

	FLoadInitialZonesThread() {
		thread = NULL;
	}

	~FLoadInitialZonesThread() {
		if (thread != NULL) {
			delete thread;
		}
	}

	TArray<FVector> zone_list;
	ASandboxTerrainController* Controller;

	bool IsFinished() {
		return state == TH_STATE_FINISHED;
	}

	virtual void Stop() { 
		if (state == TH_STATE_NEW || state == TH_STATE_RUNNING) {
			state = TH_STATE_STOP;
		}
	}

	virtual void WaitForFinish() {
		while (!IsFinished()) {

		}
	}

	void Start() {
		thread = FRunnableThread::Create(this, TEXT("THREAD_TEST"));
	}

	virtual uint32 Run() {
		state = TH_STATE_RUNNING;
		UE_LOG(LogTemp, Warning, TEXT("zone initial loader %d"), zone_list.Num());
		for (auto i = 0; i < zone_list.Num(); i++) {
			if (!Controller->IsValidLowLevel()) {
				// controller is not valid anymore
				state = TH_STATE_FINISHED;
				return 0;
			}

			if (state == TH_STATE_STOP) {
				state = TH_STATE_FINISHED;
				return 0;
			}

			FVector Index = zone_list[i];
			FVector Pos = FVector((float)(Index.X * 1000), (float)(Index.Y * 1000), (float)(Index.Z * 1000));

			//TODO maybe pass index?
			TVoxelData* NewVoxelData = Controller->CreateZoneVoxeldata(Pos);
			if (NewVoxelData->getDensityFillState() == TVoxelDataFillState::MIX) {
				UTerrainZoneComponent* Zone = Controller->GetZoneByVectorIndex(Index);
				if (Zone == NULL) {
					Controller->invokeLazyZoneAsync(Index);
				} else {
					Zone->SetVoxelData(NewVoxelData);
					std::shared_ptr<TMeshData> MeshDataPtr = Zone->generateMesh();
					Zone->getVoxelData()->resetLastMeshRegenerationTime();
					Controller->invokeZoneMeshAsync(Zone, MeshDataPtr);
				}
			}

			Controller->OnLoadZoneProgress(i, zone_list.Num());
		}

		Controller->OnLoadZoneListFinished();
{'fraction_non_alphanumeric': 0.13213627992633517, 'fraction_numerical': 0.007826887661141806, 'mean_word_length': 4.384138785625774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1693100', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1489, 'n_words': 291}