Lightweight library.(Flower)

A little place to chat about the excellent Hanappe library framework.

Moderators: naturally, seebs, makotok1123

Re: Lightweight library.(Flower)

Postby arreche » Sun Feb 03, 2013 3:42 pm

What about to create a plugins system so people could add a minimal gui, string localization and multi-resolution handling?
arreche
 
Posts: 6
Joined: Wed Jan 09, 2013 7:16 pm

Re: Lightweight library.(Flower)

Postby btatarov » Wed Feb 06, 2013 5:38 pm

Very nice, makotok1123. This small library makes more sense that the bloated thing that RapaNui is. You may not be so good with English but your coding is awesome ;)
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby makotok1123 » Thu Feb 07, 2013 1:59 pm

@arreche
>minimal gui
I will consider.(flower-gui.lua, etc ...)

>string localization
This is a combination of keys and messages.
You do not need anything special.

I want to create a message with a message corresponding to the specified key.
You will be able to respond by switching to each locale, it.

I'm out of scope in Flower.

>multi-resolution handling
This is a very difficult problem.
There is no uniform way.

@btatarov
Thank you. :)


I'm going to add some of the features now.
While maintaining a lightweight library, will provide you with additional modules.

* Class that displays the Android NinePatch
* Display TiledMapEditor(Including Isometric)
* Corresponding to resize the window
* etc
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Sun Feb 17, 2013 7:44 am

Hi there
I've added a few features and improvements.

* Add a NineImage.
* Resize Window.
* Some extensions.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby btatarov » Fri Apr 12, 2013 3:58 pm

Flower screws up the landscape rotation on iPad 1 with iOS 5. Haven't tested on other devices, yet. Here's a sample code:

main.lua
Code: Select all
  1.  

  2. flower = require "flower"

  3.  

  4. math.randomseed( os.time() )

  5. math.random(); math.random(); math.random()

  6. MOAILogMgr.setLogLevel(MOAILogMgr.LOG_NONE)

  7.  

  8. flower.openWindow("test", 1024, 768)

  9. flower.openScene("test_scene")

  10.  



test_scene.lua
Code: Select all
  1.  

  2. module(..., package.seeall)

  3.  

  4. function onCreate(e)

  5.     local layer = flower.Layer()

  6.     layer:setTouchEnabled(true)

  7.     scene:addChild(layer)

  8.  

  9.     local background = flower.SheetImage("sprites.png")

  10.     background:setTextureAtlas("sprites.lua")

  11.     background:setIndexByName('background')

  12.     background:setPos(0, 0)

  13.     background:setLayer(layer)

  14. end

  15.  



Everything works fine until you turn the device around. It resize it to twice the width and 3/4 of the height. I'm checking M.updateDisplaySize now to see if I can find anything.
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby btatarov » Fri Apr 12, 2013 4:12 pm

Actually I'm not sure if it's Flower or MOAI bug because the second I rotate Flower receives width and height reversed. I've followed the steps for landscape mode here: http://getmoai.com/wiki/index.php?title ... OS_Devices

UPDATE: This always happens in Landscape Left (even before I rotate the device). Once it gets screwed it stays that way no matter how I rotate it.

UPDATE 2: Figured this happens even without Flower managing my content. So I dug into the objC code and finally managed to fix it by commenting out the whole updateOrientation () in MoaiVC.mm
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby makotok1123 » Sun Apr 14, 2013 6:51 am

@btatarov
behavior seems to differ in the iPhone and iPad.

When you rotate, iPad is the size of the horizontal and vertical seems unchanged.
iPhone seems to change.

Either way, this problem will be solved by the host.
Android If you should have no problem rotation.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby Vavius » Tue Apr 30, 2013 6:44 am

Hello everyone!
I've just started with MOAI... Now I'm trying to find a suitable higher level framework before implementing my own.
I found Flower is awesome, super-clean code, small, easy to understand.

But I see some critical bugs in flower-samples (which makes me think that I have wrong MOAI version, or something is not right with my environment):
1) Slide transitions are not working. New scene appears on top of old one, then after a moment the old one disappears.
2) Memory leaks. I'm making MOAISim.forceGarbageCollection() and MOAISim.reportHistogram() between scene loads and allocated object count keeps growing when switching scenes.

