mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 11:22:45 +01:00
refactored Instances into createInstance, added create-instance
This commit is contained in:
parent
691928aec1
commit
6445bc50e9
@ -28,21 +28,6 @@ bool GTAEngine::load()
|
|||||||
|
|
||||||
gameData.load();
|
gameData.load();
|
||||||
|
|
||||||
// Loade all of the IDEs.
|
|
||||||
for(std::map<std::string, std::string>::iterator it = gameData.ideLocations.begin();
|
|
||||||
it != gameData.ideLocations.end();
|
|
||||||
++it) {
|
|
||||||
defineItems(it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the .zon IPLs since we want to have the zones loaded
|
|
||||||
for(std::map<std::string, std::string>::iterator it = gameData.iplLocations.begin();
|
|
||||||
it != gameData.iplLocations.end();
|
|
||||||
++it) {
|
|
||||||
loadZone(it->second);
|
|
||||||
placeItems(it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,37 +125,9 @@ bool GTAEngine::placeItems(const std::string& name)
|
|||||||
// Find the object.
|
// Find the object.
|
||||||
for( size_t i = 0; i < ipll.m_instances.size(); ++i) {
|
for( size_t i = 0; i < ipll.m_instances.size(); ++i) {
|
||||||
LoaderIPLInstance& inst = ipll.m_instances[i];
|
LoaderIPLInstance& inst = ipll.m_instances[i];
|
||||||
auto oi = objectTypes.find(inst.id);
|
glm::quat rot(-inst.rotW, inst.rotX, inst.rotY, inst.rotZ);
|
||||||
if( oi != objectTypes.end()) {
|
rot = glm::normalize(rot);
|
||||||
// Make sure the DFF and TXD are loaded
|
if(! createInstance(inst.id, glm::vec3(inst.posX, inst.posY, inst.posZ), rot)) {
|
||||||
if(! oi->second->modelName.empty()) {
|
|
||||||
gameData.loadDFF(oi->second->modelName + ".dff");
|
|
||||||
}
|
|
||||||
if(! oi->second->textureName.empty()) {
|
|
||||||
gameData.loadTXD(oi->second->textureName + ".txd");
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::quat instanceRot(-inst.rotW, inst.rotX, inst.rotY, inst.rotZ);
|
|
||||||
instanceRot = glm::normalize(instanceRot);
|
|
||||||
|
|
||||||
objectInstances.push_back(std::shared_ptr<GTAInstance>(new GTAInstance(
|
|
||||||
this,
|
|
||||||
glm::vec3(inst.posX, inst.posY, inst.posZ),
|
|
||||||
instanceRot,
|
|
||||||
gameData.models[inst.model],
|
|
||||||
glm::vec3(inst.scaleX, inst.scaleY, inst.scaleZ),
|
|
||||||
inst, oi->second, nullptr
|
|
||||||
)));
|
|
||||||
|
|
||||||
if( !oi->second->modelName.empty() ) {
|
|
||||||
modelInstances.insert({
|
|
||||||
oi->second->modelName,
|
|
||||||
objectInstances.back()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cerr << "No object for instance " << inst.id << " (" << path << ")" << std::endl;
|
std::cerr << "No object for instance " << inst.id << " (" << path << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,6 +173,42 @@ bool GTAEngine::loadZone(const std::string& path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GTAInstance *GTAEngine::createInstance(const uint16_t id, const glm::vec3& pos, const glm::quat& rot)
|
||||||
|
{
|
||||||
|
auto oi = objectTypes.find(id);
|
||||||
|
if( oi != objectTypes.end()) {
|
||||||
|
// Make sure the DFF and TXD are loaded
|
||||||
|
if(! oi->second->modelName.empty()) {
|
||||||
|
gameData.loadDFF(oi->second->modelName + ".dff");
|
||||||
|
}
|
||||||
|
if(! oi->second->textureName.empty()) {
|
||||||
|
gameData.loadTXD(oi->second->textureName + ".txd");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto instance = std::shared_ptr<GTAInstance>(new GTAInstance(
|
||||||
|
this,
|
||||||
|
pos,
|
||||||
|
rot,
|
||||||
|
gameData.models[oi->second->modelName],
|
||||||
|
glm::vec3(1.f, 1.f, 1.f),
|
||||||
|
oi->second, nullptr
|
||||||
|
));
|
||||||
|
|
||||||
|
objectInstances.push_back(instance);
|
||||||
|
|
||||||
|
if( !oi->second->modelName.empty() ) {
|
||||||
|
modelInstances.insert({
|
||||||
|
oi->second->modelName,
|
||||||
|
objectInstances.back()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
GTAVehicle *GTAEngine::createVehicle(const uint16_t id, const glm::vec3& pos, const glm::quat& rot)
|
GTAVehicle *GTAEngine::createVehicle(const uint16_t id, const glm::vec3& pos, const glm::quat& rot)
|
||||||
{
|
{
|
||||||
auto vti = vehicleTypes.find(id);
|
auto vti = vehicleTypes.find(id);
|
||||||
|
@ -7,11 +7,10 @@ GTAInstance::GTAInstance(
|
|||||||
const glm::quat& rot,
|
const glm::quat& rot,
|
||||||
Model* model,
|
Model* model,
|
||||||
const glm::vec3& scale,
|
const glm::vec3& scale,
|
||||||
LoaderIPLInstance inst,
|
|
||||||
std::shared_ptr<LoaderIDE::OBJS_t> obj,
|
std::shared_ptr<LoaderIDE::OBJS_t> obj,
|
||||||
std::shared_ptr<GTAInstance> lod
|
std::shared_ptr<GTAInstance> lod
|
||||||
)
|
)
|
||||||
: GTAObject(engine, pos, rot, model), scale(scale), instance(inst), object(obj), LODinstance(lod)
|
: GTAObject(engine, pos, rot, model), scale(scale), object(obj), LODinstance(lod)
|
||||||
{
|
{
|
||||||
btRigidBody* body = nullptr;
|
btRigidBody* body = nullptr;
|
||||||
auto phyit = engine->gameData.collisions.find(obj->modelName);
|
auto phyit = engine->gameData.collisions.find(obj->modelName);
|
||||||
@ -20,10 +19,10 @@ GTAInstance::GTAInstance(
|
|||||||
btDefaultMotionState* msta = new btDefaultMotionState;
|
btDefaultMotionState* msta = new btDefaultMotionState;
|
||||||
msta->setWorldTransform(btTransform(
|
msta->setWorldTransform(btTransform(
|
||||||
btQuaternion(
|
btQuaternion(
|
||||||
inst.rotX, inst.rotY, inst.rotZ, inst.rotW
|
rot.w, rot.x, rot.y, rot.z
|
||||||
).inverse(),
|
).inverse(),
|
||||||
btVector3(
|
btVector3(
|
||||||
inst.posX, inst.posY, inst.posZ
|
pos.x, pos.y, pos.z
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
btRigidBody::btRigidBodyConstructionInfo info(0.f, msta, cmpShape);
|
btRigidBody::btRigidBodyConstructionInfo info(0.f, msta, cmpShape);
|
||||||
@ -67,7 +66,7 @@ GTAInstance::GTAInstance(
|
|||||||
engine->dynamicsWorld->addRigidBody(body);
|
engine->dynamicsWorld->addRigidBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pathit = engine->objectNodes.find(inst.id);
|
auto pathit = engine->objectNodes.find(obj->ID);
|
||||||
if( pathit != engine->objectNodes.end() ) {
|
if( pathit != engine->objectNodes.end() ) {
|
||||||
auto& pathlist = pathit->second;
|
auto& pathlist = pathit->second;
|
||||||
for( size_t p = 0; p < pathlist.size(); ++p ) {
|
for( size_t p = 0; p < pathlist.size(); ++p ) {
|
||||||
|
@ -280,7 +280,6 @@ void GTARenderer::renderWorld()
|
|||||||
|
|
||||||
for(size_t i = 0; i < engine->objectInstances.size(); ++i) {
|
for(size_t i = 0; i < engine->objectInstances.size(); ++i) {
|
||||||
GTAInstance& inst = *engine->objectInstances[i];
|
GTAInstance& inst = *engine->objectInstances[i];
|
||||||
LoaderIPLInstance &obj = inst.instance;
|
|
||||||
|
|
||||||
if(((inst.object->flags & LoaderIDE::OBJS_t::NIGHTONLY) | (inst.object->flags & LoaderIDE::OBJS_t::DAYONLY)) != 0) {
|
if(((inst.object->flags & LoaderIDE::OBJS_t::NIGHTONLY) | (inst.object->flags & LoaderIDE::OBJS_t::DAYONLY)) != 0) {
|
||||||
//continue;
|
//continue;
|
||||||
@ -288,7 +287,7 @@ void GTARenderer::renderWorld()
|
|||||||
|
|
||||||
if(!inst.model)
|
if(!inst.model)
|
||||||
{
|
{
|
||||||
std::cout << "model " << obj.model << " not loaded (" << engine->gameData.models.size() << " models loaded)" << std::endl;
|
std::cout << "model " << inst.model << " not loaded (" << engine->gameData.models.size() << " models loaded)" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 matrixModel;
|
glm::mat4 matrixModel;
|
||||||
|
@ -83,6 +83,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool loadZone(const std::string& path);
|
bool loadZone(const std::string& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance
|
||||||
|
*/
|
||||||
|
GTAInstance *createInstance(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a vehicle
|
* Creates a vehicle
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
struct GTAInstance : public GTAObject
|
struct GTAInstance : public GTAObject
|
||||||
{
|
{
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
||||||
LoaderIPLInstance instance;
|
|
||||||
std::shared_ptr<LoaderIDE::OBJS_t> object;
|
std::shared_ptr<LoaderIDE::OBJS_t> object;
|
||||||
std::shared_ptr<GTAInstance> LODinstance;
|
std::shared_ptr<GTAInstance> LODinstance;
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ struct GTAInstance : public GTAObject
|
|||||||
const glm::quat& rot,
|
const glm::quat& rot,
|
||||||
Model* model,
|
Model* model,
|
||||||
const glm::vec3& scale,
|
const glm::vec3& scale,
|
||||||
LoaderIPLInstance inst,
|
|
||||||
std::shared_ptr<LoaderIDE::OBJS_t> obj,
|
std::shared_ptr<LoaderIDE::OBJS_t> obj,
|
||||||
std::shared_ptr<GTAInstance> lod
|
std::shared_ptr<GTAInstance> lod
|
||||||
);
|
);
|
||||||
|
@ -86,6 +86,40 @@ void command(const std::string& line)
|
|||||||
playerCharacter = gta->createPedestrian(1, plyPos);
|
playerCharacter = gta->createPedestrian(1, plyPos);
|
||||||
player = new GTAPlayerAIController(playerCharacter);
|
player = new GTAPlayerAIController(playerCharacter);
|
||||||
}
|
}
|
||||||
|
else if("list-ipl" == cmd) {
|
||||||
|
for(std::map<std::string, std::string>::iterator it = gta->gameData.iplLocations.begin();
|
||||||
|
it != gta->gameData.iplLocations.end();
|
||||||
|
++it) {
|
||||||
|
gta->logInfo(it->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if("load-ipl" == cmd) {
|
||||||
|
if(line.find(' ') != line.npos) {
|
||||||
|
std::string ipl = line.substr(line.find(' ')+1);
|
||||||
|
auto iplit = gta->gameData.iplLocations.find(ipl);
|
||||||
|
if(iplit != gta->gameData.iplLocations.end()) {
|
||||||
|
gta->logInfo("Loading: " + iplit->second);
|
||||||
|
gta->loadZone(iplit->second);
|
||||||
|
gta->placeItems(iplit->second);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gta->logInfo("Not found: " + ipl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if("create-instance" == cmd) {
|
||||||
|
if(line.find(' ') != line.npos) {
|
||||||
|
std::string ID = line.substr(line.find(' ')+1);
|
||||||
|
int intID = atoi(ID.c_str());
|
||||||
|
auto archit = gta->objectTypes.find(intID);
|
||||||
|
if(archit != gta->objectTypes.end()) {
|
||||||
|
gta->createInstance(archit->first, plyPos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gta->logInfo("Unkown Object: " + ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
gta->logInfo("Unkown command: " + cmd);
|
gta->logInfo("Unkown command: " + cmd);
|
||||||
}
|
}
|
||||||
@ -188,7 +222,7 @@ void handleCommandEvent(sf::Event &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(std::string gtapath)
|
void init(std::string gtapath, bool loadWorld)
|
||||||
{
|
{
|
||||||
// GTA GET
|
// GTA GET
|
||||||
gta = new GTAEngine(gtapath);
|
gta = new GTAEngine(gtapath);
|
||||||
@ -198,13 +232,24 @@ void init(std::string gtapath)
|
|||||||
|
|
||||||
gta->load();
|
gta->load();
|
||||||
|
|
||||||
// Test out a known IPL.
|
// Loade all of the IDEs.
|
||||||
/*gta->placeItems(gtapath + "/data/maps/industsw/industSW.ipl");
|
for(std::map<std::string, std::string>::iterator it = gta->gameData.ideLocations.begin();
|
||||||
gta->placeItems(gtapath + "/data/maps/industnw/industNW.ipl");
|
it != gta->gameData.ideLocations.end();
|
||||||
gta->placeItems(gtapath + "/data/maps/industse/industSE.ipl");
|
++it) {
|
||||||
gta->placeItems(gtapath + "/data/maps/industne/industNE.ipl");*/
|
gta->defineItems(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2);
|
if(loadWorld) {
|
||||||
|
// Load IPLs
|
||||||
|
for(std::map<std::string, std::string>::iterator it = gta->gameData.iplLocations.begin();
|
||||||
|
it != gta->gameData.iplLocations.end();
|
||||||
|
++it) {
|
||||||
|
gta->loadZone(it->second);
|
||||||
|
gta->placeItems(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);
|
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);
|
||||||
size_t k = 1;
|
size_t k = 1;
|
||||||
@ -403,9 +448,10 @@ int main(int argc, char *argv[])
|
|||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
|
bool loadWorld = false;
|
||||||
size_t w = WIDTH, h = HEIGHT;
|
size_t w = WIDTH, h = HEIGHT;
|
||||||
int c;
|
int c;
|
||||||
while( (c = getopt(argc, argv, "w:h:")) != -1) {
|
while( (c = getopt(argc, argv, "w:h:l")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'w':
|
case 'w':
|
||||||
w = atoi(optarg);
|
w = atoi(optarg);
|
||||||
@ -413,6 +459,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'h':
|
case 'h':
|
||||||
h = atoi(optarg);
|
h = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
loadWorld = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +470,7 @@ int main(int argc, char *argv[])
|
|||||||
window.create(sf::VideoMode(w, h), "GTA3 Viewer", sf::Style::Close, cs);
|
window.create(sf::VideoMode(w, h), "GTA3 Viewer", sf::Style::Close, cs);
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
init(argv[optind]);
|
init(argv[optind], loadWorld);
|
||||||
|
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user