Skip to content

Instantly share code, notes, and snippets.

View mrtrizer's full-sized avatar
💾

Denis Zdorovtsov mrtrizer

💾
View GitHub Profile
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.Collections.Generic;
[CreateAssetMenu]
public class GoogleTranslateService : ScriptableObject
{
public static GoogleTranslateService instance;
Shader "Custom/Fog"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex ("NoiseTexture", 2D) = "white" {}
}
SubShader
{
@mrtrizer
mrtrizer / main.c
Last active October 18, 2020 11:16
C language macro-intense reflection for functions
#include <stdio.h>
// Make a FOREACH macro
#define FE_0()
#define FE_1(X) *((X*)(args[0]))
#define FE_2(X, ...) FE_1(__VA_ARGS__), *((X*)(args[1]))
#define FE_3(X, ...) FE_2(__VA_ARGS__), *((X*)(args[2]))
#define FE_4(X, ...) FE_3(__VA_ARGS__), *((X*)(args[3]))
#define FE_5(X, ...) FE_4(__VA_ARGS__), *((X*)(args[4]))
#define FE_6(X, ...) FE_5(__VA_ARGS__), *((X*)(args[5]))
@mrtrizer
mrtrizer / c_ecs.c
Last active October 19, 2020 07:27
C language cache-friendly ECS
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <assert.h>
#include <stdbool.h>
typedef uint32_t EId;
typedef struct
@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
@mrtrizer
mrtrizer / typesafe_c_container.c
Last active March 14, 2021 00:55
C language type save containers. Requires GNU C11 (--std=gnu11) because of using typeof(). The benefit of this solution is compilation error if container type is wrong, or container item is of wrong type. The main idea is using function pointer to contain both type of container and type of container items.
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
unsigned int size;
void (*destructor)();
int length;
int reserved;
char* bytes;
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)
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Text.RegularExpressions;
public class AttributeManager : EditorWindow
{
@mrtrizer
mrtrizer / c_reflection.c
Last active October 5, 2021 01:31
Basic 10 lines type reflection implementation in C (see another gist if you need reflection for functions)
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
// Lib code
char* ___tid(const char* strPtr) { return (char*)strPtr; }
#define TID(type) ((intptr_t)___tid(#type))
@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
// *******************