Translate

Tuesday, November 12, 2013

Spell checking on your Git commits with VIM!


Hey all!  This is a quick tip for all you guys using git version control, and the command line.  Have you wanted to get spell checking into a basic editor but wasn't sure how to get it in vim automatically (but maybe you don't want to enable it in your ~/.vimrc for everything)?

Lucky you, I have an easy solution.  To enable spell checking in vim for all your git commits, it's as easy as one command.  In bash type (or copy paste, I won't tell anyone you dirty cheater):


git config --global core.editor "vim -c \"setlocal spell spelllang=en_us\""




That's all there is to it.  All your commits on all your projects will now use vim with spell check on by default.  That's US English of course, for other languages please substitute your language type.

To get help on spell just type in vim:

:h spell

Here's some basic commands to get you started :

  • ]s next spell error
  • [s previous spell error
  • zg add word to spellfile (correct words list)
  • z= spell suggestions
  • :help spell for more details
So now at least you can look like you care about your commit comments.

Have fun and happy viming and git'ing. :)

Monday, April 22, 2013

Want to help me make Text Message Scheduler work for you?  Please join the discussion on improvements on Reddit!

http://www.reddit.com/r/Android/comments/1crmno/can_i_get_feedback_on_my_text_message_scheduler/

Thanks Guys!

Saturday, April 13, 2013



Hey guys, take a peak at my new Text Message Scheduler app (BETA) and let me know what you think.

https://play.google.com/store/apps/details?id=com.razzlegames.textmessagescheduler

"Remind your husband to deposit that check after work! Ask your wife to pick up some eggs after Billy's soccer practice! You won't have to remember, just schedule it with Text Message Scheduler.

Text message scheduler will allow you to send a text message in the future when ever you want. 1 hour from now a few weeks from now, 10 years from now, TextMessageScheduler doesn't care!

Text Message Scheduler is so easy to use too."

Sunday, February 24, 2013

Arcade Style Physics Monkey Game



Well here's a little progress report on what I am working on. Over the last few months, I have been playing with and learning all the Android quirks, while posting here (as you may see from my previous entries). While doing this I have been active in creating an Android game in my free moments with a pretty simple but fun premise.

  •  Throw projectiles at enemies and kill them 
  • Clear all enemies to end level or free Monkey friend
  • Perhaps avoid hitting some objects (evil monkey, some enemies that multiply if hit ;) )
  • Clear certain blocks to find hidden goodies
  • Obtain all objectives to earn all full credit for level (Bananas? Stars? Dentures? )











Projectiles will be stupid fun, like poop, numbchucks, bombs, kittens, skulls, shoes and anything else I can think up.  I'll make the physics different on each one and try to tie it to the level objectives. 







Angry Birds Clone?


No no, not really.  I really want to get back to the quick play arcade roots with this game.  I want fast paced objectives and decent challenge.  I find Angry birds and all that fun, but quickly too slow and I lose sight of the objectives since the stars don't really have any concreted meaning to me.  Why 2 instead of 3, why 1 what did I do to earn 1 star?  I really never have figured that out on Angry Birds.

This game will have CLEAR goals. The goals will be fast, challenging and I hope, very fun!

So far I have a working framework on Android, graphics and physics (I am leveraging Box2D) as well as some basic goals.  I have a good amount of art completed but still have many more things to create.

I still have a long way to go, many more features add and level editor to tighten up, but I am confident if I have fun playing it, you will too.  And that's my only goal  :)

Friday, January 25, 2013

Tutorial: How to set up Smart Pointers and TR1 C++ in the Android NDK

Optimus prime is a smart pointer.  Memory leaks?! He'll straight up kick you in the throat! This isn't Go Bots son!

What's the point


If you have ever coded in C or C++ you know you've had a memory leak some time or another. Ownership semantics are best, but sometimes those are muddy and, most of the time, the benefit of automatically reclaimed pointers far outweighs any costs (they are not much in terms of resources).

What are smart pointers?  


These are pointer containers/classes with reference counting and ownership semantics built in.  The easiest to understand and use is shared_ptr, which when all references are gone delete's the object from memory, and as expected calls the objects destructor (if it exists). For example if you create a raw pointer in a function (and don't store a reference to it anywhere else)  you would get a memory leak!


