Skip to content

Commit

Permalink
Level editor work
Browse files Browse the repository at this point in the history
  • Loading branch information
elasota committed Feb 24, 2020
1 parent d63ac98 commit c78a20d
Show file tree
Hide file tree
Showing 61 changed files with 1,311 additions and 299 deletions.
2 changes: 1 addition & 1 deletion Aerofoil/Aerofoil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h" />
<ClInclude Include="..\GpCommon\GpFileCreationDisposition.h" />
<ClInclude Include="..\GpCommon\GpInputDriverProperties.h" />
<ClInclude Include="..\GpCommon\IGpColorCursor.h" />
<ClInclude Include="..\GpCommon\IGpCursor.h" />
<ClInclude Include="..\GpCommon\IGpAudioChannelCallbacks.h" />
<ClInclude Include="..\GpCommon\GpColorCursor_Win32.h" />
<ClInclude Include="..\GpCommon\IGpDisplayDriverSurface.h" />
Expand Down
22 changes: 11 additions & 11 deletions Aerofoil/GpColorCursor_Win32.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
#include "GpColorCursor_Win32.h"
#include "GpCursor_Win32.h"

#include <stdlib.h>
#include <new>

void GpColorCursor_Win32::Destroy()
void GpCursor_Win32::Destroy()
{
this->DecRef();
}

IGpColorCursor_Win32 *GpColorCursor_Win32::Load(const wchar_t *path)
IGpCursor_Win32 *GpCursor_Win32::Load(const wchar_t *path)
{
HANDLE imageH = LoadImageW(nullptr, path, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);

if (imageH == nullptr)
return nullptr;

HCURSOR cursor = reinterpret_cast<HCURSOR>(imageH);
void *storage = malloc(sizeof(GpColorCursor_Win32));
void *storage = malloc(sizeof(GpCursor_Win32));
if (!storage)
{
DestroyCursor(cursor);
return nullptr;
}

return new (storage) GpColorCursor_Win32(reinterpret_cast<HCURSOR>(cursor));
return new (storage) GpCursor_Win32(reinterpret_cast<HCURSOR>(cursor));
}

GpColorCursor_Win32::GpColorCursor_Win32(HCURSOR cursor)
GpCursor_Win32::GpCursor_Win32(HCURSOR cursor)
: m_cursor(cursor)
, m_refCount(1)
{
}

GpColorCursor_Win32::~GpColorCursor_Win32()
GpCursor_Win32::~GpCursor_Win32()
{
DestroyCursor(m_cursor);
}

const HCURSOR &GpColorCursor_Win32::GetHCursor() const
const HCURSOR &GpCursor_Win32::GetHCursor() const
{
return m_cursor;
}

void GpColorCursor_Win32::IncRef()
void GpCursor_Win32::IncRef()
{
m_refCount++;
}

void GpColorCursor_Win32::DecRef()
void GpCursor_Win32::DecRef()
{
m_refCount--;
if (m_refCount == 0)
{
this->~GpColorCursor_Win32();
this->~GpCursor_Win32();
free(this);
}
}
4 changes: 2 additions & 2 deletions Aerofoil/GpMain_Win32.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "GpMain.h"
#include "GpAudioDriverFactory.h"
#include "GpColorCursor_Win32.h"
#include "GpCursor_Win32.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFiber_Win32.h"
Expand Down Expand Up @@ -390,7 +390,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpWindowsGlobals.m_baseDir = GpFileSystem_Win32::GetInstance()->GetBasePath();

g_gpWindowsGlobals.m_createFiberFunc = GpFiber_Win32::Create;
g_gpWindowsGlobals.m_loadColorCursorFunc = GpColorCursor_Win32::Load;
g_gpWindowsGlobals.m_loadCursorFunc = GpCursor_Win32::Load;
g_gpWindowsGlobals.m_translateWindowsMessageFunc = TranslateWindowsMessage;

g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_D3D11;
Expand Down
115 changes: 114 additions & 1 deletion ConvertColorCursors/ConvertColorCursors.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CFileStream.h"
#include "BMPFormat.h"
#include "MMHandleBlock.h"
#include "ResourceCompiledTypeList.h"
#include "ResourceFile.h"
Expand All @@ -8,6 +9,7 @@
#include <assert.h>

