Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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]
1  Java Game APIs & Engines / Java 2D / Re: Some clarification on repainting dirty regions on: 2013-09-10 21:24:37
What does "culling out tiles that don't need to be rendered" mean?

And I think my proposed solution "partitions" the area of the map that needs to be traversed. There's just a little but of calculating done to find the locations of the affected tiles, and it would only loop over those, instead of looping over everything and skipping what hasn't been changed.
2  Java Game APIs & Engines / Java 2D / Some clarification on repainting dirty regions on: 2013-09-10 05:33:07
What I've got is multiple layers of tile grids, each with the same dimensions and everything, "stacked" on top of each other (because some things need to be drawn under other things).

When being painted, each "layer" is cycled through from back to front, meaning if each layer is 15x15 squares, then that's how many times the layer's repaint loops have to check for null squares/sprites/tiles to be drawn.

I'm starting to just learn about taking advantage of clipping areas, and repainting "dirty" regions with Java Graphics objects.

The system I use for traversing each layer's grid is fairly simple: each layer has a Rectangle Field called "bounds," which (for example) could be set to 15x15 (since I work with multiple levels of zoom, the actual pixel size of the layer is determined by [bounds * tile size * zoom factor]). So, the loops just go from 0 to bounds.width and bounds.height, originally designed to try and reduce working strictly with pixel locations.

Just so you understand my own understanding of my code, each time repaint is called, even with a dirty region, the loops have to traverse over 0 to bounds.width / bounds.height (right? Since the loops are still there..).

