Skip to content

Instantly share code, notes, and snippets.

View cloudwu's full-sized avatar

云风 cloudwu

View GitHub Profile
@cloudwu
cloudwu / entityid2.c
Created June 21, 2023 06:15
Compress monotonic 48bits id array, version 2
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define CHUNK_N 64
struct eid_chunk {
uint64_t id[2];
@cloudwu
cloudwu / entityid.c
Created June 21, 2023 02:16
Compress monotonic 48bits id array
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
// .size is size of sec[]
// .size * 8 >= .section_n * 8 + .n
@cloudwu
cloudwu / resumemainthread.c
Created August 25, 2022 02:10
Resume lua main thread
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>
const char * source = "print 'A' ; coroutine.yield() ; print 'B'";
int
main() {
lua_State *L = luaL_newstate();
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
struct set {
int n;
int count;
};
static int
// See: https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/
#include <stdio.h>
#define MAXN 40
#define MAXSTEP (40*40)
struct coord {
unsigned char x;
unsigned char y;
};
@cloudwu
cloudwu / period.c
Created May 20, 2021 08:45
Turn off canonical mode , forward stdin to stdout, and write \n per 100ms
// Linux: gcc -Wall -o period period.c -lpthread
// Mingw: gcc -Wall -o period.exe period.c
#include <stdio.h>
#define PERIOD 100 // 100 ms
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#include <windows.h>
@cloudwu
cloudwu / prn256.c
Last active July 2, 2021 06:50
xoshiro256 from lua 5.4
// 'xoshiro256**' algorithm from lua 5.4 implementation
#include "random.h"
#include <stdint.h>
#include <assert.h>
static inline uint64_t *
state(struct prn_state *P) {
assert(sizeof(*P) == sizeof(uint64_t) * 4);
return (uint64_t *)P;
}
#ifndef lazy_memory_h
#define lazy_memory_h
#include <stdint.h>
#include <string.h>
#define CacheLine 64
#define WordSize (sizeof(uint64_t) * 8) // 64 (bits)
#define AlignN(s, n) (( s + n - 1) / n * n)
#include "psystem.h"
#include <cstddef>
#include <cstdio>
#include <algorithm>
#include <vector>
#include "psystem_manager.h"
#define REMAP_CACHE 128
namespace {
#ifndef particle_system_manager_h
#define particle_system_manager_h
#define PARTICLE_MAX 0xffff
#define PARTICLE_INVALID PARTICLE_MAX
#ifndef PARTICLE_COMPONENT
#define PARTICLE_COMPONENT 7
#endif