Ejemplo n.º 1
0
Npc::Npc(sf::Texture* tex):Image(tex) {
	locked=true;
	direction=0;
	objectIndex=6;
	index=0;

	SetOrigin(imageWidth/2,imageHeight-11);

	SetBBox(-engine->gridSize/2+engine->gridSize/32*4,-engine->gridSize/2+engine->gridSize/32*8,
		engine->gridSize-engine->gridSize/32*8,engine->gridSize-engine->gridSize/32*15);

	AddSequence(0,0,0.25);
	AddSequence(5,5,0.25);
	AddSequence(10,10,0.25);
	AddSequence(15,15,0.25);

	AddSequence(1,4,0.2);
	AddSequence(6,9,0.2);
	AddSequence(11,14,0.2);
	AddSequence(16,19,0.2);

	SetSequence(0,1);

	sprShadow.setTexture(*engine->resourcesManager->GetTexture("sprShadow"),true);
	sprShadow.setOrigin(engine->resourcesManager->GetTexture("sprShadow")->getSize().x/2,
		engine->resourcesManager->GetTexture("sprShadow")->getSize().y/2-1*2);
};
Ejemplo n.º 2
0
Player::Player(sf::Texture &tex):Image(tex) {
	objectIndex=1;
	direction=0;
	SetBBox(-gridSize/2-gridSize/32*2,-gridSize/2-gridSize/32*7,gridSize-gridSize/32*4,gridSize-gridSize/32*12);
	//SetBBox(-28,-24,56,48);
	AddSequence(0,0,0.25);
};
Ejemplo n.º 3
0
Player::Player(char* path):Image(path) {
	objectIndex=1;
	direction=0;
	SetBBox(-gridSize/2+gridSize/32*2,-gridSize/2+gridSize/32*7,gridSize-gridSize/32*4,gridSize-gridSize/32*12);
	//SetBBox(-28,-18,56,36);
	AddSequence(0,0,0.25);
};
Ejemplo n.º 4
0
void CModel::ReOrderSequences()
{
	typedef vector<CSequence*> sequences_t; sequences_t sequences;

	// add sequences to list...

	CSequence *curSequence = m_sequences;
	while (curSequence)
	{
		sequences.push_back(curSequence);
		curSequence = curSequence->GetNext();
	}

	// re-order sequences...

	qsort( (void *)&sequences[0], (size_t)(sequences.size()), sizeof(CSequence *), ModelSequenceCompareFunc );

	// now rebuild links...

	int iTotMasterSequences = GetTotMasterSequences();	// this needs to be eval'd here, you can't do it in the for-next below
	m_sequences = NULL;
	for (int i=0; i<iTotMasterSequences; i++)
	{
		curSequence = sequences[i];
		curSequence->SetNext(NULL);

		AddSequence(curSequence);
	}

	Resequence();
}
Ejemplo n.º 5
0
void Indexer::BuildFromLines()
{
    assert(m_pos == m_bufferStart);
    m_hasSequenceIds = false;
    size_t lines = 0;
    int64_t offset = GetFileOffset();
    while (!m_done)
    {
        m_pos = (char*)memchr(m_pos, ROW_DELIMITER, m_bufferEnd - m_pos);
        if (m_pos)
        {
            SequenceDescriptor sd = {};
            sd.m_id = lines;
            sd.m_numberOfSamples = 1;
            sd.m_isValid = true;
            sd.m_fileOffsetBytes = offset;
            offset = GetFileOffset() + 1;
            sd.m_byteSize = offset - sd.m_fileOffsetBytes;
            // TODO: ignore empty lines.
            AddSequence(sd);
            ++m_pos;
            ++lines;
        }
        else
        {
            RefillBuffer();
        }
    }
}
Ejemplo n.º 6
0
/*
 * create a random sequence from either dna or protein input sequence
 * add sequence to sequence manager
 */
