bufferContextChain.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Filename: bufferContextChain.cxx
  2. // Created by: drose (16Mar06)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "bufferContextChain.h"
  19. #include "bufferContext.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // Function: BufferContextChain::get_first
  22. // Access: Public
  23. // Description: Returns the first BufferContext object stored in the
  24. // tracker. You can walk through the entire list of
  25. // objects stored on the tracker by calling get_next()
  26. // on each returned object, until the return value is
  27. // NULL.
  28. ////////////////////////////////////////////////////////////////////
  29. BufferContext *BufferContextChain::
  30. get_first() {
  31. // This method is declared non-inline so we can include
  32. // bufferContext.h, which is necessary for proper downcasting of the
  33. // _next pointer.
  34. if (_next == this) {
  35. return NULL;
  36. }
  37. return (BufferContext *)_next;
  38. }
  39. ////////////////////////////////////////////////////////////////////
  40. // Function: BufferContextChain::take_from
  41. // Access: Public
  42. // Description: Moves all of the BufferContexts from the other
  43. // tracker onto this one.
  44. ////////////////////////////////////////////////////////////////////
  45. void BufferContextChain::
  46. take_from(BufferContextChain &other) {
  47. _total_size += other._total_size;
  48. _count += other._count;
  49. other._total_size = 0;
  50. other._count = 0;
  51. LinkedListNode *llnode = other._next;
  52. while (llnode != &other) {
  53. nassertv(((BufferContext *)llnode)->_owning_chain == &other);
  54. ((BufferContext *)llnode)->_owning_chain = this;
  55. llnode = ((BufferContext *)llnode)->_next;
  56. }
  57. take_list_from(&other);
  58. }