Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3
1  Game Development / Networking & Multiplayer / Re: Networking concepts as applied to Weapon Fire on: 2006-08-05 20:48:00
For tracking shots, rather than sync positions maybe it's better to sync vectors.  That way you know where the shot is going during the times you aren't getting its position.
2  Game Development / Networking & Multiplayer / Re: Best way to timeout connections with NIO. on: 2006-08-03 00:36:52
It's just test code to see if a feature works the way I think it should.  Not part of my application Smiley
3  Game Development / Networking & Multiplayer / Re: Best way to timeout connections with NIO. on: 2006-08-02 19:43:55
To be clear, setSoTimeout does or does not work for NIO?  Everything in the doc says it is for blocking opperations.  Here is my test code that doesn't seem to do anything:
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  
while (true){
            if (selector.select()!=0){
                System.out.println("Selector returned.");
                Set keys=selector.selectedKeys();
                Iterator i=keys.iterator();
                while (i.hasNext()){
                    SelectionKey key=(SelectionKey) i.next();
                    i.remove();
                    if (key.isAcceptable()){
                        System.out.println("Got new one.");
                        ServerSocketChannel ss2=(ServerSocketChannel) key.channel();
                        SocketChannel newCon=ss2.accept();
                        newCon.configureBlocking(false);
                        newCon.register(key.selector(),SelectionKey.OP_READ);
                        newCon.socket().setSoTimeout(200); //***HERE IS MY TIMEOUT***
                   }
                    if (key.isReadable()){
                        ByteBuffer buf = ByteBuffer.allocateDirect(1024);
                        int numBytesRead = ((SocketChannel)key.channel()).read(buf);
                        if (numBytesRead==-1) {
                            key.channel().close();
                            continue;
                        }
                        buf.flip();
                        Charset myCharset = Charset.forName( "ISO-8859-1" );
                        System.out.println("Is readable:"+myCharset.decode(buf).toString());
                    }
                }
            }
        }
4  Game Development / Networking & Multiplayer / Re: Best way to timeout connections with NIO. on: 2006-08-01 21:16:40
Because I like my code efficient, i.e. I block on select, i.e. I would never get a chance to timeout the incoming connections Smiley. No other reason.

If you block on select, how do you cleanly shutdown your application?  I wanted to make my design so that I could shutdown my server socket thread without having to System.exit(), so I have a shutdown boolean that I can set and loop like this:
1  
2  
3  
4  
while (!shutdownActivated){
    if (selector.select(500)!=0){
    }
}


I was thinking this lets me not spend to much in busy loop, while at the same time letting me cleanly shut down the thread without a system exit.  Do you know of a way to have my selector select a special key when I want to shutdown the application?
5  Game Development / Networking & Multiplayer / Re: Best way to timeout connections with NIO. on: 2006-08-01 21:09:36
mySocketChannel.socket().setSoTimeout(int timeout);

The javadoc says "With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time"  Because I'm using non blocking sockets and this function was written in 1.1, I'm not sure it will do what I want.  I don't want to just 'drop' the connection though.  I want to know when it was dropped so I can log it and clean up stuff.

Assuming OP can't just drop the connection "the next time it does something AFTER the ten seconds is up" (easiest way, normally most efficient too),

I'm afraid of some hax0r just making connections and letting them sit for an easy DoS.  On a non-hax0r note I want to notify the other plays that their opponent has timed out as soon as possible.

- each time you get a selectable key, set a timestamp in a map saying that you just received something at this time, with that key as the key
 - separate thread iterates over that map periodically finding victims, and uses the selectable key objects to remove them from the selector and drop the channel
I'm currently doing something very similar.  I have a DelayQueue running in another Thread.
6  Game Development / Networking & Multiplayer / Best way to timeout connections with NIO. on: 2006-08-01 08:11:23
I am using NIO and ServerSocketChannel.  After I create a connection, I can't wait more than 10 seconds between each input from the client.  Otherwise I want to timeout the connection.  This is while handling hundreds of connections at once.  What's the best way to do this?  What would be really cool is if my selector could return a key when a connection doesn't send me anything after 10 seconds.  I could also selector.select(1) and just test every 1 second but that seems like overkill.  Right now I have another Thread dealing with timeouts.  What's the best way to do this?

