You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,13 @@ Contributing code
9
9
10
10
*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.
11
11
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:
13
13
14
14
-*src/__module__/ext.cpp* (C++) - functions that interact with C++ SFML objects but expose a pure C interface
15
15
-*src/__module__/lib.cr* (Crystal) - definition of the header file for Crystal
-*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.
19
19
20
20
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).
Copy file name to clipboardExpand all lines: README.md
+72-62Lines changed: 72 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Indeed, SFML is most often used to make video games. It provides features such a
29
29
30
30
### Differences between SFML and CrSFML
31
31
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:
33
33
34
34
- Methods are renamed to `snake_case`.
35
35
- 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+
49
49
Installation
50
50
------------
51
51
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:
53
55
54
56
```yaml
55
57
name: awesome-game
@@ -66,40 +68,40 @@ Resolve dependencies with [Shards]:
66
68
shards install
67
69
```
68
70
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).
70
72
71
-
### Prerequisites
73
+
Try running an example:
72
74
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
+
```
74
79
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]**!
76
81
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
79
83
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].
81
85
82
-
### Install SFML
86
+
### Prerequisites
83
87
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).
85
89
86
-
SFML versions 2.3.x through 2.5.x are supported by *CrSFML*.
90
+
#### Install SFML
87
91
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*.
89
93
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.
91
95
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).
93
97
94
-
Building SFML from source is as simple as downloading the source code and running:
98
+
##### Linux
95
99
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).
101
103
102
-
#### Mac
104
+
#####Mac
103
105
104
106
The easiest way to install SFML on macOS is through the [Homebrew] package manager:
105
107
@@ -108,35 +110,29 @@ brew update
108
110
brew install sfml
109
111
```
110
112
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].
112
114
113
-
###Generating sources
115
+
##### Windows
114
116
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].
116
118
117
-
As this is out of scope for [Shards], let's download the repository separately.
119
+
##### From source
118
120
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:
125
122
126
123
```bash
127
-
touch generate.cr
128
-
make
124
+
cmake .
125
+
cmake --build .
126
+
sudo make install # optional!
129
127
```
130
128
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].
134
130
135
-
####Custom SFML location
131
+
### Custom SFML location
136
132
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.
138
134
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:
Setting these variables beforehand can also fix `shards install`.
146
+
149
147
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:
150
148
151
149
```bash
@@ -158,39 +156,46 @@ set LIB=%LIB%;c:\path\to\sfml\lib
158
156
set PATH=%PATH%;c:\path\to\sfml\bin
159
157
```
160
158
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)).
162
166
163
167
```bash
164
-
cd examples
165
-
crystal snakes.cr
168
+
git clone https://github.com/oprypin/crsfml
169
+
cd crsfml
166
170
```
167
171
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:
171
173
172
174
```bash
173
-
cd~/my-project
174
-
mkdir lib
175
-
ln -s /full/path/to/crsfml/src lib/crsfml
175
+
touch generate.cr
176
+
make
176
177
```
177
178
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.
179
184
180
185
```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
183
188
```
184
189
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.
186
191
187
192
188
193
Credits
189
194
-------
190
195
191
196
*CrSFML* was made by [Oleh Prypin][oprypin].
192
197
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.
194
199
195
200
This library uses and is based on [SFML][sfml-authors].
196
201
@@ -200,10 +205,12 @@ Thanks to [Alan Willms][alanwillms] for translating [tutorials] to Crystal.
200
205
About the SFML wrapper
201
206
----------------------
202
207
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).
204
209
205
210
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).
206
211
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
+
207
214
### Why not CSFML?
208
215
209
216
[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
217
224
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.
0 commit comments