a
This commit is contained in:
parent
22f65402c7
commit
78c6ce024d
@ -56,8 +56,18 @@ void exportHelper::imageWriter(size_t idx, thread* thread) {
|
|||||||
auto* particles_copy = (Particle*)malloc(this->particles->size());
|
auto* particles_copy = (Particle*)malloc(this->particles->size());
|
||||||
this->particles->sync_to(&particles_copy);
|
this->particles->sync_to(&particles_copy);
|
||||||
|
|
||||||
|
char data[32 * 5 + 1];
|
||||||
|
data[32*5] = '\0';
|
||||||
|
|
||||||
for (size_t i = 0; i < particle_count; i++) {
|
for (size_t i = 0; i < particle_count; i++) {
|
||||||
fprintf(f, "%f %f %f %f %f\n", particles_copy[i].position.x, particles_copy[i].position.y, particles_copy[i].velocity.x, particles_copy[i].velocity.y, particles_copy[i].mass);
|
memcpy(data, &particles_copy[i].position.x, sizeof(float));
|
||||||
|
memcpy(&data[32], &particles_copy[i].position.y, sizeof(float));
|
||||||
|
memcpy(&data[64], &particles_copy[i].velocity.x, sizeof(float));
|
||||||
|
memcpy(&data[96], &particles_copy[i].velocity.y, sizeof(float));
|
||||||
|
memcpy(&data[128], &particles_copy[i].mass, sizeof(float));
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(f, "%s\n", particles_copy[i].position.x, particles_copy[i].position.y, particles_copy[i].velocity.x, particles_copy[i].velocity.y, particles_copy[i].mass);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(particles_copy);
|
free(particles_copy);
|
||||||
@ -91,4 +101,4 @@ void exportHelper::epoch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,9 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
max_dim -= 0.1;
|
max_dim -= 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
max_dim = std::abs(max_dim);
|
||||||
|
|
||||||
update_required = true;
|
update_required = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -146,9 +149,6 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (update_required) {
|
if (update_required) {
|
||||||
SDL_FillRect(surf, nullptr, SDL_MapRGB(surf->format, 0, 0, 0));
|
|
||||||
particles.clear();
|
|
||||||
|
|
||||||
char filename[256];
|
char filename[256];
|
||||||
sprintf(filename, "./output/%zu.dat", current_idx);
|
sprintf(filename, "./output/%zu.dat", current_idx);
|
||||||
|
|
||||||
@ -158,7 +158,11 @@ int main() {
|
|||||||
printf("File not found: %s\n", filename);
|
printf("File not found: %s\n", filename);
|
||||||
printf("End of simulation\n");
|
printf("End of simulation\n");
|
||||||
pause = true;
|
pause = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
SDL_FillRect(surf, nullptr, SDL_MapRGB(surf->format, 0, 0, 0));
|
||||||
|
|
||||||
|
particles.clear();
|
||||||
|
|
||||||
char *cur_line = (char *)malloc(64 * sizeof(char));
|
char *cur_line = (char *)malloc(64 * sizeof(char));
|
||||||
size_t len = 64;
|
size_t len = 64;
|
||||||
@ -168,11 +172,11 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
float x, y, vx, vy, m;
|
float x = *(float*)cur_line;
|
||||||
|
float y = *(float*)cur_line[32];
|
||||||
if (sscanf(cur_line, "%f %f %f %f %f", &x, &y, &vx, &vy, &m) != 5) {
|
float vx = *(float*)cur_line[64];
|
||||||
break;
|
float vy = *(float*)cur_line[96];
|
||||||
}
|
float m = *(float*)cur_line[128];
|
||||||
|
|
||||||
particles.push_back(Particle{m, {x, y}, {vx, vy}});
|
particles.push_back(Particle{m, {x, y}, {vx, vy}});
|
||||||
}
|
}
|
||||||
@ -210,4 +214,4 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user