Пример #1
0
bool strcmp(char* a, char* b) {
	if (lengthOf(a) != lengthOf(b)) {
		return false;
	}
	int i = 0;
	while (a[i] != '\0') {
		if (a[i] != b[i])
			return false;
		i++;
	}
	return true;
}
Пример #2
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);
	}
}
Пример #3
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);
		}
	}
}
Пример #4
0
	void setRenderInterface(RenderInterface* render_interface) override
	{
		if (m_render_interface)
		{
			for (auto& model : m_models)
			{
				m_render_interface->unloadModel(model);
			}
		}
		m_render_interface = render_interface;
		if (m_render_interface)
		{
			for (int i = 0; i < lengthOf(ICONS); ++i)
			{
				StaticString<MAX_PATH_LENGTH> tmp("models/editor/", ICONS[i], "_3d.msh");
				m_is_3d[i] = PlatformInterface::fileExists(tmp);
				if (m_is_3d[i])
				{
					Path path(tmp);
					m_models[i] = m_render_interface->loadModel(path);
				}
				else
				{
					tmp.data[0] = '\0';
					tmp << "models/editor/" << ICONS[i] << ".msh";
					Path path(tmp);
					m_models[i] = m_render_interface->loadModel(path);
				}
			}
		}
	}
Пример #5
0
	void deserialize(InputBlob& serializer) override
	{
		int count;
		serializer.read(count);
		m_prefabs.resize(count);
		if (count > 0)
			serializer.read(&m_prefabs[0], m_prefabs.size() * sizeof(m_prefabs[0]));
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			u64 key;
			Entity value;
			serializer.read(key);
			serializer.read(value);
			m_instances.insert(key, value);
		}
		serializer.read(count);
		auto* resource_manager = m_editor.getEngine().getResourceManager().get(PrefabResource::TYPE);
		for (int i = 0; i < count; ++i)
		{
			char tmp[MAX_PATH_LENGTH];
			serializer.readString(tmp, lengthOf(tmp));
			auto* res = (PrefabResource*)resource_manager->load(Path(tmp));
			m_resources.insert(res->getPath().getHash(), res);
		}
	}
Пример #6
0
	void deserialize(IDeserializer& serializer) override
	{
		int count;
		serializer.read(&count);
		reserve({count-1});
		
		auto* mng = m_editor.getEngine().getResourceManager().get(PrefabResource::TYPE);
		for (;;)
		{
			char tmp[MAX_PATH_LENGTH];
			serializer.read(tmp, lengthOf(tmp));
			if (tmp[0] == 0) break;
			auto* res = (PrefabResource*)mng->load(Path(tmp));
			m_resources.insert(res->getPath().getHash(), res);
		}

		while(m_editor.getEngine().getFileSystem().hasWork())
			m_editor.getEngine().getFileSystem().updateAsyncTransactions();

		for (;;)
		{
			u32 res_hash;
			serializer.read(&res_hash);
			if (res_hash == 0) break;
			
			Vec3 pos;
			serializer.read(&pos);
			Quat rot;
			serializer.read(&rot);
			float scale;
			serializer.read(&scale);
			doInstantiatePrefab(*m_resources[res_hash], pos, rot, scale);
		}
	}
