Doxygen Samurai Engine 0.0.1
Doxygen Samurai Engine Documentation
Loading...
Searching...
No Matches
baseContainer.h
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <string>
4#include <staticVector.h>
5#include <fstream>
6#include <staticString.h>
7#include <SDL.h>
8
9#include "input/input.h"
12#include "openGL/frameBuffer.h"
14
15#define READENTIREFILE(x) bool x(const char* name, void* buffer, size_t size)
16typedef READENTIREFILE(readEntireFile_t);
17#undef READENTIREFILE
18
19#define GETFILESIZE(x) bool x(const char* name, size_t &size)
20typedef GETFILESIZE(getFileSize_t);
21#undef GETFILESIZE
22
23static constexpr size_t MaxAllocatorsCount = 128;
24
25#if SAMURAI_SDL
26 struct PikaFramebuffer{
27 SDL_Texture* texture = {};
28 int width = 0;
29 int height = 0;
30 };
31#endif
32
33//this is passed by the engine. You should not modify the data
34//this is also used by the engine to give you acces to some io functions
36{
39
40 //readEntireFile_t *readEntireFilePointer = {};
41 //getFileSize_t *getFileSizePointer = {};
42#if !SAMURAI_SDL
44#else
45 SDL_Window* wind = {};
46 SDL_Renderer* renderer = {};
47 PikaFramebuffer requestedFBO = {};
48#endif
49
52
53
54 bool readEntireFileBinary(const char *name, void *buffer, size_t size)
55 {
56 //PIKA_DEVELOPMENT_ONLY_ASSERT(readEntireFilePointer, "read entire file pointer not assigned");
57 bool success = true;
58
60 {
61 std::ifstream f(name, std::ios::binary);
62
63 if (!f.is_open())
64 {
65 success = false;
66 }
67 else
68 {
69 f.read((char*)buffer, size);
70 f.close();
71 }
72 }
74
75 return success;
76 }
77
78 bool getFileSizeBinary(const char *name, size_t &size)
79 {
80 //PIKA_DEVELOPMENT_ONLY_ASSERT(getFileSizePointer, "get file size pointer not assigned");
81
82 bool success = true;
83 size = 0;
84
85 //todo push pop allocator or use that pointer thing (and don't forget to only use explicit allocators calls or sthing)
87 {
88 std::ifstream f(name, std::ifstream::ate | std::ifstream::binary);
89 if (!f.is_open())
90 {
91 success = false;
92 }
93 else
94 {
95 size = f.tellg();
96 f.close();
97 }
98 }
100
101 return size;
102 }
103
104};
105
106
108{
109
110 //this is the main heap allocator memory size
112
113
114 //this will use the global allocator. you won't be able to use input recording or snapshots, and the
115 //memory leak protection won't be possible.
117
118
120
121 //add file extensions here so that the engine knows that your container can open them.
123
124 //the engine will create a new window for your container and give you the fbo to bind to
125 //in release that fbo will just be the default framebuffer
127
128 unsigned int requestImguiIds = 0;
129
131
133 {
134 if (this == &other) { return true; }
135
136 return
137 this->defaultHeapMemorySize == other.defaultHeapMemorySize &&
138 this->bonusAllocators == other.bonusAllocators &&
139 this->_internalNotImplemented == other._internalNotImplemented &&
140 this->requestImguiFbo == other.requestImguiFbo &&
141 this->requestImguiIds == other.requestImguiIds &&
142 this->useDefaultAllocator == other.useDefaultAllocator;
143 ;
144 }
145
147 {
148 return !(*this == other);
149 }
150
151
152};
153
154
156{
157
158 //this is used to give to the engine basic information about your container.
159 //this function should be pure
160 //this function should not allocate memory
161 //this should not be dependent on anything that is called on create or library initialization
163
164
165 virtual bool create(RequestedContainerInfo &requestedInfo, samurai::StaticString<256> commandLineArgument) = 0;
166
167 virtual bool update(
168 samurai::Input input,
169 samurai::WindowState windowState,
170 RequestedContainerInfo &requestedInfo) = 0;
171
172 virtual ~Container() {};
173
174};
#define GETFILESIZE(x)
#define READENTIREFILE(x)
static constexpr size_t MaxAllocatorsCount
void setGlobalAllocator(samurai::memory::CustomAllocator *allocator)
void setGlobalAllocatorToStandard()
virtual bool create(RequestedContainerInfo &requestedInfo, samurai::StaticString< 256 > commandLineArgument)=0
virtual ~Container()
virtual bool update(samurai::Input input, samurai::WindowState windowState, RequestedContainerInfo &requestedInfo)=0
static ContainerStaticInfo containerInfo()
bool operator==(const ContainerStaticInfo &other)
bool operator!=(const ContainerStaticInfo &other)
samurai::StaticVector< samurai::StaticString< 16 >, 16 > extensionsSuported
samurai::StaticVector< size_t, MaxAllocatorsCount > bonusAllocators
unsigned int requestImguiIds
bool readEntireFileBinary(const char *name, void *buffer, size_t size)
samurai::StaticVector< samurai::memory::CustomAllocator, MaxAllocatorsCount > * bonusAllocators
bool getFileSizeBinary(const char *name, size_t &size)
samurai::memory::CustomAllocator * mainAllocator
samurai::GL::PikaFramebuffer requestedFBO