-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathBlueObjectProxy.cpp
More file actions
151 lines (126 loc) · 3.21 KB
/
Copy pathBlueObjectProxy.cpp
File metadata and controls
151 lines (126 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright © 2014 CCP ehf.
#include "StdAfx.h"
#include "BlueObjectProxy.h"
#include <BlueStatistics.h>
#include "IBlueOS.h"
#include "IUnloadable.h"
BlueObjectProxy::BlueObjectProxy() :
m_objectMarker( 0 ),
m_lastTimeUsed( 0 ),
m_temporary( false ),
m_isUnloaded( false )
{
}
BlueObjectProxy::~BlueObjectProxy()
{
// note: no need to call OnObjectInvalidated() to notify the builder;
// if it was hanging on to the proxy, we wouldn't get here in the first place (refcount > 0)
}
void BlueObjectProxy::OnObjectInvalidated()
{
if( m_object && m_builder)
{
m_builder->OnObjectDestroyed( m_objectMarker, this );
}
}
void BlueObjectProxy::SetBuilder( IBlueObjectBuilder* builder, unsigned int objectMarker )
{
OnObjectInvalidated(); // make sure any old builders let go
m_builder = builder;
m_objectMarker = objectMarker;
}
IRoot* BlueObjectProxy::GetObject( )
{
if( m_isUnloaded && m_object )
{
CCP_STATS_ZONE( CCP_STRINGIZE( __FUNCTION__ ) "ReloadWhenReferenced" );
IUnloadablePtr objectAsUnloadable = BlueCastPtr( m_object );
// Shouldn't need a nullptr check here - m_isUnloaded only becomes true if this
// interface is supported.
objectAsUnloadable->ReloadWhenReferenced();
m_isUnloaded = false;
}
if( !m_object && m_builder )
{
CCP_STATS_ZONE( CCP_STRINGIZE( __FUNCTION__ ) "CreateObject" );
m_object.Attach( m_builder->CreateObject( m_objectMarker, this ) );
}
m_lastTimeUsed = BeOS->GetInfo()->mRealTime;
return m_object;
}
void BlueObjectProxy::ClearObject()
{
OnObjectInvalidated();
m_object = NULL;
}
bool BlueObjectProxy::Update( Be::Time time, Be::Time timeout )
{
if( m_isUnloaded )
{
return false;
}
// If there is a time out set and we have a builder to reconstruct
// the object we null out the object if it hasn't been used for
// the given time out period.
if( m_object && timeout && m_builder )
{
// Don't operate on the time we're given, it's sim time and we're operating in real time here.
Be::Time delta = BeOS->GetInfo()->mRealTime - m_lastTimeUsed;
if( delta > timeout )
{
OnObjectInvalidated();
IUnloadablePtr objectAsUnloadable = BlueCastPtr( m_object );
if( objectAsUnloadable )
{
CCP_STATS_ZONE( CCP_STRINGIZE( __FUNCTION__ ) "UnloadWhenUnreferenced" );
objectAsUnloadable->UnloadWhenUnreferenced();
m_isUnloaded = true;
}
else
{
m_object = NULL;
}
return true;
}
}
return false;
}
bool BlueObjectProxy::IsResident() const
{
return m_object != NULL;
}
void BlueObjectProxy::SetTemporary( bool isTemporary )
{
m_temporary = isTemporary;
}
bool BlueObjectProxy::IsTemporary() const
{
return m_temporary;
}
void BlueObjectProxy::OnSelected()
{
if( m_builder)
{
m_builder->OnSelected( m_objectMarker, this );
}
}
void BlueObjectProxy::SetObject( IRoot* obj )
{
OnObjectInvalidated();
m_object = obj;
m_builder.Unlock();
}
void BlueObjectProxy::SetObjectFromBuilder( IRoot * obj )
{
m_object = obj;
}
void BlueObjectProxy::Freeze()
{
//TODO document that this can't work well with async builders? since it's a contradiction..
// .. or somehow support the freezing in the builder?
if( !m_object && m_builder )
{
m_object.Attach( m_builder->CreateObject( m_objectMarker, this ) );
}
m_builder.Unlock();
}