Skip to content

Instantly share code, notes, and snippets.

@mlfarrell
mlfarrell / membuf.cpp
Created May 28, 2016 01:11
C++ streams from memory buffer
struct membuf : std::streambuf
{
membuf(char *begin, char *end) : begin(begin), end(end)
{
this->setg(begin, begin, end);
}
virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in) override
{
if(dir == std::ios_base::cur)
@mlfarrell
mlfarrell / Manager.cpp
Last active July 2, 2018 22:14
Vulkan memory manager draft
#include <cassert>
#include <algorithm>
#include "VulkanMemoryManager.h"
using namespace std;
namespace vgl
{
namespace core
{
/* MONOPOFUCK YO MAMMA A game written by Mike Farrel for Fun *
* To Change names, and starting money, edit the initial settings *
* of the player and property structs. Just make sure to keep *
* a backup of the original source code *
*/
/* Comment made on 2/19/2002: This code is really fucking bad! *
* I'm going to try to salvage what I can and renovate what doesn't *
* work properly */
@mlfarrell
mlfarrell / Post.frag
Created December 9, 2018 03:08
Retro handheld style post processing shader
//
// Pass-through post-processing shader template
// Verto Studio 3D
// Created by Mike Farrell
//
// Please read the shader section of the user-guide
// for more information on shader programming
// within Verto Studio
precision mediump float;
@mlfarrell
mlfarrell / snippet.cpp
Created December 10, 2018 01:37
Vulkan async resource handles
struct VulkanAsyncResourceHandle
{
union
{
VkFence fence;
VkBuffer buffer;
VkImage image;
VkSampler sampler;
VkCommandBuffer commandBuffer;
};
#include "pch.h"
#include "Timer.h"
#include "System.h"
using namespace std;
namespace vui
{
Timer::Timer(int milliseconds, bool repeating, std::function<void()> callback)
{
@mlfarrell
mlfarrell / CollDetect.cpp
Last active March 18, 2024 21:04
Vertical (Wall) Coll Detect
/*** Not optimized or perfect, but hopefully helps someone else learn **/
//https://gamedev.stackexchange.com/questions/96459/fast-ray-sphere-collision-code
static bool intersectRaySegmentSphere(float3 o, float3 d, float3 so, float radius2, float3 &ip)
{
//we pass in d non-normalized to keep it's length
//then we use that length later to compare the intersection point to make sure
//we're within the actual ray segment
float l = d.length();
d /= l;
#version 450
#define VGL_VULKAN
#extension GL_ARB_separate_shader_objects : enable
#define SPRITE_SCALE 0.200000
struct PerInstance
{
//.xyz are xyz pos in 3D
//abs(.w) is texture atlas x-shift
//sign(.w) can be -1 for h-flip
#version 450
#define VGL_VULKAN
#extension GL_ARB_separate_shader_objects : enable
#ifdef GL_ES
precision highp float;
#else
#define highp
#define lowp
int Logger::Buffer::flushBuffer()
{
int num = (int)(pptr()-pbase());
/*if(cout.write(buffer, num) != num)
{
return EOF;
}*/
#if (defined WIN10_BUILD) || (defined WIN32)