Escapade - Global Game Game 2010

February 1st, 2010

For the last two years there has been an event called “Global Game Jam” where developers from all around the world gather in the same weekend and writes a game in 48 hours.

The Israeli Game Jam was actually 36 hours and produced interesting stuff. Below is our project - a minigame called “Escapade”. You play as a grandma that a giant robot has invaded her living room and disrupted her tea time. Luckily she was prepared… :)

The game was developed using the Unity game engine.

Game instructions:

W - up, S - down, A - left, D - right, Space - start the game

Art: Max Kogan

Code: Ilya Chernyakov, Ori Hanegby

click here to play in the browser:

Escapade

click here for the GGJ game page that includes the game info and full (messy) source code

Game Development, Technology , , , , ,

Chopin Ballade no.3

July 6th, 2009

As part of my piano (as a hobby) study, I have a once in a year recital. Here is a recording of a piece that I played this year, Chopin’s Ballade no. 3

General, Music , ,

Fast Path Finding in flash using A* with QuadTree

June 15th, 2009

Hi, I’ve implemented an A* path finding algorithm using quadtree spatial subdivision which is auto generated on a 2d image. The program reads a .png file and parses black pixels as free areas and non-black pixels as blocked areas. The process is divided into several phases:

QuadTree creation:

1. go over all the pixels of the current quad. if they are all blocked or all free than mark the quad as a complete quad.
2. if some pixels are blocked and some are free and the minimum quad size has reached, mark the quad as a complete quad
3. if quad is not complete, divide the quad into 4 subquads, mark them as the current one’s children and repeat the process for each child.

Visibility graph generation:

for each lowest level quad (that has no more sub quads):

1. query the quadtree for an area that it 1 pixel bigger on each side than the current quad\

2. the returned nodes are the nodes that are visible from the current node, store them in the node’s array

3. calculate the distance to each visible node from the current node and store the distances in an array

…now the data structure is ready for searching using A*…

Pathfinding with the A* algorithm

The A* algorithm calculates the optimal path on a graph between connected node. I won’t get into the details of the implementations of it because there are numerous such available. I based my implementation roughly on the one that is published here: http://blog.baseoneonline.com/?p=87

The cost for each node is it’s euclidean distance from the current node, and the heuristic (h) is the distance to the target point.

click for a demo:

CLICK HERE FOR INTERACTIVE DEMO -  click on any two free quads to find the shortest path between them.

CLICK HERE TO DOWNLOAD SOURCE CODE

Game Development, Technology, Uncategorized , , , , , ,

Open Source in Game Development

March 7th, 2009

In the recent years Israel has it’s own game conference- GameIS. For this year’s conference I’ve made a presentation about Open Source in games development. I’ve put the presentation here on my blog, it can be downloaded from here: Open Source in Game Development Presentation

The presentation was a 20 minute introductory session and gives and overview about current Open Source solutions for game needs.

Enjoy!

Game Development, Technology , , , , , , ,

Global Game Jam

February 3rd, 2009

During the last weekend (30/Jan/09 - 1/Feb/09) I have participated in an event called Global Game Jam. The event took place for the first time and it’s mission was to design and create a game in 48 hours. In Israel the event was set to 36 hours and took place at the GarageGeeks where 56 game enthusiasts met in order to face the challenge. The participants were given a phrase that the game should involve- our sentence was “As long as we have each other our problems will never be solved”. The game that our group developed is a small game about a corporate employee who has to maneuver between his managers’ request. The better you do, the more managers will pop up! The game was developed in Flash - which I never used before so I had to learn it on-the-go. Our game can be found here: http://www.globalgamejam.com/games/office-mayhem.

In the game page there is a zip file that contains the game and the full source code.

In total the Israeli site managed to develop 11 games. All the event’s game can be found here:

http://www.globalgamejam.com/Game_browser

General

Disabling “tap to click” on MSI Wind Netbook

December 18th, 2008

I’ve recently bought an MSI Wind Netbook. Generaly it’s a good computer but it has an annoying problem: the out-of-the-box configuration does not let you disable the horrible “tap-to-click” feature. The solution is to upgrade the sentelic trackpad driver which will enable the option of disabling the click tap feature. Or in simple words:

1. download and install this package: sentelic driver update 

2. after installing and rebooting double click on the trackpad shaped icon on the tray on the lower right side of the screen.

3. open the last tab which says “Finger-sensing Pad”

4. from the top combo box choose “Click on Pad”

5. uncheck “Enable on-pad click”

