#31
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Menus and Wiring


    Today I finished writing the code for a class called "ComponentConnection", which connects two pins together and draws a circuit path between them. It changes color depending on whether or not the connection is "hot" (electricity flowing through). It's orientation can be changed by dragging it with the mouse or moving the two pins it is connecting. I have also begun writing the framework needed to incorporate this class into the Robot Builder game (you never realize the amount of work you have to do on something until you start doing it, seems like). I needed a menu system for the toolkit, the chip editor, and the robot circuitry components of the game, so that is something else I have been working on for the past few days. You may have noticed a few little changes if you've visited the link. I've been trying to re-upload the game each time I finish and test something new, so people can see the progress I'm slowly making on it.
  2. #32
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Arrow Sound Effects


    I was getting a little bored with the chip editor, so I decided to work on sound for a while. I will be using the JOAL library, because it plays sounds in 3D (which I will be needing when I get back to the 3D stuff). This library is really complicated, but the flexibility it offers is awesome. I purchased a book by Andrew Davison, called Pro Java 6 3D Game Development (a very good book, btw). There is a chapter in the book dedicated to JOAL, and it goes into creating a class to simplify loading, playing, and moving sounds in 3D. I followed the guide in the book to create a SoundManager class.

    -- EDIT: The previously posted source code contained errors, so I removed it --

    There are some functions for 3D sounds (which I have not yet tested, so there are probably bugs). Initial tests of loading sounds and playing them (looping and non-looping) seem to work. Next I will look into putting sound into Robot Builder (perhaps a bump sound when the robot hits the wall).
    Last edited by paulscode; March 8th, 2008 at 02:05 PM.
  4. #33
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    lwjgl vs. JOAL


    Well, I discovered that lwjgl has its own Java binding of the OpenAL sound library, and that it is incompatible with the JOAL binding I mentioned in my last post. I actually embarrassed myself a little yesterday by posting a JOAL question on an lwjgl forum -doh!

    ANYWAY... since the applet loader program that I am using to load my game is written for lwjgl, I am already loading those libraries. Therefore, it seems logical to switch over to this other binding. They are actually quite similar, and I didn't have any trouble accomplishing the switch. I also have begun running more thorough tests on the code. Sounds are loading, and playing without any problem. However, tests of the 3D functions of the Sound Manager indicate that there is a problem (perhaps a simple typo - not sure yet). For example, a source that moves away from you should be getting quieter, but it is not. I will look into this problem further to see if I can solve it. This is kind of an important issue when you are talking about a 3D game.

    I will post the working code for the Sound Manager, when I am finished working out all the kinks. It is designed to SIGNIFICANTLY simplify sound in 3D, so I am sure a few programmers will find it very helpful.
  6. #34
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Cool Robot Builder with Sound


    Robot Builder now has a couple of sound effects! I used the lwjgl binding of OpenAL. My Sound Manager still looks pretty rough, so I won't post the source code just yet. There are also still a few more 3D-related features I want to add to the class before releasing it.
  8. #35
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    The "Sound Manager"


    I have been doing a lot of work on the Sound Manager, and I finally feel like it is in a form that I can release. You can get the source code here:
    http://www.paulscode.com/source/Soun...agerSource.zip
    Or if you just prefer to download the JAR:
    http://www.paulscode.com/source/Soun...undManager.jar

    I made a simple test applet using the Sound Manager:
    http://www.paulscode.com/source/Soun...undApplet.html
    And here the source code for the test applet:
    http://www.paulscode.com/source/Soun...pletSource.zip

    I also wrote a really basic guide:
    Code:
    Guide to the SoundManager class
    
    The simplest way to use SoundManager in your jPCT project:
    Create the SoundManager object when you initialize things:
        soundManager = new SoundManager();
    Bind the listener to the Camera after creating one:
        soundManager.bindListener( camera );
    Create some sound sources:
        soundManager.newStreamingSource( "music", "deckthehalls.ogg", true );
        soundManager.newSource( "meow", "cat.wav", false );
        soundManager.newSource( "purr", "motor.wav", true );
    Bind sound sources to Object3D's:
        soundManager.bindSource( "meow", my3DCat );
        soundManager.bindSource( "purr", my3DCat );
    Call tick() in your main game loop:
        soundManager.tick();
    Play the sounds any time you like:
        soundManager.play( "music" );
        soundManager.play( "meow" );
    Call cleanup() at the end of your project:
        soundManager.cleanup();
    
    
    Common Terms:
    ATTENUATION:  How a sound "fades" with distance.
        If there is no attenuation, a sound will play at constant volume regardless of distance
    FADE DISTANCE:  The distance at which a sound volume will become completely silent
        Used in Linear Attenuation
        (works for both mono and stereo sounds)
    LINEAR ATTENUATION:  A sound's volume is inverse to it's distance
        A sound half fade-distance away will play at half volume
    LOGRITHMIC ATTENUATION:  A sound's volume is a logrithmic function of it's distance
        A more realistic attenuation model - uses a rolloff factor
        (only works for mono sounds)
    ROLLOFF:  A value used in logrithmic attenuation.
        Smaller values for rolloff fade away at longer distances
        If rolloff is 0, then the sound will not fade
    STREAMING:  Using multiple buffers to break long sound files, (like background music) up
         into smaller pieces, so you can start playing immediately, rather than waiting to load.
    
    
    Global References:
    Attenuation models:
        public int ATTENUATION_NONE    = 0;  // no attenuation
        public int ATTENUATION_ROLLOFF = 1;  // logrithmic attenuation
        public int ATTENUATION_LINEAR  = 2;  // linear attenuation
    
    Global Varriables (can be changed to fit your preference):
    Package where the sound files are located:
        public String SOUNDFILES_LOCATION = "Sounds/";    
    Attenuation model to use if not specified (one of the references listed above):
        public int DEFAULT_ATTENUATION_MODEL = ATTENUATION_ROLLOFF;
    Default value to use for rolloff model when value isn't specified:
        public float DEFAULT_ROLLOFF_FACTOR = 0.03f;
    Default fade distance for linear model if value isn't specified:
        public float DEFAULT_FADE_DISTANCE = 500.0f;    
    Number of bytes to load at a time when streaming:
        public int STREAMING_BUFFER_SIZE = 4096*16;
    The number of buffers used for each streaming sorce:
        public int STREAMING_NUM_BUFFERS = 2;    
    The approximate size of a normal .ogg file:
        private int OGG_NORMAL_SIZE = 1048575;
    
    
    Easy Interfacing with jPCT
    When using these methods, don't forget to call tick() in the main game loop:
        bindListener( Camera c )
            Listener will automatically follow and align with the Camera object
    
       bindSource( Object3D o )
           A source will automatically follow an Object3D
    
    
    
    Method Descriptions:
    
    public void cleanUp()
        Stops all sounds and clears up any used resources
    
    public boolean bindListener( Camera c )
        Orientates the listener to match the Camera orientation
    
    public boolean bindSource( String sourcename, Object3D obj )
        Associates a sound source with an Object3D to follow
    
    Releases a source from it's associated Object3D
        public void releaseSource( String sourcename )
    
    public void releaseAllSources( Object3D obj )
        Releases all sources bound to this Object3D
        (Usually called before deleting an Object3D with sources attached to it, but not required)
    
    public void tick()
        Re-aligns the listner to the camera, and keeps sources folowing the Object3D's they are bound to
        Should be called within the game loop
        (only required if you are using bindListener or bindSource)
    
    public boolean load( String filename )
        Load the specified file (only used for non-streaming sources).
        It is not necessary for you to call this method in your program, but you can if you want to.
        (For example, you could load all the sounds at once and show a progress bar)
        SoundManager will automatically call this method if necessary when creating a source
        If "filename" is a url, it must begin with "http://"
        Returns "true" if there were no problems loading the file
        
    public boolean newSource( String sourcename, String filename, boolean toLoop )
    public boolean newSource( String sourcename, String filename, boolean toLoop, int attmodel )
    public boolean newSource( String sourcename, String filename, boolean toLoop, int attmodel, float distORroll )
    public boolean newSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel )
    public boolean newSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distORroll )
    public boolean newStreamingSource( String sourcename, String filename, boolean toLoop )
    public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, int attmodel )
    public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, int attmodel, float distORroll )
    public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel )
    public boolean newStreamingSource( String sourcename, String filename, boolean toLoop, float x, float y, float z, int attmodel, float distORroll )
        Create a new normal or streaming source.  A streaming source differs from a normal source, in that it has multiple, dynamic buffers.
        SoundManager will use default values for any value you don't specify when creating your source.
        sourcename: A unique identifier for this source (two sources may not use the same sourcename)
        filename: The name of the sound file to play at this source.  If "filename" is a url, it must begin with "http://"
            (if the sound file has not been loaded yet, then SoundManager will load it for you)
        toLoop: Should this source loop, or play the sound only once
        (x, y, z):  Location in 3D space for this source.  Default location is the origin ( 0, 0, 0 )
        attmodel:   Attenuation model to use.  Default is the value in DEFAULT_ATTENUATION_MODEL
        distORroll: Either the fading distance or rolloff factor, depending on the value of "attmodel".
    
    public boolean deleteSource( String sourcename )
        Deletes the specified source
    
    public boolean setPos( String sourcename, SimpleVector pos )
    public boolean setPos( String sourcename, float x, float y, float z )
        Moves the named sound to the specified location.
    
    public boolean play( String sourcename )
    public boolean stop( String sourcename )
    public boolean pause( String sourcename )
    public boolean rewind( String sourcename )
        Controls for playing, stopping, pausing, and rewinding a source
    
    public boolean playing( String sourcename )
        Returns true if the source is playing
    
    public void moveListener( float xStep, float zStep )
    public void moveListener( SimpleVector step )
    public void moveListener( float xStep, float yStep, float zStep )
        Moves the listener, relative to their current position.
    
    public void setListenerPos( float xNew, float zNew )
    public void setListenerPos( SimpleVector posNew )
    public void setListenerPos( float xNew, float yNew, float zNew )
        Positions the listener at the coordinates provided.
    
    public void turnListener( float angle )
        Turns the listener counterclockwise by "angle" radians, relative to their current orientation.
    
    public void setListenerOrientation( float angle )
        Sets the listener's orientation (counterclockwise rotation in radians along the y-axis)
    
    public void setListenerOrientation( SimpleVector look, SimpleVector up )
    public void setListenerOrientation( float lookX, float lookY, float lookZ, float upX, float upY, float upZ )
        Sets the listener's orientation based on a look-at point and an up-direction
    
    public void recalculateDistances()
        Recalculates the distances between each source and the listener, and recalculates the gain if a
        source is using linear attenuation.  It is not necessary for you to use this method.
        SoundManager will automatically call this method when the listener moves or rotates, or a source moves.
    One potential bug I am looking into is the fading between left and right speakers only seems to work when the source is really close to the listener. I haven't determined if it is a limitation with my soundcard, or a bug in the code. I am looking into this further. It would be helpful if a few people could run the above applet and see if they experience the same thing. Thanks in advance!
  10. #36
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    65
    Rep Power
    90
    Your robot going in circles nets 126FPS
    Comp Specs

    C2D 6750 @ 2.6Ghz
    6800 GS 256MB x2 (SLI)
    2 GB 8500 DDR2

    My other comp which is much slower nets 48 FPS
    Celeron D 3.3Ghz
    7300 GS 256 MB
    2 GB 6400 DDR2

    Your demo is very CPU intensive.
    Last edited by 0CIRCLE0; March 17th, 2008 at 10:56 PM.
  12. #37
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Talking CPU Intensiveness


    Originally Posted by 0CIRCLE0
    Your robot going in circles nets 126FPS
    Comp Specs

    C2D 6750 @ 2.6Ghz
    6800 GS 256MB x2 (SLI)
    2 GB 8500 DDR2

    My other comp which is much slower nets 48 FPS
    Celeron D 3.3Ghz
    7300 GS 256 MB
    2 GB 6400 DDR2

    Your demo is very CPU intensive.
    Yes, I have been getting a few comments like this from various people. Even on my machine, I would expect to have a considerably higher FPS than I am getting, considering how simple this applet is.

    Believe it or not, I think the issue is with the 2D components, not the 3D. I have to say -Java Swing is intuitive and easy to use, but I think it is the source of the speed issue - all my pure 3D applets run quite fast, and if I comment out the 2D rendering components of Robot Builder, it more than quadruples the speed. Instead of the Swing functions for mixing 2D with the 3D, I am looking into using direct bit-blitting, which takes away the BufferedImage overhead. EgonOlsen has added some brand new features into the latest compile of jPCT, which will make this much easier. I believe the new methods work the same for either software or hardware mode, so I am probably going to end up using hardware-accelleration after all. I plan to allow the player to choose whichever works better for their machine.

    Thanks for the feedback!

    BTW, those of you interested in seeing Robot Builder completed, you may have a little while to wait before I get back to working on it. Besides the blitting issue, I am also doing an extensive overhaul of the SoundManager class. One thing you may have noticed if you've tried to create a lot of sources (depending on your sound card), at some point the sources will just not play - ie there is a maximum number of sources that can be played at one time. Unfortunately, it seems that a source's distance from the listener has no bearing on which sources OpenAL decides to play when you have too many. This would pose a serious problem in a 3D game where you could potentially have hundreds or thousands of sound sources.

    So what I've decided to do, is make SoundManager smart enough to cull unnecessary sources. Basically, there would be a "maximum source number". Sources will have a priority based on their distance from the listener, closer sources having priority over further away sources. Sources will be culled down to the maximum source number based on their priority. Which sources are culled will change dynamically as the listener or sources move, or when non-looping sounds stop playing.

    I will keep everyone posted on how progress goes for both of these projects.
  14. #38
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    65
    Rep Power
    90
    4x the performace if you use 3d instead of 2d. Use 3d :P Anyways looking foward to seeing what you come up with and how this all comes together.
  16. #39
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Talking 2D and 3D


    Originally Posted by 0CIRCLE0
    4x the performace if you use 3d instead of 2d. Use 3d :P Anyways looking foward to seeing what you come up with and how this all comes together.
    LOL, yeh. Unfortunately Robot Builder is a 2D game..

    As for my 3D game Universe Storage, I will need to be able to mix 2D and 3D for a "heads up" style display for things like stats, etc. So I've got my fingers crossed that the blitting idea will improve performance.
  18. #40
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    3D Sound


    I haven't posted anything in a while, but this project has not been abandoned. I have been working on creating an easy-to-use 3D sound library that allows easy access to both OpenAL and JavaSound (in case one doesn't work on the end-user's computer). Anyone interested can read the history of that project at:
    http://www.jpct.net/forum2/index.php/topic,1057.0.html

    There are still a few things I need to do with the sound library, after which I will resume work on Universe Storage.
  20. #41
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    65
    Rep Power
    90
    Good to hear it wasn't abandoned.
  22. #42
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Cool 3D Sound Library and Source Code


    Here is the latest version of my SoundSystem, the 3D sound library that provides an easy, common interface for both the lwjgl binding of OpenAL (http://www.lwjgl.com) and the JavaSound API. I've recently added support for MIDI and fixed some random bugs. This will probably be the final update on this library, so I thought I would post a link to it in case anyone is interested in a really easy-to-use 3D sound library for Java:

    -- PREVIOUS LINKS ARE DEAD --

    I am currently finishing up the new SoundManager class, which will make using SoundSystem with jPCT simpler, and handle source management for large numbers of sources. I am having a problem with source management, but after I get that fixed, I will be finished with sound-related stuff and get back to graphics. I am also going to write some tutorials for the sound library, and I'll post links to those when they are finished.
    Last edited by paulscode; September 22nd, 2008 at 09:32 PM. Reason: Links are dead
  24. #43
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50
    I have made some final changes to the SoundSystem, and finished the SoundManager. I still don't like the speed of SoundManager, so I decided to not use source management in my game. SoundSystem handles sources well enough, as long as I keep the number of simultaneous playing sounds to around 32. I created a jPCT-specific version of SoundSystem which has the bind methods from SoundManager, but none of the source management stuff.

    The previous links to the library are dead, so here are the current ones:

    JARS:

    Sound System Version date: September 20, 2008 (download the Source Code)
    The base library used in Sound System jPCT and Sound Manager. It is designed to be an easy-to-use sound library for playing sound effects in 3D space. It provides a common interface to both the lwjgl binding of OpenAL (http://www.lwjgl.com) and the Java Sound API (http://java.sun.com/products/java-media/sound/). This makes SoundSystem compatible on Windows, Mac, and Linux. Currently, .wav, .ogg, and .mid audio formats are supported.

    Sound Manager Version date: September 20, 2008 (download the Source Code)
    Provides a customizable source management capability for cases where there are numerous simultaneously playing sources. The idea behind source management is that closer sources will play while further away ones will be culled. Currently, source-management is quite resource-intensive if there are more than 100 sources are active.

    Sound System jPCT Version date: September 20, 2008 (download the Source Code)
    The jPCT-friendly version of Sound System. Supports binding the Listener to a Camera and Source's to Object3D's. Also has additional methods for moving the Listener and Source's, which take SimpleVectors as parameters.


    Sound System Resources Version date: September 10, 2008
    (Only required for playing MIDI files). Contains a default sound bank (.gm) file to use if one is not already installed on the user's computer. When playing MIDI from within an applet, this JAR must be used unless another sound bank file is specified using the SoundSystemConfig.setDefaultMidiSoundBank method.


    JavaDoc Version date: September 20, 2008
    Includes the classes contained in all three of the above JARs.


    3D Sound with SoundSystem PDF (download the example programs)
    A tutorial-style guide to using the SoundSystem class.


    Demos:

    Sound Effects Player (download the Source Code)
    Demonstrates library switching on the fly, streaming background music, and playing multiple sources simultaneously.

    Holy Bouncing Helicopter Balls!! (download the Source Code)
    Demonstrates the differences between the source-management models in the Sound Manager. Active sources appear red, while culled sources appear grey.

    So moving on from 3D sound, I have decided not to finish the 2D version of Robot Builder, and create the mini-game in 3D instead. That will allow me to get more experience using jPCT before I start programming my RPG. Today I created a 3D robot model. It is rather ugly, but it will work for now. I made an applet to test the robot's inputs and outputs, sound effects, and screen animation, which you can see HERE
  26. #44
  27. Kage Bunshin
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2005
    Location
    The Seven Seas Of Rhye
    Posts
    930
    Rep Power
    423
    Wow, glad to see you are still around. And awesome job!
    "Java makes impossible things possible, but makes easy things difficult." - Somebody
  28. #45
  29. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Fort Meade, MD
    Posts
    170
    Rep Power
    50

    Map Maker


    I have started creating a map maker program. It isn't anything too fancy, just a more visual way to generate ASCII maps for terrain, altitude, and solid objects. So far, it is able to read and write terain and altitude maps. Here are a couple of screenshots:



    These maps were generated programatically, saved, and then loaded from the generated ASCII files. Now what I need to do create some type of GUI for manually editing maps.

    In the above screenshots, I used a 32X32 grid, which is 2048 polys (two triangles per grid square). I can easily change the dimentions of a map if I decide that I want more or fewer polys. You may notice that the terrain looks somewhat faceted in these screenshots. That is because the normals are calculated on a per-square basis, and therefore they do not take into account the adjacent squares. The appearance can be made smoother by recalculating all the normals after the entire map has been loaded. I could also compress the mesh considerably, since each vertice inside the terrain is coppied 4 times. All this "beautification stuff" will be done in the actual game whenever a map is loaded. For the Map Maker program, the faceted look is not really a problem, since I am not going for anything super-professional looking at this point, just functional.

IMN logo majestic logo threadwatch logo seochat tools logo