Skip to content

Instantly share code, notes, and snippets.

View mrtrizer's full-sized avatar
💾

Denis Zdorovtsov mrtrizer

💾
View GitHub Profile
@mrtrizer
mrtrizer / gist:da80957cee91f99b88d22bf0bef541d9
Created August 7, 2024 05:58
Git diff for LFS files on Windows diff.lfs.textconv
# Just cat doesn't work correctly for me because of \r\n and \n line endings difference in LFS cache and actual file
# So, every line is marked as modified
git config diff.lfs.textconv pwsh` -cwa` `'Get-Content` `$args[0]`'
@mrtrizer
mrtrizer / Test.cs
Last active September 5, 2023 09:09
Basic Tweener for Unity3d
static bool initialized;
static Action staticUpdate;
public static Task Tween<T>(T startValue, T endValue, float duration, Func<T, T, float, T> function, Action<T> callback, CancellationToken? cToken = null)
{
if (!initialized)
{
initialized = true;
var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetCurrentPlayerLoop();
const int updateSubSystemIndex = 5;
@mrtrizer
mrtrizer / ReferenceFixTool.cs
Created December 15, 2022 03:41
Fix fileId in asset file. May be useful if you change type of field and Unity doesn't fix references. Make sure to change regex pattern for your needs.
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;
public class ReferenceFixTool
{
[MenuItem("CONTEXT/ScriptableObject/Fix References")]
static void FixReferences(MenuCommand command)
{
@mrtrizer
mrtrizer / coroutine.c
Last active August 5, 2024 03:22
C language coroutine with switch-case
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define COROUTINE_START(line) switch (line) { case 0:
#define WAIT_WHILE(condition) return __LINE__; case __LINE__: if (condition) return __LINE__;
#define COROUTINE_END default: return -1; }
@mrtrizer
mrtrizer / c_containers.c
Last active June 2, 2022 11:25
C++ style containers in C language with just few macro C99 (msvc, gcc, clang). Doesn't work in C++ mainly because of anonymous struct declaration in function arguments.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
// *******************
// CONTAINERS LIBRARY
// *******************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Text.RegularExpressions;
public class AttributeManager : EditorWindow
{
public static void autoDeserialize(ObjectContext context, AutoSerialisedObject autoSerializedObject, RestoreProcess restoreProcess)
{
var cache = getClassReflectionCache(context.type);
foreach (var field in cache.fields)
{
var serializedField = autoSerializedObject.autoSerialiedFields.Find(item => item.name == field.fieldInfo.Name);
if (serializedField.value != null)
{
@mrtrizer
mrtrizer / CMakeLists.txt
Created October 26, 2020 08:56
CMake Vulkan build shaders. Tested in Visual Studio, but should also work under Linux and MacOS
cmake_minimum_required (VERSION 3.8)
set(PROJECT_NAME SimpleVulkan)
add_executable (${PROJECT_NAME} "main.c")
find_package(Vulkan REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE "./")
@mrtrizer
mrtrizer / windows_c_opengl.c
Created October 24, 2020 23:49
Windows API OpenGL initialization
#include <stdio.h>
#include <windows.h>
#include <gl/GL.h>
HDC dc;
HGLRC rc;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
@mrtrizer
mrtrizer / c_ecs_quick_access.c
Last active October 21, 2020 09:57
The main idea is to make serial components access as fast as possible because this is the most usual way to interact with components.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <assert.h>
#include <stdbool.h>
typedef uint32_t EId;
typedef struct