Showing posts with label nme. Show all posts
Showing posts with label nme. Show all posts

Saturday, April 12, 2014

RealBengine - When Bengine Goes to Real 3D

This maybe the future version of my voxel based rendering engine Bengine, code name "RealBengine". Different from the current version of Bengine, which use ray-casting and is 2.5D, RealBengine will use ray-tracing and hence you will have 6 degree of freedom instead only 4. That means you can look up and down freely without any limit. The current version of Bengine can simulate look up and down a little bit using the distorted projection trick, but this is very limited - about +/-30 degree rotation around the X-Y plane at most. What's more, in RealBengine, you're working with real 3D, so most of the algorithm has been simplified because now you're using 3D vectors rather than fake 3D trick math.

And because of the essential difference in the rendering core, RealBengine will be a totally different engine and will be written from scratch in the future. However, RealBengine is not my priority for now. A similar example with source code using ray-tracing for voxel rendering can be found at:
http://bruce-lab.blogspot.com/2011/08/simple-ray-tracing-voxel-demo.html



An old working demo of RealBengine(Win32 binary):
https://drive.google.com/file/d/0B5V2PrQ8xX_EaEZ0ai1hblMwZGc/edit?usp=sharing

This demo was written in HaXe/NME and compiled to the CPP target some time ago. This is just a simple quick proof of the ray-tracing voxel rendering algorithm. The demo needs optimization as it is slow (about 10~15 FPS in my test). A Flash/SWF version exists but too slow now.

Sunday, March 24, 2013

Fast way for per pixel bitmap manipulation in HaXe NME

I'm not sure whether this is the fastest way, but the nme.Memory API is something you must know for per pixel bitmap manipulation in NME. I learned the method from the stackoverflow thread here:
http://stackoverflow.com/questions/10157787/haxe-nme-fastest-method-for-per-pixel-bitmap-manipulation
nme.Memory support both flash and cpp targets. For flash, it use the Alchemy fast memory opcodes which can greatly boost the speed.

I ported Ralph Hauwert's Alchemy lookup-table effects to NME as a simple example for showing you how to use nme.Memory API for per pixel bitmap manipulation.

The basic idea is to do everything using a ByteArray. Create a ByteArray to hold your screen buffer, select it and use the getI32/setI32 function of the nme.Memory API. One problem is when you need to use extra data, such as some texture buffer in the process, you may need another ByteArray to hold your data. Because "selecting different memory blocks in cycles may lead to a performance loss", as stated in the API's docs, the simple trick is to create a single ByteArray as the virtual RAM, and write everything into it, while store the different position variables of the data block for later use.

In my example, I use the first part of the virtual RAM ByteArray for screen buffer and the next part for holding the texture. So you can just use the "select" function only once and then get/set values from different data blocks by the position variables you stored as the offsets of the virtual RAM's addresses.

Source Code of the example:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HXFastBitmapData
Binary:  
(Win-32)https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HXFastBitmapData/bin/w32-bin.zip
(Flash)https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HXFastBitmapData/bin/HXFastBitmapData.swf 

For pure AS3 projects, the Azoth tool also provides similar memory API for utilizing the Alchemy opcodes. If you don't want any Alchemy opcodes, you may try Vectors in AS3.

Update 2013/04/11: ASC2 now supports using fast memory opcodes in AS3.
Update 2013/05/08: Only AIR SDK 3.6 support those fast opcodes, the latest SDK 3.7 won't compile. You can download the SDK 3.6 here:
http://helpx.adobe.com/air/kb/archived-air-sdk-version.html
http://helpx.adobe.com/flash-player/release-note/fp_116_air_36_release_notes.html

Update 2013/05/07: This method also works on Android platform:
Try this pre-build apk:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HXFastBitmapData/bin/HXFastBitmapData-debug.apk

Note: When compiling for Android, run "nme setup android" first, you will install Android SDK, Android NDK, Apache ANT and Java SDK.Then open Android SDK manager and install Android 2.2 (API 8), otherwise you may encounter the "Unable to resolve target 'android-8'" problem:
http://www.nme.io/community/forums/installing-nme/unable-to-resolve-target-android-8/

Links:
http://haxe.org/api/flash/memory
http://www.nme.io/api/types/nme/Memory.html
http://stackoverflow.com/questions/10157787/haxe-nme-fastest-method-for-per-pixel-bitmap-manipulation
FlasCC version of the example: http://bruce-lab.blogspot.com/2012/12/migrating-from-alchemy-to-flascc.html
http://philippe.elsass.me/2010/05/as3-fast-memory-access-without-alchemy/
Compile AS3 Fast Memory Opcodes by ASC2:
http://obtw.wordpress.com/2013/04/03/making-bytearray-faster/

TIPS: There is no good tools for auto-formatting HaXe source code as far as I know. (FlashDevelop only supports AS3 formatting.) So I use Emacs. First rename the XXX.hx file to XXX.java, open it in Emacs, C-x h (M-x mark-whole-buffer) C-M-\ (M-x indent-region), rename it back to XXX.hx, that's it.

Thursday, August 2, 2012

Haxenme Installation Notes

1. Download the standalone installation package NME-3.4.0-Windows.exe at
http://www.haxenme.org/download/
(Haxe [2.10], Neko [1.8.2], NME [3.4.0], HXCPP [2.10], Actuate [1.43], SWF [1.13])

