vivienneanthony

Unnecessary Headers but still

Jul 14th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.97 KB | None | 0 0
  1. //
  2. // Copyright (c) 2008-2014 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. #include <Urho3D/Urho3D.h>
  24.  
  25. #include "../../../Urho3D/Core/CoreEvents.h"
  26. #include "../../../Urho3D/Engine/Engine.h"
  27. #include "../../../Urho3D/UI/Font.h"
  28. #include "../../../Urho3D/Input/Input.h"
  29. #include "../../../Urho3D/Core/ProcessUtils.h"
  30. #include "../../../Urho3D/UI/Text.h"
  31. #include "../../../Urho3D/UI/UI.h"
  32. #include "../../../Urho3D/Scene/Scene.h"
  33. #include "../../../Urho3D/Graphics/StaticModel.h"
  34. #include "../../../Urho3D/Graphics/Octree.h"
  35. #include "../../../Urho3D/Graphics/Model.h"
  36. #include "../../../Urho3D/Graphics/Material.h"
  37. #include "../../../Urho3D/Graphics/Camera.h"
  38. #include "../../../Urho3D/Resource/ResourceCache.h"
  39. #include "../../../Urho3D/Graphics/Renderer.h"
  40. #include "../../../Urho3D/Graphics/Camera.h"
  41. #include "../../../Urho3D/UI/Window.h"
  42. #include "../../../Urho3D/UI/Button.h"
  43. #include "../../../Urho3D/UI/LineEdit.h"
  44. #include "../../../Urho3D/UI/UIElement.h"
  45. #include "../../../Urho3D/Math/BoundingBox.h"
  46. #include "../../../Urho3D/UI/UIEvents.h"
  47. #include "../../../Urho3D/Graphics/DebugRenderer.h"
  48. #include "../../../Urho3D/IO/File.h"
  49. #include "../../../Urho3D/IO/FileSystem.h"
  50. #include "../../../Urho3D/Resource/XMLFile.h"
  51. #include "../../../Urho3D/Resource/XMLElement.h"
  52. #include "../../../Urho3D/IO/Deserializer.h"
  53. #include "../../../Urho3D/UI/Cursor.h"
  54. #include "../../../Urho3D/IO/FileSystem.h"
  55. #include "../../../Urho3D/UI/ListView.h"
  56. #include "../../../Urho3D/Engine/Console.h"
  57. #include "../../../Urho3D/Physics/RigidBody.h"
  58. #include "../../../Urho3D/Physics/CollisionShape.h"
  59. #include "../../../Urho3D/Physics/PhysicsWorld.h"
  60. #include "../../../Urho3D/Graphics/Animation.h"
  61. #include "../../../Urho3D/Graphics/AnimatedModel.h"
  62. #include "../../../Urho3D/Graphics/AnimationController.h"
  63. #include "../../../Urho3D/UI/BorderImage.h"
  64. #include "../../../Urho3D/Graphics/GraphicsEvents.h"
  65. #include "../../../Urho3D/Graphics/Terrain.h"
  66. #include "../../../Urho3D/Engine/EngineEvents.h"
  67. #include "../../../Urho3D/Graphics/Zone.h"
  68. #include "../../../Urho3D/IO/Log.h"
  69. #include "../../../Urho3D/Graphics/Skybox.h"
  70. #include "../../../Urho3D/UI/Sprite.h"
  71. #include "../../../Urho3D/Graphics/StaticModelGroup.h"
  72. #include "../../../Urho3D/Graphics/BillboardSet.h"
  73. #include "../../../Urho3D/Math/Random.h"
  74. #include "../../../Urho3D/Graphics/RenderPath.h"
  75. #include "../../../Urho3D/Math/Color.h"
  76. #include "../../../Urho3D/Script/ScriptFile.h"
  77. #include "../../../Urho3D/Script/Script.h"
  78. #include <Urho3D/IO/Log.h>
  79. #include <Urho3D/Core/Main.h>
  80. #include <Urho3D/Core/ProcessUtils.h>
  81. #include <Urho3D/Resource/ResourceCache.h>
  82. #include <Urho3D/Resource/ResourceEvents.h>
  83.  
  84. #include "../ExistenceComponents/GameObject.h"
  85. #include "../ExistenceComponents/InteractObject.h"
  86. #include "../ExistenceComponents/Character.h"
  87. #include "../Account.h"
  88.  
  89. #include <string>
  90. #include <iostream>
  91. #include <sstream>
  92. #include <vector>
  93. #include <iterator>
  94. #include <algorithm>
  95. #include <locale>
  96. #include <ctime>
  97. #include <cmath>
  98. #include <iomanip>
  99. #include <fstream>
  100. #include <cstdlib>
  101. #include <iostream>
  102. #include <utility>
  103. #include <algorithm>
  104.  
  105. #include "../../../Urho3D/Procedural/Procedural.h"
  106. #include "../../../Urho3D/Procedural/ProceduralTerrain.h"
  107. #include "../../../Urho3D/Procedural/RandomNumberGenerator.h"
  108.  
  109. #include "ExistenceEditor.h"
  110.  
  111. #include "../../Urho3D/Engine/DebugHud.h"
  112.  
  113. #define DEFAULTSIZE 4096
  114.  
  115. using namespace std;
  116. using namespace Urho3D;
  117.  
  118.  
  119. // Expands to this example's entry-point
  120. DEFINE_APPLICATION_MAIN(ExistenceEditor)
  121.  
  122.  
  123. ExistenceEditor::ExistenceEditor(Context* context) :
  124. Application(context)
  125. {
  126. /// Register
  127.  
  128. context_ -> RegisterFactory<Character> ("Character");
  129. context_ -> RegisterFactory<GameObject> ("GameObject");
  130. context_ -> RegisterFactory<InteractObject> ("InteractObject");
  131. context_ -> RegisterFactory<ProceduralTerrain> ("PoceduralTerrain");
  132.  
  133. cout << "Debig: Existence Editor Existence " << &applicationPtr << endl;
  134.  
  135. /// Register states
  136. cout << "Debug: Existence Editor Base Class Constructor context" << &context << " context_"<< &context_ << endl;
  137.  
  138. return;
  139. }
  140.  
  141. ExistenceEditor::~ExistenceEditor()
  142. {
  143. cout << "Debug: Existence Editor Base Class Deconstructor" << endl;
  144.  
  145. return;
  146. }
  147.  
  148.  
  149. void ExistenceEditor::Setup()
  150. {
  151. FileSystem* filesystem = GetSubsystem<FileSystem>();
  152.  
  153. // Read command line from a file if no arguments given. This is primarily intended for mobile platforms.
  154. // Note that the command file name uses a hardcoded path that does not utilize the resource system
  155. // properly (including resource path prefix), as the resource system is not yet initialized at this point
  156. const String commandFileName = filesystem->GetProgramDir() + "Data/CommandLine.txt";
  157. if (GetArguments().Empty() && filesystem->FileExists(commandFileName))
  158. {
  159. SharedPtr<File> commandFile(new File(context_, commandFileName));
  160. String commandLine = commandFile->ReadLine();
  161. commandFile->Close();
  162. ParseArguments(commandLine, false);
  163. // Reparse engine startup parameters now
  164. engineParameters_ = Engine::ParseParameters(GetArguments());
  165. }
  166.  
  167. // Check for script file name
  168. const Vector<String>& arguments = GetArguments();
  169. String scriptFileName;
  170. if (arguments.Size() && arguments[0][0] != '-')
  171. scriptFileName_ = GetInternalPath(arguments[0]);
  172.  
  173. // Show usage if not found
  174. if (scriptFileName_.Empty())
  175. {
  176. // Set file
  177. scriptFileName_=String("Scripts/Editor.as");
  178. }
  179. else
  180. {
  181. // Use the script file name as the base name for the log file
  182. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("urho3d", "logs") + GetFileNameAndExtension(scriptFileName_) + ".log";
  183. }
  184. }
  185.  
  186. void ExistenceEditor::Start()
  187. {
  188.  
  189. String extension = GetExtension(scriptFileName_);
  190.  
  191. if (extension != ".lua" && extension != ".luc")
  192. {
  193.  
  194. // Instantiate and register the AngelScript subsystem
  195. context_->RegisterSubsystem(new Script(context_));
  196.  
  197. // Hold a shared pointer to the script file to make sure it is not unloaded during runtime
  198. scriptFile_ = GetSubsystem<ResourceCache>()->GetResource<ScriptFile>(scriptFileName_);
  199.  
  200. /// \hack If we are running the editor, also instantiate Lua subsystem to enable editing Lua ScriptInstances
  201.  
  202. // If script loading is successful, proceed to main loop
  203. if (scriptFile_ && scriptFile_->Execute("void Start()"))
  204. {
  205. // Subscribe to script's reload event to allow live-reload of the application
  206. SubscribeToEvent(scriptFile_, E_RELOADSTARTED, HANDLER(ExistenceEditor, HandleScriptReloadStarted));
  207. SubscribeToEvent(scriptFile_, E_RELOADFINISHED, HANDLER(ExistenceEditor, HandleScriptReloadFinished));
  208. SubscribeToEvent(scriptFile_, E_RELOADFAILED, HANDLER(ExistenceEditor, HandleScriptReloadFailed));
  209. return;
  210. }
  211. }
  212.  
  213. // The script was not successfully loaded. Show the last error message and do not run the main loop
  214. ErrorExit();
  215. }
  216.  
  217. void ExistenceEditor::Stop()
  218. {
  219. if (scriptFile_)
  220. {
  221. // Execute the optional stop function
  222. if (scriptFile_->GetFunction("void Stop()"))
  223. scriptFile_->Execute("void Stop()");
  224. }
  225.  
  226. }
  227.  
  228. void ExistenceEditor::HandleScriptReloadStarted(StringHash eventType, VariantMap& eventData)
  229. {
  230.  
  231. if (scriptFile_->GetFunction("void Stop()"))
  232. scriptFile_->Execute("void Stop()");
  233.  
  234. }
  235.  
  236. void ExistenceEditor::HandleScriptReloadFinished(StringHash eventType, VariantMap& eventData)
  237. {
  238.  
  239. // Restart the script application after reload
  240. if (!scriptFile_->Execute("void Start()"))
  241. {
  242. scriptFile_.Reset();
  243. ErrorExit();
  244. }
  245.  
  246. }
  247.  
  248. void ExistenceEditor::HandleScriptReloadFailed(StringHash eventType, VariantMap& eventData)
  249. {
  250.  
  251. scriptFile_.Reset();
  252. ErrorExit();
  253.  
  254. }
Advertisement
Add Comment
Please, Sign In to add comment