开发者

Loading screen animation using threads

开发者 https://www.devze.com 2023-02-28 10:01 出处:网络
I have made a game, it is written in C++ and directX. When the user chooses which mission to play the screen goes blank for some time while it load in all the resources. So the user knows the game h

I have made a game, it is written in C++ and directX.

When the user chooses which mission to play the screen goes blank for some time while it load in all the resources. So the user knows the game has not crashed I want to make a loading screen with an animation.

My question is this:

  1. If one thread (the main one) crashes do all threads of that process crash?

  2. Can you destroy a thread from the thread that created it or does the thread have to terminate itself?

  3. I am new to multithreading and have not used it before. Many people say it ma开发者_运维技巧kes programs unnecessarily complex so is it worth making my program multithreaded just for a loading screen or is there another way of doing it?


If one thread (the main one) crashes do all threads of that process crash?

If the main thread crashes (i.e. the UI thread) obviously the application crashes. If any worker thread crashes, you will get an exception which you can choose to ignore.

Can you destroy a thread from the thread that created it or does the thread have to terminate itself?

Normally the thread itself should terminate itself (i.e. finish execution). Obviously you can signal any secondary thread to stop from the main thread.

I am new to multithreading and have not used it before. Many people say it makes programs unnecessarily complex so is it worth making my program multithreaded just for a loading screen or is there another way of doing it?

You'll have to learn multitasking if you're serious about programming so better now than never.


If one thread (the main one) crashes do all threads of that process crash?

If by 'crash' you mean that an unhandled exception is propagated to the operating system - Yes.

Can you destroy a thread from the thread that created it or does the thread have to terminate itself?

There's TerminateThread, but it's use is not recommended. Better notify the thread that it should terminate and leave the actual cleanup to the thread.

I am new to multithreading and have not used it before. Many people say it makes programs unnecessarily complex so is it worth making my program multithreaded just for a loading screen or is there another way of doing it?

A loading screen is actually a good example of multithreading. I wouldn't, however, create an extra thread to render your loading screen but rather use multiple threads to stream in your resources. Rendering should be done by one thread (that's generally recommended for all DirectX versions).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号