#include <string>
#include <vector>

#include "stb_image_write.h"

Expand Down Expand Up @@ -53,6 +55,14 @@ struct CursorHeader
BEUInt32_t m_cursorResourceID;
};

struct BWCursor
{
uint8_t m_pixels[32];
uint8_t m_mask[32];
BEUInt16_t m_hotSpotX;
BEUInt16_t m_hotSpotY;
};

struct IconDir
{
uint16_t m_reserved;
Expand Down Expand Up @@ -84,6 +94,108 @@ void WriteToFileCallback(void *context, void *data, int size)
fwrite(data, 1, size, static_cast<FILE*>(context));
}

void WriteToVectorCallback(void *context, void *data, int size)
{
std::vector<uint8_t> *vec = static_cast<std::vector<uint8_t>*>(context);
for (int i = 0; i < size; i++)
vec->push_back(static_cast<const uint8_t*>(data)[i]);
}

void ConvertBWCursors(PortabilityLayer::ResourceFile *resFile)
{
const PortabilityLayer::ResourceCompiledTypeList *typeList = resFile->GetResourceTypeList('CURS');
if (!typeList)
return;

const size_t numRefs = typeList->m_numRefs;
for (size_t i = 0; i < numRefs; i++)
{
const int resID = typeList->m_firstRef[i].m_resID;
const THandle<void> resHdl = resFile->LoadResource('CURS', resID);
const void *cursorDataBase = *resHdl;
const BWCursor *cursorData = static_cast<const BWCursor *>(cursorDataBase);

char outPathDebug[64];
sprintf_s(outPathDebug, "Packaged\\WinCursors\\b%i.bmp", resID);

char outPath[64];
sprintf_s(outPath, "Packaged\\WinCursors\\b%i.cur", resID);

FILE *outF = nullptr;
errno_t outErr = fopen_s(&outF, outPath, "wb");

if (!outErr)
{
IconDir iconDir;
iconDir.m_reserved = 0;
iconDir.m_type = 2;
iconDir.m_numImages = 1;

IconDirEntry iconDirEntry;
iconDirEntry.m_width = 16;
iconDirEntry.m_height = 16;
iconDirEntry.m_numColors = 0;
iconDirEntry.m_reserved = 0;
iconDirEntry.m_numPlanes_HotSpotX = cursorData->m_hotSpotX;
iconDirEntry.m_bpp_HotSpotY = cursorData->m_hotSpotY;
iconDirEntry.m_imageDataSize = 0;
iconDirEntry.m_imageDataOffset = sizeof(IconDir) + sizeof(IconDirEntry);

fwrite(&iconDir, 1, sizeof(IconDir), outF);
fwrite(&iconDirEntry, 1, sizeof(IconDirEntry), outF);

long imageDataStart = ftell(outF);

PortabilityLayer::BitmapInfoHeader bmpHeader;
bmpHeader.m_thisStructureSize = sizeof(bmpHeader);
bmpHeader.m_width = 16;
bmpHeader.m_height = 32;
bmpHeader.m_planes = 1;
bmpHeader.m_bitsPerPixel = 1;
bmpHeader.m_compression = 0;
bmpHeader.m_imageSize = (16 * 16 / 8);
bmpHeader.m_xPixelsPerMeter = 0;
bmpHeader.m_yPixelsPerMeter = 0;
bmpHeader.m_numColors = 2;
bmpHeader.m_importantColorCount = 2;

fwrite(&bmpHeader, 1, sizeof(bmpHeader), outF);

const uint8_t paletteData[] = {
0, 0, 0, 0,
255, 255, 255, 0 };

fwrite(paletteData, 1, sizeof(paletteData), outF);
uint8_t padding[2] = { 0, 0 };

for (int y = 0; y < 16; y++)
{
const uint8_t *maskRow = cursorData->m_mask + (15 - y) * 2;
const uint8_t *row = cursorData->m_pixels + (15 - y) * 2;
const uint8_t modifiedRow[] = { row[0] ^ maskRow[0], row[1] ^ maskRow[1] };
fwrite(modifiedRow, 1, 2, outF);
fwrite(padding, 1, 2, outF);
}

for (int y = 0; y < 16; y++)
{
const uint8_t *row = cursorData->m_mask + (15 - y) * 2;
const uint8_t modifiedRow[] = { row[0] ^ 255, row[1] ^ 255 };
fwrite(modifiedRow, 1, 2, outF);
fwrite(padding, 1, 2, outF);
}

long imageDataEnd = ftell(outF);

fseek(outF, sizeof(IconDir), SEEK_SET);

iconDirEntry.m_imageDataSize = static_cast<uint32_t>(imageDataEnd - imageDataStart);
fwrite(&iconDirEntry, 1, sizeof(IconDirEntry), outF);
fclose(outF);
}
}
}

