Wednesday, December 31, 2008

2008 reviews and new year wishes

2008 only left 3 hours plus, let's review my big events

  1. First complete 3D games, end of last year (2007) to beginning of this year (march 2007) I produced a complete single player 3d games, it is my "Lucky Star" game, this game feature, avatar creation, scene selection and spelling + dancing game.
  2. First flash application, also early of this year (feb ~ april 2008) i have completed a flex/flash application that's for school's student management system, with this system student and teacher has a common platform to exchange information.
  3. First time ever has the urge to start up a new company, i even announced the plan to some of my close Friends, although it couldn't work out as we planned, but this gave me more understanding how to start up a company, i haven't given up the hope yet :)
  4. Joined a new company, get a new responsibility. I be the pioneer team in my current company to setup a PC client framework, and this framework has been used for 2 games
  5. First usable game framework, I've put in all my pass knowledge into this game framework, it has audio, gui, db, event system and basic rendering functionality. and this framework gave confidence to continue my own game engine the Grunt engine.
  6. New working attitude, more mature now, better control my temper, could complement my co-worker properly now :) and able to criticise my superior at the right moment :)
Phew, quite a year isn't it? let's make some wishes for next year, hopefully it could be equally fruitful it the coming year. 

1) Create a dream game engine. this engine 2 shining features that no current engine has it
  • asynchronous communication between the modules, event system is used for the communication. async communication allow the system be threading friendly and more flexible, e.g. use mouse input to generate sound!
  • p2p + bit torrent network system, with this function, the requirement for dedicated servers could be greatly reduced
2) Flex client + java server, this could be my new company 1st product, this is basically the extension of my first flash application. this new flex application will has better graphics and more scalable.

3) Experience shader programming in LightFeather engine. hopefully could learn something from  this great engine, like what Torque Game Engine did to me :)

if 2008 gave me more confident to be independent, i hope 2009 i could be on my own feet, happy new year 2009!

Friday, December 26, 2008

new arsenals

found a wondeful 3D game engine LightFeather, it was evoluted from irrlichtNX, this engine is very complete in term functionality, it has audio, network, gui, physics and many tools available. only down point is small community size, therefore still need to evaluate it maturity.

nevertheless 5th generation of grunt engine has been started, i was planned to use these 2 engines concurrently :)

Tuesday, December 2, 2008

Grunt lua framework released!

After months of works, my scripting framework is finally release!

Features of my scripting framework
1) c++ able to call lua global functions -- call("foo","%d","%d",1, %bar)
2) c++ able to set/get lua global variables -- setVar("foo"), getVar("foo")
3) c++ able to invoke lua's class's methods -- call(this, "foo")
4) c++ able to set/get lua's class's properties -- setVar(this, "foo"), getVar(this, "foo")
5) lua able to call c++ global functions -- foo()
6) lua able to set/get c++ global varables -- bar = 2;
7) lua able to invoke c++ class's methods -- app:GetName()
8) lua able to set/get c++ class's properties -- app.name
9) lua able to add new methods and properties to c++ class
10) lua able to overwrite c++ methods and variables
11) simple interface, simple enough to use had coding instead of additional compilation steps (tolua++)
12) no dependancies (oppose to luabind)
13) clean and small!
14) very simple to torque game engine's scripting system

TODO
1) clean up the code, make sure no residue data in lua stacks
2) right now both lightuserdata and fulluserdata are used inside lua table, lightuserdata for dereferencing in c++, fulluserdata is for garbage collection only
3) garbage collection not working fully, as local object out of scope din trigger the gb, right now only trigger when lua_close is call
4) lua co-routine is not in yet
5) right now using c++ std::map to map lightuserdata and type string

and yesterday (strictly speaking is today) my company is re-structuring plus foo-fighter is dead, what a day!

the next thing that i need to do is investigate lightfeather and blender game engine. last but not least get a google code account for grunt game engine!


Monday, November 17, 2008

Life is a journey, not a destination

Learn this phrase from Jojo bizarre adventure Vento Aureo (Golden wind) series. just before the hero Leone Abbacchio die, he met his dead colleague that die because of him. in the illusion (or heaven?) he saw his dead colleague worked very hard in a crime scene (scanning every single piece of shattered glasses for finger print), he asked the colleague why his work so hard even he might just wasted his effort. the dead colleague told him, as long as he has the passion to pursue true, he'll find the criminal one day, because life's a journey not a destination, if u see life is a destination u'll start taking shortcut and ignore the journey the real meaning of life.

I was so shocked, this is a simple words but so meaningful, like if an investor only want to earn money out of a product, mostly he won't care about the product itself, but taking shortcut to imitate the most popular brand of the product. this happened everywhere nowadays.

