i develop game opengl 2d on android.
it's impotent gain performance level since view complicated , contains 300-400 objects @ same time (game loop).
i know pretty static , non-static fields in java:
private final static int number = 10; and
private final int number = 10; my question not encapsulation (as oo) performance.
what better use performance, static or non-static fields.
the idea logic use primitives float/int.
i create generic super class "views" , class must more efficient in scope of performance:
here example:
/** sprite sheet definition */ private final int sprite_width = 4; private final int sprite_height = 4; private float mscreenwidth, mscreenheight, wratio, hratio; private int mframe = 0; private int mswitcher = 0; private final int texture_count = 1; // sprite sheet use 1 image time. private int[] textures = new int[texture_count]; // frame animation protected floatbuffer vertexbuffer; private final espritedirection mdirection = espritedirection.top_to_down_left_to_right; public float x, y, initpos, finalpos, initspeed, currentpos; private bytebuffer bb1; private final int total_image_count_in_sprite = sprite_width * sprite_height; private floatbuffer[] floatbufferarray = new floatbuffer[total_image_count_in_sprite]; private float xoffset = 1.0f/sprite_width; private float yoffset = 1.0f/sprite_height; private float vertices[] = { 0.0f,3.0f,0.0f, 0.0f,0.0f,0.0f, 3.0f,3.0f,0.0f, 3.0f,0.0f,0.0f }; private float storage[][] = new float[total_image_count_in_sprite][]; private int[] sprite_x_indexes = new int[sprite_width];//{1,2,3,4}; private int[] sprite_y_indexes = new int[sprite_width];//{1,2,3,4}; i can guess multiple initiation of same class static field better, hmm
thank you,
from performance pov, once code has been compiled there should pretty little difference, since both static , (single) non-static field have been transformed memory location.
declaring field static may provide optimization possibilities @ compiler level. on other hand, typically static objects not "close to" instance data in memory, bad cache performance.
in general, not should spend time until / unless have exhausted algorithmic optimizations, , after know lose time.
Comments
Post a Comment