ScriptScene.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #include <functional>
  2. #include "NullSystemObjects.h"
  3. #include "ScriptSystem.h"
  4. #include "ScriptScene.h"
  5. #include "TaskManagerLocator.h"
  6. ScriptScene::ScriptScene(ScriptSystem *p_system, SceneLoader *p_sceneLoader) : SystemScene(p_system, p_sceneLoader)
  7. {
  8. m_scriptingTask = nullptr;
  9. }
  10. ScriptScene::~ScriptScene()
  11. {
  12. if(m_scriptingTask != nullptr)
  13. delete m_scriptingTask;
  14. }
  15. ErrorCode ScriptScene::init()
  16. {
  17. m_scriptingTask = new ScriptTask(this);
  18. return ErrorCode::Success;
  19. }
  20. ErrorCode ScriptScene::setup(const PropertySet &p_properties)
  21. {
  22. // Get default object pool size
  23. decltype(m_scriptObjects.getPoolSize()) objectPoolSize = Config::objectPoolVar().object_pool_size;
  24. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  25. {
  26. switch(p_properties[i].getPropertyID())
  27. {
  28. case Properties::ObjectPoolSize:
  29. objectPoolSize = p_properties[i].getInt();
  30. break;
  31. }
  32. }
  33. // Initialize object pools
  34. m_scriptObjects.init(objectPoolSize);
  35. return ErrorCode::Success;
  36. }
  37. void ScriptScene::update(const float p_deltaTime)
  38. {
  39. for(decltype(m_scriptObjects.getPoolSize()) i = 0, numAllocObjecs = 0, totalNumAllocObjs = m_scriptObjects.getNumAllocated(),
  40. size = m_scriptObjects.getPoolSize(); i < size && numAllocObjecs < totalNumAllocObjs; i++)
  41. {
  42. // Check if the script object is allocated inside the pool container
  43. if(m_scriptObjects[i].allocated())
  44. {
  45. auto *scriptObject = m_scriptObjects[i].getObject();
  46. // Increment the number of allocated objects (early bail mechanism)
  47. numAllocObjecs++;
  48. // Check if the script object is enabled
  49. if(scriptObject->isObjectActive())
  50. {
  51. // Update the object
  52. scriptObject->update(p_deltaTime);
  53. }
  54. }
  55. }
  56. }
  57. void ScriptScene::loadInBackground()
  58. {
  59. // Iterate over script objects and start loading them in background
  60. for(decltype(m_scriptObjects.getPoolSize()) i = 0, size = m_scriptObjects.getPoolSize(); i < size; i++)
  61. {
  62. // TODO: load in background implementation
  63. //TaskManagerLocator::get().startBackgroundThread(std::bind(&ScriptObject::loadToMemory, m_scriptObjects[i]));
  64. }
  65. }
  66. ErrorCode ScriptScene::preload()
  67. {
  68. // Load every script object. It still works in parallel, however,
  69. // it returns only when all objects have finished loading (simulating sequential call)
  70. TaskManagerLocator::get().parallelFor(size_t(0), m_scriptObjects.getPoolSize(), size_t(1), [=](size_t i)
  71. {
  72. if(m_scriptObjects[i].allocated())
  73. {
  74. m_scriptObjects[i].getObject()->loadToMemory();
  75. }
  76. });
  77. return ErrorCode::Success;
  78. }
  79. PropertySet ScriptScene::exportObject()
  80. {
  81. //// Create the root property set
  82. PropertySet propertySet(Properties::Script);
  83. //// Add root property set for scene values
  84. //auto &scene = propertySet.addPropertySet(Properties::Scene);
  85. //// Add root property set for all the objects
  86. //auto &objects = propertySet.addPropertySet(Properties::Objects);
  87. //// Add script object property sets
  88. //for(decltype(m_scriptObjects.size()) i = 0, size = m_scriptObjects.size(); i < size; i++)
  89. // objects.addPropertySet(m_scriptObjects[i]->exportObject());
  90. return propertySet;
  91. }
  92. SystemObject *ScriptScene::createObject(const PropertySet &p_properties)
  93. {
  94. // Check if property set node is present
  95. if(p_properties)
  96. {
  97. // Check if the rendering property is present
  98. auto &scriptProperty = p_properties.getPropertySetByID(Properties::Script);
  99. if(scriptProperty)
  100. {
  101. // Get the object name
  102. auto &nameProperty = p_properties.getPropertyByID(Properties::Name);
  103. // Find a place for the new object in the pool
  104. auto scriptObjectFromPool = m_scriptObjects.newObject();
  105. // Check if the pool wasn't full
  106. if(scriptObjectFromPool != nullptr)
  107. {
  108. std::string name;
  109. // If the name property is missing, generate a unique name based on the object's index in the pool
  110. if(nameProperty)
  111. name = nameProperty.getString() + " (" + GetString(Properties::ScriptObject) + ")";
  112. else
  113. name = GetString(Properties::ScriptObject) + Utilities::toString(scriptObjectFromPool->getIndex());
  114. // Construct the GraphicsObject
  115. scriptObjectFromPool->construct(this, name);
  116. auto scriptObject = scriptObjectFromPool->getObject();
  117. //graphicsObject->importObject(renderingProperty);
  118. // Start importing the newly created object in a background thread
  119. //TaskManagerLocator::get().startBackgroundThread(std::bind(&ScriptObject::importObject, scriptObject, scriptProperty));
  120. scriptObject->importObject(scriptProperty);
  121. return scriptObject;
  122. }
  123. else
  124. {
  125. ErrHandlerLoc::get().log(ErrorCode::ObjectPool_full, ErrorSource::Source_Script, "Failed to add ScriptObject - \'" + nameProperty.getString() + "\'");
  126. }
  127. }
  128. }
  129. // If valid type was not specified, or object creation failed, return a null object instead
  130. return g_nullSystemBase.getScene()->createObject(p_properties);
  131. /*/ Get certain object properties
  132. auto const &type = p_properties.getPropertyByID(Properties::Type).getID();
  133. SystemObject *newObject = nullptr;
  134. // Create the object by it's type
  135. switch(type)
  136. {
  137. case Properties::FreeCamera:
  138. newObject = loadFreeCamera(p_properties);
  139. break;
  140. case Properties::DebugUIScript:
  141. newObject = loadDebugUI(p_properties);
  142. break;
  143. case Properties::DebugMoveScript:
  144. newObject = loadDebugMove(p_properties);
  145. break;
  146. case Properties::DebugRotateScript:
  147. newObject = loadDebugRotate(p_properties);
  148. break;
  149. case Properties::SolarTimeScript:
  150. newObject = loadSolarTime(p_properties);
  151. break;
  152. case Properties::SunScript:
  153. newObject = loadSun(p_properties);
  154. break;
  155. case Properties::WorldEditScript:
  156. newObject = loadWorldEdit(p_properties);
  157. break;
  158. }
  159. // If the object creation was successful, return the new object
  160. if(newObject != nullptr)
  161. return newObject;
  162. // If valid type was not specified, or object creation failed, return a null object instead
  163. return g_nullSystemBase.getScene()->createObject(p_properties);*/
  164. }
  165. ErrorCode ScriptScene::destroyObject(SystemObject *p_systemObject)
  166. {
  167. // Check if object is valid and belongs to graphics system
  168. if(p_systemObject != nullptr && p_systemObject->getSystemType() == Systems::Graphics)
  169. {
  170. // Cast the system object to graphics object, as it belongs to the renderer scene
  171. ScriptObject *objectToDestroy = static_cast<ScriptObject *>(p_systemObject);
  172. // Try to destroy the object; return success if it succeeds
  173. if(removeObjectFromPool(*objectToDestroy))
  174. return ErrorCode::Success;
  175. }
  176. // If this point is reached, no object was found, return an appropriate error
  177. return ErrorCode::Destroy_obj_not_found;
  178. }
  179. void ScriptScene::changeOccurred(ObservedSubject *p_subject, BitMask p_changeType)
  180. {
  181. }
  182. FreeCamera *ScriptScene::loadFreeCamera(const PropertySet & p_properties)
  183. {
  184. FreeCamera *freeCamera = new FreeCamera(this, p_properties.getPropertyByID(Properties::Name).getString());
  185. // Get key-bindings from the property
  186. const auto &keybindings = p_properties.getPropertySetByID(Properties::Keybindings);
  187. // Declare keys
  188. Scancode forwardKey = Key_Invalid;
  189. Scancode backwardKey = Key_Invalid;
  190. Scancode leftStrafeKey = Key_Invalid;
  191. Scancode rightStrafeKey = Key_Invalid;
  192. Scancode sprintKey = Key_Invalid;
  193. // Check if key-bindings in the property are present
  194. if(keybindings.getPropertyID() != Properties::Null)
  195. {
  196. forwardKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::ForwardKey).getInt());
  197. backwardKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::BackwardKey).getInt());
  198. leftStrafeKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::LeftStrafeKey).getInt());
  199. rightStrafeKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::RightStrafeKey).getInt());
  200. sprintKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::SprintKey).getInt());
  201. }
  202. // Check validity of each key, use a default value in case they are invalid
  203. if(forwardKey == Scancode::Key_Invalid)
  204. forwardKey = static_cast<Scancode>(Config::inputVar().forward_key);
  205. if(backwardKey == Scancode::Key_Invalid)
  206. backwardKey = static_cast<Scancode>(Config::inputVar().backward_key);
  207. if(leftStrafeKey == Scancode::Key_Invalid)
  208. leftStrafeKey = static_cast<Scancode>(Config::inputVar().left_strafe_key);
  209. if(rightStrafeKey == Scancode::Key_Invalid)
  210. rightStrafeKey = static_cast<Scancode>(Config::inputVar().right_strafe_key);
  211. if(sprintKey == Scancode::Key_Invalid)
  212. sprintKey = static_cast<Scancode>(Config::inputVar().sprint_key);
  213. // Load property data
  214. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  215. {
  216. switch(p_properties[i].getPropertyID())
  217. {
  218. case Properties::LocalPosition:
  219. freeCamera->setPosition(p_properties[i].getVec3f());
  220. break;
  221. case Properties::Angle:
  222. freeCamera->setAngles(p_properties[i].getVec2f());
  223. break;
  224. case Properties::LowerLimit:
  225. freeCamera->setLowerLimit(p_properties[i].getFloat());
  226. break;
  227. case Properties::Speed:
  228. freeCamera->setSpeed(p_properties[i].getFloat());
  229. break;
  230. case Properties::SprintSpeed:
  231. freeCamera->setFasterSpeed(p_properties[i].getFloat());
  232. break;
  233. case Properties::UpperLimit:
  234. freeCamera->setUpperLimit(p_properties[i].getFloat());
  235. break;
  236. }
  237. }
  238. // Check if the movement speeds were set
  239. if(freeCamera->m_speed == 0.0f)
  240. freeCamera->m_speed = Config::gameplayVar().camera_freelook_speed;
  241. if(freeCamera->m_fasterSpeed == 0.0f)
  242. freeCamera->m_fasterSpeed = freeCamera->m_speed * 10.0f;
  243. // Set the keys of the object
  244. freeCamera->setForwardKey(forwardKey);
  245. freeCamera->setBackwardKey(backwardKey);
  246. freeCamera->setStrafeLeftKey(leftStrafeKey);
  247. freeCamera->setStrafeRightKey(rightStrafeKey);
  248. freeCamera->setSprintKey(sprintKey);
  249. //m_scriptObjects.push_back(freeCamera);
  250. return freeCamera;
  251. }
  252. DebugUIScript *ScriptScene::loadDebugUI(const PropertySet &p_properties)
  253. {
  254. DebugUIScript *debugUI = new DebugUIScript(this, p_properties.getPropertyByID(Properties::Name).getString());
  255. // Get key-bindings from the property
  256. const auto &keybindings = p_properties.getPropertySetByID(Properties::Keybindings);
  257. // Declare keys
  258. Scancode closeWindowKey;
  259. Scancode fullscreenKey;
  260. Scancode mouseCaptureKey;
  261. Scancode verticalSyncKey;
  262. // Check if key-bindings in the property are present
  263. if(keybindings.getPropertyID() != Properties::Null)
  264. {
  265. closeWindowKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::CloseKey).getInt());
  266. fullscreenKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::DebugFullscreenKey).getInt());
  267. mouseCaptureKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::DebugCaptureMouseKey).getInt());
  268. verticalSyncKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::DebugVertSyncKey).getInt());
  269. // Check validity of each key, use a default value in case they are invalid
  270. if(closeWindowKey == Scancode::Key_Invalid)
  271. closeWindowKey = Utilities::toScancode(Config::inputVar().close_window_key);
  272. if(fullscreenKey == Scancode::Key_Invalid)
  273. fullscreenKey = Utilities::toScancode(Config::inputVar().fullscreen_key);
  274. if(mouseCaptureKey == Scancode::Key_Invalid)
  275. mouseCaptureKey = Utilities::toScancode(Config::inputVar().clip_mouse_key);
  276. if(verticalSyncKey == Scancode::Key_Invalid)
  277. verticalSyncKey = Utilities::toScancode(Config::inputVar().vsync_key);
  278. }
  279. else
  280. {
  281. closeWindowKey = Utilities::toScancode(Config::inputVar().close_window_key);
  282. fullscreenKey = Utilities::toScancode(Config::inputVar().fullscreen_key);
  283. mouseCaptureKey = Utilities::toScancode(Config::inputVar().clip_mouse_key);
  284. verticalSyncKey = Utilities::toScancode(Config::inputVar().vsync_key);
  285. }
  286. debugUI->setCloseWindowKey(closeWindowKey);
  287. debugUI->setFullscreenKey(fullscreenKey);
  288. debugUI->setMouseCaptureKey(mouseCaptureKey);
  289. debugUI->setVerticalSyncKey(verticalSyncKey);
  290. //m_scriptObjects.push_back(debugUI);
  291. return debugUI;
  292. }
  293. DebugMoveScript *ScriptScene::loadDebugMove(const PropertySet &p_properties)
  294. {
  295. DebugMoveScript *debugMove = new DebugMoveScript(this, p_properties.getPropertyByID(Properties::Name).getString());
  296. // Load property data
  297. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  298. {
  299. switch(p_properties[i].getPropertyID())
  300. {
  301. case Properties::LocalPosition:
  302. debugMove->setOriginPosition(p_properties[i].getVec3f());
  303. break;
  304. case Properties::Radius:
  305. debugMove->setRadius(p_properties[i].getFloat());
  306. break;
  307. case Properties::LocalRotation:
  308. debugMove->setMovementAxis(p_properties[i].getVec3f());
  309. break;
  310. case Properties::Speed:
  311. debugMove->setMovementSpeed(p_properties[i].getFloat());
  312. break;
  313. }
  314. }
  315. //m_scriptObjects.push_back(debugMove);
  316. return debugMove;
  317. }
  318. DebugRotateScript *ScriptScene::loadDebugRotate(const PropertySet &p_properties)
  319. {
  320. DebugRotateScript *debugRotate = new DebugRotateScript(this, p_properties.getPropertyByID(Properties::Name).getString());
  321. // Load property data
  322. for (decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  323. {
  324. switch (p_properties[i].getPropertyID())
  325. {
  326. case Properties::Axis:
  327. debugRotate->setRotationAxis(p_properties[i].getVec3f());
  328. break;
  329. case Properties::LocalRotation:
  330. debugRotate->setRotation(p_properties[i].getVec3f());
  331. break;
  332. case Properties::Speed:
  333. debugRotate->setMovementSpeed(p_properties[i].getFloat());
  334. break;
  335. }
  336. }
  337. //m_scriptObjects.push_back(debugRotate);
  338. return debugRotate;
  339. }
  340. SolarTimeScript *ScriptScene::loadSolarTime(const PropertySet & p_properties)
  341. {
  342. SolarTimeScript *solarTimeScript = new SolarTimeScript(this, p_properties.getPropertyByID(Properties::Name).getString());
  343. // Load property data
  344. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  345. {
  346. switch(p_properties[i].getPropertyID())
  347. {
  348. case Properties::Hours:
  349. solarTimeScript->setHours(p_properties[i].getInt());
  350. break;
  351. case Properties::Minutes:
  352. solarTimeScript->setMinutes(p_properties[i].getInt());
  353. break;
  354. case Properties::Seconds:
  355. solarTimeScript->setSeconds(p_properties[i].getFloat());
  356. break;
  357. case Properties::Year:
  358. solarTimeScript->setYear(p_properties[i].getInt());
  359. break;
  360. case Properties::Month:
  361. solarTimeScript->setMonth(p_properties[i].getInt());
  362. break;
  363. case Properties::Day:
  364. solarTimeScript->setDay(p_properties[i].getInt());
  365. break;
  366. case Properties::TimeZone:
  367. solarTimeScript->setTimeZone(p_properties[i].getInt());
  368. break;
  369. case Properties::Latitude:
  370. solarTimeScript->setLatitude(p_properties[i].getFloat());
  371. break;
  372. case Properties::Longitude:
  373. solarTimeScript->setLongitude(p_properties[i].getFloat());
  374. break;
  375. case Properties::TimeMultiplier:
  376. solarTimeScript->setTimeMultiplier(p_properties[i].getFloat());
  377. break;
  378. case Properties::OffsetPosition:
  379. solarTimeScript->setOffsetPosition(p_properties[i].getFloat());
  380. break;
  381. }
  382. }
  383. //m_scriptObjects.push_back(solarTimeScript);
  384. return solarTimeScript;
  385. }
  386. SunScript *ScriptScene::loadSun(const PropertySet & p_properties)
  387. {
  388. SunScript *sunScript = new SunScript(this, p_properties.getPropertyByID(Properties::Name).getString());
  389. // Load property data
  390. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  391. {
  392. switch(p_properties[i].getPropertyID())
  393. {
  394. case Properties::Azimuth:
  395. sunScript->setAzimuthAngle(p_properties[i].getFloat());
  396. break;
  397. case Properties::Zenith:
  398. sunScript->setZenithAngle(p_properties[i].getFloat());
  399. break;
  400. }
  401. }
  402. //m_scriptObjects.push_back(sunScript);
  403. return sunScript;
  404. }
  405. WorldEditScript *ScriptScene::loadWorldEdit(const PropertySet & p_properties)
  406. {
  407. WorldEditScript *worldEditor = new WorldEditScript(this, p_properties.getPropertyByID(Properties::Name).getString(), m_sceneLoader);
  408. // Get key-bindings from the property
  409. const auto &keybindings = p_properties.getPropertySetByID(Properties::Keybindings);
  410. // Declare keys
  411. Scancode upKey;
  412. Scancode downKey;
  413. Scancode leftKey;
  414. Scancode rightKey;
  415. Scancode forwardKey;
  416. Scancode backwardKey;
  417. Scancode nextKey;
  418. Scancode previousKey;
  419. Scancode fasterMovementKey;
  420. Scancode centerKey;
  421. Scancode saveKey;
  422. Scancode modifierKey;
  423. // Check if key-bindings in the property are present
  424. if(keybindings.getPropertyID() != Properties::Null)
  425. {
  426. upKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::UpKey).getInt());
  427. downKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::DownKey).getInt());
  428. leftKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::LeftKey).getInt());
  429. rightKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::RightKey).getInt());
  430. forwardKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::ForwardKey).getInt());
  431. backwardKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::BackwardKey).getInt());
  432. nextKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::NextKey).getInt());
  433. previousKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::PreviousKey).getInt());
  434. fasterMovementKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::SprintKey).getInt());
  435. centerKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::CenterKey).getInt());
  436. saveKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::SaveKey).getInt());
  437. modifierKey = Utilities::toScancode(keybindings.getPropertyByID(Properties::ModifierKey).getInt());
  438. // Check validity of each key, use a default value in case they are invalid
  439. if(upKey == Scancode::Key_Invalid)
  440. upKey = static_cast<Scancode>(Config::inputVar().up_editor_key);
  441. if(downKey == Scancode::Key_Invalid)
  442. downKey = static_cast<Scancode>(Config::inputVar().down_editor_key);
  443. if(leftKey == Scancode::Key_Invalid)
  444. leftKey = static_cast<Scancode>(Config::inputVar().left_editor_key);
  445. if(rightKey == Scancode::Key_Invalid)
  446. rightKey = static_cast<Scancode>(Config::inputVar().right_editor_key);
  447. if(forwardKey == Scancode::Key_Invalid)
  448. forwardKey = static_cast<Scancode>(Config::inputVar().forward_key);
  449. if(backwardKey == Scancode::Key_Invalid)
  450. backwardKey = static_cast<Scancode>(Config::inputVar().backward_key);
  451. if(nextKey == Scancode::Key_Invalid)
  452. nextKey = static_cast<Scancode>(Config::inputVar().next_editor_key);
  453. if(previousKey == Scancode::Key_Invalid)
  454. previousKey = static_cast<Scancode>(Config::inputVar().previous_editor_key);
  455. if(fasterMovementKey == Scancode::Key_Invalid)
  456. fasterMovementKey = static_cast<Scancode>(Config::inputVar().sprint_key);
  457. if(centerKey == Scancode::Key_Invalid)
  458. centerKey = static_cast<Scancode>(Config::inputVar().center_key);
  459. if(saveKey == Scancode::Key_Invalid)
  460. saveKey = static_cast<Scancode>(Config::inputVar().save_editor_key);
  461. if(modifierKey == Scancode::Key_Invalid)
  462. modifierKey = static_cast<Scancode>(Config::inputVar().modifier_editor_key);
  463. }
  464. else
  465. {
  466. // Set keys to default, if they key-bindings were not present
  467. upKey = static_cast<Scancode>(Config::inputVar().up_editor_key);
  468. downKey = static_cast<Scancode>(Config::inputVar().down_editor_key);
  469. leftKey = static_cast<Scancode>(Config::inputVar().left_editor_key);
  470. rightKey = static_cast<Scancode>(Config::inputVar().right_editor_key);
  471. forwardKey = static_cast<Scancode>(Config::inputVar().forward_key);
  472. backwardKey = static_cast<Scancode>(Config::inputVar().backward_key);
  473. nextKey = static_cast<Scancode>(Config::inputVar().next_editor_key);
  474. previousKey = static_cast<Scancode>(Config::inputVar().previous_editor_key);
  475. fasterMovementKey = static_cast<Scancode>(Config::inputVar().sprint_key);
  476. centerKey = static_cast<Scancode>(Config::inputVar().center_key);
  477. saveKey = static_cast<Scancode>(Config::inputVar().save_editor_key);
  478. modifierKey = static_cast<Scancode>(Config::inputVar().modifier_editor_key);
  479. }
  480. // Load property data
  481. for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
  482. {
  483. switch(p_properties[i].getPropertyID())
  484. {
  485. case Properties::Speed:
  486. worldEditor->setSpeed(p_properties[i].getFloat());
  487. break;
  488. case Properties::SprintSpeed:
  489. worldEditor->setFasterSpeed(p_properties[i].getFloat());
  490. break;
  491. }
  492. }
  493. // Check if the movement speeds were set
  494. //if(worldEditor->m_movementSpeed == 0.0f)
  495. // worldEditor->setSpeed(Config::gameplayVar().camera_freelook_speed);
  496. //if(worldEditor->m_fasterMovementSpeed == 0.0f)
  497. // worldEditor->setFasterSpeed(worldEditor->m_movementSpeed * 10.0f);
  498. // Set the keys of the object
  499. worldEditor->setUpKey(upKey);
  500. worldEditor->setDownKey(downKey);
  501. worldEditor->setLeftKey(leftKey);
  502. worldEditor->setRightKey(rightKey);
  503. worldEditor->setForwardKey(forwardKey);
  504. worldEditor->setBackwardKey(backwardKey);
  505. worldEditor->setNextKey(nextKey);
  506. worldEditor->setPreviousKey(previousKey);
  507. worldEditor->setFasterMovementKey(fasterMovementKey);
  508. worldEditor->setCenterKey(centerKey);
  509. worldEditor->setSaveKey(saveKey);
  510. worldEditor->setModifierKey(modifierKey);
  511. //m_scriptObjects.push_back(worldEditor);
  512. return worldEditor;
  513. }