Skip to content

Commit

Permalink
More things!
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Mar 8, 2019
1 parent 4ccba66 commit a4ae6cf
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
low-level.lisp
static/
2 changes: 1 addition & 1 deletion README.mess
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
This is a wrapper library to allow you to interface with the Valve SteamWorks API.

## Setup
This library does //not// ship the SteamWorks and SteamClient binaries. You must get your own copy from "Valve"(https://partner.steamgames.com/).
This library does //not// ship the SteamWorks and SteamClient binaries. You must get your own copy from "Valve"(https://partner.steamgames.com/). Once you have the SDK, load ``cl-steamworks-generator`` and run the ``setup`` function.

# DON'T LOOK AAAAAAAAAAAAAAAAAAAAAAAAA
28 changes: 0 additions & 28 deletions callback.lisp

This file was deleted.

4 changes: 3 additions & 1 deletion cl-steamworks-generator.asd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
:components ((:file "package")
(:file "generator"))
:depends-on (:yason
:cffi))
:cffi
:pathname-utils
:alexandria))
3 changes: 2 additions & 1 deletion cl-steamworks.asd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
:homepage "https://github.com/Shinmera/cl-steamworks"
:serial T
:components ((:file "package")
(:file "low-level")
(:file "framework")
(:file "wrapper")
(:file "documentation"))
:depends-on (:documentation-utils
:alexandria
:trivial-features
:cffi))
68 changes: 68 additions & 0 deletions framework.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#|
This file is a part of cl-steamworks
(c) 2019 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#

(in-package #:org.shirakumo.fraf.steamworks.cffi)

(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *this* #.(or *compile-file-pathname* *load-pathname*
(error "COMPILE-FILE or LOAD this file.")))
(defvar *static* (make-pathname :name NIL :type NIL :defaults (merge-pathnames "static/" *this*))))

(defparameter calling-convention
#+(and x86 windows) :stdcall
#-(and x86 windows) :cdecl)

(cffi:define-foreign-library steamworks
((:and :darwin :x86)
"libsteam_api.dylib"
:search-path #.(merge-pathnames "osx32/" *static*))
((:and :unix :x86)
"libsteam_api.so"
:search-path #.(merge-pathnames "linux32/" *static*))
((:and :unix :x86-64)
"libsteam_api.so"
:search-path #.(merge-pathnames "linux64/" *static*))
((:and :windows :x86)
"steam_api.dll"
:convention :stdcall
:search-path #.(merge-pathnames "/" *static*))
((:and :windows :x86-64)
"steam_api.dll"
:search-path #.(merge-pathnames "win64/" *static*)))

(cffi:defcstruct callback
(vtable :pointer)
(flags :uint8)
(id :int))

#+windows
(cffi:defcstruct vtable
(b :pointer)
(a :pointer)
(size :pointer))

#-windows
(cffi:defcstruct vtable
(a :pointer)
(b :pointer)
(size :pointer))

(defun maybe-load-low-level (&optional (file (make-pathname :name "low-level" :type "lisp" :defaults *this*)))
(when (probe-file file)
#+asdf
(let ((component (make-instance 'asdf:cl-source-file
:parent (asdf:find-system :cl-steamworks)
:name "low-level"
:absolute-pathname file)))
(asdf:perform 'asdf:compile-op component)
(asdf:perform 'asdf:load-op component))
#-asdf
(load (compile-file file :verbose NIL :print NIL) :verbose NIL :print NIL)
T))

(or (maybe-load-low-level)
(alexandria:simple-style-warning "No low-level file present. Please install the SteamWorks SDK:
Load cl-steamworks-generator and then run (cl-steamworks-generator:setup)"))
45 changes: 38 additions & 7 deletions generator.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
(:export))
(in-package #:org.shirakumo.fraf.steamworks.generator)

(defvar *this* #.(or *compile-file-pathname* *load-pathname*
(error "COMPILE-FILE or LOAD this file.")))

(defvar *standard-low-level-file*
(make-pathname :name "low-level" :type "lisp"
:defaults #.(or *compile-file-pathname* *load-pathname*
(error "COMPILE-FILE or LOAD this file."))))
(make-pathname :name "low-level" :type "lisp" :defaults *this*))

(defvar *extras-file*
(make-pathname :name "extra" :type "json"
:defaults #.(or *compile-file-pathname* *load-pathname*
(error "COMPILE-FILE or LOAD this file."))))
(make-pathname :name "extra" :type "json" :defaults *this*))

(defparameter *c-type-map*
(let ((map (make-hash-table :test 'equalp)))
Expand Down Expand Up @@ -196,7 +195,8 @@

(defun compile-method (method)
(let ((name (format NIL "SteamAPI_~a_~a" (getf method :classname) (getf method :methodname))))
`(cffi:defcfun (,(name (strip-prefixes name "SteamAPI_ISteam" "SteamAPI_")) ,name)
`(cffi:defcfun (,(name (strip-prefixes name "SteamAPI_ISteam" "SteamAPI_")) ,name
:library org.shirakumo.fraf.steamworks.cffi::steamworks)
,(parse-typespec (getf method :returntype))
,@(when (getf method :desc) (list (getf method :desc)))
,@(loop for arg in (getf method :params)
Expand Down Expand Up @@ -260,3 +260,34 @@
(read-steam-api-spec source)))
:output output
:if-exists if-exists))

(defun query-directory ()
(format *query-io* "~&~%Please enter the path to the SteamWorks SDK root directory:~%> ")
(let ((path (read-line *query-io*)))
(when (string/= "" path)
(parse-namestring
(if (find (char path (1- (length path))) "\\/")
path
(format NIL "~a~c" path #+windows #\\ #-windows #\/))))))

(defun copy-directory-contents (source dest)
(dolist (file (directory (merge-pathnames pathname-utils:*wild-file* source)))
(cond ((pathname-utils:directory-p file)
(let ((dest (pathname-utils:subdirectory dest (pathname-utils:directory-name file))))
(ensure-directories-exist dest)
(copy-directory-contents file dest)))
(T
(let ((dest (merge-pathnames (pathname-utils:to-file file) dest)))
(alexandria:copy-file file dest))))))

(defun setup (&optional (sdk-directory (query-directory)))
(when sdk-directory
(format *query-io* "~&Copying binaries...")
(copy-directory-contents
(pathname-utils:subdirectory sdk-directory "redistributable_bin")
(ensure-directories-exist (pathname-utils:subdirectory *this* "static")))
(format *query-io* "~&Generating bindings...")
(generate (make-pathname :name "steam_api"
:type "json"
:defaults (pathname-utils:subdirectory sdk-directory "public" "steam")))
(format *query-io* "~&Done. You can now load cl-steamworks!~%")))
4 changes: 2 additions & 2 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

(defpackage #:cl-steamworks-cffi
(:nicknames #:org.shirakumo.fraf.steamworks.cffi)
(:use #:cl #:cffi)
(:use #:cl)
(:export))

(defpackage #:cl-steamworks
(:nicknames #:org.shirakumo.fraf.steamworks)
(:use #:cl #:cffi)
(:use #:cl)
(:export))

0 comments on commit a4ae6cf

Please sign in to comment.