Exemplo n.º 1
0
LinkedShader::LinkedShader(Shader *vs, Shader *fs)
		: program(0), dirtyUniforms(0) {
	program = glCreateProgram();
	glAttachShader(program, vs->shader);
	glAttachShader(program, fs->shader);
	glLinkProgram(program);

	GLint linkStatus;
	glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
	if (linkStatus != GL_TRUE) {
		GLint bufLength = 0;
		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
		if (bufLength) {
			char* buf = new char[bufLength];
			glGetProgramInfoLog(program, bufLength, NULL, buf);
			ERROR_LOG(G3D, "Could not link program:\n %s", buf);
			ERROR_LOG(G3D, "VS:\n%s", vs->source().c_str());
			ERROR_LOG(G3D, "FS:\n%s", fs->source().c_str());
			delete [] buf;	// we're dead!
		}
		return;
	}

	INFO_LOG(G3D, "Linked shader: vs %i fs %i", (int)vs->shader, (int)fs->shader);

	u_tex = glGetUniformLocation(program, "tex");
	u_proj = glGetUniformLocation(program, "u_proj");
	u_proj_through = glGetUniformLocation(program, "u_proj_through");
	u_texenv = glGetUniformLocation(program, "u_texenv");
	u_fogcolor = glGetUniformLocation(program, "u_fogcolor");
	u_fogcoef = glGetUniformLocation(program, "u_fogcoef");
	u_alphacolorref = glGetUniformLocation(program, "u_alphacolorref");
	u_colormask = glGetUniformLocation(program, "u_colormask");

	// Transform
	u_view = glGetUniformLocation(program, "u_view");
	u_world = glGetUniformLocation(program, "u_world");
	u_texmtx = glGetUniformLocation(program, "u_texmtx");
	for (int i = 0; i < 8; i++) {
		char name[64];
		sprintf(name, "u_bone%i", i);
		u_bone[i] = glGetUniformLocation(program, name);
	}

	// Lighting, texturing
	u_ambient = glGetUniformLocation(program, "u_ambient");
	u_matambientalpha = glGetUniformLocation(program, "u_matambientalpha");
	u_matdiffuse = glGetUniformLocation(program, "u_matdiffuse");
	u_matspecular = glGetUniformLocation(program, "u_matspecular");
	u_matemissive = glGetUniformLocation(program, "u_matemissive");
	u_uvscaleoffset = glGetUniformLocation(program, "u_uvscaleoffset");

	for (int i = 0; i < 4; i++) {
		char temp[64];
		sprintf(temp, "u_lightpos%i", i);
		u_lightpos[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightdir%i", i);
		u_lightdir[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightatt%i", i);
		u_lightatt[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightangle%i", i);
		u_lightangle[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightspotCoef%i", i);
		u_lightspotCoef[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightambient%i", i);
		u_lightambient[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightdiffuse%i", i);
		u_lightdiffuse[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightspecular%i", i);
		u_lightspecular[i] = glGetUniformLocation(program, temp);
	}

	a_position = glGetAttribLocation(program, "a_position");
	a_color0 = glGetAttribLocation(program, "a_color0");
	a_color1 = glGetAttribLocation(program, "a_color1");
	a_texcoord = glGetAttribLocation(program, "a_texcoord");
	a_normal = glGetAttribLocation(program, "a_normal");
	a_weight0123 = glGetAttribLocation(program, "a_weight0123");
	a_weight4567 = glGetAttribLocation(program, "a_weight4567");

	glUseProgram(program);

	// Default uniform values
	glUniform1i(u_tex, 0);
	// The rest, use the "dirty" mechanism.
	dirtyUniforms = DIRTY_ALL;
	use();
}
Exemplo n.º 2
0
SysDatalogPtr SysDatalogRepository::select(const SysDatalog& obj)
{
	soci::row row;
	SysDatalogPtr sysdatalog(new SysDatalog);
	dataBase << "SELECT  sys_datalog.datalog_id as SysDatalog_datalog_id, sys_datalog.server_id as SysDatalog_server_id, sys_datalog.dbtable as SysDatalog_dbtable, sys_datalog.dbidx as SysDatalog_dbidx, sys_datalog.action as SysDatalog_action, sys_datalog.tstamp as SysDatalog_tstamp, sys_datalog.user as SysDatalog_user, sys_datalog.data as SysDatalog_data, sys_datalog.status as SysDatalog_status, sys_datalog.error as SysDatalog_error"
	" FROM sys_datalog "
	"WHERE sys_datalog.datalog_id = :SysDatalog_datalog_id AND sys_datalog.server_id = :SysDatalog_server_id", into(row), use(obj);
	if(!dataBase.got_data())
		sysdatalog.reset();
	else
		type_conversion<SysDatalog>::from_base(row, i_ok, *sysdatalog);
	return sysdatalog;
}
Exemplo n.º 3
0
void
f (v4i *x, v4i *y)
{
  v4i const zz = *x < *y;
  use (&zz);
}
Exemplo n.º 4
0
void BackEnd::genCodeImpl(IRUnit& unit, AsmInfo* asmInfo) {
  ctr++;
  auto regs = allocateRegs(unit);
  assert(checkRegisters(unit, regs)); // calls checkCfg internally.
  Timer _t(Timer::codeGen);
  LiveRegs live_regs = computeLiveRegs(unit, regs);
  CodegenState state(unit, regs, live_regs, asmInfo);

  CodeBlock& mainCodeIn   = mcg->code.main();
  CodeBlock& coldCodeIn   = mcg->code.cold();
  CodeBlock* frozenCode   = &mcg->code.frozen();

  CodeBlock mainCode;
  CodeBlock coldCode;
  bool relocate = false;
  if (RuntimeOption::EvalJitRelocationSize &&
      supportsRelocation() &&
      coldCodeIn.canEmit(RuntimeOption::EvalJitRelocationSize * 3)) {
    /*
     * This is mainly to exercise the relocator, and ensure that its
     * not broken by new non-relocatable code. Later, it will be
     * used to do some peephole optimizations, such as reducing branch
     * sizes.
     * Allocate enough space that the relocated cold code doesn't
     * overlap the emitted cold code.
     */

    static unsigned seed = 42;
    auto off = rand_r(&seed) & (cacheLineSize() - 1);
    coldCode.init(coldCodeIn.frontier() +
                   RuntimeOption::EvalJitRelocationSize + off,
                   RuntimeOption::EvalJitRelocationSize - off, "cgRelocCold");

    mainCode.init(coldCode.frontier() +
                  RuntimeOption::EvalJitRelocationSize + off,
                  RuntimeOption::EvalJitRelocationSize - off, "cgRelocMain");

    relocate = true;
  } else {
    /*
     * Use separate code blocks, so that attempts to use the mcg's
     * code blocks directly will fail (eg by overwriting the same
     * memory being written through these locals).
     */
    coldCode.init(coldCodeIn.frontier(), coldCodeIn.available(),
                  coldCodeIn.name().c_str());
    mainCode.init(mainCodeIn.frontier(), mainCodeIn.available(),
                  mainCodeIn.name().c_str());
  }

  if (frozenCode == &coldCodeIn) {
    frozenCode = &coldCode;
  }
  auto frozenStart = frozenCode->frontier();
  auto coldStart DEBUG_ONLY = coldCodeIn.frontier();
  auto mainStart DEBUG_ONLY = mainCodeIn.frontier();
  size_t hhir_count{0};
  {
    mcg->code.lock();
    mcg->cgFixups().setBlocks(&mainCode, &coldCode, frozenCode);

    SCOPE_EXIT {
      mcg->cgFixups().setBlocks(nullptr, nullptr, nullptr);
      mcg->code.unlock();
    };

    if (RuntimeOption::EvalHHIRGenerateAsserts) {
      emitTraceCall(mainCode, unit.bcOff());
    }

    auto const linfo = layoutBlocks(unit);
    auto main_start = mainCode.frontier();
    auto cold_start = coldCode.frontier();
    auto frozen_start = frozenCode->frontier();
    Vasm vasm(&state.meta);
    auto& vunit = vasm.unit();
    // create the initial set of vasm numbered the same as hhir blocks.
    for (uint32_t i = 0, n = unit.numBlocks(); i < n; ++i) {
      state.labels[i] = vunit.makeBlock(AreaIndex::Main);
    }
    vunit.roots.push_back(state.labels[unit.entry()]);
    vasm.main(mainCode);
    vasm.cold(coldCode);
    vasm.frozen(*frozenCode);
    for (auto it = linfo.blocks.begin(); it != linfo.blocks.end(); ++it) {
      auto block = *it;
      auto v = block->hint() == Block::Hint::Unlikely ? vasm.cold() :
               block->hint() == Block::Hint::Unused ? vasm.frozen() :
               vasm.main();
      FTRACE(6, "genBlock {} on {}\n", block->id(),
             area_names[(unsigned)v.area()]);
      auto b = state.labels[block];
      vunit.blocks[b].area = v.area();
      v.use(b);
      hhir_count += genBlock(unit, v, vasm, state, block);
      assert(v.closed());
      assert(vasm.main().empty() || vasm.main().closed());
      assert(vasm.cold().empty() || vasm.cold().closed());
      assert(vasm.frozen().empty() || vasm.frozen().closed());
    }
    printUnit("after code-gen", vasm.unit());
    vasm.finish(vasm_abi);
    if (state.asmInfo) {
      auto block = unit.entry();
      state.asmInfo->asmRanges[block] = {main_start, mainCode.frontier()};
      if (mainCode.base() != coldCode.base() && frozenCode != &coldCode) {
        state.asmInfo->acoldRanges[block] = {cold_start, coldCode.frontier()};
      }
      if (mainCode.base() != frozenCode->base()) {
        state.asmInfo->afrozenRanges[block] = {frozen_start,
                                               frozenCode->frontier()};
      }
    }
  }
  auto bcMap = &mcg->cgFixups().m_bcMap;
  if (!bcMap->empty()) {
    TRACE(1, "BCMAPS before relocation\n");
    for (UNUSED auto& map : *bcMap) {
      TRACE(1, "%s %-6d %p %p %p\n", map.md5.toString().c_str(),
             map.bcStart, map.aStart, map.acoldStart, map.afrozenStart);
    }
  }

  assert(coldCodeIn.frontier() == coldStart);
  assert(mainCodeIn.frontier() == mainStart);

  if (relocate) {
    if (asmInfo) {
      printUnit(kRelocationLevel, unit, " before relocation ", &regs, asmInfo);
    }

    auto& be = mcg->backEnd();
    RelocationInfo rel;
    size_t asm_count{0};
    asm_count += be.relocate(rel, mainCodeIn,
                mainCode.base(), mainCode.frontier(),
                mcg->cgFixups());

    asm_count += be.relocate(rel, coldCodeIn,
                coldCode.base(), coldCode.frontier(),
                mcg->cgFixups());
    TRACE(1, "hhir-inst-count %ld asm %ld\n", hhir_count, asm_count);

    if (frozenCode != &coldCode) {
      rel.recordRange(frozenStart, frozenCode->frontier(),
                      frozenStart, frozenCode->frontier());
    }
    be.adjustForRelocation(rel, mcg->cgFixups());
    be.adjustForRelocation(rel, asmInfo, mcg->cgFixups());

    if (asmInfo) {
      static int64_t mainDeltaTot = 0, coldDeltaTot = 0;
      int64_t mainDelta =
        (mainCodeIn.frontier() - mainStart) -
        (mainCode.frontier() - mainCode.base());
      int64_t coldDelta =
        (coldCodeIn.frontier() - coldStart) -
        (coldCode.frontier() - coldCode.base());

      mainDeltaTot += mainDelta;
      HPHP::Trace::traceRelease("main delta after relocation: %" PRId64
                                " (%" PRId64 ")\n",
                                mainDelta, mainDeltaTot);
      coldDeltaTot += coldDelta;
      HPHP::Trace::traceRelease("cold delta after relocation: %" PRId64
                                " (%" PRId64 ")\n",
                                coldDelta, coldDeltaTot);
    }
#ifndef NDEBUG
    auto& ip = mcg->cgFixups().m_inProgressTailJumps;
    for (size_t i = 0; i < ip.size(); ++i) {
      const auto& ib = ip[i];
      assert(!mainCode.contains(ib.toSmash()));
      assert(!coldCode.contains(ib.toSmash()));
    }
    memset(mainCode.base(), 0xcc, mainCode.frontier() - mainCode.base());
    memset(coldCode.base(), 0xcc, coldCode.frontier() - coldCode.base());
#endif
  } else {
    coldCodeIn.skip(coldCode.frontier() - coldCodeIn.frontier());
    mainCodeIn.skip(mainCode.frontier() - mainCodeIn.frontier());
  }

  if (asmInfo) {
    printUnit(kCodeGenLevel, unit, " after code gen ", &regs, asmInfo);
  }
}
Exemplo n.º 5
0
static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_base)
{
	unsigned char *p;
	unsigned long size, c;
	off_t base_offset;
	unsigned shift;
	void *data;

	obj->idx.offset = consumed_bytes;
	input_crc32 = crc32(0, Z_NULL, 0);

	p = fill(1);
	c = *p;
	use(1);
	obj->type = (c >> 4) & 7;
	size = (c & 15);
	shift = 4;
	while (c & 0x80) {
		p = fill(1);
		c = *p;
		use(1);
		size += (c & 0x7f) << shift;
		shift += 7;
	}
	obj->size = size;

	switch (obj->type) {
	case OBJ_REF_DELTA:
		hashcpy(delta_base->sha1, fill(20));
		use(20);
		break;
	case OBJ_OFS_DELTA:
		memset(delta_base, 0, sizeof(*delta_base));
		p = fill(1);
		c = *p;
		use(1);
		base_offset = c & 127;
		while (c & 128) {
			base_offset += 1;
			if (!base_offset || MSB(base_offset, 7))
				bad_object(obj->idx.offset, "offset value overflow for delta base object");
			p = fill(1);
			c = *p;
			use(1);
			base_offset = (base_offset << 7) + (c & 127);
		}
		delta_base->offset = obj->idx.offset - base_offset;
		if (delta_base->offset <= 0 || delta_base->offset >= obj->idx.offset)
			bad_object(obj->idx.offset, "delta base offset is out of bound");
		break;
	case OBJ_COMMIT:
	case OBJ_TREE:
	case OBJ_BLOB:
	case OBJ_TAG:
		break;
	default:
		bad_object(obj->idx.offset, "unknown object type %d", obj->type);
	}
	obj->hdr_size = consumed_bytes - obj->idx.offset;

	data = unpack_entry_data(obj->idx.offset, obj->size);
	obj->idx.crc32 = input_crc32;
	return data;
}
Exemplo n.º 6
0
MailAccessPtr MailAccessRepository::select(const MailAccess& obj)
{
	soci::row row;
	MailAccessPtr mailaccess(new MailAccess);
	dataBase << "SELECT  mail_access.access_id as MailAccess_access_id, mail_access.sys_userid as MailAccess_sys_userid, mail_access.sys_groupid as MailAccess_sys_groupid, mail_access.sys_perm_user as MailAccess_sys_perm_user, mail_access.sys_perm_group as MailAccess_sys_perm_group, mail_access.sys_perm_other as MailAccess_sys_perm_other, mail_access.server_id as MailAccess_server_id, mail_access.source as MailAccess_source, mail_access.access as MailAccess_access, mail_access.type as MailAccess_type, mail_access.active as MailAccess_active"
	" FROM mail_access "
	"WHERE mail_access.access_id = :MailAccess_access_id AND mail_access.server_id = :MailAccess_server_id", into(row), use(obj);
	if(!dataBase.got_data())
		mailaccess.reset();
	else
		type_conversion<MailAccess>::from_base(row, i_ok, *mailaccess);
	return mailaccess;
}
MailContentFilterPtr MailContentFilterRepository::select(const MailContentFilter& obj)
{
	soci::row row;
	MailContentFilterPtr mailcontentfilter(new MailContentFilter);
	dataBase << "SELECT  mail_content_filter.content_filter_id as MailContentFilter_content_filter_id, mail_content_filter.sys_userid as MailContentFilter_sys_userid, mail_content_filter.sys_groupid as MailContentFilter_sys_groupid, mail_content_filter.sys_perm_user as MailContentFilter_sys_perm_user, mail_content_filter.sys_perm_group as MailContentFilter_sys_perm_group, mail_content_filter.sys_perm_other as MailContentFilter_sys_perm_other, mail_content_filter.server_id as MailContentFilter_server_id, mail_content_filter.type as MailContentFilter_type, mail_content_filter.pattern as MailContentFilter_pattern, mail_content_filter.data as MailContentFilter_data, mail_content_filter.action as MailContentFilter_action, mail_content_filter.active as MailContentFilter_active"
	" FROM mail_content_filter "
	"WHERE mail_content_filter.content_filter_id = :MailContentFilter_content_filter_id", into(row), use(obj);
	if(!dataBase.got_data())
		mailcontentfilter.reset();
	else
		type_conversion<MailContentFilter>::from_base(row, i_ok, *mailcontentfilter);
	return mailcontentfilter;
}
Exemplo n.º 8
0
// V-table should be defined with weak linkage.
Test2b::Test2b() { use(typeid(Test2b)); }
Exemplo n.º 9
0
// V-table should be defined with weak linkage.
Test2c::Test2c() { use(typeid(Test2c)); }
Exemplo n.º 10
0
void plogin::process()
{
	obj2["data"] = amf3object();
	amf3object & data2 = obj2["data"];

	//errors:
	//-5 = captcha
	//-99 = general error
	//-100 = holiday
	string username = data["user"];
	string password = data["pwd"];

	if (gserver->maxplayers <= gserver->currentplayersonline + 1)
	{
		gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -99, "Servers are currently overloaded. Please try again later."));
		return;
	}

	string newuser;
	string newpass;
	newuser = makesafe(username);
	newpass = makesafe(password);


	{
		Session ses(gserver->accountpool->get());
		Statement select(ses);
		select << "SELECT COUNT(*) AS a FROM `account` WHERE `email`=?;", use(newuser);
		select.execute();
		RecordSet rs(select);

		if (rs.value("a").convert<int32_t>() == 0)
		{
			//account does not exist - insert new row
			try
			{
				Statement insert(ses);
				insert << "INSERT INTO `account` (`name`, `email`, `ip`, `lastlogin`, `creation`, `password`, `status`, `reason`) VALUES ('null', ?, '', ?, ?, ?, 0, '');", use(newuser), use(unixtime()), use(unixtime()), use(newpass), now;
			}
			catch (Poco::Data::MySQL::StatementException * e)
			{
				gserver->consoleLogger->error(Poco::format("Account Create Exception: %s", e->displayText()));
				return;
			}
		}
	}

	{
		Session ses(gserver->accountpool->get());
		Statement select(ses);
		select << "SELECT * FROM `account` WHERE `email`=? AND `password`=?;", use(newuser), use(newpass);
		select.execute();
		RecordSet rs(select);

		if (rs.rowCount() == 0)
		{
			//account doesn't exist or password is wrong
			gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -2, "Incorrect account or password."));
			return;
		}
		else
		{
			int32_t masteraccountid = rs.value("id").convert<int32_t>();
			client = gserver->GetClientByParent(masteraccountid);

			bool banned = false;

			{
				//are they banned? if so, globally or for this server?
				Session ses2(gserver->serverpool->get());
				Statement select2(ses2);
				select2 << "SELECT * FROM `accounts` WHERE `parentid`=?;", use(masteraccountid);
				select2.execute();
				RecordSet rs2(select2);

				if (rs.value("status").convert<int32_t>() == -99)
					banned = true;

				if (rs2.rowCount() > 0 && rs2.value("status").convert<int32_t>() == -99)
					banned = true;

				if (banned)
				{
					string errormsg = "You are banned. Reason: ";
					errormsg += rs.value("reason").convert<string>().length() > 0 ? rs.value("reason").convert<string>() : rs2.value("reason").convert<string>();

					gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -99, errormsg));

					return;
				}
			}

			//client = gserver->GetClientByParent(parentid);
			if (client == 0)
			{
				client = gserver->NewClient();
				client->masteraccountid = masteraccountid;
				client->m_socknum = req.conn->uid;
				client->socket = req.conn;
				req.conn->client_ = client;
				client->m_connected = true;
			}
			else
			{
				if (client->m_connected)
				{
					//player already logged on
					gserver->CloseClient(client, 3, "");//multiple people logging into the same account
				}
				//Login is valid
				client->m_connected = true;
				double logintime = unixtime();
				if (logintime - client->m_lastlogin < 1000 * 5)
				{
					gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", 6, "You have tried logging in too frequently. Please try again later."));
					req.conn->stop();
					return;
				}
				client->m_lastlogin = logintime;
				if (client->socket) gserver->CloseClient(client, 3, "");
				client->socket = req.conn;
				client->m_socknum = req.conn->uid;
				client->m_ipaddress = req.conn->address;
				req.conn->client_ = client;
				gserver->consoleLogger->information(Poco::format("Already established client found # %?d", (uint32_t)client->m_clientnumber));

				if (client->m_email == "Daisy")
				{
					client->m_bdenyotherplayer = true;
					client->m_icon = 7;
				}
			}

			if (client == 0)
			{
				//error creating client object
				gserver->consoleLogger->information(Poco::format("Error creating client object @ %s:%?d", (string)__FILE__, __LINE__));
				gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -99, "Error with connecting. Please contact support."));
				return;
			}


			//account exists
			Session ses2(gserver->serverpool->get());
			Statement select2(ses2);
			select2 << "SELECT * FROM `accounts` WHERE `parentid`=?;", use(masteraccountid);
			select2.execute();
			RecordSet rs2(select2);

			if (rs2.rowCount() == 0)
			{
				//does not have an account on server
				gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -4, "need create player"));
				client->m_loggedin = true;

				return;
			}
			else
			{
				int accountid = rs2.value("accountid").convert<int32_t>();
				client->m_accountid = accountid;

				//has an account, what about cities?
				Session ses3(gserver->serverpool->get());
				Statement select3(ses3);
				select3 << "SELECT * FROM `cities` WHERE `accountid`=?;", use(accountid);
				select3.execute();
				RecordSet rs3(select3);

				if (rs3.rowCount() == 0)
				{
					//does not have any cities on server but did have an account - this only happens if you try to "restart" your account. it saves the account info while deleting your cities
					gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -4, "need create player"));
					client->m_loggedin = true;
					return;
				}
				else
				{
					//has an account and cities. process the list and send account info

					amf3object obj;
					obj["cmd"] = "server.LoginResponse";
					obj["data"] = amf3object();
					amf3object & data = obj["data"];
					data["packageId"] = 0.0f;

					double tslag = unixtime();

					if (client->GetItemCount("consume.1.a") < 10000)
						client->SetItem("consume.1.a", 10000);
					client->m_cents = 5000;

					data["player"] = client->ToObject();
					//UNLOCK(M_CLIENTLIST);

					if (client->m_city.size() == 0)
					{
						//problem
						gserver->consoleLogger->error(Poco::format("Error client has no cities @ %s:%?d", (string)__FILE__, __LINE__));
						gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -99, "Error with connecting. Please contact support."));
						return;
					}
					client->m_currentcityid = ((PlayerCity*)client->m_city.at(0))->m_castleid;
					client->m_currentcityindex = 0;
					client->m_accountexists = true;


					//check for holiday status
					stBuff * holiday = client->GetBuff("FurloughBuff");
					if (holiday && holiday->endtime > tslag)
					{
						//is in holiday - send holiday info too

						string s;
						{
							int32_t hours;
							int32_t mins;
							int32_t secs = (holiday->endtime - tslag) / 1000;

							hours = secs / 60 / 60;
							mins = secs / 60 - hours * 60;
							secs = secs - mins * 60 - hours * 60 * 60;

							std::stringstream ss;
							ss << hours << "," << mins << "," << secs;

							s = ss.str();
						}

						data["ok"] = -100;
						data["msg"] = s;
						data["errorMsg"] = s;
					}
					else
					{
						data["ok"] = 1;
						data["msg"] = "success";
					}

					gserver->SendObject(client, obj);
					//SendObject(*req.connection, obj);

					client->m_lag = unixtime() - tslag;

					client->m_loggedin = true;

					gserver->currentplayersonline++;
					client->SaveToDB();

					return;
				}
			}
		}
	}
	return;
}
Exemplo n.º 11
0
void OpenGLShader::use()
{
    use(nullptr);
}
Exemplo n.º 12
0
	void Event::play()
	{
		if(this->parent == NULL)
			parent = Event::defaultParentEvent;
		use(boost::any_cast<EnvirUseFunc>(this->at("play")));
	}