Пример #7
0
void Settings::showShortcutSettings()
{
	auto& actions = m_app.getActions();
	ImGui::LabellessInputText("Filter", m_filter, lengthOf(m_filter));
	ImGui::Columns(4);
	ImGui::Text("Label");
	ImGui::NextColumn();
	ImGui::Text("Shortcut key 1");
	ImGui::NextColumn();
	ImGui::Text("Shortcut key 2");
	ImGui::NextColumn();
	ImGui::Text("Shortcut key 3");
	ImGui::NextColumn();
	ImGui::Separator();

	for (int i = 0; i < actions.size(); ++i)
	{
		Action& a = *actions[i];
		if (m_filter[0] == 0 || stristr(a.label_long, m_filter) != 0)
		{
			ImGui::AlignTextToFramePadding();
			ImGui::Text("%s", a.label_long);
			ImGui::NextColumn();
			shortcutInput(a.shortcut[0]);
			ImGui::NextColumn();
			shortcutInput(a.shortcut[1]);
			ImGui::NextColumn();
			shortcutInput(a.shortcut[2]);
			ImGui::NextColumn();
		}
	}
	ImGui::Columns(1);

}
Пример #8
0
void NemoThumbnailLoader::shutdown()
{
    if (!instance)
        return;

    {
        QMutexLocker locker(&instance->m_mutex);

        instance->m_quit = true;

        instance->m_waitCondition.wakeOne();
    }

    instance->wait();

    ThumbnailRequestList *lists[] = {
        &instance->m_thumbnailHighPriority,
        &instance->m_thumbnailNormalPriority,
        &instance->m_thumbnailLowPriority,
        &instance->m_generateHighPriority,
        &instance->m_generateNormalPriority,
        &instance->m_generateLowPriority,
        &instance->m_completedRequests,
        &instance->m_cachedRequests
    };

    for (int i = 0; i < lengthOf(lists); ++i) {
        while (ThumbnailRequest *request = lists[i]->takeFirst())
            delete request;
    }

    delete instance;
}
Пример #9
0
OsFile& OsFile::operator <<(u64 value)
{
	char buf[30];
	toCString(value, buf, lengthOf(buf));
	write(buf, stringLength(buf));
	return *this;
}
Пример #10
0
OsFile& OsFile::operator <<(float value)
{
	char buf[128];
	toCString(value, buf, lengthOf(buf), 7);
	write(buf, stringLength(buf));
	return *this;
}
Пример #11
0
bool Sprite::load(FS::IFile& file)
{
	auto& manager = (SpriteManager&)getResourceManager();
	IAllocator& allocator = manager.m_allocator;
	JsonDeserializer serializer(file, getPath(), allocator);
	serializer.deserializeObjectBegin();
	while (!serializer.isObjectEnd())
	{
		char tmp[32];
		serializer.deserializeLabel(tmp, lengthOf(tmp));
		if (equalIStrings(tmp, "type"))
		{
			serializer.deserialize(tmp, lengthOf(tmp), "");
			type = equalIStrings(tmp, "patch9") ? PATCH9 : SIMPLE;
		}
		else if (equalIStrings(tmp, "top"))
		{
			serializer.deserialize(top, 0);
		}
		else if (equalIStrings(tmp, "bottom"))
		{
			serializer.deserialize(bottom, 0);
		}
		else if (equalIStrings(tmp, "left"))
		{
			serializer.deserialize(left, 0);
		}
		else if (equalIStrings(tmp, "right"))
		{
			serializer.deserialize(right, 0);
		}
		else if (equalIStrings(tmp, "texture"))
		{
			char texture_path[MAX_PATH_LENGTH];
			serializer.deserialize(texture_path, lengthOf(texture_path), "");
			auto* mng = m_resource_manager.getOwner().get(Texture::TYPE);
			m_texture = texture_path[0] != '\0' ? (Texture*)mng->load(Path(texture_path)) : nullptr;
		}
		else
		{
			g_log_error.log("gui") << "Unknown label " << tmp << " in " << getPath();
		}
	}
	return true;
}
Пример #12
0
const Type* vecType(Module* module, int simdWidth, const Type* type, int& simdLength)
{
    simdLength = lengthOf(simdWidth, type);

    if (simdLength == ERROR)
        return 0;

    return vecTypeRec(module, simdWidth, type, simdLength);
}
Пример #13
0
void EditorIcon::unloadIcons()
{
	for (int i = 0; i < lengthOf(icon_models); ++i)
	{
		icon_models[i]
			->getResourceManager()
			.get(ResourceManager::MODEL)
			->unload(*icon_models[i]);
	}
}
Пример #14
0
	//Useful Functions
	template <typename T> sf::Vector2<T> normalize(sf::Vector2<T> vector)
	{
		T length = lengthOf(vector);
		if (length == T(0))
		{
			return sf::Vector2<T>(T(0), T(0));
		}
		else
		{
			return (vector / length);
		}
	}
