void D3DShaderObjectProvider::create(ShaderType new_type, const std::string &source) { shader_source = source; bytecode = DataBuffer(); compile_status = false; type = new_type; }
void SoundProvider_Vorbis_Impl::load(IODevice &input) { int size = input.get_size(); buffer = DataBuffer(size); int bytes_read = input.read(buffer.get_data(), buffer.get_size()); buffer.set_size(bytes_read); }
void D3DShaderObjectProvider::create( ShaderType new_type, const void *source, int source_size ) { bytecode = DataBuffer(source, source_size); compile_status = false; type = new_type; }
void ZipFileHeader::load(IODevice &input) { signature = input.read_int32(); if (signature != 0x02014b50) { throw Exception("Incorrect File Header signature"); } version_made_by = input.read_int16(); version_needed_to_extract = input.read_int16(); general_purpose_bit_flag = input.read_int16(); compression_method = input.read_int16(); last_mod_file_time = input.read_int16(); last_mod_file_date = input.read_int16(); crc32 = input.read_uint32(); compressed_size = input.read_int32(); uncompressed_size = input.read_int32(); file_name_length = input.read_int16(); extra_field_length = input.read_int16(); file_comment_length = input.read_int16(); disk_number_start = input.read_int16(); internal_file_attributes = input.read_int16(); external_file_attributes = input.read_int32(); relative_offset_of_local_header = input.read_int32(); filename.resize(file_name_length); auto str1 = new char[file_name_length]; auto str2 = new char[extra_field_length]; auto str3 = new char[file_comment_length]; try { input.read(str1, file_name_length); input.read(str2, extra_field_length); input.read(str3, file_comment_length); if (general_purpose_bit_flag & ZIP_USE_UTF8) { filename = StringHelp::utf8_to_text(std::string(str1, file_name_length)); file_comment = StringHelp::utf8_to_text(std::string(str3, file_comment_length)); } else { filename = StringHelp::cp437_to_text(std::string(str1, file_name_length)); file_comment = StringHelp::cp437_to_text(std::string(str3, file_comment_length)); } extra_field = DataBuffer(str2, extra_field_length); delete[] str1; delete[] str2; delete[] str3; } catch (...) { delete[] str1; delete[] str2; delete[] str3; throw; } }
SoundOutput_MacOSX::SoundOutput_MacOSX(int frequency, int latency) : SoundOutput_Impl(frequency, latency), frequency(frequency), latency(latency), fragment_size(0), next_fragment(0), read_cursor(0), fragments_available(0) { fragment_size = frequency * latency / fragment_buffer_count / 1000; fragment_size = (fragment_size + 3) & ~3; // Force to be a multiple of 4 fragments_available = fragment_buffer_count; fragment_data = DataBuffer(fragment_size * sizeof(short) * 2 * fragment_buffer_count); audio_format = {0}; start_mixer_thread(); }
void D3DShaderObjectProvider::compile() { shader.clear(); info_log.clear(); if (!bytecode.get_size()) { load_compiler_dll(); std::string entry_point = "main"; std::string shader_model = get_shader_model(); ComPtr<ID3DBlob> blob; ComPtr<ID3DBlob> log; HRESULT result = d3dcompile( shader_source.data(), shader_source.length(), 0, 0, 0, entry_point.c_str(), shader_model.c_str(), D3D10_SHADER_ENABLE_STRICTNESS|D3D10_SHADER_OPTIMIZATION_LEVEL3, 0, blob.output_variable(), log.output_variable()); if (log) info_log = std::string(reinterpret_cast<char*>(log->GetBufferPointer()), log->GetBufferSize()); if (SUCCEEDED(result)) { bytecode = DataBuffer(blob->GetBufferPointer(), blob->GetBufferSize()); } else return; } try { create_shader(); find_locations(); compile_status = true; } catch (Exception &e) { if (!info_log.empty()) info_log += "\r\n"; info_log += e.message; } }
AttrData<DataTypeId> getAttr() { AttrIndexType index = AttrData<DataTypeId>::attr_index; static_assert(index!=AttrIndexType(-1)); AttrIndexType innerIndex = getInnerIndex(index); if(index == AttrIndexType(-1)) { auto guard = boost::make_lock_guard(m_mutex); m_databuffer.push_back(DataBuffer()); index = m_databuffer.size()-1; } return AttrData<DataTypeId>(index); }
void TargaLoader::read_image_data() { image_data = DataBuffer(bytes_per_pixel_entry * image_width * image_height); if (image_type == 9 || image_type == 10 || image_type == 11) // RLE compressed { DataBuffer rle_data(file.get_size() - file.get_position()); file.read(rle_data.get_data(), rle_data.get_size()); unsigned char *input = reinterpret_cast<unsigned char*>(rle_data.get_data()); unsigned char *output = reinterpret_cast<unsigned char*>(image_data.get_data()); int pixels_left = image_width * image_height; int input_available = rle_data.get_size(); while (pixels_left > 0 && input_available > 0) { int code = *input; int count = (code & 0x7f) + 1; bool rle_packet = (code & 0x80) != 0; input++; input_available--; if (rle_packet) { if (bytes_per_pixel_entry > input_available && pixels_left >= count) // Check for buffer overruns break; for (int i = 0; i < count; i++) memcpy(output + i * bytes_per_pixel_entry, input, bytes_per_pixel_entry); input += bytes_per_pixel_entry; } else { if (count * bytes_per_pixel_entry >= input_available && pixels_left >= count) // Check for buffer overruns break; memcpy(output, input, count * bytes_per_pixel_entry); input += count * bytes_per_pixel_entry; } output += bytes_per_pixel_entry * count; pixels_left -= count; } } else { file.read(image_data.get_data(), image_data.get_size()); } }
void Parser::parsePart(RequestImpl *req, DataBuffer part) { DataBuffer headers, content; DataBuffer name, filename, type; if (!part.split(EMPTY_LINE_RNRN_STRING, headers, content)) { part.split(EMPTY_LINE_NN_STRING, headers, content); } while (!headers.empty()) { DataBuffer line; DataBuffer tail = headers; bool lineFound = false; while (!tail.empty()) { DataBuffer subline, subtail; if (!tail.split(RETURN_RN_STRING, subline, subtail)) { tail.split('\n', subline, subtail); } if (subline.startsWith(ONE_SPACE_STRING) || subline.startsWith(ONE_TAB_STRING)) { line = DataBuffer(part, line.beginIndex(), subline.endIndex()); } else { if (lineFound) { break; } line = subline; } tail = subtail; lineFound = true; } parseLine(line, name, filename, type); headers = tail; } if (name.empty()) { return; } std::string name_str; name.toString(name_str); if (!filename.empty()) { req->files_.insert(std::make_pair(name_str, File(filename, type, content))); } else { std::string arg; content.toString(arg); req->args_.push_back(std::make_pair(name_str, arg)); } }
DataBuffer FileLoader::Load(const std::string& path) { FILE* file = nullptr; fopen_s(&file, path.c_str(), "r"); if(!file) { LOG_ERROR("Failed to open file: " + path); return DataBuffer(); } fseek(file, 0, SEEK_END); auto len = ftell(file); fseek(file, 0, SEEK_SET); DataBuffer buffer(len+1); fread(buffer.GetWriteableData(), len, 1, file); fclose(file); static_cast<char*>(buffer.GetWriteableData())[len] = 0; return buffer; }
void TargaLoader::read_image_id() { image_id = DataBuffer(id_length); file.read(image_id.get_data(), image_id.get_size()); }
SoundOutput_Win32::SoundOutput_Win32(int init_mixing_frequency, int init_mixing_latency) : SoundOutput_Impl(init_mixing_frequency, init_mixing_latency), audio_buffer_ready_event(INVALID_HANDLE_VALUE), is_playing(false), fragment_size(0), wait_timeout(mixing_latency * 2), write_pos(0) { try { ComPtr<IMMDeviceEnumerator> device_enumerator; HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator), 0, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)device_enumerator.output_variable()); if (FAILED(result)) throw Exception("Unable to create IMMDeviceEnumerator instance"); result = device_enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, mmdevice.output_variable()); if (FAILED(result)) throw Exception("IDeviceEnumerator.GetDefaultAudioEndpoint failed"); result = mmdevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, 0, (void**)audio_client.output_variable()); if (FAILED(result)) throw Exception("IMMDevice.Activate failed"); WAVEFORMATEXTENSIBLE wave_format; wave_format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; wave_format.Format.nChannels = 2; wave_format.Format.nBlockAlign = 2 * sizeof(float); wave_format.Format.wBitsPerSample = 8 * sizeof(float); wave_format.Format.cbSize = 22; wave_format.Samples.wValidBitsPerSample = wave_format.Format.wBitsPerSample; wave_format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; wave_format.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; wave_format.Format.nSamplesPerSec = mixing_frequency; wave_format.Format.nAvgBytesPerSec = wave_format.Format.nSamplesPerSec * wave_format.Format.nBlockAlign; WAVEFORMATEX *closest_match = 0; result = audio_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*)&wave_format, &closest_match); if (FAILED(result)) throw Exception("IAudioClient.IsFormatSupported failed"); // We could not get the exact format we wanted. Try to use the frequency that the closest matching format is using: if (result == S_FALSE) { mixing_frequency = closest_match->nSamplesPerSec; wait_timeout = mixing_latency * 2; wave_format.Format.nSamplesPerSec = mixing_frequency; wave_format.Format.nAvgBytesPerSec = wave_format.Format.nSamplesPerSec * wave_format.Format.nBlockAlign; CoTaskMemFree(closest_match); closest_match = 0; } /* // For debugging what mixing format Windows is using. WAVEFORMATEX *device_format = 0; // Note: this points at a WAVEFORMATEXTENSIBLE if cbSize is 22 result = audio_client->GetMixFormat(&device_format); if (SUCCEEDED(result)) { CoTaskMemFree(device_format); device_format = 0; } */ result = audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, mixing_latency * (REFERENCE_TIME)1000, 0, (WAVEFORMATEX*)&wave_format, 0); if (FAILED(result)) throw Exception("IAudioClient.Initialize failed"); result = audio_client->GetService(__uuidof(IAudioRenderClient), (void**)audio_render_client.output_variable()); if (FAILED(result)) throw Exception("IAudioClient.GetService(IAudioRenderClient) failed"); audio_buffer_ready_event = CreateEvent(0, TRUE, TRUE, 0); if (audio_buffer_ready_event == INVALID_HANDLE_VALUE) throw Exception("CreateEvent failed"); result = audio_client->SetEventHandle(audio_buffer_ready_event); if (FAILED(result)) throw Exception("IAudioClient.SetEventHandle failed"); result = audio_client->GetBufferSize(&fragment_size); if (FAILED(result)) throw Exception("IAudioClient.GetBufferSize failed"); next_fragment = DataBuffer(sizeof(float) * 2 * fragment_size); start_mixer_thread(); } catch (...) { if (audio_buffer_ready_event != INVALID_HANDLE_VALUE) CloseHandle(audio_buffer_ready_event); throw; } }
void TargaLoader::read_color_map() { colormap_data = DataBuffer(bytes_per_colormap_entry * colormap_length); file.read(colormap_data.get_data(), colormap_data.get_size()); }
void PNGLoader::read_chunks() { file.set_big_endian_mode(); std::map<std::string, DataBuffer> chunks; std::vector<DataBuffer> idat_chunks; uint64_t total_idat_size = 0; while (true) { unsigned int length = file.read_uint32(); char name[5]; name[4] = 0; file.read(name, 4); DataBuffer data(length); file.read(data.get_data(), data.get_size()); unsigned int crc32 = file.read_uint32(); unsigned int compare_crc32 = PNGCRC32::crc(name, data.get_data(), data.get_size()); if (crc32 != compare_crc32) throw Exception("CRC32 error"); if (name == std::string("IDAT")) // Concatenate all IDAT chunks to one big { total_idat_size += length; idat_chunks.push_back(data); } else { chunks[name] = data; if (name == std::string("IEND")) // image trailer, which is the last chunk in a PNG datastream. break; } } if (total_idat_size >= (1 << 31)) throw Exception("PNG image file too big!"); idat = DataBuffer((int)total_idat_size); int idat_pos = 0; for (auto & idat_chunk : idat_chunks) { memcpy(idat.get_data() + idat_pos, idat_chunk.get_data(), idat_chunk.get_size()); idat_pos += idat_chunk.get_size(); } ihdr = chunks["IHDR"]; plte = chunks["PLTE"]; trns = chunks["tRNS"]; chrm = chunks["cHRM"]; gama = chunks["gAMA"]; iccp = chunks["iCCP"]; sbit = chunks["sBIT"]; srgb = chunks["sRGB"]; if (ihdr.is_null() || idat_chunks.empty() || ihdr.get_size() != 13) // Always required chunks throw Exception("Invalid PNG image file"); }
void Server::ProcessPacket(ENetPacket* packet, ENetPeer* peer) { //TOOD Need to change it to a more effienct method like in the client. //TODO Maybe move the server related logic to handle here before assign the packets to the client? unsigned char header = packet->data[0]; Client* client = (Client*)peer->data; DataBuffer dataBuffer = DataBuffer(((char*)packet->data + 1), packet->dataLength - 1); switch (header) { case PACKET_HAND_SHAKE: { int protocolVersion = 0; memcpy(&protocolVersion, &packet->data[1], sizeof(int)); client->QueueIncomingPacket(std::shared_ptr<Packet>(new PacketHandshake(protocolVersion, (short)client->GetPlayerID()))); break; } case PACKET_PING: { client->SendPacket(std::shared_ptr<Packet>(new PacketPing())); break; } case PACKET_PLAYER_POSITION: { short playerID = 0; memcpy(&playerID, &packet->data[1], sizeof(short)); float posX = 0; memcpy(&posX, &packet->data[3], sizeof(float)); float posY = 0; memcpy(&posY, &packet->data[7], sizeof(float)); float velX = 0; memcpy(&velX, &packet->data[11], sizeof(float)); float velY = 0; memcpy(&velY, &packet->data[15], sizeof(float)); //Logger::Print("%d, %f, %f", playerID, posX, posY); client->QueueIncomingPacket(std::make_shared<PacketPlayerPosition>(playerID, posX, posY, velX, velY)); break; } case PACKET_CREATE_BLOCK: { char blockID = dataBuffer.ReadChar(); short chunkPos = dataBuffer.ReadShort(); //TODO Use that when the engine will run on chunks short posX = dataBuffer.ReadShort(); short posY = dataBuffer.ReadShort(); client->QueueIncomingPacket(std::make_shared<PacketCreateBlock>(blockID, chunkPos, posX, posY)); break; } case PACKET_DESTROY_BLOCK: { short chunkPos = dataBuffer.ReadShort(); //TODO Use that when the engine will run on chunks short posX = dataBuffer.ReadShort(); short posY = dataBuffer.ReadShort(); client->QueueIncomingPacket(std::make_shared<PacketDestroyBlock>(chunkPos, posX, posY)); break; } } }
/** * Creates the copy of the sub-buffer from the given offset up to given number of bytes. * * @param offset The offset to copy from. * @param amount The number of bytes to copy. * * @return Sub-buffer. */ DataBuffer DataBuffer::getSubBuffer(std::size_t offset, std::size_t amount) const { return DataBuffer(*this, offset, amount); }
REGINFO("MuxControl(5)", MuxControl(5), 32), REGINFO("MuxPrescaler(5)", MuxPrescaler(5), 32), REGINFO("MuxControl(6)", MuxControl(6), 32), REGINFO("MuxPrescaler(6)", MuxPrescaler(6), 32), REGINFO("MuxControl(7)", MuxControl(7), 32), REGINFO("MuxPrescaler(7)", MuxPrescaler(7), 32), REGINFO("FrontOutMap(0)", FrontOutMap(0), 16), REGINFO("FrontInMap(0)", FrontInMap(0), 32), REGINFO("FrontInMap(1)", FrontInMap(1), 32), REGINFO("UnivInMap(0)", UnivInMap(0), 32), REGINFO("UnivInMap(1)", UnivInMap(1), 32), REGINFO("RearInMap(12)", RearInMap(12), 32), REGINFO("RearInMap(13)", RearInMap(13), 32), REGINFO("RearInMap(14)", RearInMap(14), 32), REGINFO("RearInMap(15)", RearInMap(15), 32), REGINFO("DataBuffer(0)", DataBuffer(0), 8), REGINFO("DataBuffer(1)", DataBuffer(1), 8), REGINFO("DataBuffer(2)", DataBuffer(2), 8), REGINFO("DataBuffer(3)", DataBuffer(3), 8), REGINFO("DataBuffer(4)", DataBuffer(4), 8), REGINFO("DataBuffer(5)", DataBuffer(5), 8), REGINFO("SeqRamTS(0,0)", SeqRamTS(0,0), 32), REGINFO("SeqRamTS(0,1)", SeqRamTS(0,1), 32), REGINFO("SeqRamTS(0,2)", SeqRamTS(0,2), 32), REGINFO("SeqRamTS(0,3)", SeqRamTS(0,3), 32), REGINFO("SeqRamTS(0,4)", SeqRamTS(0,4), 32), REGINFO("SeqRamEvent(0,0)", SeqRamEvent(0,0), 8), REGINFO("SeqRamEvent(0,1)", SeqRamEvent(0,1), 8), REGINFO("SeqRamEvent(0,2)", SeqRamEvent(0,2), 8), REGINFO("SeqRamEvent(0,3)", SeqRamEvent(0,3), 8), REGINFO("SeqRamEvent(0,4)", SeqRamEvent(0,4), 8),