Knuckle Cracker

Creeper World => Custom Map Discussion => Topic started by: mopa42 on April 02, 2011, 05:00:16 PM

Title: Custom Terrain Editor in Java
Post by: mopa42 on April 02, 2011, 05:00:16 PM
Recently I was inspired (partly by this post: Upgrade the editor (http://knucklecracker.com/forums/index.php?topic=739.0)) to make my own map editor.
Why?
A reasonable question, especially since CW2 is coming soon. Mainly I just like the game a lot. Part of it is that I'm taking a java programming class this semester which has really gotten me excited about making GUIs. The other is I've been wanting to continue working on the custom map file format, which I began in my first post here (How to edit Creeper World custom map (.cwm) files by hand (http://knucklecracker.com/forums/index.php?topic=5177.0)).

So what's wrong with the current custom map editor? The main things are that it is hard to draw continuous lines (the brush skips if moved quickly), and it is hard to draw circles and other curvey terrain. Nothing that makes it impossible to use the map editor, just a little painstaking.


Anyway, under the theory that some other people might find it useful, I'd like to share this terrain editor that I made.

I say terrain editor because all that my program can do is edit the 70x48 grid of elevations. It is possible (though highly unlikely) that I could extend it to modifying emitters or walls or the like, but I just don't see the need (the current map editor works well enough). Edit - by request, version 0.5 and higher can now edit emitters.
A side note on terminology: I use the terms cell, grid, square, and sometimes pixel to refer to the 70x48 elements of the map.

Basic features / use:

Random list of other comments:

Here's a screenshot of the program in action, and then the game with the corresponding map.
(http://knucklecracker.com/forums/index.php?action=dlattach;topic=6585.0;attach=3377;image)
(http://knucklecracker.com/forums/index.php?action=dlattach;topic=6585.0;attach=3379;image)


Known limitations:
You can't [yet] set a custom image as a (temporary or permenant) background.
Very little documentation.
Can edit only terrain, which means you will still need to use the original custom map editor for the non-terrain elements.

On a technical note:
The program is a jar file, which means that for most people you can just double-click to run it. (you'll need java 6)
Jar files are zip files with a different name, so you can extract their contents. In particular, the source code (the raw .java files) is included. Feel free to look / modify / reuse for any purpose - I'm placing the code in the public domain, but that doesn't mean that it is well-organized or easily reusable.

Feedback I'd like:


TL;DR:
Download and try my new java terrain editor! You can draw circles and stuff!

I've updated the editor! (the new version, in TerrainEdit-Latest.zip, is now v0.6).
See here (http://knucklecracker.com/forums/index.php?topic=6585.msg39608#msg39608) for new features in 0.4, here (http://knucklecracker.com/forums/index.php?topic=6585.msg40343#msg40343) for 0.5a (emitters), and here (http://knucklecracker.com/forums/index.php??) for 0.6 (random terrain).

Edit - minor formatting, added note about scroll wheel
Edit - Changed TerrainEdit-Latest.zip to 0.6
Title: Re: Custom Terrain Editor in Java
Post by: MadMag on April 02, 2011, 05:07:35 PM
Wow...  Nice work!

Even a Custom brush choice.
Title: Re: Custom Terrain Editor in Java
Post by: Blaze on April 02, 2011, 05:15:11 PM
In the second shot, what is that glowing orb?
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on April 02, 2011, 05:17:53 PM
wow, this guy works miracles
Title: Re: Custom Terrain Editor in Java
Post by: Fisherck on April 02, 2011, 06:17:42 PM
Amazing. Great job! This could be very helpfull for lots of people...
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 02, 2011, 07:39:14 PM
Quote from: Blaze on April 02, 2011, 05:15:11 PM
In the second shot, what is that glowing orb?
It is the rift right as it opens. (I forgot to add a totem, so the map was almost over before I grabbed the screenshot).
Title: Re: Custom Terrain Editor in Java
Post by: UpperKEES on April 02, 2011, 10:07:09 PM
Very nice! I was actually done with CW1 map making, but I guess I'll have to try at least one more time.... :)
Title: Re: Custom Terrain Editor in Java
Post by: J on April 03, 2011, 07:12:18 AM
I can't save my maps
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on April 03, 2011, 02:45:00 PM
for reasons of security and paranoia, can I see the source code for the program?
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 03, 2011, 02:51:21 PM
Quote from: J on April 03, 2011, 07:12:18 AM
I can't save my maps
Can you tell me exactly what steps you are taking?
(my guess as to what the problem is: you have to type in the file extension yourself. The program's not smart enough to add one itself)
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 03, 2011, 02:56:55 PM
Quote from: thepenguin on April 03, 2011, 02:45:00 PM
for reasons of security and paranoia, can I see the source code for the program?
The source is included in the jar file, but you have to extract it yourself.
One way of doing that is to rename TerrainEdit.jar to contents.zip, then open the zip file. Inside you'll see a bunch of .class files (the compiled java files, the ones that get run), and a bunch of .java files (the source code). The images directory is also important - the program looks for /images/rock.jpg.
The main file is CreeperWorldTerrainEditor.java.
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on April 03, 2011, 03:03:49 PM
thanks, good to know
Title: Re: Custom Terrain Editor in Java
Post by: Fisherck on April 03, 2011, 03:14:50 PM
It even has the elusive circle brush! Where were you when I was trying to that myself? ;)
Title: Re: Custom Terrain Editor in Java
Post by: DarthVader12 on April 04, 2011, 02:37:28 PM
works fabulously
great job
you are going to update it right? ;)
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on April 09, 2011, 01:17:03 PM
Quote from: DarthVader12 on April 04, 2011, 02:37:28 PM
works fabulously
great job
you are going to update it right? ;)


what is there to update?
Title: Re: Custom Terrain Editor in Java
Post by: MadMag on April 09, 2011, 01:35:56 PM
1. Functions
2. Interface
3. More pre buildt brushes
4. Terrains
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 09, 2011, 09:00:06 PM
I'm glad you guys like the editor. I wasn't sure about releasing it, with CW2 almost out, but thought that there was no penalty for just putting it out there if anyone wanted to use it.

Quote from: DarthVader12 on April 04, 2011, 02:37:28 PM
you are going to update it right? ;)
Yes. I plan to keep working on the editor until it is as useful and complete as I can make it.
But to do that, I need to know what broken features to fix and what new features people would like me to add.
Here's my short list of stuff I want to add:

Quote from: MadMag on April 09, 2011, 01:35:56 PM
1. Functions
2. Interface
3. More pre buildt brushes
4. Terrains
Can you be more specific? What new brushes should I add?

So in general, if you guys can suggest improvements or new tools or whatever, there's a good chance I'll add them to the code.
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 14, 2011, 11:21:01 AM
First update is here!
(download TerrainEdit-Latest.zip on the first post).

New features:

I'd like to add some more tools/actions/brushes, but I don't know what else to add.
If you suggest something, I can probably have it in the next update.
Title: Re: Custom Terrain Editor in Java
Post by: J on April 14, 2011, 02:02:36 PM
Could you let us create emitters with special futures?
Title: Re: Custom Terrain Editor in Java
Post by: ontheworld on April 14, 2011, 02:05:29 PM
You mean like 5/4/5/4/5/4/5/4  amounts emitters?
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 18, 2011, 12:58:51 AM
Quote from: J on April 14, 2011, 02:02:36 PM
Could you let us create emitters with special futures?
Do you mean stacked emitters? And seeing and editing a "timeline" like thing for what the cumulative effect of the stacked emitter is?
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on April 18, 2011, 07:30:51 AM
Quote from: mopa42 on April 18, 2011, 12:58:51 AM
Quote from: J on April 14, 2011, 02:02:36 PM
Could you let us create emitters with special futures?
Do you mean stacked emitters? And seeing and editing a "timeline" like thing for what the cumulative effect of the stacked emitter is?

YES! YES! YES! that will make this something worth looking into
Title: Re: Custom Terrain Editor in Java
Post by: J on April 18, 2011, 10:54:07 AM
Or an emitter that starts when it's hit by creeper
Title: Re: Custom Terrain Editor in Java
Post by: Grauniad on April 18, 2011, 11:17:08 AM
It is a map editor, not a mechanism to change the game mechanics.
Title: Re: Custom Terrain Editor in Java
Post by: UpperKEES on April 18, 2011, 02:53:33 PM
Quote from: mopa42 on April 18, 2011, 12:58:51 AM
Do you mean stacked emitters? And seeing and editing a "timeline" like thing for what the cumulative effect of the stacked emitter is?

This would be totally awesome. I always had to use MS Excel to calculate all emitter increases and delay times. Please keep in mind that stacked emitters are emitting from bottom to top when emitting in the same frame, so only the last one has an effect when intervals coincide. This effect can also be used to stop an emitter.
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on April 25, 2011, 01:58:39 PM
Ok, I've got a preliminary release that lets you edit emitters.

Here's what's new:

In order to make that happen, I've come up with an algorithm that I hope simulates how the game behaves accurately enough.
Here's a snippet of the actual code:

creeperDepth = new float[frameCount];
float lastValue = 0;
for (int frame = 0; frame < frameCount; frame++) {

   // apply each emitter in turn (the last one in the list - the one on top - overrides others)
   float thisValue = 0;
   boolean anyFired = false;
   for (int i = 0; i < N; i++) {
       if (frame >= starts[i] && (frame - starts[i]) % intervals[i] == 0)  {
           thisValue = intensities[i];
           anyFired = true;
       }
   }

   // determine any special behavior when no emitters are active this frame
   switch (mode) {
       case DROP:
       default:
           if (!anyFired) thisValue = simParam; // simParam is value to drop to
           break;
       case HOLD:
           if (!anyFired) thisValue = lastValue;
           break;
       case DECREASE:
           if (!anyFired) thisValue = Math.max(0, lastValue - simParam); // simParam is decrease rate per frame
           break;
   }

   // record the depth
   creeperDepth[frame] = thisValue;
   lastValue = thisValue;
}


In each frame, I apply each emitter in order (which will be from bottom to top, low Z to high Z). This means that only the topmost emitter applies when they overlap.
I've given a couple of options for the simulation. They specify what happens when no emitters emit in a given frame. In the actual game, the creeper will spread out following the whole creeper flow model with the terrain and everything. There's no way I'd be able to duplicate that in-editor. Instead, you can choose between having the emitter level drop immediately to zero (or another number), hold at its old value until changed by another emitter, or decrease at a constant rate per frame (which sort-of simulates creeper flow). These options should give some flexibility to have the simulation give you a useful model for what actually happens.

There is one detail which I haven't included. In the game, creeper is only updated every 7 frames. I'm not exactly sure how to model that, or if modeling it would be useful.
Other know bugs:


I'd like some feedback on this tentative release.

Edit - spelling, known bugs
Edit - updated bugs/features for now 0.6, added screenshot
Title: Re: Custom Terrain Editor in Java
Post by: Michionlion on April 25, 2011, 02:11:08 PM
i just tried that out:  Awesome!!!!  now i can do what upper, and fish and other people did with absolutely no knowledge of how to code.  thanks
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on May 05, 2011, 08:14:17 PM
One more update (maybe the last). I've added a really slick new feature: random terrain generation!
It is similar to Chronom maps in that both generate terrain starting from a seed value, but it uses a different algorithm. I used the diamond-square (http://www.gameprogrammer.com/fractal.html#diamond) algorithm, Chronom uses Perlin noise (http://knucklecracker.com/forums/index.php?topic=5501.0).
There are three fun sliders to play with and a bunch of presets for different behavior.
The cool thing is you can set how similar the generated terrain is to the start terrain, so you can either generate all-new terrain or just add some randomness to the edges of your existing terrain.
I think you'll really like it. I had lots of fun playing with it.

(http://knucklecracker.com/forums/index.php?action=dlattach;topic=6585.0;attach=3853;image)

Other new stuff:

We're now at version 0.6.
Download it as TerrainEdit-Latest.zip on my first post.
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on May 05, 2011, 08:16:21 PM
very nice, :)
Title: Re: Custom Terrain Editor in Java
Post by: Michionlion on May 05, 2011, 08:17:59 PM
awesome!
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on May 05, 2011, 08:18:56 PM
Quote from: Michionlion on May 05, 2011, 08:17:59 PM
awesome!

I finally crashed it! :P
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on May 05, 2011, 08:33:43 PM
Quote from: thepenguin on May 05, 2011, 08:18:56 PM
I finally crashed it! :P

How? What did you do?
Title: Re: Custom Terrain Editor in Java
Post by: UpperKEES on May 06, 2011, 02:28:37 AM
Mopa42, you rock! 8)

@ Moderation team: I suggest this post gets stickied, because it's of great value to any CW1 player.
Title: Re: Custom Terrain Editor in Java
Post by: allu on May 06, 2011, 07:46:01 AM
When i open the program why it opens nokia ovi suite:P?

Hey i cant get the program open.
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on May 06, 2011, 07:48:47 AM
Quote from: mopa42 on May 05, 2011, 08:33:43 PM
Quote from: thepenguin on May 05, 2011, 08:18:56 PM
I finally crashed it! :P

How? What did you do?

fill the whole map with emitters and delete them all at once :P
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on May 06, 2011, 01:58:48 PM
Quote from: thepenguin on May 06, 2011, 07:48:47 AM
fill the whole map with emitters and delete them all at once :P

Quote from: mopa42 on April 25, 2011, 01:58:39 PM
Other know bugs:

  • Moving or deleting hundreds of emitters at once is really slow

Yeah, the way the program keeps track of emitters is really inefficient, which means that dealing with many at once takes a lot of time. This isn't a huge deal because that many emitters would probably crash the game too. And the program should eventually delete them all - I timed 94 seconds to delete a full map of emitters.
If the program actually crashes instead of just hanging for a while, well, that is a bug and I don't know how to fix it.
Title: Re: Custom Terrain Editor in Java
Post by: Grauniad on May 06, 2011, 02:03:15 PM
Quote from: mopa42 on May 06, 2011, 01:58:48 PM

If the program actually crashes instead of just hanging for a while, well, that is a bug and I don't know how to fix it.

Welcome to the wonderful world of software development. :D
Title: Re: Custom Terrain Editor in Java
Post by: thepenguin on May 06, 2011, 03:23:12 PM
Quote from: Grauniad on May 06, 2011, 02:03:15 PM
Quote from: mopa42 on May 06, 2011, 01:58:48 PM

If the program actually crashes instead of just hanging for a while, well, that is a bug and I don't know how to fix it.

Welcome to the wonderful world of software development. :D

make sure you get the tee-shirt "I survived the devving process"
Title: Re: Custom Terrain Editor in Java
Post by: mopa42 on May 16, 2011, 10:38:03 PM
Seeing how CW2 is out, I'm going to stop working on the editor. However, a new version might appear if:
1) Sudden inspiration strikes me for something really cool
2) Someone requests a specific feature in order to make a map, and I'm able to implement that feature.
3) Someone finds a serious, I-can't-use-the-program-anymore bug.
Title: Re: Custom Terrain Editor in Java
Post by: UpperKEES on May 17, 2011, 03:50:52 AM
There's also a bundle available with CW1 + CW2 for just $15, so you may get more new users anyway. :)