2014-10-27 18:43:09 -04:00
|
|
|
/*
|
|
|
|
AngelCode Scripting Library
|
2017-11-20 08:02:33 -05:00
|
|
|
Copyright (c) 2003-2015 Andreas Jonsson
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you
|
|
|
|
must not claim that you wrote the original software. If you use
|
|
|
|
this software in a product, an acknowledgment in the product
|
|
|
|
documentation would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
|
|
|
|
The original version of this library can be located at:
|
|
|
|
http://www.angelcode.com/angelscript/
|
|
|
|
|
|
|
|
Andreas Jonsson
|
|
|
|
andreas@angelcode.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "as_config.h"
|
|
|
|
#include "as_property.h"
|
|
|
|
#include "as_scriptengine.h"
|
|
|
|
|
|
|
|
BEGIN_AS_NAMESPACE
|
|
|
|
|
|
|
|
asCGlobalProperty::asCGlobalProperty()
|
|
|
|
{
|
|
|
|
memory = &storage;
|
|
|
|
memoryAllocated = false;
|
|
|
|
realAddress = 0;
|
|
|
|
initFunc = 0;
|
|
|
|
accessMask = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
refCount.set(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
asCGlobalProperty::~asCGlobalProperty()
|
|
|
|
{
|
2015-05-11 19:40:43 -04:00
|
|
|
#ifndef WIP_16BYTE_ALIGNED
|
2014-10-27 18:43:09 -04:00
|
|
|
if( memoryAllocated ) { asDELETEARRAY(memory); }
|
2015-05-11 19:40:43 -04:00
|
|
|
#else
|
|
|
|
if( memoryAllocated ) { asDELETEARRAYALIGNED(memory); }
|
|
|
|
#endif
|
|
|
|
|
2014-10-27 18:43:09 -04:00
|
|
|
if( initFunc )
|
2015-05-11 19:40:43 -04:00
|
|
|
initFunc->ReleaseInternal();
|
2014-10-27 18:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void asCGlobalProperty::AddRef()
|
|
|
|
{
|
|
|
|
refCount.atomicInc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void asCGlobalProperty::Release()
|
|
|
|
{
|
2015-05-11 19:40:43 -04:00
|
|
|
if( refCount.atomicDec() == 0 )
|
|
|
|
asDELETE(this, asCGlobalProperty);
|
|
|
|
}
|
2014-10-27 18:43:09 -04:00
|
|
|
|
2015-05-11 19:40:43 -04:00
|
|
|
void asCGlobalProperty::DestroyInternal()
|
|
|
|
{
|
|
|
|
if( initFunc )
|
2014-10-27 18:43:09 -04:00
|
|
|
{
|
2015-05-11 19:40:43 -04:00
|
|
|
initFunc->ReleaseInternal();
|
2014-10-27 18:43:09 -04:00
|
|
|
initFunc = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *asCGlobalProperty::GetAddressOfValue()
|
|
|
|
{
|
|
|
|
return memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The global property structure is responsible for allocating the storage
|
|
|
|
// method for script declared variables. Each allocation is independent of
|
|
|
|
// other global properties, so that variables can be added and removed at
|
|
|
|
// any time.
|
|
|
|
void asCGlobalProperty::AllocateMemory()
|
|
|
|
{
|
|
|
|
if( type.GetSizeOnStackDWords() > 2 )
|
|
|
|
{
|
2015-05-11 19:40:43 -04:00
|
|
|
#ifndef WIP_16BYTE_ALIGNED
|
2014-10-27 18:43:09 -04:00
|
|
|
memory = asNEWARRAY(asDWORD, type.GetSizeOnStackDWords());
|
2015-05-11 19:40:43 -04:00
|
|
|
#else
|
|
|
|
// TODO: Avoid aligned allocation if not needed to reduce the waste of memory for the alignment
|
|
|
|
memory = asNEWARRAYALIGNED(asDWORD, type.GetSizeOnStackDWords(), type.GetAlignment());
|
|
|
|
#endif
|
2014-10-27 18:43:09 -04:00
|
|
|
memoryAllocated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void asCGlobalProperty::SetRegisteredAddress(void *p)
|
|
|
|
{
|
2015-05-11 19:40:43 -04:00
|
|
|
realAddress = p;
|
2014-10-27 18:43:09 -04:00
|
|
|
if( type.IsObject() && !type.IsReference() && !type.IsObjectHandle() )
|
|
|
|
{
|
|
|
|
// The global property is a pointer to a pointer
|
|
|
|
memory = &realAddress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memory = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *asCGlobalProperty::GetRegisteredAddress() const
|
|
|
|
{
|
|
|
|
return realAddress;
|
|
|
|
}
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
void asCGlobalProperty::SetInitFunc(asCScriptFunction *in_initFunc)
|
2014-10-27 18:43:09 -04:00
|
|
|
{
|
|
|
|
// This should only be done once
|
2017-11-20 08:02:33 -05:00
|
|
|
asASSERT( initFunc == 0 );
|
2014-10-27 18:43:09 -04:00
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
initFunc = in_initFunc;
|
|
|
|
initFunc->AddRefInternal();
|
2014-10-27 18:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
asCScriptFunction *asCGlobalProperty::GetInitFunc()
|
|
|
|
{
|
|
|
|
return initFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_AS_NAMESPACE
|