I'm using Mac OS X 10.8.3 host and Moai 1.4p0.
Vavius
 
Posts: 118
Joined: Mon Apr 29, 2013 6:04 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Tue Apr 30, 2013 9:23 am

@Vavius

Vavius wrote:1) Slide transitions are not working. New scene appears on top of old one, then after a moment the old one disappears.


1.4p0 does not work.
I want you to see the release notes below for details.

https://github.com/makotok/Hanappe/blob/master/NOTES.md

Vavius wrote:2) Memory leaks. I'm making MOAISim.forceGarbageCollection() and MOAISim.reportHistogram() between scene loads and allocated object count keeps growing when switching scenes.


This is why the design of the Flower.
I did not think when close the Scene, that we should discard the module always.
For example, if you want to cache, it may be troublesome is destroyed module.

If you want to eliminate the memory leak, it can be solved by eliminating the reference to the module.
It had adopted this method in Hanappe, but was not adopted in Flower.

Code: Select all
  1.  

  2. function destroyModule(m)

  3.     if m and m._M and m._NAME then

  4.         package.loaded[m._NAME] = nil

  5.         _G[m._NAME] = nil

  6.     end

  7. end

  8.  

  9. destroyModule(require("scenes/test_scene"))

  10.  



https://github.com/makotok/Hanappe/blob ... /Scene.lua
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Tue Apr 30, 2013 11:19 am

@Vavius

Vavius wrote:2) Memory leaks. I'm making MOAISim.forceGarbageCollection() and MOAISim.reportHistogram() between scene loads and allocated object count keeps growing when switching scenes.


For the above, it is to design a memory leak is likely to occur.
Therefore, I have modified to be released at the time of the close of the scene by default.

Please check the latest source.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby Vavius » Tue Apr 30, 2013 12:26 pm

@makotok1123
Thanks a lot, missed that compatibility note =)

makotok1123 wrote:For the above, it is to design a memory leak is likely to occur.
Therefore, I have modified to be released at the time of the close of the scene by default.

Maybe it's an overkill, because caching scene modules is a nice thing and should happen by default. Just adding a method like destroyScene() should be fine.

I will look at scene management tomorrow and try modifying it a bit:
1) Try using just tables, but not modules to define scenes. In order to avoid that unrequire (destroyModule) thing.
2) Make a method to unload scene module from memory. Add new event "DESTROY" for that case

I think, we can create game objects once on module load, and initialize (or reset) them in corresponding events. Scene event can be used like this:
CREATE is for allocating objects.
OPEN is for initializing or setting state and values, scheduling animations, etc.
CLOSE - for canceling update routines.
DESTROY - for final cleanup and dealloc.
Vavius
 
Posts: 118
Joined: Mon Apr 29, 2013 6:04 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Tue Apr 30, 2013 6:34 pm

I'm sorry.
It is hard to tell because it was auto-English translation.

push was also leaked to the master branch.
I will push later.

https://github.com/makotok/Hanappe/blob ... flower.lua

If you make a correction, please pull request in github.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby btatarov » Thu May 02, 2013 2:32 pm

I'm starting my own repository with extensions for Flower that I need for my projects. Feel free to copy and modify freely anything you find useful.

https://github.com/btatarov/flower-extensions

Cheers!
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby makotok1123 » Thu May 02, 2013 11:57 pm

@btatarov
Interesting. :)
I hope that everyone share the library.

About BitmapFont.
I have added a sample of BitmapFont.
Label of Flower can be used BitmapFont.

flower.Label is MOAITextBox.
Can be all things possible in the MOAITextBox.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby btatarov » Wed May 08, 2013 8:06 am

How can I reload the current scene? I know I can do it manually refreshing all the objects but that's too much work. My scene management is 99% consisted of:

Code: Select all
  1.  

  2. flower.gotoScene(sceneName, {animation = someAnimation, second = 1.0})

  3.  



...and I have on each scene:

Code: Select all
  1.  

  2. function onStart(e)

  3.     MOAISim.forceGarbageCollection()

  4. end

  5.  



