diff --git a/android/app/src/main/jni/Android.mk b/android/app/src/main/jni/Android.mk index 0aea654..fcf105f 100644 --- a/android/app/src/main/jni/Android.mk +++ b/android/app/src/main/jni/Android.mk @@ -5,38 +5,19 @@ include $(CLEAR_VARS) LOCAL_MODULE := starwisp-core -LOCAL_CFLAGS := -DANDROID_NDK -fpermissive -DDISABLE_IMPORTGL -O3 -Wno-write-strings -DNDEBUG +LOCAL_CFLAGS := -DANDROID_NDK -Wswitch -fpermissive -DDISABLE_IMPORTGL -O3 -Wno-write-strings -DNDEBUG APP_OPTIM := release LOCAL_SRC_FILES := \ - fluxa/Sample.cpp \ - fluxa/Allocator.cpp \ - fluxa/Graph.cpp \ - fluxa/GraphNode.cpp \ - fluxa/Modules.cpp \ - fluxa/ModuleNodes.cpp \ core/list.cpp \ core/db.cpp \ core/db_container.cpp \ core/fixed.cpp \ - core/geometry.cpp \ core/idmap.cpp \ - core/noise.cpp \ sqlite/sqlite3.c \ scheme/scheme.cpp \ - engine/primitive.cpp \ - engine/text_primitive.cpp \ - engine/scenenode.cpp \ - engine/scenegraph.cpp \ - engine/texture.cpp \ - engine/importgl.c \ - engine/obj_reader.cpp \ - engine/nomadic.cpp \ - engine/engine.cpp \ - jellyfish/jellyfish.cpp \ - jellyfish/jellyfish_primitive.cpp \ - audio.cpp \ - app-android.c + app.cpp \ + app-android.c LOCAL_LDLIBS := -lGLESv1_CM -lOpenSLES -ldl -llog diff --git a/android/app/src/main/jni/app-android.c b/android/app/src/main/jni/app-android.c index 8e42eb3..eb3ae78 100644 --- a/android/app/src/main/jni/app-android.c +++ b/android/app/src/main/jni/app-android.c @@ -4,43 +4,20 @@ #include #include #include +#include +#include "app.h" #include "scheme/scheme.h" -static int sWindowWidth = 320; -static int sWindowHeight = 480; - void Java_foam_starwisp_Scheme_nativeInit(JNIEnv* env) { appInit(); } -/* Call to initialize the graphics state */ -void Java_foam_starwisp_Scheme_nativeInitGL( JNIEnv* env ) -{ - importGLInit(); - initGL(); -} - -void Java_foam_starwisp_Scheme_nativeResize( JNIEnv* env, jobject thiz, jint w, jint h ) -{ - sWindowWidth = w; - sWindowHeight = h; - __android_log_print(ANDROID_LOG_INFO, "SanAngeles", "resize w=%d h=%d", w, h); -} - - void Java_foam_starwisp_Scheme_nativeDone(JNIEnv* env) { appDeinit(); - importGLDeinit(); -} - -void Java_foam_starwisp_Scheme_nativeRender( JNIEnv* env ) -{ - appRender(sWindowWidth, sWindowHeight); } - jstring Java_foam_starwisp_Scheme_nativeEval(JNIEnv* env, jobject thiz, jstring code) { const char *native_code = (*env)->GetStringUTFChars(env, code, 0); @@ -55,26 +32,3 @@ jstring Java_foam_starwisp_Scheme_nativeEval(JNIEnv* env, jobject thiz, jstring return (*env)->NewStringUTF(env,""); } -void Java_foam_starwisp_Scheme_nativeLoadTexture(JNIEnv* env, jobject thiz, jstring texname, jbyteArray arr, jint w, jint h) -{ - char *data = (char *) (*env)->GetByteArrayElements(env,arr,NULL); - int len = (*env)->GetArrayLength(env, arr); - const char *filename = (*env)->GetStringUTFChars(env, texname, 0); - - __android_log_print(ANDROID_LOG_INFO, "starwisp", "loading texture"); - - - int id=appLoadTexture(filename,w,h,data); - - __android_log_print(ANDROID_LOG_INFO, "starwisp", "loaded texture"); - - (*env)->ReleaseStringUTFChars(env, texname, filename); - (*env)->ReleaseByteArrayElements(env,arr,data,JNI_ABORT); -} - -// create the engine and output mix objects -void Java_foam_starwisp_Scheme_createEngine(JNIEnv* env, jclass clazz) -{ - audio_init(); - create_audio_engine(); -} diff --git a/android/app/src/main/jni/app.h b/android/app/src/main/jni/app.h index 9640caf..28fc6c2 100644 --- a/android/app/src/main/jni/app.h +++ b/android/app/src/main/jni/app.h @@ -4,16 +4,9 @@ extern "C" { #endif -#define WINDOW_DEFAULT_WIDTH 640 -#define WINDOW_DEFAULT_HEIGHT 480 -#define WINDOW_BPP 16 - extern void appInit(); -extern void initGL(); extern void appDeinit(); -extern void appEval(char *code); -extern void appRender(int width, int height); -extern unsigned int appLoadTexture(const char *filename, int width, int height, char* data); +extern void appEval(const char *code); #ifdef __cplusplus } diff --git a/android/app/src/main/jni/engine/nomadic.cpp b/android/app/src/main/jni/engine/nomadic.cpp index edef2c2..5972503 100644 --- a/android/app/src/main/jni/engine/nomadic.cpp +++ b/android/app/src/main/jni/engine/nomadic.cpp @@ -19,9 +19,7 @@ #include #include -#include "importgl.h" #include "app.h" -#include "engine/engine.h" #include "scheme/scheme.h" scheme *sc=NULL;; @@ -46,25 +44,6 @@ void appInit() if (log_file!=NULL) scheme_set_output_port_file(sc, log_file); } -void initGL() -{ - int a; - - glEnable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glShadeModel(GL_SMOOTH); - glEnable(GL_BLEND); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glDisable(GL_LIGHT1); - glDisable(GL_LIGHT2); - - glEnableClientState(GL_VERTEX_ARRAY); - - engine::init(); -} - // Called from the app framework. void appDeinit() { @@ -72,93 +51,8 @@ void appDeinit() int a; } - -static void gluPerspective(GLfloat fovy, GLfloat aspect, - GLfloat zNear, GLfloat zFar) -{ - GLfloat xmin, xmax, ymin, ymax; - - ymax = zNear * (GLfloat)tan(fovy * 3.141 / 360); - ymin = -ymax; - xmin = ymin * aspect; - xmax = ymax * aspect; - - glFrustumx((GLfixed)(xmin * 65536), (GLfixed)(xmax * 65536), - (GLfixed)(ymin * 65536), (GLfixed)(ymax * 65536), - (GLfixed)(zNear * 65536), (GLfixed)(zFar * 65536)); -} - - -static void prepareFrame(int width, int height) -{ - glViewport(0, 0, width, height); - - engine::get()->set_screensize(width,height); - -// glClearColorx((GLfixed)(engine::get()->m_clear_r * 65536), -// (GLfixed)(engine::get()->m_clear_g * 65536), -// (GLfixed)(engine::get()->m_clear_b * 65536), -// (GLfixed)(0.5 * 65536)); - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45, (float)width / height, 0.5f, 150); - - glMatrixMode(GL_MODELVIEW); - - glLoadIdentity(); -} - - -static void configureLightAndMaterial() -{ - static GLfixed light0Position[] = { -0x40000, 0x100000, 0x00000, 0 }; - static GLfixed light0Diffuse[] = { 0x10000, 0x10000, 0x10000, 0x10000 }; - static GLfixed light1Position[] = { 0x10000, -0x20000, -0x10000, 0 }; - static GLfixed light1Diffuse[] = { 0x11eb, 0x23d7, 0x5999, 0x10000 }; - static GLfixed light2Position[] = { -0x10000, 0, -0x40000, 0 }; - static GLfixed light2Diffuse[] = { 0x11eb, 0x2b85, 0x23d7, 0x10000 }; - static GLfixed materialSpecular[] = { 0x10000, 0x10000, 0x10000, 0x10000 }; - - glLightxv(GL_LIGHT0, GL_POSITION, light0Position); - glLightxv(GL_LIGHT0, GL_DIFFUSE, light0Diffuse); - glLightxv(GL_LIGHT1, GL_POSITION, light1Position); - glLightxv(GL_LIGHT1, GL_DIFFUSE, light1Diffuse); - glLightxv(GL_LIGHT2, GL_POSITION, light2Position); - glLightxv(GL_LIGHT2, GL_DIFFUSE, light2Diffuse); -// glMaterialxv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular); - -// glMaterialx(GL_FRONT_AND_BACK, GL_SHININESS, 60 << 16); - glEnable(GL_COLOR_MATERIAL); -} - -// Called from the app framework. -/* The tick is current time in milliseconds, width and height - * are the image dimensions to be rendered. - */ -void appRender(int width, int height) -{ - // Prepare OpenGL ES for rendering of the frame. - prepareFrame(width, height); - - // Configure environment. - configureLightAndMaterial(); - - scheme_load_string(sc,"(frame-hook)"); - - glPushMatrix(); - engine::get()->render(); - glPopMatrix(); -} - void appEval(char *code) { scheme_load_string(sc,code); fflush(log_file); } - -u32 appLoadTexture(const char *filename,int width, int height, char* data) -{ - return engine::get()->load_texture(filename,width,height,(u8*)data); -} diff --git a/android/app/src/main/jni/scheme/scheme.cpp b/android/app/src/main/jni/scheme/scheme.cpp index 51b8a8d..169227d 100644 --- a/android/app/src/main/jni/scheme/scheme.cpp +++ b/android/app/src/main/jni/scheme/scheme.cpp @@ -40,9 +40,6 @@ #include #endif -#include "../engine/engine.h" -#include "../core/geometry.h" - char *starwisp_data = NULL; #include "core/db_container.h" @@ -50,10 +47,6 @@ db_container the_db_container; #include "core/idmap.h" idmap the_idmap; -#include "../fluxa/Graph.h" - -Graph *m_audio_graph; - #ifdef _EE #define USE_STRLWR 0 #define USE_STRCASECMP 0 @@ -4297,7 +4290,7 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) { s_retbool(is_closure(car(sc->args))); case OP_MACROP: /* macro? */ s_retbool(is_macro(car(sc->args))); -///////////// FLUXUS +///////////// STARWISP case OP_ALOG: #ifdef ANDROID_NDK __android_log_print(ANDROID_LOG_INFO, "starwisp", "%s", string_value(car(sc->args))); @@ -4426,289 +4419,6 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) { sc,mk_integer(sc,the_idmap.get( string_value(car(sc->args))))); } -//////////////////// fluxus ///////////////////////////////////////// - - case OP_PUSH: - engine::get()->push(); s_return(sc,sc->F); - case OP_POP: - engine::get()->pop(); s_return(sc,sc->F); - case OP_GRAB: - engine::get()->grab(ivalue(car(sc->args))); s_return(sc,sc->F); - case OP_UNGRAB: - engine::get()->ungrab(); s_return(sc,sc->F); - case OP_PARENT: - engine::get()->parent(ivalue(car(sc->args))); s_return(sc,sc->F); - case OP_LOCK_CAMERA: - engine::get()->lock_camera(ivalue(car(sc->args))); s_return(sc,sc->F); - case OP_IDENTITY: - engine::get()->identity(); s_return(sc,sc->F); - case OP_TRANSLATE: - engine::get()->translate(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2))); - s_return(sc,sc->F); - case OP_SCALE: - engine::get()->scale(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2))); - s_return(sc,sc->F); - case OP_ROTATE: - engine::get()->rotate(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2))); - s_return(sc,sc->F); - case OP_COLOUR: - engine::get()->colour(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2)), - rvalue(vector_elem(car(sc->args),3))); - s_return(sc,sc->F); - case OP_HINT: - { - u32 h=ivalue(car(sc->args)); - switch (h) - { - case 0: engine::get()->hint(HINT_NONE); break; //??? - case 1: engine::get()->hint(HINT_SOLID); break; - case 2: engine::get()->hint(HINT_WIRE); break; - case 3: engine::get()->hint(HINT_NORMAL); break; - case 4: engine::get()->hint(HINT_POINTS); break; - case 5: engine::get()->hint(HINT_AALIAS); break; - case 6: engine::get()->hint(HINT_BOUND); break; - case 7: engine::get()->hint(HINT_UNLIT); break; - case 8: engine::get()->hint(HINT_VERTCOLS); break; - case 9: engine::get()->hint(HINT_ORIGIN); break; - case 10: engine::get()->hint(HINT_CAST_SHADOW); break; - case 11: engine::get()->hint(HINT_IGNORE_DEPTH); break; - case 12: engine::get()->hint(HINT_DEPTH_SORT); break; - case 13: engine::get()->hint(HINT_LAZY_PARENT); break; - case 14: engine::get()->hint(HINT_CULL_CCW); break; - case 15: engine::get()->hint(HINT_WIRE_STIPPLED); break; - case 16: engine::get()->hint(HINT_SPHERE_MAP); break; - case 17: engine::get()->hint(HINT_FRUSTUM_CULL); break; - case 18: engine::get()->hint(HINT_NORMALISE); break; - case 19: engine::get()->hint(HINT_NOBLEND); break; - case 20: engine::get()->hint(HINT_NOZWRITE); break; - } - s_return(sc,sc->F); - } - case OP_DESTROY: - engine::get()->destroy(rvalue(car(sc->args))); - s_return(sc,sc->F); - case OP_LINE_WIDTH: - engine::get()->line_width(rvalue(car(sc->args))); - s_return(sc,sc->F); - case OP_TEXTURE: - engine::get()->texture(rvalue(car(sc->args))); - s_return(sc,sc->F); - case OP_LOAD_TEXTURE: - s_return(sc,mk_integer(sc,engine::get()->get_texture(string_value(car(sc->args))))); - case OP_BUILD_CUBE: - s_return(sc,mk_integer(sc,engine::get()->build_cube())); - case OP_LOAD_OBJ: - s_return(sc,mk_integer(sc,engine::get()->load_obj(string_value(car(sc->args))))); - case OP_RAW_OBJ: - s_return(sc,mk_integer(sc,engine::get()->raw_obj(string_value(car(sc->args))))); - case OP_BUILD_TEXT: - s_return(sc,mk_integer(sc,engine::get()->build_text( - string_value(car(sc->args))))); - case OP_BUILD_JELLYFISH: - s_return(sc,mk_integer(sc,engine::get()->build_jellyfish(ivalue(car(sc->args))))); - case OP_BUILD_POLYGONS: - s_return(sc,mk_integer(sc,engine::get()->build_polygons( - ivalue(car(sc->args)), - ivalue(cadr(sc->args)) - ))); - case OP_GET_TRANSFORM: - { - flx_real *m=&(engine::get()->get_transform()->m[0][0]); - pointer v=mk_vector(sc,16); - int i=0; - for (i=0; i<16; i++) - { - set_vector_elem(v,i,mk_real(sc,m[i])); - } - s_return(sc,v); - } - case OP_GET_GLOBAL_TRANSFORM: - { - mat44 mat=engine::get()->get_global_transform(); - flx_real *m=&(mat.m[0][0]); - pointer v=mk_vector(sc,16); - int i=0; - for (i=0; i<16; i++) - { - set_vector_elem(v,i,mk_real(sc,m[i])); - } - s_return(sc,v); - } - case OP_GET_CAMERA_TRANSFORM: - { - flx_real *m=&(engine::get()->get_camera_transform()->m[0][0]); - pointer v=mk_vector(sc,16); - int i=0; - for (i=0; i<16; i++) - { - set_vector_elem(v,i,mk_real(sc,m[i])); - } - s_return(sc,v); - } - case OP_GET_SCREEN_SIZE: - { - unsigned int *s=engine::get()->get_screensize(); - pointer v=mk_vector(sc,2); - set_vector_elem(v,0,mk_real(sc,s[0])); - set_vector_elem(v,1,mk_real(sc,s[1])); - s_return(sc,v); - } - case OP_APPLY_TRANSFORM: - engine::get()->apply_transform(); s_return(sc,sc->F); - case OP_CLEAR: - engine::get()->clear(); s_return(sc,sc->F); - case OP_CLEAR_COLOUR: - engine::get()->clear_colour(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2)), - rvalue(vector_elem(car(sc->args),3))); - s_return(sc,sc->F); - case OP_PDATA_SIZE: - s_return(sc,mk_integer(sc,engine::get()->pdata_size())); - case OP_PDATA_ADD: - engine::get()->pdata_add(string_value(car(sc->args))); - s_return(sc,sc->F); - case OP_PDATA_REF: - { - vec3* vec=engine::get()->pdata_get(string_value(car(sc->args)), - ivalue(cadr(sc->args))); - pointer v=mk_vector(sc,3); - if (vec) - { - set_vector_elem(v,0,mk_real(sc,vec->x)); - set_vector_elem(v,1,mk_real(sc,vec->y)); - set_vector_elem(v,2,mk_real(sc,vec->z)); - } - s_return(sc,v); - } - case OP_PDATA_SET: - { - vec3 vec(rvalue(vector_elem(caddr(sc->args),0)), - rvalue(vector_elem(caddr(sc->args),1)), - rvalue(vector_elem(caddr(sc->args),2))); - engine::get()->pdata_set(string_value(car(sc->args)), - ivalue(cadr(sc->args)), - vec); - s_return(sc,sc->F); - } - case OP_SET_TEXT: - { - engine::get()->text_set(string_value(car(sc->args))); - s_return(sc,sc->F); - } - case OP_GEO_LINE_INTERSECT: - { - vec3 svec(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2))); - vec3 evec(rvalue(vector_elem(cadr(sc->args),0)), - rvalue(vector_elem(cadr(sc->args),1)), - rvalue(vector_elem(cadr(sc->args),2))); - bb::list *points=engine::get()->geo_line_intersect(svec,evec); - if (points!=NULL) - { - pointer list=sc->NIL; - intersect_point *p=static_cast(points->m_head); - while (p!=NULL) - { - list=cons(sc,mk_real(sc,p->m_t),list); - pointer blend=sc->NIL; - intersect_point::blend *b= - static_cast - (p->m_blends.m_head); - while (b!=NULL) - { - pointer v=mk_vector(sc,3); - set_vector_elem(v,0,mk_real(sc,b->m_blend.x)); - set_vector_elem(v,1,mk_real(sc,b->m_blend.y)); - set_vector_elem(v,2,mk_real(sc,b->m_blend.z)); - - pointer l=sc->NIL; - l=cons(sc,mk_string(sc,b->m_name),v); - - blend=cons(sc,l,blend); - b=static_cast(b->m_next); - } - list=cons(sc,blend,list); - p=static_cast(p->m_next); - } - s_return(sc,list); - } - s_return(sc,sc->F); - } - case OP_GET_LINE_INTERSECT: - { - vec3 svec(rvalue(vector_elem(car(sc->args),0)), - rvalue(vector_elem(car(sc->args),1)), - rvalue(vector_elem(car(sc->args),2))); - vec3 evec(rvalue(vector_elem(cadr(sc->args),0)), - rvalue(vector_elem(cadr(sc->args),1)), - rvalue(vector_elem(cadr(sc->args),2))); - s_return(sc,mk_integer(sc,engine::get()->get_line_intersect(svec,evec))); - } - case OP_MINVERSE: - { - mat44 inm; - int i=0; - for (i=0; i<16; i++) - { - inm.arr()[i]=rvalue(vector_elem(car(sc->args),i)); - } - inm=inm.inverse(); - pointer v=mk_vector(sc,16); - for (i=0; i<16; i++) - { - set_vector_elem(v,i,mk_real(sc,inm.arr()[i])); - } - s_return(sc,v); - } - case OP_BITWISE_IOR: - { - s_return(sc,mk_integer(sc, - ivalue(car(sc->args))| - ivalue(cadr(sc->args))| - ivalue(caddr(sc->args)) - )); - } - -///////////////////////////////////////////////////////// - case OP_FLUXA_INIT: - { - m_audio_graph = new Graph(ivalue(car(sc->args)), - ivalue(cadr(sc->args))); - s_return(sc,sc->NIL); - } - case OP_FLUXA_CREATE: - { - m_audio_graph->Create(ivalue(car(sc->args)), - (Graph::Type)ivalue(cadr(sc->args)), - ivalue(caddr(sc->args))); - s_return(sc,sc->NIL); - } - case OP_FLUXA_CONNECT: - { - m_audio_graph->Connect(ivalue(car(sc->args)), - ivalue(cadr(sc->args)), - ivalue(caddr(sc->args))); - s_return(sc,sc->NIL); - } - case OP_FLUXA_PLAY: - { - m_audio_graph->Play(rvalue(car(sc->args)), - ivalue(cadr(sc->args)), - rvalue(caddr(sc->args))); - s_return(sc,sc->NIL); - } - - //////////////////// default: