CSTRAW.CPP 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/CSTRAW.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : CSTRAW.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 11/10/96 *
  26. * *
  27. * Last Update : November 10, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * CacheStraw::Get -- Fetch data from the data source. *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #include "cstraw.h"
  34. #include <string.h>
  35. /***********************************************************************************************
  36. * CacheStraw::Get -- Fetch data from the data source. *
  37. * *
  38. * This will supply the data quantity requested. It performs a regulating influence on the *
  39. * data requests passed through it. The data is requested from the next straw in the *
  40. * chain such that the data stream is requested in chunks. This serves to lessen the *
  41. * impact of multiple small data requests. *
  42. * *
  43. * INPUT: source -- Pointer to the buffer to hold the data. *
  44. * *
  45. * slen -- The number of data bytes requested. *
  46. * *
  47. * OUTPUT: Returns with the number of data bytes stored into the buffer specified. If this *
  48. * number is less than that requested, it indicates that the data source has been *
  49. * exhausted. *
  50. * *
  51. * WARNINGS: none *
  52. * *
  53. * HISTORY: *
  54. * 11/10/1996 JLB : Created. *
  55. *=============================================================================================*/
  56. int CacheStraw::Get(void * source, int slen)
  57. {
  58. int total = 0;
  59. if (Is_Valid() && source != NULL && slen > 0) {
  60. /*
  61. ** Keep processing the data request until there is no more data to supply or the request
  62. ** has been fulfilled.
  63. */
  64. while (slen > 0) {
  65. /*
  66. ** First try to fetch the data from data previously loaded into the buffer.
  67. */
  68. if (Length > 0) {
  69. int tocopy = (Length < slen) ? Length : slen;
  70. memmove(source, ((char *)BufferPtr.Get_Buffer()) + Index, tocopy);
  71. slen -= tocopy;
  72. Index += tocopy;
  73. total += tocopy;
  74. Length -= tocopy;
  75. source = (char*)source + tocopy;
  76. }
  77. if (slen == 0) break;
  78. /*
  79. ** Since there is more to be fulfilled yet the holding buffer is empty,
  80. ** refill the buffer with a fresh block of data from the source.
  81. */
  82. Length = Straw::Get(BufferPtr, BufferPtr.Get_Size());
  83. Index = 0;
  84. if (Length == 0) break;
  85. }
  86. }
  87. return(total);
  88. }