Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (582)
Games in Android Showcase (163)
games submitted by our members
Games in WIP (633)
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 ... 68
1  Game Development / Networking & Multiplayer / Re: Handling both UDP and TCP input. Multithreading? on: 2015-05-24 09:39:33
Don't use blocking IO; use non-blocking Channels along with a Selector.
It should be just as simple to just use a thread-per-client model with blocking IO... you might want to give your reasons for the advice.

Cas Smiley

My suggestion was responding to this request by the OP.

Quote
The simplest solution would be to split the packet-input thread into a TCP-input and UDP-input thread, but I'd want to avoid this if possible.

If he doesn't want blocking, and doesn't want lots of threads, non-blocking Channels accessed through a Selector is the logical suggestion.
2  Game Development / Newbie & Debugging Questions / Re: Ok to assume Instrumentation#retransformClasses(Class....) is synchronous? on: 2015-05-17 18:30:29
A 'massive' increase in bytecode footprint sounds like a misnomer. It's doubling a number that's typically tiny compared to the application. There is also no need to keep it all in memory. Once the class has been transformed, you can remove it from your collection of bytecodes that are loaded-but-not-redefined yet. With this approach it would be surprising to have more than a dozen 'pending' classes at a time in memory, on even the worst behaving VMs. So either way it seems trvial to support this - were reduction of memory footprint seems just as trivial, yet highly likely premature optimisation.

For my use case the transformed bytecode needs to be kept around so that future instrumentations have access to it (i.e. they may need to interrogate the instrumented classes as part of their own transformations [Especially relevant due to Javassist's tendency to check the validity of every type referenced in code fragments that it compiles]).

You're right though, doubling the memory footprint of the code is probably not that enormous.... though when it includes every class that the application touches within every library dependency too? (including the Java standard libraries!)
I can see that adding up to at least a few dozen MB's.

Atm the discussion is moot though, as I've encountered a bug relating to this very piece of code.... seems I've misunderstood precisely what retransform does.

:edit:

I thought the byte[] returned by transform(....) overwrote the VM's internal classfileBuffer.
Apparently it doesn't, it must be stored somewhere else alongside it.
So when retransformClasses(class) is called, the 2nd invocation of transform(....) is passed the *original* classfileBuffer. (not the transformed one that had been returned by the previous call to transform(....)).

So looks like I need to keep a copy of all transformed classes anyway, as this information cannot be read back from the VM.
3  Game Development / Newbie & Debugging Questions / Re: Ok to assume Instrumentation#retransformClasses(Class....) is synchronous? on: 2015-05-17 15:59:45
The alternative to this approach would be to store every "classfileBuffer" passed into transform(.....).
However I'm loath to take this approach, because it *might* result in a massive increase memory usage.  (potentially doubling the memory footprint of the program's bytecode)
4  Game Development / Newbie & Debugging Questions / Ok to assume Instrumentation#retransformClasses(Class....) is synchronous? on: 2015-05-17 13:36:02
I'm using this method to read back the byte[] representation of loaded classes.
(for read-only instrumentation requirements, not to actually modify)

The reason I need the in-memory representations (rather than simply grabbing them from the classpath) is 2-fold:
1) some of them will have already been instrumented
2) some of them are defined at run-time, so do not exist in the classpath.

However the javadoc on the method is rather lacking on implementation details.
The Oracle VM certainly executes it synchronously, which means this, while conceptually horrible, works fine:

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  
   private byte[] classBytes;

   /**
    * Reads back from the JVM the byte[] representation of an already loaded class
    *
    * @param className
    *            The name of the class to read back.
    * @param cl
    *            The class loader used to load the class.
    * @return
    */

   synchronized byte[] getClassBytes(String className, ClassLoader cl) {
      try {
         // trigger a retransformation (that will store the class's bytes in
         // classBytes[]
         inst.retransformClasses(cl.loadClass(className));
         byte[] classBytes = this.classBytes;
         this.classBytes = null;
         return classBytes;
      } catch (ClassNotFoundException | UnmodifiableClassException e) {
         throw new RuntimeException("Failed reading back class bytes from the JVM", e);
      }
   }

   @Override
   public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

      if (classBeingRedefined != null) {
         // this will only be reachable immediately after an invocation of
         // getClassBytes.
         // fingers crossed all implementations execute this synchronously.
         // Oracle's VM certainly does, but the method that causes the call
         // (Instrumentation#retransformClasses)
         // is not very explicit on exactly how it's implemented.
         System.out.println("byte[] read-back for " + className);
         classBytes = classfileBuffer.clone();
         return null;
      }
               //<snip>
   }
5  Game Development / Newbie & Debugging Questions / Re: Creating an instance of an object in Array List supplied by another ArrayList? on: 2015-05-14 08:45:11
I'd advise not getting bogged down with generics.

They're a huge jump in complexity with very little added value; a terrible concept for new developers to waste their time understanding.

Turn off your ide's warnings and avoid using them until you've mastered every other aspect of Java.
6  Discussions / Miscellaneous Topics / Re: Most unusual/weird syntax features in non-joke languages on: 2015-05-11 13:51:05
int [] a [];

