Added world size (the number of regions in a world)

The gird's 0, 0 index is now the center of the grid (so a 10, 10 grid goes from 4, 4 to -4, -4)
Gui_Panel_Refactor
Joeyrp 4 years ago
parent fff5c18842
commit bd63502601

@ -1,7 +1,7 @@
Build System: Build System:
✔ Add a build option to do a build without the editor @done (9/17/2021, 7:25:08 PM) ✔ Add a build option to do a build without the editor @done (9/17/2021, 7:25:08 PM)
Modify .sh scripts to recognize the noeditor flag Modify .sh scripts to recognize the noeditor flag @done (1/25/2022, 3:59:23 PM)
Core: Core:
☐ Add log settings to the state file ☐ Add log settings to the state file
@ -72,7 +72,7 @@ Utils:
Assets: Assets:
☐ Internal Asset Manager @high ✔ Internal Asset Manager @high @done (1/25/2022, 3:58:20 PM)
Types: Types:
@ -81,7 +81,7 @@ Assets:
✔ Decouple Image class from OGLRenderer @high @done (10/27/2021, 7:41:50 PM) ✔ Decouple Image class from OGLRenderer @high @done (10/27/2021, 7:41:50 PM)
☐ Font class ☐ Font class
☐ Sound class ☐ Sound class
☐ Script class ✔ Script class @done (1/25/2022, 3:58:28 PM)
Loaders: Loaders:
- Need class (or classes?) to load resources from the packed format that the pipeline generates - Need class (or classes?) to load resources from the packed format that the pipeline generates

@ -0,0 +1,33 @@
/******************************************************************************
* File - script.h
* Author - Joey Pollack
* Date - 2022/01/18 (y/m/d)
* Mod Date - 2022/01/18 (y/m/d)
* Description - Holds data for a LUA script
******************************************************************************/
#include "script.h"
namespace lunarium
{
void Script::SetScript(const char* script)
{
mScript = script;
}
const char* Script::GetScript() const
{
return mScript.c_str();
}
void Script::AddError(std::string error)
{
mScriptErrors.push_back(error);
}
const std::vector<std::string>* Script::GetErrors() const
{
return &mScriptErrors;
}
}

@ -26,7 +26,7 @@ namespace lunarium
const std::vector<std::string>* GetErrors() const; const std::vector<std::string>* GetErrors() const;
private: private:
char* mpScript; std::string mScript;
std::vector<std::string> mScriptErrors; std::vector<std::string> mScriptErrors;
}; };
} }

