Lots of updates - lua, narrator, logic, models

This commit is contained in:
2025-09-19 04:35:20 +03:00
parent 4249a0238b
commit 62e14cf075
19 changed files with 924 additions and 157 deletions

View File

@@ -17,7 +17,7 @@
#include "TerrainModule.h"
#define TERRAIN_SIZE 129
#define TERRAIN_WORLD_SIZE 4000.0f
#define TERRAIN_WORLD_SIZE 1000.0f
#define ENDLESS_TERRAIN_FILE_PREFIX Ogre::String("EndlessWorldTerrain")
#define ENDLESS_TERRAIN_FILE_SUFFIX Ogre::String("dat")
@@ -82,10 +82,11 @@ struct HeightData {
world_y + (int)img.getHeight() * BRUSH_SIZE / 2;
Ogre::ColourValue color, colorb1, colorb2;
// float d;
int map_img_x = world_img_x / (BRUSH_SIZE);
int map_img_y = world_img_y / (BRUSH_SIZE);
int brush_img_x = world_img_x % BRUSH_SIZE;
int brush_img_y = world_img_y % BRUSH_SIZE;
int div = 1;
int map_img_x = world_img_x / (BRUSH_SIZE) / div;
int map_img_y = world_img_y / (BRUSH_SIZE) / div;
int brush_img_x = (world_img_x / div) % BRUSH_SIZE;
int brush_img_y = (world_img_y / div) % BRUSH_SIZE;
if (world_img_x < 0 ||
world_img_x >= img.getWidth() * BRUSH_SIZE ||
world_img_y < 0 ||
@@ -316,6 +317,11 @@ public:
what->attachObject(ent);
what->setOrientation(item.rotation);
what->setPosition(item.position);
ECS::get<EngineData>()
.mWorld->addRigidBody(
0, ent,
Ogre::Bullet::CT_TRIMESH,
nullptr, 2, 0x7fffffff);
}
} else {
output.push_back(collider_queue.front());
@@ -367,6 +373,8 @@ struct TerrainPrivate {
TerrainModule::TerrainModule(flecs::world &ecs)
{
struct CanSetPlayerPosition {};
ecs.component<CanSetPlayerPosition>().add(flecs::Singleton);
ecs.component<Terrain>().add(flecs::Singleton);
ecs.component<TerrainPrivate>().add(flecs::Singleton);
ecs.set<TerrainPrivate>({ nullptr, {} });
@@ -528,8 +536,8 @@ TerrainModule::TerrainModule(flecs::world &ecs)
0);
item.position.y = height;
placement.altar_items.push_back(item);
for (i = -64000; i < 64000; i += 1000)
for (j = -64000; j < 64000; j += 1000) {
for (i = -64000; i < 64000; i += 2000)
for (j = -64000; j < 64000; j += 2000) {
if (i == 0 && j == 0)
continue;
Ogre::Vector3 position(i, 0, j);
@@ -566,6 +574,7 @@ TerrainModule::TerrainModule(flecs::world &ecs)
#endif
if (height > -9.0f)
continue;
#ifdef VDEBUG
std::cout << "worldSize: "
<< worldSize - 1
<< std::endl;
@@ -573,6 +582,7 @@ TerrainModule::TerrainModule(flecs::world &ecs)
<< " " << j << " "
<< height
<< std::endl;
#endif
item.entity = "altar.glb";
item.rotation =
Ogre::Quaternion(0, 0,
@@ -582,6 +592,7 @@ TerrainModule::TerrainModule(flecs::world &ecs)
placement.altar_items.push_back(
item);
}
#ifdef VDEBUG
for (i = 0; i < placement.altar_items.size();
i++) {
std::cout << "placement: " << i << " "
@@ -589,20 +600,38 @@ TerrainModule::TerrainModule(flecs::world &ecs)
.position
<< std::endl;
}
flecs::entity player = ECS::player;
CharacterLocation &loc =
player.get_mut<CharacterLocation>();
height = get_height(terrain.mTerrainGroup,
loc.position);
loc.position.y = height + 0.0f;
player.get<CharacterBase>()
.mBodyNode->setPosition(loc.position);
player.get<CharacterBase>()
.mBodyNode->setOrientation(
Ogre::Quaternion());
player.modified<CharacterLocation>();
#endif
ECS::get().add<CanSetPlayerPosition>();
}
});
ecs.system<const Terrain>("SetPlayerPosition")
.kind(flecs::OnUpdate)
.with<CanSetPlayerPosition>()
.each([this](const Terrain &terrain) {
flecs::entity player = ECS::player;
if (!player.is_valid())
return;
if (!player.has<CharacterLocation>())
return;
if (!player.has<CharacterBase>())
return;
if (!player.has<Player>())
return;
CharacterLocation &loc =
player.get_mut<CharacterLocation>();
const CharacterBase &ch = player.get<CharacterBase>();
if (!ch.mBodyNode) {
std::cout << "no player yet";
return;
}
float height =
get_height(terrain.mTerrainGroup, loc.position);
loc.position.y = height + 0.0f;
ch.mBodyNode->setPosition(loc.position);
ch.mBodyNode->setOrientation(Ogre::Quaternion());
player.modified<CharacterLocation>();
ECS::get().remove<CanSetPlayerPosition>();
});
}
float TerrainModule::get_height(Ogre::TerrainGroup *group,
const Ogre::Vector3 &position)