Java Class in modules

Hello everybody,

I have been designing modules for myself for quite some time now so I think I have become familiar with the Editor. It allowed me to make more and more complex pieces and here my problem starts…

I have just made one GamePiece with a quite complex behavior using ActionButtons, TriggerActions… All in all, my Piece uses 450+ Traits in its definition. Everything works as intended but the Editor started having real performance issues like double the time needed to open it, clicking on any entry in the Module tree (like any MapWindow or any Prototype definition…) takes about 4-5s for it to become highlighted in blue (ie: selected) and after, say, 45min to 1h of the Editor being open I get a pop-up message stating that memory has run short ; requiring me to close and reopen VASSAL. (Weirdly though, that same GamePiece in actual game does not lag that much (not the fastest but definetely playable).

I am not very surprised that such a “heavy” GamePiece creates performance problems but now is the time for me to find a way around. I note that you can add a Java class at the Module level in the Editor. I know nothing about Classes or Java programming in general but I may want to dive into it if I know Classes will solve my issue.

Please correct me :

As I understand, Java classes are compiled pieces of code in which I could basically write anything I want to have in my Module, sparing me any performance issue thanks to the compiled nature of the Class.

In my case, is it possible to write a Java Class that would replace my GamePiece (the Class will hold the definition). I don’t need custom code, everything I use already exists in the Editor (triggers etc…) ; what I need is just to write it in a Class, compile it and then getting both what I already have thanks to the Editor AND solving the performance issue.

Thank you very much !

Greetings,

Math

Yes, but all the traits you’re using are also classes. It’s unlikely that 450 traits on one piece will ever have acceptable performance, due to how the trait stack is traversed. (The long-term solution is that there won’t be a trait stack in V4.)

As for what specifically is slow, we can only speculate about that without seeing your module.

That is a lot of traits in a single piece. I find it hard to come up with a situation where one would ever need that many traits in a single piece, unless one is implementing something very very complicated. Most likely, there is another way to implement what you are trying to achieve. Perhaps you could give an outline for the reason you need that many traits.

See also recent thread Improve execution speed - @steenkh had similar issues as you do.

Custom code isn’t always the solution to a problem - often the problem lies in the implementation strategy.

That depends very much on what it is you are trying to achieve.

If you can provide your module - as @uckelman hinted at - we may be able to give you more information.

Yours,
Christian