zomgistania

Main page | About | Articles | Previous Posts | Archives

Tuesday, May 30, 2006

Type Type Revolution

I just got the most awesome idea in a while!

Combine Dance Dance Revolution with learning to type.
"..uhh what?" I hear you say..

You probably know that in DDR (or StepMania for PC) you get those arrows pointing which key to push/step/whatever.

Replace those arrows... with letters and you get Type Type Revolution!


Now that would be an intresting game. It might be confusing though with all the letters instead of the arrows, but I think it could be done and if it had lots and lots of songs available, like StepMania has at BemaniStyle, it would probably be a very intresting way of learning to type faster.

Saturday, May 27, 2006

Random ideas

Here's a bunch of things I have written down about my game with Stickies (they're floating on my desktop)

Warning, very "raw" text :]


Should units contain a function which generates a data-list of the unit? Or should there be a pre-set class which displays a unit data sheet and it would just be passed a unit as a reference? Probably the latter is better


Units could kind of have some interfaces like IArtillery/IRanged, ITransport and INaval or something? Maybe not Naval...do it with movementpenalties instead.

note: MovementPenalties is a bunch of values in the game used to determine whether unit can move over a certain terrain and if it costs more than normal

Anyway, interfaces would allow some kind of implementation

Another way would be to implement this all into the unit class itself, which would allow for a versatile XML-definition for them. To allow versatile definition but separate functionality, separate classes would be needed instead of Interfaces, eg. ArtilleryUnit, TransportUnit

With interfaces, however, you could have a transport unit which would also be artillery... =)


Optimizing idea for Tile-rendering

- Use one tile for a certain type of tile
- Move the single tile around with matrices
- eg mountain tile, grass tile and blah blah... then it gets moved around


Currently every tile is different - 14x14 map -> 196 tiles... and there are like 4 or so different kinds. I could just store a List of the locations and maybe save something?

Docking

Someone asked if it's possible to "dock" other windows to your form in #C# channel in Quakenet... The idea was so intresting I had to try it out myself since he didn't seem to have any idea on how it could be done.

Looking at MSDN is always helpful, so I started looking for native Windows-functions for changing the position of a window.

Here is a list of native Windows-functions and structs and other stuff at MSDN


Using P/Invoke in C#, I made an app which uses GetWindowPlacement, GetClientRect and SetWindowPos to sort/dock all windows that are visible and not maximized. It uses .NET built in System.Diagnostics.Process to get a list of all processes and uses the MainWindowHandle property to check if the process has a window.

You can find the source code and a binary of the application here


I tried to add useful comments to the source, so even if you're not very used to calling native windows functions and other things, you can hopefully learn something.


Now, it does not exactly dock things to itself... it just moves other forms next to it. And the algorithm which does that is not very good.. does it's job, but it could be done more effectively and such.

For "true" docking, you probably would have to add something which rearranges the other forms if you move the main form. Also you'd have to add something which monitors other processes running to see if there's a new window which needs to be docked or a process has been shut down and should be removed from the docking list.

Labels:

Friday, May 26, 2006

Haado Disuku

I found a bunch of old Quantum Fireball disks lying around today. I thought I'll install them to my server box, even though they're something like 3-4 gigs each.

It's quite painful to install disks into older computers... The disk I installed the linux on the server is a 40 gig disk. The BIOS didn't seem to support disks that big, so I had to figure out how to make it work. Didn't have the slightest clue on what mobo the box has, so I couldn't upgrade the BIOS. Luckily I found out that I could limit the size of the disk to 32 gigs by setting the jumpers to different locations.

It's always those jumpers. Rather annoying to try getting them out from the slots where they usually are in new disks: inside a connector-like thing...

So I was installing those Quantum disks, which are very reliable by the way, I've had them for years, years and more years and they still work perfect. The disks wouldn't work, not at all at first. I finally realized the jumpers. If a hard disk doesn't work, it's the jumpers (or if it makes a funny noise when you shake it, it's broken ;) )...

Why aren't the jumpers in new disks in a similar place they were on the Quantums? They were right there, easily removable, on the circuitry in the disk! Not jammed and crammed into some small slot like they are nowadays...


The next thing was I wanted to check what was on the disks.. and like I had an idea how to mount FAT16, FAT32 and NTFS partitions on Linux... well, google is my friend so that wasn't a big of a problem anyways.


Now I can host more warez! har!

Thursday, May 25, 2006

Programmer deprived of sleep - Police suspects blood money is involved

Someone might guess from the title - I've been playing Hitman - Blood Money quite lot lately. It's the 4th game in the Hitman-series and a good step forwards yet again, in terms of graphics and gameplay. It's pretty cool to be able to make your kills look like "accidents" by pushing someone over a ledge for example.

Related to hitmen, you can hire one from here


So there hasn't been anything new in the programming field for these days... Today I continued my project again though. I've implemented building new units now and a menu where you can select the map you want to play, which is rather crude but does it's job.. same goes for pretty much everything, I'll do something about the graphics and such when the functionality is done otherwise :)

