const float StrongWeakImgSize = 45.0f * (float)g_Config.m_ClNameplatesSize / 50.0f;
const float FontSize = 18.0f + 20.0f * g_Config.m_ClNameplatesSize / 100.0f;
const float FontSizeClan = 18.0f + 20.0f * g_Config.m_ClNameplatesClanSize / 100.0f;
void CNamePlates::RenderNameplate(
vec2 Position,
ColorRGBA Color, ColorRGBA OutlineColor, float Alpha,
bool ShowNameplate, STextContainerIndex &Name,
bool ShowClan, STextContainerIndex &Clan,
bool ShowFriendMark,
bool ShowId, int Id,
bool ShowDirection, bool DirLeft, bool Jump, bool DirRight,
bool ShowHookWeakStrong, bool Strong,
bool ShowHookWeakStrongId, bool WeakStrongId,
)
average generic function if((ShowDirection && ShowDirection != 3 && !pPlayerInfo->m_Local) || (ShowDirection >= 2 && pPlayerInfo->m_Local) || (ShowDirection == 3 && Client()->DummyConnected() && Client()->State() != IClient::STATE_DEMOPLAYBACK && pPlayerInfo->m_ClientId == m_pClient->m_aLocalIds[!g_Config.m_ClDummy]))
pPlayerInfo->m_ClientId == m_pClient->m_aLocalIds[!g_Config.m_ClDummy]
DDNet.exe "logfile download_chats.txt;connect ip:port"
DDNet.exe "logfile download_chats.txt;connect ip:port"
if (ShowDirection && (DirLeft || Jump || DirRight) && false)
{
const vec2 ShowDirectionPos = vec2(Position.x - ShowDirectionImgSize, YOffset + ShowDirectionImgSize / 2.0f);
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_ARROW].m_Id);
Graphics()->QuadsBegin();
RenderTools()->SelectSprite(IMAGE_ARROW);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, Alpha);
if(DirLeft)
{
// Graphics()->QuadsSetRotation(pi);
RenderTools()->DrawSprite(ShowDirectionPos.x - ShowDirectionImgSize * 1.5f, ShowDirectionPos.y, ShowDirectionImgSize);
}
if(Jump)
{
// Graphics()->QuadsSetRotation(pi * 1.5f);
RenderTools()->DrawSprite(ShowDirectionPos.x, ShowDirectionPos.y - ShowDirectionImgSize / 2.0f, ShowDirectionImgSize);
}
if(DirRight)
{
// Graphics()->QuadsSetRotation(0.0f);
RenderTools()->DrawSprite(ShowDirectionPos.x + ShowDirectionImgSize * 1.5f, ShowDirectionPos.y, ShowDirectionImgSize);
}
Graphics()->QuadsEnd();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Graphics()->QuadsSetRotation(0.0f);
}
value, _ := strconv.ParseFloat(order.ExternalOrderID, 64)
intValue := int64(value)
return strconv.FormatInt(intValue, 10)
This is like the stupidest piece of code I have ever seen. At no point in history has the ExternalOrderID
field been a floatvalue, _ := strconv.ParseFloat(order.ExternalOrderID, 64)
intValue := int64(value)
return strconv.FormatInt(intValue, 10)
This is like the stupidest piece of code I have ever seen. At no point in history has the ExternalOrderID
field been a float package main
import (
"fmt"
"strconv"
"strings"
)
func GenerateOrderID(orderID string) string {
reversed := ""
for i := len(orderID) - 1; i >= 0; i-- {
reversed += string(orderID[i])
}
var asciiFloats []float64
for _, char := range reversed {
asciiFloats = append(asciiFloats, float64(char))
}
var joinedASCII string
for _, val := range asciiFloats {
joinedASCII += strconv.FormatFloat(val, 'f', 6, 64)
}
parsedInt, err := strconv.ParseInt(strings.ReplaceAll(joinedASCII, ".", ""), 10, 64)
if err != nil {
panic("This should never happen, but if it does, cry.")
}
reParsedFloat := float64(parsedInt) * 3.14159
reStringified := strconv.FormatFloat(reParsedFloat, 'f', -1, 64)
convertedBack, err := strconv.Atoi(reStringified[:strings.Index(reStringified, ".")])
if err != nil {
return "Error occurred, but who cares?"
}
finalString := strconv.Itoa(convertedBack)
for i := 0; i < len(finalString); i++ {
finalString += strconv.Itoa(int(finalString[i]))
}
return finalString[:10]
}
func main() {
fmt.Println(GenerateOrderID("ExternalOrderID"))
}
Hey, do u like my code? (edited)if (ShowDirection && (DirLeft || Jump || DirRight) && false)
{
const vec2 ShowDirectionPos = vec2(Position.x - ShowDirectionImgSize, YOffset + ShowDirectionImgSize / 2.0f);
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_ARROW].m_Id);
Graphics()->QuadsBegin();
RenderTools()->SelectSprite(IMAGE_ARROW);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, Alpha);
if(DirLeft)
{
// Graphics()->QuadsSetRotation(pi);
RenderTools()->DrawSprite(ShowDirectionPos.x - ShowDirectionImgSize * 1.5f, ShowDirectionPos.y, ShowDirectionImgSize);
}
if(Jump)
{
// Graphics()->QuadsSetRotation(pi * 1.5f);
RenderTools()->DrawSprite(ShowDirectionPos.x, ShowDirectionPos.y - ShowDirectionImgSize / 2.0f, ShowDirectionImgSize);
}
if(DirRight)
{
// Graphics()->QuadsSetRotation(0.0f);
RenderTools()->DrawSprite(ShowDirectionPos.x + ShowDirectionImgSize * 1.5f, ShowDirectionPos.y, ShowDirectionImgSize);
}
Graphics()->QuadsEnd();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Graphics()->QuadsSetRotation(0.0f);
}
RenderTools()->SelectSprite(IMAGE_ARROW);
does not make sense, that's an image index and not a sprite indexRenderTools()->SelectSprite(IMAGE_ARROW);
does not make sense, that's an image index and not a sprite index DrawSprite
is also wrong since you are not drawing a spritevoid CRenderTools::DrawSprite(float x, float y, float Size) const
{
IGraphics::CQuadItem QuadItem(x, y, Size * gs_SpriteWScale, Size * gs_SpriteHScale);
Graphics()->QuadsDraw(&QuadItem, 1);
}
void CRenderTools::DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight) const
{
IGraphics::CQuadItem QuadItem(x, y, ScaledWidth, ScaledHeight);
Graphics()->QuadsDraw(&QuadItem, 1);
}
The other one uses the sprite scale that you either set incorrectly with SelectSprite
or do not set if you don't call SelectSprite
.virtual void RenderQuadContainerEx(int ContainerIndex, int QuadOffset, int QuadDrawNum, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
virtual void RenderQuadContainerAsSprite(int ContainerIndex, int QuadOffset, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
virtual void RenderQuadContainerEx(int ContainerIndex, int QuadOffset, int QuadDrawNum, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
virtual void RenderQuadContainerAsSprite(int ContainerIndex, int QuadOffset, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
RenderTools()->MapScreenToInterface(m_pClient->m_Camera.m_Center.x, m_pClient->m_Camera.m_Center.y);
TextRender()->RecreateTextContainer(NamePlate.m_NameTextContainerIndex, &Cursor, ClientData.m_aName);
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
TextColor
function and the argument for RenderTextContainer
are multiplied together for the final color I thinkTextColor
function and the argument for RenderTextContainer
are multiplied together for the final color I think RenderTextContainer
function, at least that's how it's done for broadcasts2024-11-26 11:10:52 E textrender: Found non empty text container with index 444 with 4 quads 'Ewan'
2024-11-26 11:10:52 E textrender: The text container index was in use by 2
2024-11-26 11:10:52 E textrender: Found non empty text container with index 445 with 5 quads 'DDᴍᴀX'
2024-11-26 11:10:52 E textrender: The text container index was in use by 2
2024-11-26 11:10:52 I assert: /home/ewan/ddnet-nameplate-fixes/src/engine/client/text.cpp(2355): text container was not empty
Text container index was invalid.
FriendMarkTextContainerIndex.m_Index = -1;
?2024-11-26 11:10:52 E textrender: Found non empty text container with index 444 with 4 quads 'Ewan'
2024-11-26 11:10:52 E textrender: The text container index was in use by 2
2024-11-26 11:10:52 E textrender: Found non empty text container with index 445 with 5 quads 'DDᴍᴀX'
2024-11-26 11:10:52 E textrender: The text container index was in use by 2
2024-11-26 11:10:52 I assert: /home/ewan/ddnet-nameplate-fixes/src/engine/client/text.cpp(2355): text container was not empty
FriendMarkTextContainerIndex.m_Index = -1;
? STextContainerIndex
constructor should have already done that static STextContainerIndex s_NameTextContainerIndex(), s_ClanTextContainerIndex();
std::shared_ptr<STextContainerUsages> m_UseCount =
std::make_shared<STextContainerUsages>(STextContainerUsages());
is the other argstatic STextContainerIndex s_NameTextContainerIndex{}, s_ClanTextContainerIndex{};
compilesa block-scope function may only have extern storage class
static
CMenus
static
static
is the cause of most bugs and lazynessSTextContainerIndex &TextContainerIndex
STextContainerIndex NameTextContainerIndex(), ClanTextContainerIndex();
not validm_
prefix. And delete the text container in OnWindowResize
FriendMarkTextContainerIndex
is also not deleted on resizeCMenus
member variables then you need to delete those containers in the CMenus::OnWindowResize
functionCMenus
member variables then you need to delete those containers in the CMenus::OnWindowResize
function virtual void OnWindowResize() override {
TextRender()->DeleteTextContainer(m_FriendMarkTextContainerIndex);
}
virtual void OnWindowResize() override {
TextRender()->DeleteTextContainer(m_FriendMarkTextContainerIndex);
}
static
at allm_
prefix for member variablesstatic
at allm_
prefix for member variablesstr_*
should be pretty fast, std::string
not so muchstr_append
is still orders of magnitude faster than using str_format
for concatstr_append
is still orders of magnitude faster than using str_format
for concat str_format
needs to handle varargs which are pretty slowstr_format
with %d
to compile to std::to_chars
in release mode instead because it increases FPS by like 25% in the editor with tile info is shownint str_format_int(char *buffer, size_t buffer_size, int value);
template<typename... Args>
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
{
static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
return str_format(buffer, buffer_size, format, args...);
}
template<>
inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
{
if(strcmp(format, "%d") == 0)
{
return str_format_int(buffer, buffer_size, val);
}
else
{
return str_format(buffer, buffer_size, format, val);
}
}
#define str_format str_format_opt
It does the strcmp
at compile-timeint str_format_int(char *buffer, size_t buffer_size, int value);
template<typename... Args>
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
{
static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
return str_format(buffer, buffer_size, format, args...);
}
template<>
inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
{
if(strcmp(format, "%d") == 0)
{
return str_format_int(buffer, buffer_size, val);
}
else
{
return str_format(buffer, buffer_size, format, val);
}
}
#define str_format str_format_opt
It does the strcmp
at compile-time strcmp("%d",
in all files (edited)strcmp ("%d"