Updates
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <Ogre.h>
|
||||
#include <OgreMeshManager.h>
|
||||
#include <pugixml.hpp>
|
||||
#include "loader.h"
|
||||
#include "Components.h"
|
||||
#include "GameData.h"
|
||||
#include "BoatModule.h"
|
||||
@@ -35,7 +38,7 @@ BoatModule::BoatModule(flecs::world &ecs)
|
||||
ECS::get<EngineData>()
|
||||
.mWorld->addRigidBody(
|
||||
0, boat.mEnt,
|
||||
Ogre::Bullet::CT_HULL,
|
||||
Ogre::Bullet::CT_TRIMESH,
|
||||
nullptr, 2, 0x7fffffff);
|
||||
} else if (type.resourceName.find(".scene") !=
|
||||
std::string::npos) {
|
||||
@@ -48,7 +51,16 @@ BoatModule::BoatModule(flecs::world &ecs)
|
||||
Ogre::SceneNode *attachment =
|
||||
eng.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode();
|
||||
attachment->loadChildren(type.resourceName);
|
||||
Ogre::DataStreamPtr scene =
|
||||
Ogre::ResourceGroupManager::getSingleton()
|
||||
.openResource(
|
||||
type.resourceName,
|
||||
Ogre::ResourceGroupManager::
|
||||
AUTODETECT_RESOURCE_GROUP_NAME);
|
||||
SceneLoader loader;
|
||||
loader.load(scene, "General", attachment,
|
||||
(int)e.raw_id());
|
||||
// attachment->loadChildren(type.resourceName);
|
||||
std::vector<Ogre::Node *> v =
|
||||
attachment->getChildren();
|
||||
int i;
|
||||
@@ -69,13 +81,15 @@ BoatModule::BoatModule(flecs::world &ecs)
|
||||
boat.mNode->_setDerivedOrientation(
|
||||
type.orientation);
|
||||
boat.mEnt = static_cast<Ogre::Entity *>(
|
||||
boat.mNode->getAttachedObject("boat"));
|
||||
boat.mNode->getAttachedObject(
|
||||
std::to_string((int)e.raw_id()) +
|
||||
"/boat"));
|
||||
BoatBody &body = e.ensure<BoatBody>();
|
||||
body.body =
|
||||
ECS::get<EngineData>()
|
||||
.mWorld->addRigidBody(
|
||||
0, boat.mEnt,
|
||||
Ogre::Bullet::CT_HULL,
|
||||
Ogre::Bullet::CT_TRIMESH,
|
||||
nullptr, 2, 0x7fffffff);
|
||||
#if 0
|
||||
boat.mEnt = eng.mScnMgr->getEntity("boat");
|
||||
@@ -84,6 +98,59 @@ BoatModule::BoatModule(flecs::world &ecs)
|
||||
BoatBody &body =
|
||||
e.ensure<BoatBody>();
|
||||
#endif
|
||||
std::vector<Ogre::Node *> slots =
|
||||
boat.mNode->getChildren();
|
||||
for (i = 0; i < slots.size(); i++) {
|
||||
Ogre::Any any =
|
||||
static_cast<Ogre::SceneNode *>(
|
||||
slots[i])
|
||||
->getUserObjectBindings()
|
||||
.getUserAny("type");
|
||||
if (!any.has_value())
|
||||
continue;
|
||||
Ogre::String obj_type =
|
||||
Ogre::any_cast<Ogre::String>(
|
||||
any);
|
||||
std::cout << "child type: " << obj_type
|
||||
<< std::endl;
|
||||
}
|
||||
if (slots.size() > 0) {
|
||||
VehicleSlots &vs =
|
||||
e.ensure<VehicleSlots>();
|
||||
for (i = 0; i < slots.size(); i++) {
|
||||
Ogre::Any any =
|
||||
static_cast<Ogre::SceneNode
|
||||
*>(
|
||||
slots[i])
|
||||
->getUserObjectBindings()
|
||||
.getUserAny(
|
||||
"type");
|
||||
if (!any.has_value())
|
||||
continue;
|
||||
Ogre::String obj_type =
|
||||
Ogre::any_cast<
|
||||
Ogre::String>(
|
||||
any);
|
||||
any = static_cast<
|
||||
Ogre::SceneNode *>(
|
||||
slots[i])
|
||||
->getUserObjectBindings()
|
||||
.getUserAny(
|
||||
"name");
|
||||
if (!any.has_value())
|
||||
continue;
|
||||
Ogre::String obj_name =
|
||||
Ogre::any_cast<
|
||||
Ogre::String>(
|
||||
any);
|
||||
vs.seats[obj_name] = {
|
||||
obj_type,
|
||||
static_cast<Ogre::SceneNode
|
||||
*>(
|
||||
slots[i])
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
e.modified<BoatBody>();
|
||||
});
|
||||
|
||||
@@ -2,5 +2,5 @@ project(gamedata)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain Overlay CONFIG)
|
||||
add_library(GameData STATIC GameData.cpp CharacterModule.cpp WaterModule.cpp SunModule.cpp TerrainModule.cpp GUIModule.cpp LuaData.cpp WorldMapModule.cpp
|
||||
BoatModule.cpp EventTriggerModule.cpp)
|
||||
target_link_libraries(GameData PUBLIC OgreMain OgreBites OgreBullet OgrePaging OgreTerrain OgreOverlay flecs::flecs_static lua)
|
||||
target_include_directories(GameData PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(GameData PUBLIC OgreMain OgreBites OgreBullet OgrePaging OgreTerrain OgreOverlay flecs::flecs_static lua sceneloader)
|
||||
target_include_directories(GameData PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
@@ -733,6 +733,33 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
<< "\n";
|
||||
});
|
||||
#endif
|
||||
ecs.system<const EngineData, const CharacterBase, CharacterSlot>(
|
||||
"UpdatePhysics2")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<CharacterDisablePhysics>()
|
||||
.each([](flecs::entity e, const EngineData &eng,
|
||||
const CharacterBase &ch, CharacterSlot &slot) {
|
||||
if (slot.parent_e.has<VehicleSlots>()) {
|
||||
const VehicleSlots &slots =
|
||||
slot.parent_e.get<VehicleSlots>();
|
||||
if (slots.seats.find(slot.slot_name) ==
|
||||
slots.seats.end())
|
||||
// invalid setting
|
||||
e.remove<CharacterSlot>();
|
||||
if (slot.activated)
|
||||
return;
|
||||
Ogre::SceneNode *slot_base =
|
||||
slots.seats.at(slot.slot_name).second;
|
||||
Ogre::Vector3 position =
|
||||
slot_base->_getDerivedPosition();
|
||||
Ogre::Quaternion orientation =
|
||||
slot_base->_getDerivedOrientation();
|
||||
ch.mBodyNode->_setDerivedPosition(position);
|
||||
ch.mBodyNode->_setDerivedOrientation(
|
||||
orientation);
|
||||
slot.activated = true;
|
||||
}
|
||||
});
|
||||
ecs.system<const EngineData, const CharacterBody>("UpdatePhysics")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<CharacterUpdatePhysicsState>()
|
||||
|
||||
@@ -11,6 +11,11 @@ struct CharacterGravity {};
|
||||
struct CharacterBuoyancy {};
|
||||
struct CharacterDisablePhysics {};
|
||||
struct CharacterUpdatePhysicsState {};
|
||||
struct CharacterSlot {
|
||||
flecs::entity parent_e;
|
||||
Ogre::String slot_name;
|
||||
bool activated;
|
||||
};
|
||||
struct CharacterBase {
|
||||
Ogre::String type;
|
||||
float mTimer;
|
||||
|
||||
@@ -76,5 +76,10 @@ struct InWater {};
|
||||
struct TerrainReady {};
|
||||
struct WaterReady {};
|
||||
struct GroundCheckReady {};
|
||||
struct VehicleSlots {
|
||||
std::unordered_map<Ogre::String,
|
||||
std::pair<Ogre::String, Ogre::SceneNode *> >
|
||||
seats;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -399,6 +399,20 @@ LuaData::LuaData()
|
||||
return 0;
|
||||
});
|
||||
lua_setglobal(L, "ecs_character_physics_control");
|
||||
lua_pushcfunction(L, [](lua_State *L) -> int {
|
||||
OgreAssert(lua_gettop(L) == 3, "Bad parameters");
|
||||
luaL_checktype(L, 1, LUA_TNUMBER); // parent
|
||||
luaL_checktype(L, 2, LUA_TNUMBER); // object
|
||||
luaL_checktype(L, 3, LUA_TSTRING); // slot
|
||||
int parent = lua_tointeger(L, 1);
|
||||
int object = lua_tointeger(L, 2);
|
||||
Ogre::String slot = lua_tostring(L, 3);
|
||||
flecs::entity parent_e = idmap.get_entity(parent);
|
||||
flecs::entity object_e = idmap.get_entity(object);
|
||||
object_e.set<CharacterSlot>({ parent_e, slot, false });
|
||||
return 0;
|
||||
});
|
||||
lua_setglobal(L, "ecs_set_slot");
|
||||
}
|
||||
|
||||
LuaData::~LuaData()
|
||||
|
||||
Reference in New Issue
Block a user