use function template#2835
Conversation
|
Sorry, I can't get why this change should be done |
|
ocgcore一直以來都是用uint8, uint16 |
|
plz keep both ReadUInt* and ReadInt* |
|
In fact uint16_t x = BufferIO::ReadInt16(p);it's still uint16_t, without problems |
done
If you want to read uint16_t, maybe you should read uint16_t not int16_t. |
|
plus could we add |
|
Maybe you can use buffer_read directly: buffer_read<uint32_t>(p);In C++, the project should not declare a read function for each integer type in the first place. Other types can be read/write by |
Just add it, and it may not be needed to use, making it tidy to have every |
|
We should not keep every Using 6~10 declarations for 1 function template is not tidy. I know it is insane, but I don't want to modify 700 lines and spend another 700 hours arguing why it is much better. |
|
I don't think there's anything wrong with utility functions. Writing them is a one-time effort, and they are simpler to use later on compared to |
|
function template的其中一個用途是 與此相比 我修改時是直接取代因此都會指定型態 |
|
how about we use |
|
Do you mean template<typename T>
static T Read(unsigned char*& p) {
T ret{};
std::memcpy(&ret, p, sizeof(T));
p += sizeof(T);
return ret;
}; |
yes |
|
too many things to do this update. I think we could do it after the Jul update (1362) |
Added deprecation warnings for the following functions: - ReadInt16 - ReadInt8 - ReadUInt8 - WriteInt16 - WriteInt8
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the legacy BufferIO::ReadIntX/WriteIntX methods and buffer_read/buffer_write calls with new templated BufferIO::Read<T> and BufferIO::Write<T> to unify integer I/O and deprecate smaller signed types.
- Introduces
template<typename T> Read/Writeinbufferio.hand marks the old methods as deprecated. - Migrates all read/write calls in the
gframemodules to the new templated interfaces. - Removes the
ocgcore/buffer.hdependency.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| gframe/bufferio.h | Added templated Read/Write, deprecated old APIs. |
| gframe/tag_duel.cpp | Replaced all WriteIntX/ReadUIntX with templates. |
| gframe/netserver.cpp | Updated packet serialization with templated I/O. |
Comments suppressed due to low confidence (2)
gframe/bufferio.h:21
- [nitpick] The deprecated ReadIntX/WriteIntX methods are still present alongside the new templated interfaces. Once migration is complete, remove these deprecated methods to reduce API surface and avoid confusion.
}
gframe/tag_duel.cpp:299
- [nitpick] This pattern of casting and templated write is repeated many times. Consider introducing a helper macro or inline function (e.g.,
WriteCount(pbuf, pdeck[i].main.size())) to reduce boilerplate and the risk of inconsistent usage.
BufferIO::Write<uint16_t>(pbuf, (uint16_t)pdeck[0].main.size());
|
question, for eco management: How to make replacement? |
|
BufferIO::ReadInt32 BufferIO::ReadInt16 BufferIO::ReadInt8 BufferIO::ReadUInt8 BufferIO::WriteInt32 BufferIO::WriteInt16 BufferIO::WriteInt8 |
Problem
Single script:
39910367
魔法都市エンディミオン
①:このカードがフィールドゾーンに存在する限り、自分または相手が魔法カードを発動する度に、このカードに魔力カウンターを1つ置く。
Change line 47 of c39910367.lua
(put 65530 counters)
The maximum number of counters is 65535, so the players can put 65530 counters.
Solution
Now we do not use int8_t and int16_t.
For types smaller than int, we only use uint8_t and uint16_t.
@mercury233
@purerosefallen
@Wind2009-Louse
@fallenstardust