/
Metallist64
/
rbfx
Обзор
Документация
Войти
/
Metallist64
/
rbfx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Samples/Sample.h
146 строк
5 KB
gleblebedev
Pointer adapter (#533)
23 апр 2023, 18:36
Не верифицирован
23 апр 2023, 18:36
d58e94b
Код
Авторство
О чём код?
// // Copyright (c) 2008-2022 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #pragma once #include <Urho3D/Engine/Application.h> #include <Urho3D/Graphics/Camera.h> #include <Urho3D/SystemUI/Console.h> #include <Urho3D/UI/Cursor.h> #if URHO3D_SYSTEMUI #include <Urho3D/SystemUI/DebugHud.h> #endif #include <Urho3D/Engine/StateManager.h> #include <Urho3D/Engine/Engine.h> #include <Urho3D/Engine/EngineDefs.h> #include <Urho3D/IO/FileSystem.h> #include <Urho3D/Graphics/Graphics.h> #include <Urho3D/Input/Input.h> #include <Urho3D/Input/InputEvents.h> #include <Urho3D/Graphics/Renderer.h> #include <Urho3D/Resource/ResourceCache.h> #include <Urho3D/Scene/Node.h> #include <Urho3D/Scene/Scene.h> #include <Urho3D/Scene/SceneEvents.h> #include <Urho3D/UI/Sprite.h> #include <Urho3D/Graphics/Texture2D.h> #include <Urho3D/Core/Timer.h> #include <Urho3D/UI/UI.h> #include <Urho3D/Resource/XMLFile.h> #include <Urho3D/IO/Log.h> #include <Urho3D/Core/Profiler.h> // All Urho3D classes reside in namespace Urho3D using namespace Urho3D; const float TOUCH_SENSITIVITY = 2.0f; /// Send this event to exit sample. URHO3D_EVENT(E_SAMPLE_EXIT_REQUESTED, SampleExitRequested) { } /// Sample class, as framework for all samples. /// - Initialization of the Urho3D engine (in Application class) /// - Modify engine parameters for windowed mode and to show the class name as title /// - Create Urho3D logo at screen /// - Set custom window title and icon /// - Create Console and Debug HUD, and use F1 and F2 key to toggle them /// - Toggle rendering options from the keys 1-8 /// - Take screenshot with key 9 /// - Handle Esc key down to hide Console or exit application /// - Init touch input on mobile platform using screen joysticks (patched for each individual sample) class Sample : public ApplicationState { // Enable type information. URHO3D_OBJECT(Sample, ApplicationState); public: /// Construct. explicit Sample(Context* context); /// Activate game state. Executed by StateManager. virtual void Activate(StringVariantMap& bundle) override; /// Deactivate game state. Executed by StateManager. virtual void Deactivate() override; /// Setup after engine initialization with optional command line parameters. virtual void Start(const ea::vector<ea::string>& args); /// Setup after engine initialization. Creates the logo, console & debug HUD. virtual void Start(); /// Cleanup after the main loop. Called by Application. virtual void Stop(); /// Return whether the Esc button should close sample. virtual bool IsEscapeEnabled() { return true; } protected: /// Create or update skybox with default model and material. void SetDefaultSkybox(Scene* scene); /// Return XML patch instructions for screen joystick layout for a specific sample app, if any. virtual ea::string GetScreenJoystickPatchString() const { return EMPTY_STRING; } /// Initialize touch input on mobile platform. void InitTouchInput(); /// Control logo visibility. void SetLogoVisible(bool enable); /// void CloseSample(); /// Logo sprite. SharedPtr<Sprite> logoSprite_; /// Scene. SharedPtr<Scene> scene_; /// Camera scene node. SharedPtr<Node> cameraNode_; /// Camera yaw angle. float yaw_; /// Camera pitch angle. float pitch_; /// Flag to indicate whether touch input has been enabled. bool touchEnabled_; private: /// Create logo. void CreateLogo(); /// Set custom window Title & Icon void SetWindowTitleAndIcon(); /// Create console and debug HUD. void CreateConsoleAndDebugHud(); /// Handle key down event to process key controls common to all samples. void HandleKeyDown(StringHash eventType, VariantMap& eventData); /// Handle key up event to process key controls common to all samples. void HandleKeyUp(StringHash eventType, VariantMap& eventData); /// Handle scene update event to control camera's pitch and yaw for all samples. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData); /// Handle touch begin event to initialize touch input on desktop platform. void HandleTouchBegin(StringHash eventType, VariantMap& eventData); /// Screen joystick index for navigational controls (mobile platforms only). unsigned screenJoystickIndex_; /// Screen joystick index for settings (mobile platforms only). unsigned screenJoystickSettingsIndex_; /// Pause flag. bool paused_; };