void P_SetYellowMessage(player_t* pl, int flags, const char* msg) { #define YELLOW_FMT "{r=1;g=0.7;b=0.3;}" #define YELLOW_FMT_LEN 18 size_t len; AutoStr* buf; if(!msg || !msg[0]) return; len = strlen(msg); buf = AutoStr_NewStd(); Str_Reserve(buf, YELLOW_FMT_LEN + len+1); Str_Set(buf, YELLOW_FMT); Str_Appendf(buf, "%s", msg); ST_LogPost(pl - players, flags, Str_Text(buf)); if(pl == &players[CONSOLEPLAYER] && cfg.echoMsg) Con_FPrintf(CPF_CYAN, "%s\n", msg); // Servers are responsible for sending these messages to the clients. /// @todo We shouldn't need to send the format string along with every /// important game message. Instead flag a bit in the packet and then /// reconstruct on the other end. NetSv_SendMessage(pl - players, Str_Text(buf)); #undef YELLOW_FMT }
void Str_Read(ddstring_t *str, Reader *reader) { size_t len = Reader_ReadUInt32(reader); char *buf = malloc(len + 1); Reader_Read(reader, buf, len); buf[len] = 0; Str_Set(str, buf); free(buf); }
void SaveInfo_Read(SaveInfo *info, Reader *reader) { saveheader_t *hdr; DENG_ASSERT(info != 0); hdr = &info->header; hdr->magic = Reader_ReadInt32(reader); hdr->version = Reader_ReadInt32(reader); hdr->gameMode = (gamemode_t)Reader_ReadInt32(reader); if(hdr->version >= 10) { Str_Read(&info->name, reader); } else { // Older formats use a fixed-length name (24 characters). #define OLD_NAME_LENGTH 24 char buf[OLD_NAME_LENGTH]; Reader_Read(reader, buf, OLD_NAME_LENGTH); Str_Set(&info->name, buf); #undef OLD_NAME_LENGTH } hdr->skill = Reader_ReadByte(reader); hdr->episode = Reader_ReadByte(reader); hdr->map = Reader_ReadByte(reader); hdr->deathmatch = Reader_ReadByte(reader); hdr->noMonsters = Reader_ReadByte(reader); #if __JHEXEN__ hdr->randomClasses = Reader_ReadByte(reader); #endif #if !__JHEXEN__ hdr->respawnMonsters = Reader_ReadByte(reader); // Older formats serialize the unpacked saveheader_t struct; skip the junk values (alignment). if(hdr->version < 10) SV_Seek(2); hdr->mapTime = Reader_ReadInt32(reader); { int i; for(i = 0; i < MAXPLAYERS; ++i) { hdr->players[i] = Reader_ReadByte(reader); }} #endif info->gameId = Reader_ReadInt32(reader); #if __JDOOM__ || __JHERETIC__ // Translate gameMode identifiers from older save versions. translateLegacyGameMode(&hdr->gameMode, hdr->version); #endif }
boolean Demo_BeginPlayback(const char* fileName) { ddstring_t buf; if(playback) return false; // Already in playback. if(netGame || isClient) return false; // Can't do it. // Check that we aren't recording anything. { int i; for(i = 0; i < DDMAXPLAYERS; ++i) { if(clients[i].recording) return false; }} // Compose the real file name. Str_InitStd(&buf); Str_Set(&buf, fileName); if(!F_IsAbsolute(&buf)) { Str_Prepend(&buf, demoPath); } F_ExpandBasePath(&buf, &buf); F_ToNativeSlashes(&buf, &buf); // Open the demo file. playdemo = lzOpen(Str_Text(&buf), "rp"); Str_Free(&buf); if(!playdemo) return false; // Failed to open the file. // OK, let's begin the demo. playback = true; isServer = false; isClient = true; readInfo.first = true; viewangleDelta = 0; lookdirDelta = 0; demoFrameZ = 1; demoZ = 0; startFOV = fieldOfView; demoStartTic = DEMOTIC; memset(posDelta, 0, sizeof(posDelta)); // Start counting frames from here. /* if(ArgCheck("-timedemo")) r_framecounter = 0; */ return true; }
static void SaveInfo_Read_Hr_v13(SaveInfo* info, Reader* reader) { saveheader_t* hdr = &info->header; char nameBuffer[V13_SAVESTRINGSIZE]; char vcheck[VERSIONSIZE]; int i; assert(info); Reader_Read(reader, nameBuffer, V13_SAVESTRINGSIZE); nameBuffer[V13_SAVESTRINGSIZE - 1] = 0; Str_Set(&info->name, nameBuffer); Reader_Read(reader, vcheck, VERSIONSIZE); //assert(!strncmp(vcheck, "version ", 8)); // Ensure save state format has been recognised by now. hdr->version = atoi(&vcheck[8]); hdr->skill = (skillmode_t) Reader_ReadByte(reader); // Interpret skill levels outside the normal range as "spawn no things". if(hdr->skill < SM_BABY || hdr->skill >= NUM_SKILL_MODES) hdr->skill = SM_NOTHINGS; hdr->episode = Reader_ReadByte(reader)-1; hdr->map = Reader_ReadByte(reader)-1; for(i = 0; i < 4; ++i) { hdr->players[i] = Reader_ReadByte(reader); } memset(&hdr->players[4], 0, sizeof(*hdr->players) * (MAXPLAYERS-4)); // Get the map time. { int a = Reader_ReadByte(reader); int b = Reader_ReadByte(reader); int c = Reader_ReadByte(reader); hdr->mapTime = (a << 16) + (b << 8) + c; } hdr->magic = 0; // Initialize with *something*. /// @note Older formats do not contain all needed values: hdr->gameMode = gameMode; // Assume the current mode. hdr->deathmatch = 0; hdr->noMonsters = 0; hdr->respawnMonsters = 0; info->gameId = 0; // None. }
static void readUri(Uri* uri, Reader* reader, de::String defaultScheme = "") { Uri_Clear(uri); ddstring_t scheme; Str_InitStd(&scheme); Str_Read(&scheme, reader); ddstring_t path; Str_InitStd(&path); Str_Read(&path, reader); if(Str_IsEmpty(&scheme) && !defaultScheme.isEmpty()) { Str_Set(&scheme, defaultScheme.toUtf8().constData()); } Uri_SetScheme(uri, Str_Text(&scheme)); Uri_SetPath (uri, Str_Text(&path )); }
void SaveInfo_Read_Hx_v9(SaveInfo *info, Reader *reader) { # define HXS_VERSION_TEXT "HXS Ver " // Do not change me! # define HXS_VERSION_TEXT_LENGTH 16 # define HXS_NAME_LENGTH 24 char verText[HXS_VERSION_TEXT_LENGTH], nameBuffer[HXS_NAME_LENGTH]; saveheader_t *hdr; DENG_ASSERT(info != 0); hdr = &info->header; Reader_Read(reader, nameBuffer, HXS_NAME_LENGTH); Str_Set(&info->name, nameBuffer); Reader_Read(reader, &verText, HXS_VERSION_TEXT_LENGTH); hdr->version = atoi(&verText[8]); /*Skip junk*/ SV_Seek(4); hdr->episode = 1; hdr->map = Reader_ReadByte(reader); hdr->skill = Reader_ReadByte(reader); hdr->deathmatch = Reader_ReadByte(reader); hdr->noMonsters = Reader_ReadByte(reader); hdr->randomClasses = Reader_ReadByte(reader); hdr->magic = MY_SAVE_MAGIC; // Lets pretend... /// @note Older formats do not contain all needed values: hdr->gameMode = gameMode; // Assume the current mode. info->gameId = 0; // None. # undef HXS_NAME_LENGTH # undef HXS_VERSION_TEXT_LENGTH # undef HXS_VERSION_TEXT }
SequenceCompleteCommandHandler(const char* _commandTemplate) { Str_Set(Str_InitStd(&commandTemplate), _commandTemplate); }
AutoStr *AutoStr_FromTextStd(const char *text) { return Str_Set(AutoStr_NewStd(), text); }
AutoStr *AutoStr_FromText(char const *text) { return Str_Set(AutoStr_New(), text); }
/// @note Derived from Qt's QByteArray q_toPercentEncoding ddstring_t *Str_PercentEncode2(ddstring_t *str, char const *excludeChars, char const *includeChars) { dd_bool didEncode = false; int i, span, begin, len; ddstring_t buf; DENG_ASSERT(str); if(!str) return 0; if(Str_IsEmpty(str)) return str; len = Str_Length(str); begin = span = 0; for(i = 0; i < len; ++i) { char ch = str->str[i]; // Are we encoding this? if(((ch >= 0x61 && ch <= 0x7A) // ALPHA || (ch >= 0x41 && ch <= 0x5A) // ALPHA || (ch >= 0x30 && ch <= 0x39) // DIGIT || ch == 0x2D // - || ch == 0x2E // . || ch == 0x5F // _ || ch == 0x7E // ~ || (excludeChars && strchr(excludeChars, ch))) && !(includeChars && strchr(includeChars, ch))) { // Not an encodeable. Span grows. span++; } else { // Found an encodeable. if(!didEncode) { Str_InitStd(&buf); Str_Reserve(&buf, len*3); // Worst case. didEncode = true; } Str_PartAppend(&buf, str->str, begin, span); Str_Appendf(&buf, "%%%X", (uint)ch); // Start a new span. begin += span + 1; span = 0; } } if(didEncode) { // Copy anything remaining. if(span) { Str_PartAppend(&buf, str->str, begin, span); } Str_Set(str, Str_Text(&buf)); Str_Free(&buf); } return str; }
ddstring_t *Str_Clear(ddstring_t *str) { return Str_Set(str, ""); }
BOOL PASCAL TV_SortCB(PTREE pTree, TV_SORTCB FAR *pSortCB, BOOL bRecurse, PFNDPACOMPARE lpfnDPACompare) { HDPA dpaSort; HDSA dsaCmp; HTREEITEM hItem, hNext, hFirstMoved; LPTVCOMPARE psCompare, FAR *ppsCompare; int i, cKids; HTREEITEM hParent = pSortCB->hParent; #ifdef DEBUG DWORD dwTime = GetTickCount(); nCompares = 0; #endif if (!hParent || hParent == TVI_ROOT) hParent = pTree->hRoot; // Code below assumes at least one kid cKids = TV_CountKids(hParent); if (!cKids) return FALSE; // Create a DSA for all the extra info we'll need dsaCmp = DSA_Create(sizeof(TVCOMPARE), cKids); if (!dsaCmp) goto Error1; // Create a DPA containing all the tree items dpaSort = DPA_Create(cKids); if (!dpaSort) goto Error2; for (hItem = hParent->hKids; hItem; hItem = hItem->hNext) { TVCOMPARE sCompare; int nItem; // If I can't sort all of them, I don't want to sort any of them // We want to cache the text callback for default processing if (!lpfnDPACompare && hItem->lpstr==LPSTR_TEXTCALLBACK) { TV_ITEM sItem; TCHAR szTemp[MAX_PATH]; sItem.pszText = szTemp; sItem.cchTextMax = ARRAYSIZE(szTemp); TV_GetItem(pTree, hItem, TVIF_TEXT, &sItem); sCompare.lpstr = NULL; sCompare.bCallBack = TRUE; Str_Set(&sCompare.lpstr, sItem.pszText); if (!sCompare.lpstr) { goto Error3; } } else { sCompare.lpstr = hItem->lpstr; sCompare.bCallBack = FALSE; } // Create the pointer for this guy and add it to the DPA list sCompare.hItem = hItem; nItem = DSA_InsertItem(dsaCmp, 0x7fff, &sCompare); if (nItem < 0) { if (sCompare.bCallBack) { Str_Set(&sCompare.lpstr, NULL); } goto Error3; } if (DPA_InsertPtr(dpaSort, 0x7fff, DSA_GetItemPtr(dsaCmp, nItem)) < 0) { goto Error3; } } // Sort the DPA, then stick them back under the parent in the new order DPA_Sort(dpaSort, lpfnDPACompare ? (PFNDPACOMPARE)lpfnDPACompare : (PFNDPACOMPARE) TV_DefCompare, (LPARAM)pSortCB); // Look for the first moved item, so we can invalidate a smaller area ppsCompare = (LPTVCOMPARE FAR *)DPA_GetPtrPtr(dpaSort); if (hParent->hKids != (*ppsCompare)->hItem) { hParent->hKids = (*ppsCompare)->hItem; hFirstMoved = hParent->hKids; } else { hFirstMoved = NULL; } // We do n-1 iterations here for (i = DPA_GetPtrCount(dpaSort) - 1; i > 0; --i, ++ppsCompare) { hNext = (*(ppsCompare+1))->hItem; if ((*ppsCompare)->hItem->hNext != hNext && !hFirstMoved) { hFirstMoved = hNext; } (*ppsCompare)->hItem->hNext = hNext; } (*ppsCompare)->hItem->hNext = NULL; TV_UpdateShownIndexes(pTree, hParent); if ((pSortCB->hParent == TVI_ROOT) || !hParent) { if (pTree->cShowing < pTree->cFullVisible) { pTree->hTop = pTree->hRoot->hKids; } } if (hFirstMoved && (hParent->state & TVIS_EXPANDED)) { RECT rcUpdate; TV_GetItemRect(pTree, hFirstMoved, &rcUpdate, FALSE); if (hParent->hNext) { RECT rcTemp; TV_GetItemRect(pTree, hParent->hNext, &rcTemp, FALSE); rcUpdate.bottom = rcTemp.bottom; } else { RECT rcClient; GetClientRect(pTree->ci.hwnd, &rcClient); // Set to maximal positive number, so the whole rest of // the treeview gets invalidated rcUpdate.bottom = rcClient.bottom; } if (pTree->fRedraw) InvalidateRect(pTree->ci.hwnd, &rcUpdate, TRUE); } Error3: DPA_Destroy(dpaSort); Error2: for (i = DSA_GetItemCount(dsaCmp) - 1; i >= 0; --i) { psCompare = DSA_GetItemPtr(dsaCmp, i); if (psCompare->bCallBack) { Str_Set(&(psCompare->lpstr), NULL); } } DSA_Destroy(dsaCmp); Error1: #ifdef DEBUG DebugMsg(DM_TRACE, TEXT("tv.sort: %ld ms; %d cmps"), GetTickCount()-dwTime, nCompares); #endif { int wNewPos; // restore the scroll position if (GetWindowStyle(pTree->ci.hwnd) & WS_VSCROLL) { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; wNewPos = 0; if (GetScrollInfo(pTree->ci.hwnd, SB_VERT, &si)) { wNewPos = si.nPos; } } else { wNewPos = 0; } if (TV_SetTopItem(pTree, wNewPos)) UpdateWindow(pTree->ci.hwnd); } // if the caret is the child of the thing that was sorted, make sure it's // visible (but if we're sorting something completely unrelated, don't bother if (pTree->hCaret) { hItem = pTree->hCaret; do { // do this first. if hParent is hCaret, we don't want to ensure visible... // only if it's an eventual child hItem = hItem->hParent; if (hParent == hItem) { TV_EnsureVisible(pTree, pTree->hCaret); } } while(hItem && hItem != pTree->hRoot); } return TRUE; }