Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2580 from Owain94/gamethreadassertions
Browse files Browse the repository at this point in the history
mixins: add more clientThread checks
  • Loading branch information
ThatGamerBlue authored May 14, 2020
2 parents 3739e4e + 06da1b8 commit 59d3441
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Named;
import net.runelite.api.ChatMessageType;
Expand All @@ -51,11 +52,14 @@
import net.runelite.api.IndexedSprite;
import net.runelite.api.IntegerNode;
import net.runelite.api.InventoryID;
import net.runelite.api.ItemDefinition;
import net.runelite.api.MenuEntry;
import net.runelite.api.MenuOpcode;
import net.runelite.api.MessageNode;
import net.runelite.api.NPC;
import net.runelite.api.NPCDefinition;
import net.runelite.api.Node;
import net.runelite.api.ObjectDefinition;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.api.Prayer;
Expand Down Expand Up @@ -498,6 +502,13 @@ public int getTotalLevel()
return totalLevel;
}

@Inject
public void addChatMessage(int type, String name, String message, String sender)
{
assert this.isClientThread() : "addChatMessage must be called on client thread";
addRSChatMessage(type, name, message, sender);
}

@Inject
@Override
public void addChatMessage(ChatMessageType type, String name, String message, String sender)
Expand All @@ -512,11 +523,19 @@ public GameState getGameState()
return GameState.of(getRSGameState());
}

@Inject
public void setGameState(int state)
{
assert this.isClientThread() : "setGameState must be called on client thread";
client.setRSGameState(state);
}

@Inject
@Override
public void setGameState(GameState gameState)
{
client.setGameState(gameState.getState());
assert this.isClientThread();
setGameState(gameState.getState());
}

@Inject
Expand Down Expand Up @@ -1015,6 +1034,14 @@ public static void draggingWidgetChanged(int idx)
client.getCallbacks().post(DraggingWidgetChanged.class, draggingWidgetChanged);
}

@Inject
public RSSprite createItemSprite(int itemId, int quantity, int border, int shadowColor, int stackable, boolean noted)
{
assert isClientThread() : "createItemSprite must be called on client thread";
return createRSItemSprite(itemId, quantity, border, shadowColor, stackable, noted);
}


@Inject
@Override
public Sprite createItemSprite(int itemId, int quantity, int border, int shadowColor, int stackable, boolean noted, int scale)
Expand Down Expand Up @@ -1958,5 +1985,30 @@ public void setMirrored(boolean isMirrored)
{
this.isMirrored = isMirrored;
};

@Inject
@Override
public ObjectDefinition getObjectDefinition(int objectId)
{
assert this.isClientThread() : "getObjectDefinition must be called on client thread";
return getRSObjectDefinition(objectId);
}

@Inject
@Override
@Nonnull
public ItemDefinition getItemDefinition(int id)
{
assert this.isClientThread() : "getItemDefinition must be called on client thread";
return getRSItemDefinition(id);
}

@Inject
@Override
public NPCDefinition getNpcDefinition(int id)
{
assert this.isClientThread() : "getNpcDefinition must be called on client thread";
return getRSNpcDefinition(id);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ public RSModel getModel(int quantity)
return rs$getModel(quantity);
}

return client.getItemDefinition(modelOverride).getModel(quantity);
return client.getRSItemDefinition(modelOverride).getModel(quantity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class RSTextureMixin implements RSTexture
rs$animate(diff);
return;
}
assert client.getDrawCallbacks() != null;

client.getDrawCallbacks().animate(this, diff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void playSoundEffect(int id, int x, int y, int range)
@Override
public void playSoundEffect(int id, int x, int y, int range, int delay)
{
assert this.isClientThread() : "playSoundEffect must be called on client thread!";
int position = ((x & 255) << 16) + ((y & 255) << 8) + (range & 255);

int[] queuedSoundEffectIDs = getQueuedSoundEffectIDs();
Expand All @@ -167,6 +168,7 @@ public void playSoundEffect(int id, int x, int y, int range, int delay)
@Override
public void playSoundEffect(int id, int volume)
{
assert client.isClientThread() : "playSoundEffect must be called on client thread";
RSSoundEffect soundEffect = getTrack(getIndexCache4(), id, 0);
if (soundEffect == null)
{
Expand Down
15 changes: 6 additions & 9 deletions runescape-api/src/main/java/net/runelite/rs/api/RSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public interface RSClient extends RSGameShell, Client
int getRSGameState();

@Import("updateGameState")
void setGameState(int gameState);
void setRSGameState(int gameState);

@Import("checkClick")
void setCheckClick(boolean checkClick);
Expand Down Expand Up @@ -331,15 +331,13 @@ public interface RSClient extends RSGameShell, Client
RSWorld[] getWorldList();

@Import("addChatMessage")
void addChatMessage(int type, String name, String message, String sender);
void addRSChatMessage(int type, String name, String message, String sender);

@Override
@Import("getObjectDefinition")
RSObjectDefinition getObjectDefinition(int objectId);
RSObjectDefinition getRSObjectDefinition(int objectId);

@Override
@Import("getNpcDefinition")
RSNPCDefinition getNpcDefinition(int npcId);
RSNPCDefinition getRSNpcDefinition(int npcId);

@Import("viewportZoom")
@Override
Expand Down Expand Up @@ -400,11 +398,10 @@ public interface RSClient extends RSGameShell, Client
RSNodeHashTable getItemContainers();

@Import("ItemDefinition_get")
@Override
RSItemDefinition getItemDefinition(int itemId);
RSItemDefinition getRSItemDefinition(int itemId);

@Import("getItemSprite")
RSSprite createItemSprite(int itemId, int quantity, int thickness, int borderColor, int stackable, boolean noted);
RSSprite createRSItemSprite(int itemId, int quantity, int thickness, int borderColor, int stackable, boolean noted);

@Import("menuAction")
void sendMenuAction(int n2, int n3, int n4, int n5, String string, String string2, int n6, int n7);
Expand Down

0 comments on commit 59d3441

Please sign in to comment.