Ejemplo n.º 1
0
		GLProgram *GLProgramManager::CreateProgram(const std::string &name) {
			SPADES_MARK_FUNCTION();

			SPLog("Loading GLSL program '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			std::vector<std::string> lines = SplitIntoLines(text);

			GLProgram *p = new GLProgram(device, name);

			for (size_t i = 0; i < lines.size(); i++) {
				std::string text = TrimSpaces(lines[i]);
				if (text.empty())
					break;

				if (text == "*shadow*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-lite*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-variance*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*dlight*") {
					std::vector<GLShader *> shaders = GLDynamicLightShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadowmap*") {
					std::vector<GLShader *> shaders = GLShadowMapShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text[0] == '*') {
					SPRaise("Unknown special shader: %s", text.c_str());
				} else if (text[0] == '#') {
					continue;
				}
				GLShader *s = CreateShader(text);

				p->Attach(s);
			}

			Stopwatch sw;
			p->Link();
			SPLog("Successfully linked GLSL program '%s' in %.3fms", name.c_str(),
			      sw.GetTime() * 1000.);
			// p->Validate();
			return p;
		}
Ejemplo n.º 2
0
CCharBufferText::CCharBufferText (CCharBuffer &data) : data (data), undo_manager (NULL)
{
    SplitIntoLines (0, data.GetSize (), line_start, line_length);

    lines_count = line_start.size ();
    ASSERT (lines_count > 0);

    data.SetListener (this);
}
	std::vector<std::pair<std::string, std::string>> ImportFltkPreference() {
		std::vector<std::pair<std::string, std::string>> ret;
		
		auto path = GetFltkPreferencePath();
		SPLog("Checking for legacy preference file: %s", path.c_str());
		
		auto *rw = SDL_RWFromFile(path.c_str(), "rb");
		if(rw == nullptr) {
			SPLog("Legacy preference file wasn't found.");
			return ret;
		}
		
		SdlFileStream stream(rw, true);
		std::string text = stream.ReadAllBytes();
		
		SPLog("Parsing %d bytes of legacy preference file", static_cast<int>(text.size()));
		
		auto lines = SplitIntoLines(text);
		std::string buf;
		auto flush = [&]{
			if(buf.empty()) return;
			
			auto idx = buf.find(':');
			if(idx != std::string::npos) {
				auto name = buf.substr(0, idx);
				auto value = buf.substr(idx + 1);
				
				if(name.size() > 0)
					ret.emplace_back(name, value);
			}
			
			buf.clear();
		};
		
		for(auto& line: lines) {
			{
				auto idx = line.find(';');
				if(idx != std::string::npos) {
					line.resize(idx);
				}
			}
			if(line.size() == 0) continue;
			if(line[0] == '[') continue; // group is not used
			if(line[0] == '+') {
				// continuation
				buf.append(line, 1, line.size() - 1);
			}else{
				flush();
				buf = line;
			}
		}
		flush();
		
		return ret;
	}
Ejemplo n.º 4
0
bool ImageSegmenter::Process()
{
	// Read input image
	m_docImage = imread(m_document_image_path.c_str(), CV_LOAD_IMAGE_GRAYSCALE); // converts to grayscale if required

	PreprocessImage(m_docImage);

	SplitIntoLines(m_docImage);	

	if (m_output_level == "LINES") {
		SaveOutput(m_output_level);
		return true;
	}
	else {
		SplitLinesIntoWords(m_docImage);
		SaveOutput(m_output_level);
	}
			
	return true;
}
Ejemplo n.º 5
0
void Patcher_HandleReceipt_ManifestFile()
{
	g_FilesInManifest.Clear();
	g_NextPatchFileIndex = 0;

	char* MessageContent = strstr( g_HTTPResultBuffer.GetData(), CRLF CRLF );
	if( !MessageContent )
	{
		AddStatus( "Error receiving manifest file.", g_StatusWarningColor );
		++g_NumWarnings;
		return;
	}

	MessageContent += 4;

	uint Offset = ( uint )( MessageContent - g_HTTPResultBuffer.GetData() );
	uint ContentSize = g_HTTPSocket->AsyncGetBytesReceived() - Offset;

	Array<SimpleString>	Lines;
	SplitIntoLines( MessageContent, ContentSize, Lines );

	for( uint LinesIndex = 0; LinesIndex + 2 < Lines.Size(); LinesIndex += 3 )
	{
		SManifestFile ManifestFile;
		ManifestFile.m_Filename = Lines[ LinesIndex ];
		ManifestFile.m_Length = Lines[ LinesIndex + 1 ];
		ManifestFile.m_Checksum = Lines[ LinesIndex + 2 ];
		ManifestFile.m_Validated = false;

		g_FilesInManifest.PushBack( ManifestFile );
	}

	AddStatus( "Manifest file received.", g_StatusColor );

	if( g_NextPatchFileIndex < g_FilesInManifest.Size() )
	{
		Patcher_GetNextPatchFile();
	}
}
Ejemplo n.º 6
0
void CCharBufferText::OnChange (unsigned int start, unsigned int old_count, unsigned int new_count)
{
    unsigned int c_start_line = GetLine (start);
    ASSERT (c_start_line < lines_count);
    unsigned int c_start_position = min (start - line_start [c_start_line], line_length [c_start_line]);

    unsigned int c_old_end_line = GetLine (start + old_count);
    ASSERT (c_old_end_line < lines_count);
    unsigned int c_old_end_position = min (start + old_count - line_start [c_old_end_line], line_length [c_old_end_line]);

    int delta = new_count - old_count;

    unsigned int before = GetLastLineEndingBefore (start);

    if (before > 0 && before < lines_count && line_length [before] == 0) before -= 1;

    unsigned int start_line = before >= lines_count ? 0 : before + 1;
    unsigned int start_pos = before >= lines_count ? 0 : line_start [before] + line_length [before];
    unsigned int after = GetFirstLineStartingAfter (start + old_count);

    if (after < lines_count && line_length [after] == 0) after += 1;

    unsigned int end_line = after >= lines_count ? lines_count : after;
    unsigned int end_pos = after >= lines_count ? data.GetSize () : line_start [after] + delta;
    unsigned int count = end_pos - start_pos;

    vector <unsigned int> starts;
    vector <unsigned int> lengths;

    SplitIntoLines (start_pos, count, starts, lengths);

    int c = starts.size ();
    ASSERT (c > 0);

    if (c == 1 && before < lines_count && after < lines_count) // Join three lines
    {
        line_length [before] += lengths [0] + line_length [after];
        line_length.erase (line_length.begin () + before + 1, line_length.begin () + after + 1);
        line_start.erase (line_start.begin () + before + 1, line_start.begin () + after + 1);

        if (delta != 0)
        {
            unsigned int size = line_length.size ();
            for (unsigned int i = before + 1; i < size; i++)
                line_start [i] += delta;
        }
    }
    else
    {
        unsigned int b = 0;
        unsigned int e = c;

        if (before < lines_count) // Append line
        {
            line_length [before] += lengths [0];
            b = 1;
        }

        if (after < lines_count) // Prepend line
        {
            line_start [after] -= lengths [c - 1];
            line_length [after] += lengths [c - 1];
            e = c - 1;
        }

        if (end_line < start_line) end_line = start_line;

        ReplaceRange (line_length, start_line, end_line - start_line, lengths, b, e - b);
        ReplaceRange (line_start, start_line, end_line - start_line, starts, b, e - b);

        if (delta != 0)
        {
            unsigned int size = line_length.size ();
            for (unsigned int i = (before < lines_count ? before + 1 : 0) + e - b; i < size; i++)
                line_start [i] += delta;
        }
    }

    lines_count = line_length.size ();

    unsigned int c_new_end_line = GetLine (start + new_count);
    ASSERT (c_new_end_line < lines_count);
    unsigned int c_new_end_position = min (start + new_count - line_start [c_new_end_line], line_length [c_new_end_line]);

    FireOnChange (c_start_line, c_start_position, c_old_end_line, c_old_end_position, c_new_end_line, c_new_end_position);
}