Exemplo n.º 13
0
void LockQuery::lock() {
	for (map<string, LockType>::iterator it = m_resources.begin(); it != m_resources.end(); ++it) {
		*m_db << "insert into waiting(client_id, name) values(:id, :name)",
			use(m_id, "id"),
			use(it->first, "name");

		for (;;) {
			try {
				transaction tr(*m_db);
				LockTypeSet mySet;
				*m_db << "select ex, pw, pr, cw, cr, nl from resources where eid = :eid and name = :name for update",
				use(m_eid, "eid"),
				use(it->first, "name"),
				into(mySet[EX]),
				into(mySet[PW]),
				into(mySet[PR]),
				into(mySet[CW]),
				into(mySet[CR]),
				into(mySet[NL]);

				bool update = m_db->got_data();

				LockTypeSet otherSet;
				*m_db << "select ifnull(sum(ex), 0), ifnull(sum(pw), 0), ifnull(sum(pr), 0), ifnull(sum(cw), 0), ifnull(sum(cr), 0), ifnull(sum(nl), 0) from resources where eid != :eid and name = :name for update",
				use(m_eid, "eid"),
				use(it->first, "name"),
				into(otherSet[EX]),
				into(otherSet[PW]),
				into(otherSet[PR]),
				into(otherSet[CW]),
				into(otherSet[CR]),
				into(otherSet[NL]);

				if (!m_db->got_data()) {
					continue;
				}

				mySet += it->second;
				if (LockTypeSet::compatible(mySet, otherSet)) {
					if (update) {
						*m_db << "update resources set ex = :ex, pw = :pw, pr = :pr, cw = :cw, cr = :cr, nl = :nl where eid = :eid and name = :name",
							use(m_eid, "eid"),
							use(it->first, "name"),
							use(mySet[EX], "ex"),
							use(mySet[PW], "pw"),
							use(mySet[PR], "pr"),
							use(mySet[CW], "cw"),
							use(mySet[CR], "cr"),
							use(mySet[NL], "nl");
					} else {
						*m_db << "insert into resources(eid, name, ex, pw, pr, cw, cr, nl) values(:eid, :name, :ex, :pw, :pr, :cw, :cr, :nl)",
							use(m_eid, "eid"),
							use(it->first, "name"),
							use(mySet[EX], "ex"),
							use(mySet[PW], "pw"),
							use(mySet[PR], "pr"),
							use(mySet[CW], "cw"),
							use(mySet[CR], "cr"),
							use(mySet[NL], "nl");
					}
					tr.commit();
					break;
				} else {
					tr.rollback();
					m_sync->wait();
				}
			} catch (...) {}
		}
		*m_db << "delete from waiting where client_id = :id and name = :name",
			use(m_id, "id"),
			use(it->first, "name");
	}
}
Exemplo n.º 14
0
void LockQuery::unlock() {
	for (map<string, LockType>::iterator it = m_resources.begin(); it != m_resources.end(); ++it) {
		LockTypeSet mySet;
			*m_db << "select ex, pw, pr, cw, cr, nl from resources where eid = :eid and name = :name",
			use(m_eid, "eid"),
			use(it->first, "name"),
			into(mySet[EX]),
			into(mySet[PW]),
			into(mySet[PR]),
			into(mySet[CW]),
			into(mySet[CR]),
			into(mySet[NL]);

		mySet -= it->second;
		*m_db << "update resources set ex = :ex, pw = :pw, pr = :pr, cw = :cw, cr = :cr, nl = :nl where eid = :eid and name = :name",
			use(m_eid, "eid"),
			use(it->first, "name"),
			use(mySet[EX], "ex"),
			use(mySet[PW], "pw"),
			use(mySet[PR], "pr"),
			use(mySet[CW], "cw"),
			use(mySet[CR], "cr"),
			use(mySet[NL], "nl");

			vector<string> address(100);
			vector<int> port(100);
			*m_db << "select address, port from clients join waiting on clients.id = waiting.client_id where name = :name",
				use(it->first), into(address), into(port);
			for (size_t i = 0; i < address.size(); ++i) {
				asio::ip::tcp::endpoint endpoint;
				endpoint.address(asio::ip::address::from_string(address[i]));
				endpoint.port(port[i]);
				m_sync->notify(endpoint);
			}
	}
}
Exemplo n.º 15
0
// V-table should be defined with weak linkage.
Test2a::Test2a() { use(typeid(Test2a)); }
Exemplo n.º 16
0
// V-table should be defined with weak linkage.
Test3a::Test3a() { use(typeid(Test3a)); }
Exemplo n.º 17
0
void testSuppression() {
	use(*maybeNull());
}
Exemplo n.º 18
0
// V-table should be defined with weak linkage.
Test3b::Test3b() { use(typeid(Test3b)); }
Exemplo n.º 19
0
 ~reserved_memory()
 {
     use();
 }
