My Writings. My Thoughts.

Podium Finish

// 二月 11th, 2010 // No Comments » // Learn a Word

最近在恶补前一段时间欠下的VOA债,难得遇到了一篇讲体育的,当中有这么一句话:

Both men are world champions and both have World Cup podium finishes this season.

句子没什么难的,关键是不知道podium finish是什么意思。podium我知道是讲台的意思,但什么叫拥有World Cup的podium finish呢。google之后,刚看到映入眼帘的几张图,就立马明白了是什么意思。

Wiki上的话:In many sports, results in the top three of a competition are often referred to as podiums, or podium finishes.

podium在这里可以翻译为领奖台的意思,那么VOA上的这句话大致意思就是:他们都是世界冠军并且在本赛季的世界杯赛中都登上了领奖台(即进入了前三)。

Game Engine Framework

// 二月 4th, 2010 // No Comments » // Some Experiences

在这次找工作的过程中,有一道笔试题让我印象深刻,题目只有简单的一句话:please use pseudo code to write a game engine framework(请用伪代码写出一个游戏引擎的框架)

当时看到这道题,完全是一种头皮发麻的感觉,虽然我对游戏引擎还算比较熟悉,但它可是个“巨象”般的庞大结构,要在短短的90分钟的笔试时间内把它“摸”完(而且90分钟也不只这一道题),那可真是天方夜谭。所以我当时在试卷上留下的结果就是,草草的画了几个模块图了事。

之后我才意识到,我根本就完全没有理解这道题,或者说,是完全没有理解一个词的意义——framework。受游戏引擎庞大印象的牵连,我把framework想得太大了。

Framework对于IT人士来说貌似是个挺时髦的词,这个词也经常被我们挂在嘴边,我也如此。但问题是,我几乎从来没有去好好的留心过或者深究过,到底什么才是framework,什么样一个东西才能被称为framework,它的准确定义又是什么呢。

看一般英汉字典里对于framework的解释:

structure giving shape and support  框架; 结构

这只是给了我们framework的中文翻译而已,几乎还是没有给我们什么有用的信息。

记住一句话:有困难,找Wiki。当我看到Wiki上对software framework精确的定义时,突然间,一切都明白了。

原文URL:http://en.wikipedia.org/wiki/Software_framework

A software framework, in computer programming, is an abstraction in which common code providing generic functionality can be selectively overridden or specialized by user code providing specific functionality. Frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined API, yet they contain some key distinguishing features that separate them from normal libraries.

Software frameworks have these distinguishing features that separate them from libraries or normal user applications:

1. inversion of control – In a framework, unlike in libraries or normal user applications, the overall program’s flow of control is not dictated by the caller, but by the framework.
2. default behavior – A framework has a default behavior. This default behavior must actually be some useful behavior and not a series of no-ops.
3. extensibility – A framework can be extended by the user usually by selective overriding or specialized by user code providing specific functionality
4. non-modifiable framework code – The framework code, in general, is not allowed to be modified. Users can extend the framework, but not modify its code.

这段话的大概意思是这样,首先表明了software framework是一种抽象体,这个抽象体通过一些公共代码提供了通用的系统功能,使用framework的用户可以在此基础上进行编码,以覆盖或者特化该系统中的相关功能。接着,这段话还说明framework也是一种库,但跟传统的软件库又不同。framework的特点被总结为以下4点:

  1. framework完全决定了程序的控制流,该控制流绝对不会被调用framework的用户(callee)改变,这就是framework跟传统的软件库不同的地方;
  2. framework提供默认行为,且这些默认行为绝对不是无意义的行为;
  3. 用户可以扩展framework的行为;
  4. framework本身的代码不允许被用户改变。

看到这里,我几乎是只有抱头痛哭的份了。因为,从开始学最基础的DirectX技术起,那每一个Demo中,不管多小的Demo,几乎就包含了这样的一种框架,抑或是说,一种游戏引擎框架。只要理解了framework的意思,这道题就根本不是什么问题。我是完全被“游戏引擎”这4个字吓住了,这道题的目的根本不是要你真正的写一个正规的游戏引擎(那是扯蛋),只要弄出一个基本架子即可,达到“麻雀虽小五脏俱全”的效果。

几乎所有的游戏或者说所有的图形渲染的程序,都是遵循下面这样一个过程,一个再熟悉不过的控制流。

FoC of Game

