Skip to content

Instantly share code, notes, and snippets.

@kkabdol
kkabdol / winrtlaunch.cpp
Last active January 29, 2016 01:25
Make sure EngineExit() is always called.
int32 GuardedMain( ... )
{
// make sure GEngineLoop::Exit() is always called.
struct EngineLoopCleanupGuard
{
~EngineLoopCleanupGuard()
{
EngineExit();
}
} CleanupGuard;
@kkabdol
kkabdol / IOSAudioDevice.cpp
Last active January 29, 2016 05:16
Returning a reference to a function-local static variable
int32& FIOSAudioDevice::GetSuspendCounter()
{
static int32 SuspendCounter = 0;
return SuspendCounter;
}
void FIOSAudioDevice::ResumeContext()
{
int32& SuspendCounter = GetSuspendCounter();
...
@kkabdol
kkabdol / enumclass.cpp
Last active February 12, 2016 17:01
strongly typed enumerations
enum Animals { Bear, Cat, Chicken };
//enum Birds { Eagle, Duck, Chicken }; // error!
enum class Fruits { Apple, Pear, Orange };
enum class Colours { Blue, White, Orange }; // no problem!
Colours r = Colours::Orange;
// int n = r; // error !
int n = static_cast<int>(r); // OK, n = 2
@kkabdol
kkabdol / weak_ptr_example.cpp
Last active February 12, 2016 16:54
std::weak_ptr
#include <iostream>
#include <memory>
std::weak_ptr<int> gw;
void f()
{
// Has to be copied into a shared_ptr before usage
if (auto spt = gw.lock()) {
std::cout << *spt << "\n";
@kkabdol
kkabdol / pragma_pack.cpp
Last active February 12, 2016 16:55
#pragma pack(1)
#pragma pack(1)
struct s_t { // sizeof s_t = 11
char a; // offset = 0, align = 1
int b; // offset = 1, align = 1
short c; // offset = 5, align = 1
int d; // offset = 7, align = 1
}S;
#pragma pack()
struct s_t { // sizeof s_t = 11
@kkabdol
kkabdol / friendclass.cpp
Last active February 16, 2016 08:04
friend class example
class B {
friend class A;
private:
int i;
};
class A {
public:
A(B b) {
@kkabdol
kkabdol / readinglist.txt
Last active July 16, 2017 05:49
Reading List
------------------------------------------------------------------
Technology
(Ordered by how close to my current task - OpenGL Optimization)
------------------------------------------------------------------
* OpenGL ES 3.0 Programming Guide
* Interactive 3D Graphics : Udacity
+ 3D Math Primer for Graphics and Game Development
+ Computer Graphics - Principles and Practice (Third Edition)
+ Mathematics for 3D Game Programming and Computer Graphics
@kkabdol
kkabdol / mapydeadzone.cpp
Last active March 10, 2016 15:57
Mapping y deadzone for gamepad thumbstick
float Interpolate( float normalizedValue, float begin, float end )
{
// first check input values
assert( normalizedValue >= 0.0f );
assert( normalizedValue <= 1.0f );
assert( end > begin );
return ( normalizedValue * ( end - begin ) ) + begin;
}
@kkabdol
kkabdol / HumanView.h
Last active March 25, 2016 07:34
HumanView
typedef std::list< shared_ptr< IScreenElement > > ScreenElementList;
class HumanView : public IGameView
{
protected:
GameViewI m_ViewId;
optional< ActorId > m_ActorId;
// this CProcessManager is for things like button animations, etc.
CProcessManager * m_pProcessManager;
@kkabdol
kkabdol / excersise-maps.go
Created April 14, 2016 08:02
go langauge exersice
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
ret := map[string]int{}