Thursday, December 24, 2009

ViruZ update 3

I moved the draw function into the entity today. I tried fiddling around with a way to effectively buffer the drawing, so it doesn't have to draw the circle again, but can just use that buffer on another position.
I don't think I got it right though. I'm not sure how cairo does things internally, but I'm just not sure.

Well, I tested the performance and I get about 50FPS with 100 outlined and anti-aliased circles, rendering on one core at 2.4Ghz; I'm still not sure how much my graphics-card is used with cairo, but I have a GeForce 9600GT.
This will probably become slower though, since there is no logic done atm, but that result shows me that it'll probably draw fast enough. 30FPS should still look fluent and maybe I can still optimize some stuff. I'm also not too sure that I'll need to draw 100 objects every frame (it's redrawing the whole scene atm).

Merry Christmas

I'm not a Christian, I don't even believe in god for that matter, but I was raised and still live in a Christian society, so Merry Christmas everybody.

If you believe in a(nother) religion, then so shall your god ram his invincible fist through me, so that my lifeless body shall explode by the mere thought of your angry god and my soul shall burn in eternity.
Good day to you, Sir/Madam.

ViruZ update 2

Okay, so now I finally fixed that window-closing. There was some weird stuff going on, because the event actually got rised and handled, but PostQuitMessage didn't seem to do its job.
So I am perkily pooping on this, which tells you to "not post the WM_QUIT message using PostMessage; [but to] use the PostQuitMessage function.". And then it works.

Yay :3

I also implemented double-buffering, using the cairo_push_group and cairo_pop_group_to_surface-functions. Well, it's not really double-buffering, since I'm not buffering the image and swap the fore- and back-buffer, but it gets rid of the flickering so it's good enough for me.
I stumbled upon them while looking for a way to copy surfaces.
I hope they cooperate with threads :S


I also started laying out a design for my virus-baseclass. I'm hoping to somehow cache the drawn circle, maybe even share that cache among equal looking viruses, and thus only having to copy the already drawn circle on the surface.

So my next step lies in putting some flesh (code) on the bones (class layout), making my draw-function loop through an array of viruses (later with threads) and use their draw-function.
After that, I will implement moving-logic to the viruses. Then the Anti-V. Then cleaning up a little and maybe I'm gonna upload a public executable.


Once I am taking care of installing GRUB to boot Ubuntu again, I'll also take care of the Linux-port. It'll be available for all Linux, which are running the X Window System and are compatible with cario. I guess.

Tuesday, December 22, 2009

ViruZ update 1

Well, I don't know if I'm going to post frequently about it, but well.. yesterday I moved the stuff into my Window-class completely.

There is a more elegant solution to my messagepump-function, instead of using a fake singleton.
Of course, other people have had this problem, too. I googled and quickly found an article on GameDev about it. Using Set/GetWindowLong with GWL_USERDATA lets you store a pointer, which will be associated with a window. I'd explain it, but it's probably easier if you just read this. If you wanna use it, you'll have to modify it a bit. Check for GetWindowLong to return NULL, because the first message is not WM_NCCREATE, but WM_GETMINMAXINFO, which does not have the lpCreateParams.
I ran into some fun invalid pointers with this :)


I then fiddled around with getting my program to close when you hit alt+F4 or click the close-button. I also ran into some invalid pointers by destroying the window on WM_CLOSE, but still running the messagepump-loop.
Fixed that by not destroying the window and calling PostQuitMessage on WM_CLOSE and WM_DESTROY. I'm gonna make WM_DESTROY check, if WM_CLOSE got called before at some point.

That only half-way fixed the problem though. There are problems when the window is closed in specific points in code. WaitMessage waits for new events only, not unhanded ones. So if I call WaitMessage after the user has pressed the close-button it would not close. I actually have no idea where that event went though.. but it just seemed to disappear then.
I fixed that just a minute ago by putting my redraw-hack in a thread, rather than in the messagepump-loop.

