Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
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 ... 72
1  Java Game APIs & Engines / Java 2D / Re: How to have BufferedImages take up less RAM on: 2017-12-08 06:57:00
Maybe I'm confused, but I recall that Java automatically caches a VolatileImage copy of a BufferedImage somewhere if you draw that image a lot, meaning that it is in fact best to use BufferedImages for your regular textures.

Essentially yes, VolatileImages are generally only of relevance for the target of a draw, not a source.
Typically of use if you're doing some fancy compositing, or buffering.

If all you're doing is drawing images, stay well clear of them.
2  Java Game APIs & Engines / Java 2D / Re: How to have BufferedImages take up less RAM on: 2017-12-05 21:47:57
- Java is an OO language, thus the term for a unit of code is 'method' not 'function'.
- Not wishing to reload the images is not a good reason to make them static.
As your program develops, the scope of your resources is likely to change; encapsulating the resources within instanced objects makes refactoring your code to accommodate such changes easier.
The typical example of this would be where your design transitions from:
a) having a single level, where all resources are held in memory at once
b) to multiple levels, where intermediary loading screens are presented to the user.
c) to, perhaps, an infinite world where resources are streamed into memory in the background as the user navigates the world.

- Images returned from ImageIO have been eligible for hardware acceleration for many years; there's no need to copy them to a new image.

As to your question:

1) Increase heap size; seems obvious, but you haven't stated whether you've tried this.
2) Don't keep everything loaded at once. As suggested above, levels + load screens, or background streaming.

It's also worth keeping in mind that every Image in the heap also occupies VRAM for its cached copy used by the h/w accelerated pipeline.
Depending upon the h/w rendering pipeline being used by Java2D (which will vary by platform, and cmdline flags), you might be wasting large amounts of VRAM because Java2D is creating power-of-2 textures that poorly fit the dimensions of your Image.
While this inefficiency won't increase your heap usage, it might significantly increase vram usage - perhaps to the point where it negatively impacts performance.
The solution here is to adopt sprite sheets, along with the associated tooling to generate them, and code to draw them.
3  Discussions / General Discussions / Re: would any of you guys be offended if on: 2017-12-01 21:10:08
Treat all religions/religious figures with equal contempt, and you'll be fine.
4  Game Development / Performance Tuning / Re: Optimal 2D rendering. on: 2017-10-18 11:53:12
For drawing a single pixel onto an accelerated surface, drawLine is faster than fillRect.

However if per pixel stuff is *all* the drawing you're doing, then do it on an unaccelerated surface direct to the image's backing int [] (exposed via DataBufferInt.getData() )

Though without hardware acceleration it's still going to be comparatively very slow; if you want to do stuff at the per pixel level, don't use Java2D.

You might be able to achieve a similar lighting effect while keeping your surfaces accelerated, but you're constrained to the composition rules defined in AlphaComposite. (The useful ones being dst_in for overlaying shadow, and src_over for applying colour). There are tutorials around on how to do this.
Though without a means of doing additive blending, you'll eventually hit a wall in what you can achieve.

Frustratingly JavaFX offers several useful (and hardware accelerated) blend modes not available in Java2D(including additive blending), but hides them behind a fundamentally flawed API design rendering them useless for the common use case.
5  Java Game APIs & Engines / JavaFX / Re: Off screen rendering, drawing images onto themselves and other shenanigans on: 2017-09-19 10:40:06
What you're missing is LWJGL.

Cas Smiley

Quite, but within the scope of the question?  Kiss

:edit:

Another limitation that's fairly prominent:
if I want to procedurally generate an image (GraphicsContext onto a Canvas seems the only way?), then reuse said generated image multiple places in the scene graph, then I must snapshot it into a WriteableImage?

It makes sense that there's no way of having multiple Canvases in the scene graph share an underlying surface, as that'd break the scene compositing process.

However snapshotting requires the creation of multiple extraneous objects, and significant memory copying; it's slow.
Does the JavaFX API really have no performant way of accomplishing this very basic functionality?!?!

