bool AndroidProjectGenerator::GenerateStringXML() { FileSystem* fs = GetSubsystem<FileSystem>(); ToolSystem* toolSystem = GetSubsystem<ToolSystem>(); Project* project = toolSystem->GetProject(); AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings(); String appName = settings->GetAppName(); if (!appName.Length()) { errorText_ = "Invalid App Name"; return false; } String strings = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; strings += "<resources>\n"; strings.AppendWithFormat("<string name=\"app_name\">%s</string>\n", appName.CString()); strings += "</resources>\n"; // Create res/values if it doesn't exist if (!fs->DirExists(buildPath_ + "/res/values")) { fs->CreateDirsRecursive(buildPath_ + "/res/values"); } // Check that we successfully created it if (!fs->DirExists(buildPath_ + "/res/values")) { errorText_ = "Unable to create directory: " + buildPath_ + "/res/values"; return false; } File file(context_, buildPath_ + "/res/values/strings.xml", FILE_WRITE); if (!file.IsOpen()) { errorText_ = "Unable to write: " + buildPath_ + "/res/values/strings.xml"; return false; } file.Write(strings.CString(), strings.Length()); return true; }
bool AndroidProjectGenerator::GenerateActivitySource() { ToolSystem* toolSystem = GetSubsystem<ToolSystem>(); Project* project = toolSystem->GetProject(); AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings(); String packageName = settings->GetPackageName(); if (!packageName.Length()) { errorText_ = "Invalid Package Name"; return false; } Vector<String> elements = settings->GetPackageName().Split('.'); String path; path.Join(elements, "/"); path = buildPath_ + "/src/" + path; Poco::File dirs(path.CString()); dirs.createDirectories(); if (!dirs.exists()) { errorText_ = "Unable to create "; return false; } String source; source.AppendWithFormat("package %s;\n", packageName.CString()); source += "import org.libsdl.app.SDLActivity;\n"; source += "public class AtomicGameEngine extends SDLActivity {\n"; source += "}\n"; File file(context_, path + "/AtomicGameEngine.java", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(source.CString(), source.Length()); return true; }
void LicenseSystem::RequestServerActivation(const String& key) { if (serverActivation_.NotNull()) { ATOMIC_LOGERROR("UIActivation::RequestServerActivation - request already exists"); return; } key_ = key; CurlManager* cm = GetSubsystem<CurlManager>(); String post; String id = GenerateMachineID(); post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString()); // todo, this should be a verify url (shouldn't auto add id) serverActivation_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_activate.php", post); SubscribeToEvent(serverActivation_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleActivationResult)); }
void JSBModule::WriteClassDefine(String& source) { source += "static void jsb_init_classes(JSVM* vm)\n{\n"; for (unsigned i = 0; i < classes_.Size(); i++) { JSBClass* klass = classes_.At(i); if (klass->isNumberArray()) continue; source.AppendWithFormat(" jsb_class_define_%s(vm);\n", klass->GetName().CString()); } source += "\n}\n\n"; }
void LicenseSystem::RequestServerVerification(const String& key) { if (serverVerification_.NotNull()) { LOGERROR("LicenseSystem::RequestServerLicense - request already exists"); return; } key_ = key; CurlManager* cm = GetSubsystem<CurlManager>(); String post; String id = GenerateMachineID(); post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString()); serverVerification_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_verify.php", post); SubscribeToEvent(serverVerification_, E_CURLCOMPLETE, HANDLER(LicenseSystem, HandleVerification)); }
void JSBModuleWriter::WriteClassDefine(String& source) { Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values(); source += "static void jsb_init_classes(JSVM* vm)\n{\n"; for (unsigned i = 0; i < classes.Size(); i++) { JSBClass* klass = classes.At(i); if (klass->IsNumberArray()) continue; source.AppendWithFormat(" jsb_class_define_%s(vm);\n", klass->GetName().CString()); } source += "\n}\n\n"; }
void Script::MessageCallback(const asSMessageInfo* msg) { String message; message.AppendWithFormat("%s:%d,%d %s", msg->section, msg->row, msg->col, msg->message); switch (msg->type) { case asMSGTYPE_ERROR: LOGERROR(message); break; case asMSGTYPE_WARNING: LOGWARNING(message); break; default: LOGINFO(message); break; } }
void IssuesWidget::UpdateIssues() { AEJavascript* aejs = GetSubsystem<AEJavascript>(); const Vector<JSError>& errors = aejs->GetJSErrors(); issueList_->DeleteAllItems(); for (unsigned i = 0; i < errors.Size(); i++) { const JSError& error = errors[i]; String errorString; String filename = GetFileNameAndExtension(error.fullpath); errorString.AppendWithFormat("%s - %s - Line: %i Column: %i", filename.CString(), error.message.CString(), error.line, error.column); issueList_->AddItem(errorString.CString(), NULL, TBID(i)); } }
void ResourceOps::HandleCreate2DLevel(const String& resourcePath, const String& resourceName, bool navigateToResource, bool reportError) { Editor* editor = GetSubsystem<Editor>(); if (!CheckCreate2DLevel(resourcePath, resourceName, reportError)) return; ResourceCache* cache = GetSubsystem<ResourceCache>(); SharedPtr<File> srcFile = cache->GetFile("ClockworkEditor/templates/template_empty.tmx"); if (srcFile.Null() || !srcFile->IsOpen()) { editor->PostModalError("Create Script Error", "Could not open module template"); return; } String fullpath = resourcePath + resourceName; if (!resourceName.EndsWith(".tmx")) fullpath += ".tmx"; if (!CopyFile(srcFile, fullpath)) { String errorMsg; errorMsg.AppendWithFormat("Error copying template:\n\n%s\n\nto:\n\n%s", "ClockworkEditor/template_empty.tmx", fullpath.CString()); editor->PostModalError("Create 2D Level Error", errorMsg); return; } if (navigateToResource) { //ResourceFrame* rframe = GetSubsystem<MainFrame>()->GetResourceFrame(); //rframe->EditResource(fullpath); } GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh(); }
void JSClassWriter::GenerateSource(String& sourceOut) { String source = ""; if (klass_->IsNumberArray()) return; WriteFunctions(source); String packageName = klass_->GetModule()->GetPackage()->GetName(); source.AppendWithFormat("static void jsb_class_define_%s(JSVM* vm)\n{\n", klass_->GetName().CString()); source.Append("duk_context* ctx = vm->GetJSContext();\n"); GenerateStaticFunctionsSource(source, packageName); GenerateNonStaticFunctionsSource(source, packageName); source.Append("}\n"); sourceOut += source; }
void JSModuleWriter::WriteModulePreInit(String& source) { source.AppendWithFormat("\nvoid jsb_package_%s_preinit_%s (JSVM* vm)\n{\n\njsb_declare_classes(vm);\n", module_->package_->GetName().ToLower().CString(), module_->GetName().ToLower().CString()); // register enums and constants source += "// enums and constants\n"; source += "duk_context* ctx = vm->GetJSContext();\n"; source.AppendWithFormat("duk_get_global_string(ctx, \"%s\");\n", module_->package_->GetName().CString()); source += "// enums\n"; Vector<SharedPtr<JSBEnum>> enums = module_->enums_.Values(); for (unsigned i = 0; i < enums.Size(); i++) { JSBEnum* jenum = enums[i]; HashMap<String, String>& values = jenum->GetValues(); HashMap<String, String>::ConstIterator itr = values.Begin(); while (itr != values.End()) { String name = (*itr).first_; source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", name.CString()); source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n",name.CString()); itr++; } } source += "// constants\n"; Vector<String> constants = module_->constants_.Keys(); for (unsigned i = 0; i < constants.Size(); i++) { source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", constants.At(i).CString()); source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", constants.At(i).CString()); } source += "duk_pop(ctx);\n"; source += "// end enums and constants\n"; source += "\n}\n"; }
void LicenseSystem::RequestServerVerification(const String& key) { if (serverVerification_.NotNull()) { ATOMIC_LOGERROR("LicenseSystem::RequestServerLicense - request already exists"); return; } FileSystem* fileSystem = GetSubsystem<FileSystem>(); if (fileSystem->FileExists(licenseCachePath_)) { Time* time = GetSubsystem<Time>(); unsigned currentTime = time->GetTimeSinceEpoch(); unsigned fileTime = fileSystem->GetLastModifiedTime(licenseCachePath_); unsigned deltaMinutes = (currentTime - fileTime)/60; if (deltaMinutes < 1) { ATOMIC_LOGINFOF("%u minutes, using cached license", deltaMinutes); SendEvent(E_LICENSE_SUCCESS); return; } } ATOMIC_LOGINFO("LicenseSystem::RequestServerLicense - requesting verification"); key_ = key; CurlManager* cm = GetSubsystem<CurlManager>(); String post; String id = GenerateMachineID(); post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString()); serverVerification_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_verify.php", post); SubscribeToEvent(serverVerification_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleVerification)); }
void SceneHudPanel::UpdatePanel(float frametime, const SharedPtr<Urho3D::UIElement> &widget) { if (!limiter_.ShouldUpdate(frametime)) return; Text *sceneText = dynamic_cast<Text*>(widget.Get()); if (!sceneText || !framework_->Renderer()) return; Scene *scene = framework_->Renderer()->MainCameraScene(); if (!scene) return; String str; SceneInfo info; auto entities = scene->Entities(); info.ents = entities.Size(); for(auto entIter = entities.Begin(); entIter != entities.End(); ++entIter) { const EntityPtr ent = entIter->second_; if (ent->Parent()) info.entsParented++; else info.entsRoot++; if (ent->IsLocal()) info.entsLocal++; if (ent->IsReplicated()) info.entsReplicated++; if (ent->IsTemporary()) info.entsTemporary++; String group = ent->Group().Trimmed(); if (!group.Empty()) { info.entGroups[group]++; InsertAlpha(info.groups, group); if ((int)group.Length() > info.pad) info.pad = group.Length() + 2; } auto components = ent->Components(); info.comps += components.Size(); for(auto compIter = components.Begin(); compIter != components.End(); ++compIter) { auto comp = compIter->second_; String type = comp->TypeName(); info.compTypes[type]++; InsertAlpha(info.types, type); if (comp->IsLocal()) info.compsLocal++; if (comp->IsReplicated()) info.compsReplicated++; if (comp->IsTemporary()) info.compsTemporary++; if ((int)type.Length() > info.pad) info.pad = type.Length() + 2; } if (components.Empty()) info.entsEmpty++; } str.AppendWithFormat("%s %u\n", PadString("Entities", info.pad).CString(), info.ents); str.AppendWithFormat(" %s %u\n", PadString("Root", info.pad).CString(), info.entsRoot); str.AppendWithFormat(" %s %u\n", PadString("Parented", info.pad).CString(), info.entsParented); str.AppendWithFormat(" %s %u\n", PadString("Empty", info.pad).CString(), info.entsEmpty); str.AppendWithFormat(" %s %u\n", PadString("Replicated", info.pad).CString(), info.entsReplicated); str.AppendWithFormat(" %s %u\n", PadString("Local", info.pad).CString(), info.entsLocal); str.AppendWithFormat(" %s %u\n\n", PadString("Temporary", info.pad).CString(), info.entsTemporary); if (!info.groups.Empty()) { str.AppendWithFormat("%s %u\n", PadString("Entity Groups", info.pad).CString(), info.groups.Size()); foreach(auto &group, info.groups) { uint num = info.entGroups[group]; str.AppendWithFormat(" %s %u\n", PadString(group, info.pad).CString(), num); } str.Append("\n"); }
void JSPackageWriter::GenerateSource() { String source = "// This file was autogenerated by JSBind, changes will be lost\n\n"; String defineGuard = package_->GetPlatformDefineGuard(); if (defineGuard.Length()) { source += ToString("%s\n\n", defineGuard.CString()); } source += "#include <Duktape/duktape.h>\n"; source += "#include <AtomicJS/Javascript/JSVM.h>\n"; source += "#include <AtomicJS/Javascript/JSAPI.h>\n"; source += "\n\nnamespace Atomic\n{\n"; String packageLower = package_->GetName().ToLower(); for (unsigned i = 0; i < package_->modules_.Size(); i++) { JSBModule* module = package_->modules_.At(i); if (module->GetDotNetModule()) continue; String moduleGuard = module->GetModuleDefineGuard(); if (moduleGuard.Length()) { source += ToString("\n%s\n", moduleGuard.CString()); } String moduleLower = module->GetName().ToLower(); source.AppendWithFormat("\nextern void jsb_package_%s_preinit_%s (JSVM* vm);", packageLower.CString(), moduleLower.CString()); source.AppendWithFormat("\nextern void jsb_package_%s_init_%s (JSVM* vm);", packageLower.CString(), moduleLower.CString()); if (moduleGuard.Length()) { source += ToString("\n#endif\n", moduleGuard.CString()); } } source += "\n\nstatic void jsb_modules_setup_prototypes(JSVM* vm)\n{\n"; source += " // It is important that these are in order so the prototypes are created properly\n"; source += " // This isn't trivial as modules can have dependencies, so do it here\n\n"; WriteProtoTypeSetup(source); source += "\n}\n"; source.AppendWithFormat("\n\nstatic void jsb_package_%s_preinit(JSVM* vm)\n{", packageLower.CString()); source.Append("\n // Create the global package object\n"); source.Append(" duk_context* ctx = vm->GetJSContext();\n"); source.Append(" duk_push_object(ctx);\n"); source.AppendWithFormat(" duk_put_global_string(ctx, \"%s\");\n", package_->GetName().CString()); for (unsigned i = 0; i < package_->modules_.Size(); i++) { JSBModule* module = package_->modules_.At(i); if (module->GetDotNetModule()) continue; String moduleGuard = module->GetModuleDefineGuard(); if (moduleGuard.Length()) { source += ToString("\n%s\n", moduleGuard.CString()); } if (module->Requires("3D")) source += "\n#ifdef ATOMIC_3D"; String moduleLower = module->GetName().ToLower(); source.AppendWithFormat("\n jsb_package_%s_preinit_%s(vm);", packageLower.CString(), moduleLower.CString()); if (module->Requires("3D")) source += "\n#endif //ATOMIC_3D\n"; if (moduleGuard.Length()) { source += ToString("\n#endif\n", moduleGuard.CString()); } } source += "\n}\n\n"; source.AppendWithFormat("\n\nvoid jsb_package_%s_init(JSVM* vm)\n{", packageLower.CString()); source.AppendWithFormat("\n\n jsb_package_%s_preinit(vm);\n", packageLower.CString()); source += "\n\n jsb_modules_setup_prototypes(vm);\n"; for (unsigned i = 0; i < package_->modules_.Size(); i++) { JSBModule* module = package_->modules_.At(i); if (module->GetDotNetModule()) continue; String moduleLower = module->GetName().ToLower(); String moduleGuard = module->GetModuleDefineGuard(); if (moduleGuard.Length()) { source += ToString("\n%s\n", moduleGuard.CString()); } if (module->Requires("3D")) source += "\n#ifdef ATOMIC_3D"; source.AppendWithFormat("\n jsb_package_%s_init_%s(vm);", packageLower.CString(), moduleLower.CString()); if (module->Requires("3D")) { source += "\n#endif //ATOMIC_3D\n"; } if (moduleGuard.Length()) { source += ToString("\n#endif\n", moduleGuard.CString()); } } source += "\n}\n\n"; // end Atomic namespace source += "\n}\n"; if (defineGuard.Length()) { source += "\n#endif\n"; } JSBind* jsbind = package_->GetSubsystem<JSBind>(); String filepath = jsbind->GetDestNativeFolder() + "/JSPackage" + package_->name_ + ".cpp"; File file(package_->GetContext()); file.Open(filepath, FILE_WRITE); file.Write(source.CString(), source.Length()); file.Close(); for (unsigned i = 0; i < package_->modules_.Size(); i++) { if (package_->modules_[i]->GetDotNetModule()) continue; JSModuleWriter writer(package_->modules_[i]); writer.GenerateSource(); } }
void JSFunctionWriter::WriteConstructor(String& source) { // TODO: refactor this if (function_->name_ == "RefCounted") { source.Append("// finalizer may be called more than once\n" \ "static int jsb_finalizer_RefCounted(duk_context *ctx)\n" \ "{\n" \ "JSVM* vm = JSVM::GetJSVM(ctx);\n" \ \ "duk_get_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \ \ "if (!duk_is_boolean(ctx, -1))\n" \ "{\n" \ "RefCounted* ref = vm->GetObjectPtr(duk_get_heapptr(ctx, 0));\n" \ "vm->RemoveObject(ref);\n" \ "ref->ReleaseRef();\n" \ "duk_push_boolean(ctx, 1);\n" \ "duk_put_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \ "}\n" \ \ "return 0;\n" \ "}\n"); } JSBClass* klass = function_->class_; JSBClass* base = klass->GetBaseClass(); // Constructor source.AppendWithFormat("duk_ret_t jsb_constructor_%s(duk_context* ctx)\n{\n", klass->GetName().CString()); source.Append( "\nJSVM* vm = JSVM::GetJSVM(ctx);\n" \ "duk_push_this(ctx);\n" \ "void *ptr = duk_get_heapptr(ctx, -1);\n" \ "duk_pop(ctx);\n\n"); source.Append(" if (!vm->GetObjectPtr(ptr, true))\n {\n"); if (!klass->IsAbstract() && !klass->IsNumberArray()) { String marshal; WriteParameterMarshal(marshal); String sparams; int cparam = 0; const Vector<JSBFunctionType*>& parameters = function_->GetParameters(); for (unsigned i = 0; i < parameters.Size(); i++, cparam++) { JSBFunctionType * ptype = parameters.At(i); String sarg; if (ptype->type_->asClassType()) { JSBClassType* classType = ptype->type_->asClassType(); JSBClass* klass = classType->class_; if (klass->GetName() == "Context") { sarg = "vm->GetContext()"; cparam--; } } if (!sarg.Length()) { sarg.AppendWithFormat("__arg%i", cparam); } sparams += sarg; if (i + 1 < parameters.Size()) sparams += ", "; } source.AppendWithFormat("if (!duk_get_top(ctx) || !duk_is_pointer(ctx, 0))\n"\ "{\n"\ "%s\n"\ "%s* native = new %s(%s);\n" \ "vm->AddObject(ptr, native, INSTANTIATION_JAVASCRIPT);\n"\ "}\n" \ "else if (duk_is_pointer(ctx, 0))\n" \ "{\n" \ "RefCounted* rc = (RefCounted*) duk_get_pointer(ctx, 0);\n" \ "vm->AddObject(ptr, rc, rc->GetInstantiationType());\n" \ "}\n", marshal.CString(), klass->GetNativeName().CString(), klass->GetNativeName().CString(), sparams.CString()); } else { if (klass->IsAbstract()) source.Append("assert(0); // abstract class new'd\n"); if (klass->IsNumberArray()) source.Append("assert(0); // number array class new'd\n"); } source.Append(" }\n"); if (base) { String basePackage = base->GetModule()->GetPackage()->GetName(); source.AppendWithFormat(" js_constructor_basecall(ctx, \"%s\", \"%s\");\n", basePackage.CString(), base->GetName().CString()); } if (function_->name_ == "RefCounted") { source.Append("duk_push_this(ctx);\n "\ "duk_push_c_function(ctx, jsb_finalizer_RefCounted, 1);\n "\ "duk_set_finalizer(ctx, -2);\n "\ "duk_pop(ctx);\n"); } source += " return 0;"; source += "\n}\n"; }
void JSFunctionWriter::WriteFunction(String& source) { JSBClass* klass = function_->class_; source.AppendWithFormat("static int jsb_class_%s_%s(duk_context* ctx)\n{\n", klass->GetName().CString(), function_->name_.CString()); WriteParameterMarshal(source); if (!function_->IsStatic()) { source.Append("duk_push_this(ctx);\n"); source.AppendWithFormat("%s* native = js_to_class_instance<%s>(ctx, -1, 0);\n", klass->GetNativeName().CString(), klass->GetNativeName().CString()); } // declare return value; bool returnDeclared = false; JSBFunctionType* returnType = function_->returnType_; if (returnType) { if (returnType->type_->asStringType()) { returnDeclared = true; source.Append("const String& retValue = "); } else if (returnType->type_->asPrimitiveType()) { returnDeclared = true; JSBPrimitiveType* prtype = returnType->type_->asPrimitiveType(); if (prtype->kind_ == JSBPrimitiveType::Bool) { source.Append("bool retValue = "); } else { source.Append("double retValue = "); } } else if (returnType->type_->asClassType()) { JSBClassType* klassType = returnType->type_->asClassType(); if (returnType->isTemplate_) { returnDeclared = true; source.AppendWithFormat("SharedPtr<%s> object = ", klassType->class_->GetNativeName().CString()); } else if (klassType->class_->IsObject()) { returnDeclared = true; source.Append("const Object* object = "); } else if (klassType->class_->IsNumberArray()) { returnDeclared = true; if (returnType->isReference_) source.AppendWithFormat("const %s& retValue = ", klassType->class_->GetName().CString()); else source.AppendWithFormat(" %s retValue = ", klassType->class_->GetName().CString()); } else { returnDeclared = true; source.Append("const RefCounted* object = "); } } else if (returnType->type_->asEnumType()) { JSBEnumType* enumType = returnType->type_->asEnumType(); returnDeclared = true; source.AppendWithFormat("%s retValue = ", enumType->enum_->GetName().CString()); } else if (returnType->type_->asVectorType()) { returnDeclared = true; JSBVectorType* vtype = returnType->type_->asVectorType(); source.AppendWithFormat("const %s& retValue = ", vtype->ToString().CString()); } } const Vector<JSBFunctionType*>& parameters = function_->GetParameters(); if (function_->IsStatic()) { source.AppendWithFormat("%s::%s(", klass->GetNativeName().CString(), function_->name_.CString()); } else { if (function_->HasMutatedReturn()) { source.AppendWithFormat("__arg%i = native->%s(", parameters.Size() - 1, function_->name_.CString()); } else { source.AppendWithFormat("native->%s(", function_->name_.CString()); } } unsigned numParams = parameters.Size(); if (numParams && function_->HasMutatedReturn()) numParams--; for (unsigned int i = 0; i < numParams; i++) { source.AppendWithFormat("__arg%i", i); if (i != numParams - 1) { source += ", "; } } source += ");\n"; if (!returnDeclared) { if (function_->HasMutatedReturn()) { // this handles the VariantVector case currently, can be expanded source.AppendWithFormat("__scriptVectorArg%i->AdaptFromVector(__arg%i);\n", parameters.Size() - 1, parameters.Size() - 1); } source += "return 0;\n"; } else { if (returnType->type_->asStringType()) { source.Append("duk_push_string(ctx, retValue.CString());\n"); } else if (returnType->type_->asPrimitiveType()) { JSBPrimitiveType* prtype = returnType->type_->asPrimitiveType(); if (prtype->kind_ == JSBPrimitiveType::Bool) { source.Append("duk_push_boolean(ctx, retValue ? 1 : 0);\n"); } else { source.Append("duk_push_number(ctx, retValue);\n"); } } else if (returnType->type_->asClassType()) { JSBClassType* klassType = returnType->type_->asClassType(); if (klassType->class_->IsObject()) { returnDeclared = true; source.Append("js_push_class_object_instance(ctx, object);\n"); } else if (klassType->class_->IsNumberArray()) { returnDeclared = true; String elementType = klassType->class_->GetArrayElementType(); source.AppendWithFormat("const %s* arrayData = retValue.Data();\n", elementType.CString()); source.Append("duk_push_array(ctx);\n"); for (int i = 0; i < klassType->class_->GetNumberArrayElements(); i++) { source.AppendWithFormat("duk_push_number(ctx, arrayData[%i]);\n", i); source.AppendWithFormat("duk_put_prop_index(ctx, -2, %i);\n", i); } } else { returnDeclared = true; source.AppendWithFormat("js_push_class_object_instance(ctx, object, \"%s\");\n", klassType->class_->GetName().CString()); } } else if (returnType->type_->asEnumType()) { returnDeclared = true; source.Append("duk_push_number(ctx, (double) retValue);\n"); } else if (returnType->type_->asVectorType()) { JSBType* vectorType = returnType->type_->asVectorType()->vectorType_; source.Append("duk_push_array(ctx);\n"); source.Append("for (unsigned i = 0; i < retValue.Size(); i++)\n{\n"); if (vectorType->asClassType()) { source.AppendWithFormat("js_push_class_object_instance(ctx, retValue[i], \"%s\");\n", vectorType->asClassType()->class_->GetName().CString()); } else { source.Append("duk_push_string(ctx, retValue[i].CString());\n"); } source.Append("duk_put_prop_index(ctx, -2, i);\n}\n"); } source += "return 1;\n"; } source.Append("}\n"); }
bool AndroidProjectGenerator::GenerateAndroidManifest() { ToolSystem* toolSystem = GetSubsystem<ToolSystem>(); Project* project = toolSystem->GetProject(); AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings(); String package = settings->GetPackageName(); if (!package.Length()) { errorText_ = "Invalid App Package name. The general naming convention is com.company.appname"; return false; } // TODO: from settings -- should this be ProductName ? String activityName = "AtomicGameEngine"; if (!activityName.Length()) { errorText_ = "Invalid Activity Name"; return false; } String manifest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; manifest += "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"; manifest.AppendWithFormat("package=\"%s\"\n", package.CString()); manifest += "android:versionCode=\"1\"\n"; manifest += "android:versionName=\"1.0\">\n"; manifest += "android:installLocation=\"auto\">\n"; manifest += "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>\n"; manifest += "<uses-permission android:name=\"android.permission.INTERNET\" />\n"; manifest += "<uses-feature android:glEsVersion=\"0x00020000\" />\n"; manifest += "<uses-sdk android:targetSdkVersion=\"12\" android:minSdkVersion=\"10\" />\n"; manifest += "<application\n"; manifest += "android:label=\"@string/app_name\"\n"; manifest += "android:icon=\"@drawable/icon\"\n"; manifest += "android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\"\n"; manifest += "android:hardwareAccelerated=\"true\"\n"; manifest += "android:allowBackup=\"false\">\n"; manifest.AppendWithFormat("<activity android:name=\".%s\"\n", activityName.CString()); manifest += "android:configChanges=\"keyboardHidden|orientation\"\n"; manifest += "android:screenOrientation=\"landscape\">\n"; manifest += "<intent-filter>\n"; manifest += "<action android:name=\"android.intent.action.MAIN\" />\n"; manifest += "<category android:name=\"android.intent.category.LAUNCHER\" />\n"; manifest += "</intent-filter>\n"; manifest += "</activity>\n"; manifest += "</application>\n"; manifest += "</manifest>\n"; File file(context_, buildPath_ + "/AndroidManifest.xml", FILE_WRITE); if (!file.IsOpen()) return false; file.Write(manifest.CString(), manifest.Length()); return true; }
void JSBModule::WriteModuleInit(String& source) { source.AppendWithFormat("\nvoid jsb_init_%s (JSVM* vm)\n{\n\n jsb_init_classes(vm);\n\n}\n\n", name_.ToLower().CString()); }
void JSBModuleWriter::WriteModuleInit(String& source) { source.AppendWithFormat("\nvoid jsb_package_%s_init_%s (JSVM* vm)\n{\n\n jsb_init_classes(vm);\n\n}\n\n", module_->package_->GetName().ToLower().CString(), module_->name_.ToLower().CString()); }
void JSFunctionWriter::WriteParameterMarshal(String& source) { // generate args const Vector<JSBFunctionType*>& parameters = function_->GetParameters(); int cparam = 0; if (parameters.Size()) { for (unsigned int i = 0; i < parameters.Size(); i++, cparam++) { JSBFunctionType * ptype = parameters.At(i); // ignore "Context" parameters if (ptype->type_->asClassType()) { JSBClassType* classType = ptype->type_->asClassType(); JSBClass* klass = classType->class_; if (klass->GetName() == "Context") { cparam--; continue; } } String pstring = ptype->ToArgString(cparam); const String& init = ptype->initializer_; if (ptype->type_->asClassType()) { JSBClassType* classType = ptype->type_->asClassType(); JSBClass* klass = classType->class_; if (!klass->IsNumberArray()) { if (init.Length()) { source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? js_to_class_instance<%s>(ctx, %i, 0) : %s;\n", pstring.CString(), cparam + 1, klass->GetNativeName().CString(), cparam, init.CString()); } else { source.AppendWithFormat("%s = js_to_class_instance<%s>(ctx, %i, 0);\n", pstring.CString(), klass->GetNativeName().CString(), cparam); } } else { int elements = klass->GetNumberArrayElements(); String elementType = klass->GetArrayElementType(); source.AppendWithFormat("%s arrayData%i[%i];\n", elementType.CString(), cparam, elements); if (init.Length()) { source.AppendWithFormat("const %s& defaultArg%i = %s;\n", klass->GetNativeName().CString(), cparam, init.CString()); source.AppendWithFormat("if (duk_get_top(ctx) >= %i) {\n", cparam + 1); } for (int j = 0; j < elements; j++) { source.AppendWithFormat("duk_get_prop_index(ctx, %i, %i);\n", cparam, j); source.AppendWithFormat("arrayData%i[%i] = (%s) duk_to_number(ctx, -1);\n", cparam, j, elementType.CString()); } source.AppendWithFormat("duk_pop_n(ctx, %i);\n", elements); if (init.Length()) { source.Append("}\n"); source.AppendWithFormat("%s __arg%i(duk_get_top(ctx) >= %i ? (const %s *) arrayData%i : defaultArg%i.Data());\n", klass->GetNativeName().CString(), cparam, cparam + 1, elementType.CString(), cparam, cparam); } else { source.AppendWithFormat("%s __arg%i(arrayData%i);\n", klass->GetNativeName().CString(), cparam, cparam); } } } else if (ptype->type_->asStringType() || ptype->type_->asStringHashType()) { if (init.Length()) { source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? duk_to_string(ctx, %i) : %s;\n", pstring.CString(), cparam + 1, cparam, init.CString()); } else { source.AppendWithFormat("%s = duk_to_string(ctx, %i);\n", pstring.CString(), cparam); } } else if (ptype->type_->asHeapPtrType()) { if (init.Length()) { source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? duk_get_heapptr(ctx, %i) : %s;\n", pstring.CString(), cparam + 1, cparam, init.CString()); } else { source.AppendWithFormat("%s = duk_get_heapptr(ctx, %i);\n", pstring.CString(), cparam); } } else if (ptype->type_->asPrimitiveType()) { JSBPrimitiveType* prtype = ptype->type_->asPrimitiveType(); if (prtype->kind_ == JSBPrimitiveType::Bool) { if (init.Length()) { source.AppendWithFormat("bool __arg%i = duk_get_top(ctx) >= %i ? (duk_to_boolean(ctx, %i) ? true : false) : %s;\n", cparam, cparam + 1, cparam, init.CString()); } else { source.AppendWithFormat("bool __arg%i = duk_to_boolean(ctx, %i) ? true : false;\n", cparam, cparam); } } else { if (init.Length()) { source.AppendWithFormat("double __arg%i = duk_get_top(ctx) >= %i ? (duk_to_number(ctx, %i)) : %s;\n", cparam, cparam + 1, cparam, init.CString()); } else { source.AppendWithFormat("double __arg%i = duk_to_number(ctx, %i);\n", cparam, cparam); } } } else if (ptype->type_->asEnumType()) { JSBEnumType* etype = ptype->type_->asEnumType(); if (init.Length()) { source.AppendWithFormat("%s __arg%i = duk_get_top(ctx) >= %i ? ((%s) ((int) duk_to_number(ctx, %i))) : %s;\n", etype->enum_->GetName().CString(), cparam, cparam + 1, etype->enum_->GetName().CString(), cparam, init.CString()); } else { source.AppendWithFormat("%s __arg%i = (%s) ((int)duk_to_number(ctx, %i));\n", etype->enum_->GetName().CString(), cparam, etype->enum_->GetName().CString(), cparam); } } else if (ptype->type_->asVectorType()) { JSBVectorType* vtype = ptype->type_->asVectorType(); if (vtype->isVariantVector_) { // variant vector arguments source.AppendWithFormat("VariantVector __arg%i;\nScriptVector* __scriptVectorArg%i = js_to_class_instance<ScriptVector>(ctx, %i, 0);\n", cparam, cparam, cparam); if (!function_->HasMutatedReturn()) source.AppendWithFormat("__scriptVectorArg%i->AdaptToVector(__arg%i);\n", cparam, cparam); } else if (ptype->isConst_) { // JS/TS side needs work for vector parameters, right now we support const (read only) // Vector of String/StringHash source.AppendWithFormat("%s __arg%i;\n", vtype->ToString().CString(), cparam); source.AppendWithFormat("if (duk_get_top(ctx) >= %i)\n{\n", cparam + 1); source.AppendWithFormat("duk_require_object_coercible(ctx, %i);\n", cparam); source.AppendWithFormat("unsigned sz = duk_get_length(ctx, %i);\n", cparam); source.AppendWithFormat("for (unsigned i = 0; i < sz; i++)\n{\n"); source.AppendWithFormat("duk_get_prop_index(ctx, 2, i);\n"); if (vtype->vectorType_->asStringType() || vtype->vectorType_->asStringHashType() ) { source.AppendWithFormat("__arg%i.Push(duk_get_string(ctx, -1));\n", cparam); } source.AppendWithFormat("duk_pop(ctx);\n"); source.AppendWithFormat("\n}\n"); source.AppendWithFormat("\n}\n"); } } } } }
void DebugHud::Update() { Graphics* graphics = GetSubsystem<Graphics>(); Renderer* renderer = GetSubsystem<Renderer>(); if (!renderer || !graphics) return; // Ensure UI-elements are not detached if (!statsText_->GetParent()) { UI* ui = GetSubsystem<UI>(); UIElement* uiRoot = ui->GetRoot(); uiRoot->AddChild(statsText_); uiRoot->AddChild(modeText_); uiRoot->AddChild(profilerText_); } if (statsText_->IsVisible()) { unsigned primitives, batches; if (!useRendererStats_) { primitives = graphics->GetNumPrimitives(); batches = graphics->GetNumBatches(); } else { primitives = renderer->GetNumPrimitives(); batches = renderer->GetNumBatches(); } String stats; stats.AppendWithFormat("Triangles %u\nBatches %u\nViews %u\nLights %u\nShadowmaps %u\nOccluders %u", primitives, batches, renderer->GetNumViews(), renderer->GetNumLights(true), renderer->GetNumShadowMaps(true), renderer->GetNumOccluders(true)); if (!appStats_.Empty()) { stats.Append("\n"); for (HashMap<String, String>::ConstIterator i = appStats_.Begin(); i != appStats_.End(); ++i) stats.AppendWithFormat("\n%s %s", i->first_.CString(), i->second_.CString()); } statsText_->SetText(stats); } if (modeText_->IsVisible()) { String mode; mode.AppendWithFormat("Tex:%s Mat:%s Spec:%s Shadows:%s Size:%i Quality:%s Occlusion:%s Instancing:%s API:%s", qualityTexts[renderer->GetTextureQuality()], qualityTexts[renderer->GetMaterialQuality()], renderer->GetSpecularLighting() ? "On" : "Off", renderer->GetDrawShadows() ? "On" : "Off", renderer->GetShadowMapSize(), shadowQualityTexts[renderer->GetShadowQuality()], renderer->GetMaxOccluderTriangles() > 0 ? "On" : "Off", renderer->GetDynamicInstancing() ? "On" : "Off", graphics->GetApiName().CString()); modeText_->SetText(mode); } Profiler* profiler = GetSubsystem<Profiler>(); if (profiler) { if (profilerTimer_.GetMSec(false) >= profilerInterval_) { profilerTimer_.Reset(); if (profilerText_->IsVisible()) { String profilerOutput = profiler->GetData(false, false, profilerMaxDepth_); profilerText_->SetText(profilerOutput); } profiler->BeginInterval(); } } }
void JSModuleWriter::WriteClassDeclaration(String& source) { Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values(); source += "static void jsb_declare_classes(JSVM* vm)\n{\n"; source += "duk_context* ctx = vm->GetJSContext();\n"; String packageName = module_->GetPackage()->GetName(); for (unsigned i = 0; i < classes.Size(); i++) { JSBClass* klass = classes.At(i); if (klass->IsNumberArray()) continue; JSBFunction* constructor = klass->GetConstructor(); if (constructor) source.AppendWithFormat(" js_class_declare<%s>(vm, \"%s\", \"%s\", jsb_constructor_%s);\n", klass->GetNativeName().CString(), packageName.CString(), klass->GetName().CString(), klass->GetName().CString()); if (klass->HasProperties()) { source.AppendWithFormat("js_class_push_propertyobject(vm, \"%s\", \"%s\");\n", packageName.CString(), klass->GetName().CString()); Vector<String> pnames; klass->GetPropertyNames(pnames); for (unsigned j = 0; j < pnames.Size(); j++) { JSBProperty* prop = klass->GetProperty(pnames[j]); source.Append("duk_push_object(ctx);\n"); if (prop->getter_ && !prop->getter_->Skip()) { source.AppendWithFormat("duk_push_c_function(ctx, jsb_class_%s_%s, 0);\n", klass->GetName().CString(), prop->getter_->GetName().CString()); source.Append("duk_put_prop_string(ctx, -2, \"get\");\n"); } if (prop->setter_ && !prop->setter_->Skip()) { source.AppendWithFormat("duk_push_c_function(ctx, jsb_class_%s_%s, 1);\n", klass->GetName().CString(), prop->setter_->GetName().CString()); source.Append("duk_put_prop_string(ctx, -2, \"set\");\n"); } String propertyName = prop->GetCasePropertyName(); source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", propertyName.CString()); } source.Append("duk_pop(ctx);\n"); } } source += "\n}\n\n"; }