Skip to content

Commit fd5ea13

Browse files
committed
gamestate: Reserve some game entity IDs for internal use.
This allows using 0 in the ID texture as respresentation for "no entity".
1 parent 2f0e318 commit fd5ea13

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

libopenage/gamestate/entity_factory.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ std::shared_ptr<activity::Activity> create_test_activity() {
110110
}
111111

112112
EntityFactory::EntityFactory() :
113-
next_entity_id{0},
114-
next_player_id{0},
115113
render_factory{nullptr} {
116114
}
117115

libopenage/gamestate/entity_factory.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2024 the openage authors. See copying.md for legal info.
1+
// Copyright 2023-2025 the openage authors. See copying.md for legal info.
22

33
#pragma once
44

@@ -118,13 +118,17 @@ class EntityFactory {
118118

119119
/**
120120
* ID of the next game entity to be created.
121+
*
122+
* IDs 0-99 are reserved.
121123
*/
122-
entity_id_t next_entity_id;
124+
entity_id_t next_entity_id = 100;
123125

124126
/**
125127
* ID of the next player to be created.
128+
*
129+
* ID 0 is reserved.
126130
*/
127-
player_id_t next_player_id;
131+
player_id_t next_player_id = 1;
128132

129133
/**
130134
* Factory for creating connector objects to the renderer which make game entities displayable.

libopenage/gamestate/event/drag_select.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
1+
// Copyright 2023-2025 the openage authors. See copying.md for legal info.
22

33
#include "drag_select.h"
44

@@ -32,7 +32,7 @@ void DragSelectHandler::invoke(openage::event::EventLoop & /* loop */,
3232
const param_map &params) {
3333
auto gstate = std::dynamic_pointer_cast<openage::gamestate::GameState>(state);
3434

35-
size_t controlled_id = params.get("controlled", 0);
35+
auto controlled_id = params.get<player_id_t>("controlled", 0);
3636

3737
Eigen::Matrix4f id_matrix = Eigen::Matrix4f::Identity();
3838
Eigen::Matrix4f cam_matrix = params.get("camera_matrix", id_matrix);

libopenage/gamestate/event/spawn_entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void SpawnEntityHandler::invoke(openage::event::EventLoop & /* loop */,
193193
}
194194

195195
// Create entity
196-
player_id_t owner_id = params.get("owner", 0);
196+
auto owner_id = params.get<player_id_t>("owner", 0);
197197
auto entity = this->factory->add_game_entity(this->loop, gstate, owner_id, nyan_entity);
198198

199199
// Setup components

libopenage/input/controller/game/controller.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424

2525
namespace openage::input::game {
2626

27-
Controller::Controller(const std::unordered_set<size_t> &controlled_factions,
28-
size_t active_faction_id) :
27+
Controller::Controller(const std::unordered_set<gamestate::player_id_t> &controlled_factions,
28+
gamestate::player_id_t active_faction_id) :
2929
controlled_factions{controlled_factions},
3030
active_faction_id{active_faction_id},
3131
outqueue{} {}
3232

33-
void Controller::set_control(size_t faction_id) {
33+
void Controller::set_control(gamestate::player_id_t faction_id) {
3434
std::unique_lock lock{this->mutex};
3535

3636
if (this->controlled_factions.find(faction_id) != this->controlled_factions.end()) {
3737
this->active_faction_id = faction_id;
3838
}
3939
}
4040

41-
size_t Controller::get_controlled() const {
41+
gamestate::player_id_t Controller::get_controlled() const {
4242
std::unique_lock lock{this->mutex};
4343

4444
return this->active_faction_id;

libopenage/input/controller/game/controller.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class Controller : public std::enable_shared_from_this<Controller> {
4646
* @param controlled_factions Factions that can be managed by the controller.
4747
* @param active_faction_id Current active faction ID.
4848
*/
49-
Controller(const std::unordered_set<size_t> &controlled_factions,
50-
size_t active_faction_id);
49+
Controller(const std::unordered_set<gamestate::player_id_t> &controlled_factions,
50+
gamestate::player_id_t active_faction_id);
5151

5252
~Controller() = default;
5353

@@ -57,7 +57,7 @@ class Controller : public std::enable_shared_from_this<Controller> {
5757
*
5858
* @param faction_id ID of the new active faction.
5959
*/
60-
void set_control(size_t faction_id);
60+
void set_control(gamestate::player_id_t faction_id);
6161

6262
/**
6363
* Get the ID of the faction actively controlled by the controller.
@@ -133,12 +133,12 @@ class Controller : public std::enable_shared_from_this<Controller> {
133133
/**
134134
* Factions controllable by this controller.
135135
*/
136-
std::unordered_set<size_t> controlled_factions;
136+
std::unordered_set<gamestate::player_id_t> controlled_factions;
137137

138138
/**
139139
* ID of the currently active faction.
140140
*/
141-
size_t active_faction_id;
141+
gamestate::player_id_t active_faction_id;
142142

143143
/**
144144
* Currently selected entities.

libopenage/presenter/presenter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ void Presenter::init_input() {
244244
log::log(INFO << "Loading game simulation controls");
245245

246246
// TODO: Remove hardcoding for controlled/active factions
247-
std::unordered_set<size_t> controlled_factions{0, 1, 2, 3};
248-
size_t active_faction_id = 0;
247+
std::unordered_set<gamestate::player_id_t> controlled_factions{1, 2, 3, 4};
248+
gamestate::player_id_t active_faction_id = 1;
249249
auto game_controller = std::make_shared<input::game::Controller>(
250250
controlled_factions, active_faction_id);
251251

0 commit comments

Comments
 (0)