Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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 ... 6
1  Game Development / Newbie & Debugging Questions / Re: Scanner works in "spurts" when piping on: 2014-02-10 00:39:54
Doesn't that seem unnecessarily complicated? My program should also be reading the data continuously, at the same pace that data is being written to the command line. Is there a way to use the buffer without writing it to a file?
2  Game Development / Newbie & Debugging Questions / Scanner works in "spurts" when piping on: 2014-02-09 23:14:45
I'm making a project where I'm taking in data from another program via the command line

If my JAR is called "project.jar", and the data-maker program is called "program" I am taking in data like this:

1  
program | java -jar project.jar


When I did this, I noticed that there was a significant amount of lag in my program. Not in the framerate at all, but rather in the rate at which the lines generated by "program" were fed into "project.jar" at an inconsistent rate. To see if this was a problem with "project.jar", I made a new JAR which is literally this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
import java.util.Scanner;

public class Printer {
   
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      while(true){
         System.out.println(sc.nextLine());
      }
   }

}


Now, "program" generates data very quickly, maybe 10 lines a second. But when I set up
1  
program | java -jar printer.jar


then THIS prints out data in the same spurts! There would be 3 or 4 seconds before a massive chunk of lines would be printed out. Why should this happen? If I pipe "program" into "printer", I should see it printing everything out continuously at the same rate "program" does.

Is this a problem with piping, or with the Scanner class, or what? How can I fix this so Scanner reads things more continuously?

Thanks
3  Game Development / Newbie & Debugging Questions / Re: "Unclosed character class near index 0" ? on: 2014-01-19 22:01:49
str.split("\\]")


That's very weird. I did not know about that. Now it works though!
4  Game Development / Newbie & Debugging Questions / Re: "Unclosed character class near index 0" ? on: 2014-01-19 21:55:31
I don't know anything about regex, I'm not gonna lie. But I was under the impression that "split" just returned an array of strings, cutting up your string using the argument as a divider

for example,

"A,B,C,D,E".split(",") = {"A", "B", "C", "D", "E"}

And that is actually true

If this ISN'T always the case, then how can I get the behavior I'm looking for?
5  Game Development / Newbie & Debugging Questions / "Unclosed character class near index 0" ? [solved] on: 2014-01-19 21:46:40
Long story short, I'm making a class to read text files in a specific way. I'm storing a lot of information about my game (including enemy stats) in text files that I read in and parse appropriately. I am not writing that class, and getting a very biazzare error.

My centralized "parsing" involves taking a string and making two String[] arrays, one that contains everything in square brackets, and one that contains everything outside of square brackets.

For example, this string
1  
2  
3  
4  
5  
6  
7  
8  
NAME: [NAME]
FILE: [FILE]
TYPE: [TYPE1] [TYPE2]
COLOR: [COLOR]
HP: [HP]
PWR: [PWR]
DEF: [DEF]
SPD: [SPD]


Should be parsed, via the method "splitInBrackets" into:
1  
[NAME, FILE, TYPE1, TYPE2, COLOR, HP, PWR, DEF, SD]


