diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 88: Add special SceneDefaultOptions class, used for setting default options for all other scenes.

Message ID 20110721123636.17019.24543.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 21, 2011, 12:36 p.m. UTC
------------------------------------------------------------
revno: 88
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
timestamp: Thu 2011-06-23 15:32:34 +0300
message:
  Add special SceneDefaultOptions class, used for setting default options for all other scenes.
added:
  src/scenedefaultoptions.cpp
modified:
  src/main.cpp
  src/scene.cpp
  src/scene.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/main.cpp'
--- src/main.cpp	2011-06-15 11:36:32 +0000
+++ src/main.cpp	2011-06-23 12:32:34 +0000
@@ -100,6 +100,8 @@ 
          scene_iter++)
     {
         Scene *scene = scene_iter->second;
+        if (scene->name().empty())
+            continue;
         Log::info("[Scene] %s\n", scene->name().c_str());
 
         const map<string, Scene::Option> &options = scene->options();
@@ -131,23 +133,26 @@ 
         bool keep_running = true;
         Benchmark *bench = *bench_iter;
         Scene &scene = bench->setup_scene();
-        Log::info("%s", scene.info_string().c_str());
-        Log::flush();
-
-        while (scene.is_running() &&
-               (keep_running = should_keep_running()))
-        {
-            screen.clear();
-
-            scene.draw();
-            scene.update();
-
-            screen.update();
+
+        if (!scene.name().empty()) {
+            Log::info("%s", scene.info_string().c_str());
+            Log::flush();
+
+            while (scene.is_running() &&
+                   (keep_running = should_keep_running()))
+            {
+                screen.clear();
+
+                scene.draw();
+                scene.update();
+
+                screen.update();
+            }
+
+            Log::info(" FPS: %u\n", scene.average_fps());
+            score += scene.average_fps();
         }
 
-        Log::info(" FPS: %u\n", scene.average_fps());
-        score += scene.average_fps();
-
         bench->teardown_scene();
 
         if (!keep_running)
@@ -169,30 +174,33 @@ 
     {
         Benchmark *bench = *bench_iter;
         Scene &scene = bench->setup_scene();
-        Log::info("%s", scene.info_string().c_str());
-        Log::flush();
-
-        screen.clear();
-        scene.draw();
-        screen.update();
-
-        string result;
-        switch(scene.validate()) {
-            case Scene::ValidationSuccess:
-                result = "Success";
-                break;
-            case Scene::ValidationFailure:
-                result = "Failure";
-                break;
-            case Scene::ValidationUnknown:
-                result = "Unknown";
-                break;
-            default:
-                break;
+
+        if (!scene.name().empty()) {
+            Log::info("%s", scene.info_string().c_str());
+            Log::flush();
+
+            screen.clear();
+            scene.draw();
+            screen.update();
+
+            string result;
+            switch(scene.validate()) {
+                case Scene::ValidationSuccess:
+                    result = "Success";
+                    break;
+                case Scene::ValidationFailure:
+                    result = "Failure";
+                    break;
+                case Scene::ValidationUnknown:
+                    result = "Unknown";
+                    break;
+                default:
+                    break;
+            }
+
+            Log::info(" Validation: %s\n", result.c_str());
         }
 
-        Log::info(" Validation: %s\n", result.c_str());
-
         bench->teardown_scene();
     }
 }
@@ -221,6 +229,7 @@ 
     }
 
     // Register the scenes, so they can be looked-up by name
+    Benchmark::register_scene(*new SceneDefaultOptions(screen));
     Benchmark::register_scene(*new SceneBuild(screen));
     Benchmark::register_scene(*new SceneTexture(screen));
     Benchmark::register_scene(*new SceneShading(screen));

=== modified file 'src/scene.cpp'
--- src/scene.cpp	2011-06-17 13:16:16 +0000
+++ src/scene.cpp	2011-06-23 12:32:34 +0000
@@ -117,6 +117,19 @@ 
     }
 }
 
+bool
+Scene::set_option_default(const string &opt, const string &val)
+{ 
+    map<string, Option>::iterator iter = mOptions.find(opt);
+
+    if (iter == mOptions.end())
+        return false;
+
+    iter->second.default_value = val;
+
+    return true;
+}
+
 
 string
 Scene::construct_title(const string &title)

=== modified file 'src/scene.h'
--- src/scene.h	2011-06-17 13:16:16 +0000
+++ src/scene.h	2011-06-23 12:32:34 +0000
@@ -36,6 +36,7 @@ 
 
 #include <string>
 #include <map>
+#include <list>
 
 class Scene
 {
@@ -79,8 +80,9 @@ 
     bool is_running();
 
     const std::string &name() { return mName; }
-    bool set_option(const std::string &opt, const std::string &val);
+    virtual bool set_option(const std::string &opt, const std::string &val);
     void reset_options();
+    bool set_option_default(const std::string &opt, const std::string &val);
     const std::map<std::string, Option> &options() { return mOptions; }
 
     static Scene &dummy()
@@ -114,6 +116,20 @@ 
     double mDuration;      // Duration of run in seconds
 };
 
+/*
+ * Special Scene used for setting the default options
+ */
+class SceneDefaultOptions : public Scene
+{
+public:
+    SceneDefaultOptions(Screen &pScreen) : Scene(pScreen, "") {}
+    bool set_option(const std::string &opt, const std::string &val);
+    void setup();
+
+private:
+    std::list<std::pair<std::string, std::string> > mDefaultOptions;
+};
+
 class SceneBuild : public Scene
 {
 public:

=== added file 'src/scenedefaultoptions.cpp'
--- src/scenedefaultoptions.cpp	1970-01-01 00:00:00 +0000
+++ src/scenedefaultoptions.cpp	2011-06-23 12:32:34 +0000
@@ -0,0 +1,47 @@ 
+/*
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis (glmark2)
+ */
+#include "scene.h"
+#include "benchmark.h"
+
+void SceneDefaultOptions::setup()
+{
+    const std::map<std::string, Scene *> &scenes = Benchmark::scenes();
+
+    for (std::list<std::pair<std::string, std::string> >::const_iterator iter = mDefaultOptions.begin();
+         iter != mDefaultOptions.end();
+         iter++)
+    {
+        for (std::map<std::string, Scene *>::const_iterator scene_iter = scenes.begin();
+             scene_iter != scenes.end();
+             scene_iter++)
+        {
+            scene_iter->second->set_option_default(iter->first, iter->second);
+        }
+    }
+}
+
+bool
+SceneDefaultOptions::set_option(const std::string &opt, const std::string &val)
+{
+    mDefaultOptions.push_back(std::pair<std::string, std::string>(opt, val));
+    return true;
+}