4
การระบุ 'ประเภท' ของเอนทิตีในระบบส่วนประกอบ - เอนทิตี
หากเอนทิตีไม่มี 'ประเภท' ชัดเจน (เช่นผู้เล่น) และเป็นเพียงชุดของส่วนประกอบฉันจะระบุเอนทิตีที่ระบบของฉันควรและไม่ควรทำงานได้อย่างไร ตัวอย่างเช่นในเกมของพงษ์พายและลูกทั้งคู่ชนกับขอบเขตของหน้าต่าง อย่างไรก็ตามระบบการจัดการการชนของแต่ละระบบจะแตกต่างกันดังนั้นระบบไม่ควรจัดการเอนทิตีที่มีชนิดผิด void PlayerCollisionSystem::update(std::vector<Entity *> entities) { typedef std::vector<Entity *>::iterator EIter; for (EIter i = entities.begin(); i != entities.end(); ++i) { Entity *player = *i; // How do I verify that the entity is a player? // Get relevant components. PositionComponent *position = player->getComponent<PositionComponent>(); VelocityComponent …
10
c++
entity-system