[Resource/Project] ACS-X
Posted: Sat May 07, 2016 11:58 am
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)
syntax: ptr_cast(type)(pointer)
example:
Game constants
Example usage
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
New function
Update 20th May 6:34 PM AEST
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
syntax: ptr_cast(type)(pointer)
example:
Code: Select all
ptr pointer = NewPtr();
SetPtr(pointer, 25);
int value = ptr_cast(int)(pointer);
FreePtr(pointer);
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
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...");
}
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
New function
- int GetBaseGame(void): returns the base game (see list below)
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
- Fixed astrtoi and astrtof