Fixes for subentity shader bindings.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1565 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
35d3a61ba2
commit
36eff7cb26
@ -528,6 +528,12 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
}
|
||||
|
||||
|
||||
- (id<OOWeakReferenceSupport>) superShaderBindingTarget
|
||||
{
|
||||
return [self parentEntity];
|
||||
}
|
||||
|
||||
|
||||
- (ShipEntity *) rootShipEntity
|
||||
{
|
||||
ShipEntity *parent = [self parentEntity];
|
||||
|
@ -33,6 +33,7 @@ MA 02110-1301, USA.
|
||||
- (void)dealloc
|
||||
{
|
||||
[drawable release];
|
||||
drawable = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
|
||||
else
|
||||
{
|
||||
ShipEntity* subent;
|
||||
quaternion_normalize(&sub_q);
|
||||
quaternion_normalize(&sub_q);
|
||||
|
||||
subent = [UNIVERSE newShipWithName:subdesc]; // retained
|
||||
if (subent == nil)
|
||||
@ -217,6 +217,7 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
|
||||
|
||||
isShip = YES;
|
||||
|
||||
// FIXME: like_ships should have been resolved before getting here. Replace with assert for no like_ship after 1.71 release. -- Ahruman 2008-04-19
|
||||
// check if this is based upon a different ship
|
||||
for (;;)
|
||||
{
|
||||
@ -600,7 +601,7 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
|
||||
{
|
||||
if (![self hasSubEntity:sub])
|
||||
{
|
||||
OOLog(@"ship.subentity.sanityCheck.failed.deatails", @"Attempt to set subentity taking damage of %@ to %@, which is not a subentity.", [self shortDescription], sub);
|
||||
OOLog(@"ship.subentity.sanityCheck.failed.details", @"Attempt to set subentity taking damage of %@ to %@, which is not a subentity.", [self shortDescription], sub);
|
||||
sub = nil;
|
||||
}
|
||||
if (![sub isShip])
|
||||
@ -2902,8 +2903,26 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
|
||||
|
||||
if (subEntities == nil) subEntities = [[NSMutableArray alloc] init];
|
||||
sub->isSubEntity = YES;
|
||||
[sub setOwner:self];
|
||||
// Order matters - need consistent state in setOwner:. -- Ahruman 2008-04-20
|
||||
[subEntities addObject:sub];
|
||||
[sub setOwner:self];
|
||||
}
|
||||
|
||||
|
||||
- (void) setOwner:(Entity *)owner
|
||||
{
|
||||
[super setOwner:owner];
|
||||
|
||||
/* Reset shader binding target so that bind-to-super works.
|
||||
This is necessary since we don't know about the owner in
|
||||
setUpShipFromDictionary:, when the mesh is initially set up.
|
||||
-- Ahruman 2008-04-19
|
||||
*/
|
||||
OODrawable *drawable_ = [self drawable];
|
||||
if (isSubEntity)
|
||||
{
|
||||
[drawable_ setBindingTarget:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -155,7 +155,7 @@ static OOMaterial *sActiveMaterial = nil;
|
||||
NSMutableDictionary *newConfig = nil;
|
||||
NSMutableDictionary *uniforms = nil;
|
||||
|
||||
if (configuration == nil) configuration = [NSDictionary dictionary];
|
||||
if (configuration == nil) configuration = [NSDictionary dictionary]; // If it's nil, lookups will always give 0/nil results regardless of defaultValue:.
|
||||
ambient = [OOColor colorWithDescription:[configuration objectForKey:@"ambient"]];
|
||||
diffuse = [OOColor colorWithDescription:[configuration objectForKey:@"diffuse"]];
|
||||
specular = [OOColor colorWithDescription:[configuration objectForKey:@"specular"]];
|
||||
@ -178,7 +178,7 @@ static OOMaterial *sActiveMaterial = nil;
|
||||
}
|
||||
|
||||
// Shininess 0 or nil/black specular colour means no specular.
|
||||
if (shininess == 0 || specular == nil || [specular isBlack])
|
||||
if (shininess == 0 || [specular isBlack])
|
||||
{
|
||||
specular = nil;
|
||||
}
|
||||
@ -257,6 +257,7 @@ static OOMaterial *sActiveMaterial = nil;
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
|
||||
+ (OOMaterial *)defaultShaderMaterialWithName:(NSString *)name
|
||||
forModelNamed:(NSString *)modelName
|
||||
configuration:(NSDictionary *)configuration
|
||||
@ -359,9 +360,8 @@ static OOMaterial *sActiveMaterial = nil;
|
||||
{
|
||||
result = [[OOSingleTextureMaterial alloc] initWithName:name configuration:configuration];
|
||||
}
|
||||
if (result == nil)
|
||||
{
|
||||
result = [[OOBasicMaterial alloc] initWithName:name];
|
||||
result = [[OOBasicMaterial alloc] initWithName:name configuration:configuration];
|
||||
}
|
||||
[result autorelease];
|
||||
}
|
||||
|
@ -111,6 +111,8 @@ typedef uint16_t OOUniformConvertOptions;
|
||||
macros:(NSDictionary *)macros
|
||||
bindingTarget:(id<OOWeakReferenceSupport>)target;
|
||||
|
||||
+ (id)placeholderMaterial;
|
||||
|
||||
- (id)initWithName:(NSString *)name
|
||||
configuration:(NSDictionary *)configuration
|
||||
macros:(NSDictionary *)macros
|
||||
|
@ -90,6 +90,23 @@ static NSString *MacrosToString(NSDictionary *macros);
|
||||
}
|
||||
|
||||
|
||||
// FIXME: should be handled at a higher level.
|
||||
+ (id)placeholderMaterial
|
||||
{
|
||||
static OOBasicMaterial *placeholderMaterial = nil;
|
||||
|
||||
if (placeholderMaterial == nil)
|
||||
{
|
||||
NSDictionary *materialDefaults = nil;
|
||||
|
||||
materialDefaults = [ResourceManager dictionaryFromFilesNamed:@"material-defaults.plist" inFolder:@"Config" andMerge:YES];
|
||||
placeholderMaterial = [[OOBasicMaterial alloc] initWithName:@"/placeholder/" configuration:[materialDefaults dictionaryForKey:@"no-textures-material"]];
|
||||
}
|
||||
|
||||
return placeholderMaterial;
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithName:(NSString *)name
|
||||
configuration:(NSDictionary *)configuration
|
||||
macros:(NSDictionary *)macros
|
||||
@ -514,12 +531,9 @@ static NSString *MacrosToString(NSDictionary *macros);
|
||||
|
||||
- (void)setBindingTarget:(id<OOWeakReferenceSupport>)target
|
||||
{
|
||||
if (target != [bindingTarget weakRefUnderlyingObject])
|
||||
{
|
||||
[[uniforms allValues] makeObjectsPerformSelector:@selector(setBindingTarget:) withObject:target];
|
||||
[bindingTarget release];
|
||||
bindingTarget = [target weakRetain];
|
||||
}
|
||||
[[uniforms allValues] makeObjectsPerformSelector:@selector(setBindingTarget:) withObject:target];
|
||||
[bindingTarget release];
|
||||
bindingTarget = [target weakRetain];
|
||||
}
|
||||
|
||||
@end
|
||||
@ -531,17 +545,8 @@ static NSString *MacrosToString(NSDictionary *macros);
|
||||
{
|
||||
id textureDef = nil;
|
||||
unsigned i = 0;
|
||||
|
||||
OOMaterial *material = nil;
|
||||
|
||||
static OOBasicMaterial *placeholderMaterial = nil;
|
||||
NSDictionary *materialDefaults = nil;
|
||||
|
||||
materialDefaults = [ResourceManager dictionaryFromFilesNamed:@"material-defaults.plist" inFolder:@"Config" andMerge:YES];
|
||||
placeholderMaterial = [[OOBasicMaterial alloc] initWithName:@"/placeholder/" configuration:[materialDefaults dictionaryForKey:@"no-textures-material"]];
|
||||
|
||||
|
||||
|
||||
// Allocate space for texture object name array
|
||||
texCount = MAX(MIN(max, [textureNames count]), 0U);
|
||||
if (texCount == 0) return;
|
||||
@ -559,14 +564,13 @@ static NSString *MacrosToString(NSDictionary *macros);
|
||||
[self setUniform:[NSString stringWithFormat:@"tex%u", i] intValue:i];
|
||||
|
||||
textureDef = [textureNames objectAtIndex:i];
|
||||
material =[[OOTexture textureWithConfiguration:textureDef] retain];
|
||||
material =[OOTexture textureWithConfiguration:textureDef];
|
||||
|
||||
if (material !=nil)
|
||||
textures[i] = [material retain];
|
||||
else{
|
||||
textures[i] = [placeholderMaterial retain];
|
||||
textures[i] = [[OOShaderMaterial placeholderMaterial] retain];
|
||||
}
|
||||
[material autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,6 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type)
|
||||
id<OOWeakReferenceSupport> superCandidate = nil;
|
||||
|
||||
if (!isBinding) return;
|
||||
if (EXPECT_NOT([value.binding.object weakRefUnderlyingObject] == [(id)target weakRefUnderlyingObject])) return;
|
||||
|
||||
// Resolve "supertarget" if applicable
|
||||
if (bindToSuper)
|
||||
@ -342,6 +341,14 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type)
|
||||
}
|
||||
}
|
||||
|
||||
/* Bad optimization - we need to be able to rebind entities when their
|
||||
owner changes.
|
||||
-- Ahruman 2008-04-19
|
||||
*/
|
||||
#if 0
|
||||
if (EXPECT_NOT([value.binding.object weakRefUnderlyingObject] == [(id)target weakRefUnderlyingObject])) return;
|
||||
#endif
|
||||
|
||||
[value.binding.object release];
|
||||
value.binding.object = [target weakRetain];
|
||||
|
||||
|
@ -34,6 +34,7 @@ MA 02110-1301, USA.
|
||||
#import "OOOpenGLExtensionManager.h"
|
||||
#import "OOGraphicsResetManager.h"
|
||||
#import "OODebugGLDrawing.h"
|
||||
#import "OOShaderMaterial.h"
|
||||
|
||||
|
||||
// If set, collision octree depth varies depending on the size of the mesh. This seems to cause collision handling glitches at present.
|
||||
@ -505,12 +506,6 @@ shaderBindingTarget:(id<OOWeakReferenceSupport>)target
|
||||
{
|
||||
OOMeshMaterialCount i;
|
||||
OOMaterial *material = nil;
|
||||
static OOBasicMaterial *placeholderMaterial = nil;
|
||||
NSDictionary *materialDefaults = nil;
|
||||
|
||||
materialDefaults = [ResourceManager dictionaryFromFilesNamed:@"material-defaults.plist" inFolder:@"Config" andMerge:YES];
|
||||
placeholderMaterial = [[OOBasicMaterial alloc] initWithName:@"/placeholder/" configuration:[materialDefaults dictionaryForKey:@"no-textures-material"]];
|
||||
|
||||
|
||||
if (materialCount != 0)
|
||||
{
|
||||
@ -524,15 +519,18 @@ shaderBindingTarget:(id<OOWeakReferenceSupport>)target
|
||||
bindingTarget:target
|
||||
forSmoothedMesh:isSmoothShaded];
|
||||
if (material!=nil)
|
||||
{
|
||||
materials[i] = [material retain];
|
||||
else{
|
||||
materials[i] = [placeholderMaterial retain];
|
||||
}
|
||||
else
|
||||
{
|
||||
materials[i] = [[OOShaderMaterial placeholderMaterial] retain];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
material = [placeholderMaterial retain];
|
||||
material = [[OOShaderMaterial placeholderMaterial] retain];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8214,9 +8214,9 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
|
||||
@"// System description grammar:\n\n"
|
||||
"digraph system_descriptions\n"
|
||||
"{\n"
|
||||
"\tgraph [charset=\"UTF-8\", label=\"System description grammar\", labelloc=t, labeljust=l rankdir=LR compound=true nodesep=0.02]\n"
|
||||
"\tedge [arrowhead=dot sametail=1]\n"
|
||||
"\tnode [shape=none height=0.2]\n\t\n"];
|
||||
"\tgraph [charset=\"UTF-8\", label=\"System description grammar\", labelloc=t, labeljust=l rankdir=LR compound=true nodesep=0.02 ranksep=1.5 concentrate=true fontname=Helvetica]\n"
|
||||
"\tedge [arrowhead=dot]\n"
|
||||
"\tnode [shape=none height=0.2 width=3 fontname=Helvetica]\n\t\n"];
|
||||
|
||||
systemDescriptions = [[self descriptions] arrayForKey:@"system_description"];
|
||||
count = [systemDescriptions count];
|
||||
|
Loading…
x
Reference in New Issue
Block a user