source: trunk/src/tiler.cpp @ 418

Last change on this file since 418 was 418, checked in by sam, 10 years ago

Fix a coding error in the null tiler detection.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16
17#include "core.h"
18
19/*
20 * Tiler implementation class
21 */
22
23static class TilerData
24{
25    friend class Tiler;
26
27public:
28    TilerData()
29#if !FINAL_RELEASE
30      : lasterror(-1)
31#endif
32    { }
33
34private:
35    Dict tilesets;
36#if !FINAL_RELEASE
37    int lasterror;
38#endif
39}
40tilerdata;
41
42static TilerData * const data = &tilerdata;
43
44/*
45 * Public Tiler class
46 */
47
48int Tiler::Register(char const *path, int w, int h, float dilate)
49{
50    int id = data->tilesets.MakeSlot(path);
51
52    if (!data->tilesets.GetEntity(id))
53    {
54        TileSet *tileset = new TileSet(path, w, h, dilate);
55        data->tilesets.SetEntity(id, tileset);
56#if !FINAL_RELEASE
57        if (id == data->lasterror)
58            data->lasterror = -1;
59#endif
60    }
61
62    return id + 1; /* ID 0 is for the empty tileset */
63}
64
65void Tiler::Deregister(int id)
66{
67    data->tilesets.RemoveSlot(id - 1); /* ID 0 is for the empty tileset */
68}
69
70void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
71{
72    int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */
73
74    TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
75#if !FINAL_RELEASE
76    if (!tileset)
77    {
78        if (id != data->lasterror)
79            fprintf(stderr, "ERROR: blitting to null tiler #%i\n", id);
80        data->lasterror = id;
81        return;
82    }
83#endif
84    tileset->BlitTile(code & 0xffff, x, y, z, o);
85}
86
Note: See TracBrowser for help on using the repository browser.