17 years of Java, and I still had to check if that was actually valid syntax.
7  Game Development / Networking & Multiplayer / Re: Handling both UDP and TCP input. Multithreading? on: 2015-05-10 10:20:13
Don't use blocking IO; use non-blocking Channels along with a Selector.
8  Game Development / Newbie & Debugging Questions / Re: how to fit a body to a sprite avoiding transparent space? on: 2015-04-10 22:27:46
i mean to remove that part manually with an image editor software, what i´m looking for is a way to do it with code

So you want to crop an Image according to the sprite's minimum bounds?

- Iterate over the source image's pixels, recording the coordinates of the left-most, top-most, right-most & bottom-most non-transparent pixels.
- create a new image, sized according to these coordinates and copy over the source image, offset according to the left/top coords.
9  Discussions / General Discussions / Re: Methods of decompiled classes on: 2015-04-09 15:34:29
Perhaps something to do with the way the Server de/serializes instances of the world?
10  Discussions / General Discussions / Re: Does Internet cost matter to you? on: 2015-04-05 23:00:44
Tell me if I get something wrong here,
but no matter how much your computer compresses the data it recieves, it only recieves the entire file and compresses it clientside then, but doesn't decrease the amount of data recieved at all unless you also make the server use the compression method and send the compressed data...
The same goes for your upload, if you compress it clientside, the server will simply not be able to use this data, unless it knows how it has been compressed.

So how exactly do you, leaving the asked question apart, even plan to do this?

Typical approach is to have a server on the Internet backbone, acting as a proxy & doing all the compression of downstream (and decompression of upstream, where applicable).

Examples: Chrome's DCP, Mozilla's Janus, Opera's Turbo.
It's really only of meaningful applicability in the bandwidth constrained world of mobile internet, and even that is rapidly contracting.
11  Discussions / General Discussions / Re: Does Internet cost matter to you? on: 2015-04-05 16:19:01
PPP already offers compression though? (CCP)
If any given ISP wants to reduce bandwidth at the expense of latency and processing cost they're free to use it?

The end user shouldn't worry themselves with such issues; they're solely a concern of the network provider.
12  Discussions / Miscellaneous Topics / Re: Crash - Corrupt File, Months of Work Lost on: 2015-03-20 19:21:39
Are you sure the filesystem doesn't have a previous version of the file?

If the file has been on your harddrive for more than 24 hours, there should be a backup.
13  Discussions / General Discussions / Re: Java and GPU's on: 2015-03-14 22:02:17
1  
2  
3  
4  
5  
   public final Font Charfont = new Font("Impact", Font.BOLD, 30);
        ...
   og.setFont( Charfont );
   og.drawRect( x,y+10,120,40 );
   og.drawString("Set up", x+26, y + 40 );

Use FontMetrics to position text.
14  Games Center / nK Game Competition - 2015 / Re: Java4K framework WIP / discussion on: 2015-02-26 17:17:41
I realize it's against the principle of the contest, but I guess there's nothing to stop participants from String-encoding compiled code - essentially turning it into a "16KiB minus encoding & instanciation overhead" contest.
15  Game Development / Newbie & Debugging Questions / Re: LibGDX:How to create Key Value pairing holding info for different datatypes on: 2015-02-25 14:01:52
Use json:

<snip>

The implementation of getting data from json objects will differ from json lib to json lib.

Yeah, though I'd prefer a json lib to automatically instantiate & populate Java objects (using reflection).
If you're doing it properly, it should also have schema definition support. (though that seems a little beyond the scope of this thread)
16  Discussions / Miscellaneous Topics / Re: Bit pissed off at uk school system... on: 2015-02-10 18:59:30
Completely reasonable IMO.

Students are minors in the care of the school; the school has a duty of care towards the other students & staff.
If searching students is necessary to execute that duty of care, all power to them.
17  Game Development / Newbie & Debugging Questions / Re: Null pointer where there should not be one...at all on: 2015-02-05 19:23:34
Rather than trying to solve the problem for you, I think it'd be more productive to explain how to solve the problem yourself.

Use a debugger.

If you run your code in Eclipse (or any other IDE), with the debugger attached, execution will halt as soon as an uncaught exception is thrown & you'll be able to inspect the state of every relevant variable in your program.

Terminal exceptions like this should be trivial to fix if you're programming with the correct tools & work process.
18  Game Development / Shared Code / Re: Sortable Map on: 2015-01-18 00:44:24
I think you'd be wanting Treemap.
19  Discussions / General Discussions / Re: How do you feel about selling out? on: 2014-12-28 02:40:03
IMO the sell outs are the consumers who buy into franchises, not the individuals who sell the franchises to mega-corps.

Judging products based upon their brand, rather than individual merit is a betrayal of the system & the greatest cancer of the games industry.

Without these lazy & ignorant consumers, the Minecraft IP would be nowhere near as valuable to Microsoft's milking department.
20  Discussions / General Discussions / Re: Lockable variables on: 2014-12-20 00:07:16
For global constants

