#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0

    Question How to simulate car in map via MFC?


    Dear Expert,

    I am doing a "route path simulation system". Basically I using dijksstra algorithm to search shortest path with interface via c++ MFC design.

    now my question........on the map.......if wan to simulate car movement (just simply move).....any idea?

    since MFC is no main function right? so, where should i go to modify the code (for adding one Car Class)?

    hope to hear expert soon....thanks in advanced..

    regards,
    onnv6
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    Keep the map and the car images in seperate CDC's.
    Have two CDC's (and bitmaps) created compatible with the display area. One is the BackBuffer the other the screenbuffer.
    The backbuffer is used to assemble a new image (make the car move).
    The screenbuffer will be drawn whole to the screen on a paint message, it holds a copy of the last image in case something else requires the screen to be up-dated

    When you need to redraw the position BitBlt() the map to the backBuffer. Then BitBlt the car image to the right coods.

    Then BitBlt the whole BackBuffer to the ScreenBuffer.

    Call InvalidateRect() to post a paint message.
    Call UpdateWindow() to get the app to process this paint msg.

    In your OnPaint() BitBlt the Screenbuffer to the CDC in the PAINTSTRUCT after BeginPaint() has filled it.
    Call EndPaint()

    This will get you a fast flicker free update that will work on even slow PC's.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0
    Dear Sir,

    First of all, i would like to thanks and appreciate Sir reply me. Sorry to let sir know, i am the novice user on MFC (visual c++). i understand sir comment on the "buffer" stuff. but the following statment is very abstract for me....

    Sir, what i meant is since....MFC dosen't provide any main function and the enter the game loop....right? how am i going to add the class? how to call? i able to simulate car inside map which is done by win32 .exe but, that is not compatible? is that a way for me to solve it?

    If sir don't mind..... i would send you my application to let sir have a looks? is that ok with sir? i will immediately send to sir on the next mail, coz i not at home right now.

    Hope to hear sir soon....and thanks for sir precious info and feedback......really appriaciate it..

    regards,
    onn
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    I haven't spent a lot of time with MFC, but all windows applications use the WinMain function in exactly the same way that console applications use the main function.

    You don't want to implement vehicle movement in the WinMain function though. You'll clearly want some event to trigger your animation algorithm. There should be an event handler function for that event. This is where you'll implement your animation. Presumably, you want to do it right after you have determined the shortest path.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0
    Dear Experts,

    Thanks for Sirs opinion and precious info...Really appreciate it! By the way, I hope my attacment regarding the interface via MFC and the "Car Class" function in console application which win32.exe code. will able to give sir clear picture on how my program going to be...........

    Yes, i did the shortest path coding via dijkstra algorithm. and i know the way to link with MFC. But, now i just want to test whether possible to "SIMULATE CAR" in the map via MFC code?. Which means once shortest path generate, the car will move from the source to destination with shortest link.

    Hope to get back Sirs soon and thanks for everything being helpfull to me.

    regards,
    onn
    Attached Files
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0
    this attacment will be my simple car simulation using win32.exe console based. So, isn't possible to use the car class and add into the MFC? if not how? if can how? hope sir will guilde me..
    thanks a lots!
    Attached Files
  12. #7
  13. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    I prefer 'mate' to 'sir'. Sorry I do not have time to fix your app...

    >>I haven't spent a lot of time with MFC, but all windows applications use the WinMain function in exactly the same way that console applications use the main function. <<

    MFC hides the message loop (pump) from you. There is no winmain() (or main()) in a MFC app.

    In a game you normally use PeekMessage() rather than GetMessage(). If there is no msg available the app does 'other' stuff (ie move the car).This is done with extra threads in MFC and over-riding the main message pump, not beginer stuff.

    This makes MFC not suitable for games IMHO. The bloated .exe produced is also a problem.

    One way round is to use a timer. Update the backbuffer (move the car) on each timer msg (WM_TIMER). Unfortuneately timer msg's have the lowest priority of all msg's and so will not be accurate <10ms. In the class view add a handler for WM_TIMER msg's or add a OnTimer().Have a look at SetTimer() on MSDN. Remember it is in milli seconds.

    Have a look at this site for C++ WIN32 programming without MFC.

    http://www.foosyerdoos.fsnet.co.uk/
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0
    Dear Sirs,

    Does anyone have a free souces which is writen in visual c++ 6.0 via MFC about simulation car? I head really exhaused to implement it...is just left the last step.

    i found very difficulties to link it. could sirs look through the zip ziles i sent sirs?

    plz....thanks sir
  16. #9
  17. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    Have you looked at over-riding the OnIdle() handler in your WinApp class?

    Also look at the Run class as this handles the message loop (pump)
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    18
    Rep Power
    0
    sorry sir, i am implementing it on MFC. i don't think MFC provided some sort of message (loop) right? if in the win32.exe, yes it got.

    so, isn't i suppose to add the game event loop on the MFC files? if yes, what code should i add? same with win32.exe code? can sir provide example?

IMN logo majestic logo threadwatch logo seochat tools logo