Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

  • Loading branch information...
commit 571788db6a12b9ecc7554aa9196296e3eb3fb2a6 0 parents
Justin Blake authored May 17, 2011

Showing 33 changed files with 347 additions and 0 deletions. Show diff stats Hide diff stats

  1. 10  .gitignore
  2. 1  .rvmrc
  3. 3  Gemfile
  4. 25  Gemfile.lock
  5. 25  LICENSE
  6. 56  README.md
  7. 1  Rakefile
  8. 89  build_configuration.rb
  9. BIN  lib/java/jme3/jMonkeyEngine3.jar
  10. BIN  lib/java/jme3/lib/eventbus-1.4.jar
  11. BIN  lib/java/jme3/lib/j-ogg-oggd.jar
  12. BIN  lib/java/jme3/lib/j-ogg-vorbisd.jar
  13. BIN  lib/java/jme3/lib/jME3-lwjgl-natives.jar
  14. BIN  lib/java/jme3/lib/jbullet.jar
  15. BIN  lib/java/jme3/lib/jheora-jst-debug-0.6.0.jar
  16. BIN  lib/java/jme3/lib/jinput.jar
  17. BIN  lib/java/jme3/lib/jme3test.jar
  18. BIN  lib/java/jme3/lib/jme3testdata.jar
  19. BIN  lib/java/jme3/lib/lwjgl.jar
  20. BIN  lib/java/jme3/lib/nifty-1.3-SNAPSHOT.jar
  21. BIN  lib/java/jme3/lib/nifty-default-controls-1.3-SNAPSHOT.jar
  22. BIN  lib/java/jme3/lib/nifty-examples-1.3-SNAPSHOT.jar
  23. BIN  lib/java/jme3/lib/nifty-style-black-1.3-SNAPSHOT.jar
  24. BIN  lib/java/jme3/lib/nifty-style-grey-1.0.jar
  25. BIN  lib/java/jme3/lib/stack-alloc.jar
  26. BIN  lib/java/jme3/lib/vecmath.jar
  27. BIN  lib/java/jme3/lib/xmlpull-xpp3-1.1.4c.jar
  28. BIN  lib/java/jruby-complete.jar
  29. 7  src/java/com/mygame/JavaPlayer.java
  30. 67  src/java/org/rubyforge/rawr/Main.java
  31. 3  src/ruby/lib/mygame.rb
  32. 7  src/ruby/lib/mygame/ruby_player.rb
  33. 53  src/ruby/main.rb
10  .gitignore
... ...
@@ -0,0 +1,10 @@
  1
+.DS_Store
  2
+
  3
+# lwjgl natives (automatically added to root directory when loaded by jme)
  4
+liblwjgl.jnilib
  5
+
  6
+# configs created automatically by rawr
  7
+Info.plist
  8
+
  9
+# build files
  10
