cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

Issues templating python class derived from a C++ class

Open rsa16 opened this issue 2 years ago • 3 comments

So, I'm creating bindings for a library I wrote in C++ in python, and I rewrote my C++ example testing the use of the library in python, however, it seems that cppyy is having trouble templating python classes. Are there any pythonizations I need to perform to get this to work correctly?

Here is the code:

from skaia.components import Transform, Sprite, Input
from skaia.core import Coordinator, System
import skaia
import cppyy.ll

coordinator = Coordinator()

class PlayerMovement(System):
    def __init__(self, c: Coordinator):
        self.coordinator = c
        
        signature = skaia.Signature()
        signature.set(self.coordinator.GetComponentType[Input]())
        self.coordinator.SetSystemSignature[PlayerMovement](signature)

        super().__init__()

    def Initialize(self, data):
        print("Player movement system initialized!")

    def Render(self):
        pass

    def Cleanup(self):
        pass

    def Update(self):
        for entity in self.mEntities:
            entityInput = self.coordinator.GetComponent[Input](entity)
            entityTransform = self.coordinator.GetComponent[Transform](entity)

            if (entityInput.UP_PRESSED):
                entityTransform.y -= 10

            if (entityInput.DOWN_PRESSED):
                entityTransform.y += 10
            
            if (entityInput.RIGHT_PRESSED):
                entityTransform.x += 10

            if (entityInput.LEFT_PRESSED):
                entityTransform.x -= 10

def main():
    print("Creating game application...")
    game = skaia.GameApplication(coordinator, "Test", 500, 600)

    print("Tracking our custom system and turning on our fps counter")
    game.TrackSystem[PlayerMovement]() # give the game our player movement system
    game.SetCounterOn() # turn on fps counter

    print("Fps counter turned on, creating entities")
    player = coordinator.CreateEntity() # skaia.Entity
    coordinator.AddComponent(player, Transform(
        x = (500 / 2) - (100 / 2), # place in horizontal center
        y = (600 / 2) - (100 / 2), # place in vertical center,
        width = 100,
        height = 100
    ))

    coordinator.AddComponent(player, Sprite(
        color = (0, 255, 255)
    ))

    coordinator.AddComponent(player, Input())
    print("Components added, starting game")

    game.Start()

if __name__ == "__main__":
    main()

I get some kind of warning on game.TrackSystem[PlayerMovement](), but I'm not really sure what it means.

IncrementalExecutor::executeFunction: symbol '??$_Construct_in_place@VDispatcher1@__cppyy_internal@@AEAPEAVCoordinator@Core@Skaia@@@std@@YAXAEAVDispatcher1@__cppyy_internal@@AEAPEAVCoordinator@Core@Skaia@@@Z' unresolved while linking symbol '__cf_9'!
You are probably missing the definition of void __cdecl std::_Construct_in_place<class __cppyy_internal::Dispatcher1,class Skaia::Core::Coordinator * __ptr64 & __ptr64>(class __cppyy_internal::Dispatcher1 & __ptr64,class Skaia::Core::Coordinator * __ptr64 & __ptr64)
Maybe you need to load the corresponding shared library?

If anyone could help that would be appreciated.

rsa16 avatar Mar 14 '23 18:03 rsa16

This is Windows, right? I've been having trouble with some STL classes (in particular algorithms) where Cling (or Clang, rather) is not correctly mangling the names when doing symbol lookups. This could be one more of these.

wlav avatar Mar 14 '23 20:03 wlav

Yeah, this is Windows.

rsa16 avatar Mar 14 '23 22:03 rsa16

So uh, is there a fix?

rsa16 avatar Mar 26 '23 18:03 rsa16