#include <iostream>
#include <cuda_runtime.h>
__global__ void generateHexString(char* result, int* array)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
result[idx] = array[idx];
}
int main()
{
const int arraySize = 16;
char array[arraySize] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
char result[arraySize];
char* d_result;
int* d_array;
cudaMalloc((void**)&d_result, arraySize * sizeof(char));
cudaMalloc((void**)&d_array, arraySize * sizeof(int));
cudaMemcpy(d_array, array, arraySize * sizeof(int), cudaMemcpyHostToDevice);
int threadsPerBlock = 16;
int blocksPerGrid = 1;
generateHexString<<<blocksPerGrid, threadsPerBlock>>>(d_result, d_array);
cudaMemcpy(result, d_result, arraySize * sizeof(char), cudaMemcpyDeviceToHost);
cudaFree(d_result);
cudaFree(d_array);
std::cout << "Generated hex string: " << result << std::endl;
return 0;
}
#include <vector>
const int voxel_size = 16;
std::vector<short> get_voxels_from_chunk(short (*voxels)[voxel_size][voxel_size][voxel_size], int world_length, int chunk_size_x, int chunk_size_y, int chunk_size_z, int chunk_id) {
std::vector<short> result;
int chunk_count_x = world_length / chunk_size_x;
int chunk_count_y = world_length / chunk_size_y;
int chunk_count_z = world_length / chunk_size_z;
int chunk_index_x = chunk_id % chunk_count_x;
int chunk_index_y = (chunk_id / chunk_count_x) % chunk_count_y;
int chunk_index_z = chunk_id / (chunk_count_x * chunk_count_y);
int x_offset = chunk_index_x * chunk_size_x;
int y_offset = chunk_index_y * chunk_size_y;
int z_offset = chunk_index_z * chunk_size_z;
for (int i = x_offset; i < x_offset + chunk_size_x; i++){
for (int ii = y_offset; ii < y_offset + chunk_size_y; ii++){
for (int iii = z_offset; iii < z_offset + chunk_size_z; iii++){
result.push_back(*(*(*(voxels + i) + ii) + iii));
}
}
}
return result;
}
int main() {
short voxels[voxel_size][voxel_size][voxel_size]; // пример массива вокселей
int world_length = voxel_size;
int chunk_size_x = 4;
int chunk_size_y = 8;
int chunk_size_z = 8;
int chunk_id = 3; // пример id чанка
std::vector<short> chunk_voxels = get_voxels_from_chunk(&voxels, world_length, chunk_size_x, chunk_size_y, chunk_size_z, chunk_id);
// обработка chunk_voxels
return 0;
}
void funcPlusMinus()
{
if (isEmpty()) {
cout << "The stack is empty" << endl;
}
else {
Stack* temp = top;
do {
if (temp->item < 0) {
cout << temp->item << " ";
}
temp = temp->down;
} while (temp != NULL);
cout << endl;
}
}