[Orxonox-commit 6549] r11190 - in code/branches/plehmannFS16/src/orxonox/controllers: . scriptTasks
plehmann at orxonox.net
plehmann at orxonox.net
Thu May 19 17:34:38 CEST 2016
Author: plehmann
Date: 2016-05-19 17:34:38 +0200 (Thu, 19 May 2016)
New Revision: 11190
Modified:
code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc
code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h
code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.cc
code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.h
Log:
modified newScriptController to prevent memory leacks caused by tasks
Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc 2016-05-19 15:34:38 UTC (rev 11190)
@@ -129,87 +129,116 @@
task->tick(dt);
}*/
- if(this->taskList_.size() != 0)
+ if(!this->taskList_.empty())
{
+ orxout() << scTime_ << endl;
- orxout() << this->scTime_ << endl;
+ orxout() << taskList_.size() << endl;
- if(this->taskList_.front().getStartTime() < this->scTime_)
+
+ if(this->taskList_.front()->getStartTime() < this->scTime_)
{
- activeTasks_.push_back(this->taskList_.front());
- this->taskList_.pop_front();
+ activeTasks_.push_back(this->taskList_.front());
+ this->taskList_.pop_front();
}
}
else
{
- //orxout() << "no tasks in taskList_" << endl;
+ orxout() << "no tasks in taskList_" << endl;
}
-
- for (std::vector<Task>::iterator it = activeTasks_.begin(); it != activeTasks_.end(); it++)
+
+ std::vector<Task*>::iterator it = activeTasks_.begin();
+ while (it != activeTasks_.end() )
{
- if( !(it->update(dt)) )
+ if( !((*it)->update(dt)) )
{
- activeTasks_.erase(it);
- it--; // set back the iterator so we continue with the next element and not with the one after that
+ (*(*it)).destroyLater();
+ it = activeTasks_.erase(it);
}
+ else
+ {
+ it++;
+ }
+
}
+
scTime_ += dt;
}
-
- void NewScriptController::createAndAddTask(Task newTask)
- {
- //taskQueue_->push(newTask);
- }
-
void NewScriptController::debugOut(float startTime)
{
- DebugTask task = DebugTask(context_);
- task.initialize(startTime);
+ DebugTask* task = new DebugTask(context_);
+
+ task->initialize(startTime);
+
+ bool inserted = false;
+
if(taskList_.empty())
{
taskList_.push_front(task);
+ inserted = true;
}
else
{
- for (std::list<Task>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
+ for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
{
- orxout() << taskList_.empty() << endl;
+ orxout() << "debugOutTask" << endl;
- if(task.getStartTime() < it->getStartTime() )
+ if(task->getStartTime() < (*it)->getStartTime() )
{
taskList_.insert(it, task);
+ inserted = true;
+ break;
}
}
}
+
+ if (!inserted)
+ {
+ taskList_.push_back(task);
+ }
+
}
void NewScriptController::stringOut(float startTime, std::string output)
{
- stringOutTask task = stringOutTask(context_);
- task.initialize(startTime, output);
+ stringOutTask* task = new stringOutTask(context_);
+
+ task->initialize(startTime, output);
+
+ bool inserted = false;
+
if(taskList_.empty())
{
taskList_.push_front(task);
+ inserted = true;
}
else
{
- for (std::list<Task>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
+ for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
{
- orxout() << taskList_.empty() << endl;
+ orxout() << "stringOutTask" << endl;
- if(task.getStartTime() < it->getStartTime() )
+ if(task->getStartTime() < (*it)->getStartTime() )
{
taskList_.insert(it, task);
+ inserted = true;
+ break;
}
}
}
+
+ if (!inserted)
+ {
+ taskList_.push_back(task);
+ }
+
}
NewScriptController* NewScriptController::getNewScriptController()
Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h 2016-05-19 15:34:38 UTC (rev 11190)
@@ -67,9 +67,6 @@
void printDebug() {orxout() << "fffff" << endl;} // tolua_export
-
- void createAndAddTask(Task newTask);
-
private:
// Information about the player that this ScriptController will
// control
@@ -84,11 +81,10 @@
int ctrlid_;
// List of events to walk through sorted by starting times
- std::list<Task> taskList_;
+ std::list<Task*> taskList_;
-
//List of Tasks currently active
- std::vector<Task> activeTasks_;
+ std::vector<Task*> activeTasks_;
// Time since the creation of this ScriptController object
float scTime_;
Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc 2016-05-19 15:34:38 UTC (rev 11190)
@@ -48,13 +48,16 @@
this->player_ = player;
this->entity_ = this->player_->getControllableEntity();
this->destination_ = destination;
+ this->velocity_ = velocity;
this->entity->setVelocity( Vector3(0,0,0) )
}
bool MoveToTask::update(float dt)
{
+ float dl = this->velocity_ * dt;
+
/* Set the position to the correct place in the trajectory */
this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h 2016-05-19 15:34:38 UTC (rev 11190)
@@ -61,6 +61,8 @@
vector3 destination_;
+ float velocity_;
+
};
}
Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.cc 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.cc 2016-05-19 15:34:38 UTC (rev 11190)
@@ -37,7 +37,7 @@
RegisterClass(Task);
- Task::Task(Context* context)
+ Task::Task(Context* context) : BaseObject(context)
{
RegisterObject(Task);
startTime_ = -1;
@@ -48,9 +48,4 @@
startTime_ = startTime;
}
- bool Task::update(float dt)
- {
- SUPER(Task, tick, dt);
- }
-
}
\ No newline at end of file
Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.h 2016-05-19 15:04:41 UTC (rev 11189)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.h 2016-05-19 15:34:38 UTC (rev 11190)
@@ -31,11 +31,12 @@
#include "infos/PlayerInfo.h"
#include "tools/interfaces/Tickable.h"
-#include "core/class/OrxonoxClass.h"
+//#include "core/class/OrxonoxClass.h"
+#include "core/BaseObject.h"
namespace orxonox
{
- class _OrxonoxExport Task : public OrxonoxClass {
+ class _OrxonoxExport Task : public BaseObject {
public:
Task(Context* context);
@@ -45,7 +46,7 @@
void initialize(float startTime);
//important return true while the task is running and false to stop it!!!
- virtual bool update(float dt);
+ virtual bool update(float dt) {return false;}
float getStartTime()
{return startTime_;}
More information about the Orxonox-commit
mailing list