Home > other >  On the c # program regularly
On the c # program regularly

Time:09-22

Learning U3D, then don't want to use the yield return new waitforsconds, about his time to write a program, as follows:
Void Pause (int delayTime) {
System. A DateTime time=new System. A DateTime ();
Time=System. A DateTime. Now;
Int s;
Do {
S=System. A DateTime. Now. Second - time. Second;
} while (s & lt; DelayTime);
}
But runtime and found a very serious problem, I put it in other ways, and put them inside the Update (), the result is of memory, basic is jammed, want to ask next reason,

CodePudding user response:

Is death cycle obviously

CodePudding user response:

It's a cycle, the update is not true of card is dead, but a phenomenon of suspended animation, only the inside of the update, such as the do - the end of the while loop will perform the following content, can consider to use threads or coroutines,

CodePudding user response:

reference 1st floor avi9111 response:
is death cycle obviously

Seems to be the end of the loop condition, and should not be not achieve the conditions,

CodePudding user response:

refer to the second floor yy763496668 response:
it's a cycle, the update is not really the card is dead, but a phenomenon of suspended animation, only the inside of the update, such as the do - at the end of the while loop will perform the following content, can consider to use threads or coroutines,

Just don't want to use association Cheng Cai wrote,
In fact, I want to know is how to write a more smooth timing method

CodePudding user response:

Update was once a frame to perform, but the while loop will make you into computer in a second after must wait for a while loop execution after coming out, and the above code and a more deadly place is before you into a while loop, the frame of time=System. A DateTime. Now; The assignment operation, but within the loop s=System. A DateTime. Now. The Second - time. Second; System. A DateTime. Now. The Second is the amount of change over time, time. The Second is the quantity of a change over time (already tested), you may take time. The Second as a constant, and the step length is the same, so the s & lt; DelayTime is used to set up, so to enter an infinite loop,
The following code, I believe you will write, is conveniently stick down,
 
Float timer=0;
//Update is called once per frame
Void the Update () {
The timer +=Time. DeltaTime;
If (timer & gt; 100)
{
The Debug Log (" time ");
}
}

CodePudding user response:

Update the while loop did not finish, the next frame when it comes, must wait for you while loop finished, you actually forced to reduce the frame rate of the loop in the Update, as low as you can see lag phenomenon is false

CodePudding user response:

The benefits of ctrip I even understand now
In fact I wrote LUA
GOLANG ctrip
But I just don't know why so many source like to use ctrip,
in the UPDATE eventsTeacher training institutions is the case, a commercial source of listed companies is also
I use is negligible, or c # also have better practice
I also said it in my blog, I used in c # 2012, at that time also don't know what the hell, ctrip is c # has been with JAVA is multithreaded not good
Results scripts out there is ctrip, LUA, GOLANG too, I also have doubt JS ctrip, wait for verification
Ctrip is the concept of mobile phone UI for WINDOWS is a different place, can also grasp beyond process, events these old concept, this certainly not taught in school
Your white hair that day timer, the teacher will only make you do make a alarm clock program as the final design

There are several reasons why so many people use affirmations
The main reason
Is if you use these newcomers, code in ctrip in very slag it doesn't matter (code), and released to the main thread, because can yield even ctrip is slow, it doesn't matter even collapsed
The main thread dominant, accounting for major resources (and is LateUpdate, FixedUpdate)
To do a 3 d game, save more resources for rendering, operation and communication,,,, very reasonable
When you understand the ctrip naturally will also use the
Also won't have these problems you
(I also said that in my blog, you let a senior programmer write a TIMER, he may be true enough you fast, even the TIMER forget how to write, he only as good as you but he chose the road potholes, less than you choose me in answer to zhihu, seems to be)

CodePudding user response:

Even if with ctrip, you will still have these problems, because it is a code logic problem,,,,,,,,,,,,,,, a senior programmers will have a lot of code logic problem, just less code, he will choose pit, analysis of less as far as possible each sentence is what problem, and then reduce the debugging, or a few days, in addition to the pass, optimized the code is very few, the reconstruction of the write c + + and the opportunity to learn more each other, but now the CPP programmer is slag,,,,,,, don't insist on a decade of CPP programmers are nothing, but you have to is a stick to a decade of CPP, your mind has a problem

CodePudding user response:

See false phenomenon is jammed, it's a cycle, the update is not really card is dead, but a phenomenon of suspended animation, only the inside of the update, such as the do - at the end of the while loop will perform the following content,
  • Related