void sstSequence::AddBeat( float time ) { vsAssert( m_beatCount < MAX_BEATS, "Too many beats in this sequence!" ); m_targetActive[ m_beatCount ] = true; m_rocket[ m_beatCount ] = NULL; m_beat[ m_beatCount++ ] = time; }
vsSemaphore::~vsSemaphore() { vsAssert(m_released, "Semaphore destroyed without being released?"); pthread_mutex_lock(&m_semaphore.mutex); pthread_cond_destroy( &m_semaphore.cond ); pthread_mutex_unlock(&m_semaphore.mutex); pthread_mutex_destroy( &m_semaphore.mutex ); }
void vsCollisionObject::AddForce( const vsVector2D &force ) { vsAssert(m_body, "Tried to add force without a body!"); b2Vec2 f(force.x, force.y); b2Vec2 w = m_body->GetWorldCenter(); m_body->ApplyForce( f, w, true ); }
void vsRenderQueueStage::StartRender() { m_batchCount = 0; vsAssert( m_batch == NULL, "Batches not cleared?" ); // m_batch = NULL; }
void vsDisplayList::VertexBuffer( vsRenderBuffer *buffer ) { vsAssert(buffer->GetContentType() == vsRenderBuffer::ContentType_Custom || buffer->GetContentType() == vsRenderBuffer::ContentType_P, "Known render buffer types should use ::BindBuffer"); m_fifo->WriteUint8( OpCode_VertexBuffer ); m_fifo->WriteVoidStar( buffer ); }
void vsDynamicMaterial::SetTexture( int i, const vsString &texture, bool linear ) { vsAssert(i >= 0 && i < MAX_TEXTURE_SLOTS, "Out of range texture requested"); vsDelete(GetResource()->m_texture[i]); GetResource()->m_texture[i] = new vsTexture(texture); if ( !linear ) GetResource()->m_texture[i]->GetResource()->SetNearestSampling(); }
static void CheckFBO() { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status == GL_FRAMEBUFFER_COMPLETE) return; status -= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; vsAssert(status == GL_FRAMEBUFFER_COMPLETE,vsFormatString("incomplete framebuffer object due to %s", c_enums[status])); }
vsFile::vsFile( const vsString &filename, vsFile::Mode mode ): m_mode(mode), m_length(0) { vsAssert( !DirectoryExists(filename), vsFormatString("Attempted to open directory '%s' as a plain file", filename.c_str()) ); if ( mode == MODE_Read ) m_file = PHYSFS_openRead( filename.c_str() ); else m_file = PHYSFS_openWrite( filename.c_str() ); if ( m_file ) { m_length = (size_t)PHYSFS_fileLength(m_file); } vsAssert( m_file != NULL, STR("Error opening file '%s': %s", filename.c_str(), PHYSFS_getLastError()) ); }
float vsToken::AsFloat() { vsAssert(m_type == Type_Float || m_type == Type_Integer, "Tried to read non-numeric token as float!"); if ( m_type == Type_Float ) return m_float; else return (float)m_int; }
void vsFile::EnsureWriteDirectoryExists( const vsString &writeDirectoryName ) // static method { if ( !DirectoryExists(writeDirectoryName) ) { int mkdirResult = PHYSFS_mkdir( writeDirectoryName.c_str() ); vsAssert( mkdirResult != 0, vsFormatString("Failed to create directory '%s%s%s': %s", PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), writeDirectoryName.c_str(), PHYSFS_getLastError()) ); } }
void vsCollisionObject::NotifyJointAdded(b2Joint *joint, vsCollisionObject *other) { vsAssert(m_jointCount < MAX_JOINTS, "Ran out of joints!"); m_joint[m_jointCount] = dynamic_cast<b2RevoluteJoint*>(joint); m_jointPartner[m_jointCount] = other; m_jointCount++; }
void vsBuiltInFont::BuildDisplayListFromString( vsDisplayList *list, const char *string, float size, float capSize, JustificationType j, const vsVector2D &offset_in ) { vsVector2D offset = offset_in; size_t len = strlen(string); if ( j != Justification_Left ) { BuildDisplayListFromString(list, string, size, capSize, Justification_Left); float width = GetDisplayListWidth(list); if ( j == Justification_Right ) offset.x = -width; if ( j == Justification_Center ) offset.x = -(width*0.5f); list->Clear(); } //float iniXOffset = offset.x; list->VertexBuffer(s_P); vsTransform2D t; for ( size_t i = 0; i < len; i++ ) { char thisChar = string[i]; float thisSize = GetSizeForCharacter(thisChar, size, capSize); int index = lookup_letterIndex(thisChar); if ( index < 57 && index >= 0 ) { vsAssert(index < 57, "Unknown char??"); offset.x += c_kerningFactor * thisSize; t.SetTranslation( offset-(thisSize*baseline) ); t.SetScale( vsVector2D(thisSize,thisSize) ); list->PushTransform(t); list->LineListBuffer( &s_I[index] ); list->PopTransform(); } // AppendCharacterToList( string[i], list, offset, thisSize ); offset.x += c_kerningFactor * thisSize; } list->ClearArrays(); }
float fsRecord::GetArg( int i ) { if ( m_argType[i] == Arg_Float ) return m_fArg[i]; else if ( m_argType[i] == Arg_Int ) return m_iArg[i]; vsAssert(0, "Unknown arg type!"); return 0.0f; }
vsRenderQueueStage * vsRenderQueue::GetStage( int i ) { vsAssert( i >= 0 && i < m_stageCount, "Requested nonexistant render stage!" ); if ( i >= 0 && i < m_stageCount ) { return &m_stage[i]; } return NULL; }
void vsRenderQueue::Draw( vsDisplayList *list ) { for ( int i = 0; i < m_stageCount; i++ ) { m_stage[i].Draw(list); } list->Append(*m_genericList); DeinitialiseTransformStack(); vsAssert( m_transformStackLevel == 0, "Unbalanced push/pop of transforms?"); }
float vsVector3D::operator[](int n) const { if ( n == 0 ) return x; else if ( n == 1 ) return y; else if ( n == 2 ) return z; vsAssert(0,"Illegal index!"); return 0.f; }
vsTextureInternal::vsTextureInternal( const vsString &filename_in ): vsResource(filename_in), m_texture(0), m_depth(false), m_premultipliedAlpha(false) { vsString filename = vsFile::GetFullFilename(filename_in); SDL_Surface *loadedImage = IMG_Load(filename.c_str()); vsAssert(loadedImage != NULL, vsFormatString("Unable to load texture %s: %s", filename.c_str(), IMG_GetError())); ProcessSurface(loadedImage); SDL_FreeSurface(loadedImage); }
void vsModelInstanceLodGroup::UpdateInstance( vsModelInstance *inst, bool show ) { vsAssert(inst->lodGroup == this, "Wrong group??"); if ( show ) { if ( inst->matrixIndex < 0 ) // we've come into view! { inst->matrixIndex = m_matrix.ItemCount(); m_matrix.AddItem( inst->matrix ); m_color.AddItem( inst->color ); m_matrixInstanceId.AddItem( inst->index ); #ifdef INSTANCED_MODEL_USES_LOCAL_BUFFER m_bufferIsDirty = true; #endif } else // we were already in view; just update our matrix { m_matrix[inst->matrixIndex] = inst->matrix; m_color[inst->matrixIndex] = inst->color; #ifdef INSTANCED_MODEL_USES_LOCAL_BUFFER m_bufferIsDirty = true; #endif } } else if ( !show && inst->matrixIndex >= 0 ) // we've gone out of view! { int swapFrom = m_matrix.ItemCount() - 1; int swapTo = inst->matrixIndex; // We don't need to swap if we were already the last thing in the list. if ( swapFrom != swapTo ) { int swapperInstanceId = m_matrixInstanceId[swapFrom]; vsModelInstance *swapper = m_instance[swapperInstanceId]; m_matrix[swapTo] = m_matrix[swapFrom]; m_color[swapTo] = m_color[swapFrom]; m_matrixInstanceId[swapTo] = m_matrixInstanceId[swapFrom]; swapper->matrixIndex = swapTo; } m_matrix.PopBack(); m_color.PopBack(); m_matrixInstanceId.PopBack(); inst->matrixIndex = -1; #ifdef INSTANCED_MODEL_USES_LOCAL_BUFFER m_bufferIsDirty = true; #endif } }
float & vsVector4D::operator[]( int n ) { if ( n == 0 ) return x; else if ( n == 1 ) return y; else if ( n == 2 ) return z; else if ( n == 3 ) return w; vsAssert(0,"Illegal index!"); return w; }
vsNetClient::vsNetClient(const vsString &address, uint16_t port) { hostent *h = gethostbyname( address.c_str() ); if (h == NULL) { #if !defined(_WIN32) // todo: Network errors under WinSock! herror("gethostbyname"); #endif vsAssert( h != NULL, vsFormatString("Gethostbyname error: See console output for details" ) ); } m_privateIP = ((struct in_addr *)h->h_addr)->s_addr; m_privatePort = port; }
vsVector4D & vsMatrix4x4::operator[](int n) { vsAssert(n >= 0 && n < 4, "Out of bounds!"); if ( n == 0 ) return x; if ( n == 1 ) return y; if ( n == 2 ) return z; return w; }
void vsMeshMaker::BakeTriangleEdge( vsMeshMakerTriangle *triangle, int vertA, int vertB ) { std::vector<vsMeshMakerTriangleEdge>::iterator iter; for ( iter = m_internalData->m_triangleEdge.begin(); iter != m_internalData->m_triangleEdge.end(); iter++ ) { vsMeshMakerTriangleEdge *edge = &*iter; if ( edge->m_bTriangle == NULL ) { if ( edge->m_aVertex == &m_vertex[vertA] && edge->m_bVertex == &m_vertex[vertB] ) { // found matching pair! vsAssert( edge->m_bTriangle == NULL, "Edge with more than two polygons??" ); edge->m_bTriangle = triangle; return; } else if ( edge->m_aVertex == &m_vertex[vertB] && edge->m_bVertex == &m_vertex[vertA] ) { // found matching pair! vsAssert( edge->m_bTriangle == NULL, "Edge with more than two polygons??" ); edge->m_bTriangle = triangle; return; } } } vsMeshMakerTriangleEdge e; e.m_aTriangle = triangle; e.m_aVertex = &m_vertex[vertA]; e.m_bVertex = &m_vertex[vertB]; m_internalData->m_triangleEdge.push_back(e); }
vsMeshMakerCell * vsMeshMaker::GetCellForPosition( const vsVector3D &position ) { vsVector3D offset = position - m_cellBounds.GetMin(); int xi = offset.x / m_cellDimX; int yi = offset.y / m_cellDimY; int zi = offset.z / m_cellDimZ; vsAssert(xi < MAKER_CELLS && yi < MAKER_CELLS && zi < MAKER_CELLS && xi >= 0 && yi >= 0 && zi >= 0, "Out of bounds!"); int ci = (MAKER_CELLS*MAKER_CELLS*zi) + (MAKER_CELLS*yi) + xi; return &m_cell[ci]; }
float vsPerlinOctave::InterpolatedNoise1D(float x) { int integer_X = int(x); float fractional_X = x - integer_X; vsAssert( fractional_X >= 0.f && fractional_X < 1.f, "Maths error: fractional_X out of bounds!" ); fractional_X = (3.0f * fractional_X * fractional_X) - (2.0f * fractional_X * fractional_X * fractional_X); float v1 = SmoothedNoise1D(integer_X); float v2 = SmoothedNoise1D(integer_X + 1); return vsInterpolate(fractional_X, v1 , v2); }
static vsString ExtractStringToken( vsString &string ) { vsAssert(string[0] == '\"', "Tried to extract a string that didn't start with \"!"); vsString result; //result.append( 1, string[0] ); // get first '"' string.erase(0,1); bool escaped = false; while( !string.empty() && string[0] ){ if ( escaped ) { if ( string[0] == 'n' ) { result.append( 1, '\n' ); } else { result.append( 1, string[0] ); } escaped = false; } else { if ( string[0] == '\"' ) { break; // end of string! } else if ( string[0] == '\\' ) { escaped = true; } else { result.append( 1, string[0] ); } } string.erase(0,1); } //result.append( 1, string[0] ); // get last '"' string.erase(0,1); return result; }
vsString fsRecord::ToString() { vsString result = m_label; result += " "; for ( int i = 0; i < m_argCount; i++ ) { if ( m_argType[i] == Arg_Float ) result += vsFormatString("%f ", m_fArg[i]); else if ( m_argType[i] == Arg_Int ) result += vsFormatString("%d ", m_iArg[i] ); else vsAssert(0, "Unknown arg type!"); } return result; }
void vsCollisionObject::SetPolygon(const vsVector2D *v, int vertexCount, const vsAngle &orientation, float density) { vsAssert( vertexCount < b2_maxPolygonVertices, "Too many vertices on collision polygon!" ); b2PolygonShape *ps = new b2PolygonShape; for ( int i = 0; i < vertexCount; i++ ) { ps->m_vertices[i].Set( v[i].x, v[i].y ); } ps->m_count = vertexCount; m_boxDef[m_boxCount].shape = ps; m_boxDef[m_boxCount].density = density; m_boxDef[m_boxCount].filter.categoryBits = m_colFlags; m_boxDef[m_boxCount].filter.maskBits = m_testFlags; m_boxDef[m_boxCount].friction = 0.1f; m_boxDef[m_boxCount].restitution = 0.3f; m_boxCount++; }
vsDisplayList * vsDisplayList::Load_Vec( vsRecord *record ) { vsDisplayList *loader = new vsDisplayList(1024 * 50); // 50k should be enough to load in just about anything. (famous last words) for( int i = 0; i < record->GetChildCount(); i++ ) { vsRecord *r = record->GetChild(i); Load_Vec_SingleRecord( loader, r ); } vsAssert(loader->GetSize() > 0.f, "Didn't get any operations in a loaded display list!" ) vsDisplayList *result = new vsDisplayList( loader->GetSize() ); result->Append(*loader); delete loader; return result; }
vsDisplayList::~vsDisplayList() { vsAssert( m_instanceCount == 0, "Deleted a display list while something was still referencing it!" ); for ( int i = 0; i < m_materialCount; i++ ) { vsDelete( m_material[i] ); } if ( m_fifo ) { delete m_fifo; m_fifo = NULL; } else if ( m_instanceParent ) { m_instanceParent->m_instanceCount--; } }
const vsVector3D & vsMatrix3x3::operator[](int n) const { if ( n == 0 ) { return x; } else if ( n == 1 ) { return y; } else if ( n == 2 ) { return z; } vsAssert(0,"ILLEGAL INDEX"); return vsVector3D::Zero; }