Skip to content

Commit 1d3a725

Browse files
committed
use SurfaceInfo.getRenderer()
1 parent c958737 commit 1d3a725

File tree

2 files changed

+3
-92
lines changed

2 files changed

+3
-92
lines changed

src/processing/mode/android/AndroidBuild.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import processing.app.exec.ProcessResult;
3939
import processing.core.PApplet;
4040
import processing.mode.java.JavaBuild;
41+
import processing.mode.java.preproc.SurfaceInfo;
4142

4243
import java.io.*;
4344
import java.util.HashMap;
@@ -228,7 +229,7 @@ public File createProject(boolean wear) throws IOException, SketchException {
228229
// build the preproc and get to work
229230
AndroidPreprocessor preproc = new AndroidPreprocessor(sketch, getPackageName());
230231
// On Android, this init will throw a SketchException if there's a problem with size()
231-
preproc.initSketchSize(sketch.getMainProgram());
232+
SurfaceInfo info = preproc.initSketchSize(sketch.getMainProgram());
232233
preproc.initSketchSmooth(sketch.getMainProgram());
233234

234235
sketchClassName = preprocess(srcFolder, getPackageName(), preproc, false);
@@ -245,9 +246,7 @@ public File createProject(boolean wear) throws IOException, SketchException {
245246
final File resFolder = new File(tmpFolder, "res");
246247
writeRes(resFolder);
247248

248-
// TODO: it would be great if we can just get the renderer from the SurfaceInfo
249-
// object returned by initSketchSize()
250-
renderer = preproc.getRenderer(sketch.getMainProgram());
249+
renderer = info.getRenderer();
251250
writeMainClass(srcFolder, renderer);
252251

253252
final File libsFolder = mkdirs(tmpFolder, "libs");

src/processing/mode/android/AndroidPreprocessor.java

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,13 @@
2626
import java.io.PrintWriter;
2727
//import java.io.Writer;
2828
import java.util.List;
29-
import java.util.regex.MatchResult;
30-
import java.util.regex.Pattern;
31-
3229
import processing.app.*;
3330
import processing.core.PApplet;
34-
import processing.data.StringList;
3531
import processing.mode.java.preproc.PdePreprocessor;
36-
//import processing.mode.java.preproc.PreprocessorResult;
3732
import processing.mode.java.preproc.SurfaceInfo;
38-
//import antlr.RecognitionException;
39-
//import antlr.TokenStreamException;
4033

4134

4235
public class AndroidPreprocessor extends PdePreprocessor {
43-
static private final Pattern VOID_SETUP_REGEX =
44-
Pattern.compile("(?:^|\\s|;)void\\s+setup\\s*\\(", Pattern.MULTILINE);
45-
static private final Pattern CLOSING_BRACE = Pattern.compile("\\}");
46-
4736
protected Sketch sketch;
4837
protected String packageName;
4938

@@ -83,84 +72,7 @@ public SurfaceInfo initSketchSize(String code) throws SketchException {
8372
sketchRenderer = surfaceInfo.getRenderer();*/
8473
return surfaceInfo;
8574
}
86-
87-
public String getRenderer(String code) {
88-
String uncommented = scrubComments(code);
89-
MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented);
90-
String searchArea = null;
91-
if (setupMatch != null) {
92-
int start = uncommented.indexOf("{", setupMatch.end());
93-
if (start >= 0) {
94-
// Find a closing brace
95-
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
96-
if (match != null) {
97-
searchArea = uncommented.substring(start + 1, match.end() - 1);
98-
} else {
99-
return null;
100-
}
101-
}
102-
}
103-
String[] sizeContents = matchMethod("size", searchArea);
104-
String[] fullContents = matchMethod("fullScreen", searchArea);
105-
if (sizeContents != null) {
106-
StringList args = breakCommas(sizeContents[1]);
107-
return (args.size() >= 3) ? args.get(2).trim() : null;
108-
}
109-
if (fullContents != null) {
110-
StringList args = breakCommas(fullContents[1]);
111-
if (args.size() > 0) { // might have no args
112-
String args0 = args.get(0).trim();
113-
if (args.size() == 1) {
114-
// could be either fullScreen(1) or fullScreen(P2D), figure out which
115-
if (args0.equals("SPAN") || PApplet.parseInt(args0, -1) != -1) {
116-
// it's the display parameter, not the renderer
117-
} else {
118-
return args0;
119-
}
120-
} else if (args.size() == 2) {
121-
return args0;
122-
} else {
123-
return null;
124-
}
125-
}
126-
}
127-
return null;
128-
}
12975

130-
static private StringList breakCommas(String contents) {
131-
StringList outgoing = new StringList();
132-
133-
boolean insideQuote = false;
134-
// The current word being read
135-
StringBuilder current = new StringBuilder();
136-
char[] chars = contents.toCharArray();
137-
for (int i = 0; i < chars.length; i++) {
138-
char c = chars[i];
139-
if (insideQuote) {
140-
current.append(c);
141-
if (c == '\"') {
142-
insideQuote = false;
143-
}
144-
} else {
145-
if (c == ',') {
146-
if (current.length() != 0) {
147-
outgoing.append(current.toString());
148-
current.setLength(0);
149-
}
150-
} else {
151-
current.append(c);
152-
if (c == '\"') {
153-
insideQuote = true;
154-
}
155-
}
156-
}
157-
}
158-
if (current.length() != 0) {
159-
outgoing.append(current.toString());
160-
}
161-
return outgoing;
162-
}
163-
16476

16577
public String[] initSketchSmooth(String code) throws SketchException {
16678
String[] info = parseSketchSmooth(code, true);

0 commit comments

Comments
 (0)