It works perfectly fine. However if I try gotoScene(sceneX) from sceneX it doesn't work. I tried things like:

Code: Select all
  1.  

  2. flower.closeScene()

  3. flower.openScene(sceneX)

  4.  



..but that doesn't work either. Anyone got a cheap trick to refresh the current scene without too much manual work?
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby Vavius » Wed May 08, 2013 8:38 am

btatarov wrote:Anyone got a cheap trick to refresh the current scene without too much manual work?

Flower does not allow to load current scene again... I haven't look at details of this decision.
For a quick hack you can try switching to dummy empty scene without transition and loading previous scene back =)


I have a problem with fonts. They look blurry and pixelated, like they are at half-resolution.
It happens om Mac and devices. I have tried specifying dpi, but it does nothing.
I'm loading fonts with flower from ttf files.
Well, this can be somehow related to some changes that I made to flower - I'm using fixed sized viewport on any device (320x480) and I've added resource suffixes for dynamic resolution images.

I'll try to make a small repro in an hour or two.
Vavius
 
Posts: 118
Joined: Mon Apr 29, 2013 6:04 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Thu May 09, 2013 10:10 am

@btatarov

1) For garbage collection

Do you that it wants to do the same thing without fail during the transition to the scene?
There are several ways.

* The processing of OPEN_COMPLETE SceneMgr, the CLOSE_COMPLETE event.
* To register the class with customized Scene.

Code: Select all
  1.  

  2. SceneMgr:addEventListener("openComplete", function() print("openComplete")end)

  3. SceneMgr:addEventListener("closeComplete", function() print("closeComplete")end)

  4.  



Code: Select all
  1.  

  2.  

  3. local class = flower.class

  4. local ClassFactory = flower.ClassFactory

  5. local CustomScene = class(Scene)

  6.  

  7. function CustomScene:initListeners()

  8.     CustomScene.__super.initListeners(self)

  9.     self:addEventListener("start", function()

  10.         MOAISim.forceGarbageCollection()

  11.     end)

  12. end

  13. SceneMgr.sceneFactory = ClassFactory(CustomScene)

  14.  

  15.  



2)For information on restarting the scene

Scene to open or close asynchronously.
Therefore, it is not close synchronously.

I think basically, I should have a scene to load.
It's treated with the scene scene even though it has already been closed is not good.

Or, this way any good if load of a simple scene.

Code: Select all
  1.  

  2. flower.closeScene()

  3. flower.callOnce(function() flower.openScene(sceneX) end)

  4.  



However, there is room for this consider design.

* Is asynchronously when accompanied animation
* I want to sync if there is no animation.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

Re: Lightweight library.(Flower)

Postby btatarov » Thu May 09, 2013 3:49 pm

@makotok1123:

Thanks! Your snippets gave me quite a few ideas how to proceed with better scene management because I patched some parts of Flower to suit my needs but there is always some garbage left behind. I may have some thoughts/experience to share later with all of Flower's users. Anyway, thanks again for the ideas. You deserve to be credited for your work so if you send me a PM with your first and last name, I'll make sure to mention you in the credits of my soon-to-be-expected game :)
Unwind... rewind...
User avatar
btatarov
 
Posts: 171
Joined: Thu Sep 27, 2012 4:14 pm

Re: Lightweight library.(Flower)

Postby Vavius » Mon May 13, 2013 1:29 am

There is possibly a bug in flower: Group (MOAIProp) is not added to the layer, but only its children are added.
I was trying to set Group size to some nonzero value to catch touches.
So is it a design decision, or a bug?
Vavius
 
Posts: 118
Joined: Mon Apr 29, 2013 6:04 am

Re: Lightweight library.(Flower)

Postby makotok1123 » Mon May 13, 2013 9:45 am

@Vavius

Not a bug. It is as intended.

Touch event is propagated to the parent from the child.
Subject to touch, must be a subject to be actually drawn.

This structure is required in order to get the Prop from Layer.
If you want to add a Group in the Layer, it will not work properly for several reasons.
makotok1123
 
Posts: 228
Joined: Fri Jan 06, 2012 11:31 am

PreviousNext

Return to Flower

Who is online

Users browsing this forum: No registered users and 0 guests

x