void insertString (char source [100], char insert [4], int start){
    int end = start + lengthOf(insert);     // The last index we must overwrite in source
    int i = start, j = 0;
    char buffer;
    
    while ( i < end ){
        buffer          = source[i];        // Store the original character
        source[i]       = insert[j];        // Swap with insert
        source[end + j] = buffer;           // Insert back into the end of the insert
        ++i, ++j;
    }
}
Пример #16
0
void luaThread::proc()
{
	lua_State *L = m_L = luaL_newstate();
	luaL_openlibs(L);

	// Initialize Functions
	lua_pushlightuserdata(L, this);
	lua_pushcclosure(L, lua_transmit, 1);
	lua_setglobal(L, "tx");

	lua_pushlightuserdata(L, this);
	lua_pushcclosure(L, lua_menu_register, 1);
	lua_setglobal(L, "register");

	lua_pushcfunction(L, lua_sleep);
	lua_setglobal(L, "sleep");

	// Run Hook every 100 instructions
	lua_sethook(L, lua_hook, LUA_MASKCOUNT, 100); 

	if( luaL_dofile(L, "./script.lua") ) {
		printf("%s\n", lua_tostring(L, -1));
	}

	HANDLE handles[] = { quitEvent, execEvent };
	while(true) switch(WaitForMultipleObjects(lengthOf(handles), handles, FALSE, INFINITE)) {
	case WAIT_OBJECT_0 + 0: // Quit
		lua_close(L);
		return;
	case WAIT_OBJECT_0 + 1: // Exec
		::ResetEvent(execEvent);
		lua_rawgeti(L, LUA_REGISTRYINDEX, m_func);
		
		running = true;

		// Call the function
		if (lua_pcall(L, 0, 0, 0) != 0) {
			const char* err = lua_tostring(L,-1);
			const char* msg = strchr(strchr(err, ':') + 1, ':');

			if( strcmp(msg,": abort") == 0 ) printf("Aborted\n");
			else printf("Error running function f:%s`", lua_tostring(L, -1));
		}
		
		if( lua_abort == L ) lua_abort = NULL;
		running = false;
		break;
	default:
	case WAIT_FAILED:
		__debugbreak();
		printf("Wait Failed");
	}
}
Пример #17
0
/*=============================================================*/
int compare(DIGITS *p, DIGITS *q){
	int p_len, q_len;
	DIGITS *p_ptr, *q_ptr;

	//Check if p/q is infinity. 
	if (q == NULL){
		return -1;
	}

	if (p == NULL){
		return 1;
	}
	
	p_len = lengthOf(p);
	q_len = lengthOf(q);
	if (p_len > q_len){
		return 1;
	}
	else if (p_len < q_len){
		return -1;
	}

	//Compare each DIGITS of these two numbers.
	p_ptr = &p;
	q_ptr = &q;
	while (p_ptr != NULL){
		int p_DIGITS = p_ptr->digit;
		int q_DIGITS = q_ptr->digit;
		if (p_DIGITS  > q_DIGITS)
			return 1;
		else if (p_DIGITS < q_DIGITS)
			return -1;
		else{
			p_ptr = p_ptr->next;
			q_ptr = q_ptr->next;
		}
	}

	return 0;
}
Пример #18
0
	IFile* createFile(const DeviceList& device_list)
	{
		IFile* prev = nullptr;
		for (int i = 0; i < lengthOf(device_list.m_devices); ++i)
		{
			if (!device_list.m_devices[i])
			{
				break;
			}
			prev = device_list.m_devices[i]->createFile(prev);
		}
		return prev;
	}
