HomeWildfire Games

Simplify GUI Proxy implementation & customisation.

Description

Simplify GUI Proxy implementation & customisation.

This finishes rP24229 and rP24384.
GUI Proxy objects are now easier to specialize, code duplication is reduced, code is made safer.
In details:

  • the proxy private is always the IGUIObject* pointer
  • the private data is accessed through a safer wrapper
  • CreateJSObject returns an opaque type to allow easier extension & prevent errors.
  • The implementation of CreateJSObject is moved near the GUI Proxy template instantiation, and both are wrapped in a convenient macro (this makes it so that if you use the macro, you can't forget to overload the method, and vice-versa).
  • The common IGUIObject JS interface no longer needs to be repeated.
  • All specialisations are again put in the same file, for improved compile-time & clarity, given there are so few lines now.
  • While at it, implement toSource which makes it possible to uneval components (does the same as toString though).

Differential Revision: https://code.wildfiregames.com/D3826

Event Timeline

nwtour added a subscriber: nwtour.Apr 10 2021, 11:55 AM

Doesn't compile on my system:

Linking pyrogenesis
g++ -o "../../../binaries/system/pyrogenesis" obj/pyrogenesis_Release/main.o    -L../../../binaries/system -L../../../libraries/source/spidermonkey/lib -L../../../libraries/source/nvtt/lib -Wl,--no-undefined -Wl,--as-needed -Wl,-z,relro -Wl,-rpath,'$ORIGIN' -Wl,--enable-new-dtags -pthread -Wl,--start-group ../../../binaries/system/libmocks_real.a ../../../binaries/system/libnetwork.a ../../../binaries/system/librlinterface.a ../../../binaries/system/libtinygettext.a ../../../binaries/system/liblobby.a ../../../binaries/system/libsimulation2.a ../../../binaries/system/libscriptinterface.a ../../../binaries/system/libengine.a ../../../binaries/system/libgraphics.a ../../../binaries/system/libatlas.a ../../../binaries/system/libgui.a ../../../binaries/system/liblowlevel.a ../../../binaries/system/libmongoose.a -lGL -lSDL2 -lpng16 -lz -lmozjs78-ps-release -lmozjs78-ps-rust -lxml2 -lboost_filesystem-mt -lboost_system-mt -lenet -lcurl -licui18n -licuuc -licudata -lsodium -lfmt -latomic -lX11 -lnvcore -lnvmath -lnvimage -lnvtt -lrt -ldl -Wl,--end-group
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_GUIProxy.o): in function `JSI_GUIProxy<CButton>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)':
/usr/include/fmt/printf.h:228: multiple definition of `JSI_GUIProxy<CButton>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)'; ../../../binaries/system/libgui.a(JSInterface_CButton.o):/usr/include/fmt/format.h:2344: first defined here
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_GUIProxy.o): in function `JSI_GUIProxy<CText>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)':
/usr/include/fmt/core.h:1060: multiple definition of `JSI_GUIProxy<CText>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)'; ../../../binaries/system/libgui.a(JSInterface_CText.o):/usr/include/fmt/format.h:2344: first defined here
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_GUIProxy.o): in function `JSI_GUIProxy<CList>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)':
/usr/include/fmt/core.h:1060: multiple definition of `JSI_GUIProxy<CList>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)'; ../../../binaries/system/libgui.a(JSInterface_CList.o):/usr/include/fmt/format.h:2344: first defined here
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_GUIProxy.o): in function `JSI_GUIProxy<IGUIObject>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)':
/usr/include/fmt/printf.h:232: multiple definition of `JSI_GUIProxy<IGUIObject>::CreateFunctions(ScriptRequest const&, GUIProxyProps*)'; ../../../binaries/system/libgui.a(JSInterface_IGUIObject.o):/usr/include/fmt/format.h:2459: first defined here
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CButton.o): in function `bool JSInterface_GUIProxy::apply_to<CButton, CButton, &CButton::getTextSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `CButton::getTextSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CButton.o): in function `bool JSInterface_GUIProxy::apply_to<CButton, IGUIObject, &IGUIObject::getComputedSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::getComputedSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CButton.o): in function `bool JSInterface_GUIProxy::apply_to<CButton, IGUIObject, &IGUIObject::blur>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::blur(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CButton.o): in function `bool JSInterface_GUIProxy::apply_to<CButton, IGUIObject, &IGUIObject::focus>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::focus(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CButton.o): in function `bool JSInterface_GUIProxy::apply_to<CButton, IGUIObject, &IGUIObject::toString>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::toString(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CList.o): in function `bool JSInterface_GUIProxy::apply_to<CList, IGUIObject, &IGUIObject::getComputedSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::getComputedSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CList.o): in function `bool JSInterface_GUIProxy::apply_to<CList, IGUIObject, &IGUIObject::blur>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::blur(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CList.o): in function `bool JSInterface_GUIProxy::apply_to<CList, IGUIObject, &IGUIObject::focus>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::focus(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CList.o): in function `bool JSInterface_GUIProxy::apply_to<CList, IGUIObject, &IGUIObject::toString>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::toString(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CText.o): in function `bool JSInterface_GUIProxy::apply_to<CText, CText, &CText::getTextSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `CText::getTextSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CText.o): in function `bool JSInterface_GUIProxy::apply_to<CText, IGUIObject, &IGUIObject::getComputedSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::getComputedSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CText.o): in function `bool JSInterface_GUIProxy::apply_to<CText, IGUIObject, &IGUIObject::blur>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::blur(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CText.o): in function `bool JSInterface_GUIProxy::apply_to<CText, IGUIObject, &IGUIObject::focus>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::focus(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_CText.o): in function `bool JSInterface_GUIProxy::apply_to<CText, IGUIObject, &IGUIObject::toString>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::toString(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_IGUIObject.o): in function `bool JSInterface_GUIProxy::apply_to<IGUIObject, IGUIObject, &IGUIObject::getComputedSize>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::getComputedSize(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_IGUIObject.o): in function `bool JSInterface_GUIProxy::apply_to<IGUIObject, IGUIObject, &IGUIObject::blur>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::blur(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_IGUIObject.o): in function `bool JSInterface_GUIProxy::apply_to<IGUIObject, IGUIObject, &IGUIObject::focus>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::focus(ScriptInterface&, JS::MutableHandle<JS::Value>)'
/usr/bin/ld.default: ../../../binaries/system/libgui.a(JSInterface_IGUIObject.o): in function `bool JSInterface_GUIProxy::apply_to<IGUIObject, IGUIObject, &IGUIObject::toString>(JSContext*, unsigned int, JS::Value*)':
/home/nwtour/ff/0ad/build/workspaces/gcc/../../../source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::toString(ScriptInterface&, JS::MutableHandle<JS::Value>)'
collect2: error: ld returned 1 exit status

@nwtour: can you be sure to make clean & delete compilation artifacts such as already-compiled static libraries?
I'm saying that because this

source/gui/Scripting/JSInterface_GUIProxy_impl.h:59: undefined reference to `IGUIObject::toString(ScriptInterface&, JS::MutableHandle<JS::Value>)'

Sounds impossible - there's no reference to such a function in the committed code.

(feel free to come by on IRC if needed)

can you be sure to make clean & delete compilation artifacts such as already-compiled static libraries?

@wraitii False alarm. Cleaning solved this errors. Thanks

That broke --without-pch.