1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02:00

Object Destruction

This commit is contained in:
Daniel Evans 2013-12-12 02:55:31 +00:00
parent 26e5172960
commit acb36be852
6 changed files with 66 additions and 5 deletions

View File

@ -98,6 +98,11 @@ public:
*/
GTACharacter* createPedestrian(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
/**
* Destroys an existing Object
*/
void destroyObject(GTAObject* object);
/**
* Game Clock
*/
@ -157,7 +162,7 @@ public:
* Pedestrians and PCs.
*/
std::vector<GTACharacter*> pedestrians;
/**
* AI Graph
*/

View File

@ -36,6 +36,8 @@ struct GTAObject
GTAObject(GTAEngine* engine, const glm::vec3& pos, const glm::quat& rot, Model* model)
: position(pos), rotation(rot), model(model), engine(engine), animator(nullptr), mHealth(0.f) {}
virtual ~GTAObject() {};
enum Type
{

View File

@ -285,3 +285,41 @@ GTACharacter* GTAEngine::createPedestrian(const uint16_t id, const glm::vec3 &po
}
return nullptr;
}
void GTAEngine::destroyObject(GTAObject* object)
{
if(object->type() == GTAObject::Character)
{
for(auto it = pedestrians.begin(); it != pedestrians.end(); ) {
if( *it == object ) {
pedestrians.erase(it++);
}
else {
++it;
}
}
}
else if(object->type() == GTAObject::Vehicle)
{
for(auto it = vehicleInstances.begin(); it != vehicleInstances.end(); ) {
if( *it == object ) {
vehicleInstances.erase(it++);
}
else {
++it;
}
}
}
else if(object->type() == GTAObject::Instance)
{
for(auto it = modelInstances.begin(); it != modelInstances.end(); ) {
if( it->second.get() == object ) {
modelInstances.erase(it++);
}
else {
++it;
}
}
}
delete object;
}

View File

@ -1,6 +1,7 @@
#define BOOST_TEST_MODULE gtfw
#include <boost/test/included/unit_test.hpp>
#include <SFML/Window.hpp>
#include <renderwure/engine/GTAEngine.hpp>
// Many tests require OpenGL be functional, seems like a reasonable solution.
@ -8,7 +9,7 @@ class GlobalFixture
{
public:
sf::Window wnd;
GlobalFixture() {
wnd.create(sf::VideoMode(640, 360), "Testing");
}

13
tests/test_world.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <boost/test/unit_test.hpp>
#include <renderwure/engine/GTAEngine.hpp>
BOOST_AUTO_TEST_SUITE(WorldTests)
GTAEngine e("");
BOOST_AUTO_TEST_CASE(world_object_destroy)
{
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -387,14 +387,16 @@ void update(float dt)
gta->renderer.camera.worldPos = plyPos;
gta->renderer.camera.frustum.view = view;
// TODO: move this inside the engine
for( size_t p = 0; p < gta->pedestrians.size(); ++p ) {
// Update all objects.
for( size_t p = 0; p < gta->pedestrians.size(); ++p) {
gta->pedestrians[p]->tick(dt);
}
for( size_t v = 0; v < gta->vehicleInstances.size(); ++v ) {
gta->vehicleInstances[v]->tick(dt);
}
gta->dynamicsWorld->stepSimulation(dt, 2, dt);
}