Skip to content

Commit 22766dd

Browse files
committed
Update instructions
1 parent d7ef625 commit 22766dd

File tree

4 files changed

+75
-66
lines changed

4 files changed

+75
-66
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
!.gitattributes
55
!*.yml
66
!*.md
7-
!LICENSE
87
!Makefile
98

109
!/generate.cr

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Contributing code
99

1010
*CrSFML* consists mostly of automatically generated code. The generator program ([*generate.cr*](generate.cr)), the static parts of *CrSFML* and the build files (CMake) are the main components to edit.
1111

12-
In addition to these, each SFML "module" has 4 files generated for it:
12+
In addition to these, each SFML "module" has 3 files generated for it:
1313

1414
- *src/__module__/ext.cpp* (C++) - functions that interact with C++ SFML objects but expose a pure C interface
1515
- *src/__module__/lib.cr* (Crystal) - definition of the header file for Crystal
1616
- *src/__module__/obj.cr* (Crystal) - object-oriented wrappers
17-
<!-- -->
18-
- *src/__module__/__module__.cr* files are tiny additions that can't be automatically generated, but they serve as the entry point for each module.
17+
18+
*src/__module__/__module__.cr* files are tiny additions that can't be automatically generated, but they serve as the entry point for each module.
1919

2020
Most of the changes to *CrSFML* will happen within one file, [*generate.cr*](generate.cr). It is indeed a very complicated and messy program. The main idea is to parse SFML's header files with... regular expressions (yes, I'm very happy with this decision, it works out nicely due to the extreme quality and consistency of SFML), form an object-based model of the constructs, and use them to render 3 files per module (as seen above).
2121

LICENSE renamed to LICENSE.md

File renamed without changes.

README.md

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Indeed, SFML is most often used to make video games. It provides features such a
2929

3030
### Differences between SFML and CrSFML
3131

32-
The API of *CrSFML* (a library for Crystal) attempts to be similar to SFML (a C++ library), but some general changes are present:
32+
The [API of *CrSFML*][api documentation] (a library for Crystal) attempts to be similar to SFML (a C++ library), but some general changes are present:
3333

