std::string GLFragmentDecompilerThread::Format(const std::string& code)
{
	const std::pair<std::string, std::function<std::string()>> repl_list[] =
	{
		{ "$$", []() -> std::string { return "$"; } },
		{ "$0", [this]{ return GetSRC<SRC0>(src0); } },
		{ "$1", [this]{ return GetSRC<SRC1>(src1); } },
		{ "$2", [this]{ return GetSRC<SRC2>(src2); } },
		{ "$t", [this]{ return AddTex(); } },
		{ "$m", [this]{ return GetMask(); } },

		{ "$ifcond ", [this]() -> std::string
		{
			const std::string& cond = GetCond();
			if (cond == "true") return "";
			return "if(" + cond + ") ";
		}
		},

		{ "$cond", [this]{ return GetCond(); } },
		{ "$c", [this]{ return AddConst(); } }
	};

	return fmt::replace_all(code, repl_list);
}
Exemple #2
0
void LField::Sync() {
	if (((GetCond() > 3) && (GetCond() < 7)) ||
		((GetCond() > 11) && (GetCond() < 15)))	{
		GetPlant()->kurangiUmur(1);
		if (IsSiram()) {
			GetPlant()->tambahHappyMeter(1);
		}
	}
	Siram = 0;	
}
std::string VertexProgramDecompiler::Format(const std::string& code)
{
	const std::pair<std::string, std::function<std::string()>> repl_list[] =
	{
		{ "$$", []() -> std::string { return "$"; } },
		{ "$0", std::bind(std::mem_fn(&VertexProgramDecompiler::GetSRC), this, 0) },
		{ "$1", std::bind(std::mem_fn(&VertexProgramDecompiler::GetSRC), this, 1) },
		{ "$2", std::bind(std::mem_fn(&VertexProgramDecompiler::GetSRC), this, 2) },
		{ "$s", std::bind(std::mem_fn(&VertexProgramDecompiler::GetSRC), this, 2) },
		{ "$awm", std::bind(std::mem_fn(&VertexProgramDecompiler::AddAddrRegWithoutMask), this) },
		{ "$am", std::bind(std::mem_fn(&VertexProgramDecompiler::AddAddrMask), this) },
		{ "$a", std::bind(std::mem_fn(&VertexProgramDecompiler::AddAddrReg), this) },

		{ "$t", std::bind(std::mem_fn(&VertexProgramDecompiler::GetTex), this) },

		{ "$fa", [this]()->std::string { return std::to_string(GetAddr()); } },
		{ "$f()", std::bind(std::mem_fn(&VertexProgramDecompiler::GetFunc), this) },
		{ "$ifcond ", [this]() -> std::string
	{
		const std::string& cond = GetCond();
		if (cond == "true") return "";
		return "if(" + cond + ") ";
	}
		},
		{ "$cond", std::bind(std::mem_fn(&VertexProgramDecompiler::GetCond), this) }
	};

	return fmt::replace_all(code, repl_list);
}
void
Ns_CondWait(Ns_Cond *cond, Ns_Mutex *mutex)
{
    int              err;

    err = pthread_cond_wait(GetCond(cond), NsGetLock(mutex));
    if (err != 0) {
	NsThreadFatal("Ns_CondWait", "pthread_cond_wait", err);
    }
}
void
Ns_CondBroadcast(Ns_Cond *cond)
{
    int             err;

    err = pthread_cond_broadcast(GetCond(cond));
    if (err != 0) {
        NsThreadFatal("Ns_CondBroadcast", "pthread_cond_broadcast", err);
    }
}
void
Ns_CondSignal(Ns_Cond *cond)
{
    int             err;

    err = pthread_cond_signal(GetCond(cond));
    if (err != 0) {
        NsThreadFatal("Ns_CondSignal", "pthread_cond_signal", err);
    }
}
int
Ns_CondTimedWait(Ns_Cond *cond, Ns_Mutex *mutex, Ns_Time *timePtr)
{
    int              err, status = NS_ERROR;
    struct timespec  ts;

    if (timePtr == NULL) {
	Ns_CondWait(cond, mutex);
	return NS_OK;
    }

    /*
     * Convert the microsecond-based Ns_Time to a nanosecond-based
     * struct timespec.
     */

    ts.tv_sec = timePtr->sec;
    ts.tv_nsec = timePtr->usec * 1000;

    /*
     * As documented on Linux, pthread_cond_timedwait may return
     * EINTR if a signal arrives.  We have noticed that 
     * EINTR can be returned on Solaris as well although this
     * is not documented.  We assume the wakeup is truely
     * spurious and simply restart the wait knowing that the
     * ts structure has not been modified.
     */

    do {
    	err = pthread_cond_timedwait(GetCond(cond), NsGetLock(mutex), &ts);
    } while (err == EINTR);
    if (err == ETIMEDOUT) {
	status = NS_TIMEOUT;
    } else if (err != 0) {
	NsThreadFatal("Ns_CondTimedWait", "pthread_cond_timedwait", err);
    } else {
	status = NS_OK;
    }
    return status;
}
Exemple #8
0
std::string GLFragmentDecompilerThread::Format(const std::string& code)
{
	const std::pair<std::string, std::function<std::string()>> repl_list[] =
	{
		{ "$$", []() -> std::string { return "$"; } },
		{ "$0", std::bind(std::mem_fn(&GLFragmentDecompilerThread::GetSRC<SRC0>), this, src0) },
		{ "$1", std::bind(std::mem_fn(&GLFragmentDecompilerThread::GetSRC<SRC1>), this, src1) },
		{ "$2", std::bind(std::mem_fn(&GLFragmentDecompilerThread::GetSRC<SRC2>), this, src2) },
		{ "$t", std::bind(std::mem_fn(&GLFragmentDecompilerThread::AddTex), this) },
		{ "$m", std::bind(std::mem_fn(&GLFragmentDecompilerThread::GetMask), this) },
		{ "$ifcond ", [this]() -> std::string
			{
				const std::string& cond = GetCond();
				if (cond == "true") return "";
				return "if(" + cond + ") ";
			}
		},
		{ "$cond", std::bind(std::mem_fn(&GLFragmentDecompilerThread::GetCond), this) },
		{ "$c", std::bind(std::mem_fn(&GLFragmentDecompilerThread::AddConst), this) }
	};

	return fmt::replace_all(code, repl_list);
}
Exemple #9
0
void LField::Kerja(char c) {
	//DAFTAR KONDISI :
		//-1 = Tidak Valid
		//0 = Non-MoveAble
		//1 = Non-PlantAble					
		//2 = Plantable belum dicangkul		--> #10 sudah disiram
		//3 = Plantable sudah dicangkul		--> #11 sudah disiram
		//4 = sudah berupa bibit			--> #12 sudah disiram
		//5 = sudah dewasa					--> #13 sudah disiram
		//6 = sudah panen					--> #14 sudah disiram
		//7 = sudah mati					--> #15 sudah disiram
	if (c == 'c') {				//cangkul
		if 		(GetCond() == 2) 					{Cangkul = 1;}
		else if (GetCond() == 4 || GetCond() == 12) {Cangkul = 1;PlantExist = 0;PlantAlive = 0;}
	}
	else if (c == 'w') {		//water
		if		((GetCond() > 1) && (GetCond() < 8)){Siram = 1;};
	}
	else if (c == 's') {		//slash
		if		(
				((GetCond() > 3) && (GetCond() < 8)) 
				|| 
				((GetCond() > 11) && (GetCond() < 16))
				)
				{PlantExist = 0;PlantAlive = 0;};
	}
	else if (c == 'h') {
		if		((GetCond() == 6) || (GetCond() == 14)) {
				if (PPlant->getTipePanen()) {
					PPlant->setHappyMeter(0);
				}
				else {
					PlantAlive = 0;
				}
		}
	}
	//MENANAM SESUAI ID
	//1 = Ganja, 2 = Opium, 3 = Coca, 4 = Tobacco, 5 = Anggur, 6 = Mushroom
	else if ((c > 47) && (c < 54)) {
		if (GetCond() == 3) {
			PlantExist = 1;
			PlantAlive = 1;
			if (c == '1') {			//GANJA
				PPlant = new Ganja;
			}
			else if (c == '2') {	//OPIUM
				PPlant = new Opium;
			}
			else if (c == '3') {	//COCA
				PPlant = new Coca;
			}
			else if (c == '4') {	//TOBACCO
				PPlant = new Tobacco;
			}
			else if (c == '5') {	//ANGGUR
				PPlant = new Anggur;
			}
			else if (c == '6') {	//MUSHROOM
				PPlant = new Mushroom;
			}
		}
	}
}