Java2D might have been a terribly API, but at least it was reasonably performant & logical once you got around its over-engineered abstraction, and knew what was actually happening under the hood.

It's maddening that all that seems to be requires is:

WriteableImage.getGraphicsContext()

You'd then be able to leverage JavaFX's more feature-rich graphics pipeline, without being burdened by the limitations of the scene graph.
I've not been so thoroughly confounded by such a fundamentally flawed API design since I did MIDP development a decade ago.
6  Java Game APIs & Engines / JavaFX / Off screen rendering, drawing images onto themselves and other shenanigans on: 2017-09-19 08:53:38
I've been enticed by the additional blend modes available in JavaFX to have a little dabble with the API.
However doing low level stuff seems incredibly clumsy?

Am I correct in thinking that drawing to an image in vram (equivalent of Java2D VolatileImage), and then drawing said image onto another image in vram, is now only possible through composition of canvas elements in the scene graph?

If this is the case, how would the current api facilitate cyclic drawing dependency? e.g. drawing a vram image onto itself? (Or, more efficiently, onto an intermediary surface, then onto itself)

A scene graph is all well and good, but shouldn't the API also expose enough of the underlying rendering pipeline so that you can implement a comparable scene graph in user code if JavaFX's offering is inadequate?

I came to JavaFX expecting a Swing 2.0, but without Canvas exposing its underlying vram surface, the API seems needlessly clunky and restrictive for anything more complex than basic image composition.

Am I missing something?
7  Game Development / Shared Code / Re: Fast Atan2 [Again] on: 2017-09-12 13:03:08
Let make next Contest "Fast Sqrt" Smiley
From my tests in the past, Java's Math.sqrt() is pretty damn fast these days, only worth it if you can beat that method substantially.

My understanding is that the above approximation is no-longer relevant 'cos we have x86 instructional support (in various forms).
8  Game Development / Shared Code / Re: take ScreenShoot on: 2017-09-11 22:59:44
ScreenShoot?

Also createScreenCapture works in screen coordinates, not Window coordinates, so your code is assuming the game window is positioned at the origin.
For your game that might be true, but in general it's a flawed assumption.

If capturing the desktop is your intent, then your code should not assume the top left of the screen begins at 0,0.
It's common for multi-monitor setups to have the primary monitor in the centre (origin: 0,0), and secondary displays to the left (origin: -width,0), and right (origin: +width,0)

To ascertain the full desktop dimensions you'll need to query GraphicsDevice(s) & GraphicsConfiguration(s) via GraphicsEnvironment.getLocalGraphicsEnvironment().
9  Discussions / Miscellaneous Topics / Re: Engineer/Programmer? sentenced in VW emissions fraud case on: 2017-08-27 23:19:25
Or at the least, make sure you at least have plausible deniability if you do so.

Umm, I don't think this is a great takeaway. The whole point is that programmers have an active role in, and as this sentence proves, a responsibility for, the code they write. Plausible deniability isn't enough.

Absolutely not!

A rigorous development process is there to relieve the programmer of all responsibility for the code they write.
The client takes responsibility for the acceptance of the design, and QA takes responsibility for the acceptance of faulty code.

Only when the programmer is wearing multiple hats, can he be accountable for his own code.
10  Games Center / Featured Games / Re: Demise of Nations for PC, Mac, Linux, Android & iOS on: 2017-08-09 10:43:08
Auxlia? Don't you mean Auxilia?

Oh never mind, looks like you might be correct; silly Latin.
11  Game Development / Newbie & Debugging Questions / Re: preven title bar to show in the part of your rendering screen on: 2017-08-03 13:43:48
rtfm

Frame javadoc, 4th paragraph of the class description.