6. press “Apply” and than “Ok”

No more annoying tap to click!

General, Technology , , , , , ,

3D in your browser 2 - Irrlicht and Firefox

December 9th, 2008

In this post we’ll discuss how to make irrlicht work inside a Firefox 3 browser as a plugin. We will base it upon the irrlicht sample and the method that was described in the activex version that can be found here. Actually the exact same irrlicht example will be used without any modifications other than the ones that were described in the activex post. The nice thing about using this method is that we seperate the browser plugin from the 3d application itself making it’s possible to write different “thin” plugins for different browsers but still use the same application without further customization.

Setting up the firefox plugin project

In this section we’ll setup the basic plugin to compile in windows. This can be viewed as a general introduction on how to compile a firefox plugin in windows regardless of Irrlicht.

get the gecko sdk: https://developer.mozilla.org/en/Gecko_SDK

get firefox source code: https://developer.mozilla.org/en/Download_Mozilla_Source_Code

you will also have to get 7zip in order to unpack the Mozilla source code and unix2dos in order to fix the visual studio project files.

extract the sdk and the source code, I will use “c:\xulrunner-sdk” for the Gecko SDK and “c:\mozilla” for firefox.

we wll base the plugin upon the “basic” plugin sample that arrives with the Mozilla source code which is located in C:\mozilla\modules\plugin\tools\sdk\samples\basic\windows

The only supplied project files are Visual Studio 6 files and I have VS2005. To make things worse, VS2005 will not be able to open and convert the project files because they are in UNIX format. We’ll fix it easily by running unix2dos on the sample files and convert them to windows format.

After converting to Windows format, open the npbasic.dsw with Visual Studio and it will ask you to convert it to it’s version.

open the project properties and add the following include folders:

(Configuration Properties->C/C++->General->Additional Include Directories)

C:\xulrunner-sdk\sdk\include

C:\mozilla\modules\plugin\tools\sdk\samples\include


(modify the paths according to where you have places your files).

Next, add the following preprocessor definitions:

(Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions)

_WINDOWS;OJI

Now the project should compile successfuly and npbasic.dll sould have been created.

Putting Irrlicht into action

As said before, we’ll use the same method that has been used int the activex sample which is passing the windows handle of the plugin window to an external application (the Irrlicht meshviewer sample in our case) that will create it’s device on top of it. See the activex post for details about the modified meshviewer sample.

Open plugin.cpp and add modify the following function:

NPBool nsPluginInstance::init(NPWindow* aWindow)
{
if(aWindow == NULL)
return FALSE;

mhWnd = (HWND)aWindow->window;
if(mhWnd == NULL)
return FALSE;

// subclass window so we can intercept window messages and
// do our drawing to it
lpOldProc = SubclassWindow(mhWnd, (WNDPROC)PluginWinProc);

// associate window with our nsPluginInstance object so we can access
// it in the window procedure
SetWindowLong(mhWnd, GWL_USERDATA, (LONG)this);

mInitialized = TRUE;
CHAR szAppPath[MAX_PATH];
CHAR szCurDir[MAX_PATH];
CHAR szWndParam[100];

sprintf(szCurDir,”C:\\irrlicht-1.4.2\\bin\\Win32-VisualStudio”);
sprintf(szAppPath,”%s\\09.MeshViewer.exe”,szCurDir);

sprintf(szWndParam,”09.MeshViewer.exe %x”,mhWnd);

STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);

::SetCurrentDirectory(szCurDir); ::CreateProcess(szAppPath,szWndParam,NULL,NULL,true,

CREATE_DEFAULT_ERROR_MODE,0,0, &siStartupInfo, &piProcessInfo);

return TRUE;
}

Thats all! I assume that the modified irrlicht sample is located under C:\irrlicht-1.4.2\bin\Win32-VisualStudio\09.MeshViewer.exe

compile the plugin and copy it (npbasic.dll) to C:\Program Files\Mozilla Firefox\plugins

edit C:\mozilla\modules\plugin\tools\sdk\samples\basic\test.html and change the following:

<center>
<embed type=”application/basic-plugin” width=800 height=600>
</center>

open test.html and you should see the following:

Download the modified source code and VS2005 project files

(please note that only the release version is configured)

Technology

3D in your browser - Irrlicht and ActiveX

November 28th, 2008

Hello,