游戏的整个控制流就可以到这么简单,除了图上所描述的东西之外,再加上一系列的消息处理,就可以组成一个基本的游戏框架了。按照wiki上所描述的基本软件framework的4大特点,再来看看游戏引擎framework是如何体现的。

  1. 很显然,游戏的控制流如上图所示,使用framework的用户无法更改;
  2. 游戏引擎framework当然提供默认的行为,比如Initialize部分封装默认的窗口初始化和一系列的设备初始化等过程;
  3. Update和Render,是framework使用者真正进行艺术创造的地方,是游戏开发者的画板。
  4. 游戏引擎framework的代码同样不允许用户修改。

用代码来表现framework是很简单的,在面向对象的语言中一般用抽象类,既提供一些默认的实现,又提供抽象接口供用户扩展。而用户要使用这个framework,只需自定义一个类继承该抽象类,并提供各个抽象方法的实现。用户所需做的只是做一系列的填空题,当然填的如何精彩这就完全取决于用户了。

写这篇文章的真正目的不是为了说明一个游戏引擎的framework是怎么样的,只是借此来强化framework的概念,这样当我们下次再说出这个词的时候,能够知其所以然,而不是自欺欺人。

如果对游戏引擎framework感兴趣,这里有一个简单的游戏引擎framework的代码可供参考: http://gpwiki.org/index.php/SDL:Tutorials:Simple_Engine_Framework

Taylor Swift

// 二月 1st, 2010 // No Comments » // Lyrics

第一次听到她是去年看某个乡村音乐颁奖典礼,后来陆陆续续的经常会听到这个名字。但今天才引起了我的深度注意——在今天的第52届的格莱美上,她一口气搬走了4个奖。于是去google深度挖掘了她的一系列信息。

人长的这么美,歌唱的这么甜,创作还巨厉害,能让人不喜欢么。

Taylor Swift

朋友传给了我2010 Grammy Nominees的专辑,这是里面她的那首You Belong With Me,来自今年格莱美的最佳专辑《Fearless》——啥都不惧,要知道她才只有21岁哪,太初生牛X不怕虎了。

You’re on the phone
With your girlfriend
She’s upset
She’s going off about
Something that you said
She doesn’t get your humor
Like I do

I’m in my room
It’s a typical tuesday night
I’m listening to the kind of music
She doesn’t like
She’ll never know your story
Like I do

But she wears short skirts
I wear t-shirts
She’s cheer captain
And I’m on the bleachers
Dreaming about the day
When you wake up and find
That what you’re looking for
Has been here the whole time

If you could see
That I’m the one
Who understands you
Been here all along
So why can’t you see
You belong with me
You belong with me.

Walking the streets
With you and your worn out jeans
I can’t help thinking
This is how it ought to be
Laughing on a park bench
Thinking to myself
Hey, isn’t this easy?

And you’ve got a smile
That could light up this whole town
I haven’t seen it in awhile
Since she brought you down
You say you’re fine
I know you better than that
Hey whatchu doing
With a girl like that

She wears high heels
I wear sneakers
She’s cheer captain
And I’m on the bleachers
Dreaming about the day
When you wake up and find
That what you’re looking for
Has been here the whole time

If you could see
That I’m the one
Who understands you
Been here all along
So why can’t you see
You belong with me
Standing by you
Waiting at your back door
All this time
How could you not know
Baby
You belong with me
You belong with me.

[Instrumental]

Oh, I remember
You driving to my house
In the middle of the night
I’m the one who makes you laugh
When you know you’re about to cry
And I know your favorite songs
And you tell me about your dreams
Think I know where you belong
Think I know it’s with me

Can’t you see
That I’m the one
Who understands you
Been here all along
So why can’t you see?
You belong with me.

Standing by you waiting at your back door
All this time how could you not know
Baby
You belong with me.
You belong with me.
You belong with me.

Have you ever thought
Just maybe
You belong with me?
You belong with me.

Farewell

// 二月 1st, 2010 // No Comments » // In My Life

今晚,正式拒掉了最后一家游戏公司的Offer。
三年了,我致力于一个叫做游戏开发的领域,目标着有一天成为一名出色的game programmer。
找得到理想的工作,却找不到理想的公司。
突然间,就这么放弃了么……
不管是喜是悲,擦干眼泪,人生的路啊,继续前行。

2 More Accessories

// 一月 22nd, 2010 // No Comments » // Guitar

刚给自己新添了两个guitar配件。g7thprotools-logo

