Exemple #1
0
void Board::place(const std::size_t colIndex, const std::size_t rowIndex, const Piece &v) {
    if (colIndex < 0 || rowIndex < 0 || colIndex > 7 || rowIndex > 7)
        throw runtime_error_ex("index out of bounds: col=%d row=%d",colIndex,rowIndex);
    else if (v == Piece::OUT_OF_BOUNDS)
        throw runtime_error_ex("cannot set square to out of bounds: col=%d row=%d",colIndex,rowIndex);
    _data[rowIndex * 8 + colIndex] = v;
}
Exemple #2
0
void Texture::copy_from_2d(const SDL_Surface& surface) {
	GLenum texture_format;
	auto bpp = surface.format->BytesPerPixel;
	if (bpp == 4) {
		// contains an alpha channel
		if (surface.format->Rmask == 0x000000ff)
			texture_format = GL_RGBA;
		else
			texture_format = GL_BGRA;
	} else if (bpp == 3) {
		// no alpha channel
		if (surface.format->Rmask == 0x000000ff)
			texture_format = GL_RGB;
		else
			texture_format = GL_BGR;
	} else
		throw runtime_error_ex("surface has invalid bytes per pixel: %d",bpp);
	activate();
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
	glTexImage2D(GL_TEXTURE_2D, 0, bpp, surface.w, surface.h, 0,
			texture_format, GL_UNSIGNED_BYTE, surface.pixels);
    _context->check_error();
}
Exemple #3
0
void Texture::copy_from(const SDL_Surface& surface) {
	if ((surface.w & (surface.w - 1)) != 0)
		throw runtime_error_ex("surface  width is not a power of 2 it is %d", surface.w);
	if ((surface.h & (surface.h - 1)) != 0)
		throw std::runtime_error("surface height is not a power of 2");
	copy_from_2d(surface);
}
Exemple #4
0
GLuint ShaderProgram::attribute_location(const GLchar * name) {
	CHECK_CONTEXT;
	const auto result = _context->glGetAttribLocation(_program, name);
	_context->check_error();
	if (result == -1)
		throw runtime_error_ex("could not find name '%s'" , name);
	return result;
}
Exemple #5
0
arti::Piece annotate(const Board::const_iterator& it) {
	if (*it == Piece::EMPTY) return *it;
	else { 
		arti::Region n;
		n.insert_neighbours(it.pos()); 
		int r = it.board()->count(n,*it);
		if (*it == *south_annotations) return Piece(south_annotations[r]);
		else if(*it == *north_annotations) return Piece(north_annotations[r]);
		else if(*it == *open_annotations) return Piece(open_annotations[r]);
		else throw runtime_error_ex("Invalid char %d",*it);
	}
};
Exemple #6
0
	string string_from_file(const char * fileName) {
		ifstream file;
		file.open(fileName);
		if (!file)
			throw file_not_found(fileName);
		// determine file size
		file.seekg(0,ios::end);
		auto length = file.tellg();
		if (length == 0)
			throw runtime_error_ex("The file ('%s') is empty", fileName);
		// read the whole file the result
		file.seekg(0,ios::beg);
		const size_t bufSize = (unsigned int) length + 1;
		string result;
		result.reserve(bufSize);
		char c;
		file.get(c);
		do {
			result += c;
			file.get(c);
		} while (file.good());
		return result;
	}
Exemple #7
0
	void create_dir(const string& path) {
			if (mkdir(path.c_str()) != 0) {
				if (errno != EEXIST)
					throw runtime_error_ex("could not create directory:'%s'",path.c_str());
			}
	}