Thanks!
7  Java Game APIs & Engines / Tools Discussion / Re: A Free IDE for slow computers, or eclipse teak on: 2005-02-14 21:24:01
I don't think I'm asking for too much at all.  JCreator does all that and runs very fast, the only problem is that it cost a license.  JCreator is what some of them were using, but not any of the newer boxes.  Sadly, it seems everything programmed in java is too slow to use Sad  I even used IntelliJ on one of these boxes as a test, and although it didn't run near as quickly as JCreator, it was "fast enough", but I can't use that either.  The problem with JCreator is that the light (free) version is VERY sparce on features.

I do make them do a few with notepad and the command prompt (to know more about what goes on under the hood), but using an IDE puts more focus on the programming aspect and less on the "which import was that" or "what was that function name again" part.

Any way I could get eclipse written in C++? hehe
8  Java Game APIs & Engines / Tools Discussion / A Free IDE for slow computers, or eclipse teaks(?) on: 2005-02-14 15:02:55
I need a free IDE for somewhat slow computers that highschool students can use to learn java.  I'ld like features like code completion, automatic imports, real time error checking, quick javadoc refrences, and 1.5 support: all of which I see in eclipse.  The problem is that eclipse can be incretibly slow on these computers.  There are lots of fancy features that students don't need to learn java, so things like CVS support or native ant support I could do without.

What free IDEs to you recommend for slow computers?

Are there tweaks I can use to eclipse to make it run faster, at the sacrafice of a few features?
9  Java Game APIs & Engines / jMonkeyEngine / Re: Simple rotation use case on: 2005-01-24 18:00:53
I won't be home till 11PMish CST so I'll look for the code then, and try to send you some PMs.  The new behavior code isn't in CVS yet, so no luck there.  The new release doesn't have a definitive date, but I'm guessing ... 1-2 months???
10  Java Game APIs & Engines / jMonkeyEngine / Re: Simple rotation use case on: 2005-01-24 17:05:10
"Is there a mechanism that does simple Rotation behaviors like Java3D? If on each frame I want an object to rotate on its Y axis by a specified amount, how do I do that? SpatialTransformer, suggested in another thread, seems more complicated than I would think necessary for a replacement to RotationBehavior."

SpatialTransformer is more complicated because it does more than RotationBehavior for Java3d.  You can use it for a simple rotation if you want.  If you want help, I can show you how to make a basic rotation behavior Controller from scratch.

"I'm looking at SpatialTransformer and I have some basic questions about why it works the way it does. If I have geometry attached to a node, I would want to attach a SpatialTransformer to it. Not sure why I have to tell it the number of objects it would be transforming - it would be all of the nodes that are the children of the node that the Transformer is attached to."

Currently, Controllers and what they are attached to have no significance.  You could attach the controller to the root node and it would do the same thing if setup the same way.  Controllers are being removed for another animation system this release of jME.  Currently, there is no way to say "do this on all the children" without writting your own update function, which isn't very difficult in itself.  I can help with this if you want.  Controllers aren't objects in the scene graph.  They are a seperate property of the objects themselves.  This seems to be one point of confusion.

Root Node
|_ Transformer
|_ Node
   |_ Planet
   |_ Node
    |_ Moon

"By Attaching the transformer to the 'root node' I expect I should be transforming everything underneath."

The controller won't animate what it's not been specificly told to animate.  ControllerNode type behavior is planned for the next jME release.  I agree this system isn't best and that's why it will be gone on the next release.

"Similarly, why would I be attaching objects to the transformer? setObject just seems awkward in this sense. I have to attach the transformer to the rootNode (which IS my pivot point) and then attach all of its children to the Transformer as well?"

