Page 1 of 1

[Resource/Project] ACS-X

Posted: Sat May 07, 2016 11:58 am
by The Zombie Killer
ACS-X is an ACS library containing various useful functions and features, including basic pointer access.
This library requires GDCC-ACC, which is a drop-in replacement for ACC, with less bugs and more features. Your existing code will compile fine under GDCC-ACC.

New functions (see further down for functions added in updates)
  • ptr NewPtr(void): returns a new pointer
  • void SetPtr(ptr pointer, <any> value): sets the value of a pointer
  • void FreePtr(ptr pointer): frees the memory of a pointer
  • int astrtoi(str string): converts a string to an integer
  • float astrtof(str string): converts a string to a float
  • str astrlower(str string): converts a string to lowercase
  • str astrupper(str string): converts a string to uppercase
  • void FadeSoundIn(int tid, int channel, int tics): fades in the currently playing sound on a channel for a specified duration
  • void FadeSoundOut(int tid, int channel, int tics): fades out the currently playing sound on a channel for a specified duration
  • void ChangeFlag(int tid, str flag, bool set): enables/disables [wiki=Actor_flags]actor flags[/wiki] on an actor
  • int GetGame(void): returns the current game (see below for available values)
  • str GetGameName(void): returns the title of the current game
  • int GetSourceport(void): returns the current source port (PORT_ZDOOM, PORT_GZDOOM or PORT_ZANDRONUM)
  • int GetMaxPlayers(void): returns the maximum number of players supported in the current source port
Pointer casts
syntax: ptr_cast(type)(pointer)
example:

Code: Select all

ptr pointer = NewPtr();
SetPtr(pointer, 25);
int value = ptr_cast(int)(pointer);
FreePtr(pointer); 
Game constants

Code: Select all

GAME_UNKNOWN
GAME_DOOM
GAME_DOOM_BFG
GAME_DOOM_ULTIMATE
GAME_DOOM2
GAME_DOOM2_PLUTONIA
GAME_DOOM2_TNT
GAME_DOOM2_BFG
GAME_FREEDOOM_DEMO
GAME_FREEDOOM_PHASE1
GAME_FREEDOOM_PHASE2
GAME_FREEDOOM_FREEDM
GAME_HERETIC
GAME_HERETIC_SHADOW
GAME_BLASPHEMER
GAME_HEXEN
GAME_HEXEN_DEATHKINGS
GAME_STRIFE
GAME_CHEX
GAME_CHEX3
GAME_URBANBRAWL
GAME_HACX
GAME_HACX2
GAME_HARMONY
GAME_SQUARE_SQUAREWARE
GAME_SQUARE
Example usage

Code: Select all

#pragma define raw on // preprocessor macros
#pragma fixed on      // fixed point type

#include "zcommon.acs"
#include "acsx.h"

script "ACS-X Demo" enter
{
    // Game name
    PrintBold(s:"Currently playing: ", s:GetGameName(), s:" (id: ", d:GetGame(), s:")");
    
    // Port detection
    switch (GetSourceport())
    {
        case PORT_ZDOOM:     PrintBold(s:"Currently playing in ZDoom."); break;
        case PORT_GZDOOM:    PrintBold(s:"Currently playing in GZDoom."); break;
        case PORT_ZANDRONUM: PrintBold(s:"Currently playing in Zandronum."); break;
        default:             PrintBold(s:"Port detection failed."); break;
    }
    
    // Pointers
    ptr string_pointer = NewPtr();
    ptr int_pointer = NewPtr();
    
    SetPtr(string_pointer, "Hello World");
    Log(s:"Pointer ", d:string_pointer, s:" is: ", s:ptr_cast(str)(string_pointer));
    SetPtr(string_pointer, "Goodbye World");
    Log(s:"Pointer ", d:string_pointer, s:" is: ", s:ptr_cast(str)(string_pointer));
    
    SetPtr(int_pointer, 25);
    Log(s:"Pointer ", d:int_pointer, s:" is: ", d:ptr_cast(int)(int_pointer));
    
    FreePtr(string_pointer);
    FreePtr(int_pointer);
    string_pointer = NULL;
    int_pointer = NULL;
    
    // FadeSound
    PlaySound(0, "brain/sight", CHAN_BODY);
    FadeSoundIn(0, CHAN_BODY, 35 * 2); // 2 second fadein
    Log(s:"Fading in for two seconds...");
    
    Delay(35 * 2);
    FadeSoundOut(0, CHAN_BODY, 35 * 4); // 4 second fadeout
    Log(s:"Fading out in four seconds...");
}
 