Now the task I took on today is updating the map editor to allow placing game objects... Units and structures. To do that, I need to do quite much other work not directly related to the task at hand:
Need to update map-format for object data - Simple, but need to do a parser for that too
Because the objects need to know which side they belong to when they are loaded, I need to change the format even more - Add details of the players involved
As the player details are saved into the map, that info needs to be changeable from the editor.. and also the game itself needs to create the players when loading a map and so on


The end result.. I'm going to make some kind of a Mission data holder class now, which will contain all the small details.. the players, the tile map, the unit data etc... also victory conditions, which I'll probably be adding later as they need something to base the win calculations on.

The editor has to be able to save Missions and the game has to be able to load Missions.


New music. I Love Disco Diamonds Vol. 39 which was released quite recently is awesome... definite recommendation for anyone who likes old synth/disco music.

And to whoever named a crazy hypertechno/eurobeat album "Shibuya Women's Pro-Wrestling Original Soundtrack"... What were you high on? I'm imagining women wrestling to high BPM techno music... @_@

Monday, May 22, 2006

Menus and stuff

I got a very simple menu system working finally.. although for some reason Direct3D.Font throws an exception when the application closes.

It's just a bunch of colored blocks and some text in them, drawn by a bunch of generic drawing functions I wrote.. faster than the old crap ones, yes. They are coupled with a Menu class which handles clicks and returns values if the user clicked on a button on the menu.

Also doing some clean-up work on the main game "State" which contains the functionality to draw the map, detect clicks and other crap.. States are basically something which can be given to the Engine, which then calls the Render and Think methods in the state... So one can have a bunch of states, like a "Main menu state" which draws a main menu like thing and contains the logic for everything that happens there and another state class which handles the game itself or something like that.

Here's a screenshot of the game.


Now I need to rework some of the game state mechanics since it was originally somewhat quickly written just to test the engine and most of the functionality was just bolted on top of it later... so it needs clean up and other work.


on the IRL side of things, only two weeks of school to go... I have no idea what I'm gonna do when the summer holiday begins... I'll probably sleep too much, stay up too long and stay in too much and look pale in the autumn compared to everyone else.. "So what have you done this summer?" - "Um, I was coding C# and IRCing"

Someone donate me a laptop and a WLAN switch/router so I can go outside and code there in the sunshine ;)

Friday, May 19, 2006

Opera will be the web-browser bundled with Wii

According to a press-release from Opera Software, their browser will come with Nintendo's Wii (ex. Revolution).

http://opera.com/pressreleases/en/2006/05/10/

Another one for Opera in the browser wars! I've always said it's the best browser around ;)

Thursday, May 18, 2006

Generating textures on-the-fly

I needed something to debug my pathfinding. I wanted to see how it advances when finding the path to a tile.

I thought... "I'll have it set the tile's texture to something else to see when it's doing what tile"... Okay. I made a bunch of graphics with a number on them and a counter on the pathfinder which changed the texture to one with a same number as the current loop was.

At first I had five numbered textures.. then I needed more. It was kind of tedious to create them in paint so I figured.. you can create a Texture from a Bitmap... What if I created the bitmap on the fly.. with GDI!

Ta-dah, I present you: generating textures on the fly with System.Drawing-classes.
The following example is "Using" System.Drawing and Microsoft.DirectX.Direct3D namespaces so if you can't find the classes, they should be somewhere in those.


//First, create a new Bitmap
Bitmap bmp = new Bitmap(20, 20);

//Create pens for drawing
//A black one for text
Pen p = new Pen(Color.Black);

//A white one for background
Pen p2 = new Pen(Color.White);

//Create a Graphics object from the Bitmap
//Dont worry, you can use a Bitmap even though
//it says Image in the parameter list
Graphics g = Graphics.FromImage(bmp);