2. Click and run to install.
(2013/3/15:
Tips: For updating NME from an older version, the simplest way is to download the new setup package, and reinstall. Uncheck the things that are already newest here, e.g., Haxe, Neko. Then select the same folder of the old installation.
http://www.nme.io/community/forums/feature-requests/eficient-way-to-upgrade-nme/)





3. Setup HaXe:
Go to D:\Motion-Twin\haxe, run haxesetup.exe


Done! Now let's test it.

4. Go to cmd:
haxe

nme


5. Now download the sample file at
http://www.joshuagranick.com/blog/2012/02/22/nme-game-example-pirate-pig/
to test.
Unzip the source code "jgranick-PiratePig-9deb597.zip" to D:\TEST_PROJECTS\jgranick-PiratePig-9deb597.
cmd commands to build the swf:
cd D:\TEST_PROJECTS\jgranick-PiratePig-9deb597
nme test "Pirate Pig.nmml" flash


and to build html:nme test project.nmml html5


6. Use Flashdevelop for nme projects. (You should install Flashdevelop at http://www.flashdevelop.org/ first)
Open Flashdevelop and configure haxe path:

Open "Pirate Pig.hxproj" and build the project:


7. To use haxecpp target windows, you need to install VC++ (nme setup windows) at
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express first.
After that
cd D:\TEST_PROJECTS\jgranick-PiratePig-9deb597
nme test "Pirate Pig.nmml" cpp

Friday, March 23, 2012

Simple Tutorial for using MochiAds with HaXeNME

HaXeNME (http://www.haxenme.org) is an open source, cross platform haxe lib for developing games using a Flash like api. Just try it if you don't know it. If you hope to write once and compile to flash/html5/cpp/ios..., HaXeNME should be your first choice. I never tried to use mochiads with haxenme, though I know it is totally possible. Since some one PMed me for this topic, I did a quick research and want to share it here as a reminder for future reference.

Note: this is not a detailed step-by-step tutorial for newbies, just a reminder. I assume you have some experience of developing with HaXeNME using FlashDevelop (http://www.flashdevelop.org). However, if you have problems, feel free to post it here below.

The general steps for using mochiads with HaXeNME:

1. Download mochi api source code and compile all the AS3 source files into a "mochi.swc", unzip the swc file, rename the "library.swf" to "mochi.swf".

2. Generate the haxe source files needed for compiling your NME project:

haxe.exe -swf mochi.swf --no-output -swf-lib mochi.swf --gen-hx-classes 
Copy the genetated "mochi" folder (in its "as3" subfolder you should find lots of haxe files, such as "MochiAd.hx", "MochiCoins.hx", ...) into your project's "src" folder.

3. Import the mochi apis in your haxe project's main class:
import mochi.as3.MochiAd;
import mochi.as3.MochiServices;
To show pregame ads, for example, using the following code, similar to AS3:
MochiServices.connect("60347b2977273733", root);
MochiAd.showPreGameAd( { id:"60347b2977273733", res:"640x580", clip: root} );

4. Edit your project's "application.nmml", add the following line to force the haxe compiler to link "mochi.swf":
<compilerflag name="-swf-lib yourpath/mochi.swf"/>
Make sure the path to "mochi.swf" is correct.

5. Compile your project, that's all.
(Besides, you can use other swf libs with haxenme similarly.)

Full source code of my test project:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HaXeNME MochiAds Test
And the demo swf proving it works:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HaXeNME MochiAds Test/bin/flash/bin/HaXeNMEMochiAdsTest.swf 

Links: 
1. NMML File Format: http://www.haxenme.org/developers/documentation/nmml-project-files/
2. http://haxe.org/doc/start/flash#using-the-library
http://www.alexjeffery.org/programming/how-to-embed-a-swf-file-in-haxe/
http://wootfu.com/2011/08/using-mochiads-with-haxe/
http://brianin3d.wordpress.com/2010/08/04/kit-kat-toe-mochiads-with-haxe/

Tuesday, January 4, 2011

Ken Silverman's GROUFST2 Terrain Raycaster Ported to AS3


Simple nice heightmap terrain raycaster, a good start for your own voxel engine.
Fork it here:
http://wonderfl.net/c/7d41
or
http://flaswf.googlecode.com/svn/trunk/GROUFST2/
==========
Update: April, 4,2011
GROUFST2 Ported to HaXe(Supporting targeting swf and cpp both):
Source Code: https://flaswf.googlecode.com/svn/trunk/GROUFST2/Groufst2HXNME
==========
Update: 11, 11,2011
Add HTML5 support:
Source Code: https://flaswf.googlecode.com/svn/trunk/GROUFST2/Groufst2HXNME/Groufst2NME_HTML5/
DEMO:  https://flaswf.googlecode.com/svn/trunk/GROUFST2/Groufst2HXNME/Groufst2NME_HTML5/Export/html5/bin/index.html (Very, very slow.)
==========

Original source code can be found at Ken's website:
Qbasic: http://www.advsys.net/ken/voxlap.htm (GROUFST2.BAS)
EVALDRAW: http://www.advsys.net/ken/download.htm (evaldraw.zip\demos\groufst2b.kc)

And

Happy Coding 2011!

Sponsors