Game test!

Co-authored-by: ValterMiari <ValterMiari@users.noreply.github.com>
This commit is contained in:
Victor Olin 2023-03-10 11:08:15 +01:00
parent 24daa73a39
commit 02c9ae0ab4
10 changed files with 162 additions and 69 deletions

View file

@ -6,43 +6,39 @@
#include <stdlib.h>
int main() {
// list<char> l;
// char c = 'a';
// for (int i = 1; i <= 5; i++) {
// l.push_back(c++);
// }
using namespace std;
using TimeStamp = std::chrono::_V2::system_clock::time_point;
// auto iter = l.begin();
// auto stop = l.end();
list<char> l;
char c = 'a';
for (int i = 1; i <= 5; i++) {
l.push_back(c++);
}
// while (iter != stop) {
// cout << *iter << " ";
auto iter = l.begin();
auto stop = l.end();
while (iter != stop) {
cout << *iter << " ";
// iter++;
// }
// cout << endl;
// iter = l.begin();
// while (*iter != *stop) {
// cout << *iter << " ";
// iter++;
// }
// cout << endl;
iter++;
}
cout << endl;
iter = l.begin();
while (*iter != *stop) {
cout << *iter << " ";
iter++;
}
cout << endl;
// cout << "rebased" << endl;
// cout << "iter: " << *iter << "\nstop: " << *stop << endl;
// TimeStamp ts = std::chrono::system_clock::now();
// std::time_t tt = std::chrono::system_clock::to_time_t(ts);
// std::string tstr = std::ctime(&tt);
// tstr.resize(tstr.size()-1);
// std::cout << tstr << std::endl;
char buffer[31];
std::time_t tt = std::time(NULL);
std::tm *ptm = std::localtime(&tt);
std::strftime(buffer, 31, "/profiler/log_%a_%H_%M_%S.txt", ptm);
std::cout << buffer << std::endl;
cout << "rebased" << endl;
cout << "iter: " << *iter << "\nstop: " << *stop << endl;
TimeStamp ts = std::chrono::system_clock::now();
std::time_t tt = std::chrono::system_clock::to_time_t(ts);
std::string tstr = std::ctime(&tt);
tstr.resize(tstr.size()-1);
std::cout << tstr << std::endl;
return 0;
}

26
src/GC/tests/file.cpp Normal file
View file

@ -0,0 +1,26 @@
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
int main()
{
char buffer[31];
std::time_t tt = std::time(NULL);
std::tm *ptm = std::localtime(&tt);
std::strftime(buffer, 31, "/logs/log_%a_%H_%M_%S.txt", ptm);
std::cout << buffer << std::endl;
const std::string TESTS_PATH = "/home/virre/dev/systemF/org/language/src/GC/tests/";
std::string path = TESTS_PATH + "/testlog.txt";
std::ofstream testF(path);
testF << "hellow yorld";
testF.close();
return 0;
}

View file

@ -1,6 +1,7 @@
#include <vector>
#include "player.hpp"
#include "heap.hpp"
#define X_LENGTH 1000;
#define Y_LENGTH 500;
@ -14,12 +15,38 @@ private:
public:
Game() {
dimensions = {X_LENGTH, Y_LENGTH};
}
Game() : dimensions(1000, 500) {}
void add_player(Player& p) {
players.push_back(p);
}
};
Player* create_player(string s, Point pos, Point size, Point dir) {
Player *p = static_cast<Player*>(GC::Heap::alloc(sizeof(Player)));
p->Player(s, pos, size, dir); // This will probably both be allocated on "our" heap as well as the heap for this program
return p;
}
std::vector<Player> create_players(int nr) {
for (int i = 0; i < nr; i++) {
Player *p = create_player(std::to_string(i), Point(i, i), Point(2, 2), Point(0, 0));
add_player(*p);
}
}
};
int main() {
GC::Heap::init();
GC::Heap *gc = GC::Heap::debug_the();
gc->check_init();
Game *game = static_cast<Game*>(gc->alloc(sizeof(Game)));
game->create_players(100);
gc->collect(GC::MARK);
gc->print_contents();
return 0;
}

View file

@ -2,6 +2,14 @@
using std::string;
class Point {
public:
int x, y;
Point(int _x, int _y) : x(_x), y(_y) {}
};
class Player {
private:
@ -13,12 +21,9 @@ private:
public:
Player(string n, Point pos, Point s, Point dir) {
name = n;
position = pos;
size = s;
direction = dir;
}
Player(string n, Point pos, Point s, Point dir)
: name(n), position(pos.x, pos.y), size(s.x, s.y), direction(dir.x, dir.y)
{}
void move() {
position.x += direction.x;
@ -31,7 +36,3 @@ public:
}
};
struct Point {
int x, y;
};