Do you want to run your 3d game or application in the web browser? in this post we’ll see how to do that from scratch in a simple way that will require almost no modifications to your existing application. I’ll use the latest Irrlicht engine version by the time of this writing- 1.4.2. In order to keep things as simple as possible and make something that can work without major modifications to the existing code we’ll run one of the irrlicht example programs in an external process that will render it’s viewport in the ActiveX window. We’ll do that by passing the window handle of the ActiveX control as a command line parameter to the application and it will create it’s irrlicht device and window with it.

Our ActiveX control will be ATL based and will require no MFC.

We’ll use the meshviewer sample from the irrlicht engine as the 3d application. For the sake of simplicity we’ll assume that the irrlicht SDK is located on “c:\irrlicht-1.4.2″.

Let’s start with the irrlicht meshviewer:

* Open the appropriate irrlicht example file- I use Visual Studio 2005 so I’ll open “c:\irrlicht-1.4.2\examples\BuildAllExamples.sln” and edit main.cpp of the meshviewer example:

* We are going to use windows API so we need to include windows.h:

/*
This tutorial show how to create a more complex application with the engine. We construct
a simple mesh viewer using the user interface API and the scenemanagement of Irrlicht.
The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes,
Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, and how to parse XML files
with the integrated XML reader of the engine.

We start like in most other tutorials: Include all nesessary header files, add a
comment to let the engine be linked with the right .lib file in Visual Studio,
and deklare some global variables. We also add two ‘using namespece’ statements, so
we do not need to write the whole names of all classes. In this tutorial, we use a
lot stuff from the gui namespace.
*/
#include <irrlicht.h>
#include <iostream>
#include <windows.h>

using namespace irr;
using namespace gui;

* We need to get the window handle of the activex control as a parameter, so add argv and argc to the main function and add some code to translate it to a window handle.

we’ll also comment out the device selection in the command window and choose automatically directx9

int main(int argc, char* argv[])
{

HWND hParentWnd;

// argv[1] will contain an HEX string with the activex window handle value
sscanf(argv[1],”%x”,&hParentWnd);

// ask user for driver
// ask user for driver
video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

/*printf(”Please select the driver you want for this example:\n”\
” (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n”\
” (d) Software Renderer\n (e) Burning’s Software Renderer\n”\
” (f) NullDevice\n (otherKey) exit\n\n”);

char key;
std::cin >> key;

switch(key)
{
case ‘a’: driverType = video::EDT_DIRECT3D9;break;
case ‘b’: driverType = video::EDT_DIRECT3D8;break;
case ‘c’: driverType = video::EDT_OPENGL;   break;
case ‘d’: driverType = video::EDT_SOFTWARE; break;
case ‘e’: driverType = video::EDT_BURNINGSVIDEO;break;
case ‘f’: driverType = video::EDT_NULL;     break;
default: return 1;
}*/

* the next thing we’ll do is to create a new window that will be the child window of the activex control. Now, why would we want to do that instead of just creating the irrlicht device straight on the activex control? the reason is that we want our application to handle windows messages sent to our window. If we would use the activex created window we will not receive them because the messages will be handled already by the activex control’s message loop. The easiest way to solve this issue is to create a new window which is a child window of the activex control’s window. We’ll replace the original irrlicht createDevice with createDeviceEx that can get the window handle as a parameter. Also window resizing has been disabled.

MyEventReceiver receiver;

HMODULE hInstance = ::GetModuleHandle(NULL);

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style            = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc    = DefWindowProc;
wcex.cbClsExtra        = 0;
wcex.cbWndExtra        = 0;
wcex.hInstance        = hInstance;
wcex.hIcon            = NULL;
wcex.hCursor        = NULL;//LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName    = NULL; //MAKEINTRESOURCE(IDC_WINEX);
wcex.lpszClassName    = “IrrWin”;
wcex.hIconSm        = NULL;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

RegisterClassEx(&wcex);
HWND hIrrlichtWindow = ::CreateWindow(”IrrWin”,”demowin”,WS_CHILD | WS_VISIBLE | WS_EX_TOPMOST, 0, 0, 800,600, hParentWnd,NULL,hInstance,NULL);

irr::SIrrlichtCreationParameters param;
param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow);
param.DriverType = video::EDT_DIRECT3D9;

Device = irr::createDeviceEx(param);
Device->setEventReceiver(&receiver);

//Device = createDevice(driverType, core::dimension2d<s32>(800, 600),
// 16, false, false, false, &receiver);

if (Device == 0)
return 1; // could not create selected driver.

Device->setResizeAble(false);

Device->setWindowCaption(L”Irrlicht Engine - Loading…”);