int ScrambleSeq(Tcl_Interp *interp,
		int seq_num)
{
    char *seq1 = GetSeqSequence(seq_num);
    int length = GetSeqLength(seq_num);
    int seq_id = GetSeqId(seq_num);
    char *seq2;
    char *name;
    time_t tim;
    int seed;
    char *parental_name, *child_name;
    int new_seq_num, start, end;
    static int num = 0;


    if (NULL == (seq2 = (char *)xmalloc((length+1) * sizeof(char))))
	return -1;

    memcpy(seq2, seq1, length);

    tim = time(NULL);
    seed = (int) tim;

    scramble_seq(seq2, length, seed);
    seq2[length] = '\0';

    parental_name = GetParentalSeqName(seq_num);
    child_name = GetSeqName(seq_num);

    if (NULL == (name = (char *)xmalloc((strlen(parental_name)+13) * 
					sizeof(char))))
	return -1;
    sprintf(name, "%s_x%d", parental_name, num);
    if (-1 == (new_seq_num = AddSequence(interp, -1, GetSeqLibrary(seq_num), 
					 name, seq2, GetSeqStructure(seq_num), 
					 GetSeqType(seq_num), NULL , " ")))
	return -1;
    xfree(name);

    if (strcmp(parental_name, child_name) != 0) {
	/* sub-sequence */
	/* 
	 * need to get seq num from seq_id instead of using seq_num incase
	 * AddSequence has deleted duplicate names
	 */
	start = GetSubSeqStart(GetSeqNum(seq_id));
	end = GetSubSeqEnd(GetSeqNum(seq_id));

	if (NULL == (name = (char *)xmalloc((strlen(child_name)+13) * 
					    sizeof(char))))
	    return -1;

	sprintf(name, "%s_x%d", child_name, num);
	if (-1 == (AddSubSequence(interp, GetSeqId(new_seq_num), start, end, name)))
	    return -1;
    }
    num++;
    return 0;
}
Ejemplo n.º 7
0
/*
 * copy range of sequence
 * add new sequence name to sequence manager
 */
int CopyRange(Tcl_Interp *interp,
	      int seq_id,
	      int start,
	      int end)
{
    int seq_num = GetSeqNum(seq_id);
    char *seq1 = GetSeqSequence(seq_num);
    char *seq2;
    char *name;
    int length = end - start + 1;
    int new_seq_num;
    char *parental_name, *child_name;
    static int count = 1;


    if (NULL == (seq2 = (char *)xmalloc((length+2) * sizeof(char))))
	return -1;
     
    strncpy(seq2, &seq1[start-1], end - start + 1);
    seq2[end - start + 1] = '\0';

    parental_name = GetParentalSeqName(seq_num);
    child_name = GetSeqName(seq_num);

    if (NULL == (name = (char *)xmalloc((strlen(parental_name)+20) * 
					sizeof(char))))
	return -1;
    sprintf(name, "%s_n%d", parental_name, count++);
    if (-1 == (new_seq_num = AddSequence(interp, -1, GetSeqLibrary(seq_num), 
					 name, seq2, GetSeqStructure(seq_num), 
					 GetSeqType(seq_num), NULL, " ")))
	return -1;
    xfree(name);

    /* don't think I need to deal with subsequences in copying a sequence. */
#if 0
    if (strcmp(parental_name, child_name) != 0) {
	/* sub-sequence */
	/* 
	 * need to get seq num from seq_id instead of using seq_num incase
	 * AddSequence has deleted duplicate names
	 */
	start = GetSubSeqStart(GetSeqNum(seq_id));
	end = GetSubSeqEnd(GetSeqNum(seq_id));

	if (NULL == (name = (char *)xmalloc((strlen(child_name)+3) * 
					    sizeof(char))))
	    return -1;

	sprintf(name, "%s_n%d", child_name, count++);
	if (-1 == (AddSubSequence(interp, GetSeqId(new_seq_num), 
				  start, end, name)))
	    return -1;
    }
#endif
    return 0;
}
Ejemplo n.º 8
0
/*
 * complement sequence
 * add new sequence name to sequence manager
 */
int ComplementSeq(Tcl_Interp *interp,
		  int seq_num)
{
    char *seq1 = GetSeqSequence(seq_num);
    char *seq2;
    char *name;
    int length = GetSeqLength(seq_num);
    int seq_id = GetSeqId(seq_num);
    int new_seq_num, start, end;
    char *parental_name, *child_name;

    if (NULL == (seq2 = (char *)xmalloc((length+1) * sizeof(char))))
	return -1;

    memcpy(seq2, seq1, length);
    (void) complement_seq(seq2, length);
    seq2[length] = '\0';

    parental_name = GetParentalSeqName(seq_num);
    child_name = GetSeqName(seq_num);

    if (NULL == (name = (char *)xmalloc((strlen(parental_name)+3) * 
					sizeof(char))))
	return -1;
    sprintf(name, "%s_c", parental_name);
    if (-1 == (new_seq_num = AddSequence(interp, -1, GetSeqLibrary(seq_num), 
					 name, seq2, GetSeqStructure(seq_num), 
					 GetSeqType(seq_num), NULL, " ")))
	return -1;

    xfree(name);

    if (strcmp(parental_name, child_name) != 0) {
	/* sub-sequence */
	/* 
	 * need to get seq num from seq_id instead of using seq_num incase
	 * AddSequence has deleted duplicate names
	 */
	start = GetSubSeqStart(GetSeqNum(seq_id));
	end = GetSubSeqEnd(GetSeqNum(seq_id));

	if (NULL == (name = (char *)xmalloc((strlen(child_name)+3) * 
					    sizeof(char))))
	    return -1;

	sprintf(name, "%s_c", child_name);
	if (-1 == (AddSubSequence(interp, GetSeqId(new_seq_num), 
				  length - end + 1, 
				  length - start + 1, name)))
	    return -1;
    }
    return 0;
}
Ejemplo n.º 9
0
/*
 * add new sequence to sequence manager, but keep as dna but with an extension
 * of _rf123 which signifies to the comparison functions that the sequence
 * is to translated into it's 3 reading frames, each of which will be used
 * in the comparison routine
 */
