예제 #1
0
int TileMapBinder::create(lua_State* L)
{
	StackChecker checker(L, "TileMapBinder::create", 1);
	
	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	Binder binder(L);
	
	int width = luaL_checkinteger(L, 1);
	int height = luaL_checkinteger(L, 2);
	GTextureBase* texturebase = static_cast<GTextureBase*>(binder.getInstance("TextureBase", 3));	
	int tilewidth = luaL_checkinteger(L, 4);
	int tileheight = luaL_checkinteger(L, 5);
	int spacingx = luaL_optinteger(L, 6, 0);
	int spacingy = luaL_optinteger(L, 7, 0);
	int marginx = luaL_optinteger(L, 8, 0);
	int marginy = luaL_optinteger(L, 9, 0);
	int displaywidth = luaL_optinteger(L, 10, tilewidth);
	int displayheight = luaL_optinteger(L, 11, tileheight);

	TileMap* tilemap = new TileMap(application->getApplication(),
								   width, height,
								   texturebase,
								   tilewidth, tileheight,
								   spacingx, spacingy,
								   marginx, marginy,
								   displaywidth, displayheight);
	binder.pushInstance("TileMap", tilemap);
		
	return 1;
}
예제 #2
0
int EventDispatcherBinder::dispatchEvent(lua_State* L)
{
	StackChecker checker(L, "EventDispatcherBinder::dispatchEvent", 0);

	Binder binder(L);
	EventDispatcher* eventDispatcher = static_cast<EventDispatcher*>(binder.getInstance("EventDispatcher", 1));

	luaL_checktype(L, 2, LUA_TTABLE);
//	lua_getfield(L, 2, "type");
	lua_getfield(L, 2, "getType");
	lua_pushvalue(L, 2);
	lua_call(L, 1, 1);
	std::string event = luaL_checkstring(L, -1);
	lua_pop(L, 1);
	LuaEvent e = LuaEvent(LuaEvent::Type(event.c_str()));

    LuaApplication *application = (LuaApplication*)luaL_getdata(L);
    lua_State *mainL = application->getLuaState();

    lua_pushvalue(L, 2);    // push event to main thread
    if (mainL != L)
        lua_xmove(L, mainL, 1);

    eventDispatcher->dispatchEvent(&e);

    lua_pop(mainL, 1);      // pop event from main thread

	return 0;
}
예제 #3
0
int ApplicationBinder::setOrientation(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	const char* orientation = luaL_checkstring(L, 2);

	if (strcmp(orientation, PORTRAIT) == 0)
	{
		application->getApplication()->setOrientation(ePortrait);
	}
	else if (strcmp(orientation, PORTRAIT_UPSIDE_DOWN) == 0)
	{
		application->getApplication()->setOrientation(ePortraitUpsideDown);
	}
	else if (strcmp(orientation, LANDSCAPE_LEFT) == 0)
	{
		application->getApplication()->setOrientation(eLandscapeLeft);
	}
	else if (strcmp(orientation, LANDSCAPE_RIGHT) == 0)
	{
		application->getApplication()->setOrientation(eLandscapeRight);
	}
	else
	{
		GStatus status(2008, "orientation");	// Parameter %s must be one of the accepted values.
		return luaL_error(L, status.errorString());
	}

	return 0;
}
예제 #4
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::luaError(const char *error)
{
	glog_e("%s", error);

	if (player_ == true)
	{
		running_ = false;

		networkManager_->printToServer(error, -1);
		networkManager_->printToServer("\n", -1);
		application_->deinitialize();
		application_->initialize();	
	}
	else
	{
		JNIEnv *env = g_getJNIEnv();
		jstring jerrormsg = env->NewStringUTF(error);
		jclass localRefCls = env->FindClass("com/giderosmobile/android/player/GiderosApplication");
		jmethodID throwError = env->GetStaticMethodID(localRefCls, "throwLuaException", "(Ljava/lang/String;)V");
		env->CallStaticVoidMethod(localRefCls, throwError, jerrormsg);
		env->DeleteLocalRef(jerrormsg);
		env->DeleteLocalRef(localRefCls);
		//g_exit();
	}
}
예제 #5
0
int ApplicationBinder::getDeviceOrientation(lua_State *L)
{
    Binder binder(L);
    (void)binder.getInstance("Application", 1);

    LuaApplication *application = static_cast<LuaApplication*>(luaL_getdata(L));

    switch (application->getApplication()->getDeviceOrientation())
    {
    case ePortrait:
        lua_pushstring(L, PORTRAIT);
        break;
    case ePortraitUpsideDown:
        lua_pushstring(L, PORTRAIT_UPSIDE_DOWN);
        break;
    case eLandscapeLeft:
        lua_pushstring(L, LANDSCAPE_LEFT);
        break;
    case eLandscapeRight:
        lua_pushstring(L, LANDSCAPE_RIGHT);
        break;
    }

    return 1;
}
예제 #6
0
int ApplicationBinder::isPlayerMode(lua_State* L)
{
    Binder binder(L);
    (void)binder.getInstance("Application", 1);
    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));
    lua_pushboolean(L, application->isPlayerMode());
    return 1;
}
예제 #7
0
int ApplicationBinder::getLogicalScaleY(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	lua_pushnumber(L, application->getLogicalScaleY());

	return 1;
}
예제 #8
0
int ApplicationBinder::getDeviceHeight(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	lua_pushnumber(L, application->getHardwareHeight());

	return 1;
}
예제 #9
0
int MeshBinder::create(lua_State *L)
{
    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    bool is3d = lua_toboolean(L, 1);

    Binder binder(L);

    binder.pushInstance("Mesh", new GMesh(application->getApplication(),is3d));

    return 1;
}
예제 #10
0
int ViewportBinder::create(lua_State* L)
{
	StackChecker checker(L, "ViewportBinder::create", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    Binder binder(L);

    Viewport* shape = new Viewport(application->getApplication());
	binder.pushInstance("Viewport", shape);

	return 1;
}
예제 #11
0
int ShapeBinder::create(lua_State* L)
{
	StackChecker checker(L, "ShapeBinder::create", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    Binder binder(L);

    Shape* shape = new Shape(application->getApplication());
	binder.pushInstance("Shape", shape);

	return 1;
}
예제 #12
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::updateHardwareOrientation()
{
    Orientation orientation = application_->orientation();

    bool b1 = orientation == ePortrait || orientation == ePortraitUpsideDown;
    bool b2 = deviceOrientation_ == ePortrait || deviceOrientation_ == ePortraitUpsideDown;

    if (b1 != b2)
        hardwareOrientation_ = deviceOrientation_;
    else
        hardwareOrientation_ = orientation;

    application_->setHardwareOrientation(hardwareOrientation_);	
}
예제 #13
0
int RenderTargetBinder::create(lua_State *L)
{
    LuaApplication *application = static_cast<LuaApplication*>(luaL_getdata(L));

    Binder binder(L);

    int width = luaL_checkinteger(L, 1);
    int height = luaL_checkinteger(L, 2);
    bool smoothing = lua_toboolean(L, 3);

    binder.pushInstance("RenderTarget", new GRenderTarget(application->getApplication(), width, height, smoothing ? eLinear : eNearest));

    return 1;
}
예제 #14
0
int ApplicationBinder::setLogicalDimensions(lua_State* L)
{
    Binder binder(L);
    (void)binder.getInstance("Application", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    int width = luaL_checkinteger(L, 2);
    int height = luaL_checkinteger(L, 3);

    application->getApplication()->setLogicalDimensions(width, height);

    return 0;
}
예제 #15
0
int ApplicationBinder::getContentHeight(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	Orientation orientation = application->orientation();

	if (orientation == eLandscapeLeft || orientation == eLandscapeRight)
		lua_pushnumber(L, application->getLogicalWidth());
	else
		lua_pushnumber(L, application->getLogicalHeight());

	return 1;
}
예제 #16
0
int DibBinder::create(lua_State* L)
{
	StackChecker checker(L, "DibBinder::create", 1);

	LuaApplication* luaapplication = static_cast<LuaApplication*>(luaL_getdata(L));
	Application* application = luaapplication->getApplication();

	const char* filename = luaL_checkstring(L, 1);
	
	Binder binder(L);

    Dib* dib = new Dib(application, filename, false, false, false, 0x00000000);
	binder.pushInstance("Dib", dib);

	return 1;
}
예제 #17
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::loadLuaFiles()
{
	std::vector<std::string> luafiles;

	G_FILE* fis = g_fopen("luafiles.txt", "rt");

	if (fis)
	{
		char line[1024];
		while (true)
		{
			if (g_fgets(line, 1024, fis) == NULL)
				break;
				
			size_t len = strlen(line);
			
			if (len > 0 && line[len - 1] == 0xa)
				line[--len] = 0;

			if (len > 0 && line[len - 1] == 0xd)
				line[--len] = 0;
			
			if (len > 0)
				luafiles.push_back(line);
		}

		g_fclose(fis);
	}
	
	GStatus status;
	for (size_t i = 0; i < luafiles.size(); ++i)
	{
		application_->loadFile(luafiles[i].c_str(), &status);
		if (status.error())
			break;
	}

	if (!status.error())
	{
		gapplication_enqueueEvent(GAPPLICATION_START_EVENT, NULL, 0);
		application_->tick(&status);
	}

	if (status.error())
        luaError(status.errorString());
}
예제 #18
0
int ApplicationBinder::setBackgroundColor(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	unsigned int color = luaL_checkinteger(L, 2);

	int r = (color >> 16) & 0xff;
	int g = (color >> 8) & 0xff;
	int b = color& 0xff;

	application->getApplication()->setBackgroundColor(r/255.f, g/255.f, b/255.f);

	return 0;
}
예제 #19
0
int ApplicationBinder::getBackgroundColor(lua_State* L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	float r, g, b;
	application->getApplication()->getBackgroundColor(&r, &g, &b);

	int ir = std::min((int)(r * 256), 255);
	int ig = std::min((int)(g * 256), 255);
	int ib = std::min((int)(b * 256), 255);

	lua_pushinteger(L, (ir << 16) | (ig << 8) | ib);

	return 1;
}
예제 #20
0
int ApplicationBinder::configureFrustum(lua_State* L)
{
    Binder binder(L);
    (void)binder.getInstance("Application", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    lua_Number fov = luaL_checknumber(L, 2);
    if (fov<0) fov=0;
    if (fov>180) fov=180;

    lua_Number farplane=0;
    if (!lua_isnoneornil(L, 3))
    	farplane = luaL_checknumber(L, 3);
    application->getApplication()->configureFrustum(fov,farplane);

    return 0;
}
예제 #21
0
int ApplicationBinder::setScaleMode(lua_State *L)
{
	Binder binder(L);
	(void)binder.getInstance("Application", 1);

	LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    const char* scaleMode = luaL_checkstring(L, 2);

    if (strcmp(scaleMode, NO_SCALE) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eNoScale);
    }
    else if (strcmp(scaleMode, CENTER) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eCenter);
    }
    else if (strcmp(scaleMode, PIXEL_PERFECT) == 0)
	{
        application->getApplication()->setLogicalScaleMode(ePixelPerfect);
    }
    else if (strcmp(scaleMode, LETTERBOX) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eLetterBox);
    }
    else if (strcmp(scaleMode, CROP) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eCrop);
    }
    else if (strcmp(scaleMode, STRETCH) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eStretch);
    }
    else if (strcmp(scaleMode, FIT_WIDTH) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eFitWidth);
    }
    else if (strcmp(scaleMode, FIT_HEIGHT) == 0)
	{
        application->getApplication()->setLogicalScaleMode(eFitHeight);
    }
	else
	{
        GStatus status(2008, "scaleMode");	// Parameter %s must be one of the accepted values.
        return luaL_error(L, status.errorString());
	}

	return 0;
}
예제 #22
0
int SpriteBinder::create(lua_State* L)
{
	StackChecker checker(L, "Sprite", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

	Binder binder(L);
    Sprite* sprite = new Sprite(application->getApplication());
	binder.pushInstance("Sprite", sprite);

/*	lua_getglobal(L, "Graphics");
	lua_getfield(L, -1, "new");
	lua_remove(L, -2);
	lua_pushvalue(L, -2);
	lua_call(L, 1, 1);
	lua_setfield(L, -2, "graphics"); // sprite.graphics = Graphics.new(sprite)
	*/

	return 1;
}
예제 #23
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::surfaceChanged(int width, int height, int rotation)
{
	if (player_ == true)
		refreshLocalIPs();

	if (width > height)
	{
		width_ = height;
		height_ = width;
	}
	else
	{
		width_ = width;
		height_ = height;
	}
	
	application_->setResolution(width_, height_);
	
	switch (rotation)
	{
	case 0:
		deviceOrientation_ = ePortrait;
		break;
	case 90:
		deviceOrientation_ = eLandscapeLeft;
		break;
	case 180:
		deviceOrientation_ = ePortraitUpsideDown;
		break;
	case 270:
		deviceOrientation_ = eLandscapeRight;
		break;
	default:
		deviceOrientation_ = ePortrait;
		break;
	}
	
	application_->getApplication()->setDeviceOrientation(deviceOrientation_);
	
	updateHardwareOrientation();
}
예제 #24
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::surfaceCreated()
{
	if (!init_)
	{
		init_ = true;
		application_->initialize();
	}
	else
	{
		gtexture_reloadTextures();
		gtexture_RestoreRenderTargets();
		gtexture_RestoreTempTextures();
	}
}
예제 #25
0
int PixelBinder::create(lua_State* L)
{
	StackChecker checker(L, "PixelBinder::create", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    Binder binder(L);

    Pixel* bitmap = new Pixel(application->getApplication());
	unsigned int color = luaL_optinteger(L, 1, 0);
	lua_Number alpha = luaL_optnumber(L, 2, 1.0);
	lua_Number w = luaL_optnumber(L, 3, 1.0);
	lua_Number h = luaL_optnumber(L, 4, w);
	int r = (color >> 16) & 0xff;
	int g = (color >> 8) & 0xff;
	int b = color & 0xff;

	bitmap->setColor(r/255.f,g/255.f,b/255.f,alpha);
	bitmap->setDimensions(w,h);

	binder.pushInstance("Pixel", bitmap);
	return 1;
}
예제 #26
0
int ApplicationBinder::getScaleMode(lua_State* L)
{
    Binder binder(L);
    (void)binder.getInstance("Application", 1);

    LuaApplication* application = static_cast<LuaApplication*>(luaL_getdata(L));

    switch (application->getApplication()->getLogicalScaleMode())
    {
    case eNoScale:
        lua_pushstring(L, NO_SCALE);
        break;
    case eCenter:
        lua_pushstring(L, CENTER);
        break;
    case ePixelPerfect:
        lua_pushstring(L, PIXEL_PERFECT);
        break;
    case eLetterBox:
        lua_pushstring(L, LETTERBOX);
        break;
    case eCrop:
        lua_pushstring(L, CROP);
        break;
    case eStretch:
        lua_pushstring(L, STRETCH);
        break;
    case eFitWidth:
        lua_pushstring(L, FIT_WIDTH);
        break;
    case eFitHeight:
        lua_pushstring(L, FIT_HEIGHT);
        break;
    }

    return 1;
}
예제 #27
0
int FontBinder::create(lua_State* L)
{
	StackChecker checker(L, "FontBinder::create", 1);

	LuaApplication* luaapplication = static_cast<LuaApplication*>(luaL_getdata(L));
	Application* application = luaapplication->getApplication();

	const char* glympfile = luaL_checkstring(L, 1);
	const char* imagefile = luaL_checkstring(L, 2);
	bool smoothing = lua_toboolean(L, 3) != 0;

	Binder binder(L);
	
    GStatus status;
    Font *font = new Font(application, glympfile, imagefile, smoothing, &status);
    if (status.error())
    {
        delete font;
        return luaL_error(L, status.errorString());
	}

	binder.pushInstance("Font", font);
	return 1;
}
예제 #28
0
static int enterFrame(lua_State* L)
{
    StackChecker checker(L, "enterFrame", 0);

    LuaApplication *luaApplication = static_cast<LuaApplication*>(luaL_getdata(L));
    Application *application = luaApplication->getApplication();

	setEnvironTable(L);

	luaL_rawgetptr(L, LUA_REGISTRYINDEX, &key_events);
	luaL_nullifytable(L, -1);
	lua_pop(L, 1);

    gevent_Tick();

    PluginManager& pluginManager = PluginManager::instance();
    for (size_t i = 0; i < pluginManager.plugins.size(); ++i)
        if (pluginManager.plugins[i].enterFrame)
            pluginManager.plugins[i].enterFrame(L);

    application->enterFrame();

	return 0;
}
예제 #29
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::loadProperties()
{
	G_FILE* fis = g_fopen("properties.bin", "rb");

	g_fseek(fis, 0, SEEK_END);
	int len = g_ftell(fis);
	g_fseek(fis, 0, SEEK_SET);

	std::vector<char> buf(len);
	g_fread(&buf[0], 1, len, fis);
	g_fclose(fis);

	ByteBuffer buffer(&buf[0], buf.size());

	buffer >> properties_.scaleMode;
	buffer >> properties_.logicalWidth;
	buffer >> properties_.logicalHeight;
	
	int scaleCount;
	buffer >> scaleCount;
	properties_.imageScales.resize(scaleCount);
	for (int i = 0; i < scaleCount; ++i)
	{
		buffer >> properties_.imageScales[i].first;
		buffer >> properties_.imageScales[i].second;
	}
	
	buffer >> properties_.orientation;
	buffer >> properties_.fps;
	buffer >> properties_.retinaDisplay;
	buffer >> properties_.autorotation;
	buffer >> properties_.mouseToTouch;
	buffer >> properties_.touchToMouse;
	buffer >> properties_.mouseTouchOrder;

	
	application_->setResolution(width_, height_);
	application_->setOrientation((Orientation)properties_.orientation);
	updateHardwareOrientation();
	application_->getApplication()->setDeviceOrientation(deviceOrientation_);
	application_->setLogicalDimensions(properties_.logicalWidth, properties_.logicalHeight);
	application_->setLogicalScaleMode((LogicalScaleMode)properties_.scaleMode);
	application_->setImageScales(properties_.imageScales);

	g_setFps(properties_.fps);
	
	ginput_setMouseToTouchEnabled(properties_.mouseToTouch);
	ginput_setTouchToMouseEnabled(properties_.touchToMouse);
	ginput_setMouseTouchOrder(properties_.mouseTouchOrder);
}
예제 #30
0
int TextureBinder::create(lua_State* L)
{
	StackChecker checker(L, "TextureBinder::create", 1);

	LuaApplication* luaapplication = static_cast<LuaApplication*>(luaL_getdata(L));
	Application* application = luaapplication->getApplication();

	const char* filename = luaL_checkstring(L, 1);

	bool smoothing = lua_toboolean(L, 2);

	bool maketransparent = false;
	unsigned int transparentcolor = 0x00000000;
    Wrap wrap = eClamp;
    Format format = eRGBA8888;
	if (!lua_isnoneornil(L, 3))
	{
		if (lua_type(L, 3) != LUA_TTABLE)
			return luaL_typerror(L, 3, "table");

		lua_getfield(L, 3, "transparentColor");
		if (!lua_isnil(L, -1))
		{
			maketransparent = true;
			transparentcolor = luaL_checkinteger(L, -1);
		}
		lua_pop(L, 1);

        lua_getfield(L, 3, "wrap");
        if (!lua_isnil(L, -1))
        {
            const char *wrapstr = luaL_checkstring(L, -1);
            if (strcmp(wrapstr, "clamp") == 0)
                wrap = eClamp;
            else if (strcmp(wrapstr, "repeat") == 0)
                wrap = eRepeat;
            else
            {
                GStatus status(2008, "wrap");		// Error #2008: Parameter %s must be one of the accepted values.
                luaL_error(L, status.errorString());
            }
        }
        lua_pop(L, 1);

        lua_getfield(L, 3, "format");
        if (!lua_isnil(L, -1))
        {
            const char *formatstr = luaL_checkstring(L, -1);
            if (strcmp(formatstr, "rgba8888") == 0)
                format = eRGBA8888;
            else if (strcmp(formatstr, "rgb888") == 0)
                format = eRGB888;
            else if (strcmp(formatstr, "rgb565") == 0)
                format = eRGB565;
            else if (strcmp(formatstr, "rgba4444") == 0)
                format = eRGBA4444;
            else if (strcmp(formatstr, "rgba5551") == 0)
                format = eRGBA5551;
            else
            {
                GStatus status(2008, "format");		// Error #2008: Parameter %s must be one of the accepted values.
                luaL_error(L, status.errorString());
            }
        }
        lua_pop(L, 1);
    }

	
	Binder binder(L);

	Texture* texture = 0;
	try
	{
        texture = new Texture(application, filename, smoothing ? eLinear : eNearest, wrap, format, maketransparent, transparentcolor);
	}
	catch (const GiderosException& e)
	{
		return luaL_error(L, e.what());
	}

	binder.pushInstance("Texture", texture);
	return 1;
}