* The next thing we should take care of is window focus. Because we are a child window of another control our window might lose focus and not receive important events such as keypresses. To fix this problem we’ll make sure we always have the focus in our irrlicht main loop (it can be found near the end of the source file) we’ll also make sure that the scene is always rendered regardless if the window is active by commenting out the code responsible for that:

// lock the logo’s edges to the bottom left corner of the screen
img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);

// draw everything

while(Device->run() && driver)
{
//if (Device->isWindowActive())
//{
if (::GetFocus() != hIrrlichtWindow)
{
::SetFocus(hIrrlichtWindow);
}

driver->beginScene(true, true, video::SColor(150,50,50,50));

smgr->drawAll();
env->drawAll();

driver->endScene();

core::stringw str(L”FPS: “);
str.append(core::stringw(driver->getFPS()));
str += L” Tris: “;
str.append(core::stringw(driver->getPrimitiveCountDrawn()));
fpstext->setText(str.c_str());

::UpdateWindow(hIrrlichtWindow);
}
//else
//Device->yield();
}

Device->drop();
return 0;

* We are done with modifying the original irrlicht sample! now let’s go on to creating the activex control: right click on the solution in the solution explorer and choose add->new project.

* on the project type choose Visual C++ -> ATL and select “ATL Project” on the right pane. I’ve put it under the irrlicht examples folder under the name “ActiveIrr”:

* The ATL project wizard will pop up. Go to “Application Settings” and check “Attributed” and click “Finish”:

* ActiveIrr project have been created and added to the solution. Select it and choose Project->Add Class..

* choose ATL -> ATL Control

* On the control wizard, type in the short name field “IrrCtl”, the rest of the field will fill automatically

* Select “Appearance” settings and check “Windowed Only”

* Press Finish

* By now a new control has been created. Open IrrCtl.h:

* Although we marked our ATL Control as Windowed Only it will still not create a window unless the m_bWindowedOnly member is set. We want our control to create a window so we’ll have a window inside our web page that will contain our application within. We’ll set the memeber in the contructor:

#ifdef _WIN32_WCE // IObjectSafety is required on Windows CE for the control to be loaded correctly
public IObjectSafetyImpl<CIrrCtl, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
#endif
public CComControl<CIrrCtl>
{
public:

CIrrCtl()
{
m_bWindowOnly = true;
}

DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
OLEMISC_CANTLINKINSIDE |
OLEMISC_INSIDEOUT |
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST

* We want to know when our window is created so we can pass it’s handle to the meshviewer. We’ll do that by adding a WM_CREATE handler. We’ll add it to the message map and a method to the class called “OnCreate” that will launch the meshviewer:

BEGIN_MSG_MAP(CIrrCtl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CComControl<CIrrCtl>)
DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

* and here the code for handling the window creation and the mesh viewer launching, just add it to the end of the CIrrCtl class:

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
WCHAR szAppPath[MAX_PATH];
WCHAR szCurDir[MAX_PATH];
WCHAR szWndParam[100];

swprintf(szCurDir,L”C:\\irrlicht-1.4.2\\bin\\Win32-VisualStudio”);
swprintf(szAppPath,L”%s\\09.MeshViewer.exe”,szCurDir);

swprintf(szWndParam,L”09.MeshViewer.exe %x”,m_hWnd);

STARTUPINFOW siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);

::SetCurrentDirectory(szCurDir);
::CreateProcess(szAppPath,szWndParam,NULL,NULL,true,CREATE_DEFAULT_ERROR_MODE,0,0, &siStartupInfo, &piProcessInfo);

return 0;
}

* Another thing that we want to do is to remove the default window drawing that is done by the control. just empty out the OnDraw function and make it look like that:

HRESULT OnDraw(ATL_DRAWINFO& di)
{
return S_OK;
}

* Open IrrCtl.htm (it’s a file in ActiveIrr project) and modify the <OBJECT> of the ActiveX to have a width and a height of 800×600 by adding a style attribute:

<OBJECT ID=”IrrCtl” CLASSID=”YOUR CLASS ID HERE!” style=“width: 800; height: 600″></OBJECT>

save the file and thats about it! compile ActiveIrr project, right click “IrrCtl.htm” and choose “View In Browser”. After confirming all the ActiveX warnings you should get something like that:

* Note that if you close the window the rendering loop starts to fail because of losing the device. You can detect this situation by checking the return status of irrlicht’s endScene() and exit your program.

download the source code

Technology , , ,