/agdg/ + /vm/ ~ Amateur Gamedev General

To be honest mate, I'm fresh out of coffee and haven't slept since yesterday.

What I'd do is I'd pretend to be one of those deaf-mutes. And by that I mean I'd re write the code without any matrices, just get the threading side of things nailed down. Then I'd adapt the properly debugged threaded code to the problem at hand (and keep a copy around in an example file in case you have to do that again later).

Your ThreadedMatrix is calling the Determinant function with false (no recursion, right?). But you can't set finished = true and also check (!d.finished) without synchronizing.

See, that's why SkyNet used the time loop so the T-1000 can lock up Sara Connor to prevent the mutation of John!

repostan from last bread since someone was helping me
if i limit it to one thread, it works but slower than before
if i do more than 1 thread, i get an IllegalMonitorStateException
i made a new class that stores the reference to the matrix, calculates it's result, and when all the instances of this class are finished they notify their parent to calculate their result
the parent in this case is a matrix, if it can make a new thread it makes a new object of the previous class, otherwise it directly calculates the result of the submatrix in that thread
after it's told all the threads to start calculating it waits until they've notified it. after that it sums up their results
so the question is why do i get an error when i'm using threads
package project;public class ThreadedMatrix implements Runnable { public Matrix matrix, parent; public boolean finished = false; public double result; public int index,x; public ThreadedMatrix(Matrix _m, Matrix _p, int _i,int _x) { matrix = _m; parent = _p; index = _i; x=_x; } @Override public void run() { // TODO Auto-generated method stub result = matrix.Determinant(false); finished=true; for (int i = 0; i < parent.threads.size(); i++) { ThreadedMatrix d = (ThreadedMatrix) parent.threads.get(i); if (!d.finished) { return; } } parent.notify(); }}
package project;import java.util.Vector;public class Matrix { public static int threadMax = 1; public static int threadCount = 1; public double[] elements; int size; public boolean separateThread = false; public void SetElement(double val, int x, int y) { elements[size * y + x] = val; } public Matrix(int _size) { size = _size; elements = new double[size * size]; } public double Get(int x, int y) { return elements[x + y * size]; } public Vector threads = new Vector(); public double Determinant(boolean quiet) { if (size == 1) {// shouldn't really happen unless someone specifically // enters a 1 sized matrix return elements[0]; } else if (size == 2) { if (separateThread) { threadCount--; } return elements[0] * elements[3] - elements[1] * elements[2]; } else { double sum = 0; for (int i = 0; i < size; i++) { Matrix sub = new Matrix(size - 1); for (int x = 0; x < size; x++) { if (x != i) { for (int y = 1; y < size; y++) { sub.SetElement(Get(x, y), (x > i ? x - 1 : x), y - 1); } } } if (threadCount < threadMax) { Thread t = new Thread(new ThreadedMatrix(sub, this, threads.size(), i)); threads.add(t); sub.separateThread = true; threadCount++; t.start(); } else sum += Math.pow((-1), i) * sub.Determinant(quiet) * Get(i, 0); } if (threadCount > 1) { try { Thread.currentThread().wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block for (int i = 0; i < threads.size(); i++) { ThreadedMatrix d = (ThreadedMatrix) threads.get(i); sum += Math.pow((-1), d.x) * d.result * Get(d.x, 0); } // e.printStackTrace(); } } return sum; } }}

I meant to reply to:

…but it wasn't posted yet. Fucking time loops, how do they werk!?

Never knew Avatar had so much in the lore, was there any Sound bender in the story? I remember metal, blood and lightning only

oh nevermind then
ok so i need to lock something until something happens, but with your explanation i got completely lost
what do i lock and how do i lock it

That's definitely one thing a lot of anime/manga do well; it's generally in the background though compared to say a game.
Same with beserk, great lore for this type of stuff too.

Not sure on the sound one.
Though it's apparent the graph on the left side is highly inspired by naruto (one thing that show does well is the lore/world building imo).

There was also combustion (mercenary hunting the group), lava (again a mercenary, and in the shitty korra series had a protag character with lava bending), and spirit is pretty much like their aether.

There's several ways to do it.

See "Volatile" keyword (I might have imagined this from another dimension), Synchronized objects, a Mutex.

The pattern is called producer / consumer, and there's a pitfall called Dead Leaks? Dead Locks, something. Whatever you do remember to Reap your children lest they become Zombies… but that may be something from another Unixverse.

Also, I forgot to mention: If not modifying the Matrix, you can share the main Matrix between all the Determinators and just zone their actions to ever decreasing ranges.

If you get dejavu that means another thread had a concurrency issue – or they changed something.

Who the hell came up with this? First levels are a mix of neighboring 4 primary elements. Does that mean that next levels of mixed elements are also combinations of next level? Water + Earth = Plant so Metal + Ice = Gasoline?

Korra does not exist user, the story ended after Aang defeated the firelord.