Ejemplo n.º 1
0
//Get the filename of a selfie quote.
std::string Monster::getSoundFireScream()
{
    static std::vector<std::string*> toBeSaid;

    ResourceManager *manager = game->getResourceManager();

    if(toBeSaid.size() < 1)
    {
        unsigned i = 1;

        std::string *path;

        path = manager->get("monster_scream" + std::to_string(i));

        while(path)
        {
            toBeSaid.push_back(path);
            i++;
            path = manager->get("monster_scream" + std::to_string(i));
        }
    }

    unsigned index = rand() % toBeSaid.size();

    //Get a pointer to a string to return.
    std::string *out = toBeSaid[index];

    //Remove the quip we just said.
    toBeSaid.erase(toBeSaid.begin() + index);

    //Return the string path to a quip.
    return *out;
}
Ejemplo n.º 2
0
void DebugLine::add_unit(ResourceManager& rm, const Matrix4x4& tm, StringId64 name, const Color4& color)
{
	const UnitResource& ur = *(const UnitResource*)rm.get(RESOURCE_TYPE_UNIT, name);

	const char* component_data = (const char*)(&ur + 1);

	for (u32 cc = 0; cc < ur.num_component_types; ++cc)
	{
		const ComponentData* component = (const ComponentData*)component_data;
		const u32* unit_index = (const u32*)(component + 1);
		const char* data = (const char*)(unit_index + component->num_instances);

		if (component->type == COMPONENT_TYPE_MESH_RENDERER)
		{
			const MeshRendererDesc* mrd = (const MeshRendererDesc*)data;
			for (u32 i = 0; i < component->num_instances; ++i, ++mrd)
			{
				const MeshResource* mr = (const MeshResource*)rm.get(RESOURCE_TYPE_MESH, mrd->mesh_resource);
				const MeshGeometry* mg = mr->geometry(mrd->geometry_name);

				add_mesh(tm
					, mg->vertices.data
					, mg->vertices.stride
					, (u16*)mg->indices.data
					, mg->indices.num
					, color
					);
			}
		}

		component_data += component->size + sizeof(ComponentData);
	}
}
Ejemplo n.º 3
0
	void offline(StringId64 id, ResourceManager& resourceManager)
	{
		SpriteResource* spriteResource = (SpriteResource*)resourceManager.get(RESOURCE_TYPE_SPRITE, id);

		bgfx::destroyVertexBuffer(spriteResource->vertexBufferHandle);
		bgfx::destroyIndexBuffer(spriteResource->indexBufferHandle);
	}
Ejemplo n.º 4
0
void ParticleEmitter::deserialize(InputBlob& blob, ResourceManager& manager)
{
	blob.read(m_spawn_count);
	blob.read(m_spawn_period);
	blob.read(m_initial_life);
	blob.read(m_initial_size);
	blob.read(m_entity);
	blob.read(m_autoemit);
	blob.read(m_local_space);
	char path[MAX_PATH_LENGTH];
	blob.readString(path, lengthOf(path));
	auto material_manager = manager.get(MATERIAL_TYPE);
	auto material = static_cast<Material*>(material_manager->load(Path(path)));
	setMaterial(material);

	int size;
	blob.read(size);
	for (auto* module : m_modules)
	{
		LUMIX_DELETE(m_allocator, module);
	}
	m_modules.clear();
	for (int i = 0; i < size; ++i)
	{
		ParticleEmitter::ModuleBase* module = nullptr;
		u32 hash;
		blob.read(hash);
		ComponentType type = PropertyRegister::getComponentTypeFromHash(hash);
		module = createModule(type, *this);
		if (module)
		{
			m_modules.push(module);
		}
	}
}
Ejemplo n.º 5
0
void ParticleEmitter::deserialize(InputBlob& blob, ResourceManager& manager, bool has_version)
{
	int version = (int)ParticleEmitterVersion::INVALID;
	if (has_version)
	{
		blob.read(version);
		if (version > (int)ParticleEmitterVersion::SPAWN_COUNT) blob.read(m_spawn_count);
	}
	blob.read(m_spawn_period);
	blob.read(m_initial_life);
	blob.read(m_initial_size);
	blob.read(m_entity);
	char path[MAX_PATH_LENGTH];
	blob.readString(path, lengthOf(path));
	auto material_manager = manager.get(ResourceManager::MATERIAL);
	auto material = static_cast<Material*>(material_manager->load(Lumix::Path(path)));
	setMaterial(material);

	int size;
	blob.read(size);
	for (auto* module : m_modules)
	{
		LUMIX_DELETE(m_allocator, module);
	}
	m_modules.clear();
	for (int i = 0; i < size; ++i)
	{
		uint32 type;
		blob.read(type);
		auto* module = createModule(type, *this);
		m_modules.push(module);
		module->deserialize(blob, version);
	}
}
Ejemplo n.º 6
0
	void offline(StringId64 id, ResourceManager& rm)
	{
		SpriteResource* so = (SpriteResource*) rm.get(SPRITE_TYPE, id);

		bgfx::destroyVertexBuffer(so->vb);
		bgfx::destroyIndexBuffer(so->ib);
	}
