Skip to content

Instantly share code, notes, and snippets.

@kkabdol
kkabdol / volatile.cpp
Last active July 15, 2016 05:40
volatile keyword
void main()
{
// 'non_volatile_int == 1' will be optimized to be 'true' by compiler
int non_volatile_int = 1;
while( non_volatile_int == 1 /* true */ )
{
// code
}
// 'volatile_int == 1' won't be optimized by compiler
@kkabdol
kkabdol / mutable_practice.cpp
Last active October 22, 2016 08:49
mutable keyword
#include <iostream>
using std::cout;
using std::endl;
static int SomeDataSource = 100;
class LazyFetching
{
public:
LazyFetching() : m_pDataSource( nullptr ) {}
@kkabdol
kkabdol / overeager_evaluation.cpp
Last active November 9, 2016 06:10
over-eager evaluation
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct Employee {
string m_name;
int m_cubicleNumber;
};
@kkabdol
kkabdol / accessmodifiers.cpp
Created November 9, 2016 09:28
Access Modifiers
// From Kirill V. Lyadvinsky
// http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance
class A
{
public:
int x;
protected:
int y;
private:
@kkabdol
kkabdol / .gitignore
Created November 11, 2016 07:04 — forked from tokineco/.gitignore
Cocos2d-x v3.x .gitignore
# OSX - https://github.com/github/gitignore/blob/master/Global/OSX.gitignore
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
// lamda example
void lamdaA ( cocos2d::Node* node )
{
auto button = node->getChildByName< cocos2d::ui::Button* >( "Button_team" );
if( button )
{
button->addTouchEventListener( [ = ]( cocos2d::Ref*, cocos2d::ui::Widget::TouchEventType type ) {
if( type == cocos2d::ui::Widget::TouchEventType::ENDED ) {
// do something
}
@kkabdol
kkabdol / cocos2dx_touchevent.cpp
Last active January 4, 2017 08:01
cocos2d touch event
#include "cocos2d.h"
void SomeNode::setup() {
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2( SomeNode::onTouchBegan, this );
listener->onTouchEnded = CC_CALLBACK_2( SomeNode::onTouchEnded, this );
dispatcher->addEventListenerWithSceneGraphPriority( listener, this );
}
@kkabdol
kkabdol / cocos_CCDownloader.cpp
Last active January 12, 2017 02:48
Code Reading
std::shared_ptr<const DownloadTask> Downloader::createDownloadDataTask(const std::string& srcUrl, const std::string& identifier/* = ""*/)
{
DownloadTask *task_ = new DownloadTask();
std::shared_ptr<const DownloadTask> task(task_);
do
{
task_->requestURL = srcUrl;
task_->identifier = identifier;
if (0 == srcUrl.length())
{
void AssetsManager::downloadAndUncompress()
{
std::thread([this]()
{
do
{
// Uncompress zip file.
if (! uncompress())
{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{
@kkabdol
kkabdol / shared_ptr_inheritance_test.cpp
Last active January 16, 2017 10:07
Smart Pointers
#include <iostream>
#include <memory>
using namespace std;
class MusicProduct {
public:
MusicProduct() {}
virtual void play() const = 0;
virtual void displayTitle() const = 0;
};