Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Efficiency in custom Map Editor - Swing or Graphics drawing?  (Read 1446 times)
0 Members and 1 Guest are viewing this topic.
Offline Waffle

Junior Newbie





« Posted 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.
Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #1 - Posted 2013-08-14 04:11:54 »

You could use a table of BufferedImage in one JPanel (instead of the jLabels), and compare speeds, or you could just create one large BufferedImage in your JPanel and just draw onto it in memory.
Offline BurntPizza
« Reply #2 - Posted 2013-08-14 04:14:32 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2013-08-14 04:15:19 »

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.
Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #4 - Posted 2013-08-14 04:19:25 »

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.

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

Imho i thought drawing onto a buffered image and cut all the extra JPanels would save memory and make the program run faster, which (using Java2D) is a more efficient way of "doing this". due to the fact that its a big change from what he is doing now it could be a little too much of a change but my answer answers the question, i believe, so it isn't "completely" off topic.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2013-08-14 04:23:28 »

Whole point of using a JPanel is for the Swing functionality. Using a BufferedImage instead is like writing your own GUI system.
Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #6 - Posted 2013-08-14 04:25:20 »

Whole point of using a JPanel is for the Swing functionality. Using a BufferedImage instead is like writing your own GUI system.

ah Ok i see where you are coming from, you are right in your own sense, but i hope you see where i'm coming from too. Also using more concrete JLabels/JPanels or a table of bufferedimages would work almost the same way which is why i mentioned it. i didnt mean cut all the scrollpane and all.
Offline Waffle

Junior Newbie





« Reply #7 - Posted 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!
Offline Jeremy
« Reply #8 - Posted 2013-08-14 09:16:31 »

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:

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline Waffle

Junior Newbie





« Reply #9 - Posted 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeremy
« Reply #10 - Posted 2013-08-14 10:55:05 »

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.

Hmm, well it should'nt be that big of an issue for a tile-based game - just keep in mind that later (when you get the engine all setup etc) and the map becomes more complex, it would be easier for you to switch over (eventually) to using your Game as a library for your map editor rather than working from scratch.

If you haven't worked out the engine yet - don't worry about it.

Eventually when you get the engine going your game's world will implement all sorts of optimizations that you can start using from within your editor that should make your life easier when you get to that stage.

*EDIT*
That said, the answer to your question is both. Use swing for the UI and graphics drawing for your map.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline davedes
« Reply #11 - Posted 2013-08-14 14:36:51 »

You can also use LibGDX for UIs. Then you don't need to worry about performance as much.

Keep in mind Spine was built with LibGDX and Scene2D:
http://esotericsoftware.com/

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (35 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (56 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!