I like this phrase so much, it could be because it gives me reason to continue my current hardship to create my own game engine instead of compromise my game idea and use existing solution. anyway let's enjoy this journey, shall we?

Tuesday, October 28, 2008

Lua binding (manually)

almost three weeks has gone, my scripting framework is still in trial and error stage. the framework i have in mind is similar to torquescript design. class inherited from ScriptObject are able to expose properties and methods to script as global or class. after same testing i come out with this design

1) Scope, global or class
only manager/singleton class can declare global scope properties and methods, it'll be meaningless otherwise.
to declare properties
registerVar(name, class, variable);
to decalre methods
registerFunc(name, class, function);
to declare class scope 
startClass(name, class);
registerVar(...);
registerFunc(...);
endClass();

2) Registration propagation
instead of using lua example's method, create a proxy class (a static class) and add the static class to script manager. my framework will use torque method instead. torque engine uses ConcreteClassVariable static variable to represent each class datatype. and the constructor for ConcreateClassVariable will register itself to ScriptMgr. when ScriptMgr open libraries, it'll call all registered ConcreateClassVariable, and ConcreateClassVariable will call T::installScript in turn, installScript() is the one contained registerVar and registerFunc.

3) Type
the expose class has 2 different type, script class or Script object. Script object == C++ manager/singleton class, script class == C++ normal class. lua script can use script object to instantiate script class and script class destruction is maintain by lua GC.

there few lua tricks i'd learn from these few weeks. 
1) LUA_ENVIRONINDEX pseudo table is only available when lua call c++ function, hence if this table are required during C++ call C++ function, then just make the later one as lua closure then call it by lua_pcall, then LUA_ENVIRONINDEX table is available to later c++ function

2) when overwriting __newindex and __index, is good to save exisiting default newindex and index function, then set them as closure parameter to new newindex and index closure.

hopefully i could implement all this wihtin 1 week time. my hand is itching to play with shader graphics and physics :)

Saturday, October 11, 2008

V8 - Lua - V8 - Lua

My mind being trowing between the V8 javascript and lua scripting language, which one should i used for my super duper simple 3d engine?

the advantage of V8 javascript:
1) backed by google,
2) faster than native lua
3) designed to be embeded
4) sandbox design,
5) huge user base from Web and flash

the advantage of lua
1) small and simple
2) api are lower level than V8
3) Lua JIT is faster than javascript

ping-pong my mind between this two scripting, read many v8 scripting vm review, most of the people said it is easier embed v8 to c++ than lua and it is faster.
see this http://blogs.bungeeconnect.com/2008/10/09/connecting-c-to-javascript-via-googles-v8/ for great introduction how to access javascript functions from c++

finally i decided to test run v8 javascript. i immediately run into problem. a suppose to be trivial problem, how to compile an external javascript? most of the example compile string, not by file. shocking google did very bad job in documentation. can't find this simple information in the entire internet.

disappointed, ya lua's api maybe more c-like, bad comment syntax, 1-based index blah blah, but when come to documentation it is much better compare to V8. so my verdict is out, concentrate on Lua first, two to three yeah later check again javascript, by the time tracemonkey and squirrelfish should be out, the documentation of them should be better than current state.

Friday, August 29, 2008

Why Cabal Sux

I have played many FREE mmorpg, but only short term relationship. some of them (knight, Requiem) have patching problem, and i ditched them in installation phase, some of them have lag problem (rappels, perfect world, silkroad), so only last for 1, 2 weeks before i look else where and some of them have bad graphics like regnum.

Recently i have a relationship with Cabal online. a considerably long relationship 1 month plus. so decided to write a review for it.

the advantage of Cabal online are:
1) feature complete, pet, weapon customization...
2) good network, not much lag
3) stable application, no patching problem
4) beautiful graphics, one of the best graphics, but silkroad is still better
5) shared inventory for all character in same account
6) fast leveling, avg 1 hour per level

it's disadvantages:
1) boring skills, most of skill have same effect, only some parameter are different
2) not much customization, if everybody spend same effort, they will get similar character! the game itself force u to do so, every 10 level there is a quest force you to set character's attribute to a reference attribute.
3) very restrictive gameplay, character can only wear armor of their class, carry weapon of thier class, really no rpg element here.

after 1+ month playing, i'm growing boring about it, i think soon i'll start lookig for a mmo.

Tuesday, July 29, 2008

miliseconds breaks from milestone rush

Getting busier nowadays as two millstone are approaching. I think is good to take a short break from my tiring journey and take down some notes about my experience in the last few weeks.

Actionscript 2.0
A simple and incomplete language. i found some shortcoming in this language. 1) no "protected" declaration, this make inheritance less useful in AS. 2) no virtual functions, strange, i could believe it until now, i may need to reconfirm this. 3) no static for variable in function 4) no constant 5) no enum 6) CANNOT define array in class for instance:

