Exemplo n.º 1
0
CzActor* CzApp::FindTappedActor(int x, int y)
{
	CzActor* hit_actor = NULL;
	CzScene* hit = NULL;
	for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
	{
		if ((CurrentScene == *it || (*it)->getAllowFocus()) && (*it)->isActive())
		{
			if (hit == NULL || (hit->getLayer() <= (*it)->getLayer()))
			{
				if (!(*it)->isDragging())
				{
					CzActor* tapped_actor = (*it)->FindTappedActor(x, y);
					CzScene* new_hit = *it;
					if (tapped_actor != NULL)
					{
						hit_actor = tapped_actor;
						hit = *it;
					}
				}
			}
		}
	}

	return hit_actor;
}
Exemplo n.º 2
0
//
// LUA_CleanupScene scene (object)
//
static int LUA_CleanupScene(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (count < 1)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.cleanup() not enough parameters, expected scene (object)");
		lua_pushboolean(lua, false);
		return 1;
	}

	// Get scene
	CzScene* scene = NULL;
	if (lua_isuserdata(lua, 1))
		scene = (CzScene*)lua_touserdata(lua, 1);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.cleanup() invalid scene (Param0), expected scene");
		lua_pushboolean(lua, false);
		return 1;
	}

	scene->CleanupRemovedActors();

	lua_pushboolean(lua, true);
	return 1;
}
Exemplo n.º 3
0
//
// LUA_SetCurrentScene(scene-name (string)) - returns previous scene
//
static int LUA_SetCurrentScene(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (lua_gettop(lua) < 1)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.setCurrent() not enough parameters, expected scene (object)");
		lua_pushnil(lua);
		return 1;
	}

	// Get the main game object
	CzApp* game = (CzApp*)CZ_GLOBAL_RESOURCES->getResourceManager()->getParent();

	// Get the scene
	CzScene* scene = NULL;
	if (lua_isuserdata(lua, 1))
		scene = (CzScene*)lua_touserdata(lua, 1);
	if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.setCurrent() Invalid scene for Param0");
		lua_pushnil(lua);
		return 1;
	}

	CzScene* prev_scene = game->getCurrentScene();
	game->changeScene(scene);

	lua_pushlightuserdata(lua, prev_scene);

	return 1;
}
Exemplo n.º 4
0
int CzProgram::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node)
{
	CzScene* scene = NULL;
	if (parent->getClassTypeHash() == CzHashes::Actor_Hash)
	{
		CzActor* actor = (CzActor*)parent;
		scene = actor->getScene();
	}
	else
	if (parent->getClassTypeHash() == CzHashes::Scene_Hash)
		scene = (CzScene*)parent;

	bool auto_run = false;
	bool priority = false;

	// Process program attributes
	for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++)
	{
		unsigned int name_hash = (*it)->getName().getHash();

		if (name_hash == CzHashes::Name_Hash)
			setName((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Tag_Hash)
			setTag((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::AutoRun_Hash)
			auto_run = (*it)->getValueAsBool();
		else
		if (name_hash == CzHashes::Priority_Hash)
			priority = (*it)->getValueAsBool();
	}

	// Prrocess commands
	ProcessCommands(NULL, true, node);

/*	// If we are declared inside a scene then program is local to the scene
	if (scene != NULL)
		scene->getResourceManager()->addResource(this);
	else
		CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this);*/

	// Add the program to a program manager
	if (scene != NULL)
		scene->getProgramManager()->addProgram(this);
	else
		CZ_GLOBAL_RESOURCES->getProgramManager()->addProgram(this);

	// if auto_run then start the program running
	if (auto_run)
		start();

	// If set as priority program then inform manager
	if (priority)
		Manager->setPriorityProgram(this);

	return 1;
}
Exemplo n.º 5
0
//
// LUA_MarketSetCallback(callback (function))
//
static int LUA_MarketSetCallback(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (count < 1)
	{
		CzScriptEngineLua::DisplayError(lua, "market.setCallback() not enough parameters, expected callback (function)");
		lua_pushboolean(lua, false);
		return 1;
	}

	if (PLATFORM_MARKET->getActiveMarket() == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Market has not been created");
		lua_pushboolean(lua, false);
		return 1;
	}

	if (PLATFORM_MARKET->getActiveMarket()->isBusy())
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Market is busy");
		lua_pushboolean(lua, false);
		return 1;
	}

	// Get the callback
	void* callback = NULL;
	if (lua_isfunction(lua, 1))
		callback = (void*)lua_topointer(lua, 1);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "market.purchase() Invalid callback, expected function for Param0");
		lua_pushboolean(lua, false);
		return 1;
	}

	// If previous callback ref set then free it
	CzScriptCallback& cb = PLATFORM_MARKET->getActiveMarket()->getScriptCallback();
	if (cb.Valid)
		lua_unref(((CzScriptEngineLua*)cb.ScriptEngine)->getState(), cb.FunctionRef);

	// Generate a new callback reference to callback function
	int callback_index = luaL_ref(lua, LUA_REGISTRYINDEX);
	cb.FunctionRef = callback_index;
	CzScene* container = (CzScene*)lua->user_data;
	if (container == NULL)
		cb.ScriptEngine = CZ_GLOBAL_RESOURCES->getScriptEngine();
	else
		cb.ScriptEngine = container->getScriptEngine();
	cb.Valid = true;

	lua_pushboolean(lua, true);

	return 1;
}
Exemplo n.º 6
0
//
// LUA_SceneToScreen scene (object) x (number) y (number) - Returns vector
//
static int LUA_SceneToScreen(lua_State *lua)
{
	if (lua_gettop(lua) < 3)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScreen() not enough parameters, expected scene (object) x (number) y (number)");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene object
	CzScene* scene = NULL;
	if (lua_isuserdata(lua, 1))
		scene = (CzScene*)lua_touserdata(lua, 1);
	if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScreen() Invalid scene object");
		lua_pushnil(lua);
		return 1;
	}

	// Get x coord
	float x = 0;
	if (lua_isnumber(lua, 2))
		x = (float)lua_tonumber(lua, 2);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScreen() expected a number for Param1");
		lua_pushnil(lua);
		return 1;
	}

	// Get y coord
	float y = 0;
	if (lua_isnumber(lua, 3))
		y = (float)lua_tonumber(lua, 3);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScreen() expected a number for Param2");
		lua_pushnil(lua);
		return 1;
	}

	CzVec2 screen = scene->VirtualToScreen(x, y);
	lua_pushvec(lua, screen.x, screen.y, 0, 0);
 
	return 1;
}
Exemplo n.º 7
0
//
// LUA_UpdateScenePhysics scene (object), time (number)
//
static int LUA_UpdateScenePhysics(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (count < 2)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() not enough parameters, expected scene (object), time (number)");
		lua_pushboolean(lua, false);
		return 1;
	}

	// Get scene
	CzScene* scene = NULL;
	if (lua_isuserdata(lua, 1))
		scene = (CzScene*)lua_touserdata(lua, 1);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() invalid scene (Param0), expected scene");
		lua_pushboolean(lua, false);
		return 1;
	}

	// Get time
	float time;
	if (lua_isnumber(lua, 2))
		time = (float)lua_tonumber(lua, 2);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.updatePhysics() Invalid time expected number for Param1");
		lua_pushboolean(lua, false);
		return 1;
	}

	scene->UpdatePhysics(time);

	lua_pushboolean(lua, true);
	return 1;
}
Exemplo n.º 8
0
int CzMarket::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node)
{
	// Process market attributes
	CzString* public_key = NULL;
	CzString* simulate = NULL;

	if (EventsManager == NULL)
		EventsManager = new CzEventManager();

	for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++)
	{
		unsigned int name_hash = (*it)->getName().getHash();

		if (name_hash == CzHashes::Name_Hash)
			setName((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Tag_Hash)
			setTag((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::OnError_Hash)
			EventsManager->addEvent("OnError", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnUnavailable_Hash)
			EventsManager->addEvent("OnUnavailable", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnComplete_Hash)
			EventsManager->addEvent("OnComplete", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnBillingDisabled_Hash)
			EventsManager->addEvent("OnBillingDisabled", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnRefund_Hash)
			EventsManager->addEvent("OnRefund", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::AndroidPublicKey_Hash)
			public_key = &(*it)->getValue();
		else
		if (name_hash == CzHashes::Simulate_Hash)
			simulate = &(*it)->getValue();
	}

	CzScene* scene = NULL;
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Scene_Hash)
		scene = (CzScene*)parent;

	Init(public_key->c_str());

	// Process products
	eCzDeviceType os = PLATFORM_SYS->getDeviceType();
	for (CzXmlNode::_Iterator it2 = node->begin(); it2 != node->end(); ++it2)
	{
		bool valid = false;
		CzMarketProduct* product = new CzMarketProduct();

		unsigned int name_hash = (*it2)->GetName().getHash();
		if (name_hash == CzHashes::Product_Hash)
		{
			for (CzXmlNode::_AttribIterator it = (*it2)->attribs_begin(); it != (*it2)->attribs_end(); ++it)
			{
				unsigned int attrib_hash = (*it)->getName().getHash();

				if (attrib_hash == CzHashes::Name_Hash)
				{
					// Search for the product
					CzMarketProduct* p = findProductByName((*it)->getValue().getHash());
					if (p == NULL)
					{
						product->Name = (*it)->getValue();
						valid = true;
					}
					else
					{
						CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Market - Product with this name already exists - ", (*it)->getValue().c_str(), DebugInfo.c_str());
						valid = false;
						break;
					}
				}
				else
				if (attrib_hash == CzHashes::iOSId_Hash)
				{
					if (os == CzDeviceType_iPhone || os == CzDeviceType_iPad)
						product->ProductID = (*it)->getValue();
				}
				else
				if (attrib_hash == CzHashes::AndroidId_Hash)
				{
					if (os == CzDeviceType_Android)
						product->ProductID = (*it)->getValue();
				}
				else
				if (attrib_hash == CzHashes::Consumable_Hash)
					product->Consumable = (*it)->getValueAsBool();
				else
				if (attrib_hash == CzHashes::Price_Hash)
					product->Price = (*it)->getValueAsFloat();
			}
		}
		if (valid)
		{
			addProduct(product);
			product->Load();
		}
		else
			delete product;
	}

	if (simulate != NULL)
		PLATFORM_MARKET->setSimulation(simulate->getHash());

	if (scene != NULL)
		return scene->getResourceManager()->addResource(this) ? 1 : 0;
	else
		return CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this) ? 1 : 0;

	return 1;
}
Exemplo n.º 9
0
/**
 @fn	void CzXomlActions_Sys::Execute(IzXomlResource* source, CzAction* action)

 @brief	The main actions executor for system related actions. All system specific actions such as LoadXOML are implemented by this method

 @param [in]	source - The source of the action
 @param [in]	action - The action to execute
 */
