[ACS] Useful libraries for ACC/BCC/GDCC

Looking for Resources for your mod/project? Want to share some of your creations so others can use them? Post them here!
Post Reply
User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

[ACS] Useful libraries for ACC/BCC/GDCC

#1

Post by TDRR » Fri Oct 04, 2024 7:46 pm

This set of libraries is mostly for GDCC-CC, GDCC's C front. But some are for vanilla ACC, so do take a look even if you don't use GDCC.

Github repository

paketlib
A library for Zandronum written in plain ACS (BCS and C headers to use the enhanced language features are available, too) that allows creating packets, sending and reading them over the network very easily. As an example:

Code: Select all

#library "pakttest"
#include "zcommon.acs"

#import "paketlib.acs"

Script "lol" OPEN
{
	str p = Packet_New();
	
	p = Packet_Append(p, 1122334499, PACKET_WORD);
	p = Packet_Append(p, 0, PACKET_WORD);
	p = Packet_AppendStr(p, "This is a test");
	p = Packet_Append(p, 13.5, PACKET_WORD);
	
	Packet_Send("ClientReceivePacket", p, -1);
}

Script "ClientReceivePacket" (int p) CLIENTSIDE
{
	p = Packet_Read(p, PACKET_WORD);
	int i1 = Packet_Rval;
	
	p = Packet_Read(p, PACKET_WORD);
	int i2 = Packet_Rval;
	
	p = Packet_ReadStr(p);
	str s = Packet_Rval;
	
	p = Packet_Read(p, PACKET_WORD);
	int f = Packet_Rval;

	Log(i:i1);
	Log(i:i2);
	Log(s:s);
	Log(f:f);
}
It's decently light on bandwidth usage as well. Overhead is a mere 1 extra byte for each 8-32bit integer/fixed point number/bool, and only 3 extra bytes for an entire string.

ACS_Common
Files: ACS_Common.c, ACS_Common.h
A header for GDCC meant to simplify writing code without libGDCC and libc, and for code intended to be ported from ACC/BCC. It does the following:
  • Enables ACS strings by default, and defines a str alias to them.
  • Enables the fixed point type for literals by default.
  • Includes ACS_Zandronum.h, as well as stdbool.h and stdfix.h to provide the remaining ACS types.
  • Defines ACS_SHORT_NAMES so ACS functions are included without the ACS_ prefix.
  • Adds a def_local macro to use inside functions, to allow using local arrays without requiring libGDCC.
  • Adds a set of printing macros taking advantage of macro magic and _Generic (Can be used like: Print("This is a number: ", 10, (char)'.');).
  • Adds the LanguageLookup, GetPrintName and IntToHex macros to cover the gaps not covered by the print functions.
Remember to rename both modprefix_sta ocurrences to fit your project.

safe-malloc
Files: safe-malloc.c, safe-malloc.h
A replacement for libGDCC aimed at simplifying mod interop/compatiblity. Performs memory allocation always starting from near the very top of the address space. Other copies of safe-malloc can coexist without issue since they're all aligned, and regular ACS mods using the same global array are very unlikely to run into any conflicts.
This also allows moving the static allocation base for your mod/libc without affecting the starting location of the heap.

Must be linked as a replacement to libGDCC, do not include the original library!

actorlib
Files: actorlib.c, actorlib.h
A library making use of GDCC's struct properties to provide an ActorT struct that can call many functions in a more seamless way. For example:

Code: Select all

ActorT monster = {someMonsterTID};

monster.health = 200; // calls ACS_SetActorProperty(0, APROP_Health, 200)
if(monster.height < 32.0) // calls ACS_GetActorPropertyFixed(0, APROP_Height)
{
    monster.speed = 32.0;
    monster.scaleX = monster.scaleX - 0.1;
}
It also provides a global called self, in much the same vein as QuakeC. This allows referring to the script activator without any extra definitions:

Code: Select all

self.giveInv("Shotgun", 1);
self.health = 150;
self.viewHeight = self.height - 2.0;
Last edited by TDRR on Fri May 02, 2025 4:16 pm, edited 6 times in total.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

User avatar
Fused
Contributor
Posts: 677
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

Re: [ACS] Useful libraries for GDCC

#2

Post by Fused » Sat Oct 05, 2024 10:12 am