The way I have it currently makes me feel like even though I've specified dirty regions to repaint (for example, when mouse hovering), there is wasted CPU usage / resources iterating over each layers' grid, even though (somehow, I don't exactly understand) the graphics object currently does what I intend it to do (repaint for hovering mouse over new square / repainting to reset from mouse leaving square). I've checked this by setting the stroke to some obscure color and making it paint the clipBounds. Only the affected Tiles were changed.

Begin question:
Would it be more efficient to locate the clipBounds on-screen (pixel x & y) coordinates with the current Graphics object, and somehow start the loops only checking grid squares that are contained in and intersect the clipBounds? This would require some "extra" arithmetic prior to beginning the loops in order to determine which squares, from [x1][y1] to [x2][y2], lie in intersection with the clip bounds (the indices would be the same for all layers, since they all have equal tile dimensions).

For example, currently I have:
Mouse movement detected at point (x,y) on-screen. Convert (x,y) coordinate of MouseEvent to (X,Y) tile within the grid, retrieve Tile's Rectangle bounds, and send that Rectangle as a dirty region to be repainted. Repaint then iterates over all layers, and within each layer, it iterates over all tiles from grid location (0,0) to (WIDTH)(HEIGHT). Somehow, because of the dirty region parameter passed, it only repaints the affected area once it reaches it within the loops, and the rest are left unchanged. However due to the nature of the repaint method, each Tile on each layer had to be passed and done "something" with, correct?

Would it be better to have:
Mouse movement detected at point (x,y) on-screen. Convert (x,y) coordinate of MouseEvent to (X,Y) tile within the grid, retrieve Tile's Rectangle bounds, and send that as a dirty region to be repainted. Now, instead of iterating over the indices of the grid, start loop at first affected Tile's (x,y) pixel location. Traverse loop in pixels, incrementing by the Tile's width and height, until the clipBounds' size has been exceeded.

Does this second way reduce computation energy and resources used?

Keep in mind, I am trying to highly optimize because I'm using a slightly old machine. This thing can give me a really good hunch as to whether or not what I've coded was done well or not. The reason this "problem" even came about is because I noticed a performance drop once the currently open Layers actually contain sprites/tiles and not empty space. It made me feel like something was being done with the entirety of each layers' objects, and not just the objects that lie directly beneath the intersection of the clipBounds.
3  Java Game APIs & Engines / Java 2D / Re: Efficiency in custom Map Editor - Swing or Graphics drawing? on: 2013-08-14 10:45:06
The way I look at it:

Your map editor is essentially an augmented version of your game. Your map editor should use the same classes and augment them where required. I.e your game map would be used to represent your map in the editor.

So you shouldn't be rendering your game map any differently than how you're rendering it in your editor. Otherwise you're reimplementing the wheel everywhere you go and updating your game map becomes hell.

Because most games typically have a minimal UI - it makes sense for there to exist another window to perform a lot of the interaction with the world that require a UI. Hmm, I'll post a screen shot of my editor to better illustrate the lay out.


Basically 95% of the editor is the game, and there is a small addition to get access to controls you wouldn't normally have via game (but are implemented via the game) that provide an interface to this. I.e, the map editor doesn't implement anything - it just allows for a more powerful interface:

This is bad for me. I haven't begun making the game engine at all yet.

My idea was to have maps prepared when I being writing the engine, and have it parse the output from the editor. Since it's just simple 2D tiles for now, I didn't see that as being much of a problem.

The problem arises on my older machine when I've got more than one map open, and when I've played around with zooming and toggling the grid visibility.

I'm trying to optimize the way the Swing components and the BufferedImage chunks are referenced between each other. At the moment, I've got maybe 6 or 7 ArrayLists and HashMaps that make referencing certain Tiles at certain locations at certain indexes, which makes it VERY easy, but I feel like I need to devise a better way to do it. There is very noticeable input lag when interacting with the Tiles on my older machine, but not my newer one (which I believe to be caused either by the way I reference each Image and JLabel, or by the way I've manipulated their ImageIcons on Mouse Events). Either way, I'd like to make my program more efficient.
4  Java Game APIs & Engines / Java 2D / Re: Efficiency in custom Map Editor - Swing or Graphics drawing? on: 2013-08-14 04:26:24
Quote
My question: is using Swing components like this the most efficient way of doing this?

"Don't fix it if it ain't broken."  Pointing
This goes especially for 'temporary' tools such as a game-specific map editor.
Yes, the performance is probably not as good as J2D, but then again, J2D isn't really that much of a step up performance-wise.

Use the "correct," "performant," way (J2D) for the actual game, and use what works (you already have it) for the tool.

I started with what I knew, and using LayoutManagers to get desired positioning was my initial motivation. It's a fairly simple tool so far, runs very smoothly on my current machine (not sure about lower end, for example my desktop is from 2008 and it may run slower on that).

Regardless, I appreciate the reply.

Don't worry about efficiency too much while it's still in early development, especially since this is just a tool and not the actual game. Anyways, I don't know too much about this, but I highly doubt overriding it would be more efficient than setting it.

@Simba Productions -
That's completely off topic. He's asking about efficiency.

This is what I figured when I first started to worry about it, but I just wanted to make sure. One of the machines I will be developing on is 5 years old, so if I take my 2-year old Laptop's processing speed for granted, I'll be limiting myself later when I need to use Old Faithful!

What do you think about managing Lists of Arrays, or bunches of Maps? I've tried to be 'considerate' and set things to null when not being used, clearing out old Lists/Maps, and using smaller data types when possible (such as short instead of int, float instead of double). Is that being too cautious for a tool like this? I feel like the practice is needed anyways!
5  Java Game APIs & Engines / Java 2D / Efficiency in custom Map Editor - Swing or Graphics drawing? on: 2013-08-14 04:08:50
Beginning a project on a game, and I decided I wanted to use my own in-house tools for development. And with that comes a Map Editor.

Since I will most likely be doing a lot of drawing with Graphics when I start to make the game itself, I thought this question was important to ask before I actually get to that part.

Currently, I am using Swing to make my Map Editor look pretty. I've got a JMenuBar, JToolBar, JSplitPanes, JScrollPanes, you name it. I'm actually pretty familiar with Swing and how to make it look nice.

So you can visualize it easier, here it is.



What you're looking at is:
  • A JTabbedPane within my main Application's JFrame, which has in it,
  • a JScrollPane, in order to allow proper viewing based on the zoom level of the
  • Custom Canvas JPanel set as the viewport, which has a specific LayoutManager, in order for the
  • Regular JPanel within the custom Canvas to be centered correctly, which contains
  • A GridBagLayout of JLabels.

Each JLabel has an icon based on whatever tile it should be. "Empty tiles" still have icons, it's just that solid darker gray color, created by an ImageFactory class which stores all my image manipulation methods.
___________________

Okay, so if you're still with me, I'd like to actually get around to asking my question.

My question: is using Swing components like this the most efficient way of doing this?

The reason I ask is, I've had to do a lot of setting and re-setting of each of those JLabels' icon images. I've got one Class called ImageFactory that manipulates the images. The icons get changes based on Mouse input (clicking, enter, exit) or some other criteria, as such:
  • If no tile is selected to be 'stamped,' there will just be an alpha composite of a color painted over the JLabel's icon to denote that it is being hovered, and will revert upon a MouseExit
  • If there is a tile on the active Stamp tool, that tile's image will replace the JLabel's icon -temporarily- to denote that it is being hovered, and will revert upon a MouseExit
  • If there is a tile on the active Stamp tool, and a JLabel is clicked, that JLabel's icon will be set to the active Stamp tile "permanently" unless reverted
  • If the option to have Grid Lines is toggled on, each JLabel's icon will be processed through the ImageFactory to have dashed lines running along the top and left edges (forms a grid, as seen in the picture)
  • If the Zoom level is changed, each JLabel's preferredSize is set to accomodate, and the icon has to be resized in the ImageFactory (grid lines applied depending)

As you can see, this seems to be a lot of Icon changing/setting, and I don't actually use any Graphics drawing (like I will within the game), except within the ImageFactory class (in order to manipulate the icons).

Is this the fastest or most efficient way to handle these things to achieve the desired outcome?

Would it be faster if I manually overrode the subclassed JPanel's paintComponent method, and drew the stuff myself?

I know this still may seem trivial since I've got the thing working how I want. I'm just worried about making it as memory-efficient and CPU-efficient as possible. Even though the setting and re-setting of each JLabel's icon happens pretty quickly, I need to be in this mindset because creating a game that is wasteful of resources is just bad practice, and I've never really had to make anything where I had to be nit-picky about these things.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (57 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!