That's your problem right there.
21  Game Development / Newbie & Debugging Questions / Re: Trouble making circular boundaries for 2D game on: 2014-11-10 22:47:00
Can't you just use the distance formula?

1  
2  
3  
4  
double distanceFromCircle = Math.sqrt( (player.x-circle.x)*(player.x-circle.x) + (player.y-circle.y)*(player.y-circle.y) );
if(distanceFromCircle < circle.radius){
   //ship is inside radius of circle
}


Where possible, always compare the squares.
22  Java Game APIs & Engines / Java 2D / Re: Fast 2D hardware scaling of images (without GL?) on: 2014-11-01 08:02:30
Try using BufferStrategy.
Also stick some delays around switching into FSEM, as its interaction with the rest of the J2D API is prone to race conditions. (Even when it's all executing on the EDT)

It's a terribly unstable and unreliable API.

Also, spinning on Component.repaint() is terribly wasteful(flooding the EDT's EventQueue with repaint events) and is not guaranteed to achieve what you want it to.
23  Discussions / Miscellaneous Topics / Re: Draw a point or a dot. on: 2014-10-31 16:50:02
From what I recall, drawLine(x,y,x,y) is the preferred way of drawing just a single pixel through the general purpose rendering pipeline.
Obviously if you're doing a lot of individual pixels, then you should bypass the pipeline, and manipulate an Image's Raster directly
24  Discussions / General Discussions / Re: Paint program that allows full rotation? on: 2014-10-14 01:11:14
Hope you're not pre-rotating sprites persecutioncomplex

Nope Cool, I could draw the text in Java2D than rotate it, but I'd like to pre-rotate the text and save it in the .png VS. programmatically rotating the text to the desired angle every frame.
Quote

So rotate the text once, and draw it into an Image?

Embedding text in graphic resources is a bad habit that should be avoided whenever possible; makes localisation a lot more difficult.
Probably not a concern for your project, just something to keep in mind going forwards.
25  Discussions / General Discussions / Re: Paint program that allows full rotation? on: 2014-10-13 10:30:38
Hope you're not pre-rotating sprites persecutioncomplex
26  Game Development / Networking & Multiplayer / Re: Using UDP and TCP? on: 2014-10-12 12:45:45
UDP & TCP serve different purposes; if you have needs that are fulfilled by using both, then it's absolutely right to use both.

If it's any reassurance, there are lots of AAA games that use.
27  Discussions / Miscellaneous Topics / Re: Name that Poker hand - Tiny Code Challenge on: 2014-10-09 20:31:32
If they were using an older version of Java (circa Java 1.5), you'd be able to completely destroy the Java FizzBuzz highscore with this:

1  
class S{static{for(int i=0;i<100;)System.out.println((++i%3<1?"Fizz":"")+(i%5>0?i%3>0?i:"":"Buzz"));}}


Back then the static initializer would execute before the main thread threw the "No Main method" error.
As that error is delivered to stderr, not stdout, it'd still fulfill the competition's requirements.

Alas, not to be.
28  Discussions / Miscellaneous Topics / Re: Name that Poker hand - Tiny Code Challenge on: 2014-10-09 20:14:39
For fizzbuzz? No, because the method declaration would be too large. It's such a tiny challenge there is no room for any fanciness.
The only one I used a recursive solution for was the sudoku solver.

Nah, for the Tiny Poker challenge.

Tbh I hadn't given it much thought, just emphasizing that micro-optimisation can only get you so far - an algorithmic change might give much more significant gains.
Though if the algorithm doesn't benefit from a virtually free & unbounded stack, it's unlikely recursion will offer a more efficient solution.

I did wonder if Java 8's lambda syntax might be able to give significant gains ( e.g. "myList.forEach(System.out::println)"), unfortunately the package locations of even the most basic class requirement (java.util.Arrays) sinks that idea pretty quickly.
29  Discussions / Miscellaneous Topics / Re: Name that Poker hand - Tiny Code Challenge on: 2014-10-09 14:41:45
I wonder if a recursive solution might be smaller.
30  Discussions / Miscellaneous Topics / Re: Is drinking half a bottle of vodka safe? on: 2014-10-09 14:32:24
Without your 'friend' noticing, replace the vodka with another clear colourless liquid and you're good to go! (so long as the replacement isn't Petrol....)
Pages: [1] 2 3 ... 68
 
Gibbo3771 (8 views)
2015-05-29 06:54:17

Ralphanese (20 views)
2015-05-28 16:52:52

theagentd (31 views)
2015-05-27 22:21:17

theagentd (35 views)
2015-05-27 22:21:08

CopyableCougar4 (25 views)
2015-05-27 19:24:50

MrMapcom (24 views)
2015-05-23 20:26:16

MrMapcom (32 views)
2015-05-23 20:23:34

Waterwolf (37 views)
2015-05-20 15:01:45

chrislo27 (44 views)
2015-05-20 03:42:21

BurntPizza (79 views)
2015-05-10 15:53:18
Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02
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!