Skip to content

Instantly share code, notes, and snippets.

View mrtrizer's full-sized avatar
💾

Denis Zdorovtsov mrtrizer

💾
View GitHub Profile
@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]))
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 / 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;
@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_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_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 / 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 / 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 "./")
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)
{