S3GE Console: Creating a Sphere on the fly.
There are many ways you could go about it. I'll tell you how I do it. S3GE uses
LUA for all scripting
and a home-grown GUI System which uses a Markup Language (S3GXL) to create Gizmos such as a Textboxes, Buttons, etc:
<!-- Engine Console -->
<gadget name="console">
<gizmo name="consolemaster" description="Show/Hide Console" collision="1" operate="1" transit="1" active="1" audio="1" visible="1">
<variable name="spritex" value="0"/>
<variable name="toggle" value="0"/>
<orientate ref="worldboundbottom" width="16" height="48" yalign="top">
<physics noresponse="true"/>
</orientate>
<event state="IDLE" behavior="pushbox" transition="xshift" scheme="pointingFX" theme="graybox" style="standard" caption=">" xalign="center" yalign="middle"/>
<event state="ENTER"/>
<event state="HOVER" scheme="pointingFX"/>
<event state="DOWN"/>
<event state="HOLD"/>
<event state="DRAG"/>
<event state="UP" >
<script language="darklua" type="1">
<![CDATA[
uiGizmoToggle = 1 - uiGizmoVariableGet(this, 'toggle')
uiGizmoVariableSet(this, 'toggle', uiGizmoToggle)
msg = uiGizmoMessageCreate()
uiGizmoMessageInsert(msg, MAUI_MSG_TYPE_VALUE, MAUI_MSG_GIZMO_CLOSE + uiGizmoToggle, 0)
uiGizmoMessageSend(msg,'consolemaster',MAUI_MSG_TO_CHILDREN,0)
uiGizmoMessageDestroy(msg)
]]>
</script>
</event>
<event state="EXIT" start="false"/>
</gizmo>
<gizmo name="consolescript" parent="consolemaster" description="S3GE Console: Type in DarkLUA Commands here.">
<orientate ref="consolemaster" width="480" height="48" xalign="right">
<physics noresponse="true"/>
</orientate>
<variable name="linecount" value="2"/>
<variable name="1" value="testobjectID = 1000"/>
<variable name="2" value="dbObjectSphereMake(testobjectID,10)"/>
<event state="IDLE" behavior="textbox" transition="ghostly" theme="notepadder" style="textboxtypeset" scheme="pointingFX" xalign="center" yalign="middle"/>
<event state="ENTER"/>
<event state="HOVER" scheme="pointingFX"/>
<event state="DOWN"/>
<event state="HOLD"/>
<event state="DRAG"/>
<event state="UP"/>
<event state="EXIT"/>
</gizmo>
<gizmo name="consoleenter" parent="consolemaster" description="Press to Execute Console Commands.">
<variable name="spritex" value="0"/>
<variable name="toggle" value="0"/>
<orientate ref="consolescript" width="92" height="48" xalign="right">
<physics noresponse="true"/>
</orientate>
<event state="IDLE" behavior="pushbox" transition="ghostly" scheme="pointingFX" theme="graybox" style="standard" caption="Enter" xalign="center" yalign="middle"/>
<event state="ENTER" />
<event state="HOVER" theme="goldbox" scheme="pointingFX" caption="Apply"/>
<event state="DOWN" theme="earthbox" caption="Confirm"/>
<event state="HOLD" theme="earthbox" caption="Confirm"/>
<event state="DRAG" theme="cherrybox" caption="Cancel"/>
<event state="UP" theme="earthbox" caption="Commit">
<script language="darklua" type="1">
<![CDATA[
luaScriptExecute('consolescript' ,uiGizmoLinesGet(uiGizmoGet('consolescript')), '')
]]>
</script>
</event>
<event state="EXIT" start="false"/>
</gizmo>
<gizmo name="consoleclear" parent="consolemaster" description="Press to Clear Console Commands.">
<variable name="spritex" value="0"/>
<variable name="toggle" value="0"/>
<orientate ref="consoleenter" width="16" height="48" xalign="right">
<physics noresponse="true"/>
</orientate>
<event state="IDLE" behavior="pushbox" transition="ghostly" scheme="pointingFX" theme="graybox" style="standard" caption="X" xalign="center" yalign="middle"/>
<event state="ENTER" />
<event state="HOVER" theme="cherrybox" scheme="pointingFX"/>
<event state="DOWN" theme="cherrybox"/>
<event state="HOLD" theme="cherrybox"/>
<event state="DRAG" theme="cherrybox"/>
<event state="UP" theme="cherrybox">
<script language="darklua" type="1">
<![CDATA[
uiGizmoVariableSet(uiGizmoGet('consolescript'),'linecount','1')
uiGizmoVariableSet(uiGizmoGet('consolescript'),'1','')
uiGizmoLinesCapture(uiGizmoGet('consolescript'),IDLE)
]]>
</script>
</event>
<event state="EXIT" start="false"/>
</gizmo>
<gizmo name="consoledebug" parent="consolemaster" description="BugLog Enabled">
<variable name="spritex" value="0"/>
<variable name="toggle" value="1"/>
<orientate ref="consoleclear" width="16" height="48" xalign="right">
<physics noresponse="true"/>
</orientate>
<event state="IDLE" behavior="pushbox" transition="ghostly" scheme="pointingFX" theme="graybox" style="standard" caption="1" xalign="center" yalign="middle"/>
<event state="ENTER" />
<event state="HOVER" theme="magicbox" scheme="pointingFX"/>
<event state="DOWN" theme="magicbox"/>
<event state="HOLD" theme="magicbox"/>
<event state="DRAG" theme="magicbox"/>
<event state="UP" theme="magicbox">
<script language="darklua" type="1">
<![CDATA[
uiGizmoToggle = 1 - uiGizmoVariableGet(this, 'toggle')
uiGizmoVariableSet(this, 'toggle', uiGizmoToggle)
uiGizmoPropertySetByEventstate(this,'Caption', uiGizmoToggle, HOVER)
if uiGizmoToggle == 1 then
bugLogEnable()
uiGizmoPropertySet(this,'Description', 'BugLog Enabled')
else
bugLogDisable()
uiGizmoPropertySet(this,'Description', 'BugLog Disabled')
end
uiGizmoCapture(this,HOVER)
]]>
</script>
</event>
<event state="EXIT" start="false"/>
</gizmo>
</gadget>
.
LUA features a fast interpreter for on the fly execution ideal for a console.
You'll have to write glue code to bind LUA to your C++ code, then use a GUI to load and execute LUA text.
inline int darklua_luaScriptExecute(lua_State *L){if(lua_gettop(L) < 3){lua_pushstring(L, "Error! < 3 arguments"); lua_error(L);}DARKLUA_RETURNSTRING(DarkLUA::System::Execute(DARKLUA_STRING(1), DARKLUA_STRING(2), (char*)DARKLUA_STRING(3)).c_str()); return 1;}
I've had to bind 1000s of functions. The current console is very rudimentary, but, at least uses a GUI. There is a little work involved and I'm certain the snippets of code may not make much sense alone.
S3GE source is freely available via SVN.