setObject is the way you tell the Controller what you want to animate.  The current way is to

1) Tell the controller everything you want to animate and how.
2) add things to your scene graph.
3) Attach controller to the scene graph.

"The other sets (position, rotation, scale) make sense to me. But I should be able to set a rotation based off a Vector3f as well (0,1,0) -> rotate along the y axis."

To do that you would have to create a Quat that represents that rotation.  There should be some functions that can do that for you in jME.  If not, I can post the math required.

"I guess what I'm saying here is that this use case is very complex when it really should be obvious and simple but in this case appears to be neither and will be harder to learn."

Modeling a solar system with sun->earth->moon is more complex than it seems at first.  You can't just attach them as children and rotate the moon around the earth because the earth is actually doing two rotations: rotating around the sun (year) and rotating around its core (days).  So if you rotate the earth to represent days and the moon is a child you end up with the moon rotating around the earth really fast.  You have to setup a center of rotation type system with a center of mass that the earth and moon can rotate around.  I've actually coded this exact thing before and posted the code on the jME forum.  I'll check my home computer and see if I still have it.
11  Java Game APIs & Engines / jMonkeyEngine / Re: SMD Animation on: 2005-01-24 16:41:17
That sounds right.  The JointController was made with the milkshape format in mind, so there may be a bit of tweaking to do.  With that said, it should still be workable for any Joint system that doesn't use multiple bones per vertex (which I don't believe halflife does).  if you run into any problems let me know.
12  Java Game APIs & Engines / jMonkeyEngine / Re: SMD Animation on: 2005-01-24 13:46:16
SMD files?  What link are you using to find out about the format?

jME expects vertices to be stored in local space, and so does JointController.  The localRefMatrix again expects transforms to be relative to the joint parent.
13  Java Game APIs & Engines / jMonkeyEngine / Re: Blender exporter, and XML issues. on: 2005-01-24 13:22:00
The multitexturing part was a new addition.  I'll look at it and see if I can add checks for those and commit as a bug fix.  Won't take long.
14  Java Game APIs & Engines / jMonkeyEngine / Re: Particle System + .jme on: 2005-01-21 23:14:01
The .jme format doesn't have partical support yet.  I could add it, but I'ld have to spend some time thinking about how to fit it in best.
15  Java Game APIs & Engines / jMonkeyEngine / BSP and the view frustum on: 2004-12-13 13:40:29
I need to see which sides of a BSP I need to render.  So I have a view frustum and a splitting plane.  If all points of the frustum are on the same side of the plane, I only render that one side.  Seems simple.  So I've ported the code here

http://www.magic-software.com/Source/Graphics/WmlBspNode.cpp

The only problem is that code doesn't work.  It seems at first he checks which side of the plane the camera is on (makes sense) and to see if he needs to render the other side he uses some kind of GetMaxCosSqrFrustumAngle function.  I'm not sure how using that lets him get away with checking only one number, or it's specific purpose?

My intuitive idea is to check the intersections of the frustum planes for 6 corners, and then check the sides of all 6 corners against the splitting plane.  That of course sounds like more work than his one number check, I just don't understand why it works.
16  Java Game APIs & Engines / jMonkeyEngine / Re: jME on OSX on: 2004-12-02 14:57:29
That's the correct repository.  Assert is java1.4

What command are you executing at the command prompt to compile the java code?

17  Discussions / Miscellaneous Topics / Re: Share the worst code you have ever seen... on: 2004-11-29 16:34:44
I remember in C there was this to swap two numbers

1  
2  
3  
void swap(int & a,int & b){
a^=b^=a^=b;
}
18  Discussions / Miscellaneous Topics / CS degrees in high demand=unemployed programers??? on: 2004-11-15 15:03:57
All I hear on the internet and from other programmers is about outsourcing and how programmers are looking through the classified for jobs and a saturated job market, but then there's this.

http://money.cnn.com/2004/11/12/pf/college/degrees_jobs/index.htm?cnn=yes

