Files
DevilutionX/Source/tmsg.cpp
T
Gleb Mazovetskiy 4fa3732526 Add missing <cstdint> includes
Done with the following script:

```ruby
Dir["Source/**/*.{h,c,cc,cpp,hpp}"].each do |path|
  v = File.read(path)
  next if !v.include?("uint32_t") || v.include?("cstdint")

  lines = v.lines
  line_num = if lines[2].start_with?(" *")
    lines.index { |l| l.start_with?(" */") } + 3
  else
    3
  end

  lines.insert(line_num, "#include <cstdint>\n")

  File.write(path, lines.join(""))
end
```

then fixed-up manually
2023-05-10 13:50:12 +01:00

67 lines
1.1 KiB
C++

/**
* @file tmsg.cpp
*
* Implementation of functionality transmitting chat messages.
*/
#include <list>
#include <cstdint>
#include "diablo.h"
#include "tmsg.h"
namespace devilution {
namespace {
struct TMsg {
uint32_t time;
std::unique_ptr<byte[]> body;
uint8_t len;
TMsg(uint32_t time, const byte *data, uint8_t len)
: time(time)
, body(new byte[len])
, len(len)
{
memcpy(body.get(), data, len);
}
};
std::list<TMsg> TimedMsgList;
} // namespace
uint8_t tmsg_get(std::unique_ptr<byte[]> *msg)
{
if (TimedMsgList.empty())
return 0;
TMsg &head = TimedMsgList.front();
if ((int)(head.time - SDL_GetTicks()) >= 0)
return 0;
uint8_t len = head.len;
*msg = std::move(head.body);
TimedMsgList.pop_front();
return len;
}
void tmsg_add(const byte *msg, uint8_t len)
{
uint32_t time = SDL_GetTicks() + gnTickDelay * 10;
TimedMsgList.emplace_back(time, msg, len);
}
void tmsg_start()
{
assert(TimedMsgList.empty());
}
void tmsg_cleanup()
{
TimedMsgList.clear();
}
} // namespace devilution