The Big Refactor

Just thought I would make a quick post about what I'm doing. I have decided to rewrite/refactor all of Lime. My plan is that the front facing API/LDI won't actually change so that you are able to drop the new code right into your project and keep going with it. There will be a couple of very small changes but it will be pretty much the same.

The main reason for this big change is that I hope the restructure (and more importantly the different OOP method) will save some memory to help speed everything up. However if this doesn't actually speed things up I will still have a much better organised codebase, rather than the monster that it is now, which will allow for easier debugging and adding of new features.

I hope to have a workable version of this by tomorrow for anyone that wishes to try it.

wow, by tomorrow? You are one lean mean coding machine. Refactoring is always a big deal for me because in the it will have to work the same way as before or better.

Care sharing your plans? Perhaps the hive mind can help you out here and there.

The faster I get it done the faster you guys can tell me what I've broken :-) And what else do I have to do, apart from my job and other projects :-)

The main difference is how I handle objects (not in the Tiled sense, the OO kind)

In the current version of Lime I create my objects pretty much like this:

1
2
3
4
5
6
7
8
9
10
11
function newObject()
 
    local self = {}
 
    function self:sayMessage(message)
        print(message)
    end
 
    return self
 
end

yeah that's the way to do OOP in Lua, metatables.

I can see how that will cut down the memory usage though I am not sure about the performance, are you displaying each tile as tile objects in the current design?

PS: Lime forum is gone. Might want to check with Corona about that

Not sure how I overlooked them before, however I am new to Lua so I will blame that :-)

Yup, each Tile created in the current version is an object of the first type detailed above. So is a Map, TileLayer, ObjectLayer, Object and Property :-) Doing it the new way should help I hope.

I have the first version ready, it is just the visual stuff right now, no physics stuff. Camera stuff isn't in yet either.

I'm not sure how I will sort out the versioning of this though just until it becomes the real version. Should it be Beta2.1 or something else?

The forum seems to be here now, may have been a mistake when they reshuffled things.

- Edit -

Physics is now in.

As I now have a version working with visuals and physics I figured I'd make a quick build and test it out on my device (a 2nd gen iTouch). And the results are...less than exciting :-(

It is still unbearably slow on the device, but this still doesn't have any visual/physical clipping going on which I do think will be the biggest speed boost.

On the plus side my code is much more organised now, which makes it all easier to understand for both myself and anyone else that is unlucky enough to have offered there assistance in fixing the speed issues :-)

It's 4am now so I guess I should go to bed, got to start the "day-job" in a few hours but after that I plan to keep bringing over the rest of the features so that this will be the de-facto Lime beta version.

good work Graham!

here's some stuff about private & static variables etc in Lua if that's any use

http://developer.anscamobile.com/forum/2010/11/09/modules-vs-classes

regards
j

I like the look of the private variable container :-)

Also, do you happen to know if there is a way of using .net style properties in Lua? I'm guessing not so on the other hand is there a way of setting a public read-only variable?

i'm not sure getters/setters exist.. you may have to define a public function to a private variable

ie getX()

have a read through these though

http://lua-users.org/wiki/ObjectProperties
http://www.bresciascienza.it/erix/progutil/gpeddler2/help/oo.html
http://lua-users.org/wiki/MutableFunctions

the first link does seem to use it like a setter ie .color = "blue" which runs a function color(self, value)

j

that MiddleClass.lua looked quite good
https://github.com/kikito/middleclass/wiki/Private-stuff

it's got mixins, inheritance etc

j.

That looks really impressive, especially for so few lines of code. Good find :-)

I'm fairly confident that the whole API is now supported and hopefully working. Famous last words.

I currently haven't included Parallax or Berries as I wanted to sort those out anyway.

Wow. I was down with flu for a couple days and the whole world has changed in that time! Thanks for all your hard work. Look forward to trying this new version.

Hope you're feeling better!

I have this new version ready to upload for testing however I'm not sure what to do about version numbers. Should this be Beta 2.1? Or Beta number 2, version 1.

I am hesitant to call it version 2 actually, it infers that there is already a version 1 in production.

Thanks. Still not 100% so take the rest of this post with a grain of salt!

Why not continue on with the 19, 20, 21 approach? Until you open up beta we can call these alpha versions if you like. When you reach the stage where you are comfortable with an open beta then you can reset the numbering to something like Beta 1, beta 2 etc.

Look forward to trying this new version.

I will go with 2.1 :-)

And here it is - http://www.justaddli.me/downloads/builds/beta/LimeBeta2.1.zip

Please keep a backup of your project in the 2.0 stage in case it all explodes going to 2.1

In theory near everything is the same, however a few places have changed ever so slightly that they may cause some problems.

Please just post here whatever problems you come up against and I will sort them out as soon as I can.

Ah where has all the delicious names gone? ;-)

That indeed was a sad (and very hard) decision.

I decided that at somepoint I would run out of fruit names (apparently Apple might already be taken) so it was better to cut my losses now and this way everything is easier to look at. For the curious, pretty much everything in Map, TileLayer, ObjectLayer, Tile, Object and TileSet was all in Lychee. As you can imagine, that was quite a bit :-)

Plus looking at the code when fixing bugs just made me hungry.

@GrahamRanson i would love to talk to You about OOP implementation in Corona. I have started a thread about it here: http://developer.anscamobile.com/forum/2011/01/21/oop-game-classes-objects-inheritance-methods-properties#comment-17770
and @jmp909 pointed me to this thread. How can i contact You?

Hey Piotr, feel free to email me at graham AT grahamranson DOT co DOT uk

@GrahamRanson Thank You. I will contact you after my "day job"

my corona forum username @ hotmail dot com

views:1820 update:2011/10/13 16:39:51
corona forums © 2003-2011