Out of the top 10 wanted degrees there's CS EE CE and IS!!!

And that's not the only study.  I've seen lots that say basicly the same thing.  It doesn't add up though.  How can the degrees be in such high demand, but there be no jobs.

Honest question: Not trying to get people mad and all.  I'm almost finished with my CS myself, and this really does make me wonder.
19  Discussions / Miscellaneous Topics / I want to remote desktop, but my IP changes! on: 2004-11-11 22:02:43
At home I run winXP and have remote desktop enabled.  When I'm not home, I'ld like to remote desktop to my computer but my IP address at home changes sometimes.  What I've been doing is looking up my IP address before I leave, email that to myself, then use that number whenever I'm gone to connect.

I'ld like to automate the process somehow.  Maybe autorun something on my home computer that could report back to ... somwhere... my current home IP periodically so I could look at that and connect that way.  Is there any way I can do this assuming I don't have my own web site and don't want to pay anything?
20  Java Game APIs & Engines / jMonkeyEngine / Re: Xith vs jME on: 2004-10-22 06:19:34
Quote
Just because of the name, "monkey engine".


*nod*.  That's why I use SuSE at home.  I refuse to use FreeBSD because of the satanic mascot.  And those penguins?  Who could take that seriously.  Lizards are way more profesional.
21  Game Development / Newbie & Debugging Questions / Re: java newbie on: 2004-10-21 14:31:07
Just to name two:
www.lwjgl.org
www.mojomonkeycoding.com
22  Java Game APIs & Engines / Xith3D Forums / Re: Merge Java3D and Xith3D? on: 2004-10-19 22:20:54
Last check, jME supported mac just as much as LWJGL does.  There were problems with loading image formats with awt, but there are ways around that.  If you posted your problem and your fix on the forums, I'm sure it would be well recieved.

I don't know what you're refering to about the ""Why in the world would you EVER need that in a GAME?" but usually if many people are questioning your design they have a valid point.

The design of jME is based on the design of a really smart person.  Not to say he's perfect, but "fundamental design flaws" is debatable at the least.

That said, Java3d just isn't ment to do the same task as Xith3d so merging wouldn't make sense.  As far as the various other projects that work on LWJGL or JOGL (xith for example), different people like their code to look different ways.  For example, I like the RenderState setup of jME.

I say "free" projects are about fun, so let people just do what's fun to them.  And I agree with Cas: API focus is a good thing.
23  Game Development / Newbie & Debugging Questions / Re: Can anyone show me how to read a  text fi on: 2004-10-18 02:01:05
Install java 1.5 and use the new Scanner class.  It's very good for C++ style reading.

//Scanner s=new Scanner(System.in);
or
// Scanner s=new Scanner(new File("input.txt"));

s.nextInt();
s.nextFloat();

and so on.
24  Java Game APIs & Engines / jMonkeyEngine / Re: Xith vs jME on: 2004-10-17 16:16:20
I see what you're saying.  I just think everything comes out even (speed wise) with how often jME uses the world location of an object and the nodes in the scene graph.
25  Java Game APIs & Engines / jMonkeyEngine / Re: Xith vs jME on: 2004-10-17 16:12:28
I was meaning to say if you have a SceneGraph of depth 10, consider each leaf node as a renderable object.  If I can figure out that the node at depth 5 is not viewable I don't need to check any nodes or leaves below it.  I need the exact position of that node to figure out if it is viewable or not.
26  Java Game APIs & Engines / jMonkeyEngine / Re: Xith vs jME on: 2004-10-17 15:57:10
The reason this happens is because each level of the scene graph has a bounding volume.  It may seem wastefull to have to transform your node all the way down the scene graph but the real speed up is during rendering.  If the middle of the scene graph can be culled with view fustrum culling, then none of the lower leaf nodes have to be checked.  To do this, you need transforms at each level.  It's also very easy and fast O(1) to get the exact world location of any node on the scene graph.
27  Game Development / Performance Tuning / Re: 3D Interface Based System on: 2004-10-15 20:16:43
Here's something that's kind of trippy. If I use instanceof and cast, my results are faster than just letting the interface figure out which function to call on its own.  Here is the new code (with your boolean fix) and my results:

Total all Slow2f.getHash() : 3407
Total all Slow2f from IVector2f.getHash() : 6735
Total mixed slow/fast getHash() inside Interface : 6795
Total switch getHash() : 3125
Total cast getHash() : 4375
The total sum is 383990368

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  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
 import java.util.Random;
 
/**
 * @author lindamoodj
 */

public class TestBenchmark {
 
 private final static int N = 800;
 private final static int NUM_ITERATIONS = 12;
 private static IVector2f[][] vecsIS;
 private static IVector2f[][] vecsIC;
 private static IVector2f[][] vecsIM;
 private static Slow2f[][] vecsS;
 private static Switch2f[][] vecsSw;
 
 static long lastTime;
 
 static long slowTime;
 static long mixedTime;
 static long slowITime;
 static long switchTime;
 static long castTime;
 static long sumT;
 private static final int ITNUM = 10;
 
 
 public static void main(String[] args) {
   
  for (int i=0;i<NUM_ITERATIONS;i++){
   initVars();
   loopInterface();
   loopSlow();
   loopMixed();
   loopSwitch();
   loopCast();
   if (i==1){
               castTime=slowTime=mixedTime=slowITime=switchTime=0;
   }
  }
  System.out.println();
  System.out.println("Total all Slow2f.getHash() : " + slowTime);
  System.out.println("Total all Slow2f from IVector2f.getHash() : " + slowITime);
  System.out.println("Total mixed slow/fast getHash() inside Interface : " + mixedTime);
  System.out.println("Total switch getHash() : " + switchTime);
  System.out.println("Total cast getHash() : " + castTime);  
  System.out.println("The total sum is " + sumT);
 }
 
 private static void loopSlow() {
  setTime();
  for (int i=0;i<ITNUM;i++)
        processArraySlow(vecsS);
  slowTime+=fromTime();
 }
 
 private static void loopCast() {
  setTime();
  for (int i=0;i<ITNUM;i++)
        processArrayCast(vecsIC);
  castTime+=fromTime();
 }
 
 private static void loopSwitch() {
  setTime();
  for (int i=0;i<ITNUM;i++)
        processArraySwitch(vecsSw);
  switchTime+=fromTime();
 }
 
 private static void loopMixed() {
  setTime();
  for (int i=0;i<ITNUM;i++)
        processArray(vecsIM);
  mixedTime+=fromTime();
 }
 
 
 private static void loopInterface() {
  setTime();
  for (int i=0;i<ITNUM;i++)
        processArray(vecsIS);
  slowITime+=fromTime();
 }
 
 private static void initVars() {
  vecsIS=new IVector2f[N][];
  vecsS=new Slow2f[N][];
  vecsIM=new IVector2f[N][];
  vecsSw=new Switch2f[N][];
  vecsIC=new IVector2f[N][];
  Random r=new Random();
  for (int i=0;i<N;i++){
   vecsIS[i]=new IVector2f[N];
   vecsS[i]=new Slow2f[N];
   vecsIM[i]=new IVector2f[N];
   vecsSw[i]=new Switch2f[N];
   vecsIC[i]=new IVector2f[N];
   for (int j=0;j<N;j++){
    float x=r.nextFloat();
    float y=r.nextFloat();
    vecsIS[i][j]=new Slow2f(x,y);
    vecsS[i][j]=new Slow2f(x,y);
    vecsSw[i][j]=new Switch2f(x,y);
    if (r.nextBoolean()){
     vecsIM[i][j]=new Slow2f(x,y);
     vecsIC[i][j]=new Slow2f(x,y);
    }
    else{
     vecsIM[i][j]=new Fast2f(x,y);
     vecsIC[i][j]=new Fast2f(x,y);
    }
   }
  }
 }
 
