AGS: Run astyle formatting

This commit is contained in:
dreammaster 2020-11-21 19:31:48 +00:00 committed by Paul Gilbert
parent 8f6391bb5b
commit 8026e4bb30
609 changed files with 65211 additions and 72813 deletions

View file

@ -33,7 +33,11 @@
#include <utility>
#include "util/string.h"
namespace AGS { namespace Common {class Stream;}}
namespace AGS {
namespace Common {
class Stream;
}
}
using AGS::Common::Stream;
using AGS::Common::String;
@ -62,8 +66,7 @@ AssetPath get_voice_over_assetpath(const String &filename);
// Custom AGS PACKFILE user object
// TODO: it is preferrable to let our Stream define custom readable window instead,
// keeping this as simple as possible for now (we may require a stream classes overhaul).
struct AGS_PACKFILE_OBJ
{
struct AGS_PACKFILE_OBJ {
std::unique_ptr<Stream> stream;
size_t asset_size = 0u;
size_t remains = 0u;

View file

@ -35,67 +35,56 @@ extern GameState play;
extern RoomStruct thisroom;
extern CCAudioClip ccDynamicAudioClip;
int AudioChannel_GetID(ScriptAudioChannel *channel)
{
int AudioChannel_GetID(ScriptAudioChannel *channel) {
return channel->id;
}
int AudioChannel_GetIsPlaying(ScriptAudioChannel *channel)
{
if (play.fast_forward)
{
int AudioChannel_GetIsPlaying(ScriptAudioChannel *channel) {
if (play.fast_forward) {
return 0;
}
return channel_is_playing(channel->id) ? 1 : 0;
}
int AudioChannel_GetPanning(ScriptAudioChannel *channel)
{
int AudioChannel_GetPanning(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
return ch->panningAsPercentage;
}
return 0;
}
void AudioChannel_SetPanning(ScriptAudioChannel *channel, int newPanning)
{
void AudioChannel_SetPanning(ScriptAudioChannel *channel, int newPanning) {
if ((newPanning < -100) || (newPanning > 100))
quitprintf("!AudioChannel.Panning: panning value must be between -100 and 100 (passed=%d)", newPanning);
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
ch->set_panning(((newPanning + 100) * 255) / 200);
ch->panningAsPercentage = newPanning;
}
}
ScriptAudioClip* AudioChannel_GetPlayingClip(ScriptAudioChannel *channel)
{
ScriptAudioClip *AudioChannel_GetPlayingClip(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
return (ScriptAudioClip*)ch->sourceClip;
if (ch) {
return (ScriptAudioClip *)ch->sourceClip;
}
return nullptr;
}
int AudioChannel_GetPosition(ScriptAudioChannel *channel)
{
int AudioChannel_GetPosition(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
if (play.fast_forward)
return 999999999;
@ -104,13 +93,11 @@ int AudioChannel_GetPosition(ScriptAudioChannel *channel)
return 0;
}
int AudioChannel_GetPositionMs(ScriptAudioChannel *channel)
{
int AudioChannel_GetPositionMs(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
if (play.fast_forward)
return 999999999;
@ -119,107 +106,89 @@ int AudioChannel_GetPositionMs(ScriptAudioChannel *channel)
return 0;
}
int AudioChannel_GetLengthMs(ScriptAudioChannel *channel)
{
int AudioChannel_GetLengthMs(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
return ch->get_length_ms();
}
return 0;
}
int AudioChannel_GetVolume(ScriptAudioChannel *channel)
{
int AudioChannel_GetVolume(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
return ch->get_volume();
}
return 0;
}
int AudioChannel_SetVolume(ScriptAudioChannel *channel, int newVolume)
{
int AudioChannel_SetVolume(ScriptAudioChannel *channel, int newVolume) {
if ((newVolume < 0) || (newVolume > 100))
quitprintf("!AudioChannel.Volume: new value out of range (supplied: %d, range: 0..100)", newVolume);
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
ch->set_volume_percent(newVolume);
}
return 0;
}
int AudioChannel_GetSpeed(ScriptAudioChannel *channel)
{
int AudioChannel_GetSpeed(ScriptAudioChannel *channel) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
return ch->get_speed();
}
return 0;
}
void AudioChannel_SetSpeed(ScriptAudioChannel *channel, int new_speed)
{
void AudioChannel_SetSpeed(ScriptAudioChannel *channel, int new_speed) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
ch->set_speed(new_speed);
}
}
void AudioChannel_Stop(ScriptAudioChannel *channel)
{
void AudioChannel_Stop(ScriptAudioChannel *channel) {
if (channel->id == SCHAN_SPEECH && play.IsNonBlockingVoiceSpeech())
stop_voice_nonblocking();
else
stop_or_fade_out_channel(channel->id, -1, nullptr);
}
void AudioChannel_Seek(ScriptAudioChannel *channel, int newPosition)
{
void AudioChannel_Seek(ScriptAudioChannel *channel, int newPosition) {
if (newPosition < 0)
quitprintf("!AudioChannel.Seek: invalid seek position %d", newPosition);
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
ch->seek(newPosition);
}
}
void AudioChannel_SetRoomLocation(ScriptAudioChannel *channel, int xPos, int yPos)
{
void AudioChannel_SetRoomLocation(ScriptAudioChannel *channel, int xPos, int yPos) {
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(channel->id);
auto *ch = lock.GetChannelIfPlaying(channel->id);
if (ch)
{
if (ch) {
int maxDist = ((xPos > thisroom.Width / 2) ? xPos : (thisroom.Width - xPos)) - AMBIENCE_FULL_DIST;
ch->xSource = (xPos > 0) ? xPos : -1;
ch->ySource = yPos;
ch->maximumPossibleDistanceAway = maxDist;
if (xPos > 0)
{
if (xPos > 0) {
update_directional_sound_vol();
}
else
{
} else {
ch->apply_directional_modifier(0);
}
}
@ -236,95 +205,79 @@ void AudioChannel_SetRoomLocation(ScriptAudioChannel *channel, int xPos, int yPo
#include "script/script_runtime.h"
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetID);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetIsPlaying(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetIsPlaying(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetIsPlaying);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPanning);
}
// void | ScriptAudioChannel *channel, int newPanning
RuntimeScriptValue Sc_AudioChannel_SetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_SetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_SetPanning);
}
// ScriptAudioClip* | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPlayingClip(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetPlayingClip(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(ScriptAudioChannel, ScriptAudioClip, ccDynamicAudioClip, AudioChannel_GetPlayingClip);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPosition);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPositionMs(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetPositionMs(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPositionMs);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetLengthMs(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetLengthMs(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetLengthMs);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetVolume);
}
// int | ScriptAudioChannel *channel, int newVolume
RuntimeScriptValue Sc_AudioChannel_SetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_SetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT(ScriptAudioChannel, AudioChannel_SetVolume);
}
// void | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_Stop(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_Stop(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptAudioChannel, AudioChannel_Stop);
}
// void | ScriptAudioChannel *channel, int newPosition
RuntimeScriptValue Sc_AudioChannel_Seek(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_Seek(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_Seek);
}
// void | ScriptAudioChannel *channel, int xPos, int yPos
RuntimeScriptValue Sc_AudioChannel_SetRoomLocation(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_SetRoomLocation(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(ScriptAudioChannel, AudioChannel_SetRoomLocation);
}
RuntimeScriptValue Sc_AudioChannel_GetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_GetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetSpeed);
}
RuntimeScriptValue Sc_AudioChannel_SetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioChannel_SetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_SetSpeed);
}
void RegisterAudioChannelAPI()
{
void RegisterAudioChannelAPI() {
ccAddExternalObjectFunction("AudioChannel::Seek^1", Sc_AudioChannel_Seek);
ccAddExternalObjectFunction("AudioChannel::SetRoomLocation^2", Sc_AudioChannel_SetRoomLocation);
ccAddExternalObjectFunction("AudioChannel::Stop^0", Sc_AudioChannel_Stop);
@ -345,17 +298,17 @@ void RegisterAudioChannelAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("AudioChannel::Seek^1", (void*)AudioChannel_Seek);
ccAddExternalFunctionForPlugin("AudioChannel::SetRoomLocation^2", (void*)AudioChannel_SetRoomLocation);
ccAddExternalFunctionForPlugin("AudioChannel::Stop^0", (void*)AudioChannel_Stop);
ccAddExternalFunctionForPlugin("AudioChannel::get_ID", (void*)AudioChannel_GetID);
ccAddExternalFunctionForPlugin("AudioChannel::get_IsPlaying", (void*)AudioChannel_GetIsPlaying);
ccAddExternalFunctionForPlugin("AudioChannel::get_LengthMs", (void*)AudioChannel_GetLengthMs);
ccAddExternalFunctionForPlugin("AudioChannel::get_Panning", (void*)AudioChannel_GetPanning);
ccAddExternalFunctionForPlugin("AudioChannel::set_Panning", (void*)AudioChannel_SetPanning);
ccAddExternalFunctionForPlugin("AudioChannel::get_PlayingClip", (void*)AudioChannel_GetPlayingClip);
ccAddExternalFunctionForPlugin("AudioChannel::get_Position", (void*)AudioChannel_GetPosition);
ccAddExternalFunctionForPlugin("AudioChannel::get_PositionMs", (void*)AudioChannel_GetPositionMs);
ccAddExternalFunctionForPlugin("AudioChannel::get_Volume", (void*)AudioChannel_GetVolume);
ccAddExternalFunctionForPlugin("AudioChannel::set_Volume", (void*)AudioChannel_SetVolume);
ccAddExternalFunctionForPlugin("AudioChannel::Seek^1", (void *)AudioChannel_Seek);
ccAddExternalFunctionForPlugin("AudioChannel::SetRoomLocation^2", (void *)AudioChannel_SetRoomLocation);
ccAddExternalFunctionForPlugin("AudioChannel::Stop^0", (void *)AudioChannel_Stop);
ccAddExternalFunctionForPlugin("AudioChannel::get_ID", (void *)AudioChannel_GetID);
ccAddExternalFunctionForPlugin("AudioChannel::get_IsPlaying", (void *)AudioChannel_GetIsPlaying);
ccAddExternalFunctionForPlugin("AudioChannel::get_LengthMs", (void *)AudioChannel_GetLengthMs);
ccAddExternalFunctionForPlugin("AudioChannel::get_Panning", (void *)AudioChannel_GetPanning);
ccAddExternalFunctionForPlugin("AudioChannel::set_Panning", (void *)AudioChannel_SetPanning);
ccAddExternalFunctionForPlugin("AudioChannel::get_PlayingClip", (void *)AudioChannel_GetPlayingClip);
ccAddExternalFunctionForPlugin("AudioChannel::get_Position", (void *)AudioChannel_GetPosition);
ccAddExternalFunctionForPlugin("AudioChannel::get_PositionMs", (void *)AudioChannel_GetPositionMs);
ccAddExternalFunctionForPlugin("AudioChannel::get_Volume", (void *)AudioChannel_GetVolume);
ccAddExternalFunctionForPlugin("AudioChannel::set_Volume", (void *)AudioChannel_SetVolume);
}

View file

@ -30,7 +30,7 @@ int AudioChannel_GetID(ScriptAudioChannel *channel);
int AudioChannel_GetIsPlaying(ScriptAudioChannel *channel);
int AudioChannel_GetPanning(ScriptAudioChannel *channel);
void AudioChannel_SetPanning(ScriptAudioChannel *channel, int newPanning);
ScriptAudioClip* AudioChannel_GetPlayingClip(ScriptAudioChannel *channel);
ScriptAudioClip *AudioChannel_GetPlayingClip(ScriptAudioChannel *channel);
int AudioChannel_GetPosition(ScriptAudioChannel *channel);
int AudioChannel_GetPositionMs(ScriptAudioChannel *channel);
int AudioChannel_GetLengthMs(ScriptAudioChannel *channel);

View file

@ -32,52 +32,42 @@ extern GameSetupStruct game;
extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1];
extern CCAudioChannel ccDynamicAudio;
int AudioClip_GetID(ScriptAudioClip *clip)
{
int AudioClip_GetID(ScriptAudioClip *clip) {
return clip->id;
}
int AudioClip_GetFileType(ScriptAudioClip *clip)
{
int AudioClip_GetFileType(ScriptAudioClip *clip) {
return clip->fileType;
}
int AudioClip_GetType(ScriptAudioClip *clip)
{
int AudioClip_GetType(ScriptAudioClip *clip) {
return clip->type;
}
int AudioClip_GetIsAvailable(ScriptAudioClip *clip)
{
int AudioClip_GetIsAvailable(ScriptAudioClip *clip) {
return DoesAssetExistInLib(get_audio_clip_assetpath(clip->bundlingType, clip->fileName)) ? 1 : 0;
}
void AudioClip_Stop(ScriptAudioClip *clip)
{
void AudioClip_Stop(ScriptAudioClip *clip) {
AudioChannelsLock lock;
for (int i = 0; i < MAX_SOUND_CHANNELS; i++)
{
auto* ch = lock.GetChannelIfPlaying(i);
if ((ch != nullptr) && (ch->sourceClip == clip))
{
for (int i = 0; i < MAX_SOUND_CHANNELS; i++) {
auto *ch = lock.GetChannelIfPlaying(i);
if ((ch != nullptr) && (ch->sourceClip == clip)) {
AudioChannel_Stop(&scrAudioChannel[i]);
}
}
}
ScriptAudioChannel* AudioClip_Play(ScriptAudioClip *clip, int priority, int repeat)
{
ScriptAudioChannel *AudioClip_Play(ScriptAudioClip *clip, int priority, int repeat) {
ScriptAudioChannel *sc_ch = play_audio_clip(clip, priority, repeat, 0, false);
return sc_ch;
}
ScriptAudioChannel* AudioClip_PlayFrom(ScriptAudioClip *clip, int position, int priority, int repeat)
{
ScriptAudioChannel *AudioClip_PlayFrom(ScriptAudioClip *clip, int position, int priority, int repeat) {
ScriptAudioChannel *sc_ch = play_audio_clip(clip, priority, repeat, position, false);
return sc_ch;
}
ScriptAudioChannel* AudioClip_PlayQueued(ScriptAudioClip *clip, int priority, int repeat)
{
ScriptAudioChannel *AudioClip_PlayQueued(ScriptAudioClip *clip, int priority, int repeat) {
ScriptAudioChannel *sc_ch = play_audio_clip(clip, priority, repeat, 0, true);
return sc_ch;
}
@ -92,55 +82,46 @@ ScriptAudioChannel* AudioClip_PlayQueued(ScriptAudioClip *clip, int priority, in
#include "script/script_api.h"
#include "script/script_runtime.h"
RuntimeScriptValue Sc_AudioClip_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioClip, AudioClip_GetID);
}
// int | ScriptAudioClip *clip
RuntimeScriptValue Sc_AudioClip_GetFileType(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_GetFileType(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioClip, AudioClip_GetFileType);
}
// int | ScriptAudioClip *clip
RuntimeScriptValue Sc_AudioClip_GetType(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_GetType(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioClip, AudioClip_GetType);
}
// int | ScriptAudioClip *clip
RuntimeScriptValue Sc_AudioClip_GetIsAvailable(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_GetIsAvailable(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioClip, AudioClip_GetIsAvailable);
}
// void | ScriptAudioClip *clip
RuntimeScriptValue Sc_AudioClip_Stop(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_Stop(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptAudioClip, AudioClip_Stop);
}
// ScriptAudioChannel* | ScriptAudioClip *clip, int priority, int repeat
RuntimeScriptValue Sc_AudioClip_Play(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_Play(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ_PINT2(ScriptAudioClip, ScriptAudioChannel, ccDynamicAudio, AudioClip_Play);
}
// ScriptAudioChannel* | ScriptAudioClip *clip, int position, int priority, int repeat
RuntimeScriptValue Sc_AudioClip_PlayFrom(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_PlayFrom(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ_PINT3(ScriptAudioClip, ScriptAudioChannel, ccDynamicAudio, AudioClip_PlayFrom);
}
// ScriptAudioChannel* | ScriptAudioClip *clip, int priority, int repeat
RuntimeScriptValue Sc_AudioClip_PlayQueued(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_AudioClip_PlayQueued(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ_PINT2(ScriptAudioClip, ScriptAudioChannel, ccDynamicAudio, AudioClip_PlayQueued);
}
void RegisterAudioClipAPI()
{
void RegisterAudioClipAPI() {
ccAddExternalObjectFunction("AudioClip::Play^2", Sc_AudioClip_Play);
ccAddExternalObjectFunction("AudioClip::PlayFrom^3", Sc_AudioClip_PlayFrom);
ccAddExternalObjectFunction("AudioClip::PlayQueued^2", Sc_AudioClip_PlayQueued);
@ -152,11 +133,11 @@ void RegisterAudioClipAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("AudioClip::Play^2", (void*)AudioClip_Play);
ccAddExternalFunctionForPlugin("AudioClip::PlayFrom^3", (void*)AudioClip_PlayFrom);
ccAddExternalFunctionForPlugin("AudioClip::PlayQueued^2", (void*)AudioClip_PlayQueued);
ccAddExternalFunctionForPlugin("AudioClip::Stop^0", (void*)AudioClip_Stop);
ccAddExternalFunctionForPlugin("AudioClip::get_FileType", (void*)AudioClip_GetFileType);
ccAddExternalFunctionForPlugin("AudioClip::get_IsAvailable", (void*)AudioClip_GetIsAvailable);
ccAddExternalFunctionForPlugin("AudioClip::get_Type", (void*)AudioClip_GetType);
ccAddExternalFunctionForPlugin("AudioClip::Play^2", (void *)AudioClip_Play);
ccAddExternalFunctionForPlugin("AudioClip::PlayFrom^3", (void *)AudioClip_PlayFrom);
ccAddExternalFunctionForPlugin("AudioClip::PlayQueued^2", (void *)AudioClip_PlayQueued);
ccAddExternalFunctionForPlugin("AudioClip::Stop^0", (void *)AudioClip_Stop);
ccAddExternalFunctionForPlugin("AudioClip::get_FileType", (void *)AudioClip_GetFileType);
ccAddExternalFunctionForPlugin("AudioClip::get_IsAvailable", (void *)AudioClip_GetIsAvailable);
ccAddExternalFunctionForPlugin("AudioClip::get_Type", (void *)AudioClip_GetType);
}

View file

@ -30,8 +30,8 @@ int AudioClip_GetFileType(ScriptAudioClip *clip);
int AudioClip_GetType(ScriptAudioClip *clip);
int AudioClip_GetIsAvailable(ScriptAudioClip *clip);
void AudioClip_Stop(ScriptAudioClip *clip);
ScriptAudioChannel* AudioClip_Play(ScriptAudioClip *clip, int priority, int repeat);
ScriptAudioChannel* AudioClip_PlayFrom(ScriptAudioClip *clip, int position, int priority, int repeat);
ScriptAudioChannel* AudioClip_PlayQueued(ScriptAudioClip *clip, int priority, int repeat);
ScriptAudioChannel *AudioClip_Play(ScriptAudioClip *clip, int priority, int repeat);
ScriptAudioChannel *AudioClip_PlayFrom(ScriptAudioClip *clip, int position, int priority, int repeat);
ScriptAudioChannel *AudioClip_PlayQueued(ScriptAudioClip *clip, int priority, int repeat);
#endif

View file

@ -35,7 +35,7 @@
using namespace AGS::Common;
extern GameSetupStruct game;
extern ViewStruct*views;
extern ViewStruct *views;
// *** BUTTON FUNCTIONS
@ -75,14 +75,13 @@ void Button_Animate(GUIButton *butt, int view, int loop, int speed, int repeat)
animbuts[numAnimButs].wait = 0;
numAnimButs++;
// launch into the first frame
if (UpdateAnimatingButton(numAnimButs - 1))
{
if (UpdateAnimatingButton(numAnimButs - 1)) {
debug_script_warn("AnimateButton: no frames to animate");
StopButtonAnimation(numAnimButs - 1);
}
}
const char* Button_GetText_New(GUIButton *butt) {
const char *Button_GetText_New(GUIButton *butt) {
return CreateNewScriptString(butt->GetText());
}
@ -118,8 +117,7 @@ int Button_GetClipImage(GUIButton *butt) {
}
void Button_SetClipImage(GUIButton *butt, int newval) {
if (butt->IsClippingImage() != (newval != 0))
{
if (butt->IsClippingImage() != (newval != 0)) {
butt->SetClipImage(newval != 0);
guis_need_update = 1;
}
@ -206,21 +204,18 @@ int UpdateAnimatingButton(int bu) {
animbuts[bu].frame++;
if (animbuts[bu].frame >= tview->loops[animbuts[bu].loop].numFrames)
{
if (animbuts[bu].frame >= tview->loops[animbuts[bu].loop].numFrames) {
if (tview->loops[animbuts[bu].loop].RunNextLoop()) {
// go to next loop
animbuts[bu].loop++;
animbuts[bu].frame = 0;
}
else if (animbuts[bu].repeat) {
} else if (animbuts[bu].repeat) {
animbuts[bu].frame = 0;
// multi-loop anim, go back
while ((animbuts[bu].loop > 0) &&
(tview->loops[animbuts[bu].loop - 1].RunNextLoop()))
animbuts[bu].loop--;
}
else
} else
return 1;
}
@ -246,62 +241,52 @@ void StopButtonAnimation(int idxn) {
// Returns the index of the AnimatingGUIButton object corresponding to the
// given button ID; returns -1 if no such animation exists
int FindAnimatedButton(int guin, int objn)
{
for (int i = 0; i < numAnimButs; ++i)
{
int FindAnimatedButton(int guin, int objn) {
for (int i = 0; i < numAnimButs; ++i) {
if (animbuts[i].ongui == guin && animbuts[i].onguibut == objn)
return i;
}
return -1;
}
void FindAndRemoveButtonAnimation(int guin, int objn)
{
void FindAndRemoveButtonAnimation(int guin, int objn) {
int idx = FindAnimatedButton(guin, objn);
if (idx >= 0)
StopButtonAnimation(idx);
}
// ** end animating buttons code
void Button_Click(GUIButton *butt, int mbut)
{
void Button_Click(GUIButton *butt, int mbut) {
process_interface_click(butt->ParentId, butt->Id, mbut);
}
bool Button_IsAnimating(GUIButton *butt)
{
bool Button_IsAnimating(GUIButton *butt) {
return FindAnimatedButton(butt->ParentId, butt->Id) >= 0;
}
// NOTE: in correspondance to similar functions for Character & Object,
// GetView returns (view index + 1), while GetLoop and GetFrame return
// zero-based index and 0 in case of no animation.
int Button_GetAnimView(GUIButton *butt)
{
int Button_GetAnimView(GUIButton *butt) {
int idx = FindAnimatedButton(butt->ParentId, butt->Id);
return idx >= 0 ? animbuts[idx].view + 1 : 0;
}
int Button_GetAnimLoop(GUIButton *butt)
{
int Button_GetAnimLoop(GUIButton *butt) {
int idx = FindAnimatedButton(butt->ParentId, butt->Id);
return idx >= 0 ? animbuts[idx].loop : 0;
}
int Button_GetAnimFrame(GUIButton *butt)
{
int Button_GetAnimFrame(GUIButton *butt) {
int idx = FindAnimatedButton(butt->ParentId, butt->Id);
return idx >= 0 ? animbuts[idx].frame : 0;
}
int Button_GetTextAlignment(GUIButton *butt)
{
int Button_GetTextAlignment(GUIButton *butt) {
return butt->TextAlignment;
}
void Button_SetTextAlignment(GUIButton *butt, int align)
{
void Button_SetTextAlignment(GUIButton *butt, int align) {
if (butt->TextAlignment != align) {
butt->TextAlignment = (FrameAlignment)align;
guis_need_update = 1;
@ -322,144 +307,119 @@ void Button_SetTextAlignment(GUIButton *butt, int align)
extern ScriptString myScriptStringImpl;
// void | GUIButton *butt, int view, int loop, int speed, int repeat
RuntimeScriptValue Sc_Button_Animate(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_Animate(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT4(GUIButton, Button_Animate);
}
// const char* | GUIButton *butt
RuntimeScriptValue Sc_Button_GetText_New(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetText_New(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(GUIButton, const char, myScriptStringImpl, Button_GetText_New);
}
// void | GUIButton *butt, char *buffer
RuntimeScriptValue Sc_Button_GetText(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(GUIButton, Button_GetText, char);
}
// void | GUIButton *butt, const char *newtx
RuntimeScriptValue Sc_Button_SetText(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(GUIButton, Button_SetText, const char);
}
// void | GUIButton *butt, int newFont
RuntimeScriptValue Sc_Button_SetFont(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetFont);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetFont(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetFont);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetClipImage(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetClipImage(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetClipImage);
}
// void | GUIButton *butt, int newval
RuntimeScriptValue Sc_Button_SetClipImage(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetClipImage(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetClipImage);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetGraphic);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetMouseOverGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetMouseOverGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetMouseOverGraphic);
}
// void | GUIButton *guil, int slotn
RuntimeScriptValue Sc_Button_SetMouseOverGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetMouseOverGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetMouseOverGraphic);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetNormalGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetNormalGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetNormalGraphic);
}
// void | GUIButton *guil, int slotn
RuntimeScriptValue Sc_Button_SetNormalGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetNormalGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetNormalGraphic);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetPushedGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetPushedGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetPushedGraphic);
}
// void | GUIButton *guil, int slotn
RuntimeScriptValue Sc_Button_SetPushedGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetPushedGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetPushedGraphic);
}
// int | GUIButton *butt
RuntimeScriptValue Sc_Button_GetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetTextColor);
}
// void | GUIButton *butt, int newcol
RuntimeScriptValue Sc_Button_SetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetTextColor);
}
RuntimeScriptValue Sc_Button_Click(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_Click(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_Click);
}
RuntimeScriptValue Sc_Button_GetAnimating(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetAnimating(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_BOOL(GUIButton, Button_IsAnimating);
}
RuntimeScriptValue Sc_Button_GetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetTextAlignment);
}
RuntimeScriptValue Sc_Button_SetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_SetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(GUIButton, Button_SetTextAlignment);
}
RuntimeScriptValue Sc_Button_GetFrame(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetFrame(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetAnimFrame);
}
RuntimeScriptValue Sc_Button_GetLoop(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetLoop(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetAnimLoop);
}
RuntimeScriptValue Sc_Button_GetView(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Button_GetView(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(GUIButton, Button_GetAnimView);
}
void RegisterButtonAPI()
{
void RegisterButtonAPI() {
ccAddExternalObjectFunction("Button::Animate^4", Sc_Button_Animate);
ccAddExternalObjectFunction("Button::Click^1", Sc_Button_Click);
ccAddExternalObjectFunction("Button::GetText^1", Sc_Button_GetText);
@ -488,22 +448,22 @@ void RegisterButtonAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("Button::Animate^4", (void*)Button_Animate);
ccAddExternalFunctionForPlugin("Button::GetText^1", (void*)Button_GetText);
ccAddExternalFunctionForPlugin("Button::SetText^1", (void*)Button_SetText);
ccAddExternalFunctionForPlugin("Button::get_ClipImage", (void*)Button_GetClipImage);
ccAddExternalFunctionForPlugin("Button::set_ClipImage", (void*)Button_SetClipImage);
ccAddExternalFunctionForPlugin("Button::get_Font", (void*)Button_GetFont);
ccAddExternalFunctionForPlugin("Button::set_Font", (void*)Button_SetFont);
ccAddExternalFunctionForPlugin("Button::get_Graphic", (void*)Button_GetGraphic);
ccAddExternalFunctionForPlugin("Button::get_MouseOverGraphic", (void*)Button_GetMouseOverGraphic);
ccAddExternalFunctionForPlugin("Button::set_MouseOverGraphic", (void*)Button_SetMouseOverGraphic);
ccAddExternalFunctionForPlugin("Button::get_NormalGraphic", (void*)Button_GetNormalGraphic);
ccAddExternalFunctionForPlugin("Button::set_NormalGraphic", (void*)Button_SetNormalGraphic);
ccAddExternalFunctionForPlugin("Button::get_PushedGraphic", (void*)Button_GetPushedGraphic);
ccAddExternalFunctionForPlugin("Button::set_PushedGraphic", (void*)Button_SetPushedGraphic);
ccAddExternalFunctionForPlugin("Button::get_Text", (void*)Button_GetText_New);
ccAddExternalFunctionForPlugin("Button::set_Text", (void*)Button_SetText);
ccAddExternalFunctionForPlugin("Button::get_TextColor", (void*)Button_GetTextColor);
ccAddExternalFunctionForPlugin("Button::set_TextColor", (void*)Button_SetTextColor);
ccAddExternalFunctionForPlugin("Button::Animate^4", (void *)Button_Animate);
ccAddExternalFunctionForPlugin("Button::GetText^1", (void *)Button_GetText);
ccAddExternalFunctionForPlugin("Button::SetText^1", (void *)Button_SetText);
ccAddExternalFunctionForPlugin("Button::get_ClipImage", (void *)Button_GetClipImage);
ccAddExternalFunctionForPlugin("Button::set_ClipImage", (void *)Button_SetClipImage);
ccAddExternalFunctionForPlugin("Button::get_Font", (void *)Button_GetFont);
ccAddExternalFunctionForPlugin("Button::set_Font", (void *)Button_SetFont);
ccAddExternalFunctionForPlugin("Button::get_Graphic", (void *)Button_GetGraphic);
ccAddExternalFunctionForPlugin("Button::get_MouseOverGraphic", (void *)Button_GetMouseOverGraphic);
ccAddExternalFunctionForPlugin("Button::set_MouseOverGraphic", (void *)Button_SetMouseOverGraphic);
ccAddExternalFunctionForPlugin("Button::get_NormalGraphic", (void *)Button_GetNormalGraphic);
ccAddExternalFunctionForPlugin("Button::set_NormalGraphic", (void *)Button_SetNormalGraphic);
ccAddExternalFunctionForPlugin("Button::get_PushedGraphic", (void *)Button_GetPushedGraphic);
ccAddExternalFunctionForPlugin("Button::set_PushedGraphic", (void *)Button_SetPushedGraphic);
ccAddExternalFunctionForPlugin("Button::get_Text", (void *)Button_GetText_New);
ccAddExternalFunctionForPlugin("Button::set_Text", (void *)Button_SetText);
ccAddExternalFunctionForPlugin("Button::get_TextColor", (void *)Button_GetTextColor);
ccAddExternalFunctionForPlugin("Button::set_TextColor", (void *)Button_SetTextColor);
}

View file

@ -28,7 +28,7 @@
using AGS::Common::GUIButton;
void Button_Animate(GUIButton *butt, int view, int loop, int speed, int repeat);
const char* Button_GetText_New(GUIButton *butt);
const char *Button_GetText_New(GUIButton *butt);
void Button_GetText(GUIButton *butt, char *buffer);
void Button_SetText(GUIButton *butt, const char *newtx);
void Button_SetFont(GUIButton *butt, int newFont);

View file

@ -23,25 +23,22 @@
#include "ac/cdaudio.h"
#include "platform/base/agsplatformdriver.h"
int use_cdplayer=0;
int use_cdplayer = 0;
bool triedToUseCdAudioCommand = false;
int need_to_stop_cd=0;
int need_to_stop_cd = 0;
int init_cd_player()
{
use_cdplayer=0;
int init_cd_player() {
use_cdplayer = 0;
return platform->InitializeCDPlayer();
}
int cd_manager(int cmdd,int datt)
{
if (!triedToUseCdAudioCommand)
{
int cd_manager(int cmdd, int datt) {
if (!triedToUseCdAudioCommand) {
triedToUseCdAudioCommand = true;
init_cd_player();
}
if (cmdd==0) return use_cdplayer;
if (use_cdplayer==0) return 0; // ignore other commands
if (cmdd == 0) return use_cdplayer;
if (use_cdplayer == 0) return 0; // ignore other commands
return platform->CDPlayerCommand(cmdd, datt);
}

View file

@ -31,6 +31,6 @@
#define CDS_DRIVEEMPTY 0x0800 // no CD in drive
int init_cd_player() ;
int cd_manager(int cmdd,int datt) ;
int cd_manager(int cmdd, int datt) ;
#endif

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@ void Character_RemoveTint(CharacterInfo *chaa);
int Character_GetHasExplicitTint(CharacterInfo *chaa);
void Character_Say(CharacterInfo *chaa, const char *text);
void Character_SayAt(CharacterInfo *chaa, int x, int y, int width, const char *texx);
ScriptOverlay* Character_SayBackground(CharacterInfo *chaa, const char *texx);
ScriptOverlay *Character_SayBackground(CharacterInfo *chaa, const char *texx);
void Character_SetAsPlayer(CharacterInfo *chaa);
void Character_SetIdleView(CharacterInfo *chaa, int iview, int itime);
void Character_SetOption(CharacterInfo *chaa, int flag, int yesorno);
@ -82,10 +82,10 @@ void Character_RunInteraction(CharacterInfo *chaa, int mood);
int Character_GetProperty(CharacterInfo *chaa, const char *property);
void Character_GetPropertyText(CharacterInfo *chaa, const char *property, char *bufer);
const char* Character_GetTextProperty(CharacterInfo *chaa, const char *property);
const char *Character_GetTextProperty(CharacterInfo *chaa, const char *property);
ScriptInvItem* Character_GetActiveInventory(CharacterInfo *chaa);
void Character_SetActiveInventory(CharacterInfo *chaa, ScriptInvItem* iit);
ScriptInvItem *Character_GetActiveInventory(CharacterInfo *chaa);
void Character_SetActiveInventory(CharacterInfo *chaa, ScriptInvItem *iit);
int Character_GetAnimating(CharacterInfo *chaa);
int Character_GetAnimationSpeed(CharacterInfo *chaa);
void Character_SetAnimationSpeed(CharacterInfo *chaa, int newval);
@ -124,7 +124,7 @@ void Character_SetMovementLinkedToAnimation(CharacterInfo *chaa, int yesorno)
int Character_GetLoop(CharacterInfo *chaa);
void Character_SetLoop(CharacterInfo *chaa, int newval);
int Character_GetMoving(CharacterInfo *chaa);
const char* Character_GetName(CharacterInfo *chaa);
const char *Character_GetName(CharacterInfo *chaa);
void Character_SetName(CharacterInfo *chaa, const char *newName);
int Character_GetNormalView(CharacterInfo *chaa);
int Character_GetPreviousRoom(CharacterInfo *chaa);
@ -163,46 +163,50 @@ int Character_GetSpeakingFrame(CharacterInfo *chaa);
//=============================================================================
struct MoveList;
namespace AGS { namespace Common { class Bitmap; } }
namespace AGS {
namespace Common {
class Bitmap;
}
}
using namespace AGS; // FIXME later
void animate_character(CharacterInfo *chap, int loopn,int sppd,int rept, int noidleoverride = 0, int direction = 0, int sframe = 0);
void walk_character(int chac,int tox,int toy,int ignwal, bool autoWalkAnims);
int find_looporder_index (int curloop);
void animate_character(CharacterInfo *chap, int loopn, int sppd, int rept, int noidleoverride = 0, int direction = 0, int sframe = 0);
void walk_character(int chac, int tox, int toy, int ignwal, bool autoWalkAnims);
int find_looporder_index(int curloop);
// returns 0 to use diagonal, 1 to not
int useDiagonal (CharacterInfo *char1);
int useDiagonal(CharacterInfo *char1);
// returns 1 normally, or 0 if they only have horizontal animations
int hasUpDownLoops(CharacterInfo *char1);
void start_character_turning (CharacterInfo *chinf, int useloop, int no_diagonal);
void fix_player_sprite(MoveList*cmls,CharacterInfo*chinf);
void start_character_turning(CharacterInfo *chinf, int useloop, int no_diagonal);
void fix_player_sprite(MoveList *cmls, CharacterInfo *chinf);
// Check whether two characters have walked into each other
int has_hit_another_character(int sourceChar);
int doNextCharMoveStep (CharacterInfo *chi, int &char_index, CharacterExtras *chex);
int doNextCharMoveStep(CharacterInfo *chi, int &char_index, CharacterExtras *chex);
int find_nearest_walkable_area_within(int *xx, int *yy, int range, int step);
void find_nearest_walkable_area (int *xx, int *yy);
void walk_character(int chac,int tox,int toy,int ignwal, bool autoWalkAnims);
void find_nearest_walkable_area(int *xx, int *yy);
void walk_character(int chac, int tox, int toy, int ignwal, bool autoWalkAnims);
void FindReasonableLoopForCharacter(CharacterInfo *chap);
void walk_or_move_character(CharacterInfo *chaa, int x, int y, int blocking, int direct, bool isWalk);
int is_valid_character(int newchar);
int wantMoveNow (CharacterInfo *chi, CharacterExtras *chex);
int wantMoveNow(CharacterInfo *chi, CharacterExtras *chex);
void setup_player_character(int charid);
void CheckViewFrameForCharacter(CharacterInfo *chi);
Common::Bitmap *GetCharacterImage(int charid, int *isFlipped);
CharacterInfo *GetCharacterAtScreen(int xx, int yy);
// Get character ID at the given room coordinates
int is_pos_on_character(int xx,int yy);
int is_pos_on_character(int xx, int yy);
void get_char_blocking_rect(int charid, int *x1, int *y1, int *width, int *y2);
// Check whether the source char has walked onto character ww
int is_char_on_another (int sourceChar, int ww, int*fromxptr, int*cwidptr);
int is_char_on_another(int sourceChar, int ww, int *fromxptr, int *cwidptr);
int my_getpixel(Common::Bitmap *blk, int x, int y);
// X and Y co-ordinates must be in 320x200 format
int check_click_on_character(int xx,int yy,int mood);
int is_pos_on_character(int xx,int yy);
int check_click_on_character(int xx, int yy, int mood);
int is_pos_on_character(int xx, int yy);
void _DisplaySpeechCore(int chid, const char *displbuf);
void _DisplayThoughtCore(int chid, const char *displbuf);
void _displayspeech(const char*texx, int aschar, int xx, int yy, int widd, int isThought);
void _displayspeech(const char *texx, int aschar, int xx, int yy, int widd, int isThought);
int get_character_currently_talking();
void DisplaySpeech(const char*texx, int aschar);
void DisplaySpeech(const char *texx, int aschar);
int update_lip_sync(int talkview, int talkloop, int *talkframeptr);
// Calculates character's bounding box in room coordinates (takes only in-room transform into account)
@ -213,7 +217,7 @@ Rect GetCharacterRoomBBox(int charid, bool use_frame_0 = false);
// or the one that is least far away from its camera; calculated as a perpendicular distance between two AABBs.
PViewport FindNearestViewport(int charid);
extern CharacterInfo*playerchar;
extern CharacterInfo *playerchar;
extern CharacterExtras *charextra;
extern MoveList *mls;
extern int32_t _sc_PlayerCharPtr;

View file

@ -23,7 +23,11 @@
#ifndef AGS_ENGINE_AC_CHARACTERCACHE_H
#define AGS_ENGINE_AC_CHARACTERCACHE_H
namespace AGS { namespace Common { class Bitmap; } }
namespace AGS {
namespace Common {
class Bitmap;
}
}
using namespace AGS; // FIXME later
// stores cached info about the character

View file

@ -25,8 +25,7 @@
using AGS::Common::Stream;
void CharacterExtras::ReadFromFile(Stream *in)
{
void CharacterExtras::ReadFromFile(Stream *in) {
in->ReadArrayOfInt16(invorder, MAX_INVORDER);
invorder_count = in->ReadInt16();
width = in->ReadInt16();
@ -44,8 +43,7 @@ void CharacterExtras::ReadFromFile(Stream *in)
animwait = in->ReadInt16();
}
void CharacterExtras::WriteToFile(Stream *out)
{
void CharacterExtras::WriteToFile(Stream *out) {
out->WriteArrayOfInt16(invorder, MAX_INVORDER);
out->WriteInt16(invorder_count);
out->WriteInt16(width);

View file

@ -26,7 +26,11 @@
#include "ac/runtime_defines.h"
// Forward declaration
namespace AGS { namespace Common { class Stream; } }
namespace AGS {
namespace Common {
class Stream;
}
}
using namespace AGS; // FIXME later
struct CharacterExtras {

View file

@ -37,7 +37,7 @@
using namespace AGS::Common;
extern ViewStruct*views;
extern ViewStruct *views;
extern GameSetupStruct game;
extern int displayed_room;
extern GameState play;
@ -68,8 +68,7 @@ int CharacterInfo::get_blocking_bottom() {
return y + 3;
}
void CharacterInfo::UpdateMoveAndAnim(int &char_index, CharacterExtras *chex, int &numSheep, int *followingAsSheep)
{
void CharacterInfo::UpdateMoveAndAnim(int &char_index, CharacterExtras *chex, int &numSheep, int *followingAsSheep) {
int res;
if (on != 1) return;
@ -105,8 +104,7 @@ void CharacterInfo::UpdateMoveAndAnim(int &char_index, CharacterExtras *chex, in
chex->process_idle_this_time = 0;
}
void CharacterInfo::UpdateFollowingExactlyCharacter()
{
void CharacterInfo::UpdateFollowingExactlyCharacter() {
x = game.chars[following].x;
y = game.chars[following].y;
z = game.chars[following].z;
@ -121,8 +119,7 @@ void CharacterInfo::UpdateFollowingExactlyCharacter()
baseline = usebase + 1;
}
int CharacterInfo::update_character_walking(CharacterExtras *chex)
{
int CharacterInfo::update_character_walking(CharacterExtras *chex) {
if (walking >= TURNING_AROUND) {
// Currently rotating to correct direction
if (walkwait > 0) walkwait--;
@ -139,13 +136,12 @@ int CharacterInfo::update_character_walking(CharacterExtras *chex)
wantloop = 7;
if ((turnlooporder[wantloop] >= views[view].numLoops) ||
(views[view].loops[turnlooporder[wantloop]].numFrames < 1) ||
((turnlooporder[wantloop] >= 4) && ((flags & CHF_NODIAGONAL)!=0))) {
((turnlooporder[wantloop] >= 4) && ((flags & CHF_NODIAGONAL) != 0))) {
if (walking >= TURNING_BACKWARDS)
wantloop--;
else
wantloop++;
}
else break;
} else break;
}
loop = turnlooporder[wantloop];
walking -= TURNING_AROUND;
@ -163,13 +159,10 @@ int CharacterInfo::update_character_walking(CharacterExtras *chex)
return 0;
}
void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *chex, int &doing_nothing)
{
if ((walking > 0) && (room == displayed_room))
{
void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *chex, int &doing_nothing) {
if ((walking > 0) && (room == displayed_room)) {
if (walkwait > 0) walkwait--;
else
{
else {
flags &= ~CHF_AWAITINGMOVE;
// Move the character
@ -186,7 +179,7 @@ void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *ch
int oldxp = x, oldyp = y;
for (int ff = 0; ff < abs(numSteps); ff++) {
if (doNextCharMoveStep (this, char_index, chex))
if (doNextCharMoveStep(this, char_index, chex))
break;
if ((walking == 0) || (walking >= TURNING_AROUND))
break;
@ -199,8 +192,7 @@ void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *ch
chex->ywas = y;
x = ((x) - oldxp) / 2 + oldxp;
y = ((y) - oldyp) / 2 + oldyp;
}
else if (numSteps > 0)
} else if (numSteps > 0)
chex->xwas = INVALID_X;
if ((flags & CHF_ANTIGLIDE) == 0)
@ -212,8 +204,7 @@ void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *ch
// check don't overflow loop
int framesInLoop = views[view].loops[loop].numFrames;
if (frame > framesInLoop)
{
if (frame > framesInLoop) {
frame = 1;
if (framesInLoop < 2)
@ -223,26 +214,23 @@ void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *ch
quitprintf("Unable to render character %d (%s) because there are no frames in loop %d", index_id, name, loop);
}
if (walking<1) {
if (walking < 1) {
chex->process_idle_this_time = 1;
doing_nothing=1;
walkwait=0;
doing_nothing = 1;
walkwait = 0;
chex->animwait = 0;
// use standing pic
Character_StopMoving(this);
frame = 0;
CheckViewFrameForCharacter(this);
}
else if (chex->animwait > 0) chex->animwait--;
} else if (chex->animwait > 0) chex->animwait--;
else {
if (flags & CHF_ANTIGLIDE)
walkwaitcounter++;
if ((flags & CHF_MOVENOTWALK) == 0)
{
if ((flags & CHF_MOVENOTWALK) == 0) {
frame++;
if (frame >= views[view].loops[loop].numFrames)
{
if (frame >= views[view].loops[loop].numFrames) {
// end of loop, so loop back round skipping the standing frame
frame = 1;
@ -264,24 +252,22 @@ void CharacterInfo::update_character_moving(int &char_index, CharacterExtras *ch
}
}
int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
{
int CharacterInfo::update_character_animating(int &aa, int &doing_nothing) {
// not moving, but animating
// idleleft is <0 while idle view is playing (.animating is 0)
if (((animating != 0) || (idleleft < 0)) &&
((walking == 0) || ((flags & CHF_MOVENOTWALK) != 0)) &&
(room == displayed_room))
{
(room == displayed_room)) {
doing_nothing = 0;
// idle anim doesn't count as doing something
if (idleleft < 0)
doing_nothing = 1;
if (wait>0) wait--;
if (wait > 0) wait--;
else if ((char_speaking == aa) && (game.options[OPT_LIPSYNCTEXT] != 0)) {
// currently talking with lip-sync speech
int fraa = frame;
wait = update_lip_sync (view, loop, &fraa) - 1;
wait = update_lip_sync(view, loop, &fraa) - 1;
// closed mouth at end of sentence
// NOTE: standard lip-sync is synchronized with text timer, not voice file
if (play.speech_in_post_state ||
@ -295,8 +281,7 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
//continue;
return RETURN_CONTINUE;
}
else {
} else {
int oldframe = frame;
if (animating & CHANIM_BACKWARDS) {
frame--;
@ -307,8 +292,7 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
loop --;
frame = views[view].loops[loop].numFrames - 1;
}
else if (animating & CHANIM_REPEAT) {
} else if (animating & CHANIM_REPEAT) {
frame = views[view].loops[loop].numFrames - 1;
@ -316,14 +300,12 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
loop++;
frame = views[view].loops[loop].numFrames - 1;
}
}
else {
} else {
frame++;
animating = 0;
}
}
}
else
} else
frame++;
if ((aa == char_speaking) &&
@ -338,15 +320,13 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
if (frame >= views[view].loops[loop].numFrames) {
if (views[view].loops[loop].RunNextLoop())
{
if (loop+1 >= views[view].numLoops)
if (views[view].loops[loop].RunNextLoop()) {
if (loop + 1 >= views[view].numLoops)
quit("!Animating character tried to overrun last loop in view");
loop++;
frame=0;
}
else if ((animating & CHANIM_REPEAT)==0) {
animating=0;
frame = 0;
} else if ((animating & CHANIM_REPEAT) == 0) {
animating = 0;
frame--;
// end of idle anim
if (idleleft < 0) {
@ -356,12 +336,11 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
// one-off anim, stop
else {
ReleaseCharacterView(aa);
idleleft=idletime;
idleleft = idletime;
}
}
}
else {
frame=0;
} else {
frame = 0;
// if it's a multi-loop animation, go back to start
if (play.no_multiloop_repeat == 0) {
while ((loop > 0) &&
@ -373,7 +352,7 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
wait = views[view].loops[loop].frames[frame].speed;
// idle anim doesn't have speed stored cos animating==0
if (idleleft < 0)
wait += animspeed+5;
wait += animspeed + 5;
else
wait += (animating >> 8) & 0x00ff;
@ -385,8 +364,7 @@ int CharacterInfo::update_character_animating(int &aa, int &doing_nothing)
return 0;
}
void CharacterInfo::update_character_follower(int &aa, int &numSheep, int *followingAsSheep, int &doing_nothing)
{
void CharacterInfo::update_character_follower(int &aa, int &numSheep, int *followingAsSheep, int &doing_nothing) {
if ((following >= 0) && (followinfo == FOLLOW_ALWAYSONTOP)) {
// an always-on-top follow
if (numSheep >= MAX_SHEEP)
@ -396,7 +374,7 @@ void CharacterInfo::update_character_follower(int &aa, int &numSheep, int *follo
}
// not moving, but should be following another character
else if ((following >= 0) && (doing_nothing == 1)) {
short distaway=(followinfo >> 8) & 0x00ff;
short distaway = (followinfo >> 8) & 0x00ff;
// no character in this room
if ((game.chars[following].on == 0) || (on == 0)) ;
else if (room < 0) {
@ -422,53 +400,46 @@ void CharacterInfo::update_character_follower(int &aa, int &numSheep, int *follo
// only move to the room-entered position if coming into
// the current room
if (play.entered_at_x > (thisroom.Width - 8)) {
x = thisroom.Width+8;
x = thisroom.Width + 8;
y = play.entered_at_y;
}
else if (play.entered_at_x < 8) {
} else if (play.entered_at_x < 8) {
x = -8;
y = play.entered_at_y;
}
else if (play.entered_at_y > (thisroom.Height - 8)) {
y = thisroom.Height+8;
} else if (play.entered_at_y > (thisroom.Height - 8)) {
y = thisroom.Height + 8;
x = play.entered_at_x;
}
else if (play.entered_at_y < thisroom.Edges.Top+8) {
y = thisroom.Edges.Top+1;
} else if (play.entered_at_y < thisroom.Edges.Top + 8) {
y = thisroom.Edges.Top + 1;
x = play.entered_at_x;
}
else {
} else {
// not at one of the edges
// delay for a few seconds to let the player move
room = -play.follow_change_room_timer;
}
if (room >= 0) {
walk_character(aa,play.entered_at_x,play.entered_at_y,1, true);
walk_character(aa, play.entered_at_x, play.entered_at_y, 1, true);
doing_nothing = 0;
}
}
}
else if (room != displayed_room) {
} else if (room != displayed_room) {
// if the characetr is following another character and
// neither is in the current room, don't try to move
}
else if ((abs(game.chars[following].x - x) > distaway+30) |
(abs(game.chars[following].y - y) > distaway+30) |
} else if ((abs(game.chars[following].x - x) > distaway + 30) |
(abs(game.chars[following].y - y) > distaway + 30) |
((followinfo & 0x00ff) == 0)) {
// in same room
int goxoffs=(Random(50)-25);
int goxoffs = (Random(50) - 25);
// make sure he's not standing on top of the other man
if (goxoffs < 0) goxoffs-=distaway;
else goxoffs+=distaway;
walk_character(aa,game.chars[following].x + goxoffs,
game.chars[following].y + (Random(50)-25),0, true);
if (goxoffs < 0) goxoffs -= distaway;
else goxoffs += distaway;
walk_character(aa, game.chars[following].x + goxoffs,
game.chars[following].y + (Random(50) - 25), 0, true);
doing_nothing = 0;
}
}
}
void CharacterInfo::update_character_idle(CharacterExtras *chex, int &doing_nothing)
{
void CharacterInfo::update_character_idle(CharacterExtras *chex, int &doing_nothing) {
// no idle animation, so skip this bit
if (idleview < 1) ;
// currently playing idle anim
@ -480,12 +451,12 @@ void CharacterInfo::update_character_idle(CharacterExtras *chex, int &doing_noth
else if ((doing_nothing == 0) || ((flags & CHF_FIXVIEW) != 0))
idleleft = idletime;
// count idle time
else if ((loopcounter%40==0) || (chex->process_idle_this_time == 1)) {
else if ((loopcounter % 40 == 0) || (chex->process_idle_this_time == 1)) {
idleleft--;
if (idleleft == -1) {
int useloop=loop;
debug_script_log("%s: Now idle (view %d)", scrname, idleview+1);
Character_LockView(this, idleview+1);
int useloop = loop;
debug_script_log("%s: Now idle (view %d)", scrname, idleview + 1);
Character_LockView(this, idleview + 1);
// SetCharView resets it to 0
idleleft = -2;
int maxLoops = views[idleview].numLoops;
@ -499,15 +470,15 @@ void CharacterInfo::update_character_idle(CharacterExtras *chex, int &doing_noth
do {
useloop = rand() % maxLoops;
// don't select a loop which is a continuation of a previous one
} while ((useloop > 0) && (views[idleview].loops[useloop-1].RunNextLoop()));
} while ((useloop > 0) && (views[idleview].loops[useloop - 1].RunNextLoop()));
}
// Normal idle anim - just reset to loop 0 if not enough to
// use the current one
else if (useloop >= maxLoops)
useloop = 0;
animate_character(this,useloop,
animspeed+5,(idletime == 0) ? 1 : 0, 1);
animate_character(this, useloop,
animspeed + 5, (idletime == 0) ? 1 : 0, 1);
// don't set Animating while the idle anim plays
animating = 0;

View file

@ -25,7 +25,7 @@
#include "platform/base/agsplatformdriver.h"
#include "script/runtimescriptvalue.h"
ScriptDateTime* DateTime_Now_Core() {
ScriptDateTime *DateTime_Now_Core() {
ScriptDateTime *sdt = new ScriptDateTime();
platform->GetSystemTime(sdt);
@ -33,7 +33,7 @@ ScriptDateTime* DateTime_Now_Core() {
return sdt;
}
ScriptDateTime* DateTime_Now() {
ScriptDateTime *DateTime_Now() {
ScriptDateTime *sdt = DateTime_Now_Core();
ccRegisterManagedObject(sdt, sdt);
return sdt;
@ -78,55 +78,46 @@ int DateTime_GetRawTime(ScriptDateTime *sdt) {
#include "script/script_runtime.h"
// ScriptDateTime* ()
RuntimeScriptValue Sc_DateTime_Now(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_Now(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO(ScriptDateTime, DateTime_Now);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetYear(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetYear(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetYear);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetMonth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetMonth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetMonth);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetDayOfMonth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetDayOfMonth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetDayOfMonth);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetHour(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetHour(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetHour);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetMinute(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetMinute(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetMinute);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetSecond(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetSecond(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetSecond);
}
// int (ScriptDateTime *sdt)
RuntimeScriptValue Sc_DateTime_GetRawTime(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DateTime_GetRawTime(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDateTime, DateTime_GetRawTime);
}
void RegisterDateTimeAPI()
{
void RegisterDateTimeAPI() {
ccAddExternalStaticFunction("DateTime::get_Now", Sc_DateTime_Now);
ccAddExternalObjectFunction("DateTime::get_DayOfMonth", Sc_DateTime_GetDayOfMonth);
ccAddExternalObjectFunction("DateTime::get_Hour", Sc_DateTime_GetHour);
@ -138,12 +129,12 @@ void RegisterDateTimeAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("DateTime::get_Now", (void*)DateTime_Now);
ccAddExternalFunctionForPlugin("DateTime::get_DayOfMonth", (void*)DateTime_GetDayOfMonth);
ccAddExternalFunctionForPlugin("DateTime::get_Hour", (void*)DateTime_GetHour);
ccAddExternalFunctionForPlugin("DateTime::get_Minute", (void*)DateTime_GetMinute);
ccAddExternalFunctionForPlugin("DateTime::get_Month", (void*)DateTime_GetMonth);
ccAddExternalFunctionForPlugin("DateTime::get_RawTime", (void*)DateTime_GetRawTime);
ccAddExternalFunctionForPlugin("DateTime::get_Second", (void*)DateTime_GetSecond);
ccAddExternalFunctionForPlugin("DateTime::get_Year", (void*)DateTime_GetYear);
ccAddExternalFunctionForPlugin("DateTime::get_Now", (void *)DateTime_Now);
ccAddExternalFunctionForPlugin("DateTime::get_DayOfMonth", (void *)DateTime_GetDayOfMonth);
ccAddExternalFunctionForPlugin("DateTime::get_Hour", (void *)DateTime_GetHour);
ccAddExternalFunctionForPlugin("DateTime::get_Minute", (void *)DateTime_GetMinute);
ccAddExternalFunctionForPlugin("DateTime::get_Month", (void *)DateTime_GetMonth);
ccAddExternalFunctionForPlugin("DateTime::get_RawTime", (void *)DateTime_GetRawTime);
ccAddExternalFunctionForPlugin("DateTime::get_Second", (void *)DateTime_GetSecond);
ccAddExternalFunctionForPlugin("DateTime::get_Year", (void *)DateTime_GetYear);
}

View file

@ -25,8 +25,8 @@
#include "ac/dynobj/scriptdatetime.h"
ScriptDateTime* DateTime_Now_Core();
ScriptDateTime* DateTime_Now();
ScriptDateTime *DateTime_Now_Core();
ScriptDateTime *DateTime_Now();
int DateTime_GetYear(ScriptDateTime *sdt);
int DateTime_GetMonth(ScriptDateTime *sdt);
int DateTime_GetDayOfMonth(ScriptDateTime *sdt);

View file

@ -66,15 +66,15 @@ extern GameSetupStruct game;
extern GameState play;
extern ccInstance *dialogScriptsInst;
extern int in_new_room;
extern CharacterInfo*playerchar;
extern CharacterInfo *playerchar;
extern SpriteCache spriteset;
extern AGSPlatformDriver *platform;
extern int cur_mode,cur_cursor;
extern int cur_mode, cur_cursor;
extern IGraphicsDriver *gfxDriver;
DialogTopic *dialog;
ScriptDialogOptionsRendering ccDialogOptionsRendering;
ScriptDrawingSurface* dialogOptionsRenderingSurface;
ScriptDrawingSurface *dialogOptionsRenderingSurface;
int said_speech_line; // used while in dialog to track whether screen needs updating
@ -97,14 +97,12 @@ void Dialog_Start(ScriptDialog *sd) {
#define SAYCHOSEN_YES 2
#define SAYCHOSEN_NO 3
int Dialog_DisplayOptions(ScriptDialog *sd, int sayChosenOption)
{
int Dialog_DisplayOptions(ScriptDialog *sd, int sayChosenOption) {
if ((sayChosenOption < 1) || (sayChosenOption > 3))
quit("!Dialog.DisplayOptions: invalid parameter passed");
int chose = show_dialog_options(sd->id, sayChosenOption, (game.options[OPT_RUNGAMEDLGOPTS] != 0));
if (chose != CHOSE_TEXTPARSER)
{
if (chose != CHOSE_TEXTPARSER) {
chose++;
}
return chose;
@ -118,8 +116,7 @@ int Dialog_GetOptionState(ScriptDialog *sd, int option) {
return GetDialogOption(sd->id, option);
}
int Dialog_HasOptionBeenChosen(ScriptDialog *sd, int option)
{
int Dialog_HasOptionBeenChosen(ScriptDialog *sd, int option) {
if ((option < 1) || (option > dialog[sd->id].numoptions))
quit("!Dialog.HasOptionBeenChosen: Invalid option number specified");
option--;
@ -129,35 +126,27 @@ int Dialog_HasOptionBeenChosen(ScriptDialog *sd, int option)
return 0;
}
void Dialog_SetHasOptionBeenChosen(ScriptDialog *sd, int option, bool chosen)
{
if (option < 1 || option > dialog[sd->id].numoptions)
{
void Dialog_SetHasOptionBeenChosen(ScriptDialog *sd, int option, bool chosen) {
if (option < 1 || option > dialog[sd->id].numoptions) {
quit("!Dialog.HasOptionBeenChosen: Invalid option number specified");
}
option--;
if (chosen)
{
if (chosen) {
dialog[sd->id].optionflags[option] |= DFLG_HASBEENCHOSEN;
}
else
{
} else {
dialog[sd->id].optionflags[option] &= ~DFLG_HASBEENCHOSEN;
}
}
int Dialog_GetOptionCount(ScriptDialog *sd)
{
int Dialog_GetOptionCount(ScriptDialog *sd) {
return dialog[sd->id].numoptions;
}
int Dialog_GetShowTextParser(ScriptDialog *sd)
{
int Dialog_GetShowTextParser(ScriptDialog *sd) {
return (dialog[sd->id].topicFlags & DTFLG_SHOWPARSER) ? 1 : 0;
}
const char* Dialog_GetOptionText(ScriptDialog *sd, int option)
{
const char *Dialog_GetOptionText(ScriptDialog *sd, int option) {
if ((option < 1) || (option > dialog[sd->id].numoptions))
quit("!Dialog.GetOptionText: Invalid option number specified");
@ -177,16 +166,14 @@ int Dialog_GetID(ScriptDialog *sd) {
#define RUN_DIALOG_GOTO_PREVIOUS -4
// dialog manager stuff
void get_dialog_script_parameters(unsigned char* &script, unsigned short* param1, unsigned short* param2)
{
void get_dialog_script_parameters(unsigned char *&script, unsigned short *param1, unsigned short *param2) {
script++;
*param1 = *script;
script++;
*param1 += *script * 256;
script++;
if (param2)
{
if (param2) {
*param2 = *script;
script++;
*param2 += *script * 256;
@ -194,33 +181,28 @@ void get_dialog_script_parameters(unsigned char* &script, unsigned short* param1
}
}
int run_dialog_script(DialogTopic*dtpp, int dialogID, int offse, int optionIndex) {
int run_dialog_script(DialogTopic *dtpp, int dialogID, int offse, int optionIndex) {
said_speech_line = 0;
int result = RUN_DIALOG_STAY;
if (dialogScriptsInst)
{
if (dialogScriptsInst) {
char funcName[100];
sprintf(funcName, "_run_dialog%d", dialogID);
RunTextScriptIParam(dialogScriptsInst, funcName, RuntimeScriptValue().SetInt32(optionIndex));
result = dialogScriptsInst->returnValue;
}
else
{
} else {
// old dialog format
if (offse == -1)
return result;
unsigned char* script = old_dialog_scripts[dialogID].get() + offse;
unsigned char *script = old_dialog_scripts[dialogID].get() + offse;
unsigned short param1 = 0;
unsigned short param2 = 0;
bool script_running = true;
while (script_running)
{
switch (*script)
{
while (script_running) {
switch (*script) {
case DCMD_SAY:
get_dialog_script_parameters(script, &param1, &param2);
@ -341,49 +323,47 @@ int run_dialog_script(DialogTopic*dtpp, int dialogID, int offse, int optionIndex
}
int write_dialog_options(Bitmap *ds, bool ds_has_alpha, int dlgxp, int curyp, int numdisp, int mouseison, int areawid,
int bullet_wid, int usingfont, DialogTopic*dtop, char*disporder, short*dispyp,
int bullet_wid, int usingfont, DialogTopic *dtop, char *disporder, short *dispyp,
int linespacing, int utextcol, int padding) {
int ww;
color_t text_color;
for (ww=0;ww<numdisp;ww++) {
for (ww = 0; ww < numdisp; ww++) {
if ((dtop->optionflags[disporder[ww]] & DFLG_HASBEENCHOSEN) &&
(play.read_dialog_option_colour >= 0)) {
// 'read' colour
text_color = ds->GetCompatibleColor(play.read_dialog_option_colour);
}
else {
} else {
// 'unread' colour
text_color = ds->GetCompatibleColor(playerchar->talkcolor);
}
if (mouseison==ww) {
if (mouseison == ww) {
if (text_color == ds->GetCompatibleColor(utextcol))
text_color = ds->GetCompatibleColor(13); // the normal colour is the same as highlight col
else text_color = ds->GetCompatibleColor(utextcol);
}
break_up_text_into_lines(get_translation(dtop->optionnames[disporder[ww]]), Lines, areawid-(2*padding+2+bullet_wid), usingfont);
dispyp[ww]=curyp;
if (game.dialog_bullet > 0)
{
break_up_text_into_lines(get_translation(dtop->optionnames[disporder[ww]]), Lines, areawid - (2 * padding + 2 + bullet_wid), usingfont);
dispyp[ww] = curyp;
if (game.dialog_bullet > 0) {
draw_gui_sprite_v330(ds, game.dialog_bullet, dlgxp, curyp, ds_has_alpha);
}
if (game.options[OPT_DIALOGNUMBERED] == kDlgOptNumbering) {
char tempbfr[20];
int actualpicwid = 0;
if (game.dialog_bullet > 0)
actualpicwid = game.SpriteInfos[game.dialog_bullet].Width+3;
actualpicwid = game.SpriteInfos[game.dialog_bullet].Width + 3;
sprintf (tempbfr, "%d.", ww + 1);
wouttext_outline (ds, dlgxp + actualpicwid, curyp, usingfont, text_color, tempbfr);
sprintf(tempbfr, "%d.", ww + 1);
wouttext_outline(ds, dlgxp + actualpicwid, curyp, usingfont, text_color, tempbfr);
}
for (size_t cc=0;cc<Lines.Count();cc++) {
wouttext_outline(ds, dlgxp+((cc==0) ? 0 : 9)+bullet_wid, curyp, usingfont, text_color, Lines[cc]);
curyp+=linespacing;
for (size_t cc = 0; cc < Lines.Count(); cc++) {
wouttext_outline(ds, dlgxp + ((cc == 0) ? 0 : 9) + bullet_wid, curyp, usingfont, text_color, Lines[cc]);
curyp += linespacing;
}
if (ww < numdisp-1)
if (ww < numdisp - 1)
curyp += data_to_game_coord(game.options[OPT_DIALOGGAP]);
}
return curyp;
@ -410,8 +390,7 @@ void draw_gui_for_dialog_options(Bitmap *ds, GUIMain *guib, int dlgxp, int dlgyp
GfxUtil::DrawSpriteWithTransparency(ds, spriteset[guib->BgImage], dlgxp, dlgyp);
}
bool get_custom_dialog_options_dimensions(int dlgnum)
{
bool get_custom_dialog_options_dimensions(int dlgnum) {
ccDialogOptionsRendering.Reset();
ccDialogOptionsRendering.dialogID = dlgnum;
@ -419,8 +398,7 @@ bool get_custom_dialog_options_dimensions(int dlgnum)
run_function_on_non_blocking_thread(&getDialogOptionsDimensionsFunc);
if ((ccDialogOptionsRendering.width > 0) &&
(ccDialogOptionsRendering.height > 0))
{
(ccDialogOptionsRendering.height > 0)) {
return true;
}
return false;
@ -429,8 +407,7 @@ bool get_custom_dialog_options_dimensions(int dlgnum)
#define MAX_TOPIC_HISTORY 50
#define DLG_OPTION_PARSER 99
struct DialogOptions
{
struct DialogOptions {
int dlgnum;
bool runGameLoopsInBackground;
@ -447,7 +424,7 @@ struct DialogOptions
IDriverDependantBitmap *ddb;
Bitmap *subBitmap;
GUITextBox *parserInput;
DialogTopic*dtop;
DialogTopic *dtop;
char disporder[MAXTOPICOPTIONS];
short dispyp[MAXTOPICOPTIONS];
@ -482,16 +459,15 @@ struct DialogOptions
void Close();
};
void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground)
{
void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground) {
dlgnum = _dlgnum;
runGameLoopsInBackground = _runGameLoopsInBackground;
dlgyp = get_fixed_pixel_size(160);
usingfont=FONT_NORMAL;
usingfont = FONT_NORMAL;
lineheight = getfontheight_outlined(usingfont);
linespacing = getfontspacing_outlined(usingfont);
curswas=cur_cursor;
curswas = cur_cursor;
bullet_wid = 0;
ddb = nullptr;
subBitmap = nullptr;
@ -508,7 +484,7 @@ void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground)
update_polled_stuff_if_runtime();
if (game.dialog_bullet > 0)
bullet_wid = game.SpriteInfos[game.dialog_bullet].Width+3;
bullet_wid = game.SpriteInfos[game.dialog_bullet].Width + 3;
// numbered options, leave space for the numbers
if (game.options[OPT_DIALOGNUMBERED] == kDlgOptNumbering)
@ -523,10 +499,10 @@ void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground)
set_mouse_cursor(CURS_ARROW);
dtop=&dialog[dlgnum];
dtop = &dialog[dlgnum];
chose=-1;
numdisp=0;
chose = -1;
numdisp = 0;
parserActivated = 0;
if ((dtop->topicFlags & DTFLG_SHOWPARSER) && (play.disable_dialog_parser == 0)) {
@ -536,22 +512,20 @@ void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground)
parserInput->Font = usingfont;
}
numdisp=0;
numdisp = 0;
for (int i = 0; i < dtop->numoptions; ++i) {
if ((dtop->optionflags[i] & DFLG_ON)==0) continue;
if ((dtop->optionflags[i] & DFLG_ON) == 0) continue;
ensure_text_valid_for_font(dtop->optionnames[i], usingfont);
disporder[numdisp]=i;
disporder[numdisp] = i;
numdisp++;
}
}
void DialogOptions::Show()
{
if (numdisp<1) quit("!DoDialog: all options have been turned off");
void DialogOptions::Show() {
if (numdisp < 1) quit("!DoDialog: all options have been turned off");
// Don't display the options if there is only one and the parser
// is not enabled.
if (!((numdisp > 1) || (parserInput != nullptr) || (play.show_single_dialog_option)))
{
if (!((numdisp > 1) || (parserInput != nullptr) || (play.show_single_dialog_option))) {
chose = disporder[0]; // only one choice, so select it
return;
}
@ -559,8 +533,8 @@ void DialogOptions::Show()
is_textwindow = 0;
forecol = play.dialog_options_highlight_color;
mouseison=-1;
mousewason=-10;
mouseison = -1;
mousewason = -10;
const Rect &ui_view = play.GetUIViewport();
dirtyx = 0;
dirtyy = 0;
@ -570,24 +544,20 @@ void DialogOptions::Show()
dlgxp = 1;
if (get_custom_dialog_options_dimensions(dlgnum))
{
if (get_custom_dialog_options_dimensions(dlgnum)) {
usingCustomRendering = true;
dirtyx = data_to_game_coord(ccDialogOptionsRendering.x);
dirtyy = data_to_game_coord(ccDialogOptionsRendering.y);
dirtywidth = data_to_game_coord(ccDialogOptionsRendering.width);
dirtyheight = data_to_game_coord(ccDialogOptionsRendering.height);
dialog_abs_x = dirtyx;
}
else if (game.options[OPT_DIALOGIFACE] > 0)
{
GUIMain*guib=&guis[game.options[OPT_DIALOGIFACE]];
} else if (game.options[OPT_DIALOGIFACE] > 0) {
GUIMain *guib = &guis[game.options[OPT_DIALOGIFACE]];
if (guib->IsTextWindow()) {
// text-window, so do the QFG4-style speech options
is_textwindow = 1;
forecol = guib->FgColor;
}
else {
} else {
dlgxp = guib->X;
dlgyp = guib->Y;
@ -597,7 +567,7 @@ void DialogOptions::Show()
dirtyheight = guib->Height;
dialog_abs_x = guib->X;
areawid=guib->Width - 5;
areawid = guib->Width - 5;
padding = TEXTWINDOW_PADDING_DEFAULT;
GET_OPTIONS_HEIGHT
@ -608,11 +578,10 @@ void DialogOptions::Show()
}
}
}
else {
} else {
//dlgyp=(play.viewport.GetHeight()-numdisp*txthit)-1;
const Rect &ui_view = play.GetUIViewport();
areawid= ui_view.GetWidth()-5;
areawid = ui_view.GetWidth() - 5;
padding = TEXTWINDOW_PADDING_DEFAULT;
GET_OPTIONS_HEIGHT
dlgyp = ui_view.GetHeight() - needheight;
@ -629,7 +598,7 @@ void DialogOptions::Show()
orixp = dlgxp;
oriyp = dlgyp;
wantRefresh = false;
mouseison=-10;
mouseison = -10;
update_polled_stuff_if_runtime();
if (!play.mouse_cursor_hidden)
@ -637,18 +606,16 @@ void DialogOptions::Show()
update_polled_stuff_if_runtime();
Redraw();
while(Run());
while (Run());
if (!play.mouse_cursor_hidden)
ags_domouse(DOMOUSE_DISABLE);
}
void DialogOptions::Redraw()
{
void DialogOptions::Redraw() {
wantRefresh = true;
if (usingCustomRendering)
{
if (usingCustomRendering) {
tempScrn = recycle_bitmap(tempScrn, game.GetColorDepth(),
data_to_game_coord(ccDialogOptionsRendering.width),
data_to_game_coord(ccDialogOptionsRendering.height));
@ -663,8 +630,7 @@ void DialogOptions::Redraw()
bool options_surface_has_alpha = false;
if (usingCustomRendering)
{
if (usingCustomRendering) {
ccDialogOptionsRendering.surfaceToRenderTo = dialogOptionsRenderingSurface;
ccDialogOptionsRendering.surfaceAccessed = false;
dialogOptionsRenderingSurface->linkedBitmapOnly = tempScrn;
@ -677,8 +643,7 @@ void DialogOptions::Redraw()
if (!ccDialogOptionsRendering.surfaceAccessed)
debug_script_warn("dialog_options_get_dimensions was implemented, but no dialog_options_render function drew anything to the surface");
if (parserInput)
{
if (parserInput) {
parserInput->X = data_to_game_coord(ccDialogOptionsRendering.parserTextboxX);
curyp = data_to_game_coord(ccDialogOptionsRendering.parserTextboxY);
areawid = data_to_game_coord(ccDialogOptionsRendering.parserTextboxWidth);
@ -686,19 +651,18 @@ void DialogOptions::Redraw()
areawid = tempScrn->GetWidth();
}
ccDialogOptionsRendering.needRepaint = false;
}
else if (is_textwindow) {
} else if (is_textwindow) {
// text window behind the options
areawid = data_to_game_coord(play.max_dialogoption_width);
int biggest = 0;
padding = guis[game.options[OPT_DIALOGIFACE]].Padding;
for (int i = 0; i < numdisp; ++i) {
break_up_text_into_lines(get_translation(dtop->optionnames[disporder[i]]), Lines, areawid-((2*padding+2)+bullet_wid), usingfont);
break_up_text_into_lines(get_translation(dtop->optionnames[disporder[i]]), Lines, areawid - ((2 * padding + 2) + bullet_wid), usingfont);
if (longestline > biggest)
biggest = longestline;
}
if (biggest < areawid - ((2*padding+6)+bullet_wid))
areawid = biggest + ((2*padding+6)+bullet_wid);
if (biggest < areawid - ((2 * padding + 6) + bullet_wid))
areawid = biggest + ((2 * padding + 6) + bullet_wid);
if (areawid < data_to_game_coord(play.min_dialogoption_width)) {
areawid = data_to_game_coord(play.min_dialogoption_width);
@ -709,15 +673,15 @@ void DialogOptions::Redraw()
GET_OPTIONS_HEIGHT
int savedwid = areawid;
int txoffs=0,tyoffs=0,yspos = ui_view.GetHeight()/2-(2*padding+needheight)/2;
int xspos = ui_view.GetWidth()/2 - areawid/2;
int txoffs = 0, tyoffs = 0, yspos = ui_view.GetHeight() / 2 - (2 * padding + needheight) / 2;
int xspos = ui_view.GetWidth() / 2 - areawid / 2;
// shift window to the right if QG4-style full-screen pic
if ((game.options[OPT_SPEECHTYPE] == 3) && (said_text > 0))
xspos = (ui_view.GetWidth() - areawid) - get_fixed_pixel_size(10);
// needs to draw the right text window, not the default
Bitmap *text_window_ds = nullptr;
draw_text_window(&text_window_ds, false, &txoffs,&tyoffs,&xspos,&yspos,&areawid,nullptr,needheight, game.options[OPT_DIALOGIFACE]);
draw_text_window(&text_window_ds, false, &txoffs, &tyoffs, &xspos, &yspos, &areawid, nullptr, needheight, game.options[OPT_DIALOGIFACE]);
options_surface_has_alpha = guis[game.options[OPT_DIALOGIFACE]].HasAlphaChannel();
// since draw_text_window incrases the width, restore it
areawid = savedwid;
@ -737,21 +701,19 @@ void DialogOptions::Redraw()
txoffs += xspos;
tyoffs += yspos;
dlgyp = tyoffs;
curyp = write_dialog_options(ds, options_surface_has_alpha, txoffs,tyoffs,numdisp,mouseison,areawid,bullet_wid,usingfont,dtop,disporder,dispyp,linespacing,forecol,padding);
curyp = write_dialog_options(ds, options_surface_has_alpha, txoffs, tyoffs, numdisp, mouseison, areawid, bullet_wid, usingfont, dtop, disporder, dispyp, linespacing, forecol, padding);
if (parserInput)
parserInput->X = txoffs;
}
else {
} else {
if (wantRefresh) {
// redraw the black background so that anti-alias
// fonts don't re-alias themselves
if (game.options[OPT_DIALOGIFACE] == 0) {
color_t draw_color = ds->GetCompatibleColor(16);
ds->FillRect(Rect(0,dlgyp-1, ui_view.GetWidth()-1, ui_view.GetHeight()-1), draw_color);
}
else {
GUIMain* guib = &guis[game.options[OPT_DIALOGIFACE]];
ds->FillRect(Rect(0, dlgyp - 1, ui_view.GetWidth() - 1, ui_view.GetHeight() - 1), draw_color);
} else {
GUIMain *guib = &guis[game.options[OPT_DIALOGIFACE]];
if (!guib->IsTextWindow())
draw_gui_for_dialog_options(ds, guib, dlgxp, dlgyp);
}
@ -760,17 +722,14 @@ void DialogOptions::Redraw()
dirtyx = 0;
dirtywidth = ui_view.GetWidth();
if (game.options[OPT_DIALOGIFACE] > 0)
{
if (game.options[OPT_DIALOGIFACE] > 0) {
// the whole GUI area should be marked dirty in order
// to ensure it gets drawn
GUIMain* guib = &guis[game.options[OPT_DIALOGIFACE]];
GUIMain *guib = &guis[game.options[OPT_DIALOGIFACE]];
dirtyheight = guib->Height;
dirtyy = dlgyp;
options_surface_has_alpha = guib->HasAlphaChannel();
}
else
{
} else {
dirtyy = dlgyp - 1;
dirtyheight = needheight + 1;
options_surface_has_alpha = false;
@ -786,7 +745,7 @@ void DialogOptions::Redraw()
//curyp = dlgyp + 1;
curyp = dlgyp;
curyp = write_dialog_options(ds, options_surface_has_alpha, dlgxp,curyp,numdisp,mouseison,areawid,bullet_wid,usingfont,dtop,disporder,dispyp,linespacing,forecol,padding);
curyp = write_dialog_options(ds, options_surface_has_alpha, dlgxp, curyp, numdisp, mouseison, areawid, bullet_wid, usingfont, dtop, disporder, dispyp, linespacing, forecol, padding);
/*if (curyp > play.viewport.GetHeight()) {
dlgyp = play.viewport.GetHeight() - (curyp - dlgyp);
@ -805,8 +764,7 @@ void DialogOptions::Redraw()
if (mouseison == DLG_OPTION_PARSER)
parserInput->TextColor = forecol;
if (game.dialog_bullet) // the parser X will get moved in a second
{
if (game.dialog_bullet) { // the parser X will get moved in a second
draw_gui_sprite_v330(ds, game.dialog_bullet, parserInput->X, parserInput->Y, options_surface_has_alpha);
}
@ -826,20 +784,16 @@ void DialogOptions::Redraw()
update_polled_stuff_if_runtime();
if (usingCustomRendering)
{
if (usingCustomRendering) {
subBitmap->Blit(tempScrn, 0, 0, 0, 0, tempScrn->GetWidth(), tempScrn->GetHeight());
invalidate_rect(dirtyx, dirtyy, dirtyx + subBitmap->GetWidth(), dirtyy + subBitmap->GetHeight(), false);
}
else
{
} else {
subBitmap->Blit(tempScrn, dirtyx, dirtyy, 0, 0, dirtywidth, dirtyheight);
}
if ((ddb != nullptr) &&
((ddb->GetWidth() != dirtywidth) ||
(ddb->GetHeight() != dirtyheight)))
{
(ddb->GetHeight() != dirtyheight))) {
gfxDriver->DestroyDDB(ddb);
ddb = nullptr;
}
@ -849,30 +803,24 @@ void DialogOptions::Redraw()
else
gfxDriver->UpdateDDBFromBitmap(ddb, subBitmap, options_surface_has_alpha);
if (runGameLoopsInBackground)
{
if (runGameLoopsInBackground) {
render_graphics(ddb, dirtyx, dirtyy);
}
}
bool DialogOptions::Run()
{
bool DialogOptions::Run() {
const bool new_custom_render = usingCustomRendering && game.options[OPT_DIALOGOPTIONSAPI] >= 0;
if (runGameLoopsInBackground)
{
if (runGameLoopsInBackground) {
play.disabled_user_interface++;
UpdateGameOnce(false, ddb, dirtyx, dirtyy);
play.disabled_user_interface--;
}
else
{
} else {
update_audio_system_on_game_loop();
render_graphics(ddb, dirtyx, dirtyy);
}
if (new_custom_render)
{
if (new_custom_render) {
runDialogOptionRepExecFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&runDialogOptionRepExecFunc);
}
@ -890,8 +838,7 @@ bool DialogOptions::Run()
//ags_domouse(DOMOUSE_DISABLE);
Redraw();
return true; // continue running loop
}
else if ((gkey >= 32) || (gkey == 13) || (gkey == 8)) {
} else if ((gkey >= 32) || (gkey == 13) || (gkey == 8)) {
parserInput->OnKeyPress(gkey);
if (!parserInput->IsActivated) {
//ags_domouse(DOMOUSE_DISABLE);
@ -899,17 +846,14 @@ bool DialogOptions::Run()
return true; // continue running loop
}
}
}
else if (new_custom_render)
{
} else if (new_custom_render) {
runDialogOptionKeyPressHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionKeyPressHandlerFunc.params[1].SetInt32(GetKeyForKeyPressCb(gkey));
run_function_on_non_blocking_thread(&runDialogOptionKeyPressHandlerFunc);
}
// Allow selection of options by keyboard shortcuts
else if (game.options[OPT_DIALOGNUMBERED] >= kDlgOptKeysOnly &&
gkey >= '1' && gkey <= '9')
{
gkey >= '1' && gkey <= '9') {
gkey -= '1';
if (gkey < numdisp) {
chose = disporder[gkey];
@ -917,15 +861,13 @@ bool DialogOptions::Run()
}
}
}
mousewason=mouseison;
mouseison=-1;
mousewason = mouseison;
mouseison = -1;
if (new_custom_render); // do not automatically detect option under mouse
else if (usingCustomRendering)
{
else if (usingCustomRendering) {
if ((mousex >= dirtyx) && (mousey >= dirtyy) &&
(mousex < dirtyx + tempScrn->GetWidth()) &&
(mousey < dirtyy + tempScrn->GetHeight()))
{
(mousey < dirtyy + tempScrn->GetHeight())) {
getDialogOptionUnderCursorFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&getDialogOptionUnderCursorFunc);
@ -933,20 +875,19 @@ bool DialogOptions::Run()
quit("!The script function dialog_options_get_active is not implemented. It must be present to use a custom dialogue system.");
mouseison = ccDialogOptionsRendering.activeOptionID;
}
else
{
} else {
ccDialogOptionsRendering.activeOptionID = -1;
}
}
else if (mousex >= dialog_abs_x && mousex < (dialog_abs_x + areawid) &&
mousey >= dlgyp && mousey < curyp)
{
mouseison=numdisp-1;
} else if (mousex >= dialog_abs_x && mousex < (dialog_abs_x + areawid) &&
mousey >= dlgyp && mousey < curyp) {
mouseison = numdisp - 1;
for (int i = 0; i < numdisp; ++i) {
if (mousey < dispyp[i]) { mouseison=i-1; break; }
if (mousey < dispyp[i]) {
mouseison = i - 1;
break;
}
if ((mouseison<0) | (mouseison>=numdisp)) mouseison=-1;
}
if ((mouseison < 0) | (mouseison >= numdisp)) mouseison = -1;
}
if (parserInput != nullptr) {
@ -965,18 +906,14 @@ bool DialogOptions::Run()
int mouseButtonPressed = NONE;
int mouseWheelTurn = 0;
if (run_service_mb_controls(mouseButtonPressed, mouseWheelTurn) && mouseButtonPressed >= 0 &&
!play.IsIgnoringInput())
{
if (mouseison < 0 && !new_custom_render)
{
if (usingCustomRendering)
{
!play.IsIgnoringInput()) {
if (mouseison < 0 && !new_custom_render) {
if (usingCustomRendering) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32(mouseButtonPressed + 1);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc);
if (runDialogOptionMouseClickHandlerFunc.atLeastOneImplementationExists)
{
if (runDialogOptionMouseClickHandlerFunc.atLeastOneImplementationExists) {
Redraw();
return true; // continue running loop
}
@ -986,34 +923,26 @@ bool DialogOptions::Run()
if (mouseison == DLG_OPTION_PARSER) {
// they clicked the text box
parserActivated = 1;
}
else if (new_custom_render)
{
} else if (new_custom_render) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32(mouseButtonPressed + 1);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc);
}
else if (usingCustomRendering)
{
} else if (usingCustomRendering) {
chose = mouseison;
return false; // end dialog options running loop
}
else {
chose=disporder[mouseison];
} else {
chose = disporder[mouseison];
return false; // end dialog options running loop
}
}
if (usingCustomRendering)
{
if (mouseWheelTurn != 0)
{
if (usingCustomRendering) {
if (mouseWheelTurn != 0) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32((mouseWheelTurn < 0) ? 9 : 8);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc);
if (!new_custom_render)
{
if (!new_custom_render) {
if (runDialogOptionMouseClickHandlerFunc.atLeastOneImplementationExists)
Redraw();
return true; // continue running loop
@ -1026,8 +955,7 @@ bool DialogOptions::Run()
if (!parserInput->Text.IsEmpty() != 0) {
chose = DLG_OPTION_PARSER;
return false; // end dialog options running loop
}
else {
} else {
parserActivated = 0;
parserInput->IsActivated = 0;
}
@ -1037,16 +965,13 @@ bool DialogOptions::Run()
Redraw();
return true; // continue running loop
}
if (new_custom_render)
{
if (ccDialogOptionsRendering.chosenOptionID >= 0)
{
if (new_custom_render) {
if (ccDialogOptionsRendering.chosenOptionID >= 0) {
chose = ccDialogOptionsRendering.chosenOptionID;
ccDialogOptionsRendering.chosenOptionID = -1;
return false; // end dialog options running loop
}
if (ccDialogOptionsRendering.needRepaint)
{
if (ccDialogOptionsRendering.needRepaint) {
Redraw();
return true; // continue running loop
}
@ -1054,23 +979,20 @@ bool DialogOptions::Run()
update_polled_stuff_if_runtime();
if (play.fast_forward == 0)
{
if (play.fast_forward == 0) {
WaitForNextFrame();
}
return true; // continue running loop
}
void DialogOptions::Close()
{
void DialogOptions::Close() {
ags_clear_input_buffer();
invalidate_screen();
if (parserActivated)
{
strcpy (play.lastParserEntry, parserInput->Text);
ParseText (parserInput->Text);
if (parserActivated) {
strcpy(play.lastParserEntry, parserInput->Text);
ParseText(parserInput->Text);
chose = CHOSE_TEXTPARSER;
}
@ -1093,27 +1015,22 @@ void DialogOptions::Close()
DialogOptions DlgOpt;
int show_dialog_options(int _dlgnum, int sayChosenOption, bool _runGameLoopsInBackground)
{
int show_dialog_options(int _dlgnum, int sayChosenOption, bool _runGameLoopsInBackground) {
DlgOpt.Prepare(_dlgnum, _runGameLoopsInBackground);
DlgOpt.Show();
DlgOpt.Close();
int dialog_choice = DlgOpt.chose;
if (dialog_choice != CHOSE_TEXTPARSER)
{
if (dialog_choice != CHOSE_TEXTPARSER) {
DialogTopic *dialog_topic = DlgOpt.dtop;
int &option_flags = dialog_topic->optionflags[dialog_choice];
const char *option_name = DlgOpt.dtop->optionnames[dialog_choice];
option_flags |= DFLG_HASBEENCHOSEN;
bool sayTheOption = false;
if (sayChosenOption == SAYCHOSEN_YES)
{
if (sayChosenOption == SAYCHOSEN_YES) {
sayTheOption = true;
}
else if (sayChosenOption == SAYCHOSEN_USEFLAG)
{
} else if (sayChosenOption == SAYCHOSEN_USEFLAG) {
sayTheOption = ((option_flags & DFLG_NOREPEAT) == 0);
}
@ -1124,8 +1041,7 @@ int show_dialog_options(int _dlgnum, int sayChosenOption, bool _runGameLoopsInBa
return dialog_choice;
}
void do_conversation(int dlgnum)
{
void do_conversation(int dlgnum) {
EndSkippingUntilCharStops();
// AGS 2.x always makes the mouse cursor visible when displaying a dialog.
@ -1140,25 +1056,21 @@ void do_conversation(int dlgnum)
// run the startup script
int tocar = run_dialog_script(dtop, dlgnum, dtop->startupentrypoint, 0);
if ((tocar == RUN_DIALOG_STOP_DIALOG) ||
(tocar == RUN_DIALOG_GOTO_PREVIOUS))
{
(tocar == RUN_DIALOG_GOTO_PREVIOUS)) {
// 'stop' or 'goto-previous' from first startup script
remove_screen_overlay(OVER_COMPLETE);
play.in_conversation--;
return;
}
else if (tocar >= 0)
} else if (tocar >= 0)
dlgnum = tocar;
while (dlgnum >= 0)
{
while (dlgnum >= 0) {
if (dlgnum >= game.numdialog)
quit("!RunDialog: invalid dialog number specified");
dtop = &dialog[dlgnum];
if (dlgnum != dlgnum_was)
{
if (dlgnum != dlgnum_was) {
// dialog topic changed, so play the startup
// script for the new topic
tocar = run_dialog_script(dtop, dlgnum, dtop->startupentrypoint, 0);
@ -1167,8 +1079,7 @@ void do_conversation(int dlgnum)
if (numPrevTopics < 1) {
// goto-previous on first topic -- end dialog
tocar = RUN_DIALOG_STOP_DIALOG;
}
else {
} else {
tocar = previousTopics[numPrevTopics - 1];
numPrevTopics--;
}
@ -1188,8 +1099,7 @@ void do_conversation(int dlgnum)
int chose = show_dialog_options(dlgnum, SAYCHOSEN_USEFLAG, (game.options[OPT_RUNGAMEDLGOPTS] != 0));
if (chose == CHOSE_TEXTPARSER)
{
if (chose == CHOSE_TEXTPARSER) {
said_speech_line = 0;
tocar = run_dialog_request(dlgnum);
@ -1201,17 +1111,14 @@ void do_conversation(int dlgnum)
EnableInterface();
set_mouse_cursor(CURS_ARROW);
}
}
else
{
} else {
tocar = run_dialog_script(dtop, dlgnum, dtop->entrypoints[chose], chose + 1);
}
if (tocar == RUN_DIALOG_GOTO_PREVIOUS) {
if (numPrevTopics < 1) {
tocar = RUN_DIALOG_STOP_DIALOG;
}
else {
} else {
tocar = previousTopics[numPrevTopics - 1];
numPrevTopics--;
}
@ -1247,66 +1154,55 @@ void do_conversation(int dlgnum)
extern ScriptString myScriptStringImpl;
// int (ScriptDialog *sd)
RuntimeScriptValue Sc_Dialog_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialog, Dialog_GetID);
}
// int (ScriptDialog *sd)
RuntimeScriptValue Sc_Dialog_GetOptionCount(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_GetOptionCount(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialog, Dialog_GetOptionCount);
}
// int (ScriptDialog *sd)
RuntimeScriptValue Sc_Dialog_GetShowTextParser(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_GetShowTextParser(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialog, Dialog_GetShowTextParser);
}
// int (ScriptDialog *sd, int sayChosenOption)
RuntimeScriptValue Sc_Dialog_DisplayOptions(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_DisplayOptions(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT(ScriptDialog, Dialog_DisplayOptions);
}
// int (ScriptDialog *sd, int option)
RuntimeScriptValue Sc_Dialog_GetOptionState(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_GetOptionState(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT(ScriptDialog, Dialog_GetOptionState);
}
// const char* (ScriptDialog *sd, int option)
RuntimeScriptValue Sc_Dialog_GetOptionText(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_GetOptionText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ_PINT(ScriptDialog, const char, myScriptStringImpl, Dialog_GetOptionText);
}
// int (ScriptDialog *sd, int option)
RuntimeScriptValue Sc_Dialog_HasOptionBeenChosen(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_HasOptionBeenChosen(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT(ScriptDialog, Dialog_HasOptionBeenChosen);
}
RuntimeScriptValue Sc_Dialog_SetHasOptionBeenChosen(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_SetHasOptionBeenChosen(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT_PBOOL(ScriptDialog, Dialog_SetHasOptionBeenChosen);
}
// void (ScriptDialog *sd, int option, int newState)
RuntimeScriptValue Sc_Dialog_SetOptionState(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_SetOptionState(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(ScriptDialog, Dialog_SetOptionState);
}
// void (ScriptDialog *sd)
RuntimeScriptValue Sc_Dialog_Start(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_Dialog_Start(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptDialog, Dialog_Start);
}
void RegisterDialogAPI()
{
void RegisterDialogAPI() {
ccAddExternalObjectFunction("Dialog::get_ID", Sc_Dialog_GetID);
ccAddExternalObjectFunction("Dialog::get_OptionCount", Sc_Dialog_GetOptionCount);
ccAddExternalObjectFunction("Dialog::get_ShowTextParser", Sc_Dialog_GetShowTextParser);
@ -1320,13 +1216,13 @@ void RegisterDialogAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("Dialog::get_ID", (void*)Dialog_GetID);
ccAddExternalFunctionForPlugin("Dialog::get_OptionCount", (void*)Dialog_GetOptionCount);
ccAddExternalFunctionForPlugin("Dialog::get_ShowTextParser", (void*)Dialog_GetShowTextParser);
ccAddExternalFunctionForPlugin("Dialog::DisplayOptions^1", (void*)Dialog_DisplayOptions);
ccAddExternalFunctionForPlugin("Dialog::GetOptionState^1", (void*)Dialog_GetOptionState);
ccAddExternalFunctionForPlugin("Dialog::GetOptionText^1", (void*)Dialog_GetOptionText);
ccAddExternalFunctionForPlugin("Dialog::HasOptionBeenChosen^1", (void*)Dialog_HasOptionBeenChosen);
ccAddExternalFunctionForPlugin("Dialog::SetOptionState^2", (void*)Dialog_SetOptionState);
ccAddExternalFunctionForPlugin("Dialog::Start^0", (void*)Dialog_Start);
ccAddExternalFunctionForPlugin("Dialog::get_ID", (void *)Dialog_GetID);
ccAddExternalFunctionForPlugin("Dialog::get_OptionCount", (void *)Dialog_GetOptionCount);
ccAddExternalFunctionForPlugin("Dialog::get_ShowTextParser", (void *)Dialog_GetShowTextParser);
ccAddExternalFunctionForPlugin("Dialog::DisplayOptions^1", (void *)Dialog_DisplayOptions);
ccAddExternalFunctionForPlugin("Dialog::GetOptionState^1", (void *)Dialog_GetOptionState);
ccAddExternalFunctionForPlugin("Dialog::GetOptionText^1", (void *)Dialog_GetOptionText);
ccAddExternalFunctionForPlugin("Dialog::HasOptionBeenChosen^1", (void *)Dialog_HasOptionBeenChosen);
ccAddExternalFunctionForPlugin("Dialog::SetOptionState^2", (void *)Dialog_SetOptionState);
ccAddExternalFunctionForPlugin("Dialog::Start^0", (void *)Dialog_Start);
}

View file

@ -29,7 +29,7 @@
int Dialog_GetID(ScriptDialog *sd);
int Dialog_GetOptionCount(ScriptDialog *sd);
int Dialog_GetShowTextParser(ScriptDialog *sd);
const char* Dialog_GetOptionText(ScriptDialog *sd, int option);
const char *Dialog_GetOptionText(ScriptDialog *sd, int option);
int Dialog_DisplayOptions(ScriptDialog *sd, int sayChosenOption);
int Dialog_GetOptionState(ScriptDialog *sd, int option);
int Dialog_HasOptionBeenChosen(ScriptDialog *sd, int option);

View file

@ -33,121 +33,98 @@ extern CCDialog ccDynamicDialog;
// ** SCRIPT DIALOGOPTIONSRENDERING OBJECT
void DialogOptionsRendering_Update(ScriptDialogOptionsRendering *dlgOptRender)
{
void DialogOptionsRendering_Update(ScriptDialogOptionsRendering *dlgOptRender) {
dlgOptRender->needRepaint = true;
}
bool DialogOptionsRendering_RunActiveOption(ScriptDialogOptionsRendering *dlgOptRender)
{
bool DialogOptionsRendering_RunActiveOption(ScriptDialogOptionsRendering *dlgOptRender) {
dlgOptRender->chosenOptionID = dlgOptRender->activeOptionID;
return dlgOptRender->chosenOptionID >= 0;
}
int DialogOptionsRendering_GetX(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetX(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->x;
}
void DialogOptionsRendering_SetX(ScriptDialogOptionsRendering *dlgOptRender, int newX)
{
void DialogOptionsRendering_SetX(ScriptDialogOptionsRendering *dlgOptRender, int newX) {
dlgOptRender->x = newX;
}
int DialogOptionsRendering_GetY(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetY(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->y;
}
void DialogOptionsRendering_SetY(ScriptDialogOptionsRendering *dlgOptRender, int newY)
{
void DialogOptionsRendering_SetY(ScriptDialogOptionsRendering *dlgOptRender, int newY) {
dlgOptRender->y = newY;
}
int DialogOptionsRendering_GetWidth(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetWidth(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->width;
}
void DialogOptionsRendering_SetWidth(ScriptDialogOptionsRendering *dlgOptRender, int newWidth)
{
void DialogOptionsRendering_SetWidth(ScriptDialogOptionsRendering *dlgOptRender, int newWidth) {
dlgOptRender->width = newWidth;
}
int DialogOptionsRendering_GetHeight(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetHeight(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->height;
}
void DialogOptionsRendering_SetHeight(ScriptDialogOptionsRendering *dlgOptRender, int newHeight)
{
void DialogOptionsRendering_SetHeight(ScriptDialogOptionsRendering *dlgOptRender, int newHeight) {
dlgOptRender->height = newHeight;
}
int DialogOptionsRendering_GetHasAlphaChannel(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetHasAlphaChannel(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->hasAlphaChannel;
}
void DialogOptionsRendering_SetHasAlphaChannel(ScriptDialogOptionsRendering *dlgOptRender, bool hasAlphaChannel)
{
void DialogOptionsRendering_SetHasAlphaChannel(ScriptDialogOptionsRendering *dlgOptRender, bool hasAlphaChannel) {
dlgOptRender->hasAlphaChannel = hasAlphaChannel;
}
int DialogOptionsRendering_GetParserTextboxX(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetParserTextboxX(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->parserTextboxX;
}
void DialogOptionsRendering_SetParserTextboxX(ScriptDialogOptionsRendering *dlgOptRender, int newX)
{
void DialogOptionsRendering_SetParserTextboxX(ScriptDialogOptionsRendering *dlgOptRender, int newX) {
dlgOptRender->parserTextboxX = newX;
}
int DialogOptionsRendering_GetParserTextboxY(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetParserTextboxY(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->parserTextboxY;
}
void DialogOptionsRendering_SetParserTextboxY(ScriptDialogOptionsRendering *dlgOptRender, int newY)
{
void DialogOptionsRendering_SetParserTextboxY(ScriptDialogOptionsRendering *dlgOptRender, int newY) {
dlgOptRender->parserTextboxY = newY;
}
int DialogOptionsRendering_GetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->parserTextboxWidth;
}
void DialogOptionsRendering_SetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender, int newWidth)
{
void DialogOptionsRendering_SetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender, int newWidth) {
dlgOptRender->parserTextboxWidth = newWidth;
}
ScriptDialog* DialogOptionsRendering_GetDialogToRender(ScriptDialogOptionsRendering *dlgOptRender)
{
ScriptDialog *DialogOptionsRendering_GetDialogToRender(ScriptDialogOptionsRendering *dlgOptRender) {
return &scrDialog[dlgOptRender->dialogID];
}
ScriptDrawingSurface* DialogOptionsRendering_GetSurface(ScriptDialogOptionsRendering *dlgOptRender)
{
ScriptDrawingSurface *DialogOptionsRendering_GetSurface(ScriptDialogOptionsRendering *dlgOptRender) {
dlgOptRender->surfaceAccessed = true;
return dlgOptRender->surfaceToRenderTo;
}
int DialogOptionsRendering_GetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender)
{
int DialogOptionsRendering_GetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender) {
return dlgOptRender->activeOptionID + 1;
}
void DialogOptionsRendering_SetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender, int activeOptionID)
{
void DialogOptionsRendering_SetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender, int activeOptionID) {
int optionCount = dialog[scrDialog[dlgOptRender->dialogID].id].numoptions;
if ((activeOptionID < 0) || (activeOptionID > optionCount))
quitprintf("DialogOptionsRenderingInfo.ActiveOptionID: invalid ID specified for this dialog (specified %d, valid range: 1..%d)", activeOptionID, optionCount);
if (dlgOptRender->activeOptionID != activeOptionID - 1)
{
if (dlgOptRender->activeOptionID != activeOptionID - 1) {
dlgOptRender->activeOptionID = activeOptionID - 1;
dlgOptRender->needRepaint = true;
}
@ -163,137 +140,114 @@ void DialogOptionsRendering_SetActiveOptionID(ScriptDialogOptionsRendering *dlgO
#include "script/script_api.h"
#include "script/script_runtime.h"
RuntimeScriptValue Sc_DialogOptionsRendering_Update(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_Update(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptDialogOptionsRendering, DialogOptionsRendering_Update);
}
RuntimeScriptValue Sc_DialogOptionsRendering_RunActiveOption(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_RunActiveOption(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_BOOL(ScriptDialogOptionsRendering, DialogOptionsRendering_RunActiveOption);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetActiveOptionID(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetActiveOptionID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetActiveOptionID);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int activeOptionID)
RuntimeScriptValue Sc_DialogOptionsRendering_SetActiveOptionID(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetActiveOptionID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetActiveOptionID);
}
// ScriptDialog* (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetDialogToRender(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetDialogToRender(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(ScriptDialogOptionsRendering, ScriptDialog, ccDynamicDialog, DialogOptionsRendering_GetDialogToRender);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetHeight);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newHeight)
RuntimeScriptValue Sc_DialogOptionsRendering_SetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetHeight);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxX(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetParserTextboxX);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newX)
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxX(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetParserTextboxX);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxY(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetParserTextboxY);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newY)
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxY(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetParserTextboxY);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetParserTextboxWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetParserTextboxWidth);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newWidth)
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetParserTextboxWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetParserTextboxWidth);
}
// ScriptDrawingSurface* (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetSurface(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetSurface(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJAUTO(ScriptDialogOptionsRendering, ScriptDrawingSurface, DialogOptionsRendering_GetSurface);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetWidth);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newWidth)
RuntimeScriptValue Sc_DialogOptionsRendering_SetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetWidth);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetX(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetX);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newX)
RuntimeScriptValue Sc_DialogOptionsRendering_SetX(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetX);
}
// int (ScriptDialogOptionsRendering *dlgOptRender)
RuntimeScriptValue Sc_DialogOptionsRendering_GetY(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetY);
}
// void (ScriptDialogOptionsRendering *dlgOptRender, int newY)
RuntimeScriptValue Sc_DialogOptionsRendering_SetY(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDialogOptionsRendering, DialogOptionsRendering_SetY);
}
RuntimeScriptValue Sc_DialogOptionsRendering_GetHasAlphaChannel(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_GetHasAlphaChannel(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDialogOptionsRendering, DialogOptionsRendering_GetHasAlphaChannel);
}
RuntimeScriptValue Sc_DialogOptionsRendering_SetHasAlphaChannel(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DialogOptionsRendering_SetHasAlphaChannel(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PBOOL(ScriptDialogOptionsRendering, DialogOptionsRendering_SetHasAlphaChannel);
}
void RegisterDialogOptionsRenderingAPI()
{
void RegisterDialogOptionsRenderingAPI() {
ccAddExternalObjectFunction("DialogOptionsRenderingInfo::Update^0", Sc_DialogOptionsRendering_Update);
ccAddExternalObjectFunction("DialogOptionsRenderingInfo::RunActiveOption^0", Sc_DialogOptionsRendering_RunActiveOption);
ccAddExternalObjectFunction("DialogOptionsRenderingInfo::get_ActiveOptionID", Sc_DialogOptionsRendering_GetActiveOptionID);
@ -319,22 +273,22 @@ void RegisterDialogOptionsRenderingAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ActiveOptionID", (void*)DialogOptionsRendering_GetActiveOptionID);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ActiveOptionID", (void*)DialogOptionsRendering_SetActiveOptionID);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_DialogToRender", (void*)DialogOptionsRendering_GetDialogToRender);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Height", (void*)DialogOptionsRendering_GetHeight);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Height", (void*)DialogOptionsRendering_SetHeight);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxX", (void*)DialogOptionsRendering_GetParserTextboxX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxX", (void*)DialogOptionsRendering_SetParserTextboxX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxY", (void*)DialogOptionsRendering_GetParserTextboxY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxY", (void*)DialogOptionsRendering_SetParserTextboxY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxWidth", (void*)DialogOptionsRendering_GetParserTextboxWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxWidth", (void*)DialogOptionsRendering_SetParserTextboxWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Surface", (void*)DialogOptionsRendering_GetSurface);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Width", (void*)DialogOptionsRendering_GetWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Width", (void*)DialogOptionsRendering_SetWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_X", (void*)DialogOptionsRendering_GetX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_X", (void*)DialogOptionsRendering_SetX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Y", (void*)DialogOptionsRendering_GetY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Y", (void*)DialogOptionsRendering_SetY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ActiveOptionID", (void *)DialogOptionsRendering_GetActiveOptionID);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ActiveOptionID", (void *)DialogOptionsRendering_SetActiveOptionID);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_DialogToRender", (void *)DialogOptionsRendering_GetDialogToRender);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Height", (void *)DialogOptionsRendering_GetHeight);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Height", (void *)DialogOptionsRendering_SetHeight);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxX", (void *)DialogOptionsRendering_GetParserTextboxX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxX", (void *)DialogOptionsRendering_SetParserTextboxX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxY", (void *)DialogOptionsRendering_GetParserTextboxY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxY", (void *)DialogOptionsRendering_SetParserTextboxY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_ParserTextBoxWidth", (void *)DialogOptionsRendering_GetParserTextboxWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_ParserTextBoxWidth", (void *)DialogOptionsRendering_SetParserTextboxWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Surface", (void *)DialogOptionsRendering_GetSurface);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Width", (void *)DialogOptionsRendering_GetWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Width", (void *)DialogOptionsRendering_SetWidth);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_X", (void *)DialogOptionsRendering_GetX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_X", (void *)DialogOptionsRendering_SetX);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::get_Y", (void *)DialogOptionsRendering_GetY);
ccAddExternalFunctionForPlugin("DialogOptionsRenderingInfo::set_Y", (void *)DialogOptionsRendering_SetY);
}

View file

@ -42,8 +42,8 @@ int DialogOptionsRendering_GetParserTextboxY(ScriptDialogOptionsRendering *dlgO
void DialogOptionsRendering_SetParserTextboxY(ScriptDialogOptionsRendering *dlgOptRender, int newY);
int DialogOptionsRendering_GetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender);
void DialogOptionsRendering_SetParserTextboxWidth(ScriptDialogOptionsRendering *dlgOptRender, int newWidth);
ScriptDialog* DialogOptionsRendering_GetDialogToRender(ScriptDialogOptionsRendering *dlgOptRender);
ScriptDrawingSurface* DialogOptionsRendering_GetSurface(ScriptDialogOptionsRendering *dlgOptRender);
ScriptDialog *DialogOptionsRendering_GetDialogToRender(ScriptDialogOptionsRendering *dlgOptRender);
ScriptDrawingSurface *DialogOptionsRendering_GetSurface(ScriptDialogOptionsRendering *dlgOptRender);
int DialogOptionsRendering_GetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender);
void DialogOptionsRendering_SetActiveOptionID(ScriptDialogOptionsRendering *dlgOptRender, int activeOptionID);

View file

@ -65,12 +65,11 @@ extern AGSPlatformDriver *platform;
extern int loops_per_character;
extern SpriteCache spriteset;
int display_message_aschar=0;
int display_message_aschar = 0;
TopBarSettings topBar;
struct DisplayVars
{
struct DisplayVars {
int lineheight; // font's height of single line
int linespacing; // font's line spacing
int fulltxtheight; // total height of all the text
@ -79,8 +78,7 @@ struct DisplayVars
// Pass yy = -1 to find Y co-ord automatically
// allowShrink = 0 for none, 1 for leftwards, 2 for rightwards
// pass blocking=2 to create permanent overlay
int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont, int asspch, int isThought, int allowShrink, bool overlayPositionFixed)
{
int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int usingfont, int asspch, int isThought, int allowShrink, bool overlayPositionFixed) {
const bool use_speech_textwindow = (asspch < 0) && (game.options[OPT_SPEECHTYPE] >= 2);
const bool use_thought_gui = (isThought) && (game.options[OPT_THOUGHTGUI] > 0);
@ -98,9 +96,9 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
int paddingDoubledScaled = get_fixed_pixel_size(padding * 2); // Just in case screen size does is not neatly divisible by 320x200
ensure_text_valid_for_font(todis, usingfont);
break_up_text_into_lines(todis, Lines, wii-2*padding, usingfont);
break_up_text_into_lines(todis, Lines, wii - 2 * padding, usingfont);
disp.lineheight = getfontheight_outlined(usingfont);
disp.linespacing= getfontspacing_outlined(usingfont);
disp.linespacing = getfontspacing_outlined(usingfont);
disp.fulltxtheight = getheightoflines(usingfont, Lines.Count());
// AGS 2.x: If the screen is faded out, fade in again when displaying a message box.
@ -138,12 +136,12 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
const Rect &ui_view = play.GetUIViewport();
if (xx == OVR_AUTOPLACE) ;
// centre text in middle of screen
else if (yy<0) yy= ui_view.GetHeight()/2-disp.fulltxtheight/2-padding;
else if (yy < 0) yy = ui_view.GetHeight() / 2 - disp.fulltxtheight / 2 - padding;
// speech, so it wants to be above the character's head
else if (asspch > 0) {
yy-=disp.fulltxtheight;
if (yy < 5) yy=5;
yy = adjust_y_for_guis (yy);
yy -= disp.fulltxtheight;
if (yy < 5) yy = 5;
yy = adjust_y_for_guis(yy);
}
if (longestline < wii - paddingDoubledScaled) {
@ -159,17 +157,16 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
xx += (oldWid - wii);
}
if (xx<-1) {
xx=(-xx)-wii/2;
if (xx < -1) {
xx = (-xx) - wii / 2;
if (xx < 0)
xx = 0;
xx = adjust_x_for_guis (xx, yy);
xx = adjust_x_for_guis(xx, yy);
if (xx + wii >= ui_view.GetWidth())
xx = (ui_view.GetWidth() - wii) - 5;
}
else if (xx<0) xx= ui_view.GetWidth()/2-wii/2;
} else if (xx < 0) xx = ui_view.GetWidth() / 2 - wii / 2;
int extraHeight = paddingDoubledScaled;
color_t text_color = MakeColor(15);
@ -188,7 +185,7 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
int adjustedXX = xx;
int adjustedYY = yy;
if ((strlen (todis) < 1) || (strcmp (todis, " ") == 0) || (wii == 0)) ;
if ((strlen(todis) < 1) || (strcmp(todis, " ") == 0) || (wii == 0)) ;
// if it's an empty speech line, don't draw anything
else if (asspch) { //text_color = ds->GetCompatibleColor(12);
int ttxleft = 0, ttxtop = paddingScaled, oriwid = wii - padding * 2;
@ -196,28 +193,24 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
if (use_speech_textwindow) {
drawBackground = 1;
}
else if (use_thought_gui) {
} else if (use_thought_gui) {
// make it treat it as drawing inside a window now
if (asspch > 0)
asspch = -asspch;
drawBackground = 1;
}
if (drawBackground)
{
if (drawBackground) {
draw_text_window_and_bar(&text_window_ds, wantFreeScreenop, &ttxleft, &ttxtop, &adjustedXX, &adjustedYY, &wii, &text_color, 0, usingGui);
if (usingGui > 0)
{
if (usingGui > 0) {
alphaChannel = guis[usingGui].HasAlphaChannel();
}
}
else if ((ShouldAntiAliasText()) && (game.GetColorDepth() >= 24))
} else if ((ShouldAntiAliasText()) && (game.GetColorDepth() >= 24))
alphaChannel = true;
for (size_t ee=0;ee<Lines.Count();ee++) {
for (size_t ee = 0; ee < Lines.Count(); ee++) {
//int ttxp=wii/2 - wgettextwidth_compensate(lines[ee], usingfont)/2;
int ttyp=ttxtop+ee*disp.linespacing;
int ttyp = ttxtop + ee * disp.linespacing;
// asspch < 0 means that it's inside a text box so don't
// centre the text
if (asspch < 0) {
@ -228,30 +221,27 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
text_color = text_window_ds->GetCompatibleColor(-asspch);
wouttext_aligned(text_window_ds, ttxleft, ttyp, oriwid, usingfont, text_color, Lines[ee], play.text_align);
}
else {
} else {
text_color = text_window_ds->GetCompatibleColor(asspch);
wouttext_aligned(text_window_ds, ttxleft, ttyp, wii, usingfont, text_color, Lines[ee], play.speech_text_align);
}
}
}
else {
int xoffs,yoffs, oriwid = wii - padding * 2;
draw_text_window_and_bar(&text_window_ds, wantFreeScreenop, &xoffs,&yoffs,&xx,&yy,&wii,&text_color);
} else {
int xoffs, yoffs, oriwid = wii - padding * 2;
draw_text_window_and_bar(&text_window_ds, wantFreeScreenop, &xoffs, &yoffs, &xx, &yy, &wii, &text_color);
if (game.options[OPT_TWCUSTOM] > 0)
{
if (game.options[OPT_TWCUSTOM] > 0) {
alphaChannel = guis[game.options[OPT_TWCUSTOM]].HasAlphaChannel();
}
adjust_y_coordinate_for_text(&yoffs, usingfont);
for (size_t ee=0;ee<Lines.Count();ee++)
wouttext_aligned (text_window_ds, xoffs, yoffs + ee * disp.linespacing, oriwid, usingfont, text_color, Lines[ee], play.text_align);
for (size_t ee = 0; ee < Lines.Count(); ee++)
wouttext_aligned(text_window_ds, xoffs, yoffs + ee * disp.linespacing, oriwid, usingfont, text_color, Lines[ee], play.text_align);
}
int ovrtype = OVER_TEXTMSG;
if (disp_type == DISPLAYTEXT_NORMALOVERLAY) ovrtype=OVER_CUSTOM;
if (disp_type == DISPLAYTEXT_NORMALOVERLAY) ovrtype = OVER_CUSTOM;
else if (disp_type >= OVER_CUSTOM) ovrtype = disp_type;
int nse = add_screen_overlay(xx, yy, ovrtype, text_window_ds, adjustedXX - xx, adjustedYY - yy, alphaChannel);
@ -268,13 +258,13 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
// If fast-forwarding, then skip immediately
if (play.fast_forward) {
remove_screen_overlay(OVER_TEXTMSG);
play.messagetime=-1;
play.messagetime = -1;
return 0;
}
if (!play.mouse_cursor_hidden)
ags_domouse(DOMOUSE_ENABLE);
int countdown = GetTextDisplayTime (todis);
int countdown = GetTextDisplayTime(todis);
int skip_setting = user_to_internal_skip_speech((SkipSpeechStyle)play.skip_display);
// Loop until skipped
while (true) {
@ -290,7 +280,7 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
}
int kp;
if (run_service_key_controls(kp)) {
check_skip_cutscene_keypress (kp);
check_skip_cutscene_keypress(kp);
if (play.fast_forward)
break;
if ((skip_setting & SKIP_KEYPRESS) && !play.IsIgnoringInput())
@ -299,8 +289,7 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
update_polled_stuff_if_runtime();
if (play.fast_forward == 0)
{
if (play.fast_forward == 0) {
WaitForNextFrame();
}
@ -312,13 +301,11 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
if (channel_is_playing(SCHAN_SPEECH) && (play.fast_forward == 0)) {
if (countdown <= 1)
countdown = 1;
}
else // if the voice has finished, remove the speech
} else // if the voice has finished, remove the speech
countdown = 0;
}
// Test for the timed auto-skip
if ((countdown < 1) && (skip_setting & SKIP_AUTOTIMER))
{
if ((countdown < 1) && (skip_setting & SKIP_AUTOTIMER)) {
play.SetIgnoreInput(play.ignore_user_input_after_text_timeout_ms);
break;
}
@ -330,15 +317,13 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
ags_domouse(DOMOUSE_DISABLE);
remove_screen_overlay(OVER_TEXTMSG);
invalidate_screen();
}
else {
} else {
// if the speech does not time out, but we are skipping a cutscene,
// allow it to time out
if ((play.messagetime < 0) && (play.fast_forward))
play.messagetime = 2;
if (!overlayPositionFixed)
{
if (!overlayPositionFixed) {
screenover[nse].positionRelativeToScreen = false;
VpPoint vpt = play.GetRoomViewport(0)->ScreenToRoom(screenover[nse].x, screenover[nse].y, false);
screenover[nse].x = vpt.first.X;
@ -348,13 +333,13 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
GameLoopUntilNoOverlay();
}
play.messagetime=-1;
play.messagetime = -1;
return 0;
}
void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int asspch, int isThought, int allowShrink, bool overlayPositionFixed) {
int usingfont=FONT_NORMAL;
if (asspch) usingfont=FONT_SPEECH;
int usingfont = FONT_NORMAL;
if (asspch) usingfont = FONT_SPEECH;
// TODO: _display_at may be called from _displayspeech, which can start
// and finalize voice speech on its own. Find out if we really need to
// keep track of this and not just stop voice regardless.
@ -362,8 +347,8 @@ void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int a
EndSkippingUntilCharStops();
if (try_auto_play_speech(text, text, play.narrator_speech, true))
{// TODO: is there any need for this flag?
if (try_auto_play_speech(text, text, play.narrator_speech, true)) {
// TODO: is there any need for this flag?
need_stop_speech = true;
}
_display_main(xx, yy, wii, text, disp_type, usingfont, asspch, isThought, allowShrink, overlayPositionFixed);
@ -372,8 +357,7 @@ void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int a
stop_voice_speech();
}
bool try_auto_play_speech(const char *text, const char *&replace_text, int charid, bool blocking)
{
bool try_auto_play_speech(const char *text, const char *&replace_text, int charid, bool blocking) {
const char *src = text;
if (src[0] != '&')
return false;
@ -385,8 +369,7 @@ bool try_auto_play_speech(const char *text, const char *&replace_text, int chari
quit("DisplaySpeech: auto-voice symbol '&' not followed by valid integer");
replace_text = src; // skip voice tag
if (play_voice_speech(charid, sndid))
{
if (play_voice_speech(charid, sndid)) {
// if Voice Only, then blank out the text
if (play.want_speech == 2)
replace_text = " ";
@ -399,11 +382,9 @@ bool try_auto_play_speech(const char *text, const char *&replace_text, int chari
// Be careful: a number of Say/Display functions expect it to be set beforehand.
int source_text_length = -1;
int GetTextDisplayLength(const char *text)
{
int GetTextDisplayLength(const char *text) {
int len = (int)strlen(text);
if ((text[0] == '&') && (play.unfactor_speech_from_textlength != 0))
{
if ((text[0] == '&') && (play.unfactor_speech_from_textlength != 0)) {
// if there's an "&12 text" type line, remove "&12 " from the source length
size_t j = 0;
while ((text[j] != ' ') && (text[j] != 0))
@ -427,8 +408,7 @@ int GetTextDisplayTime(const char *text, int canberel) {
// and music sync up correctly
uselen = source_text_length;
source_text_length = -1;
}
else {
} else {
uselen = GetTextDisplayLength(text);
}
@ -442,7 +422,7 @@ int GetTextDisplayTime(const char *text, int canberel) {
// This is calculated using a hard-coded 15 for the text speed,
// so that it's always the same no matter how fast the user
// can read.
loops_per_character = (((uselen/play.lipsync_speed)+1) * fpstimer) / uselen;
loops_per_character = (((uselen / play.lipsync_speed) + 1) * fpstimer) / uselen;
int textDisplayTimeInMS = ((uselen / (play.text_speed + play.text_speed_modifier)) + 1) * 1000;
if (textDisplayTimeInMS < play.text_min_display_time_ms)
@ -458,18 +438,15 @@ bool ShouldAntiAliasText() {
#if defined (AGS_FONTOUTLINE_MOREOPAQUE)
// TODO: was suggested by fernewelten, but it's unclear whether is necessary
// Make semi-transparent bits much more opaque
void wouttextxy_AutoOutline_Semitransparent2Opaque(Bitmap *map)
{
void wouttextxy_AutoOutline_Semitransparent2Opaque(Bitmap *map) {
if (map->GetColorDepth() < 32)
return; // such maps don't feature partial transparency
size_t const width = map->GetWidth();
size_t const height = map->GetHeight();
for (size_t y = 0; y < height; y++)
{
for (size_t y = 0; y < height; y++) {
int32 *sc_line = reinterpret_cast<int32 *>(map->GetScanLineForWriting(y));
for (size_t x = 0; x < width; x++)
{
for (size_t x = 0; x < width; x++) {
int32 &px = sc_line[x];
int const transparency = geta(px);
if (0 < transparency && transparency < 255)
@ -484,8 +461,7 @@ void wouttextxy_AutoOutline_Semitransparent2Opaque(Bitmap *map)
#endif
// Draw outline that is calculated from the text font, not derived from an outline font
void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *texx, int &xxp, int &yyp)
{
void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *texx, int &xxp, int &yyp) {
int const thickness = game.fonts.at(font).AutoOutlineThickness;
auto const style = game.fonts.at(font).AutoOutlineStyle;
if (thickness <= 0)
@ -512,14 +488,12 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
wouttextxy_AutoOutline_Semitransparent2Opaque(texx_stencil);
#endif
void(Bitmap::*pfn_drawstencil)(Bitmap *src, int dst_x, int dst_y);
if (antialias)
{ // NOTE: we must set out blender AFTER wouttextxy, or it will be overidden
void(Bitmap::*pfn_drawstencil)(Bitmap * src, int dst_x, int dst_y);
if (antialias) {
// NOTE: we must set out blender AFTER wouttextxy, or it will be overidden
set_argb2any_blender();
pfn_drawstencil = &Bitmap::TransBlendBlt;
}
else
{
} else {
pfn_drawstencil = &Bitmap::MaskedBlit;
}
@ -529,8 +503,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
yyp += thickness;
int largest_y_diff_reached_so_far = -1;
for (int x_diff = thickness; x_diff >= 0; x_diff--)
{
for (int x_diff = thickness; x_diff >= 0; x_diff--) {
// Integer arithmetics: In the following, we use terms k*(k + 1) to account for rounding.
// (k + 0.5)^2 == k*k + 2*k*0.5 + 0.5^2 == k*k + k + 0.25 ==approx. k*(k + 1)
int y_term_limit = thickness * (thickness + 1);
@ -540,8 +513,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
// extend the outline stencil to the top and bottom
for (int y_diff = largest_y_diff_reached_so_far + 1;
y_diff <= thickness && y_diff * y_diff <= y_term_limit;
y_diff++)
{
y_diff++) {
(outline_stencil.*pfn_drawstencil)(&texx_stencil, 0, thickness - y_diff);
if (y_diff > 0)
(outline_stencil.*pfn_drawstencil)(&texx_stencil, 0, thickness + y_diff);
@ -556,8 +528,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
}
// Draw an outline if requested, then draw the text on top
void wouttext_outline(Common::Bitmap *ds, int xxp, int yyp, int font, color_t text_color, const char *texx)
{
void wouttext_outline(Common::Bitmap *ds, int xxp, int yyp, int font, color_t text_color, const char *texx) {
size_t const text_font = static_cast<size_t>(font);
// Draw outline (a backdrop) if requested
color_t const outline_color = ds->GetCompatibleColor(play.speech_text_shadow);
@ -584,45 +555,38 @@ void wouttext_aligned(Bitmap *ds, int usexp, int yy, int oriwid, int usingfont,
}
// Get outline's thickness addition to the font's width or height
int get_outline_padding(int font)
{
int get_outline_padding(int font) {
if (get_font_outline(font) == FONT_OUTLINE_AUTO) {
return get_font_outline_thickness(font) * 2;
}
return 0;
}
int getfontheight_outlined(int font)
{
int getfontheight_outlined(int font) {
return getfontheight(font) + get_outline_padding(font);
}
int getfontspacing_outlined(int font)
{
int getfontspacing_outlined(int font) {
return use_default_linespacing(font) ?
getfontheight_outlined(font) :
getfontlinespacing(font);
}
int getfontlinegap(int font)
{
int getfontlinegap(int font) {
return getfontspacing_outlined(font) - getfontheight_outlined(font);
}
int getheightoflines(int font, int numlines)
{
int getheightoflines(int font, int numlines) {
return getfontspacing_outlined(font) * (numlines - 1) + getfontheight_outlined(font);
}
int wgettextwidth_compensate(const char *tex, int font)
{
int wgettextwidth_compensate(const char *tex, int font) {
return wgettextwidth(tex, font) + get_outline_padding(font);
}
void do_corner(Bitmap *ds, int sprn, int x, int y, int offx, int offy) {
if (sprn<0) return;
if (spriteset[sprn] == nullptr)
{
if (sprn < 0) return;
if (spriteset[sprn] == nullptr) {
sprn = 0;
}
@ -631,25 +595,22 @@ void do_corner(Bitmap *ds, int sprn, int x, int y, int offx, int offy) {
draw_gui_sprite_v330(ds, sprn, x, y);
}
int get_but_pic(GUIMain*guo,int indx)
{
int get_but_pic(GUIMain *guo, int indx) {
int butid = guo->GetControlID(indx);
return butid >= 0 ? guibuts[butid].Image : 0;
}
void draw_button_background(Bitmap *ds, int xx1,int yy1,int xx2,int yy2,GUIMain*iep) {
void draw_button_background(Bitmap *ds, int xx1, int yy1, int xx2, int yy2, GUIMain *iep) {
color_t draw_color;
if (iep==nullptr) { // standard window
if (iep == nullptr) { // standard window
draw_color = ds->GetCompatibleColor(15);
ds->FillRect(Rect(xx1,yy1,xx2,yy2), draw_color);
ds->FillRect(Rect(xx1, yy1, xx2, yy2), draw_color);
draw_color = ds->GetCompatibleColor(16);
ds->DrawRect(Rect(xx1,yy1,xx2,yy2), draw_color);
ds->DrawRect(Rect(xx1, yy1, xx2, yy2), draw_color);
/* draw_color = ds->GetCompatibleColor(opts.tws.backcol); ds->FillRect(Rect(xx1,yy1,xx2,yy2);
draw_color = ds->GetCompatibleColor(opts.tws.ds->GetTextColor()); ds->DrawRect(Rect(xx1+1,yy1+1,xx2-1,yy2-1);*/
}
else {
if (loaded_game_file_version < kGameVersion_262) // < 2.62
{
} else {
if (loaded_game_file_version < kGameVersion_262) { // < 2.62
// Color 0 wrongly shows as transparent instead of black
// From the changelog of 2.62:
// - Fixed text windows getting a black background if colour 0 was
@ -662,20 +623,17 @@ void draw_button_background(Bitmap *ds, int xx1,int yy1,int xx2,int yy2,GUIMain*
else draw_color = ds->GetCompatibleColor(0); // black backrgnd behind picture
if (iep->BgColor > 0)
ds->FillRect(Rect(xx1,yy1,xx2,yy2), draw_color);
ds->FillRect(Rect(xx1, yy1, xx2, yy2), draw_color);
int leftRightWidth = game.SpriteInfos[get_but_pic(iep,4)].Width;
int topBottomHeight = game.SpriteInfos[get_but_pic(iep,6)].Height;
if (iep->BgImage>0) {
int leftRightWidth = game.SpriteInfos[get_but_pic(iep, 4)].Width;
int topBottomHeight = game.SpriteInfos[get_but_pic(iep, 6)].Height;
if (iep->BgImage > 0) {
if ((loaded_game_file_version <= kGameVersion_272) // 2.xx
&& (spriteset[iep->BgImage]->GetWidth() == 1)
&& (spriteset[iep->BgImage]->GetHeight() == 1)
&& (*((unsigned int*)spriteset[iep->BgImage]->GetData()) == 0x00FF00FF))
{
&& (*((unsigned int *)spriteset[iep->BgImage]->GetData()) == 0x00FF00FF)) {
// Don't draw fully transparent dummy GUI backgrounds
}
else
{
} else {
// offset the background image and clip it so that it is drawn
// such that the border graphics can have a transparent outside
// edge
@ -685,11 +643,9 @@ void draw_button_background(Bitmap *ds, int xx1,int yy1,int xx2,int yy2,GUIMain*
int bgfinishx = xx2;
int bgfinishy = yy2;
int bgoffsyStart = bgoffsy;
while (bgoffsx <= bgfinishx)
{
while (bgoffsx <= bgfinishx) {
bgoffsy = bgoffsyStart;
while (bgoffsy <= bgfinishy)
{
while (bgoffsy <= bgfinishy) {
draw_gui_sprite_v330(ds, iep->BgImage, bgoffsx, bgoffsy);
bgoffsy += game.SpriteInfos[iep->BgImage].Height;
}
@ -700,24 +656,24 @@ void draw_button_background(Bitmap *ds, int xx1,int yy1,int xx2,int yy2,GUIMain*
}
}
int uu;
for (uu=yy1;uu <= yy2;uu+= game.SpriteInfos[get_but_pic(iep,4)].Height) {
do_corner(ds, get_but_pic(iep,4),xx1,uu,-1,0); // left side
do_corner(ds, get_but_pic(iep,5),xx2+1,uu,0,0); // right side
for (uu = yy1; uu <= yy2; uu += game.SpriteInfos[get_but_pic(iep, 4)].Height) {
do_corner(ds, get_but_pic(iep, 4), xx1, uu, -1, 0); // left side
do_corner(ds, get_but_pic(iep, 5), xx2 + 1, uu, 0, 0); // right side
}
for (uu=xx1;uu <= xx2;uu+=game.SpriteInfos[get_but_pic(iep,6)].Width) {
do_corner(ds, get_but_pic(iep,6),uu,yy1,0,-1); // top side
do_corner(ds, get_but_pic(iep,7),uu,yy2+1,0,0); // bottom side
for (uu = xx1; uu <= xx2; uu += game.SpriteInfos[get_but_pic(iep, 6)].Width) {
do_corner(ds, get_but_pic(iep, 6), uu, yy1, 0, -1); // top side
do_corner(ds, get_but_pic(iep, 7), uu, yy2 + 1, 0, 0); // bottom side
}
do_corner(ds, get_but_pic(iep,0),xx1,yy1,-1,-1); // top left
do_corner(ds, get_but_pic(iep,1),xx1,yy2+1,-1,0); // bottom left
do_corner(ds, get_but_pic(iep,2),xx2+1,yy1,0,-1); // top right
do_corner(ds, get_but_pic(iep,3),xx2+1,yy2+1,0,0); // bottom right
do_corner(ds, get_but_pic(iep, 0), xx1, yy1, -1, -1); // top left
do_corner(ds, get_but_pic(iep, 1), xx1, yy2 + 1, -1, 0); // bottom left
do_corner(ds, get_but_pic(iep, 2), xx2 + 1, yy1, 0, -1); // top right
do_corner(ds, get_but_pic(iep, 3), xx2 + 1, yy2 + 1, 0, 0); // bottom right
}
}
// Calculate the width that the left and right border of the textwindow
// GUI take up
int get_textwindow_border_width (int twgui) {
int get_textwindow_border_width(int twgui) {
if (twgui < 0)
return 0;
@ -731,7 +687,7 @@ int get_textwindow_border_width (int twgui) {
}
// get the hegiht of the text window's top border
int get_textwindow_top_border_height (int twgui) {
int get_textwindow_top_border_height(int twgui) {
if (twgui < 0)
return 0;
@ -757,7 +713,7 @@ int get_textwindow_padding(int ifnum) {
}
void draw_text_window(Bitmap **text_window_ds, bool should_free_ds,
int*xins,int*yins,int*xx,int*yy,int*wii, color_t *set_text_color, int ovrheight, int ifnum) {
int *xins, int *yins, int *xx, int *yy, int *wii, color_t *set_text_color, int ovrheight, int ifnum) {
Bitmap *ds = *text_window_ds;
if (ifnum < 0)
@ -766,13 +722,12 @@ void draw_text_window(Bitmap **text_window_ds, bool should_free_ds,
if (ifnum <= 0) {
if (ovrheight)
quit("!Cannot use QFG4 style options without custom text window");
draw_button_background(ds, 0,0,ds->GetWidth() - 1,ds->GetHeight() - 1,nullptr);
draw_button_background(ds, 0, 0, ds->GetWidth() - 1, ds->GetHeight() - 1, nullptr);
if (set_text_color)
*set_text_color = ds->GetCompatibleColor(16);
xins[0]=3;
yins[0]=3;
}
else {
xins[0] = 3;
yins[0] = 3;
} else {
if (ifnum >= game.numgui)
quitprintf("!Invalid GUI %d specified as text window (total GUIs: %d)", ifnum, game.numgui);
if (!guis[ifnum].IsTextWindow())
@ -780,28 +735,28 @@ void draw_text_window(Bitmap **text_window_ds, bool should_free_ds,
int tbnum = get_but_pic(&guis[ifnum], 0);
wii[0] += get_textwindow_border_width (ifnum);
xx[0]-=game.SpriteInfos[tbnum].Width;
yy[0]-=game.SpriteInfos[tbnum].Height;
wii[0] += get_textwindow_border_width(ifnum);
xx[0] -= game.SpriteInfos[tbnum].Width;
yy[0] -= game.SpriteInfos[tbnum].Height;
if (ovrheight == 0)
ovrheight = disp.fulltxtheight;
if (should_free_ds)
delete *text_window_ds;
int padding = get_textwindow_padding(ifnum);
*text_window_ds = BitmapHelper::CreateTransparentBitmap(wii[0],ovrheight+(padding*2)+ game.SpriteInfos[tbnum].Height*2,game.GetColorDepth());
*text_window_ds = BitmapHelper::CreateTransparentBitmap(wii[0], ovrheight + (padding * 2) + game.SpriteInfos[tbnum].Height * 2, game.GetColorDepth());
ds = *text_window_ds;
int xoffs=game.SpriteInfos[tbnum].Width,yoffs= game.SpriteInfos[tbnum].Height;
draw_button_background(ds, xoffs,yoffs,(ds->GetWidth() - xoffs) - 1,(ds->GetHeight() - yoffs) - 1,&guis[ifnum]);
int xoffs = game.SpriteInfos[tbnum].Width, yoffs = game.SpriteInfos[tbnum].Height;
draw_button_background(ds, xoffs, yoffs, (ds->GetWidth() - xoffs) - 1, (ds->GetHeight() - yoffs) - 1, &guis[ifnum]);
if (set_text_color)
*set_text_color = ds->GetCompatibleColor(guis[ifnum].FgColor);
xins[0]=xoffs+padding;
yins[0]=yoffs+padding;
xins[0] = xoffs + padding;
yins[0] = yoffs + padding;
}
}
void draw_text_window_and_bar(Bitmap **text_window_ds, bool should_free_ds,
int*xins,int*yins,int*xx,int*yy,int*wii,color_t *set_text_color,int ovrheight, int ifnum) {
int *xins, int *yins, int *xx, int *yy, int *wii, color_t *set_text_color, int ovrheight, int ifnum) {
draw_text_window(text_window_ds, should_free_ds, xins, yins, xx, yy, wii, set_text_color, ovrheight, ifnum);
@ -834,7 +789,6 @@ void draw_text_window_and_bar(Bitmap **text_window_ds, bool should_free_ds,
topBar.wantIt = 0;
// adjust the text Y position
yins[0] += topBar.height;
}
else if (topBar.wantIt)
} else if (topBar.wantIt)
topBar.wantIt = 0;
}

View file

@ -47,7 +47,7 @@ int GetTextDisplayLength(const char *text);
int GetTextDisplayTime(const char *text, int canberel = 0);
// Draw an outline if requested, then draw the text on top
void wouttext_outline(Common::Bitmap *ds, int xxp, int yyp, int usingfont, color_t text_color, const char *texx);
void wouttext_aligned (Common::Bitmap *ds, int usexp, int yy, int oriwid, int usingfont, color_t text_color, const char *text, HorAlignment align);
void wouttext_aligned(Common::Bitmap *ds, int usexp, int yy, int oriwid, int usingfont, color_t text_color, const char *text, HorAlignment align);
// TODO: GUI classes located in Common library do not make use of outlining,
// need to find a way to make all code use same functions.
// Get the maximal height of the given font, with corresponding outlining
@ -60,23 +60,23 @@ int getfontlinegap(int font);
int getheightoflines(int font, int numlines);
// Get the maximal width of the given font, with corresponding outlining
int wgettextwidth_compensate(const char *tex, int font);
void do_corner(Common::Bitmap *ds, int sprn,int xx1,int yy1,int typx,int typy);
void do_corner(Common::Bitmap *ds, int sprn, int xx1, int yy1, int typx, int typy);
// Returns the image of a button control on the GUI under given child index
int get_but_pic(GUIMain*guo,int indx);
void draw_button_background(Common::Bitmap *ds, int xx1,int yy1,int xx2,int yy2,GUIMain*iep);
int get_but_pic(GUIMain *guo, int indx);
void draw_button_background(Common::Bitmap *ds, int xx1, int yy1, int xx2, int yy2, GUIMain *iep);
// Calculate the width that the left and right border of the textwindow
// GUI take up
int get_textwindow_border_width (int twgui);
int get_textwindow_border_width(int twgui);
// get the hegiht of the text window's top border
int get_textwindow_top_border_height (int twgui);
int get_textwindow_top_border_height(int twgui);
// draw_text_window: draws the normal or custom text window
// create a new bitmap the size of the window before calling, and
// point text_window_ds to it
// returns text start x & y pos in parameters
// Warning!: draw_text_window() and draw_text_window_and_bar() can create new text_window_ds
void draw_text_window(Common::Bitmap **text_window_ds, bool should_free_ds, int*xins,int*yins,int*xx,int*yy,int*wii,color_t *set_text_color,int ovrheight, int ifnum);
void draw_text_window(Common::Bitmap **text_window_ds, bool should_free_ds, int *xins, int *yins, int *xx, int *yy, int *wii, color_t *set_text_color, int ovrheight, int ifnum);
void draw_text_window_and_bar(Common::Bitmap **text_window_ds, bool should_free_ds,
int*xins,int*yins,int*xx,int*yy,int*wii,color_t *set_text_color,int ovrheight=0, int ifnum=-1);
int *xins, int *yins, int *xx, int *yy, int *wii, color_t *set_text_color, int ovrheight = 0, int ifnum = -1);
int get_textwindow_padding(int ifnum);
// The efficient length of the last source text prepared for display

File diff suppressed because it is too large Load diff

View file

@ -29,14 +29,14 @@
#include "gfx/gfx_def.h"
#include "util/wgt2allg.h"
namespace AGS
{
namespace Common
{
class Bitmap;
typedef std::shared_ptr<Common::Bitmap> PBitmap;
}
namespace Engine { class IDriverDependantBitmap; }
namespace AGS {
namespace Common {
class Bitmap;
typedef std::shared_ptr<Common::Bitmap> PBitmap;
}
namespace Engine {
class IDriverDependantBitmap;
}
}
using namespace AGS; // FIXME later
@ -103,7 +103,7 @@ void mark_current_background_dirty();
void invalidate_cached_walkbehinds();
// Avoid freeing and reallocating the memory if possible
Common::Bitmap *recycle_bitmap(Common::Bitmap *bimp, int coldep, int wid, int hit, bool make_transparent = false);
Engine::IDriverDependantBitmap* recycle_ddb_bitmap(Engine::IDriverDependantBitmap *bimp, Common::Bitmap *source, bool hasAlpha = false, bool opaque = false);
Engine::IDriverDependantBitmap *recycle_ddb_bitmap(Engine::IDriverDependantBitmap *bimp, Common::Bitmap *source, bool hasAlpha = false, bool opaque = false);
// Draw everything
void render_graphics(Engine::IDriverDependantBitmap *extraBitmap = nullptr, int extraX = 0, int extraY = 0);
// Construct game scene, scheduling drawing list for the renderer
@ -112,8 +112,8 @@ void construct_game_scene(bool full_redraw = false);
void construct_game_screen_overlay(bool draw_mouse = true);
// Construct engine overlay with debugging tools (fps, console)
void construct_engine_overlay();
void add_to_sprite_list(Engine::IDriverDependantBitmap* spp, int xx, int yy, int baseline, int trans, int sprNum, bool isWalkBehind = false);
void tint_image (Common::Bitmap *g, Common::Bitmap *source, int red, int grn, int blu, int light_level, int luminance=255);
void add_to_sprite_list(Engine::IDriverDependantBitmap *spp, int xx, int yy, int baseline, int trans, int sprNum, bool isWalkBehind = false);
void tint_image(Common::Bitmap *g, Common::Bitmap *source, int red, int grn, int blu, int light_level, int luminance = 255);
void draw_sprite_support_alpha(Common::Bitmap *ds, bool ds_has_alpha, int xpos, int ypos, Common::Bitmap *image, bool src_has_alpha,
Common::BlendMode blend_mode = Common::kBlendMode_Alpha, int alpha = 0xFF);
void draw_sprite_slot_support_alpha(Common::Bitmap *ds, bool ds_has_alpha, int xpos, int ypos, int src_slot,
@ -126,7 +126,7 @@ void render_to_screen();
void draw_game_screen_callback();
void GfxDriverOnInitCallback(void *data);
bool GfxDriverNullSpriteCallback(int x, int y);
void putpixel_compensate (Common::Bitmap *g, int xx,int yy, int col);
void putpixel_compensate(Common::Bitmap *g, int xx, int yy, int col);
// create the actsps[aa] image with the object drawn correctly
// returns 1 if nothing at all has changed and actsps is still
// intact from last time; 0 otherwise

View file

@ -63,24 +63,21 @@ using namespace AGS::Engine;
// Dirty rects store coordinate values in the coordinate system of a camera surface,
// where coords always span from 0,0 to surface width,height.
// Converting from room to dirty rects would require subtracting room camera offsets.
struct IRSpan
{
struct IRSpan {
int x1, x2;
int mergeSpan(int tx1, int tx2);
IRSpan();
};
struct IRRow
{
struct IRRow {
IRSpan span[MAX_SPANS_PER_ROW];
int numSpans;
IRRow();
};
struct DirtyRects
{
struct DirtyRects {
// Size of the surface managed by this dirty rects object
Size SurfaceSize;
// Where the surface is rendered on screen
@ -108,17 +105,14 @@ struct DirtyRects
IRSpan::IRSpan()
: x1(0), x2(0)
{
: x1(0), x2(0) {
}
IRRow::IRRow()
: numSpans(0)
{
: numSpans(0) {
}
int IRSpan::mergeSpan(int tx1, int tx2)
{
int IRSpan::mergeSpan(int tx1, int tx2) {
if ((tx1 > x2) || (tx2 < x1))
return 0;
// overlapping, increase the span
@ -130,20 +124,16 @@ int IRSpan::mergeSpan(int tx1, int tx2)
}
DirtyRects::DirtyRects()
: NumDirtyRegions(0)
{
: NumDirtyRegions(0) {
}
bool DirtyRects::IsInit() const
{
bool DirtyRects::IsInit() const {
return DirtyRows.size() > 0;
}
void DirtyRects::Init(const Size &surf_size, const Rect &viewport)
{
void DirtyRects::Init(const Size &surf_size, const Rect &viewport) {
int height = surf_size.Height;
if (SurfaceSize != surf_size)
{
if (SurfaceSize != surf_size) {
Destroy();
SurfaceSize = surf_size;
DirtyRows.resize(height);
@ -158,19 +148,16 @@ void DirtyRects::Init(const Size &surf_size, const Rect &viewport)
Screen2DirtySurf.Init(viewport, RectWH(0, 0, surf_size.Width, surf_size.Height));
}
void DirtyRects::SetSurfaceOffsets(int x, int y)
{
void DirtyRects::SetSurfaceOffsets(int x, int y) {
Room2Screen.SetSrcOffsets(x, y);
}
void DirtyRects::Destroy()
{
void DirtyRects::Destroy() {
DirtyRows.clear();
NumDirtyRegions = 0;
}
void DirtyRects::Reset()
{
void DirtyRects::Reset() {
NumDirtyRegions = 0;
for (size_t i = 0; i < DirtyRows.size(); ++i)
@ -188,22 +175,16 @@ std::vector<DirtyRects> RoomCamRects;
std::vector<std::pair<int, int>> RoomCamPositions;
void dispose_invalid_regions(bool /* room_only */)
{
void dispose_invalid_regions(bool /* room_only */) {
RoomCamRects.clear();
RoomCamPositions.clear();
}
void init_invalid_regions(int view_index, const Size &surf_size, const Rect &viewport)
{
if (view_index < 0)
{
void init_invalid_regions(int view_index, const Size &surf_size, const Rect &viewport) {
if (view_index < 0) {
BlackRects.Init(surf_size, viewport);
}
else
{
if (RoomCamRects.size() <= (size_t)view_index)
{
} else {
if (RoomCamRects.size() <= (size_t)view_index) {
RoomCamRects.resize(view_index + 1);
RoomCamPositions.resize(view_index + 1);
}
@ -212,56 +193,45 @@ void init_invalid_regions(int view_index, const Size &surf_size, const Rect &vie
}
}
void delete_invalid_regions(int view_index)
{
if (view_index >= 0)
{
void delete_invalid_regions(int view_index) {
if (view_index >= 0) {
RoomCamRects.erase(RoomCamRects.begin() + view_index);
RoomCamPositions.erase(RoomCamPositions.begin() + view_index);
}
}
void set_invalidrects_cameraoffs(int view_index, int x, int y)
{
if (view_index < 0)
{
void set_invalidrects_cameraoffs(int view_index, int x, int y) {
if (view_index < 0) {
BlackRects.SetSurfaceOffsets(x, y);
return;
}
else
{
} else {
RoomCamRects[view_index].SetSurfaceOffsets(x, y);
}
int &posxwas = RoomCamPositions[view_index].first;
int &posywas = RoomCamPositions[view_index].second;
if ((x != posxwas) || (y != posywas))
{
if ((x != posxwas) || (y != posywas)) {
invalidate_all_camera_rects(view_index);
posxwas = x;
posywas = y;
}
}
void invalidate_all_rects()
{
for (auto &rects : RoomCamRects)
{
void invalidate_all_rects() {
for (auto &rects : RoomCamRects) {
if (!IsRectInsideRect(rects.Viewport, BlackRects.Viewport))
BlackRects.NumDirtyRegions = WHOLESCREENDIRTY;
rects.NumDirtyRegions = WHOLESCREENDIRTY;
}
}
void invalidate_all_camera_rects(int view_index)
{
void invalidate_all_camera_rects(int view_index) {
if (view_index < 0)
return;
RoomCamRects[view_index].NumDirtyRegions = WHOLESCREENDIRTY;
}
void invalidate_rect_on_surf(int x1, int y1, int x2, int y2, DirtyRects &rects)
{
void invalidate_rect_on_surf(int x1, int y1, int x2, int y2, DirtyRects &rects) {
if (rects.DirtyRows.size() == 0)
return;
if (rects.NumDirtyRegions >= MAXDIRTYREGIONS) {
@ -310,13 +280,11 @@ void invalidate_rect_on_surf(int x1, int y1, int x2, int y2, DirtyRects &rects)
}
}
}
}
else if (dirtyRow[a].numSpans < MAX_SPANS_PER_ROW) {
} else if (dirtyRow[a].numSpans < MAX_SPANS_PER_ROW) {
dirtyRow[a].span[dirtyRow[a].numSpans].x1 = x1;
dirtyRow[a].span[dirtyRow[a].numSpans].x2 = x2;
dirtyRow[a].numSpans++;
}
else {
} else {
// didn't fit in an existing span, and there are none spare
int nearestDist = 99999, nearestWas = -1, extendLeft;
int tleft, tright;
@ -345,10 +313,8 @@ void invalidate_rect_on_surf(int x1, int y1, int x2, int y2, DirtyRects &rects)
//}
}
void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool in_room)
{
if (!in_room)
{
void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool in_room) {
if (!in_room) {
// TODO: for most opimisation (esp. with multiple viewports) should perhaps
// split/cut parts of the original rectangle which overlap room viewport(s).
Rect r(x1, y1, x2, y2);
@ -364,9 +330,7 @@ void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool
x2 = rects.Screen2DirtySurf.X.ScalePt(x2);
y1 = rects.Screen2DirtySurf.Y.ScalePt(y1);
y2 = rects.Screen2DirtySurf.Y.ScalePt(y2);
}
else
{
} else {
x1 -= rects.Room2Screen.X.GetSrcOffset();
y1 -= rects.Room2Screen.Y.GetSrcOffset();
x2 -= rects.Room2Screen.X.GetSrcOffset();
@ -376,8 +340,7 @@ void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool
invalidate_rect_on_surf(x1, y1, x2, y2, rects);
}
void invalidate_rect_ds(int x1, int y1, int x2, int y2, bool in_room)
{
void invalidate_rect_ds(int x1, int y1, int x2, int y2, bool in_room) {
for (auto &rects : RoomCamRects)
invalidate_rect_ds(rects, x1, y1, x2, y2, in_room);
}
@ -387,8 +350,7 @@ void invalidate_rect_ds(int x1, int y1, int x2, int y2, bool in_room)
// while room background was 16-bit and Allegro lib does not support stretching between colour depths.
// The no_transform flag here means essentially "no offset", and indicates that the function
// must blit src on ds at 0;0. Otherwise, actual Viewport offset is used.
void update_invalid_region(Bitmap *ds, Bitmap *src, const DirtyRects &rects, bool no_transform)
{
void update_invalid_region(Bitmap *ds, Bitmap *src, const DirtyRects &rects, bool no_transform) {
if (rects.NumDirtyRegions == 0)
return;
@ -400,27 +362,21 @@ void update_invalid_region(Bitmap *ds, Bitmap *src, const DirtyRects &rects, boo
const int dst_x = no_transform ? 0 : rects.Viewport.Left;
const int dst_y = no_transform ? 0 : rects.Viewport.Top;
if (rects.NumDirtyRegions == WHOLESCREENDIRTY)
{
if (rects.NumDirtyRegions == WHOLESCREENDIRTY) {
ds->Blit(src, src_x, src_y, dst_x, dst_y, rects.SurfaceSize.Width, rects.SurfaceSize.Height);
}
else
{
} else {
const std::vector<IRRow> &dirtyRow = rects.DirtyRows;
const int surf_height = rects.SurfaceSize.Height;
// TODO: is this IsMemoryBitmap check is still relevant?
// If bitmaps properties match and no transform required other than linear offset
if ((src->GetColorDepth() == ds->GetColorDepth()) && (ds->IsMemoryBitmap()))
{
if ((src->GetColorDepth() == ds->GetColorDepth()) && (ds->IsMemoryBitmap())) {
const int bypp = src->GetBPP();
// do the fast memory copy
for (int i = 0; i < surf_height; i++)
{
for (int i = 0; i < surf_height; i++) {
const uint8_t *src_scanline = src->GetScanLine(i + src_y);
uint8_t *dst_scanline = ds->GetScanLineForWriting(i + dst_y);
const IRRow &dirty_row = dirtyRow[i];
for (int k = 0; k < dirty_row.numSpans; k++)
{
for (int k = 0; k < dirty_row.numSpans; k++) {
int tx1 = dirty_row.span[k].x1;
int tx2 = dirty_row.span[k].x2;
memcpy(&dst_scanline[(tx1 + dst_x) * bypp], &src_scanline[(tx1 + src_x) * bypp], ((tx2 - tx1) + 1) * bypp);
@ -428,19 +384,16 @@ void update_invalid_region(Bitmap *ds, Bitmap *src, const DirtyRects &rects, boo
}
}
// If has to use Blit, but still must draw with no transform but offset
else
{
else {
// do fast copy without transform
for (int i = 0, rowsInOne = 1; i < surf_height; i += rowsInOne, rowsInOne = 1)
{
for (int i = 0, rowsInOne = 1; i < surf_height; i += rowsInOne, rowsInOne = 1) {
// if there are rows with identical masks, do them all in one go
// TODO: what is this for? may this be done at the invalidate_rect merge step?
while ((i + rowsInOne < surf_height) && (memcmp(&dirtyRow[i], &dirtyRow[i + rowsInOne], sizeof(IRRow)) == 0))
rowsInOne++;
const IRRow &dirty_row = dirtyRow[i];
for (int k = 0; k < dirty_row.numSpans; k++)
{
for (int k = 0; k < dirty_row.numSpans; k++) {
int tx1 = dirty_row.span[k].x1;
int tx2 = dirty_row.span[k].x2;
ds->Blit(src, tx1 + src_x, i + src_y, tx1 + dst_x, i + dst_y, (tx2 - tx1) + 1, rowsInOne);
@ -450,30 +403,24 @@ void update_invalid_region(Bitmap *ds, Bitmap *src, const DirtyRects &rects, boo
}
}
void update_invalid_region(Bitmap *ds, color_t fill_color, const DirtyRects &rects)
{
void update_invalid_region(Bitmap *ds, color_t fill_color, const DirtyRects &rects) {
ds->SetClip(rects.Viewport);
if (rects.NumDirtyRegions == WHOLESCREENDIRTY)
{
if (rects.NumDirtyRegions == WHOLESCREENDIRTY) {
ds->FillRect(rects.Viewport, fill_color);
}
else
{
} else {
const std::vector<IRRow> &dirtyRow = rects.DirtyRows;
const int surf_height = rects.SurfaceSize.Height;
{
const PlaneScaling &tf = rects.Room2Screen;
for (int i = 0, rowsInOne = 1; i < surf_height; i += rowsInOne, rowsInOne = 1)
{
for (int i = 0, rowsInOne = 1; i < surf_height; i += rowsInOne, rowsInOne = 1) {
// if there are rows with identical masks, do them all in one go
// TODO: what is this for? may this be done at the invalidate_rect merge step?
while ((i + rowsInOne < surf_height) && (memcmp(&dirtyRow[i], &dirtyRow[i + rowsInOne], sizeof(IRRow)) == 0))
rowsInOne++;
const IRRow &dirty_row = dirtyRow[i];
for (int k = 0; k < dirty_row.numSpans; k++)
{
for (int k = 0; k < dirty_row.numSpans; k++) {
Rect src_r(dirty_row.span[k].x1, i, dirty_row.span[k].x2, i + rowsInOne - 1);
Rect dst_r = tf.ScaleRange(src_r);
ds->FillRect(dst_r, fill_color);
@ -483,16 +430,14 @@ void update_invalid_region(Bitmap *ds, color_t fill_color, const DirtyRects &rec
}
}
void update_black_invreg_and_reset(Bitmap *ds)
{
void update_black_invreg_and_reset(Bitmap *ds) {
if (!BlackRects.IsInit())
return;
update_invalid_region(ds, (color_t)0, BlackRects);
BlackRects.Reset();
}
void update_room_invreg_and_reset(int view_index, Bitmap *ds, Bitmap *src, bool no_transform)
{
void update_room_invreg_and_reset(int view_index, Bitmap *ds, Bitmap *src, bool no_transform) {
if (view_index < 0 || RoomCamRects.size() == 0)
return;

View file

@ -47,8 +47,8 @@ using namespace AGS::Engine;
extern GameSetupStruct game;
extern GameState play;
extern RoomStatus*croom;
extern RoomObject*objs;
extern RoomStatus *croom;
extern RoomObject *objs;
extern CharacterCache *charcache;
extern ObjectCache objcache[MAX_ROOM_OBJECTS];
extern SpriteCache spriteset;
@ -56,14 +56,10 @@ extern Bitmap *dynamicallyCreatedSurfaces[MAX_DYNAMIC_SURFACES];
// ** SCRIPT DRAWINGSURFACE OBJECT
void DrawingSurface_Release(ScriptDrawingSurface* sds)
{
if (sds->roomBackgroundNumber >= 0)
{
if (sds->modified)
{
if (sds->roomBackgroundNumber == play.bg_frame)
{
void DrawingSurface_Release(ScriptDrawingSurface *sds) {
if (sds->roomBackgroundNumber >= 0) {
if (sds->modified) {
if (sds->roomBackgroundNumber == play.bg_frame) {
invalidate_screen();
mark_current_background_dirty();
}
@ -72,38 +68,29 @@ void DrawingSurface_Release(ScriptDrawingSurface* sds)
sds->roomBackgroundNumber = -1;
}
if (sds->roomMaskType > kRoomAreaNone)
{
if (sds->roomMaskType == kRoomAreaWalkBehind)
{
if (sds->roomMaskType > kRoomAreaNone) {
if (sds->roomMaskType == kRoomAreaWalkBehind) {
recache_walk_behinds();
}
sds->roomMaskType = kRoomAreaNone;
}
if (sds->dynamicSpriteNumber >= 0)
{
if (sds->modified)
{
if (sds->dynamicSpriteNumber >= 0) {
if (sds->modified) {
int tt;
// force a refresh of any cached object or character images
if (croom != nullptr)
{
for (tt = 0; tt < croom->numobj; tt++)
{
if (croom != nullptr) {
for (tt = 0; tt < croom->numobj; tt++) {
if (objs[tt].num == sds->dynamicSpriteNumber)
objcache[tt].sppic = -31999;
}
}
for (tt = 0; tt < game.numcharacters; tt++)
{
for (tt = 0; tt < game.numcharacters; tt++) {
if (charcache[tt].sppic == sds->dynamicSpriteNumber)
charcache[tt].sppic = -31999;
}
for (tt = 0; tt < game.numgui; tt++)
{
for (tt = 0; tt < game.numgui; tt++) {
if ((guis[tt].BgImage == sds->dynamicSpriteNumber) &&
(guis[tt].IsDisplayed()))
{
(guis[tt].IsDisplayed())) {
guis_need_update = 1;
break;
}
@ -112,8 +99,7 @@ void DrawingSurface_Release(ScriptDrawingSurface* sds)
sds->dynamicSpriteNumber = -1;
}
if (sds->dynamicSurfaceNumber >= 0)
{
if (sds->dynamicSurfaceNumber >= 0) {
delete dynamicallyCreatedSurfaces[sds->dynamicSurfaceNumber];
dynamicallyCreatedSurfaces[sds->dynamicSurfaceNumber] = nullptr;
sds->dynamicSurfaceNumber = -1;
@ -121,35 +107,28 @@ void DrawingSurface_Release(ScriptDrawingSurface* sds)
sds->modified = 0;
}
void ScriptDrawingSurface::PointToGameResolution(int *xcoord, int *ycoord)
{
void ScriptDrawingSurface::PointToGameResolution(int *xcoord, int *ycoord) {
ctx_data_to_game_coord(*xcoord, *ycoord, highResCoordinates != 0);
}
void ScriptDrawingSurface::SizeToGameResolution(int *width, int *height)
{
void ScriptDrawingSurface::SizeToGameResolution(int *width, int *height) {
ctx_data_to_game_size(*width, *height, highResCoordinates != 0);
}
void ScriptDrawingSurface::SizeToGameResolution(int *valueToAdjust)
{
void ScriptDrawingSurface::SizeToGameResolution(int *valueToAdjust) {
*valueToAdjust = ctx_data_to_game_size(*valueToAdjust, highResCoordinates != 0);
}
// convert actual co-ordinate back to what the script is expecting
void ScriptDrawingSurface::SizeToDataResolution(int *valueToAdjust)
{
void ScriptDrawingSurface::SizeToDataResolution(int *valueToAdjust) {
*valueToAdjust = game_to_ctx_data_size(*valueToAdjust, highResCoordinates != 0);
}
ScriptDrawingSurface* DrawingSurface_CreateCopy(ScriptDrawingSurface *sds)
{
ScriptDrawingSurface *DrawingSurface_CreateCopy(ScriptDrawingSurface *sds) {
Bitmap *sourceBitmap = sds->GetBitmapSurface();
for (int i = 0; i < MAX_DYNAMIC_SURFACES; i++)
{
if (dynamicallyCreatedSurfaces[i] == nullptr)
{
for (int i = 0; i < MAX_DYNAMIC_SURFACES; i++) {
if (dynamicallyCreatedSurfaces[i] == nullptr) {
dynamicallyCreatedSurfaces[i] = BitmapHelper::CreateBitmapCopy(sourceBitmap);
ScriptDrawingSurface *newSurface = new ScriptDrawingSurface();
newSurface->dynamicSurfaceNumber = i;
@ -163,9 +142,8 @@ ScriptDrawingSurface* DrawingSurface_CreateCopy(ScriptDrawingSurface *sds)
return nullptr;
}
void DrawingSurface_DrawImageImpl(ScriptDrawingSurface* sds, Bitmap* src, int dst_x, int dst_y, int trans, int dst_width, int dst_height,
int src_x, int src_y, int src_width, int src_height, int sprite_id, bool src_has_alpha)
{
void DrawingSurface_DrawImageImpl(ScriptDrawingSurface *sds, Bitmap *src, int dst_x, int dst_y, int trans, int dst_width, int dst_height,
int src_x, int src_y, int src_width, int src_height, int sprite_id, bool src_has_alpha) {
Bitmap *ds = sds->GetBitmapSurface();
if (src == ds)
quit("!DrawingSurface.DrawImage: cannot draw onto itself");
@ -178,18 +156,34 @@ void DrawingSurface_DrawImageImpl(ScriptDrawingSurface* sds, Bitmap* src, int ds
return; // invalid src or dest rectangles
// Setup uninitialized arguments; convert coordinates for legacy script mode
if (dst_width == SCR_NO_VALUE) { dst_width = src->GetWidth(); }
else { sds->SizeToGameResolution(&dst_width); }
if (dst_height == SCR_NO_VALUE) { dst_height = src->GetHeight(); }
else { sds->SizeToGameResolution(&dst_height); }
if (dst_width == SCR_NO_VALUE) {
dst_width = src->GetWidth();
} else {
sds->SizeToGameResolution(&dst_width);
}
if (dst_height == SCR_NO_VALUE) {
dst_height = src->GetHeight();
} else {
sds->SizeToGameResolution(&dst_height);
}
if (src_x == SCR_NO_VALUE) { src_x = 0; }
if (src_y == SCR_NO_VALUE) { src_y = 0; }
if (src_x == SCR_NO_VALUE) {
src_x = 0;
}
if (src_y == SCR_NO_VALUE) {
src_y = 0;
}
sds->PointToGameResolution(&src_x, &src_y);
if (src_width == SCR_NO_VALUE) { src_width = src->GetWidth(); }
else { sds->SizeToGameResolution(&src_width); }
if (src_height == SCR_NO_VALUE) { src_height = src->GetHeight(); }
else { sds->SizeToGameResolution(&src_height); }
if (src_width == SCR_NO_VALUE) {
src_width = src->GetWidth();
} else {
sds->SizeToGameResolution(&src_width);
}
if (src_height == SCR_NO_VALUE) {
src_height = src->GetHeight();
} else {
sds->SizeToGameResolution(&src_height);
}
if (dst_x >= ds->GetWidth() || dst_x + dst_width <= 0 || dst_y >= ds->GetHeight() || dst_y + dst_height <= 0 ||
src_x >= src->GetWidth() || src_x + src_width <= 0 || src_y >= src->GetHeight() || src_y + src_height <= 0)
@ -202,8 +196,7 @@ void DrawingSurface_DrawImageImpl(ScriptDrawingSurface* sds, Bitmap* src, int ds
// if simplier blit/draw_sprite could be called (no translucency with alpha channel).
bool needToFreeBitmap = false;
if (dst_width != src->GetWidth() || dst_height != src->GetHeight() ||
src_width != src->GetWidth() || src_height != src->GetHeight())
{
src_width != src->GetWidth() || src_height != src->GetHeight()) {
// Resize and/or partial copy specified
Bitmap *newPic = BitmapHelper::CreateBitmap(dst_width, dst_height, src->GetColorDepth());
newPic->StretchBlt(src,
@ -234,100 +227,82 @@ void DrawingSurface_DrawImageImpl(ScriptDrawingSurface* sds, Bitmap* src, int ds
delete src;
}
void DrawingSurface_DrawImageEx(ScriptDrawingSurface* sds, int dst_x, int dst_y, int slot, int trans, int dst_width, int dst_height,
int src_x, int src_y, int src_width, int src_height)
{
void DrawingSurface_DrawImageEx(ScriptDrawingSurface *sds, int dst_x, int dst_y, int slot, int trans, int dst_width, int dst_height,
int src_x, int src_y, int src_width, int src_height) {
if ((slot < 0) || (spriteset[slot] == nullptr))
quit("!DrawingSurface.DrawImage: invalid sprite slot number specified");
DrawingSurface_DrawImageImpl(sds, spriteset[slot], dst_x, dst_y, trans, dst_width, dst_height,
src_x, src_y, src_width, src_height, slot, (game.SpriteInfos[slot].Flags & SPF_ALPHACHANNEL) != 0);
}
void DrawingSurface_DrawImage(ScriptDrawingSurface* sds, int xx, int yy, int slot, int trans, int width, int height)
{
void DrawingSurface_DrawImage(ScriptDrawingSurface *sds, int xx, int yy, int slot, int trans, int width, int height) {
DrawingSurface_DrawImageEx(sds, xx, yy, slot, trans, width, height, 0, 0, SCR_NO_VALUE, SCR_NO_VALUE);
}
void DrawingSurface_DrawSurfaceEx(ScriptDrawingSurface* target, ScriptDrawingSurface* source, int trans,
void DrawingSurface_DrawSurfaceEx(ScriptDrawingSurface *target, ScriptDrawingSurface *source, int trans,
int dst_x, int dst_y, int dst_width, int dst_height,
int src_x, int src_y, int src_width, int src_height)
{
int src_x, int src_y, int src_width, int src_height) {
DrawingSurface_DrawImageImpl(target, source->GetBitmapSurface(), dst_x, dst_y, trans, dst_width, dst_height,
src_x, src_y, src_width, src_height, -1, source->hasAlphaChannel);
}
void DrawingSurface_DrawSurface(ScriptDrawingSurface* target, ScriptDrawingSurface* source, int trans)
{
void DrawingSurface_DrawSurface(ScriptDrawingSurface *target, ScriptDrawingSurface *source, int trans) {
DrawingSurface_DrawSurfaceEx(target, source, trans, 0, 0, SCR_NO_VALUE, SCR_NO_VALUE, 0, 0, SCR_NO_VALUE, SCR_NO_VALUE);
}
void DrawingSurface_SetDrawingColor(ScriptDrawingSurface *sds, int newColour)
{
void DrawingSurface_SetDrawingColor(ScriptDrawingSurface *sds, int newColour) {
sds->currentColourScript = newColour;
// StartDrawing to set up ds to set the colour at the appropriate
// depth for the background
Bitmap *ds = sds->StartDrawing();
if (newColour == SCR_COLOR_TRANSPARENT)
{
if (newColour == SCR_COLOR_TRANSPARENT) {
sds->currentColour = ds->GetMaskColor();
}
else
{
} else {
sds->currentColour = ds->GetCompatibleColor(newColour);
}
sds->FinishedDrawingReadOnly();
}
int DrawingSurface_GetDrawingColor(ScriptDrawingSurface *sds)
{
int DrawingSurface_GetDrawingColor(ScriptDrawingSurface *sds) {
return sds->currentColourScript;
}
void DrawingSurface_SetUseHighResCoordinates(ScriptDrawingSurface *sds, int highRes)
{
void DrawingSurface_SetUseHighResCoordinates(ScriptDrawingSurface *sds, int highRes) {
if (game.AllowRelativeRes())
sds->highResCoordinates = (highRes) ? 1 : 0;
}
int DrawingSurface_GetUseHighResCoordinates(ScriptDrawingSurface *sds)
{
int DrawingSurface_GetUseHighResCoordinates(ScriptDrawingSurface *sds) {
return sds->highResCoordinates;
}
int DrawingSurface_GetHeight(ScriptDrawingSurface *sds)
{
int DrawingSurface_GetHeight(ScriptDrawingSurface *sds) {
Bitmap *ds = sds->GetBitmapSurface();
int height = ds->GetHeight();
sds->SizeToGameResolution(&height);
return height;
}
int DrawingSurface_GetWidth(ScriptDrawingSurface *sds)
{
int DrawingSurface_GetWidth(ScriptDrawingSurface *sds) {
Bitmap *ds = sds->GetBitmapSurface();
int width = ds->GetWidth();
sds->SizeToGameResolution(&width);
return width;
}
void DrawingSurface_Clear(ScriptDrawingSurface *sds, int colour)
{
void DrawingSurface_Clear(ScriptDrawingSurface *sds, int colour) {
Bitmap *ds = sds->StartDrawing();
int allegroColor;
if ((colour == -SCR_NO_VALUE) || (colour == SCR_COLOR_TRANSPARENT))
{
if ((colour == -SCR_NO_VALUE) || (colour == SCR_COLOR_TRANSPARENT)) {
allegroColor = ds->GetMaskColor();
}
else
{
} else {
allegroColor = ds->GetCompatibleColor(colour);
}
ds->Fill(allegroColor);
sds->FinishedDrawing();
}
void DrawingSurface_DrawCircle(ScriptDrawingSurface *sds, int x, int y, int radius)
{
void DrawingSurface_DrawCircle(ScriptDrawingSurface *sds, int x, int y, int radius) {
sds->PointToGameResolution(&x, &y);
sds->SizeToGameResolution(&radius);
@ -336,36 +311,33 @@ void DrawingSurface_DrawCircle(ScriptDrawingSurface *sds, int x, int y, int radi
sds->FinishedDrawing();
}
void DrawingSurface_DrawRectangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2)
{
void DrawingSurface_DrawRectangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2) {
sds->PointToGameResolution(&x1, &y1);
sds->PointToGameResolution(&x2, &y2);
Bitmap *ds = sds->StartDrawing();
ds->FillRect(Rect(x1,y1,x2,y2), sds->currentColour);
ds->FillRect(Rect(x1, y1, x2, y2), sds->currentColour);
sds->FinishedDrawing();
}
void DrawingSurface_DrawTriangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2, int x3, int y3)
{
void DrawingSurface_DrawTriangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2, int x3, int y3) {
sds->PointToGameResolution(&x1, &y1);
sds->PointToGameResolution(&x2, &y2);
sds->PointToGameResolution(&x3, &y3);
Bitmap *ds = sds->StartDrawing();
ds->DrawTriangle(Triangle(x1,y1,x2,y2,x3,y3), sds->currentColour);
ds->DrawTriangle(Triangle(x1, y1, x2, y2, x3, y3), sds->currentColour);
sds->FinishedDrawing();
}
void DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char* text)
{
void DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char *text) {
sds->PointToGameResolution(&xx, &yy);
Bitmap *ds = sds->StartDrawing();
// don't use wtextcolor because it will do a 16->32 conversion
color_t text_color = sds->currentColour;
if ((ds->GetColorDepth() <= 8) && (play.raw_color > 255)) {
text_color = ds->GetCompatibleColor(1);
debug_script_warn ("RawPrint: Attempted to use hi-color on 256-col background");
debug_script_warn("RawPrint: Attempted to use hi-color on 256-col background");
}
wouttext_outline(ds, xx, yy, font, text_color, text);
sds->FinishedDrawing();
@ -386,27 +358,22 @@ void DrawingSurface_DrawStringWrapped(ScriptDrawingSurface *sds, int xx, int yy,
Bitmap *ds = sds->StartDrawing();
color_t text_color = sds->currentColour;
for (size_t i = 0; i < Lines.Count(); i++)
{
for (size_t i = 0; i < Lines.Count(); i++) {
int drawAtX = xx;
if (alignment & kMAlignHCenter)
{
if (alignment & kMAlignHCenter) {
drawAtX = xx + ((wid / 2) - wgettextwidth(Lines[i], font) / 2);
}
else if (alignment & kMAlignRight)
{
} else if (alignment & kMAlignRight) {
drawAtX = (xx + wid) - wgettextwidth(Lines[i], font);
}
wouttext_outline(ds, drawAtX, yy + linespacing*i, font, text_color, Lines[i]);
wouttext_outline(ds, drawAtX, yy + linespacing * i, font, text_color, Lines[i]);
}
sds->FinishedDrawing();
}
void DrawingSurface_DrawMessageWrapped(ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int msgm)
{
void DrawingSurface_DrawMessageWrapped(ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int msgm) {
char displbuf[3000];
get_message_text(msgm, displbuf);
// it's probably too late but check anyway
@ -420,17 +387,15 @@ void DrawingSurface_DrawLine(ScriptDrawingSurface *sds, int fromx, int fromy, in
sds->PointToGameResolution(&fromx, &fromy);
sds->PointToGameResolution(&tox, &toy);
sds->SizeToGameResolution(&thickness);
int ii,jj,xx,yy;
int ii, jj, xx, yy;
Bitmap *ds = sds->StartDrawing();
// draw several lines to simulate the thickness
color_t draw_color = sds->currentColour;
for (ii = 0; ii < thickness; ii++)
{
for (ii = 0; ii < thickness; ii++) {
xx = (ii - (thickness / 2));
for (jj = 0; jj < thickness; jj++)
{
for (jj = 0; jj < thickness; jj++) {
yy = (jj - (thickness / 2));
ds->DrawLine (Line(fromx + xx, fromy + yy, tox + xx, toy + yy), draw_color);
ds->DrawLine(Line(fromx + xx, fromy + yy, tox + xx, toy + yy), draw_color);
}
}
sds->FinishedDrawing();
@ -440,14 +405,12 @@ void DrawingSurface_DrawPixel(ScriptDrawingSurface *sds, int x, int y) {
sds->PointToGameResolution(&x, &y);
int thickness = 1;
sds->SizeToGameResolution(&thickness);
int ii,jj;
int ii, jj;
Bitmap *ds = sds->StartDrawing();
// draw several pixels to simulate the thickness
color_t draw_color = sds->currentColour;
for (ii = 0; ii < thickness; ii++)
{
for (jj = 0; jj < thickness; jj++)
{
for (ii = 0; ii < thickness; ii++) {
for (jj = 0; jj < thickness; jj++) {
ds->PutPixel(x + ii, y + jj, draw_color);
}
}
@ -461,12 +424,9 @@ int DrawingSurface_GetPixel(ScriptDrawingSurface *sds, int x, int y) {
unsigned int maskColor = ds->GetMaskColor();
int colDepth = ds->GetColorDepth();
if (rawPixel == maskColor)
{
if (rawPixel == maskColor) {
rawPixel = SCR_COLOR_TRANSPARENT;
}
else if (colDepth > 8)
{
} else if (colDepth > 8) {
int r = getr_depth(colDepth, rawPixel);
int ds = getg_depth(colDepth, rawPixel);
int b = getb_depth(colDepth, rawPixel);
@ -490,146 +450,123 @@ int DrawingSurface_GetPixel(ScriptDrawingSurface *sds, int x, int y) {
#include "script/script_runtime.h"
// void (ScriptDrawingSurface *sds, int colour)
RuntimeScriptValue Sc_DrawingSurface_Clear(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_Clear(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDrawingSurface, DrawingSurface_Clear);
}
// ScriptDrawingSurface* (ScriptDrawingSurface *sds)
RuntimeScriptValue Sc_DrawingSurface_CreateCopy(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_CreateCopy(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJAUTO(ScriptDrawingSurface, ScriptDrawingSurface, DrawingSurface_CreateCopy);
}
// void (ScriptDrawingSurface *sds, int x, int y, int radius)
RuntimeScriptValue Sc_DrawingSurface_DrawCircle(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawCircle(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT3(ScriptDrawingSurface, DrawingSurface_DrawCircle);
}
// void (ScriptDrawingSurface* sds, int xx, int yy, int slot, int trans, int width, int height)
RuntimeScriptValue Sc_DrawingSurface_DrawImage_6(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawImage_6(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT6(ScriptDrawingSurface, DrawingSurface_DrawImage);
}
RuntimeScriptValue Sc_DrawingSurface_DrawImage(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawImage(void *self, const RuntimeScriptValue *params, int32_t param_count) {
ASSERT_OBJ_PARAM_COUNT(METHOD, 10);
DrawingSurface_DrawImageEx((ScriptDrawingSurface*)self, params[0].IValue, params[1].IValue, params[2].IValue, params[3].IValue, params[4].IValue, params[5].IValue,
DrawingSurface_DrawImageEx((ScriptDrawingSurface *)self, params[0].IValue, params[1].IValue, params[2].IValue, params[3].IValue, params[4].IValue, params[5].IValue,
params[6].IValue, params[7].IValue, params[8].IValue, params[9].IValue);
return RuntimeScriptValue((int32_t)0);
}
// void (ScriptDrawingSurface *sds, int fromx, int fromy, int tox, int toy, int thickness)
RuntimeScriptValue Sc_DrawingSurface_DrawLine(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawLine(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT5(ScriptDrawingSurface, DrawingSurface_DrawLine);
}
// void (ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int msgm)
RuntimeScriptValue Sc_DrawingSurface_DrawMessageWrapped(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawMessageWrapped(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT5(ScriptDrawingSurface, DrawingSurface_DrawMessageWrapped);
}
// void (ScriptDrawingSurface *sds, int x, int y)
RuntimeScriptValue Sc_DrawingSurface_DrawPixel(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawPixel(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(ScriptDrawingSurface, DrawingSurface_DrawPixel);
}
// void (ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2)
RuntimeScriptValue Sc_DrawingSurface_DrawRectangle(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawRectangle(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT4(ScriptDrawingSurface, DrawingSurface_DrawRectangle);
}
// void (ScriptDrawingSurface *sds, int xx, int yy, int font, const char* texx, ...)
RuntimeScriptValue Sc_DrawingSurface_DrawString(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawString(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_SCRIPT_SPRINTF(DrawingSurface_DrawString, 4);
DrawingSurface_DrawString((ScriptDrawingSurface*)self, params[0].IValue, params[1].IValue, params[2].IValue, scsf_buffer);
DrawingSurface_DrawString((ScriptDrawingSurface *)self, params[0].IValue, params[1].IValue, params[2].IValue, scsf_buffer);
return RuntimeScriptValue((int32_t)0);
}
// void (ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int alignment, const char *msg)
RuntimeScriptValue Sc_DrawingSurface_DrawStringWrapped_Old(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawStringWrapped_Old(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT5_POBJ(ScriptDrawingSurface, DrawingSurface_DrawStringWrapped_Old, const char);
}
RuntimeScriptValue Sc_DrawingSurface_DrawStringWrapped(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawStringWrapped(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT5_POBJ(ScriptDrawingSurface, DrawingSurface_DrawStringWrapped, const char);
}
// void (ScriptDrawingSurface* target, ScriptDrawingSurface* source, int translev)
RuntimeScriptValue Sc_DrawingSurface_DrawSurface_2(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawSurface_2(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ_PINT(ScriptDrawingSurface, DrawingSurface_DrawSurface, ScriptDrawingSurface);
}
RuntimeScriptValue Sc_DrawingSurface_DrawSurface(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawSurface(void *self, const RuntimeScriptValue *params, int32_t param_count) {
ASSERT_OBJ_PARAM_COUNT(METHOD, 10);
DrawingSurface_DrawSurfaceEx((ScriptDrawingSurface*)self, (ScriptDrawingSurface*)params[0].Ptr,
DrawingSurface_DrawSurfaceEx((ScriptDrawingSurface *)self, (ScriptDrawingSurface *)params[0].Ptr,
params[1].IValue, params[2].IValue, params[3].IValue, params[4].IValue, params[5].IValue,
params[6].IValue, params[7].IValue, params[8].IValue, params[9].IValue);
return RuntimeScriptValue((int32_t)0);
}
// void (ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2, int x3, int y3)
RuntimeScriptValue Sc_DrawingSurface_DrawTriangle(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_DrawTriangle(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT6(ScriptDrawingSurface, DrawingSurface_DrawTriangle);
}
// int (ScriptDrawingSurface *sds, int x, int y)
RuntimeScriptValue Sc_DrawingSurface_GetPixel(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_GetPixel(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT2(ScriptDrawingSurface, DrawingSurface_GetPixel);
}
// void (ScriptDrawingSurface* sds)
RuntimeScriptValue Sc_DrawingSurface_Release(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_Release(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptDrawingSurface, DrawingSurface_Release);
}
// int (ScriptDrawingSurface *sds)
RuntimeScriptValue Sc_DrawingSurface_GetDrawingColor(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_GetDrawingColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDrawingSurface, DrawingSurface_GetDrawingColor);
}
// void (ScriptDrawingSurface *sds, int newColour)
RuntimeScriptValue Sc_DrawingSurface_SetDrawingColor(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_SetDrawingColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDrawingSurface, DrawingSurface_SetDrawingColor);
}
// int (ScriptDrawingSurface *sds)
RuntimeScriptValue Sc_DrawingSurface_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDrawingSurface, DrawingSurface_GetHeight);
}
// int (ScriptDrawingSurface *sds)
RuntimeScriptValue Sc_DrawingSurface_GetUseHighResCoordinates(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_GetUseHighResCoordinates(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDrawingSurface, DrawingSurface_GetUseHighResCoordinates);
}
// void (ScriptDrawingSurface *sds, int highRes)
RuntimeScriptValue Sc_DrawingSurface_SetUseHighResCoordinates(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_SetUseHighResCoordinates(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDrawingSurface, DrawingSurface_SetUseHighResCoordinates);
}
// int (ScriptDrawingSurface *sds)
RuntimeScriptValue Sc_DrawingSurface_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DrawingSurface_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDrawingSurface, DrawingSurface_GetWidth);
}
@ -640,14 +577,12 @@ RuntimeScriptValue Sc_DrawingSurface_GetWidth(void *self, const RuntimeScriptVal
//=============================================================================
// void (ScriptDrawingSurface *sds, int xx, int yy, int font, const char* texx, ...)
void ScPl_DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char* texx, ...)
{
void ScPl_DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char *texx, ...) {
API_PLUGIN_SCRIPT_SPRINTF(texx);
DrawingSurface_DrawString(sds, xx, yy, font, scsf_buffer);
}
void RegisterDrawingSurfaceAPI(ScriptAPIVersion base_api, ScriptAPIVersion compat_api)
{
void RegisterDrawingSurfaceAPI(ScriptAPIVersion base_api, ScriptAPIVersion compat_api) {
ccAddExternalObjectFunction("DrawingSurface::Clear^1", Sc_DrawingSurface_Clear);
ccAddExternalObjectFunction("DrawingSurface::CreateCopy^0", Sc_DrawingSurface_CreateCopy);
ccAddExternalObjectFunction("DrawingSurface::DrawCircle^3", Sc_DrawingSurface_DrawCircle);
@ -676,27 +611,27 @@ void RegisterDrawingSurfaceAPI(ScriptAPIVersion base_api, ScriptAPIVersion compa
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("DrawingSurface::Clear^1", (void*)DrawingSurface_Clear);
ccAddExternalFunctionForPlugin("DrawingSurface::CreateCopy^0", (void*)DrawingSurface_CreateCopy);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawCircle^3", (void*)DrawingSurface_DrawCircle);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawImage^6", (void*)DrawingSurface_DrawImage);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawLine^5", (void*)DrawingSurface_DrawLine);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawMessageWrapped^5", (void*)DrawingSurface_DrawMessageWrapped);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawPixel^2", (void*)DrawingSurface_DrawPixel);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawRectangle^4", (void*)DrawingSurface_DrawRectangle);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawString^104", (void*)ScPl_DrawingSurface_DrawString);
ccAddExternalFunctionForPlugin("DrawingSurface::Clear^1", (void *)DrawingSurface_Clear);
ccAddExternalFunctionForPlugin("DrawingSurface::CreateCopy^0", (void *)DrawingSurface_CreateCopy);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawCircle^3", (void *)DrawingSurface_DrawCircle);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawImage^6", (void *)DrawingSurface_DrawImage);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawLine^5", (void *)DrawingSurface_DrawLine);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawMessageWrapped^5", (void *)DrawingSurface_DrawMessageWrapped);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawPixel^2", (void *)DrawingSurface_DrawPixel);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawRectangle^4", (void *)DrawingSurface_DrawRectangle);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawString^104", (void *)ScPl_DrawingSurface_DrawString);
if (base_api < kScriptAPI_v350)
ccAddExternalFunctionForPlugin("DrawingSurface::DrawStringWrapped^6", (void*)DrawingSurface_DrawStringWrapped_Old);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawStringWrapped^6", (void *)DrawingSurface_DrawStringWrapped_Old);
else
ccAddExternalFunctionForPlugin("DrawingSurface::DrawStringWrapped^6", (void*)DrawingSurface_DrawStringWrapped);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawSurface^2", (void*)DrawingSurface_DrawSurface);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawTriangle^6", (void*)DrawingSurface_DrawTriangle);
ccAddExternalFunctionForPlugin("DrawingSurface::GetPixel^2", (void*)DrawingSurface_GetPixel);
ccAddExternalFunctionForPlugin("DrawingSurface::Release^0", (void*)DrawingSurface_Release);
ccAddExternalFunctionForPlugin("DrawingSurface::get_DrawingColor", (void*)DrawingSurface_GetDrawingColor);
ccAddExternalFunctionForPlugin("DrawingSurface::set_DrawingColor", (void*)DrawingSurface_SetDrawingColor);
ccAddExternalFunctionForPlugin("DrawingSurface::get_Height", (void*)DrawingSurface_GetHeight);
ccAddExternalFunctionForPlugin("DrawingSurface::get_UseHighResCoordinates", (void*)DrawingSurface_GetUseHighResCoordinates);
ccAddExternalFunctionForPlugin("DrawingSurface::set_UseHighResCoordinates", (void*)DrawingSurface_SetUseHighResCoordinates);
ccAddExternalFunctionForPlugin("DrawingSurface::get_Width", (void*)DrawingSurface_GetWidth);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawStringWrapped^6", (void *)DrawingSurface_DrawStringWrapped);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawSurface^2", (void *)DrawingSurface_DrawSurface);
ccAddExternalFunctionForPlugin("DrawingSurface::DrawTriangle^6", (void *)DrawingSurface_DrawTriangle);
ccAddExternalFunctionForPlugin("DrawingSurface::GetPixel^2", (void *)DrawingSurface_GetPixel);
ccAddExternalFunctionForPlugin("DrawingSurface::Release^0", (void *)DrawingSurface_Release);
ccAddExternalFunctionForPlugin("DrawingSurface::get_DrawingColor", (void *)DrawingSurface_GetDrawingColor);
ccAddExternalFunctionForPlugin("DrawingSurface::set_DrawingColor", (void *)DrawingSurface_SetDrawingColor);
ccAddExternalFunctionForPlugin("DrawingSurface::get_Height", (void *)DrawingSurface_GetHeight);
ccAddExternalFunctionForPlugin("DrawingSurface::get_UseHighResCoordinates", (void *)DrawingSurface_GetUseHighResCoordinates);
ccAddExternalFunctionForPlugin("DrawingSurface::set_UseHighResCoordinates", (void *)DrawingSurface_SetUseHighResCoordinates);
ccAddExternalFunctionForPlugin("DrawingSurface::get_Width", (void *)DrawingSurface_GetWidth);
}

View file

@ -25,11 +25,11 @@
#include "ac/dynobj/scriptdrawingsurface.h"
void DrawingSurface_Release(ScriptDrawingSurface* sds);
void DrawingSurface_Release(ScriptDrawingSurface *sds);
// convert actual co-ordinate back to what the script is expecting
ScriptDrawingSurface* DrawingSurface_CreateCopy(ScriptDrawingSurface *sds);
void DrawingSurface_DrawSurface(ScriptDrawingSurface* target, ScriptDrawingSurface* source, int translev);
void DrawingSurface_DrawImage_FullSrc(ScriptDrawingSurface* sds, int xx, int yy, int slot, int trans, int width, int height);
ScriptDrawingSurface *DrawingSurface_CreateCopy(ScriptDrawingSurface *sds);
void DrawingSurface_DrawSurface(ScriptDrawingSurface *target, ScriptDrawingSurface *source, int translev);
void DrawingSurface_DrawImage_FullSrc(ScriptDrawingSurface *sds, int xx, int yy, int slot, int trans, int width, int height);
void DrawingSurface_SetDrawingColor(ScriptDrawingSurface *sds, int newColour);
int DrawingSurface_GetDrawingColor(ScriptDrawingSurface *sds);
void DrawingSurface_SetUseHighResCoordinates(ScriptDrawingSurface *sds, int highRes);
@ -40,7 +40,7 @@ void DrawingSurface_Clear(ScriptDrawingSurface *sds, int colour);
void DrawingSurface_DrawCircle(ScriptDrawingSurface *sds, int x, int y, int radius);
void DrawingSurface_DrawRectangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2);
void DrawingSurface_DrawTriangle(ScriptDrawingSurface *sds, int x1, int y1, int x2, int y2, int x3, int y3);
void DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char* text);
void DrawingSurface_DrawString(ScriptDrawingSurface *sds, int xx, int yy, int font, const char *text);
void DrawingSurface_DrawStringWrapped(ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int alignment, const char *msg);
void DrawingSurface_DrawMessageWrapped(ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int msgm);
void DrawingSurface_DrawLine(ScriptDrawingSurface *sds, int fromx, int fromy, int tox, int toy, int thickness);

View file

@ -47,8 +47,8 @@ using namespace Engine;
extern GameSetupStruct game;
extern SpriteCache spriteset;
extern RoomStruct thisroom;
extern RoomObject*objs;
extern RoomStatus*croom;
extern RoomObject *objs;
extern RoomStatus *croom;
extern CharacterCache *charcache;
extern ObjectCache objcache[MAX_ROOM_OBJECTS];
@ -66,8 +66,7 @@ void DynamicSprite_Delete(ScriptDynamicSprite *sds) {
}
}
ScriptDrawingSurface* DynamicSprite_GetDrawingSurface(ScriptDynamicSprite *dss)
{
ScriptDrawingSurface *DynamicSprite_GetDrawingSurface(ScriptDynamicSprite *dss) {
ScriptDrawingSurface *surface = new ScriptDrawingSurface();
surface->dynamicSpriteNumber = dss->slot;
@ -151,16 +150,14 @@ void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSpri
quit("!DynamicSprite.CopyTransparencyMask: sprite has been deleted");
if ((game.SpriteInfos[sds->slot].Width != game.SpriteInfos[sourceSprite].Width) ||
(game.SpriteInfos[sds->slot].Height != game.SpriteInfos[sourceSprite].Height))
{
(game.SpriteInfos[sds->slot].Height != game.SpriteInfos[sourceSprite].Height)) {
quit("!DynamicSprite.CopyTransparencyMask: sprites are not the same size");
}
Bitmap *target = spriteset[sds->slot];
Bitmap *source = spriteset[sourceSprite];
if (target->GetColorDepth() != source->GetColorDepth())
{
if (target->GetColorDepth() != source->GetColorDepth()) {
quit("!DynamicSprite.CopyTransparencyMask: sprites are not the same colour depth");
}
@ -168,16 +165,14 @@ void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSpri
bool dst_has_alpha = (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0;
bool src_has_alpha = (game.SpriteInfos[sourceSprite].Flags & SPF_ALPHACHANNEL) != 0;
game.SpriteInfos[sds->slot].Flags &= ~SPF_ALPHACHANNEL;
if (src_has_alpha)
{
if (src_has_alpha) {
game.SpriteInfos[sds->slot].Flags |= SPF_ALPHACHANNEL;
}
BitmapHelper::CopyTransparency(target, source, dst_has_alpha, src_has_alpha);
}
void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int height, int x, int y)
{
void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int height, int x, int y) {
if (sds->slot == 0)
quit("!DynamicSprite.ChangeCanvasSize: sprite has been deleted");
if ((width < 1) || (height < 1))
@ -238,8 +233,7 @@ void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int he
width = (cosVal * (double)game.SpriteInfos[sds->slot].Width + sinVal * (double)game.SpriteInfos[sds->slot].Height);
height = (sinVal * (double)game.SpriteInfos[sds->slot].Width + cosVal * (double)game.SpriteInfos[sds->slot].Height);
}
else {
} else {
data_to_game_coords(&width, &height);
}
@ -260,8 +254,7 @@ void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int he
add_dynamic_sprite(sds->slot, newPic, (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
}
void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
{
void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance) {
Bitmap *source = spriteset[sds->slot];
Bitmap *newPic = BitmapHelper::CreateBitmap(source->GetWidth(), source->GetHeight(), source->GetColorDepth());
@ -272,8 +265,7 @@ void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue,
add_dynamic_sprite(sds->slot, newPic, (game.SpriteInfos[sds->slot].Flags & SPF_ALPHACHANNEL) != 0);
}
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
{
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char *namm) {
if (sds->slot == 0)
quit("!DynamicSprite.SaveToFile: sprite has been deleted");
@ -287,7 +279,7 @@ int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
return spriteset[sds->slot]->SaveToFile(rp.FullPath, palette) ? 1 : 0;
}
ScriptDynamicSprite* DynamicSprite_CreateFromSaveGame(int sgslot, int width, int height) {
ScriptDynamicSprite *DynamicSprite_CreateFromSaveGame(int sgslot, int width, int height) {
int slotnum = LoadSaveSlotScreenshot(sgslot, width, height);
if (slotnum) {
ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(slotnum);
@ -296,7 +288,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromSaveGame(int sgslot, int width, int
return nullptr;
}
ScriptDynamicSprite* DynamicSprite_CreateFromFile(const char *filename) {
ScriptDynamicSprite *DynamicSprite_CreateFromFile(const char *filename) {
int slotnum = LoadImageFile(filename);
if (slotnum) {
ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(slotnum);
@ -305,7 +297,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromFile(const char *filename) {
return nullptr;
}
ScriptDynamicSprite* DynamicSprite_CreateFromScreenShot(int width, int height) {
ScriptDynamicSprite *DynamicSprite_CreateFromScreenShot(int width, int height) {
// TODO: refactor and merge with create_savegame_screenshot()
@ -334,7 +326,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromScreenShot(int width, int height) {
return new_spr;
}
ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite(int slot, int preserveAlphaChannel) {
ScriptDynamicSprite *DynamicSprite_CreateFromExistingSprite(int slot, int preserveAlphaChannel) {
int gotSlot = spriteset.GetFreeIndex();
if (gotSlot <= 0)
@ -356,8 +348,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite(int slot, int preser
return new_spr;
}
ScriptDynamicSprite* DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height)
{
ScriptDynamicSprite *DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height) {
int gotSlot = spriteset.GetFreeIndex();
if (gotSlot <= 0)
return nullptr;
@ -386,8 +377,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface
return new_spr;
}
ScriptDynamicSprite* DynamicSprite_Create(int width, int height, int alphaChannel)
{
ScriptDynamicSprite *DynamicSprite_Create(int width, int height, int alphaChannel) {
data_to_game_coords(&width, &height);
int gotSlot = spriteset.GetFreeIndex();
@ -406,17 +396,15 @@ ScriptDynamicSprite* DynamicSprite_Create(int width, int height, int alphaChanne
return new_spr;
}
ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite_Old(int slot)
{
ScriptDynamicSprite *DynamicSprite_CreateFromExistingSprite_Old(int slot) {
return DynamicSprite_CreateFromExistingSprite(slot, 0);
}
ScriptDynamicSprite* DynamicSprite_CreateFromBackground(int frame, int x1, int y1, int width, int height) {
ScriptDynamicSprite *DynamicSprite_CreateFromBackground(int frame, int x1, int y1, int width, int height) {
if (frame == SCR_NO_VALUE) {
frame = play.bg_frame;
}
else if ((frame < 0) || ((size_t)frame >= thisroom.BgFrameCount))
} else if ((frame < 0) || ((size_t)frame >= thisroom.BgFrameCount))
quit("!DynamicSprite.CreateFromBackground: invalid frame specified");
if (x1 == SCR_NO_VALUE) {
@ -424,8 +412,7 @@ ScriptDynamicSprite* DynamicSprite_CreateFromBackground(int frame, int x1, int y
y1 = 0;
width = play.room_width;
height = play.room_height;
}
else if ((x1 < 0) || (y1 < 0) || (width < 1) || (height < 1) ||
} else if ((x1 < 0) || (y1 < 0) || (width < 1) || (height < 1) ||
(x1 + width > play.room_width) || (y1 + height > play.room_height))
quit("!DynamicSprite.CreateFromBackground: invalid co-ordinates specified");
@ -468,7 +455,7 @@ void add_dynamic_sprite(int gotSlot, Bitmap *redin, bool hasAlpha) {
game.SpriteInfos[gotSlot].Height = redin->GetHeight();
}
void free_dynamic_sprite (int gotSlot) {
void free_dynamic_sprite(int gotSlot) {
int tt;
if ((gotSlot < 0) || (gotSlot >= spriteset.GetSpriteSlotCount()))
@ -498,16 +485,12 @@ void free_dynamic_sprite (int gotSlot) {
}
// force refresh of any object caches using the sprite
if (croom != nullptr)
{
for (tt = 0; tt < croom->numobj; tt++)
{
if (objs[tt].num == gotSlot)
{
if (croom != nullptr) {
for (tt = 0; tt < croom->numobj; tt++) {
if (objs[tt].num == gotSlot) {
objs[tt].num = 0;
objcache[tt].sppic = -1;
}
else if (objcache[tt].sppic == gotSlot)
} else if (objcache[tt].sppic == gotSlot)
objcache[tt].sppic = -1;
}
}
@ -524,140 +507,117 @@ void free_dynamic_sprite (int gotSlot) {
#include "script/script_runtime.h"
// void (ScriptDynamicSprite *sds, int width, int height, int x, int y)
RuntimeScriptValue Sc_DynamicSprite_ChangeCanvasSize(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_ChangeCanvasSize(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT4(ScriptDynamicSprite, DynamicSprite_ChangeCanvasSize);
}
// void (ScriptDynamicSprite *sds, int sourceSprite)
RuntimeScriptValue Sc_DynamicSprite_CopyTransparencyMask(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CopyTransparencyMask(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDynamicSprite, DynamicSprite_CopyTransparencyMask);
}
// void (ScriptDynamicSprite *sds, int x1, int y1, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_Crop(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Crop(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT4(ScriptDynamicSprite, DynamicSprite_Crop);
}
// void (ScriptDynamicSprite *sds)
RuntimeScriptValue Sc_DynamicSprite_Delete(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Delete(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptDynamicSprite, DynamicSprite_Delete);
}
// void (ScriptDynamicSprite *sds, int direction)
RuntimeScriptValue Sc_DynamicSprite_Flip(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Flip(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptDynamicSprite, DynamicSprite_Flip);
}
// ScriptDrawingSurface* (ScriptDynamicSprite *dss)
RuntimeScriptValue Sc_DynamicSprite_GetDrawingSurface(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_GetDrawingSurface(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJAUTO(ScriptDynamicSprite, ScriptDrawingSurface, DynamicSprite_GetDrawingSurface);
}
// void (ScriptDynamicSprite *sds, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_Resize(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Resize(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(ScriptDynamicSprite, DynamicSprite_Resize);
}
// void (ScriptDynamicSprite *sds, int angle, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_Rotate(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Rotate(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT3(ScriptDynamicSprite, DynamicSprite_Rotate);
}
// int (ScriptDynamicSprite *sds, const char* namm)
RuntimeScriptValue Sc_DynamicSprite_SaveToFile(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_SaveToFile(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_POBJ(ScriptDynamicSprite, DynamicSprite_SaveToFile, const char);
}
// void (ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
RuntimeScriptValue Sc_DynamicSprite_Tint(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Tint(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT5(ScriptDynamicSprite, DynamicSprite_Tint);
}
// int (ScriptDynamicSprite *sds)
RuntimeScriptValue Sc_DynamicSprite_GetColorDepth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_GetColorDepth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetColorDepth);
}
// int (ScriptDynamicSprite *sds)
RuntimeScriptValue Sc_DynamicSprite_GetGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_GetGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetGraphic);
}
// int (ScriptDynamicSprite *sds)
RuntimeScriptValue Sc_DynamicSprite_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetHeight);
}
// int (ScriptDynamicSprite *sds)
RuntimeScriptValue Sc_DynamicSprite_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetWidth);
}
// ScriptDynamicSprite* (int width, int height, int alphaChannel)
RuntimeScriptValue Sc_DynamicSprite_Create(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_Create(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT3(ScriptDynamicSprite, DynamicSprite_Create);
}
// ScriptDynamicSprite* (int frame, int x1, int y1, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_CreateFromBackground(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromBackground(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT5(ScriptDynamicSprite, DynamicSprite_CreateFromBackground);
}
// ScriptDynamicSprite* (ScriptDrawingSurface *sds, int x, int y, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_CreateFromDrawingSurface(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromDrawingSurface(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_POBJ_PINT4(ScriptDynamicSprite, DynamicSprite_CreateFromDrawingSurface, ScriptDrawingSurface);
}
// ScriptDynamicSprite* (int slot)
RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite_Old(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite_Old(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT(ScriptDynamicSprite, DynamicSprite_CreateFromExistingSprite_Old);
}
// ScriptDynamicSprite* (int slot, int preserveAlphaChannel)
RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT2(ScriptDynamicSprite, DynamicSprite_CreateFromExistingSprite);
}
// ScriptDynamicSprite* (const char *filename)
RuntimeScriptValue Sc_DynamicSprite_CreateFromFile(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromFile(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_POBJ(ScriptDynamicSprite, DynamicSprite_CreateFromFile, const char);
}
// ScriptDynamicSprite* (int sgslot, int width, int height)
RuntimeScriptValue Sc_DynamicSprite_CreateFromSaveGame(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromSaveGame(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT3(ScriptDynamicSprite, DynamicSprite_CreateFromSaveGame);
}
// ScriptDynamicSprite* (int width, int height)
RuntimeScriptValue Sc_DynamicSprite_CreateFromScreenShot(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_DynamicSprite_CreateFromScreenShot(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_PINT2(ScriptDynamicSprite, DynamicSprite_CreateFromScreenShot);
}
void RegisterDynamicSpriteAPI()
{
void RegisterDynamicSpriteAPI() {
ccAddExternalObjectFunction("DynamicSprite::ChangeCanvasSize^4", Sc_DynamicSprite_ChangeCanvasSize);
ccAddExternalObjectFunction("DynamicSprite::CopyTransparencyMask^1", Sc_DynamicSprite_CopyTransparencyMask);
ccAddExternalObjectFunction("DynamicSprite::Crop^4", Sc_DynamicSprite_Crop);
@ -683,26 +643,26 @@ void RegisterDynamicSpriteAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("DynamicSprite::ChangeCanvasSize^4", (void*)DynamicSprite_ChangeCanvasSize);
ccAddExternalFunctionForPlugin("DynamicSprite::CopyTransparencyMask^1", (void*)DynamicSprite_CopyTransparencyMask);
ccAddExternalFunctionForPlugin("DynamicSprite::Crop^4", (void*)DynamicSprite_Crop);
ccAddExternalFunctionForPlugin("DynamicSprite::Delete", (void*)DynamicSprite_Delete);
ccAddExternalFunctionForPlugin("DynamicSprite::Flip^1", (void*)DynamicSprite_Flip);
ccAddExternalFunctionForPlugin("DynamicSprite::GetDrawingSurface^0", (void*)DynamicSprite_GetDrawingSurface);
ccAddExternalFunctionForPlugin("DynamicSprite::Resize^2", (void*)DynamicSprite_Resize);
ccAddExternalFunctionForPlugin("DynamicSprite::Rotate^3", (void*)DynamicSprite_Rotate);
ccAddExternalFunctionForPlugin("DynamicSprite::SaveToFile^1", (void*)DynamicSprite_SaveToFile);
ccAddExternalFunctionForPlugin("DynamicSprite::Tint^5", (void*)DynamicSprite_Tint);
ccAddExternalFunctionForPlugin("DynamicSprite::get_ColorDepth", (void*)DynamicSprite_GetColorDepth);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Graphic", (void*)DynamicSprite_GetGraphic);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Height", (void*)DynamicSprite_GetHeight);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Width", (void*)DynamicSprite_GetWidth);
ccAddExternalFunctionForPlugin("DynamicSprite::Create^3", (void*)DynamicSprite_Create);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromBackground", (void*)DynamicSprite_CreateFromBackground);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromDrawingSurface^5", (void*)DynamicSprite_CreateFromDrawingSurface);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^1", (void*)DynamicSprite_CreateFromExistingSprite_Old);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^2", (void*)DynamicSprite_CreateFromExistingSprite);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromFile", (void*)DynamicSprite_CreateFromFile);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromSaveGame", (void*)DynamicSprite_CreateFromSaveGame);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromScreenShot", (void*)DynamicSprite_CreateFromScreenShot);
ccAddExternalFunctionForPlugin("DynamicSprite::ChangeCanvasSize^4", (void *)DynamicSprite_ChangeCanvasSize);
ccAddExternalFunctionForPlugin("DynamicSprite::CopyTransparencyMask^1", (void *)DynamicSprite_CopyTransparencyMask);
ccAddExternalFunctionForPlugin("DynamicSprite::Crop^4", (void *)DynamicSprite_Crop);
ccAddExternalFunctionForPlugin("DynamicSprite::Delete", (void *)DynamicSprite_Delete);
ccAddExternalFunctionForPlugin("DynamicSprite::Flip^1", (void *)DynamicSprite_Flip);
ccAddExternalFunctionForPlugin("DynamicSprite::GetDrawingSurface^0", (void *)DynamicSprite_GetDrawingSurface);
ccAddExternalFunctionForPlugin("DynamicSprite::Resize^2", (void *)DynamicSprite_Resize);
ccAddExternalFunctionForPlugin("DynamicSprite::Rotate^3", (void *)DynamicSprite_Rotate);
ccAddExternalFunctionForPlugin("DynamicSprite::SaveToFile^1", (void *)DynamicSprite_SaveToFile);
ccAddExternalFunctionForPlugin("DynamicSprite::Tint^5", (void *)DynamicSprite_Tint);
ccAddExternalFunctionForPlugin("DynamicSprite::get_ColorDepth", (void *)DynamicSprite_GetColorDepth);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Graphic", (void *)DynamicSprite_GetGraphic);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Height", (void *)DynamicSprite_GetHeight);
ccAddExternalFunctionForPlugin("DynamicSprite::get_Width", (void *)DynamicSprite_GetWidth);
ccAddExternalFunctionForPlugin("DynamicSprite::Create^3", (void *)DynamicSprite_Create);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromBackground", (void *)DynamicSprite_CreateFromBackground);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromDrawingSurface^5", (void *)DynamicSprite_CreateFromDrawingSurface);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^1", (void *)DynamicSprite_CreateFromExistingSprite_Old);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^2", (void *)DynamicSprite_CreateFromExistingSprite);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromFile", (void *)DynamicSprite_CreateFromFile);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromSaveGame", (void *)DynamicSprite_CreateFromSaveGame);
ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromScreenShot", (void *)DynamicSprite_CreateFromScreenShot);
}

View file

@ -27,7 +27,7 @@
#include "ac/dynobj/scriptdrawingsurface.h"
void DynamicSprite_Delete(ScriptDynamicSprite *sds);
ScriptDrawingSurface* DynamicSprite_GetDrawingSurface(ScriptDynamicSprite *dss);
ScriptDrawingSurface *DynamicSprite_GetDrawingSurface(ScriptDynamicSprite *dss);
int DynamicSprite_GetGraphic(ScriptDynamicSprite *sds);
int DynamicSprite_GetWidth(ScriptDynamicSprite *sds);
int DynamicSprite_GetHeight(ScriptDynamicSprite *sds);
@ -39,18 +39,18 @@ void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int hei
void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int height);
void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int height);
void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance);
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm);
ScriptDynamicSprite* DynamicSprite_CreateFromSaveGame(int sgslot, int width, int height);
ScriptDynamicSprite* DynamicSprite_CreateFromFile(const char *filename);
ScriptDynamicSprite* DynamicSprite_CreateFromScreenShot(int width, int height);
ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite(int slot, int preserveAlphaChannel);
ScriptDynamicSprite* DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height);
ScriptDynamicSprite* DynamicSprite_Create(int width, int height, int alphaChannel);
ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite_Old(int slot);
ScriptDynamicSprite* DynamicSprite_CreateFromBackground(int frame, int x1, int y1, int width, int height);
int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char *namm);
ScriptDynamicSprite *DynamicSprite_CreateFromSaveGame(int sgslot, int width, int height);
ScriptDynamicSprite *DynamicSprite_CreateFromFile(const char *filename);
ScriptDynamicSprite *DynamicSprite_CreateFromScreenShot(int width, int height);
ScriptDynamicSprite *DynamicSprite_CreateFromExistingSprite(int slot, int preserveAlphaChannel);
ScriptDynamicSprite *DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height);
ScriptDynamicSprite *DynamicSprite_Create(int width, int height, int alphaChannel);
ScriptDynamicSprite *DynamicSprite_CreateFromExistingSprite_Old(int slot);
ScriptDynamicSprite *DynamicSprite_CreateFromBackground(int frame, int x1, int y1, int width, int height);
void add_dynamic_sprite(int gotSlot, Common::Bitmap *redin, bool hasAlpha = false);
void free_dynamic_sprite (int gotSlot);
void free_dynamic_sprite(int gotSlot);
#endif

View file

@ -42,14 +42,14 @@ void AGSCCDynamicObject::StartSerialize(char *sbuffer) {
void AGSCCDynamicObject::SerializeInt(int val) {
char *chptr = &serbuffer[bytesSoFar];
int *iptr = (int*)chptr;
int *iptr = (int *)chptr;
*iptr = BBOp::Int32FromLE(val);
bytesSoFar += 4;
}
void AGSCCDynamicObject::SerializeFloat(float val) {
char *chptr = &serbuffer[bytesSoFar];
float *fptr = (float*)chptr;
float *fptr = (float *)chptr;
*fptr = BBOp::FloatFromLE(val);
bytesSoFar += 4;
}
@ -61,7 +61,7 @@ int AGSCCDynamicObject::EndSerialize() {
void AGSCCDynamicObject::StartUnserialize(const char *sbuffer, int pTotalBytes) {
bytesSoFar = 0;
totalBytes = pTotalBytes;
serbuffer = (char*)sbuffer;
serbuffer = (char *)sbuffer;
}
int AGSCCDynamicObject::UnserializeInt() {
@ -70,7 +70,7 @@ int AGSCCDynamicObject::UnserializeInt() {
char *chptr = &serbuffer[bytesSoFar];
bytesSoFar += 4;
return BBOp::Int32FromLE(*((int*)chptr));
return BBOp::Int32FromLE(*((int *)chptr));
}
float AGSCCDynamicObject::UnserializeFloat() {
@ -79,60 +79,49 @@ float AGSCCDynamicObject::UnserializeFloat() {
char *chptr = &serbuffer[bytesSoFar];
bytesSoFar += 4;
return BBOp::FloatFromLE(*((float*)chptr));
return BBOp::FloatFromLE(*((float *)chptr));
}
const char* AGSCCDynamicObject::GetFieldPtr(const char *address, intptr_t offset)
{
const char *AGSCCDynamicObject::GetFieldPtr(const char *address, intptr_t offset) {
return address + offset;
}
void AGSCCDynamicObject::Read(const char *address, intptr_t offset, void *dest, int size)
{
void AGSCCDynamicObject::Read(const char *address, intptr_t offset, void *dest, int size) {
memcpy(dest, address + offset, size);
}
uint8_t AGSCCDynamicObject::ReadInt8(const char *address, intptr_t offset)
{
return *(uint8_t*)(address + offset);
uint8_t AGSCCDynamicObject::ReadInt8(const char *address, intptr_t offset) {
return *(uint8_t *)(address + offset);
}
int16_t AGSCCDynamicObject::ReadInt16(const char *address, intptr_t offset)
{
return *(int16_t*)(address + offset);
int16_t AGSCCDynamicObject::ReadInt16(const char *address, intptr_t offset) {
return *(int16_t *)(address + offset);
}
int32_t AGSCCDynamicObject::ReadInt32(const char *address, intptr_t offset)
{
return *(int32_t*)(address + offset);
int32_t AGSCCDynamicObject::ReadInt32(const char *address, intptr_t offset) {
return *(int32_t *)(address + offset);
}
float AGSCCDynamicObject::ReadFloat(const char *address, intptr_t offset)
{
return *(float*)(address + offset);
float AGSCCDynamicObject::ReadFloat(const char *address, intptr_t offset) {
return *(float *)(address + offset);
}
void AGSCCDynamicObject::Write(const char *address, intptr_t offset, void *src, int size)
{
memcpy((void*)(address + offset), src, size);
void AGSCCDynamicObject::Write(const char *address, intptr_t offset, void *src, int size) {
memcpy((void *)(address + offset), src, size);
}
void AGSCCDynamicObject::WriteInt8(const char *address, intptr_t offset, uint8_t val)
{
*(uint8_t*)(address + offset) = val;
void AGSCCDynamicObject::WriteInt8(const char *address, intptr_t offset, uint8_t val) {
*(uint8_t *)(address + offset) = val;
}
void AGSCCDynamicObject::WriteInt16(const char *address, intptr_t offset, int16_t val)
{
*(int16_t*)(address + offset) = val;
void AGSCCDynamicObject::WriteInt16(const char *address, intptr_t offset, int16_t val) {
*(int16_t *)(address + offset) = val;
}
void AGSCCDynamicObject::WriteInt32(const char *address, intptr_t offset, int32_t val)
{
*(int32_t*)(address + offset) = val;
void AGSCCDynamicObject::WriteInt32(const char *address, intptr_t offset, int32_t val) {
*(int32_t *)(address + offset) = val;
}
void AGSCCDynamicObject::WriteFloat(const char *address, intptr_t offset, float val)
{
*(float*)(address + offset) = val;
void AGSCCDynamicObject::WriteFloat(const char *address, intptr_t offset, float val) {
*(float *)(address + offset) = val;
}

View file

@ -36,7 +36,7 @@ public:
virtual void Unserialize(int index, const char *serializedData, int dataSize) = 0;
// Legacy support for reading and writing object values by their relative offset
const char* GetFieldPtr(const char *address, intptr_t offset) override;
const char *GetFieldPtr(const char *address, intptr_t offset) override;
void Read(const char *address, intptr_t offset, void *dest, int size) override;
uint8_t ReadInt8(const char *address, intptr_t offset) override;
int16_t ReadInt16(const char *address, intptr_t offset) override;

View file

@ -31,7 +31,7 @@ const char *CCAudioChannel::GetType() {
}
int CCAudioChannel::Serialize(const char *address, char *buffer, int bufsize) {
ScriptAudioChannel *ach = (ScriptAudioChannel*)address;
ScriptAudioChannel *ach = (ScriptAudioChannel *)address;
StartSerialize(buffer);
SerializeInt(ach->id);
return EndSerialize();

View file

@ -31,7 +31,7 @@ const char *CCAudioClip::GetType() {
}
int CCAudioClip::Serialize(const char *address, char *buffer, int bufsize) {
ScriptAudioClip *ach = (ScriptAudioClip*)address;
ScriptAudioClip *ach = (ScriptAudioClip *)address;
StartSerialize(buffer);
SerializeInt(ach->id);
return EndSerialize();

View file

@ -36,7 +36,7 @@ const char *CCCharacter::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCCharacter::Serialize(const char *address, char *buffer, int bufsize) {
CharacterInfo *chaa = (CharacterInfo*)address;
CharacterInfo *chaa = (CharacterInfo *)address;
StartSerialize(buffer);
SerializeInt(chaa->index_id);
return EndSerialize();
@ -48,18 +48,15 @@ void CCCharacter::Unserialize(int index, const char *serializedData, int dataSiz
ccRegisterUnserializedObject(index, &game.chars[num], this);
}
void CCCharacter::WriteInt16(const char *address, intptr_t offset, int16_t val)
{
*(int16_t*)(address + offset) = val;
void CCCharacter::WriteInt16(const char *address, intptr_t offset, int16_t val) {
*(int16_t *)(address + offset) = val;
// Detect when a game directly modifies the inventory, which causes the displayed
// and actual inventory to diverge since 2.70. Force an update of the displayed
// inventory for older games that reply on the previous behaviour.
if (loaded_game_file_version < kGameVersion_270)
{
if (loaded_game_file_version < kGameVersion_270) {
const int invoffset = 112;
if (offset >= invoffset && offset < (invoffset + MAX_INV * sizeof(short)))
{
if (offset >= invoffset && offset < (invoffset + MAX_INV * sizeof(short))) {
update_invorder();
}
}

View file

@ -33,7 +33,7 @@ const char *CCDialog::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCDialog::Serialize(const char *address, char *buffer, int bufsize) {
ScriptDialog *shh = (ScriptDialog*)address;
ScriptDialog *shh = (ScriptDialog *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -34,16 +34,12 @@ int CCDynamicArray::Dispose(const char *address, bool force) {
// If it's an array of managed objects, release their ref counts;
// except if this array is forcefully removed from the managed pool,
// in which case just ignore these.
if (!force)
{
int *elementCount = (int*)address;
if (elementCount[0] & ARRAY_MANAGED_TYPE_FLAG)
{
if (!force) {
int *elementCount = (int *)address;
if (elementCount[0] & ARRAY_MANAGED_TYPE_FLAG) {
elementCount[0] &= ~ARRAY_MANAGED_TYPE_FLAG;
for (int i = 0; i < elementCount[0]; i++)
{
if (elementCount[2 + i] != 0)
{
for (int i = 0; i < elementCount[0]; i++) {
if (elementCount[2 + i] != 0) {
ccReleaseObjectReference(elementCount[2 + i]);
}
}
@ -57,10 +53,9 @@ int CCDynamicArray::Dispose(const char *address, bool force) {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCDynamicArray::Serialize(const char *address, char *buffer, int bufsize) {
int *sizeInBytes = &((int*)address)[-1];
int *sizeInBytes = &((int *)address)[-1];
int sizeToWrite = *sizeInBytes + 8;
if (sizeToWrite > bufsize)
{
if (sizeToWrite > bufsize) {
// buffer not big enough, ask for a bigger one
return -sizeToWrite;
}
@ -74,19 +69,17 @@ void CCDynamicArray::Unserialize(int index, const char *serializedData, int data
ccRegisterUnserializedObject(index, &newArray[8], this);
}
DynObjectRef CCDynamicArray::Create(int numElements, int elementSize, bool isManagedType)
{
DynObjectRef CCDynamicArray::Create(int numElements, int elementSize, bool isManagedType) {
char *newArray = new char[numElements * elementSize + 8];
memset(newArray, 0, numElements * elementSize + 8);
int *sizePtr = (int*)newArray;
int *sizePtr = (int *)newArray;
sizePtr[0] = numElements;
sizePtr[1] = numElements * elementSize;
if (isManagedType)
sizePtr[0] |= ARRAY_MANAGED_TYPE_FLAG;
void *obj_ptr = &newArray[8];
int32_t handle = ccRegisterManagedObject(obj_ptr, this);
if (handle == 0)
{
if (handle == 0) {
delete[] newArray;
return DynObjectRef(0, nullptr);
}
@ -94,74 +87,61 @@ DynObjectRef CCDynamicArray::Create(int numElements, int elementSize, bool isMan
}
const char* CCDynamicArray::GetFieldPtr(const char *address, intptr_t offset)
{
const char *CCDynamicArray::GetFieldPtr(const char *address, intptr_t offset) {
return address + offset;
}
void CCDynamicArray::Read(const char *address, intptr_t offset, void *dest, int size)
{
void CCDynamicArray::Read(const char *address, intptr_t offset, void *dest, int size) {
memcpy(dest, address + offset, size);
}
uint8_t CCDynamicArray::ReadInt8(const char *address, intptr_t offset)
{
return *(uint8_t*)(address + offset);
uint8_t CCDynamicArray::ReadInt8(const char *address, intptr_t offset) {
return *(uint8_t *)(address + offset);
}
int16_t CCDynamicArray::ReadInt16(const char *address, intptr_t offset)
{
return *(int16_t*)(address + offset);
int16_t CCDynamicArray::ReadInt16(const char *address, intptr_t offset) {
return *(int16_t *)(address + offset);
}
int32_t CCDynamicArray::ReadInt32(const char *address, intptr_t offset)
{
return *(int32_t*)(address + offset);
int32_t CCDynamicArray::ReadInt32(const char *address, intptr_t offset) {
return *(int32_t *)(address + offset);
}
float CCDynamicArray::ReadFloat(const char *address, intptr_t offset)
{
return *(float*)(address + offset);
float CCDynamicArray::ReadFloat(const char *address, intptr_t offset) {
return *(float *)(address + offset);
}
void CCDynamicArray::Write(const char *address, intptr_t offset, void *src, int size)
{
memcpy((void*)(address + offset), src, size);
void CCDynamicArray::Write(const char *address, intptr_t offset, void *src, int size) {
memcpy((void *)(address + offset), src, size);
}
void CCDynamicArray::WriteInt8(const char *address, intptr_t offset, uint8_t val)
{
*(uint8_t*)(address + offset) = val;
void CCDynamicArray::WriteInt8(const char *address, intptr_t offset, uint8_t val) {
*(uint8_t *)(address + offset) = val;
}
void CCDynamicArray::WriteInt16(const char *address, intptr_t offset, int16_t val)
{
*(int16_t*)(address + offset) = val;
void CCDynamicArray::WriteInt16(const char *address, intptr_t offset, int16_t val) {
*(int16_t *)(address + offset) = val;
}
void CCDynamicArray::WriteInt32(const char *address, intptr_t offset, int32_t val)
{
*(int32_t*)(address + offset) = val;
void CCDynamicArray::WriteInt32(const char *address, intptr_t offset, int32_t val) {
*(int32_t *)(address + offset) = val;
}
void CCDynamicArray::WriteFloat(const char *address, intptr_t offset, float val)
{
*(float*)(address + offset) = val;
void CCDynamicArray::WriteFloat(const char *address, intptr_t offset, float val) {
*(float *)(address + offset) = val;
}
CCDynamicArray globalDynamicArray;
DynObjectRef DynamicArrayHelpers::CreateStringArray(const std::vector<const char*> items)
{
DynObjectRef DynamicArrayHelpers::CreateStringArray(const std::vector<const char *> items) {
// NOTE: we need element size of "handle" for array of managed pointers
DynObjectRef arr = globalDynamicArray.Create(items.size(), sizeof(int32_t), true);
if (!arr.second)
return arr;
// Create script strings and put handles into array
int32_t *slots = static_cast<int32_t*>(arr.second);
for (auto s : items)
{
int32_t *slots = static_cast<int32_t *>(arr.second);
for (auto s : items) {
DynObjectRef str = stringClassImpl->CreateString(s);
*(slots++) = str.first;
}

View file

@ -29,8 +29,7 @@
#define CC_DYNAMIC_ARRAY_TYPE_NAME "CCDynamicArray"
#define ARRAY_MANAGED_TYPE_FLAG 0x80000000
struct CCDynamicArray final : ICCDynamicObject
{
struct CCDynamicArray final : ICCDynamicObject {
// return the type name of the object
const char *GetType() override;
int Dispose(const char *address, bool force) override;
@ -42,7 +41,7 @@ struct CCDynamicArray final : ICCDynamicObject
DynObjectRef Create(int numElements, int elementSize, bool isManagedType);
// Legacy support for reading and writing object values by their relative offset
const char* GetFieldPtr(const char *address, intptr_t offset) override;
const char *GetFieldPtr(const char *address, intptr_t offset) override;
void Read(const char *address, intptr_t offset, void *dest, int size) override;
uint8_t ReadInt8(const char *address, intptr_t offset) override;
int16_t ReadInt16(const char *address, intptr_t offset) override;
@ -58,10 +57,9 @@ struct CCDynamicArray final : ICCDynamicObject
extern CCDynamicArray globalDynamicArray;
// Helper functions for setting up dynamic arrays.
namespace DynamicArrayHelpers
{
// Create array of managed strings
DynObjectRef CreateStringArray(const std::vector<const char*>);
namespace DynamicArrayHelpers {
// Create array of managed strings
DynObjectRef CreateStringArray(const std::vector<const char *>);
};
#endif

View file

@ -57,7 +57,7 @@ void ccSetStringClassImpl(ICCStringClass *theClass) {
// register a memory handle for the object and allow script
// pointers to point to it
int32_t ccRegisterManagedObject(const void *object, ICCDynamicObject *callback, bool plugin_object) {
int32_t handl = pool.AddObject((const char*)object, callback, plugin_object);
int32_t handl = pool.AddObject((const char *)object, callback, plugin_object);
ManagedObjectLog("Register managed object type '%s' handle=%d addr=%08X",
((callback == NULL) ? "(unknown)" : callback->GetType()), handl, object);
@ -67,12 +67,12 @@ int32_t ccRegisterManagedObject(const void *object, ICCDynamicObject *callback,
// register a de-serialized object
int32_t ccRegisterUnserializedObject(int index, const void *object, ICCDynamicObject *callback, bool plugin_object) {
return pool.AddUnserializedObject((const char*)object, callback, plugin_object, index);
return pool.AddUnserializedObject((const char *)object, callback, plugin_object, index);
}
// unregister a particular object
int ccUnRegisterManagedObject(const void *object) {
return pool.RemoveObject((const char*)object);
return pool.RemoveObject((const char *)object);
}
// remove all registered objects
@ -127,8 +127,7 @@ const char *ccGetObjectAddressFromHandle(int32_t handle) {
return addr;
}
ScriptValueType ccGetObjectAddressAndManagerFromHandle(int32_t handle, void *&object, ICCDynamicObject *&manager)
{
ScriptValueType ccGetObjectAddressAndManagerFromHandle(int32_t handle, void *&object, ICCDynamicObject *&manager) {
if (handle == 0) {
object = nullptr;
manager = nullptr;

View file

@ -33,11 +33,15 @@
#include "core/types.h"
// Forward declaration
namespace AGS { namespace Common { class Stream; } }
namespace AGS {
namespace Common {
class Stream;
}
}
using namespace AGS; // FIXME later
// A pair of managed handle and abstract object pointer
typedef std::pair<int32_t, void*> DynObjectRef;
typedef std::pair<int32_t, void *> DynObjectRef;
// OBJECT-BASED SCRIPTING RUNTIME FUNCTIONS
@ -71,7 +75,7 @@ struct ICCDynamicObject {
// necessary, because byte-code does not contain any distinct operation for this case.
// The worst thing here is that with the current byte-code structure we can never tell whether
// offset 0 means getting pointer to whole object or a pointer to its first field.
virtual const char* GetFieldPtr(const char *address, intptr_t offset) = 0;
virtual const char *GetFieldPtr(const char *address, intptr_t offset) = 0;
virtual void Read(const char *address, intptr_t offset, void *dest, int size) = 0;
virtual uint8_t ReadInt8(const char *address, intptr_t offset) = 0;
virtual int16_t ReadInt16(const char *address, intptr_t offset) = 0;

View file

@ -33,7 +33,7 @@ const char *CCGUI::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCGUI::Serialize(const char *address, char *buffer, int bufsize) {
ScriptGUI *shh = (ScriptGUI*)address;
ScriptGUI *shh = (ScriptGUI *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -35,7 +35,7 @@ const char *CCGUIObject::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCGUIObject::Serialize(const char *address, char *buffer, int bufsize) {
GUIObject *guio = (GUIObject*)address;
GUIObject *guio = (GUIObject *)address;
StartSerialize(buffer);
SerializeInt(guio->ParentId);
SerializeInt(guio->Id);

View file

@ -35,7 +35,7 @@ const char *CCHotspot::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCHotspot::Serialize(const char *address, char *buffer, int bufsize) {
ScriptHotspot *shh = (ScriptHotspot*)address;
ScriptHotspot *shh = (ScriptHotspot *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -34,7 +34,7 @@ const char *CCInventory::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCInventory::Serialize(const char *address, char *buffer, int bufsize) {
ScriptInvItem *shh = (ScriptInvItem*)address;
ScriptInvItem *shh = (ScriptInvItem *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -35,7 +35,7 @@ const char *CCObject::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCObject::Serialize(const char *address, char *buffer, int bufsize) {
ScriptObject *shh = (ScriptObject*)address;
ScriptObject *shh = (ScriptObject *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -35,7 +35,7 @@ const char *CCRegion::GetType() {
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCRegion::Serialize(const char *address, char *buffer, int bufsize) {
ScriptRegion *shh = (ScriptRegion*)address;
ScriptRegion *shh = (ScriptRegion *)address;
StartSerialize(buffer);
SerializeInt(shh->id);
return EndSerialize();

View file

@ -42,7 +42,7 @@ extern CCInventory ccDynamicInv;
extern CCGUI ccDynamicGUI;
extern CCObject ccDynamicObject;
extern CCDialog ccDynamicDialog;
extern ScriptDrawingSurface* dialogOptionsRenderingSurface;
extern ScriptDrawingSurface *dialogOptionsRenderingSurface;
extern ScriptDialogOptionsRendering ccDialogOptionsRendering;
extern PluginObjectReader pluginReaders[MAX_PLUGIN_OBJECT_READERS];
extern int numPluginReaders;
@ -54,89 +54,61 @@ extern int numPluginReaders;
void AGSDeSerializer::Unserialize(int index, const char *objectType, const char *serializedData, int dataSize) {
if (strcmp(objectType, "GUIObject") == 0) {
ccDynamicGUIObject.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Character") == 0) {
} else if (strcmp(objectType, "Character") == 0) {
ccDynamicCharacter.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Hotspot") == 0) {
} else if (strcmp(objectType, "Hotspot") == 0) {
ccDynamicHotspot.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Region") == 0) {
} else if (strcmp(objectType, "Region") == 0) {
ccDynamicRegion.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Inventory") == 0) {
} else if (strcmp(objectType, "Inventory") == 0) {
ccDynamicInv.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Dialog") == 0) {
} else if (strcmp(objectType, "Dialog") == 0) {
ccDynamicDialog.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "GUI") == 0) {
} else if (strcmp(objectType, "GUI") == 0) {
ccDynamicGUI.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Object") == 0) {
} else if (strcmp(objectType, "Object") == 0) {
ccDynamicObject.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "String") == 0) {
} else if (strcmp(objectType, "String") == 0) {
ScriptString *scf = new ScriptString();
scf->Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "File") == 0) {
} else if (strcmp(objectType, "File") == 0) {
// files cannot be restored properly -- so just recreate
// the object; attempting any operations on it will fail
sc_File *scf = new sc_File();
ccRegisterUnserializedObject(index, scf, scf);
}
else if (strcmp(objectType, "Overlay") == 0) {
} else if (strcmp(objectType, "Overlay") == 0) {
ScriptOverlay *scf = new ScriptOverlay();
scf->Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "DateTime") == 0) {
} else if (strcmp(objectType, "DateTime") == 0) {
ScriptDateTime *scf = new ScriptDateTime();
scf->Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "ViewFrame") == 0) {
} else if (strcmp(objectType, "ViewFrame") == 0) {
ScriptViewFrame *scf = new ScriptViewFrame();
scf->Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "DynamicSprite") == 0) {
} else if (strcmp(objectType, "DynamicSprite") == 0) {
ScriptDynamicSprite *scf = new ScriptDynamicSprite();
scf->Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "DrawingSurface") == 0) {
} else if (strcmp(objectType, "DrawingSurface") == 0) {
ScriptDrawingSurface *sds = new ScriptDrawingSurface();
sds->Unserialize(index, serializedData, dataSize);
if (sds->isLinkedBitmapOnly)
{
if (sds->isLinkedBitmapOnly) {
dialogOptionsRenderingSurface = sds;
}
}
else if (strcmp(objectType, "DialogOptionsRendering") == 0)
{
} else if (strcmp(objectType, "DialogOptionsRendering") == 0) {
ccDialogOptionsRendering.Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "StringDictionary") == 0)
{
} else if (strcmp(objectType, "StringDictionary") == 0) {
Dict_Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "StringSet") == 0)
{
} else if (strcmp(objectType, "StringSet") == 0) {
Set_Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Viewport2") == 0)
{
} else if (strcmp(objectType, "Viewport2") == 0) {
Viewport_Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "Camera2") == 0)
{
} else if (strcmp(objectType, "Camera2") == 0) {
Camera_Unserialize(index, serializedData, dataSize);
}
else if (strcmp(objectType, "UserObject") == 0) {
} else if (strcmp(objectType, "UserObject") == 0) {
ScriptUserObject *suo = new ScriptUserObject();
suo->Unserialize(index, serializedData, dataSize);
}
else if (!unserialize_audio_script_object(index, objectType, serializedData, dataSize))
{
} else if (!unserialize_audio_script_object(index, objectType, serializedData, dataSize)) {
// check if the type is read by a plugin
for (int ii = 0; ii < numPluginReaders; ii++) {
if (strcmp(objectType, pluginReaders[ii].type) == 0) {

View file

@ -38,10 +38,14 @@ const auto GARBAGE_COLLECTION_INTERVAL = 1024;
const auto RESERVED_SIZE = 2048;
int ManagedObjectPool::Remove(ManagedObject &o, bool force) {
if (!o.isUsed()) { return 1; } // already removed
if (!o.isUsed()) {
return 1; // already removed
}
bool canBeRemovedFromPool = o.callback->Dispose(o.addr, force) != 0;
if (!(canBeRemovedFromPool || force)) { return 0; }
if (!(canBeRemovedFromPool || force)) {
return 0;
}
auto handle = o.handle;
available_ids.push(o.handle);
@ -55,9 +59,13 @@ int ManagedObjectPool::Remove(ManagedObject &o, bool force) {
}
int32_t ManagedObjectPool::AddRef(int32_t handle) {
if (handle < 0 || (size_t)handle >= objects.size()) { return 0; }
auto & o = objects[handle];
if (!o.isUsed()) { return 0; }
if (handle < 0 || (size_t)handle >= objects.size()) {
return 0;
}
auto &o = objects[handle];
if (!o.isUsed()) {
return 0;
}
o.refCount += 1;
ManagedObjectLog("Line %d AddRef: handle=%d new refcount=%d", currentline, o.handle, o.refCount);
@ -65,17 +73,27 @@ int32_t ManagedObjectPool::AddRef(int32_t handle) {
}
int ManagedObjectPool::CheckDispose(int32_t handle) {
if (handle < 0 || (size_t)handle >= objects.size()) { return 1; }
auto & o = objects[handle];
if (!o.isUsed()) { return 1; }
if (o.refCount >= 1) { return 0; }
if (handle < 0 || (size_t)handle >= objects.size()) {
return 1;
}
auto &o = objects[handle];
if (!o.isUsed()) {
return 1;
}
if (o.refCount >= 1) {
return 0;
}
return Remove(o);
}
int32_t ManagedObjectPool::SubRef(int32_t handle) {
if (handle < 0 || (size_t)handle >= objects.size()) { return 0; }
auto & o = objects[handle];
if (!o.isUsed()) { return 0; }
if (handle < 0 || (size_t)handle >= objects.size()) {
return 0;
}
auto &o = objects[handle];
if (!o.isUsed()) {
return 0;
}
o.refCount--;
auto newRefCount = o.refCount;
@ -89,25 +107,37 @@ int32_t ManagedObjectPool::SubRef(int32_t handle) {
}
int32_t ManagedObjectPool::AddressToHandle(const char *addr) {
if (addr == nullptr) { return 0; }
if (addr == nullptr) {
return 0;
}
auto it = handleByAddress.find(addr);
if (it == handleByAddress.end()) { return 0; }
if (it == handleByAddress.end()) {
return 0;
}
return it->second;
}
// this function is called often (whenever a pointer is used)
const char* ManagedObjectPool::HandleToAddress(int32_t handle) {
if (handle < 0 || (size_t)handle >= objects.size()) { return nullptr; }
auto & o = objects[handle];
if (!o.isUsed()) { return nullptr; }
const char *ManagedObjectPool::HandleToAddress(int32_t handle) {
if (handle < 0 || (size_t)handle >= objects.size()) {
return nullptr;
}
auto &o = objects[handle];
if (!o.isUsed()) {
return nullptr;
}
return o.addr;
}
// this function is called often (whenever a pointer is used)
ScriptValueType ManagedObjectPool::HandleToAddressAndManager(int32_t handle, void *&object, ICCDynamicObject *&manager) {
if (handle < 0 || (size_t)handle >= objects.size()) { return kScValUndefined; }
auto & o = objects[handle];
if (!o.isUsed()) { return kScValUndefined; }
if (handle < 0 || (size_t)handle >= objects.size()) {
return kScValUndefined;
}
auto &o = objects[handle];
if (!o.isUsed()) {
return kScValUndefined;
}
object = (void *)o.addr; // WARNING: This strips the const from the char* pointer.
manager = o.callback;
@ -115,26 +145,32 @@ ScriptValueType ManagedObjectPool::HandleToAddressAndManager(int32_t handle, voi
}
int ManagedObjectPool::RemoveObject(const char *address) {
if (address == nullptr) { return 0; }
if (address == nullptr) {
return 0;
}
auto it = handleByAddress.find(address);
if (it == handleByAddress.end()) { return 0; }
if (it == handleByAddress.end()) {
return 0;
}
auto & o = objects[it->second];
auto &o = objects[it->second];
return Remove(o, true);
}
void ManagedObjectPool::RunGarbageCollectionIfAppropriate()
{
if (objectCreationCounter <= GARBAGE_COLLECTION_INTERVAL) { return; }
void ManagedObjectPool::RunGarbageCollectionIfAppropriate() {
if (objectCreationCounter <= GARBAGE_COLLECTION_INTERVAL) {
return;
}
RunGarbageCollection();
objectCreationCounter = 0;
}
void ManagedObjectPool::RunGarbageCollection()
{
void ManagedObjectPool::RunGarbageCollection() {
for (int i = 1; i < nextHandle; i++) {
auto & o = objects[i];
if (!o.isUsed()) { continue; }
auto &o = objects[i];
if (!o.isUsed()) {
continue;
}
if (o.refCount < 1) {
Remove(o);
}
@ -142,8 +178,7 @@ void ManagedObjectPool::RunGarbageCollection()
ManagedObjectLog("Ran garbage collection");
}
int ManagedObjectPool::AddObject(const char *address, ICCDynamicObject *callback, bool plugin_object)
{
int ManagedObjectPool::AddObject(const char *address, ICCDynamicObject *callback, bool plugin_object) {
int32_t handle;
if (!available_ids.empty()) {
@ -156,8 +191,11 @@ int ManagedObjectPool::AddObject(const char *address, ICCDynamicObject *callback
}
}
auto & o = objects[handle];
if (o.isUsed()) { cc_error("used: %d", handle); return 0; }
auto &o = objects[handle];
if (o.isUsed()) {
cc_error("used: %d", handle);
return 0;
}
o = ManagedObject(plugin_object ? kScValPluginObject : kScValDynamicObject, handle, address, callback);
@ -168,15 +206,20 @@ int ManagedObjectPool::AddObject(const char *address, ICCDynamicObject *callback
}
int ManagedObjectPool::AddUnserializedObject(const char *address, ICCDynamicObject *callback, bool plugin_object, int handle)
{
if (handle < 0) { cc_error("Attempt to assign invalid handle: %d", handle); return 0; }
int ManagedObjectPool::AddUnserializedObject(const char *address, ICCDynamicObject *callback, bool plugin_object, int handle) {
if (handle < 0) {
cc_error("Attempt to assign invalid handle: %d", handle);
return 0;
}
if ((size_t)handle >= objects.size()) {
objects.resize(handle + 1024, ManagedObject());
}
auto & o = objects[handle];
if (o.isUsed()) { cc_error("bad save. used: %d", o.handle); return 0; }
auto &o = objects[handle];
if (o.isUsed()) {
cc_error("bad save. used: %d", o.handle);
return 0;
}
o = ManagedObject(plugin_object ? kScValPluginObject : kScValDynamicObject, handle, address, callback);
@ -198,7 +241,7 @@ void ManagedObjectPool::WriteToDisk(Stream *out) {
int size = 0;
for (int i = 1; i < nextHandle; i++) {
auto const & o = objects[i];
auto const &o = objects[i];
if (o.isUsed()) {
size += 1;
}
@ -206,17 +249,18 @@ void ManagedObjectPool::WriteToDisk(Stream *out) {
out->WriteInt32(size);
for (int i = 1; i < nextHandle; i++) {
auto const & o = objects[i];
if (!o.isUsed()) { continue; }
auto const &o = objects[i];
if (!o.isUsed()) {
continue;
}
// handle
out->WriteInt32(o.handle);
// write the type of the object
StrUtil::WriteCStr((char*)o.callback->GetType(), out);
StrUtil::WriteCStr((char *)o.callback->GetType(), out);
// now write the object data
int bytesWritten = o.callback->Serialize(o.addr, &serializeBuffer.front(), serializeBuffer.size());
if ((bytesWritten < 0) && ((size_t)(-bytesWritten) > serializeBuffer.size()))
{
if ((bytesWritten < 0) && ((size_t)(-bytesWritten) > serializeBuffer.size())) {
// buffer not big enough, re-allocate with requested size
serializeBuffer.resize(-bytesWritten);
bytesWritten = o.callback->Serialize(o.addr, &serializeBuffer.front(), serializeBuffer.size());
@ -243,8 +287,7 @@ int ManagedObjectPool::ReadFromDisk(Stream *in, ICCObjectReader *reader) {
auto version = in->ReadInt32();
switch (version) {
case 1:
{
case 1: {
// IMPORTANT: numObjs is "nextHandleId", which is why we iterate from 1 to numObjs-1
int numObjs = in->ReadInt32();
for (int i = 1; i < numObjs; i++) {
@ -266,15 +309,14 @@ int ManagedObjectPool::ReadFromDisk(Stream *in, ICCObjectReader *reader) {
}
}
break;
case 2:
{
case 2: {
// This is actually number of objects written.
int objectsSize = in->ReadInt32();
for (int i = 0; i < objectsSize; i++) {
auto handle = in->ReadInt32();
assert (handle >= 1);
assert(handle >= 1);
StrUtil::ReadCStr(typeNameBuffer, in, sizeof(typeNameBuffer));
assert (typeNameBuffer[0] != 0);
assert(typeNameBuffer[0] != 0);
size_t numBytes = in->ReadInt32();
if (numBytes > serializeBuffer.size()) {
serializeBuffer.resize(numBytes);
@ -296,7 +338,9 @@ int ManagedObjectPool::ReadFromDisk(Stream *in, ICCObjectReader *reader) {
}
// re-adjust next handles. (in case saved in random order)
while (!available_ids.empty()) { available_ids.pop(); }
while (!available_ids.empty()) {
available_ids.pop();
}
nextHandle = 1;
for (const auto &o : objects) {
@ -316,11 +360,15 @@ int ManagedObjectPool::ReadFromDisk(Stream *in, ICCObjectReader *reader) {
// de-allocate all objects
void ManagedObjectPool::reset() {
for (int i = 1; i < nextHandle; i++) {
auto & o = objects[i];
if (!o.isUsed()) { continue; }
auto &o = objects[i];
if (!o.isUsed()) {
continue;
}
Remove(o, true);
}
while (!available_ids.empty()) { available_ids.pop(); }
while (!available_ids.empty()) {
available_ids.pop();
}
nextHandle = 1;
}

View file

@ -30,7 +30,11 @@
#include "script/runtimescriptvalue.h"
#include "ac/dynobj/cc_dynamicobject.h" // ICCDynamicObject
namespace AGS { namespace Common { class Stream; }}
namespace AGS {
namespace Common {
class Stream;
}
}
using namespace AGS; // FIXME later
struct ManagedObjectPool final {
@ -45,11 +49,13 @@ private:
ICCDynamicObject *callback;
int refCount;
bool isUsed() const { return obj_type != kScValUndefined; }
bool isUsed() const {
return obj_type != kScValUndefined;
}
ManagedObject()
: obj_type(kScValUndefined), handle(0), addr(nullptr), callback(nullptr), refCount(0) {}
ManagedObject(ScriptValueType obj_type, int32_t handle, const char *addr, ICCDynamicObject * callback)
ManagedObject(ScriptValueType obj_type, int32_t handle, const char *addr, ICCDynamicObject *callback)
: obj_type(obj_type), handle(handle), addr(addr), callback(callback), refCount(0) {}
};
@ -71,7 +77,7 @@ public:
int CheckDispose(int32_t handle);
int32_t SubRef(int32_t handle);
int32_t AddressToHandle(const char *addr);
const char* HandleToAddress(int32_t handle);
const char *HandleToAddress(int32_t handle);
ScriptValueType HandleToAddressAndManager(int32_t handle, void *&object, ICCDynamicObject *&manager);
int RemoveObject(const char *address);
void RunGarbageCollectionIfAppropriate();
@ -82,7 +88,7 @@ public:
void reset();
ManagedObjectPool();
const char* disableDisposeForObject {nullptr};
const char *disableDisposeForObject {nullptr};
};
extern ManagedObjectPool pool;

View file

@ -23,8 +23,7 @@
#ifndef AGS_ENGINE_AC_DYNOBJ_SCRIPTAUDIOCHANNEL_H
#define AGS_ENGINE_AC_DYNOBJ_SCRIPTAUDIOCHANNEL_H
struct ScriptAudioChannel
{
struct ScriptAudioChannel {
int id;
int reserved;
};

View file

@ -28,42 +28,36 @@ using namespace AGS::Common;
ScriptCamera::ScriptCamera(int id) : _id(id) {}
const char *ScriptCamera::GetType()
{
const char *ScriptCamera::GetType() {
return "Camera2";
}
int ScriptCamera::Dispose(const char *address, bool force)
{
int ScriptCamera::Dispose(const char *address, bool force) {
// Note that ScriptCamera is a reference to actual Camera object,
// and this deletes the reference, while camera may remain in GameState.
delete this;
return 1;
}
int ScriptCamera::Serialize(const char *address, char *buffer, int bufsize)
{
int ScriptCamera::Serialize(const char *address, char *buffer, int bufsize) {
StartSerialize(buffer);
SerializeInt(_id);
return EndSerialize();
}
void ScriptCamera::Unserialize(int index, const char *serializedData, int dataSize)
{
void ScriptCamera::Unserialize(int index, const char *serializedData, int dataSize) {
StartUnserialize(serializedData, dataSize);
_id = UnserializeInt();
ccRegisterUnserializedObject(index, this, this);
}
ScriptCamera *Camera_Unserialize(int handle, const char *serializedData, int dataSize)
{
ScriptCamera *Camera_Unserialize(int handle, const char *serializedData, int dataSize) {
// The way it works now, we must not create a new script object,
// but acquire one from the GameState, which keeps the first reference.
// This is essential because GameState should be able to invalidate any
// script references when Camera gets removed.
const int id = BBOp::Int32FromLE(*((int*)serializedData));
if (id >= 0)
{
const int id = BBOp::Int32FromLE(*((int *)serializedData));
if (id >= 0) {
auto scam = play.RegisterRoomCamera(id, handle);
if (scam)
return scam;

View file

@ -26,16 +26,21 @@
#include "ac/dynobj/cc_agsdynamicobject.h"
// ScriptCamera keeps a reference to actual room Camera in script.
struct ScriptCamera final : AGSCCDynamicObject
{
struct ScriptCamera final : AGSCCDynamicObject {
public:
ScriptCamera(int id);
// Get camera index; negative means the camera was deleted
int GetID() const { return _id; }
void SetID(int id) { _id = id; }
int GetID() const {
return _id;
}
void SetID(int id) {
_id = id;
}
// Reset camera index to indicate that this reference is no longer valid
void Invalidate() { _id = -1; }
void Invalidate() {
_id = -1;
}
const char *GetType() override;
int Dispose(const char *address, bool force) override;

View file

@ -37,8 +37,7 @@ void ScriptDialogOptionsRendering::Unserialize(int index, const char *serialized
ccRegisterUnserializedObject(index, this, this);
}
void ScriptDialogOptionsRendering::Reset()
{
void ScriptDialogOptionsRendering::Reset() {
x = 0;
y = 0;
width = 0;
@ -55,7 +54,6 @@ void ScriptDialogOptionsRendering::Reset()
needRepaint = false;
}
ScriptDialogOptionsRendering::ScriptDialogOptionsRendering()
{
ScriptDialogOptionsRendering::ScriptDialogOptionsRendering() {
Reset();
}

View file

@ -22,23 +22,19 @@
#include "ac/dynobj/scriptdict.h"
int ScriptDictBase::Dispose(const char *address, bool force)
{
int ScriptDictBase::Dispose(const char *address, bool force) {
Clear();
delete this;
return 1;
}
const char *ScriptDictBase::GetType()
{
const char *ScriptDictBase::GetType() {
return "StringDictionary";
}
int ScriptDictBase::Serialize(const char *address, char *buffer, int bufsize)
{
int ScriptDictBase::Serialize(const char *address, char *buffer, int bufsize) {
size_t total_sz = CalcSerializeSize() + sizeof(int32_t) * 2;
if (bufsize < 0 || total_sz >(size_t)bufsize)
{
if (bufsize < 0 || total_sz > (size_t)bufsize) {
// buffer not big enough, ask for a bigger one
return -((int)total_sz);
}
@ -49,8 +45,7 @@ int ScriptDictBase::Serialize(const char *address, char *buffer, int bufsize)
return EndSerialize();
}
void ScriptDictBase::Unserialize(int index, const char *serializedData, int dataSize)
{
void ScriptDictBase::Unserialize(int index, const char *serializedData, int dataSize) {
// NOTE: we expect sorted/case flags are read by external reader;
// this is awkward, but I did not find better design solution atm
StartUnserialize(serializedData, dataSize);

View file

@ -45,8 +45,7 @@
using namespace AGS::Common;
class ScriptDictBase : public AGSCCDynamicObject
{
class ScriptDictBase : public AGSCCDynamicObject {
public:
int Dispose(const char *address, bool force) override;
const char *GetType() override;
@ -62,8 +61,8 @@ public:
virtual bool Remove(const char *key) = 0;
virtual bool Set(const char *key, const char *value) = 0;
virtual int GetItemCount() = 0;
virtual void GetKeys(std::vector<const char*> &buf) const = 0;
virtual void GetValues(std::vector<const char*> &buf) const = 0;
virtual void GetKeys(std::vector<const char *> &buf) const = 0;
virtual void GetValues(std::vector<const char *> &buf) const = 0;
private:
virtual size_t CalcSerializeSize() = 0;
@ -72,59 +71,59 @@ private:
};
template <typename TDict, bool is_sorted, bool is_casesensitive>
class ScriptDictImpl final : public ScriptDictBase
{
class ScriptDictImpl final : public ScriptDictBase {
public:
typedef typename TDict::const_iterator ConstIterator;
ScriptDictImpl() = default;
bool IsCaseSensitive() const override { return is_casesensitive; }
bool IsSorted() const override { return is_sorted; }
bool IsCaseSensitive() const override {
return is_casesensitive;
}
bool IsSorted() const override {
return is_sorted;
}
void Clear() override
{
void Clear() override {
for (auto it = _dic.begin(); it != _dic.end(); ++it)
DeleteItem(it);
_dic.clear();
}
bool Contains(const char *key) override { return _dic.count(String::Wrapper(key)) != 0; }
const char *Get(const char *key) override
{
bool Contains(const char *key) override {
return _dic.count(String::Wrapper(key)) != 0;
}
const char *Get(const char *key) override {
auto it = _dic.find(String::Wrapper(key));
if (it == _dic.end()) return nullptr;
return it->second.GetNullableCStr();
}
bool Remove(const char *key) override
{
bool Remove(const char *key) override {
auto it = _dic.find(String::Wrapper(key));
if (it == _dic.end()) return false;
DeleteItem(it);
_dic.erase(it);
return true;
}
bool Set(const char *key, const char *value) override
{
bool Set(const char *key, const char *value) override {
if (!key) return false;
size_t key_len = strlen(key);
size_t value_len = value ? strlen(value) : 0;
return TryAddItem(key, key_len, value, value_len);
}
int GetItemCount() override { return _dic.size(); }
void GetKeys(std::vector<const char*> &buf) const override
{
int GetItemCount() override {
return _dic.size();
}
void GetKeys(std::vector<const char *> &buf) const override {
for (auto it = _dic.begin(); it != _dic.end(); ++it)
buf.push_back(it->first.GetCStr()); // keys cannot be null
}
void GetValues(std::vector<const char*> &buf) const override
{
void GetValues(std::vector<const char *> &buf) const override {
for (auto it = _dic.begin(); it != _dic.end(); ++it)
buf.push_back(it->second.GetNullableCStr()); // values may be null
}
private:
bool TryAddItem(const char *key, size_t key_len, const char *value, size_t value_len)
{
bool TryAddItem(const char *key, size_t key_len, const char *value, size_t value_len) {
String elem_key(key, key_len);
String elem_value;
if (value)
@ -132,55 +131,47 @@ private:
_dic[elem_key] = elem_value;
return true;
}
void DeleteItem(ConstIterator it) { /* do nothing */ }
void DeleteItem(ConstIterator it) {
/* do nothing */
}
size_t CalcSerializeSize() override
{
size_t CalcSerializeSize() override {
size_t total_sz = sizeof(int32_t);
for (auto it = _dic.begin(); it != _dic.end(); ++it)
{
for (auto it = _dic.begin(); it != _dic.end(); ++it) {
total_sz += sizeof(int32_t) + it->first.GetLength();
total_sz += sizeof(int32_t) + it->second.GetLength();
}
return total_sz;
}
void SerializeContainer() override
{
void SerializeContainer() override {
SerializeInt((int)_dic.size());
for (auto it = _dic.begin(); it != _dic.end(); ++it)
{
for (auto it = _dic.begin(); it != _dic.end(); ++it) {
SerializeInt((int)it->first.GetLength());
memcpy(&serbuffer[bytesSoFar], it->first.GetCStr(), it->first.GetLength());
bytesSoFar += it->first.GetLength();
if (it->second.GetNullableCStr()) // values may be null
{
if (it->second.GetNullableCStr()) { // values may be null
SerializeInt((int)it->second.GetLength());
memcpy(&serbuffer[bytesSoFar], it->second.GetCStr(), it->second.GetLength());
bytesSoFar += it->second.GetLength();
}
else
{
} else {
SerializeInt(-1);
}
}
}
void UnserializeContainer(const char *serializedData) override
{
void UnserializeContainer(const char *serializedData) override {
size_t item_count = (size_t)UnserializeInt();
for (size_t i = 0; i < item_count; ++i)
{
for (size_t i = 0; i < item_count; ++i) {
size_t key_len = UnserializeInt();
int key_pos = bytesSoFar; bytesSoFar += key_len;
int key_pos = bytesSoFar;
bytesSoFar += key_len;
size_t value_len = UnserializeInt();
if (value_len == (size_t)-1)
{
if (value_len == (size_t) - 1) {
TryAddItem(&serializedData[key_pos], key_len, nullptr, 0);
}
else
{
int value_pos = bytesSoFar; bytesSoFar += value_len;
} else {
int value_pos = bytesSoFar;
bytesSoFar += value_len;
TryAddItem(&serializedData[key_pos], key_len, &serializedData[value_pos], value_len);
}
}

View file

@ -38,8 +38,7 @@ extern Bitmap *dynamicallyCreatedSurfaces[MAX_DYNAMIC_SURFACES];
extern GameState play;
extern GameSetupStruct game;
Bitmap* ScriptDrawingSurface::GetBitmapSurface()
{
Bitmap *ScriptDrawingSurface::GetBitmapSurface() {
// TODO: consider creating weak_ptr here, and store one in the DrawingSurface!
if (roomBackgroundNumber >= 0)
return thisroom.BgFrames[roomBackgroundNumber].Graphic.get();
@ -55,19 +54,16 @@ Bitmap* ScriptDrawingSurface::GetBitmapSurface()
return nullptr;
}
Bitmap *ScriptDrawingSurface::StartDrawing()
{
Bitmap *ScriptDrawingSurface::StartDrawing() {
//abufBackup = abuf;
return this->GetBitmapSurface();
}
void ScriptDrawingSurface::FinishedDrawingReadOnly()
{
void ScriptDrawingSurface::FinishedDrawingReadOnly() {
//abuf = abufBackup;
}
void ScriptDrawingSurface::FinishedDrawing()
{
void ScriptDrawingSurface::FinishedDrawing() {
FinishedDrawingReadOnly();
modified = 1;
}
@ -114,8 +110,7 @@ void ScriptDrawingSurface::Unserialize(int index, const char *serializedData, in
ccRegisterUnserializedObject(index, this, this);
}
ScriptDrawingSurface::ScriptDrawingSurface()
{
ScriptDrawingSurface::ScriptDrawingSurface() {
roomBackgroundNumber = -1;
roomMaskType = kRoomAreaNone;
dynamicSpriteNumber = -1;
@ -130,8 +125,7 @@ ScriptDrawingSurface::ScriptDrawingSurface()
// NOTE: Normally in contemporary games coordinates ratio will always be 1:1.
// But we still support legacy drawing, so have to set this up even for modern games,
// otherwise we'd have to complicate conversion conditions further.
if (game.IsLegacyHiRes() && game.IsDataInNativeCoordinates())
{
if (game.IsLegacyHiRes() && game.IsDataInNativeCoordinates()) {
highResCoordinates = 1;
}
}

View file

@ -26,7 +26,11 @@
#include "ac/dynobj/cc_agsdynamicobject.h"
#include "game/roomstruct.h"
namespace AGS { namespace Common { class Bitmap; }}
namespace AGS {
namespace Common {
class Bitmap;
}
}
struct ScriptDrawingSurface final : AGSCCDynamicObject {
// These numbers and types are used to determine the source of this drawing surface;
@ -48,7 +52,7 @@ struct ScriptDrawingSurface final : AGSCCDynamicObject {
const char *GetType() override;
int Serialize(const char *address, char *buffer, int bufsize) override;
void Unserialize(int index, const char *serializedData, int dataSize) override;
Common::Bitmap* GetBitmapSurface();
Common::Bitmap *GetBitmapSurface();
Common::Bitmap *StartDrawing();
void PointToGameResolution(int *xcoord, int *ycoord);
void SizeToGameResolution(int *width, int *height);

View file

@ -25,9 +25,9 @@
// CHECKME: actually NULLs here will be equal to kFile_Open & kFile_Read
const Common::FileOpenMode sc_File::fopenModes[] =
{Common::kFile_Open/*CHECKME, was undefined*/, Common::kFile_Open, Common::kFile_CreateAlways, Common::kFile_Create};
{Common::kFile_Open/*CHECKME, was undefined*/, Common::kFile_Open, Common::kFile_CreateAlways, Common::kFile_Create};
const Common::FileWorkMode sc_File::fworkModes[] =
{Common::kFile_Read/*CHECKME, was undefined*/, Common::kFile_Read, Common::kFile_Write, Common::kFile_Write};
{Common::kFile_Read/*CHECKME, was undefined*/, Common::kFile_Read, Common::kFile_Write, Common::kFile_Write};
int sc_File::Dispose(const char *address, bool force) {
Close();
@ -63,51 +63,40 @@ sc_File::sc_File() {
}
const char* sc_File::GetFieldPtr(const char *address, intptr_t offset)
{
const char *sc_File::GetFieldPtr(const char *address, intptr_t offset) {
return address;
}
void sc_File::Read(const char *address, intptr_t offset, void *dest, int size)
{
void sc_File::Read(const char *address, intptr_t offset, void *dest, int size) {
}
uint8_t sc_File::ReadInt8(const char *address, intptr_t offset)
{
uint8_t sc_File::ReadInt8(const char *address, intptr_t offset) {
return 0;
}
int16_t sc_File::ReadInt16(const char *address, intptr_t offset)
{
int16_t sc_File::ReadInt16(const char *address, intptr_t offset) {
return 0;
}
int32_t sc_File::ReadInt32(const char *address, intptr_t offset)
{
int32_t sc_File::ReadInt32(const char *address, intptr_t offset) {
return 0;
}
float sc_File::ReadFloat(const char *address, intptr_t offset)
{
float sc_File::ReadFloat(const char *address, intptr_t offset) {
return 0.0;
}
void sc_File::Write(const char *address, intptr_t offset, void *src, int size)
{
void sc_File::Write(const char *address, intptr_t offset, void *src, int size) {
}
void sc_File::WriteInt8(const char *address, intptr_t offset, uint8_t val)
{
void sc_File::WriteInt8(const char *address, intptr_t offset, uint8_t val) {
}
void sc_File::WriteInt16(const char *address, intptr_t offset, int16_t val)
{
void sc_File::WriteInt16(const char *address, intptr_t offset, int16_t val) {
}
void sc_File::WriteInt32(const char *address, intptr_t offset, int32_t val)
{
void sc_File::WriteInt32(const char *address, intptr_t offset, int32_t val) {
}
void sc_File::WriteFloat(const char *address, intptr_t offset, float val)
{
void sc_File::WriteFloat(const char *address, intptr_t offset, float val) {
}

View file

@ -50,7 +50,7 @@ struct sc_File final : ICCDynamicObject {
sc_File();
// Legacy support for reading and writing object values by their relative offset
const char* GetFieldPtr(const char *address, intptr_t offset) override;
const char *GetFieldPtr(const char *address, intptr_t offset) override;
void Read(const char *address, intptr_t offset, void *dest, int size) override;
uint8_t ReadInt8(const char *address, intptr_t offset) override;
int16_t ReadInt16(const char *address, intptr_t offset) override;

View file

@ -25,7 +25,7 @@
// The text script's "mouse" struct
struct ScriptMouse {
int x,y;
int x, y;
};
#endif

View file

@ -26,22 +26,19 @@
#include "ac/runtime_defines.h"
#include "ac/screenoverlay.h"
int ScriptOverlay::Dispose(const char *address, bool force)
{
int ScriptOverlay::Dispose(const char *address, bool force) {
// since the managed object is being deleted, remove the
// reference so it doesn't try and dispose something else
// with that handle later
int overlayIndex = find_overlay_of_type(overlayId);
if (overlayIndex >= 0)
{
if (overlayIndex >= 0) {
screenover[overlayIndex].associatedOverlayHandle = 0;
}
// if this is being removed voluntarily (ie. pointer out of
// scope) then remove the associateed overlay
// Otherwise, it's a Restre Game or something so don't
if ((!force) && (!isBackgroundSpeech) && (Overlay_GetValid(this)))
{
if ((!force) && (!isBackgroundSpeech) && (Overlay_GetValid(this))) {
Remove();
}
@ -71,11 +68,9 @@ void ScriptOverlay::Unserialize(int index, const char *serializedData, int dataS
ccRegisterUnserializedObject(index, this, this);
}
void ScriptOverlay::Remove()
{
void ScriptOverlay::Remove() {
int overlayIndex = find_overlay_of_type(overlayId);
if (overlayIndex < 0)
{
if (overlayIndex < 0) {
quit("ScriptOverlay::Remove: overlay is not there!");
}
remove_screen_overlay_index(overlayIndex);

View file

@ -22,23 +22,19 @@
#include "ac/dynobj/scriptset.h"
int ScriptSetBase::Dispose(const char *address, bool force)
{
int ScriptSetBase::Dispose(const char *address, bool force) {
Clear();
delete this;
return 1;
}
const char *ScriptSetBase::GetType()
{
const char *ScriptSetBase::GetType() {
return "StringSet";
}
int ScriptSetBase::Serialize(const char *address, char *buffer, int bufsize)
{
int ScriptSetBase::Serialize(const char *address, char *buffer, int bufsize) {
size_t total_sz = CalcSerializeSize() + sizeof(int32_t) * 2;
if (bufsize < 0 || total_sz > (size_t)bufsize)
{
if (bufsize < 0 || total_sz > (size_t)bufsize) {
// buffer not big enough, ask for a bigger one
return -((int)total_sz);
}
@ -49,8 +45,7 @@ int ScriptSetBase::Serialize(const char *address, char *buffer, int bufsize)
return EndSerialize();
}
void ScriptSetBase::Unserialize(int index, const char *serializedData, int dataSize)
{
void ScriptSetBase::Unserialize(int index, const char *serializedData, int dataSize) {
// NOTE: we expect sorted/case flags are read by external reader;
// this is awkward, but I did not find better design solution atm
StartUnserialize(serializedData, dataSize);

View file

@ -44,8 +44,7 @@
using namespace AGS::Common;
class ScriptSetBase : public AGSCCDynamicObject
{
class ScriptSetBase : public AGSCCDynamicObject {
public:
int Dispose(const char *address, bool force) override;
const char *GetType() override;
@ -60,7 +59,7 @@ public:
virtual bool Contains(const char *item) const = 0;
virtual bool Remove(const char *item) = 0;
virtual int GetItemCount() const = 0;
virtual void GetItems(std::vector<const char*> &buf) const = 0;
virtual void GetItems(std::vector<const char *> &buf) const = 0;
private:
virtual size_t CalcSerializeSize() = 0;
@ -69,75 +68,74 @@ private:
};
template <typename TSet, bool is_sorted, bool is_casesensitive>
class ScriptSetImpl final : public ScriptSetBase
{
class ScriptSetImpl final : public ScriptSetBase {
public:
typedef typename TSet::const_iterator ConstIterator;
ScriptSetImpl() = default;
bool IsCaseSensitive() const override { return is_casesensitive; }
bool IsSorted() const override { return is_sorted; }
bool IsCaseSensitive() const override {
return is_casesensitive;
}
bool IsSorted() const override {
return is_sorted;
}
bool Add(const char *item) override
{
bool Add(const char *item) override {
if (!item) return false;
size_t len = strlen(item);
return TryAddItem(item, len);
}
void Clear() override
{
void Clear() override {
for (auto it = _set.begin(); it != _set.end(); ++it)
DeleteItem(it);
_set.clear();
}
bool Contains(const char *item) const override { return _set.count(String::Wrapper(item)) != 0; }
bool Remove(const char *item) override
{
bool Contains(const char *item) const override {
return _set.count(String::Wrapper(item)) != 0;
}
bool Remove(const char *item) override {
auto it = _set.find(String::Wrapper(item));
if (it == _set.end()) return false;
DeleteItem(it);
_set.erase(it);
return true;
}
int GetItemCount() const override { return _set.size(); }
void GetItems(std::vector<const char*> &buf) const override
{
int GetItemCount() const override {
return _set.size();
}
void GetItems(std::vector<const char *> &buf) const override {
for (auto it = _set.begin(); it != _set.end(); ++it)
buf.push_back(it->GetCStr());
}
private:
bool TryAddItem(const char *item, size_t len)
{
bool TryAddItem(const char *item, size_t len) {
return _set.insert(String(item, len)).second;
}
void DeleteItem(ConstIterator it) { /* do nothing */ }
void DeleteItem(ConstIterator it) {
/* do nothing */
}
size_t CalcSerializeSize() override
{
size_t CalcSerializeSize() override {
size_t total_sz = sizeof(int32_t);
for (auto it = _set.begin(); it != _set.end(); ++it)
total_sz += sizeof(int32_t) + it->GetLength();
return total_sz;
}
void SerializeContainer() override
{
void SerializeContainer() override {
SerializeInt((int)_set.size());
for (auto it = _set.begin(); it != _set.end(); ++it)
{
for (auto it = _set.begin(); it != _set.end(); ++it) {
SerializeInt((int)it->GetLength());
memcpy(&serbuffer[bytesSoFar], it->GetCStr(), it->GetLength());
bytesSoFar += it->GetLength();
}
}
void UnserializeContainer(const char *serializedData) override
{
void UnserializeContainer(const char *serializedData) override {
size_t item_count = (size_t)UnserializeInt();
for (size_t i = 0; i < item_count; ++i)
{
for (size_t i = 0; i < item_count; ++i) {
size_t len = UnserializeInt();
TryAddItem(&serializedData[bytesSoFar], len);
bytesSoFar += len;

View file

@ -59,7 +59,7 @@ int ScriptString::Serialize(const char *address, char *buffer, int bufsize) {
void ScriptString::Unserialize(int index, const char *serializedData, int dataSize) {
StartUnserialize(serializedData, dataSize);
int textsize = UnserializeInt();
text = (char*)malloc(textsize + 1);
text = (char *)malloc(textsize + 1);
strcpy(text, &serializedData[bytesSoFar]);
ccRegisterUnserializedObject(index, text, this);
}
@ -69,6 +69,6 @@ ScriptString::ScriptString() {
}
ScriptString::ScriptString(const char *fromText) {
text = (char*)malloc(strlen(fromText) + 1);
text = (char *)malloc(strlen(fromText) + 1);
strcpy(text, fromText);
}

View file

@ -25,7 +25,7 @@
// The text script's "system" struct
struct ScriptSystem {
int width,height;
int width, height;
int coldepth;
int os;
int windowed;

View file

@ -24,38 +24,32 @@
#include "scriptuserobject.h"
// return the type name of the object
const char *ScriptUserObject::GetType()
{
const char *ScriptUserObject::GetType() {
return "UserObject";
}
ScriptUserObject::ScriptUserObject()
: _size(0)
, _data(nullptr)
{
, _data(nullptr) {
}
ScriptUserObject::~ScriptUserObject()
{
ScriptUserObject::~ScriptUserObject() {
delete [] _data;
}
/* static */ ScriptUserObject *ScriptUserObject::CreateManaged(size_t size)
{
/* static */ ScriptUserObject *ScriptUserObject::CreateManaged(size_t size) {
ScriptUserObject *suo = new ScriptUserObject();
suo->Create(nullptr, size);
ccRegisterManagedObject(suo, suo);
return suo;
}
void ScriptUserObject::Create(const char *data, size_t size)
{
void ScriptUserObject::Create(const char *data, size_t size) {
delete [] _data;
_data = nullptr;
_size = size;
if (_size > 0)
{
if (_size > 0) {
_data = new char[size];
if (data)
memcpy(_data, data, _size);
@ -64,14 +58,12 @@ void ScriptUserObject::Create(const char *data, size_t size)
}
}
int ScriptUserObject::Dispose(const char *address, bool force)
{
int ScriptUserObject::Dispose(const char *address, bool force) {
delete this;
return 1;
}
int ScriptUserObject::Serialize(const char *address, char *buffer, int bufsize)
{
int ScriptUserObject::Serialize(const char *address, char *buffer, int bufsize) {
if (_size > bufsize)
// buffer not big enough, ask for a bigger one
return -_size;
@ -80,73 +72,60 @@ int ScriptUserObject::Serialize(const char *address, char *buffer, int bufsize)
return _size;
}
void ScriptUserObject::Unserialize(int index, const char *serializedData, int dataSize)
{
void ScriptUserObject::Unserialize(int index, const char *serializedData, int dataSize) {
Create(serializedData, dataSize);
ccRegisterUnserializedObject(index, this, this);
}
const char* ScriptUserObject::GetFieldPtr(const char *address, intptr_t offset)
{
const char *ScriptUserObject::GetFieldPtr(const char *address, intptr_t offset) {
return _data + offset;
}
void ScriptUserObject::Read(const char *address, intptr_t offset, void *dest, int size)
{
void ScriptUserObject::Read(const char *address, intptr_t offset, void *dest, int size) {
memcpy(dest, _data + offset, size);
}
uint8_t ScriptUserObject::ReadInt8(const char *address, intptr_t offset)
{
return *(uint8_t*)(_data + offset);
uint8_t ScriptUserObject::ReadInt8(const char *address, intptr_t offset) {
return *(uint8_t *)(_data + offset);
}
int16_t ScriptUserObject::ReadInt16(const char *address, intptr_t offset)
{
return *(int16_t*)(_data + offset);
int16_t ScriptUserObject::ReadInt16(const char *address, intptr_t offset) {
return *(int16_t *)(_data + offset);
}
int32_t ScriptUserObject::ReadInt32(const char *address, intptr_t offset)
{
return *(int32_t*)(_data + offset);
int32_t ScriptUserObject::ReadInt32(const char *address, intptr_t offset) {
return *(int32_t *)(_data + offset);
}
float ScriptUserObject::ReadFloat(const char *address, intptr_t offset)
{
return *(float*)(_data + offset);
float ScriptUserObject::ReadFloat(const char *address, intptr_t offset) {
return *(float *)(_data + offset);
}
void ScriptUserObject::Write(const char *address, intptr_t offset, void *src, int size)
{
memcpy((void*)(_data + offset), src, size);
void ScriptUserObject::Write(const char *address, intptr_t offset, void *src, int size) {
memcpy((void *)(_data + offset), src, size);
}
void ScriptUserObject::WriteInt8(const char *address, intptr_t offset, uint8_t val)
{
*(uint8_t*)(_data + offset) = val;
void ScriptUserObject::WriteInt8(const char *address, intptr_t offset, uint8_t val) {
*(uint8_t *)(_data + offset) = val;
}
void ScriptUserObject::WriteInt16(const char *address, intptr_t offset, int16_t val)
{
*(int16_t*)(_data + offset) = val;
void ScriptUserObject::WriteInt16(const char *address, intptr_t offset, int16_t val) {
*(int16_t *)(_data + offset) = val;
}
void ScriptUserObject::WriteInt32(const char *address, intptr_t offset, int32_t val)
{
*(int32_t*)(_data + offset) = val;
void ScriptUserObject::WriteInt32(const char *address, intptr_t offset, int32_t val) {
*(int32_t *)(_data + offset) = val;
}
void ScriptUserObject::WriteFloat(const char *address, intptr_t offset, float val)
{
*(float*)(_data + offset) = val;
void ScriptUserObject::WriteFloat(const char *address, intptr_t offset, float val) {
*(float *)(_data + offset) = val;
}
// Allocates managed struct containing two ints: X and Y
ScriptUserObject *ScriptStructHelpers::CreatePoint(int x, int y)
{
ScriptUserObject *ScriptStructHelpers::CreatePoint(int x, int y) {
ScriptUserObject *suo = ScriptUserObject::CreateManaged(sizeof(int32_t) * 2);
suo->WriteInt32((const char*)suo, 0, x);
suo->WriteInt32((const char*)suo, sizeof(int32_t), y);
suo->WriteInt32((const char *)suo, 0, x);
suo->WriteInt32((const char *)suo, sizeof(int32_t), y);
return suo;
}

View file

@ -31,8 +31,7 @@
#include "ac/dynobj/cc_agsdynamicobject.h"
struct ScriptUserObject final : ICCDynamicObject
{
struct ScriptUserObject final : ICCDynamicObject {
public:
ScriptUserObject();
@ -52,7 +51,7 @@ public:
virtual void Unserialize(int index, const char *serializedData, int dataSize);
// Support for reading and writing object values by their relative offset
const char* GetFieldPtr(const char *address, intptr_t offset) override;
const char *GetFieldPtr(const char *address, intptr_t offset) override;
void Read(const char *address, intptr_t offset, void *dest, int size) override;
uint8_t ReadInt8(const char *address, intptr_t offset) override;
int16_t ReadInt16(const char *address, intptr_t offset) override;
@ -77,10 +76,9 @@ private:
// Helper functions for setting up custom managed structs based on ScriptUserObject.
namespace ScriptStructHelpers
{
// Creates a managed Point object, represented as a pair of X and Y coordinates.
ScriptUserObject *CreatePoint(int x, int y);
namespace ScriptStructHelpers {
// Creates a managed Point object, represented as a pair of X and Y coordinates.
ScriptUserObject *CreatePoint(int x, int y);
};
#endif

View file

@ -28,42 +28,36 @@ using namespace AGS::Common;
ScriptViewport::ScriptViewport(int id) : _id(id) {}
const char *ScriptViewport::GetType()
{
const char *ScriptViewport::GetType() {
return "Viewport2";
}
int ScriptViewport::Dispose(const char *address, bool force)
{
int ScriptViewport::Dispose(const char *address, bool force) {
// Note that ScriptViewport is a reference to actual Viewport object,
// and this deletes the reference, while viewport may remain in GameState.
delete this;
return 1;
}
int ScriptViewport::Serialize(const char *address, char *buffer, int bufsize)
{
int ScriptViewport::Serialize(const char *address, char *buffer, int bufsize) {
StartSerialize(buffer);
SerializeInt(_id);
return EndSerialize();
}
void ScriptViewport::Unserialize(int index, const char *serializedData, int dataSize)
{
void ScriptViewport::Unserialize(int index, const char *serializedData, int dataSize) {
StartUnserialize(serializedData, dataSize);
_id = UnserializeInt();
ccRegisterUnserializedObject(index, this, this);
}
ScriptViewport *Viewport_Unserialize(int handle, const char *serializedData, int dataSize)
{
ScriptViewport *Viewport_Unserialize(int handle, const char *serializedData, int dataSize) {
// The way it works now, we must not create a new script object,
// but acquire one from the GameState, which keeps the first reference.
// This is essential because GameState should be able to invalidate any
// script references when Viewport gets removed.
const int id = BBOp::Int32FromLE(*((int*)serializedData));
if (id >= 0)
{
const int id = BBOp::Int32FromLE(*((int *)serializedData));
if (id >= 0) {
auto scview = play.RegisterRoomViewport(id, handle);
if (scview)
return scview;

View file

@ -26,15 +26,20 @@
#include "ac/dynobj/cc_agsdynamicobject.h"
// ScriptViewport keeps a reference to actual room Viewport in script.
struct ScriptViewport final : AGSCCDynamicObject
{
struct ScriptViewport final : AGSCCDynamicObject {
public:
ScriptViewport(int id);
// Get viewport index; negative means the viewport was deleted
int GetID() const { return _id; }
void SetID(int id) { _id = id; }
int GetID() const {
return _id;
}
void SetID(int id) {
_id = id;
}
// Reset viewport index to indicate that this reference is no longer valid
void Invalidate() { _id = -1; }
void Invalidate() {
_id = -1;
}
const char *GetType() override;
int Dispose(const char *address, bool force) override;

View file

@ -47,7 +47,7 @@ using namespace AGS::Engine;
extern GameSetupStruct game;
extern RoomStruct thisroom;
extern RoomStatus*croom;
extern RoomStatus *croom;
extern int displayed_room;
extern GameState play;
extern color palette[256];
@ -55,19 +55,19 @@ extern IGraphicsDriver *gfxDriver;
extern AGSPlatformDriver *platform;
extern color old_palette[256];
int in_enters_screen=0,done_es_error = 0;
int in_enters_screen = 0, done_es_error = 0;
int in_leaves_screen = -1;
EventHappened event[MAXEVENTS+1];
int numevents=0;
EventHappened event[MAXEVENTS + 1];
int numevents = 0;
const char*evblockbasename;
const char *evblockbasename;
int evblocknum;
int inside_processevent=0;
int inside_processevent = 0;
int eventClaimed = EVENT_NONE;
const char*tsnames[4]={nullptr, REP_EXEC_NAME, "on_key_press","on_mouse_click"};
const char *tsnames[4] = {nullptr, REP_EXEC_NAME, "on_key_press", "on_mouse_click"};
int run_claimable_event(const char *tsname, bool includeRoom, int numParams, const RuntimeScriptValue *params, bool *eventWasClaimed) {
@ -105,115 +105,99 @@ int run_claimable_event(const char *tsname, bool includeRoom, int numParams, con
}
// runs the global script on_event function
void run_on_event (int evtype, RuntimeScriptValue &wparam)
{
void run_on_event(int evtype, RuntimeScriptValue &wparam) {
QueueScriptFunction(kScInstGame, "on_event", 2, RuntimeScriptValue().SetInt32(evtype), wparam);
}
void run_room_event(int id) {
evblockbasename="room";
evblockbasename = "room";
if (thisroom.EventHandlers != nullptr)
{
if (thisroom.EventHandlers != nullptr) {
run_interaction_script(thisroom.EventHandlers.get(), id);
}
else
{
run_interaction_event (&croom->intrRoom, id);
} else {
run_interaction_event(&croom->intrRoom, id);
}
}
void run_event_block_inv(int invNum, int event) {
evblockbasename="inventory%d";
if (loaded_game_file_version > kGameVersion_272)
{
evblockbasename = "inventory%d";
if (loaded_game_file_version > kGameVersion_272) {
run_interaction_script(game.invScripts[invNum].get(), event);
}
else
{
} else {
run_interaction_event(game.intrInv[invNum].get(), event);
}
}
// event list functions
void setevent(int evtyp,int ev1,int ev2,int ev3) {
event[numevents].type=evtyp;
event[numevents].data1=ev1;
event[numevents].data2=ev2;
event[numevents].data3=ev3;
event[numevents].player=game.playercharacter;
void setevent(int evtyp, int ev1, int ev2, int ev3) {
event[numevents].type = evtyp;
event[numevents].data1 = ev1;
event[numevents].data2 = ev2;
event[numevents].data3 = ev3;
event[numevents].player = game.playercharacter;
numevents++;
if (numevents>=MAXEVENTS) quit("too many events posted");
if (numevents >= MAXEVENTS) quit("too many events posted");
}
// TODO: this is kind of a hack, which forces event to be processed even if
// it was fired from insides of other event processing.
// The proper solution would be to do the event processing overhaul in AGS.
void force_event(int evtyp,int ev1,int ev2,int ev3)
{
void force_event(int evtyp, int ev1, int ev2, int ev3) {
if (inside_processevent)
runevent_now(evtyp, ev1, ev2, ev3);
else
setevent(evtyp, ev1, ev2, ev3);
}
void process_event(EventHappened*evp) {
void process_event(EventHappened *evp) {
RuntimeScriptValue rval_null;
if (evp->type==EV_TEXTSCRIPT) {
ccError=0;
if (evp->type == EV_TEXTSCRIPT) {
ccError = 0;
if (evp->data2 > -1000) {
QueueScriptFunction(kScInstGame, tsnames[evp->data1], 1, RuntimeScriptValue().SetInt32(evp->data2));
}
else {
} else {
QueueScriptFunction(kScInstGame, tsnames[evp->data1]);
}
}
else if (evp->type==EV_NEWROOM) {
} else if (evp->type == EV_NEWROOM) {
NewRoom(evp->data1);
}
else if (evp->type==EV_RUNEVBLOCK) {
Interaction*evpt=nullptr;
} else if (evp->type == EV_RUNEVBLOCK) {
Interaction *evpt = nullptr;
PInteractionScripts scriptPtr = nullptr;
const char *oldbasename = evblockbasename;
int oldblocknum = evblocknum;
if (evp->data1==EVB_HOTSPOT) {
if (evp->data1 == EVB_HOTSPOT) {
if (thisroom.Hotspots[evp->data2].EventHandlers != nullptr)
scriptPtr = thisroom.Hotspots[evp->data2].EventHandlers;
else
evpt=&croom->intrHotspot[evp->data2];
evpt = &croom->intrHotspot[evp->data2];
evblockbasename="hotspot%d";
evblocknum=evp->data2;
evblockbasename = "hotspot%d";
evblocknum = evp->data2;
//Debug::Printf("Running hotspot interaction for hotspot %d, event %d", evp->data2, evp->data3);
}
else if (evp->data1==EVB_ROOM) {
} else if (evp->data1 == EVB_ROOM) {
if (thisroom.EventHandlers != nullptr)
scriptPtr = thisroom.EventHandlers;
else
evpt=&croom->intrRoom;
evpt = &croom->intrRoom;
evblockbasename="room";
evblockbasename = "room";
if (evp->data3 == 5) {
in_enters_screen ++;
run_on_event (GE_ENTER_ROOM, RuntimeScriptValue().SetInt32(displayed_room));
run_on_event(GE_ENTER_ROOM, RuntimeScriptValue().SetInt32(displayed_room));
}
//Debug::Printf("Running room interaction, event %d", evp->data3);
}
if (scriptPtr != nullptr)
{
if (scriptPtr != nullptr) {
run_interaction_script(scriptPtr.get(), evp->data3);
}
else if (evpt != nullptr)
{
run_interaction_event(evpt,evp->data3);
}
else
} else if (evpt != nullptr) {
run_interaction_event(evpt, evp->data3);
} else
quit("process_event: RunEvBlock: unknown evb type");
evblockbasename = oldbasename;
@ -221,8 +205,7 @@ void process_event(EventHappened*evp) {
if ((evp->data3 == 5) && (evp->data1 == EVB_ROOM))
in_enters_screen --;
}
else if (evp->type==EV_FADEIN) {
} else if (evp->type == EV_FADEIN) {
// if they change the transition type before the fadein, make
// sure the screen doesn't freeze up
play.screen_is_faded_out = 0;
@ -244,8 +227,7 @@ void process_event(EventHappened*evp) {
const bool ignore_transition = (play.screen_tint > 0);
if (((theTransition == FADE_CROSSFADE) || (theTransition == FADE_DISSOLVE)) &&
(saved_viewport_bitmap == nullptr) && !ignore_transition)
{
(saved_viewport_bitmap == nullptr) && !ignore_transition) {
// transition type was not crossfade/dissolve when the screen faded out,
// but it is now when the screen fades in (Eg. a save game was restored
// with a different setting). Therefore just fade normally.
@ -259,18 +241,12 @@ void process_event(EventHappened*evp) {
if ((theTransition == FADE_INSTANT) || ignore_transition)
set_palette_range(palette, 0, 255, 0);
else if (theTransition == FADE_NORMAL)
{
my_fade_in(palette,5);
}
else if (theTransition == FADE_BOXOUT)
{
if (!gfxDriver->UsesMemoryBackBuffer())
{
else if (theTransition == FADE_NORMAL) {
my_fade_in(palette, 5);
} else if (theTransition == FADE_BOXOUT) {
if (!gfxDriver->UsesMemoryBackBuffer()) {
gfxDriver->BoxOutEffect(false, get_fixed_pixel_size(16), 1000 / GetGameSpeed());
}
else
{
} else {
// First of all we render the game once again and save backbuffer from further editing.
// We put temporary bitmap as a new backbuffer for the transition period, and
// will be drawing saved image of the game over to that backbuffer, simulating "box-out".
@ -287,8 +263,7 @@ void process_event(EventHappened*evp) {
const int speed = get_fixed_pixel_size(16);
const int yspeed = viewport.GetHeight() / (viewport.GetWidth() / speed);
int boxwid = speed, boxhit = yspeed;
while (boxwid < temp_scr->GetWidth())
{
while (boxwid < temp_scr->GetWidth()) {
boxwid += speed;
boxhit += yspeed;
boxwid = Math::Clamp(boxwid, 0, viewport.GetWidth());
@ -305,9 +280,7 @@ void process_event(EventHappened*evp) {
gfxDriver->SetMemoryBackBuffer(saved_backbuf);
}
play.screen_is_faded_out = 0;
}
else if (theTransition == FADE_CROSSFADE)
{
} else if (theTransition == FADE_CROSSFADE) {
if (game.color_depth == 1)
quit("!Cannot use crossfade screen transition in 256-colour games");
@ -322,8 +295,7 @@ void process_event(EventHappened*evp) {
construct_game_scene(true);
construct_game_screen_overlay(false);
if (transparency > 16)
{
if (transparency > 16) {
// on last frame of fade (where transparency < 16), don't
// draw the old screen on top
gfxDriver->DrawSprite(0, 0, ddb);
@ -339,25 +311,23 @@ void process_event(EventHappened*evp) {
saved_viewport_bitmap = nullptr;
set_palette_range(palette, 0, 255, 0);
gfxDriver->DestroyDDB(ddb);
}
else if (theTransition == FADE_DISSOLVE) {
int pattern[16]={0,4,14,9,5,11,2,8,10,3,12,7,15,6,13,1};
int aa,bb,cc;
} else if (theTransition == FADE_DISSOLVE) {
int pattern[16] = {0, 4, 14, 9, 5, 11, 2, 8, 10, 3, 12, 7, 15, 6, 13, 1};
int aa, bb, cc;
color interpal[256];
IDriverDependantBitmap *ddb = prepare_screen_for_transition_in();
for (aa=0;aa<16;aa++) {
for (aa = 0; aa < 16; aa++) {
// merge the palette while dithering
if (game.color_depth == 1)
{
fade_interpolate(old_palette,palette,interpal,aa*4,0,255);
if (game.color_depth == 1) {
fade_interpolate(old_palette, palette, interpal, aa * 4, 0, 255);
set_palette_range(interpal, 0, 255, 0);
}
// do the dissolving
int maskCol = saved_viewport_bitmap->GetMaskColor();
for (bb=0;bb<viewport.GetWidth();bb+=4) {
for (cc=0;cc<viewport.GetHeight();cc+=4) {
saved_viewport_bitmap->PutPixel(bb+pattern[aa]/4, cc+pattern[aa]%4, maskCol);
for (bb = 0; bb < viewport.GetWidth(); bb += 4) {
for (cc = 0; cc < viewport.GetHeight(); cc += 4) {
saved_viewport_bitmap->PutPixel(bb + pattern[aa] / 4, cc + pattern[aa] % 4, maskCol);
}
}
gfxDriver->UpdateDDBFromBitmap(ddb, saved_viewport_bitmap, false);
@ -375,14 +345,13 @@ void process_event(EventHappened*evp) {
gfxDriver->DestroyDDB(ddb);
}
}
else if (evp->type==EV_IFACECLICK)
} else if (evp->type == EV_IFACECLICK)
process_interface_click(evp->data1, evp->data2, evp->data3);
else quit("process_event: unknown event to process");
}
void runevent_now (int evtyp, int ev1, int ev2, int ev3) {
void runevent_now(int evtyp, int ev1, int ev2, int ev3) {
EventHappened evh;
evh.type = evtyp;
evh.data1 = ev1;
@ -392,7 +361,7 @@ void runevent_now (int evtyp, int ev1, int ev2, int ev3) {
process_event(&evh);
}
void processallevents(int numev,EventHappened*evlist) {
void processallevents(int numev, EventHappened *evlist) {
int dd;
if (inside_processevent)
@ -408,7 +377,7 @@ void processallevents(int numev,EventHappened*evlist) {
inside_processevent++;
for (dd=0;dd<numev;dd++) {
for (dd = 0; dd < numev; dd++) {
process_event(&copyOfList[dd]);
@ -420,8 +389,8 @@ void processallevents(int numev,EventHappened*evlist) {
}
void update_events() {
processallevents(numevents,&event[0]);
numevents=0;
processallevents(numevents, &event[0]);
numevents = 0;
}
// end event list functions

View file

@ -52,36 +52,36 @@
struct EventHappened {
int type;
int data1,data2,data3;
int data1, data2, data3;
int player;
};
int run_claimable_event(const char *tsname, bool includeRoom, int numParams, const RuntimeScriptValue *params, bool *eventWasClaimed);
// runs the global script on_event fnuction
void run_on_event (int evtype, RuntimeScriptValue &wparam);
void run_on_event(int evtype, RuntimeScriptValue &wparam);
void run_room_event(int id);
void run_event_block_inv(int invNum, int event);
// event list functions
void setevent(int evtyp,int ev1=0,int ev2=-1000,int ev3=0);
void force_event(int evtyp,int ev1=0,int ev2=-1000,int ev3=0);
void process_event(EventHappened*evp);
void runevent_now (int evtyp, int ev1, int ev2, int ev3);
void processallevents(int numev,EventHappened*evlist);
void setevent(int evtyp, int ev1 = 0, int ev2 = -1000, int ev3 = 0);
void force_event(int evtyp, int ev1 = 0, int ev2 = -1000, int ev3 = 0);
void process_event(EventHappened *evp);
void runevent_now(int evtyp, int ev1, int ev2, int ev3);
void processallevents(int numev, EventHappened *evlist);
void update_events();
// end event list functions
void ClaimEvent();
extern int in_enters_screen,done_es_error;
extern int in_enters_screen, done_es_error;
extern int in_leaves_screen;
extern EventHappened event[MAXEVENTS+1];
extern EventHappened event[MAXEVENTS + 1];
extern int numevents;
extern const char*evblockbasename;
extern const char *evblockbasename;
extern int evblocknum;
extern int eventClaimed;
extern const char*tsnames[4];
extern const char *tsnames[4];
#endif

View file

@ -121,7 +121,7 @@ void File_WriteRawLine(sc_File *fil, const char *towrite) {
FileWriteRawLine(fil->handle, towrite);
}
void File_ReadRawLine(sc_File *fil, char* buffer) {
void File_ReadRawLine(sc_File *fil, char *buffer) {
Stream *in = get_valid_file_stream_from_handle(fil->handle, "File.ReadRawLine");
check_strlen(buffer);
int i = 0;
@ -141,7 +141,7 @@ void File_ReadRawLine(sc_File *fil, char* buffer) {
buffer[i] = 0;
}
const char* File_ReadRawLineBack(sc_File *fil) {
const char *File_ReadRawLineBack(sc_File *fil) {
char readbuffer[MAX_MAXSTRLEN + 1];
File_ReadRawLine(fil, readbuffer);
return CreateNewScriptString(readbuffer);
@ -151,7 +151,7 @@ void File_ReadString(sc_File *fil, char *toread) {
FileRead(fil->handle, toread);
}
const char* File_ReadStringBack(sc_File *fil) {
const char *File_ReadStringBack(sc_File *fil) {
Stream *in = get_valid_file_stream_from_handle(fil->handle, "File.ReadStringBack");
if (in->EOS()) {
return CreateNewScriptString("");
@ -161,7 +161,7 @@ const char* File_ReadStringBack(sc_File *fil) {
if ((lle >= 20000) || (lle < 1))
quit("!File.ReadStringBack: file was not written by WriteString");
char *retVal = (char*)malloc(lle);
char *retVal = (char *)malloc(lle);
in->Read(retVal, lle);
return CreateNewScriptString(retVal, false);
@ -179,10 +179,11 @@ int File_ReadRawInt(sc_File *fil) {
return FileReadRawInt(fil->handle);
}
int File_Seek(sc_File *fil, int offset, int origin)
{
int File_Seek(sc_File *fil, int offset, int origin) {
Stream *in = get_valid_file_stream_from_handle(fil->handle, "File.Seek");
if (!in->Seek(offset, (StreamSeek)origin)) { return -1; }
if (!in->Seek(offset, (StreamSeek)origin)) {
return -1;
}
return in->GetPosition();
}
@ -198,8 +199,7 @@ int File_GetError(sc_File *fil) {
return FileIsError(fil->handle);
}
int File_GetPosition(sc_File *fil)
{
int File_GetPosition(sc_File *fil) {
if (fil->handle <= 0)
return -1;
Stream *stream = get_valid_file_stream_from_handle(fil->handle, "File.Position");
@ -215,17 +215,12 @@ const String UserSavedgamesRootToken = "$MYDOCS$";
const String GameSavedgamesDirToken = "$SAVEGAMEDIR$";
const String GameDataDirToken = "$APPDATADIR$";
void FixupFilename(char *filename)
{
void FixupFilename(char *filename) {
const char *illegal = platform->GetIllegalFileChars();
for (char *name_ptr = filename; *name_ptr; ++name_ptr)
{
if (*name_ptr < ' ')
{
for (char *name_ptr = filename; *name_ptr; ++name_ptr) {
if (*name_ptr < ' ') {
*name_ptr = '_';
}
else
{
} else {
for (const char *ch_ptr = illegal; *ch_ptr; ++ch_ptr)
if (*name_ptr == *ch_ptr)
*name_ptr = '_';
@ -237,19 +232,16 @@ void FixupFilename(char *filename)
// if there is and there is no slash between token and the rest of the string,
// then assigns new string that has such slash.
// Returns TRUE if the new string was created, and FALSE if the path was good.
bool FixSlashAfterToken(const String &path, const String &token, String &new_path)
{
bool FixSlashAfterToken(const String &path, const String &token, String &new_path) {
if (path.CompareLeft(token) == 0 && path.GetLength() > token.GetLength() &&
path[token.GetLength()] != '/')
{
path[token.GetLength()] != '/') {
new_path = String::FromFormat("%s/%s", token.GetCStr(), path.Mid(token.GetLength()).GetCStr());
return true;
}
return false;
}
String FixSlashAfterToken(const String &path)
{
String FixSlashAfterToken(const String &path) {
String fixed_path = path;
Path::FixupPath(fixed_path);
if (FixSlashAfterToken(fixed_path, GameInstallRootToken, fixed_path) ||
@ -260,8 +252,7 @@ String FixSlashAfterToken(const String &path)
return path;
}
String MakeSpecialSubDir(const String &sp_dir)
{
String MakeSpecialSubDir(const String &sp_dir) {
if (is_relative_filename(sp_dir))
return sp_dir;
String full_path = sp_dir;
@ -272,8 +263,7 @@ String MakeSpecialSubDir(const String &sp_dir)
return full_path;
}
String MakeAppDataPath()
{
String MakeAppDataPath() {
String app_data_path = usetup.shared_data_dir;
if (app_data_path.IsEmpty())
app_data_path = MakeSpecialSubDir(PathOrCurDir(platform->GetAllUsersDataDirectory()));
@ -282,19 +272,16 @@ String MakeAppDataPath()
return app_data_path;
}
bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath &rp)
{
bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath &rp) {
rp = ResolvedPath();
bool is_absolute = !is_relative_filename(orig_sc_path);
if (is_absolute && !read_only)
{
if (is_absolute && !read_only) {
debug_script_warn("Attempt to access file '%s' denied (cannot write to absolute path)", orig_sc_path.GetCStr());
return false;
}
if (is_absolute)
{
if (is_absolute) {
rp.FullPath = orig_sc_path;
return true;
}
@ -303,10 +290,8 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
String parent_dir;
String child_path;
String alt_path;
if (sc_path.CompareLeft(GameInstallRootToken, GameInstallRootToken.GetLength()) == 0)
{
if (!read_only)
{
if (sc_path.CompareLeft(GameInstallRootToken, GameInstallRootToken.GetLength()) == 0) {
if (!read_only) {
debug_script_warn("Attempt to access file '%s' denied (cannot write to game installation directory)",
sc_path.GetCStr());
return false;
@ -314,19 +299,13 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
parent_dir = get_install_dir();
parent_dir.AppendChar('/');
child_path = sc_path.Mid(GameInstallRootToken.GetLength());
}
else if (sc_path.CompareLeft(GameSavedgamesDirToken, GameSavedgamesDirToken.GetLength()) == 0)
{
} else if (sc_path.CompareLeft(GameSavedgamesDirToken, GameSavedgamesDirToken.GetLength()) == 0) {
parent_dir = get_save_game_directory();
child_path = sc_path.Mid(GameSavedgamesDirToken.GetLength());
}
else if (sc_path.CompareLeft(GameDataDirToken, GameDataDirToken.GetLength()) == 0)
{
} else if (sc_path.CompareLeft(GameDataDirToken, GameDataDirToken.GetLength()) == 0) {
parent_dir = MakeAppDataPath();
child_path = sc_path.Mid(GameDataDirToken.GetLength());
}
else
{
} else {
child_path = sc_path;
// For games which were made without having safe paths in mind,
@ -346,8 +325,7 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
// For games made in the safe-path-aware versions of AGS, report a warning
// if the unsafe path is used for write operation
if (!read_only && game.options[OPT_SAFEFILEPATHS])
{
if (!read_only && game.options[OPT_SAFEFILEPATHS]) {
debug_script_warn("Attempt to access file '%s' denied (cannot write to game installation directory);\nPath will be remapped to the app data directory: '%s'",
sc_path.GetCStr(), parent_dir.GetCStr());
}
@ -358,10 +336,8 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
String full_path = String::FromFormat("%s%s", parent_dir.GetCStr(), child_path.GetCStr());
// don't allow write operations for relative paths outside game dir
if (!read_only)
{
if (!Path::IsSameOrSubDir(parent_dir, full_path))
{
if (!read_only) {
if (!Path::IsSameOrSubDir(parent_dir, full_path)) {
debug_script_warn("Attempt to access file '%s' denied (outside of game directory)", sc_path.GetCStr());
return false;
}
@ -372,28 +348,24 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
return true;
}
bool ResolveWritePathAndCreateDirs(const String &sc_path, ResolvedPath &rp)
{
bool ResolveWritePathAndCreateDirs(const String &sc_path, ResolvedPath &rp) {
if (!ResolveScriptPath(sc_path, false, rp))
return false;
if (!Directory::CreateAllDirectories(rp.BaseDir, Path::GetDirectoryPath(rp.FullPath)))
{
if (!Directory::CreateAllDirectories(rp.BaseDir, Path::GetDirectoryPath(rp.FullPath))) {
debug_script_warn("ResolveScriptPath: failed to create all subdirectories: %s", rp.FullPath.GetCStr());
return false;
}
return true;
}
Stream *LocateAsset(const AssetPath &path, size_t &asset_size)
{
Stream *LocateAsset(const AssetPath &path, size_t &asset_size) {
String assetlib = path.first;
String assetname = path.second;
bool needsetback = false;
// Change to the different library, if required
// TODO: teaching AssetManager to register multiple libraries simultaneously
// will let us skip this step, and also make this operation much faster.
if (!assetlib.IsEmpty() && assetlib.CompareNoCase(ResPaths.GamePak.Name) != 0)
{
if (!assetlib.IsEmpty() && assetlib.CompareNoCase(ResPaths.GamePak.Name) != 0) {
AssetManager::SetDataFile(get_known_assetlib(assetlib));
needsetback = true;
}
@ -407,33 +379,27 @@ Stream *LocateAsset(const AssetPath &path, size_t &asset_size)
//
// AGS custom PACKFILE callbacks, that use our own Stream object
//
static int ags_pf_fclose(void *userdata)
{
delete (AGS_PACKFILE_OBJ*)userdata;
static int ags_pf_fclose(void *userdata) {
delete(AGS_PACKFILE_OBJ *)userdata;
return 0;
}
static int ags_pf_getc(void *userdata)
{
AGS_PACKFILE_OBJ* obj = (AGS_PACKFILE_OBJ*)userdata;
if (obj->remains > 0)
{
static int ags_pf_getc(void *userdata) {
AGS_PACKFILE_OBJ *obj = (AGS_PACKFILE_OBJ *)userdata;
if (obj->remains > 0) {
obj->remains--;
return obj->stream->ReadByte();
}
return -1;
}
static int ags_pf_ungetc(int c, void *userdata)
{
static int ags_pf_ungetc(int c, void *userdata) {
return -1; // we do not want to support this
}
static long ags_pf_fread(void *p, long n, void *userdata)
{
AGS_PACKFILE_OBJ* obj = (AGS_PACKFILE_OBJ*)userdata;
if (obj->remains > 0)
{
static long ags_pf_fread(void *p, long n, void *userdata) {
AGS_PACKFILE_OBJ *obj = (AGS_PACKFILE_OBJ *)userdata;
if (obj->remains > 0) {
size_t read = Math::Min(obj->remains, (size_t)n);
obj->remains -= read;
return obj->stream->Read(p, read);
@ -441,29 +407,24 @@ static long ags_pf_fread(void *p, long n, void *userdata)
return -1;
}
static int ags_pf_putc(int c, void *userdata)
{
static int ags_pf_putc(int c, void *userdata) {
return -1; // don't support write
}
static long ags_pf_fwrite(AL_CONST void *p, long n, void *userdata)
{
static long ags_pf_fwrite(AL_CONST void *p, long n, void *userdata) {
return -1; // don't support write
}
static int ags_pf_fseek(void *userdata, int offset)
{
static int ags_pf_fseek(void *userdata, int offset) {
return -1; // don't support seek
}
static int ags_pf_feof(void *userdata)
{
return ((AGS_PACKFILE_OBJ*)userdata)->remains == 0;
static int ags_pf_feof(void *userdata) {
return ((AGS_PACKFILE_OBJ *)userdata)->remains == 0;
}
static int ags_pf_ferror(void *userdata)
{
return ((AGS_PACKFILE_OBJ*)userdata)->stream->HasErrors() ? 1 : 0;
static int ags_pf_ferror(void *userdata) {
return ((AGS_PACKFILE_OBJ *)userdata)->stream->HasErrors() ? 1 : 0;
}
// Custom PACKFILE callback table
@ -480,12 +441,10 @@ static PACKFILE_VTABLE ags_packfile_vtable = {
};
//
PACKFILE *PackfileFromAsset(const AssetPath &path, size_t &asset_size)
{
PACKFILE *PackfileFromAsset(const AssetPath &path, size_t &asset_size) {
Stream *asset_stream = LocateAsset(path, asset_size);
if (asset_stream && asset_size > 0)
{
AGS_PACKFILE_OBJ* obj = new AGS_PACKFILE_OBJ;
if (asset_stream && asset_size > 0) {
AGS_PACKFILE_OBJ *obj = new AGS_PACKFILE_OBJ;
obj->stream.reset(asset_stream);
obj->asset_size = asset_size;
obj->remains = asset_size;
@ -494,22 +453,19 @@ PACKFILE *PackfileFromAsset(const AssetPath &path, size_t &asset_size)
return nullptr;
}
DUMBFILE *DUMBfileFromAsset(const AssetPath &path, size_t &asset_size)
{
DUMBFILE *DUMBfileFromAsset(const AssetPath &path, size_t &asset_size) {
PACKFILE *pf = PackfileFromAsset(path, asset_size);
if (pf)
return dumbfile_open_packfile(pf);
return nullptr;
}
bool DoesAssetExistInLib(const AssetPath &assetname)
{
bool DoesAssetExistInLib(const AssetPath &assetname) {
bool needsetback = false;
// Change to the different library, if required
// TODO: teaching AssetManager to register multiple libraries simultaneously
// will let us skip this step, and also make this operation much faster.
if (!assetname.first.IsEmpty() && assetname.first.CompareNoCase(ResPaths.GamePak.Name) != 0)
{
if (!assetname.first.IsEmpty() && assetname.first.CompareNoCase(ResPaths.GamePak.Name) != 0) {
AssetManager::SetDataFile(get_known_assetlib(assetname.first));
needsetback = true;
}
@ -519,8 +475,7 @@ bool DoesAssetExistInLib(const AssetPath &assetname)
return res;
}
void set_install_dir(const String &path, const String &audio_path, const String &voice_path)
{
void set_install_dir(const String &path, const String &audio_path, const String &voice_path) {
if (path.IsEmpty())
installDirectory = ".";
else
@ -535,35 +490,29 @@ void set_install_dir(const String &path, const String &audio_path, const String
installVoiceDirectory = Path::MakePathNoSlash(voice_path);
}
String get_install_dir()
{
String get_install_dir() {
return installDirectory;
}
String get_audio_install_dir()
{
String get_audio_install_dir() {
return installAudioDirectory;
}
String get_voice_install_dir()
{
String get_voice_install_dir() {
return installVoiceDirectory;
}
void get_install_dir_path(char* buffer, const char *fileName)
{
void get_install_dir_path(char *buffer, const char *fileName) {
sprintf(buffer, "%s/%s", installDirectory.GetCStr(), fileName);
}
String find_assetlib(const String &filename)
{
String libname = cbuf_to_string_and_free( ci_find_file(ResPaths.DataDir, filename) );
String find_assetlib(const String &filename) {
String libname = cbuf_to_string_and_free(ci_find_file(ResPaths.DataDir, filename));
if (AssetManager::IsDataFile(libname))
return libname;
if (Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0)
{
if (Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0) {
// Hack for running in Debugger
libname = cbuf_to_string_and_free( ci_find_file(installDirectory, filename) );
libname = cbuf_to_string_and_free(ci_find_file(installDirectory, filename));
if (AssetManager::IsDataFile(libname))
return libname;
}
@ -571,8 +520,7 @@ String find_assetlib(const String &filename)
}
// Looks up for known valid asset library and returns path, or empty string if failed
String get_known_assetlib(const String &filename)
{
String get_known_assetlib(const String &filename) {
// TODO: write now there's only 3 regular PAKs, so we may do this quick
// string comparison, but if we support more maybe we could use a table.
if (filename.CompareNoCase(ResPaths.GamePak.Name) == 0)
@ -584,23 +532,19 @@ String get_known_assetlib(const String &filename)
return String();
}
Stream *find_open_asset(const String &filename)
{
Stream *find_open_asset(const String &filename) {
Stream *asset_s = Common::AssetManager::OpenAsset(filename);
if (!asset_s && Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0)
{
if (!asset_s && Path::ComparePaths(ResPaths.DataDir, installDirectory) != 0) {
// Just in case they're running in Debug, try standalone file in compiled folder
asset_s = ci_fopen(String::FromFormat("%s/%s", installDirectory.GetCStr(), filename.GetCStr()));
}
return asset_s;
}
AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename)
{
AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
// Special case is explicitly defined audio directory, which should be
// tried first regardless of bundling type.
if (Path::ComparePaths(ResPaths.DataDir, installAudioDirectory) != 0)
{
if (Path::ComparePaths(ResPaths.DataDir, installAudioDirectory) != 0) {
String filepath = String::FromFormat("%s/%s", installAudioDirectory.GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
@ -613,12 +557,10 @@ AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename)
return AssetPath();
}
AssetPath get_voice_over_assetpath(const String &filename)
{
AssetPath get_voice_over_assetpath(const String &filename) {
// Special case is explicitly defined voice-over directory, which should be
// tried first.
if (Path::ComparePaths(ResPaths.DataDir, installVoiceDirectory) != 0)
{
if (Path::ComparePaths(ResPaths.DataDir, installVoiceDirectory) != 0) {
String filepath = String::FromFormat("%s/%s", installVoiceDirectory.GetCStr(), filename.GetCStr());
if (Path::IsFile(filepath))
return AssetPath("", filepath);
@ -630,14 +572,10 @@ ScriptFileHandle valid_handles[MAX_OPEN_SCRIPT_FILES + 1];
// [IKM] NOTE: this is not precisely the number of files opened at this moment,
// but rather maximal number of handles that were used simultaneously during game run
int num_open_script_files = 0;
ScriptFileHandle *check_valid_file_handle_ptr(Stream *stream_ptr, const char *operation_name)
{
if (stream_ptr)
{
for (int i = 0; i < num_open_script_files; ++i)
{
if (stream_ptr == valid_handles[i].stream)
{
ScriptFileHandle *check_valid_file_handle_ptr(Stream *stream_ptr, const char *operation_name) {
if (stream_ptr) {
for (int i = 0; i < num_open_script_files; ++i) {
if (stream_ptr == valid_handles[i].stream) {
return &valid_handles[i];
}
}
@ -648,14 +586,10 @@ ScriptFileHandle *check_valid_file_handle_ptr(Stream *stream_ptr, const char *op
return nullptr;
}
ScriptFileHandle *check_valid_file_handle_int32(int32_t handle, const char *operation_name)
{
if (handle > 0)
{
for (int i = 0; i < num_open_script_files; ++i)
{
if (handle == valid_handles[i].handle)
{
ScriptFileHandle *check_valid_file_handle_int32(int32_t handle, const char *operation_name) {
if (handle > 0) {
for (int i = 0; i < num_open_script_files; ++i) {
if (handle == valid_handles[i].handle) {
return &valid_handles[i];
}
}
@ -666,8 +600,7 @@ ScriptFileHandle *check_valid_file_handle_int32(int32_t handle, const char *oper
return nullptr;
}
Stream *get_valid_file_stream_from_handle(int32_t handle, const char *operation_name)
{
Stream *get_valid_file_stream_from_handle(int32_t handle, const char *operation_name) {
ScriptFileHandle *sc_handle = check_valid_file_handle_int32(handle, operation_name);
return sc_handle ? sc_handle->stream : nullptr;
}
@ -686,120 +619,100 @@ Stream *get_valid_file_stream_from_handle(int32_t handle, const char *operation_
extern ScriptString myScriptStringImpl;
// int (const char *fnmm)
RuntimeScriptValue Sc_File_Delete(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_Delete(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_INT_POBJ(File_Delete, const char);
}
// int (const char *fnmm)
RuntimeScriptValue Sc_File_Exists(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_Exists(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_INT_POBJ(File_Exists, const char);
}
// void *(const char *fnmm, int mode)
RuntimeScriptValue Sc_sc_OpenFile(const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_sc_OpenFile(const RuntimeScriptValue *params, int32_t param_count) {
API_SCALL_OBJAUTO_POBJ_PINT(sc_File, sc_OpenFile, const char);
}
// void (sc_File *fil)
RuntimeScriptValue Sc_File_Close(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_Close(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(sc_File, File_Close);
}
// int (sc_File *fil)
RuntimeScriptValue Sc_File_ReadInt(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadInt(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_ReadInt);
}
// int (sc_File *fil)
RuntimeScriptValue Sc_File_ReadRawChar(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadRawChar(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_ReadRawChar);
}
// int (sc_File *fil)
RuntimeScriptValue Sc_File_ReadRawInt(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadRawInt(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_ReadRawInt);
}
// void (sc_File *fil, char* buffer)
RuntimeScriptValue Sc_File_ReadRawLine(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadRawLine(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(sc_File, File_ReadRawLine, char);
}
// const char* (sc_File *fil)
RuntimeScriptValue Sc_File_ReadRawLineBack(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadRawLineBack(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(sc_File, const char, myScriptStringImpl, File_ReadRawLineBack);
}
// void (sc_File *fil, char *toread)
RuntimeScriptValue Sc_File_ReadString(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadString(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(sc_File, File_ReadString, char);
}
// const char* (sc_File *fil)
RuntimeScriptValue Sc_File_ReadStringBack(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_ReadStringBack(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(sc_File, const char, myScriptStringImpl, File_ReadStringBack);
}
// void (sc_File *fil, int towrite)
RuntimeScriptValue Sc_File_WriteInt(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_WriteInt(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(sc_File, File_WriteInt);
}
// void (sc_File *fil, int towrite)
RuntimeScriptValue Sc_File_WriteRawChar(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_WriteRawChar(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(sc_File, File_WriteRawChar);
}
// void (sc_File *fil, const char *towrite)
RuntimeScriptValue Sc_File_WriteRawLine(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_WriteRawLine(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(sc_File, File_WriteRawLine, const char);
}
// void (sc_File *fil, const char *towrite)
RuntimeScriptValue Sc_File_WriteString(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_WriteString(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_POBJ(sc_File, File_WriteString, const char);
}
RuntimeScriptValue Sc_File_Seek(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_Seek(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT2(sc_File, File_Seek);
}
// int (sc_File *fil)
RuntimeScriptValue Sc_File_GetEOF(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_GetEOF(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_GetEOF);
}
// int (sc_File *fil)
RuntimeScriptValue Sc_File_GetError(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_GetError(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_GetError);
}
RuntimeScriptValue Sc_File_GetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
RuntimeScriptValue Sc_File_GetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(sc_File, File_GetPosition);
}
void RegisterFileAPI()
{
void RegisterFileAPI() {
ccAddExternalStaticFunction("File::Delete^1", Sc_File_Delete);
ccAddExternalStaticFunction("File::Exists^1", Sc_File_Exists);
ccAddExternalStaticFunction("File::Open^2", Sc_sc_OpenFile);
@ -822,21 +735,21 @@ void RegisterFileAPI()
/* ----------------------- Registering unsafe exports for plugins -----------------------*/
ccAddExternalFunctionForPlugin("File::Delete^1", (void*)File_Delete);
ccAddExternalFunctionForPlugin("File::Exists^1", (void*)File_Exists);
ccAddExternalFunctionForPlugin("File::Open^2", (void*)sc_OpenFile);
ccAddExternalFunctionForPlugin("File::Close^0", (void*)File_Close);
ccAddExternalFunctionForPlugin("File::ReadInt^0", (void*)File_ReadInt);
ccAddExternalFunctionForPlugin("File::ReadRawChar^0", (void*)File_ReadRawChar);
ccAddExternalFunctionForPlugin("File::ReadRawInt^0", (void*)File_ReadRawInt);
ccAddExternalFunctionForPlugin("File::ReadRawLine^1", (void*)File_ReadRawLine);
ccAddExternalFunctionForPlugin("File::ReadRawLineBack^0", (void*)File_ReadRawLineBack);
ccAddExternalFunctionForPlugin("File::ReadString^1", (void*)File_ReadString);
ccAddExternalFunctionForPlugin("File::ReadStringBack^0", (void*)File_ReadStringBack);
ccAddExternalFunctionForPlugin("File::WriteInt^1", (void*)File_WriteInt);
ccAddExternalFunctionForPlugin("File::WriteRawChar^1", (void*)File_WriteRawChar);
ccAddExternalFunctionForPlugin("File::WriteRawLine^1", (void*)File_WriteRawLine);
ccAddExternalFunctionForPlugin("File::WriteString^1", (void*)File_WriteString);
ccAddExternalFunctionForPlugin("File::get_EOF", (void*)File_GetEOF);
ccAddExternalFunctionForPlugin("File::get_Error", (void*)File_GetError);
ccAddExternalFunctionForPlugin("File::Delete^1", (void *)File_Delete);
ccAddExternalFunctionForPlugin("File::Exists^1", (void *)File_Exists);
ccAddExternalFunctionForPlugin("File::Open^2", (void *)sc_OpenFile);
ccAddExternalFunctionForPlugin("File::Close^0", (void *)File_Close);
ccAddExternalFunctionForPlugin("File::ReadInt^0", (void *)File_ReadInt);
ccAddExternalFunctionForPlugin("File::ReadRawChar^0", (void *)File_ReadRawChar);
ccAddExternalFunctionForPlugin("File::ReadRawInt^0", (void *)File_ReadRawInt);
ccAddExternalFunctionForPlugin("File::ReadRawLine^1", (void *)File_ReadRawLine);
ccAddExternalFunctionForPlugin("File::ReadRawLineBack^0", (void *)File_ReadRawLineBack);
ccAddExternalFunctionForPlugin("File::ReadString^1", (void *)File_ReadString);
ccAddExternalFunctionForPlugin("File::ReadStringBack^0", (void *)File_ReadStringBack);
ccAddExternalFunctionForPlugin("File::WriteInt^1", (void *)File_WriteInt);
ccAddExternalFunctionForPlugin("File::WriteRawChar^1", (void *)File_WriteRawChar);
ccAddExternalFunctionForPlugin("File::WriteRawLine^1", (void *)File_WriteRawLine);
ccAddExternalFunctionForPlugin("File::WriteString^1", (void *)File_WriteString);
ccAddExternalFunctionForPlugin("File::get_EOF", (void *)File_GetEOF);
ccAddExternalFunctionForPlugin("File::get_Error", (void *)File_GetError);
}

View file

@ -41,10 +41,10 @@ void File_WriteString(sc_File *fil, const char *towrite);
void File_WriteInt(sc_File *fil, int towrite);
void File_WriteRawChar(sc_File *fil, int towrite);
void File_WriteRawLine(sc_File *fil, const char *towrite);
void File_ReadRawLine(sc_File *fil, char* buffer);
const char* File_ReadRawLineBack(sc_File *fil);
void File_ReadRawLine(sc_File *fil, char *buffer);
const char *File_ReadRawLineBack(sc_File *fil);
void File_ReadString(sc_File *fil, char *toread);
const char* File_ReadStringBack(sc_File *fil);
const char *File_ReadStringBack(sc_File *fil);
int File_ReadInt(sc_File *fil);
int File_ReadRawChar(sc_File *fil);
int File_ReadRawInt(sc_File *fil);
@ -53,8 +53,7 @@ int File_GetEOF(sc_File *fil);
int File_GetError(sc_File *fil);
int File_GetPosition(sc_File *fil);
struct ScriptFileHandle
{
struct ScriptFileHandle {
Stream *stream;
int32_t handle;
};

File diff suppressed because it is too large Load diff

View file

@ -34,7 +34,12 @@
#include "util/string.h"
// Forward declaration
namespace AGS { namespace Common { class Bitmap; class Stream; } }
namespace AGS {
namespace Common {
class Bitmap;
class Stream;
}
}
using namespace AGS; // FIXME later
#define RAGMODE_PRESERVEGLOBALINT 1
@ -55,8 +60,7 @@ using namespace AGS; // FIXME later
#define GP_NUMINVITEMS 12
#define GP_ISFRAMEFLIPPED 13
enum CutsceneSkipStyle
{
enum CutsceneSkipStyle {
kSkipSceneUndefined = 0,
eSkipSceneEscOnly = 1,
eSkipSceneAnyKey = 2,
@ -92,9 +96,9 @@ bool SetCustomSaveParent(const Common::String &path);
// as a relative to system's user saves directory
bool SetSaveGameDirectoryPath(const char *newFolder, bool explicit_path = false);
int Game_SetSaveGameDirectory(const char *newFolder);
const char* Game_GetSaveSlotDescription(int slnum);
const char *Game_GetSaveSlotDescription(int slnum);
const char* Game_GetGlobalStrings(int index);
const char *Game_GetGlobalStrings(int index);
int Game_GetInventoryItemCount();
int Game_GetFontCount();
@ -108,7 +112,7 @@ int Game_GetSpriteHeight(int spriteNum);
int Game_GetLoopCountForView(int viewNumber);
int Game_GetRunNextSettingForLoop(int viewNumber, int loopNumber);
int Game_GetFrameCountForLoop(int viewNumber, int loopNumber);
ScriptViewFrame* Game_GetViewFrame(int viewNumber, int loopNumber, int frame);
ScriptViewFrame *Game_GetViewFrame(int viewNumber, int loopNumber, int frame);
int Game_DoOnceOnly(const char *token);
int Game_GetTextReadingSpeed();
@ -125,15 +129,15 @@ int Game_GetSkippingCutscene();
int Game_GetInSkippableCutscene();
int Game_GetColorFromRGB(int red, int grn, int blu);
const char* Game_InputBox(const char *msg);
const char* Game_GetLocationName(int x, int y);
const char *Game_InputBox(const char *msg);
const char *Game_GetLocationName(int x, int y);
const char* Game_GetGlobalMessages(int index);
const char *Game_GetGlobalMessages(int index);
int Game_GetSpeechFont();
int Game_GetNormalFont();
const char* Game_GetTranslationFilename();
const char *Game_GetTranslationFilename();
int Game_ChangeTranslation(const char *newFilename);
//=============================================================================
@ -151,7 +155,7 @@ void save_game_dialog();
void free_do_once_tokens();
// Free all the memory associated with the game
void unload_game_file();
void save_game(int slotn, const char*descript);
void save_game(int slotn, const char *descript);
bool read_savedgame_description(const Common::String &savedgame, Common::String &description);
bool read_savedgame_screenshot(const Common::String &savedgame, int &want_shot);
// Tries to restore saved game and displays an error on failure; if the error occured
@ -167,13 +171,13 @@ long write_screen_shot_for_vista(Common::Stream *out, Common::Bitmap *screenshot
bool is_in_cutscene();
CutsceneSkipStyle get_cutscene_skipstyle();
void start_skipping_cutscene ();
void start_skipping_cutscene();
bool check_skip_cutscene_keypress(int kgn);
bool check_skip_cutscene_mclick(int mbut);
void initialize_skippable_cutscene();
void stop_fast_forwarding();
int __GetLocationType(int xxx,int yyy, int allowHotspot0);
int __GetLocationType(int xxx, int yyy, int allowHotspot0);
// Called whenever game looses input focus
void display_switch_out();
@ -184,9 +188,9 @@ void display_switch_out_suspend();
// Called when the game gets input focus and should resume
void display_switch_in_resume();
void replace_tokens(const char*srcmes,char*destm, int maxlen = 99999);
const char *get_global_message (int msnum);
void get_message_text (int msnum, char *buffer, char giveErr = 1);
void replace_tokens(const char *srcmes, char *destm, int maxlen = 99999);
const char *get_global_message(int msnum);
void get_message_text(int msnum, char *buffer, char giveErr = 1);
bool unserialize_audio_script_object(int index, const char *objectType, const char *serializedData, int dataSize);

View file

@ -23,11 +23,10 @@
#include "util/wgt2allg.h" // DIGI_AUTODETECT & MIDI_AUTODETECT
#include "ac/gamesetup.h"
GameSetup::GameSetup()
{
digicard=DIGI_AUTODETECT;
midicard=MIDI_AUTODETECT;
mod_player=1;
GameSetup::GameSetup() {
digicard = DIGI_AUTODETECT;
midicard = MIDI_AUTODETECT;
mod_player = 1;
no_speech_pack = false;
textheight = 0;
enable_antialiasing = false;

View file

@ -28,8 +28,7 @@
// Mouse control activation type
enum MouseControlWhen
{
enum MouseControlWhen {
kMouseCtrl_Never, // never control mouse (track system mouse position)
kMouseCtrl_Fullscreen, // control mouse in fullscreen only
kMouseCtrl_Always, // always control mouse (fullscreen and windowed)
@ -37,8 +36,7 @@ enum MouseControlWhen
};
// Mouse speed definition, specifies how the speed setting is applied to the mouse movement
enum MouseSpeedDef
{
enum MouseSpeedDef {
kMouseSpeed_Absolute, // apply speed multiplier directly
kMouseSpeed_CurrentDisplay, // keep speed/resolution relation based on current system display mode
kNumMouseSpeedDefs

View file

@ -47,30 +47,25 @@ extern RoomStruct thisroom;
extern CharacterInfo *playerchar;
extern ScriptSystem scsystem;
GameState::GameState()
{
GameState::GameState() {
_isAutoRoomViewport = true;
_mainViewportHasChanged = false;
}
void GameState::Free()
{
void GameState::Free() {
raw_drawing_surface.reset();
FreeProperties();
}
bool GameState::IsAutoRoomViewport() const
{
bool GameState::IsAutoRoomViewport() const {
return _isAutoRoomViewport;
}
void GameState::SetAutoRoomViewport(bool on)
{
void GameState::SetAutoRoomViewport(bool on) {
_isAutoRoomViewport = on;
}
void GameState::SetMainViewport(const Rect &viewport)
{
void GameState::SetMainViewport(const Rect &viewport) {
_mainViewport.SetRect(viewport);
Mouse::SetGraphicArea();
scsystem.viewport_width = game_to_data_coord(_mainViewport.GetRect().GetWidth());
@ -78,28 +73,23 @@ void GameState::SetMainViewport(const Rect &viewport)
_mainViewportHasChanged = true;
}
const Rect &GameState::GetMainViewport() const
{
const Rect &GameState::GetMainViewport() const {
return _mainViewport.GetRect();
}
const Rect &GameState::GetUIViewport() const
{
const Rect &GameState::GetUIViewport() const {
return _uiViewport.GetRect();
}
PViewport GameState::GetRoomViewport(int index) const
{
PViewport GameState::GetRoomViewport(int index) const {
return _roomViewports[index];
}
const std::vector<PViewport> &GameState::GetRoomViewportsZOrdered() const
{
const std::vector<PViewport> &GameState::GetRoomViewportsZOrdered() const {
return _roomViewportsSorted;
}
PViewport GameState::GetRoomViewportAt(int x, int y) const
{
PViewport GameState::GetRoomViewportAt(int x, int y) const {
// We iterate backwards, because in AGS low z-order means bottom
for (auto it = _roomViewportsSorted.rbegin(); it != _roomViewportsSorted.rend(); ++it)
if ((*it)->IsVisible() && (*it)->GetRect().IsInside(x, y))
@ -107,51 +97,41 @@ PViewport GameState::GetRoomViewportAt(int x, int y) const
return nullptr;
}
Rect GameState::GetUIViewportAbs() const
{
Rect GameState::GetUIViewportAbs() const {
return Rect::MoveBy(_uiViewport.GetRect(), _mainViewport.GetRect().Left, _mainViewport.GetRect().Top);
}
Rect GameState::GetRoomViewportAbs(int index) const
{
Rect GameState::GetRoomViewportAbs(int index) const {
return Rect::MoveBy(_roomViewports[index]->GetRect(), _mainViewport.GetRect().Left, _mainViewport.GetRect().Top);
}
void GameState::SetUIViewport(const Rect &viewport)
{
void GameState::SetUIViewport(const Rect &viewport) {
_uiViewport.SetRect(viewport);
}
static bool ViewportZOrder(const PViewport e1, const PViewport e2)
{
static bool ViewportZOrder(const PViewport e1, const PViewport e2) {
return e1->GetZOrder() < e2->GetZOrder();
}
void GameState::UpdateViewports()
{
if (_mainViewportHasChanged)
{
void GameState::UpdateViewports() {
if (_mainViewportHasChanged) {
on_mainviewport_changed();
_mainViewportHasChanged = false;
}
if (_roomViewportZOrderChanged)
{
if (_roomViewportZOrderChanged) {
auto old_sort = _roomViewportsSorted;
_roomViewportsSorted = _roomViewports;
std::sort(_roomViewportsSorted.begin(), _roomViewportsSorted.end(), ViewportZOrder);
for (size_t i = 0; i < _roomViewportsSorted.size(); ++i)
{
for (size_t i = 0; i < _roomViewportsSorted.size(); ++i) {
if (i >= old_sort.size() || _roomViewportsSorted[i] != old_sort[i])
_roomViewportsSorted[i]->SetChangedVisible();
}
_roomViewportZOrderChanged = false;
}
size_t vp_changed = -1;
for (size_t i = _roomViewportsSorted.size(); i-- > 0;)
{
for (size_t i = _roomViewportsSorted.size(); i-- > 0;) {
auto vp = _roomViewportsSorted[i];
if (vp->HasChangedSize() || vp->HasChangedPosition() || vp->HasChangedVisible())
{
if (vp->HasChangedSize() || vp->HasChangedPosition() || vp->HasChangedVisible()) {
vp_changed = i;
on_roomviewport_changed(vp.get());
vp->ClearChangedFlags();
@ -159,107 +139,85 @@ void GameState::UpdateViewports()
}
if (vp_changed != -1)
detect_roomviewport_overlaps(vp_changed);
for (auto cam : _roomCameras)
{
if (cam->HasChangedSize() || cam->HasChangedPosition())
{
for (auto cam : _roomCameras) {
if (cam->HasChangedSize() || cam->HasChangedPosition()) {
on_roomcamera_changed(cam.get());
cam->ClearChangedFlags();
}
}
}
void GameState::InvalidateViewportZOrder()
{
void GameState::InvalidateViewportZOrder() {
_roomViewportZOrderChanged = true;
}
PCamera GameState::GetRoomCamera(int index) const
{
PCamera GameState::GetRoomCamera(int index) const {
return _roomCameras[index];
}
void GameState::UpdateRoomCameras()
{
void GameState::UpdateRoomCameras() {
for (size_t i = 0; i < _roomCameras.size(); ++i)
UpdateRoomCamera(i);
}
void GameState::UpdateRoomCamera(int index)
{
void GameState::UpdateRoomCamera(int index) {
auto cam = _roomCameras[index];
const Rect &rc = cam->GetRect();
const Size real_room_sz = Size(data_to_game_coord(thisroom.Width), data_to_game_coord(thisroom.Height));
if ((real_room_sz.Width > rc.GetWidth()) || (real_room_sz.Height > rc.GetHeight()))
{
if ((real_room_sz.Width > rc.GetWidth()) || (real_room_sz.Height > rc.GetHeight())) {
// TODO: split out into Camera Behavior
if (!cam->IsLocked())
{
if (!cam->IsLocked()) {
int x = data_to_game_coord(playerchar->x) - rc.GetWidth() / 2;
int y = data_to_game_coord(playerchar->y) - rc.GetHeight() / 2;
cam->SetAt(x, y);
}
}
else
{
} else {
cam->SetAt(0, 0);
}
}
Point GameState::RoomToScreen(int roomx, int roomy)
{
Point GameState::RoomToScreen(int roomx, int roomy) {
return _roomViewports[0]->RoomToScreen(roomx, roomy, false).first;
}
int GameState::RoomToScreenX(int roomx)
{
int GameState::RoomToScreenX(int roomx) {
return _roomViewports[0]->RoomToScreen(roomx, 0, false).first.X;
}
int GameState::RoomToScreenY(int roomy)
{
int GameState::RoomToScreenY(int roomy) {
return _roomViewports[0]->RoomToScreen(0, roomy, false).first.Y;
}
VpPoint GameState::ScreenToRoomImpl(int scrx, int scry, int view_index, bool clip_viewport, bool convert_cam_to_data)
{
VpPoint GameState::ScreenToRoomImpl(int scrx, int scry, int view_index, bool clip_viewport, bool convert_cam_to_data) {
PViewport view;
if (view_index < 0)
{
if (view_index < 0) {
view = GetRoomViewportAt(scrx, scry);
if (!view)
return std::make_pair(Point(), -1);
}
else
{
} else {
view = _roomViewports[view_index];
}
return view->ScreenToRoom(scrx, scry, clip_viewport, convert_cam_to_data);
}
VpPoint GameState::ScreenToRoom(int scrx, int scry)
{
VpPoint GameState::ScreenToRoom(int scrx, int scry) {
if (game.options[OPT_BASESCRIPTAPI] >= kScriptAPI_v3507)
return ScreenToRoomImpl(scrx, scry, -1, true, false);
return ScreenToRoomImpl(scrx, scry, 0, false, false);
}
VpPoint GameState::ScreenToRoomDivDown(int scrx, int scry)
{
VpPoint GameState::ScreenToRoomDivDown(int scrx, int scry) {
if (game.options[OPT_BASESCRIPTAPI] >= kScriptAPI_v3507)
return ScreenToRoomImpl(scrx, scry, -1, true, true);
return ScreenToRoomImpl(scrx, scry, 0, false, true);
}
void GameState::CreatePrimaryViewportAndCamera()
{
if (_roomViewports.size() == 0)
{
void GameState::CreatePrimaryViewportAndCamera() {
if (_roomViewports.size() == 0) {
play.CreateRoomViewport();
play.RegisterRoomViewport(0);
}
if (_roomCameras.size() == 0)
{
if (_roomCameras.size() == 0) {
play.CreateRoomCamera();
play.RegisterRoomCamera(0);
}
@ -267,8 +225,7 @@ void GameState::CreatePrimaryViewportAndCamera()
_roomCameras[0]->LinkToViewport(_roomViewports[0]);
}
PViewport GameState::CreateRoomViewport()
{
PViewport GameState::CreateRoomViewport() {
int index = (int)_roomViewports.size();
PViewport viewport(new Viewport());
viewport->SetID(index);
@ -282,26 +239,21 @@ PViewport GameState::CreateRoomViewport()
return viewport;
}
ScriptViewport *GameState::RegisterRoomViewport(int index, int32_t handle)
{
ScriptViewport *GameState::RegisterRoomViewport(int index, int32_t handle) {
if (index < 0 || (size_t)index >= _roomViewports.size())
return nullptr;
auto &scobj = _scViewportRefs[index];
if (handle == 0)
{
if (handle == 0) {
handle = ccRegisterManagedObject(scobj.first, scobj.first);
ccAddObjectReference(handle); // one reference for the GameState
}
else
{
} else {
ccRegisterUnserializedObject(handle, scobj.first, scobj.first);
}
scobj.second = handle;
return scobj.first;
}
void GameState::DeleteRoomViewport(int index)
{
void GameState::DeleteRoomViewport(int index) {
// NOTE: viewport 0 can not be deleted
if (index <= 0 || (size_t)index >= _roomViewports.size())
return;
@ -313,15 +265,12 @@ void GameState::DeleteRoomViewport(int index)
cam->UnlinkFromViewport(index);
_roomViewports.erase(_roomViewports.begin() + index);
_scViewportRefs.erase(_scViewportRefs.begin() + index);
for (size_t i = index; i < _roomViewports.size(); ++i)
{
for (size_t i = index; i < _roomViewports.size(); ++i) {
_roomViewports[i]->SetID(i);
_scViewportRefs[i].first->SetID(i);
}
for (size_t i = 0; i < _roomViewportsSorted.size(); ++i)
{
if (_roomViewportsSorted[i]->GetID() == index)
{
for (size_t i = 0; i < _roomViewportsSorted.size(); ++i) {
if (_roomViewportsSorted[i]->GetID() == index) {
_roomViewportsSorted.erase(_roomViewportsSorted.begin() + i);
break;
}
@ -329,13 +278,11 @@ void GameState::DeleteRoomViewport(int index)
on_roomviewport_deleted(index);
}
int GameState::GetRoomViewportCount() const
{
int GameState::GetRoomViewportCount() const {
return (int)_roomViewports.size();
}
PCamera GameState::CreateRoomCamera()
{
PCamera GameState::CreateRoomCamera() {
int index = (int)_roomCameras.size();
PCamera camera(new Camera());
camera->SetID(index);
@ -347,100 +294,83 @@ PCamera GameState::CreateRoomCamera()
return camera;
}
ScriptCamera *GameState::RegisterRoomCamera(int index, int32_t handle)
{
ScriptCamera *GameState::RegisterRoomCamera(int index, int32_t handle) {
if (index < 0 || (size_t)index >= _roomCameras.size())
return nullptr;
auto &scobj = _scCameraRefs[index];
if (handle == 0)
{
if (handle == 0) {
handle = ccRegisterManagedObject(scobj.first, scobj.first);
ccAddObjectReference(handle); // one reference for the GameState
}
else
{
} else {
ccRegisterUnserializedObject(handle, scobj.first, scobj.first);
}
scobj.second = handle;
return scobj.first;
}
void GameState::DeleteRoomCamera(int index)
{
void GameState::DeleteRoomCamera(int index) {
// NOTE: camera 0 can not be deleted
if (index <= 0 || (size_t)index >= _roomCameras.size())
return;
auto scobj = _scCameraRefs[index];
scobj.first->Invalidate();
ccReleaseObjectReference(scobj.second);
for (auto& viewref : _roomCameras[index]->GetLinkedViewports())
{
for (auto &viewref : _roomCameras[index]->GetLinkedViewports()) {
auto view = viewref.lock();
if (view)
view->LinkCamera(nullptr);
}
_roomCameras.erase(_roomCameras.begin() + index);
_scCameraRefs.erase(_scCameraRefs.begin() + index);
for (size_t i = index; i < _roomCameras.size(); ++i)
{
for (size_t i = index; i < _roomCameras.size(); ++i) {
_roomCameras[i]->SetID(i);
_scCameraRefs[i].first->SetID(i);
}
}
int GameState::GetRoomCameraCount() const
{
int GameState::GetRoomCameraCount() const {
return (int)_roomCameras.size();
}
ScriptViewport *GameState::GetScriptViewport(int index)
{
ScriptViewport *GameState::GetScriptViewport(int index) {
if (index < 0 || (size_t)index >= _roomViewports.size())
return NULL;
return _scViewportRefs[index].first;
}
ScriptCamera *GameState::GetScriptCamera(int index)
{
ScriptCamera *GameState::GetScriptCamera(int index) {
if (index < 0 || (size_t)index >= _roomCameras.size())
return NULL;
return _scCameraRefs[index].first;
}
bool GameState::IsIgnoringInput() const
{
bool GameState::IsIgnoringInput() const {
return AGS_Clock::now() < _ignoreUserInputUntilTime;
}
void GameState::SetIgnoreInput(int timeout_ms)
{
void GameState::SetIgnoreInput(int timeout_ms) {
if (AGS_Clock::now() + std::chrono::milliseconds(timeout_ms) > _ignoreUserInputUntilTime)
_ignoreUserInputUntilTime = AGS_Clock::now() + std::chrono::milliseconds(timeout_ms);
}
void GameState::ClearIgnoreInput()
{
void GameState::ClearIgnoreInput() {
_ignoreUserInputUntilTime = AGS_Clock::now();
}
bool GameState::IsBlockingVoiceSpeech() const
{
bool GameState::IsBlockingVoiceSpeech() const {
return speech_has_voice && speech_voice_blocking;
}
bool GameState::IsNonBlockingVoiceSpeech() const
{
bool GameState::IsNonBlockingVoiceSpeech() const {
return speech_has_voice && !speech_voice_blocking;
}
bool GameState::ShouldPlayVoiceSpeech() const
{
bool GameState::ShouldPlayVoiceSpeech() const {
return !play.fast_forward &&
(play.want_speech >= 1) && (!ResPaths.SpeechPak.Name.IsEmpty());
}
void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver, RestoredData &r_data)
{
void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver, RestoredData &r_data) {
const bool old_save = svg_ver < kGSSvgVersion_Initial;
score = in->ReadInt32();
usedmode = in->ReadInt32();
@ -500,7 +430,7 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
min_dialogoption_width = in->ReadInt32();
disable_dialog_parser = in->ReadInt32();
anim_background_speed = in->ReadInt32(); // the setting for this room
top_bar_backcolor= in->ReadInt32();
top_bar_backcolor = in->ReadInt32();
top_bar_textcolor = in->ReadInt32();
top_bar_bordercolor = in->ReadInt32();
top_bar_borderwidth = in->ReadInt32();
@ -531,8 +461,7 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
if (old_save)
in->ReadArrayOfInt32(reserved, GAME_STATE_RESERVED_INTS);
// ** up to here is referenced in the script "game." object
if (old_save)
{
if (old_save) {
in->ReadInt32(); // recording
in->ReadInt32(); // playback
in->ReadInt16(); // gamestep
@ -557,10 +486,9 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
music_repeat = in->ReadInt32();
music_master_volume = in->ReadInt32();
digital_master_volume = in->ReadInt32();
in->Read(walkable_areas_on, MAX_WALK_AREAS+1);
in->Read(walkable_areas_on, MAX_WALK_AREAS + 1);
screen_flipped = in->ReadInt16();
if (svg_ver < kGSSvgVersion_3510)
{
if (svg_ver < kGSSvgVersion_3510) {
short offsets_locked = in->ReadInt16();
if (offsets_locked != 0)
r_data.Camera0_Flags = kSvgCamPosLocked;
@ -581,12 +509,12 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
in_conversation = in->ReadInt32();
screen_tint = in->ReadInt32();
num_parsed_words = in->ReadInt32();
in->ReadArrayOfInt16( parsed_words, MAX_PARSED_WORDS);
in->Read( bad_parsed_word, 100);
in->ReadArrayOfInt16(parsed_words, MAX_PARSED_WORDS);
in->Read(bad_parsed_word, 100);
raw_color = in->ReadInt32();
if (old_save)
in->ReadArrayOfInt32(raw_modified, MAX_ROOM_BGFRAMES);
in->ReadArrayOfInt16( filenumbers, MAXSAVEGAMES);
in->ReadArrayOfInt16(filenumbers, MAXSAVEGAMES);
if (old_save)
in->ReadInt32(); // room_changes
mouse_cursor_hidden = in->ReadInt32();
@ -612,12 +540,10 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
restore_cursor_mode_to = in->ReadInt32();
restore_cursor_image_to = in->ReadInt32();
music_queue_size = in->ReadInt16();
in->ReadArrayOfInt16( music_queue, MAX_QUEUED_MUSIC);
in->ReadArrayOfInt16(music_queue, MAX_QUEUED_MUSIC);
new_music_queue_size = in->ReadInt16();
if (!old_save)
{
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i)
{
if (!old_save) {
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i) {
new_music_queue[i].ReadFromFile(in);
}
}
@ -643,17 +569,14 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
in->ReadInt32(); // gamma_adjustment -- do not apply gamma level from savegame
temporarily_turned_off_character = in->ReadInt16();
inv_backwards_compatibility = in->ReadInt16();
if (old_save)
{
if (old_save) {
in->ReadInt32(); // gui_draw_order
in->ReadInt32(); // do_once_tokens;
}
int num_do_once_tokens = in->ReadInt32();
do_once_tokens.resize(num_do_once_tokens);
if (!old_save)
{
for (int i = 0; i < num_do_once_tokens; ++i)
{
if (!old_save) {
for (int i = 0; i < num_do_once_tokens; ++i) {
StrUtil::ReadString(do_once_tokens[i], in);
}
}
@ -663,16 +586,14 @@ void GameState::ReadFromSavegame(Common::Stream *in, GameStateSvgVersion svg_ver
in->ReadInt32(); // ignore_user_input_until_time -- do not apply from savegame
if (old_save)
in->ReadArrayOfInt32(default_audio_type_volumes, MAX_AUDIO_TYPES);
if (svg_ver >= kGSSvgVersion_3509)
{
if (svg_ver >= kGSSvgVersion_3509) {
int voice_speech_flags = in->ReadInt32();
speech_has_voice = voice_speech_flags != 0;
speech_voice_blocking = (voice_speech_flags & 0x02) != 0;
}
}
void GameState::WriteForSavegame(Common::Stream *out) const
{
void GameState::WriteForSavegame(Common::Stream *out) const {
// NOTE: following parameters are never saved:
// recording, playback, gamestep, screen_is_faded_out, room_changes
out->WriteInt32(score);
@ -757,97 +678,95 @@ void GameState::WriteForSavegame(Common::Stream *out) const
out->WriteInt32(dialog_options_highlight_color);
// ** up to here is referenced in the script "game." object
out->WriteInt32(randseed); // random seed
out->WriteInt32( player_on_region); // player's current region
out->WriteInt32( check_interaction_only);
out->WriteInt32( bg_frame);
out->WriteInt32( bg_anim_delay); // for animating backgrounds
out->WriteInt32( music_vol_was); // before the volume drop
out->WriteInt32(player_on_region); // player's current region
out->WriteInt32(check_interaction_only);
out->WriteInt32(bg_frame);
out->WriteInt32(bg_anim_delay); // for animating backgrounds
out->WriteInt32(music_vol_was); // before the volume drop
out->WriteInt16(wait_counter);
out->WriteInt16(mboundx1);
out->WriteInt16(mboundx2);
out->WriteInt16(mboundy1);
out->WriteInt16(mboundy2);
out->WriteInt32( fade_effect);
out->WriteInt32( bg_frame_locked);
out->WriteInt32(fade_effect);
out->WriteInt32(bg_frame_locked);
out->WriteArrayOfInt32(globalscriptvars, MAXGSVALUES);
out->WriteInt32( cur_music_number);
out->WriteInt32( music_repeat);
out->WriteInt32( music_master_volume);
out->WriteInt32( digital_master_volume);
out->Write(walkable_areas_on, MAX_WALK_AREAS+1);
out->WriteInt16( screen_flipped);
out->WriteInt32( entered_at_x);
out->WriteInt32( entered_at_y);
out->WriteInt32( entered_edge);
out->WriteInt32( want_speech);
out->WriteInt32( cant_skip_speech);
out->WriteInt32(cur_music_number);
out->WriteInt32(music_repeat);
out->WriteInt32(music_master_volume);
out->WriteInt32(digital_master_volume);
out->Write(walkable_areas_on, MAX_WALK_AREAS + 1);
out->WriteInt16(screen_flipped);
out->WriteInt32(entered_at_x);
out->WriteInt32(entered_at_y);
out->WriteInt32(entered_edge);
out->WriteInt32(want_speech);
out->WriteInt32(cant_skip_speech);
out->WriteArrayOfInt32(script_timers, MAX_TIMERS);
out->WriteInt32( sound_volume);
out->WriteInt32( speech_volume);
out->WriteInt32( normal_font);
out->WriteInt32( speech_font);
out->WriteInt8( key_skip_wait);
out->WriteInt32( swap_portrait_lastchar);
out->WriteInt32( separate_music_lib);
out->WriteInt32( in_conversation);
out->WriteInt32( screen_tint);
out->WriteInt32( num_parsed_words);
out->WriteArrayOfInt16( parsed_words, MAX_PARSED_WORDS);
out->Write( bad_parsed_word, 100);
out->WriteInt32( raw_color);
out->WriteArrayOfInt16( filenumbers, MAXSAVEGAMES);
out->WriteInt32( mouse_cursor_hidden);
out->WriteInt32( silent_midi);
out->WriteInt32( silent_midi_channel);
out->WriteInt32( current_music_repeating);
out->WriteInt32( shakesc_delay);
out->WriteInt32( shakesc_amount);
out->WriteInt32( shakesc_length);
out->WriteInt32( rtint_red);
out->WriteInt32( rtint_green);
out->WriteInt32( rtint_blue);
out->WriteInt32( rtint_level);
out->WriteInt32( rtint_light);
out->WriteInt32(sound_volume);
out->WriteInt32(speech_volume);
out->WriteInt32(normal_font);
out->WriteInt32(speech_font);
out->WriteInt8(key_skip_wait);
out->WriteInt32(swap_portrait_lastchar);
out->WriteInt32(separate_music_lib);
out->WriteInt32(in_conversation);
out->WriteInt32(screen_tint);
out->WriteInt32(num_parsed_words);
out->WriteArrayOfInt16(parsed_words, MAX_PARSED_WORDS);
out->Write(bad_parsed_word, 100);
out->WriteInt32(raw_color);
out->WriteArrayOfInt16(filenumbers, MAXSAVEGAMES);
out->WriteInt32(mouse_cursor_hidden);
out->WriteInt32(silent_midi);
out->WriteInt32(silent_midi_channel);
out->WriteInt32(current_music_repeating);
out->WriteInt32(shakesc_delay);
out->WriteInt32(shakesc_amount);
out->WriteInt32(shakesc_length);
out->WriteInt32(rtint_red);
out->WriteInt32(rtint_green);
out->WriteInt32(rtint_blue);
out->WriteInt32(rtint_level);
out->WriteInt32(rtint_light);
out->WriteBool(rtint_enabled);
out->WriteInt32( end_cutscene_music);
out->WriteInt32( skip_until_char_stops);
out->WriteInt32( get_loc_name_last_time);
out->WriteInt32( get_loc_name_save_cursor);
out->WriteInt32( restore_cursor_mode_to);
out->WriteInt32( restore_cursor_image_to);
out->WriteInt16( music_queue_size);
out->WriteArrayOfInt16( music_queue, MAX_QUEUED_MUSIC);
out->WriteInt32(end_cutscene_music);
out->WriteInt32(skip_until_char_stops);
out->WriteInt32(get_loc_name_last_time);
out->WriteInt32(get_loc_name_save_cursor);
out->WriteInt32(restore_cursor_mode_to);
out->WriteInt32(restore_cursor_image_to);
out->WriteInt16(music_queue_size);
out->WriteArrayOfInt16(music_queue, MAX_QUEUED_MUSIC);
out->WriteInt16(new_music_queue_size);
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i)
{
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i) {
new_music_queue[i].WriteToFile(out);
}
out->WriteInt16( crossfading_out_channel);
out->WriteInt16( crossfade_step);
out->WriteInt16( crossfade_out_volume_per_step);
out->WriteInt16( crossfade_initial_volume_out);
out->WriteInt16( crossfading_in_channel);
out->WriteInt16( crossfade_in_volume_per_step);
out->WriteInt16( crossfade_final_volume_in);
out->WriteInt16(crossfading_out_channel);
out->WriteInt16(crossfade_step);
out->WriteInt16(crossfade_out_volume_per_step);
out->WriteInt16(crossfade_initial_volume_out);
out->WriteInt16(crossfading_in_channel);
out->WriteInt16(crossfade_in_volume_per_step);
out->WriteInt16(crossfade_final_volume_in);
out->Write(takeover_from, 50);
out->Write(playmp3file_name, PLAYMP3FILE_MAX_FILENAME_LEN);
out->Write(globalstrings, MAXGLOBALSTRINGS * MAX_MAXSTRLEN);
out->Write(lastParserEntry, MAX_MAXSTRLEN);
out->Write(game_name, 100);
out->WriteInt32( ground_level_areas_disabled);
out->WriteInt32( next_screen_transition);
out->WriteInt32( gamma_adjustment);
out->WriteInt32(ground_level_areas_disabled);
out->WriteInt32(next_screen_transition);
out->WriteInt32(gamma_adjustment);
out->WriteInt16(temporarily_turned_off_character);
out->WriteInt16(inv_backwards_compatibility);
out->WriteInt32(do_once_tokens.size());
for (int i = 0; i < (int)do_once_tokens.size(); ++i)
{
for (int i = 0; i < (int)do_once_tokens.size(); ++i) {
StrUtil::WriteString(do_once_tokens[i], out);
}
out->WriteInt32( text_min_display_time_ms);
out->WriteInt32( ignore_user_input_after_text_timeout_ms);
out->WriteInt32(text_min_display_time_ms);
out->WriteInt32(ignore_user_input_after_text_timeout_ms);
int voice_speech_flags = speech_has_voice ? 0x01 : 0;
if (speech_voice_blocking)
@ -855,47 +774,39 @@ void GameState::WriteForSavegame(Common::Stream *out) const
out->WriteInt32(voice_speech_flags);
}
void GameState::ReadQueuedAudioItems_Aligned(Common::Stream *in)
{
void GameState::ReadQueuedAudioItems_Aligned(Common::Stream *in) {
AlignedStream align_s(in, Common::kAligned_Read);
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i)
{
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i) {
new_music_queue[i].ReadFromFile(&align_s);
align_s.Reset();
}
}
void GameState::FreeProperties()
{
void GameState::FreeProperties() {
for (auto &p : charProps)
p.clear();
for (auto &p : invProps)
p.clear();
}
void GameState::FreeViewportsAndCameras()
{
void GameState::FreeViewportsAndCameras() {
_roomViewports.clear();
_roomViewportsSorted.clear();
for (auto &scobj : _scViewportRefs)
{
for (auto &scobj : _scViewportRefs) {
scobj.first->Invalidate();
ccReleaseObjectReference(scobj.second);
}
_scViewportRefs.clear();
_roomCameras.clear();
for (auto &scobj : _scCameraRefs)
{
for (auto &scobj : _scCameraRefs) {
scobj.first->Invalidate();
ccReleaseObjectReference(scobj.second);
}
_scCameraRefs.clear();
}
void GameState::ReadCustomProperties_v340(Common::Stream *in)
{
if (loaded_game_file_version >= kGameVersion_340_4)
{
void GameState::ReadCustomProperties_v340(Common::Stream *in) {
if (loaded_game_file_version >= kGameVersion_340_4) {
// After runtime property values were read we also copy missing default,
// because we do not keep defaults in the saved game, and also in case
// this save is made by an older game version which had different
@ -907,10 +818,8 @@ void GameState::ReadCustomProperties_v340(Common::Stream *in)
}
}
void GameState::WriteCustomProperties_v340(Common::Stream *out) const
{
if (loaded_game_file_version >= kGameVersion_340_4)
{
void GameState::WriteCustomProperties_v340(Common::Stream *out) const {
if (loaded_game_file_version >= kGameVersion_340_4) {
// We temporarily remove properties that kept default values
// just for the saving data time to avoid getting lots of
// redundant data into saved games
@ -922,13 +831,14 @@ void GameState::WriteCustomProperties_v340(Common::Stream *out) const
}
// Converts legacy alignment type used in script API
HorAlignment ConvertLegacyScriptAlignment(LegacyScriptAlignment align)
{
switch (align)
{
case kLegacyScAlignLeft: return kHAlignLeft;
case kLegacyScAlignCentre: return kHAlignCenter;
case kLegacyScAlignRight: return kHAlignRight;
HorAlignment ConvertLegacyScriptAlignment(LegacyScriptAlignment align) {
switch (align) {
case kLegacyScAlignLeft:
return kHAlignLeft;
case kLegacyScAlignCentre:
return kHAlignCenter;
case kLegacyScAlignRight:
return kHAlignRight;
}
return kHAlignNone;
}
@ -936,8 +846,7 @@ HorAlignment ConvertLegacyScriptAlignment(LegacyScriptAlignment align)
// Reads legacy alignment type from the value set in script depending on the
// current Script API level. This is made to make it possible to change
// Alignment constants in the Script API and still support old version.
HorAlignment ReadScriptAlignment(int32_t align)
{
HorAlignment ReadScriptAlignment(int32_t align) {
return game.options[OPT_BASESCRIPTAPI] < kScriptAPI_v350 ?
ConvertLegacyScriptAlignment((LegacyScriptAlignment)align) :
(HorAlignment)align;

View file

@ -37,14 +37,15 @@
#include "ac/timer.h"
// Forward declaration
namespace AGS
{
namespace Common
{
class Bitmap; class Stream;
typedef std::shared_ptr<Bitmap> PBitmap;
}
namespace Engine { struct RestoredData; }
namespace AGS {
namespace Common {
class Bitmap;
class Stream;
typedef std::shared_ptr<Bitmap> PBitmap;
}
namespace Engine {
struct RestoredData;
}
}
using namespace AGS; // FIXME later
struct ScriptViewport;
@ -53,8 +54,7 @@ struct ScriptCamera;
#define GAME_STATE_RESERVED_INTS 5
// Savegame data format
enum GameStateSvgVersion
{
enum GameStateSvgVersion {
kGSSvgVersion_OldFormat = -1, // TODO: remove after old save support is dropped
kGSSvgVersion_Initial = 0,
kGSSvgVersion_350 = 1,
@ -74,11 +74,11 @@ struct GameState {
int globalvars[MAXGLOBALVARS]; // obsolete
int messagetime; // time left for auto-remove messages
int usedinv; // inventory item last used
int inv_top,inv_numdisp,obsolete_inv_numorder,inv_numinline;
int inv_top, inv_numdisp, obsolete_inv_numorder, inv_numinline;
int text_speed; // how quickly text is removed
int sierra_inv_color; // background used to paint defualt inv window
int talkanim_speed; // animation speed of talking anims
int inv_item_wid,inv_item_hit; // set by SetInvDimensions
int inv_item_wid, inv_item_hit; // set by SetInvDimensions
int speech_text_shadow; // colour of outline fonts (default black)
int swap_portrait_side; // sierra-style speech swap sides
int speech_textwindow_gui; // textwindow used for sierra-style speech
@ -151,25 +151,25 @@ struct GameState {
int player_on_region; // player's current region
int screen_is_faded_out; // the screen is currently black
int check_interaction_only;
int bg_frame,bg_anim_delay; // for animating backgrounds
int bg_frame, bg_anim_delay; // for animating backgrounds
int music_vol_was; // before the volume drop
short wait_counter;
char wait_skipped_by; // tells how last wait was skipped [not serialized]
int wait_skipped_by_data; // extended data telling how last wait was skipped [not serialized]
short mboundx1,mboundx2,mboundy1,mboundy2;
short mboundx1, mboundx2, mboundy1, mboundy2;
int fade_effect;
int bg_frame_locked;
int globalscriptvars[MAXGSVALUES];
int cur_music_number,music_repeat;
int cur_music_number, music_repeat;
int music_master_volume;
int digital_master_volume;
char walkable_areas_on[MAX_WALK_AREAS+1];
char walkable_areas_on[MAX_WALK_AREAS + 1];
short screen_flipped;
int entered_at_x,entered_at_y, entered_edge;
int entered_at_x, entered_at_y, entered_edge;
int want_speech;
int cant_skip_speech;
int script_timers[MAX_TIMERS];
int sound_volume,speech_volume;
int sound_volume, speech_volume;
int normal_font, speech_font;
char key_skip_wait;
int swap_portrait_lastchar;
@ -380,8 +380,8 @@ private:
// Script viewports and cameras are references to real data export to
// user script. They became invalidated as the actual object gets
// destroyed, but are kept in memory to prevent script errors.
std::vector<std::pair<ScriptViewport*, int32_t>> _scViewportRefs;
std::vector<std::pair<ScriptCamera*, int32_t>> _scCameraRefs;
std::vector<std::pair<ScriptViewport *, int32_t>> _scViewportRefs;
std::vector<std::pair<ScriptCamera *, int32_t>> _scCameraRefs;
// Tells that the main viewport's position has changed since last game update
bool _mainViewportHasChanged;

File diff suppressed because it is too large Load diff

View file

@ -45,7 +45,7 @@ extern RoomStruct thisroom;
extern SpeechLipSyncLine *splipsync;
extern int numLipLines, curLipLine, curLipLinePhoneme;
void StopAmbientSound (int channel) {
void StopAmbientSound(int channel) {
if ((channel < 0) || (channel >= MAX_SOUND_CHANNELS))
quit("!StopAmbientSound: invalid channel");
@ -56,7 +56,7 @@ void StopAmbientSound (int channel) {
ambient[channel].channel = 0;
}
void PlayAmbientSound (int channel, int sndnum, int vol, int x, int y) {
void PlayAmbientSound(int channel, int sndnum, int vol, int x, int y) {
// the channel parameter is to allow multiple ambient sounds in future
if ((channel < 1) || (channel == SCHAN_SPEECH) || (channel >= MAX_SOUND_CHANNELS))
quit("!PlayAmbientSound: invalid channel number");
@ -77,7 +77,7 @@ void PlayAmbientSound (int channel, int sndnum, int vol, int x, int y) {
SOUNDCLIP *asound = aclip ? load_sound_and_play(aclip, true) : nullptr;
if (asound == nullptr) {
debug_script_warn ("Cannot load ambient sound %d", sndnum);
debug_script_warn("Cannot load ambient sound %d", sndnum);
debug_script_log("FAILED to load ambient sound %d", sndnum);
return;
}
@ -141,7 +141,7 @@ int PlaySoundEx(int val1, int channel) {
StopAmbientSound(channel);
if (val1 < 0) {
stop_and_destroy_channel (channel);
stop_and_destroy_channel(channel);
return -1;
}
// if skipping a cutscene, don't try and play the sound
@ -149,7 +149,7 @@ int PlaySoundEx(int val1, int channel) {
return -1;
// free the old sound
stop_and_destroy_channel (channel);
stop_and_destroy_channel(channel);
debug_script_log("Playing sound %d on channel %d", val1, channel);
SOUNDCLIP *soundfx = aclip ? load_sound_and_play(aclip, false) : nullptr;
@ -160,8 +160,8 @@ int PlaySoundEx(int val1, int channel) {
}
soundfx->priority = 10;
soundfx->set_volume (play.sound_volume);
set_clip_to_channel(channel,soundfx);
soundfx->set_volume(play.sound_volume);
set_clip_to_channel(channel, soundfx);
return channel;
}
@ -178,7 +178,7 @@ void PlayMusicResetQueue(int newmus) {
newmusic(newmus);
}
void SeekMIDIPosition (int position) {
void SeekMIDIPosition(int position) {
if (play.silent_midi == 0 && current_music_type != MUS_MIDI)
return;
@ -188,14 +188,14 @@ void SeekMIDIPosition (int position) {
debug_script_log("Seek MIDI position to %d", position);
}
int GetMIDIPosition () {
int GetMIDIPosition() {
if (play.fast_forward)
return 99999;
if (play.silent_midi == 0 && current_music_type != MUS_MIDI)
return -1; // returns -1 on failure according to old manuals
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
auto *ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
if (ch) {
return ch->get_pos();
}
@ -214,8 +214,8 @@ int IsMusicPlaying() {
AudioChannelsLock lock;
auto *ch = lock.GetChannel(SCHAN_MUSIC);
if (ch == nullptr)
{ // This was probably a hacky fix in case it was not reset by game update; TODO: find out if needed
if (ch == nullptr) {
// This was probably a hacky fix in case it was not reset by game update; TODO: find out if needed
current_music_type = 0;
return 0;
}
@ -249,8 +249,7 @@ int PlayMusicQueued(int musnum) {
if (play.music_repeat) {
debug_script_log("Queuing music %d to loop", musnum);
musnum += QUEUED_MUSIC_REPEAT;
}
else {
} else {
debug_script_log("Queuing music %d", musnum);
}
@ -277,14 +276,14 @@ void SeekMODPattern(int patnum) {
return;
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
auto *ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
if (ch) {
ch->seek (patnum);
ch->seek(patnum);
debug_script_log("Seek MOD/XM to pattern %d", patnum);
}
}
void SeekMP3PosMillis (int posn) {
void SeekMP3PosMillis(int posn) {
if (current_music_type != MUS_MP3 && current_music_type != MUS_OGG)
return;
@ -297,7 +296,7 @@ void SeekMP3PosMillis (int posn) {
mus_ch->seek(posn);
}
int GetMP3PosMillis () {
int GetMP3PosMillis() {
// in case they have "while (GetMP3PosMillis() < 5000) "
if (play.fast_forward)
return 999999;
@ -305,13 +304,13 @@ int GetMP3PosMillis () {
return 0; // returns 0 on failure according to old manuals
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
auto *ch = lock.GetChannelIfPlaying(SCHAN_MUSIC);
if (ch) {
int result = ch->get_pos_ms();
if (result >= 0)
return result;
return ch->get_pos ();
return ch->get_pos();
}
return 0;
@ -320,52 +319,51 @@ int GetMP3PosMillis () {
void SetMusicVolume(int newvol) {
if ((newvol < kRoomVolumeMin) || (newvol > kRoomVolumeMax))
quitprintf("!SetMusicVolume: invalid volume number. Must be from %d to %d.", kRoomVolumeMin, kRoomVolumeMax);
thisroom.Options.MusicVolume=(RoomVolumeMod)newvol;
thisroom.Options.MusicVolume = (RoomVolumeMod)newvol;
update_music_volume();
}
void SetMusicMasterVolume(int newvol) {
const int min_volume = loaded_game_file_version < kGameVersion_330 ? 0 :
-LegacyMusicMasterVolumeAdjustment - (kRoomVolumeMax * LegacyRoomVolumeFactor);
if ((newvol < min_volume) | (newvol>100))
if ((newvol < min_volume) | (newvol > 100))
quitprintf("!SetMusicMasterVolume: invalid volume - must be from %d to %d", min_volume, 100);
play.music_master_volume=newvol+LegacyMusicMasterVolumeAdjustment;
play.music_master_volume = newvol + LegacyMusicMasterVolumeAdjustment;
update_music_volume();
}
void SetSoundVolume(int newvol) {
if ((newvol<0) | (newvol>255))
if ((newvol < 0) | (newvol > 255))
quit("!SetSoundVolume: invalid volume - must be from 0-255");
play.sound_volume = newvol;
Game_SetAudioTypeVolume(AUDIOTYPE_LEGACY_AMBIENT_SOUND, (newvol * 100) / 255, VOL_BOTH);
Game_SetAudioTypeVolume(AUDIOTYPE_LEGACY_SOUND, (newvol * 100) / 255, VOL_BOTH);
update_ambient_sound_vol ();
update_ambient_sound_vol();
}
void SetChannelVolume(int chan, int newvol) {
if ((newvol<0) || (newvol>255))
if ((newvol < 0) || (newvol > 255))
quit("!SetChannelVolume: invalid volume - must be from 0-255");
if ((chan < 0) || (chan >= MAX_SOUND_CHANNELS))
quit("!SetChannelVolume: invalid channel id");
AudioChannelsLock lock;
auto* ch = lock.GetChannelIfPlaying(chan);
auto *ch = lock.GetChannelIfPlaying(chan);
if (ch) {
if (chan == ambient[chan].channel) {
ambient[chan].vol = newvol;
update_ambient_sound_vol();
}
else
ch->set_volume (newvol);
} else
ch->set_volume(newvol);
}
}
void SetDigitalMasterVolume (int newvol) {
if ((newvol<0) | (newvol>100))
void SetDigitalMasterVolume(int newvol) {
if ((newvol < 0) | (newvol > 100))
quit("!SetDigitalMasterVolume: invalid volume - must be from 0-100");
play.digital_master_volume = newvol;
set_volume ((newvol * 255) / 100, -1);
set_volume((newvol * 255) / 100, -1);
}
int GetCurrentMusic() {
@ -373,10 +371,10 @@ int GetCurrentMusic() {
}
void SetMusicRepeat(int loopflag) {
play.music_repeat=loopflag;
play.music_repeat = loopflag;
}
void PlayMP3File (const char *filename) {
void PlayMP3File(const char *filename) {
if (strlen(filename) >= PLAYMP3FILE_MAX_FILENAME_LEN)
quit("!PlayMP3File: filename too long");
@ -384,7 +382,7 @@ void PlayMP3File (const char *filename) {
AssetPath asset_name("", filename);
int useChan = prepare_for_new_music ();
int useChan = prepare_for_new_music();
bool doLoop = (play.music_repeat > 0);
SOUNDCLIP *clip = nullptr;
@ -398,7 +396,7 @@ void PlayMP3File (const char *filename) {
play.cur_music_number = 1000;
// save the filename (if it's not what we were supplied with)
if (filename != &play.playmp3file_name[0])
strcpy (play.playmp3file_name, filename);
strcpy(play.playmp3file_name, filename);
} else {
clip->destroy();
delete clip;
@ -407,8 +405,7 @@ void PlayMP3File (const char *filename) {
}
}
if (!clip)
{
if (!clip) {
clip = my_load_static_mp3(asset_name, 150, doLoop);
if (clip) {
if (clip->play()) {
@ -428,7 +425,7 @@ void PlayMP3File (const char *filename) {
if (!clip) {
set_clip_to_channel(useChan, nullptr);
debug_script_warn ("PlayMP3File: file '%s' not found or cannot play", filename);
debug_script_warn("PlayMP3File: file '%s' not found or cannot play", filename);
}
post_new_music_check(useChan);
@ -436,11 +433,11 @@ void PlayMP3File (const char *filename) {
update_music_volume();
}
void PlaySilentMIDI (int mnum) {
void PlaySilentMIDI(int mnum) {
if (current_music_type == MUS_MIDI)
quit("!PlaySilentMIDI: proper midi music is in progress");
set_volume (-1, 0);
set_volume(-1, 0);
play.silent_midi = mnum;
play.silent_midi_channel = SCHAN_SPEECH;
stop_and_destroy_channel(play.silent_midi_channel);
@ -450,8 +447,7 @@ void PlaySilentMIDI (int mnum) {
stop_voice_nonblocking();
SOUNDCLIP *clip = load_sound_clip_from_old_style_number(true, mnum, false);
if (clip == nullptr)
{
if (clip == nullptr) {
quitprintf("!PlaySilentMIDI: failed to load aMusic%d", mnum);
}
AudioChannelsLock lock;
@ -466,20 +462,20 @@ void PlaySilentMIDI (int mnum) {
}
void SetSpeechVolume(int newvol) {
if ((newvol<0) | (newvol>255))
if ((newvol < 0) | (newvol > 255))
quit("!SetSpeechVolume: invalid volume - must be from 0-255");
AudioChannelsLock lock;
auto* ch = lock.GetChannel(SCHAN_SPEECH);
auto *ch = lock.GetChannel(SCHAN_SPEECH);
if (ch)
ch->set_volume (newvol);
ch->set_volume(newvol);
play.speech_volume = newvol;
}
// 0 = text only
// 1 = voice & text
// 2 = voice only
void SetVoiceMode (int newmod) {
void SetVoiceMode(int newmod) {
if ((newmod < 0) | (newmod > 2))
quit("!SetVoiceMode: invalid mode number (must be 0,1,2)");
// If speech is turned off, store the mode anyway in case the
@ -490,8 +486,7 @@ void SetVoiceMode (int newmod) {
play.want_speech = newmod;
}
int GetVoiceMode()
{
int GetVoiceMode() {
return play.want_speech >= 0 ? play.want_speech : -(play.want_speech + 1);
}
@ -501,33 +496,28 @@ int IsVoxAvailable() {
return 1;
}
int IsMusicVoxAvailable () {
int IsMusicVoxAvailable() {
return play.separate_music_lib;
}
extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1];
ScriptAudioChannel *PlayVoiceClip(CharacterInfo *ch, int sndid, bool as_speech)
{
ScriptAudioChannel *PlayVoiceClip(CharacterInfo *ch, int sndid, bool as_speech) {
if (!play_voice_nonblocking(ch->index_id, sndid, as_speech))
return NULL;
return &scrAudioChannel[SCHAN_SPEECH];
}
// Construct an asset name for the voice-over clip for the given character and cue id
String get_cue_filename(int charid, int sndid)
{
String get_cue_filename(int charid, int sndid) {
String script_name;
if (charid >= 0)
{
if (charid >= 0) {
// append the first 4 characters of the script name to the filename
if (game.chars[charid].scrname[0] == 'c')
script_name.SetString(&game.chars[charid].scrname[1], 4);
else
script_name.SetString(game.chars[charid].scrname, 4);
}
else
{
} else {
script_name = "NARR";
}
return String::FromFormat("%s%d", script_name.GetCStr(), sndid);
@ -535,8 +525,7 @@ String get_cue_filename(int charid, int sndid)
// Play voice-over clip on the common channel;
// voice_name should be bare clip name without extension
static bool play_voice_clip_on_channel(const String &voice_name)
{
static bool play_voice_clip_on_channel(const String &voice_name) {
stop_and_destroy_channel(SCHAN_SPEECH);
String asset_name = voice_name;
@ -567,14 +556,13 @@ static bool play_voice_clip_on_channel(const String &voice_name)
return false;
}
set_clip_to_channel(SCHAN_SPEECH,speechmp3);
set_clip_to_channel(SCHAN_SPEECH, speechmp3);
return true;
}
// Play voice-over clip and adjust audio volumes;
// voice_name should be bare clip name without extension
static bool play_voice_clip_impl(const String &voice_name, bool as_speech, bool is_blocking)
{
static bool play_voice_clip_impl(const String &voice_name, bool as_speech, bool is_blocking) {
if (!play_voice_clip_on_channel(voice_name))
return false;
if (!as_speech)
@ -597,8 +585,7 @@ static bool play_voice_clip_impl(const String &voice_name, bool as_speech, bool
}
// Stop voice-over clip and schedule audio volume reset
static void stop_voice_clip_impl()
{
static void stop_voice_clip_impl() {
play.music_master_volume = play.music_vol_was;
// update the music in a bit (fixes two speeches follow each other
// and music going up-then-down)
@ -606,8 +593,7 @@ static void stop_voice_clip_impl()
stop_and_destroy_channel(SCHAN_SPEECH);
}
bool play_voice_speech(int charid, int sndid)
{
bool play_voice_speech(int charid, int sndid) {
// don't play speech if we're skipping a cutscene
if (!play.ShouldPlayVoiceSpeech())
return false;
@ -639,8 +625,7 @@ bool play_voice_speech(int charid, int sndid)
return true;
}
bool play_voice_nonblocking(int charid, int sndid, bool as_speech)
{
bool play_voice_nonblocking(int charid, int sndid, bool as_speech) {
// don't play voice if we're skipping a cutscene
if (!play.ShouldPlayVoiceSpeech())
return false;
@ -652,8 +637,7 @@ bool play_voice_nonblocking(int charid, int sndid, bool as_speech)
return play_voice_clip_impl(voice_file, as_speech, false);
}
void stop_voice_speech()
{
void stop_voice_speech() {
if (!play.speech_has_voice)
return;
@ -662,8 +646,7 @@ void stop_voice_speech()
// Reset lipsync
curLipLine = -1;
// Set back to Sierra w/bgrnd
if (play.no_textbg_when_voice == 2)
{
if (play.no_textbg_when_voice == 2) {
play.no_textbg_when_voice = 1;
game.options[OPT_SPEECHTYPE] = 2;
}
@ -671,8 +654,7 @@ void stop_voice_speech()
play.speech_voice_blocking = false;
}
void stop_voice_nonblocking()
{
void stop_voice_nonblocking() {
if (!play.speech_has_voice)
return;
stop_voice_clip_impl();
@ -680,8 +662,7 @@ void stop_voice_nonblocking()
// otherwise we might be inside blocking speech function and should let
// it keep these flags to be able to finalize properly.
// This is an imperfection of current speech implementation.
if (!play.speech_voice_blocking)
{
if (!play.speech_voice_blocking) {
play.speech_has_voice = false;
play.speech_voice_blocking = false;
}

View file

@ -23,8 +23,8 @@
#ifndef AGS_ENGINE_AC_GLOBALAUDIO_H
#define AGS_ENGINE_AC_GLOBALAUDIO_H
void StopAmbientSound (int channel);
void PlayAmbientSound (int channel, int sndnum, int vol, int x, int y);
void StopAmbientSound(int channel);
void PlayAmbientSound(int channel, int sndnum, int vol, int x, int y);
int IsChannelPlaying(int chan);
int IsSoundPlaying();
// returns -1 on failure, channel number on success
@ -32,29 +32,29 @@ int PlaySoundEx(int val1, int channel);
void StopAllSounds(int evenAmbient);
void PlayMusicResetQueue(int newmus);
void SeekMIDIPosition (int position);
int GetMIDIPosition ();
void SeekMIDIPosition(int position);
int GetMIDIPosition();
int IsMusicPlaying();
int PlayMusicQueued(int musnum);
void scr_StopMusic();
void SeekMODPattern(int patnum);
void SeekMP3PosMillis (int posn);
int GetMP3PosMillis ();
void SeekMP3PosMillis(int posn);
int GetMP3PosMillis();
void SetMusicVolume(int newvol);
void SetMusicMasterVolume(int newvol);
void SetSoundVolume(int newvol);
void SetChannelVolume(int chan, int newvol);
void SetDigitalMasterVolume (int newvol);
void SetDigitalMasterVolume(int newvol);
int GetCurrentMusic();
void SetMusicRepeat(int loopflag);
void PlayMP3File (const char *filename);
void PlaySilentMIDI (int mnum);
void PlayMP3File(const char *filename);
void PlaySilentMIDI(int mnum);
void SetSpeechVolume(int newvol);
void SetVoiceMode (int newmod);
int GetVoiceMode ();
void SetVoiceMode(int newmod);
int GetVoiceMode();
int IsVoxAvailable();
int IsMusicVoxAvailable ();
int IsMusicVoxAvailable();
struct CharacterInfo;
struct ScriptAudioChannel;

View file

@ -32,76 +32,71 @@ using namespace AGS::Common;
extern GameSetupStruct game;
void SetButtonText(int guin,int objn, const char*newtx) {
void SetButtonText(int guin, int objn, const char *newtx) {
VALIDATE_STRING(newtx);
if ((guin<0) | (guin>=game.numgui))
if ((guin < 0) | (guin >= game.numgui))
quit("!SetButtonText: invalid GUI number");
if ((objn<0) | (objn>=guis[guin].GetControlCount()))
if ((objn < 0) | (objn >= guis[guin].GetControlCount()))
quit("!SetButtonText: invalid object number");
if (guis[guin].GetControlType(objn)!=kGUIButton)
if (guis[guin].GetControlType(objn) != kGUIButton)
quit("!SetButtonText: specified control is not a button");
GUIButton*guil=(GUIButton*)guis[guin].GetControl(objn);
GUIButton *guil = (GUIButton *)guis[guin].GetControl(objn);
Button_SetText(guil, newtx);
}
void AnimateButton(int guin, int objn, int view, int loop, int speed, int repeat) {
if ((guin<0) | (guin>=game.numgui)) quit("!AnimateButton: invalid GUI number");
if ((objn<0) | (objn>=guis[guin].GetControlCount())) quit("!AnimateButton: invalid object number");
if (guis[guin].GetControlType(objn)!=kGUIButton)
if ((guin < 0) | (guin >= game.numgui)) quit("!AnimateButton: invalid GUI number");
if ((objn < 0) | (objn >= guis[guin].GetControlCount())) quit("!AnimateButton: invalid object number");
if (guis[guin].GetControlType(objn) != kGUIButton)
quit("!AnimateButton: specified control is not a button");
Button_Animate((GUIButton*)guis[guin].GetControl(objn), view, loop, speed, repeat);
Button_Animate((GUIButton *)guis[guin].GetControl(objn), view, loop, speed, repeat);
}
int GetButtonPic(int guin, int objn, int ptype) {
if ((guin<0) | (guin>=game.numgui)) quit("!GetButtonPic: invalid GUI number");
if ((objn<0) | (objn>=guis[guin].GetControlCount())) quit("!GetButtonPic: invalid object number");
if (guis[guin].GetControlType(objn)!=kGUIButton)
if ((guin < 0) | (guin >= game.numgui)) quit("!GetButtonPic: invalid GUI number");
if ((objn < 0) | (objn >= guis[guin].GetControlCount())) quit("!GetButtonPic: invalid object number");
if (guis[guin].GetControlType(objn) != kGUIButton)
quit("!GetButtonPic: specified control is not a button");
if ((ptype < 0) | (ptype > 3)) quit("!GetButtonPic: invalid pic type");
GUIButton*guil=(GUIButton*)guis[guin].GetControl(objn);
GUIButton *guil = (GUIButton *)guis[guin].GetControl(objn);
if (ptype == 0) {
// currently displayed pic
if (guil->CurrentImage < 0)
return guil->Image;
return guil->CurrentImage;
}
else if (ptype==1) {
} else if (ptype == 1) {
// nomal pic
return guil->Image;
}
else if (ptype==2) {
} else if (ptype == 2) {
// mouseover pic
return guil->MouseOverImage;
}
else { // pushed pic
} else { // pushed pic
return guil->PushedImage;
}
quit("internal error in getbuttonpic");
}
void SetButtonPic(int guin,int objn,int ptype,int slotn) {
if ((guin<0) | (guin>=game.numgui)) quit("!SetButtonPic: invalid GUI number");
if ((objn<0) | (objn>=guis[guin].GetControlCount())) quit("!SetButtonPic: invalid object number");
if (guis[guin].GetControlType(objn)!=kGUIButton)
void SetButtonPic(int guin, int objn, int ptype, int slotn) {
if ((guin < 0) | (guin >= game.numgui)) quit("!SetButtonPic: invalid GUI number");
if ((objn < 0) | (objn >= guis[guin].GetControlCount())) quit("!SetButtonPic: invalid object number");
if (guis[guin].GetControlType(objn) != kGUIButton)
quit("!SetButtonPic: specified control is not a button");
if ((ptype<1) | (ptype>3)) quit("!SetButtonPic: invalid pic type");
if ((ptype < 1) | (ptype > 3)) quit("!SetButtonPic: invalid pic type");
GUIButton*guil=(GUIButton*)guis[guin].GetControl(objn);
if (ptype==1) {
GUIButton *guil = (GUIButton *)guis[guin].GetControl(objn);
if (ptype == 1) {
Button_SetNormalGraphic(guil, slotn);
}
else if (ptype==2) {
} else if (ptype == 2) {
// mouseover pic
Button_SetMouseOverGraphic(guil, slotn);
}
else { // pushed pic
} else { // pushed pic
Button_SetPushedGraphic(guil, slotn);
}
}

View file

@ -23,9 +23,9 @@
#ifndef AGS_ENGINE_AC_GLOBALBUTTON_H
#define AGS_ENGINE_AC_GLOBALBUTTON_H
void SetButtonText(int guin,int objn, const char*newtx);
void SetButtonText(int guin, int objn, const char *newtx);
void AnimateButton(int guin, int objn, int view, int loop, int speed, int repeat);
int GetButtonPic(int guin, int objn, int ptype);
void SetButtonPic(int guin,int objn,int ptype,int slotn);
void SetButtonPic(int guin, int objn, int ptype, int slotn);
#endif

View file

@ -51,8 +51,8 @@ using namespace AGS::Common;
extern GameSetupStruct game;
extern ViewStruct*views;
extern RoomObject*objs;
extern ViewStruct *views;
extern RoomObject *objs;
extern RoomStruct thisroom;
extern GameState play;
extern ScriptObject scrObj[MAX_ROOM_OBJECTS];
@ -60,9 +60,9 @@ extern ScriptInvItem scrInv[MAX_INV];
// defined in character unit
extern CharacterExtras *charextra;
extern CharacterInfo*playerchar;
extern CharacterInfo *playerchar;
extern int32_t _sc_PlayerCharPtr;
extern CharacterInfo*playerchar;
extern CharacterInfo *playerchar;
void StopMoving(int chaa) {
@ -91,7 +91,7 @@ void FaceLocation(int cha, int xx, int yy) {
Character_FaceLocation(&game.chars[cha], xx, yy, BLOCKING);
}
void FaceCharacter(int cha,int toface) {
void FaceCharacter(int cha, int toface) {
if (!is_valid_character(cha))
quit("!FaceCharacter: Invalid character specified");
if (!is_valid_character(toface))
@ -113,58 +113,52 @@ void SetCharacterIdle(int who, int iview, int itime) {
int GetCharacterWidth(int ww) {
CharacterInfo *char1 = &game.chars[ww];
if (charextra[ww].width < 1)
{
if (charextra[ww].width < 1) {
if ((char1->view < 0) ||
(char1->loop >= views[char1->view].numLoops) ||
(char1->frame >= views[char1->view].loops[char1->loop].numFrames))
{
(char1->frame >= views[char1->view].loops[char1->loop].numFrames)) {
debug_script_warn("GetCharacterWidth: Character %s has invalid frame: view %d, loop %d, frame %d", char1->scrname, char1->view + 1, char1->loop, char1->frame);
return data_to_game_coord(4);
}
return game.SpriteInfos[views[char1->view].loops[char1->loop].frames[char1->frame].pic].Width;
}
else
} else
return charextra[ww].width;
}
int GetCharacterHeight(int charid) {
CharacterInfo *char1 = &game.chars[charid];
if (charextra[charid].height < 1)
{
if (charextra[charid].height < 1) {
if ((char1->view < 0) ||
(char1->loop >= views[char1->view].numLoops) ||
(char1->frame >= views[char1->view].loops[char1->loop].numFrames))
{
(char1->frame >= views[char1->view].loops[char1->loop].numFrames)) {
debug_script_warn("GetCharacterHeight: Character %s has invalid frame: view %d, loop %d, frame %d", char1->scrname, char1->view + 1, char1->loop, char1->frame);
return data_to_game_coord(2);
}
return game.SpriteInfos[views[char1->view].loops[char1->loop].frames[char1->frame].pic].Height;
}
else
} else
return charextra[charid].height;
}
void SetCharacterBaseline (int obn, int basel) {
void SetCharacterBaseline(int obn, int basel) {
if (!is_valid_character(obn)) quit("!SetCharacterBaseline: invalid object number specified");
Character_SetBaseline(&game.chars[obn], basel);
}
// pass trans=0 for fully solid, trans=100 for fully transparent
void SetCharacterTransparency(int obn,int trans) {
void SetCharacterTransparency(int obn, int trans) {
if (!is_valid_character(obn))
quit("!SetCharTransparent: invalid character number specified");
Character_SetTransparency(&game.chars[obn], trans);
}
void scAnimateCharacter (int chh, int loopn, int sppd, int rept) {
void scAnimateCharacter(int chh, int loopn, int sppd, int rept) {
if (!is_valid_character(chh))
quit("AnimateCharacter: invalid character");
@ -203,8 +197,7 @@ void FollowCharacterEx(int who, int tofollow, int distaway, int eagerness) {
if (!is_valid_character(who))
quit("!FollowCharacter: Invalid character specified");
CharacterInfo *chtofollow = nullptr;
if (tofollow != -1)
{
if (tofollow != -1) {
if (!is_valid_character(tofollow))
quit("!FollowCharacterEx: invalid character to follow");
else
@ -215,10 +208,10 @@ void FollowCharacterEx(int who, int tofollow, int distaway, int eagerness) {
}
void FollowCharacter(int who, int tofollow) {
FollowCharacterEx(who,tofollow,10,97);
FollowCharacterEx(who, tofollow, 10, 97);
}
void SetCharacterIgnoreLight (int who, int yesorno) {
void SetCharacterIgnoreLight(int who, int yesorno) {
if (!is_valid_character(who))
quit("!SetCharacterIgnoreLight: Invalid character specified");
@ -228,13 +221,13 @@ void SetCharacterIgnoreLight (int who, int yesorno) {
void MoveCharacter(int cc,int xx,int yy) {
walk_character(cc,xx,yy,0, true);
void MoveCharacter(int cc, int xx, int yy) {
walk_character(cc, xx, yy, 0, true);
}
void MoveCharacterDirect(int cc,int xx, int yy) {
walk_character(cc,xx,yy,1, true);
void MoveCharacterDirect(int cc, int xx, int yy) {
walk_character(cc, xx, yy, 1, true);
}
void MoveCharacterStraight(int cc,int xx, int yy) {
void MoveCharacterStraight(int cc, int xx, int yy) {
if (!is_valid_character(cc))
quit("!MoveCharacterStraight: invalid character specified");
@ -242,7 +235,7 @@ void MoveCharacterStraight(int cc,int xx, int yy) {
}
// Append to character path
void MoveCharacterPath (int chac, int tox, int toy) {
void MoveCharacterPath(int chac, int tox, int toy) {
if (!is_valid_character(chac))
quit("!MoveCharacterPath: invalid character specified");
@ -262,24 +255,24 @@ void SetCharacterSpeedEx(int chaa, int xspeed, int yspeed) {
}
void SetCharacterSpeed(int chaa,int nspeed) {
void SetCharacterSpeed(int chaa, int nspeed) {
SetCharacterSpeedEx(chaa, nspeed, nspeed);
}
void SetTalkingColor(int chaa,int ncol) {
void SetTalkingColor(int chaa, int ncol) {
if (!is_valid_character(chaa)) quit("!SetTalkingColor: invalid character");
Character_SetSpeechColor(&game.chars[chaa], ncol);
}
void SetCharacterSpeechView (int chaa, int vii) {
void SetCharacterSpeechView(int chaa, int vii) {
if (!is_valid_character(chaa))
quit("!SetCharacterSpeechView: invalid character specified");
Character_SetSpeechView(&game.chars[chaa], vii);
}
void SetCharacterBlinkView (int chaa, int vii, int intrv) {
void SetCharacterBlinkView(int chaa, int vii, int intrv) {
if (!is_valid_character(chaa))
quit("!SetCharacterBlinkView: invalid character specified");
@ -287,7 +280,7 @@ void SetCharacterBlinkView (int chaa, int vii, int intrv) {
Character_SetBlinkInterval(&game.chars[chaa], intrv);
}
void SetCharacterView(int chaa,int vii) {
void SetCharacterView(int chaa, int vii) {
if (!is_valid_character(chaa))
quit("!SetCharacterView: invalid character specified");
@ -300,35 +293,35 @@ void SetCharacterFrame(int chaa, int view, int loop, int frame) {
}
// similar to SetCharView, but aligns the frame to make it line up
void SetCharacterViewEx (int chaa, int vii, int loop, int align) {
void SetCharacterViewEx(int chaa, int vii, int loop, int align) {
Character_LockViewAligned(&game.chars[chaa], vii, loop, align);
}
void SetCharacterViewOffset (int chaa, int vii, int xoffs, int yoffs) {
void SetCharacterViewOffset(int chaa, int vii, int xoffs, int yoffs) {
Character_LockViewOffset(&game.chars[chaa], vii, xoffs, yoffs);
}
void ChangeCharacterView(int chaa,int vii) {
void ChangeCharacterView(int chaa, int vii) {
if (!is_valid_character(chaa))
quit("!ChangeCharacterView: invalid character specified");
Character_ChangeView(&game.chars[chaa], vii);
}
void SetCharacterClickable (int cha, int clik) {
void SetCharacterClickable(int cha, int clik) {
if (!is_valid_character(cha))
quit("!SetCharacterClickable: Invalid character specified");
// make the character clicklabe (reset "No interaction" bit)
game.chars[cha].flags&=~CHF_NOINTERACT;
game.chars[cha].flags &= ~CHF_NOINTERACT;
// if they don't want it clickable, set the relevant bit
if (clik == 0)
game.chars[cha].flags|=CHF_NOINTERACT;
game.chars[cha].flags |= CHF_NOINTERACT;
}
void SetCharacterIgnoreWalkbehinds (int cha, int clik) {
void SetCharacterIgnoreWalkbehinds(int cha, int clik) {
if (!is_valid_character(cha))
quit("!SetCharacterIgnoreWalkbehinds: Invalid character specified");
@ -336,50 +329,47 @@ void SetCharacterIgnoreWalkbehinds (int cha, int clik) {
}
void MoveCharacterToObject(int chaa,int obbj) {
void MoveCharacterToObject(int chaa, int obbj) {
// invalid object, do nothing
// this allows MoveCharacterToObject(EGO, GetObjectAt(...));
if (!is_valid_object(obbj))
return;
walk_character(chaa,objs[obbj].x+5,objs[obbj].y+6,0, true);
walk_character(chaa, objs[obbj].x + 5, objs[obbj].y + 6, 0, true);
GameLoopUntilNotMoving(&game.chars[chaa].walking);
}
void MoveCharacterToHotspot(int chaa,int hotsp) {
if ((hotsp<0) || (hotsp>=MAX_ROOM_HOTSPOTS))
void MoveCharacterToHotspot(int chaa, int hotsp) {
if ((hotsp < 0) || (hotsp >= MAX_ROOM_HOTSPOTS))
quit("!MovecharacterToHotspot: invalid hotspot");
if (thisroom.Hotspots[hotsp].WalkTo.X<1) return;
walk_character(chaa,thisroom.Hotspots[hotsp].WalkTo.X,thisroom.Hotspots[hotsp].WalkTo.Y,0, true);
if (thisroom.Hotspots[hotsp].WalkTo.X < 1) return;
walk_character(chaa, thisroom.Hotspots[hotsp].WalkTo.X, thisroom.Hotspots[hotsp].WalkTo.Y, 0, true);
GameLoopUntilNotMoving(&game.chars[chaa].walking);
}
void MoveCharacterBlocking(int chaa,int xx,int yy,int direct) {
if (!is_valid_character (chaa))
void MoveCharacterBlocking(int chaa, int xx, int yy, int direct) {
if (!is_valid_character(chaa))
quit("!MoveCharacterBlocking: invalid character");
// check if they try to move the player when Hide Player Char is
// ticked -- otherwise this will hang the game
if (game.chars[chaa].on != 1)
{
if (game.chars[chaa].on != 1) {
debug_script_warn("MoveCharacterBlocking: character is turned off (is Hide Player Character selected?) and cannot be moved");
return;
}
if (direct)
MoveCharacterDirect(chaa,xx,yy);
MoveCharacterDirect(chaa, xx, yy);
else
MoveCharacter(chaa,xx,yy);
MoveCharacter(chaa, xx, yy);
GameLoopUntilNotMoving(&game.chars[chaa].walking);
}
int GetCharacterSpeechAnimationDelay(CharacterInfo *cha)
{
if ((loaded_game_file_version < kGameVersion_312) && (game.options[OPT_SPEECHTYPE] != 0))
{
int GetCharacterSpeechAnimationDelay(CharacterInfo *cha) {
if ((loaded_game_file_version < kGameVersion_312) && (game.options[OPT_SPEECHTYPE] != 0)) {
// legacy versions of AGS assigned a fixed delay to Sierra-style speech only
return 5;
}
@ -389,38 +379,36 @@ int GetCharacterSpeechAnimationDelay(CharacterInfo *cha)
return cha->speech_anim_speed;
}
void RunCharacterInteraction (int cc, int mood) {
void RunCharacterInteraction(int cc, int mood) {
if (!is_valid_character(cc))
quit("!RunCharacterInteraction: invalid character");
int passon=-1,cdata=-1;
if (mood==MODE_LOOK) passon=0;
else if (mood==MODE_HAND) passon=1;
else if (mood==MODE_TALK) passon=2;
else if (mood==MODE_USE) { passon=3;
cdata=playerchar->activeinv;
play.usedinv=cdata;
}
else if (mood==MODE_PICKUP) passon = 5;
else if (mood==MODE_CUSTOM1) passon = 6;
else if (mood==MODE_CUSTOM2) passon = 7;
int passon = -1, cdata = -1;
if (mood == MODE_LOOK) passon = 0;
else if (mood == MODE_HAND) passon = 1;
else if (mood == MODE_TALK) passon = 2;
else if (mood == MODE_USE) {
passon = 3;
cdata = playerchar->activeinv;
play.usedinv = cdata;
} else if (mood == MODE_PICKUP) passon = 5;
else if (mood == MODE_CUSTOM1) passon = 6;
else if (mood == MODE_CUSTOM2) passon = 7;
evblockbasename="character%d"; evblocknum=cc;
if (loaded_game_file_version > kGameVersion_272)
{
if (passon>=0)
evblockbasename = "character%d";
evblocknum = cc;
if (loaded_game_file_version > kGameVersion_272) {
if (passon >= 0)
run_interaction_script(game.charScripts[cc].get(), passon, 4, (passon == 3));
run_interaction_script(game.charScripts[cc].get(), 4); // any click on char
}
else
{
if (passon>=0)
run_interaction_event(game.intrChar[cc].get(),passon, 4, (passon == 3));
run_interaction_event(game.intrChar[cc].get(),4); // any click on char
} else {
if (passon >= 0)
run_interaction_event(game.intrChar[cc].get(), passon, 4, (passon == 3));
run_interaction_event(game.intrChar[cc].get(), 4); // any click on char
}
}
int AreCharObjColliding(int charid,int objid) {
int AreCharObjColliding(int charid, int objid) {
if (!is_valid_character(charid))
quit("!AreCharObjColliding: invalid character");
if (!is_valid_object(objid))
@ -429,7 +417,7 @@ int AreCharObjColliding(int charid,int objid) {
return Character_IsCollidingWithObject(&game.chars[charid], &scrObj[objid]);
}
int AreCharactersColliding(int cchar1,int cchar2) {
int AreCharactersColliding(int cchar1, int cchar2) {
if (!is_valid_character(cchar1))
quit("!AreCharactersColliding: invalid char1");
if (!is_valid_character(cchar2))
@ -438,21 +426,21 @@ int AreCharactersColliding(int cchar1,int cchar2) {
return Character_IsCollidingWithChar(&game.chars[cchar1], &game.chars[cchar2]);
}
int GetCharacterProperty (int cha, const char *property) {
int GetCharacterProperty(int cha, const char *property) {
if (!is_valid_character(cha))
quit("!GetCharacterProperty: invalid character");
return get_int_property (game.charProps[cha], play.charProps[cha], property);
return get_int_property(game.charProps[cha], play.charProps[cha], property);
}
void SetCharacterProperty (int who, int flag, int yesorno) {
void SetCharacterProperty(int who, int flag, int yesorno) {
if (!is_valid_character(who))
quit("!SetCharacterProperty: Invalid character specified");
Character_SetOption(&game.chars[who], flag, yesorno);
}
void GetCharacterPropertyText (int item, const char *property, char *bufer) {
get_text_property (game.charProps[item], play.charProps[item], property, bufer);
void GetCharacterPropertyText(int item, const char *property, char *bufer) {
get_text_property(game.charProps[item], play.charProps[item], property, bufer);
}
int GetCharIDAtScreen(int xx, int yy) {
@ -479,7 +467,7 @@ void update_invorder() {
int ff, howmany;
// Iterate through all inv items, adding them once (or multiple
// times if requested) to the list.
for (ff=0;ff < game.numinvitems;ff++) {
for (ff = 0; ff < game.numinvitems; ff++) {
howmany = game.chars[cc].inv[ff];
if ((game.options[OPT_DUPLICATEINV] == 0) && (howmany > 1))
howmany = 1;
@ -543,7 +531,7 @@ void DisplayThought(int chid, const char *text) {
}
void __sc_displayspeech(int chid, const char *text) {
if ((chid<0) || (chid>=game.numcharacters))
if ((chid < 0) || (chid >= game.numcharacters))
quit("!DisplaySpeech: invalid character specified");
_DisplaySpeechCore(chid, text);
@ -551,13 +539,13 @@ void __sc_displayspeech(int chid, const char *text) {
// **** THIS IS UNDOCUMENTED BECAUSE IT DOESN'T WORK PROPERLY
// **** AT 640x400 AND DOESN'T USE THE RIGHT SPEECH STYLE
void DisplaySpeechAt (int xx, int yy, int wii, int aschar, const char*spch) {
void DisplaySpeechAt(int xx, int yy, int wii, int aschar, const char *spch) {
data_to_game_coords(&xx, &yy);
wii = data_to_game_coord(wii);
_displayspeech (get_translation(spch), aschar, xx, yy, wii, 0);
_displayspeech(get_translation(spch), aschar, xx, yy, wii, 0);
}
int DisplaySpeechBackground(int charid, const char*speel) {
int DisplaySpeechBackground(int charid, const char *speel) {
// remove any previous background speech for this character
for (size_t i = 0; i < screenover.size();) {
if (screenover[i].bgSpeechForChar == charid)
@ -566,7 +554,7 @@ int DisplaySpeechBackground(int charid, const char*speel) {
i++;
}
int ovrl=CreateTextOverlay(OVR_AUTOPLACE,charid,play.GetUIViewport().GetWidth()/2,FONT_SPEECH,
int ovrl = CreateTextOverlay(OVR_AUTOPLACE, charid, play.GetUIViewport().GetWidth() / 2, FONT_SPEECH,
-game.chars[charid].talkcolor, get_translation(speel), DISPLAYTEXT_NORMALOVERLAY);
int scid = find_overlay_of_type(ovrl);

View file

@ -29,50 +29,50 @@ void StopMoving(int chaa);
void ReleaseCharacterView(int chat);
void MoveToWalkableArea(int charid);
void FaceLocation(int cha, int xx, int yy);
void FaceCharacter(int cha,int toface);
void FaceCharacter(int cha, int toface);
void SetCharacterIdle(int who, int iview, int itime);
int GetCharacterWidth(int ww);
int GetCharacterHeight(int charid);
void SetCharacterBaseline (int obn, int basel);
void SetCharacterBaseline(int obn, int basel);
// pass trans=0 for fully solid, trans=100 for fully transparent
void SetCharacterTransparency(int obn,int trans);
void scAnimateCharacter (int chh, int loopn, int sppd, int rept);
void SetCharacterTransparency(int obn, int trans);
void scAnimateCharacter(int chh, int loopn, int sppd, int rept);
void AnimateCharacterEx(int chh, int loopn, int sppd, int rept, int direction, int blocking);
void SetPlayerCharacter(int newchar);
void FollowCharacterEx(int who, int tofollow, int distaway, int eagerness);
void FollowCharacter(int who, int tofollow);
void SetCharacterIgnoreLight (int who, int yesorno);
void MoveCharacter(int cc,int xx,int yy);
void MoveCharacterDirect(int cc,int xx, int yy);
void MoveCharacterStraight(int cc,int xx, int yy);
void SetCharacterIgnoreLight(int who, int yesorno);
void MoveCharacter(int cc, int xx, int yy);
void MoveCharacterDirect(int cc, int xx, int yy);
void MoveCharacterStraight(int cc, int xx, int yy);
// Append to character path
void MoveCharacterPath (int chac, int tox, int toy);
void MoveCharacterPath(int chac, int tox, int toy);
void SetCharacterSpeedEx(int chaa, int xspeed, int yspeed);
void SetCharacterSpeed(int chaa,int nspeed);
void SetTalkingColor(int chaa,int ncol);
void SetCharacterSpeechView (int chaa, int vii);
void SetCharacterBlinkView (int chaa, int vii, int intrv);
void SetCharacterView(int chaa,int vii);
void SetCharacterSpeed(int chaa, int nspeed);
void SetTalkingColor(int chaa, int ncol);
void SetCharacterSpeechView(int chaa, int vii);
void SetCharacterBlinkView(int chaa, int vii, int intrv);
void SetCharacterView(int chaa, int vii);
void SetCharacterFrame(int chaa, int view, int loop, int frame);
// similar to SetCharView, but aligns the frame to make it line up
void SetCharacterViewEx (int chaa, int vii, int loop, int align);
void SetCharacterViewOffset (int chaa, int vii, int xoffs, int yoffs);
void ChangeCharacterView(int chaa,int vii);
void SetCharacterClickable (int cha, int clik);
void SetCharacterIgnoreWalkbehinds (int cha, int clik);
void MoveCharacterToObject(int chaa,int obbj);
void MoveCharacterToHotspot(int chaa,int hotsp);
void MoveCharacterBlocking(int chaa,int xx,int yy,int direct);
void SetCharacterViewEx(int chaa, int vii, int loop, int align);
void SetCharacterViewOffset(int chaa, int vii, int xoffs, int yoffs);
void ChangeCharacterView(int chaa, int vii);
void SetCharacterClickable(int cha, int clik);
void SetCharacterIgnoreWalkbehinds(int cha, int clik);
void MoveCharacterToObject(int chaa, int obbj);
void MoveCharacterToHotspot(int chaa, int hotsp);
void MoveCharacterBlocking(int chaa, int xx, int yy, int direct);
void RunCharacterInteraction (int cc, int mood);
int AreCharObjColliding(int charid,int objid);
int AreCharactersColliding(int cchar1,int cchar2);
void RunCharacterInteraction(int cc, int mood);
int AreCharObjColliding(int charid, int objid);
int AreCharactersColliding(int cchar1, int cchar2);
int GetCharacterProperty (int cha, const char *property);
void SetCharacterProperty (int who, int flag, int yesorno);
int GetCharacterProperty(int cha, const char *property);
void SetCharacterProperty(int who, int flag, int yesorno);
int GetPlayerCharacter();
void GetCharacterPropertyText (int item, const char *property, char *bufer);
void GetCharacterPropertyText(int item, const char *property, char *bufer);
int GetCharacterSpeechAnimationDelay(CharacterInfo *cha);
int GetCharIDAtScreen(int xx, int yy);
@ -86,7 +86,7 @@ void lose_inventory(int inum);
void DisplayThought(int chid, const char *text);
void __sc_displayspeech(int chid, const char *text);
void DisplaySpeechAt (int xx, int yy, int wii, int aschar, const char*spch);
int DisplaySpeechBackground(int charid, const char*speel);
void DisplaySpeechAt(int xx, int yy, int wii, int aschar, const char *spch);
int DisplaySpeechBackground(int charid, const char *speel);
#endif

View file

@ -42,7 +42,7 @@ int sc_GetTime(int whatti) {
return returnVal;
}
int GetRawTime () {
int GetRawTime() {
// TODO: we might need to modify script API to support larger time type
return static_cast<int>(time(nullptr));
}

View file

@ -24,6 +24,6 @@
#define AGS_ENGINE_AC_GLOBALDATETIME_H
int sc_GetTime(int whatti) ;
int GetRawTime ();
int GetRawTime();
#endif

View file

@ -54,7 +54,7 @@ extern GameSetupStruct game;
extern GameSetup usetup;
extern GameState play;
extern RoomStruct thisroom;
extern CharacterInfo*playerchar;
extern CharacterInfo *playerchar;
extern int convert_16bit_bgr;
extern IGraphicsDriver *gfxDriver;
@ -64,8 +64,7 @@ extern int displayed_room, starting_room;
extern MoveList *mls;
extern char transFileName[MAX_PATH];
String GetRuntimeInfo()
{
String GetRuntimeInfo() {
DisplayMode mode = gfxDriver->GetDisplayMode();
Rect render_frame = gfxDriver->GetRenderDestination();
PGfxFilter filter = gfxDriver->GetGraphicsFilter();
@ -94,29 +93,27 @@ String GetRuntimeInfo()
return runtimeInfo;
}
void script_debug(int cmdd,int dataa) {
if (play.debug_mode==0) return;
void script_debug(int cmdd, int dataa) {
if (play.debug_mode == 0) return;
int rr;
if (cmdd==0) {
for (rr=1;rr<game.numinvitems;rr++)
playerchar->inv[rr]=1;
if (cmdd == 0) {
for (rr = 1; rr < game.numinvitems; rr++)
playerchar->inv[rr] = 1;
update_invorder();
// Display("invorder decided there are %d items[display %d",play.inv_numorder,play.inv_numdisp);
}
else if (cmdd==1) {
} else if (cmdd == 1) {
String toDisplay = GetRuntimeInfo();
Display(toDisplay.GetCStr());
// Display("shftR: %d shftG: %d shftB: %d", _rgb_r_shift_16, _rgb_g_shift_16, _rgb_b_shift_16);
// Display("Remaining memory: %d kb",_go32_dpmi_remaining_virtual_memory()/1024);
//Display("Play char bcd: %d",->GetColorDepth(spriteset[views[playerchar->view].frames[playerchar->loop][playerchar->frame].pic]));
}
else if (cmdd==2)
{ // show walkable areas from here
} else if (cmdd == 2) {
// show walkable areas from here
// TODO: support multiple viewports?!
const int viewport_index = 0;
const int camera_index = 0;
Bitmap *tempw=BitmapHelper::CreateBitmap(thisroom.WalkAreaMask->GetWidth(),thisroom.WalkAreaMask->GetHeight());
tempw->Blit(prepare_walkable_areas(-1),0,0,0,0,tempw->GetWidth(),tempw->GetHeight());
Bitmap *tempw = BitmapHelper::CreateBitmap(thisroom.WalkAreaMask->GetWidth(), thisroom.WalkAreaMask->GetHeight());
tempw->Blit(prepare_walkable_areas(-1), 0, 0, 0, 0, tempw->GetWidth(), tempw->GetHeight());
const Rect &viewport = play.GetRoomViewport(viewport_index)->GetRect();
const Rect &camera = play.GetRoomCamera(camera_index)->GetRect();
Bitmap *view_bmp = BitmapHelper::CreateBitmap(viewport.GetWidth(), viewport.GetHeight());
@ -131,48 +128,41 @@ void script_debug(int cmdd,int dataa) {
gfxDriver->DestroyDDB(ddb);
ags_wait_until_keypress();
invalidate_screen();
}
else if (cmdd==3)
{
} else if (cmdd == 3) {
int goToRoom = -1;
if (game.roomCount == 0)
{
if (game.roomCount == 0) {
char inroomtex[80];
sprintf(inroomtex, "!Enter new room: (in room %d)", displayed_room);
setup_for_dialog();
goToRoom = enternumberwindow(inroomtex);
restore_after_dialog();
}
else
{
} else {
setup_for_dialog();
goToRoom = roomSelectorWindow(displayed_room, game.roomCount, game.roomNumbers, game.roomNames);
restore_after_dialog();
}
if (goToRoom >= 0)
NewRoom(goToRoom);
}
else if (cmdd == 4) {
} else if (cmdd == 4) {
if (display_fps != kFPS_Forced)
display_fps = (FPSDisplayMode)dataa;
}
else if (cmdd == 5) {
} else if (cmdd == 5) {
if (dataa == 0) dataa = game.playercharacter;
if (game.chars[dataa].walking < 1) {
Display("Not currently moving.");
return;
}
Bitmap *tempw=BitmapHelper::CreateTransparentBitmap(thisroom.WalkAreaMask->GetWidth(),thisroom.WalkAreaMask->GetHeight());
Bitmap *tempw = BitmapHelper::CreateTransparentBitmap(thisroom.WalkAreaMask->GetWidth(), thisroom.WalkAreaMask->GetHeight());
int mlsnum = game.chars[dataa].walking;
if (game.chars[dataa].walking >= TURNING_AROUND)
mlsnum %= TURNING_AROUND;
MoveList*cmls = &mls[mlsnum];
for (int i = 0; i < cmls->numstage-1; i++) {
short srcx=short((cmls->pos[i] >> 16) & 0x00ffff);
short srcy=short(cmls->pos[i] & 0x00ffff);
short targetx=short((cmls->pos[i+1] >> 16) & 0x00ffff);
short targety=short(cmls->pos[i+1] & 0x00ffff);
tempw->DrawLine(Line(srcx, srcy, targetx, targety), MakeColor(i+1));
MoveList *cmls = &mls[mlsnum];
for (int i = 0; i < cmls->numstage - 1; i++) {
short srcx = short((cmls->pos[i] >> 16) & 0x00ffff);
short srcy = short(cmls->pos[i] & 0x00ffff);
short targetx = short((cmls->pos[i + 1] >> 16) & 0x00ffff);
short targety = short(cmls->pos[i + 1] & 0x00ffff);
tempw->DrawLine(Line(srcx, srcy, targetx, targety), MakeColor(i + 1));
}
// TODO: support multiple viewports?!
@ -191,8 +181,7 @@ void script_debug(int cmdd,int dataa) {
delete view_bmp;
gfxDriver->DestroyDDB(ddb);
ags_wait_until_keypress();
}
else if (cmdd == 99)
} else if (cmdd == 99)
ccSetOption(SCOPT_DEBUGRUN, dataa);
else quit("!Debug: unknown command code");
}

View file

@ -27,6 +27,6 @@
#include "util/string.h"
AGS::Common::String GetRuntimeInfo();
void script_debug(int cmdd,int dataa);
void script_debug(int cmdd, int dataa);
#endif

View file

@ -39,7 +39,7 @@ extern DialogTopic *dialog;
ScriptPosition last_in_dialog_request_script_pos;
void RunDialog(int tum) {
if ((tum<0) | (tum>=game.numdialog))
if ((tum < 0) | (tum >= game.numdialog))
quit("!RunDialog: invalid topic number specified");
can_run_delayed_command();
@ -72,16 +72,13 @@ void StopDialog() {
play.stop_dialog_at_end = DIALOG_STOP;
}
void SetDialogOption(int dlg, int opt, int onoroff, bool dlg_script)
{
if ((dlg<0) | (dlg>=game.numdialog))
void SetDialogOption(int dlg, int opt, int onoroff, bool dlg_script) {
if ((dlg < 0) | (dlg >= game.numdialog))
quit("!SetDialogOption: Invalid topic number specified");
if ((opt<1) | (opt>dialog[dlg].numoptions))
{
if ((opt < 1) | (opt > dialog[dlg].numoptions)) {
// Pre-3.1.1 games had "dialog scripts" that were written in different language and
// parsed differently; its "option-on/off" commands were more permissive.
if (dlg_script)
{
if (dlg_script) {
Debug::Printf(kDbgGroup_Game, kDbgMsg_Error, "SetDialogOption: Invalid option number specified (%d : %d)", dlg, opt);
return;
}
@ -89,17 +86,17 @@ void SetDialogOption(int dlg, int opt, int onoroff, bool dlg_script)
}
opt--;
dialog[dlg].optionflags[opt]&=~DFLG_ON;
if ((onoroff==1) & ((dialog[dlg].optionflags[opt] & DFLG_OFFPERM)==0))
dialog[dlg].optionflags[opt]|=DFLG_ON;
else if (onoroff==2)
dialog[dlg].optionflags[opt]|=DFLG_OFFPERM;
dialog[dlg].optionflags[opt] &= ~DFLG_ON;
if ((onoroff == 1) & ((dialog[dlg].optionflags[opt] & DFLG_OFFPERM) == 0))
dialog[dlg].optionflags[opt] |= DFLG_ON;
else if (onoroff == 2)
dialog[dlg].optionflags[opt] |= DFLG_OFFPERM;
}
int GetDialogOption (int dlg, int opt) {
if ((dlg<0) | (dlg>=game.numdialog))
int GetDialogOption(int dlg, int opt) {
if ((dlg < 0) | (dlg >= game.numdialog))
quit("!GetDialogOption: Invalid topic number specified");
if ((opt<1) | (opt>dialog[dlg].numoptions))
if ((opt < 1) | (opt > dialog[dlg].numoptions))
quit("!GetDialogOption: Invalid option number specified");
opt--;

View file

@ -24,7 +24,7 @@
#define AGS_ENGINE_AC_GLOBALDIALOG_H
void RunDialog(int tum);
int GetDialogOption (int dlg, int opt);
int GetDialogOption(int dlg, int opt);
void SetDialogOption(int dlg, int opt, int onoroff, bool dlg_script = false);
void StopDialog();

View file

@ -49,22 +49,20 @@ extern RoomStruct thisroom;
extern int display_message_aschar;
extern GameSetupStruct game;
void Display(const char*texx, ...) {
void Display(const char *texx, ...) {
char displbuf[STD_BUFFER_SIZE];
va_list ap;
va_start(ap,texx);
va_start(ap, texx);
vsprintf(displbuf, get_translation(texx), ap);
va_end(ap);
DisplayAtY (-1, displbuf);
DisplayAtY(-1, displbuf);
}
void DisplaySimple(const char *text)
{
DisplayAtY (-1, text);
void DisplaySimple(const char *text) {
DisplayAtY(-1, text);
}
void DisplayTopBar(int ypos, int ttexcol, int backcol, const char *title, const char *text)
{
void DisplayTopBar(int ypos, int ttexcol, int backcol, const char *title, const char *text) {
// FIXME: refactor source_text_length and get rid of this ugly hack!
const int real_text_sourcelen = source_text_length;
snprintf(topBar.text, sizeof(topBar.text), "%s", get_translation(title));
@ -102,31 +100,30 @@ void DisplayMessageBar(int ypos, int ttexcol, int backcol, const char *title, in
void DisplayMessageAtY(int msnum, int ypos) {
char msgbufr[3001];
if (msnum>=500) {
get_message_text (msnum, msgbufr);
if (msnum >= 500) {
get_message_text(msnum, msgbufr);
if (display_message_aschar > 0)
DisplaySpeech(msgbufr, display_message_aschar);
else
DisplayAtY(ypos, msgbufr);
display_message_aschar=0;
display_message_aschar = 0;
return;
}
if (display_message_aschar > 0) {
display_message_aschar=0;
display_message_aschar = 0;
quit("!DisplayMessage: data column specified a character for local\n"
"message; use the message editor to select the character for room\n"
"messages.\n");
}
int repeatloop=1;
int repeatloop = 1;
while (repeatloop) {
get_message_text (msnum, msgbufr);
get_message_text(msnum, msgbufr);
if (thisroom.MessageInfos[msnum].DisplayAs > 0) {
DisplaySpeech(msgbufr, thisroom.MessageInfos[msnum].DisplayAs - 1);
}
else {
} else {
// time out automatically if they have set that
int oldGameSkipDisp = play.skip_display;
if (thisroom.MessageInfos[msnum].Flags & MSG_TIMELIMIT)
@ -138,28 +135,27 @@ void DisplayMessageAtY(int msnum, int ypos) {
}
if (thisroom.MessageInfos[msnum].Flags & MSG_DISPLAYNEXT) {
msnum++;
repeatloop=1;
}
else
repeatloop=0;
repeatloop = 1;
} else
repeatloop = 0;
}
}
void DisplayMessage(int msnum) {
DisplayMessageAtY (msnum, -1);
DisplayMessageAtY(msnum, -1);
}
void DisplayAt(int xxp,int yyp,int widd, const char* text) {
void DisplayAt(int xxp, int yyp, int widd, const char *text) {
data_to_game_coords(&xxp, &yyp);
widd = data_to_game_coord(widd);
if (widd<1) widd=play.GetUIViewport().GetWidth()/2;
if (xxp<0) xxp=play.GetUIViewport().GetWidth()/2-widd/2;
if (widd < 1) widd = play.GetUIViewport().GetWidth() / 2;
if (xxp < 0) xxp = play.GetUIViewport().GetWidth() / 2 - widd / 2;
_display_at(xxp, yyp, widd, text, DISPLAYTEXT_MESSAGEBOX, 0, 0, 0, false);
}
void DisplayAtY (int ypos, const char *texx) {
void DisplayAtY(int ypos, const char *texx) {
const Rect &ui_view = play.GetUIViewport();
if ((ypos < -1) || (ypos >= ui_view.GetHeight()))
quitprintf("!DisplayAtY: invalid Y co-ordinate supplied (used: %d; valid: 0..%d)", ypos, ui_view.GetHeight());
@ -188,13 +184,13 @@ void DisplayAtY (int ypos, const char *texx) {
}
}
void SetSpeechStyle (int newstyle) {
void SetSpeechStyle(int newstyle) {
if ((newstyle < 0) || (newstyle > 3))
quit("!SetSpeechStyle: must use a SPEECH_* constant as parameter");
game.options[OPT_SPEECHTYPE] = newstyle;
}
void SetSkipSpeech (SkipSpeechStyle newval) {
void SetSkipSpeech(SkipSpeechStyle newval) {
if ((newval < kSkipSpeechFirst) || (newval > kSkipSpeechLast))
quit("!SetSkipSpeech: invalid skip mode specified");
@ -202,7 +198,6 @@ void SetSkipSpeech (SkipSpeechStyle newval) {
play.cant_skip_speech = user_to_internal_skip_speech((SkipSpeechStyle)newval);
}
SkipSpeechStyle GetSkipSpeech()
{
SkipSpeechStyle GetSkipSpeech() {
return internal_skip_speech_to_user(play.cant_skip_speech);
}

View file

@ -25,18 +25,18 @@
#include "ac/speech.h"
void Display(const char*texx, ...); // applies translation
void DisplaySimple(const char* text); // does not apply translation
void DisplayAt(int xxp,int yyp,int widd, const char*text);
void DisplayAtY (int ypos, const char *texx);
void Display(const char *texx, ...); // applies translation
void DisplaySimple(const char *text); // does not apply translation
void DisplayAt(int xxp, int yyp, int widd, const char *text);
void DisplayAtY(int ypos, const char *texx);
void DisplayMessage(int msnum);
void DisplayMessageAtY(int msnum, int ypos);
void DisplayTopBar(int ypos, int ttexcol, int backcol, const char *title, const char *text);
// Display a room/global message in the bar
void DisplayMessageBar(int ypos, int ttexcol, int backcol, const char *title, int msgnum);
void SetSpeechStyle (int newstyle);
void SetSkipSpeech (SkipSpeechStyle newval);
void SetSpeechStyle(int newstyle);
void SetSkipSpeech(SkipSpeechStyle newval);
SkipSpeechStyle GetSkipSpeech();
#endif

View file

@ -52,7 +52,7 @@ extern GameSetupStruct game;
#define RAW_SURFACE() (play.raw_drawing_surface.get())
// RawSaveScreen: copy the current screen to a backup bitmap
void RawSaveScreen () {
void RawSaveScreen() {
if (raw_saved_screen != nullptr)
delete raw_saved_screen;
PBitmap source = thisroom.BgFrames[play.bg_frame].Graphic;
@ -90,7 +90,7 @@ void RawRestoreScreenTinted(int red, int green, int blue, int opacity) {
mark_current_background_dirty();
}
void RawDrawFrameTransparent (int frame, int translev) {
void RawDrawFrameTransparent(int frame, int translev) {
if ((frame < 0) || ((size_t)frame >= thisroom.BgFrameCount) ||
(translev < 0) || (translev > 99))
quit("!RawDrawFrameTransparent: invalid parameter (transparency must be 0-99, frame a valid BG frame)");
@ -103,15 +103,12 @@ void RawDrawFrameTransparent (int frame, int translev) {
quit("!RawDrawFrameTransparent: cannot draw current background onto itself");
RAW_START();
if (translev == 0)
{
if (translev == 0) {
// just draw it over the top, no transparency
RAW_SURFACE()->Blit(bg.get(), 0, 0, 0, 0, bg->GetWidth(), bg->GetHeight());
}
else
{
} else {
// Draw it transparently
GfxUtil::DrawSpriteWithTransparency (RAW_SURFACE(), bg.get(), 0, 0,
GfxUtil::DrawSpriteWithTransparency(RAW_SURFACE(), bg.get(), 0, 0,
GfxDef::Trans100ToAlpha255(translev));
}
invalidate_screen();
@ -119,14 +116,14 @@ void RawDrawFrameTransparent (int frame, int translev) {
RAW_END();
}
void RawClear (int clr) {
void RawClear(int clr) {
RAW_START();
clr = RAW_SURFACE()->GetCompatibleColor(clr);
RAW_SURFACE()->Clear (clr);
RAW_SURFACE()->Clear(clr);
invalidate_screen();
mark_current_background_dirty();
}
void RawSetColor (int clr) {
void RawSetColor(int clr) {
// set the colour at the appropriate depth for the background
play.raw_color = MakeColor(clr);
}
@ -137,13 +134,13 @@ void RawSetColorRGB(int red, int grn, int blu) {
play.raw_color = makecol_depth(thisroom.BgFrames[play.bg_frame].Graphic->GetColorDepth(), red, grn, blu);
}
void RawPrint (int xx, int yy, const char *text) {
void RawPrint(int xx, int yy, const char *text) {
RAW_START();
// don't use wtextcolor because it will do a 16->32 conversion
color_t text_color = play.raw_color;
if ((RAW_SURFACE()->GetColorDepth() <= 8) && (play.raw_color > 255)) {
text_color = RAW_SURFACE()->GetCompatibleColor(1);
debug_script_warn ("RawPrint: Attempted to use hi-color on 256-col background");
debug_script_warn("RawPrint: Attempted to use hi-color on 256-col background");
}
data_to_game_coords(&xx, &yy);
wouttext_outline(RAW_SURFACE(), xx, yy, play.normal_font, text_color, text);
@ -153,13 +150,13 @@ void RawPrint (int xx, int yy, const char *text) {
mark_current_background_dirty();
RAW_END();
}
void RawPrintMessageWrapped (int xx, int yy, int wid, int font, int msgm) {
void RawPrintMessageWrapped(int xx, int yy, int wid, int font, int msgm) {
char displbuf[3000];
int linespacing = getfontspacing_outlined(font);
data_to_game_coords(&xx, &yy);
wid = data_to_game_coord(wid);
get_message_text (msgm, displbuf);
get_message_text(msgm, displbuf);
// it's probably too late but check anyway
if (strlen(displbuf) > 2899)
quit("!RawPrintMessageWrapped: message too long");
@ -169,7 +166,7 @@ void RawPrintMessageWrapped (int xx, int yy, int wid, int font, int msgm) {
RAW_START();
color_t text_color = play.raw_color;
for (size_t i = 0; i < Lines.Count(); i++)
wouttext_outline(RAW_SURFACE(), xx, yy + linespacing*i, font, text_color, Lines[i]);
wouttext_outline(RAW_SURFACE(), xx, yy + linespacing * i, font, text_color, Lines[i]);
invalidate_screen();
mark_current_background_dirty();
RAW_END();
@ -260,29 +257,29 @@ void RawDrawImageResized(int xx, int yy, int gotSlot, int width, int height) {
update_polled_stuff_if_runtime(); // this operation can be slow so stop music skipping
RAW_END();
}
void RawDrawLine (int fromx, int fromy, int tox, int toy) {
void RawDrawLine(int fromx, int fromy, int tox, int toy) {
data_to_game_coords(&fromx, &fromy);
data_to_game_coords(&tox, &toy);
play.raw_modified[play.bg_frame] = 1;
int ii,jj;
int ii, jj;
// draw a line thick enough to look the same at all resolutions
PBitmap bg = thisroom.BgFrames[play.bg_frame].Graphic;
color_t draw_color = play.raw_color;
for (ii = 0; ii < get_fixed_pixel_size(1); ii++) {
for (jj = 0; jj < get_fixed_pixel_size(1); jj++)
bg->DrawLine (Line(fromx+ii, fromy+jj, tox+ii, toy+jj), draw_color);
bg->DrawLine(Line(fromx + ii, fromy + jj, tox + ii, toy + jj), draw_color);
}
invalidate_screen();
mark_current_background_dirty();
}
void RawDrawCircle (int xx, int yy, int rad) {
void RawDrawCircle(int xx, int yy, int rad) {
data_to_game_coords(&xx, &yy);
rad = data_to_game_coord(rad);
play.raw_modified[play.bg_frame] = 1;
PBitmap bg = thisroom.BgFrames[play.bg_frame].Graphic;
bg->FillCircle(Circle (xx, yy, rad), play.raw_color);
bg->FillCircle(Circle(xx, yy, rad), play.raw_color);
invalidate_screen();
mark_current_background_dirty();
}
@ -292,7 +289,7 @@ void RawDrawRectangle(int x1, int y1, int x2, int y2) {
data_to_game_round_up(&x2, &y2);
PBitmap bg = thisroom.BgFrames[play.bg_frame].Graphic;
bg->FillRect(Rect(x1,y1,x2,y2), play.raw_color);
bg->FillRect(Rect(x1, y1, x2, y2), play.raw_color);
invalidate_screen();
mark_current_background_dirty();
}
@ -303,7 +300,7 @@ void RawDrawTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
data_to_game_coords(&x3, &y3);
PBitmap bg = thisroom.BgFrames[play.bg_frame].Graphic;
bg->DrawTriangle(Triangle (x1,y1,x2,y2,x3,y3), play.raw_color);
bg->DrawTriangle(Triangle(x1, y1, x2, y2, x3, y3), play.raw_color);
invalidate_screen();
mark_current_background_dirty();
}

View file

@ -23,26 +23,26 @@
#ifndef AGS_ENGINE_AC_GLOBALDRAWINGSURFACE_H
#define AGS_ENGINE_AC_GLOBALDRAWINGSURFACE_H
void RawSaveScreen ();
void RawSaveScreen();
// RawRestoreScreen: copy backup bitmap back to screen; we
// deliberately don't free the Common::Bitmap *cos they can multiple restore
// and it gets freed on room exit anyway
void RawRestoreScreen();
// Restores the backup bitmap, but tints it to the specified level
void RawRestoreScreenTinted(int red, int green, int blue, int opacity);
void RawDrawFrameTransparent (int frame, int translev);
void RawClear (int clr);
void RawSetColor (int clr);
void RawDrawFrameTransparent(int frame, int translev);
void RawClear(int clr);
void RawSetColor(int clr);
void RawSetColorRGB(int red, int grn, int blu);
void RawPrint (int xx, int yy, const char *text);
void RawPrintMessageWrapped (int xx, int yy, int wid, int font, int msgm);
void RawPrint(int xx, int yy, const char *text);
void RawPrintMessageWrapped(int xx, int yy, int wid, int font, int msgm);
void RawDrawImageCore(int xx, int yy, int slot, int alpha = 0xFF);
void RawDrawImage(int xx, int yy, int slot);
void RawDrawImageOffset(int xx, int yy, int slot);
void RawDrawImageTransparent(int xx, int yy, int slot, int opacity);
void RawDrawImageResized(int xx, int yy, int gotSlot, int width, int height);
void RawDrawLine (int fromx, int fromy, int tox, int toy);
void RawDrawCircle (int xx, int yy, int rad);
void RawDrawLine(int fromx, int fromy, int tox, int toy);
void RawDrawCircle(int xx, int yy, int rad);
void RawDrawRectangle(int x1, int y1, int x2, int y2);
void RawDrawTriangle(int x1, int y1, int x2, int y2, int x3, int y3);

View file

@ -36,8 +36,7 @@ using namespace AGS::Engine;
extern SpriteCache spriteset;
extern IGraphicsDriver *gfxDriver;
int LoadImageFile(const char *filename)
{
int LoadImageFile(const char *filename) {
ResolvedPath rp;
if (!ResolveScriptPath(filename, true, rp))
return 0;

View file

@ -34,8 +34,7 @@
using namespace AGS::Common;
int32_t FileOpenCMode(const char*fnmm, const char* cmode)
{
int32_t FileOpenCMode(const char *fnmm, const char *cmode) {
Common::FileOpenMode open_mode;
Common::FileWorkMode work_mode;
// NOTE: here we ignore the text-mode flag. AGS 2.62 did not let
@ -43,46 +42,38 @@ int32_t FileOpenCMode(const char*fnmm, const char* cmode)
// writing logic in AGS makes extra control characters added for
// security reasons, and FileWriteRawLine adds CR/LF to the end
// of string on its own.
if (!Common::File::GetFileModesFromCMode(cmode, open_mode, work_mode))
{
if (!Common::File::GetFileModesFromCMode(cmode, open_mode, work_mode)) {
return 0;
}
return FileOpen(fnmm, open_mode, work_mode);
}
// Find a free file slot to use
int32_t FindFreeFileSlot()
{
int32_t FindFreeFileSlot() {
int useindx = 0;
for (; useindx < num_open_script_files; useindx++)
{
for (; useindx < num_open_script_files; useindx++) {
if (valid_handles[useindx].stream == nullptr)
break;
}
if (useindx >= num_open_script_files &&
num_open_script_files >= MAX_OPEN_SCRIPT_FILES)
{
num_open_script_files >= MAX_OPEN_SCRIPT_FILES) {
quit("!FileOpen: tried to open more than 10 files simultaneously - close some first");
return -1;
}
return useindx;
}
int32_t FileOpen(const char*fnmm, Common::FileOpenMode open_mode, Common::FileWorkMode work_mode)
{
int32_t FileOpen(const char *fnmm, Common::FileOpenMode open_mode, Common::FileWorkMode work_mode) {
int32_t useindx = FindFreeFileSlot();
if (useindx < 0)
return 0;
ResolvedPath rp;
if (open_mode == kFile_Open && work_mode == kFile_Read)
{
if (open_mode == kFile_Open && work_mode == kFile_Read) {
if (!ResolveScriptPath(fnmm, true, rp))
return 0;
}
else
{
} else {
if (!ResolveWritePathAndCreateDirs(fnmm, rp))
return 0;
}
@ -102,35 +93,35 @@ int32_t FileOpen(const char*fnmm, Common::FileOpenMode open_mode, Common::FileWo
}
void FileClose(int32_t handle) {
ScriptFileHandle *sc_handle = check_valid_file_handle_int32(handle,"FileClose");
ScriptFileHandle *sc_handle = check_valid_file_handle_int32(handle, "FileClose");
delete sc_handle->stream;
sc_handle->stream = nullptr;
sc_handle->handle = 0;
}
}
void FileWrite(int32_t handle, const char *towrite) {
Stream *out = get_valid_file_stream_from_handle(handle,"FileWrite");
out->WriteInt32(strlen(towrite)+1);
out->Write(towrite,strlen(towrite)+1);
}
void FileWriteRawLine(int32_t handle, const char*towrite) {
Stream *out = get_valid_file_stream_from_handle(handle,"FileWriteRawLine");
out->Write(towrite,strlen(towrite));
out->WriteInt8 (13);
out->WriteInt8 (10);
}
void FileRead(int32_t handle,char*toread) {
Stream *out = get_valid_file_stream_from_handle(handle, "FileWrite");
out->WriteInt32(strlen(towrite) + 1);
out->Write(towrite, strlen(towrite) + 1);
}
void FileWriteRawLine(int32_t handle, const char *towrite) {
Stream *out = get_valid_file_stream_from_handle(handle, "FileWriteRawLine");
out->Write(towrite, strlen(towrite));
out->WriteInt8(13);
out->WriteInt8(10);
}
void FileRead(int32_t handle, char *toread) {
VALIDATE_STRING(toread);
Stream *in = get_valid_file_stream_from_handle(handle,"FileRead");
Stream *in = get_valid_file_stream_from_handle(handle, "FileRead");
if (in->EOS()) {
toread[0] = 0;
return;
}
int lle=in->ReadInt32();
if ((lle>=200) | (lle<1)) quit("!FileRead: file was not written by FileWrite");
in->Read(toread,lle);
}
int FileIsEOF (int32_t handle) {
Stream *stream = get_valid_file_stream_from_handle(handle,"FileIsEOF");
int lle = in->ReadInt32();
if ((lle >= 200) | (lle < 1)) quit("!FileRead: file was not written by FileWrite");
in->Read(toread, lle);
}
int FileIsEOF(int32_t handle) {
Stream *stream = get_valid_file_stream_from_handle(handle, "FileIsEOF");
if (stream->EOS())
return 1;
@ -138,12 +129,12 @@ int FileIsEOF (int32_t handle) {
if (stream->HasErrors())
return 1;
if (stream->GetPosition () >= stream->GetLength())
if (stream->GetPosition() >= stream->GetLength())
return 1;
return 0;
}
int FileIsError(int32_t handle) {
Stream *stream = get_valid_file_stream_from_handle(handle,"FileIsError");
Stream *stream = get_valid_file_stream_from_handle(handle, "FileIsError");
// TODO: stream errors
if (stream->HasErrors())
@ -151,33 +142,33 @@ int FileIsError(int32_t handle) {
return 0;
}
void FileWriteInt(int32_t handle,int into) {
Stream *out = get_valid_file_stream_from_handle(handle,"FileWriteInt");
void FileWriteInt(int32_t handle, int into) {
Stream *out = get_valid_file_stream_from_handle(handle, "FileWriteInt");
out->WriteInt8('I');
out->WriteInt32(into);
}
}
int FileReadInt(int32_t handle) {
Stream *in = get_valid_file_stream_from_handle(handle,"FileReadInt");
Stream *in = get_valid_file_stream_from_handle(handle, "FileReadInt");
if (in->EOS())
return -1;
if (in->ReadInt8()!='I')
if (in->ReadInt8() != 'I')
quit("!FileReadInt: File read back in wrong order");
return in->ReadInt32();
}
}
char FileReadRawChar(int32_t handle) {
Stream *in = get_valid_file_stream_from_handle(handle,"FileReadRawChar");
Stream *in = get_valid_file_stream_from_handle(handle, "FileReadRawChar");
if (in->EOS())
return -1;
return in->ReadInt8();
}
}
int FileReadRawInt(int32_t handle) {
Stream *in = get_valid_file_stream_from_handle(handle,"FileReadRawInt");
Stream *in = get_valid_file_stream_from_handle(handle, "FileReadRawInt");
if (in->EOS())
return -1;
return in->ReadInt32();
}
void FileWriteRawChar(int32_t handle, int chartoWrite) {
Stream *out = get_valid_file_stream_from_handle(handle,"FileWriteRawChar");
Stream *out = get_valid_file_stream_from_handle(handle, "FileWriteRawChar");
if ((chartoWrite < 0) || (chartoWrite > 255))
quit("!FileWriteRawChar: can only write values 0-255");

View file

@ -25,19 +25,23 @@
#include "util/file.h"
namespace AGS { namespace Common { class Stream; } }
namespace AGS {
namespace Common {
class Stream;
}
}
using namespace AGS; // FIXME later
int32_t FileOpen(const char*fnmm, Common::FileOpenMode open_mode, Common::FileWorkMode work_mode);
int32_t FileOpen(const char *fnmm, Common::FileOpenMode open_mode, Common::FileWorkMode work_mode);
// NOTE: FileOpenCMode is a backwards-compatible replacement for old-style global script function FileOpen
int32_t FileOpenCMode(const char*fnmm, const char* cmode);
int32_t FileOpenCMode(const char *fnmm, const char *cmode);
void FileClose(int32_t handle);
void FileWrite(int32_t handle, const char *towrite);
void FileWriteRawLine(int32_t handle, const char*towrite);
void FileRead(int32_t handle,char*toread);
int FileIsEOF (int32_t handle);
void FileWriteRawLine(int32_t handle, const char *towrite);
void FileRead(int32_t handle, char *toread);
int FileIsEOF(int32_t handle);
int FileIsError(int32_t handle);
void FileWriteInt(int32_t handle,int into);
void FileWriteInt(int32_t handle, int into);
int FileReadInt(int32_t handle);
char FileReadRawChar(int32_t handle);
int FileReadRawInt(int32_t handle);

File diff suppressed because it is too large Load diff

Some files were not shown because too many files have changed in this diff Show more