因为最近一直在练Norwegian Wood这首歌,而这首歌是需要capo在2nd fret的,于是就迫切的在淘宝商城挑中了这款G7th Nashville Capo。号称是世界上最强的capo之一,我虽然吉他弹不起世界上最强之一,但这种小的配件还是用得起的,嘿嘿。之前自己曾经有过一个capo的,记得是花20块钱在王府井的一个商店里买的,不过后来就跟我的第一把民谣琴长眠在老家了。

这第二个配件完全是在搜寻capo过程中无意中看到的,没想到练指力还能有这么专业的指力训练器。一直觉得自己左手力量比较欠缺,需要加强,于是就毫不犹豫的买下了它,试着用用。买了个中等强度的,7磅,足足22公斤多。但俗话说不管练什么得讲究科学方法,盲目练只会适得其反,所以还得好好研究下这款Prohands指力训练器的用法。

Quotes from “Clean Code: A Handbook of Agile Software Craftsmanship” (1)

// 一月 20th, 2010 // 2 Comments » // Some Experiences

最近在读这本Robert Martin的Clean Code,中文译本是《代码简洁之道》,我觉得非常好看。我一直比较注重写出简洁出色的代码,并且一直以为自己在这方面做的还不错,但随着这本书的阅读,虽然我的一些观点和想法被得到验证,但另外一些却完全被颠覆。也让我意识到离一个出色的专业程序员还有多大的差距。

We’ve all looked at the mess we’ve just made and then have chosen to leave it for another day. We’ve all felt the relief of seeing our messy program work and deciding that a working mess is better than nothing. We’ve all said we’d go back and clean it up later. Of course, in those days we didn’t know LeBlanc’s law: Later equals never.

这样的经历真是太普遍了,我们写了一堆烂代码并且实现了某个功能,颇有成就感,但同时我们也意识到这是一堆垃圾代码,并且提醒自己等未来有空了一定要回来收拾这堆垃圾。但——Later equals never,我们再也没回来过。
所以,垃圾要及时处理,不然就这样遗臭下去了。

Replace the temptation to create noise with the determination to clean your code. You’ll find it makes you a better and happier programmer.

程序员避免忧郁症的好方法就是遵循简洁之道。

And now note the word that Bjarne uses to describe the consequence of that inelegance. He uses the word “tempt.” There is a deep truth here. Bad code tempts the mess to grow! When others change bad code, they tend to make it worse.

当面对一堆烂代码时,很少有人愿意去收拾这堆烂摊子,结果就是让它们烂到极致.(让我想起之前做过的一个flash项目,接手时是噩梦般的代码,我只能东补西凑,到最后功能加的越多,越是恐怖的混乱,几乎完全无法维护)

You get the drift. Indeed, the ratio of time spent reading vs. writing is well over 10:1. We are constantly reading old code as part of the effort to write new code. Because this ratio is so high, we want the reading of code to be easy, even if it makes the writing harder. Of course there’s no way to write code without reading it, so making it easy to read actually makes it easier to write.

这和我以前一直所想的观点正好契合,写只有1次,而读会有N次(N会随着不同的项目有着巨大的差别),所以为了那更多更多次的读,多花时间在写上是绝对值得的。而Martin给出了读写的比例至少在10:1的样子,他还提出了“要想写容易,得先容易读“。

It was the bad code that brought the company down.

烂代码让这家公司歇菜了!烂代码的威力如此恐怖,对于这点,我坚信不疑。

Clean code is simple and direct. Clean code reads like well-written prose.

简洁的代码读起来应该像优美的散文。

One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king. Professionals use their powers for good and write code that others can understand.

聪明的程序员不等于专业的程序员。

In short, a programmer who writes clean code is an artist who can take a blank screen through a series of transformations until it is an elegantly coded system.

我热爱艺术,所以我热爱简洁漂亮的代码。我梦想成为一个艺术家,从程序员入手是个不错的选择。

The Flow Chart of “Hey Jude”

// 十二月 2nd, 2009 // 1 Comment » // Lyrics

今天在豆瓣上发现了一张很有意思的图,作为程序员同时又是Beatlemania的我很稀饭这张图。据说这周末在Mao Livehouse有向披头士致敬的演出,我有点儿心动了,希望到时能过去。
p350656348

On Sale

// 十一月 21st, 2009 // 3 Comments » // Something In The Way

这是我最近的个人状态:On Sale.