Great work! I really hope custom compilers get some more attention when libraries like these are around to help develop mods. The fact that they make it so much easier is something that should be pointed out more.
My mods
Image Image

My socials
Image Image

User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

Re: [ACS] Useful libraries for GDCC

#3

Post by TDRR » Sat Oct 05, 2024 3:53 pm

Agreed. They really do make life a lot, lot easier.

I'd also like to point out that GDCC has had a good wiki for a while now. It documents both the ACS and C fronts.
https://github.com/DavidPH/GDCC/wiki

If anyone knows some C, come check it out! The wiki documents all extensions GDCC adds to help it work with the ACS VM and the engine more completely, and there's even a getting started guide now.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

User avatar
Fused
Contributor
Posts: 677
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

Re: [ACS] Useful libraries for GDCC

#4

Post by Fused » Sun Oct 06, 2024 8:21 pm

Nice, the wiki seems to be a lot more descriptive on the ACS front too now compared to when I was using it. I hope it attracts more people.
My mods
Image Image

My socials
Image Image

User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

Re: [ACS] Useful libraries for GDCC

#5

Post by TDRR » Mon Nov 25, 2024 2:37 am

I've added an extra library to help simplify writing code that doesn't use libGDCC or libc (often useful for extremely strict compatibility demands). It also makes porting code from ACS/BCS quite a bit simpler, as it sets a lot of defaults to be closer to them.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

Re: [ACS] Useful libraries for ACC/BCC/GDCC

#6

Post by TDRR » Wed Apr 30, 2025 3:11 am

Added an extra library to help create packets to send over the network, in light of the recent `CLIENTSIDEONLY` bugfix that broke some mods depending on the broken behavior. It's fairly efficient on bandwidth and performance, the overhead is only 1 byte per byte/short/word, and 3 bytes for an entire string. The way it works is that you simply write the things you want to write in the order you want, it'll craft a string and send it over the network, and then you can read your packet back in the same order on the receiving end. And that's it!

Unlike the previous set of libraries, this one is written in plain old ACS to simplify adoption.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

User avatar
Ivan
Addicted to Zandronum
Posts: 2225
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

Re: [ACS] Useful libraries for ACC/BCC/GDCC

#7

Post by Ivan » Wed Apr 30, 2025 7:16 pm

TDRR wrote:
Wed Apr 30, 2025 3:11 am
Added an extra library to help create packets to send over the network, in light of the recent `CLIENTSIDEONLY` bugfix that broke some mods depending on the broken behavior. It's fairly efficient on bandwidth and performance, the overhead is only 1 byte per byte/short/word, and 3 bytes for an entire string. The way it works is that you simply write the things you want to write in the order you want, it'll craft a string and send it over the network, and then you can read your packet back in the same order on the receiving end. And that's it!

Unlike the previous set of libraries, this one is written in plain old ACS to simplify adoption.
What's the bugged behavior you mention here?
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

Re: [ACS] Useful libraries for ACC/BCC/GDCC

#8

Post by TDRR » Fri May 02, 2025 12:46 pm

CLIENTSIDEONLY used to (in some cases only it seems, like ACS spawn funcs) spawn the actor on the server as well, and you could run functions affecting the actor and they'd be networked to the client as well. This was unintended (and caused network usage very similar to not having the flag at all), but some modders noticed it and started taking advantage of the bug. When it was fixed, many complained because they were left with no alternative.

This is supposed to help with that and hopefully to avoid similar kinds of hacks in the future.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

User avatar
TDRR
Forum Regular
Posts: 244
Joined: Thu Jun 28, 2018 9:13 pm
Location: Venezuela
Contact:

Re: [ACS] Useful libraries for ACC/BCC/GDCC

#9

Post by TDRR » Fri May 02, 2025 4:19 pm

I've updated paketlib with a pair of functions to get the current size of a packet, and the max size allowed by the current server configuration. These take into account the header all packets sent by SendNetworkString have.

Headers for BCS and C are available as well, so you can link them into your projects. Note that the C header does not import the library for you, since it's designed to allow you to choose whether to link statically or dynamically.
When I consider Your heavens, the work of Your fingers, The moon and the stars, which You have ordained; What is man that You take thought of him, And the son of man that You care for him? (Psalms 8:3-4, NASB)
My Discord tag is @tdrr, and it's my preferred contact method. I also check PMs here from time to time.
I also have a Discord server for my projects.

Post Reply