Add optimized mode to custom params. Ownership of shared pointers
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
dba7479803
commit
7276e3cff3
Binary file not shown.
57
main.cpp
57
main.cpp
@ -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:
|
int data=4;
|
||||||
Example()
|
~C2(){
|
||||||
{
|
printf("C2 destroyed\n");
|
||||||
sAppName = "Example";
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
class C1{
|
||||||
std::unordered_map<int,Block> Blocks;
|
public:
|
||||||
bool OnUserCreate() override
|
~C1(){
|
||||||
{
|
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();
|
|
||||||
|
|
||||||
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
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…
x
Reference in New Issue
Block a user