Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问题:有关于多个相同的Object #7

Open
EveSunMaple opened this issue Feb 11, 2024 · 3 comments
Open

问题:有关于多个相同的Object #7

EveSunMaple opened this issue Feb 11, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@EveSunMaple
Copy link
Owner

现在每次调用新建都不得不重读文件,太慢了,需要预加载!
如:

// 发射子弹,father 中有需要的内容
BaseObject* NewBullet(BaseObject* father, const std::string& name)
{
    // 问题->
    Json::Value objectData = readJsonFromFile(BULLETS);
    const Json::Value object = objectData["bullets"][name];
    if (object == NULL) return nullptr;
    BaseObject* newObject = new BaseObject(5, false, nullptr, spriteMap[name], nullptr, nullptr, false);
    // sprite
    float fireSpeed = father->variable["fireSpeed"];
    float fireAngle = father->variable["fireAngle"];
    newObject->mass = object["sprite"]["mass"].asFloat();
    newObject->health = object["sprite"]["health"].asFloat();
    newObject->maxSpeed = object["sprite"]["maxSpeed"].asFloat();
    newObject->maxSpeedAngle = object["sprite"]["maxSpeedAngle"].asFloat();
    newObject->friction = object["sprite"]["friction"].asFloat();
    newObject->frictionAngle = object["sprite"]["frictionAngle"].asFloat();
    newObject->angle = father->angle + RandomNumber(-fireAngle, fireAngle);
    float Angle = Remainder(newObject->angle, 360) * (float)acos(-1) / 180;
    newObject->speedX = father->speedX + fireSpeed * sin(Angle);
    newObject->speedY = father->speedX + fireSpeed * cos(Angle);
    newObject->x = father->x;
    newObject->y = father->y;
    // variable
    newObject->variable["rotateAcceleration"] = object["sprite"]["rotateAcceleration"].asFloat();
    newObject->variable["forceAcceleration"] = object["sprite"]["forceAcceleration"].asFloat();
    newObject->variable["maxForce"] = object["sprite"]["maxForce"].asFloat();
    newObject->variable["liftTime"] = object["sprite"]["maxForce"].asFloat();
    // collisionBox
    for (const Json::Value point : object["collisionBox"])
        easy2d::Point(point[0].asFloat(), point[1].asFloat());
    newObject->Init(); // 初始化
    
    return newObject;
}

在下个dev提交修改

@EveSunMaple EveSunMaple added the enhancement New feature or request label Feb 11, 2024
@EveSunMaple EveSunMaple self-assigned this Feb 11, 2024
@EveSunMaple
Copy link
Owner Author

已在6ed3d6c提交中解决此问题

@EveSunMaple
Copy link
Owner Author

重新启用BaseObject复制函数,所有文件应该在启动前读完,Json::Value也必须在加载之后销毁

@EveSunMaple EveSunMaple reopened this Feb 13, 2024
@EveSunMaple
Copy link
Owner Author

已在6ed3d6c提交中解决此问题

此条作废

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant