void StringBuffer::appendHelper(char ch) { if (!valid()) makeValid(1); if (m_len == m_cap) { growBy(1); } m_str->mutableData()[m_len++] = ch; }
void StringBuffer::appendHelper(char ch) { if (!valid()) makeValid(1); if (m_len == m_cap) { growBy(1); } m_buffer[m_len++] = ch; }
K3b::Msf::Msf( int i ) : m_minutes(0), m_seconds(0), m_frames(i) { makeValid(); }
void K3b::Msf::setValue( int m, int s, int f ) { m_minutes = m; m_seconds = s; m_frames = f; makeValid(); }
void K3b::Msf::Private::setValue( int m, int s, int f ) { minutes = m; seconds = s; frames = f; makeValid(); }
K3b::Msf::Msf( int m, int s, int f ) : m_minutes(m), m_seconds(s), m_frames(f) { makeValid(); }
Private( int m = 0, int s = 0, int f = 0 ) : minutes(m), seconds(s), frames(f) { makeValid(); }
K3b::Msf& K3b::Msf::operator=( int i ) { m_frames = i; m_seconds = 0; m_minutes = 0; makeValid(); return *this; }
K3b::Msf& K3b::Msf::operator+=( const K3b::Msf& m ) { m_frames += m.frames(); m_seconds += m.seconds(); m_minutes += m.minutes(); makeValid(); return *this; }
void StringBuffer::appendHelper(const char *s, int len) { if (!valid()) makeValid(len); assert(s); assert(len >= 0); if (len <= 0) return; if (len > m_cap - m_len) { growBy(len); } memcpy(m_buffer + m_len, s, len); m_len += len; }
int main() { while (true) { //thrust PID error = setpoint - getHeight(); integral = integral + error * dt; derivative = (error - previous_error); thrust = Kp * error + Ki * integral + Kd * derivative; //Pitch PID error_P = 0 - getPitch(); integral_P = integral_P + error_P * dt; derivative_P = (error_P - pre_error_P); pitch = Kp * error_P + Ki * integral_P + Kd * derivative_P; //Roll PID error_R = 0 - getRoll(); integral_R = integral_R + error_R * dt; derivative_R = (error_R - pre_error_R); roll = Kp * error_R + Ki * integral_P + Kd * derivative_R; //Motor controls if (thrust > 255) thrust = 255; else if (thrust < 0) thrust = 0; setFR(makeValid(thrust + pitch + roll)); // front right setFL(makeValid(thrust + pitch - roll)); // front left setBR(makeValid(thrust - pitch + roll)); // back right setBL(makeValid(thrust - pitch - roll)); // back left //set previous errors previous_error = error; pre_error_P = error_P; pre_error_R = error_R; Sleep(1000 * dt); } }
char* StringBuffer::appendCursor(int size) { if (!m_str) { makeValid(size); } else if (m_cap - m_len < size) { m_str->setSize(m_len); auto const tmp = m_str->reserve(m_len + size); if (UNLIKELY(tmp != m_str)) { assertx(m_str->hasExactlyOneRef()); m_str->release(); m_str = tmp; } m_cap = m_str->capacity(); } return m_str->mutableData() + m_len; }
void StringBuffer::read(FILE* in, int page_size /* = 1024 */) { assert(in); assert(page_size > 0); if (!valid()) makeValid(page_size); while (true) { int buffer_size = m_cap - m_len; if (buffer_size < page_size) { growBy(page_size); buffer_size = m_cap - m_len; } size_t len = fread(m_buffer + m_len, 1, buffer_size, in); if (len == 0) break; m_len += len; } }
void StringBuffer::read(File* in, int page_size /* = 1024 */) { assert(in); assert(page_size > 0); if (!valid()) makeValid(page_size); while (true) { int buffer_size = m_cap - m_len; if (buffer_size < page_size) { growBy(page_size); buffer_size = m_cap - m_len; } int64_t len = in->readImpl(m_buffer + m_len, buffer_size); assert(len >= 0); if (len == 0) break; m_len += len; } }
char* StringBuffer::appendCursor(int size) { if (!m_buffer) { makeValid(size); } else if (m_cap - m_len < size) { m_str->setSize(m_len); auto const tmp = m_str->reserve(m_len + size); if (UNLIKELY(tmp != m_str)) { assert(m_str->hasExactlyOneRef()); m_str->release(); m_str = tmp; } auto const s = m_str->bufferSlice(); m_buffer = s.ptr; m_cap = s.len; } return m_buffer + m_len; }
bool nTexture::TextureInternal::bind(uint slot, const nTextureSampler *smp, bool forceSync) const { if(makeValid(forceSync, slot)) { if(nGL::getState()->getTextureBinding(slot).tex != this) { TextureHandle::setGLActiveTexture(slot); glBindTexture(GL_TEXTURE_2D, *handle); } if(!smp) { smp = nGL::getState()->getDefaultSampler(props.mipmaping); } smp->bind(slot); nGL::getState()->setTextureBinding(this, slot); return true; } else { unbind(slot); return false; } }
void K3b::Msf::addFrames( int f ) { m_frames += f; makeValid(); }
int main(int argc, char *argv[]) { int i, selectIndex, tintValue, optionSwitch, negativeIndex, yiq, terse, enableRed, enableBlue, enableGreen, ret, exitStatus; i = yiq = terse = tintValue = optionSwitch = negativeIndex = enableRed = enableBlue = enableGreen = ret = exitStatus = 0; selectIndex = -1; long red, blue, green; red = blue = green = 0; char *colorString, *inputString; char negativeTintInput[10] = ""; /* -l (limit), -i (invert), -s (select) */ while ((i = getopt (argc, argv, ":rghbtlis:c")) != -1) switch(i) { case 'l': optionSwitch = 1; break; case 'i': optionSwitch = -1; break; case 'c': optionSwitch = 2; break; case 'r': enableRed = 1; break; case 'g': enableGreen = 1; break; case 'b': enableBlue = 1; break; case 's': selectIndex = atoi(optarg); break; case 'h': usage(); case 't': terse = 1; break; case '?': /* here we hand number arguments to a string to parse */ /* because we want to do negative args without escaping (--) */ switch(optopt) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': negativeTintInput[negativeIndex++] = optopt; break; default: usage(); } } /* always gonna need an input string. */ if (argv[optind] == NULL) usage(); /* if not inverting, need tint value. */ if (optionSwitch != -1 && optionSwitch != 2 && !negativeIndex) if (argv[optind] == NULL) usage(); /* default to all colors. */ if (!enableRed && !enableGreen && !enableBlue) enableRed = enableGreen = enableBlue = 1; /* set input and color strings, default to last 6 characters. */ inputString = argv[argc - 1]; selectIndex = selectIndex == -1 ? strlen(inputString) - 6 : selectIndex; colorString = &inputString[selectIndex]; /* set color handles. */ red = hexToDec(colorString, 0); green = hexToDec(colorString, 2); blue = hexToDec(colorString, 4); /* set and apply the tint value if we're using it */ if (optionSwitch != -1 && optionSwitch != 2) { tintValue = negativeIndex ? -1 * atoi(negativeTintInput) : atoi(argv[optind]); red += tintValue; green += tintValue; blue += tintValue; } /* do the thing */ switch(optionSwitch) { case -1: /* invert */ red = 255 - red; green = 255 - green; blue = 255 - blue; break; case 0: /* normal */ case 1: /* limit */ ret = makeValid(&red, optionSwitch); ret += makeValid(&green, optionSwitch); ret += makeValid(&blue, optionSwitch); exitStatus = ret >=2 ? 1 : 0; break; case 2: /* contrast - ref: https://24ways.org/2010/calculating-color-contrast/ */ yiq = ((red * 299) + (green * 587) + (blue * 114)) / 1000; exit(yiq >= 128 ? 1 : 0); } /* insert result if enabled */ if (enableRed) decToHex(red, &colorString[0]); if (enableGreen) decToHex(green, &colorString[2]); if (enableBlue) decToHex(blue, &colorString[4]); /* print color only */ if (terse) { colorString[6] = '\0'; inputString = colorString; } printf("%s", inputString); exit(exitStatus); }
K3b::Msf& K3b::Msf::operator-=( int i ) { m_frames -= i; makeValid(); return *this; }
void K3b::Msf::addMinutes( int m ) { m_minutes += m; makeValid(); }
void K3b::Msf::addSeconds( int s ) { m_seconds += s; makeValid(); }
uint nTexture::TextureInternal::getGLHandle() const { if(!makeValid(true)) { nError("Unable to get texture handle"); } return *handle; }