Skip to content

Commit 0d3cfdc

Browse files
committed
gamestate: Make a lookup function for next comand switching.
1 parent 6e62921 commit 0d3cfdc

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_sources(libopenage
22
command_in_queue.cpp
3+
next_command_switch.cpp
34
next_command.cpp
45
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2024-2024 the openage authors. See copying.md for legal info.
2+
3+
#include "next_command_switch.h"
4+
5+
#include "gamestate/component/internal/command_queue.h"
6+
#include "gamestate/game_entity.h"
7+
8+
9+
namespace openage::gamestate::activity {
10+
11+
int next_command_switch(const time::time_t &time,
12+
const std::shared_ptr<gamestate::GameEntity> &entity) {
13+
auto command_queue = std::dynamic_pointer_cast<component::CommandQueue>(
14+
entity->get_component(component::component_t::COMMANDQUEUE));
15+
16+
if (command_queue->get_queue().empty(time)) {
17+
return -1;
18+
}
19+
20+
auto command = command_queue->get_queue().front(time);
21+
22+
return static_cast<int>(command->get_type());
23+
}
24+
25+
} // namespace openage::gamestate::activity
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024-2024 the openage authors. See copying.md for legal info.
2+
3+
#pragma once
4+
5+
#include <cstddef>
6+
#include <memory>
7+
8+
#include "time/time.h"
9+
10+
11+
namespace openage::gamestate {
12+
class GameEntity;
13+
14+
namespace activity {
15+
16+
/**
17+
* Returns true if the next command in the queue is an idle command.
18+
*/
19+
int next_command_switch(const time::time_t &time,
20+
const std::shared_ptr<gamestate::GameEntity> &entity);
21+
22+
} // namespace activity
23+
} // namespace openage::gamestate

0 commit comments

Comments
 (0)