//Create a font
System.Drawing.Font font = new System.Drawing.Font(
System.Drawing.FontFamily.GenericSerif,10);

//Create a Rectangle for filling the whole bitmap
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);


//Fill with white
g.FillRectangle(p2.Brush, rect);

//Draw some text with black in the top corner
g.DrawString("10", font, p.Brush, 1, 1);


//Now create a texture from the bitmap and you're done!
Texture t = new Texture(device, bmp, 0, Pool.Managed);


Now obviously this isn't very fast. Actually not fast at all... but it can be used for purproses like I did when the speed is not a problem.

Wednesday, May 17, 2006

A static engine

Earlier today.. or actually yesterday.. I was working on my game project again. It's going to be a small strategy game, kind of like Advance Wars. So anyways, I'm in the phase where I'm figuring out things like units and structures... how they will be done etc.

I have a base class for game objects, aptly named "GameObject". For now, there's also a GameObjectType enum, which can be two different things: either "Unit" or "Structure". I have my unit code in quite good order at the moment. The game loads unit data from an XML file, which defines the unit's name, texture, movement, weaponry and armor. The data is then saved into a container class, from where you can get a certain unit's details with the unit's name, eg. "Tank" or "Infantry" or whatever.. the class returns a struct, which has a method for generating a Unit-object from the data. The Unit object is an actual renderable class, which contains all the logic and related. I've used some units in my tests, and they can be moved around the map, when you select one, you'll get a highlight of the area where it can move to and so on.

Now, I was making a similar class for structures... Structures in my game would be something like... factories, where you could build tanks, airbases for building jets and helis and so on..
So obviously, a structure must be able to create a whole new unit into the world.. if it wants to, not every structure will do that. While implementing that, I ran into several problems. Firstly, the object manager, which is used to handle the units in the game.. eg. when the game is in "select unit" state, mouse clicks trigger a check in the object manager which then checks if you clicked on a unit or not and returns the unit in question if you did and so on... the problem with this was that the structures needed a reference to this.. well, no problem.. I'll just pass it to the structure-class constructor and save it. Okay, that's solved.

Next.
The actual game engine's device for rendering stuff. It would need that too! Guh.. I got tired of having to pass stuff not really even related to the object, so I thought that I'll try to see if I can modify the engine so that it's accessible from everywhere in the code...

so I made it a static class

I had tried to do this earlier in another project which I scrapped later due to loss of intrest and time... and failed miserably. The engine would always get stuck into the main loop, never even rendering anything. I had no idea what was the problem back then.

Now that I had succesfully already got my engine drawing into a windows forms control, a Panel to be specific, I thought that maybe I could get it working this time. Well, I did.

I tried the static engine with my map editor first, because it was simply easier to change than the game itself. As I have posted earlier on, the "old" engine is built inside a form... and the game is built inside that very same form too and so on... It was a bit hasty I guess, but now I have the engine as a separate class. (guess what it's called... that's right, "Engine")

There's just one problem with the editor now.. the other controls aren't drawn properly. They are drawn, but they kind of disappear and aren't visible at all times and other stuff like that. I think it's probably the render loop I'm using (http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx) since it's so crazily optimized for rendering with DirectX.

If someone knows about fixing that, let me know.



Another fun thing I stumbled upon: SizeF.Equals(something) is stupondously more expensive to call than comparing the Width and Height properties... I had NO idea. Thank you CLR Profiler for .NET Framework 2.0.

That's about it. For now. Back to hacking the engine and optimizing things. And I want to be able to sleep normally again goddamnit.

Friday, May 12, 2006

Getting rid of "Restart computer now" nag screen after automatic updates

You know that thing, which keeps popping up every 10 minutes or so, asking you to restart now or later... eventually gets a timer too...

Here's how to get rid of that most idiotic dialog in Windows XP I've ever seen!


Start / Run / gpedit.msc / Local Computer Policy / Computer Configuration / Administrative Templates / Windows Components / Windows Update / Re-prompt for restart with scheduled installations

Update April 14th 2007: this one's been wrong so long... You have to set the above value to some arbitary number to make it take that long until it shows up again. Doesn't seem it's possible to completely get rid of it, but the maximum value 1440 or something is quite long =)

Do it now, for the sake of your mental health.

Labels:

A*

A*... does that ring any bells? It should, if you've been playing with pathfinding algorithms.

I made an incredibly crap implementation of that into my tile based game thing. Incredibly crappy, eg. it takes ages to find a path sometimes... but hey, it does find the path, even though it adds some 20.000 tiles to the lists even though the map doesn't contain that many... I know it's buggy, yes


