Thursday, December 31, 2009

ViruZ update 8

So, I guess another time was today. Because I fixed the huge FPS lag.
cairo_scale seems to be a slow operation (or at least drawing on it after such a transformation). I had a buffer with a single blue circle, then would loop over it a few times to draw it.
The circles would be small at first and become bigger till they reach a certain size.

I tried out some different stuff, and it proved to be the fastest way when I just re-draw the circle each time it gets bigger, instead of scaling a buffer.
The performance-hit is now about 5FPS per core (since that drawing is not threaded (yet?)).

Here's a screenshot of it:

There's a nasty bug atm, which leads the program to just stop rendering after a time. I'm pretty sure the time is bound to the FPS, so it stops after a certain amount of rendered frames.
At first I thought it would be a memory-overrun somewhere, but that looked fine in the performance-monitor. So I began checking the code and the drawing-functions are executed properly. Then I suspected that maybe my timer would reach its max and stop counting, but that would just lead to an overflow and cause weird moving-behavior for one frame. Plus, I calculated that it will have to run over 500 years before it overflows.
I tried commenting out the drawing of my serum and the viruses (as well the update-function-calls), but it still just freezes.
I'm very clueless, but search will go on.

This post is, compared to the other ViruZ updates, quite early. This is due to tomorrow being the year 2010. I'm going to a friends New Years party in about 10 minutes, so I was searching for something to do and remembered, that I will probably not be able to post an update within the next few hours and that it would kill most of the time I wanna kill.
So, here it is. yaaaaaaaaaaaaaaaaay[/noemotion][/sarcasm]

Wednesday, December 30, 2009

ViruZ update 7

I still tweaked the render-code a bit today. Well, for threaded drawing at least.
I have a loop, in which I update and then draw the viruses. The mutex is only required for drawing, that's why I didn't put both in one function.
I also can then update while the window should not be drawn (e.g. minimized Window).

So, before I was like

