Example #1
0
Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const SystemPath &path, Space* oldSpace)
	: m_starSystemCache(oldSpace ? oldSpace->m_starSystemCache : galaxy->NewStarSystemSlaveCache())
	, m_game(game)
	, m_frameIndexValid(false)
	, m_bodyIndexValid(false)
	, m_sbodyIndexValid(false)
	, m_bodyNearFinder(this)
#ifndef NDEBUG
	, m_processingFinalizationQueue(false)
#endif
{
	m_starSystem = galaxy->GetStarSystem(path);

	Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED };
	Random rand(_init, 5);
	m_background.reset(new Background::Container(Pi::renderer, rand));

	CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath());

	// XXX set radius in constructor
	m_rootFrame.reset(new Frame(0, Lang::SYSTEM));
	m_rootFrame->SetRadius(FLT_MAX);

	GenBody(m_game->GetTime(), m_starSystem->GetRootBody().Get(), m_rootFrame.get());
	m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep());

	GenSectorCache(galaxy, &path);

	//DebugDumpFrames();
}
Example #2
0
void Space::GenBody(SystemBody *sbody, Frame *f)
{
    Body *b = 0;

    if (sbody->type != SystemBody::TYPE_GRAVPOINT) {
        if (sbody->GetSuperType() == SystemBody::SUPERTYPE_STAR) {
            Star *star = new Star(sbody);
            b = star;
        } else if ((sbody->type == SystemBody::TYPE_STARPORT_ORBITAL) ||
                   (sbody->type == SystemBody::TYPE_STARPORT_SURFACE)) {
            SpaceStation *ss = new SpaceStation(sbody);
            b = ss;
        } else {
            Planet *planet = new Planet(sbody);
            b = planet;
        }
        b->SetLabel(sbody->name.c_str());
        b->SetPosition(vector3d(0,0,0));
        AddBody(b);
    }
    f = MakeFrameFor(sbody, b, f);

    for (std::vector<SystemBody*>::iterator i = sbody->children.begin(); i != sbody->children.end(); ++i) {
        GenBody(*i, f);
    }
}
Example #3
0
Space::Space(Game *game, const SystemPath &path)
	: m_game(game)
	, m_frameIndexValid(false)
	, m_bodyIndexValid(false)
	, m_sbodyIndexValid(false)
	, m_background(Pi::renderer)
	, m_bodyNearFinder(this)
#ifndef NDEBUG
	, m_processingFinalizationQueue(false)
#endif
{
	m_starSystem = StarSystem::GetCached(path);
	m_background.Refresh(m_starSystem->GetSeed());

	CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath());

	// XXX set radius in constructor
	m_rootFrame.Reset(new Frame(0, Lang::SYSTEM));
	m_rootFrame->SetRadius(FLT_MAX);

	GenBody(m_starSystem->rootBody.Get(), m_rootFrame.Get());
	m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep());

	//DebugDumpFrames();
}
Example #4
0
Space::Space(Game *game, const SystemPath &path) : m_game(game), m_frameIndexValid(false), m_bodyIndexValid(false), m_sbodyIndexValid(false)
{
	m_starSystem = StarSystem::GetCached(path);
	m_background.Refresh(m_starSystem->m_seed);

	// XXX set radius in constructor
	m_rootFrame.Reset(new Frame(0, Lang::SYSTEM));
	m_rootFrame->SetRadius(FLT_MAX);

	GenBody(m_starSystem->rootBody, m_rootFrame.Get());
	m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep());
}
Example #5
0
void Space::GenBody(double time, SystemBody* sbody, Frame* f)
{
	Entity e = m_entities->create();

	if (sbody->GetType() != SystemBody::TYPE_GRAVPOINT) {
		if (sbody->GetSuperType() == SystemBody::SUPERTYPE_STAR) {
			CreateStar(e, sbody);
		} else if ((sbody->GetType() == SystemBody::TYPE_STARPORT_ORBITAL) ||
		           (sbody->GetType() == SystemBody::TYPE_STARPORT_SURFACE)) {
			//SpaceStation *ss = new SpaceStation(sbody);
			//b = ss;
			return;
		} else {
			CreatePlanet(e, sbody);
		}
		e.assign<NameComponent>(sbody->GetName());
		e.assign<PosOrientComponent>(vector3d(0.0), matrix3x3d(1.0));
	}
	f = MakeFrameFor(time, sbody, e, f);

	for (SystemBody* child : sbody->GetChildren())
		GenBody(time, child, f);
}
Example #6
0
Space::Space(Game *game, const SystemPath &path)
	: m_game(game)
	, m_frameIndexValid(false)
	, m_bodyIndexValid(false)
	, m_sbodyIndexValid(false)
	, m_bodyNearFinder(this)
#ifndef NDEBUG
	, m_processingFinalizationQueue(false)