int TranslateTogether(Tcl_Interp *interp,
		      int seq_num)
{
    char *name;
    char *dna_seq;
    char *prot_seq;
    int seq_id = GetSeqId(seq_num);
    int new_seq_num;
    char *parental_name, *child_name;
    int start, end;

#ifdef DEBUG
    printf("START translate together \n");
#endif
    dna_seq = GetSeqSequence(seq_num);
    if (NULL == (prot_seq = strdup(dna_seq)))
	return -1;
    
    parental_name = GetParentalSeqName(seq_num);
    child_name = GetSeqName(seq_num);

    if (NULL == (name = (char *)xmalloc((strlen(parental_name)+7) * 
					sizeof(char))))
	return -1;
    sprintf(name, "%s_rf123", parental_name);
    if (-1 == (new_seq_num = AddSequence(interp, -1, GetSeqLibrary(seq_num), 
					 name, prot_seq, LINEAR, PROTEIN, NULL, " ")))
	return -1;

    xfree(name);

    if (strcmp(parental_name, child_name) != 0) {
	/* sub-sequence */
	/* 
	 * need to get seq num from seq_id instead of using seq_num incase
	 * AddSequence has deleted duplicate names
	 */
	start = GetSubSeqStart(GetSeqNum(seq_id));
	end = GetSubSeqEnd(GetSeqNum(seq_id));

	if (NULL == (name = (char *)xmalloc((strlen(child_name)+7) * 
					    sizeof(char))))
	    return -1;

	sprintf(name, "%s_rf123", child_name);
	new_seq_num = AddSubSequence(interp, GetSeqId(new_seq_num), start, end, 
				     name);
    }
    return new_seq_num;
}
Ejemplo n.º 10
0
void Redis::Call(IKernel * kernel, const IScriptArgumentReader * reader, IScriptResultWriter * writer) {
	s64 sequenceId;
	s32 threadId;
	s32 size = 0;
	const void * context = nullptr;

	if (!reader->Read("liS", &sequenceId, &threadId, &context, &size)) {
		writer->Write("b", false);
		return;
	}

	if (s_sessions.empty() && s_sessions[threadId % s_sessions.size()]->IsConnected())
		writer->Write("b", false);
	else {
		auto session = s_sessions[threadId % s_sessions.size()];
		session->Send(context, size);
		session->AddSequence(sequenceId);
		writer->Write("b", true);
	}
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
#if defined(USE_MSXML)
	CoInitialize(0);
#endif

	const char *fname = "data.xml";
	if (argc > 1)
		fname = argv[1];

	InitSynthesizer();

	mix.SetChannels(2);
	mix.MasterVolume(1.0, 1.0);
	mix.ChannelOn(0, 1);
	mix.ChannelOn(1, 1);
	mix.ChannelVolume(0, 1.0);
	mix.ChannelVolume(1, 1.0);
#ifdef ADD_REVERB
	mix.SetFxChannels(1);
	mix.FxInit(0, &rvrb, 0.1);
	mix.FxLevel(0, 0, 0.2);
	mix.FxLevel(0, 1, 0.2);
	rvrb.InitReverb(1.0, 2.0);
#endif

	inMgr.Init(&mix, &wvf);

	inMgr.AddType("Tone", ToneInstr::ToneFactory, ToneInstr::ToneEventFactory);
	inMgr.AddType("ToneFM", ToneFM::ToneFMFactory, ToneFM::ToneFMEventFactory);
	inMgr.AddType("AddSynth", AddSynth::AddSynthFactory, AddSynth::AddSynthEventFactory);
	inMgr.AddType("SubSynth", SubSynth::SubSynthFactory, SubSynth::SubSynthEventFactory);
	inMgr.AddType("FMSynth", FMSynth::FMSynthFactory, FMSynth::FMSynthEventFactory);
	inMgr.AddType("MatrixSynth", MatrixSynth::MatrixSynthFactory, MatrixSynth::MatrixSynthEventFactory);
	inMgr.AddType("WFSynth", WFSynth::WFSynthFactory, WFSynth::WFSynthEventFactory);
	inMgr.AddType("Chuffer", Chuffer::ChufferFactory, Chuffer::ChufferEventFactory);
	inMgr.AddType("ModSynth", ModSynth::ModSynthFactory, ModSynth::ModSynthEventFactory);
	inMgr.AddType("BuzzSynth", BuzzSynth::InstrFactory, BuzzSynth::EventFactory);
	InstrMapEntry *ime = 0;
	while ((ime = inMgr.EnumType(ime)) != 0)
		ime->dumpTmplt = DestroyTemplate;

	XmlSynthDoc doc;
	XmlSynthElem rootNode(&doc);
	if (!doc.Open(fname, &rootNode))
	{
		printf("Cannot open file %s\n", fname);
		exit(1);
	}

	// Optional: use LoadInstrLib(inMgr, fname)
	// but we want to discover the inum values
	// and add sequences programaticaly...

	XmlSynthElem elem(&doc);
	XmlSynthElem *inst = rootNode.FirstChild(&elem);
	while (inst != NULL)
	{
		if (inst->TagMatch("instr"))
		{
			InstrConfig *ent = inMgr.LoadInstr(inst);
			if (strcmp(ent->instrType->GetType(), "WFSynth") == 0)
				AddEvent(ent->inum, 48, 1.0);
			else
				AddSequence(ent->inum, 0.25);
		}

		inst = elem.NextSibling(&elem);
	}
	doc.Close();

	if (wvf.OpenWaveFile("example10.wav", 2))
	{
		printf("Cannot open wavefile for output\n");
		exit(1);
	}
	seq.Sequence(inMgr);

#ifdef ADD_REVERB
	// drain the reverb...
	AmpValue lv;
	AmpValue rv;
	long n = synthParams.isampleRate;
	while (n-- > 0)
	{
		mix.Out(&lv, &rv);
		wvf.Output2(lv, rv);
	}
#endif

	wvf.CloseWaveFile();

	///////////////////////////////////////////////////////////////
	// Code to test instrument save functions...
#define TEST_SAVE_INSTR 1
#ifdef TEST_SAVE_INSTR
	doc.NewDoc("instrlib", &rootNode);
	InstrConfig *inc = inMgr.EnumInstr(0);
	while (inc)
	{
		InstrMapEntry *ime = inc->instrType;
		Instrument *ip = (Instrument *)inc->instrTmplt;
		if (ip)
		{
			rootNode.AddChild("instr", &elem);
			elem.SetAttribute("id", inc->inum);
			elem.SetAttribute("type", ime->itype);
			elem.SetAttribute("name", inc->GetName());
			elem.SetAttribute("desc", inc->GetDesc());
			ip->Save(&elem);
		}
		inc = inMgr.EnumInstr(inc);
	}
	bsString outxml(fname);
	bsString outbase;
	bsString outfile;
	outxml.SplitPath(outbase, outfile, 1);
	outxml = outbase;
	outxml += '_';
	outxml += outfile;
	doc.Save(outxml);
#endif
	///////////////////////////////////////////////////////////////

	return 0;
}
Ejemplo n.º 12
0
void Indexer::Build()
{
    if (!m_chunks.empty())
    {
        return;
    }
    
    if (m_maxChunkSize > 0)
    {
        auto fileSize = filesize(m_file);
        m_chunks.reserve((fileSize + m_maxChunkSize - 1) / m_maxChunkSize);
    }

    m_chunks.push_back({});

    RefillBuffer(); // read the first block of data
    if (m_done)
    {
        RuntimeError("Input file is empty");
    }

    if ((m_bufferEnd - m_bufferStart > 3) &&
        (m_bufferStart[0] == '\xEF' && m_bufferStart[1] == '\xBB' && m_bufferStart[2] == '\xBF'))
    {
        // input file contains UTF-8 BOM value, skip it.
        m_pos += 3;
        m_fileOffsetStart += 3;
        m_bufferStart += 3;
    }

    // check the first byte and decide what to do next
    if (!m_hasSequenceIds || m_bufferStart[0] == NAME_PREFIX)
    {
        // skip sequence id parsing, treat lines as individual sequences
        BuildFromLines();
        return;
    }

    size_t id = 0;
    int64_t offset = GetFileOffset();
    // read the very first sequence id
    if (!GetNextSequenceId(id))
    {
        RuntimeError("Expected a sequence id at the offset %" PRIi64 ", none was found.", offset);
    }

    SequenceDescriptor sd = {};
    sd.m_id = id;
    sd.m_fileOffsetBytes = offset;
    sd.m_isValid = true;

    while (!m_done)
    {
        SkipLine(); // ignore whatever is left on this line.
        offset = GetFileOffset(); // a new line starts at this offset;
        sd.m_numberOfSamples++;

        if (!m_done && GetNextSequenceId(id) && id != sd.m_id)
        {
            // found a new sequence, which starts at the [offset] bytes into the file
            sd.m_byteSize = offset - sd.m_fileOffsetBytes;
            AddSequence(sd);
            sd = {};
            sd.m_id = id;
            sd.m_fileOffsetBytes = offset;
            sd.m_isValid = true;
        }
    }

    // calculate the byte size for the last sequence
    sd.m_byteSize = m_fileOffsetEnd - sd.m_fileOffsetBytes;
    AddSequence(sd);
}
Ejemplo n.º 13
0
int TranslateSeq(Tcl_Interp *interp,
		 int seq_num,
		 int rf,
		 int start,
		 int end)
{
    int i;
    char *name;
    char *dna_seq;
    char *prot_seq;
    int cnt = 0;
    int seq_id = GetSeqId(seq_num);
    int new_seq_num;
    char *ptr;
    char *parental_name, *child_name;
    char *new_name;
    int length = end - start + 1;
    static int num = 0;

#ifdef DEBUG
    printf("START translate seq %d to %d\n", start, end);
#endif
    dna_seq = GetSeqSequence(seq_num);
    if (NULL == (prot_seq = (char *)xmalloc(((length/3)+3) * sizeof(char))))
	return -1;
    if (NULL == (new_name = (char *)xmalloc(strlen(GetSeqName(seq_num))
					    * sizeof(char))))
	return -1;

    for (i = rf+start-1; i < end-2; i+=3) {
	prot_seq[cnt++] = codon_to_acid1(&dna_seq[i]);
    }
    prot_seq[cnt] = '\0';
#ifdef DEBUG
    printf("%s\n", prot_seq);
#endif
    /* 
     * special case: remove _rf123 from name before adding _rfx to end 
     */
    parental_name = GetParentalSeqName(seq_num);
    child_name = GetSeqName(seq_num);
    ptr = strstr(parental_name, "_rf123");

    if (NULL == (name = (char *)xmalloc((strlen(parental_name)+28) 
					 * sizeof(char))))
	return -1;
    if (ptr) {
	strncpy(new_name, parental_name, (ptr - parental_name));
	new_name[ptr - parental_name] = '\0';
	strcat(new_name, ptr+6);
	sprintf(name, "%s_rf%d_%d", new_name, rf+1, num);
    } else {
	sprintf(name, "%s_rf%d_%d", parental_name, rf+1, num);
    }

    /* proteins can only be LINEAR ! */
    if (-1 == (new_seq_num = AddSequence(interp, -1, GetSeqLibrary(seq_num), 
					 name, prot_seq, LINEAR, PROTEIN, NULL, " ")))
	return -1;
    xfree(name);
    xfree(new_name);

    if (strcmp(parental_name, child_name) != 0) {
	/* sub-sequence */
	/* 
	 * need to get seq num from seq_id instead of using seq_num incase
	 * AddSequence has deleted duplicate names
	 */
	start = ceil((GetSubSeqStart(GetSeqNum(seq_id))-1)/3.0 + 1);
	end = (GetSubSeqEnd(GetSeqNum(seq_id)) - rf) / 3;
	if (NULL == (name = (char *)xmalloc((strlen(child_name)+15) * 
					    sizeof(char))))
	    return -1;
	if (NULL == (new_name = (char *)xmalloc(strlen(GetSeqName(seq_num))
						* sizeof(char))))
	    return -1;

	ptr = strstr(child_name, "_rf123");
	
	if (ptr) {
	    strncpy(new_name, child_name, (ptr - child_name));
	    new_name[ptr - child_name] = '\0';
	    strcat(new_name, ptr+6);
	    sprintf(name, "%s_rf%d_%d", new_name, rf+1, num);
	} else {
	    sprintf(name, "%s_rf%d_%d", child_name, rf+1, num);
	}

	/* sprintf(name, "%s_rf%d", child_name, rf+1); */
	new_seq_num = AddSubSequence(interp, GetSeqId(new_seq_num), start, end, 
				     name);
	xfree(new_name);
    }
    num++;
    return new_seq_num;
}