Jump to content

[1.8][Java?] Loading function (math) from string.


Ernio

Recommended Posts

I am looking for either lib or idea how to.

 

I want to have formula for parameters like MaxHealth or other stats like Critical% be saved inside config.

I've alredy everything done to manipulate anything I want, now I need formula.

Simplified example:

Map<String, Integer> attributes; // map holding attributes of entity
//let's say there are those keys/values inside that map:
S, 100
A, 44
K, 90

public int getValueOf(Key key)
{
// Here I want to get formula loaded by config that for this "key"will be for example: "(S+A)*K" and I want this method to return right value.
}

 

Now - I am not stupid - it's very easy to write something like that using shitload of if-s and whatever else, but that all would operate on Strings and have significantly longer computation time than normal "return (S+A)*K" coded in Java.

 

I guess my question is - does anyone know a tool (if that is even possible) that would allow me to create (on config load) virtual method computing my value and give me near-JVM-standard computing time?

 

I hope it's clear what I am looking for.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You will have to write a Parser. Basicly a bunch of well suited if, while and for loops in which you check the function for errors and if there aren't any, then do the solving.

Now - I am not stupid - it's very easy to write something like that using shitload of if-s and whatever else, but that all would operate on Strings and have significantly longer computation time than normal "return (S+A)*K" coded in Java.

Parsing is goddamn slow, I need fast computation from String, like pre-prepared calculator.

 

Draco  - this is what I don't really feel like doing :D

Is there some library for such stuff? Must be (looking), maybe someone used such?

 

EDIT

And by fast I mean FPS-time (suitable to be ran per-tick or even render loop)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Draco  - this is what I don't really feel like doing :D

 

Tough.  Because that's what you're trying to do.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Why are you concerned about performance -- do you really need to run this every tick?

 

In terms of performance optimization, generally you should only worry about it if it is proven to be a problem. You shouldn't be stupid about performance, but you also shouldn't compromise the goal of making simple, logical, readable code unless truly necessary. A parser would be very logical and readable, so I'd only get fancy if needed.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Here we go!

 

iVHfwLc.gif

 

Note:

If any of you has something that you can honestly recommend on dynamic compilation - feel free to post. Right now I got some googles, slowly molding the idea of my quest here.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Why the crap don't you just save these values in NBT...?

- Just because things are the way they are doesn't mean they can't be the way you want them to be. Unless they're aspen trees. You can tell they're aspens 'cause the way they are.

Link to comment
Share on other sites

How complicated and varied are your formulae? If there is any regularity you could come up with your own notation that is easy to transform, like how linear algebraic equations can be represented by a matrix.

 

I guess technically that is still a "parser" but it would be very easy to implement as a calculation.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.