3434
- Methods are renamed to `snake_case`.
3535
- Getter, setter methods are changed:
@@ -49,7 +49,9 @@ The API of *CrSFML* (a library for Crystal) attempts to be similar to SFML (a C+
4949
Installation
5050
------------
5151

52-
Create a _shard.yml_ file in your project's folder (or add to it) with the following contents:
52+
First, [install SFML](#install-sfml).
53+
54+
Then create a _shard.yml_ file in your project's folder (or add to it) with the following contents:
5355

5456
```yaml
5557
name: awesome-game
@@ -66,40 +68,40 @@ Resolve dependencies with [Shards]:
6668
shards install
6769
```
6870

69-
During installation this will invoke `make` to build the C++ wrappers as object files.
71+
During installation this will invoke `make` to build the C++ wrappers as object files. If that fails, see [Custom SFML location](#custom-sfml-location).
7072

71-
### Prerequisites
73+
Try running an example:
7274

73-
The C++ wrappers require a C++ compiler (C++03 will do).
75+
```bash
76+
cp lib/crsfml/examples/snakes.cr .
77+
crystal snakes.cr
78+
```
7479

75-
[SFML] must be [installed](#install-sfml), with the version that matches `SFML_VERSION` in _src/common.cr_ (usually latest). If it doesn't, no need to look for an older release of *CrSFML*, just [re-generate the sources](#generating-sources) for your version.
80+
Now you're ready for the **[tutorials]**!
7681

77-
- Linux note: if you're installing SFML from your distribution's package manager, make sure it is not some old version.
78-
- Mac note: SFML can be installed through [Homebrew].
82+
##### Windows
7983

80-
If SFML is not installed in a global/default location, see [Custom SFML location](#custom-sfml-location)
84+
Crystal does not officially support Windows, but CrSFML supports it and is perfectly usable already. See [a video detailing the full setup][windows-setup].
8185

82-
### Install SFML
86+
### Prerequisites
8387

84-
The first step is to install the [SFML] library itself. There are detailed [official instructions][sfml-install] on how to install it manually, however, on many systems there are easier ways.
88+
The C++ wrappers require a C++ compiler (C++03 will do).
8589

86-
SFML versions 2.3.x through 2.5.x are supported by *CrSFML*.
90+
#### Install SFML
8791

88-
#### Linux
92+
[SFML] must be installed, with the version that matches `SFML_VERSION` in [src/version.cr](src/version.cr) (usually latest). If it doesn't, no need to look for an older release of *CrSFML*, just [re-generate the sources](#generating-sources) for your version. SFML versions 2.3.x through 2.5.x are supported by *CrSFML*.
8993

90-
Many Linux-based systems provide SFML through their package manager. Make sure to install the *-dev* packages if there is such a separation in your Linux distribution of choice.
94+
There are detailed [official instructions][sfml-install] on how to install SFML manually, but on many systems there are easier ways.
9195

92-
Note that most often the packages provided by Linux distributions are outdated. If you're installing an older version of SFML (not recommended), make sure that it's still [supported by *CrSFML*](#install-sfml). You will need to [re-generate the sources](#generating-sources).
96+
If SFML is not installed in a global/default location, see [Custom SFML location](#custom-sfml-location).
9397

94-
Building SFML from source is as simple as downloading the source code and running:
98+
##### Linux
9599

96-
```bash
97-
cmake .
98-
cmake --build
99-
sudo make install # optional!
100-
```
100+
Many Linux-based systems provide SFML through their package manager. Make sure to install the *-dev* packages if there is such a separation in your Linux distribution of choice.
101+
102+
Note that most often the packages provided by Linux distributions are outdated. If you're installing an older version of SFML (not recommended), make sure that it's still [supported by *CrSFML*](#install-sfml). You will need to [re-generate the sources](#generating-sources).
101103

102-
#### Mac
104+
##### Mac
103105

104106
The easiest way to install SFML on macOS is through the [Homebrew] package manager:
105107

@@ -108,35 +110,29 @@ brew update
108110
brew install sfml
109111
```
110112

111-
It can also be installed by copying binaries, as described in [official instructions][sfml-install], or by building from source in the same way as [on Linux](#linux).
113+
It can also be installed by copying binaries, as described in [official instructions][sfml-install].
112114

113-
### Generating sources
115+
##### Windows
114116

115-
CrSFML's sources come almost entirely from a [generator program](generate.cr). They are based on a particular version of SFML. But as sources for the latest version are already bundled, usually you don't need to do this. [More details](CONTRIBUTING.md).
117+
Downloading [the official binaries][sfml-download] ("Visual C++ 15 (2017) - 64-bit") will do. Check out [the video on how to set things up on Windows][windows-setup].
116118

117-
As this is out of scope for [Shards], let's download the repository separately.
119+
##### From source
118120

119-
```bash
120-
git clone https://github.com/oprypin/crsfml
121-
cd crsfml
122-
```
123-
124-
Then we can generate the sources, either directly with `crystal generate.cr` or as part of the build process:
121+
Building SFML from source is as simple as downloading the source code and running:
125122

126123
```bash
127-
touch generate.cr
128-
make
124+
cmake .
125+
cmake --build .
126+
sudo make install # optional!
129127
```
130128

131-
If run successfully, this generates all the source files and also compiles the C++ wrapper.
132-
133-
If SFML can't be found, see the next section.
129+
In some cases the dependencies are bundled with SFML, otherwise see the [official build instructions][sfml-build].
134130

135-
#### Custom SFML location
131+
### Custom SFML location
136132

137-
If SFML's headers and libraries are not in a path where the compiler would look by default, additional steps are needed.
133+
If SFML's headers and libraries are not in a path where the compiler would look by default (and the defaults usually work only on Linux), additional steps are needed.
138134

139-
First, before building the extensions, you need to configure the path
135+
First, before building the extensions (`make`) or generating sources, you need to configure the include path:
140136

141137
```bash
142138
export SFML_INCLUDE_DIR=/full/path/to/sfml/include
@@ -146,6 +142,8 @@ Windows equivalent:
146142
set INCLUDE=%INCLUDE%;C:\path\to\sfml\include
147143
```
148144

145+
Setting these variables beforehand can also fix `shards install`.
146+
149147
Then, whenever using *CrSFML*, you need to configure the path to SFML libraries so the linker can find them. To apply these for the current shell session, run:
150148

151149
```bash
@@ -158,39 +156,46 @@ set LIB=%LIB%;c:\path\to\sfml\lib
158156
set PATH=%PATH%;c:\path\to\sfml\bin
159157
```
160158

161-
Now try running an example:
159+
CrSFML's top-level scripts also need the include path to work. E.g. `crystal generate.cr -- /full/path/to/sfml/include`.
160+
161+
### Generating sources
162+
163+
CrSFML's sources come almost entirely from a [generator program](generate.cr). They are based on a particular version of SFML. But as sources for the latest version are already bundled, usually you don't need to do this. [More details](CONTRIBUTING.md).
164+
165+
As this is out of scope for [Shards], let's download the repository separately (then use CrSFML [without Shards](#crsfml-without-shards)).
162166

163167
```bash
164-
cd examples
165-
crystal snakes.cr
168+
git clone https://github.com/oprypin/crsfml
169+
cd crsfml
166170
```
167171

168-
#### Make CrSFML available to your project
169-
170-
Create a symbolic link to *CrSFML* in your project's *lib* folder.
172+
Then we can generate the sources, either directly with `crystal generate.cr` or as part of the build process:
171173

172174
```bash
173-
cd ~/my-project
174-
mkdir lib
175-
ln -s /full/path/to/crsfml/src lib/crsfml
175+
touch generate.cr
176+
make
176177
```
177178

178-
Try using it:
179+
If run successfully, this generates all the source files and also compiles the C++ wrapper.
180+
181+
### CrSFML without Shards
182+
183+
It's also possible to use *CrSFML* outside of Shards, as with any library. One option is to directly create a symbolic link to *CrSFML* in your project's *lib* folder.
179184

180185
```bash
181-
echo 'require "crsfml"' >> awesome_game.cr
182-
crystal awesome_game.cr
186+
mkdir lib
187+
ln -s /full/path/to/crsfml lib/crsfml
183188
```
184189

185-
Now you're ready for the [tutorials]!
190+
Another option is to `export CRYSTAL_PATH=/full/path/to` a directory that contains the *crsfml* directory.
186191

187192

188193
Credits
189194
-------
190195

191196
*CrSFML* was made by [Oleh Prypin][oprypin].
192197

193-
*CrSFML* is [licensed](LICENSE) under the terms and conditions of the *zlib/libpng* license.
198+
*CrSFML* is [licensed](LICENSE.md) under the terms and conditions of the *zlib/libpng* license.
194199

195200
This library uses and is based on [SFML][sfml-authors].
196201

@@ -200,10 +205,12 @@ Thanks to [Alan Willms][alanwillms] for translating [tutorials] to Crystal.
200205
About the SFML wrapper
201206
----------------------
202207

203-
The C++ → C wrapper's external interface consists entirely of simple functions that accept only native types (such as `float`, `uint32_t`, `char*`) and untyped pointers (`void*`). The function names consist of the original SFML class name, the function name itself, and a base62 hash of the parameter types. The user of the library is expected to know the size of the buffers needed for each object, because VoidCSFML does not allocate memory for them. Initialization is done in a buffer supplied by the user. Return types are never used; instead, the output is done into a pointer (which is usually the last argument of the function), but, as usual, the memory allocation is the caller's job. The first argument of each function is a pointer to the receiver object (if applicable).
208+
The C++ → C wrapper's external interface consists entirely of simple functions that accept only native types (such as `float`, `uint32_t`, `char*`) and untyped pointers (`void*`). The untyped pointers are never exposed to the user, only to other auto-generated parts of the code. The function names consist of the original SFML class name, the function name itself, and a base62 hash of the parameter types. Return types are never used; instead, the output is done into a pointer (which is usually the last argument of the function), but, as usual, the memory allocation is the caller's job. The first argument of each function is a pointer to the receiver object (if applicable).
204209

205210
Abstract classes are implemented by exposing a collection of global callback variables, which must be set by the user if they want to use the corresponding class. The callback's first argument is the object, and some arguments are pointers that need to be assigned to inside the callback implementation (because return values are not used).
206211

212+
Compilation of the C++ extensions is based only on SFML's header files, these are made into object files, and all the linking is deferred to the final linker invocation done by Crystal.
213+
207214
### Why not CSFML?
208215

209216
[CSFML] is a great library that allows SFML to be used with C. It goes to great lengths to be human-friendly and does a good job of converting C++ idioms to C idioms. In the past *CrSFML* used to be based on it, but after a while it became apparent that the advantages of CSFML's nice interface are also disadvantages when constructing (especially auto-generated) bindings that attempt to look as close to the real SFML as possible.
@@ -217,19 +224,22 @@ Instead of that, the C++ → C wrapper passes the bare SFML data types directly
217224
Not to forget that the wrapper is made automatically, so it can be quickly updated to any SFML release and prevents human error that could happen when implementing CSFML.
218225

219226

220-
[tutorials]: http://oprypin.github.io/crsfml/tutorials/
221-
[api documentation]: http://oprypin.github.io/crsfml/api/
222-
[releases]: https://github.com/oprypin/crsfml/releases
227+
[tutorials]: https://oprypin.github.io/crsfml/tutorials/
228+
[api documentation]: https://oprypin.github.io/crsfml/api/
223229
[demos]: https://github.com/oprypin/crsfml-examples
224230

225-
[sfml]: http://www.sfml-dev.org/ "Simple and Fast Multimedia Library"
231+
[windows-setup]: https://pryp.in/blog/28/running-crystal-natively-on-windows-building-videogame-examples.html
232+
233+
[sfml]: https://www.sfml-dev.org/ "Simple and Fast Multimedia Library"
226234
[csfml]: https://github.com/SFML/CSFML
227235
[sfml-authors]: https://github.com/SFML/SFML#readme
228-
[sfml-install]: http://www.sfml-dev.org/tutorials/
236+
[sfml-download]: https://www.sfml-dev.org/download.php
237+
[sfml-install]: https://www.sfml-dev.org/tutorials/
238+
[sfml-build]: https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php
229239

230-
[homebrew]: http://brew.sh/
240+
[homebrew]: https://brew.sh/
231241

232-
[crystal]: http://crystal-lang.org/
242+
[crystal]: https://crystal-lang.org/
233243
[shards]: https://github.com/crystal-lang/shards
234244

235245
[oprypin]: https://github.com/oprypin

0 commit comments

Comments
 (0)