Ejemplo n.º 7
0
Material::Material(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
	: Resource(path, resource_manager, allocator)
	, m_shader(nullptr)
	, m_uniforms(allocator)
	, m_allocator(allocator)
	, m_texture_count(0)
	, m_render_states(0)
	, m_specular(1, 1, 1)
	, m_shininess(4)
	, m_shader_instance(nullptr)
	, m_shader_mask(0)
{
	auto* manager = resource_manager.get(ResourceManager::MATERIAL);
	auto* mat_manager = static_cast<MaterialManager*>(manager);

	s_alpha_cutout_define_idx = mat_manager->getRenderer().getShaderDefineIdx("ALPHA_CUTOUT");
	s_shadow_receiver_define_idx = mat_manager->getRenderer().getShaderDefineIdx("SHADOW_RECEIVER");

	enableZTest(true);
	enableBackfaceCulling(true);
	enableShadowReceiving(true);
	for (int i = 0; i < MAX_TEXTURE_COUNT; ++i)
	{
		m_textures[i] = nullptr;
	}
}
Ejemplo n.º 8
0
	void offline(StringId64 id, ResourceManager& rm)
	{
		ResourceId res_id;
		res_id.type = SHADER_TYPE;
		res_id.name = id;

		Shader* shader = (Shader*) rm.get(res_id);
		bgfx::destroyProgram(shader->program);
	}
Ejemplo n.º 9
0
	void online(StringId64 id, ResourceManager& rm)
	{
		ResourceId res_id;
		res_id.type = SHADER_TYPE;
		res_id.name = id;

		Shader* shader = (Shader*) rm.get(res_id);
		bgfx::ShaderHandle vs = bgfx::createShader(shader->vs);
		bgfx::ShaderHandle fs = bgfx::createShader(shader->fs);
		shader->program = bgfx::createProgram(vs, fs, true);
	}
Ejemplo n.º 10
0
	void online(StringId64 id, ResourceManager& rm)
	{
		SpriteResource* so = (SpriteResource*) rm.get(SPRITE_TYPE, id);

		bgfx::VertexDecl decl;
		decl.begin()
			.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
			.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float, false)
			.end();

		so->vb = bgfx::createVertexBuffer(so->vbmem, decl);
		so->ib = bgfx::createIndexBuffer(so->ibmem);
	}
Ejemplo n.º 11
0
	void online(StringId64 id, ResourceManager& resourceManager)
	{
		SpriteResource* spriteResource = (SpriteResource*)resourceManager.get(RESOURCE_TYPE_SPRITE, id);

		bgfx::VertexDecl vertexDecl;
		vertexDecl.begin()
			.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
			.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float, false)
			.end();

		spriteResource->vertexBufferHandle = bgfx::createVertexBuffer(spriteResource->vertexBufferMemory, vertexDecl);
		spriteResource->indexBufferHandle = bgfx::createIndexBuffer(spriteResource->indexBufferMemory);
	}
