Ejemplo n.º 1
0
int SpriteBinder::removeChild(lua_State* L)
{
	StackChecker checker(L, "SpriteBinder::removeChild", 0);

	Binder binder(L);
	Sprite* sprite = static_cast<Sprite*>(binder.getInstance("Sprite", 1));
	Sprite* child = static_cast<Sprite*>(binder.getInstance("Sprite", 2));

	GStatus status;
	int index = sprite->getChildIndex(child, &status);
	if (status.error() == true)
		return luaL_error(L, status.errorString());

	lua_pushnil(L);
	lua_setfield(L, 2, "__parent");		// child.__parent = nil

	lua_getfield(L, 1, "__children");	// push sprite.__children
	lua_pushlightuserdata(L, child);
	lua_pushnil(L);
	lua_rawset(L, -3);					// sprite.__children[sprite] = nil
	lua_pop(L, 1);						// pop sprite.__children

	sprite->removeChild(index);

	return 0;
}
Ejemplo n.º 2
0
int TileMapBinder::getTile(lua_State* L)
{
    StackChecker checker(L, "TileMapBinder::getTile", 3);
	
	Binder binder(L);
	TileMap* tilemap = static_cast<TileMap*>(binder.getInstance("TileMap", 1));	 

	
	int x = luaL_checkinteger(L, 2) - 1;
	int y = luaL_checkinteger(L, 3) - 1;
    int tx, ty, flip;

	GStatus status;
    tilemap->get(x, y, &tx, &ty, &flip, &status);
	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}

	if (TileMap::isEmpty(tx, ty))
	{
		lua_pushnil(L);
		lua_pushnil(L);
        lua_pushnil(L);
	}
	else
	{
		lua_pushinteger(L, tx + 1);
        lua_pushinteger(L, ty + 1);
        lua_pushinteger(L, flip);
    }
	
    return 3;
}
Ejemplo n.º 3
0
int SpriteBinder::addChildAt(lua_State* L)
{
	StackChecker checker(L, "SpriteBinder::addChildAt", 0);

	Binder binder(L);
	Sprite* sprite = static_cast<Sprite*>(binder.getInstance("Sprite", 1));
	Sprite* child = static_cast<Sprite*>(binder.getInstance("Sprite", 2));
	int index = luaL_checkinteger(L, 3);

	GStatus status;
    if (sprite->canChildBeAddedAt(child, index - 1, &status) == false)
		return luaL_error(L, status.errorString());

	if (child->parent() == sprite)
	{
        sprite->addChildAt(child, index - 1);
		return 0;
	}

	if (child->parent())
	{
		// remove from parent's __children table
		lua_getfield(L, 2, "__parent");			// push child.__parent
		lua_getfield(L, -1, "__children");		// push child.__parent.__children

		lua_pushlightuserdata(L, child);
		lua_pushnil(L);
		lua_rawset(L, -3);						// child.__parent.__children[child] = nil

		lua_pop(L, 2);							// pop child.__parent and child.__parent.__children
	}

	// set new parent
	lua_pushvalue(L, 1);
	lua_setfield(L, 2, "__parent");				// child.__parent = sprite

	createChildrenTable(L);

	// add to __children table
	lua_getfield(L, 1, "__children");			// push sprite.__children
	lua_pushlightuserdata(L, child);
	lua_pushvalue(L, 2);
	lua_rawset(L, -3);							// sprite.__children[child] = child
	lua_pop(L, 1);								// pop sprite.__children

    sprite->addChildAt(child, index - 1);

	return 0;
}
Ejemplo n.º 4
0
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());
}
Ejemplo n.º 5
0
int TileMapBinder::clearTile(lua_State* L)
{
	StackChecker checker(L, "TileMapBinder::clearTile", 0);

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

	int x = luaL_checkinteger(L, 2) - 1;
	int y = luaL_checkinteger(L, 3) - 1;

	GStatus status;
    tilemap->set(x, y, TileMap::EMPTY_TILE, TileMap::EMPTY_TILE, 0, &status);
	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}

	return 0;
}
Ejemplo n.º 6
0
int SpriteBinder::set(lua_State* L)
{
	StackChecker checker(L, "SpriteBinder::set", 0);

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

	const char* param = luaL_checkstring(L, 2);
	lua_Number value = luaL_checknumber(L, 3);

	GStatus status;
	sprite->set(param, value, &status);

	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}

	return 0;
}
Ejemplo n.º 7
0
int SpriteBinder::get(lua_State* L)
{
	StackChecker checker(L, "SpriteBinder::get", 1);

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

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

	GStatus status;
	float value = sprite->get(param, &status);

	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}

	lua_pushnumber(L, value);

	return 1;
}
Ejemplo n.º 8
0
int SpriteBinder::getChildIndex(lua_State* L)
{
	StackChecker checker(L, "SpriteBinder::getChildIndex", 1);

	Binder binder(L);
	Sprite* sprite = static_cast<Sprite*>(binder.getInstance("Sprite", 1));
	Sprite* child = static_cast<Sprite*>(binder.getInstance("Sprite", 2));


	GStatus status;
	int index = sprite->getChildIndex(child, &status);

	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}

	lua_pushinteger(L, index + 1);

	return 1;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