Adding ACS-X into a project
1. Download acsx-pub.zip
2. Put all of the files from the zip inside your project
3. Put acsx.h and acsx_import.h from the scripts folder somewhere where gdcc-acc can find them. You can do this in Slade 3 by going Edit -> Preferences -> Scripting -> ACS and adding an include path to somewhere containing those two files.
4. Add #include "acsx.h" below #include "zcommon.acs" in any source files you want to use ACS-X in.

Update 8th May 5:06 AM AEST
New functions
  • ptr NewPtrArray(int size): returns a new pointer array
  • ptr ResizePtrArray(ptr array, int size): reallocates a pointer array with a new size, and returns the new pointer
  • ptr GetPtrArray(ptr array, int element): returns a pointer to an element in an array
Update 8th May 5:50 AM AEST
New function
  • int GetBaseGame(void): returns the base game (see list below)
Base game constants

Code: Select all

BASEGAME_UNKNOWN
BASEGAME_DOOM
BASEGAME_HERETIC
BASEGAME_BLASPHEMER
BASEGAME_HEXEN
BASEGAME_STRIFE
BASEGAME_CHEX
BASEGAME_URBANBRAWL
BASEGAME_HACX
BASEGAME_HARMONY
BASEGAME_SQUARE
Update 20th May 6:34 PM AEST
  • Fixed astrtoi and astrtof
Download Now!

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 12:31 pm
by Kinsie
Impressive. Most impressive!

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 1:06 pm
by The Zombie Killer
Updated, now supports arrays!

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 1:07 pm
by Zhs2
If the source port knows ACS but doesn't have GetPlayerAccountName or the dynamic light actor, it must be ZDoom rite?

Also, the LANGUAGE solution for game checking is extensive (and unfortunately necessary), but if you're going to go the whole way with that shebang might as well also allow checking based on game family (e.g. Game-Doom, Game-Heretic, Game-Hexen, Game-Strife, Game-Chex, and so forth) because a lot of features may be common enough to a single game family that checking for "GAME_DOOM2"|"GAME_DOOM2_PLUTONIA"|"GAME_DOOM2_TNT"|"GAME_DOOM2_BFG" is a mouthful to define, and for each family case...

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 1:18 pm
by The Zombie Killer
Zhs2 wrote:If the source port knows ACS but doesn't have GetPlayerAccountName or the dynamic light actor, it must be ZDoom rite?
I can account for other ports later on, although for now I'm only going for ZDoom and its mainstream derivatives.
Zhs2 wrote:Also, the LANGUAGE solution for game checking is extensive (and unfortunately necessary), but if you're going to go the whole way with that shebang might as well also allow checking based on game family (e.g. Game-Doom, Game-Heretic, Game-Hexen, Game-Strife, Game-Chex, and so forth) because a lot of features may be common enough to a single game family that checking for "GAME_DOOM2"|"GAME_DOOM2_PLUTONIA"|"GAME_DOOM2_TNT"|"GAME_DOOM2_BFG" is a mouthful to define, and for each family case...
I actually have that on my todo list, heh.

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 1:44 pm
by |ndußtrial
square/virus are also detected as iwads without tweaking!

Re: [Resource/Project] ACS-X

Posted: Sat May 07, 2016 1:50 pm
by The Zombie Killer
Added GetBaseGame()

Re: [Resource/Project] ACS-X

Posted: Fri May 20, 2016 2:34 am
by The Zombie Killer
Updated

Re: [Resource/Project] ACS-X

Posted: Sat May 21, 2016 9:05 pm
by Matt
Put acsx.h and acsx_import.h from the scripts folder somewhere where gdcc-acc can find them.
And where might this be? Putting them in the same folder as gdcc-acc doesn't work.

Re: [Resource/Project] ACS-X

Posted: Sat May 21, 2016 9:54 pm
by The Zombie Killer
the same folder as your source files would work. Alternatively, you can pass

Code: Select all

-i path/to/directory
to gdcc-acc when you compile

Re: [Resource/Project] ACS-X

Posted: Sat May 21, 2016 10:53 pm
by Matt
Thanks, though it seems like a problem I'm having with GDCC generally in being unable to locate anything.

Re: [Resource/Project] ACS-X

Posted: Mon Nov 07, 2016 10:28 am
by Silentdarkness12
Dunno if this is still being supported, but is there some way to make this work with SLADE?

I tried renaming the executable, but it throws the error of unknown source type. I've followed the SLADE instructions, but the error has not changed.