void csBulletCollider::FillWithColliderGeometry ( csRef<iGeneralFactoryState> genmesh_fact) { // @@@ TODO #if 0 switch (geomType) { case BOX_COLLIDER_GEOMETRY: { SimdTransform trans; SimdVector3 max; SimdVector3 min; BoxShape* b = (BoxShape*)pc->GetRigidBody ()->GetCollisionShape (); csBox3 box; for (int i = 0; i < b->GetNumVertices (); i++) { SimdVector3 vtx; b->GetVertex (i, vtx); box.AddBoundingVertexTest (csVector3 (vtx[0], vtx[1], vtx[2])); } genmesh_fact->GenerateBox (box); genmesh_fact->CalculateNormals (); } break; default: break; } #endif }
csPtr<iString> AssetManager::LoadDocument (iObjectRegistry* object_reg, csRef<iDocument>& doc, const char* vfspath, const char* file) { doc.Invalidate (); csRef<iVFS> vfs = csQueryRegistry<iVFS> (object_reg); if (vfspath) vfs->PushDir (vfspath); csRef<iDataBuffer> buf = vfs->ReadFile (file); if (vfspath) vfs->PopDir (); if (!buf) return 0; // No error, just a non-existing file. csRef<iDocumentSystem> docsys; docsys = csQueryRegistry<iDocumentSystem> (object_reg); if (!docsys) docsys.AttachNew (new csTinyDocumentSystem ()); doc = docsys->CreateDocument (); const char* error = doc->Parse (buf->GetData ()); if (error) { scfString* msg = new scfString ();; msg->Format ("Can't parse '%s': %s", file, error); doc.Invalidate (); return msg; } return 0; }
pawsFrameDrawable::pawsFrameDrawable(csRef<iDocumentNode> node) : scfImplementationType (this) { defaultTransparentColourBlue = -1; defaultTransparentColourGreen = -1; defaultTransparentColourRed = -1; defaultAlphaValue = 0; // Read off the image and file vars imageFileLocation = node->GetAttributeValue("file"); resourceName = node->GetAttributeValue("resource"); csString typeStr(node->GetAttributeValue("type")); type = FDT_FULL; if (typeStr == "horizontal") type = FDT_HORIZONTAL; else if (typeStr == "vertical") type = FDT_VERTICAL; csRef<iDocumentNodeIterator> iter = node->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> childNode = iter->Next(); // Read the default alpha value. if (strcmp(childNode->GetValue(), "alpha") == 0) defaultAlphaValue = childNode->GetAttributeValueAsInt("level"); // Read the default transparent colour. else if (strcmp(childNode->GetValue(), "trans") == 0) { defaultTransparentColourRed = childNode->GetAttributeValueAsInt("r"); defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g"); defaultTransparentColourBlue = childNode->GetAttributeValueAsInt("b"); } else if (strcmp(childNode->GetValue(), "top_left") == 0) LoadPiece(childNode, FDP_TOP_LEFT); else if (strcmp(childNode->GetValue(), "top") == 0) LoadPiece(childNode, FDP_TOP); else if (strcmp(childNode->GetValue(), "top_right") == 0) LoadPiece(childNode, FDP_TOP_RIGHT); else if (strcmp(childNode->GetValue(), "left") == 0) LoadPiece(childNode, FDP_LEFT); else if (strcmp(childNode->GetValue(), "middle") == 0) LoadPiece(childNode, FDP_MIDDLE); else if (strcmp(childNode->GetValue(), "right") == 0) LoadPiece(childNode, FDP_RIGHT); else if (strcmp(childNode->GetValue(), "bottom_left") == 0) LoadPiece(childNode, FDP_BOTTOM_LEFT); else if (strcmp(childNode->GetValue(), "bottom") == 0) LoadPiece(childNode, FDP_BOTTOM); else if (strcmp(childNode->GetValue(), "bottom_right") == 0) LoadPiece(childNode, FDP_BOTTOM_RIGHT); } }
void G2DTestSystemDriver::BlitTest () { int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); myG2D->SetClipRect(0,0,w,h); myG2D->DrawBox(0,0,w,h, dsteel); SetFont (fontItalic); WriteCentered (0,-16*8, white, -1, "BLIT() TEST"); SetFont (fontLarge); WriteCentered (0,-16*7, black, dsteel, "This will test whether iGraphics2D->Blit() works correctly"); WriteCentered (0,-16*6, black, dsteel, "on this canvas."); WriteCentered (0,-16*4, black, dsteel, "You should see an image of an arrow and the word %s.", CS::Quote::Double ("up")); WriteCentered (0,-16*3, black, dsteel, "It is surrounded by a green rectangle, and the image"); WriteCentered (0,-16*2, black, dsteel, "itself has a black border. No red should be visible"); WriteCentered (0,-16*1, black, dsteel, "and the border has to be complete, too."); if (blitTestImage.IsValid ()) { const int imW = blitTestImage->GetWidth (); const int imH = blitTestImage->GetHeight (); const int bx = (w - imW) / 2; const int by = h / 2; DrawClipRect (bx, by, imW + 1, imH + 1); myG2D->Blit (bx + 1, by + 1, imW, imH, (unsigned char*)blitTestImage->GetImageData ()); } }
void G2DTestSystemDriver::DrawFreetypeTest () { const char* fontFaces[] = {"DejaVuSans", "DejaVuSansBoldOblique", "DejaVuSansMono", "DejaVuSerif", 0}; const int fontSizes[] = {4, 8, 12, 24, 0}; int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); myG2D->SetClipRect(0,0,w,h); myG2D->DrawBox(0,0,w,h, dsteel); SetFont (fontItalic); int tpos = -h / 2; WriteCentered (0, tpos, white, -1, "FREETYPE2 PLUGIN TEST"); SetFont (fontLarge); WriteCentered (0, tpos + 16*2, black, -1, "If the FreeType2 plugin was built and activated in the"); WriteCentered (0, tpos + 16*3, black, -1, "g2dtest.cfg file (it is by default), you should see text"); WriteCentered (0, tpos + 16*4, black, -1, "in various faces and sizes below."); csRefArray<iFont> fonts; // The used fonts are all kept until the end of this function, to provide // some more "stress" on the font cache. int y = tpos + 16*7; int i = 0; while (fontFaces[i] != 0) { csString str; int j = 0; while (fontSizes[j] != 0) { int fW, fH; csRef<iFont> font = GetFont (fontFaces[i], fontSizes[j]); if (font) { fonts.Push (font); SetFont (font); str.Clear (); str << fontFaces[i] << ", Size " << fontSizes[j]; WriteCentered (0, y, yellow, -1, str.GetData ()); font->GetDimensions (str.GetData (), fW, fH); y += fH + 4; } j++; } i++; } SetFont (fontCourier); WriteCentered (2, 0, green, -1, "press any key to continue"); }
void csTextureList::AddBatch (csRef<iTextureLoaderIterator> itr, bool precache) { CS::Threading::ScopedWriteLock lock(texLock); while(itr->HasNext()) { iTextureWrapper* tex = itr->Next(); Push(tex); if(precache && tex->GetTextureHandle()) { tex->GetTextureHandle()->Precache(); } } }
void CopyXMLNode(csRef<iDocumentNode> source, csRef<iDocumentNode> target, int mode) { if (mode == 0) { target->RemoveNodes(); target->RemoveAttributes(); } // copy nodes csRef<iDocumentNodeIterator> nodeIter = source->GetNodes(); while (nodeIter->HasNext()) { csRef<iDocumentNode> child = nodeIter->Next(); csRef<iDocumentNode> targetChild = target->GetNode(child->GetValue()); if (targetChild==NULL || mode==3) // Mode 3 means don't merge tags but just insert multiples, so we create a new one here every time { targetChild = target->CreateNodeBefore(child->GetType()); if (targetChild == NULL) assert(!"failed to create XML node, you are probably using wrong XML parser (xmlread instead of xmltiny)"); targetChild->SetValue(child->GetValue()); } CopyXMLNode(child, targetChild, mode); } // copy attributes csRef <iDocumentAttributeIterator> attrIter = source->GetAttributes(); while (attrIter->HasNext()) { csRef<iDocumentAttribute> attr = attrIter->Next(); const char* attrName = attr->GetName(); if (mode==1 || !target->GetAttribute(attrName)) target->SetAttribute(attrName, attr->GetValue()); } }
void G2DTestSystemDriver::DrawStartupScreen () { myG2D->DrawBox (20, 20, myG2D->GetWidth () - 40, myG2D->GetHeight () - 40, blue); SetFont (fontItalic); WriteCentered (0, -20, white, -1, "WELCOME"); SetFont (fontLarge); WriteCentered (0, 0, white, -1, "to graphics canvas plugin"); WriteCentered (0, +20, white, -1, "test application"); SetFont (fontCourier); WriteCentered (2, 0, green, -1, "please wait five seconds"); }
void csMeshList::AddBatch (csRef<iMeshLoaderIterator> itr) { CS::Threading::ScopedWriteLock lock(meshLock); while(itr->HasNext()) { iMeshWrapper* obj = itr->Next(); PrepareMesh (obj); const char* name = obj->QueryObject ()->GetName (); if (name) meshes_hash.Put (name, obj); obj->QueryObject ()->AddNameChangeListener (listener); list.Push (obj); } }
void psCharAppearance::ProcessAttach(csRef<iMeshWrapper> meshWrap, csRef<iSpriteCal3DSocket> socket) { if(!socket.IsValid()) return; CS_ASSERT(socket.IsValid()); meshWrap->GetFlags().Set(CS_ENTITY_NODECAL); const char* socketName = socket->GetName(); // Given a socket name of "righthand", we're looking for a key in the form of "socket_righthand" csString keyName = "socket_"; keyName += socketName; // Variables for transform to be specified float trans_x = 0, trans_y = 0.0, trans_z = 0, rot_x = -PI/2, rot_y = 0, rot_z = 0; csRef<iObjectIterator> it = meshWrap->GetFactory()->QueryObject()->GetIterator(); while ( it->HasNext() ) { csRef<iKeyValuePair> key ( scfQueryInterface<iKeyValuePair> (it->Next())); if (key && keyName == key->GetKey()) { sscanf(key->GetValue(),"%f,%f,%f,%f,%f,%f",&trans_x,&trans_y,&trans_z,&rot_x,&rot_y,&rot_z); } } meshWrap->QuerySceneNode()->SetParent( baseMesh->QuerySceneNode ()); socket->SetMeshWrapper( meshWrap ); socket->SetTransform( csTransform(csZRotMatrix3(rot_z)*csYRotMatrix3(rot_y)*csXRotMatrix3(rot_x), csVector3(trans_x,trans_y,trans_z)) ); usedSlots.PushSmart(socketName); }
pawsImageDrawable::pawsImageDrawable(csRef<iDocumentNode> node) : scfImplementationType (this) { debugImageErrors = true; defaultTransparentColourBlue = -1; defaultTransparentColourGreen = -1; defaultTransparentColourRed = -1; defaultAlphaValue = 0; // Read off the image and file vars imageFileLocation = node->GetAttributeValue( "file" ); resourceName = node->GetAttributeValue( "resource" ); tiled = node->GetAttributeValueAsBool("tiled"); csRef<iDocumentNodeIterator> iter = node->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> childNode = iter->Next(); // Read the texture rectangle for this image. if ( strcmp( childNode->GetValue(), "texturerect" ) == 0 ) { textureRectangle.xmin = childNode->GetAttributeValueAsInt("x"); textureRectangle.ymin = childNode->GetAttributeValueAsInt("y"); int width = childNode->GetAttributeValueAsInt("width"); int height = childNode->GetAttributeValueAsInt("height"); textureRectangle.SetSize(width, height); } // Read the default alpha value. if ( strcmp( childNode->GetValue(), "alpha" ) == 0 ) { defaultAlphaValue = childNode->GetAttributeValueAsInt("level"); } // Read the default transparent colour. if ( strcmp( childNode->GetValue(), "trans" ) == 0 ) { defaultTransparentColourRed = childNode->GetAttributeValueAsInt("r"); defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g"); defaultTransparentColourBlue = childNode->GetAttributeValueAsInt("b"); } } PreparePixmap(); }
void G2DTestSystemDriver::DrawContextInfoScreen () { SetFont (fontLarge); WriteCentered (0,-16*2, white, -1, "Some information about graphics context"); WriteCentered (0,-16*1, gray, -1, "Screen size: %d x %d", myG2D->GetWidth (), myG2D->GetHeight ()); WriteCentered (0, 0, gray, -1, "Pixel format: %d BPP", myG2D->GetColorDepth()); int MinX, MinY, MaxX, MaxY; myG2D->GetClipRect (MinX, MinY, MaxX, MaxY); WriteCentered (0, 16*1, gray, -1, "Current clipping rectangle: %d,%d - %d,%d", MinX, MinY, MaxX, MaxY); SetFont (fontCourier); WriteCentered (2, 0, green, -1, "press any key to continue"); }
void csTinyXmlNode::RemoveNodes (csRef<iDocumentNodeIterator> children) { if ((node->Type() != TiDocumentNode::ELEMENT) && (node->Type() != TiDocumentNode::DOCUMENT)) return; TiDocumentNodeChildren* node_children = GetTiNodeChildren (); while (children->HasNext ()) { csRef<iDocumentNode> n = children->Next (); csTinyXmlNode* tiNode = static_cast<csTinyXmlNode*>((iDocumentNode*)n); node_children->RemoveChild (tiNode->GetTiNode ()); } lastChild = 0; }
void G2DTestSystemDriver::DrawCustomCursorScreen () { int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); myG2D->SetClipRect(0,0,w,h); myG2D->DrawBox(0,0,w,h, dsteel); SetFont (fontItalic); int tpos = -h / 2; WriteCentered (0, tpos, white, -1, "CUSTOM MOUSE CURSOR"); SetFont (fontLarge); WriteCentered (0, tpos + 16*2, black, -1, "If your current canvas supports custom mouse cursors"); WriteCentered (0, tpos + 16*3, black, -1, "you shouldn't see your systems default cursor now."); }
void G2DTestSystemDriver::DrawWindowResizeScreen () { DrawWindowScreen (); myG2D->AllowResize (true); myG2D->DrawBox (0, myG2D->GetHeight () / 2 + 16, myG2D->GetWidth (), 16 * 4, blue); SetFont (fontLarge); WriteCentered (0, 16*1, white, -1, "Now resizing should be enabled. Try to resize the"); WriteCentered (0, 16*2, white, -1, "window: you should be either unable to do it (if"); WriteCentered (0, 16*3, white, -1, "canvas driver does not support resize) or see"); WriteCentered (0, 16*4, white, -1, "the current window size in top-right corner."); SetFont (fontCourier); WriteCentered (2, 0, green, -1, "press any key to continue"); }
bool PawsManager::PlaySound(csRef<iSndSysData> sounddata) { if(!useSounds) return true; // If there is no sound loader or renderer, sound loading and playing will not be performed if (!sounddata.IsValid() || !soundrenderer.IsValid() ) return false; // Create a stream for this sound csRef<iSndSysStream> sndstream=soundrenderer->CreateStream(sounddata,CS_SND3D_DISABLE); if (!sndstream.IsValid()) return false; // This stream should unregister (and all sources) automatically when it's done playing sndstream->SetAutoUnregister(true); // Create a source just for this sound. csRef<iSndSysSource> source=soundrenderer->CreateSource(sndstream); if (!source.IsValid()) { soundrenderer->RemoveStream(sndstream); return false; } source->SetVolume(volume); sndstream->Unpause(); // Although we lose the reference, the CS sound renderer holds a reference to the source until playback is complete return true; }
void G2DTestSystemDriver::SetCustomCursor () { if (cursorPlugin) { cursorPlugin->SwitchCursor ("Hand"); } }
csRef<iStringArray> csScanPluginDirs (csPathsList* dirs, csRef<iStringArray>& plugins) { iStringArray* messages = 0; if (!plugins) plugins.AttachNew (new scfStringArray ()); for (size_t i = 0; i < dirs->Length (); i++) { iStringArray* dirMessages = 0; InternalScanPluginDir (dirMessages, (*dirs)[i].path, plugins, (*dirs)[i].scanRecursive); if (dirMessages != 0) { csString tmp; tmp.Format ("The following error(s) occured while scanning '%s':", (*dirs)[i].path.GetDataSafe ()); AppendStrVecString (messages, tmp); for (size_t i = 0; i < dirMessages->GetSize(); i++) { tmp.Format (" %s", dirMessages->Get (i)); AppendStrVecString (messages, tmp); } dirMessages->DecRef(); } } return csPtr<iStringArray> (messages); }
static void UpdateInstancingParams (bool allDataDirty, const DataArray& array, csRef<iRenderBuffer>& buffer, csShaderVariable* sv) { bool updateData = allDataDirty; if (!buffer || (buffer->GetElementCount() != array.Capacity())) { buffer = csRenderBuffer::CreateRenderBuffer (array.Capacity(), CS_BUF_STREAM, CS_BUFCOMP_FLOAT, sizeof (typename DataArray::ValueType) / sizeof(float)); sv->SetValue (buffer); updateData = true; } if (updateData) buffer->SetData (array.GetArray()); }
LayerSampler (int basemap_w, int basemap_h, MaterialLayer* layer) : textureScale (layer->texture_scale) { float layer_needed_x = float (basemap_w) / textureScale.x; float layer_needed_y = float (basemap_h) / textureScale.y; iImage* layerImage = layer->GetImage(); int mip_x = csFindNearestPowerOf2 ( int (ceil (layerImage->GetWidth() / layer_needed_x))); int mip_y = csFindNearestPowerOf2 ( int (ceil (layerImage->GetHeight() / layer_needed_y))); int mip = csMax ( csClamp (csLog2 (mip_x), csLog2 (layerImage->GetWidth()), 0), csClamp (csLog2 (mip_y), csLog2 (layerImage->GetHeight()), 0)); img = GetImageMip (layerImage, mip); img_w = img->GetWidth(); img_h = img->GetHeight(); }
void G2DTestSystemDriver::DrawCustomIconScreen () { int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); myG2D->SetClipRect(0,0,w,h); myG2D->DrawBox(0,0,w,h, dsteel); SetFont (fontItalic); int tpos = -h / 2; WriteCentered (0, tpos, white, -1, "CUSTOM WINDOW ICON"); SetFont (fontLarge); WriteCentered (0, tpos + 16*2, black, -1, "If your current canvas supports custom window icons"); WriteCentered (0, tpos + 16*3, black, -1, "the window icon should have changed."); WriteCentered (0, tpos + 16*4, black, -1, "It should look like a %s of the Crystal Space logo.", CS::Quote::Double ("shard")); }
bool psServerVitals::SendStatDRMessage(uint32_t clientnum, EID eid, int flags, csRef<PlayerGroup> group) { bool backup=0; if (flags) { backup = statsDirty ? true : false; statsDirty = flags; } else if (version % 10 == 0) // every 10th msg to this person, send everything statsDirty = DIRTY_VITAL_ALL; if (!statsDirty) return false; csArray<float> fVitals; csArray<uint32_t> uiVitals; if (statsDirty & DIRTY_VITAL_HP) fVitals.Push(PERCENT_VALUE(VITAL_HITPOINTS)); if (statsDirty & DIRTY_VITAL_HP_RATE) fVitals.Push(PERCENT_RATE(VITAL_HITPOINTS)); if (statsDirty & DIRTY_VITAL_MANA) fVitals.Push(PERCENT_VALUE(VITAL_MANA)); if (statsDirty & DIRTY_VITAL_MANA_RATE) fVitals.Push(PERCENT_RATE(VITAL_MANA)); // Physical Stamina if (statsDirty & DIRTY_VITAL_PYSSTAMINA) fVitals.Push(PERCENT_VALUE(VITAL_PYSSTAMINA)); if (statsDirty & DIRTY_VITAL_PYSSTAMINA_RATE) fVitals.Push(PERCENT_RATE(VITAL_PYSSTAMINA)); // Mental Stamina if (statsDirty & DIRTY_VITAL_MENSTAMINA) fVitals.Push(PERCENT_VALUE(VITAL_MENSTAMINA)); if (statsDirty & DIRTY_VITAL_MENSTAMINA_RATE) fVitals.Push(PERCENT_RATE(VITAL_MENSTAMINA)); if (statsDirty & DIRTY_VITAL_EXPERIENCE) uiVitals.Push(GetExp()); if (statsDirty & DIRTY_VITAL_PROGRESSION) uiVitals.Push(GetPP()); psStatDRMessage msg(clientnum, eid, fVitals, uiVitals, ++version, statsDirty); if (group == NULL) msg.SendMessage(); else group->Broadcast(msg.msg); statsDirty = backup; return true; }
csString GetNodeXML(csRef<iDocumentNode> node, bool childrenOnly) { psString xml; csRef<iDocumentNodeIterator> nodes; csRef<iDocumentAttributeIterator> attrs; if (!childrenOnly) xml.Format("<%s", node->GetValue()); attrs = node->GetAttributes(); while (attrs->HasNext()) { csRef<iDocumentAttribute> attr = attrs->Next(); csString escpxml = EscpXML(attr->GetValue()); xml.AppendFmt(" %s=\"%s\"", attr->GetName(), escpxml.GetData() ); } if (!childrenOnly) xml += ">"; nodes = node->GetNodes(); if (nodes->HasNext()) { while (nodes->HasNext()) { csRef<iDocumentNode> child = nodes->Next(); if (child->GetType() == CS_NODE_TEXT) { // add the node-content to the string..but escape special XML chars in it xml += EscpXML(child->GetContentsValue()); } else { xml += GetNodeXML(child); } } } if (!childrenOnly) { // add the node-content to the string..but escape special XML chars in it xml += EscpXML(node->GetContentsValue()); xml.AppendFmt("</%s>", node->GetValue()); } return xml; }
void G2DTestSystemDriver::DrawClipRect(int sx, int sy, int sw, int sh) { myG2D->DrawLine (sx, sy, sx + sw, sy, green); myG2D->DrawLine (sx, sy + sh, sx + sw, sy + sh, green); myG2D->DrawLine (sx, sy, sx, sy + sh, green); myG2D->DrawLine (sx + sw, sy, sx + sw, sy + sh, green); myG2D->DrawLine (sx+1, sy+1, sx + sw-1, sy+1, red); myG2D->DrawLine (sx+1, sy + sh-1, sx + sw-1, sy + sh-1, red); myG2D->DrawLine (sx+1, sy+1, sx+1, sy + sh-1, red); myG2D->DrawLine (sx + sw - 1, sy+1, sx + sw - 1, sy + sh-1, red); }
void G2DTestSystemDriver::DrawTextTest () { // Draw a grid of lines so that transparent text background will be visible int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); int i; for (i = 0; i < w; i += 4) { myG2D->DrawLine (float(i), 0.0f, float(i) + 50.0f, float(h), dsteel); myG2D->DrawLine (float(w - i), 0.0f, float(w - i) - 50.0f, float(h), dsteel); } SetFont (fontItalic); WriteCentered (0,-16*7, white, -1, "TEXT DRAWING TEST"); SetFont (fontLarge); WriteCentered (0,-16*5, blue, -1, "This is blue text with transparent background"); WriteCentered (0,-16*4, green, blue, "This is green text on blue background"); WriteCentered (0,-16*3, yellow, gray, "Yellow text on gray background"); WriteCentered (0,-16*2, red, black, "Red text on black background"); WriteCentered (0,-16*1, black, white, "Black text on white background"); SetFont (fontCourier); int sx = 0, sy = h / 2 + 48, sw = w, sh = h / 2 - 48; myG2D->DrawBox (sx, sy, sw, sh, dsteel); const char *text = "Crystal Space rulez"; int tw, th; font->GetDimensions (text, tw, th); size_t cc = strlen (text); // Test text drawing performance for 1/4 seconds int colors [4] = { red, green, blue, yellow }; sx += 20; sw -= 40 + tw; sy += 10; sh -= 20 + th; csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; size_t char_count = 0; do { for (i = 0; i < 2000; i++) { float x = sx + rng.Get () * sw; float y = sy + rng.Get () * sh; myG2D->Write (font, int(x), int(y), colors [rng.Get (4)], black, text); char_count += cc; } myG2D->PerformExtension ("flush"); delta_time = csGetTicks () - start_time; } while (delta_time < 500); float perf = char_count * (1000.0f / delta_time); SetFont (fontLarge); WriteCentered (0, 16*1, green, black, " Performance: %20.1f characters/second ", perf); }
void Run() { { CS::Threading::MutexScopedLock lock (doneMutex); // construct the netManager is its own thread to avoid wrong warnings of dynamic thread checking via valgrind netManager.AttachNew(new NetManager(thread)); if (!netManager->Initialize(client_firstmsg, npcclient_firstmsg, timeout)) { Error1 ("Network thread initialization failed!\nIs there already a server running?"); delete netManager; netManager = NULL; initDone.NotifyAll(); return; } initDone.NotifyAll(); } /* run the network loop */ netManager->Run(); }
csRef < iDocumentNode > MD32spr::CreateValueNode(csRef < iDocumentNode > &parent, const char *name, const char *value) { csRef < iDocumentNode > child = parent->CreateNodeBefore(CS_NODE_ELEMENT, 0); child->SetValue(name); csRef < iDocumentNode > text = child->CreateNodeBefore(CS_NODE_TEXT, 0); text->SetValue(value); return child; }
int G2DTestSystemDriver::MakeColor (int r, int g, int b, int a) { /*if (!pfmt.PalEntries) return ((r >> (8 - pfmt.RedBits)) << pfmt.RedShift) | ((g >> (8 - pfmt.GreenBits)) << pfmt.GreenShift) | ((b >> (8 - pfmt.BlueBits)) << pfmt.BlueShift) | ((a >> (8 - pfmt.AlphaBits)) << pfmt.AlphaShift); // In paletted mode this is easy since we have a uniform 3-3-2 palette return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);*/ return myG2D->FindRGB (r, g, b, a); }
void G2DTestSystemDriver::WriteCentered (int mode, int dy, int fg, int bg, const char *format, ...) { if (!font) return; csString text; va_list arg; va_start (arg, format); text.FormatV (format, arg); va_end (arg); int fw, fh; font->GetDimensions (text, fw, fh); int x = (myG2D->GetWidth () - fw) / 2; int y = 0; switch (mode) { case 0: // centered by Y y = dy + myG2D->GetHeight () / 2; break; case 1: // from top y = dy; break; case 2: // from bottom y = dy + (myG2D->GetHeight () - 1 - fh); break; } myG2D->Write (font, x, y + fh - font->GetDescent(), fg, bg, text, CS_WRITE_BASELINE); }
void G2DTestSystemDriver::PixelClipTest () { int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); int sx = w/4, sy = h / 2 + 60, sw = w/2, sh = h / 4 - 60; myG2D->SetClipRect(0,0,w,h); myG2D->DrawBox(0,0,w,h, dsteel); SetFont (fontItalic); WriteCentered (0,16*-12, white, -1, "PIXEL CLIP TEST"); SetFont (fontLarge); WriteCentered (0,16*-10, black, dsteel, "This will test if pixel clipping is being done properly"); WriteCentered (0,16*-8, black, dsteel, "For each of the following clip tests we will be drawing"); WriteCentered (0,16*-7, black, dsteel, "a 1 pixel wide green rectangle with a 1 pixel wide red rectangle"); WriteCentered (0,16*-6, black, dsteel, "inside of it."); WriteCentered (0,16*-4, black, dsteel, "The clipping rectangle has been set so the red rectangle is"); WriteCentered (0,16*-3, black, dsteel, "inside the clipping region. If any of the lines of the red rectangle"); WriteCentered (0,16*-2, black, dsteel, "are solid (not drawn over) then the clipping region is cutting off too much"); WriteCentered (0,16*0, black, dsteel, "The green rectangle is outside the clipping region. If any of the lines"); WriteCentered (0,16*1, black, dsteel, "of the green rectangle are being drawn over then the clipping region is"); WriteCentered (0,16*2, black, dsteel, "not clipping enough."); SetFont (fontCourier); DrawClipRect(sx, sy, sw, sh); myG2D->SetClipRect(sx + 1, sy + 1, sx + sw, sy + sh); // Test random pixel drawing csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; // widen the range where we try to draw pixels sx -= 10; sy -= 10; sw += 20; sh += 20; do { int i; for (i = 0; i < 1000; i++) { int x = int(sx + rng.Get () * sw); int y = int(sy + rng.Get () * sh); myG2D->DrawPixel(x,y,black); } delta_time = csGetTicks () - start_time; } while (delta_time < 100); }