void ConvertCursors(PortabilityLayer::ResourceFile *resFile)
{
const PortabilityLayer::ResourceCompiledTypeList *typeList = resFile->GetResourceTypeList('crsr');
Expand Down Expand Up @@ -196,7 +308,7 @@ void ConvertCursors(PortabilityLayer::ResourceFile *resFile)
}

char outPath[64];
sprintf_s(outPath, "Packaged\\WinCursors\\%i.cur", resID);
sprintf_s(outPath, "Packaged\\WinCursors\\c%i.cur", resID);

FILE *outF = nullptr;
errno_t outErr = fopen_s(&outF, outPath, "wb");
Expand Down Expand Up @@ -335,6 +447,7 @@ int main(int argc, const char **argv)
stream.Close();

ConvertCursors(resFile);
ConvertBWCursors(resFile);
ConvertIconFamily(resFile, 'ics#', 'ics8', "Small", 16);
ConvertIconFamily(resFile, 'ICN#', 'icl8', "Large", 32);

Expand Down
18 changes: 9 additions & 9 deletions GpApp/AnimCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "Externs.h"
#include "Environ.h"
#include "HostDisplayDriver.h"
#include "IGpColorCursor.h"
#include "IGpCursor.h"
#include "IGpDisplayDriver.h"
#include "ResourceManager.h"

Expand All @@ -37,7 +37,7 @@ typedef struct
{
struct
{
IGpColorCursor *hwCursor;
IGpCursor *hwCursor;
} frame[1];
} compiledAcurRec;

Expand All @@ -61,7 +61,7 @@ compiledAcurHandle compiledAnimCursorH = nil;
Boolean GetColorCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCursH)
{
short i, j;
IGpColorCursor *hwCursor;
IGpCursor *hwCursor;
Boolean result = true;

if (ballCursH)
Expand All @@ -70,7 +70,7 @@ Boolean GetColorCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCu
HideCursor(); // Hide the cursor
for (i = 0; i < j; i++) // Walk through the acur resource
{
hwCursor = PortabilityLayer::HostDisplayDriver::GetInstance()->LoadColorCursor((*ballCursH)->frame[i].resID); // Get the cursor
hwCursor = PortabilityLayer::HostDisplayDriver::GetInstance()->LoadCursor(true, (*ballCursH)->frame[i].resID); // Get the cursor
if (hwCursor == nil) // Make sure a real cursor was returned
{ // If not, trash all cursors loaded
for (j = 0; j < i; j++)
Expand All @@ -81,7 +81,7 @@ Boolean GetColorCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCu
else // But, if the cursor loaded ok
{ // add it to our list or cursor handles
(*compiledBallCursH)->frame[i].hwCursor = hwCursor;
PortabilityLayer::HostDisplayDriver::GetInstance()->SetColorCursor(hwCursor);
PortabilityLayer::HostDisplayDriver::GetInstance()->SetCursor(hwCursor);
}
}
InitCursor(); // Show the cursor again (as arrow)
Expand Down Expand Up @@ -168,10 +168,10 @@ void IncrementCursor (void)
(*animCursorH)->index++;
(*animCursorH)->index %= (*animCursorH)->n;

PortabilityLayer::HostDisplayDriver::GetInstance()->SetColorCursor((*compiledAnimCursorH)->frame[(*animCursorH)->index].hwCursor);
PortabilityLayer::HostDisplayDriver::GetInstance()->SetCursor((*compiledAnimCursorH)->frame[(*animCursorH)->index].hwCursor);
}
else
SetBuiltinCursor(watchCursor);
PortabilityLayer::HostDisplayDriver::GetInstance()->SetStandardCursor(EGpStandardCursors::kWait);
}

