Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

115 Neutral

About HolyGrail

  • Rank
  1. HolyGrail

    weird win32 GDI bug

    Hello, Quote:From what I understand, messages are dispatched when an event happens and with GetMessage() when there are no messages, the program halts/stalls. This is counter productive considering a game with moving graphics where things need to be repainted regardless of input. If you try to render objects aside the WM_PAINT it is very time/CPU consuming and there is a risk like you say of a program lock. Because you have an infinite loop and every time tick /milliseconds conceeded from the OS scheduler to your program/main thread, you try to render many GDI objects.. with Direct X/D3d ( with D3DXSprite ) it is totally different : you can call a render() function following a while(msg.message != WM_QUIT){} else.... because all rendering process is delegated to Direct X rendering pipeline so the main thread linked to your program doesn't have to deal with all GDI stuff This is a a part of the Tut06_Meshes\Meshes.cpp example taken from the DirectX SDK Quote: while( msg.message!=WM_QUIT ) { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else Render(); } But no confusion ! : this is an example ONLY for Direct X Quote:And how can I put motion picture in a WM_PAINT message? it is very simple :-) : when your program starts , create a timer and then during each timer event simply call InvalidateRect() or SendMessage(hwnd,WM_PAINT,0,0) to force the Operating System to place a WM_PAINT message in your program messages loop to repaint the window. During each timer event or tick , you can render animations with a simple frame pointer. If you want more performance you can also call QueryPerformanceCounter(). But it's not recommended to render object like in the code provided before
  2. HolyGrail

    weird win32 GDI bug

    Quote:Original post by boogyman19946 Alright, I've been happily restoring my programming on the pong game I've started some week ago and I am struggling with a weird and relatively hard to find bug. Can anyone help me out? Hello Boogyman the way you try to perfom drawing with GDI is very wrong If you want to use GDI and paint objects on the screen, you should consider using WM_PAINT message instead. With the code given above what you are doing in fact is creating a bottleneck in the message processing Quote: /// the main function entry point int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { MSG msg ; WNDCLASS wndclass ; wndclass.lpfnWndProc = WndProc ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("Can't Create Window!"), g_szAppName, MB_ICONERROR) ; return 0 ; } ////// window initialization ///// //.... ////// window message dispatching ///// while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } /////// Window Procedure function ///// static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hdc; static PAINTSTRUCT ps; switch (message) { case WM_SIZE: break; case WM_PAINT: hdc=BeginPaint(&ps); /////////////////// use the HDC and make all drawing here Paint_Objects(hdc); ReleaseDC(hdc); } break; return DefWindowProc(hWnd, message, wParam, lParam); } void Paint_Objects(HDC hdc) { HDC hMainDC = hdc; HDC hMemDC = CreateCompatibleDC(hMainDC); backBuffer.ClearBuffer(); ////////////////// // MOVE OBJECTS // ////////////////// if (!gPause) { PlayerEnum pe; gpPlayerTwo->MoveTowards(gpBall->mPosition); // non human player moves towards ball pe = gpBall->MoveBall(*gpPlayerOne, *gpPlayerTwo); if(pe != NONE) { if (pe == PLAYER1) { gpPlayerOne->mScore++; TextOut(hMainDC, 400, 300, "Player 1 scored!", 17); } else if (pe == PLAYER2) { gpPlayerTwo->mScore++; TextOut(hMainDC, 400, 300, "Player 2 scored!", 17); } //gpPlayerOne->CenterPlayer(center); //gpPlayerTwo->CenterPlayer(center); gpBall->ResetBall(); Sleep(2000); } } ///////////// // DRAWING // ///////////// // Background HBITMAP hbmpOld = (HBITMAP)SelectObject(hMemDC, hBackgrBmp); BitBlt(hMainDC, 0, 0, backBuffer.mWidth, backBuffer.mHeight, hMemDC, 0, 0, SRCCOPY); // Draw objects gpBall->Draw(hMainDC, hMemDC); gpPlayerOne->Draw(hMainDC, hMemDC); gpPlayerTwo->Draw(hMainDC, hMemDC); std::string tempString = "Player 1's score: "; tempString += itos(gpPlayerOne->mScore); TextOut(hMainDC, 260, 50, tempString.c_str(), tempString.length()); tempString.erase(); tempString = "Player 2's score: "; tempString += itos(gpPlayerTwo->mScore); TextOut(hMainDC, 410, 50, tempString.c_str(), tempString.length()); tempString.erase(); if (gPause) TextOut(hMainDC, 400, 300, "Paused!", 7); backBuffer.PresentBuffer(); ////////////// // CLEAN UP // ////////////// SelectObject(hMemDC, hbmpOld); DeleteDC(hMemDC); DeleteObject(hbmpOld); Sleep(20); } } } I should recommend to create a graphic class managing back-buffer HDC and all other stuff
  3. Hello Kwee, 1-I strongly recommend you to have a look at the MSDN the knowledge database. One book I would recommend is the Windows Programming by Charles Petzold ( not the one related to .NET , the one dealing with win32) Quote: First problem was that WndProc must be static (i.e. cannot be a method of instance of class). So I searched here and found this 2-you must declare the WndProc procedure as a static function because this function is called every x milliseconds by a system scheduler, the Program Manager. So if you don't declare it as static, the function pointer holding the adress of the procedure won't be valid. If it's static it is ok. Quote: The common pattern in all of them, that the message handling connected to a window. Why is this? this is a win32 issue ; I recommend you to find a book explaining win32 programming. If your 32 bit win32 program creates a window, the you must "attach" to it a pool of messages. If you create a window with CreateWindow, your window procedure must process all messages sent by the system and the Program Manager. For example, if the user with his mouse moves the window, the system through PM sends notifications to the program, WM_SIZE,WM_MOVE Quote: Wouldn't it be more elegant to create some class like EventDispatcher that simply will iterate over the events (peekmessage() ) and send the event to listeners who subscribed to receive the event? you can do this but it is only by your own conception; win32 has been designed to be as "low-level" as possible.
  4. Hello Tingle 1-you can use D3DXMesh it's easier to load meshes and render them on the screen A more sophisticated way would be to use shaders and HLSL language but if you are learning Direct X it would be better to know the bases of Direct X 2-yes you can create and design your own mesh class.. Quote: Are complete worlds put inside one buffer sequence? Yes/No ; you have to decide of a good technique to load or not large meshes into memory. For example one common trick is to render high level-of-details in front of the scene and render low polygon models in the background.. You can use a view frustum culling technique to optimize the rendering process If you are learning how to program a video game, the most important thing to know is to have an accurate idea of the game you want to make : "I want to make a tetris, I want to make a bomberman..." even if it's in 3D realtime
  5. HolyGrail

    2D games, where to share?

    I totally agree with Matty_Alan, you should share your game by promoting it on free games websites Quote:Original post by MyH34DHurtz You can share it here! Got to Forums, down to "image of the day", and there you can link it, and allow people to try the game, and tell you what they think. Whats better feed back than the feedback of other Game developers? promoting your game *only* on game-dev websites is a very bad thing. Except if you require special technical help or technical issues... To improve your game it is very important to get the feeling/feed-back of the end-user and player ,not only from a game developers audience. If any player plays with your game and give you a good feed-back so you can make some enhancements to your game creation and why not to sell it ;-) Quote:Original post by neal8929 But what about the rest of the people who make games in C++ that are not meant to be played from a web browser? Where is a good website or community where a person could upload a freeware game to see what people think of it? send me a PM I know some websites...this is where Im' going to release my game..
  6. Quote: Other techniques can involve grouping. i.e. if a group of units are given a move command it may work for your game to just generate a single path for that group and have everyone flock around the leader. but this is very game specific and may not work for you. I'd stick to the above first. Hierarchical A* is also something you want to look at for an RTS. pathing across a whole map with traditional A* is obviously going to be hugely expensive. -me Wow I didn't think about grouping units and make a single path it's a good idea ! Thank you for the tip !
  7. Ok thanks to all. Thank you for the quad tree technique and thank you for the link to Gamedev it is very useful ( diablos_blade and alnite ) Yes I would better use a profiler :)
  8. Hello everybody thank you replies :) Quote:Look around the web for optimisation techniques and try to apply them. yes I was thinking of setting the pathfinding loop into a thread Quote:Original post by diablos_blade The obvious choice is some form of spatial partitioning. Quad trees and tiles work well for RTS style games. If you are already using a tile system for your path finding you could adapt it to provide functionallity to efficiently query all the entities in an area. . ok this a good suggestion. But how can I build quad trees for partitioning ? Like a BSP tree in a FPS Game ( for example DOOM ) ? You say by using a quad tree, what do I put on the root then on the leaves ? Quote:Original post by Rubicon You should look at time-slicing if you've not already. Many things can be shaved off to better spread their cpu load. In a batch of say 10 frames, update tanks 0,9,19,29 on frame 1, 1,10,20,30 on frame 2 etc. Nobody will notice and your A* already runs 10 times quicker by being called 10 times less often per frame. It's a little bit complicated to me but I'm going to think about it. Thank you again.
  9. Hi everybody, I'm finishing my game after a long hard work. It's an RTS game. Basically I have 2 kinds of unit ,player units and ennemies units. In the main loop during every time tick the player and ennemies units ( let's say every 100 milliseconds ) are updated : movement and fighting . I use A* algorithm for entity pathfinding. Concerning the attack of each unit , for example , if the player presses the mouse right button down, it gives the order to shoot at the enemy. I use STL containers to manage units. Basicially what I'm doing is a loop like this if the player gives the order to attack: Quote: std::list<PlayerUnit> listPlayers; std::list<EnemyUnit> listEnemies; ... std::list<PlayerUnit>::iterator iter; std::list<EnemyUnit>::iterator iter2; int PlayerPositionX; int PlayerPositionY; int EnemyPositionX; int EnemyPositionY; iter=listPlayers.begin(); while( iter !=listPlayers()) { PlayerPositionX=(*iter).GetPositionX; PlayerPositionY=(*iter).GetPositionY; iter2= listEnemies.begin(); while( iter !=listPlayers()) { EnemyPositionX=(*iter2).GetPositionX; EnemyPositionY=(*iter2).GetPositionY; // check if ennemy is in sight of player unit - 200 is random value if ( FindDistance( PlayerPositionX,PlayerPositionY,EnemyPositionX,EnemyPositionY) <200 ) { (*iter).Attack((*iter2); } iter2++; } iter++; } This code is also used to make enemies units attack player units. My question is : instead of using a dumb and basic loop as mentioned aboved is there any way to improve the cross attack algorithm ? If you select a few amount of player units it's ok but hundred of units and the frame rates drops. Any "smart" algorithm to give ? Binary trees ? Thank you for the replies
  10. Quote:The most straightforward way to do what you're asking is as follows (and actually doesn't involve any trig):vector2 direction = target - current_position; direction.normalize(); // Then, for each update: current_position += direction * speed * time_step; ok but with your solution we don't know when to start and when to finish to update the position
  11. Hello Shuwo, once you've got the k ( slope ) and the m of your equation , simply make a loop where you can store the coordinates of your sprite for example in a container like std::vector or std::list You can also use a polar-cartesian conversion if you want to use angles and range for the bullet: Once you have a stack of sprite coordinates you can move your sprite with a Sprite::Update() method during every timer event
  12. Hi, there is a simple way to do that : given the origin point and the target point , you can calculate the line equation between origin and target. Otherwise yes if you want to consider a shooting angle and a particular range you can use trigonometric transformations. Check in Wikipedia for formulas.
  13. HolyGrail

    DX9 Deprecated for learning or....

    Quote:Original post by ollyb342 I'm asking if it there would be any drawbacks to learning DX9 now that DX10 is out. I'm only leaning towards DX9 as there's alot more learning materials about. Ollie. Definitely no ! This is why doing ; I'm a mere beginner in Direct3d and still learning Direct3d with D3d9. There are differences between D3d9 and D3d9 but I think that it's a good base to learn Direct3d with D3d9. And don't forget that a lot of Windows users still have systems running under Windows XP.
  14. A .mov file is an Apple Quicktime file. You need to 1-read and decompress the file to a raw format frame by frame 2-play each frame.
  15. HolyGrail

    directx 10 e mfc

    Quote:Original post by giugio Hy. Is possible to insert in a picturebox handle or a dialog handle a dx 10 output? How? If you have the HWND /CWnd of the window /dialog window yes it's possible. Check in the samples of the Direct X SDK some use MFC classes.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!