source: trunk/src/tiler.cpp @ 222

Last change on this file since 222 was 222, checked in by sam, 11 years ago

Add support for rotated views and stretched tiles.

  • Property svn:keywords set to Id
File size: 1.3 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 "core.h"
16
17/*
18 * Tiler implementation class
19 */
20
21static class TilerData
22{
23    friend class Tiler;
24
25public:
26    Dict tilesets;
27}
28tilerdata;
29
30static TilerData * const data = &tilerdata;
31
32/*
33 * Public Tiler class
34 */
35
36int Tiler::Register(char const *path, int w, int h, float dilate)
37{
38    int id = data->tilesets.MakeSlot(path);
39
40    if (!data->tilesets.GetEntity(id))
41    {
42        TileSet *tileset = new TileSet(path, w, h, dilate);
43        data->tilesets.SetEntity(id, tileset);
44    }
45
46    return id + 1; /* ID 0 is for the empty tileset */
47}
48
49void Tiler::Deregister(int id)
50{
51    data->tilesets.RemoveSlot(id - 1); /* ID 0 is for the empty tileset */
52}
53
54void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
55{
56    int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */
57
58    TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
59    tileset->BlitTile(code & 0xffff, x, y, z, o);
60}
61
Note: See TracBrowser for help on using the repository browser.