+package/*
1  .rvmrc
... ...
@@ -0,0 +1 @@
  1
+rvm jruby-1.6.0@jme
3  Gemfile
... ...
@@ -0,0 +1,3 @@
  1
+source :rubygems
  2
+
  3
+gem "rawr"
25  Gemfile.lock
... ...
@@ -0,0 +1,25 @@
  1
+GEM
  2
+  remote: http://rubygems.org/
  3
+  specs:
  4
+    builder (3.0.0)
  5
+    hoe (2.9.4)
  6
+      rake (>= 0.8.7)
  7
+    rake (0.8.7)
  8
+    rawr (1.4.5)
  9
+      rubyzip
  10
+      user-choices
  11
+    rubyzip (0.9.4)
  12
+    s4t-utils (1.0.4)
  13
+      hoe (>= 1.3.0)
  14
+    user-choices (1.1.6.1)
  15
+      builder (>= 2.1.2)
  16
+      s4t-utils (>= 1.0.3)
  17
+      xml-simple (>= 1.0.11)
  18
+    xml-simple (1.0.15)
  19
+
  20
+PLATFORMS
  21
+  java
  22
+  ruby
  23
+
  24
+DEPENDENCIES
  25
+  rawr
25  LICENSE
... ...
@@ -0,0 +1,25 @@
  1
+Copyright (c) 2011, Justin Blake
  2
+All rights reserved.
  3
+
  4
+Redistribution and use in source and binary forms, with or without
  5
+modification, are permitted provided that the following conditions are met:
  6
+
  7
+* Redistributions of source code must retain the above copyright notice, this
  8
+  list of conditions and the following disclaimer.
  9
+* Redistributions in binary form must reproduce the above copyright
  10
+  notice, this list of conditions and the following disclaimer in the
  11
+  documentation and/or other materials provided with the distribution.
  12
+* Neither the name of Hentzia nor the names of its
  13
+  contributors may be used to endorse or promote products derived from this
  14
+  software without specific prior written permission.
  15
+
  16
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  20
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  README.md
Source Rendered
... ...
@@ -0,0 +1,56 @@
  1
+# jMonkeyEngine 3 with JRuby
  2
+
  3
+This is an example/template for game programming using [jMonkeyEngine 3][1]
  4
+with [JRuby][2]. Including multi-platform packaging using [Rawr][3].
  5
+
  6
+[1]: http://jmonkeyengine.com/
  7
+[2]: http://www.jruby.org/
  8
+[3]: http://rawr.rubyforge.org/
  9
+
  10
+The sample code is adapted and expanded from
  11
+[the "Hello SimpleApplication" tutorial on the jme wiki](http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication)
  12
+
  13
+## Important directories:
  14
+
  15
+    jme3-jruby-template
  16
+    |
  17
+    |__lib
  18
+    |  |
  19
+    |  |__java # => Put third-party java libraries here
  20
+    |
  21
+    |__package
  22
+    |  |
  23
+    |  |__classes
  24
+    |     |
  25
+    |     |_java # => Where your own java classes get compiled to
  26
+    |
  27
+    |__src
  28
+       |
  29
+       |__java # => Source code for your own java classes
  30
+       |
  31
+       |__ruby
  32
+          |
  33
+          |__lib # => The bulk of your ruby code should live here
  34
+          |
  35
+          |__main.rb # => The file that actually gets run
  36
+        
  37
+## Running the sample code:
  38
+
  39
+The sample code displays a blue box. You can walk around with the wasd keys
  40
+and look around with the mouse. As an example of mixing ruby and java, it also
  41
+includes code to print messages to the console from a ruby class and a java
  42
+class. See `src/ruby/main.rb` for the juicy details.
  43
+
  44
+First, install [JRuby][1] and [Rawr][3]. I'll leave the specifics up to you,
  45
+but I highly recommend [rvm](https://rvm.beginrescueend.com/).
  46
+
  47
+To run the code directly with jruby:
  48
+
  49
+    rake rawr:compile
  50
+    jruby src/ruby/main.rb
  51
+
  52
+## TODO:
  53
+
  54
+When running the code as a jar or windows/osx executable, it chokes on
  55
+`require "mygame/ruby_player"`. Need to fix that and add packaging to the
  56
+usage instructions.
1  Rakefile
... ...
@@ -0,0 +1 @@
  1
+require 'rawr'
89  build_configuration.rb
... ...
@@ -0,0 +1,89 @@
  1
+configuration do |c|
  2
+	# The name for your resulting application file (e.g., if the project_name is 'foo' then you'll get foo.jar, foo.exe, etc.)
  3
+	# default value: "jruby-test"
  4
+	#
  5
+	#c.project_name = "jruby-test"
  6
+
  7
+	# Undocumented option 'output_dir'
  8
+	# default value: "package"
  9
+	#
  10
+	#c.output_dir = "package"
  11
+
  12
+	# The main ruby file to invoke, minus the .rb extension
  13
+	# default value: "main"
  14
+	#
  15
+	c.main_ruby_file = "ruby/main"
  16
+
  17
+	# The fully-qualified name of the main Java file used to initiate the application.
  18
+	# default value: "org.rubyforge.rawr.Main"
  19
+	#
  20
+	#c.main_java_file = "org.rubyforge.rawr.Main"
  21
+
  22
+	# A list of directories where source files reside
  23
+	# default value: ["src"]
  24
+	#
  25
+	#c.source_dirs = ["src"]
  26
+
  27
+	# A list of regexps of files to exclude
  28
+	# default value: []
  29
+	#
  30
+	#c.source_exclude_filter = []
  31
+
  32
+	# Whether Ruby source files should be compiled into .class files
  33
+	# default value: true
  34
+	#
  35
+	#c.compile_ruby_files = true
  36
+
  37
+	# A list of individual Java library files to include.
  38
+	# default value: []
  39
+	#
  40
+	#c.java_lib_files = []
  41
+
  42
+	# A list of directories for rawr to include . All files in the given directories get bundled up.
  43
+	# default value: ["lib/java"]
  44
+	#
  45
+	#c.java_lib_dirs = ["lib/java"]
  46
+
  47
+	# Undocumented option 'files_to_copy'
  48
+	# default value: []
  49
+	#
  50
+	#c.files_to_copy = []
  51
+
  52
+	# Undocumented option 'target_jvm_version'
  53
+	# default value: 1.6
  54
+	#
  55
+	#c.target_jvm_version = 1.6
  56
+
  57
+	# Undocumented option 'jvm_arguments'
  58
+	# default value: ""
  59
+	#
  60
+	#c.jvm_arguments = ""
  61
+
  62
+	# Undocumented option 'java_library_path'
  63
+	# default value: ""
  64
+	#
  65
+	#c.java_library_path = ""
  66
+
  67
+	# Undocumented option 'extra_user_jars'
  68
+	# default value: {}
  69
+	#
  70
+	#c.extra_user_jars[:data] = { :directory => 'data/images/png',
  71
+	#                             :location_in_jar => 'images',
  72
+	#                             :exclude => /*.bak$/ }
  73
+
  74
+	# Undocumented option 'mac_do_not_generate_plist'
  75
+	# default value: nil
  76
+	#
  77
+	#c.mac_do_not_generate_plist = nil
  78
+
  79
+	# Undocumented option 'mac_icon_path'
  80
+	# default value: nil
  81
+	#
  82
+	#c.mac_icon_path = nil
  83
+
  84
+	# Undocumented option 'windows_icon_path'
  85
+	# default value: nil
  86
+	#
  87
+	#c.windows_icon_path = nil
  88
+
  89
+end
BIN  lib/java/jme3/jMonkeyEngine3.jar
Binary file not shown
BIN  lib/java/jme3/lib/eventbus-1.4.jar
Binary file not shown
BIN  lib/java/jme3/lib/j-ogg-oggd.jar
Binary file not shown
BIN  lib/java/jme3/lib/j-ogg-vorbisd.jar
Binary file not shown
BIN  lib/java/jme3/lib/jME3-lwjgl-natives.jar
Binary file not shown
BIN  lib/java/jme3/lib/jbullet.jar
Binary file not shown
BIN  lib/java/jme3/lib/jheora-jst-debug-0.6.0.jar
Binary file not shown
BIN  lib/java/jme3/lib/jinput.jar
Binary file not shown
BIN  lib/java/jme3/lib/jme3test.jar
Binary file not shown
BIN  lib/java/jme3/lib/jme3testdata.jar
Binary file not shown
BIN  lib/java/jme3/lib/lwjgl.jar
Binary file not shown
BIN  lib/java/jme3/lib/nifty-1.3-SNAPSHOT.jar
Binary file not shown
BIN  lib/java/jme3/lib/nifty-default-controls-1.3-SNAPSHOT.jar
Binary file not shown
BIN  lib/java/jme3/lib/nifty-examples-1.3-SNAPSHOT.jar
Binary file not shown
BIN  lib/java/jme3/lib/nifty-style-black-1.3-SNAPSHOT.jar
Binary file not shown
BIN  lib/java/jme3/lib/nifty-style-grey-1.0.jar
Binary file not shown
BIN  lib/java/jme3/lib/stack-alloc.jar
Binary file not shown
BIN  lib/java/jme3/lib/vecmath.jar
Binary file not shown
BIN  lib/java/jme3/lib/xmlpull-xpp3-1.1.4c.jar
Binary file not shown
BIN  lib/java/jruby-complete.jar
Binary file not shown
7  src/java/com/mygame/JavaPlayer.java
... ...
@@ -0,0 +1,7 @@
  1
+package com.mygame;
  2
+
  3
+public class JavaPlayer {
  4
+  public String greeting() {
  5
+    return "================> Hello from Java!";
  6
+  }
  7
+}
67  src/java/org/rubyforge/rawr/Main.java
... ...
@@ -0,0 +1,67 @@
  1
+package org.rubyforge.rawr;
  2
+
  3
+import java.io.BufferedReader;
  4
+import java.io.InputStreamReader;
  5
+import java.io.InputStream;
  6
+import java.io.IOException;
  7
+import java.net.URL;
  8
+
  9
+
  10
+import java.util.ArrayList;
  11
+import org.jruby.Ruby;
  12
+import org.jruby.RubyInstanceConfig;
  13
+import org.jruby.javasupport.JavaEmbedUtils;
  14
+
  15
+public class Main
  16
+{
  17
+  public static void main(String[] args) throws Exception
  18
+  {   
  19
+    RubyInstanceConfig config = new RubyInstanceConfig();
  20
+    config.setArgv(args);
  21
+    Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(0), config);
  22
+    String mainRubyFile = "main";
  23
+   
  24
+    ArrayList<String> config_data = new ArrayList<String>();
  25
+    try{
  26
+      java.io.InputStream ins = Main.class.getClassLoader().getResourceAsStream("run_configuration");
  27
+      if (ins == null ) {
  28
+        System.err.println("Did not find configuration file 'run_configuration', using defaults.");
  29
+      } else {
  30
+        config_data = getConfigFileContents(ins);
  31
+      }
  32
+    }
  33
+    catch(IOException ioe)
  34
+    {
  35
+      System.err.println("Error loading run configuration file 'run_configuration', using defaults: " + ioe);
  36
+    }
  37
+    catch(java.lang.NullPointerException npe)
  38
+    {
  39
+      System.err.println("Error loading run configuration file 'run_configuration', using defaults: " + npe );
  40
+    }
  41
+
  42
+    for(String line : config_data) {
  43
+        String[] parts = line.split(":");
  44
+        if("main_ruby_file".equals(parts[0].replaceAll(" ", ""))) {
  45
+            mainRubyFile = parts[1].replaceAll(" ", "");
  46
+        }
  47
+    }
  48
+
  49
+    runtime.evalScriptlet("require '" + mainRubyFile + "'");
  50
+  }
  51
+
  52
+  public static URL getResource(String path) {
  53
+      return Main.class.getClassLoader().getResource(path);
  54
+  }
  55
+
  56
+  private static ArrayList<String> getConfigFileContents(InputStream input) throws IOException, java.lang.NullPointerException {
  57
+    BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  58
+    String line;
  59
+    ArrayList<String> contents = new ArrayList<String>();
  60
+
  61
+    while ((line = reader.readLine()) != null) {
  62
+      contents.add(line);
  63
+    }
  64
+    reader.close();
  65
+    return(contents);
  66
+  }
  67
+}
3  src/ruby/lib/mygame.rb
... ...
@@ -0,0 +1,3 @@
  1
+module Mygame
  2
+  # Top-level namespace stuffs...
  3
+end
7  src/ruby/lib/mygame/ruby_player.rb
... ...
@@ -0,0 +1,7 @@
  1
+module Mygame
  2
+  class RubyPlayer
  3
+    def greeting
  4
+      "================> Hello from Ruby!"
  5
+    end
  6
+  end
  7
+end
53  src/ruby/main.rb
... ...
@@ -0,0 +1,53 @@
  1
+require "java"
  2
+require "pathname"
  3
+
  4
+PROJECT_ROOT = Pathname.new(File.expand_path("../..", File.dirname(__FILE__)))
  5
+$CLASSPATH << PROJECT_ROOT + "lib/java/jme3/jMonkeyEngine3.jar"
  6
+
  7
+# Our own java classes will be compiled to this directory.
  8
+$CLASSPATH << PROJECT_ROOT + "package/classes/java"
  9
+
  10
+# Our ruby code will be compiled as java classes here
  11
+$CLASSPATH << PROJECT_ROOT + "package/classes/ruby/ruby/lib"
  12
+
  13
+# Our own ruby code should be under this directory...
  14
+$: << PROJECT_ROOT + "src/ruby/lib"
  15
+
  16
+# ...for example, our ruby player class!
  17
+require "mygame/ruby_player"
  18
+
  19
+java_import com.jme3.app.SimpleApplication
  20
+java_import com.jme3.material.Material
  21
+java_import com.jme3.math.Vector3f
  22
+java_import com.jme3.scene.Geometry
  23
+java_import com.jme3.scene.shape.Box
  24
+java_import com.jme3.math.ColorRGBA
  25
+
  26
+class Main < SimpleApplication
  27
+  
  28
+  # You should be able to use simple_init_app here but it seemed buggy. So stick
  29
+  # with java-style camel-casing when overriding methods defined in jme java
  30
+  # classes. Oh well.
  31
+  def simpleInitApp
  32
+
  33
+    # Draw a blue box. Look around with mouse. Move around with wasd.
  34
+    box = Box.new(Vector3f::ZERO, 1, 1, 1)
  35
+    geometry = Geometry.new("Box", box)
  36
+    material = Material.new(self.asset_manager, "Common/MatDefs/Misc/Unshaded.j3md")
  37
+    material.set_color("Color", ColorRGBA::Blue)
  38
+    geometry.material = material
  39
+    self.root_node.attach_child(geometry)
  40
+
  41
+    # Example of using your own ruby and java classes.
  42
+    # Use include (ruby) and java_import (java) to access without namespaces.
  43
+    java_player = com.mygame.JavaPlayer.new
  44
+    ruby_player = Mygame::RubyPlayer.new
  45
+    
  46
+    # Output will display in the console (not the game window).
  47
+    puts java_player.greeting
  48
+    puts ruby_player.greeting
  49
+  end
  50
+end
  51
+
  52
+main = Main.new
  53
+main.start

0 notes on commit 571788d

Please sign in to comment.
Something went wrong with that request. Please try again.