void leak_function()
{
  Sprite* sprite = new Sprite();
  // Use sprite

  // After function ends, we forgot to delete sprite :Z
}

But if we were to use a smart pointer, such as shared_ptr, we no longer have to worry about this.

Note, in this case of just using scope this smart pointer is better.

void function()
{
  std::shared_ptr<sprite> sprite =
    new std::shared_ptr<sprite>(new Sprite());

  // Use sprite

  // After function ends, sprite memory is reclaimed
}

So what happened? Once the shared_ptr went out of scope, the shared_ptr's destructor was called and its reference count was decremented.  Since the reference count was zero, it deleted itself.  Yay! Easy right?

Yeah, but it's easy to remember to delete, just do it before the end of the function.

Michael Bolton always forgets mundane details!


Sure, but there are many cases where you might want to pass a reference around to many containers, and you're not quite sure on the life time.  Especially as your project changes, sometimes you can make a mistake and your newest version has a memory leak, simply because you've forgotten some mundane detail . Using smart pointers is a cure for memory leaks (almost).


History of smart pointers in Android


These smart points sound great you say?  Ever wanted to have smart pointers in the Android NDK? How about the tr1 standards in the C++11 aka C++0x features? These features are great, but it has not been easy to get these into Android in past versions of the NDK.  

In past NDKs we would cross compile libboost for Android which contains much of the smart pointer code the TR1 standard is based on. Boost is a *great* library with loads of conveniences.  However to wrestle boost into Android, you would run into a few compile issues here and there and have to do a little exception handling trickery with the boost namespace.



This is a fine solution, using boost etc. However, I am here today to tell you a way to get all the TR1 standard C++ inclusions that are already part of the Android NDK, with no need for a reliance on a ported library. These features are not enabled in most examples you find on the NET. No problem... I am here to tell you how to grab these suckers and put them to work.

Here all the steps needed here to get you to these great C++ conveniences in your Android NDK code.

Steps to add TR1 Support for your C++ Android project:


  1. Open up jni/Application.mk 
  2. Delete or comment out any current definition of APP_STL and replace with:  APP_STL := gnustl_static 
  3. Delete or comment out any reference in Application.mk to stlport_static (you won't need it anymore) 
  4. Update to newer version of NDK without bug noted here
    1. Must be >= ndk 8d . (A bug in earlier versions of gcc in the ndk causes build issues) 
  5. Add #include   to any files that will use shared_ptr. 
  6. Add to Android.mk: LOCAL_CPPFLAGS =: -std=c++0x

Great now how do I use it?


Well for shared pointers all you need to do is #include <memory>   and reference them like so.

(I like to make a type for all my SharedPtrs):

#include  <memory>
// Your other code etc. class Sprite; //  Smart pointer type for convenience typedef std::shared_ptr<sprite> SpritePtr; Now I have a shared_ptr type definition to use like so:
SpritePtr sprite = SpritePtr(new Sprite());

Special tip:


If you have a type that you NEVER want to have a pointer to and force all instances to be in a smart pointer you can do something like this:

class Sprite
{
  // Sprite definition... blah blah

private:
  Sprite(){}

public:
  SpritePtr createSprite()
  {
     return SpritePtr(new Sprite());
  }
};

This forces all users of the class to obtain a smart pointer instance. It does negate any stack creation benefits, however (unless you override new operator etc), but that's not too important in most cases.

So that's it for now folks.  I hope you have fun not having memory leaks in your Android C++ code!

Tuesday, January 15, 2013

Emacs/Vim: Jump to errors for Java and C++ on Android

Any of you guys use vim or emacs to develop Android apps?  I sure do.  No substitute for a good editor.  Only problem is when I am doing NDK code and Java mixed (like so many others who develop games), the editor won't go to the errors in Java code since Ant formats the error output strangely.

Well fear not folks, it is an easy fix.  I usually do all my development in a Makefile that calls ant for the Java stuff and the normal ndk-build for the JNI stuff:

http://code.google.com/p/razzlegames-android-ndk-tutorial/source/browse/trunk/Makefile


You simply add the -emacs option to your ant command.  I personally bind a function key to :make in vim, and have the ant command as one of the default targets.  It ends up being called like this for debug builds:

ant -emacs  debug


Now, with this addition, Vim and emacs will jump to all your NDK and Java errors for Android development.

It's as easy as that folks!  Happy Viming!