赞
踩
运行在VS2022,x86,Debug下。
// 物理引擎子系统 class PhysicsSystem { public: void init() { cout << "Initializing physics engine..." << endl;} void update() { cout << "Updating physics..." << endl; } }; //渲染子系统 class GraphicsSystem { public: void init() { cout << "Initializing graphics..." <<endl; } void render() { cout << "Rendering graphics..." << endl;} }; //粒子子系统 class ParticleSystem { public: void init() { cout << "Initializing particle..." << endl; } void createParticle() { cout << "Creating particle..." << endl; } }; //游戏引擎外观 class GameEngineFacade { private: PhysicsSystem* physics; GraphicsSystem* graphics; ParticleSystem* particle; GameEngineFacade() //私有构造函数 { physics = new PhysicsSystem(); graphics = new GraphicsSystem(); particle = new ParticleSystem(); } ~GameEngineFacade() //私有析构函数 { if (physics) { delete physics; physics = nullptr; } if (graphics) { delete graphics; graphics = nullptr; } if (particle) { delete particle; particle = nullptr; } } GameEngineFacade(const GameEngineFacade&) = delete; //删除拷贝构造函数 GameEngineFacade& operator=(const GameEngineFacade&) = delete; //删除赋值运算符 GameEngineFacade(GameEngineFacade&&) = delete; //删除移动构造函数 GameEngineFacade& operator=(GameEngineFacade&&) = delete; //删除移动赋值运算符 public: static GameEngineFacade* getInstance() //静态函数,获取实例 { static GameEngineFacade instance; //局部静态变量,存储实例 return &instance; } void initGame() { graphics->init(); physics->init(); particle->init(); } void updateGame() { physics->update(); particle->createParticle(); } void renderGame() { graphics->render(); } }; int main() { GameEngineFacade* gameEngine = GameEngineFacade::getInstance(); gameEngine->initGame(); gameEngine->updateGame(); }
反汇编分析,子系统资源创建到释放过程
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。