Updated instance icon, no more SDL

This commit is contained in:
Vulpovile
2023-11-02 00:07:10 -07:00
parent 5d96985667
commit 3c415e7297
13 changed files with 808 additions and 104 deletions

View File

@@ -1,6 +1,6 @@
#include <G3DAll.h>
#pragma once
#include <iostream>
#include <string.h>
class AudioPlayer
{
public:

View File

@@ -1,11 +1,7 @@
#include "AudioPlayer.h"
#include "SDL.h"
#include "SDL_audio.h"
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <Windows.h>
#include <Mmsystem.h>
#define NUM_SOUNDS 32
static SDL_AudioSpec fmt;
static bool initiated = false;
AudioPlayer::AudioPlayer(void)
@@ -15,98 +11,15 @@ AudioPlayer::AudioPlayer(void)
AudioPlayer::~AudioPlayer(void)
{
SDL_CloseAudio();
}
void AudioPlayer::init()
{
initiated = true;
extern void mixaudio(void *unused, Uint8 *stream, int len);
fmt.freq = 22050;
fmt.format = AUDIO_S16LSB;
fmt.channels = 2;
fmt.samples = 1024; /* A good value for games */
fmt.callback = mixaudio;
fmt.userdata = NULL;
/* Open the audio device and start playing sound! */
if ( SDL_OpenAudio(&fmt, NULL) < 0 ) {
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
}
SDL_PauseAudio(0);
}
static struct sample {
Uint8 *data;
Uint32 dpos;
Uint32 dlen;
} sounds[NUM_SOUNDS];
void mixaudio(void *unused, Uint8 *stream, int len)
{
int i;
Uint32 amount;
for ( i=0; i<NUM_SOUNDS; ++i ) {
amount = (sounds[i].dlen-sounds[i].dpos);
if ( amount > (Uint32)len ) {
amount = len;
}
SDL_MixAudio(stream, &sounds[i].data[sounds[i].dpos], amount, SDL_MIX_MAXVOLUME);
sounds[i].dpos += amount;
}
}
void AudioPlayer::playSound(std::string fileString)
{
if(initiated)
{
char *file = new char[fileString.length() + 1];
strcpy(file, fileString.c_str());
int index;
SDL_AudioSpec wave;
Uint8 *data;
Uint32 dlen;
SDL_AudioCVT cvt;
/* Look for an empty (or finished) sound slot */
for ( index=0; index<NUM_SOUNDS; ++index ) {
if ( sounds[index].dpos == sounds[index].dlen ) {
break;
}
}
if ( index == NUM_SOUNDS )
return;
/* Load the sound file and convert it to 16-bit stereo at 22kHz */
if ( SDL_LoadWAV(file, &wave, &data, &dlen) == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
return;
}
SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq,
AUDIO_S16, 2, fmt.freq);
cvt.buf = (Uint8*)malloc(dlen*cvt.len_mult);
memcpy(cvt.buf, data, dlen);
cvt.len = dlen;
SDL_ConvertAudio(&cvt);
SDL_FreeWAV(data);
/* Put the sound data in the slot (it starts playing immediately) */
if ( sounds[index].data ) {
free(sounds[index].data);
}
SDL_LockAudio();
sounds[index].data = cvt.buf;
sounds[index].dlen = cvt.len_cvt;
sounds[index].dpos = 0;
SDL_UnlockAudio();
delete [] file;
}
else
{
OutputDebugString("Audio player not initialized, sound will not play\r\n");
}
//TODO probably use something a bit better
PlaySound(fileString.c_str(), NULL, SND_FILENAME | SND_ASYNC);
}

View File

@@ -667,9 +667,9 @@ void DataModelInstance::drawMessage(RenderDevice* rd)
}
}
char brkc[12];
sprintf_s(brkc, "%d", brickCount);
_snprintf(brkc, 12, "%d", brickCount);
char instc[12];
sprintf_s(instc, "%d", instCount);
_snprintf(instc, 12, "%d", instCount);
message = "Bricks: ";
message += brkc;
message += " Snaps: ";

View File

@@ -109,8 +109,8 @@ std::vector<PROPGRIDITEM> LevelInstance::getProperties()
PIT_CHECK
));
sprintf_s(timerTxt, "%g", timer);
sprintf_s(scoreTxt, "%d", score);
_snprintf(timerTxt, 12, "%g", timer);
_snprintf(scoreTxt, 12, "%d", score);
properties.push_back(createPGI("Gameplay",
"InitialTimerValue",
"The amount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.",

View File

@@ -723,14 +723,14 @@ std::vector<PROPGRIDITEM> PartInstance::getProperties()
(LPARAM)anchored,
PIT_CHECK
));
sprintf_s(pto, "%g, %g, %g", position.x, position.y, position.z);
_snprintf(pto, 512, "%g, %g, %g", position.x, position.y, position.z);
properties.push_back(createPGI("Item",
"Offset",
"The position of the object in the workspace",
(LPARAM)pto,
PIT_EDIT
));
sprintf_s(pto2, "%g, %g, %g", size.x, size.y, size.z);
_snprintf(pto2, 512, "%g, %g, %g", size.x, size.y, size.z);
properties.push_back(createPGI("Item",
"Size",
"The size of the object in the workspace",
@@ -759,8 +759,8 @@ std::vector<PROPGRIDITEM> PartInstance::getProperties()
TEXT("NoSound\0Victory\0Boing\0Break\0Snap\0Bomb\0Splat\0Page\0Ping\0Swoosh\0Click\0Clock\0Step\0StepOn")
));
sprintf_s(changeScoreTxt, "%d", changeScore);
sprintf_s(changeTimerTxt, "%g", changeTimer);
_snprintf(changeScoreTxt, 12, "%d", changeScore);
_snprintf(changeTimerTxt, 12, "%g", changeTimer);
properties.push_back(createPGI("OnTouch",
"ChangeScore",
"How the score is affected when touched",

View File

@@ -142,6 +142,12 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int main(int argc, char** argv) {
HINSTANCE hThisInstance = GetModuleHandle(NULL);
return WinMain(hThisInstance, NULL, NULL, 1);
}
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow)
{
#ifndef _DEBUG
try{
#endif
@@ -158,7 +164,6 @@ int main(int argc, char** argv) {
icc.dwICC = ICC_WIN95_CLASSES/*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|
ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES*/;
InitCommonControlsEx(&icc);
HMODULE hThisInstance = GetModuleHandle(NULL);
if (!createWindowClass("mainHWND",WndProc,hThisInstance))
return false;