已经把自己挂牌出去一个多月了,但今年的市场行情确实不容乐观,纵眼望去,it is the massive scene of layoffs.

为了给自己找到一个理想的买家,最近一个月是在四处散发自己的“传单”,但一部分传单发出去之后就是杳无音信,一部分给了我回复,也给了我纸上证明自己的机会,不过一直自我感觉发挥的不理想。所以到现在为止,还没有一家买家给我face-to-face的机会,更没有收到一份“Purchase Order”。

几家欢喜几家愁,一江春水你往哪儿流啊。呜呼,什么时候才能把自己卖出去呢,我能找到一家中意的买家么。

谁将是我跨出校园后的第一个雇主呢,继续耐心的等待中…

My Footsteps of Programming 3DS Max Exporter Plug-in

// 十一月 20th, 2009 // 2 Comments » // Computer Graphics

Several months ago, I achieved to develop a 3DS Max exporter plug-in. But until recently, I didn’t get the time to jot down something about my experience while developing it. Finally, thank God, I am starting to write this article, in case that several years later I totally forget how I did it at that time.

As you know, 3DS Max is a powerful tool for creating 3D models, especially widely-used in games. But generally we cannot directly get our model from 3DS Max, otherwise, we need a sort of middleware to retrieve specified model data we need from 3DS Max and export them into a specific type of file. This middleware is right the exporter plug-in.

OK, with this concept in mind, let’s get started.

Step by step, I will roughly present my footsteps of programming a 3ds max exporter plug-in based on 3DS Max 9 SDK.

Get familiar with 3DS Max and SDK

As we all know, there are a series of 3DS Max versions. Firstly you need to choose one to program based on. At the time of my embarking on this plug-in, the latest version is 3DS Max 2009. However, I chose Max 9 because it is already a widely-used and popular version. Most importantly, my laboratory was using Max 9.

Before doing some real programming jobs, it is pretty important to gain some basic concepts of 3ds max. We needn’t to be a perfect 3D designer ourselves, but these are the essential concepts we must know.

  • what is a Node in 3ds max
  • the hierarchical chart of nodes
  • how materials are attached to a node
  • what is a node’s Modifier
  • key-frame animation and how bone nodes are attached to normal nodes
  • the Biped technique

The fact is, the more we want to export from 3DS Max, the more we need to concern about it. For example, if we also want to export the data of camera or light from Max(meshes for games usually don’t export these data), we must apprehend what is a camera or light node in Max and how they work with other nodes.

But how the hell could we get the detail of these knowledge? Turn to the Max SDK Document, whenever you have any confusion with Max. Besides, we can also log on to Autodesk’s official Web site for more help.

BTW, the assumption here is that you are already familiar with some 3D concepts, like vertex, triangle, mesh, texture, space transformation, skinned animation, etc. If you are still a 3D newbie, you’d better figure them out firstly.

To be continued…

Predefine mesh file format

Export static mesh data

Export skinned animation

Colours

// 十一月 14th, 2009 // 3 Comments » // Music Heaven

百忙之中,贴一首我很喜欢的歌,一首喜欢了很久的歌,Colours。

原作是Donovan,但我第一次听到这首歌的版本是他和Joan Baez的Duet版,后来才听到了Donovan的原版。在Duet版本中,Donovan的声音像极了迪伦,以至于我第一次听到时默认为就是贝茨和迪伦的合唱版。

两个版本我都很喜欢,不过更喜欢有贝茨掺和进来的版本,太他妈好听了。

这里我将两个版本都呈上,配着北京今天的阳光,这样的音乐让人忘记了最近所有的不快。

Colours – by Donovan

Colours – a live duet by Donovan & Joan Baez

Yellow is the colour of my true love’s hair,
In the morning, when we rise,
In the morning, when we rise.
That’s the time, that’s the time,
I love the best.

Blue’s the colour of the sky-y,
In the morning, when we rise,
In the morning, when we rise.
That’s the time, that’s the time,
I love the best.

Green’s the colour of the sparklin’ corn,
In the morning, when we rise,
In the morning, when we rise.
That’s the time, that’s the time,
I love the best.

Mellow is the feeling that I get,
When I see her, m-hmm,
When I see her, oh yeah.
That’s the time, that’s the time,
I love the best.

Freedom is a word I rarely use,
Without thinking, m-hmm,
Without thinking, oh yeah.
Of the time, of the time,
When I’ve been loved.