[edit:
No, I didn't fix it. Strange stuff, it does not work at all. It only works after you've moved the window o_O
After you've done that, it works like it should]


The only problem left is slight flickering. I just have to double-buffer it by hand, then it won't flicker I bet :)


Screenshot:
note: that screenshot was shot yesterday

built cairo

Wow, this seems to be my blog-month. Or maybe it's the holidays. Or my short hair. Or something else, that makes me more productive.


Note: the following-stuff is quite programming-related and might confuse you if you are not a programmer yourself


Whatever it is, I got cairo to compile and link, finally. Thanks to Stack Overflow I opened the MSYS-enviroment in the Microsoft Visual Studio Commandline Enviroment and thus got the UNIX-tools with the MSVC-tools.
Well, it wasn't as easy as just typing 'make' into it, I had to fiddle around with the makefiles, got some nasty errors, but now I've build all the required libs and cairo itself.

I was already thinking about just using pre-built libraries, but now I can sleep better :P


cairo doesn't have convenience-functions like SDL or OpenGL (though [{free, open}]GLUT) or something to open a window. I could use some GUI-library, but since I'll be using cairo to draw everything that seems to be a little bloat. I'll just have to write the platform-specific stuff for Windows and UNIX with XServer, maybe also MacOS stuff, myself.

As I can only boot Windows atm (install had overridden the boot-sector; didn't care to fix it yet) I started working on the Windows-port. I seem to have to use GDI for cairo, though I am wondering whether or not I am still getting the hardware-accelerated goodness.

I got a Window open pretty fast and used tutorial-code to draw on it, but I wanted debug-output. So I used AllocConsole, but std::cout can't print on that without rerouting.. and that code I saw for that seemed weird, so I wrote a small templated function to use WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), ... instead.

Windows seems to think that my Application does not respond very well and draws that loading-cursor when you hover over it. I also can't click the close-button; probably the same reason. I'm not really sure how to fix it, but I'll care about that later.


I initially had problems redrawing the graphic, which is needed since the scene is going to have moving stuff. I was thinking that RedrawWindow(wnd, NULL, NULL, RDW_INTERNALPAINT) would work, but the message/event WM_PAINT didn't go through. I then tried obtaining the rect via GetBoundsRect(GetDC(wnd), &rect, 0), but it is empty. I simply hard-coded it to have the same height and width as the window itself, and using this I can redraw fine.
Of course I won't be drawing the whole window over and over again in the final version if it doesn't need to be.


Well, right now I am on packing the test-stuff I had into a Window-class. It seems like I can't get a std::tr1::function with __stdcall. Really sucks, because I need to call a member-function for the MessagePump and the Windows SDK uses the __stdcall calling convention.
I tried around with casts 'n stuff, but I can't seem to get it to work :'(

I'll fiddle around a bit more, and if it doesn't work I'll hack it by having a static function in the Window-class returning an instance of itself. Kinda like a singleton, only that Window is no singleton...

Sunday, December 20, 2009

ViruZ - fifth rewrite

Some of you might have heard ViruZ before, but I doubt you will remember it.
I posted about it when I still wrote in German.

So, it was a flash-game before. It's about viruses you have to kill with an antidote.
The viruses are represented with circles and you can inject the antidote with a mouse-click on the cursor-position. The viruses move around randomly.
On injecting the antidote, the viruses in a set area around that spot will be infected and become sick. Some may survive, some may die. Any viruses, that are near enough on sick viruses, will get sick themselves.

I had a flash-version going, then attempted to rewrite that with proper use of OOP, but I ran into some complications with my C++-way of thinking.
After that I attempted to rewrite it in C++ using Qt. I also had some problems due to being new to Qt, but now, on my forth rewrite, I got around them.
Sadly Qt seems to be too slow. It draws 50 viruses at around 3 FPS. I am using vector-graphics, but they should be hardware-accelerated and I'm using caching, so it's probably the loop. They are saved in a stack-allocated array, so it's probably just to big.
Well, Qt is meant to be used for GUIs, not really games.

I'd use threads to batch-process the movement and maybe try to coordinate batched drawing, but Qt seems to be limited in its threading-ability.

So I am looking into cairo atm. I've already managed getting zlib and libpng to build, but I'm kinda clueless about cairo. fmake doesn't seem to work, so I'll try downloading MSYS.

Thursday, December 17, 2009

'Bout mah hair today

Well, today things look a bit different.

If you were reading the post of yesterday, you will notice that I was emotionally touched by the events that went wrong. I gave it some thought yesterday evening and I dealt with it.
My mother should know after more than 19 years, that I am not that well with names. And if she doesn't care that I really take this to my heart and that I am disappointed in myself, well that's just not my concern. I did say sorry, I did explain myself and I did search for solutions, but frankly I do not have a time machine (yet!).

So, when I stood up this morning and looked this new face in the mirror, my first thought was about "Man, do I have big eye brows". Of course I also was reminded that I was going to the wrong barber shop and that I might not be able to sell my hair, though I have gone through some trouble to get to this point, but whatever.
It feels great having short hair, finally after having decided for this over a year ago.


Also, no pics yet. I only have the before-picture atm and I wanna post both at the same time.
You still have to wait. Or kill yourself and become a spiritual creature that can travel through the multiverse and the time. Have fun! and try not to make a mess :/