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. 53
      main.cpp
  3. 2
      sig

Binary file not shown.

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

2
sig

@ -3,7 +3,7 @@ export AUTO_UPDATE=true
source utils/define.sh source utils/define.sh
define PROJECT_NAME "C++ProjectTemplate" 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++" define LANGUAGE "C++"
source utils/main.sh source utils/main.sh

Loading…
Cancel
Save