example 'clog-demo': update to CLOG version 2.2; update CLOG apk demo

This commit is contained in:
pls.153 2025-04-16 18:01:02 +02:00
parent 7c9a9d2b53
commit e98a7ed161
30 changed files with 10673 additions and 10264 deletions

View file

@ -1,7 +1,9 @@
(defsystem :app
:serial t
:depends-on (#-clog-loaded :clog) ; requires this fork: https://github.com/pls153/clog
;; requires this CLOG fork: https://gitlab.com/eql/clog-for-mobile/-/blob/main/clog-2.2.tgz
:depends-on (#-clog-loaded :clog)
:components ((:file "lisp/package")
(:file "lisp/ini")
(:file "lisp/ui-vars")
(:file "lisp/swank-quicklisp")
(:file "lisp/eval")

View file

@ -69,6 +69,8 @@ android {
QT += androidextras
}
ANDROID_MIN_SDK_VERSION = 21
ANDROID_TARGET_SDK_VERSION = 34
ANDROID_EXTRA_LIBS += $$ECL/lib/libecl.so
ANDROID_PACKAGE_SOURCE_DIR = ../platforms/android

View file

@ -4,9 +4,12 @@
(in-package :clog-demo-1)
(defparameter *app-mode* nil
"Run application once and shutdown")
;; Game Display
(defconstant display-width 300)
(defconstant display-height 450)
(defconstant display-width 375)
(defconstant display-height 375)
;; Snake Parameters
(defconstant initial-length 5)
@ -51,7 +54,8 @@
(setf (hiddenp splash) t)))
(defun local-file (file)
(format nil "file://~A" (merge-pathnames file)))
#+android file
#-android (format nil "file://~A" (merge-pathnames (x:cc "static-files/" file))))
(defun paint (body cx app)
(let ((game-over nil)
@ -83,34 +87,34 @@
(>= (* (car head-cell) segment-size) display-width)
(>= (* (cadr head-cell) segment-size) display-height)
(self-collision))
(fill-style cx :red)
(font-style cx "bold 20px sans-serif")
(setf (fill-style cx) :red
(font-style cx) "bold 20px sans-serif")
(fill-text cx "GAME OVER" 30 30)
(play-media (create-audio body
:source (local-file "htm/demo/game-over.wav")
:source (local-file "demo/game-over.wav")
:controls nil))
(setf game-over t))
(t
(fill-style cx :purple)
(setf (fill-style cx) :purple)
(push head-cell (snake app))
(dolist (cell (snake app))
(draw-segment cell))
(fill-style cx :white)
(setf (fill-style cx) :white)
(cond ((equal head-cell (food app))
(fill-text cx (format nil "Score: ~A" (score app))
5 (- display-height 15))
(setf (score app) (+ (score app) 10))
(fill-style cx :green)
(setf (fill-style cx) :green)
(fill-text cx (format nil "Score: ~A" (score app))
5 (- display-height 15))
(play-media (create-audio body
:source (local-file "htm/demo/eat.wav")
:source (local-file "demo/eat.wav")
:controls nil))
(setf (food app) (new-food)))
(t
(draw-segment (car (last (snake app))))
(setf (snake app) (butlast (snake app)))))
(fill-style cx :brown)
(setf (fill-style cx) :brown)
(draw-segment (food app))))
game-over)))
@ -160,8 +164,8 @@
(dotimes (n initial-length)
(push (list n 0) (snake app)))
(setf context (create-context2d disp))
(font-style context "normal 20px sans-serif")
(fill-style context :green)
(setf (font-style context) "normal 20px sans-serif"
(fill-style context) :green)
(fill-text context (format nil "Score: ~A" (score app))
5 (- display-height 15))
(set-on-key-down body #'on-key-down :disable-default t)
@ -170,7 +174,7 @@
(set-on-click up-btn #'on-click)
(set-on-click down-btn #'on-click)
(play-media (create-audio body
:source (local-file "htm/demo/start.wav")
:source (local-file "demo/start.wav")
:controls nil))
;; Game loop
(loop

File diff suppressed because one or more lines are too long

View file

@ -1 +0,0 @@
(defsystem :mgl-pax)

View file

@ -8,8 +8,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/boot.js" type="text/javascript"></script>
<noscript><%= (@ meta) %></noscript>
</HEAD>
<BODY>
<noscript><%= (@ body) %></noscript>
</BODY>
<noscript>Your browser must support JavaScript and be HTML 5 compilant to see this site.</noscript>
</HTML>

View file

@ -1,9 +1,21 @@
var _ws;
var adr;
var _ws=null;
var adr; var adrc;
var clog={};
var pingerid;
var retryid;
var s = document.location.search;
var tokens;
var r = /[?&]?([^=]+)=([^&]*)/g;
var ios = false;
clog['body']=document.body;
clog['head']=document.head;
clog['documentElement']=document.documentElement;
clog['window']=window;
clog['navigator']=navigator;
clog['document']=window.document;
clog['location']=window.location;
if (typeof clog_debug == 'undefined') {
clog_debug = false;
}
@ -52,48 +64,38 @@ function Setup_ws() {
}
}
var rc = function (event) {
console.log (event);
clearInterval (retryid);
_ws = null;
_ws = new WebSocket (adr + '?r=' + clog['connection_id']);
_ws.onopen = function (event) {
console.log ('reconnect successful');
Setup_ws();
}
_ws.onclose = function (event) {
console.log ('reconnect failure');
console.log (Date.now());
retryid = setInterval(function () {rc("Failed reconnect - trying again")}, 500);
}
}
_ws.onerror = function (event) {
console.log ('onerror: reconnect');
_ws = null;
_ws = new WebSocket (adr + '?r=' + clog['connection_id']);
_ws.onopen = function (event) {
console.log ('onerror: reconnect successful');
Setup_ws();
rc("onerror - trying reconnect")
}
_ws.onclose = function (event) {
console.log ('onerror: reconnect failure');
Shutdown_ws(event);
}
}
_ws.onclose = function (event) {
console.log ('onclose: reconnect');
_ws = null;
_ws = new WebSocket (adr + '?r=' + clog['connection_id']);
_ws.onopen = function (event) {
console.log ('onclose: reconnect successful');
Setup_ws();
}
_ws.onclose = function (event) {
console.log ('onclose: reconnect failure');
if (event.code && event.code === 1000) {
console.log("WebSocket connection got normal close from server. Don't reconnect.");
Shutdown_ws(event);
} else {
rc("onclose - trying reconnnect");
}
}
}
$( document ).ready(function() {
var s = document.location.search;
var tokens;
var r = /[?&]?([^=]+)=([^&]*)/g;
clog['body']=document.body;
clog['head']=document.head;
clog['documentElement']=document.documentElement;
clog['window']=window;
clog['navigator']=navigator;
clog['document']=window.document;
clog['location']=window.location;
function Open_ws() {
/*
if (location.protocol == 'https:') {
adr = 'wss://' + location.hostname;
@ -108,12 +110,16 @@ $( document ).ready(function() {
if (ios) {
adr = 'ws://127.0.0.1:8080';
if (clog['connection_id']) {
adrc = adr + '?r=' + clog['connection_id'];
} else { adrc = adr }
try {
console.log ('connecting to ' + adr);
_ws = new WebSocket (adr);
console.log ('connecting to ' + adrc);
_ws = new WebSocket (adrc);
} catch (e) {
console.log ('trying again, connecting to ' + adr);
_ws = new WebSocket (adr);
console.log ('trying again, connecting to ' + adrc);
_ws = new WebSocket (adrc);
}
if (_ws != null) {
@ -123,8 +129,11 @@ $( document ).ready(function() {
}
pingerid = setInterval (function () {Ping_ws ();}, 10000);
} else {
document.writeln ('If you are seeing this your browser or your connection to the internet is blocking web_wss.');
document.writeln ('If you are seeing this your browser or your connection to the internet is blocking websockets.');
}
}
}
});
$( document ).ready(function() {
if (_ws == null) { Open_ws(); }
});

File diff suppressed because one or more lines are too long

View file

@ -1 +0,0 @@
clog-assets/htm

View file

@ -4,7 +4,7 @@
(setf clog-connection::*send-to-webview*
#+ios (lambda (js) (qml:qjs |send| ui:*server* js))
#-ios (lambda (js) (qml:q! |runJavaScript| ui:*browser* js)))
#-ios (lambda (js) (qml:q! |runJavaScript| ui:*browser* js nil)))
(defun webview/on-new-connection ()
(clog-connection::handle-new-connection 'qml-webview nil))
@ -12,11 +12,9 @@
(defun webview/on-message (message)
(clog-connection::handle-message 'qml-webview message))
(defun webview/on-close ()
(clog-connection::handle-close-connection 'qml-webview))
(defun boot ()
(qml:q> |url| ui:*browser* (format nil "file://~A"
(merge-pathnames "htm/boot.html"))))
(qml:q> |url| ui:*browser*
#+android "file:///android_asset/lib/static-files/boot.html"
#-android (format nil "file://~A" (merge-pathnames "static-files/boot.html"))))
(export 'boot)

View file

@ -0,0 +1,22 @@
(in-package :qml)
(export
(list #+android '*shell-output*
#+android 'shell))
;;; add function 'shell' (android only)
#+android
(defvar *shell-output* nil)
#+android
(defun shell (command)
"Run shell commands; example:
(shell \"df -h\")"
(let ((s (ext:run-program "sh" (list "-c" command))))
(setf *shell-output*
(loop :for line = (read-line s nil nil)
:while line :collect line)))
(princ (x:join *shell-output* #\Newline))
(values))

View file

@ -2,9 +2,7 @@
(:use :cl :qml)
(:export))
;;; hack, loads empty systems to suppress ASDF runtime error "system not found"
;; hack, loads empty system to suppress ASDF runtime error "system not found"
(progn
(push *default-pathname-defaults* asdf:*central-registry*)
(asdf:load-system :mgl-pax)
(asdf:load-system :clog))

View file

@ -41,12 +41,12 @@
"/lib/ecl-*/")))
(shell (cc "cp " lib "*.doc " *assets*))
(shell (cc "cp -r " lib "encodings " *assets*))))
(shell (cc "rm -r " *assets* "htm/*")) ; may have changed
(shell (cc "cp -r ../clog-assets/htm " *assets*))
(shell (cc "rm -r " *assets* "static-files/*")) ; may have changed
(shell (cc "cp -r ../clog-assets/static-files " *assets*))
(shell (cc "cp -r ../clog-assets/*.asd " *assets*)))
#+ios
(with-open-file (s (merge-pathnames "htm/js/boot.js" *assets*)
(with-open-file (s (merge-pathnames "static-files/js/boot.js" *assets*)
:direction :output :if-exists :append)
(write-line "ios = true;" s))

View file

@ -10,10 +10,22 @@
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="CLOG demo" android:extractNativeLibs="true" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="CLOG demo" android:screenOrientation="unspecified" android:launchMode="singleTop" android:exported="true">
<application
android:hardwareAccelerated="true"
android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:label="CLOG demo"
android:extractNativeLibs="true"
android:icon="@drawable/icon"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:name="org.qtproject.qt5.android.bindings.QtActivity"
android:label="CLOG demo"
android:screenOrientation="unspecified"
android:launchMode="singleTop"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Before After
Before After

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">org.lqml.example.clog</domain>
</domain-config>
</network-security-config>

View file

@ -1,3 +1,4 @@
;;; define here how to load eventual, not yet installed dependencies
;;; (for cross-compiling only)
(ql:quickload :clog) ; requires this fork: https://github.com/pls153/clog
(ql:quickload :clog) ; requires this fork: https://gitlab.com/eql/clog-for-mobile/-/blob/main/clog-2.2.tgz

View file

@ -35,11 +35,9 @@ Item {
Button {
id: reload
anchors.bottom: parent.bottom
font.pixelSize: 18
text: "Reload"
onClicked: {
if (Qt.platform.os !== "ios") {
Lisp.call("clog:webview/on-close")
}
browser.reload()
}
}
@ -47,6 +45,7 @@ Item {
Button {
anchors.bottom: parent.bottom
anchors.right: parent.right
font.pixelSize: 18
text: "log/REPL"
onClicked: view.currentIndex = 1
}

View file

@ -11,6 +11,7 @@ Item {
z: 1
Text {
font.pixelSize: 18
text: "REPL"
anchors.verticalCenter: show.verticalCenter
visible: !show.checked

View file

@ -37,9 +37,6 @@ Item {
default: return
}
main.log("[status] " + state)
if (status === WebSocket.Closed) {
Lisp.call("clog:webview/on-close")
}
})
}

View file

@ -1,4 +1,4 @@
*This example is outdated and not really useful anymore, sorry.*
*This example has been updated in 2025 to CLOG version 2.2.*
Try it
@ -23,7 +23,7 @@ for installing the Slime sources where this example can find them.
**Important**: you need to put this fork of CLOG in your
`~/quicklisp/local-projects/` directory:
[CLOG for mobile](https://github.com/pls153/clog).
[CLOG for mobile](https://gitlab.com/eql/clog-for-mobile/-/blob/main/clog-2.2.tgz).
If you want to run this example on the desktop, you need to uncomment the Qt
WebEngine dependency in [../../src/lqml.pro](../../src/lqml.pro) and rebuild

View file

@ -0,0 +1 @@
clog-assets/static-files