Pol  Revision:f37d500
object_storage.cpp
Go to the documentation of this file.
1 #include "object_storage.h"
2 
3 #include <string.h>
4 
5 #include "../objecthash.h"
6 #include "../reftypes.h"
7 #include "../uobject.h"
8 
9 namespace Pol
10 {
11 namespace Core
12 {
14 
16  : incremental_save_count( 0 ),
17  current_incremental_save( 0 ),
18  incremental_serial_index(),
19  deferred_insertions(),
20  modified_serials(),
21  deleted_serials(),
22  clean_objects( 0 ),
23  dirty_objects( 0 ),
24  incremental_saves_disabled( false ),
25  objecthash()
26 {
27 }
28 
30 
31 
33 {
34  objecthash.Clear();
36  deferred_insertions.clear();
37  modified_serials.clear();
38  deleted_serials.clear();
39 }
40 
42 {
43  ObjectHash::OH_const_iterator hs_citr = objStorageManager.objecthash.begin(),
44  hs_cend = objStorageManager.objecthash.end();
45 
46  MemoryUsage usage;
47  memset( &usage, 0, sizeof( usage ) );
48 
49  usage.objcount = std::distance( hs_citr, hs_cend );
50 
51  for ( ; hs_citr != hs_cend; ++hs_citr )
52  {
53  size_t size = ( sizeof( void* ) * 3 + 1 ) / 2;
54  const UObjectRef& ref = ( *hs_citr ).second;
55  size += ref->estimatedSize();
56  usage.objsize += size;
57  if ( ref->isa( UOBJ_CLASS::CLASS_ITEM ) )
58  {
59  usage.obj_item_size += size;
60  usage.obj_item_count++;
61  }
62  else if ( ref->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
63  {
64  usage.obj_cont_size += size;
65  usage.obj_cont_count++;
66  }
67  else if ( ref->isa( UOBJ_CLASS::CLASS_CHARACTER ) )
68  {
69  usage.obj_char_size += size;
70  usage.obj_char_count++;
71  }
72  else if ( ref->isa( UOBJ_CLASS::CLASS_NPC ) )
73  {
74  usage.obj_npc_size += size;
75  usage.obj_npc_count++;
76  }
77  else if ( ref->isa( UOBJ_CLASS::CLASS_WEAPON ) )
78  {
79  usage.obj_weapon_size += size;
80  usage.obj_weapon_count++;
81  }
82  else if ( ref->isa( UOBJ_CLASS::CLASS_ARMOR ) )
83  {
84  usage.obj_armor_size += size;
85  usage.obj_armor_count++;
86  }
87  else if ( ref->isa( UOBJ_CLASS::CLASS_MULTI ) )
88  {
89  usage.obj_multi_size += size;
90  usage.obj_multi_count++;
91  }
92  }
93 
94  usage.misc = sizeof( ObjectStorageManager );
95  usage.misc += 3 * sizeof( u32* ) + modified_serials.capacity() * sizeof( u32 );
96  usage.misc += 3 * sizeof( u32* ) + deleted_serials.capacity() * sizeof( u32 );
97 
98  usage.misc += ( sizeof( pol_serial_t ) + sizeof( unsigned ) + ( sizeof( void* ) * 3 + 1 ) / 2 ) *
100  usage.misc += ( sizeof( pol_serial_t ) + sizeof( UObject* ) + ( sizeof( void* ) * 3 + 1 ) / 2 ) *
101  deferred_insertions.size();
102 
103  return usage;
104 }
105 }
106 }
hs::const_iterator OH_const_iterator
Definition: objecthash.h:47
hs::const_iterator begin() const
Definition: objecthash.cpp:239
MemoryUsage estimateSize() const
unsigned int u32
Definition: rawtypes.h:27
std::vector< u32 > deleted_serials
std::vector< u32 > modified_serials
SerialIndexMap incremental_serial_index
u32 pol_serial_t
Definition: poltype.h:23
ObjectStorageManager objStorageManager
hs::const_iterator end() const
Definition: objecthash.cpp:244
Definition: berror.cpp:12