Jump to content
  • Advertisement
Sign in to follow this  
StratBoy61

My Screensaver using DirectX 9.0

This topic is 4653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I am rather new to the video game field, my background being more *traditional* developments (databases and enterprise stuff). However, I am pretty decided to dedicate myself to a serious project in the video game business (since I quit my job for it!). My first serious project, this screensaver that you can download at http://animateddesktop.site.voila.fr. AnimatedDesktop Screensaver sample Feel free to use it if you like it. You will notice that I mentioned about a registered version for $1.99. However, this version is not ready yet (I assume that I must host a web site in order to automate the online registration process or have a provider that allows programs to be run on their servers) and I first wanted to have some feedback about the program itself. My latest work was the integration of a 2D physics engine sample in the screensaver. My next project will be focused on a 3D physics engine. I will certainly shamelessly integrate Chris Hecker's 3D physics engine sample (http://www.d6.com/users/checker/dynamics.htm#samples) into my code to start with... once again :) I might post something later in the Help Wanted forum. I have an idea of an interesting project, but I want to move forward a little bit more on it before I can speak about it. Cheers StratBoy61

Share this post


Link to post
Share on other sites
Advertisement
I like it. : ) How do you get the info on which icons are on the screen. Also I was wondering how you gather the current screen(without the icons). I am guessing you find the info on what the current picture is, but how?? : ) I like how the icons themselves are lights. : ) Good work!
Levi

Share this post


Link to post
Share on other sites
It looks nice! Cool idea!

I think it will look nicer if you set 'center of gravity' of the objects to be the center of the icon and the text. Now you have center of gravity in the middle of the icon only, which makes it look unnatural when it rotates freely.

Also, what going on behind the scenes? Any heavy collisinos detection routines or something?

I ran it on a laptop with a not-so-good graphics chip (an integrated Intel Express 915AG or something) but I think I should be able to run it smoothly, now I have like 15-20 fps.

If I would have to make a guess, I would guess that you have a texture for each icon in the app, and hence need to change the texture on the D3D-device for each icon you render. If that is the case, the app will run a lot faster if you drew the icons from diffrent source rects from the same texture.

Changing texture on the device is slow, so avoid it as much as you can.

Also, I think you should make the simulation run in "realtime", that is if I would drop a coin at the same time that an icon began to fell, they would reach the bottom of the screen at the same time. (Maybe it is running in slowmotion because of the heavy-things-behind the scenes though.)

I could definitly have this one as my standard screensaver, if it would be a bit more polished. [smile]

Share this post


Link to post
Share on other sites
Thank you for your feedback !

1) In order to get the info about where the icons are on the screen, I used the code below. If you just paste it in a new VC++ project (like a simple DialogBox with only one button, in the OnButton1() method), it should work.


HWND hWnd = ::FindWindow("Progman", NULL);

if (NULL != hWnd)
hWnd = FindWindowEx(hWnd, NULL, "SHELLDLL_DefView", NULL);
if (NULL != hWnd)
hWnd = FindWindowEx(hWnd, NULL, "SysListView32", NULL);
if (NULL == hWnd)
MessageBox("SysListView32 not found", "Not Found", MB_OK);

// if the window was found, ...
if (NULL != hWnd)
{
int count=(int)::SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);
int i;

LVITEM lvi, *_lvi;
IMAGEINFO *pImageInfo;
POINT itemPoint, *pRemoteItemPoint;
RECT itemRect, *pRemoteItemRect;
HIMAGELIST pImageList;
char item[512], subitem[512], Msg[255];
char *_item, *_subitem;
unsigned long pid;
HANDLE process;

GetWindowThreadProcessId(hWnd, &pid);
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|
PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);

lvi.cchTextMax=512;
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);

