Jump to content

  • Log In with Google      Sign In   
  • Create Account

SillyCow

Member Since 03 Sep 2008
Offline Last Active Dec 13 2014 04:19 PM

#5193523 Java - Maximum Recommended Threads At One Time ?

Posted by SillyCow on 18 November 2014 - 04:31 PM

Most answers are ignoring the word  "JAVA" in the title. Java has executors. If you want to use alot of threads, use a threadpool executor( or possibly a "stream" if you are using java 8).

 

Those are nice ways to obscure the fact that you are using threads. If you can subdivide whatever it you are doing into a bunch of short tasks, you can let the system manage how many threads you are using.

 

Since you are looking to "wait" for timers, may I suggest you use:

1. A timer thread: To push events into the executor. (don't actually run them, just schedule them to run later in the executor)

2. A threadpool executor: To execute the events.

 

Then you can play with the treadpool size. Notice that the timer thread is not bogged down, because it is not doing any real work.

 

All of these classes are supplied with Java. You don't have to write anything yourself




#5193304 Polygonzing a mesh

Posted by SillyCow on 17 November 2014 - 02:53 PM

You are right. I was a bit sloppy in my description.

1. I wrote convex, but meant concave. You can see a Concave polygon in the example set.

2. There are no floating verticies, or floating edges for that matter. (no holes are allowed either, so no islands exist)

3. There are no duplicate verticies. (I run a preprocessing step and "weld" all vertices within a threshold).

4. No two edges overlap. (I run a preprocessing step and split all overlapping edges). 

5. All of the lines in the example above, including the borders, and the diagonals that you see are created by the artist

 

So the vertices are not random with regard to the edges. They are related in that every vertex is part of an edge. And if the artist draws two colliding edges, a vertex is automatically inserted at the intersection and the edges are split along it.




#5116924 Many to one relation in an SQLite database

Posted by SillyCow on 14 December 2013 - 01:57 PM


select * from Class where Race like '%Elf%';

This has terrible performance. It is an unindexed query. This means that you are reading your entire table every time you retrieve a line.

 

If you ever want to make the "who is an elf" query, you should definetly normalize your database.




#5104892 Where can I learn software engineering, for free?

Posted by SillyCow on 27 October 2013 - 05:27 PM

How much do you already know?

Do you know the basics: MVC, etc...?




#5101648 Transfer (Trade) System?

Posted by SillyCow on 15 October 2013 - 03:31 PM

Learn about the standard library containers,

Specifically, look for a tutorial on "STL maps" to get started.

Then learn about the rest of stl.




#5100851 Trying to simulate the flamethrower from GTA2

Posted by SillyCow on 12 October 2013 - 01:30 PM

Do you mean that the near part of the flame in GTA is straighter, then the far part of the flame?

 

If so, make your flame decelerate as it get farther from your gun.

 

I will assume you are currently multiplying your flame's direction by the time elapsed.

Change it so that the more time elapsed, the farther & slower your flame should be.

 

instead of multiplying by time, multiply by some root of time.

 

Instead of: 

Position = FlameDirection * Time

Do either:

Position = FlameDirection * sqrt(Time)

or:

Position = FlameDirection * Math.pow( Time , float_number_smaller_than_one)

The smaller float_number_smaller_than_one is, the more "bending" you will have.




#5097552 space wars

Posted by SillyCow on 28 September 2013 - 11:26 PM

Switch the order of your rotate and translate.

When you want to rotate an object on it's axis, rotation should come first.

However, since openGL transforms are a stack, what happens first is what is closest to the code.

So the order of transforms of opengl is actually resversed.

 

This is kind of confusing at first, but is really logical when you need heirerchial animations (like a skeleton). It's also required because of the linear-algebra behind openGL.

 

So what you should be doing is:


void DrawShip(GLfloat position_X,GLfloat position_Y, GLfloat position_Z, GLfloat rotation,GLfloat color)
{
glPushMatrix();
glColor3f(color,0.0f,0.0f);
glTranslatef(position_X,position_Y,position_Z); //move only after the ship is rotated.
glRotatef(rotation,0.0f,0.0f,1.0f); //Now rotation will happen before movement
glBegin(GL_LINE_LOOP);glVertex3f(0.0f,-0.25f+position_Y,0.0f); glVertex3f(-0.25f,-0.5f+position_Y,0.0f); glVertex3f(-0.5f,-0.5f+position_Y,0.0f); glVertex3f(-0.0f,0.5f+position_Y,0.0f);
glVertex3f(0.5f,-0.5f+position_Y,0.0f);
glVertex3f(0.25f,-0.5f+position_Y,0.0f);
glVertex3f(0.0f,-0.25f+position_Y,0.0f);
glEnd();
glPopMatrix();
 }



#5097494 3 Questions on my mind about (winsock)

Posted by SillyCow on 28 September 2013 - 03:18 PM

1. Yes identify your clients. Usually a server has more than one game at a time. So besides "not mirroring client 1 back to itself", it's also about "not sending client 3 which is in another game" back to clients 1 and 2.

 

2. You can use asynchronous io. Look up TCP IO selector on google. It can handle many connections on a single thread. The problem is that It is more difficult then using threads, so if you only have less then 10 connections at a time, don't think about it and keep using threads.

 

3. Some people like to use UDP instead of TCP for multiplayer. It is much faster than TCP, and you can also broadcast to more than one player at a time. The problem is UDP packets can arrive out of order, so you need to re-order them. If you are using TCP, don't worry about it. TCP is basically a high level protocol over UDP that includes ordering and error handling. If you are making a realtime game, I would turn on TCP_NODELAY to prevent TCP from delaying transmission of your data. These delays can reach several 100s of milliseconds.




#5095280 Trouble getting a stable framerate (C++/Allegro 4)

Posted by SillyCow on 19 September 2013 - 04:22 PM

limit your speed to a sliding window:

1. Keep a sliding window (queue) of your last 50 frames' times (or any other number)

2. If your current frame is too far ahead of it's time: You want 50 FPS, but a second has not passed since the last 50 frames, then sleep a little bit.

3. You will also want to check the last 2 frames, to set an upper bound for speed: It is ok for the game to accelerate to compensate for missed frames, but there should be a limit on the maximum rate. If you do not do this, and you have some long frames, then your game will jitter.

 

Regardless of these points, you should separate your logic code from your render code. Your logic should never fall behind as a result of frame drawing speed. If you use a single thread it should look something like this.

while(true){
   bool wasUpdated=false;
   int targetLogicTime=CalculateTimeFromSlidingWindowAsMentionedAbove();
   while(currentTime()>targetLogicTime){
       //calculate logic:
       calculateStuff();//put all your logic code here
       wasUpdated=true;
       //limit and stabalize your FPS:
       UpdateSlidingWindowAsMentionedAbove(currentTime());
       targetLogicTime=CalculateTimeFromSlidingWindowAsMentionedAbove();
   }
   if(wasUpdated){
     drawStuff();//Draw everything here
   }else{
       sleep(1ms);//give the CPU time to rest to avoid busy waiting.
   }
}

Basically, this loop makes sure:

1. Your frame rate doesn't explode

2. If your drawing rate goes down, your game rate stays the same (car still takes 60 seconds to drive from A to B regardless of frame rate)

3. You don't draw redundant frames (frames where nothing has changed)

4. If available, you give the CPU some time to rest. (Very important for desktop CPU temperature, and laptop/phone battery life).

 

You can get better performance if you do this on two threads, but that's a whole other story.




#5092561 c++11 Multithreading not working! Please help!

Posted by SillyCow on 08 September 2013 - 05:20 PM

You have a race condition.

Thread 1 can notify thread 2  before thread 2 ever starts waiting.

So thread 2 will continue waiting forever because thread1 notified it when it wasn't waiting.

 

It is customary in these situations to wait and lock on the same mutex. That way you never miss a notification.




#5092523 Seeking Advice on Windows IDEs, Cygwin, Windows versions, et. al.

Posted by SillyCow on 08 September 2013 - 01:09 PM

Visual Studio is an Amazing C++ IDE.

By far the best C++ IDE I have encountered anywhere.

That said, getting the full experience is very expensive. (Even after you but V.S. you still need to shell out for some good plugins).

If you are a hobbyist, and are not ok with the express edition, don't use it.

 

If you are looking for alternatives, you can use Eclipse CDT or Netbeans.

Disadvantage is, they are very slow and poor in features.

Also, they were originally designed for JAVA, so some of the design seems clunky.

The advantage is they are free, and come preloaded with alot features such as refactoring.

Also, they work with several compilers: Cygwin, Ming32, etc...

 

Always use an IDE, preferably with an integrated debugger. Even when working with Linux.




#5090663 Should I learn how to draw?

Posted by SillyCow on 31 August 2013 - 02:44 PM


'images' like in real life pictures or just other peoples' drawings?

Doesn't matter. It's sort of like tracing over another picture. So it can be a photo, a sketch or anything else. The obvious advantage of drawing by yourself, is that you can get any picture you like. The obvious disatvantage is that it takes way more time then searching on google.

 

 


well if it takes just takes couple months to learn how to draw comic-book/cartoon art(assuming that I draw 2-3 hours a day and reach these results), I see no harm in learning how.

Make sure you take a course, or read a book. What a lot of people who do not draw fail to realise is that drawing is methodical. Just like you learn Loops, Methods, Data-Structures and Algorithms before you can program, you need to study drawing techniques. Just sketching on a piece of paper for a couple of months will not yield good results. It would be the same as opening an editor and writing random code smile.png .

 

I took a short course and practiced at home and it did wonders for me.

 

 

 


Then again, some don't draw pleasure from drawing I wish you luck however, it is a skill that will elude me forver, due to a lack of passion and patience for it.

 

Agreed, no amateur game-dev should draw unless it fascinates him or brings him some enjoyment. You can make excellent games without knowing how to draw. 




#5090605 Should I learn how to draw?

Posted by SillyCow on 31 August 2013 - 10:34 AM


also, Is drawing neccesarry for 3d games?

No. At the higher levels, you nead to model over a sketch. But you can download an image from the internet, and model over that.

 

 

 


should I learn how to draw too? like what if I want to test out some games, do I need artwork for it?
I mean im not trying to be michelangelo or anything, I just want to be competent enough to draw figures for game testing.

No, For testing purposes, you can use ugly art (stick figures/ 8 bit).

 

Regardless, learning how to draw is fun.

Alot of people don't try to learn it, and assume you are only born with it.

Learning how to draw decent comic-book level takes  around 1-2 months, art if you have no prior knowledge .

And you need a scanner to use your drawings in a game.

Do you have 1-2 months & a scanner?




#5087254 10 distinct ways to start a game programming (for beginners)

Posted by SillyCow on 19 August 2013 - 04:31 AM

I like to start my game protoypes as text. Since I am not an artist, I find generating sprites and models very boring and time consuming. As such the whole gfx-engine stuff doesn't saave me any grief.

 

So what I do is prototype my games as text:

http://www.youtube.com/watch?v=KLJUydLB4Z8

 

Once I figure out the game is fun, I spend time adding graphics:

https://play.google.com/store/apps/details?id=com.eyalgames.enemiesofthecrown

 

But basically I have a very playable game to prototype before I ever get started with the graphics portion.

The biggest plusses:

  • If I want a new sprite, I just add a new letter.
  • I develop on mobiles, but I can easily debug on my PC.

This can also somewhat work for an FPS style game, if you start out top view, and add camera angles later.




#5082046 Non-random evasion in turn-based games?

Posted by SillyCow on 31 July 2013 - 04:05 PM

A game I played had a defend mechansim where a character could defend instead of attacking. This would skip your chance to attack, but would reduce the damage done to said character. This was especially interesting when battling ranged units.

 

Technically this isn't evasion, but it's a similar concept.






PARTNERS