los-cocos / cocos

graphic library for games and multimedia, for python language on PC-like hardware
http://los-cocos.github.io/cocos-site/
Other
632 stars 146 forks source link

Make it possible to create CocosNodes without initialising the director #331

Closed MartinHowarth closed 4 years ago

MartinHowarth commented 4 years ago

This is to allow non-gui testing of cocosnode functionaliy (and subclasses in downstream users code).

I've got a PR for this, will update momentarily.

ccanepa commented 4 years ago

One way to test without gui is the one used in repo\utest, have you seen that?

Your proposed change, make camera a property lazy initialized, is not complex, but will add a call in each cocosnode when the scene draws. And calls are relativelly costly in python.

What if in your testing situation you do

class FakeCamera:
  pass

import cocos.camera
cocos.camera.camera = FakeCamera

or similar?

MartinHowarth commented 4 years ago

Ok, you're right to be concerned about performance for such a core component - I'll just mock it out instead.