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

Enhancement engine py version api #578

Conversation

BenjamenMeyer
Copy link
Member

Thank you for submitting a pull request and becoming a contributor to the Vega Strike Core Engine.

Please answer the following:

Code Changes:

Issues:

Purpose:

  • Centralizes the VS Engine Version data to the CMake Files and exports it via a C/C++ Header for consumption
  • Add a new Engine Asset API Version for easy compatibility determination, much like the API Version in Google Android
  • Integrate the Version Data into an object that can be read by the Python game assets

NOTE: The Python side presently does not work. This needs to be figured out before I can release the PR.
NOTE: This will need to get ported to 0.8.x before #349 is closed.

- CMake controls the version information, export it via a
  configurable header(s).
- Display the version information from the version header when
  using `--help`
- Show the version information from the version header in the setup
  tooling
Introduce an Assets API version similar to the Google Android
API Version. It's a simple single value that increments when the
API is changed and can increment indepent of the engine version.

This allows the Assets API to change slightly even between minor
releases, or not change at all across major releases, and to
communicate that via a simple mechanism.
Initial pass as integrating the API version data into the Python API.
A basic test show's it's not working as intended as the object
on `VS` returns `None`.
@BenjamenMeyer
Copy link
Member Author

NOTE: My tests for the Python side is simple:

  • Start Python3 with the Engine path in its module search where it's possible to import VS
  • Inspect the VS object under the Python Debugger UI'
  • Try to access the new object and its methods under the Python Debugger

@stephengtuggy
Copy link
Contributor

I think you have to actually have the Engine (C++ code) running, and execute Python code from within it, for the VS object to be visible. Hence, I put my test code under engine/src/python/init.cpp, just before the VegaStrikeLogging::VegaStrikeLogger::FlushLogs(); line near the end of the file. The code I added is:

    const std::string python_snippet_to_run{"import VS\nprint(VS.EngineVersionData().GetVersion())"};
    PyRun_SimpleString(python_snippet_to_run.c_str());
    Python::reseterrors();

I also changed engine/src/python/unit_wrapper.cpp, line 188, to read:

PYTHON_BEGIN_CLASS( VS, VegaStrike::EngineVersionData, "EngineVersionData")

instead of

PYTHON_BEGIN_CLASS( VS, VegaStrike::EngineVersionData, "Version")

And it worked! I was able to retrieve a 4-tuple containing the engine version (0, 9, 0, 'a6c15fe40'), and output it to the console, using that Python print statement.

@BenjamenMeyer
Copy link
Member Author

@stephengtuggy thanks... I did add something to the Assets, but it was getting a None so was trying a few other ways to do so as well.

@BenjamenMeyer
Copy link
Member Author

BenjamenMeyer commented Oct 6, 2021

UPDATE: Figured it out. The VS.EngineVersionData needed to be called as a function itself as opposed to a property; there was also an issue with the the string formatting. Fixed it.

I made your change, and I can get the same response within the engine itself like you got:

SIMULATION_ATOM: 0.01
log directory : '/home/bmeyer/.vegastrike/logs'
['/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload']
['', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/builtin', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/quests', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/missions', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/ai', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules', '/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/bases', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload']
(0, 9, 0, 'd958fdff1')
Processing technique techniques/fixed.technique
Processing tag technique
Fallback is fixed5

However, the goal is to get it to operate from the Game Assets. So I applied the following diff to the Asset Productions:

Assets-Production$ git diff
diff --git a/modules/GUI.py b/modules/GUI.py
index 9a26d0b5..d40c3a8c 100644
--- a/modules/GUI.py
+++ b/modules/GUI.py
@@ -354,6 +354,11 @@ class GUIRoot:
         self.needRedraw = {}
         self.modalElement = None
         self.keyTarget = None
+
+        trace(_GUITraceLevel, "::: What's in VS object %s :::" %(dir(VS)))
+        trace(_GUITraceLevel, "::: Engine Version %s :::" %(VS.EngineVersionData.GetVersion()))
+        trace(_GUITraceLevel, "::: Asset API Version %s :::" %(VS.EngineVersionData.GetAssetAPIVersion()))
+
         Base.GlobalKeyPython('#\nfrom GUI import GUIRootSingleton\nGUIRootSingleton.keyEvent()\n')
 
     def setScreenDimensions(self,screenX,screenY):

And I end up with the following stack trace a little further down in the game console output:

Traceback (most recent call last):
  File "main_menunightprivateer.py", line 30, in <module>
  File "/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/GUI.py", line 448, in GUIInit
    GUIRootSingleton = GUIRoot(screenX,screenY,marginX,marginY,**kwargs)
  File "/home/bmeyer/Devel/opensource/vegastrike/assets/Assets-Production/modules/GUI.py", line 359, in __init__
    trace(_GUITraceLevel, "::: Engine Version %s :::" %(VS.EngineVersionData.GetVersion()))
Boost.Python.ArgumentError: Python argument types in
    None.GetVersion()
did not match C++ signature:
    GetVersion(VegaStrike::EngineVersionData {lvalue})

- Thanks @stephengtuggy for the final bits
- Rename `Version` to `EngineVersion`
- Generate an output of the version data from within the engine
@BenjamenMeyer BenjamenMeyer marked this pull request as ready for review October 6, 2021 05:55
@stephengtuggy
Copy link
Contributor

The Windows CI is failing on this line:

#include <unistd.h>

in engineVersion.h.

This header file is not available on Windows. Is there another header file you can use instead, @BenjamenMeyer ?

@BenjamenMeyer
Copy link
Member Author

@stephengtuggy yeah, really meant stdint.h ... hopefully that'll fix the CI issues.

@BenjamenMeyer BenjamenMeyer merged commit 0afad6d into vegastrike:master Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants