]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
(refs #5495) Performance optimizations for Project Game
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 24 Nov 2014 10:47:53 +0000 (10:47 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 24 Nov 2014 10:47:53 +0000 (10:47 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30595 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java

index 31314bbdf4df9e7ac046b41924679428e33f30af..4a473bd9702dc824ebffa8c90695893bda4c90c5 100644 (file)
@@ -45,10 +45,10 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {
        protected double stepDuration = DEFAULT_STEP_DURATION;\r
        protected int savePer = 1;\r
 \r
-       protected HashMap<String, Integer> subscriptionIndexes;\r
+       public HashMap<String, Integer> subscriptionIndexes;\r
        protected double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
        \r
-       THashMap<String, TDoubleArrayList> results;\r
+       TDoubleArrayList[] results;\r
 \r
        public String[] subscription;\r
        \r
@@ -122,7 +122,7 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {
 \r
                monitor.subTask("Save results (time = " + time + ")");\r
                for(int k = 0; k < subscription.length; k++) {\r
-                       setResults(time, subscription[k], currentValues[k]);\r
+                       setResults(time, k, currentValues[k]);\r
                }\r
                \r
                lastResultTime = time;\r
@@ -131,11 +131,11 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {
     \r
        private double lastResultTime = Double.NaN;\r
 \r
-       public void setResults(double time, String key, Double value) {\r
-               TDoubleArrayList list = results.get(key);\r
+       public void setResults(double time, int index, Double value) {\r
+               TDoubleArrayList list = results[index];\r
                if(list == null) {\r
                        list = new TDoubleArrayList();\r
-                       results.put(key, list);\r
+                       results[index] = list;\r
                }\r
                if(time == lastResultTime) {\r
                        list.set(list.size()-1, value);\r
@@ -147,14 +147,20 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {
        \r
        public void clearResults() {\r
                lastResultTime = Double.NaN;\r
-               results.clear();\r
+               for(int i=0;i<results.length;i++)\r
+                       results[i] = null;\r
+               //results.clear();\r
+       }\r
+       \r
+       public void simulateDuration(double duration, boolean useJob) {\r
+               SimulateDurationJob job = new SimulateDurationJob(this, "Simulate steps", duration, useJob);\r
+               if(useJob) job.schedule();\r
+               else job.run(new NullProgressMonitor());\r
        }\r
        \r
        @Override\r
        public void simulateDuration(double duration) {\r
-               Job job = new SimulateDurationJob(this, "Simulate steps", duration);\r
-               // Start the Job\r
-               job.schedule();\r
+               simulateDuration(duration, true);\r
        }\r
        \r
        public void refresh() {\r