Archive

Posts Tagged ‘programming’

Scripting iOS games with LUA (lua-wax)

April 6, 2012 Leave a comment

Creating game for iPhone/iPad is one thing, but making it enjoyable is way harder. Most of current games use physics for animation, to make scenes more realistic and not repeatable every time you start the same game level. You can teach your level designer Objective-C to code different behaviors for different things, but the simpler method is to script it in LUA. Lots of previous and today games use this scripting language to describe AI, events and many other things.

I wanted to implement LUA to my upcoming game and found pretty good library called wax. Its pretty impressive. All you have to do is:

#include
- (void) runLuaScript
{
    wax_start("your_script.lua", nil);
}

The problem was that you were unable to execute wax_start() function again (it was possible, but had no effect, script was not executed once again). It lead to big problem, how to load different scripts for different levels? To achieve it you have to clone/fork/download my forked version of wax that fixes that issue.

Steps to do:

  1. You can add my repository as submodule to your XCode workspace by executing command:
    git add submodule git@github.com:zbyhoo/wax.git
  2. Add libwax.a from your workspace to “Link Binary With Libraries” building phase
  3. Finally add “$(SRCROOT)”/wax/lib path (with recursive search) to your “User Header Search Paths” in Build Settings.

Now you will be able to do it this way in your application:

#include
- (void) runLuaScript
{
    wax_start("your_script.lua", nil);
    wax_end();
}

You can call runLuaScript method as many times you want.

Using you Objective-C classes in lua wax is really simple.

-- your_script.lua sample
local my_object = MyObjcClass:init
my_object:someMethod()
my_object:anotherMethodWithArgument("hello")
my_object:oneMoreMethodWithArgument_secondArgument("hello", "lua world")

For more details for lua wax take a look at Wiki page.

UPDATE:
My commits have been pulled to the original repo, so now you can use it instead of my fork.

Code Smells After Reading “Clean Code”

July 27, 2011 Leave a comment

I created projects that I don’t want to look at any more, because of complexity and total mess. You probably heard about “Clean Code” by Robert C. Martin, if not I encourage you to buy this book and read it.

I thought that having technical knowledge is enough to create great applications. It’s not true. Source code is written by developers for developers. Having clean code is one of the most important things in software development. It’s very wide idea but I will write the most important (for me) code smells that I will try to use in my all projects. Read more…

Print TODO/FIXME Comment as Warning in XCode

July 12, 2011 Leave a comment

When I’m implementing new functionality I start with the general design and then I’m implementing newly created classes and methods. Sometimes I leave a method or two for later implementation (i.e. after creating unit test for this method) and almost always putting comment:

// TODO: nice comment here

It already happened to me, that I left this comment unnecessary or (the worst case scenario) I forgot to implement this TODO part 😦 To get rid of these mistakes you can add Run Script phase in Build Phases of your project’s target with some nice shell command. To do this, click on your target, move to Build Phases tab and in right-bottom corner click Add Build Phase and choose Add Run Script. Leave shell as it is and in the content of the script paste following two lines:

KEYWORDS="TODO.*:|FIXME.*:|\?\?\?.*:|\!\!\!.*:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.mm" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
At the end of second line you can add i.e.:
| grep -v ExternalSources
This will prevent from printing warnings for TODO/FIXME comments in file paths containing “ExternalSources”. It’s in case you use third party source code that still needs some work to be done 🙂
The latest revision of this script can be found at my github repository: todo xcode gist
Categories: mac, programming Tags: , ,

Learning Ruby with Project Euler

May 2, 2011 Leave a comment

After completing Ruby Koans it’s time to move forward. Next step is Project Euler. There are plenty of problems to solve, so learning advanced Ruby programming will be neccessary.

I created github project where I will post all my solutions. You can also see this project page on my blog, where I will post updates if any.

Categories: programming Tags: , ,

My old project – Crash3D graphic engine

April 28, 2011 Leave a comment

Today I found one of my really old pojects. It’s 3D graphic engine that I wanted to use during development of my games. I’ve never finished it. I even don’t want to look into the source code any more, because I remember that it was horrible. I was learning C++ back then. First I was writing a code and then thinking about design, and of course no tests at all instead of manual ones (today I have totally different philosophy).

Read more…

Categories: programming Tags: ,

CodeRetreat – TDD and Pair Programming

April 10, 2011 Leave a comment

I thought I know much about Test Driven Development (TDD) and Pair Programming. After attending CODERETREAT organized by Software Craftsmanship in Krakow I know that I was wrong. Theory is something totally different then practice.

This event was facilitated by Corey Haines, one of the inventors of this type of exercise (more info about it at this page). He encouraged us to use four elements of simple design, what really increased code testability and made it readable. He was also giving us really good hints during and between coding sessions. Next day I looked at my current home growth projects and realized how much can be improved there.

Software developer is always learning. When one thinks that he knows enough, he just don’t know that he is wrong and need to learn much more.

Categories: events Tags: , ,

Pitfalls of Object Oriented Programming

April 9, 2011 Leave a comment

Couple of days ago I was at AGH University in Krakow listening to Adam Sawicki’s talk about “Pitfalls of Object Oriented Programming”. This event was prepared by SKN Shader (group of students programming computer games).

Speech was interesting, but really short (1 hour only). Adam was talking about pitfalls we can fall into when over interpreting object oriented programming principles, i.e. wrappers which in the end of the project looks like things that we were trying to wrap, but we failed or usually wrong use of singleton pattern.

One thing really interested me. It was data-driven design. This concept is focused on data processing optimization which is highly used in computer games development (because of this focus on optimization). I don’t know much about it, but for sure its worth reading. Some information you can find on Adam Sawicki’s webpage.

Categories: events Tags: , ,