void D3D12RingBufferAllocator::consume(uint32_t write_marker, uint32_t size) {
	UENSURE(consumable_size(write_marker, false) >= size);
	if(_read == _wrap && is_split(write_marker))
		_read += _size + (_size - (_read & _mask)) + size;
	else
		_read += size;
}
Esempio n. 2
0
Quad::~Quad()
{
	if(is_split())
	{
		delete quads[0][0];
		delete quads[0][1];
		delete quads[1][0];
		delete quads[1][1];
	}
}
uint32_t D3D12RingBufferAllocator::produce(uint32_t size)
{
	uint32_t masked_write = _write & _mask;

	if (is_split(_write)) {
		uint32_t available_size;
		if (_wrap == _read) {
			available_size = masked_write ? (_size - masked_write) : 0;
		}
		else {
			UENSURE((_read & _mask) >= (_write & _mask));
			available_size = (_read - _write) & _mask;
		}

		if (available_size >= size) {
			uint32_t ret = _write & _mask;
			_write += size;
			return ret;
		}
		goto failed;
	}

	bool empty = is_empty();

	if(masked_write && empty && _size >= size)
		goto write_front;

	if (!masked_write && !empty) {
		goto check_front;
	}

	if ((_size - masked_write) >= size) {
		uint32_t ret = _write & _mask;
		_write += size;
		return ret;
	}

check_front:
	if ((_read & _mask) >= size) {
write_front:
		_wrap = _write;
		uint32_t ret = _write & _mask;
		_write += _size + (_size - masked_write) + size;
		return ret;
	}
failed:
	uint32_t amount_consumed = consume_to_signaled_fence();
	if(amount_consumed >= size)
		return produce(size);	// try again

	return INVALID_ALLOCATION;
}
Esempio n. 4
0
Quad *Quad::get_at(double x, double y, int max_level, int level)
{
	if(!is_split())
		return this;

	/*if(max_level>-1 && level>=max_level)
		return this;*/

	int a = ( x < *x_mid() ) ? 0 : 1;
	int b = ( y < *y_mid() ) ? 0 : 1;

	return quads[b][a]->get_at(x, y, max_level, level+1);
}
Esempio n. 5
0
void Quad::track_down(double x, double y, int levels)
{
	if(levels>0)
	{
		int a = ( x < *x_mid() ) ? 0 : 1;
		int b = ( y < *y_mid() ) ? 0 : 1;

		if( !is_split() )
			split();

		quads[b][a]->track_down(x, y, levels-1);
	}
}
Esempio n. 6
0
void Quad::split()
{
	if(is_split())
		return;

	quads[0][0] = new Quad(V);
	quads[0][1] = new Quad(V);
	quads[1][0] = new Quad(V);
	quads[1][1] = new Quad(V);
	
	quads[0][0]->set_range( *x1(), *x_mid(), *y1(), *y_mid() );
	quads[0][1]->set_range( *x_mid(), *x2(), *y1(), *y_mid() );
	quads[1][0]->set_range( *x1(), *x_mid(), *y_mid(), *y2() );
	quads[1][1]->set_range( *x_mid(), *x2(), *y_mid(), *y2() );
}
Esempio n. 7
0
void Terrain::split()
{
	if(is_split())
		return;

	quads[0][0] = new Terrain(V);
	quads[0][1] = new Terrain(V);
	quads[1][0] = new Terrain(V);
	quads[1][1] = new Terrain(V);

	quads[0][0]->set_range(*x1(), *x_mid(), *y1(), *y_mid());
	quads[0][1]->set_range(*x_mid(), *x2(), *y1(), *y_mid());
	quads[1][0]->set_range(*x1(), *x_mid(), *y_mid(), *y2());
	quads[1][1]->set_range(*x_mid(), *x2(), *y_mid(), *y2());
}
Esempio n. 8
0
void Terrain::track_down(double x, double y, double nz, int levels)
{
	if( levels > 0 ) {
		int a = ( x < *x_mid() ) ? 0 : 1;
		int b = ( y < *y_mid() ) ? 0 : 1;

		if( !is_split() )
			split();

		dynamic_cast<Terrain*>(quads[b][a])->track_down(x, y, nz, levels-1);
	}
	else {
		z[0][0]=
		z[0][1]=
		z[1][1]=
		z[1][0] = z_mean_ = nz;
	}
}
Esempio n. 9
0
void cParty::writeTo(std::ostream& file, const cScenario& scen) const {
	file << "CREATEVERSION " << std::hex << OBOE_CURRENT_VERSION << std::dec << '\n';
	file << "AGE " << age << '\n';
	file << "GOLD " << gold << '\n';
	file << "FOOD " << food << '\n';
	file << "NEXTID " << next_pc_id << '\n';
	file << "HOSTILES " << int(hostiles_present)  << '\n';
	file << "EASY " << int(easy_mode) << '\n';
	file << "LESSWM " << int(less_wm) << '\n';
	for(int i = 0; i < 310; i++)
		for(int j = 0; j < 50; j++)
			if(stuff_done[i][j] > 0)
				file << "SDF " << i << ' ' << j << ' ' << unsigned(stuff_done[i][j]) << '\n';
	for(auto iter = pointers.begin(); iter != pointers.end(); iter++)
		file << "POINTER " << iter->first << ' ' << iter->second.first << ' ' << iter->second.second << '\n';
	for(int i = 0; i < magic_ptrs.size(); i++)
		file << "POINTER " << i << ' ' << int(magic_ptrs[i]) << '\n';
	file << "LIGHT " << light_level << '\n';
	file << "OUTCORNER " << outdoor_corner.x << ' ' << outdoor_corner.y << '\n';
	file << "INWHICHCORNER " << i_w_c.x << ' ' << i_w_c.y << '\n';
	file << "SECTOR " << out_loc.x << ' ' << out_loc.y << '\n';
	file << "LOCINSECTOR " << loc_in_sec.x << ' ' << loc_in_sec.y << '\n';
	file << "IN " << in_boat << ' ' << in_horse << '\n';
	for(auto& kv : status) {
		if(kv.second > 0)
			file << "STATUS " << kv.first << ' ' << kv.second << '\n';
	}
	if(is_split()) {
		file << "SPLIT_LEFT_IN " << left_in << '\n';
		file << "SPLIT_LEFT_AT " << left_at.x << ' ' << left_at.y << '\n';
	}
	for(int i : m_noted)
		file << "ROSTER " << i << '\n';
	for(int i : m_seen)
		file << "SEEN " << i << '\n';
	for(int i = 0; i < 4; i++)
		if(imprisoned_monst[i] > 0)
			file << "SOULCRYSTAL " << i << ' ' << imprisoned_monst[i] << '\n';
	file << "DIRECTION " << direction << '\n';
	file << "WHICHSLOT " << at_which_save_slot << '\n';
	for(int i = 0; i < creature_save.size(); i++) {
		file << "TOWNSAVE " << i << ' ' << creature_save[i].which_town;
		if(creature_save[i].hostile) file << " HOSTILE";
		file << '\n';
	}
	for(int i = 0; i < alchemy.size(); i++)
		if(alchemy[i])
			file << "ALCHEMY " << i << '\n';
	for(int i = 0; i < scen.towns.size(); i++) {
		if(scen.towns[i]->item_taken.any())
			file << "ITEMTAKEN " << i << ' ' << scen.towns[i]->item_taken << '\n';
		if(scen.towns[i]->can_find == scen.towns[i]->is_hidden)
			file << (scen.towns[i]->can_find ? "TOWNVISIBLE " : "TOWNHIDDEN ") << i << '\n';
		if(scen.towns[i]->m_killed > 0)
			file << "TOWNSLAUGHTER " << i << ' ' << scen.towns[i]->m_killed << '\n';
	}
	for(auto key : key_times)
		file << "EVENT " << key.first << ' ' << key.second << '\n';
	for(int i : spec_items)
		file << "ITEM " << i << '\n';
	file << "KILLS " << total_m_killed << '\n';
	file << "DAMAGE " << total_dam_done << '\n';
	file << "WOUNDS " << total_dam_taken << '\n';
	file << "EXPERIENCE " << total_xp_gained << '\n';
	file << "SCENARIO " << scen_name << '\n';
	file << "WON " << scen_won << '\n';
	file << "PLAYED " << scen_played << '\n';
	for(auto p : active_quests)
		file << "QUEST " << p.first << ' ' << p.second.status << ' ' << p.second.start << ' ' << p.second.source << '\n';
	for(auto p : store_limited_stock) {
		for(auto p2 : p.second) {
			file << "SHOPSTOCK " << p.first << p2.first << p2.second;
		}
	}
	for(auto iter = campaign_flags.begin(); iter != campaign_flags.end(); iter++){
		std::string campaign_id = maybe_quote_string(iter->first);
		// Okay, we have the campaign ID in a state such that reading it back in will restore the original ID.
		// Now output any flags that are set for this campaign.
		for(unsigned int i = 0; i < 25; i++)
			for(unsigned int j = 0; j < 20; j++)
				if(iter->second.idx[i][j] > 0)
					file << "CAMPAIGN " << campaign_id << ' ' << i << ' ' << j << ' ' << unsigned(iter->second.idx[i][j]) << '\n';
	}
	file << '\f';
	for(int i = 0; i < boats.size(); i++){
		if(boats[i].exists) {
			file << "BOAT " << i << '\n';
			boats[i].writeTo(file);
			file << '\f';
		}
	}
	file << '\f';
	for(int i = 0; i < horses.size(); i++){
		if(horses[i].exists) {
			file << "HORSE " << i << '\n';
			horses[i].writeTo(file);
			file << '\f';
		}
	}
	file << '\f';
	for(auto& p : magic_store_items) {
		for(int j = 0; j < p.second.size(); j++)
			if(p.second[j].variety != eItemType::NO_ITEM){
				file << "MAGICSTORE " << p.first << ' ' << j << '\n';
				p.second[j].writeTo(file);
				file << '\f';
			}
	}
	file << '\f';
	for(int i = 0; i < job_banks.size(); i++) {
		file << "JOBBANK " << i << ' ' << job_banks[i].anger << '\n';
		if(!job_banks[i].inited) continue;
		for(int j = 0; j < 6; j++)
			file << "JOB " << j << ' ' << job_banks[i].jobs[j] << '\n';
	}
	file << '\f';
	for(int i = 0; i < out_c.size(); i++)
		if(out_c[i].exists){
			file << "ENCOUNTER " << i << "\n";
			file << "DIRECTION " << out_c[i].direction << '\n';
			file << "SECTOR " << out_c[i].which_sector.x << ' ' << out_c[i].which_sector.y << '\n';
			file << "LOCINSECTOR " << out_c[i].m_loc.x << ' ' << out_c[i].m_loc.y << '\n';
			file << "HOME " << out_c[i].home_sector.x << ' ' << out_c[i].home_sector.y << '\n';
			file << "-\n";
			out_c[i].what_monst.writeTo(file);
			file << '\f';
		}
	file << '\f';
	file << '\f';
	for(unsigned int i = 0; i < party_event_timers.size(); i++)
		file << "TIMER " << ' ' << party_event_timers[i].time << ' ' << party_event_timers[i].node_type
			 << ' ' << party_event_timers[i].node << '\f';
	file << '\f';
	for(int i = 0; i < creature_save.size(); i++)
		for(int j = 0; j < creature_save[i].size(); j++) {
			if(creature_save[i][j].active > 0) {
				file << "CREATURE " << i << ' ' << j << '\n';
				creature_save[i][j].writeTo(file);
				file << '\f';
			}
		}
	file << '\f';
	for(int i = 0; i < stored_items.size(); i++)
		for(size_t j = 0; j < stored_items[i].size(); j++)
			if(stored_items[i][j].variety != eItemType::NO_ITEM){
				file << "STORED " << i << ' ' << j << '\n';
				stored_items[i][j].writeTo(file);
				file << '\f';
			}
	if(summons.size() > 0) {
		file << '\f';
		int i = 0;
		for(const cMonster& monst : summons) {
			file << "SUMMON " << i++ << '\n';
			monst.writeTo(file);
			file << '\f';
		}
	}
	if(journal.size() > 0) {
		file << '\f';
		for(const cJournal& entry : journal) {
			file << "JOURNAL " << entry.day << ' ' << maybe_quote_string(entry.in_scen) << '\n' << entry.the_str << '\n';
			file << '\f';
		}
	}
	if(special_notes.size() > 0) {
		file << '\f';
		for(const cEncNote& note : special_notes) {
			file << "ENCNOTE " << note.type << ' ' << maybe_quote_string(note.where) << '\n' << note.the_str << '\n';
			file << '\f';
		}
	}
	if(talk_save.size() > 0) {
		file << '\f';
		for(const cConvers& note : talk_save) {
			file << "TALKNOTE";
			file << "WHO " << maybe_quote_string(note.who_said) << '\n';
			file << "WHERE " << maybe_quote_string(note.in_town) << ' ' << maybe_quote_string(note.in_scen) << '\n';
			file << "-\n" << note.the_str1 << '\n' << note.the_str2 << '\n';
			file << '\f';
		}
	}
}