 private static void processArray(IVector2f[][] a){
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++)
    sum+=a[j][i].getHash();
  sumT+=sum;
 }
 
 private static void processArrayCast(IVector2f[][] a){
         float sum=0;
         for (int i=0;i<a.length;i++)
          for (int j=0;j<a[i].length;j++){
                if (a[j][i] instanceof Fast2f)
                      sum+=((Fast2f)a[j][i]).getHash();
                else
                      sum+=((Slow2f)a[j][i]).getHash();
          }
         sumT+=sum;
        }
 
 private static void processArraySwitch(Switch2f[][] a) {
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++){
    Switch2f.fastSwitch=!Switch2f.fastSwitch;
    sum+=a[j][i].getHash();
   }
  sumT+=sum;
 }
 
 private static void processArraySlow(Slow2f[][] a){
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++)
    sum+=a[j][i].getHash();
  sumT+=sum;
 }
 
 private static void setTime(){
  lastTime=System.currentTimeMillis();
 }
 
 private static long fromTime(){
  return System.currentTimeMillis()-lastTime;
 }
 
 private static interface IVector2f{
  void set(float x,float y);
  float getHash();
 }
 
 private static class Slow2f implements IVector2f{
  float x,y;
  public Slow2f(float x,float y) {
   set(x,y);
  }
 
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   return x+y;
  }
 }
 
 private static class Switch2f implements IVector2f{
  float x,y;
  public static boolean fastSwitch;
  public Switch2f(float x,float y) {
   set(x,y);
  }
 
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   if (fastSwitch)
    return 1.0f;
   else
    return x+y;
  }
 }
 
 
 private static class Fast2f implements IVector2f{
  float x,y;
  public Fast2f(float x, float y) {
   set(x,y);
  }
   
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   return 1.0f;
  }
 }
}
28  Game Development / Performance Tuning / Re: 3D Interface Based System on: 2004-10-15 19:53:15
Damn order of operations! Smiley  I was supprised as well at the speed of the SwitchVector class.  An explanation would be very interesting as to why it's faster and what could be done to make the interface implimentation as fast.
29  Game Development / Performance Tuning / Re: 3D Interface Based System on: 2004-10-15 16:29:34
Here is my modified code that removes the prints, allows it to warm up iterations before timing, and loops each iteration

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  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
 import java.util.Random;
 
/**
 * @author lindamoodj
 */

public class TestBenchmark {
 
 private final static int N = 800;
 private final static int NUM_ITERATIONS = 12;
 private static IVector2f[][] vecsIS;
 private static IVector2f[][] vecsIM;
 private static Slow2f[][] vecsS;
 private static Switch2f[][] vecsSw;
 
 static long lastTime;
 
 static long slowTime;
 static long mixedTime;
 static long slowITime;
 static long switchTime;
private static final int ITNUM = 10;
 
 
 public static void main(String[] args) {
   
  for (int i=0;i<NUM_ITERATIONS;i++){
   initVars();
   loopInterface();
   loopSlow();
   loopMixed();
   loopSwitch();
   if (i==1){
               slowTime=mixedTime=slowITime=switchTime=0;
   }
//   System.out.println();
 }
  System.out.println();
  System.out.println("Total all Slow2f.getHash() : " + slowTime);
  System.out.println("Total all Slow2f from IVector2f.getHash() : " + slowITime);
  System.out.println("Total mixed slow/fast getHash() inside Interface : " + mixedTime);
  System.out.println("Total switch getHash() : " + switchTime);
 
 }
 
 private static void loopSlow() {
//  System.out.println("getHash of all Slow2f()");
 setTime();
//  processArray(vecsS);
 for (int i=0;i<ITNUM;i++)
        processArraySlow(vecsS);
  slowTime+=fromTime();
  //System.out.println("The time taken:" + fromTime());
}
 
