renamed Core namespace to core
This commit is contained in:
@@ -22,7 +22,7 @@ using uchar = unsigned char;
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Core {
|
||||
namespace core {
|
||||
namespace Constants {
|
||||
|
||||
//===========================================================================================
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Core {
|
||||
namespace core {
|
||||
|
||||
bool Controller::isActive() const { return active_; }
|
||||
|
||||
@@ -173,13 +173,13 @@ void Controller::CreateGuiContext() {
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/DroidSans.ttf", 16.0f);
|
||||
|
||||
// Set the default style
|
||||
Style::ColorsYaze();
|
||||
gui::ColorsYaze();
|
||||
|
||||
// Build a new ImGui frame
|
||||
ImGui_ImplSDLRenderer_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(sdl_window_.get());
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
} // namespace core
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
@@ -16,7 +16,7 @@ int main(int argc, char **argv);
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Core {
|
||||
namespace core {
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "controller.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
yaze::application::Core::Controller controller;
|
||||
yaze::application::core::Controller controller;
|
||||
controller.onEntry();
|
||||
while (controller.isActive()) {
|
||||
controller.onInput();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace yaze {
|
||||
namespace application {
|
||||
namespace Data {
|
||||
|
||||
using namespace Core;
|
||||
using namespace core;
|
||||
using namespace Graphics;
|
||||
|
||||
Overworld::~Overworld() {
|
||||
@@ -104,7 +104,7 @@ void Overworld::AssembleMap32Tiles() {
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap16Tiles() {
|
||||
int tpos = Core::Constants::map16Tiles;
|
||||
int tpos = core::Constants::map16Tiles;
|
||||
for (int i = 0; i < 4096; i += 1) // 3760
|
||||
{
|
||||
TileInfo t0 = GetTilesInfo((uintptr_t)rom_.GetRawData() + tpos);
|
||||
|
||||
@@ -49,8 +49,8 @@ class Overworld {
|
||||
std::vector<ushort> tileRightEntrance;
|
||||
|
||||
int map32address[4] = {
|
||||
Core::Constants::map32TilesTL, Core::Constants::map32TilesTR,
|
||||
Core::Constants::map32TilesBL, Core::Constants::map32TilesBR};
|
||||
core::Constants::map32TilesTL, core::Constants::map32TilesTR,
|
||||
core::Constants::map32TilesBL, core::Constants::map32TilesBR};
|
||||
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include "Core/constants.h"
|
||||
#include "gui/input.h"
|
||||
#include "Data/rom.h"
|
||||
#include "Editor/overworld_editor.h"
|
||||
#include "Graphics/icons.h"
|
||||
#include "Graphics/palette.h"
|
||||
#include "Graphics/tile.h"
|
||||
#include "gui/icons.h"
|
||||
#include "gui/input.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace Editor {
|
||||
|
||||
using namespace Core;
|
||||
using namespace core;
|
||||
|
||||
Editor::Editor() {
|
||||
for (auto &k : Core::Constants::kKeywords)
|
||||
for (auto &k : core::Constants::kKeywords)
|
||||
language_65816_.mKeywords.emplace(k);
|
||||
|
||||
for (auto &k : Core::Constants::kIdentifiers) {
|
||||
for (auto &k : core::Constants::kIdentifiers) {
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = "Built-in function";
|
||||
language_65816_.mIdentifiers.insert(std::make_pair(std::string(k), id));
|
||||
@@ -296,10 +296,10 @@ void Editor::DrawGraphicsSheet(int offset) {
|
||||
|
||||
unsigned int snesAddr = 0;
|
||||
unsigned int pcAddr = 0;
|
||||
snesAddr = (unsigned int)((
|
||||
((uchar)(rom_.GetRawData()[0x4F80 + offset]) << 16) |
|
||||
((uchar)(rom_.GetRawData()[0x505F + offset]) << 8) |
|
||||
((uchar)(rom_.GetRawData()[0x513E + offset]))));
|
||||
snesAddr =
|
||||
(unsigned int)((((uchar)(rom_.GetRawData()[0x4F80 + offset]) << 16) |
|
||||
((uchar)(rom_.GetRawData()[0x505F + offset]) << 8) |
|
||||
((uchar)(rom_.GetRawData()[0x513E + offset]))));
|
||||
pcAddr = rom_.SnesToPc(snesAddr);
|
||||
std::cout << "Decompressing..." << std::endl;
|
||||
char *decomp = rom_.Decompress(pcAddr);
|
||||
|
||||
@@ -36,7 +36,7 @@ void OverworldEditor::Update() {
|
||||
if (rom_.isLoaded()) {
|
||||
if (!all_graphics_loaded_) {
|
||||
LoadGraphics();
|
||||
overworld_.Load(rom_);
|
||||
//overworld_.Load(rom_);
|
||||
all_graphics_loaded_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@ namespace Graphics {
|
||||
int GetPCGfxAddress(char *romData, char id) {
|
||||
char **info1 = new char *[255];
|
||||
int gfxPointer1 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_1_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_1_pointer]),
|
||||
lorom_snes_to_pc((romData[core::Constants::gfx_1_pointer + 1] << 8) +
|
||||
(romData[core::Constants::gfx_1_pointer]),
|
||||
info1);
|
||||
int gfxPointer2 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_2_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_2_pointer]),
|
||||
lorom_snes_to_pc((romData[core::Constants::gfx_2_pointer + 1] << 8) +
|
||||
(romData[core::Constants::gfx_2_pointer]),
|
||||
info1);
|
||||
int gfxPointer3 =
|
||||
lorom_snes_to_pc((romData[Core::Constants::gfx_3_pointer + 1] << 8) +
|
||||
(romData[Core::Constants::gfx_3_pointer]),
|
||||
lorom_snes_to_pc((romData[core::Constants::gfx_3_pointer + 1] << 8) +
|
||||
(romData[core::Constants::gfx_3_pointer]),
|
||||
info1);
|
||||
|
||||
char gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||
@@ -45,7 +45,7 @@ char *CreateAllGfxDataRaw(char *romData) {
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
for (int i = 0; i < Core::Constants::NumberOfSheets; i++) {
|
||||
for (int i = 0; i < core::Constants::NumberOfSheets; i++) {
|
||||
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||
@@ -53,15 +53,15 @@ char *CreateAllGfxDataRaw(char *romData) {
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new char[Core::Constants::Uncompressed3BPPSize];
|
||||
data = new char[core::Constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(romData, (char)i);
|
||||
for (int j = 0; j < Core::Constants::Uncompressed3BPPSize; j++) {
|
||||
for (int j = 0; j < core::Constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = romData[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data = alttp_decompress_gfx((char *)romData,
|
||||
GetPCGfxAddress(romData, (char)i),
|
||||
Core::Constants::UncompressedSheetSize,
|
||||
core::Constants::UncompressedSheetSize,
|
||||
&uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < Core::Constants::NumberOfSheets; s++) // Per Sheet
|
||||
for (int s = 0; s < core::Constants::NumberOfSheets; s++) // Per Sheet
|
||||
{
|
||||
for (int j = 0; j < 4; j++) // Per Tile Line Y
|
||||
{
|
||||
@@ -160,9 +160,9 @@ void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
|
||||
}
|
||||
|
||||
if (isbpp3[s]) {
|
||||
sheetPosition += Core::Constants::Uncompressed3BPPSize;
|
||||
sheetPosition += core::Constants::Uncompressed3BPPSize;
|
||||
} else {
|
||||
sheetPosition += Core::Constants::UncompressedSheetSize;
|
||||
sheetPosition += core::Constants::UncompressedSheetSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Bitmap {
|
||||
char *pixel_data_;
|
||||
};
|
||||
|
||||
static bool isbpp3[Core::Constants::NumberOfSheets];
|
||||
static bool isbpp3[core::Constants::NumberOfSheets];
|
||||
|
||||
int GetPCGfxAddress(char *romData, char id);
|
||||
char *CreateAllGfxDataRaw(char *romData);
|
||||
|
||||
1232
src/application/core/constants.h
Normal file
1232
src/application/core/constants.h
Normal file
File diff suppressed because it is too large
Load Diff
185
src/application/core/controller.cc
Normal file
185
src/application/core/controller.cc
Normal file
@@ -0,0 +1,185 @@
|
||||
#include "controller.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/backends/imgui_impl_sdl.h>
|
||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Editor/editor.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace core {
|
||||
|
||||
bool Controller::isActive() const { return active_; }
|
||||
|
||||
void Controller::onEntry() {
|
||||
CreateWindow();
|
||||
CreateRenderer();
|
||||
CreateGuiContext();
|
||||
editor_.SetupScreen(sdl_renderer_);
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
|
||||
io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey(SDLK_RETURN);
|
||||
io.KeyMap[ImGuiKey_UpArrow] = SDL_GetScancodeFromKey(SDLK_UP);
|
||||
io.KeyMap[ImGuiKey_DownArrow] = SDL_GetScancodeFromKey(SDLK_DOWN);
|
||||
io.KeyMap[ImGuiKey_Tab] = SDL_GetScancodeFromKey(SDLK_TAB);
|
||||
io.KeyMap[ImGuiKey_LeftCtrl] = SDL_GetScancodeFromKey(SDLK_LCTRL);
|
||||
active_ = true;
|
||||
}
|
||||
|
||||
void Controller::onInput() {
|
||||
int wheel = 0;
|
||||
int mouseX;
|
||||
int mouseY;
|
||||
SDL_Event event;
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
const int buttons = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_UP:
|
||||
case SDLK_DOWN:
|
||||
case SDLK_RETURN:
|
||||
case SDLK_BACKSPACE:
|
||||
case SDLK_TAB:
|
||||
io.KeysDown[event.key.keysym.scancode] =
|
||||
(event.type == SDL_KEYDOWN);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYUP: {
|
||||
int key = event.key.keysym.scancode;
|
||||
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
|
||||
io.KeysDown[key] = (event.type == SDL_KEYDOWN);
|
||||
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
|
||||
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
|
||||
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
|
||||
io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
quit();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
io.DisplaySize.x = static_cast<float>(event.window.data1);
|
||||
io.DisplaySize.y = static_cast<float>(event.window.data2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
io.AddInputCharactersUTF8(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
wheel = event.wheel.y;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
io.DeltaTime = 1.0f / 60.0f;
|
||||
io.MousePos = ImVec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
|
||||
io.MouseDown[0] = buttons & SDL_BUTTON(SDL_BUTTON_LEFT);
|
||||
io.MouseDown[1] = buttons & SDL_BUTTON(SDL_BUTTON_RIGHT);
|
||||
io.MouseWheel = static_cast<float>(wheel);
|
||||
}
|
||||
|
||||
void Controller::onLoad() { editor_.UpdateScreen(); }
|
||||
|
||||
void Controller::doRender() {
|
||||
SDL_RenderClear(sdl_renderer_.get());
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
||||
SDL_RenderPresent(sdl_renderer_.get());
|
||||
}
|
||||
|
||||
void Controller::onExit() {
|
||||
ImGui_ImplSDLRenderer_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void Controller::CreateWindow() {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING)) {
|
||||
SDL_Log("SDL_Init: %s\n", SDL_GetError());
|
||||
} else {
|
||||
sdl_window_ = std::unique_ptr<SDL_Window, sdl_deleter>(
|
||||
SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
||||
1200, // width, in pixels
|
||||
800, // height, in pixels
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL),
|
||||
sdl_deleter());
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::CreateRenderer() {
|
||||
if (sdl_window_ == nullptr) {
|
||||
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
} else {
|
||||
sdl_renderer_ = std::unique_ptr<SDL_Renderer, sdl_deleter>(
|
||||
SDL_CreateRenderer(
|
||||
sdl_window_.get(), -1,
|
||||
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
|
||||
sdl_deleter());
|
||||
if (sdl_renderer_ == nullptr) {
|
||||
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
} else {
|
||||
SDL_SetRenderDrawBlendMode(sdl_renderer_.get(), SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(sdl_renderer_.get(), 0x00, 0x00, 0x00, 0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::CreateGuiContext() {
|
||||
// Create the ImGui and ImPlot contexts
|
||||
ImGui::CreateContext();
|
||||
|
||||
// Initialize ImGui for SDL
|
||||
ImGui_ImplSDL2_InitForSDLRenderer(sdl_window_.get(), sdl_renderer_.get());
|
||||
ImGui_ImplSDLRenderer_Init(sdl_renderer_.get());
|
||||
|
||||
// Load available fonts
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Karla-Regular.ttf", 14.0f);
|
||||
|
||||
// merge in icons from Google Material Design
|
||||
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
||||
ImFontConfig icons_config;
|
||||
icons_config.MergeMode = true;
|
||||
icons_config.GlyphOffset.y = 5.0f;
|
||||
icons_config.GlyphMinAdvanceX = 13.0f;
|
||||
icons_config.PixelSnapH = true;
|
||||
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, 18.0f, &icons_config,
|
||||
icons_ranges);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Roboto-Medium.ttf", 14.0f);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Cousine-Regular.ttf", 14.0f);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/DroidSans.ttf", 16.0f);
|
||||
|
||||
// Set the default style
|
||||
gui::ColorsYaze();
|
||||
|
||||
// Build a new ImGui frame
|
||||
ImGui_ImplSDLRenderer_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(sdl_window_.get());
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
55
src/application/core/controller.h
Normal file
55
src/application/core/controller.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
#define YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
#define SDL_MAIN_HANDLED
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/backends/imgui_impl_sdl.h>
|
||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include "Editor/editor.h"
|
||||
#include "gui/icons.h"
|
||||
#include "gui/style.h"
|
||||
|
||||
int main(int argc, char **argv);
|
||||
|
||||
namespace yaze {
|
||||
namespace application {
|
||||
namespace core {
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller() = default;
|
||||
|
||||
bool isActive() const;
|
||||
void onEntry();
|
||||
void onInput();
|
||||
void onLoad();
|
||||
void doRender();
|
||||
void onExit();
|
||||
|
||||
private:
|
||||
void CreateWindow();
|
||||
void CreateRenderer();
|
||||
void CreateGuiContext();
|
||||
inline void quit() { active_ = false; }
|
||||
friend int ::main(int argc, char **argv);
|
||||
|
||||
struct sdl_deleter {
|
||||
void operator()(SDL_Window *p) const { SDL_DestroyWindow(p); }
|
||||
void operator()(SDL_Renderer *p) const { SDL_DestroyRenderer(p); }
|
||||
void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); }
|
||||
};
|
||||
|
||||
bool active_;
|
||||
Editor::Editor editor_;
|
||||
std::shared_ptr<SDL_Window> sdl_window_;
|
||||
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
} // namespace application
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
18
src/application/core/entry_point.h
Normal file
18
src/application/core/entry_point.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef YAZE_APPLICATION_CONTROLLER_ENTRYPOINT_H
|
||||
#define YAZE_APPLICATION_CONTROLLER_ENTRYPOINT_H
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
yaze::application::core::Controller controller;
|
||||
controller.onEntry();
|
||||
while (controller.isActive()) {
|
||||
controller.onInput();
|
||||
controller.onLoad();
|
||||
controller.doRender();
|
||||
}
|
||||
controller.onExit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif // YAZE_APPLICATION_CONTROLLER_ENTRYPOINT_H
|
||||
Reference in New Issue
Block a user