#endif
{
	m_starSystem = StarSystemCache::GetCached(path);

	// XXX set radius in constructor
	m_rootFrame.reset(new Frame(0, Lang::SYSTEM));
	m_rootFrame->SetRadius(FLT_MAX);

	GenBody(m_game->GetTime(), m_starSystem->m_rootBody.Get(), m_rootFrame.get());
	m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep());

	GenSectorCache(&path);

	//DebugDumpFrames();
}
Example #7
0
void Space::CreateTestScene(Entity player, double time)
{
	auto renderer = p3::game->GetRenderer();
	m_renderer = renderer;

	StarSystemCache::ShrinkCache(SystemPath(), true);
	Sector::cache.ClearCache();
	SystemPath path(10,0,0,0);
	m_starSystem = StarSystemCache::GetCached(path);

	GenBody(time, m_starSystem->m_rootBody.Get(), m_rootFrame.get());
	m_rootFrame->UpdateOrbitRails(time, 1.0);

	//init "player"
	{
		auto model = p3::game->GetModelCache()->FindModel("kanara");
		SDL_assert(model);
		player.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		player.assign<PosOrientComponent>(vector3d(0,0,1e6), matrix3x3d(1.0));
		player.assign<MassComponent>(10.0);
		player.assign<DynamicsComponent>();
		player.assign<ThrusterComponent>();
		player.assign<WeaponComponent>();
		player.assign<PlayerInputComponent>();
		player.assign<CollisionMeshComponent>(player, model->GetCollisionMesh());
		player.assign<FrameComponent>(GetRootFrame());
		//player.assign<ColorComponent>(Color(0,255,255,255));
		player.assign<ShipAIComponent>();
		player.assign<NameComponent>("Player");

		GetRootFrame()->GetCollisionSpace()->AddGeom(player.component<CollisionMeshComponent>()->geom.get());
	}

	//init "AI"
	{
		auto model = p3::game->GetModelCache()->FindModel("natrix");
		SDL_assert(model);
		Entity ship = m_entities->create();
		ship.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		ship.assign<PosOrientComponent>(vector3d(0,0,1e6 - 200), matrix3x3d(1.0));
		ship.assign<MassComponent>(10.0);
		ship.assign<DynamicsComponent>();
		ship.assign<ThrusterComponent>();
		ship.assign<WeaponComponent>();
		ship.assign<CollisionMeshComponent>(ship, model->GetCollisionMesh());
		ship.assign<FrameComponent>(GetRootFrame());
		ship.assign<ColorComponent>(Color(255,0,0,255));
		ship.assign<ShipAIComponent>();
		ship.assign<NameComponent>("Drone");
		ship.assign<AICommandComponent>(); //kamikaze
		auto aicmd = ship.component<AICommandComponent>();
		aicmd->SetKamikaze(player);

		GetRootFrame()->GetCollisionSpace()->AddGeom(ship.component<CollisionMeshComponent>()->geom.get());
	}

	//some scenery
	//Entity obstacle = m_entities->create();
	if (0)
	{
		Entity obstacle = m_entities->create();
		auto model = p3::game->GetModelCache()->FindModel("kbuilding02");
		obstacle.assign<PosOrientComponent>(vector3d(0, 0, -200), matrix3x3d(1.0));
		obstacle.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		obstacle.assign<MassComponent>(100.0);
		obstacle.assign<DynamicsComponent>();
		obstacle.assign<CollisionMeshComponent>(obstacle, model->GetCollisionMesh());
		obstacle.assign<FrameComponent>(GetRootFrame());

		GetRootFrame()->GetCollisionSpace()->AddGeom(obstacle.component<CollisionMeshComponent>()->geom.get());

		Entity hangAroundMember = m_entities->create();
		hangAroundMember.assign<PosOrientComponent>(vector3d(0.0), matrix3x3d(1.0));
		hangAroundMember.assign<AttachToEntityComponent>(obstacle, vector3d(0, 50, 0));
		hangAroundMember.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		hangAroundMember.assign<FrameComponent>(GetRootFrame());
	}

	//init camera
	//left camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.f, 0.f, 0.5f, 1.f);
		camc->camera->clearColor = Color(0, 40, 0, 0);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 50, 100), matrix3x3d(1.0));
		camera.assign<CameraLookAtComponent>(player);
		camera.assign<FrameComponent>(GetRootFrame());
		//camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 50));
	}

	//right top camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.5f, 0.5f, 0.5f, 0.5f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(100, -10, -10), matrix3x3d(1.0));
		//camera.assign<CameraLookAtComponent>(obstacle);
		camera.assign<FrameComponent>(GetRootFrame());
	}
	//right bottom camera
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		//camc->camera->clearColor = Color(10, 10, 10, 0);
		camc->camera->viewport = vector4f(0.0f, 0.f, 1.0f, 1.0f);
		//camc->camera->viewport = vector4f(0.5f, 0.f, 0.5f, 1.0f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 0, 0), matrix3x3d(1.0));
		camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 10));
		camera.assign<FrameComponent>(GetRootFrame());
	}
}