Add optimized mode to custom params. Ownership of shared pointers

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent dba7479803
commit 7276e3cff3
  1. BIN
      C++ProjectTemplate
  2. 57
      main.cpp
  3. 2
      sig

Binary file not shown.

@ -1,37 +1,40 @@
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include <unordered_map>
#include "Block.h"
#include <memory>
#include <stdio.h>
class Example : public olc::PixelGameEngine
{
public:
Example()
{
sAppName = "Example";
class C2{
public:
int data=4;
~C2(){
printf("C2 destroyed\n");
}
};
public:
std::unordered_map<int,Block> Blocks;
bool OnUserCreate() override
{
// Called once at the start, so create things here
Blocks[126]=Block(25,10,255,255,255);
return true;
class C1{
public:
~C1(){
printf("C1 destroyed\n");
}
bool OnUserUpdate(float fElapsedTime) override
{
return true;
void PrintData(std::weak_ptr<C2>ptr) {
printf("Data is %d\n",ptr.lock()->data);
}
};
int main()
{
Example demo;
if (demo.Construct(256, 240, 4, 4))
demo.Start();
int main(){
std::shared_ptr<C1> ptrA{std::make_shared<C1>()};
return 0;
std::weak_ptr<C1>ptrA_2=ptrA;
if (!ptrA_2.expired()) {
printf("Count:%ld",ptrA.use_count());
std::shared_ptr<C1> ptrA_3{ptrA};
printf("Inside if statement.\n");
std::shared_ptr<C2> ptrB{std::make_shared<C2>()};
ptrA_2.lock()->PrintData(ptrB);
printf("Count:%ld",ptrA.use_count());
}
printf("Count:%ld",ptrA.use_count());
printf("Outside if statement.\n");
return -1;
}

2
sig

@ -3,7 +3,7 @@ export AUTO_UPDATE=true
source utils/define.sh
define PROJECT_NAME "C++ProjectTemplate"
define CUSTOM_PARAMS "-std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs -lpulse -lpulse-simple"
define CUSTOM_PARAMS "-std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs -lpulse -lpulse-simple -O3 -s -DNDEBUG"
define LANGUAGE "C++"
source utils/main.sh

Loading…
Cancel
Save