The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
id.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "log.hpp"
16 #include "units/id.hpp"
17 
18 #include <cassert>
19 
20 static lg::log_domain log_unit("unit");
21 #define DBG_UT LOG_STREAM(debug, log_unit)
22 
23 namespace n_unit
24 {
26 
27  id_manager::id_manager() : next_id_(0), fake_id_(0)
28  {}
29 
31  {
33  DBG_UT << "id: " << next_id_ << "\n";
34  return unit_id::create_real(++next_id_);
35  }
36 
38  {
40  DBG_UT << "fake id: " << fake_id_ << "\n";
41  return unit_id::create_fake(++fake_id_);
42  }
43 
44  size_t id_manager::get_save_id() const
45  {
46  return next_id_;
47  }
48 
49  void id_manager::set_save_id(size_t id)
50  {
51  clear();
52  DBG_UT << "set save id: " << id << "\n";
53  next_id_ = id;
54  }
55 
57  {
58  fake_id_ = 0;
59  }
60 
62  {
63  next_id_ = 0;
64  reset_fake();
65  }
66 }
static unit_id create_real(size_t val)
Definition: id.hpp:35
unit_id next_fake_id()
Definition: id.cpp:37
#define DBG_UT
Definition: id.cpp:21
size_t get_save_id() const
Used for saving id to savegame.
Definition: id.cpp:44
unit_id next_id()
returns id for unit that is created
Definition: id.cpp:30
Definition: id.cpp:23
void set_save_id(size_t)
Definition: id.cpp:49
GLuint id
Definition: glew.h:1647
void clear()
Clears id counter after game.
Definition: id.cpp:61
size_t fake_id_
Definition: id.hpp:49
static id_manager manager_
Definition: id.hpp:50
static lg::log_domain log_unit("unit")
Standard logging facilities (interface).
static unit_id create_fake(size_t val)
Definition: id.hpp:36
void reset_fake()
Definition: id.cpp:56
size_t next_id_
Definition: id.hpp:48
static const size_t highest_bit
Definition: id.hpp:29