void CzXomlActions_Sys::Execute(IzXomlResource* source, CzAction* action)
{
	if (source == NULL)
	{
#if defined(_DEBUG)
		CzDebug::Log(CZ_DEBUG_CHANNEL_ERROR, "Source was not found for action - ", action->_MethodName.c_str(), action->Parent->getDebugInfo().c_str());
#endif
		return;
	}

	// Determine the container
	CzApp* game;
	CzScene* scene;
	CzActor* actor;
	IzXomlResource* cont = IzXomlAction::getContainer(source, game, scene, actor);

	switch (Type)
	{
	case Action_LoadXOML:
		{
			if (!action->Params[0].isEmpty())
			{
				IzXomlResource* parent = NULL;
				if (!action->Params[1].isEmpty())
					parent = scene->getResourceManager()->findResource(action->getParameter2(cont).getHash(), CzHashes::Scene_Hash);
				if (parent == NULL)
					parent = game;
				CZ_XOML->Process(parent, action->getParameter1(cont).c_str());
			}
		}
		break;
	case Action_FromTemplate:
		{
			if (!action->Params[0].isEmpty())
			{
				if (!action->Params[2].isEmpty())
				{
					CzScene* target_scene = game->findScene(action->getParameter3(cont).getHash());
					CzXomlLoad::CreateInstance(scene, target_scene, &action->getParameter1(cont), &action->getParameter2(cont));
				}
				else
					CzXomlLoad::CreateInstance(scene, scene, &action->getParameter1(cont), &action->getParameter2(cont));
			}
		}
		break;
	case Action_Launch:
		{
			if (!action->Params[0].isEmpty())
				PLATFORM_SYS->ExecuteViaOS(action->getParameter1(cont).c_str(), false);
		}
		break;
	case Action_SetBGColour:
		{
			int components[8];
			if (action->getParameter1(cont).getAsListOfInt(components) == 4)
				game->SetBackgroundColour((uint8)components[0], (uint8)components[1], (uint8)components[2], (uint8)components[3]);
			else
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - SetBGColour - Incorrect component count - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_EnterValue:	// EnterValue Message To User, Variable to place value in
		{
			CzXomlVariable* var = CzXomlVariable::GetVariable(action->Params[1], scene);
			if (var != NULL)
			{
				const char* str = CZ_INPUT->showOnScreenKeyboard(action->getParameter1(cont).c_str(), 0, (action->getParameter3(cont) == "0") ? NULL : var->getValue().c_str());
				if (str != NULL)
					var->setValue(str);
			}
			else
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - Enter Value - Target variable not found - ", action->getParameter2(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_Exit:				// Exits the app
		PLATFORM_SYS->RequestQuit();
		break;
	case Action_DebugText:
		{
			CzDebug::Log(CZ_DEBUG_CHANNEL_NONE, action->getParameter1(cont).c_str(), action->getParameter2(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_LoadFile:	// File, blocking, filename (optional), scene (optional)
		{
			IzXomlResource* parent = NULL;
			if (!action->Params[3].isEmpty())
				scene = game->findScene(action->getParameter4(cont).getHash());
			if (!action->Params[0].isEmpty())
			{
				if (scene == NULL)
					CzDebug::Log(CZ_DEBUG_CHANNEL_ERROR, "Action - LoadFile - Scene is invalid - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
				else
				{
					CzDataFile* file = (CzDataFile*)scene->getResourceManager()->findResource(action->getParameter1(cont).getHash(), CzHashes::File_Hash);
					if (file != NULL)
					{
						if (!action->Params[2].isEmpty())
						{
							// New filename was supplied so load new file contents into file
							file->Init(action->getParameter3(cont).c_str(), true, action->getParameter2(cont).getAsBool());
						}
						else
							file->Load(action->getParameter2(cont).getAsBool());
					}
					else
						CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - LoadFile - File resource could not be found - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
				}
			}
		}
		break;
	case Action_PauseTime:				// Pauses / un-pauses app time
		game->setTimePaused(action->getParameter1(cont).getAsBool());
		break;
	}
}
Exemplo n.º 10
0
//
// LUA_ScreenToScene scene (object) x (number) y (number) include_camera (boolean) - Returns vector
//
static int LUA_ScreenToScene(lua_State *lua)
{
	if (lua_gettop(lua) < 3)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScene() not enough parameters, expected scene (object) x (number) y (number) include_camera (boolean)");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene object
	CzScene* scene = NULL;
	if (lua_isuserdata(lua, 1))
		scene = (CzScene*)lua_touserdata(lua, 1);
	if (scene == NULL || scene->getClassTypeHash() != CzHashes::Scene_Hash)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScene() Invalid scene object");
		lua_pushnil(lua);
		return 1;
	}

	// Get x coord
	float x = 0;
	if (lua_isnumber(lua, 2))
		x = (float)lua_tonumber(lua, 2);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a number for Param1");
		lua_pushnil(lua);
		return 1;
	}

	// Get y coord
	float y = 0;
	if (lua_isnumber(lua, 3))
		y = (float)lua_tonumber(lua, 3);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a number for Param2");
		lua_pushnil(lua);
		return 1;
	}

	// Get include camera parameter
	bool camera = false;
	if (lua_gettop(lua) > 3)
	{
		if (lua_isboolean(lua, 4))
			camera = lua_toboolean(lua, 4) != 0;
		else
		{
			CzScriptEngineLua::DisplayError(lua, "scene.toScene() expected a boolean for Param3");
			lua_pushnil(lua);
			return 1;
		}
	}

	CzVec2 s;
	if (camera)
		s = scene->ScreenToCamera(x, y);
	else
		s = scene->ScreenToVirtual(x, y);
	lua_pushvec(lua, s.x, s.y, 0, 0);
 
	return 1;
}
Exemplo n.º 11
0
//
// LUA_CreateScene scene-name (string), width (number), height (number), canvas_fit (string), origin (string), physics (boolean), batching (boolean), script-engine (string)
//
static int LUA_CreateScene(lua_State *lua)
{
	if (lua_gettop(lua) < 8)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() not enough parameters, scene-name (string), width (number), height (number), canvas_fit (string), origin (string), physics (boolean), batching (boolean), script-engine (string)");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene name
	const char* name = NULL;
	if (lua_isstring(lua, 1))
		name = lua_tostring(lua, 1);
	if (name == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid name for Param0, expected string");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene size
	int width, height;
	if (lua_isnumber(lua, 2))
		width = (int)lua_tonumber(lua, 2);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid width for Param1, expected number");
		lua_pushnil(lua);
		return 1;
	}
	if (lua_isnumber(lua, 3))
		height = (int)lua_tonumber(lua, 3);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid height for Param2, expected number");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene canvas fit
	const char* canvas_fit = NULL;
	if (lua_isstring(lua, 4))
		canvas_fit = lua_tostring(lua, 4);
	if (canvas_fit == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid canvas_fit for Param3, expected string");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene canvas origin
	const char* canvas_org = NULL;
	if (lua_isstring(lua, 5))
		canvas_org = lua_tostring(lua, 5);
	if (canvas_org == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid canvas_fit for Param4, expected string");
		lua_pushnil(lua);
		return 1;
	}

	unsigned int canvas_fit_hash = CZ_HASH(canvas_fit);
	unsigned int canvas_org_hash = CZ_HASH(canvas_org);
	CzScene::eCanvasFit fit = CzScene::Fit_None;
	if (canvas_fit_hash == CZ_HASH("width"))
		fit = CzScene::Fit_Width;
	else
	if (canvas_fit_hash == CZ_HASH("height"))
		fit = CzScene::Fit_Height;
	else
	if (canvas_fit_hash == CZ_HASH("both"))
		fit = CzScene::Fit_Both;
	else
	if (canvas_fit_hash == CZ_HASH("best"))
		fit = CzScene::Fit_Best;
	CzScene::eCanvasOrigin org = CzScene::Origin_Centre;
	if (canvas_org_hash == CZ_HASH("top"))
		org = CzScene::Origin_Top;
	else
	if (canvas_org_hash == CZ_HASH("left"))
		org = CzScene::Origin_Left;
	else
	if (canvas_org_hash == CZ_HASH("topleft"))
		org = CzScene::Origin_TopLeft;

	// Get the scene physics / batching
	bool physics = false, batching = false;
	if (lua_isboolean(lua, 6))
		physics = lua_toboolean(lua, 6) != 0;
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid physics for Param5, expected boolean");
		lua_pushnil(lua);
		return 1;
	}
	if (lua_isboolean(lua, 7))
		batching = lua_toboolean(lua, 7) != 0;
	else
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid batching for Param6, expected boolean");
		lua_pushnil(lua);
		return 1;
	}

	// Get the scene script engine
	const char* script_engine = NULL;
	if (lua_isstring(lua, 8))
		script_engine = lua_tostring(lua, 8);
	if (script_engine == NULL)
	{
		CzScriptEngineLua::DisplayError(lua, "scene.create() Invalid script-engine for Param7, expected string");
		lua_pushnil(lua);
		return 1;
	}

	CzScene* scene = new CzScene();
	scene->setName(name);
	scene->Init();
	scene->setBatching(batching);
	scene->setVirtualTransform(width, height, 0, fit, org);

	// Create script engine
	CzString se = script_engine;
	if (script_engine != NULL)
		scene->setScriptEngine(se);

	// Add scene to game
	CzApp* game = (CzApp*)CZ_GLOBAL_RESOURCES->getResourceManager()->getParent();
	game->addScene(scene, false);

	// Return the scene
	lua_pushlightuserdata(lua, scene);

	return 1;
}
Exemplo n.º 12
0
void CzApp::Draw()
{
	PLATFORM_RENDER->Begin();
#if defined(CZ_ENABLE_METRICS)
	CzMetrics::TotalSpritesProcessed = 0;
	CzMetrics::TotalActorsProcessed = 0;
#endif

	// Calculate max layers, also draw any scenes that have negative layers
	int max_layers = 0;
	for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
	{
		CzScene* s = *it;
		if (!s->isDestroyed())
		{
			int layer = s->getLayer();
			if (layer < 0)
				s->Draw();
			else
			if (layer < CZ_MAX_SCENE_LAYERS && layer > max_layers)
				max_layers = layer;
		}
	}

	// Draw all scenes in layer order
	int num_scenes = Scenes.size();
	for (int t = 0; t <= max_layers; t++)
	{
		for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
		{
			CzScene* s = *it;
			if (!s->isDestroyed())
			{
				if (s->getLayer() == t)
					s->Draw();
			}
		}
	}
	// Draw any scenes that have layers that are out of range last
	for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
	{
		CzScene* s = *it;
		if (!s->isDestroyed())
		{
			int layer = s->getLayer();
			if (layer >= CZ_MAX_SCENE_LAYERS)
				s->Draw();
		}
	}

	// Take care of any post draw rendering
	PostDraw();

#if defined(CZ_ENABLE_METRICS)
	CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "TotalSpritesProcessed - ", CzString(CzMetrics::TotalSpritesProcessed).c_str());
	CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "TotalSpritesCreated - ", CzString(CzMetrics::TotalSpritesCreated).c_str());
	CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "TotalSpritesDestroyed - ", CzString(CzMetrics::TotalSpritesDestroyed).c_str());