Exemplo n.º 20
0
// V-table should be defined with weak linkage.
Test3c::Test3c() { use(typeid(Test3c)); }
Exemplo n.º 21
0
int main ()
{
  use (&v_char);
  use (&v_signed_char);
  use (&v_unsigned_char);

  use (&v_short);
  use (&v_signed_short);
  use (&v_unsigned_short);

  use (&v_int);
  use (&v_signed_int);
  use (&v_unsigned_int);

  use (&v_long);
  use (&v_signed_long);
  use (&v_unsigned_long);

  use (&v_long_long);
  use (&v_signed_long_long);
  use (&v_unsigned_long_long);

  use (&v_float);
  use (&v_double);

  use (v_char_array);
  use (v_signed_char_array);
  use (v_unsigned_char_array);

  use (v_short_array);
  use (v_signed_short_array);
  use (v_unsigned_short_array);

  use (v_int_array);
  use (v_signed_int_array);
  use (v_unsigned_int_array);

  use (v_long_array);
  use (v_signed_long_array);
  use (v_unsigned_long_array);

  use (v_float_array);
  use (v_double_array);

  use (v_char_pointer);
  use (v_signed_char_pointer);
  use (v_unsigned_char_pointer);

  use (v_short_pointer);
  use (v_signed_short_pointer);
  use (v_unsigned_short_pointer);

  use (v_int_pointer);
  use (v_signed_int_pointer);
  use (v_unsigned_int_pointer);

  use (v_long_pointer);
  use (v_signed_long_pointer);
  use (v_unsigned_long_pointer);

  use (v_float_pointer);
  use (v_double_pointer);

  use (v_char_pointer_pointer);
  use (v_signed_char_pointer_pointer);
  use (v_unsigned_char_pointer_pointer);

  use (v_short_pointer_pointer);
  use (v_signed_short_pointer_pointer);
  use (v_unsigned_short_pointer_pointer);

  use (v_int_pointer_pointer);
  use (v_signed_int_pointer_pointer);
  use (v_unsigned_int_pointer_pointer);

  use (v_long_pointer_pointer);
  use (v_signed_long_pointer_pointer);
  use (v_unsigned_long_pointer_pointer);

  use (v_float_pointer_pointer);
  use (v_double_pointer_pointer);

  use (v_char_array_pointer);
  use (v_signed_char_array_pointer);
  use (v_unsigned_char_array_pointer);

  use (v_short_array_pointer);
  use (v_signed_short_array_pointer);
  use (v_unsigned_short_array_pointer);

  use (v_int_array_pointer);
  use (v_signed_int_array_pointer);
  use (v_unsigned_int_array_pointer);

  use (v_long_array_pointer);
  use (v_signed_long_array_pointer);
  use (v_unsigned_long_array_pointer);

  use (v_float_array_pointer);
  use (v_double_array_pointer);

  use (v_char_pointer_array);
  use (v_signed_char_pointer_array);
  use (v_unsigned_char_pointer_array);

  use (v_short_pointer_array);
  use (v_signed_short_pointer_array);
  use (v_unsigned_short_pointer_array);

  use (v_int_pointer_array);
  use (v_signed_int_pointer_array);
  use (v_unsigned_int_pointer_array);

  use (v_long_pointer_array);
  use (v_signed_long_pointer_array);
  use (v_unsigned_long_pointer_array);

  use (v_float_pointer_array);
  use (v_double_pointer_array);

  use (&v_struct1);
  use (&v_struct2);
  use (&v_struct3);

  use (&v_union);
  use (&v_union2);
  use (&v_union3);

  use (&v_boolean);
  use (&v_boolean2);
  use (&v_misordered);

  use (&v_char_func);
  use (&v_signed_char_func);
  use (&v_unsigned_char_func);

  use (&v_short_func);
  use (&v_signed_short_func);
  use (&v_unsigned_short_func);

  use (&v_int_func);
  use (&v_signed_int_func);
  use (&v_unsigned_int_func);

  use (&v_long_func);
  use (&v_signed_long_func);
  use (&v_unsigned_long_func);

  use (&v_long_long_func);
  use (&v_signed_long_long_func);
  use (&v_unsigned_long_long_func);

  use (&v_float_func);
  use (&v_double_func);
}
Exemplo n.º 22
0
// V-table should be defined externally.
Test0a::Test0a() { use(typeid(Test0a)); }
Exemplo n.º 23
0
void statement(int loop, Swtch swp, int lev) {
	float ref = refinc;

	if (Aflag >= 2 && lev == 15)
		warning("more than 15 levels of nested statements\n");
	switch (t) {
	case IF:       ifstmt(genlabel(2), loop, swp, lev + 1);
 break;
	case WHILE:    whilestmt(genlabel(3), swp, lev + 1); break;
	case DO:       dostmt(genlabel(3), swp, lev + 1); expect(';');
					break;

	case FOR:      forstmt(genlabel(4), swp, lev + 1);
 break;
	case BREAK:    walk(NULL, 0, 0);
		       definept(NULL);
		       if (swp && swp->lab > loop)
		       	branch(swp->lab + 1);
		       else if (loop)
		       	branch(loop + 2);
		       else
		       	error("illegal break statement\n");
		       t = gettok(); expect(';');
					   break;

	case CONTINUE: walk(NULL, 0, 0);
		       definept(NULL);
		       if (loop)
		       	branch(loop + 1);
		       else
		       	error("illegal continue statement\n");
		       t = gettok(); expect(';');
					      break;

	case SWITCH:   swstmt(loop, genlabel(2), lev + 1);
 break;
	case CASE:     {
		       	int lab = genlabel(1);
		       	if (swp == NULL)
		       		error("illegal case label\n");
		       	definelab(lab);
		       	while (t == CASE) {
		       		static char stop[] = { IF, ID, 0 };
		       		Tree p;
		       		t = gettok();
		       		p = constexpr(0);
		       		if (generic(p->op) == CNST && isint(p->type)) {
		       			if (swp) {
		       				needconst++;
		       				p = cast(p, swp->sym->type);
		       				if (p->type->op == UNSIGNED)
		       					p->u.v.i = extend(p->u.v.u, p->type);
		       				needconst--;
		       				caselabel(swp, p->u.v.i, lab);
		       			}
		       		} else
		       			error("case label must be a constant integer expression\n");

		       		test(':', stop);
		       	}
		       	statement(loop, swp, lev);
		       } break;
	case DEFAULT:  if (swp == NULL)
		       	error("illegal default label\n");
		       else if (swp->deflab)
		       	error("extra default label\n");
		       else {
		       	swp->deflab = findlabel(swp->lab);
		       	definelab(swp->deflab->u.l.label);
		       }
		       t = gettok();
		       expect(':');
		       statement(loop, swp, lev); break;
	case RETURN:   {
		       	Type rty = freturn(cfunc->type);
		       	t = gettok();
		       	definept(NULL);
		       	if (t != ';')
		       		if (rty == voidtype) {
		       			error("extraneous return value\n");
		       			expr(0);
		       			retcode(NULL);
		       		} else
		       			retcode(expr(0));
		       	else {
		       		if (rty != voidtype)
		       			warning("missing return value\n");
		       		retcode(NULL);
		       	}
		       	branch(cfunc->u.f.label);
		       } expect(';');
					    break;

	case '{':      compound(loop, swp, lev + 1); break;
	case ';':      definept(NULL); t = gettok(); break;
	case GOTO:     walk(NULL, 0, 0);
		       definept(NULL);
		       t = gettok();
		       if (t == ID) {
		       	Symbol p = lookup(token, stmtlabs);
		       	if (p == NULL) {
				p = install(token, &stmtlabs, 0, FUNC);
				p->scope = LABELS;
				p->u.l.label = genlabel(1);
				p->src = src;
			}
		       	use(p, src);
		       	branch(p->u.l.label);
		       	t = gettok();
		       } else
		       	error("missing label in goto\n"); expect(';');
					  break;

	case ID:       if (getchr() == ':') {
		       	stmtlabel();
		       	statement(loop, swp, lev);
		       	break;
		       }
	default:       definept(NULL);
		       if (kind[t] != ID) {
		       	error("unrecognized statement\n");
		       	t = gettok();
		       } else {
		       	Tree e = expr0(0);
		       	listnodes(e, 0, 0);
		       	if (nodecount == 0 || nodecount > 200)
		       		walk(NULL, 0, 0);
		       	else if (glevel) walk(NULL, 0, 0);
		       	deallocate(STMT);
		       } expect(';');
						break;

	}
	if (kind[t] != IF && kind[t] != ID
	&& t != '}' && t != EOI) {
		static char stop[] = { IF, ID, '}', 0 };
		error("illegal statement termination\n");
		skipto(0, stop);
	}
	refinc = ref;
}
Exemplo n.º 24
0
// V-table should be defined externally.
Test0b::Test0b() { use(typeid(Test0b)); }
Exemplo n.º 25
0
void SessionWrapper::execute(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	SessionHolder* pSessionHolder = Wrapper::unwrapNative<SessionHolder>(args);
	Poco::Data::Session& session = pSessionHolder->session();
	if (args.Length() > 0)
	{
		RecordSetHolder* pRecordSetHolder = new RecordSetHolder;
		pRecordSetHolder->reserveBindings(static_cast<std::size_t>(args.Length() - 1));
		try
		{
			Poco::Data::Statement statement = (session << toString(args[0]));
			for (int i = 1; i < args.Length(); i++)
			{
				if (args[i]->IsString())
				{
					statement , use(pRecordSetHolder->bindValue(toString(args[i])));
				}
				else if (args[i]->IsBoolean())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->BooleanValue()));
				}
				else if (args[i]->IsInt32())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->Int32Value()));
				}
				else if (args[i]->IsUint32())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->Uint32Value()));
				}
				else if (args[i]->IsNumber())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->NumberValue()));
				}
