Sunday, March 21, 2010

never keep java.sql.connection for later use

from c++ and framework development background, i also try to minimize repeated tasks in program cycle. my recent discovery is to get java.sql.connection at application initialization and keep it for application runtime use. so far so good, no problem during development time, since server never up for more than 10 hours. but once it put it for deployment, i received this error

mysql connection disconnected: The last packet successfully received from the server was 312,686,980 milliseconds ago

I first i thought is my server OS shutdown the harddisk or network system after long period of idling. after much debugging, i found that is my own wonderful code causes this problem. to solve it i should getConnection everytime connection is required.

Tuesday, March 16, 2010

quirk of unity3d gui

unity3d's gui (gui version 2) is very special in my opinion, very different from standard gui system. in my opinion, normal gui should have gui object that could be use to get and set gui properties and event system to interact with other objects. but unity gui doesn't has any of this. it provides some functions for u to draw gui. and this functions need to be called every frame. to hide gui? stop calling those function in your loop! to disable gui? (still visible) put GUI.enabled=false before the gui and GUI.enabled after it, cool? i don't know.

lacking of event system also make data collection need to be done every frame, think polling method. is this good? i'm not sure. and the gui system is very basic (gui version 1 is more primitive). it doesn't has tooltip ui, drag n drop ui. and some hack are required to make bitmap buttons. wanted animated bitmap button? you need to hack the system again, probably use unity version 1 gui system to hack an animated bitmap button.

these are a few comments i have regarding unity gui system.
1) if using GUI.BeginScrollView, horinzontal and vertical scroll bars are always shown unless GUILayout.BeginScrollView is used instead.
2) no tab control, use toolbar to hack a tab control? prepare for a very button-ization tab looks.
3) no tooltips control, you need to hack one for yourself. prepare for polling tooltip string for normal gui and window gui. yes you need to poll separately. and because of lacking gui objects, tooltip is a hack for letting developer know which gui is under mouse cursor, cool?
4) toggle button could be selected by all three mouse button, and no way to disable anyone of them
5) due to the gui system design, GUI.grid is useless, it is very hard to customise it, for example you want only one of the button in grid is selected at any one time. hack a grid using button or toggle is easier.

enough ranting about unity3d, it does has it string points. the thing i like the most is component-based design. create a new game play without engine source code is very possible now. second strong point is the very customizable editor, you could use it the same scripting system to extend the editor functionality! third thing i like is minimalist design, i hoe unity 3 not going to break this.