Now, when I pass that exact string into my method, I get this error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Caused by: java.util.regex.PatternSyntaxException: Unclosed character class near index 0
[
^
   at java.util.regex.Pattern.error(Unknown Source)
   at java.util.regex.Pattern.clazz(Unknown Source)
   at java.util.regex.Pattern.sequence(Unknown Source)
   at java.util.regex.Pattern.expr(Unknown Source)
   at java.util.regex.Pattern.compile(Unknown Source)
   at java.util.regex.Pattern.<init>(Unknown Source)
   at java.util.regex.Pattern.compile(Unknown Source)
   at java.lang.String.split(Unknown Source)
   at java.lang.String.split(Unknown Source)


at the line that says "String[] comp = ref.split("[");"

Why is this happening? (Method code below)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
private String[] splitInBrackets(String ref){
      System.out.println(ref);
      String[] comp = ref.split("[");
      //split
     //NAME: [NAME] AGE: [AGE]
     //into
     //|NAME: |NAME] AGE: |AGE]
     //then for each component splits it further to get out the parts in the [ ]
     
      //will throw out of bounds exception if weird stuff isn't formatted with the brackets
     for(int i = 1; i < comp.length; i++){
         String[] dcomp = comp[i].split("]");
         comp[i] = dcomp[0];
      }
     
      return comp;
   }
6  Game Development / Newbie & Debugging Questions / Re: Limits of drawing BufferedImages? on: 2014-01-10 02:25:50
Also make sure you are not using getRGB, setRGB, getDataBuffer or anything like that, those calls will cause Java2D to unaccelerate the image.

I use those calls to load some BufferedImage instances initially, but I only do these things once at the start and not every frame. I've made my game so all images are in on a grayscale and "colorized" by taking the RGB array using getRGB from image files, doing some math on all the pixels, and then making a new BufferedImage using setRGB
7  Game Development / Newbie & Debugging Questions / Limits of drawing BufferedImages? on: 2014-01-09 18:53:49
I am making a game with pure java, drawing BufferedImage objects to a Graphics2D object.

My game has a simple rendering system, namely it just draws a bunch of tiles.

However, I have found that when I draw too many images onto the screen in one frame (name 1/60th of a second), this number being around 1000, my fps drops to around 30.

Is there a better way to do this? How can I draw images faster?
8  Game Development / Newbie & Debugging Questions / Re: Brighten RGB color? on: 2014-01-03 09:10:29
That first article was very good! Using it, I made my own class that can brighten colors in the way I wanted.

I will post it here in case someone else in the future is trying to do the same thing.

I tested it and it works Smiley

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  
import java.awt.Color;

public class ColorOperator {
   
   //colorInt should be a standard rgb hex value, like 0xffffff
  //light  should be a number from 0 to 255, 0 being black, 255 being white
  //returns a hex rgb int at the appropriate brightness level
  public static int setColorBrightness(int colorInt, int light){
      int r = ( colorInt >> 16 ) & 0xff;
      int g = ( colorInt >> 8 ) & 0xff;
      int b = ( colorInt ) & 0xff;

      float[] hsb = Color.RGBtoHSB(r, g, b, null);
      float[] hsl = HSBtoHSL(hsb);
      hsl[2] = light / 255f;
      hsb = HSLtoHSB(hsl);
           
      return Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]) & 0xffffff;
   }
   
   public static float[] HSBtoHSL(float[] hsb){
      float[] hsl = new float[3];
     
      float l = (2 - hsb[1]) * hsb[2] / 2;
      float d = (l < .5f ? l * 2 : 2f - l * 2);
     
      hsl[0] = hsb[0];
      hsl[1] = d == 0 ? 0 : hsb[1] * hsb[2] / d;
      hsl[2] = l;
     
      return hsl;
   }
   
   public static float[] HSLtoHSB(float[] hsl){
      float[] hsb = new float[3];
     
      float b = hsl[2] + hsl[1] * (hsl[2] < .5f ? hsl[2] * 2 : 2 - hsl[2] * 2) / 2;
     
      hsb[0] = hsl[0];
      hsb[1] = b == 0 ? 0 : 2 * (1 - hsl[2] / b);
      hsb[2] = b;
     
      return hsb;
   }

}
9  Game Development / Newbie & Debugging Questions / Re: Brighten RGB color? on: 2014-01-02 07:06:56
Ahhh, I thought HSB was the same as HSL, but it is actually the same as HSV. So that makes more sense. If anyone knows of a way to convert from HSB to HSL, I'd be appreciate it.
10  Game Development / Newbie & Debugging Questions / Brighten RGB color? [solved] on: 2014-01-02 05:12:03
I thought I'd be able to find an answer to this, but it's turned out to be harder than I thought.

In MS paint, there's a color editor tool that lets you brighten colors


My question is, what is the math behind that color brightening tool, rgb wise?

I thought that if I took a color, and converted the brightness in the "HSB" color model presented by the Color class, I would get an identical effect. However, this isn't quite what I was looking for. For example, it's impossible for me to brighten purple all the way up to white. It merely becomes a very bright purple. Using the Color class "brighten" and "darken" methods produce the same result.

So, simply put, how, numerically, can I implement a method that brightens or darkens a color by an amount that produces an effect identical to that in the picture?

Thanks
11  Game Development / Newbie & Debugging Questions / Re: JFrame dimensions? on: 2013-12-31 04:40:12
So how could I get the width and height using the aforementioned frame.getWidth() and the "getInset()" method, because the only variables I see from the Inset are top, bottom, right, and left, and I don't quite see how to use that information. I don't quite understand what to add and subtract.

Thanks
12  Game Development / Newbie & Debugging Questions / JFrame dimensions? on: 2013-12-31 03:46:30
I want my next game to have a re sizable window (no external libraries used)

How do I get the size of the interior of the JFrame?
What I mean is, I can get the total width/height of the JFrame "frame" via "frame.getWidth()"

The problem is that I set the size of the frame to be 640 x 480, but when I get the dimensions via the method above, I get 646 x 509.

I can only imagine that the numbers get bigger because of the size of the border of the window.

But I don't want those dimensions, I want the dimensions of what I'm actually drawing on.

I know I could just subtract 6 and 29, but that won't work for every OS.

So how can I get the dimensions I'm looking for?

Thanks.
13  Game Development / Newbie & Debugging Questions / Piping into a JAR [solved] on: 2013-12-12 12:27:15
I have jar called thing.jar
It continuously receives output from the console
So when I run

