Saturday, July 24, 2010

Ogre SDK on Mac

Ogre SDK在Mac XCode下的安裝



首先,我們當然要有SDK

Download

選擇Mac OS X, 這個版本應該就可以了 (iPhone又是另外一個故事,下一篇再介紹)



接下來把他解壓縮到本機,我個人是直接丟到Documents



然後各位應該就會碰到第一個障礙:XCode Project打開後build出一堆錯(多半是CMake找不到甚麼檔案有的沒有的)這是一個已知bug,請升級CMake到2.8.2以上

Download



再度執行看看,如果再不行的話就需要重建.xcodeproj

Screen shot 2010-07-24 at 4.00.47 AM.png

重建也沒那麼恐怖,按照下面一步一步來

首先先在Application裡面找出CMake按下去

將Source指到你的sdk跟目錄,build binaries也指到同樣的地方

按下Configure會出現選擇編譯器跟目的檔的畫面

Screen shot 2010-07-24 at 4.05.36 AM.png

選好後再按Configure一次,Generate就亮了,按下Generate,收工。夠簡單了吧



接下來.xcodeproj似乎就可以正常運作了,記得把左上角調整成Release或者RelWithDebInfo

Screen shot 2010-07-24 at 4.08.23 AM.png



ok 接下來就是build and run! 大多數的人會在這裡碰到第二道難題:奇怪,為什麼build and run跑不出執行檔?這時候應該要打開console看一下了!

Screen shot 2010-07-24 at 3.56.33 AM.png



歐賣尬,要是一輩子沒想到開console不就被它栽到了。這個問題的成因是,nVidia顯卡下它需要CG Toolkit來執行demo(ATi要不要我不知道,有人能給個答案嗎 =P) 來吧,我們拿個最新版本來玩玩

Download



安裝好以後,再度執行他的執行檔,成功!

Screen shot 2010-07-24 at 4.13.48 AM.png





希望這對用Mac OSX開發Ogre3D遊戲的人有點幫助 :3



Wednesday, February 03, 2010

else....where??

http://thedailywtf.com/Articles/Else-where.aspx

「我手下曾經有一個非常強的專家,他留下一句名言:給我足夠的NAND Gate(譯註 : 這是一種邏輯閘,相當於先取and再取not...剩下的請查閱這裡),我將統治全世界」,Rob B,在他的一本書裡面寫到:「其實換個繞口令一點的說法,你用上一整片的NAND Gates,你可以做出其他邏輯閘能作到的任何事情。當然啦,因為有其他邏輯閘能作這些事情,你實在不該浪費一狗票NAND gates來作這種無聊的事情。恩...這樣的確是辦得到的...寫code的時候偶爾也會有類似的思維」

「前陣子我們從我們的外包商那裡看到了一份實在是爛到爆炸的C++ code。這東西平均每行出錯率實在是真他媽的高,而且他的寫碼風格讓我們越看越想咒他老母。不過,這種What the fuck的感覺,到我們看到這組code的時候達到了最高點。」


while(true)
{
if(mainType == 7)
{
subType = 4;
break;
}

if(mainType == 9)
{
subType = 6;
break;
}

if(mainType == 11)
{
subType = 9;
break;
}

break;
}


「來來來我們看看這堆鳥東西....」Rob繼續寫到:「我花了些時間在想,他幹麼寫這樣?這個while loop到底是幹麼的?只是拿來搭配break跳過下面那些if的嗎?我還真沒看過那麼蠢的,完全不是拿來作條件判斷的break...好啦,這是我第一次看到。」

Bob補充:「我幾乎可以確定這傢伙完全不知道什麼叫做else if....他好像只知道if while break,所以就把他們拼在一起了...用這種超白爛的方法做出這個邏輯。」

Tuesday, February 02, 2010

Classic WTF : What the hell enum!?

One day, while I was roaming through Internet, I bump into a article while I was viewing a frequently viewed forum =3

in HeaderDefine.h(This is a header file that will be included in almost every files)


/*----Be sure you have READ this!----
...
...(a long term of manual of this header)
...

I have made this way to make sure
everyone will read this manual.
By Genius Jason
----------------------------------------------/*
enum DECLARE
{
I_HAVE_READ_THE_MANUAL_AND_KNOW_WHAT_I_AM_DOING_THIS = 38106,
I_HAVE_READ_ABOVE_AND_AGGREED_THE_TERM_OF_USE = 39100
};


You might be confused what the hell it is for, ya, it's a trick. While using some function or callback, you have to follow his way or a assert will be invoked :

KaimCore.Init(I_HAVE_READ_ABOVE_AND_.....
KamiCore.CleanupDump(I_HAVE_READ_THE_MANUAL_AND...



"Fuck you Jason you damn moron!"

Game loop in C#

Game update loop is a problem in C#. Of course, first thought of us must be attach the Idle event of Application, like this.


Application.Idle += new EventHandler(OnAppIdle);
Application.Run(mMainFrame);

........
........

static void OnAppIdle(object sender, EventArgs e)
{
//Do some game loop update here
mMainFrame.DoUpdate();

}



It seems reasonable, we register a listener to Idle event, so it must be run OnAppIdle while application idle, right?

Partially right.

When the application keep going, it will only get message while "When application need to be updated". It means, therefore, if you leave mouse out of this application form(so no MouseMove event sent), it will totally stop, so it will be updated only when getting some message : such like OnMouseMove....etc.

Solution is from Rich, and he found it in sample of MDX applications. Don't ask me how to do it, just need to know use this way to keep the game loop.

We might discuss this in later post =3


static class Program
{
///
/// The main entry point for the application.
///

///
static SceneEditorMain mMainFrame;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

mMainFrame = new SceneEditorMain();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(mMainFrame);
}

static void OnAppIdle(object sender, EventArgs e)
{
while (AppStillIdle)
{
mMainFrame.DoUpdate();
}
}


private static bool AppStillIdle
{
get
{
NativeMethods.Message msg;
return !NativeMethods.PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
}
}


}

public class NativeMethods
{
/**/
/// Windows Message
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public uint msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point p;
}

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
}