@ -5,6 +5,8 @@
* Mod Date - 2022/01/25 (y/m/d) * Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D fixed-size array of data. Size must be set when * Description - A 2D fixed-size array of data. Size must be set when
* this container is created and can not be changed later. * this container is created and can not be changed later.
* The 0, 0 position is the center of the grid (meaning negative
* indices are valid).
******************************************************************************/ ******************************************************************************/
#ifndef GRID_H_ #ifndef GRID_H_
@ -33,6 +35,7 @@ namespace lunarium
T Data; T Data;
}; };
Sizei mHalfSize;
Sizei mSize; Sizei mSize;
Node** mGrid; Node** mGrid;
}; };
@ -46,6 +49,9 @@ namespace lunarium
Grid<T>::Grid(Sizei size) Grid<T>::Grid(Sizei size)
: mSize(size) : mSize(size)
{ {
mHalfSize.Width = size.Width / 2;
mHalfSize.Height = size.Height / 2;
mGrid = new Node*[size.Width]; mGrid = new Node*[size.Width];
for (int i = 0; i < size.Width; i++) for (int i = 0; i < size.Width; i++)
{ {
@ -56,19 +62,19 @@ namespace lunarium
template<typename T> template<typename T>
T* Grid<T>::operator[](Point2Di at) T* Grid<T>::operator[](Point2Di at)
{ {
return &mGrid[at.X][at.Y].Data; return &mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data;
} }
template<typename T> template<typename T>
T Grid<T>::GetAt(Point2Di at) T Grid<T>::GetAt(Point2Di at)
{ {
return mGrid[at.X][at.Y].Data; return mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data;
} }
template<typename T> template<typename T>
void Grid<T>::SetAt(Point2Di at, T value) void Grid<T>::SetAt(Point2Di at, T value)
{ {
mGrid[at.X][at.Y].Data = value; mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data = value;
} }
template<typename T> template<typename T>

@ -18,8 +18,8 @@
namespace lunarium namespace lunarium
{ {
World::World(Camera* pCam, Sizei region_size) World::World(Camera* pCam, Sizei region_size, Sizei world_size)
: mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mRegions(region_size) : mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mRegions(region_size), mWorldSize(world_size)
{ {
mActiveRegion = { 0, 0 }; mActiveRegion = { 0, 0 };
mRegions.SetAll(nullptr); mRegions.SetAll(nullptr);
@ -68,6 +68,16 @@ namespace lunarium
return OpRes::Fail("World::SetRegion failed because a region already exists at (%n, %n)", at.X, at.Y); return OpRes::Fail("World::SetRegion failed because a region already exists at (%n, %n)", at.X, at.Y);
} }
// Validate the layers - each image needs to match the region size
for (int i = 0; i < region->mLayers.size(); i++)
{
if (region->mLayers[i]->GetWidth() != mRegionSize.Width
|| region->mLayers[i]->GetHeight() != mRegionSize.Height)
{
return OpRes::Fail("World::SetRegion failed because the region contains layers that do not match the region size");
}
}
*mRegions[at] = region; *mRegions[at] = region;
return OpRes::OK(); return OpRes::OK();
} }

@ -39,7 +39,7 @@ namespace lunarium
public: // INTERFACE public: // INTERFACE
World(Camera* pCam, Sizei region_size); World(Camera* pCam, Sizei region_size, Sizei world_size);
void OnLoad(); void OnLoad();
void OnUnload(); void OnUnload();
@ -65,7 +65,8 @@ namespace lunarium
Camera* mpCamera; Camera* mpCamera;
std::vector<GameObject*> mWorldObjects; std::vector<GameObject*> mWorldObjects;
Script* mpWorldScript; Script* mpWorldScript;
Sizei mRegionSize; Sizei mRegionSize; // in pixels
Sizei mWorldSize; // num regions ex. 10x10
Grid<Region*> mRegions; Grid<Region*> mRegions;
Point2Di mActiveRegion; Point2Di mActiveRegion;

@ -41,7 +41,7 @@ namespace lunarium
box_angle = 0.0f; box_angle = 0.0f;
// Setup the grid container // Setup the grid container
*mGrid[{5, 5}] = new GridTestObj {5, "This is grid space 5, 5"}; *mGrid[{-2, 0}] = new GridTestObj {5, "This is grid space -2, 0"};
} }
void SimpleRenderScene::OnTick(double delta) void SimpleRenderScene::OnTick(double delta)
@ -118,6 +118,6 @@ namespace lunarium
g->DrawBox(Rectangle(400, 400, 128.0f, 128.0f), Color(0.0f, 1.0f, 0.0f, 1.0f), 2.0f, box_angle); g->DrawBox(Rectangle(400, 400, 128.0f, 128.0f), Color(0.0f, 1.0f, 0.0f, 1.0f), 2.0f, box_angle);
g->DrawString((*mGrid[{5, 5,}])->msg.c_str(), Rectangle::MakeFromTopLeft(200.0f, 500.0f, 500.0f, 200.0f), Color(0.5f, 0.0f, 0.75f, 1.0f)); g->DrawString((*mGrid[{-2, 0,}])->msg.c_str(), Rectangle::MakeFromTopLeft(200.0f, 500.0f, 500.0f, 200.0f), Color(0.5f, 0.0f, 0.75f, 1.0f));
} }
} }

@ -1,6 +1,6 @@
<State> <State>
<DataDirectory>data/</DataDirectory> <DataDirectory>data/</DataDirectory>
<Mode Type="editor" /> <Mode Type="test" />
<Display Renderer="opengl" IsFullScreen="false" VSyncEnabled="true"> <Display Renderer="opengl" IsFullScreen="false" VSyncEnabled="true">
<FullScreenResolution Width="1920" Height="1080" /> <FullScreenResolution Width="1920" Height="1080" />
<WindowedSize Width="1280" Height="720" /> <WindowedSize Width="1280" Height="720" />

Loading…
Cancel
Save