1 //
2 // Copyright (c) 2008-2017 the Urho3D project.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 //
22 
23 #pragma once
24 
25 #include "Sample.h"
26 
27 namespace Urho3D
28 {
29 
30 class Node;
31 class Scene;
32 
33 }
34 
35 /// Huge object count example.
36 /// This sample demonstrates:
37 ///     - Creating a scene with 250 x 250 simple objects
38 ///     - Competing with http://yosoygames.com.ar/wp/2013/07/ogre-2-0-is-up-to-3x-faster/ :)
39 ///     - Allowing examination of performance hotspots in the rendering code
40 ///     - Using the profiler to measure the time taken to animate the scene
41 ///     - Optionally speeding up rendering by grouping objects with the StaticModelGroup component
42 class HugeObjectCount : public Sample
43 {
44     URHO3D_OBJECT(HugeObjectCount, Sample);
45 
46 public:
47     /// Construct.
48     HugeObjectCount(Context* context);
49 
50     /// Setup after engine initialization and before running the main loop.
51     virtual void Start();
52 
53 protected:
54     /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
GetScreenJoystickPatchString()55     virtual String GetScreenJoystickPatchString() const { return
56         "<patch>"
57         "    <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
58         "    <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Group</replace>"
59         "    <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
60         "        <element type=\"Text\">"
61         "            <attribute name=\"Name\" value=\"KeyBinding\" />"
62         "            <attribute name=\"Text\" value=\"G\" />"
63         "        </element>"
64         "    </add>"
65         "    <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
66         "    <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Animation</replace>"
67         "    <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
68         "        <element type=\"Text\">"
69         "            <attribute name=\"Name\" value=\"KeyBinding\" />"
70         "            <attribute name=\"Text\" value=\"SPACE\" />"
71         "        </element>"
72         "    </add>"
73         "</patch>";
74     }
75 
76 private:
77     /// Construct the scene content.
78     void CreateScene();
79     /// Construct an instruction text to the UI.
80     void CreateInstructions();
81     /// Set up a viewport for displaying the scene.
82     void SetupViewport();
83     /// Subscribe to application-wide logic update events.
84     void SubscribeToEvents();
85     /// Read input and move the camera.
86     void MoveCamera(float timeStep);
87     /// Animate the scene.
88     void AnimateObjects(float timeStep);
89     /// Handle the logic update event.
90     void HandleUpdate(StringHash eventType, VariantMap& eventData);
91 
92     /// Box scene nodes.
93     Vector<SharedPtr<Node> > boxNodes_;
94     /// Animation flag.
95     bool animate_;
96     /// Group optimization flag.
97     bool useGroups_;
98 };
99