I was playing with an idea of a "raster renderer" thing made with Direct3D. As you might know, you can draw vertices and wire-frame triangles too... I thought that what if you'd render lines with that kind of rendering, like you'd draw lines with GDI or anything... and raw pixels with single vertices.

Something which could draw filled rectangles and stuff would probably be very possible. Need to look into that after I've fixed the pathfinding code. I could use that to render simple graphics.


Another night spent with no sleep. I need to do something about my sleeping cycles. The next thing I'll be doing now is probably hit the shower and go to the store to grab some Pepsi or something :]

Sunday, May 07, 2006

Keyboard hooks revisited

I realized there's an even simpler way to make a global keyboard hook than the way I demonstrated earlier, though this method requires DirectX.

Using the DirectInput Device class for acquiring the keyboard you can create a global keyboard hook. It's very simple, just a matter of few lines of code

The following code could be used for hooking the keyboard


using DXI = Microsoft.DirectX.DirectInput;

//this is taken from my keyboard handler class
//keyboard is a DXI.Device in the class.
public void AcquireKeyboard(System.Windows.Forms.Control parent)
{
keyboard = new DXI.Device(DXI.SystemGuid.Keyboard);
keyboard.SetDataFormat(DXI.DeviceDataFormat.Keyboard);

keyboard.SetCooperativeLevel(parent,
DXI.CooperativeLevelFlags.Background |
DXI.CooperativeLevelFlags.NonExclusive);


keyboard.Properties.BufferSize = 10;

keyboard.Acquire();
}

Reading the keyboard input could be done with the following


DXI.BufferedDataCollection dataCollection = keyboard.GetBufferedData();
DXI.Key key;

if (dataCollection != null)
{
//loop through the keys changed
foreach (DXI.BufferedData data in dataCollection)
{
key = (DXI.Key)data.Offset;
//now we have the key
//do something with it here
}
}


In the above code, data.ButtonPressedData is 1 if the key was pressed down and 0 if the key was lifted.

With this method though, you won't get an event notification when a key state is changed. You have to make a loop which checks the key state and write your own event or such.

Here's my keyboardmanager class code
I don't know if it's any good, but it works well enough at least for now... and it has events which get triggered properly.
To acquire the KB, just call the AcquireKeyboard method with the form as a parameter and make a loop which calls Update()

Tiling trouble

Last time I posted about the tile map editor thing for my engine.

Now I'm in the middle of reworking the whole tile map code. There was a certain bit of problem: all the data a tile had was the texture and the name of the texture.

..and the texture name part was kind of glued on top of the Plane object :p


So now I've made a struct for tile data. It contains a name for the tile, a tile type (something like.. can go here, can't go here and such) and a TextureData struct, which contains the name of the texture and a reference to the actual Texture object.

I need to do some refactoring on the tilemap classes to make it use the new data structures and so on.



Being an old C/C++ user (and PHP), I sometimes just can't get it into my head that C# passes classes as references. I always feel like I'd need to use a pointer or something like that. Honestly said it's a very useful feature to not have to do that.

More engineering

I've been working on a tile map editor today.

I bound my engine into a Panel object residing inside another form... a bit hacky at the moment, as the engine itself is bound into another form. When the editor starts, you get a "ghost form" into the background which is the engine's own form :)

The map editor itself is looking quite good. It loads textures from a file, saves maps into a XML format... changing tile textures is done with clicking the tile with the mouse... I like it! I'm quite surprised I even managed to get it working that well!


I had a huge problem with getting the mouse click detection working... the tile positions would just get offset so much that you'd have to click in a totally different location than the tile itself.

I found out that by setting device.Transform.World = Matrix.Identity after rendering a scene fixes it. It was that simple, and I tried all kinds of weird stuff... bleh.

I also had a small problem with changin the cursors coordinates from the screen coords to the applications coordinates... but after a bit of looking, there was a function on the Control class which does it for me. PointToClient(Point p)



And continuing on my earlier attempts of optimizing the rendering process...

Every tile in a tilemap has a vertexbuffer, containing the vertices for it. Someone suggested that I should use a static vertexbuffer... then every tile would use the same buffer, therefore saving resources.
Okay, so I do that...

FPS with a non-static vertexbuffer = ~260
FPS with a static vertexbuffer = ~360

Nice I'd say.