//-------------------------------------------------------------- DecrementCursor
Expand All @@ -188,10 +188,10 @@ void DecrementCursor (void)
if (((*animCursorH)->index) < 0)
(*animCursorH)->index = ((*animCursorH)->n) - 1;

PortabilityLayer::HostDisplayDriver::GetInstance()->SetColorCursor((*compiledAnimCursorH)->frame[(*animCursorH)->index].hwCursor);
PortabilityLayer::HostDisplayDriver::GetInstance()->SetCursor((*compiledAnimCursorH)->frame[(*animCursorH)->index].hwCursor);
}
else
SetBuiltinCursor(watchCursor);
PortabilityLayer::HostDisplayDriver::GetInstance()->SetStandardCursor(EGpStandardCursors::kWait);
}

//-------------------------------------------------------------- SpinCursor
Expand Down
6 changes: 3 additions & 3 deletions GpApp/Coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ void OpenCoordWindow (void)

if (coordWindow == nil)
{
const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar;
const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar | PortabilityLayer::WindowStyleFlags::kCloseBox;

QSetRect(&coordWindowRect, 0, 0, 50, 38);
if (thisMac.hasColor)
coordWindow = NewCWindow(nil, &coordWindowRect,
PSTR("Tools"), false, windowStyle, kPutInFront, true, 0L);
PSTR("Tools"), false, windowStyle, kPutInFront, 0L);
else
coordWindow = NewWindow(nil, &coordWindowRect,
PSTR("Tools"), false, windowStyle, kPutInFront, true, 0L);
PSTR("Tools"), false, windowStyle, kPutInFront, 0L);

if (coordWindow == nil)
RedAlert(kErrNoMemory);
Expand Down
4 changes: 3 additions & 1 deletion GpApp/DialogUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ void GetDialogString (Dialog *theDialog, short item, StringPtr theString)

void SetDialogString (Dialog *theDialog, short item, const PLPasStr &theString)
{
theDialog->GetItems()[item - 1].GetWidget()->SetString(theString);
PortabilityLayer::Widget *widget = theDialog->GetItems()[item - 1].GetWidget();
widget->SetString(theString);
widget->DrawControl(theDialog->GetWindow()->GetDrawSurface());
}

//-------------------------------------------------------------- GetDialogStringLen
Expand Down
1 change: 1 addition & 0 deletions GpApp/DynamicMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Environ.h"
#include "MainWindow.h"
#include "Objects.h"
#include "QDPixMap.h"
#include "RectUtils.h"
#include "Room.h"
#include "Utilities.h"
Expand Down
2 changes: 1 addition & 1 deletion GpApp/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void HandleIdleTask (void)
{
if (theMode == kEditMode)
{
SetPort((GrafPtr)mainWindow);
SetPort(&mainWindow->GetDrawSurface()->m_port);
DoMarquee();

if ((autoRoomEdit) && (newRoomNow))
Expand Down
2 changes: 1 addition & 1 deletion GpApp/HighScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void DoHighScores (void)
Rect tempRect;

SpinCursor(3);
SetPort((GrafPtr)workSrcMap);
SetPort(&workSrcMap->m_port);
workSrcMap->FillRect(workSrcRect);
QSetRect(&tempRect, 0, 0, 640, 480);
QOffsetRect(&tempRect, splashOriginH, splashOriginV);
Expand Down
8 changes: 3 additions & 5 deletions GpApp/House.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
void UpdateGoToDialog (Dialog *);
Boolean GoToFilter (Dialog *, EventRecord *, short *);

extern PortabilityLayer::ResourceArchive *houseResFork;


houseHand thisHouse;
linksPtr linksList;
Expand Down Expand Up @@ -241,11 +243,7 @@ void WhereDoesGliderBegin (Rect *theRect, short mode)

Boolean HouseHasOriginalPicts (void)
{
short nPicts;

PL_NotYetImplemented(); nPicts = 0;
//nPicts = Count1Resources('PICT');
return (nPicts > 0);
return houseResFork->HasAnyResourcesOfType('PICT');
}

//-------------------------------------------------------------- CountHouseLinks
Expand Down
Loading

0 comments on commit c78a20d

Please sign in to comment.