1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
//
//
#include "testing.h"
#include "scripting/api/objs/vecmath.h"
#include "scripting/api/objs/enums.h"
#include "scripting/api/objs/texture.h"
#include "scripting/api/objs/object.h"
#include "scripting/api/objs/particle.h"
#include "scripting/lua/LuaValue.h"
#include "scripting/api/objs/bytearray.h"
#include "scripting/api/objs/audio_stream.h"
#include "sound/audiostr.h"
#include "physics/physics.h"
#include "graphics/2d.h"
#include "io/timer.h"
#include "particle/particle.h"
#include "playerman/player.h"
#include "cutscene/movie.h"
#include "network/multi_options.h"
namespace scripting {
namespace api {
//*************************Testing stuff*************************
//This section is for stuff that's considered experimental.
ADE_LIB(l_Testing, "Testing", "ts", "Experimental or testing stuff");
ADE_FUNC(openAudioStreamMem,
l_Testing,
"string snddata, enumeration stream_type /* AUDIOSTREAM_* values */",
"Opens an audio stream of the specified in-memory file contents and type.",
"audio_stream",
"A handle to the opened stream or invalid on error")
{
luacpp::LuaValue snddata_arr(L);
enum_h streamTypeEnum;
if (!ade_get_args(L, "ao", &snddata_arr, l_Enum.Get(&streamTypeEnum))) {
return ade_set_args(L, "o", l_AudioStream.Set(-1));
}
int streamType;
switch (streamTypeEnum.index) {
case LE_ASF_EVENTMUSIC:
streamType = ASF_EVENTMUSIC;
break;
case LE_ASF_MENUMUSIC:
streamType = ASF_MENUMUSIC;
break;
case LE_ASF_VOICE:
streamType = ASF_VOICE;
break;
default:
LuaError(L, "Invalid audio stream type %d.", streamTypeEnum.index);
return ade_set_args(L, "o", l_AudioStream.Set(-1));
}
if (!snddata_arr.pushValue(L))
return ade_set_args(L, "o", l_AudioStream.Set(-1));
if (!lua_isstring(L, -1)) {
lua_pop(L, 1);
LuaError(L, "Expected binary string containing audio.");
return ade_set_args(L, "o", l_AudioStream.Set(-1));
}
size_t snd_len;
auto snddata = lua_tolstring(L, -1, &snd_len);
int ah = audiostream_open_mem(reinterpret_cast<const uint8_t *>(snddata), snd_len, streamType);
lua_pop(L, 1);
if (ah < 0) {
LuaError(L,"Stream could not be opened. Did you pass valid audio?");
return ade_set_args(L, "o", l_AudioStream.Set(-1));
}
return ade_set_args(L, "o", l_AudioStream.Set(ah));
}
ADE_FUNC(avdTest, l_Testing, NULL, "Test the AVD Physics code", NULL, NULL)
{
SCP_UNUSED(L); // unused parameter
static bool initialized = false;
static avd_movement avd;
if(!initialized)
{
avd.setAVD(10.0f, 3.0f, 1.0f, 1.0f, 0.0f);
initialized = true;
}
for(int i = 0; i < 3000; i++)
{
float Pc, Vc;
avd.get((float)i/1000.0f, &Pc, &Vc);
gr_set_color(0, 255, 0);
gr_pixel(i/10, gr_screen.clip_bottom - (int)(Pc*10.0f), GR_RESIZE_NONE);
gr_set_color(255, 0, 0);
gr_pixel(i/10, gr_screen.clip_bottom - (int)(Vc*10.0f), GR_RESIZE_NONE);
avd.get(&Pc, &Vc);
gr_set_color(255, 255, 255);
gr_pixel((timestamp()%3000)/10, gr_screen.clip_bottom - (int)(Pc*10.0f), GR_RESIZE_NONE);
gr_pixel((timestamp()%3000)/10, gr_screen.clip_bottom - (int)(Vc*10.0f), GR_RESIZE_NONE);
}
return ADE_RETURN_NIL;
}
ADE_FUNC_DEPRECATED(createParticle,
l_Testing,
"vector Position, vector Velocity, number Lifetime, number Radius, enumeration Type, [number "
"TracerLength=-1, boolean Reverse=false, texture Texture=Nil, object AttachedObject=Nil]",
"Creates a particle. Use PARTICLE_* enumerations for type."
"Reverse reverse animation, if one is specified"
"Attached object specifies object that Position will be (and always be) relative to.",
"particle",
"Handle to the created particle",
gameversion::version(19, 0, 0, 0),
"Not available in the testing library anymore. Use gr.createPersistentParticle instead.")
{
// Need to consume tracer_length parameter but it isn't used anymore
vec3d pos, vel;
float lifetime, rad;
float temp;
enum_h *type = NULL;
bool rev=false;
object_h *objh=NULL;
texture_h* texture = nullptr;
ade_get_args(L, "ooffo|fboo", l_Vector.Get(&pos), l_Vector.Get(&vel), &lifetime, &rad,
l_Enum.GetPtr(&type), &temp, &rev, l_Texture.GetPtr(&texture), l_Object.GetPtr(&objh));
return ADE_RETURN_NIL;
}
ADE_FUNC(getStack, l_Testing, NULL, "Generates an ADE stackdump", "string", "Current Lua stack")
{
char buf[10240] = {'\0'};
ade_stackdump(L, buf);
return ade_set_args(L, "s", buf);
}
ADE_FUNC(isCurrentPlayerMulti, l_Testing, NULL, "Returns whether current player is a multiplayer pilot or not.", "boolean", "Whether current player is a multiplayer pilot or not")
{
if(Player == NULL)
return ade_set_error(L, "b", false);
if(!(Player->flags & PLAYER_FLAGS_IS_MULTI))
return ADE_RETURN_FALSE;
return ADE_RETURN_TRUE;
}
ADE_FUNC(isPXOEnabled, l_Testing, NULL, "Returns whether PXO is currently enabled in the configuration.", "boolean", "Whether PXO is enabled or not")
{
if(!(Multi_options_g.pxo))
return ADE_RETURN_FALSE;
return ADE_RETURN_TRUE;
}
ADE_FUNC(playCutscene, l_Testing, NULL, "Forces a cutscene by the specified filename string to play. Should really only be used in a non-gameplay state (i.e. start of GS_STATE_BRIEFING) otherwise odd side effects may occur. Highly Experimental.", "string", NULL)
{
//This whole thing is a quick hack and can probably be done way better, but is currently functioning fine for my purposes.
const char* filename;
if (!ade_get_args(L, "s", &filename))
return ADE_RETURN_FALSE;
movie::play(filename);
return ADE_RETURN_TRUE;
}
}
}
|