void PrepareForMT() { selection = null; for (int m = 0; m < mods.Length; m++) { MegaModifier mod = mods[m]; mod.valid = false; if (mod != null && mod.ModEnabled) { modContext.Offset = mod.Offset; modContext.bbox = mod.bbox; mod.SetTM(); if (mod.ModLateUpdate(modContext)) { mod.valid = true; if ((mod.ChannelsReq() & MegaModChannel.Verts) != 0) { mod.verts = GetSourceVerts(); // is this a ref or does it do a copy mod.sverts = GetDestVerts(); } if (UpdateMesh < 1) { UpdateMesh = 1; } dirtyChannels |= mod.ChannelsChanged(); } mod.selection = selection; mod.PrepareMT(this, Cores + 1); } } }
// Per modifyobject to use mt or not // auto bias of first task on num of waits public void ModifyObjectMT() { //#if UNITY_4 || UNITY_5 || UNITY_2017 #if UNITY_EDITOR if (!Application.isPlaying && Selection.activeGameObject != gameObject) { return; } #endif //#endif #if UNITY_FLASH || UNITY_PS3 || UNITY_METRO || UNITY_WP8 ModifyObject(); #else if (Cores == 0) { Cores = SystemInfo.processorCount - 1; } // Dont use mt in editor mode if (!UseThreading || !ThreadingOn || Cores < 1 || !Application.isPlaying) { ModifyObject(); return; } if (tasks == null) { MakeThreads(); } if (Enabled && mods != null) { dirtyChannels = MegaModChannel.None; //if ( GrabVerts ) //{ //if ( sverts.Length < mesh.vertexCount ) //sverts = new Vector3[mesh.vertexCount]; //verts = mesh.vertices; //} VertsSource = true; UVsSource = true; modContext.mod = this; PrepareForMT(); // Set up tasks int step = verts.Length / (Cores + 1); if (Cores > 0) { int index = step; for (int i = 0; i < tasks.Length; i++) { tasks[i].jobtype = MegaJobType.Modifier; tasks[i].index = i + 1; tasks[i].cores = tasks.Length; tasks[i].start = index; tasks[i].end = index + step; tasks[i].modcontext = modContext; index += step; } tasks[Cores - 1].end = verts.Length; for (int i = 0; i < tasks.Length; i++) { tasks[i].pauseevent.Set(); } } // Do this thread work DoWork1(0, step); // Bias the first job to reduce wait // Now need to sit and wait for jobs done, we should be doing work here WaitJobs(); for (int m = 0; m < mods.Length; m++) { MegaModifier mod = mods[m]; if (mod.valid) { mod.DoneMT(this); } } Done(); if (UpdateMesh == 1) { SetMesh(ref sverts); UpdateMesh = 0; } else { if (UpdateMesh == 0) { SetMesh(ref verts); UpdateMesh = -1; // Dont need to set verts again until a mod is enabled } } } #endif }
public void ModifyObject() { if (Enabled && mods != null) { dirtyChannels = MegaModChannel.None; //if ( GrabVerts ) //{ //if ( sverts.Length < mesh.vertexCount ) //sverts = new Vector3[mesh.vertexCount]; //verts = mesh.vertices; //} VertsSource = true; UVsSource = true; modContext.mod = this; selection = null; for (int i = 0; i < mods.Length; i++) { MegaModifier mod = mods[i]; if (mod != null && mod.ModEnabled) { // **group** if (mod.instance) { // Actually dont even do this have a GetValues method mod.SetValues(mod.instance); } if ((mod.ChannelsReq() & MegaModChannel.Verts) != 0) // should be changed { mod.verts = GetSourceVerts(); mod.sverts = GetDestVerts(); } modContext.Offset = mod.Offset; modContext.bbox = mod.bbox; mod.SetTM(); if (mod.ModLateUpdate(modContext)) { if (selection != null) { mod.ModifyWeighted(this); if (UpdateMesh < 1) { UpdateMesh = 1; } } else { if (UpdateMesh < 1) { mod.Modify(this); UpdateMesh = 1; } else { mod.Modify(this); } } dirtyChannels |= mod.ChannelsChanged(); mod.ModEnd(this); } } } if (UpdateMesh == 1) { SetMesh(ref sverts); UpdateMesh = 0; } else { if (UpdateMesh == 0) { SetMesh(ref verts); UpdateMesh = -1; // Dont need to set verts again until a mod is enabled } } } }
void PrepareForMT() { selection = null; for ( int m = 0; m < mods.Length; m++ ) { MegaModifier mod = mods[m]; mod.valid = false; if ( mod != null && mod.ModEnabled ) { modContext.Offset = mod.Offset; modContext.bbox = mod.bbox; mod.SetTM(); if ( mod.ModLateUpdate(modContext) ) { mod.valid = true; if ( (mod.ChannelsReq() & MegaModChannel.Verts) != 0 ) { mod.verts = GetSourceVerts(); // is this a ref or does it do a copy mod.sverts = GetDestVerts(); } if ( UpdateMesh < 1 ) UpdateMesh = 1; dirtyChannels |= mod.ChannelsChanged(); } mod.selection = selection; mod.PrepareMT(this, Cores + 1); } } }
// Per modifyobject to use mt or not // auto bias of first task on num of waits public void ModifyObjectMT() { #if UNITY_FLASH || UNITY_PS3 ModifyObject(); #else if ( Cores == 0 ) Cores = SystemInfo.processorCount - 1; // Dont use mt in editor mode if ( !UseThreading || !ThreadingOn || Cores < 1 || !Application.isPlaying ) { ModifyObject(); return; } if ( tasks == null ) MakeThreads(); if ( Enabled && mods != null ) { dirtyChannels = MegaModChannel.None; if ( GrabVerts ) { if ( sverts.Length < mesh.vertexCount ) sverts = new Vector3[mesh.vertexCount]; verts = mesh.vertices; } VertsSource = true; UVsSource = true; modContext.mod = this; PrepareForMT(); // Set up tasks int step = verts.Length / (Cores + 1); if ( Cores > 0 ) { int index = step; for ( int i = 0; i < tasks.Length; i++ ) { tasks[i].jobtype = MegaJobType.Modifier; tasks[i].index = i + 1; tasks[i].cores = tasks.Length; tasks[i].start = index; tasks[i].end = index + step; tasks[i].modcontext = modContext; index += step; } tasks[Cores - 1].end = verts.Length; for ( int i = 0; i < tasks.Length; i++ ) tasks[i].pauseevent.Set(); } // Do this thread work DoWork1(0, step); // Bias the first job to reduce wait // Now need to sit and wait for jobs done, we should be doing work here WaitJobs(); Done(); if ( UpdateMesh == 1 ) { SetMesh(ref sverts); UpdateMesh = 0; } else { if ( UpdateMesh == 0 ) { SetMesh(ref verts); UpdateMesh = -1; // Dont need to set verts again until a mod is enabled } } } #endif }
public void ModifyObject() { if ( Enabled && mods != null ) { dirtyChannels = MegaModChannel.None; if ( GrabVerts ) { if ( sverts.Length < mesh.vertexCount ) sverts = new Vector3[mesh.vertexCount]; verts = mesh.vertices; } VertsSource = true; UVsSource = true; modContext.mod = this; selection = null; foreach ( MegaModifier mod in mods ) { if ( mod != null && mod.ModEnabled ) { // **group** if ( mod.instance ) { // Actually dont even do this have a GetValues method mod.SetValues(mod.instance); //mod = mod.instance; } if ( (mod.ChannelsReq() & MegaModChannel.Verts) != 0 ) // should be changed { mod.verts = GetSourceVerts(); mod.sverts = GetDestVerts(); } modContext.Offset = mod.Offset; modContext.bbox = mod.bbox; mod.SetTM(); if ( mod.ModLateUpdate(modContext) ) { if ( selection != null ) { mod.ModifyWeighted(this); if ( UpdateMesh < 1 ) UpdateMesh = 1; } else { if ( UpdateMesh < 1 ) { //UpdateMesh = 1; //mod.Modify(ref sverts, ref verts); //mod.Modify(GetDestVerts(), GetSourceVerts()); mod.Modify(this); UpdateMesh = 1; } else { //mod.Modify(ref sverts, ref sverts); //mod.Modify(GetDestVerts(false), GetSourceVerts(true)); mod.Modify(this); } } dirtyChannels |= mod.ChannelsChanged(); mod.ModEnd(this); } } } if ( UpdateMesh == 1 ) { SetMesh(ref sverts); UpdateMesh = 0; } else { if ( UpdateMesh == 0 ) { SetMesh(ref verts); UpdateMesh = -1; // Dont need to set verts again until a mod is enabled } } } }