[OLPC-Games] KuKu refactor for decreased playtime lag

Julius B. Lucks julius at younglucks.com
Sun Aug 19 10:29:24 EDT 2007


Hey Chris,

That's awesome!  I have been refactoring some of the backend of kuku,  
but have not touched the main event loop yet - hence the current  
version in the main branch of the git repo is out of date of the xo  
that is on the wiki.  There is a branch called trial-2 in the git  
repo which contains code that should be very similar to the posted xo  
file.  You should be able to see it in the cloned repo by doing 'git  
checkout -b my-trial-2 origin/trial-2'.  (Also see http:// 
wiki.laptop.org/go/Kuku/Git_Usage)

The only changes I have done to the main kuku.py file have to do with  
import statements and pulling out some class definitions due to my  
module refactoring.  The best way to create a patch would be to do  
the following with git (sorry if you know this git stuff already).

git clone (kuku repo url)
git checkout -b kuku_patch_branch
(port your patch to kuku.py)
git add kuku.py
git commit
git format-patch master..kuku_patch_branch

That should create a file called 0001_my-commit-message.patch.  You  
can send the patch to the list and I'll apply it and check it in.  If  
you have set your git config variables with your name and email, it  
will commit it as you when I apply the patch.

Right now there are no tests for the kuku.py, but there are some for  
the other modules (like Tile and Grid).

This is really exciting and I'm stoked that you did this.  Note that  
there is a lot of refactoring work that needs to be done including

* update wrapper code to use the Lincoln Quirk's git repository
* refactor widgets._ScreenWidget using pygame.Sprite
* unit tests for question.py in test_question.py
* refactor Scenario out of kuku and unittest
** The Scenario should take control of the pygame loop and hand  
control back
*** this would handle animations in the middle of the game to support  
a storyboard
** rewrite game_over, game_win, game_start, reset_board, etc. in  
terms of Scenarios
*** add more unit-tests before do this
* factor State out of kuku and unittest
** state should be expanded to allow multiplayer mode
* factor Actor and Player out of kuku and unittest
* fator QuestionAnswer out of kuku, rename and unittest
* move initialization out of kuku.py
* refactor tile and grid with pygame.Sprite classes

I'll be on IRC later today (Sunday) around 5 or 6ish sitting in #olpc- 
content as jblucks if you want to chat about the patch etc.  Please  
feel free to keep refactoring away - the next major step will be to  
add collaboration to kuku which should start with refactoring the  
State class out of kuku.py.

And please put your name up on the wiki page as a contributor!

Cheers,

Julius

------------------------------------------------------------------------ 
---------------
Please Reply to My Permanent Address: julius at younglucks.com
http://www.openwetware.org/wiki/User:Julius_B._Lucks
------------------------------------------------------------------------ 
----------------



On Aug 19, 2007, at 4:20 AM, Christopher Schmidt wrote:

> KuKu currently lags significantly when using the arrow keys. With a
> little bit of profiling and refactoring, I was able to decrease the
> level of CPU time used by KuKu by a factor of 2 on my mac.  
> Essentially,
> only changed pieces of display are updated, rather than the whole grid
> being updated every loop through the event loop, which was making the
> gameplay quite difficult.
>
> In my experience, this turned the lag time from practicaly  
> unplayable to
> practically unnoticable.
>
> I attempted to put together a patch with git, but when I git-cloned  
> the
> repo, it didn't come anywhere near to matching the code that is in the
> current .xo from the wiki: Which one is more up to date/should I be
> using? (I can port my patch over -- it's primarily to the main event
> loop of the game only.)
>
> How should I create a patch? Are there tests I should be running?
>
> I created https://dev.laptop.org/ticket/2900 to upload the patch, and
> will put it there if anyone can help me figure out what I need to  
> do to
> create it.
>
> http://crschmidt.net/olpc/KukuAnakula.xo is the current version of the
> code I've written.
> http://crschmidt.net/olpc/Kuku-original.profile.txt is the profiling
> data before the rewrite.
> http://crschmidt.net/olpc/Kuku-refactor.profile.txt is the profiling
> data after.
>
> This data is generated by hotshot, grepped for 'kuku' (insensitive).
> Function call counts drop from 8614 in the original to 744 in the  
> refactor,
> for a 5 second game where I move the chicken to each of the squares.
>
> Note that this was simply a small 'attack the largest numbers first'
> approach -- it's possible that a more concentrated effort would be  
> able
> to determine more places where optimization is possible.  
> Specifically, I
> avoided optimizing the case where images are loaded, though I think my
> changes to limit grid.draw() will also have the result of limiting the
> image redraws I saw being a problem at one point.
>
> Looking forward to helping if my changes are acceptable.
>
> Regards,
> -- 
> Christopher Schmidt
> MetaCarta
> _______________________________________________
> Games mailing list
> Games at lists.laptop.org
> http://lists.laptop.org/listinfo/games

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.laptop.org/pipermail/games/attachments/20070819/fc635090/attachment.htm 


More information about the Games mailing list