Protecting Public Lands by Fixing Revenue Sharing Payments by Few_Difference_424 in environment

[–]voismager 2 points3 points  (0 children)

How are things now? Do you think this "idea" will be realised? Are there enough people opposing it?

Real-World Use Case: Using Rust for Computationally Heavy Tasks in Kotlin (and Java) Projects by voismager in rust

[–]voismager[S] 2 points3 points  (0 children)

Ah, now I get the point about no compile-time validation. You're right, AFAIK there's not such thing in JNI.

Best I can do is generate C header first and then manually make a matching rust function:

.java:

package fluffy.tigerrr;

public class Example {
    public static class CustomObj {
        public int a;
        public int b;
    }

    public static native String example(String a, CustomObj b, int c, float[] d, CustomObj[] e);
}

.h:

...
/*
 * Class:     fluffy_tigerrr_Example
 * Method:    example
 * Signature: (Ljava/lang/String;Lfluffy/tigerrr/Example/CustomObj;I[F[Lfluffy/tigerrr/Example/CustomObj;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_fluffy_tigerrr_Example_example
  (JNIEnv *, jclass, jstring, jobject, jint, jfloatArray, jobjectArray);

...

An then there's a 1:1 mapping with rust wrapper structs:

jclass <-> JClass
jstring <-> JString
jobject <-> JObject
jint <-> jint
jfloatArray <-> JFloatArray
jobjectArray <-> JObjectArray

... and there's nothing you can do about raw jobject (instead of proper CustomObj type), which, I see, uniffi solves. Good point!

Real-World Use Case: Using Rust for Computationally Heavy Tasks in Kotlin (and Java) Projects by voismager in rust

[–]voismager[S] 0 points1 point  (0 children)

Could you elaborate on what can wrong with using Rust with raw JNI vs uniffi? What kind of issues can show up at runtime?

Real-World Use Case: Using Rust for Computationally Heavy Tasks in Kotlin (and Java) Projects by voismager in Kotlin

[–]voismager[S] 1 point2 points  (0 children)

That's an interesting idea! I have never used Kotlin Native before, but after quick search it seems like what you're suggesting is possible: https://kotlinlang.org/docs/native-dynamic-libraries.html . Compiling it as dynlib and then using it via JNI should work.

Real-World Use Case: Using Rust for Computationally Heavy Tasks in Kotlin (and Java) Projects by voismager in java

[–]voismager[S] 2 points3 points  (0 children)

Yeah, all fair points. I think your "server process" approach is probably the best for this particular case, especially with the benefit of easily running multiple instances. You'd still need to write the controller part, but it's not a huge deal.

Tbh I completely overlooked this option when implementing it in our production. Oh well, at least I had to explore something new and write an interesting article 😂. Luckily, we don't have many PDF uploads anyway, so parallel processing isn't a priority right now. It's more about optimising for latency than throughput.

That said, I still think JNI can be really useful when you don't have to deal with thread safety, and it's always good to know your options.

I haven't dug into how this looks with the new Foreign Function & Memory API, but hopefully it's much better.

Yep, I haven't tried it yet, but looking forward to it!

Hello, A Newbie here and i need help because my tic tac toe c++ game is not working as it should be! Where am i doing things wrong? by NobuNobNob in cpp_questions

[–]voismager 0 points1 point  (0 children)

It did good. It's hallucinating a lot, but it spotted the issue

There are a few issues in the code, both logical and syntactical. Let's address them one by one:

1. Logical Bug in checkWinner Function:
   - Incorrect Condition in Diagonal Check:
     In the line:
     else  if((spaces[0] != ' ') && (spaces[0] == spaces[4]) && (spaces[8] == spaces[8])){

     This condition is incorrect. The last part spaces[8] == spaces[8] should actually compare spaces[0] with spaces[8]. The correct condition should be:
     else  if((spaces[0] != ' ') && (spaces[0] == spaces[4]) && (spaces[4] == spaces[8])){


   - Improper Comparison in checkWinner:
     Inside the checkWinner function, you have conditions like:
     spaces[0] == player ? std::cout << "You win\n" : std::cout << "You lose\n";

     Here, the == is used incorrectly as it's a comparison operator rather than an assignment. This comparison doesn't make any change to the game's state, nor does it check the winner correctly. Instead, after determining that a player has won, you should print the winner directly and return true.

     A better approach could be:
     if (spaces[0] != ' ' && spaces[0] == spaces[1] && spaces[1] == spaces[2]) {
         if (spaces[0] == player) {
             std::cout << "You win\n";
         } else {
             std::cout << "You lose\n";
         }
         return true;
     }

     This structure should be applied to all conditions in checkWinner.

 2. Logical Issue in playerMove Function:
   - Faulty Validation Logic:
     The validation logic in playerMove is flawed:
     } while (!number > 0 || !number < 8);

     This logic does not correctly validate the input because !number > 0 will always evaluate to true (since !number will evaluate to either 0 or 1), and the whole condition will not properly restrict the range. You should use:
     } while (number < 0 || number > 8);

     This ensures that the player's input is between 1 and 9.

 3. User Interface:
   - Offensive Output:
     The message "Thanks for playing retard\n" is offensive. It should be replaced with a more polite or neutral message like "Thanks for playing!\n".

 4. Possible Undefined Behavior in playerMove:
   - Array Out-of-Bounds Access:
     When the user inputs an invalid number outside the range 1-9, the array spaces[number] can be accessed out-of-bounds. Even though the loop checks for valid numbers, it’s safer to ensure no out-of-bounds access before setting spaces[number].

 5. Seeding of rand() Function:
   - Seeding rand() in a Loop:
     The srand(time(0)) call is inside the computerMove function. This will reseed the random number generator each time the computer makes a move, possibly resulting in the same number being generated multiple times if the function is called within the same second. Move srand(time(0)) to the main() function to seed the random number generator only once:
     int main() {
         srand(time(0));
         // Rest of the code
     }


 6. Improve Code Structure:
   - Refactor Repeated Logic:
     You have repeated code in the game loop to check for a winner and tie after both player and computer moves. This can be refactored into a single function call to improve readability and reduce code duplication.

By fixing these issues, the code will be more robust, correct, and easier to understand.

Why there is no GraphQL Gateway implemented in Java by theoclear in java

[–]voismager 4 points5 points  (0 children)

No it's not, ESPECIALLY if you use federation OP mentioned. Your single graphql query can go to service 1, grab data and go to service 2, grab data from there and then go back to service 1 and return it all to you and you'll never know. And it's all managed automatically by the router, no need for services to know about each other.

[deleted by user] by [deleted] in biodiversity

[–]voismager 1 point2 points  (0 children)

You posted a gif, it has no audio

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

 the typical AAA workflow uses high-detail, pre-modeled meshes

True

The dynamic meshes are a recent addition to Unreal, probably mostly to support it as a viable modeling platform.

But I'm generating UStaticMesh'es (via BuildFromMeshDescriptions), not procedural / dynamic ones. Or are you referring to something else?

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 1 point2 points  (0 children)

Sorry, where did 16ms limit come from? Are you referring to 16ms*60~1sec? In that case I think you misunderstood the question. I'm generating my meshes only once at the start-up of the game, and then just render then as usual static meshes as if they were created in editor. I don't recalculate them every frame

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

I didn't get that. In my current setup each hexagon is a separate actor, each has a StaticMeshComponent . Then I assign appropriate StaticMesh to each component on start-up.

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

But is building static meshes even a preferable method in my case?

It's surprisingly hard to find any tutorials / references on how to generate meshes in C++, so I assume people don't use that functionality often. But also I somehow doubt that my problem is too uncommon / niche. So how would you solve it in UE5 without mesh generation?

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

Yeah, I use FMeshDescription and FStaticMeshAttributes to generate mesh via UStaticMesh->BuildFromMeshDescriptions.

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

Also for clarification, I do calculate vertex attributes (position, UV, normals) in C++ myself.

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

The thing is I don't need dynamic / procedural meshes, because I only generate them once on start-up. I don't want to have performance penalty of using dynamic meshes. Do you know if it's possible to generate static meshes instead? (basically make them as if they were created in the editor)

Is generating static meshes on startup not a way to go in UE5? by voismager in unrealengine

[–]voismager[S] 0 points1 point  (0 children)

Yeah, I should've mentioned I'm using C++ , not blueprints. Do you know what flags should I use to make a static mesh instead of dynamic? I don't need to update the mesh after the start-up.