void qspCallSaveGame(QSP_CHAR *file) { /* Здесь позволяем пользователю выбрать файл */ /* для сохранения состояния игры и сохраняем */ /* в нем текущее состояние */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_SAVEGAMESTATUS].IsSet) { qspSaveCallState(&state, QSP_FALSE, QSP_TRUE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_SAVEGAMESTATUS].FuncVal, qspCallBacks[QSP_CALL_SAVEGAMESTATUS].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
QSP_BOOL qspCallIsPlayingFile(QSP_CHAR *file) { /* Здесь проверяем, проигрывается ли файл */ QSPCallState state; QSP_BOOL isPlaying; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_ISPLAYINGFILE].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_ISPLAYINGFILE].FuncVal, qspCallBacks[QSP_CALL_ISPLAYINGFILE].ThisVal, args); AS3_Release(args); flyield(); isPlaying = (QSP_BOOL)AS3_IntValue(result); AS3_Release(result); qspRestoreCallState(&state); return isPlaying; } return QSP_FALSE; }
QSP_CHAR *qspCallInputBox(QSP_CHAR *text) { /* Здесь вводим текст */ QSPCallState state; QSP_CHAR *buffer; AS3_Val args; char *strUTF8; char *resText; int maxLen = 511; if (qspCallBacks[QSP_CALL_INPUTBOX].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (text) { strUTF8 = qspW2C(text); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_INPUTBOX].FuncVal, qspCallBacks[QSP_CALL_INPUTBOX].ThisVal, args); AS3_Release(args); flyield(); resText = AS3_StringValue(result); AS3_Release(result); buffer = qspC2W(resText); free(resText); qspRestoreCallState(&state); } else buffer = qspGetNewText(QSP_FMT(""), 0); return buffer; }
AS3_Val cloneMesh( void * self, AS3_Val args ) { Mesh* src, *mesh; Material* material; Texture* texture; int render_mode, i; Vector3D** vp; AS3_ArrayValue( args, "PtrType, PtrType, PtrType, IntType",& src, & material, & texture, & render_mode); mesh = mesh_clone(src, material, texture, render_mode); if( ( vp = ( Vector3D * * )malloc( sizeof( Vector3D * ) * mesh -> nVertices ) ) == NULL ) { return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", mesh, & mesh->lightEnable, & mesh->fogEnable, & mesh->useMipmap, //& mesh->terrainTrace, & mesh->mip_dist, & mesh->v_dirty, & mesh->octree_depth, & mesh->addressMode, & mesh->texTransform->rotation, mesh->texTransform->offset, mesh->texTransform->scale, & mesh->texTransformDirty, & mesh->hit, & mesh->skinMeshController); } for( i = 0; i < mesh -> nVertices; i ++ ) { vp[i] = mesh -> vertices[i]->position; } return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", mesh, & mesh->lightEnable, & mesh->fogEnable, & mesh->useMipmap, //& mesh->terrainTrace, & mesh->mip_dist, & mesh->v_dirty, & mesh->octree_depth, & mesh->addressMode, & mesh->texTransform->rotation, mesh->texTransform->offset, mesh->texTransform->scale, & mesh->texTransformDirty, & mesh->hit, & mesh->skinMeshController, & vp ); }
/* * Create an ActionScript value from the lua stack starting * at index start and ending at index end. If collapse_array == 1, * an empty return will be transformed into AS3_Undefined() and a * return of length 1 will just return the specific value. * Otherwise an array is returned. */ AS3_Val create_as3_value_from_lua_stack( lua_State * L, int start, int end, BOOL collapse_array ) { /* WARNING: Panic alert! Use L*_FN checkers here! */ LCALL(L, stack); AS3_Val ret; SPAM(("create_as3_value_from_lua_stack(): begin")); if (collapse_array == TRUE && start > end) { ret = AS3_Null(); } else if (collapse_array == TRUE && start == end) { ret = get_as3_value_from_lua_stack(L, start); } else { int i; ret = AS3_Array(""); for (i = start; i <= end; ++i) { AS3_Val value; AS3_Val r; /*SPAM(("create_as3_value_from_lua_stack() + 1 begin"));*/ value = get_as3_value_from_lua_stack(L, i); r = AS3_CallTS("push", ret, "AS3ValType", value); SAFE_RELEASE(r); /* Ignoring result */ SAFE_RELEASE(value); /*SPAM(("create_as3_value_from_lua_stack() + 1 end"));*/ } } #ifdef DO_SPAM SPAM(("create_as3_value_from_lua_stack(): end")); AS3_Trace( AS3_Call( getQualifiedClassName_method, NULL, AS3_Array("AS3ValType", ret) ) ); #endif /* DO_SPAM */ LCHECK_FN(L, stack, 0, fatal_error); return ret; }
AS3_Val initializeMorphChannel( void* self, AS3_Val args ) { Animation* animation; int length, i, duration = 0; char* name; float* times; Vector3D** vertices; int* verticesLength; MorphChannel* channel; Frame* frames; AS3_ArrayValue(args, "PtrType, IntType, PtrType, PtrType, PtrType, PtrType", &animation, &length, &name, ×, &vertices, &verticesLength); if(length) { if( ( frames = ( Frame * )malloc(sizeof(Frame) * length) ) == NULL ) exit( TRUE ); for(i = 0; i < length; i ++) { frames[i].length = verticesLength[i]; frames[i].vertices = vertices[i]; frames[i].time = times[i]; memcpy(frames[i].name, name + i * FRAME_NAME_LENGTH, FRAME_NAME_LENGTH); duration += frames[i].time; } } channel = newMorphChannel(animation, frames, length, duration); return AS3_Array("PtrType, PtrType, PtrType, PtrType", channel, &channel->dirty, channel->currentFrameName, &channel->nameLength); }
AS3_Val doUnAes(void *data, AS3_Val args) { AS3_Val input = NULL; unsigned int in_len; char * ar; AS3_ArrayValue(args, "AS3ValType, IntType", &input, &in_len); ar = (char *)malloc(in_len); AS3_ByteArray_readBytes((void*)ar, input, in_len); char * aesData; int out_len = 0; char * keyStr = "kael"; //use AES to Decrypt the bytes aesData = DES_Decrypt(ar, keyStr, in_len, &out_len ); //make a new as3 byteArray var AS3_Val baNS = AS3_String("flash.utils"); AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray"); AS3_Val emptyParams = AS3_Array(""); AS3_Val byteArray2 = AS3_New(baClass, emptyParams); AS3_ByteArray_writeBytes(byteArray2, aesData, out_len); return byteArray2; }
AS3_Val initializeLight( void* self, AS3_Val args ) { //Scene * scene; Entity * source; int type; Light * light; Lights * node; AS3_ArrayValue( args, "PtrType, IntType", &source, &type ); light = newPointLight( type, source ); //scene_addLight( scene, light ); if( ( node = ( Lights * )malloc( sizeof( Lights ) ) ) == NULL ) { exit( TRUE ); } node -> light = light; node -> next = NULL; return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", light, &light->mode, &light->bOnOff, &light->type, light->ambient, light->diffuse, light->specular, &light->range, &light->falloff, &light->theta, &light->phi, &light->attenuation0, &light->attenuation1, &light->attenuation2, node ); }
AS3_Val initializeScene( void* self, AS3_Val args ) { Scene * scene; scene = newScene(); return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", scene, & scene->nNodes, & scene->nVertices, & scene->nFaces, & scene->nRenderList, & scene->nCullList, & scene->nClippList, &scene->terrain ); }
AS3_Val initializeTexture( void* self, AS3_Val args ) { char * name; Texture * texture; AS3_ArrayValue( args, "StrType", &name ); texture = newTexture( name ); return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType", texture, & texture->perspective_dist, &texture->perspectiveLP_dist, &texture->alphaTestRef, &texture->numMipLevels); }
/* setup some useful constants */ void initialize_as3_constants() { no_params = AS3_Array(""); zero_param = AS3_Int(0); Number_class = get_class2(NULL, "Number"); int_class = get_class2(NULL, "int"); String_class = get_class2(NULL, "String"); Boolean_class = get_class2(NULL, "Boolean"); flash_utils_namespace = AS3_String("flash.utils"); getQualifiedClassName_method = AS3_NSGetS(flash_utils_namespace, "getQualifiedClassName"); Array_class = get_class2(NULL, "Array"); }
/* * Given an ActionScript object, push it onto the Lua stack as a Lua native * type if a primitive class (String, Number, Boolean, int, null). * If object is not convertible to native Lua value, do not push anything * (and return 0). * * WARNING: It important that this function does not touch * non-primitive values (like Arrays). If this will be changed, * optional primitive autoconversion logic will break. */ int push_as3_to_lua_stack_if_convertible(lua_State * L, AS3_Val val) { LCALL(L, stack); #ifdef DO_SPAM SPAM(("push_as3_to_lua_stack_if_convertible(): begin: value, type")); AS3_Trace(val); AS3_Trace( AS3_Call( getQualifiedClassName_method, NULL, AS3_Array("AS3ValType", val) ) ); #endif /* DO_SPAM */ if (AS3_InstanceOf(val, Number_class)) { lua_pushnumber(L, AS3_NumberValue(val)); } else if (AS3_InstanceOf(val, int_class)) { lua_pushinteger(L, AS3_IntValue(val)); } else if (AS3_InstanceOf(val, String_class)) { size_t length = 0; AS3_Malloced_Str str = get_string_bytes(val, &length); lua_pushlstring(L, str, length); free(str); } else if (AS3_InstanceOf(val, Boolean_class)) { lua_pushboolean(L, AS3_IntValue(val)); } else if (val == AS3_Undefined()) { lua_pushnil(L); } else if (is_null(val)) { lua_pushnil(L); } else { SPAM(("push_as3_to_lua_stack_if_convertible(): not convertible")); LRETURN(L, stack, 0); } SPAM(("push_as3_to_lua_stack_if_convertible(): end")); LRETURN(L, stack, 1); }
void qspCallShowPicture(QSP_CHAR *file) { /* Здесь показываем изображение */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_SHOWIMAGE].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_SHOWIMAGE].FuncVal, qspCallBacks[QSP_CALL_SHOWIMAGE].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallShowMessage(QSP_CHAR *text) { /* Здесь показываем сообщение */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_SHOWMSGSTR].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (text) { strUTF8 = qspW2C(text); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_SHOWMSGSTR].FuncVal, qspCallBacks[QSP_CALL_SHOWMSGSTR].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallCloseFile(QSP_CHAR *file) { /* Здесь выполняем закрытие файла */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_CLOSEFILE].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_CLOSEFILE].FuncVal, qspCallBacks[QSP_CALL_CLOSEFILE].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallSystem(QSP_CHAR *cmd) { /* Здесь выполняем системный вызов */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_SYSTEM].IsSet) { qspSaveCallState(&state, QSP_FALSE, QSP_FALSE); if (cmd) { strUTF8 = qspW2C(cmd); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_SYSTEM].FuncVal, qspCallBacks[QSP_CALL_SYSTEM].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallSetInputStrText(QSP_CHAR *text) { /* Здесь устанавливаем текст строки ввода */ QSPCallState state; AS3_Val args; char *textUTF8; if (qspCallBacks[QSP_CALL_SETINPUTSTRTEXT].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (text) { textUTF8 = qspW2C(text); args = AS3_Array("StrType", textUTF8); free(textUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_SETINPUTSTRTEXT].FuncVal, qspCallBacks[QSP_CALL_SETINPUTSTRTEXT].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallDebug(QSP_CHAR *str) { /* Здесь передаем управление отладчику */ QSPCallState state; char *strUTF8; AS3_Val args; if (qspCallBacks[QSP_CALL_DEBUG].IsSet) { qspSaveCallState(&state, QSP_FALSE, QSP_FALSE); if (str) { strUTF8 = qspW2C(str); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_DEBUG].FuncVal, qspCallBacks[QSP_CALL_DEBUG].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallPlayFile(QSP_CHAR *file, int volume) { /* Здесь начинаем воспроизведение файла с заданной громкостью */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_PLAYFILE].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType, IntType", strUTF8, volume); free(strUTF8); } else args = AS3_Array("StrType, IntType", 0, volume); AS3_Call(qspCallBacks[QSP_CALL_PLAYFILE].FuncVal, qspCallBacks[QSP_CALL_PLAYFILE].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
/* TODO: Ugly workaround. Remove. See http://tinyurl.com/a9djb2 */ BOOL is_null(AS3_Val val) { BOOL result = FALSE; AS3_Val argsVal = AS3_Array("AS3ValType", val); AS3_Val classNameVal = AS3_Call(getQualifiedClassName_method, NULL, argsVal); AS3_Malloced_Str className = AS3_StringValue(classNameVal); AS3_Release(argsVal); AS3_Release(classNameVal); result = (strncmp(className, "null", 4) == 0); free(className); return result; }
void qspCallSetTimer(int msecs) { /* Здесь устанавливаем интервал таймера */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_SETTIMER].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); args = AS3_Array("IntType", msecs); AS3_Call(qspCallBacks[QSP_CALL_SETTIMER].FuncVal, qspCallBacks[QSP_CALL_SETTIMER].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
AS3_Val initializeAnimation( void* self, AS3_Val args ) { Animation* a; Entity* parent; int isPlay, loop; int maxTime, minTime; AS3_ArrayValue(args, "PtrType, IntType, IntType, IntType, IntType", &parent, &isPlay, &loop, &maxTime, &minTime); a = newAnimation(isPlay, loop, maxTime, minTime); parent->animation = a; return AS3_Array("PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", a, &a->isPlay, &a->loop, &a->minTime, &a->maxTime, &a->durationTime, &a->time, &a->timeMode); }
AS3_Val initializeViewport( void* self, AS3_Val args ) { Viewport * view; Scene * scene; Camera * camera; double width, height; AS3_ArrayValue( args, "DoubleType, DoubleType, PtrType, PtrType", &width, &height, &camera, &scene ); view = newViewport( (float)width, (float)height, scene, camera ); return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", view, view->videoBuffer, view->zBuffer, & view->camera, & view->scene, &view->sortTransList ); }
void qspCallRefreshInt(QSP_BOOL isRedraw) { /* Здесь выполняем обновление интерфейса */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_REFRESHINT].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); args = AS3_Array("IntType", isRedraw); AS3_Call(qspCallBacks[QSP_CALL_REFRESHINT].FuncVal, qspCallBacks[QSP_CALL_REFRESHINT].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallOpenGame(QSP_CHAR *file) { /* Здесь позволяем пользователю выбрать файл */ /* состояния игры для загрузки и загружаем его */ QSPCallState state; AS3_Val args; char *strUTF8; if (qspCallBacks[QSP_CALL_OPENGAMESTATUS].IsSet) { qspSaveCallState(&state, QSP_FALSE, QSP_TRUE); if (file) { strUTF8 = qspW2C(file); args = AS3_Array("StrType", strUTF8); free(strUTF8); } else args = AS3_Array("StrType", 0); AS3_Call(qspCallBacks[QSP_CALL_OPENGAMESTATUS].FuncVal, qspCallBacks[QSP_CALL_OPENGAMESTATUS].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallShowMenu() { /* Здесь показываем меню */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_SHOWMENU].IsSet) { qspSaveCallState(&state, QSP_FALSE, QSP_TRUE); args = AS3_Array(""); AS3_Call(qspCallBacks[QSP_CALL_SHOWMENU].FuncVal, qspCallBacks[QSP_CALL_SHOWMENU].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallShowWindow(int type, QSP_BOOL isShow) { /* Здесь показываем или скрываем окно */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_SHOWWINDOW].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); args = AS3_Array("IntType, IntType", type, isShow); AS3_Call(qspCallBacks[QSP_CALL_SHOWWINDOW].FuncVal, qspCallBacks[QSP_CALL_SHOWWINDOW].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallSleep(int msecs) { /* Здесь ожидаем заданное количество миллисекунд */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_SLEEP].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); args = AS3_Array("IntType", msecs); AS3_Call(qspCallBacks[QSP_CALL_SLEEP].FuncVal, qspCallBacks[QSP_CALL_SLEEP].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
void qspCallDeleteMenu() { /* Здесь удаляем текущее меню */ QSPCallState state; AS3_Val args; if (qspCallBacks[QSP_CALL_DELETEMENU].IsSet) { qspSaveCallState(&state, QSP_TRUE, QSP_FALSE); args = AS3_Array(""); AS3_Call(qspCallBacks[QSP_CALL_DELETEMENU].FuncVal, qspCallBacks[QSP_CALL_DELETEMENU].ThisVal, args); AS3_Release(args); flyield(); qspRestoreCallState(&state); } }
AS3_Val initialize3DS( void* self, AS3_Val args ) { FILE * file; void * dest; Entity * entity; A3DS * a3ds; DWORD render_mode; AS3_ArrayValue(args, "AS3ValType, PtrType, IntType", &dest, &entity, &render_mode); file = funopen((void *)dest, readByteArray, writeByteArray, seekByteArray, closeByteArray); a3ds = A3DS_Create( file, entity, render_mode ); return AS3_Array( "PtrType, IntType, IntType, PtrType, IntType, IntType, IntType", a3ds, a3ds->mNum, a3ds->tNum, a3ds->a3d_materialList->next, FPOS( A3DS_MaterialList, next ), FPOS( A3DS_MaterialList, texture ), FPOS( Texture, name ) ); }