Skip to content
Browse files

Working version 1.4.2. Fixes render state bug when drawing primitive …

…after mesh:draw and adds list*Data functions for browsing data stores
  • Loading branch information...
1 parent 6094c08 commit 88127c659772706bf12bbf480c44d4dc710115d3 @TwoLivesLeft committed Jun 7, 2012
View
16 CodeaTemplate/CodeaTemplate/CodifyAppDelegate.m
@@ -1,3 +1,19 @@
+//
+// Copyright 2012 Two Lives Left Pty. Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
//
// CodifyAppDelegate.h
// ___PROJECTNAME___
View
1 CodeaTemplate/Codify/BasicRendererViewController.h
@@ -114,6 +114,7 @@
- (void) clearSupportedOrientations;
- (void) addSupportedOrientation:(NSUInteger)codeaOrientation;
+- (void) setupDataStore;
- (void) setupRenderGlobals;
- (void) setupPhysicsGlobals;
- (void) setupAccelerometerValues;
View
39 CodeaTemplate/Codify/BasicRendererViewController.mm
@@ -104,14 +104,14 @@ - (int) orientationFromUIOrientation:(UIInterfaceOrientation)uio
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
-
- if(self){
- supportedOrientations = [[NSMutableSet alloc] initWithCapacity:4];
- [self addSupportedOrientation:ORIENTATION_ANY];
- }
-
- return self;
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+
+ if(self){
+ supportedOrientations = [[NSMutableSet alloc] initWithCapacity:4];
+ [self addSupportedOrientation:ORIENTATION_ANY];
+ }
+
+ return self;
}
- (void) setup
@@ -178,6 +178,18 @@ - (void) setup
screenCapture.delegate = self;
}
+- (void) setupDataStore
+{
+ if( self.project )
+ {
+ setLocalDataPrefix(self.project.name);
+ setProjectDataPath(self.project.bundlePath);
+ setProjectInfoStore(self.project.info);
+ }
+
+ setupGlobalData();
+}
+
- (void) setupRenderGlobals
{
//Create a global touch
@@ -489,7 +501,7 @@ - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterface
#pragma mark - View preparation
- (void) prepareViewForDisplay
-{
+{
//Do some basic GL setup
[self startAnimation];
[self initialDrawSetup];
@@ -572,7 +584,7 @@ - (void)viewDidLoad
//Create keyboard input view
keyboardInputView = [[KeyboardInputView alloc] init];
- [self.view addSubview:keyboardInputView];
+ [self.view addSubview:keyboardInputView];
keyboardInputView.delegate = self;
}
@@ -932,11 +944,6 @@ - (void)initialDrawSetup
[physicsManager reset];
pc_initialize(physicsManager);
- setLocalDataPrefix(self.project.name);
- setProjectDataPath(self.project.bundlePath);
- setProjectInfoStore(self.project.info);
- setupGlobalData();
-
self.glView.retainedBacking = NO;
[self.glView setFramebuffer];
@@ -1151,7 +1158,7 @@ - (void) addSupportedOrientation:(NSUInteger)codeaOrientation
[supportedOrientations addObject:[NSNumber numberWithUnsignedInteger:UIInterfaceOrientationLandscapeRight]];
[supportedOrientations addObject:[NSNumber numberWithUnsignedInteger:UIInterfaceOrientationPortrait]];
[supportedOrientations addObject:[NSNumber numberWithUnsignedInteger:UIInterfaceOrientationPortraitUpsideDown]];
- break;
+ break;
default: //Default to landscape left and right
[supportedOrientations addObject:[NSNumber numberWithUnsignedInteger:UIInterfaceOrientationLandscapeLeft]];
View
7 CodeaTemplate/Codify/CodifyScriptExecute.m
@@ -51,8 +51,8 @@ - (id) init
*/
//Pre-load classes and sandbox lua files
- [preloadScripts addObject:SCRIPT_STRING("LuaSandbox")];
- [preloadScripts addObject:SCRIPT_STRING("Class")];
+ [preloadScripts addObject:SCRIPT_STRING("LuaSandbox")];
+ [preloadScripts addObject:SCRIPT_STRING("Class")];
//luaSandbox = [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LuaSandbox" ofType:@"lua"] usedEncoding:NULL error:NULL] retain];
//luaClasses = [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Class" ofType:@"lua"] usedEncoding:NULL error:NULL] retain];
@@ -97,6 +97,8 @@ - (BOOL) validateProject:(Project*)project
[scriptState close];
[scriptState createWithFakeLibs];
[renderController setupRenderGlobals];
+ [renderController setupPhysicsGlobals];
+ [renderController setupDataStore];
BOOL containsErrors = ![self loadAdditionalCode];
@@ -134,6 +136,7 @@ - (BOOL) runProject:(Project*)project
[scriptState create];
[renderController setupRenderGlobals];
[renderController setupPhysicsGlobals];
+ [renderController setupDataStore];
[renderController setupAccelerometerValues];
if( ![self loadAdditionalCode] )
View
6 CodeaTemplate/Codify/LuaState.m
@@ -643,11 +643,14 @@ - (void) create
LuaRegFunc(readLocalData);
LuaRegFunc(saveLocalData);
LuaRegFunc(clearLocalData);
+ LuaRegFunc(listLocalData);
LuaRegFunc(readProjectData);
LuaRegFunc(saveProjectData);
LuaRegFunc(clearProjectData);
+ LuaRegFunc(listProjectData);
LuaRegFunc(readGlobalData);
LuaRegFunc(saveGlobalData);
+ LuaRegFunc(listGlobalData);
LuaRegFunc(readProjectInfo);
LuaRegFunc(saveProjectInfo);
// LuaRegFunc(saveDocumentsImage);
@@ -798,11 +801,14 @@ - (void) createWithFakeLibs
LuaRegFunc(readLocalData);
LuaDudFunc(saveLocalData);
LuaDudFunc(clearLocalData);
+ LuaDudFunc(listLocalData);
LuaRegFunc(readProjectData);
LuaDudFunc(saveProjectData);
LuaDudFunc(clearProjectData);
+ LuaDudFunc(listProjectData);
LuaRegFunc(readGlobalData);
LuaDudFunc(saveGlobalData);
+ LuaDudFunc(listGlobalData);
LuaRegFunc(readProjectInfo);
LuaDudFunc(saveProjectInfo);
// LuaDudFunc(saveDocumentsImage);
View
3 CodeaTemplate/Codify/Persistence.h
@@ -34,13 +34,16 @@ extern "C" {
int saveLocalData(lua_State *L);
int readLocalData(lua_State *L);
int clearLocalData(lua_State *L);
+ int listLocalData(lua_State *L);
int saveProjectData(lua_State *L);
int readProjectData(lua_State *L);
int clearProjectData(lua_State *L);
+ int listProjectData(lua_State *L);
int saveGlobalData(lua_State *L);
int readGlobalData(lua_State *L);
+ int listGlobalData(lua_State *L);
int saveProjectInfo(lua_State *L);
int readProjectInfo(lua_State *L);
View
107 CodeaTemplate/Codify/Persistence.m
@@ -96,8 +96,6 @@ void removeLocalDataForPrefix(NSString* name)
[[NSUserDefaults standardUserDefaults] removeObjectForKey:prefix];
}
-
-
int clearLocalData(lua_State *L)
{
[currentLocalStore release];
@@ -108,17 +106,44 @@ int clearLocalData(lua_State *L)
int saveLocalData(lua_State *L)
{
- assert(currentPrefix != nil);
- int num = saveData(L, currentLocalStore);
- saveLocalStore();
- return num;
+ if( currentPrefix != nil )
+ {
+ int num = saveData(L, currentLocalStore);
+ saveLocalStore();
+ return num;
+ }
+
+ return 0;
}
int readLocalData(lua_State *L)
{
- assert(currentPrefix != nil);
- int num = readData(L, currentLocalStore);
- return num;
+ if( currentPrefix != nil )
+ {
+ int num = readData(L, currentLocalStore);
+ return num;
+ }
+
+ return 0;
+}
+
+int listLocalData(lua_State *L)
+{
+ if( currentPrefix != nil )
+ {
+ lua_newtable(L);
+
+ int index = 1;
+ for( NSString *key in [currentLocalStore allKeys] )
+ {
+ lua_pushstring(L, [key UTF8String]);
+ lua_rawseti(L, -2, index);
+ index++;
+ }
+ return 1;
+ }
+
+ return 0;
}
#pragma mark - Project Info
@@ -149,7 +174,7 @@ void saveProjectStore()
{
if(![currentProjectStore writeToFile:currentProjectDataPath atomically:YES])
{
- CDLog(@"Didn't write project data store for some reason");
+ DBLog(@"Didn't write project data store for some reason");
}
}
}
@@ -186,17 +211,44 @@ int clearProjectData(lua_State *L)
int saveProjectData(lua_State *L)
{
- assert(currentProjectDataPath != nil);
- int num = saveData(L, currentProjectStore);
- saveProjectStore();
- return num;
+ if(currentProjectDataPath != nil)
+ {
+ int num = saveData(L, currentProjectStore);
+ saveProjectStore();
+ return num;
+ }
+
+ return 0;
}
int readProjectData(lua_State *L)
{
- assert(currentProjectDataPath != nil);
- int num = readData(L, currentProjectStore);
- return num;
+ if(currentProjectDataPath != nil)
+ {
+ int num = readData(L, currentProjectStore);
+ return num;
+ }
+
+ return 0;
+}
+
+int listProjectData(lua_State *L)
+{
+ if( currentProjectDataPath != nil )
+ {
+ lua_newtable(L);
+
+ int index = 1;
+ for( NSString *key in [currentProjectStore allKeys] )
+ {
+ lua_pushstring(L, [key UTF8String]);
+ lua_rawseti(L, -2, index);
+ index++;
+ }
+ return 1;
+ }
+
+ return 0;
}
#pragma mark - Global Data
@@ -234,6 +286,25 @@ int readGlobalData(lua_State *L)
return num;
}
+int listGlobalData(lua_State *L)
+{
+ if( currentGlobalStore != nil )
+ {
+ lua_newtable(L);
+
+ int index = 1;
+ for( NSString *key in [currentGlobalStore allKeys] )
+ {
+ lua_pushstring(L, [key UTF8String]);
+ lua_rawseti(L, -2, index);
+ index++;
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
#pragma mark - Generic Functions
//Checks if there are any null characters before the last character in the string
//len is the size before the null terminating character ie, "abc\0" has length 3 (assuming it doesnt have an extra \0 at the end).
@@ -437,7 +508,7 @@ int readData(lua_State *L, NSDictionary* readFromDict)
UIImage *newImage = [UIImage imageWithCGImage:imageRef];
CGDataProviderRelease(provider);
CGImageRelease(imageRef);
- CGColorSpaceRelease(colorSpaceRef);
+ CGColorSpaceRelease(colorSpaceRef);
// Flip image
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:newImage];
View
14 CodeaTemplate/Codify/RenderCommands.mm
@@ -1293,6 +1293,8 @@ int rect(lua_State *L)
1, 1,
};
+ [renderAPI setBlendMode:BLEND_MODE_PREMULT];
+
//Load uniforms into shader
Shader *shader = nil;
@@ -1313,7 +1315,6 @@ int rect(lua_State *L)
[renderAPI setAttributeNamed:@"Vertex" withPointer:rectVerts size:2 andType:GL_FLOAT];
[renderAPI setAttributeNamed:@"TexCoord" withPointer:rectUV size:2 andType:GL_FLOAT];
- [renderAPI setBlendMode:BLEND_MODE_PREMULT];
if( [shader hasUniform:@"Size"] )
glUniform2f([shader uniformLocation:@"Size"], w, h);
@@ -1393,6 +1394,8 @@ int ellipse(struct lua_State *L)
x+w, y+h,
};
+ [renderAPI setBlendMode:BLEND_MODE_PREMULT];
+
//Load uniforms into shader
Shader *shader = nil;
if( [renderAPI useStroke] )
@@ -1406,7 +1409,6 @@ int ellipse(struct lua_State *L)
[renderAPI setAttributeNamed:@"Vertex" withPointer:ellipseVerts size:2 andType:GL_FLOAT];
[renderAPI setAttributeNamed:@"TexCoord" withPointer:ellipseUV size:2 andType:GL_FLOAT];
- [renderAPI setBlendMode:BLEND_MODE_PREMULT];
glUniform2f([shader uniformLocation:@"Radius"], w, h);
@@ -1479,11 +1481,12 @@ int point(lua_State *L)
};
//Load uniforms into shader
+ [renderAPI setBlendMode:BLEND_MODE_PREMULT];
+
Shader *shader = [renderAPI useShader:@"CircleNoStroke"];
[renderAPI setAttributeNamed:@"Vertex" withPointer:ellipseVerts size:2 andType:GL_FLOAT];
[renderAPI setAttributeNamed:@"TexCoord" withPointer:ellipseUV size:2 andType:GL_FLOAT];
- [renderAPI setBlendMode:BLEND_MODE_PREMULT];
glUniform2f([shader uniformLocation:@"Radius"], w, h);
@@ -1544,6 +1547,8 @@ int line(lua_State *L)
x2, y2
};
+ [renderAPI setBlendMode:BLEND_MODE_PREMULT];
+
[renderAPI useShader:@"SimpleLine"];
[renderAPI setAttributeNamed:@"Vertex" withPointer:linePoints size:2 andType:GL_FLOAT];
@@ -1597,10 +1602,11 @@ int line(lua_State *L)
1, 1,
};
+ [renderAPI setBlendMode:BLEND_MODE_PREMULT];
+
Shader* shader = [renderAPI useShader:@"Line"];
[renderAPI setAttributeNamed:@"Vertex" withPointer:linePoints size:2 andType:GL_FLOAT];
[renderAPI setAttributeNamed:@"TexCoord" withPointer:lineUV size:2 andType:GL_FLOAT];
- [renderAPI setBlendMode:BLEND_MODE_PREMULT];
glUniform2f([shader uniformLocation:@"Size"],len,strokeWidth);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

0 comments on commit 88127c6

Please sign in to comment.
Something went wrong with that request. Please try again.