Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of this line?

Tags:

java

I am looking at a sample game project. Can you explain these lines:

public static final int GAMEPAD_UP = 0x0040;

What is the use of 0x0040;?

This is the full code:

package com.androidemu;

public class Emulator {
    public static final int VIDEO_W = 240;
    public static final int VIDEO_H = 160;

    public static final int GAMEPAD_UP        = 0x0040;
    public static final int GAMEPAD_DOWN    = 0x0080;
    public static final int GAMEPAD_LEFT    = 0x0020;
    public static final int GAMEPAD_RIGHT    = 0x0010;
    public static final int GAMEPAD_A        = 0x0001;
    public static final int GAMEPAD_B        = 0x0002;
    public static final int GAMEPAD_SELECT    = 0x0004;
    public static final int GAMEPAD_START    = 0x0008;
    public static final int GAMEPAD_TL        = 0x0200;
    public static final int GAMEPAD_TR        = 0x0100;

    public static final int GAMEPAD_A_TURBO    = (GAMEPAD_A << 16);
    public static final int GAMEPAD_B_TURBO    = (GAMEPAD_B << 16);

    public static final int GAMEPAD_UP_LEFT = (GAMEPAD_UP | GAMEPAD_LEFT);
    public static final int GAMEPAD_UP_RIGHT = (GAMEPAD_UP | GAMEPAD_RIGHT);
    public static final int GAMEPAD_DOWN_LEFT = (GAMEPAD_DOWN | GAMEPAD_LEFT);
    public static final int GAMEPAD_DOWN_RIGHT = (GAMEPAD_DOWN | GAMEPAD_RIGHT);

    public native void setRenderSurface(EmulatorView surface,
            int width, int height);
    public native void setKeyStates(int states);
    public native void setOption(String name, String value);

    public native boolean initialize(String libdir, String datadir);
    public native void cleanUp();
    public native void reset();
    public native void power();
    public native boolean loadBIOS(String file);
    public native boolean loadROM(String file);
    public native void unloadROM();
    public native void pause();
    public native void resume();
    public native void run();
    public native boolean saveState(String file);
    public native boolean loadState(String file);

    public void setOption(String name, boolean value) {
        setOption(name, value ? "true" : "false");
    }

    static {
        System.loadLibrary("gba");
    }
}

What are the purpose of these values?

like image 492
raja Avatar asked Mar 01 '11 09:03

raja


People also ask

What is the meaning of these lines?

Similar to something else. Here, look at this picture—I want to get a birthday cake along these lines for my party.

What is the real meaning of line?

a continuous extent of length, straight or curved, without breadth or thickness; the trace of a moving point. something arranged along a line, especially a straight line; a row or series: a line of trees. a number of persons standing one behind the other and waiting their turns at or for something; queue.

What does it mean in line with this?

Definition of in line with : in agreement with The new policy is in line with the plans that were discussed last year. My thinking is in line with yours. The red one is more in line with what I had in mind.

What does line mean in slang?

Line refers to a line of drugs like cocaine, sniffed off a surface.


2 Answers

It's a value that has exactly one bit set:

00000000000000000000000001000000

So you can also have, say, GAMEPAD_RIGHT=0x0010 and you can OR both value and test for any of them indivuadlly by AND'ing. It is very common in games, especially on mobile devices.

The purpose of such coding is to optimize space and to be able to test various cases in one line.

By using one bit for, say, every possible gamepad key, you can represent on one int (even on one byte in the old 8-bit console days, where console have very few keys) the state of each key (it's either 'on' or 'off').

UP + RIGHT, with both key pressed, gives:

00000000000000000000000001000000

               OR

00000000000000000000000000010000

               =

00000000000000000000000001010000
like image 110
Gugussee Avatar answered Sep 22 '22 04:09

Gugussee


 public static final int GAMEPAD_UP = 0x0040;

public static void main(String args[]){
    System.out.print(GAMEPAD_UP);

}


 Output: 64

0x0040 is hexadecimanl(base 16) representation of 64(base 10).

like image 32
Abhishek Avatar answered Sep 21 '22 04:09

Abhishek