Show Posts
|
|
Pages: [1] 2 3
|
|
1
|
Discussions / General Discussions / Re: Geometry classes
|
on: 2013-01-26 21:12:36
|
Immutable objects absolutely easier to reason about, no question. And on the average desktop app, you're not likely to notice the difference if you create them by the millions. But if you're creating them every frame on an Android machine, then you end up having to compromise and use mutable objects. Seems to me modern platforms are pushing us backward  I agree with you, the immutable approches is the more straightforward but not the most efficient in mobile platform. I don't like primitives for storing theses kind of coordinates. when i saw a method like xxx(int x1,int y1, int x2 , int y2 , int x3 , int y3, int x4 , int y4 , ...) i have a headhache...
|
|
|
|
|
2
|
Discussions / General Discussions / Geometry classes
|
on: 2013-01-26 16:47:04
|
I would discuss about a small geometry implementation: Consider having all basic classes like Point, Dimension, Rectangle, Circle. By example, you will find on a Circle a method like : 1
| public Point getCenter(); |
What would be your options ?: - Having "Point" immutable that let you the liberty to return the Point from the Circle object without any risk that somebody change it. - Having "Point" mutable that you must enforce in a some way any modifications (like with listeners). But even if you are able to intercept changes, theses changes may corrupt some objects states. (exemple changing corners of a rectangle that do not give a rectangle anymore). At this time, my own geometry approche it to use immutable object for all objects. But it's not the best approche for reduce objects allocations. Each time i want to translate, rotate, ... a geometry objects, i must instanciate a new one... The mutable approches is fine when you perform an animation and translate a series of geometry objects each update() or render() depending of what you do. Sébastien.
|
|
|
|
|
4
|
Discussions / General Discussions / Re: Coding Standards
|
on: 2013-01-24 12:48:11
|
If you have a getter and a setter that get and set the fields directly, your field *is* public; you might as well declare it public then and skip de getter/setter. If you have a getter that returns the field directly, your field is basically public and read-only. You might as well declare your field public final then and skip the getter.
The field is an implementation details, the getter is the API. If you let the caller to use directly the field you can't rely on an implementation changes without to refactor all usages. I take by example, if you want to change your implementation for a precise field that you want to set it lazy. You want only to read and instanciate it only when it is accessed. If you done a getter at the start point, you can reimplement the getter in order to get your lazy function without any impact of the usage. My position is this - You can never have issues to encalupsate a field with getter and setter. (at least no new issue than the direct access version) - You can have various issues when letting direct access to your field (that become a API part your class) So, with this reflexion, i create "get" for all fields if they needs to be publicly accessed outside.
|
|
|
|
|
5
|
Discussions / General Discussions / Re: Coding Standards
|
on: 2013-01-23 08:24:25
|
|
I'm working from 10 years in software industry and my standards are very far far of yours.
- fields are always private, if you need access, a get/set is intended for. if you want to optimize (a very little), you can force the getter to be final (that can be a good contract in lot of cases). With the final, the .class may not use an invokevirtual that can increase performance. - Around the reference immutability, for me it's not a standard point but more a contract point of what you are doing. you can't set it as a global state. - For methods that instanciate objects that must cache references results, it depends of the aspect of this returned type. if the returned object is immutable itself (like String), it's a good approach. it's the hell if differents caller can modify your cached instances concurrently. Theses cases can always be handled by the "mind aware" of the developper but they are very dangerous since you are in a team and works on big projects.
|
|
|
|
|
8
|
Discussions / Miscellaneous Topics / Re: Is programming as a job boring?
|
on: 2013-01-07 19:17:47
|
I read that a job is not boring if it's always fun. But i will take my 10 years in the same company for providing my position on it: 1. I love my job 2. It's not always fun. It's a Job and even if the mains tasks maybe fun, you have responsabilities, dead-lines , and you must handles theses and it's not a fun time 3. It's difficult... A job is not easy (i assume this as a true assertion in computer science at least  ) 4. Some day i don't want to go to my job because i know it will be a hard day But with all of theses statements, i continue to love my job even if there are boring period on it.... In a "freetime" developpement process, you are developping only when you want. in other words, only when it's fun for you. It's very different with a Job, you must work even if it's not "your" day and even if you don't found it fun
|
|
|
|
|
9
|
Discussions / Miscellaneous Topics / Re: What's your favorite game.
|
on: 2012-12-15 11:22:18
|
|
Very old games: - Arkanoid - Pop Corn - Barbarians - Dune 2 - Lemmings - Prince of Persia
Old games: - Ufo 1 & 2 - Privateer - Doom 2 - Warcraft 2 - Cim City 2000 - Diablo 1 & 2 - Baldur's Gate 1 & 2 - Syndicate - Worms
More recents games - World of warcraft - Diablo 3
I spent so lot of times with old games when i was young....
|
|
|
|
|
10
|
Discussions / Java Gaming Wiki / Re: ArrayList vs LinkedList
|
on: 2012-11-15 00:09:47
|
|
In fact
adding an item on an ArrayList can't be considered as O(1) cost since an array list may perform an array re-allocation if the current allocation becomes fullor unsufficient. This method perform a full instanciation of a new array and a full copy that have a cost that depends of the size of the list.
So, this threads talk about the memory fragmentation of a LinkedList but not the wast space of an ArrayList and the re-allocation process that may be a real penalty in adding operations.
By example, Create an ArrayList with the default constructor that mean an initial capacity of 10 and you will insert on your list 600 items. @11th insertion ==> array[10] copied on a new array[15] @15th insertion ==> array[15] copied on a new array[22] @23th insertion ==> array[22] copied on a new array[33] @34th insertion ==> array[33] copied on a new array[49] @50th insertion ==> array[49] copied on a new array[73] @74th insertion ==> array[73] copied on a new array[109] @110th insertion ==> array[109] copied on a new array[163] @164th insertion ==> array[163] copied on a new array[244] @245th insertion ==> array[244] copied on a new array[366] @367th insertion ==> array[366] copied on a new array[549] @550th insertion ==> array[549] copied on a new array[823] @600th insertion ==> you have an array of 823 that means a wast of 223 bullets and 11 arrays instanciations and copy.
Hopefully in often/some cases, we can estimate the final size of a list before filling it. When it's the case, we should consider to use the good one constructor in order to prevent theses reallocations. With a LinkedList you haven't this issue.
|
|
|
|
|
11
|
Game Development / Networking & Multiplayer / Re: What do Java game developers use for Database persistence?
|
on: 2012-05-18 09:58:25
|
|
(Theses configuration was not always useed for games but for my projects in general)
Database + Persistence Layer : H2 + Hibernate (for larger project that fit he need of an SQL langage) Database + Persistence Layer : Cassandra + Custom persistence layer (for servers that just need to store some simple data structures) Database + Persistence Layer : Serialization + Custom persistance layer (for small games)
|
|
|
|
|
14
|
Java Game APIs & Engines / OpenGL Development / drawing 2D image
|
on: 2012-05-17 09:33:48
|
So, i have a question. I want be able to draw an image with alpha on the screen. I want the color fusion to be done with the current color on the buffer. For this i fo it: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0f,0f,0f,0f);
glEnable(GL.GL_TEXTURE_2D ); glBindTexture(GL.GL_TEXTURE_2D, ctx.getTexture().getTextureId() ); glBegin(GL.GL_QUADS); glTexCoord2f( textureBounds[0].getX() , textureBounds[0].getY() ); glVertex2f ( x , y ); glTexCoord2f( textureBounds[1].getX() , textureBounds[1].getY() ); glVertex2f( x + img.getWidth() , y ); glTexCoord2f( textureBounds[2].getX() , textureBounds[2].getY() ); glVertex2f( x + img.getWidth() , y + img.getHeight() ); glTexCoord2f( textureBounds[3].getX() , textureBounds[3].getY() ); glVertex2f(x, y + img.getHeight() ); glEnd(); glBindTexture( GL.GL_TEXTURE_2D , 0 );
|
With this sequence, it draw nothing. It le me thinks that the translucent color disable the quad to be visible ? PS: with an opaque image, it's the same.... i don't undestand what it do....
|
|
|
|
|
18
|
Java Game APIs & Engines / OpenGL Development / Re: Texture a Quad
|
on: 2012-05-14 23:14:19
|
With this version, i handle correctly the 0.0f and 1.0f texCoord 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public static class TextureCoordInterpolator { private int x,y; private int width,height; private int textureWidth,textureHeight; private Rectangle anchor; public void getTextureCoord( float pX , float pY ) { float rx = ( ( pX - anchor.getX() ) % anchor.getWidth() ) / ( anchor.getWidth() - 1 ); float ry = ( ( pY - anchor.getY() ) % anchor.getHeight() ) / ( anchor.getHeight() - 1 ); System.out.println("getTextureCoord(" + pX + "," + pY + ") == subTextureCoord(" + rx + "," + ry + ")"); float gx = ( x + (rx * width) ) / textureWidth; float gy = ( y + (ry * height) ) / textureHeight; System.out.println("getTextureCoord(" + pX + "," + pY + ") == globalTextureCoord(" + gx + "," + gy + ")"); } } |
|
|
|
|
|
19
|
Java Game APIs & Engines / OpenGL Development / Re: Texture a Quad
|
on: 2012-05-14 22:37:55
|
At the first, i decide to wrote the coord mapping in java before to try to do it in a pixel shader. It give this try : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public static class TextureCoordInterpolator { private int x,y; private int width,height; private int textureWidth,textureHeight; private Rectangle anchor; public void getTextureCoord( float pX , float pY ) { float sx = ( pX - anchor.getX() ) / ( anchor.getWidth() ); float sy = ( pY - anchor.getY() ) / ( anchor.getHeight() ); System.out.println("getTextureCoord(" + pX + "," + pY + ") == subTextureCoord(" + sx + "," + sy + ")"); float rx = sx - (int)sx; float ry = sy - (int)sy; System.out.println("getTextureCoord(" + pX + "," + pY + ") == normalSubTextureCoord(" + rx + "," + ry + ")"); float gx = ( x + (rx * width) ) / textureWidth; float gy = ( y + (ry * height) ) / textureHeight; System.out.println("getTextureCoord(" + pX + "," + pY + ") == globalTextureCoord(" + gx + "," + gy + ")"); } |
It globbaly works, except that i don't see any difference between the 0f and the 1f texCoord. I'm not sure how can i handle it properly !! any idea ? my main was: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public static void main(String[] args) { TextureCoordInterpolator test = new TextureCoordInterpolator(); test.x = 50; test.y = 50; test.width = 100; test.height = 100; test.textureWidth = 200; test.textureHeight = 200; test.anchor = new Rectangle( 5 , 5 , 20 , 20 ); test.getTextureCoord(5,5); test.getTextureCoord(24,24); test.getTextureCoord(25,24); test.getTextureCoord(26,24); } |
|
|
|
|
|
22
|
Java Game APIs & Engines / OpenGL Development / Re: Texture a Quad
|
on: 2012-05-14 18:32:49
|
|
The quad is just a case of filling form that should work. I want to "generalize" it for triangles, shapes (with tesselation), circles (a shape) etc....
i don't know at all what is a pixel shader and how it works... I will go deeper this evening on this stuff.
|
|
|
|
|
23
|
Java Game APIs & Engines / OpenGL Development / Re: Texture a Quad
|
on: 2012-05-14 16:39:23
|
I understand better how things works. But now, i would texture a quad with a repeat factor but only with a region of a texture So for the example, Considering that i want to use only the rectangle (0.25,0.25) x (0.75,0.75) of a texture. But i want to repeat i 4 times on a quad that have dimension (100,100) and starting at (50,50) i would do a things like it 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| glTexCoord(0.25,0.25); glVertex2f( 50 , 50 );
glTexCoord(3.75,0.25); glVertex2f( 150 , 50);
glTexCoord( 3.75 , 3.75 ); glVertex2f( 150 , 150);
glTexCoord( 0.25 , 3.75 ); glVertex2f( 50 , 150); |
(the vertices order may be wrong, i do it without my dev pc) So if i understand, it will draw like it Horizontall i will have 1
| [0.25 ~ 1] + [0 ~ 1 ] + [0 ~ 1 ] + [0 ~ 1 ] + [0 ~ 0.75 ] |
Instead of what i want: 1
| [0.25 ~ 0.75] + [0.25 ~ 0.75] + [0.25 ~ 0.75] + [0.25 ~ 0.75] |
How can i achieve my goal ? Thanks in advance.
|
|
|
|
|
24
|
Java Game APIs & Engines / OpenGL Development / Re: Texture a Quad
|
on: 2012-05-14 09:31:38
|
Hi Sébastien
I have a question for you. Have you noticed an important boost when using the repeat factor instead of using more vertices?
In your case, I would use something close to [0.5,0.5] [4.5,0.5][4.5,2.5][0.5,2.5] (not tested).
Ok, if i understand it correctly, the 0.5 to 4.5 on the x axis means to draw 4 times the texture on this region starting it at the middle of the texture (0.5f) This way it give the clamp point (0.5) and the scale (number of repetitions in the region). I will try it this evening, i understand better how texCoord works (all examples found are always the same with texCoord from 0 to 1) Thanks for all.
|
|
|
|
|
25
|
Java Game APIs & Engines / OpenGL Development / Texture a Quad
|
on: 2012-05-14 07:17:49
|
Hi, I want to texture a quad like it:  In black, the quad that i want to fill with the texture. In Gray, the texture clamp & size with a repeat factor. I must set the texture coord for 4 vertices, how can i give in this way the texture scaling and the texture clamp point and the repeat mode ? Bets regards, Sébastien.
|
|
|
|
|
26
|
Game Development / Game Play & Game Design / Re: Game Internal Organization?
|
on: 2012-05-10 08:21:15
|
I can't stress enough how important a proper amount of sleep is: developing is 80% debugging*, and with enough sleep, you write fewer bugs, find the remaining ones faster, etc.
I completely agree. There have been numerous instances where I've rage quit and gone to bed because I couldn't fix a problem....only to have a EUREKA!! moment as soon as I woke up  my EUREKA time becomes often in the bathroom...
|
|
|
|
|
27
|
Game Development / Game Play & Game Design / Re: Game Internal Organization?
|
on: 2012-05-09 19:10:40
|
|
By example, when i wrote a game (always little games because i havent' sufficient commitment alone) i wrote because i love to develop. It's a game because all the days i work on business application and want to add more fun when it's at home. But i don't do a game for the game itself.
I really think that this spirit is the ** bad way **, because i lost often some objectives and disgress often quickly and for too long time. The functionnal end-result should be always the main objective but i can't work like it.
|
|
|
|
|
28
|
Game Development / Game Play & Game Design / Re: Game Internal Organization?
|
on: 2012-05-09 08:03:23
|
|
My trick would be to use inheritance only for main behaviours and natural things and use composition / injection dependances to glue others functionnalities. It let you more flexibility after to construct more variants of behaviour than inheritance that may block you in an inheritance tree for a specified functionnality.
|
|
|
|
|
29
|
Java Game APIs & Engines / OpenGL Development / Re: FBO for drawing / modify an image
|
on: 2012-05-05 09:51:27
|
It works fine for now. FOr add deeper in my tools, in can draw on a specific region on a texture. it becomes when we create a "subimage" from another one at the API level. i must in this case let it drawing only in the texture that corresponds to it's subimage. For now, i used a translatef + scissor like it: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public void bind(GLContext ctx) { ImageContext imageContext = (ImageContext)image.getContext(); ctx.getGL11().glMatrixMode( GL.GL_PROJECTION ); ctx.getGL11().glPushMatrix(); ctx.getGL11().glLoadIdentity(); ctx.getGL11().glOrtho( 0 , imageContext.getTextureWidth() , 0 , imageContext.getTextureHeight() , 1, -1); ctx.getGL11().glMatrixMode( GL.GL_MODELVIEW ); ctx.getGL11().glPushMatrix(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferId); super.bind(ctx); ctx.getGL11().glViewport( 0 , 0 , imageContext.getTextureWidth() , imageContext.getTextureHeight() ); ctx.getGL11().glTranslatef( imageContext.getX() , imageContext.getY() , 0f ); ctx.getGL11().glEnable( GL.GL_SCISSOR_TEST ); ctx.getGL11().glScissor( imageContext.getX() , imageContext.getY() , imageContext.getWidth() , imageContext.getHeight() ); } |
I would know if the viewport reset before translate call ? because here i explain a translate from my viewport coordonate reardless previous translatef that may be done before. It seems to work well, bu i want to be sure. Thanks in advance.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|