Skip to content

Instantly share code, notes, and snippets.

@onionmk2
onionmk2 / get_global_id.cu
Last active January 5, 2018 02:12 — forked from athiakos/cuda cheat sheet
cuda のid計算がよくわからないので、まとめてみる。
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
namespace comment_thread_id
{
/*
blockIdx.x == n
blockIdx.y == 1
blockIdx.z == 1
@onionmk2
onionmk2 / gist:a2c26752975a2509dc69cf564f87e709
Created April 3, 2017 23:43 — forked from LearnCocos2D/gist:77f0ced228292676689f
Overview of Entity Component System (ECS) variations with pseudo-code

For background and further references see: Entity Component Systems on Wikipedia

ECS by Scott Bilas (GDC 2002)

Entity->Components->Update
  • entity = class: no logic + no data OR at most small set of frequently used data (ie position)
  • component = class: logic + data
foreach entity in allEntities do
    foreach component in entity.components do
@onionmk2
onionmk2 / gist:97a593048f4efe1fcd48e3760bb7b73e
Created February 16, 2017 11:52 — forked from tany3/gist:2d032cbbbd9db04b976d
重複処理 IEnumerableをそのまま使い回さない - Possible multiple enumeration of IEnumerable

IEnumerableをそのまま使うと、使う度に毎回変換される。遅延実行。 http://confluence.jetbrains.com/display/ReSharper/Possible+multiple+enumeration+of+IEnumerable

Assuming that GetNames() returns an IEnumerable, we are, effectively, doing extra work by enumerating this collection twice in the two foreach statements. If GetNames() results in a database query, you end up doing that query twice, while both times getting the same data.

ということで、特に複数回使う場合など適宜ToList()やToArray()しておく。

参考:LINQ クエリの概要 (C#) http://msdn.microsoft.com/ja-jp/library/bb397906.aspx

@onionmk2
onionmk2 / Singletons.md
Created February 5, 2017 10:34 — forked from Ashwinning/Singletons.md
A copy of the post on Singletons in Unity/C# as it appeared on UnityPatterns.com

Singletons

Original post by David Laskey on UnityPatterns

As you develop in Unity, you’ll often find that it’s handy to have just single instances of certain objects. For example, let’s say we have a single GameObject, “MusicManager”, that’s in charge of our music. It might look like this:

using UnityEngine;