Ejemplo n.º 12
0
void ShaderManager::offline(StringId64 id, ResourceManager& rm)
{
	const ShaderResource* shader = (ShaderResource*)rm.get(RESOURCE_TYPE_SHADER, id);

	for (u32 i = 0; i < array::size(shader->_data); ++i)
	{
		const ShaderResource::Data& data = shader->_data[i];
		const ShaderData& sd = get(data.name);

		bgfx::destroyProgram(sd.program);

		sort_map::remove(_shader_map, data.name);
		sort_map::sort(_shader_map);
	}
}
Ejemplo n.º 13
0
void ShaderManager::online(StringId64 id, ResourceManager& rm)
{
	const ShaderResource* shader = (ShaderResource*)rm.get(RESOURCE_TYPE_SHADER, id);

	for (u32 i = 0; i < array::size(shader->_data); ++i)
	{
		const ShaderResource::Data& data = shader->_data[i];

		bgfx::ShaderHandle vs = bgfx::createShader(data.vsmem);
		CE_ASSERT(bgfx::isValid(vs), "Failed to create vertex shader");
		bgfx::ShaderHandle fs = bgfx::createShader(data.fsmem);
		CE_ASSERT(bgfx::isValid(fs), "Failed to create fragment shader");
		bgfx::ProgramHandle program = bgfx::createProgram(vs, fs, true);
		CE_ASSERT(bgfx::isValid(program), "Failed to create GPU program");

		add_shader(data.name, data.state, program);
	}
}
Ejemplo n.º 14
0
void ShaderManager::offline(StringId64 id, ResourceManager& rm)
{
	const ShaderResource* shader = (ShaderResource*)rm.get(RESOURCE_TYPE_SHADER, id);

	for (u32 i = 0; i < array::size(shader->_data); ++i)
	{
		const ShaderResource::Data& data = shader->_data[i];

		ShaderData sd;
		sd.state = BGFX_STATE_DEFAULT;
		sd.program = BGFX_INVALID_HANDLE;
		sd = hash_map::get(_shader_map, data.name, sd);

		bgfx::destroyProgram(sd.program);

		hash_map::remove(_shader_map, data.name);
	}
}
Ejemplo n.º 15
0
	void online(StringId64 id, ResourceManager& rm)
	{
		MaterialResource* mr = (MaterialResource*) rm.get(MATERIAL_TYPE, id);

		char* base = (char*)mr + dynamic_data_offset(mr);

		for (uint32_t i = 0; i < num_textures(mr); i++)
		{
			TextureData* td = get_texture_data(mr, i);
			TextureHandle* th = get_texture_handle(mr, i, base);
			th->sampler_handle = bgfx::createUniform(get_texture_name(mr, td), bgfx::UniformType::Uniform1iv).idx;
		}

		for (uint32_t i = 0; i < num_uniforms(mr); i++)
		{
			UniformData* ud = get_uniform_data(mr, i);
			UniformHandle* uh = get_uniform_handle(mr, i, base);
			uh->uniform_handle = bgfx::createUniform(get_uniform_name(mr, ud), bgfx::UniformType::Uniform4fv).idx;
		}
	}
Ejemplo n.º 16
0
void MaterialManager::online(StringId64 id, ResourceManager& rm)
{
	using namespace material_resource;

	MaterialResource* mr = (MaterialResource*) rm.get(RESOURCE_TYPE_MATERIAL, id);

	char* base = (char*)mr + mr->dynamic_data_offset;

	for (u32 i = 0; i < mr->num_textures; ++i)
	{
		TextureData* td    = get_texture_data(mr, i);
		TextureHandle* th  = get_texture_handle(mr, i, base);
		th->sampler_handle = bgfx::createUniform(get_texture_name(mr, td), bgfx::UniformType::Int1).idx;
	}

	for (u32 i = 0; i < mr->num_uniforms; ++i)
	{
		UniformData* ud    = get_uniform_data(mr, i);
		UniformHandle* uh  = get_uniform_handle(mr, i, base);
		uh->uniform_handle = bgfx::createUniform(get_uniform_name(mr, ud), bgfx::UniformType::Vec4).idx;
	}
}
Ejemplo n.º 17
0
	void offline(StringId64 id, ResourceManager& rm)
	{
		MaterialResource* mr = (MaterialResource*) rm.get(MATERIAL_TYPE, id);

		char* base = (char*) mr + dynamic_data_offset(mr);

		for (uint32_t i = 0; i < num_textures(mr); i++)
		{
			TextureHandle* th = get_texture_handle(mr, i, base);
			bgfx::UniformHandle sh;
			sh.idx = th->sampler_handle;
			bgfx::destroyUniform(sh);
		}

		for (uint32_t i = 0; i < num_uniforms(mr); i++)
		{
			UniformHandle* uh = get_uniform_handle(mr, i, base);
			bgfx::UniformHandle bgfx_uh;
			bgfx_uh.idx = uh->uniform_handle;
			bgfx::destroyUniform(bgfx_uh);
		}
	}
