Ernio Posted May 12, 2015 Posted May 12, 2015 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. Quote 1.7.10 is no longer supported by forge, you are on your own.
Draco18s Posted May 12, 2015 Posted May 12, 2015 https://www.google.com/#safe=off&q=how+to+write+a+compiler+for+a+trivial+language Quote 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.
ItsAMysteriousYT Posted May 12, 2015 Posted May 12, 2015 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. Quote
Ernio Posted May 12, 2015 Author Posted May 12, 2015 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 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) Quote 1.7.10 is no longer supported by forge, you are on your own.
Draco18s Posted May 12, 2015 Posted May 12, 2015 Draco - this is what I don't really feel like doing Tough. Because that's what you're trying to do. Quote 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.
ItsAMysteriousYT Posted May 12, 2015 Posted May 12, 2015 Yep And if youz write a good parser, it will be fast. Just set break; and if-stuff right and it will run fast. Quote
jabelar Posted May 12, 2015 Posted May 12, 2015 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. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Ernio Posted May 12, 2015 Author Posted May 12, 2015 Here we go! 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. Quote 1.7.10 is no longer supported by forge, you are on your own.
AnZaNaMa Posted May 13, 2015 Posted May 13, 2015 Why the crap don't you just save these values in NBT...? Quote - 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.
Ernio Posted May 13, 2015 Author Posted May 13, 2015 I think you didn't understand what the topic is about. I don't save, I compute. Quote 1.7.10 is no longer supported by forge, you are on your own.
jabelar Posted May 15, 2015 Posted May 15, 2015 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. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Recommended Posts
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.