int TileMapBinder::setTile(lua_State* L)
{
	StackChecker checker(L, "TileMapBinder::setTile", 0);
	
	Binder binder(L);
	TileMap* tilemap = static_cast<TileMap*>(binder.getInstance("TileMap", 1));	
	
	int x = luaL_checkinteger(L, 2) - 1;
	int y = luaL_checkinteger(L, 3) - 1;
	int tx = luaL_checkinteger(L, 4) - 1;
	int ty = luaL_checkinteger(L, 5) - 1;
    int flip = luaL_optinteger(L, 6, 0);


	GStatus status;
    tilemap->set(x, y, tx, ty, flip, &status);
	if (status.error() == true)
	{
		luaL_error(L, status.errorString());
		return 0;
	}	
	
	return 0;
}
Ejemplo n.º 11
0
void ApplicationManager::drawFrame() {
	if (networkManager_)
		networkManager_->tick();

	// if we're in app mode, skip the first 10 frames as black screen
	// because a pattern like surfaceChanged(a,b), drawFrame, drawFrame, drawFrame, ..., surfaceChanged(b,a) is possible
	// and we want to execute lua files after getting the final device resolution
	if (player_ == false) {
		if (nframe_++ < 10) {
			glClearColor(0, 0, 0, 1);
			glClear (GL_COLOR_BUFFER_BIT);

			return;
		}
	}

	if (player_ == false) {
		if (applicationStarted_ == false) {
			if (!appName.empty())
				play(appName.c_str());
			else
			{
				loadProperties();
				loadLuaFiles();
			}
			skipFirstEnterFrame_ = true;

			/*
			 bool licensed = (licenseKey_[15] == 'f' && licenseKey_[16] == 'f');
			 if (licensed)
			 {
			 loadLuaFiles();
			 skipFirstEnterFrame_ = true;
			 }
			 else
			 {
			 application_->getApplication()->setBackgroundColor(0, 0, 0);
			 splashScreen_ = new SplashScreen(application_->getApplication());
			 application_->getApplication()->stage()->addChild(splashScreen_);
			 splashScreen_->unref();
			 }
			 */

			applicationStarted_ = true;
		}

		/*		if (splashScreen_ && splashScreen_->isFinished())
		 {
		 application_->getApplication()->stage()->removeChild(splashScreen_);
		 splashScreen_ = NULL;
		 application_->getApplication()->setBackgroundColor(1, 1, 1);

		 loadLuaFiles();
		 skipFirstEnterFrame_ = true;
		 }*/
	}

	if (skipFirstEnterFrame_ == true) {
		skipFirstEnterFrame_ = false;
	} else {
		GStatus status;
		application_->enterFrame(&status);
		if (status.error())
			luaError(status.errorString());
          gaudio_AdvanceStreamBuffers();		  
	}

	application_->clearBuffers();
	application_->renderScene(1);
	drawIPs();
}