Skip to content

Instantly share code, notes, and snippets.

View gashtio's full-sized avatar

Nikola Vasilev gashtio

View GitHub Profile
@gashtio
gashtio / D3DPERF_SetOptionsTest.cpp
Created September 5, 2012 07:44
Simple application testing D3DPERF_SetOptions
#include <windows.h>
#include <d3d9.h>
#include <iostream>
#pragma comment(lib, "d3d9.lib")
int main()
{
::D3DPERF_SetOptions(1);
std::cout << "Good job!\n" << std::endl;
}
@gashtio
gashtio / WaitDebugger.cpp
Created September 5, 2012 07:45
Wait for debugger to attach
while (!::IsDebuggerPresent())
{
::Sleep(100);
}
::DebugBreak();
@gashtio
gashtio / acv_to_lut.cpp
Created September 21, 2012 21:05
Creating a 3D LUT from a set of cubic splines, obtained from an acv file
const size_t CUBE_SIZE = 16;
std::vector<float> red(CUBE_SIZE);
std::vector<float> green(CUBE_SIZE);
std::vector<float> blue(CUBE_SIZE);
for (size_t i = 0; i < CUBE_SIZE; ++i)
{
float input = (float)i / (float)(CUBE_SIZE - 1);
float input255 = input * 255.0f;
@gashtio
gashtio / GetMaterialTexId.cpp
Created October 24, 2012 14:30
Obtaining the texture ID of a material in CryEngine 3
if (viewListener->GetTextureId() <= 0)
{
material = gEnv->p3DEngine->GetMaterialManager()->FindMaterial("materials/placeholder_1280_720");
if (material)
{
const STexSamplerRT& sampler = material->GetShaderItem().m_pShaderResources->GetTexture(EFTT_DIFFUSE)->m_Sampler;
const int texId = sampler.m_pITex->GetTextureID();
viewListener->SetTextureId(texId);
}
@gashtio
gashtio / Exports.cpp
Created November 3, 2012 10:27
Simple exported callback from a DLL
#include <iostream>
#define LIBAPI __declspec(dllexport)
#define LIBSTDCALL __stdcall
struct SimpleStruct
{
SimpleStruct() : Value(0) {}
operator int ()
@gashtio
gashtio / Program.cs
Created November 3, 2012 10:36
Simple C++/C# interop with a method returning a structure
using System;
using System.Runtime.InteropServices;
namespace Executable
{
struct SimpleStruct
{
public SimpleStruct(int value)
{
Value = value;
@gashtio
gashtio / AutoBinding.cs
Created December 18, 2012 10:16
Binding JavaScript automatically in Unity3D using Coherent UI
public class AutomaticBinding : MonoBehaviour {
[Coherent.UI.CoherentMethod("ApplyOptions", false)]
public void ApplyOptions(GameOptions options)
{
// Do something with options
}
}
@gashtio
gashtio / ManualBinding.cs
Created December 18, 2012 10:17
Binding JavaScript manually in Unity3D using Coherent UI
public class ManualBinding : MonoBehaviour {
private CoherentUIView m_View;
// Use this for initialization
void Start () {
m_View = GetComponent<CoherentUIView>();
m_View.Listener.ReadyForBindings += HandleReadyForBindings;
}
@gashtio
gashtio / Game.cpp
Created January 28, 2013 12:34
Initialization of Coherent UI plugin for CryEngine3
bool CGame::Init(IGameFramework *pFramework)
{
// Initialize Coherent UI
PluginManager::IPluginBase* pCoherentUIPlugin = gPluginManager->GetPluginByName("CoherentUI");
m_pCoherentUIPlugin = static_cast<CoherentUIPlugin::IPluginCoherentUI*>(pCoherentUIPlugin ? pCoherentUIPlugin->GetConcreteInterface() : NULL);
if (m_pCoherentUIPlugin)
{
m_pCoherentUIPlugin->InitializeSystem();
}
}
@gashtio
gashtio / Game.cpp
Created January 28, 2013 12:38
Adding the Coherent UI plugin IPlayerEventListener in the CryGame code
void CGame::OnActionEvent(const SActionEvent& event)
{
switch(event.m_event)
{
...
case eAE_inGame:
if (m_pCoherentUIPlugin)
{