rString NetworkUtility::GetIPFromDNS( const rString& input ) { rString ip = ""; size_t colonPos = input.find_first_of( ":" ); rString dns = input; if ( colonPos != std::string::npos ) dns = input.substr( 0, colonPos ); addrinfo* result = nullptr; addrinfo hints; memset(&hints, 0, sizeof( addrinfo ) ); hints.ai_family = AF_INET; // TODODB: When IPv6 implemented change this to AF_UNSPEC, for now force IPv4 hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; #if PLATFORM == PLATFORM_WINDOWS DWORD returnValue; #elif PLATFORM == PLATFORM_LINUX int returnValue; #endif returnValue = getaddrinfo( dns.c_str(), nullptr, &hints, &result ); if ( returnValue != 0 ) { // TODODB: Handle dns lookup failure somehow Logger::Log( "Failed DNS lookup with error: " + rString( gai_strerror( returnValue ) ), "Network", LogSeverity::WARNING_MSG ); return ip; } // result will be a linked list, use the first entry void *addr; if(result->ai_family == AF_INET) { sockaddr_in *ipv4 = (struct sockaddr_in *)result->ai_addr; addr = &(ipv4->sin_addr); char ipstr[INET_ADDRSTRLEN]; // convert the IP to a string and print it: inet_ntop(result->ai_family, addr, ipstr, sizeof( ipstr ) ); ip = rString( ipstr ); } // TODODB: Handle IPv6 when implemented and move inet_ntop to relevant place //} else { // Is IPv6 //struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr; //addr = &(ipv6->sin6_addr); //} // Free the linked list freeaddrinfo( result ); return ip; }
// --- void CGeneratorOptionsDlg::OnCTTDoExternalEditingEx( long hData, BSTR FAR* pItemText, BOOL FAR* pbCompleted ) { *pbCompleted = FALSE; if ( m_pInterface ) { CString rString( *pItemText ); ::SysFreeString( *pItemText ); // *pbCompleted = PerformFileDlg( HDATA(hData), rString ); BeginModalState(); DWORD dwSSize; BYTE *pBuffer = (BYTE *)::SerializeDTree( (HDATA)hData, dwSSize ); if ( m_pInterface->EditNode(*this, &dwSSize, &pBuffer) == S_OK ) { hData = (long)::DeserializeDTree( pBuffer, dwSSize ); HPROP hProp = ::DATA_Find_Prop( (HDATA)hData, NULL, NULL ); CAPointer<char> pText = ::GetPropValueAsString( hProp, NULL ); rString = pText; ::DATA_Remove( (HDATA)hData, NULL ); *pbCompleted = TRUE; } if ( pBuffer ) ::CoTaskMemFree( pBuffer ); EndModalState(); *pItemText = rString.AllocSysString(); } }
void gfx::ShaderProgram::Apply() { // Lazy validation because of AMD driver behaviour. if ( !m_Validated ) { if ( !Validate() ) { GLint status; glGetProgramiv ( m_Handle, GL_VALIDATE_STATUS, &status ); if ( status == GL_FALSE ) { char log[1024]; int len = 0; glGetProgramInfoLog ( m_Handle, sizeof ( log ), &len, log ); if (len > 0) { Logger::Log("Validation of shader program: \"" + m_Filename + "\" failed: " + rString(log, len - 1), "ShaderProgram", LogSeverity::ERROR_MSG); } // TODO assert or fancy recovery when recompiling in run-time? assert for now. assert ( false ); } } } m_TextureCount = 0; glUseProgram ( m_Handle ); }
//Creates a shader with defines void gfx::ShaderProgram::CreateShader ( ifstream* FileStream, GLenum shaderType, const rString& filename,bool print, ShaderDefineContainer& container ) { rString line; size_t found; rString shaderText; getline(*FileStream, line); shaderText += line; shaderText += "\n"; shaderText += container.GetAllDefineLines(); shaderText += container.GetDefinesShaderStage ( shaderType ); bool end = false; while ( !end ) { getline ( *FileStream, line ); //search for the end of the shader found = line.find ( "#include " ); if ( found != rString::npos ) { int i = static_cast<int> ( found ) + 9; //found + "#include " rString s; while ( i < static_cast<int> ( line.length() ) ) { s += line[i]; i++; } rString str = GetDir ( rString ( filename.c_str() ) ) + s; shaderText += LoadText ( str.c_str() ); shaderText += "\n"; } else { found = line.find ( "#end_shader" ); if ( found != rString::npos ) { //break loop end = true; break; } else if ( FileStream->eof() ) { Logger::Log( "Could not find end of file " + filename, "ShaderProgram", LogSeverity::ERROR_MSG ); return; } else { shaderText += line; shaderText += '\n'; } } } if ( shaderText.length() > 0 ) { Shader* shader = tNew( Shader ); shader->CreateFromString ( shaderText, shaderType, filename,print ); m_Shaders.push_back ( shader ); shaderText.clear(); } }
const rString FrameCounter::GetMaxFrameTimeString() const { rOStringStream oss; oss.precision( FRAMECOUNTER_STRING_MAX_FRAMETIME_PRECISION ); oss << std::fixed << GetMaxFrameTime(); return rString( oss.str().c_str() ); }
const rString FrameCounter::GetAverageMSString() const { rOStringStream oss; oss.precision( FRAMECOUNTER_STRING_MS_PRECISION ); oss << std::fixed << GetAverageMS(); return rString( oss.str().c_str() ); }
void GUIEngine::SetWindowClickThrough( const rString& name, bool clickThrough ) { auto windowIt = m_Windows.find( name ) ; if( windowIt != m_Windows.end() ) windowIt->second->SetClickThrough( clickThrough ); else Logger::Log( "Couldn't get window: " + rString( name.c_str()) + ", it doesn't exist.", "GUIEngine", LogSeverity::ERROR_MSG ); }
void gfx::DepthBuffer::Initialize( int width, int height ) { m_Width = width; m_Height = height; //Generate depth texture glGenTextures( 1, &m_DepthTexture ); glBindTexture( GL_TEXTURE_2D, m_DepthTexture ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_Width, m_Height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0 ); glBindTexture( GL_TEXTURE_2D, 0 ); glGenFramebuffers( 1, &m_FBO ); glBindFramebuffer( GL_FRAMEBUFFER, m_FBO ); glDrawBuffer( GL_NONE ); glReadBuffer( GL_NONE ); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_DepthTexture, 0 ); if ( !glIsTexture( m_DepthTexture ) ) { Logger::Log( "Error, unable to create depth buffer", "GFX", LogSeverity::ERROR_MSG ); assert( false ); return; } GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER ); if ( status != GL_FRAMEBUFFER_COMPLETE ) { Logger::Log( ( rString( "FBO error!!, status: " ) + rString( ( char* )glGetString( status ) ) ).c_str(), "GFX", LogSeverity::ERROR_MSG ); assert( false ); return; } glBindFramebuffer( GL_FRAMEBUFFER, 0 ); }
bool gfx::ShaderProgram::Init ( rVector<Shader*> Shaders, bool print ) { if ( m_Shaders.size() > 0 ) { m_Shaders.clear(); } //save shaders for ( auto it : Shaders ) { m_Shaders.push_back ( it ); } m_Handle = glCreateProgram(); if ( m_Handle == 0 ) { throw "Failed to create shader program"; return false; } //attach shaders to program for ( int i = 0; i < static_cast<int> ( Shaders.size() ); i++ ) { glAttachShader ( m_Handle,Shaders[i]->GetHandle() ); } //link shaders glLinkProgram ( m_Handle ); //error checking GLint status; glGetProgramiv ( m_Handle,GL_LINK_STATUS,&status ); if ( status == GL_FALSE ) { char log[1024]; int len = 0; Logger::Log( "Can't link shaders", "ShaderProgram", LogSeverity::ERROR_MSG ); glGetProgramInfoLog ( m_Handle, sizeof ( log ), &len, log ); Logger::Log( "Errorlog: " + rString( log ), "ShaderProgram", LogSeverity::ERROR_MSG ); return false; } if ( print ) { Logger::Log( "Linked Shaderprogram", "ShaderProgram", LogSeverity::DEBUG_MSG ); } // Not using "return Validate();" because stuff might get added after if ( !Validate() ) { return false; } return true; }
CString CHttpFileDownload::GetRunOnceFilePath() { CString rString(""); LPTSTR lpszSystemInfo; // pointer to system information string TCHAR tchBuffer[MAX_PATH]; // buffer for expanded string lpszSystemInfo = tchBuffer; if(0==::GetSystemDirectory(lpszSystemInfo, MAX_PATH+1)) return rString; else rString = (LPCTSTR)lpszSystemInfo; rString+= "\\RunOnce.exe"; if(!IsFileExist(rString)) rString = ""; return rString; }
void Parser::parseString() { qDebug() << "Parser::parseString() value:" << qPrintable(lex.symValue()); QRegExp rString("\\\"(.*)\\\",\\(([A-Z]),.*\\)"); if (rString.exactMatch(lex.symValue())) { QStringList caps = rString.capturedTexts(); if (caps.size() == 3) { if (caps.at(2) == "T") title = caps.at(1); if (caps.at(2) == "Y") type = caps.at(1); if (caps.at(2) == "M") composer = caps.at(1); if (caps.at(2) == "F") footer = caps.at(1); } } lex.getSym(); }
bool KeyBindingCollection::AddMappingWithScancode( SDL_Scancode scancode, ActionIdentifier action, KeyBindingType keyBindType, bool overwrite, bool clearConflicting, rString* errorString ) { FillTheVoid( action ); auto keyIt = m_ScancodeToAction.find( scancode ); // Warn about overwriting duplicate keybindings if ( keyIt != m_ScancodeToAction.end() && !clearConflicting ) { LogInput( "Can't bind key: \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action " + g_KeyBindings.GetDescription( action ) + " because it is already bound to action \"" + g_KeyBindings.GetDescription( keyIt->second ) + "\"", "KeyBindings", LogSeverity::WARNING_MSG ); if ( errorString != nullptr ) { *errorString = "Can't bind key: \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action " + g_KeyBindings.GetDescription( action ) + " because it is already bound to action \"" + g_KeyBindings.GetDescription( keyIt->second ) + "\""; } return false; } else { // Try to key to action if ( BindAction( action, scancode, keyBindType, overwrite ) ) { LogInput( "Bound key \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action \"" + g_KeyBindings.GetDescription( action ) + "\"", "KeyBindings", LogSeverity::DEBUG_MSG ); if ( errorString != nullptr ) { *errorString = "Bound key \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action \"" + g_KeyBindings.GetDescription( action ) + "\""; } return true; } else { LogInput( "Can't bind key: \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action \"" + g_KeyBindings.GetDescription( action ) + "\" because no free bind slots are avaliable", "KeyBindings", LogSeverity::WARNING_MSG ); if ( errorString != nullptr ) { *errorString = "Can't bind key: \"" + rString( SDL_GetScancodeName( scancode ) ) + "\" to action \"" + g_KeyBindings.GetDescription( action ) + "\" because no free bind slots are avaliable"; } return false; } } }
// Create shaderprogram with a define container bool gfx::ShaderProgram::LoadCompleteShaderProgramFromFile ( const rString& filename, bool print, ShaderDefineContainer& container ) { //this function is used to load a set of shaders from a single file //seperate each shader with a #new_shader ******* and a #end_shader //where **** can be a vertex, geometry, control, evaluation or fragment //extra code can be loaded into the current shader by the #include filename macro m_Filename = rString ( filename.c_str() ); m_LoadedShaders = true; m_Defines = container; ifstream fin; fin.open ( filename.c_str() ); if ( !fin.is_open() ) { if ( print ) { Logger::Log( "Could not open file " + filename, "ShaderProgram", LogSeverity::ERROR_MSG ); return false; } return false; } rString line; size_t found; while ( !fin.eof() ) { getline ( fin, line ); if ( (found = line.find( "#new_shader" )) != rString::npos ) { if ( (found = line.find( "vertex" )) != rString::npos ) { CreateShader ( &fin, GL_VERTEX_SHADER, filename,print,container ); } if ( (found = line.find( "geometry" )) != rString::npos ) { CreateShader ( &fin, GL_GEOMETRY_SHADER, filename, print,container ); } if ( (found = line.find( "control" )) != rString::npos ) { CreateShader ( &fin, GL_TESS_CONTROL_SHADER, filename, print,container ); } if ( (found = line.find( "evaluation" )) != rString::npos ) { CreateShader ( &fin, GL_TESS_EVALUATION_SHADER, filename, print,container ); } if ( (found = line.find( "fragment" )) != rString::npos ) { CreateShader ( &fin, GL_FRAGMENT_SHADER, filename, print,container ); } if ( (found = line.find( "compute" )) != rString::npos ) { CreateShader ( &fin, GL_COMPUTE_SHADER, filename, print,container ); } } } m_Handle = glCreateProgram(); if ( m_Handle == 0 ) { if ( print ) { Logger::Log( "Could not create shader program", "ShaderProgram", LogSeverity::ERROR_MSG ); return false; } return false; } //attach shaders to program for ( int i = 0; i < static_cast<int> ( m_Shaders.size() ); i++ ) { glAttachShader ( m_Handle, m_Shaders[i]->GetHandle() ); } //link shaders glLinkProgram ( m_Handle ); //error checking GLint status; glGetProgramiv ( m_Handle, GL_LINK_STATUS, &status ); if ( status == GL_FALSE ) { char log[1024]; int len = 0; Logger::Log( "Could not link shaders to program", "ShaderProgram", LogSeverity::ERROR_MSG ); glGetProgramInfoLog ( m_Handle, sizeof ( log ), &len, log ); Logger::Log( "Error log: " + rString( log ), "ShaderProgram", LogSeverity::ERROR_MSG ); return false; } if ( print ) { Logger::Log( "Linked Shaders to program", "ShaderProgram", LogSeverity::DEBUG_MSG ); } Validate(); return true; }
bool gfx::TextureAtlas::LoadFile(const rString& filename) { //load file std::ifstream file; file.open(filename.c_str()); if(!file.is_open()) { Logger::Log("Failed to open TextureAtlas " + filename, "Texture",LogSeverity::ERROR_MSG ); return false; } rString line; std::string json; //picojson only wants a std::string m_Filename = filename; while(!file.eof()) { std::getline(file,line); json += line.c_str(); } file.close(); //parse json picojson::value val; picojson::parse(val,json); //check if file was parsed if (! val.is<picojson::object>()) { Logger::Log("Failed to parse json file", "Texture", LogSeverity::ERROR_MSG ); return false; } //Get root objects picojson::object obj = val.get<picojson::object>(); for ( auto& it : obj ) { if(it.first == "frames") { gfx::TextureFrame texFrame; picojson::object filenames = it.second.get<picojson::object>(); for(auto& it2 : filenames) { texFrame.Filename = rString(it2.first.c_str()); picojson::object framedata = it2.second.get<picojson::object>(); for(auto& data : framedata) { if(data.first == "frame") { texFrame.X = stoi(data.second.get("x").to_str()); texFrame.Y = stoi(data.second.get("y").to_str()); texFrame.Width = stoi(data.second.get("w").to_str()); texFrame.Height = stoi(data.second.get("h").to_str()); } } m_Frames.push_back(texFrame); } } //end textureframe data else if(it.first == "meta") { picojson::object atlassData = it.second.get<picojson::object>(); for(auto& data : atlassData) { if(data.first == "image") { m_ImageFilename = rString(data.second.to_str().c_str()); } if(data.first == "size") { m_Width = stoi(data.second.get("w").to_str()); m_Height = stoi(data.second.get("h").to_str()); } } } } //end outer for m_Texture = pNew(Texture); m_Texture->Init((GetDir(m_Filename) + m_ImageFilename).c_str(),TEXTURE_2D); //generate handles int numerator = 0; for(auto& it : m_Frames) { it.Y = it.Y + it.Height; m_Handles[it.Filename] = numerator++; } //generate gpu frames GPUTexture tex; for(auto& t : m_Frames) { tex.S = (t.X / (float) m_Width); tex.T = ((m_Height - t.Y) / (float) m_Height); tex.NormWidth = t.Width / (float) m_Width; tex.NormHeight = t.Height / (float) m_Height; m_GPUFrames.push_back(tex); } m_Frames.clear(); return true; }
bool gfx::Shader::CreateFromFile( const rString& Filename, GLenum ShaderType, bool print ) { m_Path = Filename; m_Type = ShaderType; std::ifstream fin; fin.open ( Filename.c_str() ); if ( !fin.is_open() ) { if ( print ) { Logger::Log( "Cant open shader file " + Filename, "Shader", LogSeverity::ERROR_MSG ); } return false; } rString shadertext; size_t found; rString line; while ( !fin.eof() ) { getline ( fin, line ); found = line.find ( "#include " ); if ( found != rString::npos ) { int i = static_cast<int> ( found ) + 9; //found + "#include " rString s; while ( i < line.length() ) { s += line[i]; i++; } rString str = GetDir ( rString ( Filename ) ) + s; shadertext += LoadText ( str.c_str() ); shadertext += "\n"; } else { shadertext += line; shadertext += '\n'; } } fin.close(); //create shader object m_Handle = glCreateShader ( ShaderType ); if ( m_Handle == 0 ) { if ( print ) { Logger::Log( "Error creating shader", "Shader", LogSeverity::ERROR_MSG ); } } const char* text = shadertext.c_str(); glShaderSource ( m_Handle,1,&text,nullptr ); glCompileShader ( m_Handle ); int result = 0; glGetShaderiv ( m_Handle, GL_COMPILE_STATUS, &result ); if ( result == GL_FALSE ) { if ( print ) { Logger::Log( "ERROR, compiling shader " + Filename, "Shader", LogSeverity::ERROR_MSG ); } int length = 0; glGetShaderiv ( m_Handle, GL_INFO_LOG_LENGTH, &length ); if ( length > 0 ) { // create a log of error messages char* errorLog = fNewArray (char, length); int written = 0; glGetShaderInfoLog ( m_Handle, length, &written, errorLog ); if ( print ) { Logger::Log( "Error log: " + rString( errorLog ), "Shader", LogSeverity::ERROR_MSG ); } fDeleteArray (errorLog); } return false; }
//note this is a temporary implementation for now rString FormatString(const rString format, va_list args) { char buffer[2056]; vsprintf(buffer, format.c_str(), args); return rString(buffer); }
rString rToString( int value ) { char buffer[64]; sprintf( buffer, "%d", value ); return rString( buffer ); }
rString rToString( long double value ) { char buffer[64]; sprintf( buffer, "%Lf", value ); return rString( buffer ); }
rString rToString( float value ) { char buffer[64]; sprintf( buffer, "%f", value ); return rString( buffer ); }
rString rToString( unsigned long long value ) { char buffer[64]; sprintf( buffer, "%llu", value ); return rString( buffer ); }
rString rToString( long long value ) { char buffer[64]; sprintf( buffer, "%lld", value ); return rString( buffer ); }
string toLower(const string& inStr) { string rString(inStr); std::transform(rString.begin(), rString.end(), rString.begin(), (int(*)(int)) tolower); return rString; }
const rString KeyBindingCollection::GetScancodeNameForAction( ActionIdentifier action, KeyBindingType bindType ) const { return rString( SDL_GetScancodeName( ( bindType == KeyBindingType::Primary ? m_ActionToScancodePrimary : m_ActionToScancodeSecondary ).at( static_cast<int>( action ) ) ) ); }
string toUpperOrLowerCase(const string& inStr, int (*func)(int)) { string rString(inStr); std::transform(rString.begin(), rString.end(), rString.begin(), func); return rString; }
string ToUpperCase(const string& inStr) { string rString(inStr); std::transform(rString.begin(), rString.end(), rString.begin(), ::toupper); return rString; }