Quote
A frame may have its native decorations (i.e. Frame and Titlebar) turned off with setUndecorated. This can only be done while the frame is not displayable.
12  Game Development / Newbie & Debugging Questions / Re: [Help] PNG + transparency + PSP 4.12 on: 2017-07-17 23:17:45
Sounds like you just need to learn how to properly use your paint package of choice.

Though a small note; basic png supports 3 types of transparency;
  • full alpha channel per pixel
  • per color alpha (for palettized images)
  • simple alpha mask

Your paint package will typically use the one most appropriate & efficient for your image's color depth, though not always.
13  Game Development / Shared Code / Re: Faster Than Light JSON Parser on: 2017-07-06 23:45:41
2. Implement that table via a ByteBuffer and do the lookup with sun.misc.Unsafe.getByte() to get rid of the default Java array access bounds checks.

Wow, you really are trusting the integrity of your data  Clueless
14  Game Development / Shared Code / Re: Faster Than Light JSON Parser on: 2017-07-06 12:34:46
I'm almost certain that a single case switch...

1  
2  
3  
4  
5  
         switch (c) {
         case '"':
            string(input, listener, inobject);
            continue;
         }

...will be slower than a simple if branch.
The reason being even a tableswitch involves a branch to check bounds (both upper & lower).

The index must be of type int and is popped from the operand stack. If index is less than low or index is greater than high, then a target address is calculated by adding default to the address of the opcode of this tableswitch instruction. Otherwise, the offset at position index - low of the jump table is extracted. The target address is calculated by adding that offset to the address of the opcode of this tableswitch instruction. Execution then continues at the target address.

Of course your benchmarking might have found otherwise?

