// // Copyright (c) 2008-2018 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #include "../Precompiled.h" #include "../AngelScript/Script.h" #include "../AngelScript/ScriptFile.h" #include "../AngelScript/ScriptInstance.h" #include "../Core/Context.h" #include "../Core/CoreEvents.h" #include "../Core/Profiler.h" #include "../IO/FileSystem.h" #include "../IO/Log.h" #include "../IO/MemoryBuffer.h" #include "../Resource/ResourceCache.h" #include #include "../DebugNew.h" namespace Urho3D { /// Helper class for saving AngelScript bytecode. class ByteCodeSerializer : public asIBinaryStream { public: /// Construct. explicit ByteCodeSerializer(Serializer& dest) : dest_(dest) { } /// Read from stream (no-op). void Read(void* ptr, asUINT size) override { // No-op, can not read from a Serializer } /// Write to stream. void Write(const void* ptr, asUINT size) override { dest_.Write(ptr, size); } private: /// Destination stream. Serializer& dest_; }; /// Helper class for loading AngelScript bytecode. class ByteCodeDeserializer : public asIBinaryStream { public: /// Construct. explicit ByteCodeDeserializer(MemoryBuffer& source) : source_(source) { } /// Read from stream. void Read(void* ptr, asUINT size) override { source_.Read(ptr, size); } /// Write to stream (no-op). void Write(const void* ptr, asUINT size) override { } private: /// Source stream. MemoryBuffer& source_; }; ScriptFile::ScriptFile(Context* context) : Resource(context), script_(GetSubsystem