This commit is contained in:
James Seibel
2023-10-28 08:56:27 -05:00
parent b3c4ea47d7
commit f746f8b4ec
2 changed files with 172 additions and 20 deletions
@@ -20,6 +20,7 @@
package com.seibel.distanthorizons.core.util.objects;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.coreapi.ModInfo;
import org.apache.logging.log4j.Logger;
import java.lang.invoke.MethodHandles;
@@ -196,32 +197,47 @@ public final class GLMessage
// helper classes //
//================//
/**
* Expected message format: <br>
* <code>
* [LWJGL] OpenGL debug message <br>
* ID: 0x20071 <br>
* Source: API <br>
* Type: OTHER <br>
* Severity: NOTIFICATION <br>
* Message: Buffer detailed info: Buffer object 1014084 (bound to ...
* </code>
*/
public static class Builder
{
/** how many stages are present in the message parser */
private static final int FINAL_PARSER_STAGE_INDEX = 15;
public static final Builder DEFAULT_MESSAGE_BUILDER =
new Builder(
(type) -> { // type filter
if (type == GLMessage.EType.POP_GROUP)
return false;
if (type == GLMessage.EType.PUSH_GROUP)
return false;
if (type == GLMessage.EType.MARKER)
return false;
// if (type == GLMessage.Type.PERFORMANCE) return false;
return true;
},
(severity) -> { // severity filter
if (severity == GLMessage.ESeverity.NOTIFICATION)
return false;
return true;
},
null
);
new Builder(
(type) ->
{ // type filter
if (type == GLMessage.EType.POP_GROUP)
return false;
if (type == GLMessage.EType.PUSH_GROUP)
return false;
if (type == GLMessage.EType.MARKER)
return false;
// if (type == GLMessage.Type.PERFORMANCE) return false;
return true;
},
(severity) ->
{ // severity filter
if (severity == GLMessage.ESeverity.NOTIFICATION)
return false;
return true;
},
null
);
private final StringBuilder inProgressMessageBuilder = new StringBuilder();
private EType type;
private ESeverity severity;
private ESource source;
@@ -271,8 +287,8 @@ public final class GLMessage
{
// TODO fix implementation for MC 1.20.2 and newer
// please see the incomplete GLMessageTest for an example as to how the message formats differ
if (true)
return null;
//if (true)
// return null;
str = str.trim();
if (str.isEmpty())
@@ -295,6 +311,41 @@ public final class GLMessage
// the message isn't finished yet
return null;
// TODO implement a method that works for both MC 1.20.2+ and 1.20.1-
//if (str.equals(HEADER) && inProgressMessageBuilder.length() != 0)
//{
// boolean parseSuccess = runNextParserStage(str);
// if (parseSuccess && parserStage > FINAL_PARSER_STAGE_INDEX)
// {
// this.parserStage = 0;
// GLMessage msg = new GLMessage(this.type, this.severity, this.source, this.id, this.message);
// if (doesMessagePassFilters(msg))
// {
// return msg;
// }
// else
// {
// inProgressMessageBuilder.setLength(0);
// return null;
// }
// }
// else
// {
// if (!parseSuccess)
// {
// LOGGER.warn("Failed to parse GLMessage line '{}' at stage {}", str, parserStage);
// inProgressMessageBuilder.setLength(0);
// }
//
// return null;
// }
//}
//else
//{
// inProgressMessageBuilder.append(str);
// return null;
//}
}
private boolean doesMessagePassFilters(GLMessage msg)
@@ -368,6 +419,7 @@ public final class GLMessage
private boolean checkAndIncStage(String givenString, String expectedString)
{
boolean equal = givenString.equals(expectedString);
//boolean equal = givenString.contains(expectedString);
if (equal)
this.parserStage++;
return equal;
+100
View File
@@ -0,0 +1,100 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package tests;
import com.seibel.distanthorizons.core.util.objects.GLMessage;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
public class GLMessageTest
{
public static final String MESSAGE_ID = "0x20071";
public static final GLMessage.ESource MESSAGE_SOURCE = GLMessage.ESource.API;
public static final GLMessage.EType MESSAGE_TYPE = GLMessage.EType.OTHER;
public static final GLMessage.ESeverity MESSAGE_SEVERITY = GLMessage.ESeverity.NOTIFICATION;
public static final String MESSAGE = "Buffer detailed info: Buffer object 1014084 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as\" \"the source for buffer object operations.";
/** This is how debug messages were sent prior to Minecraft 1.20.2 */
private static final String[] PRE_1_20_2_MESSAGE_ARRAY =
{
"[LWJGL] OpenGL debug message"
,"ID", ":", "0x20071"
,"Source", ":", "API"
,"Type", ":", "OTHER"
,"Severity", ":", "NOTIFICATION"
,"Message", ":", "Buffer detailed info: Buffer object 1014084 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as\" \"the source for buffer object operations."
// optional addition to force the builder into noticing the message ended, shouldn't be necessary
//,"[LWJGL] OpenGL debug message"
};
/** This is how debug messages were sent after (and including) Minecraft 1.20.2 */
private static final String[] POST_1_20_2_MESSAGE_ARRAY =
{
"[LWJGL] OpenGL debug message"
,"ID: 0x20071"
,"Source: API"
,"Type: OTHER"
,"Severity: NOTIFICATION"
,"Message: Buffer detailed info: Buffer object 1014084 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as\" \"the source for buffer object operations."
// optional addition to force the builder into noticing the message ended, shouldn't be necessary
//,"[LWJGL] OpenGL debug message"
};
@Test
public void preMc1_20_2()
{
ArrayList<GLMessage> messageList = new ArrayList<>();
for (String str : PRE_1_20_2_MESSAGE_ARRAY)
{
GLMessage message = GLMessage.Builder.DEFAULT_MESSAGE_BUILDER.add(str);
if (message != null)
{
messageList.add(message);
}
}
//Assert.assertEquals("Incorrect message parse count.", 1, messageList.size());
//testMessage(messageList.get(0));
}
@Test
public void mc1_20_2()
{
// TODO
}
private static void messageMatchesExpected(GLMessage testMessage)
{
Assert.assertEquals(MESSAGE_ID, testMessage.id);
Assert.assertEquals(MESSAGE_SOURCE, testMessage.source);
Assert.assertEquals(MESSAGE_TYPE, testMessage.type);
Assert.assertEquals(MESSAGE_SEVERITY, testMessage.severity);
Assert.assertEquals(MESSAGE, testMessage.message);
}
}