 private static void loopSwitch() {
//  System.out.println("getHash of all Switch2f()");
 setTime();
//  processArray(vecsS);
 for (int i=0;i<ITNUM;i++)
        processArraySwitch(vecsSw);
  switchTime+=fromTime();
  //System.out.println("The time taken:" + fromTime());
}
 
 private static void loopMixed() {
//  System.out.println("getHash of mixed slow and fast inside Interface");
 setTime();
  for (int i=0;i<ITNUM;i++)
        processArray(vecsIM);
  mixedTime+=fromTime();
//  System.out.println("The time taken:" + fromTime());
}
 
 
 private static void loopInterface() {
//  System.out.println("getHash of all Slow2f() inside interface");
 setTime();
  for (int i=0;i<ITNUM;i++)
        processArray(vecsIS);
  slowITime+=fromTime();
//  System.out.println("The time taken:" + fromTime());
}
 
 private static void initVars() {
  vecsIS=new IVector2f[N][];
  vecsS=new Slow2f[N][];
  vecsIM=new IVector2f[N][];
  vecsSw=new Switch2f[N][];
  Random r=new Random();
  for (int i=0;i<N;i++){
   vecsIS[i]=new IVector2f[N];
   vecsS[i]=new Slow2f[N];
   vecsIM[i]=new IVector2f[N];
   vecsSw[i]=new Switch2f[N];
   for (int j=0;j<N;j++){
    float x=r.nextFloat();
    float y=r.nextFloat();
    vecsIS[i][j]=new Slow2f(x,y);
    vecsS[i][j]=new Slow2f(x,y);
    vecsSw[i][j]=new Switch2f(x,y);
    if (i+j%2==0)
     vecsIM[i][j]=new Slow2f(x,y);
    else
     vecsIM[i][j]=new Fast2f(x,y);
   }
  }
 }
 
 private static void processArray(IVector2f[][] a){
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++)
    sum+=a[j][i].getHash();
//  System.out.println("The sum is " + sum);
}
 
 private static void processArraySwitch(Switch2f[][] a) {
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++){
    Switch2f.fastSwitch=!Switch2f.fastSwitch;
    sum+=a[j][i].getHash();
   }
//  System.out.println("The sum is " + sum);
}
 
 private static void processArraySlow(Slow2f[][] a){
  float sum=0;
  for (int i=0;i<a.length;i++)
   for (int j=0;j<a[i].length;j++)
    sum+=a[j][i].getHash();
//  System.out.println("The sum is " + sum);
}
 
 private static void setTime(){
  lastTime=System.currentTimeMillis();
 }
 
 private static long fromTime(){
  return System.currentTimeMillis()-lastTime;
 }
 
 private static interface IVector2f{
  void set(float x,float y);
  float getHash();
 }
 
 private static class Slow2f implements IVector2f{
  float x,y;
  public Slow2f(float x,float y) {
   set(x,y);
  }
 
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   return x+y;
  }
 }
 
 private static class Switch2f implements IVector2f{
  float x,y;
  public static boolean fastSwitch;
  public Switch2f(float x,float y) {
   set(x,y);
  }
 
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   if (fastSwitch)
    return 1.0f;
   else
    return x+y;
  }
 }
 
 
 private static class Fast2f implements IVector2f{
  float x,y;
  public Fast2f(float x, float y) {
   set(x,y);
  }
   
  public void set(float x, float y) {
   this.x=x;
   this.y=y;
  }
 
  public float getHash() {
   return 1.0f;
  }
 }
}
30  Game Development / Performance Tuning / Re: 3D Interface Based System on: 2004-10-15 16:26:47
With -server option, iterating each iteration 10 times, and removing all print statements except the last 4 I get the following:

Total all Slow2f.getHash() : 3814
Total all Slow2f from IVector2f.getHash() : 8219
Total mixed slow/fast getHash() inside Interface : 7749
Total switch getHash() : 4220

-server seems to be able to switch interfaces a bit better but is still slower overall than not using an interface.  

Warming up seems to help each proportionally the same.
Pages: [1] 2 3
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (19 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!