Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (602)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Better way of doing this?  (Read 1570 times)
0 Members and 1 Guest are viewing this topic.
Offline tgmg

Junior Newbie

« Posted 2009-03-07 17:00:29 »

This is quite a strange project but I will try to explain it. It takes code from an application called game maker ( and converts that code to java.
In the game maker language (gml) you don't need to declare variables, you just use them, and you can use a variable that is not defined yet from another 'object'. Also variables can be either double or string and it can change from one to the other.
The current system works but since I am just a hobby programmer I don't have very much experience so there could be a faster way to do it. Speed is important because its the backend of all the games. Its already faster than gm but i still would like to know if it can be any faster.

here is an example how the current system will convert gml:
{self.setVariable("s",self.getVariable("s") .add((Game.getValueOf(1))));}

It uses a hashtable to store all the variable names with their values:
public void setVariable(java.lang.String name, Variable value) {
        variables.put(name, value);

     * Gets the value of the variable with string name.
    public Variable getVariable(java.lang.String name) {
        Variable o = (Variable) variables.get(name.toString());
        if (o == null) {
            o=new Integer(0);
            variables.put(name.toString(),o );
            return o;
        return o;

Code for Game.getValueOf():
public static Variable getValueOf(int i){
        if (NUMBER_VARIABLE !=null){
        return NUMBER_VARIABLE;
        else {
            NUMBER_VARIABLE=new Integer(i);
        integers.put(i, NUMBER_VARIABLE);
        return NUMBER_VARIABLE;

It also uses a hashtable to store all numbers that will be used, to save memory rather than doing new Integer() every time.

Heres some more source files if you need to see them:

Thats basically the system, it uses hashtables and Variable objects to get and set variables. is their a more efficient way of doing this.

I appreciate any help Smiley
Offline pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

« Reply #1 - Posted 2009-03-07 17:57:02 »

You won't get much more efficient without actually compiling GML to bytecode, but I must say that I find the type system absolutely horrible. "Hello, World" + 1 = 1?!
Offline tgmg

Junior Newbie

« Reply #2 - Posted 2009-03-07 18:03:06 »

You won't get much more efficient without actually compiling GML to bytecode, but I must say that I find the type system absolutely horrible. "Hello, World" + 1 = 1?!
Actually "Hello, World" + 1 = "Hello, World1"
As it uses the string add function.

Yeah I suppose it is horrible but I can't think of a better way of doing things Undecided.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #3 - Posted 2009-03-08 01:59:39 »

maybe an idea but i will requiere some works and make source code coufusing,  only to do if performance is very important.

1 - read the script and collect how many variable and their names. (each name will have an index)
 => create an indexed array at the start of your translated java
Variable variables[] = new Variable[NB_VAR];
for(int n=0;n<NB_VAR;n++)
 variables[n] =new Variable();


a - use index everywhere
b - remove null check/alloc
c - remove casting

public Variable getVariable(int idx) {
       return variables[idx]

public void setVariable(idx,value) {

or even faster replace method call directly by object reference in the variables arrray

if "s" is the first vaiables

static int VAR_S=0;


Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (14 views)
2015-07-29 04:35:27

Riven (36 views)
2015-07-27 16:38:00

Riven (18 views)
2015-07-27 15:35:20

Riven (21 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (30 views)
2015-07-25 00:14:37

BurntPizza (41 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (29 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!