class test
{
public arr:Array = new Array;
}

the "arr" is shared among the "test" class instances. it behave same as c++ static property. the correct way to define it, is define it in class member function, constructor is a good place for that.

C++
I encountered a interesting problem in c++. e.g.

int *arr[2];

arr[0] = new int;
arr[1] = new int;

delete [] arr; // <= return error, claiming should use delete instead.

the correct way to use delete [] should be

int **arr;
arr = new *int[2];
delete []arr;

and i also found at interesting coding technique. e.g.

struct Player
{
Player(int age);
};

int addToGroup(Player np);

addToGroup(11); // <= it works without error! c++ compiler will create a player instance and feed in 11 as parameter

to disable this nice feature you have to do this

struct Player
{
explicit Player(int age);
};

ok, is 1am here, i should rest now for tomorrow milestone rush...

Tuesday, June 17, 2008

c++ new can has argument! (without operator overloading)

After using C++ for years, first time i relised that the new operator can accept argument, and it is quite useful. the usefulness this feature that i can think of are as follow:
  • no "delete" and "new" for replacing a unwanted object instance, simply call obj.~TYPE and new (&obj) TYPE, no memory manipulation required
  • allow object instances to be placed side by side (array), this allow object to be accessed faster and avoid memory segmentation
  • object-oriented, support object construction and destruction

this feature is best use for object pooling such as thread pool, hash table (see sauerbraten)

IBM c++ doc has a very good introduction about this.

The placement syntax is commonly used to invoke the global placement new
function. The global placement new function initializes an object or objects at
the location specified by the placement argument in the placement new
expression. This location must address storage that has previously been
allocated by some other means, because the global placement new function does
not itself allocate memory. In the following example, no new memory is allocated
by the calls new(whole) X(8);, new(seg2) X(9);, or new(seg3) X(10); Instead, the
constructors X(8), X(9), and X(10) are called to reinitialize the memory
allocated to the buffer whole. Because placement new does not allocate memory,
you should not use delete to deallocate objects created with the
placement
syntax. You can only delete the entire memory pool (delete whole). In the
example, you can keep the memory buffer but destroy the object stored in it by
explicitly calling a destructor.

Sunday, June 1, 2008

Grunt Library Network Module Alpha 1 Done!

After much head scratching and hair pulling, the network module was finally done! this shinning module features SDL_Net and ENet support, pluggable buffer method, pluggable protocol adding and stripping method.

The pluggable method was using c++ template method, that's mean my network module is mostly templated so that user can swap and change any protocol and buffering methods(currently they are in same class) as they wish. i spent 1 week plus a lot of hair :) to push these features out.

The next step will be building Flex, Torque Game Engine (TNL), Sauerbraten (Enet) and Clanlib client codes, hopefully my hair can last that long

Saturday, May 24, 2008

Quit Google Search

Finally get tired of google search. to be precise I'm tired of google's 403 forbidden problem. this happened when google search page was hit too frequently within certain period of time. usually this wouldn't be at issue, but problem appear when all my family member go online on the same time, my family member are all google fan, so they used google very often and we all shared one public ip, DANG! 403 forbidden now kick in to annoy me, and today i finally feel that enough is enough, i shifted to msn search engine today. surprised! msn search is exactly same as google nowsaday, i forgot when is the last time i use msn search. i feel comfortable immediately, i think i'll stay will msn search for pretty long time.

besides this, i have good news. i finally make sdl_net and enet sit peacefully in my c++ network framework. now my network support tcp, udp and enet network protocol and they are all cross-platform readied! integrating enet is actually quite tricky, because it is quite high level compare to tcp and udp and they is one strange problem. the ENetPacket can't be reused, it must be replaced after the packet sent. if not it'll give you random crash (if you send packet very fast it won't crash at all, what's the logic?)

another thing i would like to take note of is std::map index operator []. you can't use this to find item, e.g.

B* b = ur_map[a];
if (!b) return "not found";

because that will add a new entry to your map! the correct way to find a item is used std::map::find()

Monday, May 12, 2008

inconsistency in sdl_net

just discovered a trap in sdl_net on little endian system. sdl_net used 2 endian system in it's api!!?, if you use SDL_XXX_OPEN(), you should enter the port number follow the endian of your system. but when u set destination address in UDPpacket, you must always convert it to big endian! this took me 1 Sunday to find out

Wednesday, April 30, 2008

Multiple instance of torque on 1 pc

My dancing game doesn't work well in multiplayer mode, part of the reason is i only have 1 development pc. to overcome that i hacked torque engine to make it run multiple instance (it's disable by default).