for each(virus) {

now it's alike

for each(virus) {
  while(!tryObtainingMutex()) {
    virus = next_virus;
  //we have the mutex now
  for each(virus in queue)
if(!queue.empty()) {
  for each(virus in queue)

It's much more code, but I still got 10-20 more FPS out of it on my dual-core.
I also cleaned the thread-class. I guess I'm gonna keep it.

I also implemented the serum. Well, partly. Mostly just the drawing- and animation-part.
Sadly the FPS get cut in half while drawing it D:
I guess I'm doing something wrong.. but I'll get behind that at another time.

ViruZ update 6

I've been implementing a hacky way of clipping/masking stuff. I simply wanted to look at the FPS-change.
I've been writing some stuff for only drawing half the screen. Turns out that this as well does not affect the FPS much. I'm scrapping out half the frame and almost no change!
I guess I won't get much of a FPS boost for optimizing my drawing-routine. The most stuff seems to originate from the loops (stepping through each virus and calling its update- and draw-function) and from some other internal stuff, but not really drawing the vector graphics.

That's a bit disappointing, but at least I won't have to worry about that and can concentrate more about the actual game.

Sunday, December 27, 2009

ViruZ update 5

So, I added threading. The array is split into n parts, so that then n threads can get to work drawing. I'm using a CRITICAL_SECTION to keep cairo okay, since it does not support threads.
Well, since my viruses have a rather small logic (they bounce around), that didn't really pay off for the effort.

I have to make something more efficient, such as creating n rectangles or something and draw on them without the need of a CRITICAL_SECTION I guess, but drawing the viruses doesn't really seem to be the bottleneck.
Drawing them in one thread I get 150-200FPS, in two (I have a dual-core without Hyper-Threading) 170-240FPS and not drawing viruses at all (so just background & FPS-text) 240-430FPS.
The former two are again 100 viruses and I am still drawing the whole screen each frame.

The Thread-class I made is pretty hacky; I think I'm going to take it out again. I'll try how well it performs when I add this separate rectangle-thing and decide upon that. If I get a boost of about 100FPS or more I'll fix the class up, if not I'll remove that feature.

Friday, December 25, 2009

ViruZ update 4

A major performance-improvement today. Turns out that double-buffering increased the performance!
My guess is, that this way the device context doesn't have to be updated at every call of the paint-function.

I also added simple movement (the circles are simply moving in one direction) and the speed I'm getting from this is about 180-280 FPS for still 100 viruses, represented by outlined and anti-aliased circles blah blah :D
Oh, and the FPS-text is also drawn :P

I'm also still always drawing the whole frame and only using one thread to draw.
I also fixed some small stuff in my message-pump, which caused some messages to be sent twice (tbh I'm not sure if that is still occouring..).

note: that L on the FPS just indicates, that it is a double-precision float(ing-point number).

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.

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 :)

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 :/

Wednesday, December 16, 2009

Mah hair

is about 3mm long. And just an hour ago they were about 60cm long. Kind of a bit of a difference, huh?

I explained some stuff in my previous Mah hair-post, so I won't have you tell about that stuff. But I have something to say about my visit to the barber: My mother made an appointment by one in the city where we live.
My Ex-Girlfriend wanted to see me getting my hair cut off, so I met her a little sooner. We were driving with the bike to the barber, but as it will turn out, I simply did not remember the full description of the way when I saw a barbershop.

I am planning to sell my hair. That's not the reason why I cut it of, but it's a nice thing, since it's not costing me much if I do so. My mother already explained to the barber how they shall cur my hair so we can sell it, but since I got to the wrong place they did not do it like planned.

When I got home my mother was really mad at me. She's in doubt that I can sell it appropriately now and she doesn't want to go to that barbershop she made the appointment with, since that wrong I did makes her look bad to them. I tried to explain why it went wrong and that I am sorry for the way it turned out, but it is understandable that she still is mad.

I am really disappointed in myself for not realizing that I was inside the wrong shop. It all seemed so easy-going, but now everything just looks so... I don't know; I can't find the right words for it, at least something bad.

If I am still able to sell my hair, I will pass the money to my parents. I feel just wrong taking it now, even if it turns out alright. I know that I cannot right the wrongs I did today, never ever probably, but I will just have to live with that.
I actually thought that I will be happy looking in the mirror and seeing my short hair, but now all I will remember is the sorrow of this day.

Also, I will post pictures of me with and without my long hair soonish.

Monday, December 7, 2009


I've been jogging two weeks ago, the first time I did real sports after my ligaments had been torn. I really enjoyed sweating out of physical effort.
It's been for school sport, and I'm glad to say that my muscles didn't get too rusty within the 2.5month. I think I could have been jogging with the top, if I hadn't told my teacher why I prefer C# to Java. We had a little discussion about C# vs Java and my teacher was looking for the pupils on the back, so I would have had to put a lot of effort to reach the top ones. Besides, I tried not to get too far away from the group that I was already in, since we were quite spread out.

We were jogging about 50min. and a distance of about 7km, which calculates to an average speed of 2 1/3 m/s.
I also had hella aching muscles afterwards :P It kicked in about evening after I've been sitting on the computer for some while.

I think the lack of sport really demotivates me for some reason. I haven't been doing much work lately: haven't been learning for tests, not doing any homework (I usually at least try to remember what we did last lesson and if there is any homework we must do), barely been preparing the speeches I have to give, little coding, ...
One good thing I did was writing this up. And this is because its ticket is marked essential and I'm quite excited about the project CML. For one about the actual code that we'll have to write, the design concepts we have to think up as well as its application.
But CML is material for another blog-post...

So, getting back to sports, after I've been playing badminton last week in school, I've decided that my foot should be healed well enough to get started with volleyball again. Since on Friday last week we had a match or some tournament I didn't participate. I also don't go Tuesdays, because we have school sport on Wednesday and I've already been missing enough of that...

As such, I am looking forward to this Friday. Badly enough though that till then I will have conducted all my presentations. I think I still can prepare for a test we write this year though.

Stay safe folks!