[Release] Wait Class

Posts 1–7 of 7 · Page 1 of 1
[Release] Wait Class
I originally coded this in Java, but i recoded it in C++ to use on gellin's base to recreate the font without causing lag.

So basically what this code does is it cause's the execution of certain code to be delayed, like the Sleep() function, but it doesn't cause the whole thread to pause, therefore there is no lag. It just takes the current system times, waits the ammount specified, and then lets execution of the method continue.

This code IS c/p friendly.


If your using this more generally (like not in gellin's base) then use this example.
EXAMPLE 1
Wait.h
Code:
#include <time.h>

class cWait{
	public:

	void wait(int waittime);
	void startWait();
	bool isWait();
};

extern class cWait Wait;
Wait.cpp
Code:
#include "Wait.h"

long waitin;
long t0, t1;

void cWait::wait(int waittime){
	waitin = waittime;
}

void cWait::startWait(){
	t0 = time(NULL) * 1000;
}

bool cWait::isWait(){
	t1 = time(NULL) * 1000;
	return (t1 - t0) < waitin;
}

If your using this class with gellin's base, then use this example.
EXAMPLE 2
Wait.h
Code:
#include <time.h>

class cWait{
	public:

	void startWait();
	bool isWait();
};

extern class cWait Wait;
Wait.cpp
Code:
#include "Wait.h"

long waitin = 20000;
long t0, t1;

void cWait::startWait(){
	t0 = time(NULL) * 1000;
}

bool cWait::isWait(){
	t1 = time(NULL) * 1000;
	return (t1 - t0) < waitin;
}

Then to add this to your RenderFrame.
Use (In Gellin's base)
Code:
if(!Wait.isWait()){
	this->UpdateFont(pDevice);
	Wait.startWait();
}

If you don't understand this code, or think it's worthless, let me know. Just trying to help lol.
So this will activate the code even if I have sleep functions in the same thread?
Why would you need a sleep class??
Do you know what the point of a class is? So that you can have multiple instances of the same thing. You should make waitin, t0, and t1 members of the class.
Quote Originally Posted by mmbob View Post
Do you know what the point of a class is? So that you can have multiple instances of the same thing. You should make waitin, t0, and t1 members of the class.
Oh thanks i was to sleepy at my time of post
Quote Originally Posted by mmbob View Post
Do you know what the point of a class is? So that you can have multiple instances of the same thing. You should make waitin, t0, and t1 members of the class.
yea i was thinkin the same thing.

if u have t0 and t1 outside like that. no matter how much u classes u make it will always be the same.

same thing for waittime
Quote Originally Posted by Finish View Post
yea i was thinkin the same thing.

if u have t0 and t1 outside like that. no matter how much u classes u make it will always be the same.

same thing for waittime
Ya I realized that after I posted it. To lazy to update. It works fine if your using only one instance of it like in gellin's base. If you want to recode it go for it, that is the point of sharing. Java's classes are a bit different than C++'s so I wasn't exactly sure how to do it.
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us