Jun 17, 2009

WarHammer[0];



最近玩戰鎚,不過大概快玩不下去了,bug很多,而且G1S跑起來也不順,3G的RAM加上8600GT還不能順暢的運作,這個game一定有些問題,雖然設定上還有些意思,但我從第一天開始就覺得:無論美術程式,都無法與Blizzard 打對台。今天累了,提一個奇怪的rendering bug就好,其他有空再說。

圖不是很清楚,左上角紅框裡還有個「方框」,喔不!這是個誤會,實際上那是盞燈,週遭則是充滿煙霧(風沙?)的場景,會跑出個這麼突兀的方框是 z check 跟 z write 的問題,燈看起來是張textue (texture animation?maybe)的billboard,屬於半透明物件,整片煙霧也是半透明物件,這兩個東西都會等到整個場景畫得差不多後才會畫上去,為得是半透明的渲染未經排序的話結果會是錯的。我猜問題是這樣發生的:燈影跟煙霧畫的順序不一定,有時燈先畫,有時煙霧先,所以這個問題不是一直存在。接著,畫燈影的時候 z write 是開著的,畫霧的時候 z check 是開著的,結果燈先畫的話,因為 z write(z 值還可能是錯的),導致畫煙霧時 z check 後沒辦法畫那一塊,最後就生出一個方框了。

ZZzzZzZzzzz...快睡著了......

why UnAdvise ?

If you are familier with COM, you would usually work with AdviseFooEventSink / UnAdviseFooEventSink. You have to call UnAdviseFooEventSink explicitly somewhere ...... it`s better not in the scope of this event sink, especially in the destructor of event object. But WHY ?

I try to demo something by directshow recently. When working with filter, I made some mistake in accident today. I did something like UnAdviseFooEventSink in the destrucotr of event object. Let`s check what happen :

  1. when the event sink object is created, the reference count should be 1.
  2. when Foo Advise the sink object, reference count of sink object increase to 2.
  3. when I don`t need the sink object anymore and try to release it, reference count decrease to 1.
  4. Now the owner of the sink object is Foo, and I wish sink object to be UnAdvise when being deleted.
  5. Since Foo is still the owner of sink object, sink object won`t be deleted if Foo doesn`t do extra work.

Thanks for the debugging function of baseclass of dshow, I got some ugly assert and try to fix it.

BTW, the same isuue would happen in cocoa of Mac, too. If 2 objects are the owner of each other (retain each other), they should be disconnected before release the final reference outside of the scope.

Jun 1, 2009

some methods to optimized gui rendering.

I thought about gui rendering today and got some ideas. Here is a brief note (but this should be useless since ui rendering is an old topic).

Sometimes we have to render ui with 3d API such as d3d. For example, it`s hard to rendering ui with video without d3d on windows. The generic method to rendering gui is to render many "rectangle", like buttons, checkbox, combobox, etc. Each rectangle need one draw call. When there are too many controls (include text), it may call draw primitive too much times and start to affect the performance. There are some points we can try :

[1]. Sort entire gui rendering by texture. The first issue make us render rectangle one by one is : all images may not on the same texture. For controls that share the same texture we have a chance to draw many "triangle list" to reduce the draw call.

[2]. Separate gui to dynamic & static part. All controls share the same "dynamic" vertex buffer. For dynamic controls, changing vertex position to move their position. For static controls, their position is fixed. So all vertices in the buffer can sort by their state to 2 part, too. Then there is a chance to minimize the vertex update method.

[3]. All controls share the same "dynamic" index buffer. For those hided control, we can just ignore them by not applying index. Sort the index could get better performance, too.

[4]. If there is alpha controls, separate them to another pass......or everything is gone.

[5]. So now you can :
  1. get a single texture with all images of controls.
  2. update position of dynamic controls by update vertex buffer.
  3. update visibility of controls by update index buffer.
  4. collect all characters in the same texture (or less textures)
  5. pray.
[6]. I am kidding... please inform me if you tried it. 

May 28, 2009

Prince of Persia !

怎麼可以有了新歡就忘了舊愛呢?G1S 我還沒忘記你啊!且看看你做了什麼事!

話說前一陣子在玩新的波斯王子,還沒玩完,不過已經讓我碰到幽靈事件了:


走近一看……



公主到底是怎麼飛上去的啊!波斯王子的畫面依然令我驚豔(之前只玩過時之砂),改變不大,要說最大的變化就是……這一代是波斯公主遇到一個很強的路人,只是公主太強大了,所以只要路人在年老力衰前達成任務即可,就算往懸崖跳一百次,公主也不會只救你九十九次!比較難過的是隨著劇情發展,公主跟路人會開始調情……是怎樣!打個電動都活該被閃嗎! \_/

stupid flying triangle

Finally, I rendered a stupid flying triangle in iPhone simulator. Though I never investigate OpenGL before, but it easier than d3d. So writing code to render simple object is quickly. But I am usually confused with gl functions. Like the "glTranslatef", this C function can`t tell me which matrix I try to translate now, just like many old C functions. It`s fortunate that I still don`t have to take care heavily matrix calculation in current stage.

I guess it`s time to start to make a simple game after learning how to render text, since the basic touch function need only override some method in UIView.



BTW, I tried to programming on symbian (sdk from nokia) long long ago. Maybe I was too weak so I could not make the simulator work correctly. I bough a book for that OS, but I never touch them again after several "days". (OK, that happened in 4th month of my programming life).

May 27, 2009

xcode is still not my friend !

Though I said Hello world 3 times, I am still not familiar with xcode. It took me several minutes to check why the debugger can`t work as visual studio. Then I unchecked the "Load symbols lazily" in accident and debugger can stop at the break point in the beginning. I don`t know if visual studio can do the same thing. But it should be useful in somewhere, maybe the symbols can be loaded when application crashing. That will help when debugging a big app. BTW, I don`t know if there is any default app like mspaint.exe in Mac, so there is no mark to show you the position of the option. It is the first one in the right panel. Wish you don`t have to enjoy it... XD

May 18, 2009

Lua

這幾天看Lua,寫了個測試程式,記得以前剛開始學windows GDI 的時候,最喜歡寫一堆字母在視窗裡飛來飛去的效果,還寫個螢幕保護程式版。配上 Lua 之後,每一個新的效果只要寫寫幾行 script 就搞定啦!

function OnLaunched()
local c = 512;

local x = 0;
local y = 0;

while (c > 0) do

x = math.random(0, 800);
y = math.random(0, 600);

AddNewParticle(math.random(65, 90));
SetNewParticleColor(
256 * math.random(0, 255),
0x00000200);

SetNewParticlePosition(x, y);
SetNewParticleVecl(0, math.random(1, 4));
SetNewParticleAccel(0, math.random(1, 4));
DeliverParticle();

c = c - 1;
end
end

function OnLButtonUp(x, y)
end

function OnParticleKilled(c)
local x = 0;
local y = 0;

while (c > 0) do
x = math.random(0, 800);
y = math.random(0, 600);

AddNewParticle(math.random(65, 90));
SetNewParticleColor(
256 * math.random(0, 255),
0x00000200);
SetNewParticlePosition(x, y);
SetNewParticleVecl(0, math.random(1, 4));
SetNewParticleAccel(0, math.random(1, 4));
DeliverParticle();

c = c - 1;
end
end


沒力了。

不想貼了。

自己猜吧!