|
@@ -0,0 +1,138 @@
|
|
|
|
|
+//
|
|
|
|
|
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
|
|
|
|
|
+// LICENSE: Atomic Game Engine Editor and Tools EULA
|
|
|
|
|
+// Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
|
|
|
|
|
+// license information: https://github.com/AtomicGameEngine/AtomicGameEngine
|
|
|
|
|
+//
|
|
|
|
|
+
|
|
|
|
|
+#include <Atomic/IO/FileSystem.h>
|
|
|
|
|
+
|
|
|
|
|
+#include "../JSBind.h"
|
|
|
|
|
+#include "../JSBPackage.h"
|
|
|
|
|
+#include "../JSBModule.h"
|
|
|
|
|
+#include "../JSBEnum.h"
|
|
|
|
|
+#include "../JSBClass.h"
|
|
|
|
|
+#include "../JSBFunction.h"
|
|
|
|
|
+
|
|
|
|
|
+#include "CSBClassWriter.h"
|
|
|
|
|
+#include "CSBModuleWriter.h"
|
|
|
|
|
+
|
|
|
|
|
+namespace ToolCore
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+CSBModuleWriter::CSBModuleWriter(JSBModule *module) : module_(module)
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CSBModuleWriter::WriteIncludes(String& source)
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ Vector<String>& includes = module_->includes_;
|
|
|
|
|
+ for (unsigned i = 0; i < includes.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (includes[i].StartsWith("<"))
|
|
|
|
|
+ source.AppendWithFormat("#include %s\n", includes[i].CString());
|
|
|
|
|
+ else
|
|
|
|
|
+ source.AppendWithFormat("#include \"%s\"\n", includes[i].CString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Vector<JSBHeader*> allheaders;
|
|
|
|
|
+
|
|
|
|
|
+ HashMap<StringHash, SharedPtr<JSBEnum> >::Iterator eitr = module_->enums_.Begin();
|
|
|
|
|
+ while (eitr != module_->enums_.End())
|
|
|
|
|
+ {
|
|
|
|
|
+ allheaders.Push(eitr->second_->GetHeader());
|
|
|
|
|
+ eitr++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ HashMap<StringHash, SharedPtr<JSBClass> >::Iterator citr = module_->classes_.Begin();
|
|
|
|
|
+ while (citr != module_->classes_.End())
|
|
|
|
|
+ {
|
|
|
|
|
+ allheaders.Push(citr->second_->GetHeader());
|
|
|
|
|
+ citr++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Vector<JSBHeader*> included;
|
|
|
|
|
+
|
|
|
|
|
+ for (unsigned i = 0; i < allheaders.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ JSBHeader* header = allheaders.At(i);
|
|
|
|
|
+
|
|
|
|
|
+ if (included.Contains(header))
|
|
|
|
|
+ continue;
|
|
|
|
|
+
|
|
|
|
|
+ String headerPath = GetPath(header->GetFilePath());
|
|
|
|
|
+
|
|
|
|
|
+ String headerfile = GetFileNameAndExtension(header->GetFilePath());
|
|
|
|
|
+
|
|
|
|
|
+ JSBind* jsbind = header->GetSubsystem<JSBind>();
|
|
|
|
|
+
|
|
|
|
|
+ headerPath.Replace(jsbind->GetSourceRootFolder() + "Source/", "");
|
|
|
|
|
+
|
|
|
|
|
+ source.AppendWithFormat("#include <%s%s>\n", headerPath.CString(), headerfile.CString());
|
|
|
|
|
+
|
|
|
|
|
+ included.Push(header);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+void CSBModuleWriter::GenerateSource(String& sourceOut)
|
|
|
|
|
+{
|
|
|
|
|
+ source_ = "// This file was autogenerated by JSBind, changes will be lost\n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "#ifdef ATOMIC_PLATFORM_WINDOWS\n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "#pragma warning(disable: 4244) // possible loss of data\n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "#endif\n";
|
|
|
|
|
+
|
|
|
|
|
+ if (module_->Requires("3D"))
|
|
|
|
|
+ {
|
|
|
|
|
+ source_ += "#ifdef ATOMIC_3D\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "#include <Duktape/duktape.h>\n";
|
|
|
|
|
+ source_ += "#include <AtomicJS/Javascript/JSVM.h>\n";
|
|
|
|
|
+ source_ += "#include <AtomicJS/Javascript/JSAPI.h>\n";
|
|
|
|
|
+
|
|
|
|
|
+ WriteIncludes(source_);
|
|
|
|
|
+
|
|
|
|
|
+ String ns = module_->GetPackage()->GetNamespace();
|
|
|
|
|
+
|
|
|
|
|
+ if (ns != "Atomic")
|
|
|
|
|
+ {
|
|
|
|
|
+ source_ += "\n\nusing namespace " + ns + ";\n\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "\n\nnamespace Atomic\n{\n \n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "// Begin Class Declarations\n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "// End Class Declarations\n\n";
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "// Begin Classes\n";
|
|
|
|
|
+
|
|
|
|
|
+ Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();
|
|
|
|
|
+
|
|
|
|
|
+ for (unsigned i = 0; i < classes.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ CSBClassWriter clsWriter(classes[i]);
|
|
|
|
|
+ clsWriter.GenerateSource(source_);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ source_ += "// End Classes\n\n";
|
|
|
|
|
+
|
|
|
|
|
+ // end Atomic namespace
|
|
|
|
|
+ source_ += "\n}\n";
|
|
|
|
|
+
|
|
|
|
|
+ if (module_->Requires("3D"))
|
|
|
|
|
+ {
|
|
|
|
|
+ source_ += "#endif //ATOMIC_3D\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sourceOut = source_;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+}
|