#flibble dibble silly 90% quote content check#
15  Game Development / Shared Code / Re: Faster Than Light JSON Parser on: 2017-07-06 11:50:43
Going back to isEscaped; granted it's a fringe case, but rather than counting the escaped characters, just toggle a boolean?

  • It would eliminate the limitation of 2 billion sequential escaped characters persecutioncomplex
  • It might be quicker. (not that it'd ever be noticeable outside of the degenerate case of every character in every literal being '\' )
  • It demonstrates the intent of the code a little more obviously

1  
2  
3  
4  
5  
6  
7  
    private boolean isEscaped(byte[] input) {
        int p = pos - 1;
        boolean escaped = false;
        while (read(input, p--) == '\\')
            escaped=!escaped;
        return escaped;
    }


Though looking at the bytecode generated by javac 8, it appears that negating booleans is done with a branch now!? (I believe it used to be done with an xor)
Presumably that's something optimized by the JIT.
16  Game Development / Shared Code / Re: Faster Than Light JSON Parser on: 2017-07-06 11:31:09
As it operates on bytes, it doesn't support non-ASCII characters, no?
It does support the UTF-8 character coding, since all recognized tokens (", :, 0-9, etc.) are also in the ASCII range (highest bit not set). Or in other words: There will not be any byte of the 1-4 bytes in a single UTF-8 character encoding that can be misinterpreted as a recognized token by the parser, since all such bytes use the highest order bits to indicate that there are more bytes to follow. Quite clever of them to design the character coding this way.
So you can use any UTF-8 encoded character you like in object key names and string value literals.

Makes sense; so ParseInterface#stringLiteral(int off, int len) is the number of bytes that make up the literal, not necessarily the number of characters.
Should make sure the ParseInterface javadoc makes that clear.
17  Game Development / Shared Code / Re: Faster Than Light JSON Parser on: 2017-07-05 22:20:07
Really minor tweak;

byte c
in isescaped(...) should be an int. (As it is being used as a counter, not intermediary storage of a value copied from input)

....and the method itself should be named isEscaped(...)  Pointing

I'd also decide whether the class is going to be stateful, or not.
At the moment you're storing pos as state, but passing the byte[] & ParseListener around as parameters.

Go with one, or the other; doing both looks messy.
Given the aim is minimal weight & dependencies, I'd be inclined to make it stateless so everything can be static.
Either way, I doubt it'd have any noticeable impact upon performance.
18  Game Development / Shared Code / Re: "Better" LinkedList implementation on: 2017-06-19 14:49:23
I'd be inclined to have a reference in the Element, to the List that owns it.

It'd allow fail-fast protection against multiple logic errors (adding an Element to multiple lists/the same list multiple times, removing/moving an element from a List that it's not a member of, etc), making the code far less fragile.
19  Discussions / Miscellaneous Topics / Re: Programming in schools - opinions? on: 2017-02-24 12:20:42
@Abuse, I think all tests should allow laptops and spreadsheets, mostly for the ability to easily save and see intermediate results which is hard in a calculator, and to be able to see the history of working in prior cells' working to spot an error.

Are we imagining different examination techniques?
I'm still imagining paper examinations where the calculator simply supplements the written word; it's the responsibility of the student to record their working on the examination paper.

What you're suggesting sounds like a transition to completely digital examination, and while that paradigm shift is in the works, it's yet to become mainstream here in the UK.
I do agree though; digitally recording all intermediate working would be a much better way of evaluating a student's level of understanding, but spreadsheets are not the ideal tool for that purpose.

Quote
and regular * not x and / not รท symbols which are encountered all over the workplace and in everyday life.

Mathematical operator symbology is indeed a mess, and the pervasiveness of competing Computer Science symbology has only muddied the water further.
That's a whole different topic though.
20  Discussions / Miscellaneous Topics / Re: Programming in schools - opinions? on: 2017-02-23 16:30:15
Just to be clear, when I say "teaching programmin" in an elementary school, I expect to make it accordingly, that means no gradle or complex projects, but simple exercises, like moving an character through a 2d tiled-map. Something that also attract their attention and is, somehow, fun.

Teaching programming should be, indeed, teaching how to elaborate and process algorightms

Precisely.

I introduced my 5 year old nephew (mad on Minecraft) to code.org's Minecraft Hour of Code, and he found it incredibly rewarding.
Programming (in all its guises) is already prevalent throughout our society, and will be even more so in the future; introducing it early as a 'play thing' is vital for future learning.

It's hardly a new concept; anyone remember this:

Or this:
21  Discussions / Miscellaneous Topics / Re: Programming in schools - opinions? on: 2017-02-23 13:33:52
On a related note, I always think it's incredibly dumb how students are forced to use such limited calculators in exams. All exams in math related subjects should allow spreadsheets or mathematica or Google or a programming language on a laptop.

At what level are you talking about?

No highschool student would ever need access to such powerful tools to solve the problems they're being examined on.
Moreover, having access to such tools would change the focus of the examination; you'd no longer be testing them on their understanding of the topic, but on their ability to use the tools.
22  Discussions / Miscellaneous Topics / Re: Programming in schools - opinions? on: 2017-02-23 02:31:47
Programming is logical problem solving; it's an essential life skill for everyone.
It can (and should) be taught to all young children.

Coding on the other hand (and which I suspect is what the OP is actually talking about?), is a far more specialised discipline that not everyone can grasp to the same level.
So while you don't anticipate every pupil who is taught coding at school, will go on to use it in their professional life, they will know of its existence & thus have an understanding of how computers & technology work.

The parallel would be the car; everyone uses them, most know how they work, but very few would dare attempt anything but the most superficial of servicing.

Thankfully both programming & coding have been a part of the national curriculum here in the UK for some time, so I guess someone in authority knows where society & technology are headed.
23  Game Development / Newbie & Debugging Questions / Re: Peculiar stacktrace and an error I've never seen before on: 2017-02-21 03:09:43
unless this person has a software running that does exactly that, which I wouldn't assume.

Yeah, I had that thought today too.

Perhaps you've detected someone messing around with your game in a dev environment, for some nefarious (or otherwise) purpose.
24  Game Development / Newbie & Debugging Questions / Re: Peculiar stacktrace and an error I've never seen before on: 2017-02-19 19:37:24
1st place I'd look would be JAVA_TOOL_OPTIONS or _JAVA_OPTIONS environment variables for anything untoward.
Presumably you log & report the values of these on launch?
25  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Advantages of Ant? on: 2017-01-29 23:45:43
We simply do not allow any external dependencies in a build, period. The entirety of the repository must be sufficient to produce all artefacts.

Cas Smiley

Wow!

So you've got an entire VM image containing OS & apps checked in?  Grin
26  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Advantages of Ant? on: 2017-01-26 16:49:53
IME having external dependencies in a build is a bit like building your castle on sand. The build must always succeed. Discuss.

So you're advocating the inclusion of external packages with your build, rather than having them pulled from a central repository?

I'm of the opposite opinion; pulling from a central repository minimizes data duplication, and therefore fewer places for mysterious build errors to creep in.
Either you get the correct version of the correct library, or you get nothing. Fail fast.
27  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Advantages of Ant? on: 2017-01-25 16:49:27
Surprised nobody has mentioned Maven; from my limited experience with it, it's Ant done right.
Great Eclipse integration too, and you can host your maven repository directly on github.

Takes a little while to get your head around the concepts, but the way dependencies are handled makes it a dream to use (especially when you're pulling from others' Maven projects)
28  Game Development / Newbie & Debugging Questions / Re: getting rid of "instanceof" on: 2017-01-14 23:31:18
@cylab - Your post (reply # 29) showed me that you can use a class type as a key in a HashMap, so thank you for that.  Pointing I wanted to do that one point and didn't know it was actually possible. Also, I like the implementation you suggest as it is very clean. I'll probably try that at some point, but for now this implementation is working well.

I read in several spots on the thread that casting might smell of bad design, which I do in places, namely where a state is assigned to a Mob:
1  
2  
3  
4  
5  
6  
@Override
   public MobState init(Mob m) {
      brick = (Brick) m;
      brick.setCol(0xffff00);
      return this;
   }


The problem is that I can't assign the type and recognize the subclass methods without casting. It doesn't generate a compile time error if you pass the wrong type as an argument, but I have tested it and it will throw a ClassCastException and print a stack trace. So I was wondering if this is considered bad design and if there is a better approach? Thank you all for contributing to the thread- your expert advice has been very enlightening!

In that example, it looks like your MobState super-class should be a generic type, with the init method using the class' parameterized type for its parameter.
Something like:

1  
2  
3  
4  
abstract class MobState<T> {

public abstract MobState init(T m);
}


The return type could probably be parameterized too, though I've no idea what your MobState / Mob class heirarchy looks like.
29  Game Development / Newbie & Debugging Questions / Re: Type checking an init method on: 2016-12-27 15:44:54
I'd advise that you don't get yourself wrapped up in unnecessary Generics boilerplate.

What value is this bringing to your code?
Is it reducing, or increasing, complexity & readability?
30  Game Development / Game Play & Game Design / Re: The best way to normalize chances in a two-player game? on: 2016-12-09 23:14:42
IMO the large 1st-player advantage given by the rules necessitates multiple games for each level, with serve alternating between players.
Victory would then require a 2 game lead (break their serve & hold yours).
Basically Tennis tie breaker.

1st serve wouldn't matter, so decide it with a hidden coin toss.

It'd elongate each level, but it seems to me all the other alternatives are radical departures from the classic game.
Pages: [1] 2 3 ... 72
 
Ecumene (143 views)
2017-09-30 02:57:34

theagentd (207 views)
2017-09-26 18:23:31

cybrmynd (291 views)
2017-08-02 12:28:51

cybrmynd (283 views)
2017-08-02 12:19:43

cybrmynd (293 views)
2017-08-02 12:18:09

Sralse (286 views)
2017-07-25 17:13:48

Archive (953 views)
2017-04-27 17:45:51

buddyBro (1089 views)
2017-04-05 03:38:00

CopyableCougar4 (1655 views)
2017-03-24 15:39:42

theagentd (1421 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!