1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
|
/*
* Copyright (C) 2009 The Android Open Source Project
*
* 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.
*/
#include "rsContext.h"
#include "rsScriptC.h"
#include "rsMatrix.h"
#include "rsNoise.h"
#include "acc/acc.h"
#include "utils/Timers.h"
#define GL_GLEXT_PROTOTYPES
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <time.h>
using namespace android;
using namespace android::renderscript;
#define GET_TLS() Context::ScriptTLSStruct * tls = \
(Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
Context * rsc = tls->mContext; \
ScriptC * sc = (ScriptC *) tls->mScript
typedef struct {
float x;
float y;
float z;
} vec3_t;
typedef struct {
float x;
float y;
float z;
float w;
} vec4_t;
typedef struct {
float x;
float y;
} vec2_t;
//////////////////////////////////////////////////////////////////////////////
// IO routines
//////////////////////////////////////////////////////////////////////////////
static float SC_loadF(uint32_t bank, uint32_t offset)
{
GET_TLS();
const void *vp = sc->mSlots[bank]->getPtr();
const float *f = static_cast<const float *>(vp);
//LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
return f[offset];
}
static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
{
GET_TLS();
const void *vp = sc->mSlots[bank]->getPtr();
const int32_t *i = static_cast<const int32_t *>(vp);
//LOGE("loadI32 %i %i = %i", bank, offset, t);
return i[offset];
}
static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
float *f = static_cast<float *>(vp);
return f + offset;
}
static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
int32_t *i = static_cast<int32_t *>(vp);
return i + offset;
}
static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
{
SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
void *vp = tm->mVertexBuffers[idx]->getPtr();;
return static_cast<float *>(vp);
}
static void SC_updateSimpleMesh(RsSimpleMesh mesh)
{
SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
sm->uploadAll();
}
static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
{
GET_TLS();
const void *vp = sc->mSlots[bank]->getPtr();
const uint32_t *i = static_cast<const uint32_t *>(vp);
return i[offset];
}
static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
{
GET_TLS();
const void *vp = sc->mSlots[bank]->getPtr();
const float *f = static_cast<const float *>(vp);
memcpy(v, &f[offset], sizeof(rsc_Vector4));
}
static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
{
GET_TLS();
const void *vp = sc->mSlots[bank]->getPtr();
const float *f = static_cast<const float *>(vp);
memcpy(m, &f[offset], sizeof(rsc_Matrix));
}
static void SC_storeF(uint32_t bank, uint32_t offset, float v)
{
//LOGE("storeF %i %i %f", bank, offset, v);
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
float *f = static_cast<float *>(vp);
f[offset] = v;
}
static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
int32_t *f = static_cast<int32_t *>(vp);
static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
}
static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
uint32_t *f = static_cast<uint32_t *>(vp);
static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
}
static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
float *f = static_cast<float *>(vp);
memcpy(&f[offset], v, sizeof(rsc_Vector4));
}
static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
{
GET_TLS();
void *vp = sc->mSlots[bank]->getPtr();
float *f = static_cast<float *>(vp);
memcpy(&f[offset], m, sizeof(rsc_Matrix));
}
//////////////////////////////////////////////////////////////////////////////
// Vec3 routines
//////////////////////////////////////////////////////////////////////////////
static void SC_vec3Norm(vec3_t *v)
{
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
len = 1 / len;
v->x *= len;
v->y *= len;
v->z *= len;
}
static float SC_vec3Length(const vec3_t *v)
{
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
}
static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
{
dest->x = lhs->x + rhs->x;
dest->y = lhs->y + rhs->y;
dest->z = lhs->z + rhs->z;
}
static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
{
dest->x = lhs->x - rhs->x;
dest->y = lhs->y - rhs->y;
dest->z = lhs->z - rhs->z;
}
static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
{
float x = lhs->y * rhs->z - lhs->z * rhs->y;
float y = lhs->z * rhs->x - lhs->x * rhs->z;
float z = lhs->x * rhs->y - lhs->y * rhs->x;
dest->x = x;
dest->y = y;
dest->z = z;
}
static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
{
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
}
static void SC_vec3Scale(vec3_t *lhs, float scale)
{
lhs->x *= scale;
lhs->y *= scale;
lhs->z *= scale;
}
//////////////////////////////////////////////////////////////////////////////
// Vec4 routines
//////////////////////////////////////////////////////////////////////////////
static void SC_vec4Norm(vec4_t *v)
{
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
len = 1 / len;
v->x *= len;
v->y *= len;
v->z *= len;
v->w *= len;
}
static float SC_vec4Length(const vec4_t *v)
{
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
}
static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
{
dest->x = lhs->x + rhs->x;
dest->y = lhs->y + rhs->y;
dest->z = lhs->z + rhs->z;
dest->w = lhs->w + rhs->w;
}
static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
{
dest->x = lhs->x - rhs->x;
dest->y = lhs->y - rhs->y;
dest->z = lhs->z - rhs->z;
dest->w = lhs->w - rhs->w;
}
static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
{
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
}
static void SC_vec4Scale(vec4_t *lhs, float scale)
{
lhs->x *= scale;
lhs->y *= scale;
lhs->z *= scale;
lhs->w *= scale;
}
//////////////////////////////////////////////////////////////////////////////
// Math routines
//////////////////////////////////////////////////////////////////////////////
#define PI 3.1415926f
#define DEG_TO_RAD PI / 180.0f
#define RAD_TO_DEG 180.0f / PI
static float SC_sinf_fast(float x)
{
const float A = 1.0f / (2.0f * M_PI);
const float B = -16.0f;
const float C = 8.0f;
// scale angle for easy argument reduction
x *= A;
if (fabsf(x) >= 0.5f) {
// argument reduction
x = x - ceilf(x + 0.5f) + 1.0f;
}
const float y = B * x * fabsf(x) + C * x;
return 0.2215f * (y * fabsf(y) - y) + y;
}
static float SC_cosf_fast(float x)
{
x += float(M_PI / 2);
const float A = 1.0f / (2.0f * M_PI);
const float B = -16.0f;
const float C = 8.0f;
// scale angle for easy argument reduction
x *= A;
if (fabsf(x) >= 0.5f) {
// argument reduction
x = x - ceilf(x + 0.5f) + 1.0f;
}
const float y = B * x * fabsf(x) + C * x;
return 0.2215f * (y * fabsf(y) - y) + y;
}
static float SC_randf(float max)
{
float r = (float)rand();
return r / RAND_MAX * max;
}
static float SC_randf2(float min, float max)
{
float r = (float)rand();
return r / RAND_MAX * (max - min) + min;
}
static int SC_sign(int value)
{
return (value > 0) - (value < 0);
}
static float SC_signf(float value)
{
return (value > 0) - (value < 0);
}
static float SC_clampf(float amount, float low, float high)
{
return amount < low ? low : (amount > high ? high : amount);
}
static int SC_clamp(int amount, int low, int high)
{
return amount < low ? low : (amount > high ? high : amount);
}
static float SC_maxf(float a, float b)
{
return a > b ? a : b;
}
static float SC_minf(float a, float b)
{
return a < b ? a : b;
}
static float SC_sqrf(float v)
{
return v * v;
}
static int SC_sqr(int v)
{
return v * v;
}
static float SC_fracf(float v)
{
return v - floorf(v);
}
static float SC_roundf(float v)
{
return floorf(v + 0.4999999999);
}
static float SC_distf2(float x1, float y1, float x2, float y2)
{
float x = x2 - x1;
float y = y2 - y1;
return sqrtf(x * x + y * y);
}
static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
{
float x = x2 - x1;
float y = y2 - y1;
float z = z2 - z1;
return sqrtf(x * x + y * y + z * z);
}
static float SC_magf2(float a, float b)
{
return sqrtf(a * a + b * b);
}
static float SC_magf3(float a, float b, float c)
{
return sqrtf(a * a + b * b + c * c);
}
static float SC_radf(float degrees)
{
return degrees * DEG_TO_RAD;
}
static float SC_degf(float radians)
{
return radians * RAD_TO_DEG;
}
static float SC_lerpf(float start, float stop, float amount)
{
return start + (stop - start) * amount;
}
static float SC_normf(float start, float stop, float value)
{
return (value - start) / (stop - start);
}
static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
{
return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
}
//////////////////////////////////////////////////////////////////////////////
// Time routines
//////////////////////////////////////////////////////////////////////////////
static int32_t SC_second()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_sec;
}
static int32_t SC_minute()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_min;
}
static int32_t SC_hour()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_hour;
}
static int32_t SC_day()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_mday;
}
static int32_t SC_month()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_mon;
}
static int32_t SC_year()
{
GET_TLS();
time_t rawtime;
time(&rawtime);
struct tm *timeinfo;
timeinfo = localtime(&rawtime);
return timeinfo->tm_year;
}
static int32_t SC_uptimeMillis()
{
return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
}
static int32_t SC_startTimeMillis()
{
GET_TLS();
return sc->mEnviroment.mStartTimeMillis;
}
static int32_t SC_elapsedTimeMillis()
{
GET_TLS();
return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
- sc->mEnviroment.mStartTimeMillis;
}
//////////////////////////////////////////////////////////////////////////////
// Matrix routines
//////////////////////////////////////////////////////////////////////////////
static void SC_matrixLoadIdentity(rsc_Matrix *mat)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->loadIdentity();
}
static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->load(f);
}
static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->load(reinterpret_cast<const Matrix *>(newmat));
}
static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->loadRotate(rot, x, y, z);
}
static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->loadScale(x, y, z);
}
static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->loadTranslate(x, y, z);
}
static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
reinterpret_cast<const Matrix *>(rhs));
}
static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->multiply(reinterpret_cast<const Matrix *>(rhs));
}
static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->rotate(rot, x, y, z);
}
static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->scale(x, y, z);
}
static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
{
Matrix *m = reinterpret_cast<Matrix *>(mat);
m->translate(x, y, z);
}
static void SC_vec2Rand(float *vec, float maxLen)
{
float angle = SC_randf(PI * 2);
float len = SC_randf(maxLen);
vec[0] = len * sinf(angle);
vec[1] = len * cosf(angle);
}
//////////////////////////////////////////////////////////////////////////////
// Context
//////////////////////////////////////////////////////////////////////////////
static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
{
GET_TLS();
rsi_ProgramFragmentBindTexture(rsc,
static_cast<ProgramFragment *>(vpf),
slot,
static_cast<Allocation *>(va));
}
static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
{
GET_TLS();
rsi_ProgramFragmentBindSampler(rsc,
static_cast<ProgramFragment *>(vpf),
slot,
static_cast<Sampler *>(vs));
}
static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
{
GET_TLS();
rsi_ContextBindProgramFragmentStore(rsc, pfs);
}
static void SC_bindProgramFragment(RsProgramFragment pf)
{
GET_TLS();
rsi_ContextBindProgramFragment(rsc, pf);
}
static void SC_bindProgramVertex(RsProgramVertex pv)
{
GET_TLS();
rsi_ContextBindProgramVertex(rsc, pv);
}
//////////////////////////////////////////////////////////////////////////////
// VP
//////////////////////////////////////////////////////////////////////////////
static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
{
GET_TLS();
rsc->getVertex()->setModelviewMatrix(m);
}
static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
{
GET_TLS();
rsc->getVertex()->setTextureMatrix(m);
}
//////////////////////////////////////////////////////////////////////////////
// Drawing
//////////////////////////////////////////////////////////////////////////////
static void SC_drawLine(float x1, float y1, float z1,
float x2, float y2, float z2)
{
GET_TLS();
rsc->setupCheck();
float vtx[] = { x1, y1, z1, x2, y2, z2 };
glBindBuffer(GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
}
static void SC_drawPoint(float x, float y, float z)
{
GET_TLS();
rsc->setupCheck();
float vtx[] = { x, y, z };
glBindBuffer(GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, 1);
}
static void SC_drawQuadTexCoords(float x1, float y1, float z1,
float u1, float v1,
float x2, float y2, float z2,
float u2, float v2,
float x3, float y3, float z3,
float u3, float v3,
float x4, float y4, float z4,
float u4, float v4)
{
GET_TLS();
//LOGE("Quad");
//LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
//LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
//LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
//LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
rsc->setupCheck();
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, tex);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, tex);
glClientActiveTexture(GL_TEXTURE0);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
//glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
static void SC_drawQuad(float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4)
{
SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
x2, y2, z2, 1, 1,
x3, y3, z3, 1, 0,
x4, y4, z4, 0, 0);
}
static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
{
GET_TLS();
rsc->setupCheck();
GLint crop[4] = {0, h, w, -h};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
glDrawTexfOES(x, y, z, w, h);
}
static void SC_drawSprite(float x, float y, float z, float w, float h)
{
GET_TLS();
rsc->setupCheck();
float vin[3] = {x, y, z};
float vout[4];
//LOGE("ds in %f %f %f", x, y, z);
rsc->getVertex()->transformToScreen(rsc, vout, vin);
//LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
vout[0] /= vout[3];
vout[1] /= vout[3];
vout[2] /= vout[3];
vout[0] *= rsc->getWidth() / 2;
vout[1] *= rsc->getHeight() / 2;
vout[0] += rsc->getWidth() / 2;
vout[1] += rsc->getHeight() / 2;
vout[0] -= w/2;
vout[1] -= h/2;
//LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
// U, V, W, H
GLint crop[4] = {0, h, w, -h};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
glDrawTexiOES(vout[0], vout[1], 0/*vout[2]*/, w, h);
}
static void SC_drawRect(float x1, float y1,
float x2, float y2, float z)
{
SC_drawQuad(x1, y2, z,
x2, y2, z,
x2, y1, z,
x1, y1, z);
}
static void SC_drawSimpleMesh(RsSimpleMesh vsm)
{
GET_TLS();
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
rsc->setupCheck();
sm->render();
}
static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
{
GET_TLS();
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
rsc->setupCheck();
sm->renderRange(start, len);
}
//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////
static void SC_color(float r, float g, float b, float a)
{
glColor4f(r, g, b, a);
}
static void SC_ambient(float r, float g, float b, float a)
{
GLfloat params[] = { r, g, b, a };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
}
static void SC_diffuse(float r, float g, float b, float a)
{
GLfloat params[] = { r, g, b, a };
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
}
static void SC_specular(float r, float g, float b, float a)
{
GLfloat params[] = { r, g, b, a };
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
}
static void SC_emission(float r, float g, float b, float a)
{
GLfloat params[] = { r, g, b, a };
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
}
static void SC_shininess(float s)
{
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
}
static void SC_pointAttenuation(float a, float b, float c)
{
GLfloat params[] = { a, b, c };
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
}
static void SC_hsbToRgb(float h, float s, float b, float* rgb)
{
float red = 0.0f;
float green = 0.0f;
float blue = 0.0f;
float x = h;
float y = s;
float z = b;
float hf = (x - (int) x) * 6.0f;
int ihf = (int) hf;
float f = hf - ihf;
float pv = z * (1.0f - y);
float qv = z * (1.0f - y * f);
float tv = z * (1.0f - y * (1.0f - f));
switch (ihf) {
case 0: // Red is the dominant color
red = z;
green = tv;
blue = pv;
break;
case 1: // Green is the dominant color
red = qv;
green = z;
blue = pv;
break;
case 2:
red = pv;
green = z;
blue = tv;
break;
case 3: // Blue is the dominant color
red = pv;
green = qv;
blue = z;
break;
case 4:
red = tv;
green = pv;
blue = z;
break;
case 5: // Red is the dominant color
red = z;
green = pv;
blue = qv;
break;
}
rgb[0] = red;
rgb[1] = green;
rgb[2] = blue;
}
static int SC_hsbToAbgr(float h, float s, float b, float a)
{
float rgb[3];
SC_hsbToRgb(h, s, b, rgb);
return int(a * 255.0f) << 24 |
int(rgb[2] * 255.0f) << 16 |
int(rgb[1] * 255.0f) << 8 |
int(rgb[0] * 255.0f);
}
static void SC_hsb(float h, float s, float b, float a)
{
float rgb[3];
SC_hsbToRgb(h, s, b, rgb);
glColor4f(rgb[0], rgb[1], rgb[2], a);
}
static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
{
GET_TLS();
rsi_AllocationUploadToTexture(rsc, va, baseMipLevel);
}
static void SC_uploadToBufferObject(RsAllocation va)
{
GET_TLS();
rsi_AllocationUploadToBufferObject(rsc, va);
}
static void SC_ClearColor(float r, float g, float b, float a)
{
//LOGE("c %f %f %f %f", r, g, b, a);
GET_TLS();
sc->mEnviroment.mClearColor[0] = r;
sc->mEnviroment.mClearColor[1] = g;
sc->mEnviroment.mClearColor[2] = b;
sc->mEnviroment.mClearColor[3] = a;
}
static void SC_debugF(const char *s, float f)
{
LOGE("%s %f", s, f);
}
static void SC_debugHexF(const char *s, float f)
{
LOGE("%s 0x%x", s, *((int *) (&f)));
}
static void SC_debugI32(const char *s, int32_t i)
{
LOGE("%s %i", s, i);
}
static void SC_debugHexI32(const char *s, int32_t i)
{
LOGE("%s 0x%x", s, i);
}
static uint32_t SC_getWidth()
{
GET_TLS();
return rsc->getWidth();
}
static uint32_t SC_getHeight()
{
GET_TLS();
return rsc->getHeight();
}
static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
{
uint32_t c = 0;
c |= (uint32_t)(r * 255.f + 0.5f);
c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
return c;
}
static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
{
uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
return rs888to565(ir, ig, ib);
}
static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
{
GET_TLS();
return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
}
static void SC_scriptCall(int scriptID)
{
GET_TLS();
rsc->runScript((Script *)scriptID, 0);
}
//////////////////////////////////////////////////////////////////////////////
// Class implementation
//////////////////////////////////////////////////////////////////////////////
ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
// IO
{ "loadI32", (void *)&SC_loadI32,
"int", "(int, int)" },
//{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
{ "loadF", (void *)&SC_loadF,
"float", "(int, int)" },
{ "loadArrayF", (void *)&SC_loadArrayF,
"float*", "(int, int)" },
{ "loadArrayI32", (void *)&SC_loadArrayI32,
"int*", "(int, int)" },
{ "loadVec4", (void *)&SC_loadVec4,
"void", "(int, int, float *)" },
{ "loadMatrix", (void *)&SC_loadMatrix,
"void", "(int, int, float *)" },
{ "storeI32", (void *)&SC_storeI32,
"void", "(int, int, int)" },
//{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
{ "storeF", (void *)&SC_storeF,
"void", "(int, int, float)" },
{ "storeVec4", (void *)&SC_storeVec4,
"void", "(int, int, float *)" },
{ "storeMatrix", (void *)&SC_storeMatrix,
"void", "(int, int, float *)" },
{ "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
"float*", "(int, int)" },
{ "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
"void", "(int)" },
// math
{ "modf", (void *)&fmod,
"float", "(float, float)" },
{ "abs", (void *)&abs,
"int", "(int)" },
{ "absf", (void *)&fabsf,
"float", "(float)" },
{ "sinf_fast", (void *)&SC_sinf_fast,
"float", "(float)" },
{ "cosf_fast", (void *)&SC_cosf_fast,
"float", "(float)" },
{ "sinf", (void *)&sinf,
"float", "(float)" },
{ "cosf", (void *)&cosf,
"float", "(float)" },
{ "asinf", (void *)&asinf,
"float", "(float)" },
{ "acosf", (void *)&acosf,
"float", "(float)" },
{ "atanf", (void *)&atanf,
"float", "(float)" },
{ "atan2f", (void *)&atan2f,
"float", "(float, float)" },
{ "fabsf", (void *)&fabsf,
"float", "(float)" },
{ "randf", (void *)&SC_randf,
"float", "(float)" },
{ "randf2", (void *)&SC_randf2,
"float", "(float, float)" },
{ "floorf", (void *)&floorf,
"float", "(float)" },
{ "fracf", (void *)&SC_fracf,
"float", "(float)" },
{ "ceilf", (void *)&ceilf,
"float", "(float)" },
{ "roundf", (void *)&SC_roundf,
"float", "(float)" },
{ "expf", (void *)&expf,
"float", "(float)" },
{ "logf", (void *)&logf,
"float", "(float)" },
{ "powf", (void *)&powf,
"float", "(float, float)" },
{ "maxf", (void *)&SC_maxf,
"float", "(float, float)" },
{ "minf", (void *)&SC_minf,
"float", "(float, float)" },
{ "sqrt", (void *)&sqrt,
"int", "(int)" },
{ "sqrtf", (void *)&sqrtf,
"float", "(float)" },
{ "sqr", (void *)&SC_sqr,
"int", "(int)" },
{ "sqrf", (void *)&SC_sqrf,
"float", "(float)" },
{ "sign", (void *)&SC_sign,
"int", "(int)" },
{ "signf", (void *)&SC_signf,
"float", "(float)" },
{ "clamp", (void *)&SC_clamp,
"int", "(int, int, int)" },
{ "clampf", (void *)&SC_clampf,
"float", "(float, float, float)" },
{ "distf2", (void *)&SC_distf2,
"float", "(float, float, float, float)" },
{ "distf3", (void *)&SC_distf3,
"float", "(float, float, float, float, float, float)" },
{ "magf2", (void *)&SC_magf2,
"float", "(float, float)" },
{ "magf3", (void *)&SC_magf3,
"float", "(float, float, float)" },
{ "radf", (void *)&SC_radf,
"float", "(float)" },
{ "degf", (void *)&SC_degf,
"float", "(float)" },
{ "lerpf", (void *)&SC_lerpf,
"float", "(float, float, float)" },
{ "normf", (void *)&SC_normf,
"float", "(float, float, float)" },
{ "mapf", (void *)&SC_mapf,
"float", "(float, float, float, float, float)" },
{ "noisef", (void *)&SC_noisef,
"float", "(float)" },
{ "noisef2", (void *)&SC_noisef2,
"float", "(float, float)" },
{ "noisef3", (void *)&SC_noisef3,
"float", "(float, float, float)" },
{ "turbulencef2", (void *)&SC_turbulencef2,
"float", "(float, float, float)" },
{ "turbulencef3", (void *)&SC_turbulencef3,
"float", "(float, float, float, float)" },
// time
{ "second", (void *)&SC_second,
"int", "()" },
{ "minute", (void *)&SC_minute,
"int", "()" },
{ "hour", (void *)&SC_hour,
"int", "()" },
{ "day", (void *)&SC_day,
"int", "()" },
{ "month", (void *)&SC_month,
"int", "()" },
{ "year", (void *)&SC_year,
"int", "()" },
{ "uptimeMillis", (void*)&SC_uptimeMillis,
"int", "()" }, // TODO: use long instead
{ "startTimeMillis", (void*)&SC_startTimeMillis,
"int", "()" }, // TODO: use long instead
{ "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
"int", "()" }, // TODO: use long instead
// matrix
{ "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
"void", "(float *mat)" },
{ "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
"void", "(float *mat, float *f)" },
{ "matrixLoadMat", (void *)&SC_matrixLoadMat,
"void", "(float *mat, float *newmat)" },
{ "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
"void", "(float *mat, float rot, float x, float y, float z)" },
{ "matrixLoadScale", (void *)&SC_matrixLoadScale,
"void", "(float *mat, float x, float y, float z)" },
{ "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
"void", "(float *mat, float x, float y, float z)" },
{ "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
"void", "(float *mat, float *lhs, float *rhs)" },
{ "matrixMultiply", (void *)&SC_matrixMultiply,
"void", "(float *mat, float *rhs)" },
{ "matrixRotate", (void *)&SC_matrixRotate,
"void", "(float *mat, float rot, float x, float y, float z)" },
{ "matrixScale", (void *)&SC_matrixScale,
"void", "(float *mat, float x, float y, float z)" },
{ "matrixTranslate", (void *)&SC_matrixTranslate,
"void", "(float *mat, float x, float y, float z)" },
// vector
{ "vec2Rand", (void *)&SC_vec2Rand,
"void", "(float *vec, float maxLen)" },
// vec3
{ "vec3Norm", (void *)&SC_vec3Norm,
"void", "(struct vec3_s *)" },
{ "vec3Length", (void *)&SC_vec3Length,
"float", "(struct vec3_s *)" },
{ "vec3Add", (void *)&SC_vec3Add,
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
{ "vec3Sub", (void *)&SC_vec3Sub,
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
{ "vec3Cross", (void *)&SC_vec3Cross,
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
{ "vec3Dot", (void *)&SC_vec3Dot,
"float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
{ "vec3Scale", (void *)&SC_vec3Scale,
"void", "(struct vec3_s *lhs, float scale)" },
// vec4
{ "vec4Norm", (void *)&SC_vec4Norm,
"void", "(struct vec4_s *)" },
{ "vec4Length", (void *)&SC_vec4Length,
"float", "(struct vec4_s *)" },
{ "vec4Add", (void *)&SC_vec4Add,
"void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
{ "vec4Sub", (void *)&SC_vec4Sub,
"void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
{ "vec4Dot", (void *)&SC_vec4Dot,
"float", "(struct vec4_s *lhs, struct vec4_s *rhs)" },
{ "vec4Scale", (void *)&SC_vec4Scale,
"void", "(struct vec4_s *lhs, float scale)" },
// context
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
"void", "(int)" },
{ "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
"void", "(int)" },
{ "bindProgramStore", (void *)&SC_bindProgramFragmentStore,
"void", "(int)" },
{ "bindProgramVertex", (void *)&SC_bindProgramVertex,
"void", "(int)" },
{ "bindSampler", (void *)&SC_bindSampler,
"void", "(int, int, int)" },
{ "bindTexture", (void *)&SC_bindTexture,
"void", "(int, int, int)" },
// vp
{ "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
"void", "(void *)" },
{ "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
"void", "(void *)" },
// drawing
{ "drawRect", (void *)&SC_drawRect,
"void", "(float x1, float y1, float x2, float y2, float z)" },
{ "drawQuad", (void *)&SC_drawQuad,
"void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
{ "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
"void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
{ "drawSprite", (void *)&SC_drawSprite,
"void", "(float x, float y, float z, float w, float h)" },
{ "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace,
"void", "(float x, float y, float z, float w, float h)" },
{ "drawLine", (void *)&SC_drawLine,
"void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
{ "drawPoint", (void *)&SC_drawPoint,
"void", "(float x1, float y1, float z1)" },
{ "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
"void", "(int ism)" },
{ "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
"void", "(int ism, int start, int len)" },
// misc
{ "pfClearColor", (void *)&SC_ClearColor,
"void", "(float, float, float, float)" },
{ "color", (void *)&SC_color,
"void", "(float, float, float, float)" },
{ "hsb", (void *)&SC_hsb,
"void", "(float, float, float, float)" },
{ "hsbToRgb", (void *)&SC_hsbToRgb,
"void", "(float, float, float, float*)" },
{ "hsbToAbgr", (void *)&SC_hsbToAbgr,
"int", "(float, float, float, float)" },
{ "ambient", (void *)&SC_ambient,
"void", "(float, float, float, float)" },
{ "diffuse", (void *)&SC_diffuse,
"void", "(float, float, float, float)" },
{ "specular", (void *)&SC_specular,
"void", "(float, float, float, float)" },
{ "emission", (void *)&SC_emission,
"void", "(float, float, float, float)" },
{ "shininess", (void *)&SC_shininess,
"void", "(float)" },
{ "pointAttenuation", (void *)&SC_pointAttenuation,
"void", "(float, float, float)" },
{ "uploadToTexture", (void *)&SC_uploadToTexture,
"void", "(int, int)" },
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
"void", "(int)" },
{ "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
"int", "(float, float, float, float)" },
{ "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
"int", "(float, float, float)" },
{ "getWidth", (void *)&SC_getWidth,
"int", "()" },
{ "getHeight", (void *)&SC_getHeight,
"int", "()" },
{ "sendToClient", (void *)&SC_toClient,
"int", "(void *data, int cmdID, int len, int waitForSpace)" },
{ "debugF", (void *)&SC_debugF,
"void", "(void *, float)" },
{ "debugI32", (void *)&SC_debugI32,
"void", "(void *, int)" },
{ "debugHexF", (void *)&SC_debugHexF,
"void", "(void *, float)" },
{ "debugHexI32", (void *)&SC_debugHexI32,
"void", "(void *, int)" },
{ "scriptCall", (void *)&SC_scriptCall,
"void", "(int)" },
{ NULL, NULL, NULL, NULL }
};
const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
{
ScriptCState::SymbolTable_t *syms = gSyms;
while (syms->mPtr) {
if (!strcmp(syms->mName, sym)) {
return syms;
}
syms++;
}
return NULL;
}
void ScriptCState::appendDecls(String8 *str)
{
ScriptCState::SymbolTable_t *syms = gSyms;
while (syms->mPtr) {
str->append(syms->mRet);
str->append(" ");
str->append(syms->mName);
str->append(syms->mParam);
str->append(";\n");
syms++;
}
}
|