Skip to content

Commit

Permalink
Made ambient light level a JS read/write property, namely ambientLeve…
Browse files Browse the repository at this point in the history
…l (for naming compatibility with existent ambient_level shipdata property). This is set per system.
  • Loading branch information
AnotherCommander committed Dec 4, 2014
1 parent 3a824bc commit 2962ab9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Core/Scripting/OOJSSystem.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
kSystem_allDemoShips, // demo ships, array of Ship, read-only
kSystem_allShips, // ships in system, array of Ship, read-only
kSystem_allVisualEffects, // VEs in system, array of VEs, read-only
kSystem_ambientLevel, // ambient light level, float, read/write
kSystem_breakPattern, // witchspace break pattern shown
kSystem_description, // description, string, read/write
kSystem_economy, // economy ID, integer, read/write
Expand Down Expand Up @@ -149,6 +150,7 @@
{ "allDemoShips", kSystem_allDemoShips, OOJS_PROP_READONLY_CB },
{ "allShips", kSystem_allShips, OOJS_PROP_READONLY_CB },
{ "allVisualEffects", kSystem_allVisualEffects, OOJS_PROP_READONLY_CB },
{ "ambientLevel", kSystem_ambientLevel, OOJS_PROP_READWRITE_CB },
{ "breakPattern", kSystem_breakPattern, OOJS_PROP_READWRITE_CB },
{ "description", kSystem_description, OOJS_PROP_READWRITE_CB },
{ "economy", kSystem_economy, OOJS_PROP_READWRITE_CB },
Expand Down Expand Up @@ -311,6 +313,9 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsid propID,
handled = YES;
break;

case kSystem_ambientLevel:
return JS_NewNumberValue(context, [UNIVERSE ambientLightLevel], value);

case kSystem_info:
*value = GetJSSystemInfoForSystem(context, [player currentGalaxyID], [player currentSystemID]);
return YES;
Expand Down Expand Up @@ -461,6 +466,7 @@ static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsid propID,
OOSystemID system;
NSString *stringValue = nil;
NSString *manifest = nil;
jsdouble fValue;
int32 iValue;
JSBool bValue;

Expand All @@ -471,6 +477,15 @@ static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsid propID,

switch (JSID_TO_INT(propID))
{
case kSystem_ambientLevel:
if (JS_ValueToNumber(context, *value, &fValue))
{
[UNIVERSE setAmbientLightLevel:fValue];
[UNIVERSE setLighting];
return YES;
}
break;

case kSystem_breakPattern:
if (JS_ValueToBoolean(context, *value, &bValue))
{
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Universe.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ enum
NSMutableArray *allPlanets;
NSMutableSet *allStations;

float ambientLightLevel;

NSMutableDictionary *populatorSettings;
OOTimeDelta next_repopulation;
NSString *system_repopulator;
Expand Down Expand Up @@ -373,6 +375,8 @@ enum
- (NSDictionary *) getPopulatorSettings;
- (void) setPopulatorSetting:(NSString *)key to:(NSDictionary *)setting;
- (HPVector) locationByCode:(NSString *)code withSun:(OOSunEntity *)sun andPlanet:(OOPlanetEntity *)planet;
- (void) setAmbientLightLevel:(float)newValue;
- (float) ambientLightLevel;
- (void) setLighting;
- (void) forceLightSwitch;
- (void) setMainLightPosition: (Vector) sunPos;
Expand Down
22 changes: 20 additions & 2 deletions src/Core/Universe.m
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ - (void) setUpWitchspaceBetweenSystem:(OOSystemID)s1 andSystem:(OOSystemID)s2
[self addEntity:thing];
[thing release];

ambientLightLevel = [systeminfo oo_floatForKey:@"ambient_level" defaultValue:1.0];
[self setLighting]; // also sets initial lights positions.

OOLog(kOOLogUniversePopulateWitchspace, @"Populating witchspace ...");
Expand Down Expand Up @@ -985,6 +986,9 @@ - (void) setUpSpace
{
h1 += 0.33;
}

ambientLightLevel = [systeminfo oo_floatForKey:@"ambient_level" defaultValue:1.0];

// pick a main sequence colour

dict_object=[systeminfo objectForKey:@"sun_color"];
Expand Down Expand Up @@ -1540,6 +1544,21 @@ - (HPVector) locationByCode:(NSString *)code withSun:(OOSunEntity *)sun andPlane
}


- (void) setAmbientLightLevel:(float)newValue
{
NSAssert(UNIVERSE != nil, @"Attempt to set ambient light level with a non yet existent universe.");

ambientLightLevel = OOClamp_0_max_f(newValue, 10.0f);
return;
}


- (float) ambientLightLevel
{
return ambientLightLevel;
}


- (void) setLighting
{
/*
Expand All @@ -1558,7 +1577,6 @@ where there is no sun (witch/interstellar space) this is placed at the origin

*/

NSDictionary *systeminfo = [self currentSystemData];
OOSunEntity *the_sun = [self sun];
SkyEntity *the_sky = nil;
GLfloat sun_pos[] = {0.0, 0.0, 0.0, 1.0}; // equivalent to kZeroVector - for interstellar space.
Expand Down Expand Up @@ -1601,7 +1619,7 @@ where there is no sun (witch/interstellar space) this is placed at the origin
r = r * (1.0 - SUN_AMBIENT_INFLUENCE) + sun_diffuse[0] * SUN_AMBIENT_INFLUENCE;
g = g * (1.0 - SUN_AMBIENT_INFLUENCE) + sun_diffuse[1] * SUN_AMBIENT_INFLUENCE;
b = b * (1.0 - SUN_AMBIENT_INFLUENCE) + sun_diffuse[2] * SUN_AMBIENT_INFLUENCE;
GLfloat ambient_level = [systeminfo oo_floatForKey:@"ambient_level" defaultValue:1.0];
GLfloat ambient_level = [self ambientLightLevel];
stars_ambient[0] = ambient_level * 0.0625 * (1.0 + r) * (1.0 + r);
stars_ambient[1] = ambient_level * 0.0625 * (1.0 + g) * (1.0 + g);
stars_ambient[2] = ambient_level * 0.0625 * (1.0 + b) * (1.0 + b);
Expand Down

1 comment on commit 2962ab9

@AnotherCommander
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake in commit comment: It should be planetinfo.plist, not shipdata.plist.

Please sign in to comment.