Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify example code and docs.

  • Loading branch information...
commit 2f50eb21141baddb5a38a499a95a9bb55810fb4d 1 parent 4266f19
@blaix authored
View
46 README.md
@@ -9,29 +9,26 @@ with [JRuby][2]. Including multi-platform packaging using [Rawr][3].
## Getting started:
-Take a look at `src/main.rb`. It is heavily commented to the point of absurdity.
-
-It is adapted and expanded from
-[the "Hello SimpleApplication" tutorial on the jme wiki](http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication).
-
-It displays a blue box. You can walk around with the wasd keys
-and look around with the mouse. Hit `ESC` to quit.
-
-As an example of mixing ruby and java, it also includes code to print messages
-to the console from a ruby class and a java class. See `src/main.rb` for the
-juicy details.
+Take a look at `src/main.rb`. It's a port of
+[the "Hello SimpleApplication" tutorial on the jme wiki](http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication)
+with additional code to illustrate using your own ruby and java classes alongside each other.
### Running the sample code:
-First, install [JRuby][1] and [Rawr][3]. I'll leave the specifics up to you,
-but I highly recommend [rvm](https://rvm.beginrescueend.com/).
+The sample code draws a blue box, lets you walk around with the wasd keys,
+look around with the mouse, and hit `ESC` to exit. It also prints some
+messages to the console to illustrate calling your own custom ruby and java
+classes.
+
+Make sure you have [JRuby][1] and [Rawr][3]. I'll leave the specifics up to you,
+but I highly recommend using [rvm](https://rvm.beginrescueend.com/).
To run the code directly with jruby:
rake rawr:compile
jruby src/ruby/main.rb
-You only need the compile step if you have java code under `src` (which we do).
+You only need the compile step if you have java code under `src/java` (which we do).
To package and run the app as a jar:
@@ -43,10 +40,10 @@ To package and run the app as an OS X .app:
rake rawr:bundle:app
open package/osx/jme3-jruby-template.app
-To package and run the app as a Windows exe:
+To package and run the app as a Windows .exe:
rake rawr:bundle:exe
- package/osx/jme3-jruby-template.exe
+ package/windows/jme3-jruby-template.exe
## Important files/directories:
@@ -62,22 +59,17 @@ To package and run the app as a Windows exe:
| |
| |__classes
| |
- | |__java # => *.class files compiled from the *.java files under src/
+ | |__java # => *.class files compiled from the *.java files under src/java
| |
- | |__ruby # => *.class files compiled from the *.rb files under src/
+ | |__ruby # => *.class files compiled from the *.rb files under src/ruby
|
|__src
|
- |__java # => Source code for your java classes
- |
- |__lib # => Source code for your ruby classes
+ |__java # => Your own java source code lives here
|
- |__main.rb # => The file that gets executed on startup
-
-The meat of your app is under `src`. This is where your own ruby and java
-source code lives. Third-party code lives under `lib` (not to be confused with
-`src/lib`), and everything gets compiled to `package` (customizable in
-`build_configuration.rb`).
+ |__ruby # => Your own ruby source code lives here
+ |
+ |__main.rb # => The file that gets executed on startup
## TODO:
View
2  build_configuration.rb
@@ -22,7 +22,7 @@
# A list of directories where source files reside
# default value: ["src"]
#
- #c.source_dirs = ["src"]
+ c.source_dirs = ["src/ruby", "src/java"]
# A list of regexps of files to exclude
# default value: []
View
2  src/java/com/mygame/JavaPlayer.java → src/java/JavaPlayer.java
@@ -1,5 +1,3 @@
-package com.mygame;
-
public class JavaPlayer {
public String greeting() {
return "================> Hello from Java!";
View
3  src/lib/mygame.rb
@@ -1,3 +0,0 @@
-module Mygame
- # Top-level namespace stuffs...
-end
View
7 src/lib/mygame/ruby_player.rb
@@ -1,7 +0,0 @@
-module Mygame
- class RubyPlayer
- def greeting
- "================> Hello from Ruby!"
- end
- end
-end
View
70 src/main.rb
@@ -1,70 +0,0 @@
-# This is what turns on the java magic:
-require "java"
-
-# We're going to add some stuff to the java class path,
-# this constant will make our lives easier.
-require "pathname"
-PROJECT_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
-
-# jme3 provides an "all-in-one" jar that includes all its assets and
-# dependencies. Put it on the classpath and you will have access to everything
-$CLASSPATH << PROJECT_ROOT + "lib/java/jme3/jMonkeyEngine3.jar"
-
-# Our own java and ruby classes (under src) get compiled to these directories:
-$CLASSPATH << PROJECT_ROOT + "package/classes/java"
-$CLASSPATH << PROJECT_ROOT + "package/classes/ruby"
-
-# Ruby's load path isn't as sexy as java's classpath, which means we still
-# need to explicitely require our ruby classes for them to be available (just
-# like vanilla ruby). Our java classes will "just work" (assuming you don't
-# mind typing out the full package name - otherwise you can use `java_import`)
-require "lib/mygame/ruby_player"
-
-# We have access to all the jme3 classes since jMonkeyEngine3.jar is on our
-# classpath. Here we use java_import on the classes we're going to use so we
-# don't have to type out the whole package name every time.
-java_import com.jme3.app.SimpleApplication
-java_import com.jme3.material.Material
-java_import com.jme3.math.Vector3f
-java_import com.jme3.scene.Geometry
-java_import com.jme3.scene.shape.Box
-java_import com.jme3.math.ColorRGBA
-# We could do the same thing with our own java classes if we want.
-# For example: java_import com.mygame.JavaPlayer
-
-class Main < SimpleApplication
-
- # JRuby lets you use ruby-style method names for java methods, which means
- # we should be able to use simple_init_app here, but it seemed buggy. So
- # we should stick with java-style camel-casing when overriding methods
- # defined in jme java classes. Oh well.
- def simpleInitApp
-
- # Draw a blue box. Look around with mouse. Move around with wasd.
- # This is straight out of the first tutorial on the jme3 wiki:
- # http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication
- # but updated to use ruby-style method calls.
- box = Box.new(Vector3f::ZERO, 1, 1, 1)
- geometry = Geometry.new("Box", box)
- material = Material.new(self.asset_manager, "Common/MatDefs/Misc/Unshaded.j3md")
- material.set_color("Color", ColorRGBA::Blue)
- geometry.material = material
- self.root_node.attach_child(geometry)
-
- # Example of using our own ruby and java classes.
- # These are defined under src/java and src/lib
- # I avoided using include/java_import to show the conventional
- # relationship between file paths and namespaces.
- java_player = com.mygame.JavaPlayer.new
- ruby_player = Mygame::RubyPlayer.new
-
- # Output will display in the console (not the game window).
- puts java_player.greeting
- puts ruby_player.greeting
- end
-end
-
-# There is no automatically-executed main method in ruby,
-# so we need to explicitely call .start outside of our class.
-main = Main.new
-main.start
View
51 src/ruby/main.rb
@@ -0,0 +1,51 @@
+require "java"
+require "pathname"
+
+PROJECT_ROOT = Pathname.new(File.expand_path("../..", File.dirname(__FILE__)))
+
+# Load up what we need to run a simple jme3 app:
+$CLASSPATH << PROJECT_ROOT + "lib/java/jme3/jMonkeyEngine3.jar"
+java_import "com.jme3.app.SimpleApplication"
+java_import "com.jme3.material.Material"
+java_import "com.jme3.math.Vector3f"
+java_import "com.jme3.scene.Geometry"
+java_import "com.jme3.scene.shape.Box"
+java_import "com.jme3.math.ColorRGBA"
+
+# Directories containing our compiled classes get added to the class path...
+$CLASSPATH << PROJECT_ROOT + "package/classes/java"
+$CLASSPATH << PROJECT_ROOT + "package/classes/ruby"
+
+# And directories containing our source code get added to the load path...
+$: << PROJECT_ROOT + "src/ruby"
+$: << PROJECT_ROOT + "src/java"
+
+# Use require to pull in our own ruby files
+# and java_import to pull in our own java classes
+require "ruby_player"
+java_import "JavaPlayer"
+
+class Main < SimpleApplication
+ def simpleInitApp
+
+ # The typical "Hello World" jme code, ported straight from:
+ # http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication
+ box = Box.new(Vector3f::ZERO, 1, 1, 1)
+ geometry = Geometry.new("Box", box)
+ material = Material.new(self.asset_manager, "Common/MatDefs/Misc/Unshaded.j3md")
+ material.set_color("Color", ColorRGBA::Blue)
+ geometry.material = material
+ self.root_node.attach_child(geometry)
+
+ # Example of using our own ruby and java classes:
+ java_player = JavaPlayer.new # from src/java/JavaPlayer.java
+ ruby_player = RubyPlayer.new # from src/ruby/ruby_player.rb
+
+ # Output will display in the console (not the game window).
+ puts java_player.greeting
+ puts ruby_player.greeting
+ end
+end
+
+main = Main.new
+main.start
View
5 src/ruby/ruby_player.rb
@@ -0,0 +1,5 @@
+class RubyPlayer
+ def greeting
+ "================> Hello from Ruby!"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.