MeshT *NewMesh(uint32_t vertices, uint32_t polygons, uint32_t surfaces) { MeshT *mesh = NewInstance(MeshT); mesh->vertexNum = vertices; mesh->polygonNum = polygons; mesh->surfaceNum = surfaces; mesh->vertex = NewTable(Vector3D, vertices); mesh->polygon = NewTable(TriangleT, polygons); mesh->surface = NewTableOfType(SurfaceT, surfaces); return mesh; }
nsresult nsMsgSearchValidityManager::InitLocalNewsTable() { NS_ASSERTION (nsnull == m_localNewsTable, "already have local news validity table"); nsresult rv = NewTable(getter_AddRefs(m_localNewsTable)); NS_ENSURE_SUCCESS(rv, rv); return SetLocalNews(m_localNewsTable); }
void BlurV3(PixBufT *dstBuf, PixBufT *srcBuf) { uint8_t *dst = dstBuf->data; uint8_t *prev = srcBuf->data; uint8_t *next = srcBuf->data + 2 * srcBuf->width; int16_t x, y; /* at any given moment keeps a sum of three pixels */ int16_t *line = NewTable(int16_t, srcBuf->width); /* initially line is a sum of srcLine[0] and srcLine[1] */ for (x = 0; x < srcBuf->width; x++) { line[x] = srcBuf->data[x] + srcBuf->data[x + srcBuf->width]; *dst++ = DIV_BY_3(line[x]); } ASSERT(dstBuf->width == srcBuf->width, "Width does not match (%d != %d)", dstBuf->width, srcBuf->width); ASSERT(dstBuf->height == srcBuf->height, "Height does not match (%d != %d)", dstBuf->height, srcBuf->height); y = srcBuf->height - 2; do { for (x = 0; x < srcBuf->width; x++) { line[x] += *next++; *dst++ = DIV_BY_3(line[x]); line[x] -= *prev++; } } while (--y >= 0); for (x = 0; x < srcBuf->width; x++) *dst++ = DIV_BY_3(line[x]); MemUnref(line); }
BOOL IDatabase::Assign( PHDBTableInfo p,DWORD fl ) { WORD n; Flags = fl; //Tables number for( n = 0; p[n].Name; n++ ); Count = n; //Create tables Items = new PITable[ n ]; memset( Items, 0, sizeof(PITable)*Count ); for( n = 0; n < Count; p++,n++ ) { Items[n] = NewTable(p); if ( !Items[n] ) return FALSE; if ( !Items[n]->Assign(p,Flags) ) { delete Items[n]; Items[n] = NULL; return FALSE; } } return TRUE; }
PaletteT *NewPalette(size_t count) { PaletteT *palette = NewInstance(PaletteT); palette->count = count; palette->colors = NewTable(RGB, count); return palette; }
nsresult nsMsgSearchValidityManager::InitLocalABAndTable() { NS_ASSERTION(!m_localABAndTable, "don't call this twice!"); nsresult rv = NewTable(getter_AddRefs(m_localABAndTable)); NS_ENSURE_SUCCESS(rv, rv); rv = SetUpABTable(m_localABAndTable, false); NS_ENSURE_SUCCESS(rv, rv); return rv; }
nsresult nsMsgSearchValidityManager::InitLocalNewsJunkBodyTable() { NS_ASSERTION (nullptr == m_localNewsJunkBodyTable, "already have local news+junk+body validity table"); nsresult rv = NewTable(getter_AddRefs(m_localNewsJunkBodyTable)); NS_ENSURE_SUCCESS(rv, rv); rv = SetLocalNews(m_localNewsJunkBodyTable); NS_ENSURE_SUCCESS(rv, rv); rv = SetJunk(m_localNewsJunkBodyTable); NS_ENSURE_SUCCESS(rv, rv); return SetBody(m_localNewsJunkBodyTable); }
UVMapT *NewUVMap(size_t width, size_t height, UVMapTypeT type, size_t textureW, size_t textureH) { UVMapT *map = NewInstance(UVMapT); map->type = type; map->width = width; map->height = height; if (type == UV_FAST) { ASSERT(textureW == 256 && textureH == 256, "In optimized mode texture size has to be 256x256."); map->map.fast.u = NewTable(uint8_t, width * height); map->map.fast.v = NewTable(uint8_t, width * height); } else if (type == UV_NORMAL) { map->map.normal.u = NewTable(int16_t, width * height); map->map.normal.v = NewTable(int16_t, width * height); } else if (type == UV_ACCURATE) { map->map.accurate.u = NewTable(FP16, width * height); map->map.accurate.v = NewTable(FP16, width * height); } /* initially there's no texture attached */ map->textureW = textureW; map->textureH = textureH; return map; }
/* * Calculates a map from vertex index into a list of polygon the vertex belongs * to. mesh->polygon can be considered as a map from polygon number to polygon * vertices, so this procedure calculates a reverse map. */ void CalculateVertexToPolygonMap(MeshT *mesh) { IndexArrayT *vertex = NewTable(IndexArrayT, mesh->vertexNum); uint16_t *indices = NewTable(uint16_t, mesh->polygonNum * 3); int i, j; for (i = 0; i < mesh->polygonNum; i++) { TriangleT *polygon = &mesh->polygon[i]; uint16_t p1 = polygon->p[0]; uint16_t p2 = polygon->p[1]; uint16_t p3 = polygon->p[2]; vertex[p1].count++; vertex[p2].count++; vertex[p3].count++; } for (i = 0, j = 0; i < mesh->vertexNum; i++) { vertex[i].index = &indices[j]; j += vertex[i].count; } for (i = 0; i < mesh->vertexNum; i++) vertex[i].count = 0; for (i = 0; i < mesh->polygonNum; i++) { TriangleT *polygon = &mesh->polygon[i]; uint16_t p1 = polygon->p[0]; uint16_t p2 = polygon->p[1]; uint16_t p3 = polygon->p[2]; vertex[p1].index[vertex[p1].count++] = i; vertex[p2].index[vertex[p2].count++] = i; vertex[p3].index[vertex[p3].count++] = i; } mesh->vertexToPoly.vertex = vertex; mesh->vertexToPoly.indices = indices; }
void LBCommTable::Resize() { LBCommData* old_set = set; TableState* old_state = state; int old_sz = cur_sz; NewTable(old_sz*2); for(int i=0; i < old_sz; i++) { if (old_state[i] == InUse) HashInsert(old_set[i]); } delete [] old_set; delete [] old_state; }
static void Init() { canvas = NewPixBuf(PIXBUF_CLUT, WIDTH, HEIGHT); shades = NewPixBuf(PIXBUF_GRAY, WIDTH, HEIGHT); PixBufSetColorMap(shades, colorMap); uvmap = NewUVMap(WIDTH, HEIGHT, UV_FAST, 256, 256); uvmap->lightMap = shades; UVMapGenerate4(uvmap); UVMapSetTexture(uvmap, texture); component = NewPixBufWrapper(WIDTH, HEIGHT, uvmap->map.fast.u); colorFunc = NewTable(uint8_t, 256); InitDisplay(WIDTH, HEIGHT, DEPTH); LoadPalette(texturePal); }
/* * Vertex normal vector is defined as averaged normal of all adjacent polygons. * Assumption is made that each vertex belong to at least one polygon. */ void CalculateVertexNormals(MeshT *mesh) { size_t i, j; mesh->vertexNormal = NewTable(Vector3D, mesh->vertexNum); for (i = 0; i < mesh->vertexNum; i++) { Vector3D normal = { 0.0f, 0.0f, 0.0f }; for (j = 0; j < mesh->vertexToPoly.vertex[i].count; j++) { uint16_t p = mesh->vertexToPoly.vertex[i].index[j]; V3D_Add(&normal, &normal, &mesh->surfaceNormal[p]); } V3D_Normalize(&mesh->vertexNormal[i], &normal, 1.0f); } }
static uint8_t *CalculateLightFunc() { uint8_t *array = NewTable(uint8_t, 65536); int i; for (i = -32768; i < 32768; i++) { int value = i; if (value < 0) value = -value; if (value < 128) value = 128; else if (value > 255) value = 255; array[(uint16_t)i] = value; } return array; }
bool ParseValue(ParserT *parser, JsonNodeT **node_p) { TokenT *token; JsonNodeT *node = *node_p; if (!node) (*node_p) = node = NewInstance(JsonNodeT); if ((token = ParserMatch(parser, TOK_LBRACE))) { node->type = JSON_OBJECT; node->u.object.num = token->size; if (token->size) node->u.object.item = NewTable(JsonPairT, token->size); return ParseObject(parser, node); } else if ((token = ParserMatch(parser, TOK_LBRACKET))) { node->type = JSON_ARRAY; node->u.array.num = token->size; if (token->size) node->u.array.item = NewTable(JsonNodeT *, token->size); return ParseArray(parser, node); }
HashMapT *NewHashMap(size_t initialSize) { HashMapT *self = NewInstance(HashMapT); { size_t n = 0; size_t i; for (i = 0; i < sizeof(HashTableSize) / sizeof(size_t); i++) { if (HashTableSize[i] > initialSize) { n = HashTableSize[i]; break; } } if (n == 0) PANIC("Table too large (%ld)", initialSize); self->map = NewTable(EntryT, n); } return self; }
void main() { int i, size; HashTable *dict; // ispunja hash tablice razlicitih velicina svim rijecima iz datoteke for(size = 256; size < (1<<18); size *= 2) { float st, et; dict = NewTable(size); st = clock(); fillTable(dict); // PrintTable(dict); et = clock(); printf("Size = %d, load factor = %f, time = %f\n", dict->size, (float)dict->load / dict->size, (et-st)/CLOCKS_PER_SEC); DeleteTable(dict); } }
/* * For given triangle T with vertices A, B and C, surface normal N is a cross * product between vectors AB and BC. * * Ordering of vertices in polygon description is meaningful - depending on * that the normal vector will be directed inwards or outwards. * * Lightwave convention is used: * "The vertex list for each polygon should begin at a convex vertex and * proceed clockwise as seen from the visible side of the polygon." */ void CalculateSurfaceNormals(MeshT *mesh) { size_t i; if (mesh->surfaceNormal) PANIC("Already added surface normals to mesh %p.", mesh); mesh->surfaceNormal = NewTable(Vector3D, mesh->polygonNum); for (i = 0; i < mesh->polygonNum; i++) { Vector3D *normal = &mesh->surfaceNormal[i]; Vector3D u, v; size_t p1 = mesh->polygon[i].p[0]; size_t p2 = mesh->polygon[i].p[1]; size_t p3 = mesh->polygon[i].p[2]; V3D_Sub(&u, &mesh->vertex[p1], &mesh->vertex[p2]); V3D_Sub(&v, &mesh->vertex[p2], &mesh->vertex[p3]); V3D_Cross(normal, &u, &v); V3D_NormalizeToUnit(normal, normal); } }
static TokenT *ReadTokens(const char *json, int num) { LexerT lexer; TokenT *tokens = NULL; int i; LexerInit(&lexer, json); if ((tokens = NewTable(TokenT, num))) { LexerInit(&lexer, json); for (i = 0; i < num; i++) { LexerNextToken(&lexer, &tokens[i]); #ifdef DEBUG_LEXER printf("%4d: ", i); TokenPrint(&tokens[i]); #endif } TokenAssignParents(tokens, num); } return tokens; }
void BeAccessibleWindow::MessageReceived(BMessage* msg) { switch(msg->what) { case COMPACT_DATABASE_MSG: { GlobalSQLMgr->Compact(); break; } case OPEN_DATABASE_MSG: { BString path; if (msg->FindString("path", &path) == B_OK) { OpenDatabase(BPath(path.String())); } break; } case MENU_FILE_NEW_MSG: { fNewFile->Show(); break; } case MENU_FILE_OPEN_MSG: { fOpenFile->Show(); break; } case MENU_FILE_CLOSE_MSG: { CloseDatabase(); break; } case OPEN_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table" || name == "TableList") OpenTable(DATA_VIEW); //else if (name == "Query") break; } case DESIGN_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table") OpenTable(DESIGN_VIEW); //else if (name == "Query") break; } case NEW_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table") NewTable(DESIGN_VIEW); //else if (name == "Query") } case ENABLE_OPEN_BUTTON: { BString listName; msg->FindString("ListName", &listName); if (listName == "TableList") { fTableTab->fOpenButton->SetEnabled(true); fTableTab->fDesignButton->SetEnabled(true); } //else if (listName == "QueryList") break; } case DISABLE_OPEN_BUTTON: { BString listName; msg->FindString("ListName", &listName); if (listName == "TableList") { fTableTab->fOpenButton->SetEnabled(false); fTableTab->fDesignButton->SetEnabled(false); } //else if (listName == "QueryList") break; } case B_QUIT_REQUESTED: { BMessenger(be_app).SendMessage(B_QUIT_REQUESTED); break; } case IMPORT_FILE_REQUESTED_MSG: { fImportFile->SetTarget(BMessenger(this)); fImportFile->Show(); break; } case IMPORT_FILE_MSG: { entry_ref ref; msg->FindRef("refs", &ref); const BEntry entry(&ref, true); BPath dbPath(&entry); BRect frame(200,200,600,700); ImportFileWindow* importWindow = new ImportFileWindow(frame, dbPath.Path()); importWindow->Show(); break; } default: { BWindow::MessageReceived(msg); break; } } }
static void MeshCalculateEdges(MeshT *mesh) { TriangleEdgeT *edges = NewTable(TriangleEdgeT, mesh->polygonNum * 3); int i, j; { TriangleEdgeT *edge = edges; TriangleT *polygon = mesh->polygon; for (i = 0; i < mesh->polygonNum; i++, polygon++) { int16_t p0 = polygon->p[0]; int16_t p1 = polygon->p[1]; int16_t p2 = polygon->p[2]; if (p0 < p1) { edge->p[0] = p0; edge->p[1] = p1; } else { edge->p[0] = p1; edge->p[1] = p0; } edge->polygon = i; edge->vertex = 0; edge++; if (p1 < p2) { edge->p[0] = p1; edge->p[1] = p2; } else { edge->p[0] = p2; edge->p[1] = p1; } edge->polygon = i; edge->vertex = 1; edge++; if (p0 < p2) { edge->p[0] = p0; edge->p[1] = p2; } else { edge->p[0] = p2; edge->p[1] = p0; } edge->polygon = i; edge->vertex = 2; edge++; } } /* Sort all edges */ TableSort(edges, EdgeCmp, 0, mesh->polygonNum * 3 - 1); /* Count unique edges */ for (i = 1, mesh->edgeNum = 1; i < mesh->polygonNum * 3; i++) if (edges[i].p[0] != edges[i - 1].p[0] || edges[i].p[1] != edges[i - 1].p[1]) mesh->edgeNum++; { TriangleEdgeT *edge = edges; mesh->edge = NewTable(EdgeT, mesh->edgeNum); mesh->edge[0].p[0] = edge->p[0]; mesh->edge[0].p[1] = edge->p[1]; mesh->polygon[edge->polygon].e[edge->vertex] = 0; edge++; for (i = 1, j = 0; i < mesh->polygonNum * 3; i++, edge++) { if (edge[0].p[0] != edge[-1].p[0] || edge[0].p[1] != edge[-1].p[1]) { j++; mesh->edge[j].p[0] = edge->p[0]; mesh->edge[j].p[1] = edge->p[1]; } mesh->polygon[edge->polygon].e[edge->vertex] = j; } } MemUnref(edges); }
//----------------------------------------------------------------------------- nsresult nsMsgSearchValidityManager::InitLocalNewsTable() { NS_ASSERTION (nsnull == m_localNewsTable, "already have local news validty table"); nsresult err = NewTable (getter_AddRefs(m_localNewsTable)); if (NS_SUCCEEDED(err)) { m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Subject, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Subject, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Subject, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Subject, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Subject, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Subject, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Subject, nsMsgSearchOp::EndsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Subject, nsMsgSearchOp::EndsWith, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Body, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Body, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Body, nsMsgSearchOp::DoesntContain, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Body, nsMsgSearchOp::DoesntContain, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Body, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Body, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Body, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Body, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Date, nsMsgSearchOp::IsBefore, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Date, nsMsgSearchOp::IsAfter, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Date, nsMsgSearchOp::IsAfter, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Date, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Date, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::Date, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::Date, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsGreaterThan, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::IsLessThan, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::AgeInDays, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::MsgStatus, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::MsgStatus, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::MsgStatus, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::MsgStatus, nsMsgSearchOp::Isnt, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Contains, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Is, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::Is, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::BeginsWith, 1); m_localNewsTable->SetAvailable (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::EndsWith, 1); m_localNewsTable->SetEnabled (nsMsgSearchAttrib::OtherHeader, nsMsgSearchOp::EndsWith, 1); } return err; }