New Moai SDK release. 1.4p0

3. March 2013

 

After a 4 month pause, there has been a new Moai release.  They also removed sign up requirements to download the SDK ( which was misleading before, so nice move ) as well as added nightly builds for those that like to walk on the wild side.

 

The biggest new features are android keyboard support ( finally! ), better threading and off screen frame buffering.  The full changelog is below

 

tTerrainMask () to MOAIPathFinder; renamed setTerrainScale () to setTerrainWeight ()
* Some work has been done on threading. Check MOAIThread.
* added support for default texture; finished async load; samples for async texture load
  and default texture
* added support in MOAIDataBuffer to detect zip files, inflate on load; added inflate on load
  support to MOAIDataIOTask
* moai coding style guide in .doc format
* first phase of offscreen rendering architecture completed
* added setClearColor () to MOAILayer
* samples to test multiple viewports inside an offscreen buffer
* integrated sfmt random number generator
* Merged playnomi contribs to MOAIImage, MOAIImageTexture, MOAIParticleSystem and MOAIParticlePexPlugin

 


by Adam Villalobos ( https://github.com/adamvillalobos )
* Adding GCM support ( replacing C2DM ) to Android host.
* Adding file not found log if a texture file fails to load
* Fixing build errors for DataTaskIO
* Fixing issue with setting visibility not properly updating dependencies
* Fixing bug with Font reloading on Android
* Added Android keyboard support

 

by John Copic ( https://github.com/JohnCopic )
* Adding sfmt lib to android build.

 


by JoakimBlomberg ( https://github.com/JoakimBlomberg )
* Script node apply of attributes should unpack attribute id or it will not be applied

 

by Bogdan Tatarov ( https://github.com/btatarov )
* adding MOAIUnitzSound::_getFilename()

 


by mxttie ( https://github.com/mxttie )
* updated box2d physics sample adding mouse manipulation using mouse joint

 


by Tommo Zhou ( https://github.com/tommo )
* fix edge case that new-created-paused action cannot receive further update
* fix: MOAIImageTexture not override OnInvalidate

 


by Antonio ( https://github.com/antback )
* Initial Camera Support for iOS

 


by sporksmith ( https://github.com/sporksmith )
* Log file-open failures

 


by Clement Farabet ( https://github.com/clementfarabet )
* Fixed VSYNC issue for OSX host.
* Added missing files to iOS (XCode) project.

 


by Francisco Tufro ( https://github.com/franciscotufro )
* Several fixes in build systems for all platforms
* New release script in bin/distribute

 


by Stephen Belanger ( https://github.com/Qard )
* Recommended to enable this with C-Ares
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTNOSIGNAL

 


by Ben Borowski ( https://github.com/typeoneerror )
* Adds call to FMOD update to iOS sample project.

 


by Robert Wahler ( https://github.com/robertwahler )
* GlutHost will run "main.lua" if host binary is called without arguments
* add Lua global 'arg' that mimics the lua/luajit built-in global 'arg' to GlutHost

 


by Alexey Zankevich ( https://github.com/Nepherhotep )
* MOAIJsonParser fix - checking if lua number is integer has been added
* Added EVENT_PAUSE, EVENT_RESUME events to MOAISim
* Fixed MOAIEnvironment.screenDpi nil issue for Android
* Fixed MOAIEnvironment.screenDpi nil issue for iOS host

 


by Seebs ( https://github.com/seebs )
* Clarify description of textbox color escapes, fixing one typo and reducing confusion
  between number of bits and number of values represented.
* build.sh: Terser output
* add (untested) support for controlling GL blend equations.

 


by ChairGraveyard ( https://github.com/ChairGraveyard )
* Add support for collideConnected flag to MOAIBox2DWorld::_addRopeJoint
by out-of-pixel ( https://github.com/out-of-pixel )
* Fixed last Key Error from MOAIAnimCurve

 


by superquadratic ( https://github.com/superquadratic )
* Fix Clang 4.2 (Xcode 4.6) Compiler Warnings

 

They also changed the file structure as follows:

bin/ Development binaries for Windows and MacOSX, Linux will be added soon
docs/ Documentation for this release and attribution images
hosts/ Source and IDE projects for the different platform's hosts
include/ Include headers
lib/ Compiled (static and/or dynamic) libraries for all the supported platforms
samples/ Moai SDK feature samples

 

Head on over to the Moai website to download.

News ,




A couple brief Moai tutorials

1. November 2012

 

In the last couple days a few very useful tutorials have shown up on the Moai forums, I thought I would bring to your attention.

 

Resource Manager with Multi-Res support

This is an intermediate level tutorial, as the author suggested, there aren’t actually all that many tutorials serving this skill level.  He has a couple more tutorials in the works, hopefully at the same link.  In the author’s words, this tutorial:

The resource manager that we will be creating will actually be divided into several parts, each adding specific functionality and some really handy features. As far as the application (your game logic) is concerned, there is a namespace called 'ResMan' that provides functions for retrieving any type of data that it needs. This tutorial will start with a simple interface in the ResMan namespace for retrieving images and fonts, as the tutorial progresses the interface will be expanded to include more resource types as well as implement some very handy functionality.

 

 

Extending MOAI Lua host with additional 3rd party libraries

Another slightly shorter tutorial, this one is also at the intermediate level.  In the authors own words:

This is a brief how to which I'm posting here because it might save you 5 minutes (or me 5 minutes if I do this again). Recently I added lua 'bit ops' to the MOAI host so I could have bit flags. It was completely painless and here's a little recipe:

 

Basically it illustrates how to add another lua module to the Moai host, in this case bit ops, very handy.

 

Nice work guys, keep ‘em coming.  I really have to start a new Moai tutorial soon…

Programming , ,




MOAI SDK 1.3r2 released

24. October 2012

 

Zipline just announced a new release of the Moai SDK, 1.3r2.  This release is mostly due to the release of iOS 6 and is a bit of a double edged sword.  What’s the catch you say?

 

Most importantly, we have updated the Moai Xcode project to support Apple's latest Xcode version 4.5 and the iOS 6 SDK. What does this mean for you? The biggest change is that Xcode 4.5 adds support for armv7s and the iPhone 5, but drops support for older armv6 iOS devices, and requires a minimum of iOS 4.3. Apple's armv6 devices include the iPhone 3G and earlier iPhones, and the first two generations of iPod touch devices. The Moai codebase on github can still be used to build to armv6 with previous Xcode versions, but your build flags will need to be reverted to support this.

 

So basically if you are supporting the most popular iPhone (3g), Apple just forked your world up.  You of course can still do it, but you will need to support two toolchains to do so, which sucks.

 

Other details of the release:

-iOS 6 and armv7s support added

-Dropped armv6 support on iOS

-Added setFailOnError method to MOAIHTTPTask to allow getting information from 400+ codes

-Modified MOAITextDesigner's layout behaviour to snap the layout cursor's Y-Coordinate to integer boundaries between lines of text

-Modifed MOAITextDesigner's layout method to snap lines of text to integer boundaries to prevent blurring

-Fixed a buffer overrun issue in Visual Studio 2010

-Fixed 'setLength' function on MOAIBOX2DDistanceJoint

-Fixed a bug with Curl HTTP task resetting on certain calls

-Fixed offscreen buffer ( MOAIFrameBuffer ) clipping bug

-Fixed issue with MOAICpBody not registering MOAITransformBase functions

-Fixed issue with MOAISerializer not handling escaped quotes

-Fixing bug causing '.fnt' file to fail to load if not in the current directory

-Added MOAIBox2DRopeJoint to global Lua class registration

-Added a fill method to MOAIGrid

-Fixed issue with MOAIParticleEmmiter so that it uses the proper location and apply transforms in the correct order

-Fixed a bug with 3d picking

-Added sort modes to propListForRay

 

As I said, mostly all about iOS6.

 

Don’t blame Moai for the lack of Arm6 support, that’s Apple’s boneheaded decision.  If you are willing to forgo iOS6 SDK goodies, there appears to be a way to support arm6 devices in XCode 4.5.  Your actual mileage may vary!

News ,




Using Moai with Chrome ( NaCL ( Native Client ( Inception moment there ) ) )

22. October 2012

This post is going to look at getting your Moai app to run under NaCL, which is Google’s mechanism for allowing you to execute C++ code within Chrome.  There are a number of restrictions, but fortunately Zipline have done most of the hard work for us.

 

Like any other platform, your code is run within a host.  If you are working from the binary ( non-GitHub ) distribution, the host is already built for you and you can skip ahead until you encounter the text “STOP SKIPPING AHEAD!”.  If you are working from Github sources, you need to build the host first.  That is what we are going to do next.

 

Building the Chrome Host

 

First is a matter of locating it.  The source for the NaCL host is located at moai-install-dir/scons/

There are a few things you are going to need to continue…

 

First off, if you haven’t already installed Cygwin, I highly recommend that you do.  The Android  build process basically requires it, so I am going to assume you already have it.  If you don’t, refer to the Android installation guide Cygwin section for details.

You also need to have Python 2.6 or 2.7 installed.  To check, fire up Cygwin terminal and type:

python –V

If you get an error that the command wasn’t found, Python isn’t installed so let’s install it.  The easiest way is to run the Cygwin setup application, then click Next next next until you get to the Select Packages screen.  In the search box enter Python, in the results expand Python and select python: Python language interpreter.

image

Make sure you don’t have any Cygwin Terminal windows open, then click Next and let Cygwin do it’s thing.

 

Now that you have Python installed, we need to download the native client SDK. (That’s the direct download link btw… )

Save it somewhere you can remember.  Open the archive and extract the folder nacl_sdk.  I went with c:\dev\nacl_sdk, but choose whatever you want, just be sure to update your paths accordingly.

Now open a Cygwin terminal window and change in to the nacl sdk directory, which in my case is:

cd /cygdrive/c/dev/nacl_sdk/

Now we want to run the installer/downloader.  In the terminal window type:

./naclsdk update pepper_17

Even though the current version is 22, you need to install 17, as it ships with developer tools Moai depends on.  For some reason, Scons has been removed from future versions.  That is what the above command does, gets and attempts to install pepper version 17.



 

DEALING WITH GOOGLE DEVELOPER TOOLS GOTCHA BELOW!

OK, here’s the thing, we are dealing with Google developer tools, and Google developer tools are always broken in some way, especially on Windows, naclsdk is of course no exception.  After running the above command you will be greeted with the following error:

-------------------------------------------------------------------------------------------------

Updating bundle pepper_17 to version 17, revision 112997
Traceback (most recent call last):
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_main.py", line 759, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_main.py", line 752, in main
    InvokeCommand(args)
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_main.py", line 741, in InvokeCommand
    command(options, args[1:], config)
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_main.py", line 583, in Update
    UpdateBundle()
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_main.py", line 564, in UpdateBundle
    RenameDir(bundle_move_path, bundle_path)
  File "/cygdrive/c/dev/nacl_sdk/sdk_tools/sdk_update_common.py", line 56, in RenameDir
    shutil.move(srcdir, destdir)
  File "/usr/lib/python2.6/shutil.py", line 260, in move
    copy2(src, real_dst)
  File "/usr/lib/python2.6/shutil.py", line 95, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 50, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: u'/cygdrive/c/dev/nacl_sdk/pepper_17_update'

YAY!  Don’t worry, it’s pretty easy to work around.  The installer is trying to execute a program that doesn’t exist, but the installer was downloaded as part of the above process.  Go in to the folder sdk_cache and locate the file naclsdk_win.exe and run it.  When prompted for an install path, install it to your NACL_SDK folder/pepper_17.  In my case that means C:\dev\nacl_sdk\pepper_17

Now we need to set an environment variable with the path to the NACL SDK.

setx NACL_SDK_ROOT /cygdrive/c/dev/nacl_sdk

Keep in mind, the setx command requires administrator rights, so be sure to run your cygwin terminal as administrator if you aren’t already.

Now the bummer part, exit and restart Cygwin terminal, system level environment variables don’t take immediate effect.

 

Are we there yet? Nope… it’s FMOD install time

Close… one more dependency left… FMOD.  FMOD is a commercial audio system ( AKA, if you ship a product, you’ve got to pay to use it ).  With most of Moai, you can get by using the free Untz audio system, but with NaCL, FMOD is required.  So you either have to gut the FMOD library from the build dependencies or download and configure FMOD.  I’ve opted for the second ( audio is after all, kind of nice! ), but either option is open to you.

Head on over to the FMOD download page and download the archive for FMOD for Google Native Client. Unfortunately you need to download a version that supports the same Chrome version as Moai (17).  The following direct link will download the correct version. (Direct linkIT IS VERY IMPORTANT YOU DOWNLOAD THIS VERSION…. just so you know.

Save and extract that archive somewhere.  This file is a tar.gz, so if you are using a program such as 7zip, you need to extract it, then extract the file you just extracted.  I took the resulting folder, renamed it fmodchrome and copied it to c:\dev\.  The resulting directory should look like:

image

Now we need to set yet another environment variable, one named FMOD_CHROME_SDK_ROOT and pointing at this new directory.  Once again in Cygwin terminal type:

setx FMOD_CHROME_SDK_ROOT /cygdrive/c/dev/fmodchrome

Once again, you need to exit and restart Cygwin terminal for this variable to take effect.

 

It’s building time!

 

At this point in time, there seems to be a problem with the scons build script so that the paths ../3rdparty and ../src aren’t working, at least, not on Windows.  The following is a brutal hack, and I will post a better solution when I come up with it.  For now, we simply copy all the source into the scons folder.  Copy the contents of [moaifolder]/src, [moaifolder]/3rdParty and [moaifolder]/scons/src to the scons directory.

Now cd in to the maoi scons directory, on my pc /cygdrive/c/dev/moai-dev/scons and run

./build.sh

Hopefully all went well.  If you get errors… something didn’t go so well… if you want, just skip ahead and download the version I compiled.  You only really need the build process working if you intend to alter the host.

 

Now copy the following files to a new folder:

moai.nmf

moai_x86_32.nexe

maoi_x86_64.nexe

 

This is your Moai Host ready to go. 

 

If for some reason you couldn’t get your host to build, you can download mine.

 

STOP SKIPPING AHEAD!

 

Packaging your app to run in Chrome

Now you need to package your application up into Chrome friendly goodness.  The steps are fairly straight forward

In the folder you copied the .nmf and .nexe files, create a new file called manifest.json here is what I put in mine:

manifest.json

{
    "name":"moai",
    "version":"42",
    "app": {
        "launch": {
          "local_path": "moai.html"
        }
      }
}

Now you need an html file to actually host your application. As you probably guessed by the manifest file, I called mine moai.html:

moai.html

<!DOCTYPE html>
<html>

<head>
<body>
  <title>Hello Moai!</title>
  <div>
    <embed name="nacl_module"
           id="moai"
           width=480 height=320
           src="moai.nmf"
           type="application/x-nacl" />
  </div>

</body>
</html>

Finally you need your Moai application ( the lua bits ).  Just copy your project sources into the same directory, just be sure a file is called main.lua, this is your app entry point and will automatically be called the the host.  Here for example is my folder:

image

I simply grabbed the sources from this tutorial.

 

 

Configure Chrome to run your app

Now you need to let Chrome know you want to enable NaCL applications.  In Chromes location bar enter chrome://flags, the following window should appear.

image

Scroll down and enable Native Client as shown by the arrow. You need to restart Chrome for this to take effect!

So, um, restart Chrome.

 

Now you need to add your application.  To do this, in Chrome, drop down the Menu and select Tools->Extensions.

 

image

In the resulting window, enable Developer Mode, then click Load unpacked extension…

 

In the browse dialog, navigate to the folder you’ve saved everything in then click OK.

image

 

Your extension should now be installed.  Launch a new tab ( CTRL+N ) in Chrome, and at the bottom of the screen, select Apps

image

 

Your app icon should appear on the page:

image

 

Click it.

 

Voila, a Moai application running in Chrome:

image

 

Enjoy.

Programming , , , ,




Moai soft keyboard for Android now available

12. October 2012

 

If you followed my Moai tutorial series, you may recall in this post I mentioned that Android keyboard support currently didn’t exist, although there is an effort underway to fix that.  Well, a user over on the Moai forums got sick of waiting and implemented a soft keyboard using MoaiGui, which I covered in this post.

 

It is written as a Lua module and the only dependency is you need to pass in your Moaigui object.  Here is the code:

--utility function
function distance ( x1, y1, x2, y2 )
        return math.sqrt ((( x2 - x1 ) ^ 2 ) + (( y2 - y1 ) ^ 2 ))
end

k = {}

local kboard = nil
local keysWide = 1
local keySize = 5
local boardHeight = keySize
local left = 50 - keySize/2
local top = 100
local xpos = left
local ypos = top
local rowCount = 0
local speed = 1000
local textbox = nil

--release all gui objects
k.destroyKeyboard = function (self, gui)
        if kboard ~= nil then
                for k, v in pairs(kboard) do
                        gui:destroyWindow(v)
                end
                kboard = nil
        end
end

--setup a new keyboard, starting with only 1 row
k.createKeyboard = function (self, gui, charsWide)
        if kboard ~= nil then destroyKeyboard(gui) end
        kboard = {}
        keysWide = charsWide
        boardHeight = keySize
        left = 50 - keySize*charsWide/2
        xpos = left
        top = 100
        ypos = top
        rowCount = 0
end

 

local function keyClick(event, data)
        --give focus to selected textbox so that it receives the keypress
        if textbox ~= nil then data.g:setFocus(textbox) end
        --pass keypress to gui
        data.g:injectKeyDown(data.character)
        data.g:injectKeyUp(data.character)
end

 

k.addKey = function (self, gui, char)
        if kboard == nil then return end
        --empty string indicates skipping a key slot
        if char ~= "" then
                kboard[char] = gui:createButton()
                kboard[char]:setPos(xpos, ypos)
                kboard[char]:setDim(keySize, keySize)
                kboard[char]:setText(char)
                data = {}

                data.g = gui
                if char == "<" then
                        data.character = 8 --backspace
                else
                        data.character = string.byte(char) --ascii value of character
                end

                kboard[char]:registerEventHandler(kboard[char].EVENT_BUTTON_CLICK, nil, keyClick, data)
        end
        --increment to next key in row
        rowCount = rowCount + 1
        xpos = xpos + keySize
        if rowCount >= keysWide then
                --new row
                xpos = left
                ypos = ypos + keySize
                boardHeight = boardHeight + keySize
                rowCount = 0
        end
end

 

--moves the key to its place at the bottom of the screen (or off the screen if show=false).
--NOTE: only returns once the move has finished
local function moveKey(key, show)
        local x, y = key:getPos()
        --move onto the screen
        local newy = y - boardHeight
        --move off the screen
        if not show then newy = y + boardHeight end
        --not really the best way of getting the target location, but the easiest/quickest solution
        key:setPos(x, newy)
        local tx, ty = key._rootProp:getLoc()
        key:setPos(x,y)
        --calculate a travel time relevant to the distance being traveled
        local travelTime = distance(x, y, x, newy) / speed

        MOAIThread.blockOnAction(key._rootProp:seekLoc(tx, ty, travelTime, MOAIEaseType.LINEAR))
        --the seekLoc only moves the prop, the prop container is not aware of the move, so tell it.
        key:setPos(x, newy)
end

 

--moves all keys to the desired location
k.showKeyboard = function (self, gui, show)
        if kboard == nil then return end
        --only need to pass in show when you want to hide the keyboard
        if show == nil then show = true end
        for k, v in pairs(kboard) do
                --move keys in separate threads
                MOAIThread.new():run(moveKey, v, show)
        end
end

 

k.hideKeyboard = function (self, gui)
        self:showKeyboard(gui, false)
end

k.setTextbox = function(self, tbox)
        textbox = tbox
end

return k

 

 

And here is some code demonstrating the keyboard in action:

 

local kb = require "keyboard"

kb:createKeyboard(gui, 11)
keys = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<",
        "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "",
        "", "a", "s", "d", "f", "g", "h", "j", "k", "l",  "",
        "", "", "z", "x", "c", "v", "b", "n", "m"}
for k, v in pairs(keys) do
        kb:addKey(gui, v)
end

kb:showKeyboard(gui)

local editBox = nil
local function handleEditBoxGainFocus(self, event)
        self._cursorPos = #self._internalText + 1
        self:_addCursor()
        kb:setTextbox(editBox)
        return self:_baseHandleGainFocus(event)
end

editBox = gui:createEditBox()
editBox :setPos(40, 30)
editBox :setDim(20, 5)
editBox :setText("")
editBox ._onHandleGainFocus = handleEditBoxGainFocus

 

 

None of this code is mine, all of the credit goes to lancew over on the Moai forums.  The only thing I have done is slightly changed the formatting to make it a bit more legible. You can read the original thread right here.

 

Great work Lance!

Programming ,