There's the problem of different sized tiles though... If I were to have different sized tiles (they're all of the same size at the moment), the static buffer wouldn't work...

So I added a static Size-struct, containing the size of the tile in the vertexbuffer. Every tile also has their very own size struct, which is then compared to the static one to see if the vertices in the static buffer are correct.
If the size differs, the Plane calls it's own Reset() method which initializes the static buffer with the correct vertices.



Onwards, to where no man has gone before!

Saturday, May 06, 2006

A new version of Windows Live Messenger

Microsoft put out a new version of Windows Live Messenger beta today.

The interface has been changed to look a bit different, with some fancy graphics.
They have also fixed the "What I'm listening to" feature to show the artist's name too. Probably other fixes too but I didn't notice anything other than the obvious :)


Friday, May 05, 2006

Picking up stuff from 3D-space with mouse rays

Okay so I finally have it figured out thanks to the nice people at microsoft.public.win32.programmer.directx.managed newsgroup.

I'll just post the code here too in case someone else might someday run into a similar problem, and to be honest, there are no good examples of doing this unless you're using a Mesh object.


//Checks if point P is inside the plane
internal bool PointIntersects(Point p, Device d, out IntersectInformation intersectInfo)
{
//Create near and far vectors from the Point location
Vector3 near = new Vector3(p.X, p.Y, 0);
Vector3 far = new Vector3(p.X, p.Y, 1);

//Unproject the vectors into world coordinates
near.Unproject(d.Viewport,
d.Transform.Projection,
d.Transform.View, Matrix.Translation(location));
far.Unproject(d.Viewport,
d.Transform.Projection,
d.Transform.View, Matrix.Translation(location));

//Calculate the direction of the ray from the vectors
Vector3 dir = Vector3.Subtract(far, near);

//Set up the locations of the vertices
//in the first triangle in the quad
Vector3 loc1 = location; //Bottom left
Vector3 loc2 = new Vector3(location.X,
location.Y + size.Height, location.Z); //top left
Vector3 loc3 = new Vector3(location.X+size.Width,
location.Y, location.Z); //bottom right


//check for intersection
bool intersection = Geometry.IntersectTri(loc1, loc2, loc3,
near, dir, out intersectInfo);

//If we didn't find an intersection in the first triangle,
//check the second
if (!intersection)
{
//Set loc1 to the coordinate of the top right vertex
loc1 = new Vector3(location.X + size.Width,
location.Y + size.Height, location.Z);

//Check the other triangle
intersection = Geometry.IntersectTri(loc2, loc1, loc3,
near, dir, out intersectInfo);
}

return intersection;
}


I used that inside my Plane class which is used for rendering 2D-like quads.

Thursday, May 04, 2006

Engineering

What I've been working on lately is a 2D-engine type of thing. It's made with managed DirectX.

A fake-2D that is... It uses Direct3D to create vertices in 3D-space and renders textured quads that look like 2D.

Screeny

If some smartypants thinks he can identify the game where I stole the tile graphics from, go ahead and try to guess. ;)

The engine currently can render a tile map like in the screenshot... the rendering process can probably be optimized by using some trickery and made faster. The actual tile map data is loaded from a XML file like this and the texture data is saved in a resource file, which uses some MS defined resource file format... I made a small utility to create resource files and add/remove/extract resources to/from them and a DLL which contains the code for getting System.IO.Streams of the files inside.

So now I'm trying to get "picking" to work. What's this picking? It basically means that I want to get the engine to detect what objects are under the mouse cursor in 3D-space... which is giving me a damn headache. I've tried projecting the mouse coordinates into 3D space to create vectors and rays and whatever and calculating intersections... and tried projecting the quads into 2d space, which was more successful but the quad positions are a bit offset, so it's not working well enough either. HELPPpp...


On other news, Super GT 2006 was released today (actually yesterday as I'm posting this on 4th). The linked page contains samples... so go go go.


And on the other other news, which are actually rather old, the fansubbing group Bakafish has been subbing Hard Gay episodes. For those of you who don't know who this Hard Gay persona is, go ahead and take a look at this wikipedia article... or actually, I'll just say it here: He's hilarious. 'nuff said about that.

Visit Bakakage forums for the episodes. You may have to register to get access to the Hard Gay forum.



My random thought of the moment: why do most people think I'm weird, because I don't feel any need to "hunt" women? Actually even I find it weird at times, since everyone says so... Come on, sex is not the only thing a woman can offer.


That's it for now.