#if POCO_VERSION > 0x01050000
				else if (args[i]->IsDate())
				{
					v8::Local<v8::Date> jsDate = v8::Local<v8::Date>::Cast(args[i]);
					double millis = jsDate->ValueOf();
					Poco::Timestamp ts(static_cast<Poco::Timestamp::TimeVal>(millis*1000));
					Poco::DateTime dateTime(ts);
					statement , use(pRecordSetHolder->bindValue(dateTime));
				}
#endif
				else
				{
					throw Poco::InvalidArgumentException(Poco::format("cannot convert argument %d to native type", i));
				}
			}
			if (pSessionHolder->getPageSize() > 0)
			{
				statement , limit(pSessionHolder->getPageSize());
			}
			statement.execute();
			pRecordSetHolder->assignStatement(statement);
			pRecordSetHolder->updateRecordSet();
			RecordSetWrapper wrapper;
			v8::Persistent<v8::Object>& recordSetObject(wrapper.wrapNativePersistent(args.GetIsolate(), pRecordSetHolder));
			args.GetReturnValue().Set(recordSetObject);
		}
		catch (Poco::Exception& exc)
		{
			delete pRecordSetHolder;
			returnException(args, exc);
		}
	}
}
Exemplo n.º 26
0
// V-table needs to be defined weakly.
Test1a::Test1a() { use(typeid(Test1a)); }
Exemplo n.º 27
0
void OpenGL1::onDraw(){
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    // add your codes here...
    /*!
     *  @author wuxingogo, 15-04-06 00:04:09
     *
     *  @brief  获得当前的着色器程序
     *
     *  @return nil
     */
    auto glProgram = getGLProgram();
    
    glProgram->use();
    /*!
     *  @author wuxingogo, 15-04-06 00:04:17
     *
     *  @brief  set cocos2dx default shader
     */
    glProgram->setUniformsForBuiltins();
    
    auto size = Director::getInstance()->getWinSize();
    /*!
     *  @author wuxingogo, 15-04-06 00:04:48
     *
     *  @brief  triangle vertex
     */
    float vertex[] = {
        0,0,
        size.width , 0,
        size.width / 2, size.height
    };
    /*!
     *  @author wuxingogo, 15-04-06 00:04:27
     *
     *  @brief  color vertex
     */
    float color[] = {
        0,1,0,1,
        1,0,0,1,
        0,0,1,1
    };
    /*!
     *  @author wuxingogo, 15-04-06 00:04:40
     *
     *  @brief  set addtive GL Enable, the color and vertex.
     */
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
    
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertex);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, color);

    
    glDrawArrays(GL_TRIANGLES, 0, 3);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 3);
    
    CHECK_GL_ERROR_DEBUG();
    
    
}
Exemplo n.º 28
0
// V-table should be defined weakly..
Test1b::Test1b() { use(typeid(Test1b)); }
Exemplo n.º 29
0
LinkedShader::LinkedShader(Shader *vs, Shader *fs, u32 vertType, bool useHWTransform, LinkedShader *previous)
		: useHWTransform_(useHWTransform), program(0), dirtyUniforms(0) {
	PROFILE_THIS_SCOPE("shaderlink");

	program = glCreateProgram();
	vs_ = vs;
	glAttachShader(program, vs->shader);
	glAttachShader(program, fs->shader);

	// Bind attribute locations to fixed locations so that they're
	// the same in all shaders. We use this later to minimize the calls to
	// glEnableVertexAttribArray and glDisableVertexAttribArray.
	glBindAttribLocation(program, ATTR_POSITION, "position");
	glBindAttribLocation(program, ATTR_TEXCOORD, "texcoord");
	glBindAttribLocation(program, ATTR_NORMAL, "normal");
	glBindAttribLocation(program, ATTR_W1, "w1");
	glBindAttribLocation(program, ATTR_W2, "w2");
	glBindAttribLocation(program, ATTR_COLOR0, "color0");
	glBindAttribLocation(program, ATTR_COLOR1, "color1");

#ifndef USING_GLES2
	if (gstate_c.featureFlags & GPU_SUPPORTS_DUALSOURCE_BLEND) {
		// Dual source alpha
		glBindFragDataLocationIndexed(program, 0, 0, "fragColor0");
		glBindFragDataLocationIndexed(program, 0, 1, "fragColor1");
	} else if (gl_extensions.VersionGEThan(3, 3, 0)) {
		glBindFragDataLocation(program, 0, "fragColor0");
	}
#endif

	glLinkProgram(program);

	GLint linkStatus = GL_FALSE;
	glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
	if (linkStatus != GL_TRUE) {
		GLint bufLength = 0;
		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
		if (bufLength) {
			char* buf = new char[bufLength];
			glGetProgramInfoLog(program, bufLength, NULL, buf);
#ifdef ANDROID
			ELOG("Could not link program:\n %s", buf);
#endif
			ERROR_LOG(G3D, "Could not link program:\n %s", buf);
			ERROR_LOG(G3D, "VS:\n%s", vs->source().c_str());
			ERROR_LOG(G3D, "FS:\n%s", fs->source().c_str());
			Reporting::ReportMessage("Error in shader program link: info: %s / fs: %s / vs: %s", buf, fs->source().c_str(), vs->source().c_str());
#ifdef SHADERLOG
			OutputDebugStringUTF8(buf);
			OutputDebugStringUTF8(vs->source().c_str());
			OutputDebugStringUTF8(fs->source().c_str());
#endif
			delete [] buf;	// we're dead!
		}
		// Prevent a buffer overflow.
		numBones = 0;
		return;
	}

	INFO_LOG(G3D, "Linked shader: vs %i fs %i", (int)vs->shader, (int)fs->shader);

	u_tex = glGetUniformLocation(program, "tex");
	u_proj = glGetUniformLocation(program, "u_proj");
	u_proj_through = glGetUniformLocation(program, "u_proj_through");
	u_texenv = glGetUniformLocation(program, "u_texenv");
	u_fogcolor = glGetUniformLocation(program, "u_fogcolor");
	u_fogcoef = glGetUniformLocation(program, "u_fogcoef");
	u_alphacolorref = glGetUniformLocation(program, "u_alphacolorref");
	u_alphacolormask = glGetUniformLocation(program, "u_alphacolormask");
	u_stencilReplaceValue = glGetUniformLocation(program, "u_stencilReplaceValue");
	u_testtex = glGetUniformLocation(program, "testtex");

	u_fbotex = glGetUniformLocation(program, "fbotex");
	u_blendFixA = glGetUniformLocation(program, "u_blendFixA");
	u_blendFixB = glGetUniformLocation(program, "u_blendFixB");
	u_fbotexSize = glGetUniformLocation(program, "u_fbotexSize");

	// Transform
	u_view = glGetUniformLocation(program, "u_view");
	u_world = glGetUniformLocation(program, "u_world");
	u_texmtx = glGetUniformLocation(program, "u_texmtx");
	if (vertTypeGetWeightMask(vertType) != GE_VTYPE_WEIGHT_NONE)
		numBones = TranslateNumBones(vertTypeGetNumBoneWeights(vertType));
	else
		numBones = 0;
	u_depthRange = glGetUniformLocation(program, "u_depthRange");

#ifdef USE_BONE_ARRAY
	u_bone = glGetUniformLocation(program, "u_bone");
#else
	for (int i = 0; i < 8; i++) {
		char name[10];
		sprintf(name, "u_bone%i", i);
		u_bone[i] = glGetUniformLocation(program, name);
	}
#endif

	// Lighting, texturing
	u_ambient = glGetUniformLocation(program, "u_ambient");
	u_matambientalpha = glGetUniformLocation(program, "u_matambientalpha");
	u_matdiffuse = glGetUniformLocation(program, "u_matdiffuse");
	u_matspecular = glGetUniformLocation(program, "u_matspecular");
	u_matemissive = glGetUniformLocation(program, "u_matemissive");
	u_uvscaleoffset = glGetUniformLocation(program, "u_uvscaleoffset");
	u_texclamp = glGetUniformLocation(program, "u_texclamp");
	u_texclampoff = glGetUniformLocation(program, "u_texclampoff");

	for (int i = 0; i < 4; i++) {
		char temp[64];
		sprintf(temp, "u_lightpos%i", i);
		u_lightpos[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightdir%i", i);
		u_lightdir[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightatt%i", i);
		u_lightatt[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightangle%i", i);
		u_lightangle[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightspotCoef%i", i);
		u_lightspotCoef[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightambient%i", i);
		u_lightambient[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightdiffuse%i", i);
		u_lightdiffuse[i] = glGetUniformLocation(program, temp);
		sprintf(temp, "u_lightspecular%i", i);
		u_lightspecular[i] = glGetUniformLocation(program, temp);
	}

	attrMask = 0;
	if (-1 != glGetAttribLocation(program, "position")) attrMask |= 1 << ATTR_POSITION;
	if (-1 != glGetAttribLocation(program, "texcoord")) attrMask |= 1 << ATTR_TEXCOORD;
	if (-1 != glGetAttribLocation(program, "normal")) attrMask |= 1 << ATTR_NORMAL;
	if (-1 != glGetAttribLocation(program, "w1")) attrMask |= 1 << ATTR_W1;
	if (-1 != glGetAttribLocation(program, "w2")) attrMask |= 1 << ATTR_W2;
	if (-1 != glGetAttribLocation(program, "color0")) attrMask |= 1 << ATTR_COLOR0;
	if (-1 != glGetAttribLocation(program, "color1")) attrMask |= 1 << ATTR_COLOR1;

	availableUniforms = 0;
	if (u_proj != -1) availableUniforms |= DIRTY_PROJMATRIX;
	if (u_proj_through != -1) availableUniforms |= DIRTY_PROJTHROUGHMATRIX;
	if (u_texenv != -1) availableUniforms |= DIRTY_TEXENV;
	if (u_alphacolorref != -1) availableUniforms |= DIRTY_ALPHACOLORREF;
	if (u_alphacolormask != -1) availableUniforms |= DIRTY_ALPHACOLORMASK;
	if (u_fogcolor != -1) availableUniforms |= DIRTY_FOGCOLOR;
	if (u_fogcoef != -1) availableUniforms |= DIRTY_FOGCOEF;
	if (u_texenv != -1) availableUniforms |= DIRTY_TEXENV;
	if (u_uvscaleoffset != -1) availableUniforms |= DIRTY_UVSCALEOFFSET;
	if (u_texclamp != -1) availableUniforms |= DIRTY_TEXCLAMP;
	if (u_world != -1) availableUniforms |= DIRTY_WORLDMATRIX;
	if (u_view != -1) availableUniforms |= DIRTY_VIEWMATRIX;
	if (u_texmtx != -1) availableUniforms |= DIRTY_TEXMATRIX;
	if (u_stencilReplaceValue != -1) availableUniforms |= DIRTY_STENCILREPLACEVALUE;
	if (u_blendFixA != -1 || u_blendFixB != -1 || u_fbotexSize != -1) availableUniforms |= DIRTY_SHADERBLEND;
	if (u_depthRange != -1)
		availableUniforms |= DIRTY_DEPTHRANGE;

	// Looping up to numBones lets us avoid checking u_bone[i]
#ifdef USE_BONE_ARRAY
	if (u_bone != -1) {
		for (int i = 0; i < numBones; i++) {
			availableUniforms |= DIRTY_BONEMATRIX0 << i;
		}
	}
#else
	for (int i = 0; i < numBones; i++) {
		if (u_bone[i] != -1)
			availableUniforms |= DIRTY_BONEMATRIX0 << i;
	}
#endif
	if (u_ambient != -1) availableUniforms |= DIRTY_AMBIENT;
	if (u_matambientalpha != -1) availableUniforms |= DIRTY_MATAMBIENTALPHA;
	if (u_matdiffuse != -1) availableUniforms |= DIRTY_MATDIFFUSE;
	if (u_matemissive != -1) availableUniforms |= DIRTY_MATEMISSIVE;
	if (u_matspecular != -1) availableUniforms |= DIRTY_MATSPECULAR;
	for (int i = 0; i < 4; i++) {
		if (u_lightdir[i] != -1 ||
				u_lightspecular[i] != -1 ||
				u_lightpos[i] != -1)
			availableUniforms |= DIRTY_LIGHT0 << i;
	}

	glUseProgram(program);

	// Default uniform values
	glUniform1i(u_tex, 0);
	glUniform1i(u_fbotex, 1);
	glUniform1i(u_testtex, 2);
	// The rest, use the "dirty" mechanism.
	dirtyUniforms = DIRTY_ALL;
	use(vertType, previous);
}
void f() { use(&Child::Method); }