pRemoteItemPoint=(POINT*)VirtualAllocEx(process, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);
pRemoteItemRect=(RECT*)VirtualAllocEx(process, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
pImageInfo=(IMAGEINFO*)VirtualAllocEx(process, NULL, sizeof(IMAGEINFO), MEM_COMMIT, PAGE_READWRITE);
pImageList=(HIMAGELIST)VirtualAllocEx(process, NULL, sizeof(_IMAGELIST), MEM_COMMIT, PAGE_READWRITE);


for(i=0; i<count; i++) {
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);

lvi.iSubItem=1;
lvi.pszText=_subitem;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);

ReadProcessMemory(process, _item, item, 512, NULL);
ReadProcessMemory(process, _subitem, subitem, 512, NULL);

itemPoint.x=0;
itemPoint.y=0;
WriteProcessMemory(process, pRemoteItemPoint, &itemPoint, sizeof(POINT), NULL);
::SendMessage(hWnd, LVM_GETITEMPOSITION, (WPARAM)i, (LPARAM)pRemoteItemPoint);
ReadProcessMemory(process, pRemoteItemPoint, &itemPoint, sizeof(POINT), NULL);

ZeroMemory(&itemRect, sizeof(RECT));
WriteProcessMemory(process, pRemoteItemRect, &itemRect, sizeof(RECT), NULL);
::SendMessage(hWnd, LVM_GETITEMRECT, (WPARAM)i, (LPARAM)pRemoteItemRect);
ReadProcessMemory(process, pRemoteItemRect, &itemRect, sizeof(RECT), NULL);


wsprintf(Msg, "%s - %s [%d,%d]\nitemRect.left = %d\nitemRect.right = %d\nitemRect.top = %d\nitemRect.bottom = %d",
item, subitem, itemPoint.x, itemPoint.y, itemRect.left, itemRect.right, itemRect.top, itemRect.bottom);
MessageBox(Msg, "SysListView32", MB_OK);
}

VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
VirtualFreeEx(process, pRemoteItemPoint, 0, MEM_RELEASE);
VirtualFreeEx(process, pRemoteItemRect, 0, MEM_RELEASE);
VirtualFreeEx(process, pImageList, 0, MEM_RELEASE);
VirtualFreeEx(process, pImageInfo, 0, MEM_RELEASE);
}





2) In order to get the current screen, I search for information in the Windows XP registry ; the background image, the desktop color and some other stuff. As for the resolution, I call the GetSystemMetrics(int nIndex) function with the SM_CXSCREEN and SM_CYSCREEN flags.

3) Regarding the collision detection and physics routine, I shamelessly copied Chris Hecker's code of his "2D Physics Sample". Nothing much, just cut and paste :)
So you noticed that the gravity center was only the icon and not the text ? It is completely true. I have not tried to set it to the center of the whole structure (icon+text). I was thinking that the physics routine would not handle it, or that it would be too slow... I might take a look at it, just to see if it is possible and what is the impact on the performance.

4) Speaking of performance, you are completely right regarding the texture. I actually use as many textures as there are icons. This number is even actually doubled, because there is also one texure for the icons' titles ! To tell you the truth, I thought about what you said --about chuncks of a unique texture ! Okay, it is easy to say that afterwards, I know... :) I think that you are totally right: It should improve the performances on slow video cards systems.
Now, do you think that it is worth doing it --as an exercise ? Are a lot of games today using this "trick" ?

5) I beleive that if you set the icons' speed to a higher value (in the Settings panel), the simulation could look more "realtime". I arbitrarily put a maximum of 30, but if you manually edit the AnimatedDesktop.ini file and put a value like, say "60", it might look more natural.

Cheers
StratBoy61

Share this post


Link to post
Share on other sites
Quote:
Original post by StratBoy61
4) Speaking of performance, you are completely right regarding the texture. I actually use as many textures as there are icons.

Enselic is coming through, he shoots, AND HE SCOOORES!!

Quote:

Now, do you think that it is worth doing it --as an exercise ? Are a lot of games today using this "trick" ?

I rank that as the absolute number one priority of the items on your 'to improve list'. All serious engines/programmers use this technique.

In this kind of app there's is no need for an engine, but having all those icons on the same texture will improve performance significantly. I wouldn't be surprised if you were able to increase performance by 200%.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!