Ejemplo n.º 18
0
void MaterialManager::offline(StringId64 id, ResourceManager& rm)
{
	using namespace material_resource;

	MaterialResource* mr = (MaterialResource*) rm.get(RESOURCE_TYPE_MATERIAL, id);

	char* base = (char*) mr + mr->dynamic_data_offset;

	for (u32 i = 0; i < mr->num_textures; ++i)
	{
		TextureHandle* th = get_texture_handle(mr, i, base);
		bgfx::UniformHandle sh;
		sh.idx = th->sampler_handle;
		bgfx::destroyUniform(sh);
	}

	for (u32 i = 0; i < mr->num_uniforms; ++i)
	{
		UniformHandle* uh = get_uniform_handle(mr, i, base);
		bgfx::UniformHandle bgfx_uh;
		bgfx_uh.idx = uh->uniform_handle;
		bgfx::destroyUniform(bgfx_uh);
	}
}
Ejemplo n.º 19
0
void Level3::create_level()
{
	ResourceManager *res = ResourceManager::init("level1");
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	Sprite *ground = Sprite::create(res->get("ground"));
	ground->setPosition(5 * PT_X, 0.25f*PT_Y);
	ground->setScale(visibleSize.width / ground->getContentSize().width, 0.5 * PT_X / ground->getContentSize().height);
	layer->addChild(ground, -1);
	/*set up cho background*/
	Sprite *background = Sprite::create(res->get("background_top"));
	background->setPosition(Point(0, 0.5 * PT_Y));
	background->setAnchorPoint(Point(0, 0));
	background->setScale(visibleSize.width / background->getContentSize().width, (visibleSize.height - 0.5 * PT_Y) / background->getContentSize().height);
	layer->addChild(background, -1);

	res->setTag("all");
	//*Set up cho dai bac*
	spymanager->createSpy()->filename(res->get("daibac"))->x(9)->y(0.8)->width(1)->height(1)->createA();
	//*Tao bong bong'*
	b2Body *bodybubble = spymanager->createSpy()->filename(res->get("bubble", "level3"))->x(2.25)->y(5.4)->width(0.5)->height(0.65)->typeBody(b2_dynamicBody)->density(0.5)->createA()->setTag("bubble")->getBody();
	bodybubble->SetGravityScale(-1);
	//*Tao con pig lien ket voi bong bong tren*
	b2Body *bodypig_1 = spymanager->createSpy()->filename(res->get("goal", "level1"))->x(2.25)->y(4.25)->R(0.25)->density(0.5)->restitution(0.2)->friction(0.7)->typeBody(b2_dynamicBody)->type(typeSprite::circle)->createA()->setTag("goal")->getBody();
	//*Tao cai day noi hai vat tren*
	b2Body *bodyrope_1 = spymanager->createSpy()->filename(res->get("rope", "level3"))->x(2.25)->y(4.75)->width(0.05)->height(1)->density(0.5)->typeBody(b2_dynamicBody)->createA()->setTag("rope")->getBody();
	/*gio noi chung lai bang revolute joint*/
	bodybubble->SetGravityScale(-(bodypig_1->GetMass() + bodyrope_1->GetMass()) / bodybubble->GetMass());
	b2RevoluteJointDef def;
	def.collideConnected = false;
	def.bodyA = bodypig_1;
	def.bodyB = bodyrope_1;
	def.localAnchorA.Set(0, 0.25);
	def.localAnchorB.Set(0, -0.5);
	world->CreateJoint(&def)->SetUserData((void*)"pig_rope");
	def.bodyA = bodybubble;
	def.bodyB = bodyrope_1;
	def.localAnchorA.Set(0, -0.3);
	def.localAnchorB.Set(0, 0.5);
	world->CreateJoint(&def);
	//*Tao qua bong bong thu 2*
	b2Body *bodybubble_2 = spymanager->createSpy()->filename(res->get("bubble", "level3"))->x(6.25)->y(6.375)->width(0.5)->height(0.65)->typeBody(b2_dynamicBody)->density(0.5)->createA()->setTag("bubble")->getBody();
	//*Tao con pig lien ket voi bong bong tren*
	b2Body *bodypig_2 = spymanager->createSpy()->filename(res->get("goal", "level1"))->x(6.25)->y(5.25)->R(0.25)->density(0.5)->restitution(0.2)->friction(0.7)->typeBody(b2_dynamicBody)->type(typeSprite::circle)->createA()->setTag("goal")->getBody();
	//*Tao cai day noi hai vat tren*
	b2Body *bodyrope_2 = spymanager->createSpy()->filename(res->get("rope", "level3"))->x(5.75)->y(5.25)->width(0.05)->height(1)->density(0.5)->typeBody(b2_dynamicBody)->createA()->setTag("rope")->getBody();
	/*gio noi chung lai bang revolute joint*/
	bodybubble_2->SetGravityScale(-(bodypig_2->GetMass() + bodyrope_2->GetMass()) / bodybubble_2->GetMass());
	def.collideConnected = false;
	def.bodyA = bodypig_2;
	def.bodyB = bodyrope_2;
	def.localAnchorA.Set(0, 0.25);
	def.localAnchorB.Set(0, -0.5);
	world->CreateJoint(&def)->SetUserData((void*)"pig_rope");

	def.bodyA = bodybubble_2;
	def.bodyB = bodyrope_2;
	def.localAnchorA.Set(0, -0.3);
	def.localAnchorB.Set(0, 0.5);
	world->CreateJoint(&def);

	//*Tao dan*
	spymanager->createSpy()->filename(res->get("dan", "level1"))->R(0.25)->type(typeSprite::circle)->x(8.25)->y(1.5)->createS()->setTag("dan");


	delete res;
	logicgame->setCountMonster(2);
	logicgame->setLevelPlaying(3);

}