#endif
	PLATFORM_RENDER->End();

	// Swap display buffers
	PLATFORM_DISPLAY->Swap();

	// Clear the screen
	PLATFORM_DISPLAY->Clear();

	// Yield to the operating system
	PLATFORM_SYS->YieldToOS(0);
}
Exemplo n.º 13
0
bool CzApp::Update()
{
	IzPlatformDisplay* display = PLATFORM_DISPLAY;

	// If power saving mode disabled then turn back light on
	if (CZ_SETTINGS->getPreventPowerSaving())
		PLATFORM_SYS->BacklightOn();

	// Calculate how long the last game frame took - We use this to scale all of our transient variables that rely upon time so that everything moves at the same rate
	// regardless of our devices frame rate
	float dt = 0;
	if (!TimePaused)
	{
		uint64 current_time = PLATFORM_SYS->getTimeInMs();
		dt = (float)(current_time - LastFrameTime)  / 1000.0f;
		FrameRate = (FrameRate + (1.0f / dt)) / 2.0f;
//		float dt = (float)(PLATFORM_SYS->getTimeInMs() - LastFrameTime) / FRAME_SPEED_LOCK_MS;
//		if (dt < 0.00001f) dt = 0.00001f;
//		if (dt > 10.0f) dt = 10.0f;
		LastFrameTime = current_time;
	}

	// Update input system
	CZ_INPUT->Update();
	UpdateSystemTouches();

	// Check for device orientation / size change
	int screen_width = display->getCurrentWidth();
	int screen_height = display->getCurrentHeight();
	int angle = display->getOrientation();
	if (angle != ScreenOrientation)
	{
		ScreenOrientation = angle;
	}
	
	if (screen_width != ScreenSize.x || screen_height != ScreenSize.y)	// NB: When Marmalade orientation changes it doesnt appear to update screen width and height correctly so we use width and height instead.
	{
		NotifyOrientationChanged();
//		NotifySizeChanged();
	}

	// Update gloabl resource manager
	CZ_GLOBAL_RESOURCES->Update(dt);

	// Update all scene local variables
	for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
		(*it)->getVariableManager()->Update();

	// Run any global programs
	CZ_GLOBAL_RESOURCES->getProgramManager()->Execute(dt);

	// Check for scene change
	// Notify scenes that there is a change of circumstances
	if (CurrentScene != NextScene)
	{
		if (CurrentScene != NULL)
		{
			CurrentScene->NotifyLostFocus(NextScene);
			if (CurrentScene->getAllowSuspend())
				CurrentScene->NotifySuspending(NextScene);
		}
		if (NextScene != NULL)
		{
			NextScene->NotifyGainedFocus(CurrentScene);
			if (NextScene->getAllowSuspend())
				NextScene->NotifyResuming(CurrentScene);
		}
		CurrentScene = NextScene;
	}

	// Update all scenes that are not suspended
	// Note that because actions taken in scenes can change the order of scenes in the Scenes list we need to create a local termporary list that does not get updated
	SceneList.clear();
	for (_Iterator it = Scenes.begin(); it != Scenes.end(); ++it)
		SceneList.add(*it);
	for (int t = 0; t < SceneList.getSize(); t++)
	{
		CzScene* s = SceneList.element_at(t);
		if (s != NULL)
		{
			if (CurrentScene == s)
				s->Update(dt);
			else
			{
				if (!s->getAllowSuspend())
					s->Update(dt);
			}
		}
	}

	// Handle touch event
	if (CurrentScene != NULL)
		ProcessEvents(CurrentScene);

	// Process back key event for key focus actor
	if (KeyFocus != NULL)
	{
		CzScene* focus_scene = KeyFocus->getScene();
		if (focus_scene != NULL && focus_scene->isActive())
		{
			if (CZ_INPUT->isBackPressed())
				KeyFocus->NotifyBackKey();
			if (CZ_INPUT->isMenuPressed())
				KeyFocus->NotifyMenuKey();
		}
	}

	// Update http manager
	if (CZ_HTTP_MANAGER != NULL)
	{
		CZ_HTTP_MANAGER->Update();
	}

	CzAnimTimeline::UpdateRunCount();

	// Update audio
	PLATFORM_AUDIO->Update();

	// Remove any scenes that got deleted last frame
	for (CzList<CzScene*>::iterator it = SceneRemovals.begin(); it != SceneRemovals.end(); ++it)
	{
		for (_Iterator it2 = Scenes.begin(); it2 != Scenes.end(); ++it2)
		{
			if (*it2 == *it)
			{
				// If scene was current scene and had touch or key focus then reset the focus
				if (CurrentScene == *it2)
					CurrentScene = NULL;
				for (int t = 0; t < CZ_MAX_TOUCHES; t++)
				{
					if (TouchFocus[t] != NULL && TouchFocus[t]->getScene() == *it2)
						TouchFocus[t] = NULL;
				}
				if (KeyFocus != NULL && KeyFocus->getScene() == *it2)
					KeyFocus = NULL;

				if (NextScene == *it2)
					NextScene = NULL;
				delete *it2;
				Scenes.erase(it2);
				break;
			}
		}
	}
	SceneRemovals.clear();
	TotalFrames++;

	return true;
}
Exemplo n.º 14
0
int CzCamera::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node)
{
	// Process attributes
	for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++)
	{
		unsigned int name_hash = (*it)->getName().getHash();

		if (name_hash == CzHashes::Name_Hash)
			setName((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Tag_Hash)
			setTag((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Position_Hash)
		{
			if (!(*it)->getValueAsPoint(Position))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::Position", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::Angle_Hash)
			Angle = (*it)->getValueAsFloat();
		else
		if (name_hash == CzHashes::Scale_Hash)
			Scale = (*it)->getValueAsFloat();
		else
		if (name_hash == CzHashes::TargetX_Hash)
			setTargetX((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::TargetY_Hash)
			setTargetY((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::VelocityDamping_Hash)
		{
			if (!(*it)->getValueAsPoint(VelocityDamping))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::VelocityDamping", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::FollowSpeed_Hash)
		{
			if (!(*it)->getValueAsPoint(FollowSpeed))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::FollowSpeed", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::TouchPanX_Hash)
			setTouchPanX((*it)->getValueAsBool());
		else
		if (name_hash == CzHashes::TouchPanY_Hash)
			setTouchPanY((*it)->getValueAsBool());
		else
		if (name_hash == CzHashes::IgnoreActors_Hash)
			setIgnoreActors((*it)->getValueAsBool());
	}

	// If we are declared inside a scene then shape is local to the scene
	CzScene* scene = NULL;
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Actor_Hash)
		scene = ((CzActor*)parent)->getScene();
	else
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Scene_Hash)
		scene = (CzScene*)parent;
	Scene = scene;

	bool ret = false;
	if (scene != NULL)
		ret = scene->getResourceManager()->addResource(this);
	else
		ret = CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this);

	if (!ret)
		return 0;

	Update(0);

	return 1;
}