Example #1
0
GameInstSet::~GameInstSet() {

	for (int i = 0, j = 0; i < unit_capacity; i++) {
		GameInst* inst = unit_set[i].inst;
		if (valid_inst(inst)) {
			inst->free_reference();
		}
	}

	for (int i = 0; i < deallocation_list.size(); i++) {
		deallocation_list[i]->free_reference();
	}
}
Example #2
0
void GameInstSet::clear() {
	for (int i = 0; i < unit_capacity; i++) {
		GameInst* inst = unit_set[i].inst;
		if (valid_inst(inst)) {
			inst->free_reference();
		}
	}
	next_id = 1;
	unit_amnt = 0;
	depthlist_map.clear();
	memset(&unit_set[0], 0, unit_capacity * sizeof(InstanceState));
	memset(&unit_grid[0], 0, grid_w * grid_h * sizeof(InstanceLinkedList));
}
Example #3
0
void GameInstSet::copy_to(GameInstSet& inst_set) const {

	DepthMap::const_iterator it = depthlist_map.end();
	//Synch live objects
	for (int ind = 0; it != depthlist_map.begin();) {
		--it;
		InstanceState* state = it->second.start_of_list;
		while (state) {
			GameInst* inst = state->inst;
			obj_id id = inst->id;
			GameInst* oinst = inst_set.get_instance(id);
			if (oinst == NULL || typeid(inst) != typeid(oinst)) {
				inst_set.add_instance(inst->clone(), id);
				if (oinst)
					oinst->destroyed = true;
			}
			state = state->next_same_depth;
		}
	}
	//Remove dead objects
	for (int i = 0; i < inst_set.unit_capacity; i++) {
		InstanceState* state = &inst_set.unit_set[i];
		GameInst* oinst = state->inst;
		if (valid_inst(oinst)) {
			if (!oinst->destroyed) {
				GameInst* inst = get_instance(oinst->id);
				if (inst != NULL) {
					inst_set.__update_collision_position(state,
							Pos(oinst->x, oinst->y), Pos(inst->x, inst->y));
					inst->copy_to(oinst);
				} else
					inst_set.__remove_instance(state);
				inst->free_reference();
			}

		}
	}
	inst_set.next_id = this->next_id;
	LANARTS_ASSERT(check_copy_integrity(inst_set));
}