1  
java -jar thing.jar

and then start typing away at the keyboard, everything I type is received by the scanner in thing.jar

Now I have a little class file, FakeInput, such that when I run

1  
java FakeInput

It just creates a whole lotta random output, printing it onto the console (with a 10 millisecond delay between each print) until I press ctrl-c and tell it to stop.

I want to pipe the OUTPUT from FakeInput into the INPUT of thing.jar

So why doesn't these lines work?

1  
2  
java FakeInput | java -jar thing.jar
java -jar thing.jar < java FakeInput

Some weird errors happen instead, the gui window for thing.jar freezes, but shouldn't there be a way to run them at the same time?

How can I do what I want?
Thank you.

EDIT: I SOLVED THE PROBLEM. For anyone reading the thread in the future,
1  
java FakeInput | java -jar thing.jar

Totally works. The only problem is that a 10 millisecond delay was much to short. I changed it to 100 milliseconds and it works.
Thanks.
14  Game Development / Newbie & Debugging Questions / Re: Compiling and running a LWJGL Project on: 2013-12-12 12:24:00
You are a saint! Thank you so much!

For those of you who read this later, do what he said and put your natives in the folder "Windows" (for example) which is in the folder "nat" which is in the same folder as your JAR
15  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 11:31:35
Ok, It's asking me for parameters, but I don't understand where exactly to put them
Should I run it like this (if my jar is named Game.jar and I had eclipse export the libraries into the folder Game_lib

java -jar FatJar -lib Game_lib -main package.Main -output FatGame.jar

Where do I even specify to use Game.jar?
16  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 05:01:56
Ok cool, but how do I use it? What parameters does it take?
17  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 04:03:46
The first time I ran it there was an error in the console (if I remember correctly) but I ran it again, and while there was no error, no window opened either.
18  Game Development / Newbie & Debugging Questions / Compiling and running a LWJGL Project [solved] on: 2013-12-12 03:24:34
Very simply, how can this be done?
I do not mind if I have to write a complicated batch file.
I have been trying to do this for a while and it is very confusing. For example, how can I edit a manifest file in eclipse? What exactly do I have to do?

I can't use JarSplice in it's current state because it won't let me take input from the command line.

I am using 3 Jars in my library: lwjgl_util.jar, lwjgl.jar, slick.jar

How exactly can I run my project outside of my IDE in cmd?

Thanks!
19  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 03:20:07
I get an error when I run it.
20  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 15:05:45
The problem here has nothing to do with your code at all. It is JarSplice's fault. When running the JAR that is spit out by JarSplice, you are actually running its launcher, which, now that I look at the code, does not forward its stdin stream to your program. I'll talk to kappa about fixing this bug.

Ah yes! Why didn't I think of that? Previously, before I moved my project to LWJGL, I had no reason to use Jarsplice, so I didn't. I didn't even imagine that Jarsplice would be the source of this problem. Thanks for pointing this out, I'll now work on finding a way to launch my project without Jarsplice...
21  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 04:36:50
Ok, let me explain how this project is used.

That's exactly right, this project is accepting lines from the scanner on an infinite loop, updating things in the program according to structured strings put into the console.

The actual use of this is to read data from a microsoft kinect. Once again, this is only a pet project, so I didn't want to get bogged down in confusing libraries.

I found a program online that outputs data from the kinect into lines on the command prompt. So for example, if two people are walking around a room, the output can look like this, where a new line is written every fraction of a second or so:

1  
2  
3  
4  
5  
6  
7  
8  
user 1: head at (444, 444, 444)
user 2: head at (1001, 1000, 1000)
user 1: head at (444, 445, 444)
user 2: head at (1002, 1000, 1000)
user 1: head at (444, 446, 444)
user 2: head at (1003, 1000, 1000)
user 1: head at (444, 447, 444)
user 2: head at (1004, 1000, 1000)


By piping this data into my Jar in the command line, I can very easily pipe all this data into my program.
For example, I can do this like this in the command line:
1  
NISimpleSkeleton.exe | java -jar project.jar

where NISimpleSkeleton.exe is the program that outputs the data from the kinect into the command line. My JAR reads this data in real time and updates the program accordingly.

This method of organization works very well. The only problems came from when I changed the "engine" of this project to the LWJGL, at which point it stopped working for the simple reason that it stopped being able to accept the data from the command line.

That is how I am using the scanner, I hope that brings light to the issue.
22  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 04:16:45
I don't quite see how that will help.
Here is my class that reads in the input, for reference. It runs in it's own Thread parallel to two other threads in my program:

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  
import java.util.Scanner;

public class Reader implements Runnable {

   Scanner sc = new Scanner(System.in);
   
   public Reader(){}
   
   public void run() {
      while(AudioRunner.keepGoing){
         String input = sc.nextLine();

         AudioRunner.pause();
         while(!AudioRunner.hasStopped){
            sleep(10);
         }

         Person.updatePeople(input);
         
         AudioRunner.resume();
      }
   }
   
   private void sleep(int time){
      try {
         Thread.sleep(time);
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

}


The "updatePeople()" method does many operations on the received String. Here is what that method looks like:

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  
public static void updatePeople(String input){
      Feed.nextLine(input);
     
      if(input.length() < 10 || !input.substring(0, 5).equals("user "))
         return;

      input = input.replace("user ", "");
      char numChar = input.charAt(0);
      int numPerson = Integer.parseInt(numChar+"");
     
      while(numPerson > numberOfPeople)
         new Person();

      people.get(numPerson-1).updatePerson(input);
   }

public void updatePerson(String input){
      if(input.charAt(0) != '('){
         updatePerson(input.substring(1));
         return;
      }
     
      input = input.substring(1,input.length()-1);
      input = input.replaceAll(" ", "");
     
      String[] coordsString = input.split(",");
      double[] coords = new double[3];
      for(int i = 0; i < 3; i++)
         coords[i] = Double.parseDouble(coordsString[i]);
     
      //left is more negative x
     setLocation(coords[0], coords[1], coords[2]);
   }


This code isn't meant to be understandable for anyone but me, really, because this is a pet project. The point is that I'm doing many operations on many received strings, and I am splitting them using ',' for the purposes of parsing strings into useful data. This works fine when I'm not using the LWJGL
23  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 03:52:59
I am 99% sure this is a problem relating to input and not something else. My previous project that takes in console input in and identical way (through the Scanner) acts as expected. The program in question (along with that OpenAL demo I linked to) will not accept console input.

The thing is that when I type things into the console I AM using new lines. If I type in multiple commands (separated by new lines) then each "command" is parroted back out to me separately when the program ends.

So how can I configure everything so things are accepted into the scanner with each new line?

Thanks so much!
24  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 02:19:41
Using JarSplice I have been able to make everything work as I would hope. As I need to put input into my program using the command prompt, I don't need to be able to click the icon to make it run, but rather use the command "java -jar program.jar"

So if I were to transfer my project to NetBeans (which could take a while) what would you suggest I look into so that the Jar will properly take in things from the console? I don't see much written about this subject currently and I'm not sure how to proceed.

Thanks
25  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 01:52:14
For example, the program found here ( http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source ) works fine in eclipse, but the moment you take it to command prompt as a fatjar, it refuses to take any input from the user.
26  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? on: 2013-11-27 23:14:22
When the program ends, all of the commands typed into the console while the program was running become visible, along with an error message. It looks like this:

>[command]
'[command]' is not recognized as an internal or external command, operable program, or batch file.
27  Game Development / Newbie & Debugging Questions / Does LWJGL affect input from the command line? [unsolved] on: 2013-11-27 22:47:13
I'm making a project that takes in data from the command line using the Scanner in the typical way. I am usually able to pipe from a text file or another device.

I switched out a lot of the code in the project to run with the LWJGL. In eclipse it works fine and the program reads things typed in the console. However, when I run it from the command line as a fat jar (using "java -jar project.jar") it does not receive and data piped into it or typed in the command line.

Does this have something to do with the structure of LWJGL displays or something similar? How can I successfully pipe data into my Jar?

Thanks
28  Game Development / Newbie & Debugging Questions / Re: Loading textures without FileInputStream? on: 2013-11-12 05:17:18
In a bout of laziness and desperation, I broke my own rule and posted a forum question before fully researching the topic
Turns out I can just use this line instead of my other line:

1  
         tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(directory));


The end
29  Game Development / Newbie & Debugging Questions / Loading textures without FileInputStream? on: 2013-11-12 05:08:19
I am trying to make a runnable jar of my project made in LWJGL. It works fine in Eclipse. I used JarSplice to make a FatJar, however it closed instantly upon running. The console, as well as some research http://stackoverflow.com/questions/12116151/fat-jar-instantly-closes , tells me it is a problem with my use of the FileInputStream.

Here is what my texture loading looks like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

public class ResLoader {
   
   public static Texture loadTexture(String directory){
      Texture tex = null;
      try {
         tex = TextureLoader.getTexture("PNG", new FileInputStream(new File(directory)), GL11.GL_NEAREST);
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return tex;
   }
   
}


How can I rewrite this without use of the FileInputStream?

Thank you
30  Game Development / Newbie & Debugging Questions / Re: How can one draw text? on: 2013-11-11 08:10:36
Excellent, thank you! This was a very confusing block of code.
Pages: [1] 2 3 ... 6
 

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 (75 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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
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!