Пример #19
0
const FunctionType* vecFunctionType(Module* module, 
                                    int simdWidth, 
                                    const FunctionType* type, 
                                    const bvector& uniforms, 
                                    int& simdLength)
{
    simdLength = lengthOf(simdWidth, type);

    if (simdLength == ERROR)
        return 0;

    return cast<FunctionType>( vecTypeRec(module, simdWidth, type, uniforms, simdLength) );
}
Пример #20
0
TYPE *convert(node *list) {
    int i = 0;
    int length = lengthOf(list);
    TYPE *ans = malloc(sizeof(TYPE) * (length+1));
    
    while (list) {
        ans[i] = list->payload;
        list = list->next;
        i++;
    }
    ans[i] = sentinel;
    return ans;
}
Пример #21
0
static uint32 getDefineMaskFromDense(const Shader& shader, uint32 dense)
{
	uint32 mask = 0;
	int defines_count = Math::minimum(lengthOf(shader.m_combintions.defines), int(sizeof(dense) * 8));

	for (int i = 0; i < defines_count; ++i)
	{
		if (dense & (1 << i))
		{
			mask |= 1 << shader.m_combintions.defines[i];
		}
	}
	return mask;
}
bool replaceString (char source [], char find [], char replace []){
    int findString (const char haystack [], const char needle []);
    void removeString(char string [], int start, int length);
    int lengthOf(char source []);
    void insertString (char source [100], char insert [4], int start);
    
    int start = findString(source, find);
    
    if ( start > -1 ){
        removeString (source, start, lengthOf(find));
        insertString (source, replace, start);
        return true;
    }
    
    return false;   // If the string is not found
}
Пример #23
0
void JsonSerializer::deserialize(Path& value, const Path& default_value)
{
	if (!m_is_string_token)
	{
		value = default_value;
	}
	else
	{
		char tmp[MAX_PATH_LENGTH];
		int size = Math::minimum(lengthOf(tmp) - 1, m_token_size);
		copyMemory(tmp, m_token, size);
		tmp[size] = '\0';
		value = tmp;
		deserializeToken();
	}
}
Пример #24
0
bool Model::parseLODs(FS::IFile& file)
{
	i32 lod_count;
	file.read(&lod_count, sizeof(lod_count));
	if (lod_count <= 0 || lod_count > lengthOf(m_lods))
	{
		return false;
	}
	for (int i = 0; i < lod_count; ++i)
	{
		file.read(&m_lods[i].to_mesh, sizeof(m_lods[i].to_mesh));
		file.read(&m_lods[i].distance, sizeof(m_lods[i].distance));
		m_lods[i].from_mesh = i > 0 ? m_lods[i - 1].to_mesh + 1 : 0;
	}
	return true;
}
Пример #25
0
bool makePath(const char* path)
{
	char tmp[MAX_PATH];
	char* out = tmp;
	const char* in = path;
	while (*in && out - tmp < lengthOf(tmp) - 1)
	{
		*out = *in == '/' ? '\\' : *in;
		++out;
		++in;
	}
	*out = '\0';

	int error_code = SHCreateDirectoryEx(NULL, tmp, NULL);
	return error_code == ERROR_SUCCESS;
}
Пример #26
0
	void setRenderInterface(RenderInterface* render_interface) override
	{
		if (m_render_interface)
		{
			for (auto& model : m_models)
			{
				m_render_interface->unloadModel(model);
			}
		}
		m_render_interface = render_interface;
		if (m_render_interface)
		{
			for (int i = 0; i < lengthOf(ICONS); ++i)
			{
				m_models[i] = m_render_interface->loadModel(Path(ICONS[i]));
			}
		}
	}
Пример #27
0
ShaderInstance::~ShaderInstance()
{
    for (int i = 0; i < lengthOf(program_handles); ++i)
    {
        if (bgfx::isValid(program_handles[i]))
        {
            bgfx::destroyProgram(program_handles[i]);
        }
    }

    for (auto* binary : binaries)
    {
        if (!binary) continue;

        shader.removeDependency(*binary);
        binary->getResourceManager().unload(*binary);
    }
}
Пример #28
0
ShaderInstance::~ShaderInstance()
{
	for (int i = 0; i < lengthOf(m_program_handles); ++i)
	{
		if (bgfx::isValid(m_program_handles[i]))
		{
			bgfx::destroyProgram(m_program_handles[i]);
		}
	}

	for (auto* binary : m_binaries)
	{
		if (!binary) continue;

		m_shader.removeDependency(*binary);
		auto* manager = binary->getResourceManager().get(ResourceManager::SHADER_BINARY);
		manager->unload(*binary);
	}
}
Пример #29
0
int convertToInt(DIGITS *number){
	DIGITS *ptr;
	int len, result;
	ptr = number;

	len = lengthOf(ptr);
	result = 0;
	while (ptr != 0){
		if (len > 1)
			result += pow(10, len - 1)*(ptr->digit);
		else
			result += ptr->digit;
		len--;
		ptr = ptr->next;
	}

	/*printf("%d", result);*/
	return result;
}
Пример #30
0
bool getSaveFilename(char* out, int max_size, const char* filter, const char* default_extension)
{
	char tmp[MAX_PATH_LENGTH];
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.lpstrFile = tmp;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = lengthOf(tmp);
	ofn.lpstrFilter = filter;
	ofn.nFilterIndex = 1;
	ofn.lpstrDefExt = default_extension;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR | OFN_NONETWORKBUTTON;

	bool res = GetSaveFileName(&ofn) != FALSE;
	if (res) PathUtils::normalize(tmp, out, max_size);
	return res;
}