Archive

Archive for 11.05.2011

Building SFML 2.0

11.05.2011 7 comments
Note: this tutorial is deprecated. Please take a look at one of my new ones, either for Visual C++/NMake (Windows), MinGW (Windows) or GCC/Make (Ubuntu/other Unix).

To set up SFML 2.0, there are a number of steps. If you want, you can watch SFML 2.0 build video for Code::Blocks, or for Visual Studio.



Otherwise, I shall outline the necessary steps here, before providing a few more details where necessary.

  1. Download CMake from the website, or go straight to the download page.
  2. Download the SFML 2.0 source, unzip the file, move it to an accessible location and rename the folder.
  3. Create a solution file for your IDE using CMake, setting BUILD_SHARED_LIBS to TRUE.
  4. Take note of the value of STATIC_STD_LIBS, as you must link the C runtime to your project in the same manner as it is linked to the SFML binaries
  5. Open the solution file in your IDE and build SFML 2.0 in Debug and Release configuration (if your IDE supports multiple configurations).
  6. Repeat steps 3 & 4, with BUILD_SHARED_LIBS set to false.
  7. If your IDE does not support multiple configurations, repeat steps 3 – 5, setting.
  8. Copy and paste the resulting libraries to a better location: put them all in a lib subdirectory of your main SFML 2 directory: c:/sfml/sfml2.
    Read more…

Introduction to Resource Management

So what is the idea behind resource management? Well we’re writing a game, which as software goes, has rather a lot of resources to be managed. Textures. Models. Sounds. Music. Player save files. It seems to me that we have three options, and here they are in order of increasing usefulness.

1. Manage all resources as we go: if we need an image, type all the loading code for an image; if we need another, type it again. This is the easiest solution, and might be fine for small projects. But since we’re trying to write a reusable engine which is hopefully applicable to larger projects, it just won’t do. (Also, we’d have to be very careful to be sure we unloaded all the resources at the end when we’re done with them.)

2. Write manager classes: one to manager images, one to manage sounds and so forth. Clearly, this is better than option 1. We can save on typing by putting the loading code into a reusable member function. We can also add some nice extras like prevention of multiple loading of the same resource,  referring to resources by string IDs, and automatic unloading of resources at shutdown time.

3. Number 2 is nice, but there’s still some code redundancy remaining. What’s the difference between managing sound resources and image resources? Just the loading (and unloading) process. All management that goes on in between is pretty much the same. Thus our final option: a generic resource manager – a single class which can be used for managing images, sounds, music, you name it! If it can be loaded and unloaded, our manager will handle it!

In fact, there are going to be several resource managers, since I have two designs in mind, along with a subtle tweak to one of them. But more of that in the next post: for now I just wanted you to know the motivation for generic resource management methods.

There’s one other thing I just want to remark on now: the structure of my posts regarding each engine component. For each one, I shall release the following components in this order:

  1. An article discussing the features of the component, without any actual code
  2. A “code summary” post showing some or all of the header file for the class, to demonstrate its intended public interface
  3. An “implementation” post in which I not only provide all the code, but also detailed descriptions as to how it works
  4. A “usage” post, with a simple (but often contrived) example to show you how I intend the component to be used
  5. A “testing/debugging” post in which we write another sample which tests the component’s behaviour in every different situation we can think of
  6. A “samples” post in which I give some more useful examples of usage
  7. A summary post, with a brief textual summary of the component’s purpose, plus a copy of it’s public interface
That’s all for now. The next post on resource management will be an article on my first resource management construct, but before then there might be some posts about video tutorials and setting up SFML 2.0 in various IDES.
Follow

Get every new post delivered to your Inbox.

Join 40 other followers