#JavaFX Fluid Simulation
1 messages Β· Page 4 of 1
ok updated master 3
going to check in like 10min
ok sure
it is because you forgot to set simulationStarted = false in the endSimulation method
it still works fine right?
nope i can still interact with it
oh you might need a break in that statement
in the try catch
also the error is printing because of e.printStacktrace()
here?
yeahh
also I still recommend not to use Thread.sleep here
does the UI look nice btw?
what should i use instead?
yeah why not, but it could get some improvements
I would slightly do the loop differently
YES IT WORKS
coudl you elaborate?
I would have a continous loop (while(true), which will update fluid.step as fast as possible), but only render the n number of times per second based on the FPS you try to implement
ahh so theres no set TPS?
to prevent too many updates?
but I wouldnt do it in this case
you probably wont change it 
whatever
your simulation
I would do it differently but π€·ββοΈ
i will if i have time π
I gotta do the whole writeup and everything
all good its fine
so this is all a rush from now on
yeah try to get it working first
yeahh
it works good now
I got two main bits left which is the implementation of barriers
and recording the fluid e.g. saving the fluid data somewhere in a file
btw in which way do you want to store recordings?
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
hmm not so sure yet
probably save the arrays and just re render
maybe i can implement some sort of compression
Yeah otherwise itβs going to be really big
Just store the changes or smth might be the best idea to easily implement
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
hello guys
wdym the changes
ohh you mean the fluid inputs?
yeah or smth like that
ahh ok
i got a quick question
so i'm just looking at the input handling stuff
for (FluidInput source : sourceQueue) {
sourceConsumer.accept(source);
}
sourceQueue.clear();```
is it more efficient doing this or is it more efficient dequeuing a node one at a time and then accepting it
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
hello
got some bad news
teacher doesn't like the fact that i used a List in my queue class π
package com.fluidity.program.utilities;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class Queue<T> {
private List<T> queue;
private int MAX_SIZE;
public Queue() {
this.queue = new ArrayList<>();
}
public void enqueue(T data) {
if (queue.size() == MAX_SIZE && MAX_SIZE != 0) {
throw new ArrayIndexOutOfBoundsException();
}
queue.add(data);
}
public T dequeue() {
if (isEmpty()) {
throw new NoSuchElementException();
}
return queue.remove(queue.size() - 1);
}
public T peek() {
return queue.get(queue.size() - 1);
}
public boolean isEmpty() {
return queue.isEmpty();
}
public void setMAX_SIZE(int MAX_SIZE) {
this.MAX_SIZE = MAX_SIZE;
}
public int size() {
return queue.size();
}
public Queue<T> copy() {
Queue<T> copy = new Queue<>();
copy.queue = new ArrayList<>(queue);
copy.setMAX_SIZE(MAX_SIZE);
return copy;
}
@Override
public String toString() {
StringBuilder output = new StringBuilder();
for (T t : queue) {
output.append(t.toString())
.append(" ");
}
output.append("\n");
return output.toString();
}
}
this is my queue implementation
however he doesn't like that I use the list for it π
Did he give any feedback on what he wants instead? I haven't checked the full topic given it's length.
yeahh he said to use an array implementation
and then change lengths manually
i implemented it and it works fine
thing is im planning to do some sort of fluid saving so I can backtrack though the fluid
@Override
public void run() {
this.running = true;
this.FLUID_WIDTH = fluid.WIDTH;
this.FLUID_HEIGHT = fluid.HEIGHT;
final double TIME_PER_TICK = 1.0 / TPS;
final double TIME_PER_FRAME = 1.0 / DESIRED_FPS;
long lastTime = System.nanoTime();
double unprocessedTime = 0;
double frameTime = 0;
while (running) {
long now = System.nanoTime();
long passedTime = now - lastTime;
lastTime = now;
unprocessedTime += passedTime / 1_000_000_000.0;
frameTime += passedTime / 1_000_000_000.0;
// Update fluid and handle inputs as many times as needed to catch up with the target TPS
while (unprocessedTime > TIME_PER_TICK) {
fluid.step(TIME_PER_TICK);
addSourcesFromUI(fluid);
unprocessedTime -= TIME_PER_TICK;
}
// Render if it's time for a new frame
if (frameTime >= TIME_PER_FRAME) {
if (densityPlot) {
render(fluid.dens.clone()); // Render with the most recent fluid density
} else if (xVelocityPlot) {
render(fluid.u.clone()); // Render with the most recent fluid density
} else if (yVelocityPlot) {
render(fluid.v.clone()); // Render with the most recent fluid density
}
frameTime = 0;
}
// Sleep to cap the rendering FPS
long sleepTime = (long) ((TIME_PER_FRAME - frameTime) * 1_000_000_000);
if (sleepTime > 0) {
try {
Thread.sleep(sleepTime / 1_000_000, (int) (sleepTime % 1_000_000));
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
}
}```
Detected code, here are some useful tools:
@Override
public void run() {
this .running = true;
this .FLUID_WIDTH = fluid.WIDTH;
this .FLUID_HEIGHT = fluid.HEIGHT;
final double TIME_PER_TICK = 1.0 / TPS;
final double TIME_PER_FRAME = 1.0 / DESIRED_FPS;
long lastTime = System.nanoTime();
double unprocessedTime = 0;
double frameTime = 0;
while (running) {
long now = System.nanoTime();
long passedTime = now - lastTime;
lastTime = now;
unprocessedTime += passedTime / 1_000_000_000.0;
frameTime += passedTime / 1_000_000_000.0;
// Update fluid and handle inputs as many times as needed to catch up with the target TPS
while (unprocessedTime > TIME_PER_TICK) {
fluid.step(TIME_PER_TICK);
addSourcesFromUI(fluid);
unprocessedTime -= TIME_PER_TICK;
}
// Render if it's time for a new frame
if (frameTime >= TIME_PER_FRAME) {
if (densityPlot) {
render(fluid.dens.clone());
// Render with the most recent fluid density
}
else if (xVelocityPlot) {
render(fluid.u.clone());
// Render with the most recent fluid density
}
else if (yVelocityPlot) {
render(fluid.v.clone());
// Render with the most recent fluid density
}
frameTime = 0;
}
// Sleep to cap the rendering FPS
long sleepTime = (long ) ((TIME_PER_FRAME - frameTime) * 1_000_000_000);
if (sleepTime > 0) {
try {
Thread.sleep(sleepTime / 1_000_000, (int ) (sleepTime % 1_000_000));
} catch (InterruptedException e) {
e.printStackTrace();
break ;
}
}
}
}
this doesn't really require any prerequisite knowledge about the simulation but how can I save the fluid at 10fps whilst the simulation is running at 60fps?
anyone know?
i was thinking of having a frameCount variable and resetting it every 10 frames that are rendered?
how tf does this thread has 3k messages, what happened here π
it changed on auto close time, OP asked to be open for a while
before your if (frameTime >= TIME_PER_FRAME) { a modulus operator on frameTime to check if it's 0 and then log it?
yeah but this is for a 60fps loop
i want it so that no matter what TIME_PER_FRAME is, I can do some other functionality at the same time but at 4 FPS or something
unlesse the FPS < 4fps
which it wont be
because minimum is 15 in my sim
But before that you can just put another if ((frameTime % (TIME_PER_FRAME/6)) == 0) you'd do it once every 10 FPS
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
.
helloooooo
just a quick question
if i plan to rollback the fluid, should i still be using a loop to render the rollbacks?
is there a method which makes sure a key can't be held but only pressed?
:DD
yea above
and above π
in which regards?
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
Feels like a new question
If itβs just about that you would just add an event filter
i did but it doesnt work
ok?
share what you did
how am I supposed to help you otherwise?
oh yeah sorry
i thought u would know it's on master3 lmao
Okay yeah actually mb
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
this thread has 3118 messages 
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
helellalooooo
not anymore
lol
let thread sleep
Thread.sleep(Long.MAX_VALUE);
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
i aplogize for reactinge to the message
bros thread so inactive it got closed
π
im just looking back on it for writing my writeup
hey @boreal socket when this thing kept causing my program to freeze, what can i say was the problem that we fixed using all the daemon and executor stuff?
not sure which freeze you are referring to
but setting it daemon is technically unrelated
well just the reason why I replaced my delta tome loop with urs tbh
daemon is for closing right?
I cant tell anymore tbh
but I think the freeze wasnt caused by the loop itself
it was caused by the underlying code
which was failing somehow before
but I cant tell anymore
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
eh it's fine i waffled it
I kinda just need help trying to explain what an ExecutorService and setDaemon is in words
ok
what you got so far?
The fluid seems to flow in the direction of a velocity field that is transformed when a force is applied on the field. This is the kind of output that we require and it is the output which was required by our stakeholders for an ``intuitive" understanding. On top of this fix to the error, I have added some features that were meant to be added later but are however needed for now. This involves the use of what we call an ExecutorSerice and a specific attribute known as daemon.```
hm thats not really what the executor is used for here
you used it to run your simulation next to the javafx thread
without interfering it and thus blocking it
ahh ok
also I just see that you removed Platfom.runLater call 
dont do that
your threaded application isnt really safe
it starts lagging π
then you did something else wrong
is this what an ExecutorService does?
you try to fix a bug with something completely unrelated
and thus creating a different problem/bug
I would summary ExecturoService contextless like this:
ExecutorService is an enhanced API to create Threads. It produces Future objects for tracking progress of one or more asynchronous tasks
in your case the task is the simulation
you want it to be threaded so that your javafx thread (rendering and stuff) wont get blocked by the simulation
you set the created thread for the simulation daemon, so that it wont block terminating the whole application if the javafx thread (aka all non-daemon threads) finished/failed/etc
Platform threads are designated daemon or non-daemon threads. When the Java virtual machine starts up, there is usually one non-daemon thread (the thread that typically calls the application's main method). The shutdown sequence begins when all started non-daemon threads have terminated. Unstarted non-daemon threads do not prevent the shutdown sequence from beginning.
ah yes the run later works
only wrap it around the stuff that actually needs it though
yep
so changing the pixels on the canvas
only the render methdo
bro
i haven't slept in 2 days no joke
im gonna get a heart attack or smth π
i drank 5 monster energies today
need to finish this documentation π
yeahh
also
what exactly does the run later do and what does it solve?
idk how to put it in words lmao
it lets you run code on the JavaFX thread
so the render method is called on your custom thread
but you want to do stuff on the javafx thread
Platform.runLater gives you that ability
ahh
though you need to be careful
Run the specified Runnable on the JavaFX Application Thread at some unspecified time in the future.
yea
NOTE: applications should avoid flooding JavaFX with too many pending Runnables. Otherwise, the application may become unresponsive. Applications are encouraged to batch up multiple operations into fewer runLater calls. Additionally, long-running operations should be done on a background thread where possible, freeing up the JavaFX Application Thread for GUI operations.
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
Hi
yes
also
I just want to say a huge thanks to @boreal socket , @steep elbow and @dense hare for helping me along this project lmao
i've come a long way ngl
and it's looking good rn
just trying to speedrun the writeup now
but i've done all the programming
they don't care about the niche features
so im getting rid of the recordings
i donβt know how but i only just realized ur making a fluid simulation
iβm very much impressed and good luck with ur journey
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
is there a way to generate a UML diagram for an intelliJ project?
there are some plugins
what's a good one?
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
How do i reset a scene completely?
like say if i want a scene to be reset on the click of a button
hey @boreal socket what does this mean?
what got rejected π
your runnable
oh no
I guess your executor just got one thread
i think i reset my scene wrong π
public void resetScene(ProgramState scene) {
initialiseUI(scene);
setManager(scene);
loadScene(scene);
}```
Detected code, here are some useful tools:
@FXML
private void onGoToSettingsClick() {
simulationStarted = false;
simulationFuture.cancel(true);
EXECUTOR.close();
manager.resetScene(ProgramState.SIMULATION);
manager.loadScene(ProgramState.SETTINGS);
}
Detected code, here are some useful tools:
I end it like that
also thats not how you properly shutdown an executor service iirc
there is this, but idk
pretty sure that is my very last bug to talk about in the writeup
need to further read the docs
Dang I read thru half of your convo, this stuff is interesting
how far are you done?
Is it fully concurrent?
@grand garnet
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure π
wdym
i finished all the coding and stuff and i've sent it in
it says this π«₯
how are you creating the jar?
the processing, is it multi-threaded?
did you create a fat jar?