Skip to content

Instantly share code, notes, and snippets.

View gyakoo's full-sized avatar

Manu Marin gyakoo

View GitHub Profile
@gyakoo
gyakoo / LoopMaterialsZone.cpp
Last active August 29, 2015 14:25
Iterate through all materials in all static instances in a Zone in Havok Anarchy
// Iterate through all materials in all static instances in a Zone
{
VisZoneResourceManager_cl &mgr = VisZoneResourceManager_cl::GlobalManager();
// iterate through all zones
for (int i=mgr.GetResourceCount()-1; i >= 0; i--)
{
VisZoneResource_cl *pZone = mgr.GetZoneByIndex(i);
if (!pZone || !pZone->m_bHandleZone || pZone->IsMissing()) continue;
// for all objects in the zone
@gyakoo
gyakoo / SetSurfaceParameter.cpp
Last active August 29, 2015 14:25
Set Surface shader parameter (all constant buffers) in Havok Anarchy
// Set a parameter value for a specific surface.
// It will set all parameters in all passes for all shader stages (vs, ps ...) of the surface technique
void SetSurfaceParameter(VisSurface_cl& surf, const char* param, const char* value)
{
VCompiledTechnique* technique = surf.GetTechnique();
if ( !technique )
return;
int count = technique->GetShaderCount();
for ( int s = 0; s < count; ++ s )
@gyakoo
gyakoo / InputDriver.cpp
Created July 16, 2015 21:09
My generic c++ input driver interface for games
class gyInput : public gyReflectedObject
{
GY_PIMPL_CLASS();
GY_DECLARE_REFLECT(gyInput);
public:
gy_override int Create(gyVarDict& createParams);
gy_override void FillCreateTemplate(gyVarDict& outTemplate);
void Recycle();
gyIDInputTrigger TriggerCreate( gyInputDevice devType, gyInputIndex iindex, const gyInputTriggerOpts& opts=gyInputTriggerOpts::DEFAULT );
@gyakoo
gyakoo / astar.lua
Last active August 14, 2021 23:53
A* in lua
--gyakoo@gmail.com
-- This is an implementation of the basic A*
--[[
Summary of the A* Method
1) Add the starting square (or node) to the open list.
2) Repeat the following:
a) Look for the lowest F cost square on the open list. We refer to this as the current square.
b) Switch it to the closed list.
@gyakoo
gyakoo / Testing graphics driver.cpp
Created July 18, 2015 06:37
Ok something has to be simplified...
struct gyShape2D
{
void CreateRect( gyv2f& lefttop, gyv2f& size )
{
gyVertexElement elements[] =
{
gyVertexElement( VES_POSITION, 0, FMT_R32G32B32A32_F, 0 ),
};
auto& rf = gyGetRendererFactory();
vl = rf.CreateVertexLayout(elements,1);
@gyakoo
gyakoo / dict.c
Last active August 29, 2015 14:27
Small C dictionary I created for a home project. Not totally perfect but gives me more performance than std::map<> in my scenario
////////////////////////////////////////////////////////////////////////////////////////////////
// DICTIONARY : DATA
////////////////////////////////////////////////////////////////////////////////////////////////
typedef unsigned long (*flt_dict_hash)(const unsigned char*, int);
typedef int (*flt_dict_keycomp)(const char*, const char*, int);
typedef void (*flt_dict_visitor)(char* key, void* value);
typedef struct flt_dict_node
{
char* key;
unsigned long keyhash;
@gyakoo
gyakoo / stack-node.c
Last active August 29, 2015 14:27
Minimal C stack ADT
typedef struct flt_stack_node
{
void* value;
struct flt_stack_node* prev;
}flt_stack_node;
typedef struct flt_stack
{
struct flt_stack_node* tail;
int n_entries;
@gyakoo
gyakoo / cs_atomic.c
Created August 21, 2015 16:43
Minimal naïve critical-section and some atomic operations multiplatform
#ifdef _MSC_VER
typedef struct flt_critsec
{
CRITICAL_SECTION cs;
}flt_critsec;
flt_critsec* flt_critsec_create()
{
flt_critsec* cs=(flt_critsec*)flt_malloc(sizeof(flt_critsec));
InitializeCriticalSection(&cs->cs);
@gyakoo
gyakoo / stack-array.c
Created August 21, 2015 17:53
Fixed heap array C for Stack ADT
typedef struct flt_stack
{
void** entries;
int count;
int capacity;
}flt_stack;
int flt_stack_create(flt_stack** s, int capacity)
{
flt_stack* _s = (flt_stack*)flt_calloc(1,sizeof(flt_stack));
@gyakoo
gyakoo / dyn array.c
Last active August 29, 2015 14:28
Small C snippet to have a dynamically allocated array (only few operations)
struct flt_array;
typedef void (*flt_array_growpolicy)(flt_array*);
typedef struct flt_array
{
void** data;
int size;
int capacity;
flt_array_growpolicy growpolicy;
}flt_array;