Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Programmer16

Member Since 31 Jan 2003
Offline Last Active Dec 21 2014 10:26 PM

Topics I've Started

So...the world has ended. What do you do now?

19 February 2012 - 06:24 PM

Ok, I've reworded this a little bit as it was kind of confusing.

So, let's say the world has ended and you are one of the few survivors. It doesn't really matter how the world ended, but I'll post some facts to make things a little more interesting:
  • The majority of the water supply is no longer available (dried up, tainted, whatever)
  • Of the population (per state/province) 5% survived as normal, living human beings.
  • Of the population (per state/province) 30% turned into mutants/zombies/[insert something else mean or scary here].
  • The remaining population has died.
  • Animals, buildings, the landscape, etc were unaffected by the tragedy.
  • There are a few known 'safe havens'
As I stated, you're one of the survivors, so what would you do? Obviously there are no right or wrong answers and you can post whatever you think. You can also post more than one idea.

This is a question that I've always been curious about; I know (or rather, I'm pretty sure) what I would do, but I'm curious what others would do.

Anyway, I'll start off:
I'm kind of a scrounger, but with the threat looming overhead I would find weapons and armor first. Then, I might just go looting. I'm also the protecting sort, so I would probably be looking for other survivors/people in need while doing said looting. On top of that I'm smart enough to realize that I'd have to rest eventually and that usually goes better with someone watching your back so I'd either start looking for one of the safe havens or start building a fort of my own.

LuaInterface and Coroutines

16 October 2010 - 07:45 PM

I've spent the last two days working on this and I've finally cobbled together a mediocre solution.

To start-off, I have 5 coroutine managing functions:

function SetupCoroutineTable()
coroutine_table = { };
end

function AddCoroutine(Item)
table.insert(coroutine_table, Item);
end

function RemoveCoroutine(Index)
table.remove(coroutine_table, Index);
end

function ResumeCoroutine(Index)
Item = coroutine_table[Index];
if coroutine.status(Item) ~= 'dead' then
coroutine.resume(Item);
end
end

function ResumeAllCoroutines()
for Index,Item in ipairs(coroutine_table) do
ResumeCoroutine(Index);
end
end





I call SetupCoroutineTable at the start of my program. The major issue I see here is that I don't manage the table at all (just keep inserting and only remove when told to.) I could add a managing function that clears the dead coroutines, but this is the least of my concerns right now.

Now for my sample. The main idea behind this is to use for scripting scenes (move player here, show message, do this, etc.) So, I went with counting.


-- the function that my code calls.
-- Would be somthing like an event's OnActivate function.
function foo()
count(10);
display('Finished counting to 10.\n');
count(21);
display('Finished counting to 21.\n');
end

-- This is the count function called above.
function count(value)
set_value(0); -- C# method
count_to(value); -- C# method
while get_value() < value do -- get_value() is another C# method
coroutine.yield();
end
end





This is one of my major issue: I don't want to have to write systems like this for everything that I want the script to be able to wait on (i.e. ideally count would be in the actual code.)

Now for the ugly part. I have a method in C#:

public void CallScriptFunction(string Name)
{
luaVM.DoString(@"local coro = coroutine.create(" + Name + ");
InsertCoroutine(coro);
coroutine.resume(coro);");
}





The main issues being that: it's very hacked together and it's not flexible (doesn't support calling a method with arguments.)

What I'm wondering is if anyone has any insight into a better solution (or some suggestions to improve what I have.)

Edited at 4:25am
I just got done trying a new system. It uses the main portion, but is more flexible. I implemented a class named WaitInfo which contains a delegate that returns a bool. This is returned from any method I want to allow to wait. Then, in my lua code, I pass the WaitInfo to my wait function. Here's the revised code


public delegate bool WaitPredicate();
public sealed class WaitInfo
{
WaitPredicate predicate;

public WaitInfo(WaitPredicate Predicate)
{
this.predicate = Predicate;
}

public bool IsFinished()
{
return predicate();
}
}

public WaitInfo CountTo(int Value)
{
TaskManager.Add(new CountTask((task) =>
{
++countValue;
Output += countValue.ToString() + " ";
if(countValue >= Value)
task.Kill();
}));

return new WaitInfo(new WaitPredicate(() => { return countValue >= Value; }));
}



The new WaitInfo class and CountTo method (note that I tried just returning a WaitPredicate, but I can't get Lua to call it. I don't get any errors, it's just never called. I was thinking maybe I need to call Invoke or something, but I didn't try it.)


function wait(winfo)
while not winfo:IsFinished() do
coroutine.yield();
end
end

function foo()
local winfo = count_to(10);
wait(winfo);
display('finished the first count!\n');

winfo = count_to(21);
wait(winfo);
display('finished the second count!\n');
end



The new wait function and update foo function.

This new system is much better than what I had, but I'm still looking for suggestions; especially on the coroutine-wrapping code I've implemented (read: the major hack I have in place.)

Edited at 4:56am
Ok, I just went back through and yes, I can simply return a WaitPredicate and then in wait I just call winfo:Invoke().

Also, is using DoString() as I am even stable? If so, I could omit the wait function and set it up using DoString() straight from the methods (i.e. inside of CountTo and such.)

I'd also like to note that a lot of code is just for testing this (like the CountTo method's code and what-not.) I'm just trying to get the system nailed down.

[Edited by - Programmer16 on October 17, 2010 4:01:55 AM]

[C++/DX9] Weird texture editing & render issue

03 March 2008 - 07:47 AM

I coded up some drawing routines for my Texture class, including a Layer class (it all wraps up creating an instance of IDirect3DSurface9, locking, setting/getting pixel data, and unlocking.) It all works fine...except if I try to use it during runtime. The weird part? It does work...kind of. If I save the texture to a file, the file looks perfect, however it doesn't render correctly. I've double checked all of my code and the texture is being rendered every frame. Here's the code for my wrappers
class Texture
{
public:
	static TextureManager TexturePool;
	typedef boost::shared_ptr<Texture> Pointer;

	class Layer
	{
		IDirect3DSurface9 *ComPtr;
		D3DLOCKED_RECT LockedRect;
		dft::Math::Rectangle LockedSection;
		DWORD *Bits;
		Texture *Owner;
		friend Texture;
	public:
		typedef boost::shared_ptr<Layer> Pointer;

		Layer();
		~Layer();
		bool Create(dft::Graphics::Texture *SourceTexture, int Layer = 0);

		bool Lock(dft::Math::Rectangle *LockSection, int Flags = D3DLOCK_READONLY);
		dft::Graphics::Color GetPixel(int X, int Y);
		dft::Graphics::Color GetPixel(const dft::Math::Point Location);
		dft::Graphics::Color *GetPixelChunk(dft::Math::Rectangle *SourceRectangle);
		void SetPixel(int X, int Y, dft::Graphics::Color PixelColor);
		void SetPixel(const dft::Math::Point Location, dft::Graphics::Color PixelColor);
		void DrawLine(int StartX, int StartY, int EndX, int EndY, dft::Graphics::Color PixelColor);
		void DrawLine(const dft::Math::Point &StartPoint, const dft::Math::Point &EndPoint, dft::Graphics::Color PixelColor);
		void DrawRectangle(int X, int Y, int Width, int Height, dft::Graphics::Color PixelColor);
		void DrawRectangle(const dft::Math::Rectangle &DestinationRectangle, dft::Graphics::Color PixelColor);
		void DrawRectangle(const dft::Math::Point &Location, const dft::Math::Dimensions &Size, dft::Graphics::Color PixelColor);
		void DrawChunk(const dft::Math::Point &Location, dft::Graphics::Color *Chunk, const dft::Math::Dimensions &ChunkSize);
		void CopyFromLayer(Layer::Pointer Source, const dft::Math::Rectangle &SourceRectangle, const dft::Math::Rectangle &Destination);
		void Unlock();
	};

	class Information
	{
	public:
		int Levels;
		unsigned long Usage;
		D3DFORMAT Format;
		D3DPOOL Pool;
		unsigned long Filter;
		unsigned long MipFilter;
	};

	IDirect3DTexture9 *ComPtr;
	std::string FilePath;
	Math::Dimensions Size;
	Math::Dimensions ImageSize;
	Device *GfxDevice;
	Information Info;

	Texture();
	~Texture();

	ReturnValueEx<HRESULT> LoadFromFile(Device &GfxDevice, const std::string &FilePath);
	ReturnValueEx<HRESULT> LoadFromFileEx(Device &GfxDevice, const std::string &FilePath, int Width, int Height, int Levels, unsigned long Usage, D3DFORMAT Format, D3DPOOL Pool, unsigned long Filter, unsigned long MipFilter);
	ReturnValueEx<HRESULT> CreateBlank(Device &GfxDevice, int Width, int Height, int Levels, unsigned long Usage, D3DFORMAT Format, D3DPOOL Pool, const std::string &Name);
	ReturnValueEx<HRESULT> Save(const std::string &OutputFilePath, D3DXIMAGE_FILEFORMAT ImageFileFormat);
	Layer::Pointer GetLayer(int Layer = 0);
	bool Reload();
	void Release();

	static Pointer GetTexture(Device &GfxDevice, const std::string &Path);
};

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::Layer::Layer()
{
	Bits = 0;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::Layer::~Layer()
{
	if(ComPtr)
	{
		ComPtr->Release();
		ComPtr = 0;
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
bool Texture::Layer::Create(dft::Graphics::Texture *SourceTexture, int Layer)
{
	if(!SourceTexture)
		return false;
	if(FAILED(SourceTexture->ComPtr->GetSurfaceLevel(Layer, &ComPtr)))
		return false;
	Owner = SourceTexture;
	return true;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
bool Texture::Layer::Lock(dft::Math::Rectangle *LockSection, int Flags)
{
	if(FAILED(ComPtr->LockRect(&LockedRect, LockSection != 0 ? &LockSection->ToRECT() : 0, Flags)))
		return false;
	Bits =(DWORD*)(LockedRect.pBits);
	if(LockSection)
		LockedSection = *LockSection;
	else if(Owner)
		LockedSection = dft::Math::Rectangle(0, 0, Owner->Size);
	return true;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dft::Graphics::Color Texture::Layer::GetPixel(int X, int Y)
{
	if(X > (LockedSection.Width() - LockedSection.Left) || Y > (LockedSection.Height() - LockedSection.Top) || X < 0 || Y < 0 || !Bits)
		return dft::Graphics::Color::FromArgb(0, 0, 0, 0);
	return Bits[((LockedRect.Pitch / sizeof(DWORD)) * Y) + X];
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dft::Graphics::Color Texture::Layer::GetPixel(const dft::Math::Point Location)
{
	return GetPixel(Location.X, Location.Y);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dft::Graphics::Color *Texture::Layer::GetPixelChunk(dft::Math::Rectangle *SourceRectangle)
{
	if(!Bits)
		return 0;

	if(SourceRectangle)
	{
		if(SourceRectangle->Width() == 0 || SourceRectangle->Height() == 0)
			return 0;
	}
	else
		SourceRectangle = &LockedSection;

	dft::Graphics::Color *Output = new dft::Graphics::Color[SourceRectangle->Area()];
	for(int Y = SourceRectangle->Top; Y < SourceRectangle->Bottom; ++Y)
	{
		for(int X = SourceRectangle->Left; X < SourceRectangle->Right; ++X)
		{
			int Index = ((Y - SourceRectangle->Top) * SourceRectangle->Width()) + (X - SourceRectangle->Left);
			Output[((Y - SourceRectangle->Top) * SourceRectangle->Width()) + (X - SourceRectangle->Left)] = GetPixel(X, Y);
		}
	}
	return Output;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::SetPixel(int X, int Y, dft::Graphics::Color PixelColor)
{
	if(X > (LockedSection.Width() - LockedSection.Left) || Y > (LockedSection.Height() - LockedSection.Top) || X < 0 || Y < 0 || !Bits)
		return;
	Bits[((LockedRect.Pitch / sizeof(DWORD)) * Y) + X] = PixelColor;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::SetPixel(const dft::Math::Point Location, dft::Graphics::Color PixelColor)
{
	SetPixel(Location.X, Location.Y, PixelColor);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawLine(int StartX, int StartY, int EndX, int EndY, dft::Graphics::Color PixelColor)
{
	bool Steep = abs(EndY - StartY) > abs(EndX - StartX);
	if(Steep)
	{
		StartX ^= StartY;
		StartY ^= StartX;
		StartX ^= StartY;

		EndX ^= EndY;
		EndY ^= EndX;
		EndX ^= EndY;
	}

	if(StartX > EndX)
	{
		StartX ^= EndX;
		EndX ^= StartX;
		StartX ^= EndX;

		StartY ^= EndY;
		EndY ^= StartY;
		StartY ^= EndY;
	}

	int DeltaX = EndX - StartX;
	int DeltaY = abs(EndY - StartY);
	int Error = -(DeltaX + 1) / 2;
	int YStep = 0;
	int Y = StartY;
	if(StartY < EndY)
		YStep = 1;
	else
		YStep = -1;

	for(int X = StartX; X < EndX; ++X)
	{
		if(Steep)
			SetPixel(Y, X, PixelColor);
		else
			SetPixel(X, Y, PixelColor);
		Error = Error + DeltaY;
		if(Error >= 0)
		{
			Y = Y + YStep;
			Error = Error - DeltaX;
		}
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawLine(const dft::Math::Point &StartPoint, const dft::Math::Point &EndPoint, dft::Graphics::Color PixelColor)
{
	DrawLine(StartPoint.X, StartPoint.Y, EndPoint.X, EndPoint.Y, PixelColor);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawRectangle(int X, int Y, int Width, int Height, dft::Graphics::Color PixelColor)
{
	for(int CurrentY = Y; CurrentY < (Y + Height); ++CurrentY)
	{
		DrawLine(X, CurrentY, X + Width, CurrentY, PixelColor);
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawRectangle(const dft::Math::Rectangle &DestinationRectangle, dft::Graphics::Color PixelColor)
{
	DrawRectangle(DestinationRectangle.Left, DestinationRectangle.Top, DestinationRectangle.Width(), DestinationRectangle.Height(), PixelColor);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawRectangle(const dft::Math::Point &Location, const dft::Math::Dimensions &Size, dft::Graphics::Color PixelColor)
{
	DrawRectangle(Location.X, Location.Y, Size.Width, Size.Height, PixelColor);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::DrawChunk(const dft::Math::Point &Location, dft::Graphics::Color *Chunk, const dft::Math::Dimensions &ChunkSize)
{
	if(!Chunk)
		return;

	for(int Y = 0; Y < ChunkSize.Height; ++Y)
	{
		for(int X = 0; X < ChunkSize.Width; ++X)
		{
			SetPixel(Location.X + X, Location.Y + Y, Chunk[(Y * ChunkSize.Width) + X]);
		}
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::CopyFromLayer(Layer::Pointer Source, const dft::Math::Rectangle &SourceRectangle, const dft::Math::Rectangle &Destination)
{
	dft::Graphics::Color *Chunk = Source->GetPixelChunk(&dft::Math::Rectangle(SourceRectangle));
	if(!Chunk)
		return;

	dft::Math::Dimensions ChunkSize = SourceRectangle.Size();
	int ColumnCount = (int)(ceil(((float)Destination.Width() / (float)ChunkSize.Width)));
	int RowCount = (int)(ceil(((float)Destination.Height() / (float)ChunkSize.Height)));
	for(int Row = 0; Row < RowCount; ++Row)
	{
		for(int Column = 0; Column < ColumnCount; ++Column)
		{
			DrawChunk(dft::Math::Point((ChunkSize.Width * Column) + Destination.Left, (ChunkSize.Height * Row) + Destination.Top), Chunk, ChunkSize);
		}
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Layer::Unlock()
{
	ComPtr->UnlockRect();
	Bits = 0;
	ZeroMemory(&LockedRect, sizeof(D3DLOCKED_RECT));
	LockedSection = LockedSection.Zero;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::Texture()
{
	ComPtr = 0;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::~Texture()
{
	Release();
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ReturnValueEx<HRESULT> Texture::LoadFromFile(Device &GfxDevice, const std::string &FilePath)
{
	return LoadFromFileEx(GfxDevice, FilePath, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ReturnValueEx<HRESULT> Texture::LoadFromFileEx(Device &GfxDevice, const std::string &FilePath, int Width, int Height, int Levels, unsigned long Usage, D3DFORMAT Format, D3DPOOL Pool, unsigned long Filter, unsigned long MipFilter)
{
	this->GfxDevice = &GfxDevice;
	std::string AbsoluteFilePath = FileSystem::GetAbsolutePath(FilePath);
	HRESULT Result = S_OK;
	D3DXIMAGE_INFO ImageInfo;
	if(FAILED(Result = D3DXCreateTextureFromFileEx(GfxDevice.ComPtr, AbsoluteFilePath.c_str(), Width, Height, Levels, Usage, Format, Pool, Filter, MipFilter, 0, &ImageInfo, 0, &ComPtr)))
		return ReturnValueEx<HRESULT>(false, Result, String::Format("Failed to load texture \"%s\". - %s", AbsoluteFilePath.c_str(), DXGetErrorDescription9(Result)));

	D3DSURFACE_DESC Desc;
	ComPtr->GetLevelDesc(0, &Desc);
	Size = Math::Dimensions(Desc.Width, Desc.Height);
	this->ImageSize = dft::Math::Dimensions(ImageInfo.Width, ImageInfo.Height);
	this->FilePath = AbsoluteFilePath;
	Info.Levels = Levels;
	Info.Usage = Usage;
	Info.Format = Format;
	Info.Pool = Pool;
	Info.Filter = Filter;
	Info.MipFilter = MipFilter;
	return ReturnValueEx<HRESULT>(true, Result, String::Format("Loaded the texture \"%s\".", FilePath.c_str()));
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ReturnValueEx<HRESULT> Texture::CreateBlank(Device &GfxDevice, int Width, int Height, int Levels, unsigned long Usage, D3DFORMAT Format, D3DPOOL Pool, const std::string &Name)
{
	HRESULT Result = S_OK;
	if(FAILED((Result = GfxDevice.ComPtr->CreateTexture(Width, Height, Levels, Usage, Format, Pool, &ComPtr, 0))))
		return ReturnValueEx<HRESULT>(false, Result, String::Format("Failed to create a blank texture with the name \"%s\". - %s", Name.c_str(), DXGetErrorDescription9(Result)));

	D3DSURFACE_DESC Desc;
	ComPtr->GetLevelDesc(0, &Desc);
	Size = Math::Dimensions(Desc.Width, Desc.Height);
	this->FilePath = Name;
	return ReturnValueEx<HRESULT>(true, Result, String::Format("Created the blank texture \"%s\".", FilePath.c_str()));
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ReturnValueEx<HRESULT> Texture::Save(const std::string &OutputFilePath, D3DXIMAGE_FILEFORMAT ImageFileFormat)
{
	HRESULT Result = S_OK;
	if(FAILED(Result = D3DXSaveTextureToFile(dft::FileSystem::GetAbsolutePath(OutputFilePath).c_str(), ImageFileFormat, ComPtr, 0)))
		return ReturnValueEx<HRESULT>(false, Result, String::Format("Failed to save the texture \"%s\" to the file \"%s\". - %s", FilePath.c_str(), OutputFilePath.c_str(), DXGetErrorDescription9(Result)));
	return ReturnValueEx<HRESULT>(true, Result, String::Format("Successfully saved the texture \"%s\" to the file \"%s.\"", FilePath.c_str(), OutputFilePath.c_str()));
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::Layer::Pointer Texture::GetLayer(int LayerIndex)
{
	Layer::Pointer NewLayer(new Layer);
	if(NewLayer->Create(this, LayerIndex))
		return NewLayer;
	return Layer::Pointer();
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
bool Texture::Reload()
{
	if(!GfxDevice)
		return false;
	Information Info = this->Info;
	std::string FilePath = this->FilePath;
	Release();
	return LoadFromFileEx(*GfxDevice, FilePath, Size.Width, Size.Height, Info.Levels, Info.Usage, Info.Format, Info.Pool, Info.Filter, Info.MipFilter).Succeeded;
	return true;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Texture::Release()
{
	if(ComPtr)
	{
		ComPtr->Release();
		ComPtr = 0;
		FilePath = "";
		Size = Math::Dimensions(0, 0);
		ZeroMemory(&Info, sizeof(Information));
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Texture::Pointer Texture::GetTexture(Device &GfxDevice, const std::string &Path)
{
	return TexturePool.GetTexture(GfxDevice, Path);
}



And here's my project's code that uses it:
// Creating the texture -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// this works fine
ScratchTexture->CreateBlank(GfxDevice, Background->Size.Width, Background->Size.Height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, Name + "Scratch");
dft::Graphics::Texture::Layer::Pointer Layer = ScratchTexture->GetLayer(0);
Layer->Lock(0);
for(std::vector<ScratchArea>::iterator Itor = ScratchAreas.begin(); Itor != ScratchAreas.end(); ++Itor)
Layer->DrawRectangle(Itor->Location, Itor->Size, dft::Graphics::Color(255, 128, 128, 128));
Layer->Unlock();

// Modifying Function -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dft::Math::Point Temp = Event.Position;
dft::Graphics::Texture::Layer::Pointer Layer = ScratchTexture->GetLayer(0);
Layer->Lock(0);
Layer->DrawLine(Temp.X - 4, Temp.Y + 4, Temp.X + 4, Temp.Y - 4, dft::Graphics::Color(0, 0, 0, 0));
Layer->DrawLine(Temp.X - 4, Temp.Y + 3, Temp.X + 3, Temp.Y - 4, dft::Graphics::Color(0, 0, 0, 0));
Layer->DrawLine(Temp.X - 3, Temp.Y + 4, Temp.X + 4, Temp.Y - 3, dft::Graphics::Color(0, 0, 0, 0));
Layer->Unlock();
// temp line ##TEMP##
ScratchTexture->Save("Output.png", D3DXIFF_PNG);



If you need any other information, just say so and I'll post it.

MessageBox style function

20 February 2008 - 07:13 AM

I'm working on a MessageBox style function for my game. Here's an example:
void OnActivate()
{
    std::string Choices[] = {"Yes", "No"};
    std::string Choice = dft::ShowChoiceBox("Do you want to continue?", Choices, sizeof(Choices) / sizeof(std::string) /* other stuff here */);
    if(Choice == "No")
        MyApp.Running = false;
}

The problem I'm having is the message loop. I've got it working by copying the main window's message pump. My question is: is this an ok solution? Or is there a better solution I should be looking for?

Journal Email Notifications

31 May 2007 - 05:40 PM

I was wondering if we could get email notifications for replies to our journals. I'd much prefer that to refreshing the page every now and then. Thanks!

PARTNERS