on scripting side, finction initCanvas(%windowName, %effectName) initiate the the checking. this srcipt calls torque engine createCanvas or createEffectCanvas (this is new to me, it is for transition effect when setContent is called, should test this out later). and on engine side, this function Platform::excludeOtherInstances("TorqueTest") is checking multiple instances. but this is only call under release mode! so basically i don't need to hack any engine code to make it run multiple instances. haha wasting time again, but at lest i discovered a new canvas class

Friday, March 28, 2008

Flex Games programming

I have some experience in flex programming, but only in application development. i love the gui part of flex framework, it is much better than java in my opinion.

This time i try to use flex for game programming, not flash codes compile with flex compiler, but really use flex framework to do game.

The very first problem i encounter was there is no example could be found on net! i wonder why, but nevertheless i still found one close enough example from Rico on Flex, it uses AS3 but purely flash api to create a tetris game. as part of learning i decided to redo this tetris game with flex, that is using concept such as canvas, panel, flexSprite, flexShape and mxml!

Although i just started, i already found 2 useful experience:
1) To create double array, do this will create error
_allBricks[m].push(new Array(MASKS[m].length));
should do this instead
_allBricks[m] = new Array(MASKS[m].length);

2) flexShape don't have to added to flexSprite as child, you can add it directly to canvas. to do that:
var _nextBrickDisplay:Shape = new Shape;
var previewUI:UIComponent = new UIComponent;
previewUI.addChild(_nextBrickDisplay);
this.addChild(previewUI);

Monday, March 17, 2008

java gotcha

while working on jdbc, i wanted to filter out invalid character in sql statement such as "'" the single quote. the way i first did is

newSql = orgSql.replaceAll("'", "\'");

it works? doh no! after a little bit searching i found the solution here Avoid the dreaded replaceAll method, the correct way to do it should be

newSql = orgSql.replaceAll("'", \\\\\');

5 slashes, yes, because this statement goin to compile 2 times before it being execute, so java will eat 2 them, regex will eat another 2. the remaining will be "\'". elegant right?

talking about jdbc, in previous java game server, i was using hibernate for the job, but it give me very big headache, the lazyness feature don't work on me at all, give me bunch of exception, at the end i have to manually store the data in heap. after that i seared i'll use jdbc instead.

Thursday, March 13, 2008

Tortured by an Ogre (3D)

This was 4.16am, and iwas still in front of my pc, and all this stay up late is because of my itching hand went to update my ogre3d to latest version, directly from official cvs. the latest ogre3d make 2 of my projects couldn't compile and/or crashed at runtime. and my ego make the things worse, i decided to tamed the new monster instead of going back to the old one. so here i'm, coding at 5am in the moring.

this is not good, today's news said main sleep less then 5 hours can cause overweight problems. i must take note all the problems that i encounter today so that i won't repeat them again

1) my ogre3d framework suddenly complain material for AmbientOneTexture couldn't be found, this is a easy one, just need to add Examples.material to media folder that all, but the reason why new version need these file still unkown

2) my 9th life copy couldn't compiled. this was due to Ogre3d 1.4.7 removed Entity::setNormaliseNormals and Renderable::getWorldOrientation and Renderable::getWorldPosition. they took me awhile to discover setNormaliseNormals and getWorldXXXX are no longer required, can remove them entirely without searching for new subtitute. getWorldOrientation and getWorldPosition for other class (SceneBode) can use _getDerivedPosition instead

3) after my 9th life compiling, it crashed at runtime, at reported all particle file not found! wth? and this b*tch, wasted my 4 hours go and debog the new ogre3d line by line, started from initialiseAllResourceGroups() to OgreParticleSystemManager::parseScript(), after 4 hours then i relised new ogre3d used new script compiler, which compined *.os, *.material, *particle... to one, and this caused serious problem to me. and the solution is simply add OGRE_NONCLIENT_BUILD;FREEIMAGE_LIB;OGRE_USE_NEW_COMPILERS=0 to preprocessor! good lesson, never used cutting edge IT product, never!

my eye was a little bit not cooroperate. i actually there was still one problem bugging me, that was from my the other project. the smartfoxserver don't me to upload file to my server, i still searching for solution for it, sigh... good night

Tuesday, March 11, 2008

A journey begun! is it?

Not too long ago i had watched a japanese movie called Kikujiro, it is about a journey between a gangster (yakuza) and innocent kid. the journey was set out to find the kid's mother, who left the kid at his very young age. as the movie progressed, i discovered that, the journey is actually a journey of life for both of them, a journey that change both of thier life forever.

Not too long ago i 'd resigned from my ex-employer, and thinking of setting up my own software business. i guess more or less i have debarked my own journey of life, and i hoped it will be as fruitful as the one in Kikujiro.

Currently i have a few project at hand, first one is about 3d online dancing game and the second one is web application using flex and smartfoxserver. they are both very new to me, i'll jot down my discovery on this small space of mine :)