954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to multitask?

This may come off as a rather broad question, but I need to learn how to multitask in c++.
I am developing a game, and to do so I need to learn how to program applications to run in realtime.
(I want multiple characters to do things at the same time, rather than having a turn based game as I currently have.)
For those of you who may 'know' me, I have progressed quite a large amount in the last few weeks so I will have a reasonably larger grasp on what you have to say... By this I mean I won't sit there like "what, huh... I wish you guys could explain things good" (I said that about ancient dragon once over such a simple subject as RECTs)
Well thanks for any help, and P.S. - I use Bloodshed (gcc compiler) NOT visual c++, therefore I would appreciate any code to be compatible with bloodshed.

Brent.tc
Junior Poster in Training
90 posts since Oct 2006
Reputation Points: 10
Solved Threads: 1
 

I've been sent here by the gods of compilers with this message.

http://msdn.microsoft.com/vstudio/express/downloads/

You will now "fit in" with the rest.

But in all honesty, I really can't say enough about the 2005 express editions of visual studio. They truly are amazing. And not only that, but it's as close to the real world as you'll ever get with home development.

Now onto your question:

Game programming consists of 3 core functions (how people actually write the game differs, but in reality, these 3 steps are taken in every game).

1. Initialization.
2. Update.
3. Shutdown.

Pretty self explanatory. What you're looking for is going to be in step #2, the Update methods of the game. In here you'll have the game update objects on the screen/collision/physics/death/movement etc...

For more specific examples, you'd of course need some more specific questions, but this is what i figured you'd be looking for with that broad of a question, so hope it helps.

mariocatch
Junior Poster
103 posts since Apr 2007
Reputation Points: 11
Solved Threads: 17
 

>> need to learn how to multitask in c++.

Its called multi-threading. Here are more information.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

he's not talking about threading im sure. as he wants to know how to update objects on the screen at the same time, which would be updating a game, not threading, so refer to my previous post Brent.tc

mariocatch
Junior Poster
103 posts since Apr 2007
Reputation Points: 11
Solved Threads: 17
 

> he's not talking about threading im sure.
For a small scale project, yes, but for real games, multi threading is what he is looking for. Games almost always make use of multi threading.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

he wants to know how to update objects on a screen... lets not complicate him with things such as multi threading.

mariocatch
Junior Poster
103 posts since Apr 2007
Reputation Points: 11
Solved Threads: 17
 

I've only made graphical games on GBA, but the principals are probably the same.
In your main gane loop, you'll have one (or more) function(s) that update a character's or whatever's position, and then once all of those functions have been run through, you update the screen.

fatnickc
Newbie Poster
15 posts since May 2007
Reputation Points: 17
Solved Threads: 3
 
he wants to know how to update objects on a screen... lets not complicate him with things such as multi threading.

I agree with this poster.
Suggesting multi-threading to a beginner programmer is like giving a gun to a 3 year old. And since we're talking C++ here you can be damn sure he'd reuse the bullets!

What needs to be conveyed to the original poster is what design patterns can be used to achieve the desired effect.

iMalc
Newbie Poster
6 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 
I agree with this poster. Suggesting multi-threading to a beginner programmer is like giving a gun to a 3 year old. And since we're talking C++ here you can be damn sure he'd reuse the bullets! What needs to be conveyed to the original poster is what design patterns can be used to achieve the desired effect.

Don't shoot the messenger! Brent asked about multi-threading, so I pointed him in that direction. I won't pretend to know his skills or read his mind.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I agree with Ancient Dragon as well as the rest. Yes, I am quite the beginner, but I am eager to learn, so thanks all. Oh and mariocatch, if you honestly think I have not looked into vc++ and the other microsoft products you are wrong... I actually have a copy of the Visual C++ ISO, but i have been using Bloodshed since I started, and with bloodshed I am capable of compiling (Even if compilation with VC++ is possible, I will continue to use Bloodshed)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
So, multitasking is a more simple concept of multithreading? or are they completely different?
I will look into the links in your posts (perhaps something I should have done already) and get back to you.

Ohh, by the way, next year I will be in highschool which will allow me to take classes in this order where G = grade and S = semester and C = classname (G-S C)
10-1 Visual basic
10 - 2 C++
11 - 1 Java
11 - 2 Web Development (php and whatnot)
12 - 1 Advanced (I assume C# and perhaps ASM)
12 - 1 (Same as 12 - 2)
*-*-*-*-*-*-*-*-*-*-*-*
I assume that microsofts products will be used in school so I'll "fit in" soon enough.

Brent.tc
Junior Poster in Training
90 posts since Oct 2006
Reputation Points: 10
Solved Threads: 1
 

>So, multitasking is a more simple concept of multithreading?
Think of it this way: you can say multitask in everyday life without people looking strangely at you. In other words, you're doing multiple tasks at the same time. In the computer world, tasks are called "threads", so that's where the word multithreading comes from.

A normal program consists of one thread, which means it does everything one by one. A multithreaded program will split up its tasks and do several at the same time by branching out into threads.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 
(Even if compilation with VC++ is possible, I will continue to use Bloodshed)


don't say i didn't warn you if you get a job in the real world and ask them if you can use bloodshed...

btw, you don't want to learn about multithreading yet. it's not going solve your intial issue of "UPDATING OBJECTS ON THE SCREEN". am i the only seeing his question correctly? you don't need multithreading to do what he asked, in fact you shouldnt even use it to update things on a screen. use your MAIN GAME loop for that.

mariocatch
Junior Poster
103 posts since Apr 2007
Reputation Points: 11
Solved Threads: 17
 

I don't see the word screen anywhere in his post...

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

> So, multitasking is a more simple concept of multithreading?
Mutitasking is what your operating systems are packed with. You have the ability to execute more than one tasks / processes. You can read an ebook using Acrobat reader at the same time download something. You are given the feeling that its all happening at the same time even though its not. The OS allocates time slices or frames to each of these processes and these slices are so small that you get the feeling of multiple tasks being executed simultaneously. It is made possible through 'task switching'.

Multi-threading is tightly bound to the concept of using more than one threads to execute the same task. Thus you can have more than one tasks running and for each task there would be multiple threads. Threads are handled almost in the same way as tasks though there are subtle differences. Thus in lay man's terms:

Multi-tasking - more than one application running
Multi-threading - more than one threads running per application

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

My earlier advice stands.

You can do a hell of a lot with one thread. A lot of highly complex games of all kinds use one thread.
It would be a mistake to think that you need to do multi-threading simple to have a program do more than one thing each frame. Multi-threading introduces you to a huge range of issues revolving around concurrency which simply don't exist with single-threading. Everything becomes 10 times more difficult.
Multithreading isn't EVER something you do just because you think you need to. Multithreading is something you do when you KNOW you absolutely have to!

If you haven't already got several years experience with writing games on the relevant platform, or if you don't know how to design a game so that many different things happen each frame, then threading is just not going to help you.

Simply give examples of what you want to do and then we can help you properly design the solution.

iMalc
Newbie Poster
6 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You