diff --git a/src/Core/Entities/PlanetEntity.h b/src/Core/Entities/PlanetEntity.h index 7e180d29..a36972a7 100644 --- a/src/Core/Entities/PlanetEntity.h +++ b/src/Core/Entities/PlanetEntity.h @@ -90,16 +90,16 @@ typedef struct Vector rotationAxis; } -- (id) initAsMainPlanetForSystemSeed:(Random_Seed) p_seed; -- (void) miniaturize; -- (id) initMiniatureFromPlanet:(PlanetEntity *)planet; - (id) initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(Random_Seed)p_seed; +- (void) miniaturize; - (BOOL) setUpPlanetFromTexture:(NSString *)fileName; - (int*) r_seed; - (int) planet_seed; - (BOOL) isTextured; +- (BOOL) isExplicitlyTextured; // Specified texture, not synthesized. +- (OOTexture *) texture; - (NSString *) textureFileName; - (double) polar_color_factor; diff --git a/src/Core/Entities/PlanetEntity.m b/src/Core/Entities/PlanetEntity.m index 3130d6ea..76e2c06e 100644 --- a/src/Core/Entities/PlanetEntity.m +++ b/src/Core/Entities/PlanetEntity.m @@ -81,8 +81,6 @@ static GLfloat texture_uv_array[10400 * 2]; - (id) initMiniatureFromPlanet:(PlanetEntity*) planet withAlpha:(float) alpha; -- (OOTexture *) texture; - - (void) loadTexture:(NSDictionary *)configuration; - (OOTexture *) planetTextureWithInfo:(NSDictionary *)info; - (OOTexture *) cloudTextureWithCloudColor:(OOColor *)cloudColor cloudImpress:(GLfloat)cloud_impress cloudBias:(GLfloat)cloud_bias; @@ -231,7 +229,7 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured); shuttles_on_ground = 0; last_launch_time = 0.0; shuttle_launch_interval = 3600.0; - + scanClass = CLASS_NO_DRAW; orientation.w = M_SQRT1_2; @@ -266,16 +264,6 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured); } -- (id) initAsMainPlanetForSystemSeed:(Random_Seed) p_seed -{ - // this is exclusively called to initialise the main planet - NSMutableDictionary* planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:p_seed]]; - - [planetInfo oo_setBool:equal_seeds(p_seed, [UNIVERSE systemSeed]) forKey:@"mainForLocalSystem"]; - return [self initFromDictionary:planetInfo withAtmosphere:YES andSeed:p_seed]; -} - - - (void) miniaturize { shuttles_on_ground = 0; @@ -297,90 +285,6 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured); } -- (id) initMiniatureFromPlanet:(PlanetEntity *)planet -{ - return [self initMiniatureFromPlanet:planet withAlpha:1.0f]; -} - - -- (id) initMiniatureFromPlanet:(PlanetEntity *)planet withAlpha:(float)alpha -{ - int i; - - if (planet == nil) - { - [self release]; - return nil; - } - - if (!(self = [super init])) return nil; - - _texture = [[planet texture] retain]; - _textureFileName = [[planet textureFileName] copy]; - - planet_seed = [planet planet_seed]; - shuttles_on_ground = 0; - last_launch_time = 0.0; - shuttle_launch_interval = 3600.0; - - collision_radius = [planet collisionRadius] * PLANET_MINIATURE_FACTOR; // teeny tiny - - scanClass = CLASS_NO_DRAW; - [self setStatus:STATUS_COCKPIT_DISPLAY]; - - orientation = planet->orientation; - - if ([planet planetType] == STELLAR_TYPE_ATMOSPHERE) - { - planet_type = STELLAR_TYPE_ATMOSPHERE; - rotational_velocity = 0.02; - [self setModelName:kTexturedPlanetModel]; - } - else - { - planet_type = STELLAR_TYPE_MINIATURE; - rotational_velocity = 0.04; - [self setModelName:(_texture != nil) ? kTexturedPlanetModel : kUntexturedPlanetModel]; - } - - [self rescaleTo:1.0]; - - for (i = 0; i < 3; i++) - { - amb_land[i] = [planet amb_land][i]; - amb_sea[i] = [planet amb_sea][i]; - amb_polar_land[i] = [planet amb_polar_land][i]; - amb_polar_sea[i] = [planet amb_polar_sea][i]; - } - //alpha channel - amb_land[i] = [planet amb_land][i] * alpha; - amb_sea[i] = [planet amb_sea][i] * alpha; - amb_polar_land[i] = [planet amb_polar_land][i] * alpha; - amb_polar_sea[i] = [planet amb_polar_sea][i] * alpha; - - - vertexdata = planet->vertexdata; - [self scaleVertices]; - - if (planet->atmosphere) - { - // copy clouds but make fainter if isTextureImage - atmosphere = [[PlanetEntity alloc] initMiniatureFromPlanet:planet->atmosphere withAlpha:planet->isTextureImage ? 0.6f : 1.0f]; - atmosphere->collision_radius = collision_radius + ATMOSPHERE_DEPTH * PLANET_MINIATURE_FACTOR*2.0; //not to scale: invisible otherwise - [atmosphere rescaleTo:1.0]; - [atmosphere scaleVertices]; - - atmosphere->root_planet = self; - } - - rotationAxis = kBasisYVector; - - [[OOGraphicsResetManager sharedManager] registerClient:self]; - - return self; -} - - - (id) initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(Random_Seed)p_seed; { BOOL procGen = NO; @@ -400,28 +304,37 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured); else planet_seed = p_seed.a * 7 + p_seed.c * 11 + p_seed.e * 13; // pseudo-random set-up for vertex colours - NSDictionary *textureSpec = [dict oo_textureSpecifierForKey:@"texture" defaultName:nil]; - if (textureSpec == nil && !procGen && !atmo) + OOTexture *texture = [dict oo_objectOfClass:[OOTexture class] forKey:@"_oo_textureObject"]; + if (texture != nil) { - // Moons use metal.png by default. - textureSpec = OOTextureSpecFromObject(@"metal.png", nil); + _texture = [texture retain]; + isTextureImage = [dict oo_boolForKey:@"_oo_isExplicitlyTextured"]; } - if (textureSpec != nil) + else { - [self loadTexture:textureSpec]; - } - - NSString *seedStr = [dict oo_stringForKey:@"seed"]; - if (seedStr != nil) - { - Random_Seed seed = RandomSeedFromString(seedStr); - if (!is_nil_seed(seed)) + NSDictionary *textureSpec = [dict oo_textureSpecifierForKey:@"texture" defaultName:nil]; + if (textureSpec == nil && !procGen && !atmo) { - p_seed = seed; + // Moons use metal.png by default. + textureSpec = OOTextureSpecFromObject(@"metal.png", nil); } - else + if (textureSpec != nil) { - OOLogERR(@"planet.fromDict", @"could not interpret \"%@\" as planet seed, using default.", seedStr); + [self loadTexture:textureSpec]; + } + + NSString *seedStr = [dict oo_stringForKey:@"seed"]; + if (seedStr != nil) + { + Random_Seed seed = RandomSeedFromString(seedStr); + if (!is_nil_seed(seed)) + { + p_seed = seed; + } + else + { + OOLogERR(@"planet.fromDict", @"could not interpret \"%@\" as planet seed, using default.", seedStr); + } } } @@ -1448,6 +1361,12 @@ static int baseVertexIndexForEdge(int va, int vb, BOOL textured) } +- (BOOL) isExplicitlyTextured +{ + return isTextureImage; +} + + - (OOTexture *) texture { return _texture; diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index d459fa2e..98961b39 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -2638,19 +2638,27 @@ static int scriptRandomSeed = -1; // ensure proper random function if (doppelganger == nil) return NO; #else - OOPlanetEntity* doppelganger=nil; + OOPlanetEntity* doppelganger = nil; + NSMutableDictionary *planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:target_system_seed]]; + if ([i_key isEqualToString:@"local-planet"] && [UNIVERSE sun]) { - // use a clone of the current system planet, to include temporary js retexturing! - doppelganger = [[OOPlanetEntity alloc] initMiniatureFromPlanet:[UNIVERSE planet]]; + OOPlanetEntity *mainPlanet = [UNIVERSE planet]; + OOTexture *texture = [mainPlanet texture]; + if (texture != nil) + { + [planetInfo setObject:texture forKey:@"_oo_textureObject"]; + [planetInfo oo_setBool:[mainPlanet isExplicitlyTextured] forKey:@"_oo_isExplicitlyTextured"]; + [planetInfo oo_setBool:YES forKey:@"mainForLocalSystem"]; + [planetInfo oo_setQuaternion:[mainPlanet orientation] forKey:@"orientation"]; + } } - else - { - doppelganger = [[OOPlanetEntity alloc] initAsMainPlanetForSystemSeed:target_system_seed]; - [doppelganger miniaturize]; - } - if (!doppelganger) - return NO; + + doppelganger = [[OOPlanetEntity alloc] initFromDictionary:planetInfo withAtmosphere:YES andSeed:target_system_seed]; + [doppelganger miniaturize]; + [doppelganger autorelease]; + + if (doppelganger == nil) return NO; #endif ScanVectorFromString([[i_info subarrayWithRange:NSMakeRange(1, 3)] componentsJoinedByString:@" "], &model_p0); @@ -2673,9 +2681,6 @@ static int scriptRandomSeed = -1; // ensure proper random function [doppelganger setPosition: model_p0]; [UNIVERSE addEntity:doppelganger]; -#if !NEW_PLANETS - [doppelganger autorelease]; -#endif return YES; } diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 86f206a1..7be0f72d 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -702,7 +702,11 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context); { // set the system seed for random number generation seed_for_planet_description(system_seed); - OOPlanetEntity *a_planet = [[OOPlanetEntity alloc] initAsMainPlanetForSystemSeed:[UNIVERSE systemSeed]]; + + Random_Seed systemSeed = [self systemSeed]; + NSMutableDictionary *planetDict = [NSMutableDictionary dictionaryWithDictionary:[self generateSystemData:systemSeed]]; + [planetDict oo_setBool:YES forKey:@"mainForLocalSystem"]; + OOPlanetEntity *a_planet = [[OOPlanetEntity alloc] initFromDictionary:planetDict withAtmosphere:YES andSeed:systemSeed]; double planet_radius = [a_planet radius]; double planet_zpos = (12.0 + (Ranrot() & 3) - (Ranrot() & 3) ) * planet_radius; // 9..15 pr (planet radii) ahead